Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1872360rwb; Tue, 29 Nov 2022 21:50:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf5XjsVqXoBAz6a1MixQ4BvRSIMu44ie5UsvkIya3gbrC9Qxf0UQ8QqVLXWccVr60i6N8Aj+ X-Received: by 2002:a17:903:41c8:b0:17d:b9c:cd64 with SMTP id u8-20020a17090341c800b0017d0b9ccd64mr42400941ple.40.1669787454675; Tue, 29 Nov 2022 21:50:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669787454; cv=none; d=google.com; s=arc-20160816; b=iDxmyTurTNwmn4Z8INZQ6gFcEwgtvpAUIm2d4XYyGd2iGHMX7NAL6YrEtgJFpfePto CVLLoVdQ2pW1N2R8l8o/oS63ZvsbM4yyTeFpyGl715CP3X9fzoppjcIBzeAZxs4xD75G oA8x/ezg7j7dfA2MCw57i9U/c1V52EqKivPVO9euNdO4bAFrBGWFUEdvp8CVayqP+0lZ uo+zKse91NSsfGq7FydxoRfsCoFwQDzzAK4fEfe/4WHj0bpPQpg/z63BjSGFKcUsJdEI TMWOPPvm1RRlPMWZpKYZuQbWeSMWO/K9MMj1PlTT9nxCywj2JciZnEVWGBROv9uzjuA7 wFbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=mI0GyqzE6SXQ9Ez+7zJclAE8NR5OsjvV147Ld9Fekks=; b=IL0ohI7L6YVN3iAn/4GynZBy+7JAE9eK7MXmFLYPUgx48dkJlKwK1E6t4X8Yg5oPIu ykXV+0Pz9o0lukTa64L9PBnBMXKX5pFdOOO+TyTyNvAa6IVPFBCCy0a53VWZnO+AQxcm VsYsJJVfEROQXYAvaIeYGCBHjrN0xoPnKo/4htMRoIjNbgO2hJR6nAbBbGKwJH5dKrwg /CxN4wffhdyTv6LvwdyifTk3ZCdhxrnMXJdaX4RWNC3jpcQCD+1BECYujRUGEx8ILfqY QFr2BKYOzP2CKlnthj8uN+PNT3EutVQrOJay0TKdAmijMeIPHRaZ3qVpypUF777tigTf 3u/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PL2zvx2Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 139-20020a630591000000b0045cc8781244si401934pgf.220.2022.11.29.21.50.43; Tue, 29 Nov 2022 21:50:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PL2zvx2Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233016AbiK3Ez4 (ORCPT + 84 others); Tue, 29 Nov 2022 23:55:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232432AbiK3Ezx (ORCPT ); Tue, 29 Nov 2022 23:55:53 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B89A2A952 for ; Tue, 29 Nov 2022 20:55:53 -0800 (PST) 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 1BABDB81A20 for ; Wed, 30 Nov 2022 04:55:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9DF7C433C1; Wed, 30 Nov 2022 04:55:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669784150; bh=daPHIaEHptqDmcDblMDn8/EoMgNWvo+d8jmNIXKhKd0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PL2zvx2YDqjotznYfAZappPMQryiVaJrJ1t0SfIH4EqY1zE5zTtej11IhOFSOW3Jy 0J5+4d6xexSRrVqj8kHiUULIfNpJhWTYr7gSmHahzn9hwV+xG9xjoLWpzp0Hq3I7Rf uS36UKaTt9RThkSBgn6uLGH/Sjsupg3ZUXREOqgz95WQyr0SXLnDDf3/wjQ4JZkdc6 9gEXSY81QAegMI/GomMgOfZAZtQoeKv0CBdHei4A3/0H/5dy0HyVcRZEuvsiRww8gJ mJ0G61tlaHK6owHSd35LOlAeVODlBFvvnkFnpD3GZhf2f9KZ2fukEakbMuGmICXU3h EZidm0s5ewqMA== Date: Tue, 29 Nov 2022 20:55:48 -0800 From: Eric Biggers To: "Jason A. Donenfeld" Cc: linux-kernel@vger.kernel.org, Sultan Alsawaf Subject: Re: [PATCH] random: align entropy_timer_state to cache line Message-ID: References: <20221130020815.283814-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221130020815.283814-1-Jason@zx2c4.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jason, On Wed, Nov 30, 2022 at 03:08:15AM +0100, Jason A. Donenfeld wrote: > The theory behind the jitter dance is that multiple things are poking at > the same cache line. This only works, however, if those things are > actually all in the same cache line. Ensure this is the case by aligning > the struct on the stack to the cache line size. > > On x86, this indeed aligns the stack struct: > > 000000000000000c : > { > c: 55 push %rbp > - d: 53 push %rbx > - e: 48 83 ec 38 sub $0x38,%rsp > + d: 48 89 e5 mov %rsp,%rbp > + 10: 41 54 push %r12 > + 12: 53 push %rbx > + 13: 48 83 e4 c0 and $0xffffffffffffffc0,%rsp > + 17: 48 83 ec 40 sub $0x40,%rsp > > Cc: Sultan Alsawaf > Fixes: 50ee7529ec45 ("random: try to actively add entropy rather than passively wait for it") > Signed-off-by: Jason A. Donenfeld > --- > drivers/char/random.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/char/random.c b/drivers/char/random.c > index 67558b95d531..2494e08c76d8 100644 > --- a/drivers/char/random.c > +++ b/drivers/char/random.c > @@ -1262,7 +1262,7 @@ static void __cold entropy_timer(struct timer_list *timer) > static void __cold try_to_generate_entropy(void) > { > enum { NUM_TRIAL_SAMPLES = 8192, MAX_SAMPLES_PER_BIT = HZ / 15 }; > - struct entropy_timer_state stack; > + struct entropy_timer_state stack ____cacheline_aligned; Several years ago, there was a whole thing about how __attribute__((aligned)) to more than 8 bytes doesn't actually work on stack variables in the kernel on x86, because the kernel only keeps the stack 8-byte aligned but gcc assumes it is 16-byte aligned. See https://lore.kernel.org/linux-crypto/20170110143340.GA3787@gondor.apana.org.au/T/#t IIRC, nothing was done about it at the time. Has that been resolved in the intervening years? - Eric