From patchwork Thu Aug 22 07:13:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 13772813 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 D9DB8C5320E for ; Thu, 22 Aug 2024 07:13:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 746A76B01F5; Thu, 22 Aug 2024 03:13:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F67C6B01F7; Thu, 22 Aug 2024 03:13:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5BDD26B029F; Thu, 22 Aug 2024 03:13:37 -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 3DD946B01F5 for ; Thu, 22 Aug 2024 03:13:37 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id DB6AF1213FE for ; Thu, 22 Aug 2024 07:13:36 +0000 (UTC) X-FDA: 82479016032.23.BA9ADA5 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by imf06.hostedemail.com (Postfix) with ESMTP id A90D418001F for ; Thu, 22 Aug 2024 07:13:34 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.235.10 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu; dmarc=pass (policy=quarantine) header.from=csgroup.eu ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724310774; a=rsa-sha256; cv=none; b=VhSWvJRcwm+8LxDKV+KXRR7u+YJ/FUrUZH/kadkbtkX5wHV64gTcDqMYp7zzjLPCDyx4Zu 631vR8K539VODMHMnlIiu1RKG+TzqfPyZ9gmoYLXn0kojq225Jb37Omftz26l0PU7iK7Kd g8qic5DGkNEu5ZG+opfNbfftT3jMKKE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; spf=pass (imf06.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.235.10 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu; dmarc=pass (policy=quarantine) header.from=csgroup.eu ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724310774; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wIcjOS5mdzYYCt6rXdfHi7QObcg9a7ZKGf4I39Qdb90=; b=eJbPhq6NVloQZ7l9/gM5CBKEnmYdUmUEDhRhz7O3i+ipx4N0Q/dafb1jnPTo+1aKEsvffb CnFkNFUJmnLIMFvax5rZrgn/kUb1xlLdbSivbyaPJhB8JJ4M+JGpvbjvB1iQcY2fQmD441 KJpLzZ++uqy+tjGw2pgQPFigjDurSqE= Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4WqDv86QrKz9sSN; Thu, 22 Aug 2024 09:13:24 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FdCDskQ2p5WL; Thu, 22 Aug 2024 09:13:24 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4WqDv85QXJz9sSH; Thu, 22 Aug 2024 09:13:24 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A7ED78B77E; Thu, 22 Aug 2024 09:13:24 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id ouP_vD4wp4xB; Thu, 22 Aug 2024 09:13:24 +0200 (CEST) Received: from PO20335.idsi0.si.c-s.fr (PO16920.IDSI0.si.c-s.fr [192.168.232.181]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 944968B763; Thu, 22 Aug 2024 09:13:23 +0200 (CEST) From: Christophe Leroy To: Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , "Theodore Ts'o" , "Jason A. Donenfeld" , Arnd Bergmann , Andrew Morton , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Vincenzo Frascino , Shuah Khan Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 02/17] vdso: Clean header inclusion in getrandom Date: Thu, 22 Aug 2024 09:13:10 +0200 Message-ID: <2a081f1fff5e40f496153f8e0162fc7ec5adab2e.1724309198.git.christophe.leroy@csgroup.eu> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1724310793; l=3539; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=t1ii3oP+DWJaA3RAVE9qv0Jl6VLeHCEWNNWvjxnIH5Q=; b=ANTjekVtAyR0hDVIxrc3nu2T9PxOuN9Ua7Gf4v/suoPDxg/04vzQWBh3+1ksJJaTwPqkpldnx KcQYfaLEwU7BvUlhMxVrCjpvlWYlePU5fPx0kouXgxCqKaovwoxnEp7 X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= X-Stat-Signature: pkwoe98uxzn83mysx541aa66yragpkyj X-Rspamd-Queue-Id: A90D418001F X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724310814-34375 X-HE-Meta: U2FsdGVkX1+L7rQ7yHL7Mp6bMfZnpNYnpSiEIZDz5kmv4I4qZ6pD9TqbVlGF9kitYEexBLyDHOpGjirmT7+k31FpmjO2KnUbcORUy630OIuU6jYYZSt9RBHnb27LWKLU1Re1P7ZzOWykwPxB5YhGkobXczqkpOJmcIwKoJbF/38bUmOpux+3JGUZFKh6jSpM+Os8uINfQj9jIZkeZcca2TV/FLKLWNpI1GyoChFsOmu1A5SK1pavsAfmOwpYX+tgqnCg63irmCrdRoU2tbhvkRcYWaqrwsw146j7RdaU6gChbqIi0c71FhCRe5O6ajHMLuIQxQ73429Y9PPk5J5VV2/4SFv6TrYIqy+CIOoZX3IWP6yvhZbEx/IbD1J/vUuHcfu73IDe9uD4Gz9bfZNBMrae2om7S0rq8H3998fuVv0Kb4jlg/HOtd3Fv73Jma7TiVgdkbEeT0lPLJA6wR+bIZeqGeZGWojAkQXjTDzKjOvIGrtGNyhr7/j71ljtHPz/tWzDLrVxoAGKHBYjJjA7R9zqPXpT2Q2LEEwKS7tXemye2HRG7W/UwnW5X77k8CbY2VzVeKCszK3HDfVbj8/wWGOoA04BJj2vP4n/NFc2W6up2Z/eP9ZuVfAdgpv630/KXjj9I5Rqlbuvknu5o4F3QKvEjpIbi7miIA2dxciCj4LPLhBSrcUuER0v2iOZJAVAJiI6yrq+jevulVIdfXitCa3RgpcKOLMbyWoWyQnQp9LrUH2B8f+BuYJ27D5kRLQ6mxrshIf9JS3PTB+vt/jVGW7nW6gqS5XCUHT0/1YAsj/5QCMQtWgfjUADPybMrBEoZ0V9zVrc2MQBoPdC01aSTQ0lAGBKAxzLz9CgXX4blp2alMZRl5EKbOPnyugB/fqaHxkCE/Tr3IaqkamqeJz36JX4n3Xq5id7rOywl1aX4raXSjxmiXSPlloopiD1yYTNCE7kTacbDO1CKb/C2xi T7Ld7GE5 9gX+PTqx8c8K8opZWGmroWwKxMvL0ZSXNflYeh8vyNH3nf4Vlx+H2fp4clTL/sszYvev/h1dmhyOFpCgYeqibx0Lyn9zhK6LusFyhd+gzQ0xho4hx6kvMK9Vcw+Z505zks+Zv8F+vw8Ehzh6NoWD9K1S5QfAQbxZRFxZU9H1yolQ7oelqHMmUOSPCp0p7sA+1uEhKxUUAxYFpJw9CJmFKJWG5dA== 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: Building a VDSO32 on a 64 bits kernel is problematic when some system headers are included. See commit 8c59ab839f52 ("lib/vdso: Enable common headers") for more details. Minimise the amount of headers by moving needed items into dedicated common headers. For PAGE_SIZE and PAGE_MASK, redefine them from CONFIG_PAGE_SHIFT in the same way as commit cffaefd15a8f ("vdso: Use CONFIG_PAGE_SHIFT in vdso/datapage.h") Signed-off-by: Christophe Leroy --- arch/x86/include/asm/pvclock.h | 1 + include/vdso/helpers.h | 1 + lib/vdso/getrandom.c | 15 ++++++++------- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/pvclock.h b/arch/x86/include/asm/pvclock.h index 0c92db84469d..6e4f8fae3ce9 100644 --- a/arch/x86/include/asm/pvclock.h +++ b/arch/x86/include/asm/pvclock.h @@ -5,6 +5,7 @@ #include #include +struct timespec64; /* some helper functions for xen and kvm pv clock sources */ u64 pvclock_clocksource_read(struct pvclock_vcpu_time_info *src); u64 pvclock_clocksource_read_nowd(struct pvclock_vcpu_time_info *src); diff --git a/include/vdso/helpers.h b/include/vdso/helpers.h index 73501149439d..3ddb03bb05cb 100644 --- a/include/vdso/helpers.h +++ b/include/vdso/helpers.h @@ -4,6 +4,7 @@ #ifndef __ASSEMBLY__ +#include #include static __always_inline u32 vdso_read_begin(const struct vdso_data *vd) diff --git a/lib/vdso/getrandom.c b/lib/vdso/getrandom.c index b230f0b10832..cab153c5f9be 100644 --- a/lib/vdso/getrandom.c +++ b/lib/vdso/getrandom.c @@ -3,15 +3,13 @@ * Copyright (C) 2022-2024 Jason A. Donenfeld . All Rights Reserved. */ -#include -#include -#include +#include #include #include +#include #include -#include -#include #include +#include #define MEMCPY_AND_ZERO_SRC(type, dst, src, len) do { \ while (len >= sizeof(type)) { \ @@ -23,6 +21,9 @@ } \ } while (0) +#define _PAGE_SIZE (1UL << CONFIG_PAGE_SHIFT) +#define _PAGE_MASK (~(_PAGE_SIZE - 1)) + static void memcpy_and_zero_src(void *dst, void *src, size_t len) { if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) { @@ -64,7 +65,7 @@ static __always_inline ssize_t __cvdso_getrandom_data(const struct vdso_rng_data *rng_info, void *buffer, size_t len, unsigned int flags, void *opaque_state, size_t opaque_len) { - ssize_t ret = min_t(size_t, INT_MAX & PAGE_MASK /* = MAX_RW_COUNT */, len); + ssize_t ret = min_t(size_t, INT_MAX & _PAGE_MASK /* = MAX_RW_COUNT */, len); struct vgetrandom_state *state = opaque_state; size_t batch_len, nblocks, orig_len = len; bool in_use, have_retried = false; @@ -82,7 +83,7 @@ __cvdso_getrandom_data(const struct vdso_rng_data *rng_info, void *buffer, size_ } /* The state must not straddle a page, since pages can be zeroed at any time. */ - if (unlikely(((unsigned long)opaque_state & ~PAGE_MASK) + sizeof(*state) > PAGE_SIZE)) + if (unlikely(((unsigned long)opaque_state & ~_PAGE_MASK) + sizeof(*state) > _PAGE_SIZE)) return -EFAULT; /* If the caller passes the wrong size, which might happen due to CRIU, fallback. */