Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2804426lqo; Tue, 14 May 2024 09:33:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWbyvNnKCDJh6YAX6BC3xpR5G6j7PqRWYsN/Hwm//6yb9QVGsWtY4CZDZZtR7dAV6hLomoF5uL3xKQaXoYFQ09OkToPtx73IKyjp/k29g== X-Google-Smtp-Source: AGHT+IHCr56ZBFAu4QmRW0w+6RY9oWL+pclInCQ0OhETuW3Zat9HrfqcbP9iy57OAdOQxPeCSxGi X-Received: by 2002:a17:907:3e11:b0:a5a:1871:e2a1 with SMTP id a640c23a62f3a-a5a2d5cb5eemr922725466b.33.1715704401478; Tue, 14 May 2024 09:33:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715704401; cv=pass; d=google.com; s=arc-20160816; b=RvCUPIiiIsBcH3vkLdBlVte8fXkNTKNV5I6JATu7EiOuoCWtpjsN+5pMkK18QhEwGI dCl7sjTPnbRZgWcxsLnfbf0p8lSEnNYBcD59NMDubb58zLAbuv4VbLfp8r9m0rZQCrxj VgbpkTqjzED7D4A4CuPp1p/tEcATA5xcf4lVRTAkTwDJ4+nEaZwITWn0UnnC8JFqQWgC g44+4CIoFMau7K6GZpFS+aTAs/0Y27DMx9RSw724lknITLDHp7f2XmgXpJxfUTS0BmIJ ukDIg5sWfe67ZvQB3Eo/99nxregyc2ngV/KpH/Z25DStS154aBRKWA/o5Xs/E/rTSkVa LsbA== 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:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=34Q/BDHry0KBYFlzUh40edm+mtri4LfGkiRP1RWInqk=; fh=oZi5eKU0QjNjqhVy+lIrjjGGjaz7VxxV59RKsfbjyYw=; b=eyZs3E5NOsm1jILVbdvKU8BdI+uldmQCS3fw+9If5ySDP2jEsHJIakPO9j8G/FXCYq dhxnjIlN1DG72eRhCZwIHnfWseZFLNnEdL0nEjipPER4fn93I/5k7u8R1n0pqsp5/KjX y88T5uW/zyziF2dTHYab3HW7wYJE0/m5ZFxdlNJ7HBNXtpBPUsAOMoGM9gu3/ED+mVF9 Rt8FSYJ6IZn1biBX34Vn2EQgyDex8zhcG/FyV56Vn6eUzTYcD8jwar81pCnUugB1+exg 6OrmPUuGCotco2Jzn/OPn84L6uHGOI5CLmEL05+mnAvnnpRgreusyM/oyXHcBa7h8JQw 9/qg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WTI29hSi; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-178955-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178955-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a179460e3si661214066b.203.2024.05.14.09.33.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 09:33:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-178955-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WTI29hSi; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-178955-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178955-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 3A39B1F21640 for ; Tue, 14 May 2024 16:33:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 07FDD339A0; Tue, 14 May 2024 16:33:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WTI29hSi" 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 2BE2D28366 for ; Tue, 14 May 2024 16:33:12 +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=1715704393; cv=none; b=LkNcwmwDvjKdMyJkr6B66Mee6OwI28Aq1PAXfkLWgEN1WQV9jr7TCyuveKzr30f6VA4mBwAbzEJ4D9D3UKPpkxrXC9BkJZJFf1+H+pxMdRSLSJIBTPkcOGVbsRldUmRi/sYkIH8b1Ap3pNMOm5DnMq/VNOmKlyIwFZmBTZSXB/o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715704393; c=relaxed/simple; bh=2O3FVoVp95G4P4aUBtb5SLdBJuD22ckBazyVVu22ZDA=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=qQyzVGscLZJgKaQSF29oPQFljaQ8sCx+Zq5794MBuB1+RYvHZlP1Zh+c0z/tjJbSvk6m9np2GKdTFaVuhMn8fv2Yr74R9vp6PgzMBA/cgzVk99sU/VMcPdoLAmsa40zoklpX8IXjVwqYaiORW2f1geA4QehNtKQXfIHGgWeUgx4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WTI29hSi; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40F1BC2BD10; Tue, 14 May 2024 16:33:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715704392; bh=2O3FVoVp95G4P4aUBtb5SLdBJuD22ckBazyVVu22ZDA=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=WTI29hSiyDCBZ/ISmRKtXANpO+MIhVZR4JWCVcJqN9/o+DiUQ5X0GEXAdrgRbrqyZ b+wMqcBFG+zX/Kql95Loc0oVKFWI3aDu/VsJ6sUjSCyxr34W2VMnjPBg7uvGlV/hZf 58sTwPUhjQ7JMumSjb2rr2cwE1QWDF6sGQYy+c8i5MpLLEcO/yEfjel9AzUt4f9Ndw iHHJc31d3f817J5K1WR8DjMU2QpBKILOiQ3F5iJ+kPtnSXMw28vI/Wyx4ymQyRvfsG S0fOOCFPj7SWbYL/SpOwoFMZPh2UYXNv3uMEs0lkKg9UHfVRQRY8cPajbAQF84TznI /HHuZ+HKrZCgw== From: =?utf-8?B?QmrDtnJuIFTDtnBlbA==?= To: Alexandre Ghiti Cc: Albert Ou , David Hildenbrand , Palmer Dabbelt , Paul Walmsley , linux-riscv@lists.infradead.org, =?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: Re: [PATCH v2 1/8] riscv: mm: Pre-allocate vmemmap/direct map PGD entries In-Reply-To: References: <20240514140446.538622-1-bjorn@kernel.org> <20240514140446.538622-2-bjorn@kernel.org> Date: Tue, 14 May 2024 18:33:09 +0200 Message-ID: <87wmnwtku2.fsf@all.your.base.are.belong.to.us> 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: quoted-printable Alexandre Ghiti writes: > Hi Bj=C3=B6rn, > > On Tue, May 14, 2024 at 4:05=E2=80=AFPM Bj=C3=B6rn T=C3=B6pel wrote: >> >> From: Bj=C3=B6rn T=C3=B6pel >> >> 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=C3=B6rn T=C3=B6pel >> --- >> 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/kas= an.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(u= nsigned 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, "dire= ct map"); >> + } >> } >> #endif >> -- >> 2.40.1 >> > > As you asked, with > https://lore.kernel.org/linux-riscv/20240514133614.87813-1-alexghiti@rivo= sinc.com/T/#u, > you will be able to remove the usage of KASAN_SHADOW_START. Very nice -- consistency! I'll need to respin, so I'll clean this up for the next version. > But anyhow, you can add: > > Reviewed-by: Alexandre Ghiti Thank you! Bj=C3=B6rn