From patchwork Tue May 14 14:04:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= X-Patchwork-Id: 13664169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0D81C04FFE for ; Tue, 14 May 2024 14:05:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BC808D0023; Tue, 14 May 2024 10:05:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 76B218D000D; Tue, 14 May 2024 10:05:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 632DD8D0023; Tue, 14 May 2024 10:05:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 47BA38D000D for ; Tue, 14 May 2024 10:05:12 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D9AF61212F1 for ; Tue, 14 May 2024 14:05:11 +0000 (UTC) X-FDA: 82117173222.24.2B8D9A5 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf28.hostedemail.com (Postfix) with ESMTP id 29A80C0002 for ; Tue, 14 May 2024 14:05:09 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rYtSJeVM; spf=pass (imf28.hostedemail.com: domain of bjorn@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=bjorn@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715695510; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NU8G0jAcb6KILkeAYLGZQxD4tkcTzVuo02GzGNwIgI8=; b=SBhjGPD2/i4kWHX94qsSnw1y+6vjzvGIltoYe4Oa5dAVPFAJ1xQkjESaneyLi3IWFqmurB 4cvSt6wmouJkt5WjNdKaHdpN+aZZKDaaWsWDGC6MKv+7wL50t0mKd+ZMLMz+lFQzfS1iKW FASwKGx9ctEBT8gx6gJ45HZAQHN+Hb8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715695510; a=rsa-sha256; cv=none; b=jNqQqWgexQKhFbaza4tGHvyIrIw5PeAfs1Ab4HA0oY07+9q9hUy22kjCf9tP6q887owpTd pWi+acqeLTnzDmmhlsFbZOf7A776CG7S+3tPGb/toRqHWbUWJVAbCpgD7/b+OYAOH18YN8 Z1OHOGYxabIVRISK/x0PzubhOY0J7cY= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rYtSJeVM; spf=pass (imf28.hostedemail.com: domain of bjorn@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=bjorn@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 618796126D; Tue, 14 May 2024 14:05:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BECB4C32781; Tue, 14 May 2024 14:05:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715695509; bh=oxMeKBSMHMQ7nR2cm5Yl3ZY7RY3tugjaWnxRJMQRo0c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rYtSJeVMCifMMvCoAZTlKZARdYfjyGb+3HXKoeh+9gLb/UkaJfTd3fdRakqc0wiiH xli61NfPUMpvvGx5MC2NpP4aFHaN7qIflyQLsdsGYfftEKuMMD4ZDdwSMxKUopldg2 epoHMB0A0f3xCqgRT8XnILBwq4c/Qcf+I9hdtDNmbMUoN6M+E4TfZeNPnRXQe7VCEi mVVd21lXjUiNzuH2g3rQ4vZwbs8BiVsB38K+pOqnMbn3sV+WHj2eBwtH9deDcFJFka VMVpGHW1o/zEaD/fzjuO4Rbeu3m9Kilyv7C53dWfpR7M8Aa7K8gCfy9ZFkXpBtkQwB u0bIh5mMUxCRg== From: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= To: Alexandre Ghiti , Albert Ou , David Hildenbrand , Palmer Dabbelt , Paul Walmsley , linux-riscv@lists.infradead.org Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Andrew Bresticker , Chethan Seshadri , Lorenzo Stoakes , Oscar Salvador , Santosh Mamila , Sivakumar Munnangi , Sunil V L , linux-kernel@vger.kernel.org, linux-mm@kvack.org, virtualization@lists.linux-foundation.org Subject: [PATCH v2 1/8] riscv: mm: Pre-allocate vmemmap/direct map PGD entries Date: Tue, 14 May 2024 16:04:39 +0200 Message-Id: <20240514140446.538622-2-bjorn@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240514140446.538622-1-bjorn@kernel.org> References: <20240514140446.538622-1-bjorn@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 29A80C0002 X-Rspam-User: X-Stat-Signature: nc375c4mjwbjgj4rwycwy8et4ysdrz9f X-HE-Tag: 1715695509-651735 X-HE-Meta: U2FsdGVkX1+99UfeQPin60DV8un8AiPh20SYFbohTg01PLEI9Zlnd85W5lXkZwocjDl1UdmW75CYA9BHaSP7to2BM5k1jrQsLcpDGeOPF2r/lC0arQBE/d7QDJ3qRwG0XH2m8BXGxy8yXKFuiiue9kjw5hqMbcDIs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HfSQio2u7HifHuwvRopTrVWlRFYzWMscy6zDer7aZQxkvqUJJQwceite/tv0Z3aWeC/dPHaZHZTSvng59ztcV8CrxIQKcjfgtpyIug1zAwuCc3UKnizSucGmVn8brG7ILbE8TJYdnxxmW2Sk4cUBXAj4eC 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: List-Subscribe: List-Unsubscribe: From: Björn Töpel The RISC-V port copies the PGD table from init_mm/swapper_pg_dir to all userland page tables, which means that if the PGD level table is changed, other page tables has to be updated as well. Instead of having the PGD changes ripple out to all tables, the synchronization can be avoided by pre-allocating the PGD entries/pages at boot, avoiding the synchronization all together. This is currently done for the bpf/modules, and vmalloc PGD regions. Extend this scheme for the PGD regions touched by memory hotplugging. Prepare the RISC-V port for memory hotplug by pre-allocate vmemmap/direct map entries at the PGD level. This will roughly waste ~128 worth of 4K pages when memory hotplugging is enabled in the kernel configuration. Signed-off-by: Björn Töpel Reviewed-by: Alexandre Ghiti --- arch/riscv/include/asm/kasan.h | 4 ++-- arch/riscv/mm/init.c | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/kasan.h b/arch/riscv/include/asm/kasan.h index 0b85e363e778..e6a0071bdb56 100644 --- a/arch/riscv/include/asm/kasan.h +++ b/arch/riscv/include/asm/kasan.h @@ -6,8 +6,6 @@ #ifndef __ASSEMBLY__ -#ifdef CONFIG_KASAN - /* * The following comment was copied from arm64: * KASAN_SHADOW_START: beginning of the kernel virtual addresses. @@ -34,6 +32,8 @@ */ #define KASAN_SHADOW_START ((KASAN_SHADOW_END - KASAN_SHADOW_SIZE) & PGDIR_MASK) #define KASAN_SHADOW_END MODULES_LOWEST_VADDR + +#ifdef CONFIG_KASAN #define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL) void kasan_init(void); diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 2574f6a3b0e7..5b8cdfafb52a 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -1488,10 +1489,16 @@ static void __init preallocate_pgd_pages_range(unsigned long start, unsigned lon panic("Failed to pre-allocate %s pages for %s area\n", lvl, area); } +#define PAGE_END KASAN_SHADOW_START + void __init pgtable_cache_init(void) { preallocate_pgd_pages_range(VMALLOC_START, VMALLOC_END, "vmalloc"); if (IS_ENABLED(CONFIG_MODULES)) preallocate_pgd_pages_range(MODULES_VADDR, MODULES_END, "bpf/modules"); + if (IS_ENABLED(CONFIG_MEMORY_HOTPLUG)) { + preallocate_pgd_pages_range(VMEMMAP_START, VMEMMAP_END, "vmemmap"); + preallocate_pgd_pages_range(PAGE_OFFSET, PAGE_END, "direct map"); + } } #endif