From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8981618D62D; Tue, 27 Aug 2024 23:00:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=63.228.1.57 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724799651; cv=none; b=NFVpYFAX7he7VvHBDFtkxT9T4a4pn4/WWHDjjMQx88YPfuAXx7Dgj8UpWIxwk48ok/yf98/jeg1xtnnJ+hq5Ng7r5f6iwIfvi130X5fnrB2f8KoTbQE4YhjsHDV/ylE/FTnl/bjQsYxvPUlHBK51OdN9kdTXowO9uEyrMDYCZfU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724799651; c=relaxed/simple; bh=zVR+j9/Y69HgPcEEApJAHkp51d4U9AleXPztiiA++P8=; h=Date:From:To:Cc:Subject:Message-ID:References:Mime-Version: Content-Type:Content-Disposition:In-Reply-To; b=qMfYUGrkEh5D+cYXn60iktOmbQFaII36/YhbucpyAbpuhG+0VoXxMr74S88I2cX34A195t1FKUompzeC478534Z5Mc1/MWvCaq45s1vYv77xl/R/XF7k+hL2hVh42MFJG0VqBmDWvTt/NJZ4S29Vv9ojfiB2/XmHLDkeNg0vxHU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org; spf=pass smtp.mailfrom=kernel.crashing.org; arc=none smtp.client-ip=63.228.1.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.crashing.org Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 47RMrWeM032045; Tue, 27 Aug 2024 17:53:32 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 47RMrUKh032044; Tue, 27 Aug 2024 17:53:30 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Tue, 27 Aug 2024 17:53:30 -0500 From: Segher Boessenkool To: Eric Biggers Cc: Christophe Leroy , Michael Ellerman , Nicholas Piggin , 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 , 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: Re: [PATCH v2 05/17] vdso: Avoid call to memset() by getrandom Message-ID: <20240827225330.GC29862@gate.crashing.org> References: <5deb67090b214f0e6eae96b7c406546d1a16f89b.1724309198.git.christophe.leroy@csgroup.eu> <20240827180819.GB2049@sol.localdomain> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240827180819.GB2049@sol.localdomain> User-Agent: Mutt/1.4.2.3i On Tue, Aug 27, 2024 at 11:08:19AM -0700, Eric Biggers wrote: > On Thu, Aug 22, 2024 at 09:13:13AM +0200, Christophe Leroy wrote: > > With the current implementation, __cvdso_getrandom_data() calls > > memset(), which is unexpected in the VDSO. > > > > Rewrite opaque data initialisation to avoid memset(). > > > > Signed-off-by: Christophe Leroy > > --- > > lib/vdso/getrandom.c | 15 ++++++++++----- > > 1 file changed, 10 insertions(+), 5 deletions(-) > > > > diff --git a/lib/vdso/getrandom.c b/lib/vdso/getrandom.c > > index cab153c5f9be..4a56f45141b4 100644 > > --- a/lib/vdso/getrandom.c > > +++ b/lib/vdso/getrandom.c > > @@ -4,6 +4,7 @@ > > */ > > > > #include > > +#include > > #include > > #include > > #include > > @@ -74,11 +75,15 @@ __cvdso_getrandom_data(const struct vdso_rng_data *rng_info, void *buffer, size_ > > u32 counter[2] = { 0 }; > > > > if (unlikely(opaque_len == ~0UL && !buffer && !len && !flags)) { > > - *(struct vgetrandom_opaque_params *)opaque_state = (struct vgetrandom_opaque_params) { > > - .size_of_opaque_state = sizeof(*state), > > - .mmap_prot = PROT_READ | PROT_WRITE, > > - .mmap_flags = MAP_DROPPABLE | MAP_ANONYMOUS > > - }; > > + struct vgetrandom_opaque_params *params = opaque_state; > > + int i; > > + > > + params->size_of_opaque_state = sizeof(*state); > > + params->mmap_prot = PROT_READ | PROT_WRITE; > > + params->mmap_flags = MAP_DROPPABLE | MAP_ANONYMOUS; > > + for (i = 0; i < ARRAY_SIZE(params->reserved); i++) > > + params->reserved[i] = 0; > > + > > return 0; > > } > > Is there a compiler flag that could be used to disable the generation of calls > to memset? -fno-tree-loop-distribute-patterns . But, as always, read up on it, see what it actually does (and how it avoids your problem, and mostly: learn what the actual problem *was*!) Have fun, Segher