From patchwork Mon Feb 15 19:22:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 12089131 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,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 11A5AC433E0 for ; Mon, 15 Feb 2021 19:23:54 +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 B221664DEC for ; Mon, 15 Feb 2021 19:23:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B221664DEC 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=+hELcKVA7PkQZHepG8ptTGvsJ2vKrrIVXbT0vhBjiZQ=; b=zUQbaSbZ3WasBqQBj3T5gNnI8s mtCwku2Zb2yjEX8X9ZHTLYUJZFLhQTH2+PLD3whPdFWMmHvDTJOxkLX7b7Lk5sLNpsN7xVppPDsNR f0V4he9gmNaxAEm0ukoMXbqRn0k/ts1rCG2Hkf7dWZQ5EMgpQNd8vJJi4Te4wSXQzkREQxeILVaFn v25achfpZuZmdCij5XCfgsLmQzHLju9oa0NZLDfS5wNEMwmLsSe2sw/N+ebICbnsNF2/1XdSXMkgJ Ix8m1b/AWq7YQTl7ca12EW/qiwkNsnv/POkI5QHFTB4eoueEMtw57oyK8R1mSPQY6M4gk2bwgyGia kpLqnDcg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lBjSK-0000p5-Jf; Mon, 15 Feb 2021 19:22:48 +0000 Received: from mail-qk1-x733.google.com ([2607:f8b0:4864:20::733]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lBjSE-0000nO-NK for linux-arm-kernel@lists.infradead.org; Mon, 15 Feb 2021 19:22:43 +0000 Received: by mail-qk1-x733.google.com with SMTP id b14so7412278qkk.0 for ; Mon, 15 Feb 2021 11:22:42 -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=jQ/sRmVJLQf6vZhL8n+vvwrkXkH2FJ5o+f5Rn4ud6SM=; b=KnI7VDWwFDBXDNaQ/PgxE3dGe4hVu2B1QGjEVaOCQyYDQO/6aaU26Zi0D5LHshGxqk p2BD42e+v3UB3x0GFRdBrRfraXuk1Bbl2rWEVJ9UowYK8KBaQOKllTCcK0zZZFpMKmHC 9h5Ct9kF2s73QIW9UcMt8z1ArHi6VOmL5IJ/1FdRrqf+raowzM643IRtaMUeV1Z48hPy bOF6i+xj1+4QlsRLrbtXiY3CzLqD5kPGtNcutvvyGOoHMmGaYD9c5RY1MKIUTXAPh1Lx TSa06GUlsPPDhZ7ASD5fupqGDOapQbB/2H/rWGV+yK6P+O42psyarwJGAuT5vRUbN3dO YO0g== 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=jQ/sRmVJLQf6vZhL8n+vvwrkXkH2FJ5o+f5Rn4ud6SM=; b=OYDqEB+2VbTbTBUaFNoQ3yH1ajh7pdesn9YRqSIIJfnnGbXEOXEKTSBE3VMXqT/P3+ odrzbSPNV9dJvJh3+h9V5nmfNB8SNI37FDF7pPXDRCgMw5FWT2tm04tsXoyhozKdvmxL JWZr3+8Gzgz/VQMh/7WWt9bKkcGgFTPWFdJQxKcKYFqp+6WWOsXE8+/5tfMYeDdvYIdd Ke8tAqib8ZAqgdmLqrGshwoa8l3yRIQq2VMculF99iUBkQTo+BDdgVNOTD0zzBH7ajzY blQMX/9hCxdrFVNaV/bhVYoz7/BIKTinu9o/I9cwcEI1RKryJKfvpLqXGMecf5bQeAqA jLvg== X-Gm-Message-State: AOAM533Uk0eOPPOTF3nk+ZOgApmWU7Dty9fZBtj1XU8XnQJBUyYkOVCO V4IjkE2WnUcP6dqyd01x1D0K7g== X-Google-Smtp-Source: ABdhPJzZRJRjqasuMeS1hejv+g7Zzm/rLY4SFGdLLz4dzY/2fE1iICmzvOZ9haQyadjzj2HTShxJoQ== X-Received: by 2002:a37:6358:: with SMTP id x85mr3630382qkb.70.1613416960788; Mon, 15 Feb 2021 11:22:40 -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 i20sm11631668qtv.73.2021.02.15.11.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 11:22:40 -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 Subject: [PATCH v2 1/1] arm64: mm: correct the inside linear map boundaries during hotplug check Date: Mon, 15 Feb 2021 14:22:37 -0500 Message-Id: <20210215192237.362706-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210215192237.362706-1-pasha.tatashin@soleen.com> References: <20210215192237.362706-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-20210215_142242_773646_20545B81 X-CRM114-Status: GOOD ( 17.14 ) 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 --- arch/arm64/mm/mmu.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index ae0c3d023824..cc16443ea67f 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1444,14 +1444,30 @@ static void __remove_pgd_mapping(pgd_t *pgdir, unsigned long start, u64 size) static bool inside_linear_region(u64 start, u64 size) { + 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)] * accommodating both its ends but excluding PAGE_END. Max physical * range which can be mapped inside this linear mapping range, must * also be derived from its end points. */ - return start >= __pa(_PAGE_OFFSET(vabits_actual)) && - (start + size - 1) <= __pa(PAGE_END - 1); + return start >= start_linear_pa && (start + size - 1) <= end_linear_pa; } int arch_add_memory(int nid, u64 start, u64 size,