Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2708979lqo; Tue, 14 May 2024 07:05:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWqZclVW6uzeVYuWlp0UxyP1CYH6a45j2kQn5dHOVb49xBb2IBhWUk0us2ycJY/3amc4kztbKS6sy0tJg8Y56QOEp5Pf37lpfUdnQ86yw== X-Google-Smtp-Source: AGHT+IFwb2G7gPwhOgK50DsmICwNjdtvQOzFSmgjLEvOTSdRc020SrJhc3YyDK+DxbgiviPEiuW/ X-Received: by 2002:a17:903:41c9:b0:1e1:3300:702b with SMTP id d9443c01a7336-1ef43d1558emr141441465ad.15.1715695550607; Tue, 14 May 2024 07:05:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715695550; cv=pass; d=google.com; s=arc-20160816; b=jQ/Hxz1LYOIAKCjEJdgRg0RaA5MEtyX0bH2SuUA2sSgLnUfV1uYPM5e9X62M6yrgGX ZQX7ZzoG3smR1Lkp5n2UzM46Y0SFNkW4QtfyvjGuqRISTKTIuTkKGvZAhJHwHfvEuG1W nHwK6UEEsZNmPwZ6YbbV+LiVXHklEuc7cF2fRcQeYxQREYd1HJVKzjr+uns9bL1m8dm8 G81BNIXfYEgVJSzJ2k2rxNyOHHRndrKfFSMMHLVrcHkqEViIRdR3c1ABxX4RLe5xi+AV erLa/L6CxARyTt4BLjJYwdS8XLk6KHsOs/L/QD3zUW2yWukbgr9rmB1nSiaCheMORyOn tybQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=NU8G0jAcb6KILkeAYLGZQxD4tkcTzVuo02GzGNwIgI8=; fh=uMFliFihFxUmoRF8pjhRbK6V6DFjFNjH6h18EfWUiEU=; b=gwRjgB/fm7Nu0E2PYJJ34Q5HDPe8wpdfDoacnNyRggKO5ev5yWsixh8Kd0UK88d4+z oDjFI5K4O6zXQK2A5BdKC0/+ztagA5PWLYtpiixh9e+Dlb4F86VoqLZljHtmagynC6PO RvLC1KhiEVn8EF6p9xL1AuZQ8GhJjRYLWE3y+nY8LtV27i7RKxz649BBxgxSRF+BGcfH QNNkN4etXkeYxRvTViGYbo1EOYn25F/xBXKoq1+pTEyeR+QjbhzWN09NJ6csl4FLS92B VmQR8CnQGaEqLIqRF5auRYN6C1xs5h/py/LJWQFFxLYdpL5UlNOUrk3GofGhPiRoA7zg ecCw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rYtSJeVM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-178779-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178779-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-63409e8259fsi11453700a12.99.2024.05.14.07.05.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 07:05:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-178779-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rYtSJeVM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-178779-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178779-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 998BFB22143 for ; Tue, 14 May 2024 14:05:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7ED1E145321; Tue, 14 May 2024 14:05:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rYtSJeVM" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B1F9144D25 for ; Tue, 14 May 2024 14:05:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715695509; cv=none; b=V+scSQC4DH0nkwln4WbInb/1yAQJMlYI7XyH5rfcYrInOafdAL2VsQcnEoO/YqlknSGaSzmiY+luBhwEJANRYqPK4ovS7sDk32l3KvJ5TgtfZsbNH2jOFRyE7iazztf7h1Xe6R5K5nY4aq7OtVy7LD0pjlJdjzwRjjEgfsXZ6DA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715695509; c=relaxed/simple; bh=oxMeKBSMHMQ7nR2cm5Yl3ZY7RY3tugjaWnxRJMQRo0c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=PNxx9BzRSeq5yioWPdcc9iKAg8l0SYwdmX8TjtIjGCcEAUU2xZZicTwDdMtg898qhpu7ruAlsE0KqhDnHzJ9Vmg3uaUKkXR9arhTUq/ukWVbf+qgKOKXReaaAsC0FbkTiHJJKYbTDKoorAruJGB0PK10iQx5Wj19+W3VFG6lAys= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rYtSJeVM; arc=none smtp.client-ip=10.30.226.201 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?q?Bj=C3=B6rn=20T=C3=B6pel?= To: Alexandre Ghiti , Albert Ou , David Hildenbrand , Palmer Dabbelt , Paul Walmsley , linux-riscv@lists.infradead.org Cc: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- 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 -- 2.40.1