Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp233084lqr; Wed, 5 Jun 2024 04:41:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXU95+HPtS+Hd5Xky9ochp4JaejrvZubpdRkbdjUQcKm11P/xWjoYbz5uiQUoj+jc6uLWWLJt30ysixThoUCuA8BRHCfLEsAeFpgWAJoA== X-Google-Smtp-Source: AGHT+IHjtGcQu/2p8ytGVDEXrISj9G9Tn+7dI+F+5pq0Or3qWx7Vy+QHrMENP4/8dnOix+X+woKm X-Received: by 2002:a81:e20e:0:b0:61b:1c6f:830e with SMTP id 00721157ae682-62cbb5ce7a6mr21737607b3.43.1717587715203; Wed, 05 Jun 2024 04:41:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717587715; cv=pass; d=google.com; s=arc-20160816; b=b7NJYZ25t5ejI471Dk9RsfmVCyNew179rxZPXn6oYIYyq8u/3vC4ajmhRh37ZsacXh kIUTNnnYodqtPyHRc9oejTZntKBkBF2KXny6V9eI5UeCaBIsmcQGMOMVzKwTbWdWuvRg IP1XXnC49xJfQanM8ntD/W5q/MIiKBhGrdwQJGHx6DsIwRnJHV3aGg3ZLZUVGB8JJQop 5YvqJT8kL0BBkDVrYkNCA8bSouxyejUbI3Q5QdZFd8bKu57Eq6wwwnzBb8TERKy9HVD0 3K8KB7u5DNTclNnOVwjApr/dBf5xTksjXY5y6GnUhSlfZ2S7gSWW3rb04JMKZMDHiaIi ytPw== 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=iPRV/6FetLB6q/cO8mOCjqXtnrBf/F9VJ26oeNfsMWE=; fh=/tocBNknTX0CBdcxdKGUdCq+MQUhEmbYJSr49AVQ1Gk=; b=GKcFR2qeg7g1Hol0lS9Kszuxsi+0H/X7uyPJx1AglQneDSspi0X4vSQiESv3S3QbJK 9znd87X16R0bD3Wqk46DMr7o/h3KIut8MREVd728F3V2xFZ0HmiD4du7pxITrz7WN5VC 0M/BwTWXw1k/ICZIP2wDmWA9ftX4EXQA3aXzGNwJexuUULH5psgxutV4jF2Af7zGuKzj mt6xdfrtv4ejnbH97HcUVaYZS4sc16shQoHCMq+kJV0hewWeVOdXIci8OzZFmIWkbJnF OqVxrQQG5WICg005ewt/A6+Gxeao9NmurQrphLZa+ZnBFquuh4SEiG0GNhj1wfSDJsQL O/cw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HATjXYku; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202276-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202276-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6ae4b401a21si14982806d6.256.2024.06.05.04.41.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 04:41:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202276-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HATjXYku; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202276-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202276-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E556C1C22902 for ; Wed, 5 Jun 2024 11:41:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3644119308E; Wed, 5 Jun 2024 11:41:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HATjXYku" 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 61D93140380 for ; Wed, 5 Jun 2024 11:41:23 +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=1717587684; cv=none; b=uudsI2FISMMGXKLbrEgZDhi2GoOOBylh+Gp01UKpJh8GZR2owC4O0nTjalVgWG8YjIP+IYEXWX1G24+d9+P3sVMaNoun9Afayp9NaxM5/DB+o1dy1hxWci2ZPPT2v32sVk4OqYyK7n933ttfP8tNs6uYcGFrI1mYukn0XOXfuEE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717587684; c=relaxed/simple; bh=HsHTP5EMBxXRbP7gHM9U5cuEmdv/0OsepSBXxmcR9vk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XWKEN5MJedXWEZSVUNhGqqyaZvEXvELcUWhh1YvWABaO+rDAQdEjZCZcBDAlwT3It2KOETJl+d6tK/4uL3RCvbgIns5fyzBJBpgeOEJJTudhnt380d5j72KWNAlkMTdYoI25DmwrzRWIk8Y0bUaXz5ZxCOomAUYqzJ7ed96wwLs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HATjXYku; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0A38C32781; Wed, 5 Jun 2024 11:41:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717587683; bh=HsHTP5EMBxXRbP7gHM9U5cuEmdv/0OsepSBXxmcR9vk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HATjXYkuNGAJd6ZLv+T2v73tr+Mc6k2jRhJItwlkYIAMhhwWJcS9UAkccUyjIGocm FpT5Qk21uUbdooqRUAgy0kZUw+P/J0vSaZ/BBxDRdx4Ux/+hf7kGQ9N5Qrv6wvPA7i nDivxB55BW0xjUIvNRnHMGR086mp0iiVgd/1dXwNc6PCovq009SjJTw4oRIZcmWQYR jCrbPH4Os670nJF5DH11/jvO5GP+uTC5v335/W5W7nBd01MhUwdEyweJtBVvSA7sad ALF4qUwr8X3xtfo2/HtKrJcfrhAbSKFg21UaNds30Hdi0KwftR7UHoI+cd51TBVay7 nivI6FKPDR+hA== 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, Oscar Salvador Cc: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Andrew Bresticker , Chethan Seshadri , Lorenzo Stoakes , Santosh Mamila , Sivakumar Munnangi , Sunil V L , linux-kernel@vger.kernel.org, linux-mm@kvack.org, virtualization@lists.linux-foundation.org Subject: [PATCH v4 02/11] riscv: mm: Pre-allocate vmemmap/direct map/kasan PGD entries Date: Wed, 5 Jun 2024 13:40:45 +0200 Message-ID: <20240605114100.315918-3-bjorn@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605114100.315918-1-bjorn@kernel.org> References: <20240605114100.315918-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/kasan entries at the PGD level. This will roughly waste ~128 (plus 32 if KASAN is enabled) worth of 4K pages when memory hotplugging is enabled in the kernel configuration. Reviewed-by: Alexandre Ghiti Signed-off-by: Björn Töpel --- arch/riscv/include/asm/kasan.h | 4 ++-- arch/riscv/mm/init.c | 9 +++++++++ 2 files changed, 11 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 fe5072f66c8c..a5b3bc1f3b88 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -1493,11 +1494,19 @@ 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"); + if (IS_ENABLED(CONFIG_KASAN)) + preallocate_pgd_pages_range(KASAN_SHADOW_START, KASAN_SHADOW_END, "kasan"); + } } #endif -- 2.43.0