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 From patchwork Tue May 14 14:04:40 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: 13664170 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 7626CC25B75 for ; Tue, 14 May 2024 14:05:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 12D8A8D0024; Tue, 14 May 2024 10:05:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DD668D000D; Tue, 14 May 2024 10:05:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E232B8D0024; Tue, 14 May 2024 10:05:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B78CD8D000D for ; Tue, 14 May 2024 10:05:16 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 653B71611E5 for ; Tue, 14 May 2024 14:05:16 +0000 (UTC) X-FDA: 82117173432.21.FE9DB08 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf01.hostedemail.com (Postfix) with ESMTP id 884F34001D for ; Tue, 14 May 2024 14:05:14 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Um6pxZBb; spf=pass (imf01.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715695514; a=rsa-sha256; cv=none; b=atr2bc+cH9H7bkfmMvUOKWfL9wzSFOVsvfQM2vKTkWfDssgm5TSUSlr+U7E2AYQ64G1wiW STjFVQCEbDbuUPPakMwiF6UE/yOt9inlABcQQ0GH9/CQkw5NpxHXImI1Cf2B0NEwtMsp2s +zrNHkDKmG4vQK30juWy3aY7ZhkBmMk= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Um6pxZBb; spf=pass (imf01.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=1715695514; 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=0Oio/wtUWs+J7EH2oiE04eQUjTO43oml1tzH1K3UrX0=; b=U/4rF3rTsOuFbbsoJY+xMXLthdPlVrznoZeFQIIkmSDA3IArqD2QVXhxjbO32yd4ADsxHG I4ak2aC70CnHlUv3TaE0otezyzO7hIqncyjdgpNCyqmdAEG2ZAyyhvVAaCBoi0zMJArzCa 3ZXTRMcUE2LDX/Dmm0WE1hjJAOuE3TM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id BB79261263; Tue, 14 May 2024 14:05:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9ABF4C32782; Tue, 14 May 2024 14:05:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715695513; bh=TaDiQetQybqKd6ZxR/jcE5PkU8hQbMlo+vFY+ZDy3zE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Um6pxZBb03VIozcHaKKyM/e7rsrF2bB7BRxYDLJp7hWQla6fuSi8TPOnXKDNIPa56 DMA6SCQqLJvrf9NPtQQa3VDNIg3QbcaUzxenDWFXHcy7WZ+e9lijNqsV1qEuKedsCj fhMgKGD4nqxmx88Pdfkw7QlsmYYUk1nO9c47s/UIXGvNBuqd/42g3ZEPlTu0yF+Uhn BzU437TCi2CekrhYc2nT6ojxNdLYrUlwfGcJsofv+Rl8Qf8Q4BeOiRki3hU/ihNoo/ CQZHkziFcg/X+M1WW5G561IkP3VC6xbOqRHxvURTL4ZpvQyOc5rHaDhZt9wGsJy2hU g9z/70AL1e2Wg== 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 2/8] riscv: mm: Change attribute from __init to __meminit for page functions Date: Tue, 14 May 2024 16:04:40 +0200 Message-Id: <20240514140446.538622-3-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-Queue-Id: 884F34001D X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: an7u1heaf38ybjitxsaz17cb1zp6nww9 X-HE-Tag: 1715695514-801538 X-HE-Meta: U2FsdGVkX19N0YVNTLsjlUUjon0dmCd+kVgYb0cVRodB9ZURwe/+3M6v5qPzHt1pvmLGQOVgDa4S1Zond3DMN3S7ASHqcQjvXxP3R1rxtT8UBuqnu9uhHqhIDEY5OIZPbqmfkznnwfe3yyG6kyI7sPsZ8UQ6d2VYkeZRc5BLsjjlE4ywjaAI/fdhYVnKcZn3Cr2Vu0ys6fO1P8PxCuz6iXrV0aE57cQ3vJ139ZqcMqCsc1Yg8oG0R2Cn/c6GHHDRZ9S2w3dUKWfHrrfJ1/bLdnSsCtQ/W8ZdYdxVR7x2J4RxVFS3rNfZlqmfytoC5I38b1ChhzheJC5WXpfPFxb/YdnZCWoaZ3U0VvLeGvjqlDgXOSm8NB9LQTKO9Y3/6LOxQ+AVKkvHM/c6UiFTJT1fhBgaDV8/r63Sa5JvfCsjrvuRyUprWC5KIf50aqebaGsLThLtrnfgBdXJJQ6nbY/IcFGcvvmQQS9U4AFbSvNym89Dfbvw6dMik5mgvEATwAL9ft++IPSuSbXXDnwBnqi6qcvTWK0KXqdtmGd9I9FGse+NExuMIGPG9GcFcXPIOeASuaAV0KwX3mvVLvY1i79DooLFhlnz5leo85Wzjmwrrl54RhqGLgE0zF4u0K8JcOvf7RqwjSBZdibfSMvgi3Nn+6jBfIgU+AFRH1Wa+Fg5BYHfV+TTitAY0oX4AFA9Q2RG9VIOWcvmySieh7uosVBySD2yn3z7QJae+kCR9KzyU66Npw+kBw80sevSY6EyV6QW+guESPM7kw2dQL2ksvS1GA8z/bLIFh8/a7ifVrp5P+WzqlzNIOUluO1qRZJz/xJhNV93zc9HyI4yoqtMiEZrUvPexzicpAZJQc+xaGM7/nPN+mpAtc+KUPx2n6kUWaNOGTfzPv+SS5ye1sid5inH/EWz4n7KZKZBaDN4yo4xjh9f6Wxv9tLVUGZDDzZd4rNZHEh5Zx/wCVLMw2rSPOS F4bTzGY/ dAo1a3nj4fdeocn69hSUYh8Yc4/XJsIrJnQzJyqTH2Uww2rDpnvDkb4P5mn2dtN4Cb1uKajoL+YxzNVQSmMzjnty0UDAl9aMP+oc21DF4IdiLr90oQaX7S+wps47XQq2Ckmp/uMD1rSKNgsodruGRa2ItYiZmq0Q+wFCxd9MvSkd4ZHs5y8PJVYjVthMBo+f2ko6qW7huiY8YZCWl1R69eYGw72Immecw/8umMyDMN3wa7xDO3HDYImf12GFUOp9uyrXIllrTHYfbJhpBigL9yxLXF6H8RnAYxSTfvpgAKUjmhG+I2w96NWGovBt4y286tYTybvVL9oMlgQ4MRdI2jDUTM4xdnWe2obXGAfJ8+ZedFhc8oYHz859T0Gtm3iVCGt9UfNWD1wfTvHM= 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 Prepare for memory hotplugging support by changing from __init to __meminit for the page table functions that are used by the upcoming architecture specific callbacks. Changing the __init attribute to __meminit, avoids that the functions are removed after init. The __meminit attribute makes sure the functions are kept in the kernel text post init, but only if memory hotplugging is enabled for the build. Also, make sure that the altmap parameter is properly passed on to vmemmap_populate_hugepages(). Signed-off-by: Björn Töpel Reviewed-by: David Hildenbrand Reviewed-by: Oscar Salvador --- arch/riscv/include/asm/mmu.h | 4 +-- arch/riscv/include/asm/pgtable.h | 2 +- arch/riscv/mm/init.c | 58 ++++++++++++++------------------ 3 files changed, 29 insertions(+), 35 deletions(-) diff --git a/arch/riscv/include/asm/mmu.h b/arch/riscv/include/asm/mmu.h index 60be458e94da..c09c3c79f496 100644 --- a/arch/riscv/include/asm/mmu.h +++ b/arch/riscv/include/asm/mmu.h @@ -28,8 +28,8 @@ typedef struct { #endif } mm_context_t; -void __init create_pgd_mapping(pgd_t *pgdp, uintptr_t va, phys_addr_t pa, - phys_addr_t sz, pgprot_t prot); +void __meminit create_pgd_mapping(pgd_t *pgdp, uintptr_t va, phys_addr_t pa, phys_addr_t sz, + pgprot_t prot); #endif /* __ASSEMBLY__ */ #endif /* _ASM_RISCV_MMU_H */ diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 58fd7b70b903..7933f493db71 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -162,7 +162,7 @@ struct pt_alloc_ops { #endif }; -extern struct pt_alloc_ops pt_ops __initdata; +extern struct pt_alloc_ops pt_ops __meminitdata; #ifdef CONFIG_MMU /* Number of PGD entries that a user-mode program can use */ diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 5b8cdfafb52a..c969427eab88 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -295,7 +295,7 @@ static void __init setup_bootmem(void) } #ifdef CONFIG_MMU -struct pt_alloc_ops pt_ops __initdata; +struct pt_alloc_ops pt_ops __meminitdata; pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss; pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss; @@ -357,7 +357,7 @@ static inline pte_t *__init get_pte_virt_fixmap(phys_addr_t pa) return (pte_t *)set_fixmap_offset(FIX_PTE, pa); } -static inline pte_t *__init get_pte_virt_late(phys_addr_t pa) +static inline pte_t *__meminit get_pte_virt_late(phys_addr_t pa) { return (pte_t *) __va(pa); } @@ -376,7 +376,7 @@ static inline phys_addr_t __init alloc_pte_fixmap(uintptr_t va) return memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE); } -static phys_addr_t __init alloc_pte_late(uintptr_t va) +static phys_addr_t __meminit alloc_pte_late(uintptr_t va) { struct ptdesc *ptdesc = pagetable_alloc(GFP_KERNEL & ~__GFP_HIGHMEM, 0); @@ -384,9 +384,8 @@ static phys_addr_t __init alloc_pte_late(uintptr_t va) return __pa((pte_t *)ptdesc_address(ptdesc)); } -static void __init create_pte_mapping(pte_t *ptep, - uintptr_t va, phys_addr_t pa, - phys_addr_t sz, pgprot_t prot) +static void __meminit create_pte_mapping(pte_t *ptep, uintptr_t va, phys_addr_t pa, phys_addr_t sz, + pgprot_t prot) { uintptr_t pte_idx = pte_index(va); @@ -440,7 +439,7 @@ static pmd_t *__init get_pmd_virt_fixmap(phys_addr_t pa) return (pmd_t *)set_fixmap_offset(FIX_PMD, pa); } -static pmd_t *__init get_pmd_virt_late(phys_addr_t pa) +static pmd_t *__meminit get_pmd_virt_late(phys_addr_t pa) { return (pmd_t *) __va(pa); } @@ -457,7 +456,7 @@ static phys_addr_t __init alloc_pmd_fixmap(uintptr_t va) return memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE); } -static phys_addr_t __init alloc_pmd_late(uintptr_t va) +static phys_addr_t __meminit alloc_pmd_late(uintptr_t va) { struct ptdesc *ptdesc = pagetable_alloc(GFP_KERNEL & ~__GFP_HIGHMEM, 0); @@ -465,9 +464,9 @@ static phys_addr_t __init alloc_pmd_late(uintptr_t va) return __pa((pmd_t *)ptdesc_address(ptdesc)); } -static void __init create_pmd_mapping(pmd_t *pmdp, - uintptr_t va, phys_addr_t pa, - phys_addr_t sz, pgprot_t prot) +static void __meminit create_pmd_mapping(pmd_t *pmdp, + uintptr_t va, phys_addr_t pa, + phys_addr_t sz, pgprot_t prot) { pte_t *ptep; phys_addr_t pte_phys; @@ -503,7 +502,7 @@ static pud_t *__init get_pud_virt_fixmap(phys_addr_t pa) return (pud_t *)set_fixmap_offset(FIX_PUD, pa); } -static pud_t *__init get_pud_virt_late(phys_addr_t pa) +static pud_t *__meminit get_pud_virt_late(phys_addr_t pa) { return (pud_t *)__va(pa); } @@ -521,7 +520,7 @@ static phys_addr_t __init alloc_pud_fixmap(uintptr_t va) return memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE); } -static phys_addr_t alloc_pud_late(uintptr_t va) +static phys_addr_t __meminit alloc_pud_late(uintptr_t va) { unsigned long vaddr; @@ -541,7 +540,7 @@ static p4d_t *__init get_p4d_virt_fixmap(phys_addr_t pa) return (p4d_t *)set_fixmap_offset(FIX_P4D, pa); } -static p4d_t *__init get_p4d_virt_late(phys_addr_t pa) +static p4d_t *__meminit get_p4d_virt_late(phys_addr_t pa) { return (p4d_t *)__va(pa); } @@ -559,7 +558,7 @@ static phys_addr_t __init alloc_p4d_fixmap(uintptr_t va) return memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE); } -static phys_addr_t alloc_p4d_late(uintptr_t va) +static phys_addr_t __meminit alloc_p4d_late(uintptr_t va) { unsigned long vaddr; @@ -568,9 +567,8 @@ static phys_addr_t alloc_p4d_late(uintptr_t va) return __pa(vaddr); } -static void __init create_pud_mapping(pud_t *pudp, - uintptr_t va, phys_addr_t pa, - phys_addr_t sz, pgprot_t prot) +static void __meminit create_pud_mapping(pud_t *pudp, uintptr_t va, phys_addr_t pa, phys_addr_t sz, + pgprot_t prot) { pmd_t *nextp; phys_addr_t next_phys; @@ -595,9 +593,8 @@ static void __init create_pud_mapping(pud_t *pudp, create_pmd_mapping(nextp, va, pa, sz, prot); } -static void __init create_p4d_mapping(p4d_t *p4dp, - uintptr_t va, phys_addr_t pa, - phys_addr_t sz, pgprot_t prot) +static void __meminit create_p4d_mapping(p4d_t *p4dp, uintptr_t va, phys_addr_t pa, phys_addr_t sz, + pgprot_t prot) { pud_t *nextp; phys_addr_t next_phys; @@ -653,9 +650,8 @@ static void __init create_p4d_mapping(p4d_t *p4dp, #define create_pmd_mapping(__pmdp, __va, __pa, __sz, __prot) do {} while(0) #endif /* __PAGETABLE_PMD_FOLDED */ -void __init create_pgd_mapping(pgd_t *pgdp, - uintptr_t va, phys_addr_t pa, - phys_addr_t sz, pgprot_t prot) +void __meminit create_pgd_mapping(pgd_t *pgdp, uintptr_t va, phys_addr_t pa, phys_addr_t sz, + pgprot_t prot) { pgd_next_t *nextp; phys_addr_t next_phys; @@ -680,8 +676,7 @@ void __init create_pgd_mapping(pgd_t *pgdp, create_pgd_next_mapping(nextp, va, pa, sz, prot); } -static uintptr_t __init best_map_size(phys_addr_t pa, uintptr_t va, - phys_addr_t size) +static uintptr_t __meminit best_map_size(phys_addr_t pa, uintptr_t va, phys_addr_t size) { if (pgtable_l5_enabled && !(pa & (P4D_SIZE - 1)) && !(va & (P4D_SIZE - 1)) && size >= P4D_SIZE) @@ -714,7 +709,7 @@ asmlinkage void __init __copy_data(void) #endif #ifdef CONFIG_STRICT_KERNEL_RWX -static __init pgprot_t pgprot_from_va(uintptr_t va) +static __meminit pgprot_t pgprot_from_va(uintptr_t va) { if (is_va_kernel_text(va)) return PAGE_KERNEL_READ_EXEC; @@ -739,7 +734,7 @@ void mark_rodata_ro(void) set_memory_ro); } #else -static __init pgprot_t pgprot_from_va(uintptr_t va) +static __meminit pgprot_t pgprot_from_va(uintptr_t va) { if (IS_ENABLED(CONFIG_64BIT) && !is_kernel_mapping(va)) return PAGE_KERNEL; @@ -1231,9 +1226,8 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) pt_ops_set_fixmap(); } -static void __init create_linear_mapping_range(phys_addr_t start, - phys_addr_t end, - uintptr_t fixed_map_size) +static void __meminit create_linear_mapping_range(phys_addr_t start, phys_addr_t end, + uintptr_t fixed_map_size) { phys_addr_t pa; uintptr_t va, map_size; @@ -1435,7 +1429,7 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node, * memory hotplug, we are not able to update all the page tables with * the new PMDs. */ - return vmemmap_populate_hugepages(start, end, node, NULL); + return vmemmap_populate_hugepages(start, end, node, altmap); } #endif From patchwork Tue May 14 14:04:41 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: 13664171 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 D733CC04FFE for ; Tue, 14 May 2024 14:05:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 684698D0025; Tue, 14 May 2024 10:05:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 633AA8D000D; Tue, 14 May 2024 10:05:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 508548D0025; Tue, 14 May 2024 10:05:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 30F168D000D for ; Tue, 14 May 2024 10:05:21 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D10091A1218 for ; Tue, 14 May 2024 14:05:20 +0000 (UTC) X-FDA: 82117173600.28.AF99DA0 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf11.hostedemail.com (Postfix) with ESMTP id 2191240013 for ; Tue, 14 May 2024 14:05:18 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=tutFg42F; spf=pass (imf11.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715695519; a=rsa-sha256; cv=none; b=riRjGnd/DBnCsG0hlpkZAInC6V+2AiF5SdtAEbBxKlNdLJZm9McMHJtLq3aHwCd30t9Ygx b7+HpjTw0k07PrJL7rIJG2R/IddwbgerMgDkE2QsNuVLILGtPII6ek/pk6CQ8x6lfgQSMY WPm+u8HfAZl55Hox+jaqctcF9dmnlY4= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=tutFg42F; spf=pass (imf11.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=1715695519; 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=d96B3AWmv3rJbTmg3844gH356qrKf2Yi/vSAtG1DPGU=; b=H2BgvEkOhmQhTud2BYUk39mgiSzU8npiJOYNR40KcRmwzT2/LYs7jCJ/CRRa6tR4qT55lp FgK22PT123u3XS6WHELeOm9dEvDvUkYkf6UzfE8vBuqHstopgx0pXzo10WhVCZU8xZJm5V wJ4PlZf9p8reppznXfhmMmMQHwX0pCk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 3183261276; Tue, 14 May 2024 14:05:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B219C32781; Tue, 14 May 2024 14:05:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715695518; bh=pGRP84KXNHRvDwj4d3tBEvZ5yXWiOvKEJ5ie6tEwIpw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tutFg42F+WZxo8OqjmYracQbf76JUHyChIpewLcaBxxXzAHL9f9NzUzxKpCwPQPMp JAOf7a5DMjRYICN6Zd3nayVU2QucQqYBCAI8sN3NmvDZjznrg3QP+0FsKPkhBf5X1d DjQUz7i2J5ltDjh2koA8AsRmQ0kDN4rVWu0JQFdPf4Vmy6PaVJo12jabRGD99LsIn6 QsnhffWfY2J+BIqE97O1tmA6XlKvqzaJOazwfm63YK7bQUZNkTJ0dnTNMdXBkL3W1n IXNollIatVKhq1PFO/MKuIo9s9ffetE+5TaxWGUT6CgxwvGg7EYhSFKTurXIn/mT0T 2VnjGlsE++ceA== 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 3/8] riscv: mm: Refactor create_linear_mapping_range() for memory hot add Date: Tue, 14 May 2024 16:04:41 +0200 Message-Id: <20240514140446.538622-4-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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 2191240013 X-Stat-Signature: w913wyirjjnzeukhgtwky71moxrjezz3 X-HE-Tag: 1715695518-528934 X-HE-Meta: U2FsdGVkX1973WKnxKasRLaOpDPq6kt9lbNfajU5MrH73WBrI8BsEHuMt9stEXaBcUUV6Xvx6UCZ9T7ntbmnsG3VCGJcBhVoVSJpNWe3bvXy1rMZYFrMTS3ofU7uQlXhuUM8Y2QUJrOn9jQ/A0WqgXFbxw9c1CCrREGVPGfPv3NE10KU0Vh8pz2Ev56HFFQ9KQmaq/pzL4iOgRI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imWiz6Dn7DHqCu53vLFzc8WjMpNHu58ilMikDCGr5TpvnAsiuJdAUgmsWY5YbKyKIZhTGTzNmall/JDDmCK2UJSccS1VuaeIwYbQ9E= 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 Add a parameter to the direct map setup function, so it can be used in arch_add_memory() later. Signed-off-by: Björn Töpel Reviewed-by: David Hildenbrand Reviewed-by: Alexandre Ghiti Reviewed-by: Oscar Salvador --- arch/riscv/mm/init.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index c969427eab88..6f72b0b2b854 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -1227,7 +1227,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa) } static void __meminit create_linear_mapping_range(phys_addr_t start, phys_addr_t end, - uintptr_t fixed_map_size) + uintptr_t fixed_map_size, const pgprot_t *pgprot) { phys_addr_t pa; uintptr_t va, map_size; @@ -1238,7 +1238,7 @@ static void __meminit create_linear_mapping_range(phys_addr_t start, phys_addr_t best_map_size(pa, va, end - pa); create_pgd_mapping(swapper_pg_dir, va, pa, map_size, - pgprot_from_va(va)); + pgprot ? *pgprot : pgprot_from_va(va)); } } @@ -1282,22 +1282,19 @@ static void __init create_linear_mapping_page_table(void) if (end >= __pa(PAGE_OFFSET) + memory_limit) end = __pa(PAGE_OFFSET) + memory_limit; - create_linear_mapping_range(start, end, 0); + create_linear_mapping_range(start, end, 0, NULL); } #ifdef CONFIG_STRICT_KERNEL_RWX - create_linear_mapping_range(ktext_start, ktext_start + ktext_size, 0); - create_linear_mapping_range(krodata_start, - krodata_start + krodata_size, 0); + create_linear_mapping_range(ktext_start, ktext_start + ktext_size, 0, NULL); + create_linear_mapping_range(krodata_start, krodata_start + krodata_size, 0, NULL); memblock_clear_nomap(ktext_start, ktext_size); memblock_clear_nomap(krodata_start, krodata_size); #endif #ifdef CONFIG_KFENCE - create_linear_mapping_range(kfence_pool, - kfence_pool + KFENCE_POOL_SIZE, - PAGE_SIZE); + create_linear_mapping_range(kfence_pool, kfence_pool + KFENCE_POOL_SIZE, PAGE_SIZE, NULL); memblock_clear_nomap(kfence_pool, KFENCE_POOL_SIZE); #endif From patchwork Tue May 14 14:04:42 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: 13664173 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 C1B01C41513 for ; Tue, 14 May 2024 14:05:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 37E058D0027; Tue, 14 May 2024 10:05:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 303F08D000D; Tue, 14 May 2024 10:05:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E14A8D0027; Tue, 14 May 2024 10:05:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E2A2E8D000D for ; Tue, 14 May 2024 10:05:30 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5B62E1212E1 for ; Tue, 14 May 2024 14:05:30 +0000 (UTC) X-FDA: 82117174020.02.2DADAD0 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf23.hostedemail.com (Postfix) with ESMTP id EE5CB14001B for ; Tue, 14 May 2024 14:05:27 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=qJp+pNmr; spf=pass (imf23.hostedemail.com: domain of bjorn@kernel.org designates 145.40.73.55 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=1715695528; 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=snQ8OF9Bh0Qq0MwPYyH9pHa+yNSHDLOBvtngCsCLtug=; b=vBm361AHGcZZvg0Wg/iJoilysA2nPRfTW0hQk8PGiRW+9HFJWWh6A0g6Gq6MKv71n7yOHu nOmfQ7G3tUd246/dur6bX/xlOxj0McVXu7kuzG06PgVQIZ2lnmt6qEAElopENnuv00srep h9Ud0LX1rx9sNNbiRkt2t+d04qegaFs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715695528; a=rsa-sha256; cv=none; b=RKH43aRTo9yYFQzHy0hXOm2tJ8Ch7xIvSrixT5pEp6skli+kKQw7VjgY1oeL9+Q0qZtXWf D5qeHLFLFsEDYvtu57HpdGdgR37w+4QOy/0HXoGJFIPPBnHU9JEWmCsHdXUT8TSss/5s3P O2l5znGaxSQlEstEkPza/Ak/+tDwEqc= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=qJp+pNmr; spf=pass (imf23.hostedemail.com: domain of bjorn@kernel.org designates 145.40.73.55 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 sin.source.kernel.org (Postfix) with ESMTP id DA595CE1290; Tue, 14 May 2024 14:05:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71035C32782; Tue, 14 May 2024 14:05:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715695522; bh=KrXLi2kuhfXzcPr+BoNvWMq+KlIFOy4AuLG7kxwToYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qJp+pNmrnz2hVpw3ad/kdlC3wpDSy94U8cdclU7Y7AHoh1yrK5uwu7FPeuJrmjv8m DFM/uYWS2H44l8qKMC+uOJeRNLMQyPOGghW7IuFo7YZPggnkJxEh44Gg3ZQAQSFrSq QOe4J2HCtPFecfwfKl8+/b6GjnF90naa+RZ3qRbWrLNrrF6zi/rxpo62MieP1NpgDj 9JPmB0ipQUv3I+2c7oUx9omig2cfqp+yG7/qs+VfFFwgfBf3Xs4/2Q8xjmcxox33H0 LtH2mRL8D/SX2fgmIEwUvBMZVQOYb5npRRDc2cGRpvSqdVzBllfNTxAQ/SIeEm0mcd bkyQaYhcOsyPw== 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 4/8] riscv: mm: Add memory hotplugging support Date: Tue, 14 May 2024 16:04:42 +0200 Message-Id: <20240514140446.538622-5-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-Rspam-User: X-Stat-Signature: 9r85f5uzntmg51tp4abu3in1daubfk1b X-Rspamd-Server: rspam07 X-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qTIOVh6HSAmc3p0JZQqEDvqNrEOx2HfTALbBTs+gRjVQOhYMatDbjkKBnHb1C78b6UYjElqbTyA/xmILur7B7aZhvClmaBFqhl1Bn+JYRg0CFAuqXKsr5N0lrHePAQih54TKLdhXBAjjse+D22OvHLzebOo66AHxHxKjoFp5D4zjIEPvEefv7UkcG5WzQly2DeR2mS9OV3DWMx/meVe9LXBzIAxr8HSew+Dzi/wVEPx2JiOWJ9HuVp7xbyL1yocqNpnI922ezdgY9dEA/cBocy6CRVstRg4hD4f9k/MFsOzBCkHejowe9Xw== 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 For an architecture to support memory hotplugging, a couple of callbacks needs to be implemented: arch_add_memory() This callback is responsible for adding the physical memory into the direct map, and call into the memory hotplugging generic code via __add_pages() that adds the corresponding struct page entries, and updates the vmemmap mapping. arch_remove_memory() This is the inverse of the callback above. vmemmap_free() This function tears down the vmemmap mappings (if CONFIG_SPARSEMEM_VMEMMAP is enabled), and also deallocates the backing vmemmap pages. Note that for persistent memory, an alternative allocator for the backing pages can be used; The vmem_altmap. This means that when the backing pages are cleared, extra care is needed so that the correct deallocation method is used. arch_get_mappable_range() This functions returns the PA range that the direct map can map. Used by the MHP internals for sanity checks. The page table unmap/teardown functions are heavily based on code from the x86 tree. The same remove_pgd_mapping() function is used in both vmemmap_free() and arch_remove_memory(), but in the latter function the backing pages are not removed. Signed-off-by: Björn Töpel --- arch/riscv/mm/init.c | 242 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 242 insertions(+) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 6f72b0b2b854..7f0b921a3d3a 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -1493,3 +1493,245 @@ void __init pgtable_cache_init(void) } } #endif + +#ifdef CONFIG_MEMORY_HOTPLUG +static void __meminit free_pte_table(pte_t *pte_start, pmd_t *pmd) +{ + pte_t *pte; + int i; + + for (i = 0; i < PTRS_PER_PTE; i++) { + pte = pte_start + i; + if (!pte_none(*pte)) + return; + } + + free_pages((unsigned long)page_address(pmd_page(*pmd)), 0); + pmd_clear(pmd); +} + +static void __meminit free_pmd_table(pmd_t *pmd_start, pud_t *pud) +{ + pmd_t *pmd; + int i; + + for (i = 0; i < PTRS_PER_PMD; i++) { + pmd = pmd_start + i; + if (!pmd_none(*pmd)) + return; + } + + free_pages((unsigned long)page_address(pud_page(*pud)), 0); + pud_clear(pud); +} + +static void __meminit free_pud_table(pud_t *pud_start, p4d_t *p4d) +{ + pud_t *pud; + int i; + + for (i = 0; i < PTRS_PER_PUD; i++) { + pud = pud_start + i; + if (!pud_none(*pud)) + return; + } + + free_pages((unsigned long)page_address(p4d_page(*p4d)), 0); + p4d_clear(p4d); +} + +static void __meminit free_vmemmap_storage(struct page *page, size_t size, + struct vmem_altmap *altmap) +{ + if (altmap) + vmem_altmap_free(altmap, size >> PAGE_SHIFT); + else + free_pages((unsigned long)page_address(page), get_order(size)); +} + +static void __meminit remove_pte_mapping(pte_t *pte_base, unsigned long addr, unsigned long end, + bool is_vmemmap, struct vmem_altmap *altmap) +{ + unsigned long next; + pte_t *ptep, pte; + + for (; addr < end; addr = next) { + next = (addr + PAGE_SIZE) & PAGE_MASK; + if (next > end) + next = end; + + ptep = pte_base + pte_index(addr); + pte = READ_ONCE(*ptep); + + if (!pte_present(*ptep)) + continue; + + pte_clear(&init_mm, addr, ptep); + if (is_vmemmap) + free_vmemmap_storage(pte_page(pte), PAGE_SIZE, altmap); + } +} + +static void __meminit remove_pmd_mapping(pmd_t *pmd_base, unsigned long addr, unsigned long end, + bool is_vmemmap, struct vmem_altmap *altmap) +{ + unsigned long next; + pte_t *pte_base; + pmd_t *pmdp, pmd; + + for (; addr < end; addr = next) { + next = pmd_addr_end(addr, end); + pmdp = pmd_base + pmd_index(addr); + pmd = READ_ONCE(*pmdp); + + if (!pmd_present(pmd)) + continue; + + if (pmd_leaf(pmd)) { + pmd_clear(pmdp); + if (is_vmemmap) + free_vmemmap_storage(pmd_page(pmd), PMD_SIZE, altmap); + continue; + } + + pte_base = (pte_t *)pmd_page_vaddr(*pmdp); + remove_pte_mapping(pte_base, addr, next, is_vmemmap, altmap); + free_pte_table(pte_base, pmdp); + } +} + +static void __meminit remove_pud_mapping(pud_t *pud_base, unsigned long addr, unsigned long end, + bool is_vmemmap, struct vmem_altmap *altmap) +{ + unsigned long next; + pud_t *pudp, pud; + pmd_t *pmd_base; + + for (; addr < end; addr = next) { + next = pud_addr_end(addr, end); + pudp = pud_base + pud_index(addr); + pud = READ_ONCE(*pudp); + + if (!pud_present(pud)) + continue; + + if (pud_leaf(pud)) { + if (pgtable_l4_enabled) { + pud_clear(pudp); + if (is_vmemmap) + free_vmemmap_storage(pud_page(pud), PUD_SIZE, altmap); + } + continue; + } + + pmd_base = pmd_offset(pudp, 0); + remove_pmd_mapping(pmd_base, addr, next, is_vmemmap, altmap); + + if (pgtable_l4_enabled) + free_pmd_table(pmd_base, pudp); + } +} + +static void __meminit remove_p4d_mapping(p4d_t *p4d_base, unsigned long addr, unsigned long end, + bool is_vmemmap, struct vmem_altmap *altmap) +{ + unsigned long next; + p4d_t *p4dp, p4d; + pud_t *pud_base; + + for (; addr < end; addr = next) { + next = p4d_addr_end(addr, end); + p4dp = p4d_base + p4d_index(addr); + p4d = READ_ONCE(*p4dp); + + if (!p4d_present(p4d)) + continue; + + if (p4d_leaf(p4d)) { + if (pgtable_l5_enabled) { + p4d_clear(p4dp); + if (is_vmemmap) + free_vmemmap_storage(p4d_page(p4d), P4D_SIZE, altmap); + } + continue; + } + + pud_base = pud_offset(p4dp, 0); + remove_pud_mapping(pud_base, addr, next, is_vmemmap, altmap); + + if (pgtable_l5_enabled) + free_pud_table(pud_base, p4dp); + } +} + +static void __meminit remove_pgd_mapping(unsigned long va, unsigned long end, bool is_vmemmap, + struct vmem_altmap *altmap) +{ + unsigned long addr, next; + p4d_t *p4d_base; + pgd_t *pgd; + + for (addr = va; addr < end; addr = next) { + next = pgd_addr_end(addr, end); + pgd = pgd_offset_k(addr); + + if (!pgd_present(*pgd)) + continue; + + if (pgd_leaf(*pgd)) + continue; + + p4d_base = p4d_offset(pgd, 0); + remove_p4d_mapping(p4d_base, addr, next, is_vmemmap, altmap); + } + + flush_tlb_all(); +} + +static void __meminit remove_linear_mapping(phys_addr_t start, u64 size) +{ + unsigned long va = (unsigned long)__va(start); + unsigned long end = (unsigned long)__va(start + size); + + remove_pgd_mapping(va, end, false, NULL); +} + +struct range arch_get_mappable_range(void) +{ + struct range mhp_range; + + mhp_range.start = __pa(PAGE_OFFSET); + mhp_range.end = __pa(PAGE_END - 1); + return mhp_range; +} + +int __ref arch_add_memory(int nid, u64 start, u64 size, struct mhp_params *params) +{ + int ret; + + create_linear_mapping_range(start, start + size, 0, ¶ms->pgprot); + flush_tlb_all(); + ret = __add_pages(nid, start >> PAGE_SHIFT, size >> PAGE_SHIFT, params); + if (ret) { + remove_linear_mapping(start, size); + return ret; + } + + max_pfn = PFN_UP(start + size); + max_low_pfn = max_pfn; + return 0; +} + +void __ref arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap) +{ + __remove_pages(start >> PAGE_SHIFT, size >> PAGE_SHIFT, altmap); + remove_linear_mapping(start, size); +} + +#ifdef CONFIG_SPARSEMEM_VMEMMAP +void __ref vmemmap_free(unsigned long start, unsigned long end, struct vmem_altmap *altmap) +{ + remove_pgd_mapping(start, end, true, altmap); +} +#endif /* CONFIG_SPARSEMEM_VMEMMAP */ +#endif /* CONFIG_MEMORY_HOTPLUG */ From patchwork Tue May 14 14:04:43 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: 13664172 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 CBE61C25B75 for ; Tue, 14 May 2024 14:05:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 60EF78D0026; Tue, 14 May 2024 10:05:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 597BC8D000D; Tue, 14 May 2024 10:05:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 460558D0026; Tue, 14 May 2024 10:05:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 27C0B8D000D for ; Tue, 14 May 2024 10:05:30 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D2FDA812A0 for ; Tue, 14 May 2024 14:05:29 +0000 (UTC) X-FDA: 82117173978.19.6FBE3A6 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf27.hostedemail.com (Postfix) with ESMTP id ADA9F40032 for ; Tue, 14 May 2024 14:05:27 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AnRBLrwi; spf=pass (imf27.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=1715695527; 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=HmEirQnD2a44bOYNrbhBt5+emQXsA+YdRl4voQyD5Ms=; b=1L12z2WPc86VuJztTzbsCYwieeV2iGSZ4EAj4cDgSxnP0zVhPZA3EDBd8LdCooU/VGrqIe MHjcENOYhuaHJtSEUcQHBLmZrb/6mzg/Z3qmkbfeW41iNZrfduapSyWEZBoJharZyb8102 EA+AmYbQyccg+PAGVhaINTeHgFOEZyA= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AnRBLrwi; spf=pass (imf27.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715695527; a=rsa-sha256; cv=none; b=LH6rdSaF6KON/e/CXgSQ1BekxO9XYTMIersLEi8CnsCwlyxZpxEi7hVzsU8m0DrPQNX7vQ q4g5ce9BjSzy33LidX7FjaghqAp25xsNZoFJLkvDyLHXNhP0koPvN8pGObfWsVM7TcU0/W 3+XNPB3FOYB93/cFJ14kT4y8+rcqP20= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id BC7816126C; Tue, 14 May 2024 14:05:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3894C32781; Tue, 14 May 2024 14:05:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715695526; bh=KbKqzNvXWA/Za9nd3AYnat1xf+LOO0b3PgRZV0HvyKk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AnRBLrwiGydV55YKVxP1C2hTU/+iQo4dd8w0faa4jtVHR4jHZ5anUbKb5yZ5ye3XS ys1kla9pYrDzdZbLunoTrtdPNqqAUbKtu1CJ//68MFbQyh5y7aZhC46YK55JtaUZA5 ra5G2sERmBqf/UFx2SPaMVXfoiGS2kPxfZFkZNOUlVD19QOqS/SUV5MZU/mFGOVgDv IXn6OG9dtirrJO/Dh3vnNlqnjzdI4qDmljqWq0kBU+c0CiDbOdoWE/pFltLXqLokVT r19LtiBw6rEEkbg+nNadg08rNjWgfdZZVOpJ69iuykQqloruiT2sEewRtB7kCuWmPz qDl5PWv830HDA== 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 5/8] riscv: mm: Take memory hotplug read-lock during kernel page table dump Date: Tue, 14 May 2024 16:04:43 +0200 Message-Id: <20240514140446.538622-6-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-Stat-Signature: uitxj6bb6y7pn9rhcfs5er7oojsqtb1r X-Rspamd-Queue-Id: ADA9F40032 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1715695527-836127 X-HE-Meta: U2FsdGVkX1/GgYnB7UdzCHm0O2g+ceKGaofahNBrcnPUfQRDKEnA+5woAcy4rrJvMzsdj4IC5q8/lCMvTb0am/+d1T0PZRWAyLCDsdEriBXAiWDfhtWndgYk0Kh0nT5M4nPXrOQANgcniK9i1yiL8ei3vo3vB26Ee4SmC+kq3BT5HHRwUPs9SVzIJyZbc93gQfOD/Fj2id/1PfvFwgf4DmJfjzAAJz265yT7OiJvCDxkWEgIedzBsdqjTnufq8MNJbk9hyF/Qb05ug4/Tm9qIiksunG2bT8nZ3MSxmPIb4g25uri+MykhkVX6vmqLsvRheOBgEa3B2MwP6N6Be9VWKb+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: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Björn Töpel During memory hot remove, the ptdump functionality can end up touching stale data. Avoid any potential crashes (or worse), by holding the memory hotplug read-lock while traversing the page table. This change is analogous to arm64's commit bf2b59f60ee1 ("arm64/mm: Hold memory hotplug lock while walking for kernel page table dump"). Signed-off-by: Björn Töpel Reviewed-by: David Hildenbrand Reviewed-by: Oscar Salvador --- arch/riscv/mm/ptdump.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/riscv/mm/ptdump.c b/arch/riscv/mm/ptdump.c index 1289cc6d3700..9d5f657a251b 100644 --- a/arch/riscv/mm/ptdump.c +++ b/arch/riscv/mm/ptdump.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -370,7 +371,9 @@ bool ptdump_check_wx(void) static int ptdump_show(struct seq_file *m, void *v) { + get_online_mems(); ptdump_walk(m, m->private); + put_online_mems(); return 0; } From patchwork Tue May 14 14:04:44 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: 13664175 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 14132C25B75 for ; Tue, 14 May 2024 14:05:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF1BA6B0145; Tue, 14 May 2024 10:05:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A78C98D000D; Tue, 14 May 2024 10:05:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8CD796B0149; Tue, 14 May 2024 10:05:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6930E6B0145 for ; Tue, 14 May 2024 10:05:40 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C9E814121B for ; Tue, 14 May 2024 14:05:39 +0000 (UTC) X-FDA: 82117174398.25.40FCD06 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf14.hostedemail.com (Postfix) with ESMTP id 95EE5100017 for ; Tue, 14 May 2024 14:05:37 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="T0t8ZY/k"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf14.hostedemail.com: domain of bjorn@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=bjorn@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715695538; 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=/56fCBGstP/3s2ip8CZfHqAcktkqIv0lnVUx5MFhgcc=; b=4xBjXZM2dyXw8U5YDIEvlqsImOCF3IQ9FQnvCze4Drs+0sXWC6Q0J9KaQeFbvq7dNd6VMw tHp1o8IMkeR4wlNAJOXEQbEsMj/c+70ePrjfwKsCwJy3G5QLj8lLA3+KFo+l4cZMTgnR2D 7rU74pQwjiSaVU4QF2gYf1xuD2K3BqU= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="T0t8ZY/k"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf14.hostedemail.com: domain of bjorn@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=bjorn@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715695538; a=rsa-sha256; cv=none; b=1CItefGTUbwril3K0E4LwisnmTn+Ad7hoEAuAKZ0PWEubB3BHC+WEJdWJQG/Av10g5FsO5 3RwE+tJyPNxdDggei9xky8LNXKosEUoRjuRKRgyB4rNoIQBzYJ9v1z8/ovN7afmmTK9S70 gTKoRuLDmSZyD/CVz4SrziigsLGgPiY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id B05FBCE127B; Tue, 14 May 2024 14:05:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07D16C32781; Tue, 14 May 2024 14:05:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715695531; bh=0+IP68HpeOuix87ttHx6QCBPaROV37lTjVVbI88agM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T0t8ZY/krMImQEE1pbX37Lqd9otojKaCNU52Jdf+6IsnQPuwbjYf/17i4Dfm9wU/N cG8ZVIKuEChYfl+ArN6nlpcBLN94ethBeWZaRLHF2O26wOR/YjsM4iypPJlep2EOIs WnQduiMtRTX6HihYJYNGu+Zvx4ZfY6kifpj7mrb3c0qzOXrMObRZ+pyv1Di+53Y4BR yVzogJGugSULHDBgRoPYVq0AQf3NMvV11V+DCtVicxdz9nCIPrBc3BZjkQibvEOlkP LsDeyAlUKQ2u6jbtG/qyTzE50IDMatmyZSG5pDBfnCFVFZOhVoq3W+Su/3lVcXaMJx OvCy8N0USQs3Q== 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 6/8] riscv: Enable memory hotplugging for RISC-V Date: Tue, 14 May 2024 16:04:44 +0200 Message-Id: <20240514140446.538622-7-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-Queue-Id: 95EE5100017 X-Stat-Signature: j6xos8nco8khoogerc36f7z9h9yufkx4 X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1715695537-628311 X-HE-Meta: U2FsdGVkX1/34YcPBGrO6IOEqhByGIWZpIFg1ILoA1FpcZFAsW5YsyPyaoG50KpJ2L7bDOZXUqXbx1ITxbFhUkZiimVFFHmoMwpTCzOlaU51HcWqEhtAb4CP6Bu+aIQKJU+sjj9IcjWMKauhD8zgG1g+8l9YDJfM51Tqd1/gKeqQstrNbcMcoQg2j+dgeDrbEvT3lOkB56MzboVG6h3EdWoWPDYJbh252bqxfghhvLsuTS27fCLccCnpoEHXPqSmRy0q3lQ+yEx+XJHMvtNEzWfXtuctczDVXdLROSac8wZVUwqldYp9pqckFSOoyNtIfD7tC5xc1mbLnv06NnujQeJWpDFoWr5XO3IKcygAXWvXqWU5sh5JgOowK/Gn7dFs3ymiBGtR6F3GUMZxpIqf1Gh2xniDh2bJcOD48g74nhSTojQsNPadvaXoxcSR03/0iEjLpJ1yebTBY8we1uLz//Np8GND6yUvtGpt3ONCcjj4237Dxb13p0UHIvXdOr8lwX8Z4uPc17vRiXYfuo/p5b4dyY35EHnq7cpwaTp8DMCPwiT4b/EWLdvtQ5991IUWcMVeWWR9hflStgCCoIvAZgHBJZeKzi2JH2W6X2IbuhtI2FiQZpLqAbMwjMNlPftV3GNrDlkVxZm/+C47U7NHHSPRpMtZlI4gx11VCfahPkwc/sCvpbcjOmHyyuBengL3kzA0UPM+rfxk8KQTc203bp3fmFPyo0aCw25zpTK2OTOvj+KBW8lIPB0QOx+NDai+664QBQIi4xwEcaygkVJFKoy7g2MHr0frYnDThKBVzpMLGhNOHxYJKWReC2d3VWC3GfdWg2KzZ7GKgYlwBSg5QGpf05LwpZIIcWCG2zb6NW9YA9s/rJEqeQ6pFncsqa4DLleR9a0adZZpdQxtDjBZ/Zdvg8Xj4EgSP/DJWwvEWpQ4/F2m53o2oFm+zVzP/B0tzuycn/av+rE5mR8wJFN 08dA46no LsKCEAdPuTFMRkPIw78jbEnmtFBJHGVOKenKdifLKEDnEu2kyPfef6lbHcEovPmlI6VciweLfh65ypbbjtfLmxhcKgRC3h+Mh4wiDxrMHNjcGsPs2TYzZZMdl4tLvzugNP3gqbnR0DIkNG6ljMgHUw9xSs/63eCpHKYd+ygSIAR+2IDVWReK6bOIk97TKuAEv6yZnv2BX2UDL7L0siqRD7+abCm5AEnFYqUe5iQGBj+yY32nS5mOGZuUlHIvigpRCeh4WBemevLmmunw3n7BbSHy3JyKopokIBtR/o/Aw33jvhVPyTh+0BuZPhliHDDKk3l8fc9PQ9w2ZoD1gnZYTZ69oIAj3DRvoY4SF 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 Enable ARCH_ENABLE_MEMORY_HOTPLUG and ARCH_ENABLE_MEMORY_HOTREMOVE for RISC-V. Signed-off-by: Björn Töpel --- arch/riscv/Kconfig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 6bec1bce6586..b9398b64bb69 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -16,6 +16,8 @@ config RISCV select ACPI_REDUCED_HARDWARE_ONLY if ACPI select ARCH_DMA_DEFAULT_COHERENT select ARCH_ENABLE_HUGEPAGE_MIGRATION if HUGETLB_PAGE && MIGRATION + select ARCH_ENABLE_MEMORY_HOTPLUG if SPARSEMEM && 64BIT && MMU + select ARCH_ENABLE_MEMORY_HOTREMOVE if MEMORY_HOTPLUG select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2 select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE select ARCH_HAS_BINFMT_FLAT From patchwork Tue May 14 14:04:45 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: 13664174 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 E0523C04FFE for ; Tue, 14 May 2024 14:05:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 79B556B0141; Tue, 14 May 2024 10:05:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7465D6B0145; Tue, 14 May 2024 10:05:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60E766B0143; Tue, 14 May 2024 10:05:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3F06C6B0137 for ; Tue, 14 May 2024 10:05:39 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1E0E91A11E9 for ; Tue, 14 May 2024 14:05:38 +0000 (UTC) X-FDA: 82117174356.23.E60FDF4 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id 6DBCF1A002A for ; Tue, 14 May 2024 14:05:36 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CLn+SxlD; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of bjorn@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=bjorn@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1715695536; 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=JbHZnw7PFA0FUbdb+xKg+2Zte+grzzf1tk9742U3SdA=; b=C+f9LRt5ddL76Qwabb7vhLPKE6/Up8ZyziwyfcFVSMq+1YjvtSMbzgKFD7aM8308+Hb71T YvLtiOh0kAXtd8IhOCxvmLlSsf9L9JgWt4rEvxSHLP9RzdrjPV/Iu4I4GqdRZ1Icc0pabG uMf6dt/PBIoGur5lBqMH+zJU+b0Vsfg= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=CLn+SxlD; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of bjorn@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=bjorn@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715695536; a=rsa-sha256; cv=none; b=Q0Ht0SvOcc0K0+twfDGfsVXu/eYX9fWHb5rlvps7yMd5cV2j8IA95KcS1A5xVi8rtS0EB9 CNUeDw3k9c9PRN63SwFZGlxaZjpKy3iYENDE5cLgATdeefM8czq2EI+DJBeLLgLfXuesFK ywB1++ftTpBS5tu8cHttiJp3QMx4Ums= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id AA8446125F; Tue, 14 May 2024 14:05:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83515C4AF08; Tue, 14 May 2024 14:05:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715695535; bh=QKyUQtzdUFj7E7VWNazUrxKopSKCrJnxnXXoOO9I0K8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CLn+SxlD8a96Vi/A8lM2sysKVhH0gslhMRcG6/RFuCTRCj2QJXz/7tp2j4DwGGwTh 3s6+5SUO1nIjpJAF+WtJvgA5aYItK96Sb3keVQ5qAfR9fAiDhQy59AoJmhOA2XrWK0 ayQTEDyQFC54D6M7YKYx+IH/4KGsZRVrjgQhbTKhXcfDLpAlCxTd0vf7jvzMqhg10D FNo9crb1rFcLhNsxwlSJXLQJLbLFUx+Vn0fV6a2SnBO6Ql/K2f7S+Cub2+7EHXyNVt uL67hybo+QeRgGEosWl6aS/r8OQD0+M4q/Pkdwp8hNvF8RE8kn0rk6udwYclskf6Ei XJ5CR8WHHNG4w== 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 7/8] virtio-mem: Enable virtio-mem for RISC-V Date: Tue, 14 May 2024 16:04:45 +0200 Message-Id: <20240514140446.538622-8-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-Queue-Id: 6DBCF1A002A X-Stat-Signature: ffipybx8o576qw89apt1r883q35cfphh X-Rspam-User: X-Rspamd-Server: rspam11 X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Bji9zLGUMmhXI3WKRpeka7bE2WGZDU65QFtmlydNtwXNNHSB+68YLa3ZhewlFu2iuJTn7OHUGidfqPkFanrmh0WGnaybJOcag2NEmkmtUE0Vi9aMumx5OJcKK8JWwI53FuUp1+cwFGcIyh/Vh+jxyMlUf7utQIIP6JQK9OmZSKntyOuJy+/4bwucd0niS1h48TmoC60PwnuylPZgTolAKlQlSkWWtcetBvMHHn97VRtX9LSZf27fwuSiVVKT7f0Tn5ZlqojEp4Nclhr/rdG7YZscQgEK4F3r1fd09 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 Now that RISC-V has memory hotplugging support, virtio-mem can be used on the platform. Signed-off-by: Björn Töpel Acked-by: David Hildenbrand --- drivers/virtio/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig index c17193544268..4e5cebf1b82a 100644 --- a/drivers/virtio/Kconfig +++ b/drivers/virtio/Kconfig @@ -122,7 +122,7 @@ config VIRTIO_BALLOON config VIRTIO_MEM tristate "Virtio mem driver" - depends on X86_64 || ARM64 + depends on X86_64 || ARM64 || RISCV depends on VIRTIO depends on MEMORY_HOTPLUG depends on MEMORY_HOTREMOVE From patchwork Tue May 14 14:04:46 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: 13664176 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 E6954C04FFE for ; Tue, 14 May 2024 14:05:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17D9A6B0149; Tue, 14 May 2024 10:05:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 12FFF6B014B; Tue, 14 May 2024 10:05:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9C2E6B014C; Tue, 14 May 2024 10:05:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C26B96B0149 for ; Tue, 14 May 2024 10:05:42 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3B9361C0AA6 for ; Tue, 14 May 2024 14:05:42 +0000 (UTC) X-FDA: 82117174524.30.A1EB7BF Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf09.hostedemail.com (Postfix) with ESMTP id 7E73C14003F for ; Tue, 14 May 2024 14:05:40 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DocwhOPM; spf=pass (imf09.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=1715695540; 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=lwVEAOz0NyD/sQaWGzFjQscH92aI1v23LVpziabaD9g=; b=2CsX9pV6lQUmr91LT+52vh9t4fFILRiW1PxVjX07GBw+axk/HGd36PJaBYHWjoeo46EVKi 1seAeEsaJdO6slUhQLTkHY26D1rwjO1ZQqXoRnRjsyhmFi59JE5AzubRymxj4qdByitkIc FrKUmYhFVeju+ntbZzTaZOF7j9FoqKo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1715695540; a=rsa-sha256; cv=none; b=MhUuXwqas3vXTRUSttmEoMNZ8whTL+po8qCRi6LMrYW99euVIUgoRaP+JpHYais8qgMVRy JhEcn8o+JOpSVhW5X6feY/j0viKmE6lFVjbvD8DTLotBuU3nkVWLX6p2f2rF8HYih1v0P2 WCPl/I7RXGj8rNOKJr7v0AKoZsCDHOw= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DocwhOPM; spf=pass (imf09.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 C6ECE61277; Tue, 14 May 2024 14:05:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7AD3C32782; Tue, 14 May 2024 14:05:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715695539; bh=ID0c8KED4MaRAhJEPecqve06L1MFkX8CguX3Z8emb34=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DocwhOPMzvezJPtOLEyIs2TIRSDK1iKYiQIktTqvDEydUXhzyMFEVIe4w7rEBUoLH s1Aip/eIuRLs0LXxRO2MMKQduZjZ4DBOo06roaRsDYMD4/V0p/WrJ1lfcdUWNFUWwn ODSRdACvCftCwaJk1JNzfbi3KPDD6bOSxG75Dty41GwFFUJmy5m2JNOYIkDK9lRWK4 +67Ojs55jbeazXTVY+CfQswUJQMXyrqtCucl7p6pKvQpAHUytS7hU/8LLSnmhoiUR/ 8vk20MjslNrDRrN0YMhL+gaxgJaWiumVfcpTRg8PMQDoBY6o9yqd75mDcjXratHavn aZt3F8dpoR/bA== 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 8/8] riscv: mm: Add support for ZONE_DEVICE Date: Tue, 14 May 2024 16:04:46 +0200 Message-Id: <20240514140446.538622-9-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-Rspam-User: X-Stat-Signature: w5uwwuepxtcsu5nkzixt19fp6wcktbax X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7E73C14003F X-HE-Tag: 1715695540-350485 X-HE-Meta: U2FsdGVkX19eA0pTKBX5ZnNT6rIXpXjVvoSXSfKpRsmyiO9/87HLUbBZdBtnyZKYBd9DRn822aoXhW+KeMq2r4vsHA+hOu/Q07/YKKjv8/KPV8zZW9YJ4CdsTG4yxfp2VOW3wKmLqeFgxbIbi2jOOkqlx7r/kmTNBIxEPEz40qseIX5kFz0V7bp1/I+lM6j6Jaxm3XaI/Ae7x8DWbUcYCQBHOI6jKOFTpYVjp3g/ohsTFQ4PnBehwGHf1D5aBNKCNZinNmyky1h4+ltFCaw1C0UcAREweDipF/wfd1VlVluCYxeNpCTuVrlSI2zoY99EwejhVsf6mtKVeSL1ffvOQ5UAc2ZGzwbKJtdiQXH5WsxQvx934yVbFWliogqLVL7Tqishp5NyCPuqTMjoRD7XQRyK9KkIYvP/M2iRIMUDbaqJbHq9/HpIWM1KZnin2D3EKETTgJWPaVH5LtPP/0zmlgliEIEaLrcKIUEZL/Jj9BuIxCfF7HsJTiheYzg5mtxvayTXnmZDgqlj3RLsQNPXrjrdrFrQ/radhBKuFeDslznbiUFdjYpksmkz4BsweXU82/URl2Hy+1eefhfEagQ2OZeSMtimAi65Td+c3V6kKvQVyK5Kb1y1TN1/xc8iHM5jnogQjyrzdc1xcUnvufjSJV9lUlLMb7fxJ+ZV6upOTCTyUnEzVHXUjMKyofnR6HaucBMOd8afvUEcGKSJ4vOJE0PS67gfL+Ri8Tb1B7axOTzPIvw4BwnKRzKURS48s1+tVlFQ1QX+QjtVRQKOnJzT3v6t8PG5RccOlWkufkWIeQaTgoIDVS782lCN/1Mg/5z/19tmZgAmSrYFKixBveNfkZWBdx6COvi6NmjZcnjXks1Jsh91Rwdbem7HIGx9IXdotgiEZdq6MiM3H/RsOGJ5ZAG0UJB2eeQTXTmwt1TZ3l01F0Vexly+u85zK6HyfrEOtz45JeJNGEhwulU535f d48sVtEM tYf7sNoJwxcf2vJVyz7Heeme0t7DSZyXfosUXKPWObrEZhSTOeeBSggPU7mnL0UfCS5xWCqp5g0Kxf+9rCsNUK5scTMtbohZdqd02ide0j2pcps3vrmQU/Eqi/N+sSc9cquYGPNhd4tXFoRBw4anqx9gWuf4rlfNuNkmeEBkn3LtmtXmU5mytUdcuQnXGhNhV6L0Zdz4hqGidJGE/KgVz7u24KYeJParifWbXdfyJnmy61TXNokJA877YFGzvNmCNxciRAiQb9jzCpGZn6lQQ8aMawgapM/t4Gjkg3GKdq0wUTmpVchUTZVysZWlNx1B2G39Rv021945X5KxeUJEYEp6w3lyFQPe3ld89VWYEGUpKZ05S2WjaH7fxNA== 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 ZONE_DEVICE pages need DEVMAP PTEs support to function (ARCH_HAS_PTE_DEVMAP). Claim another RSW (reserved for software) bit in the PTE for DEVMAP mark, add the corresponding helpers, and enable ARCH_HAS_PTE_DEVMAP for riscv64. Signed-off-by: Björn Töpel --- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/pgtable-64.h | 20 ++++++++++++++++++++ arch/riscv/include/asm/pgtable-bits.h | 1 + arch/riscv/include/asm/pgtable.h | 15 +++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index b9398b64bb69..6d426afdd904 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -36,6 +36,7 @@ config RISCV select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE select ARCH_HAS_PMEM_API select ARCH_HAS_PREPARE_SYNC_CORE_CMD + select ARCH_HAS_PTE_DEVMAP if 64BIT && MMU select ARCH_HAS_PTE_SPECIAL select ARCH_HAS_SET_DIRECT_MAP if MMU select ARCH_HAS_SET_MEMORY if MMU diff --git a/arch/riscv/include/asm/pgtable-64.h b/arch/riscv/include/asm/pgtable-64.h index 221a5c1ee287..c67a9bbfd010 100644 --- a/arch/riscv/include/asm/pgtable-64.h +++ b/arch/riscv/include/asm/pgtable-64.h @@ -400,4 +400,24 @@ static inline struct page *pgd_page(pgd_t pgd) #define p4d_offset p4d_offset p4d_t *p4d_offset(pgd_t *pgd, unsigned long address); +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +static inline int pte_devmap(pte_t pte); +static inline pte_t pmd_pte(pmd_t pmd); + +static inline int pmd_devmap(pmd_t pmd) +{ + return pte_devmap(pmd_pte(pmd)); +} + +static inline int pud_devmap(pud_t pud) +{ + return 0; +} + +static inline int pgd_devmap(pgd_t pgd) +{ + return 0; +} +#endif + #endif /* _ASM_RISCV_PGTABLE_64_H */ diff --git a/arch/riscv/include/asm/pgtable-bits.h b/arch/riscv/include/asm/pgtable-bits.h index 179bd4afece4..a8f5205cea54 100644 --- a/arch/riscv/include/asm/pgtable-bits.h +++ b/arch/riscv/include/asm/pgtable-bits.h @@ -19,6 +19,7 @@ #define _PAGE_SOFT (3 << 8) /* Reserved for software */ #define _PAGE_SPECIAL (1 << 8) /* RSW: 0x1 */ +#define _PAGE_DEVMAP (1 << 9) /* RSW, devmap */ #define _PAGE_TABLE _PAGE_PRESENT /* diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 7933f493db71..216de1db3cd0 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -387,6 +387,11 @@ static inline int pte_special(pte_t pte) return pte_val(pte) & _PAGE_SPECIAL; } +static inline int pte_devmap(pte_t pte) +{ + return pte_val(pte) & _PAGE_DEVMAP; +} + /* static inline pte_t pte_rdprotect(pte_t pte) */ static inline pte_t pte_wrprotect(pte_t pte) @@ -428,6 +433,11 @@ static inline pte_t pte_mkspecial(pte_t pte) return __pte(pte_val(pte) | _PAGE_SPECIAL); } +static inline pte_t pte_mkdevmap(pte_t pte) +{ + return __pte(pte_val(pte) | _PAGE_DEVMAP); +} + static inline pte_t pte_mkhuge(pte_t pte) { return pte; @@ -711,6 +721,11 @@ static inline pmd_t pmd_mkdirty(pmd_t pmd) return pte_pmd(pte_mkdirty(pmd_pte(pmd))); } +static inline pmd_t pmd_mkdevmap(pmd_t pmd) +{ + return pte_pmd(pte_mkdevmap(pmd_pte(pmd))); +} + static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr, pmd_t *pmdp, pmd_t pmd) {