From patchwork Mon Feb 29 12:39:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 63203 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp1222673lbc; Mon, 29 Feb 2016 04:41:05 -0800 (PST) X-Received: by 10.66.90.226 with SMTP id bz2mr21769759pab.31.1456749665079; Mon, 29 Feb 2016 04:41:05 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id u83si14677951pfa.236.2016.02.29.04.41.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Feb 2016 04:41:05 -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; 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; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aaN7W-0003wJ-0r; Mon, 29 Feb 2016 12:40:14 +0000 Received: from mail-io0-x22f.google.com ([2607:f8b0:4001:c06::22f]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aaN7S-0002jO-02 for linux-arm-kernel@lists.infradead.org; Mon, 29 Feb 2016 12:40:11 +0000 Received: by mail-io0-x22f.google.com with SMTP id l127so184202526iof.3 for ; Mon, 29 Feb 2016 04:39:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=pFASdvdjuofOc6fhoZay1EDNVlNtffSFpCSycLIt2Is=; b=IPNeLvjY0Y9ttaFwJ52APSQsOciPkp1izuEqhL/K4VBL+zpVxKcXbI173Ns1liw4T8 Yg8g8mopF9vmUR4iD31dM5XFaHlocqmd6sSwJ1PVSxwkFKRFRN1WLlyPItS0GNDIEMlc NiKHU9tUGYCrxt1Fe81O2IFmSYMx8Np0+NfTE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=pFASdvdjuofOc6fhoZay1EDNVlNtffSFpCSycLIt2Is=; b=K2gv0bgxDzAsfsPQGdXTMcDjDWawQStW52jdG96eYmHxzd2eOHMdHKPNgKuaNIxdi/ eg0Ljp6bz7off33MCa5upRCz/hhbtgMiPtTKk+7/49ruXY6a8iOGkhkWTsjlwUDmL5Q6 b/taqEcs+1mWJjjTb4MrllUdObQyxdhVPSciPaeaC0PXdMz3GM2zya9036e+9HF+vJvQ hZCq10+qNzFInFetAK4yJBMdrl1yk4w4jWC13wBXsj/OfodhkJxXscka/j7YvWVPZwOj IA7YE6uTaz6NF20ZvdFj8mpwb72w7uccKsIdfmS3VEQ/ytbkOK5ezpdZS+Lqn9ZDRqwc Tonw== X-Gm-Message-State: AG10YOQ0wD94oQoi6KK4jLe7euyQU62qUPID1HzbLnf96Z85iFYV1k6UPL/lgz4K6LbA3wMOJ7nrcC+M0rhy6xt3 MIME-Version: 1.0 X-Received: by 10.107.18.199 with SMTP id 68mr18207910ios.130.1456749588940; Mon, 29 Feb 2016 04:39:48 -0800 (PST) Received: by 10.36.29.6 with HTTP; Mon, 29 Feb 2016 04:39:48 -0800 (PST) In-Reply-To: <1456505834-8638-3-git-send-email-ard.biesheuvel@linaro.org> References: <1456505834-8638-1-git-send-email-ard.biesheuvel@linaro.org> <1456505834-8638-3-git-send-email-ard.biesheuvel@linaro.org> Date: Mon, 29 Feb 2016 13:39:48 +0100 Message-ID: Subject: Re: [PATCH v2 2/2] arm64: mm: treat memstart_addr as a signed quantity From: Ard Biesheuvel To: "linux-arm-kernel@lists.infradead.org" , Will Deacon , Catalin Marinas , Mark Rutland X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160229_044010_263027_16112770 X-CRM114-Status: GOOD ( 16.48 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2607:f8b0:4001:c06:0:0:0:22f 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_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -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.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org On 26 February 2016 at 17:57, Ard Biesheuvel wrote: > Commit c031a4213c11 ("arm64: kaslr: randomize the linear region") > implements randomization of the linear region, by subtracting a random > multiple of PUD_SIZE from memstart_addr. This causes the virtual mapping > of system RAM to move upwards in the linear region, and at the same time > causes memstart_addr to assume a value which may be negative if the offset > of system RAM in the physical space is smaller than its offset relative to > PAGE_OFFSET in the virtual space. > > Since memstart_addr is effectively an offset now, redefine its type as s64 > so that expressions involving shifting or division preserve its sign. > > Signed-off-by: Ard Biesheuvel FYI this results in a warning, please fold > --- > arch/arm64/include/asm/memory.h | 2 +- > arch/arm64/mm/init.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h > index 5f8667a99e41..12f8a00fb3f1 100644 > --- a/arch/arm64/include/asm/memory.h > +++ b/arch/arm64/include/asm/memory.h > @@ -135,7 +135,7 @@ > #include > #include > > -extern phys_addr_t memstart_addr; > +extern s64 memstart_addr; > /* PHYS_OFFSET - the physical address of the start of memory. */ > #define PHYS_OFFSET ({ VM_BUG_ON(memstart_addr & 1); memstart_addr; }) > > diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c > index 4ea7efc28e65..a2977d33e0dc 100644 > --- a/arch/arm64/mm/init.c > +++ b/arch/arm64/mm/init.c > @@ -54,7 +54,7 @@ > * executes, which assigns it its actual value. So use a default value > * that cannot be mistaken for a real physical address. > */ > -phys_addr_t memstart_addr __read_mostly = ~0ULL; > +s64 memstart_addr __read_mostly = -1; > phys_addr_t arm64_dma_phys_limit __read_mostly; > > #ifdef CONFIG_BLK_DEV_INITRD > -- > 2.5.0 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 67ce440cb702..9cfe94b41b54 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -181,7 +181,7 @@ void __init arm64_memblock_init(void) * linear mapping. Take care not to clip the kernel which may be * high in memory. */ - memblock_remove(max(memstart_addr + linear_region_size, __pa(_end)), + memblock_remove(max_t(u64, memstart_addr + linear_region_size, __pa(_end)), ULLONG_MAX); if (memblock_end_of_DRAM() > linear_region_size) memblock_remove(0, memblock_end_of_DRAM() - linear_region_size);