From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70F62C433F5 for ; Fri, 4 Feb 2022 15:57:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236975AbiBDP5W (ORCPT ); Fri, 4 Feb 2022 10:57:22 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:60832 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230211AbiBDP5T (ORCPT ); Fri, 4 Feb 2022 10:57:19 -0500 Date: Fri, 4 Feb 2022 16:57:17 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1643990238; 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: in-reply-to:in-reply-to:references:references; bh=H1SCG2oNEv5W4scfTi2aoSVlrGEsagG8YtlUCrxXMoc=; b=txa+5yoi77400sJ+kR49rS2Je7vH/2cXg90NNwmpJixdhgnvyQllNEjVpK2PJISKcVXdow Zx2Jkue406jvVTI3YdFq4kpsjfWVE+73YfTfHJM/KO/+wLoaX5b3WN9TvL03k1LXiNcOKj aWVbkDIR9ScWYdIK27xoytGmQuITCfWzhWHnRjNE8b3wDos4bh54izbCaOULNKx1VYl3se f1iznbXmks8tYUSPjo/lGxUFqQioAjHP+dyUcNfuirk3o6/3Xa/y1DtX1cgyb6vCWQtgzc teVeK9wXiKtwDw/C8F67OoW92HhK5+M84Irwo545jzQ+eefWUA/FUIOVEy70nw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1643990238; 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: in-reply-to:in-reply-to:references:references; bh=H1SCG2oNEv5W4scfTi2aoSVlrGEsagG8YtlUCrxXMoc=; b=mMMY6+4ZE7IHnOSHIJOU2dA8h9SK4XnbKUQ+/L+8V+dPtoLhg4bIRTElV9yt36Vpie95QY 8M39nb8owshZ1XDg== From: Sebastian Andrzej Siewior To: "Jason A. Donenfeld" Cc: Andy Lutomirski , Boqun Feng , Will Deacon , Peter Zijlstra , Ingo Molnar , Waiman Long , Sultan Alsawaf , Theodore Ts'o , Andy Lutomirski , Jonathan =?utf-8?Q?Neusch=C3=A4fer?= , LKML , Thomas Gleixner Subject: Re: [PATCH v3] random: remove batched entropy locking Message-ID: References: <20220204155142.56419-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220204155142.56419-1-Jason@zx2c4.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-02-04 16:51:42 [+0100], Jason A. Donenfeld wrote: > index 455615ac169a..3e54b90a3ff8 100644 > --- a/drivers/char/random.c > +++ b/drivers/char/random.c > @@ -1759,41 +1762,54 @@ u64 get_random_u64(void) > unsigned long flags; > struct batched_entropy *batch; > static void *previous; > + int next_gen; > > warn_unseeded_randomness(&previous); > > - batch = raw_cpu_ptr(&batched_entropy_u64); > - spin_lock_irqsave(&batch->batch_lock, flags); > - if (batch->position % ARRAY_SIZE(batch->entropy_u64) == 0) { > + batch = this_cpu_ptr(&batched_entropy_u64); > + local_lock_irqsave(&batch->lock, flags); Does this compile and work? From the looks of it, this should be: local_lock_irqsave(&batched_entropy_u64.lock, flags); batch = this_cpu_ptr(&batched_entropy_u64); and we could do s/this_cpu_ptr/raw_cpu_ptr/ Sebastian