From patchwork Fri Jan 10 15:23:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13935042 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1E1AEE77188 for ; Fri, 10 Jan 2025 15:37:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jKl3DhQmQa5hldobu3W0bZWFG2pizi3OuWZRVQz0XEA=; b=iCmc0Fx0cbLO91 l8Fk4M9qikvaa0epZlfzZcAdPY/vhJ8yWRxsXJR98XRa0b6jh3Tlbu6AV+i1fQMhDMXmjf2qbxE56 ML234xEA3nBCOjoYmmaBXyMqwnVlTKgb0p0wRlvW4rV8ZycouA2dLduLe8gndX6Ef+cJ2/U0hh4PP WOciTgrGJ+6bzBPxgXYyPgnHX3kxTIRx/fsQirot8uffh4ccZB/SpYDFPrRhOXXn7F96OT6XRv/w1 NDoAiy+aawj6bsNVGmNzQ09g4nA6QUrifjHkvbLoow1ZjcDtOKblszT7F6FPYjnrWDv1WGiEhTaYL rI5Kei0wqZce8NIZS3Gw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tWH4y-0000000FzCw-3LDC; Fri, 10 Jan 2025 15:37:44 +0000 Received: from galois.linutronix.de ([193.142.43.55]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tWGrg-0000000FtjY-14Dw; Fri, 10 Jan 2025 15:24:01 +0000 From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736522635; h=from:from: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; bh=2hF0doQ8ABpgn/aNZsNNVwp/0/3UT02lIHINaA5tvUM=; b=4QuV6WLv+qM0NFq/bU50gvu9jHJbGQqi8ZhB1pWOJo78K7X8EMY2cqzf+A0eJ3euP6AoM0 3ZgoB397PR5qBYy4Ji2YF5V5UlQDbEFyfk4u8GXDBtnxZE2qjnL+2jmv4vuaIsaezwXOSZ hwdc3Iqa+1S91NJqKlHixWQY9bBHOG+dGCoc8F1rFRxxvjDF5+usOvgWMbZs+TZP/R8CjB c5zeenPso/iK5Muu0FVxXZzMwgvBPwh6VwzXRiz9M+2AobY70sdWEN9azGRgZEoT3kGFN5 GE1kIR8fbyssrgwer81DVIhdrwGGYCCC0p5dNAeLcv8MU05MrLi78ZR4Qu9StA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736522635; h=from:from: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; bh=2hF0doQ8ABpgn/aNZsNNVwp/0/3UT02lIHINaA5tvUM=; b=6C/eB/zjdtEzQvYPxdxc0wgWqNTengxBY22KHhSipUPGZt0oE+VYTtMiCbpmEs2qO3htJ6 bAtCMpTjfRigOvCQ== Date: Fri, 10 Jan 2025 16:23:46 +0100 Subject: [PATCH v2 07/18] vdso: Add generic architecture-specific data storage MIME-Version: 1.0 Message-Id: <20250110-vdso-store-rng-v2-7-350c9179bbf1@linutronix.de> References: <20250110-vdso-store-rng-v2-0-350c9179bbf1@linutronix.de> In-Reply-To: <20250110-vdso-store-rng-v2-0-350c9179bbf1@linutronix.de> To: "James E.J. Bottomley" , Helge Deller , Andy Lutomirski , Thomas Gleixner , Vincenzo Frascino , Anna-Maria Behnsen , Frederic Weisbecker , Andrew Morton , Catalin Marinas , Will Deacon , Theodore Ts'o , "Jason A. Donenfeld" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Huacai Chen , WANG Xuerui , Russell King , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Thomas Bogendoerfer , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Madhavan Srinivasan , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Arnd Bergmann , Guo Ren Cc: linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, loongarch@lists.linux.dev, linux-s390@vger.kernel.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arch@vger.kernel.org, Nam Cao , =?utf-8?q?Thom?= =?utf-8?q?as_Wei=C3=9Fschuh?= , linux-csky@vger.kernel.org X-Developer-Signature: v=1; a=ed25519-sha256; t=1736522629; l=4823; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=2OGLOTIn3mrK94nEr9eCVL0nPgn4S3w/pFtDFpXzfrI=; b=BWqHXYbHF2N14HCyKEALbacHP4B4k0Olfuqv1Ny6/4qxq5QHetPRa9vRN0DxHlVRIYSAWu+an Ie7iC4RpCs5CHpDT8JL7bXGs/W4j5ZDMEXMmBF0IlVo9oyq1D256JK5 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250110_072400_579427_D0346C80 X-CRM114-Status: GOOD ( 15.36 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Some architectures need to architecture-specific data to the vDSO. Enable the generic vDSO storage mechanism to both store and map this data. Some architectures require more than a single page, like LoongArch, so prepare for that usecase, too. Signed-off-by: Thomas Weißschuh --- arch/Kconfig | 4 ++++ include/vdso/datapage.h | 25 +++++++++++++++++++++++++ lib/vdso/datastore.c | 14 ++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index 6682b2a53e342cbacc05b70ef99cb1c47efe55e8..48f37e6c00674f433a0d6e6e05ce72c27cf000b7 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1576,6 +1576,10 @@ config HAVE_SPARSE_SYSCALL_NR entries at 4000, 5000 and 6000 locations. This option turns on syscall related optimizations for a given architecture. +config ARCH_HAS_VDSO_ARCH_DATA + depends on GENERIC_VDSO_DATA_STORE + bool + config ARCH_HAS_VDSO_TIME_DATA bool diff --git a/include/vdso/datapage.h b/include/vdso/datapage.h index 7dbc8797e3b8923c06f4b6b34790766e68b2abd2..46658b39c28250e977f5a3454224c3ed0fb4c81d 100644 --- a/include/vdso/datapage.h +++ b/include/vdso/datapage.h @@ -9,11 +9,13 @@ #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -25,6 +27,15 @@ struct arch_vdso_time_data {}; #endif +#if defined(CONFIG_ARCH_HAS_VDSO_ARCH_DATA) +#include +#elif defined(CONFIG_GENERIC_VDSO_DATA_STORE) +struct vdso_arch_data { + /* Needed for the generic code, never actually used at runtime */ + char __unused; +}; +#endif + #define VDSO_BASES (CLOCK_TAI + 1) #define VDSO_HRES (BIT(CLOCK_REALTIME) | \ BIT(CLOCK_MONOTONIC) | \ @@ -145,9 +156,11 @@ extern struct vdso_rng_data _vdso_rng_data __attribute__((visibility("hidden"))) #else extern struct vdso_time_data vdso_u_time_data[CS_BASES] __attribute__((visibility("hidden"))); extern struct vdso_rng_data vdso_u_rng_data __attribute__((visibility("hidden"))); +extern struct vdso_arch_data vdso_u_arch_data __attribute__((visibility("hidden"))); extern struct vdso_time_data *vdso_k_time_data; extern struct vdso_rng_data *vdso_k_rng_data; +extern struct vdso_arch_data *vdso_k_arch_data; #endif /** @@ -160,10 +173,15 @@ union vdso_data_store { #ifdef CONFIG_GENERIC_VDSO_DATA_STORE +#define VDSO_ARCH_DATA_SIZE ALIGN(sizeof(struct vdso_arch_data), PAGE_SIZE) +#define VDSO_ARCH_DATA_PAGES (VDSO_ARCH_DATA_SIZE >> PAGE_SHIFT) + enum vdso_pages { VDSO_TIME_PAGE_OFFSET, VDSO_TIMENS_PAGE_OFFSET, VDSO_RNG_PAGE_OFFSET, + VDSO_ARCH_PAGES_START, + VDSO_ARCH_PAGES_END = VDSO_ARCH_PAGES_START + VDSO_ARCH_DATA_PAGES - 1, VDSO_NR_PAGES }; @@ -193,10 +211,17 @@ enum vdso_pages { #define __vdso_u_rng_data #endif +#ifdef CONFIG_ARCH_HAS_VDSO_ARCH_DATA +#define __vdso_u_arch_data PROVIDE(vdso_u_arch_data = vdso_u_data + 3 * PAGE_SIZE); +#else +#define __vdso_u_arch_data +#endif + #define VDSO_VVAR_SYMS \ PROVIDE(vdso_u_data = . - __VDSO_PAGES * PAGE_SIZE); \ PROVIDE(vdso_u_time_data = vdso_u_data); \ __vdso_u_rng_data \ + __vdso_u_arch_data \ #endif /* !__ASSEMBLY__ */ diff --git a/lib/vdso/datastore.c b/lib/vdso/datastore.c index 9260b00dc8520af109bd9dd05ac7f7504eafbea0..0959d62d78586ef458eb5f7c1e152f6b5d4cbf85 100644 --- a/lib/vdso/datastore.c +++ b/lib/vdso/datastore.c @@ -26,6 +26,14 @@ struct vdso_rng_data *vdso_k_rng_data = &vdso_rng_data_store.data; static_assert(sizeof(vdso_rng_data_store) == PAGE_SIZE); #endif /* CONFIG_VDSO_GETRANDOM */ +#ifdef CONFIG_ARCH_HAS_VDSO_ARCH_DATA +static union { + struct vdso_arch_data data; + u8 page[VDSO_ARCH_DATA_SIZE]; +} vdso_arch_data_store __page_aligned_data; +struct vdso_arch_data *vdso_k_arch_data = &vdso_arch_data_store.data; +#endif /* CONFIG_ARCH_HAS_VDSO_ARCH_DATA */ + static vm_fault_t vvar_fault(const struct vm_special_mapping *sm, struct vm_area_struct *vma, struct vm_fault *vmf) { @@ -67,6 +75,12 @@ static vm_fault_t vvar_fault(const struct vm_special_mapping *sm, return VM_FAULT_SIGBUS; pfn = __phys_to_pfn(__pa_symbol(vdso_k_rng_data)); break; + case VDSO_ARCH_PAGES_START ... VDSO_ARCH_PAGES_END: + if (!IS_ENABLED(CONFIG_ARCH_HAS_VDSO_ARCH_DATA)) + return VM_FAULT_SIGBUS; + pfn = __phys_to_pfn(__pa_symbol(vdso_k_arch_data)) + + vmf->pgoff - VDSO_ARCH_PAGES_START; + break; default: return VM_FAULT_SIGBUS; }