From patchwork Tue Feb 16 15:03:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12090141 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 678D0C433E0 for ; Tue, 16 Feb 2021 15:04:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0500C64E04 for ; Tue, 16 Feb 2021 15:04:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0500C64E04 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 95CD56B006E; Tue, 16 Feb 2021 10:04:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 90CBC6B0070; Tue, 16 Feb 2021 10:04:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 821BD6B0071; Tue, 16 Feb 2021 10:04:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0225.hostedemail.com [216.40.44.225]) by kanga.kvack.org (Postfix) with ESMTP id 6D3316B006E for ; Tue, 16 Feb 2021 10:04:02 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E2D1B18015CD5 for ; Tue, 16 Feb 2021 15:04:01 +0000 (UTC) X-FDA: 77824451082.20.use77_560b79f27644 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id D655B18158429 for ; Tue, 16 Feb 2021 15:03:56 +0000 (UTC) X-HE-Tag: use77_560b79f27644 X-Filterd-Recvd-Size: 5429 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Tue, 16 Feb 2021 15:03:56 +0000 (UTC) Received: by mail-qk1-f179.google.com with SMTP id t63so9665834qkc.1 for ; Tue, 16 Feb 2021 07:03:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ay8uwB0CTxM9fLlpwvadwe5o1xh2kfirYugdARh6qzo=; b=k7EqMg9kJLL8nPXc1g1KYll31mwbGJqR7byNIl86kDtjVabbkoZ7qaxEpL8T2Qi0js aBg+YXVaFEAV8qfY0kQ9bW8iILxOa1qcgm8kDV6aj1yQgs+IbNNcjwmlwUCBMu6psJZw DyRx+dAideXVRR/cyE/z606e+HmEu2WpuO5pbKeaqchwN3QaU+7kICmcJRPCEfOgLj+X UNF4Kv+OgR9qVixgnMdDa+Mu4pH8IN9+32jHuuPNKZD3FOqy2EQ5jj4qL4nv8f0ia7Og GNxcF27O/P6g9AAwfjAAvuOz+PG6RpD/ydI4PIpSPjAVUYVbbILns1LltVdl6e+dmS6R EtBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ay8uwB0CTxM9fLlpwvadwe5o1xh2kfirYugdARh6qzo=; b=ZJy+VAogjA8E3nZ+zeGZNAzZiwTEk1RmPm5E+H2oKFSDJxWIjmbt4PepnTOxSJHhHd 9BlSrcurZ9wO4An18Yfj6EjqjlFEXhcJo5qZ36/usd/QIzJCBj7S/2lSNiZRH3BIZsPm LAtV8U9CvRjIZWqsVq8dsu3dCDO4XnPn7zpc2xIFTCiQ1VP7LokoQIl6gmA5fA9XcfyO NOi3goBCikGkaV9VJF07cIh8vcQ7Bv/izJk2bWryDr6fxoI4nGGVVudWjv/lO+PCfwg0 X1D1WRGo17qQRFrWRtaLCBdvrspES6wJC931BMCJJW2gnR13Yx674RvL33fSqhmPXm8l DUQw== X-Gm-Message-State: AOAM5325p12+3eF+JiCEJoFQ1aneB6iG06u5sCAirdwOzHK3G2Liytod yXpCdC9uGAQYJbYvZkuwTL6mMHtzfBPpU6bp X-Google-Smtp-Source: ABdhPJwW7utT/hOP1SW7omxfaCEy7a+KeblzASdzbL2doa5YFxaGaz/wCRpe30wAuw1/8Zizt98i4g== X-Received: by 2002:a05:620a:145:: with SMTP id e5mr19950557qkn.293.1613487835630; Tue, 16 Feb 2021 07:03:55 -0800 (PST) Received: from localhost.localdomain (c-73-69-118-222.hsd1.nh.comcast.net. [73.69.118.222]) by smtp.gmail.com with ESMTPSA id t19sm14974271qke.109.2021.02.16.07.03.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Feb 2021 07:03:54 -0800 (PST) From: Pavel Tatashin To: pasha.tatashin@soleen.com, tyhicks@linux.microsoft.com, jmorris@namei.org, catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, anshuman.khandual@arm.com, 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 Subject: [PATCH v3 1/1] arm64: mm: correct the inside linear map range during hotplug check Date: Tue, 16 Feb 2021 10:03:51 -0500 Message-Id: <20210216150351.129018-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210216150351.129018-1-pasha.tatashin@soleen.com> References: <20210216150351.129018-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 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: 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 Signed-off-by: Pavel Tatashin Fixes: 58284a901b42 ("arm64/mm: Validate hotplug range before creating linear mapping") Tested-by: Tyler Hicks Reviewed-by: Anshuman Khandual --- 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; }