From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 062D8C433E0 for ; Wed, 24 Feb 2021 07:12:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6877564EC9 for ; Wed, 24 Feb 2021 07:12:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6877564EC9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 68D2C6B006E; Wed, 24 Feb 2021 02:12:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 616B36B0070; Wed, 24 Feb 2021 02:12:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DD2B6B0071; Wed, 24 Feb 2021 02:12:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0064.hostedemail.com [216.40.44.64]) by kanga.kvack.org (Postfix) with ESMTP id 349106B006E for ; Wed, 24 Feb 2021 02:12:08 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id DE3228792 for ; Wed, 24 Feb 2021 07:12:07 +0000 (UTC) X-FDA: 77852292294.23.E3BE129 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf20.hostedemail.com (Postfix) with ESMTP id 5103ADA for ; Wed, 24 Feb 2021 07:12:07 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 85CD71FB; Tue, 23 Feb 2021 23:12:06 -0800 (PST) Received: from [10.163.64.181] (unknown [10.163.64.181]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 35D053F73D; Tue, 23 Feb 2021 23:12:01 -0800 (PST) Subject: Re: [PATCH v3 1/1] arm64: mm: correct the inside linear map range during hotplug check To: Pavel Tatashin , tyhicks@linux.microsoft.com, jmorris@namei.org, catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, rppt@kernel.org, logang@deltatee.com, ardb@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, mhocko@suse.com, linux-mm@kvack.org References: <20210216150351.129018-1-pasha.tatashin@soleen.com> <20210216150351.129018-2-pasha.tatashin@soleen.com> From: Anshuman Khandual Message-ID: <605fb3ad-7208-6d27-f055-cb642be8804b@arm.com> Date: Wed, 24 Feb 2021 12:42:31 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210216150351.129018-2-pasha.tatashin@soleen.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Stat-Signature: hi3hodpjuyw3mjgn1fztod5zhz6cse8p X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 5103ADA Received-SPF: none (arm.com>: No applicable sender policy available) receiver=imf20; identity=mailfrom; envelope-from=""; helo=foss.arm.com; client-ip=217.140.110.172 X-HE-DKIM-Result: none/none X-HE-Tag: 1614150727-136068 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2/16/21 8:33 PM, Pavel Tatashin wrote: > Memory hotplug may fail on systems with CONFIG_RANDOMIZE_BASE because the > linear map range is not checked correctly. > > The start physical address that linear map covers can be actually at the > end of the range because of randomization. Check that and if so reduce it > to 0. > > This can be verified on QEMU with setting kaslr-seed to ~0ul: > > memstart_offset_seed = 0xffff > START: __pa(_PAGE_OFFSET(vabits_actual)) = ffff9000c0000000 > END: __pa(PAGE_END - 1) = 1000bfffffff This would have tripped the check in mhp_get_pluggable_range() with errors something like here, which is expected. Hotplug memory [0x680000000-0x688000000] exceeds maximum addressable range [0x0-0x0] Hotplug memory [0x6c0000000-0x6c8000000] exceeds maximum addressable range [0x0-0x0] Hotplug memory [0x700000000-0x708000000] exceeds maximum addressable range [0x0-0x0] Hotplug memory [0x780000000-0x788000000] exceeds maximum addressable range [0x0-0x0] Hotplug memory [0x7c0000000-0x7c8000000] exceeds maximum addressable range [0x0-0x0] > > Signed-off-by: Pavel Tatashin > Fixes: 58284a901b42 ("arm64/mm: Validate hotplug range before creating linear mapping") > Tested-by: Tyler Hicks > --- > arch/arm64/mm/mmu.c | 21 +++++++++++++++++++-- > 1 file changed, 19 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > index ef7698c4e2f0..0d9c115e427f 100644 > --- a/arch/arm64/mm/mmu.c > +++ b/arch/arm64/mm/mmu.c > @@ -1447,6 +1447,22 @@ static void __remove_pgd_mapping(pgd_t *pgdir, unsigned long start, u64 size) > struct range arch_get_mappable_range(void) > { > struct range mhp_range; > + u64 start_linear_pa = __pa(_PAGE_OFFSET(vabits_actual)); > + u64 end_linear_pa = __pa(PAGE_END - 1); > + > + if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) { > + /* > + * Check for a wrap, it is possible because of randomized linear > + * mapping the start physical address is actually bigger than > + * the end physical address. In this case set start to zero > + * because [0, end_linear_pa] range must still be able to cover > + * all addressable physical addresses. > + */ > + if (start_linear_pa > end_linear_pa) > + start_linear_pa = 0; > + } > + > + WARN_ON(start_linear_pa > end_linear_pa); > > /* > * Linear mapping region is the range [PAGE_OFFSET..(PAGE_END - 1)] > @@ -1454,8 +1470,9 @@ struct range arch_get_mappable_range(void) > * range which can be mapped inside this linear mapping range, must > * also be derived from its end points. > */ > - mhp_range.start = __pa(_PAGE_OFFSET(vabits_actual)); > - mhp_range.end = __pa(PAGE_END - 1); > + mhp_range.start = start_linear_pa; > + mhp_range.end = end_linear_pa; > + > return mhp_range; > } LGTM. Reviewed-by: Anshuman Khandual