Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp3022817lqo; Tue, 21 May 2024 04:49:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUJFuZ4tjhVLa85APFmL+p8v0NHjCb267trdBwVug2MrjZY50P3t8ZWr+WEtndsrOZoqblHZwvTkYfddZs++OaflG+z2WYc474/J9QMOg== X-Google-Smtp-Source: AGHT+IGIxgH4HPnumESHKbEm0sAFGPA36CM2OPKkexdhb43Az+6Omahhq34/3m/pFAHV8rAdDzAs X-Received: by 2002:a17:906:69cf:b0:a59:a356:3f6d with SMTP id a640c23a62f3a-a5a2d672c34mr2091210766b.54.1716292156269; Tue, 21 May 2024 04:49:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716292156; cv=pass; d=google.com; s=arc-20160816; b=HRNegnnXQqD3BNH2WZCkAql87PSLdfOU+kBCr2pmmboiyMhiiQpIxLzajsSUIAf5PO UhrBECAonxSG2UV/6e12Zx/UEVMsjiMsFmPPGnnQZ3fAxAG8hcJ51veX8nLHwo27WM5D EZX/AIOp72WjO9JuGJP0nmY4hbNmqDQj+ltAAcUhw0S/cJr296trmijXiGxdmWhTACdS O1WVxum24G1QpumatIQn9l499mMQVJDGOdb0GnLRmFBVJU+QqBuV1nwWgGr1VAhjTla+ w1+8sY22yi0x2c57KpT0BaqMQSwjBbqdYMlw0bUdJ+9ck9a79bGq2rBe4tbKrbQy7yCX 78gg== 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=DxS7gl1tG68/oOAo3eCp2XGdbHDrgigFYs+jMjpC2vw=; fh=/tocBNknTX0CBdcxdKGUdCq+MQUhEmbYJSr49AVQ1Gk=; b=FH0Fs1v7ngbvTzkglWelCHFiaCtUEBzSLKSq4AcaOZdq8i6llhLIbrZW107qkS72Rj RDmrCVhLuk+xnS0VGXbqycQ6+mJnvtsr1EaYGQJdlargphDlhBQ0vzH3fjNu37OE60gB 5nCmDSSsfVRAEW5wng1VC3vwlQyvAIBICCHdw1b1KP4tB/7+jeYI84Ut1NE4TABF0yFM g/FBa9WU8ZU5Ar4OmjtB7m4k5rh69wgzNiFjq1sRdyDYsv6iioP/aZGUFf7RdvTUL0o1 sWtwu7xMPRcLSeDAg4Emfc7Gn+NoFc4KCI4uGB0CDfWyYvBmV0jgXgPRfqCYEnTjKHDd Ve1w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=o5nLepXe; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-184898-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184898-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-a5a17ba55dfsi1401527366b.596.2024.05.21.04.49.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 04:49:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-184898-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=o5nLepXe; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-184898-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-184898-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 034411F234B8 for ; Tue, 21 May 2024 11:49:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9C33957318; Tue, 21 May 2024 11:48:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="o5nLepXe" 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 C82636CDAD for ; Tue, 21 May 2024 11:48:54 +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=1716292134; cv=none; b=ZGdiqfKQ4yKY2gLpegX2uA4bfKkF9gyJQUct00dEiwJ9JlPpLHqGEEUVCDh9aILftfleAeteFXqfTKMvCGmEP3PnY9LqtkaCFuIKLUBUT6lpMU0xcNai7mWQ70WFLv7Ty9o3JucIUnuEmD94GOXvJiWiwNfFNloaRFuIX90sq0Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716292134; c=relaxed/simple; bh=nfJcShROxet1Zcs9SjZc/rXdynjgyC+wVMctU8YOdM8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Q5Ci7UMQleHOgrsVkWKYr9r6perx2jFPYnOPmrrR3mEj8nx/jV5Hg12Eopo8EOZFRuxGo85bo4CFkiAgGRApdne5cBSUC1/qn4gXg76R/hu7JNSl7m/xV9HRIyJYUfY3q7ZaJQgbQ+eeSJt7LZxVCqNGouPbT6FnvP/cEKxfym0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=o5nLepXe; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1475C4AF09; Tue, 21 May 2024 11:48:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716292134; bh=nfJcShROxet1Zcs9SjZc/rXdynjgyC+wVMctU8YOdM8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o5nLepXejKU2VOMdC1SRZPZvOZANI4opdVRkd8+TPMDK5sR0P07NwX2ZJc79N4eQZ bfaqTkEl6t3lFSwKwGIAvi6aKuwLCtjqA4R28DwMCONu+LBEGDp5huVkPzSrGGxpd3 eAcze83sdvqq0s5ijrEJlIMQhBoRLsPinLO1fb+pp/i5dnM4oCQdFZahjroxJU+tqs ZfAsw+QYO295mUt8WJNF8A1EuNCBtYJdN32QaUsHu3K8cxyCjruvL8/XB8PAlIhEie b/8oz9DQETq8tgzZZdrqszIj0S0PXOjWIcDgLIx3Il4t+3513huBPyuUBrwrHotznV 5JmJyHV48MBQA== 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 v3 2/9] riscv: mm: Pre-allocate vmemmap/direct map PGD entries Date: Tue, 21 May 2024 13:48:23 +0200 Message-Id: <20240521114830.841660-3-bjorn@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240521114830.841660-1-bjorn@kernel.org> References: <20240521114830.841660-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. Reviewed-by: Alexandre Ghiti 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 b66f846e7634..c98010ede810 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