From patchwork Wed Jan 11 14:54:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 90897 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1159368qgi; Wed, 11 Jan 2017 06:55:30 -0800 (PST) X-Received: by 10.99.95.216 with SMTP id t207mr11396684pgb.0.1484146530150; Wed, 11 Jan 2017 06:55:30 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id 188si6027491pgd.181.2017.01.11.06.55.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jan 2017 06:55:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cRKJF-0002vk-Bh; Wed, 11 Jan 2017 14:55:29 +0000 Received: from mail-wj0-x22b.google.com ([2a00:1450:400c:c01::22b]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cRKJ9-0001kM-Qc for linux-arm-kernel@lists.infradead.org; Wed, 11 Jan 2017 14:55:25 +0000 Received: by mail-wj0-x22b.google.com with SMTP id tn15so104411333wjb.1 for ; Wed, 11 Jan 2017 06:55:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=DB9R+c5F2ONmn7ig6FSoXvTXEOVOiQmImE12MfkRMlw=; b=L5PUNKvpgH7FkGmMC1siy191yo26+b+ErlOpw/WDhZuDWHSZjvHvoPbgSnLOYFbZYb s4nij8zDRj4ZyWFcB25Mf4KBqxBIGaLd9x/uN78fWSBAhFUM/2UYa0GG5u8jIQfyqaHd QwvNThLlw6TE6Dcnmq2IbSShRtPGV5vxMShso= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=DB9R+c5F2ONmn7ig6FSoXvTXEOVOiQmImE12MfkRMlw=; b=GGAZCEbtTgBcuKhwB7638uLuoQxD5BrPR3Mm1W31R6H5pUDGumV9nvMpP+xUAKIj+R bN1AK2Kh4sC2nKp1aN5aUiiI104xneloYfun9An12KqJbtSSMmKNL9tn4A+Ck4Dw9aRo VY7P1b/vLB2IpBoebCyN2yvAEbYz31owgmylRUB0TffXRVUJ7hG3oXXMPsnawFhMHJ9W a206EA4osYPate2eqpU6YeztzbmRKW3lO7fJ2G9gT8lyKDQHQN6dPfYpUdRT6YOx42W9 VJRYx31+gOjTi6iv7vHcMJsxFxmgQ73CO78FwU9PTSqrds3D4JfZPC2yH9iV6TGPpNgD mQTw== X-Gm-Message-State: AIkVDXLjOYQa462BRdwMK1N9TEwihTmT/iiEOQItI9CNMHYwOT82IX6PYBXGeCa3KWSDp6r8 X-Received: by 10.194.98.208 with SMTP id ek16mr6533618wjb.94.1484146501117; Wed, 11 Jan 2017 06:55:01 -0800 (PST) Received: from localhost.localdomain ([160.167.203.25]) by smtp.gmail.com with ESMTPSA id f76sm9425021wmd.15.2017.01.11.06.54.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Jan 2017 06:55:00 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, mark.rutland@arm.com, will.deacon@arm.com Subject: [PATCH] arm64: assembler: make adr_l work in modules under KASLR Date: Wed, 11 Jan 2017 14:54:53 +0000 Message-Id: <1484146493-18460-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170111_065524_029865_570E6B44 X-CRM114-Status: GOOD ( 12.92 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c01:0:0:0:22b listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: catalin.marinas@arm.com, Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org When CONFIG_RANDOMIZE_MODULE_REGION_FULL=y, the offset between loaded modules and the core kernel may exceed 4 GB, putting symbols exported by the core kernel out of the reach of the ordinary adrp/add instruction pairs used to generate relative symbol references. So make the adr_l macro emit a movz/movk sequence instead when executing in module context. While at it, remove the pointless special case for the stack pointer. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/assembler.h | 36 +++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) -- 2.7.4 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel Acked-by: Mark Rutland Acked-by: Will Deacon diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index 446f6c46d4b1..3a4301163e04 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -164,22 +164,25 @@ lr .req x30 // link register /* * Pseudo-ops for PC-relative adr/ldr/str , where - * is within the range +/- 4 GB of the PC. + * is within the range +/- 4 GB of the PC when running + * in core kernel context. In module context, a movz/movk sequence + * is used, since modules may be loaded far away from the kernel + * when KASLR is in effect. */ /* * @dst: destination register (64 bit wide) * @sym: name of the symbol - * @tmp: optional scratch register to be used if == sp, which - * is not allowed in an adrp instruction */ - .macro adr_l, dst, sym, tmp= - .ifb \tmp + .macro adr_l, dst, sym +#ifndef MODULE adrp \dst, \sym add \dst, \dst, :lo12:\sym - .else - adrp \tmp, \sym - add \dst, \tmp, :lo12:\sym - .endif +#else + movz \dst, #:abs_g3:\sym + movk \dst, #:abs_g2_nc:\sym + movk \dst, #:abs_g1_nc:\sym + movk \dst, #:abs_g0_nc:\sym +#endif .endm /* @@ -190,6 +193,7 @@ lr .req x30 // link register * the address */ .macro ldr_l, dst, sym, tmp= +#ifndef MODULE .ifb \tmp adrp \dst, \sym ldr \dst, [\dst, :lo12:\sym] @@ -197,6 +201,15 @@ lr .req x30 // link register adrp \tmp, \sym ldr \dst, [\tmp, :lo12:\sym] .endif +#else + .ifb \tmp + adr_l \dst, \sym + ldr \dst, [\dst] + .else + adr_l \tmp, \sym + ldr \dst, [\tmp] + .endif +#endif .endm /* @@ -206,8 +219,13 @@ lr .req x30 // link register * while needs to be preserved. */ .macro str_l, src, sym, tmp +#ifndef MODULE adrp \tmp, \sym str \src, [\tmp, :lo12:\sym] +#else + adr_l \tmp, \sym + str \src, [\tmp] +#endif .endm /*