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: 12090133 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.8 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,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 6F9F8C433DB for ; Tue, 16 Feb 2021 15:05:38 +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 3AA5B64E02 for ; Tue, 16 Feb 2021 15:05:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3AA5B64E02 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.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:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:To:From: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zJ0ezk/cQC59bDFTCnnXqG/uIV0uh5z9YhBkXKv4WoU=; b=2giQqiLNuhK3PIxdqtW3z/wSzk hc1nQsQQRcuoG+Vtweuk9idKqR/Ofo1iy+8AsCw+M4Knd5Vrh//TFMHxuOtulYp2rSNDa+P4wXIT4 VqaA8Ddr4B2bDA2E94j0GWZ65cykhY3Oi5Iwrt51Siabk34YkLhwnJQ51lMAbV3K6cakrJvQwGKqu zAHuoFlX7zdPmOCJQ4FRBBZDQlIVbxDmmZouetRzBlqJ/aYk8RU+asvwCQ3qBLFTI5caHITs1hTaY JenPxnObBpbaQkALWPrJjve1IecHdhJaR5PMimTldFq75LKoddn3obtzZgc39jEhiV/wZef9bQ8jq SXhroF8A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lC1tR-0004Rd-1s; Tue, 16 Feb 2021 15:04:01 +0000 Received: from mail-qk1-x735.google.com ([2607:f8b0:4864:20::735]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lC1tN-0004QT-Gt for linux-arm-kernel@lists.infradead.org; Tue, 16 Feb 2021 15:03:58 +0000 Received: by mail-qk1-x735.google.com with SMTP id m144so9593009qke.10 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=b8G3Rdyn03ETB9kBRkMAsAkBjYdzDwkS9NvpKrSdkPPI/BY5LOwgh/7Y3lESbOLRxz HnSBakE0GzmRVidDaGTbCZ0uaC7AsHjbfiqlGgujanA460J8Rkm6QOc4Qh2M9wZiP48G qBBDalNqpBnaExvAdwtzBNVR9yVUSFOxLZ29eY/e8bgJakxjdw5eZ9DoyiMnjyWeFwRl 82UGMG5oKsUZfGFeJzwmmaq+CAdH65gglaKR2yWaDp7YQah06fuB0sFAPERDq2FbVamK e/D5TLj+5GA9xTFj8zT2eKQdyBEEztfNAUYFY/YKTwvEcCMnniklt1wnR6dV6EhEvdxg lLNw== X-Gm-Message-State: AOAM533xgNQYtBZCuEaFGvvQhvGBZLtNEVp5JQ9l6gZ9uxZLWO/7Gm2F IP33U4r85qogU51J+f+76PMf4Q== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210216_100357_591022_1BA91E11 X-CRM114-Status: GOOD ( 16.61 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; }