From nobody Fri Dec 19 19:00:34 2025 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 1C2BBC43219 for ; Thu, 13 Oct 2022 17:58:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230234AbiJMR60 (ORCPT ); Thu, 13 Oct 2022 13:58:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230230AbiJMR51 (ORCPT ); Thu, 13 Oct 2022 13:57:27 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 380E8659EF; Thu, 13 Oct 2022 10:56:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 18BB6B81CF4; Thu, 13 Oct 2022 17:56:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FF15C433D6; Thu, 13 Oct 2022 17:56:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665683763; bh=NP1XPEhn7jtkvGePO/ii4tg8z2O0BgSRceDNFGGZJbk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JXwH/mBoenPXO1zXVoUy4hPIxLn1+pEHD7viMJz/6opnDQaXqqYxHt2ZS/xOc4+5p shgUamLT44+1qZV/Pz9J/McBavNugFAb6SllJMQDX3PMXeqVwP0Oqh4tiJKjHLio72 I1+mTSNOdpnfKprSIRfG3qXxBY5iyqhNIos7CIl8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sebastian Andrzej Siewior , "Jason A. Donenfeld" Subject: [PATCH 5.10 41/54] random: avoid reading two cache lines on irq randomness Date: Thu, 13 Oct 2022 19:52:35 +0200 Message-Id: <20221013175148.335434415@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013175147.337501757@linuxfoundation.org> References: <20221013175147.337501757@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Jason A. Donenfeld commit 9ee0507e896b45af6d65408c77815800bce30008 upstream. In order to avoid reading and dirtying two cache lines on every IRQ, move the work_struct to the bottom of the fast_pool struct. add_ interrupt_randomness() always touches .pool and .count, which are currently split, because .mix pushes everything down. Instead, move .mix to the bottom, so that .pool and .count are always in the first cache line, since .mix is only accessed when the pool is full. Fixes: 58340f8e952b ("random: defer fast pool mixing to worker") Reviewed-by: Sebastian Andrzej Siewior Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -895,10 +895,10 @@ void __cold add_bootloader_randomness(co EXPORT_SYMBOL_GPL(add_bootloader_randomness); =20 struct fast_pool { - struct work_struct mix; unsigned long pool[4]; unsigned long last; unsigned int count; + struct work_struct mix; }; =20 static DEFINE_PER_CPU(struct fast_pool, irq_randomness) =3D {