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.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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=unavailable 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 0AEC5C433E0 for ; Wed, 24 Feb 2021 07:13:47 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A33CA64EC9 for ; Wed, 24 Feb 2021 07:13:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A33CA64EC9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe :List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From:References:To:Subject: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=5CGLqNvhZ1w6umQVd2dGP20Unb7eGONmuNe5GbJEOj0=; b=znBpxYOpmbz3EPhhFJeYxFLcbx jSyhj5LJJtgC0ZByODg1yejaBBnWgOVXuiaxoS6wNzw0C0LGLScLC7xrSZCBghn8lWZz394n3tHq8 uDUAPHixkJht9uwHy4nMZFuZySLerHzhgplrdd9DCptOnj8bYz7JR54B4DDl+fDq4/dE4PP8OQCYW 6kdzwAd7Ic1uw2UZAmJGWj5Q4yHvOGPCc5x8+dwqjmfw6T20ydYSIjs5joz+ka3tEPa1OUJvtqAWQ fJmmOnWY+WvoQNAXC0G+6XIHk8N129BlhCfVDLKOeIfsOwy5wIkEJmDKxrq8RXWkCXhoXVyDbRCjZ qU9rMF1g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lEoLD-0006kt-KD; Wed, 24 Feb 2021 07:12:12 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lEoLB-0006kC-1K for linux-arm-kernel@lists.infradead.org; Wed, 24 Feb 2021 07:12:10 +0000 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-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210224_021209_202429_9064E916 X-CRM114-Status: GOOD ( 25.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel