Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2825533rwb; Wed, 30 Nov 2022 11:21:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf4OVcCTDEqlCWOM+y/qLnlS01ATani4ROJN7/HtcbLrb78tKiek0iafwwwBvgMvmJxjE3mr X-Received: by 2002:a17:906:6d03:b0:78d:9d0b:a9f6 with SMTP id m3-20020a1709066d0300b0078d9d0ba9f6mr6274459ejr.661.1669836113787; Wed, 30 Nov 2022 11:21:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669836113; cv=none; d=google.com; s=arc-20160816; b=AgVtlSm1HOymRdarf+qfRTXIutDQ24gOMcawe9T6TMPkbdllR8ojxRBH3fmQse7okK kOXGpk8BEr9P2NxzjGp9JdtzLajgD4gpFvedx6XnjqdEV3GlrqCCnNPGEud7PqvmGvxt ZgcGF09YvDqPAeyeNzOTMgAJ773U0KTe2obIyhAUZeg3fQPa2aR5N2TayYN+88ITOsbx wiBqrJ1/EdgI4z/j3P9B9R/PO0nUJOl13OhidBB2OCEVAAEtzHWb5g/uKDgvvnGczDTt UQjBOatoEK2zW4OtFuTUcj7AX8oPG58IuXAOmXAjJHMt20P/2s4+xqdSM5GpDyOOdH/Y 62JA== 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=rdncmydNLWuTrvKSvS7F6870ZmKfjI6RgP71TZ96GqE=; b=NmpmMaOGGz7LoL3C2BPg/dD8AKpX/ziEYkcMI6yZcyAbRZofwDDDNZkul23B/WlRn9 +o+YPsTFPwHNuY9vTrpnZ02gBwQoIncDVS1IhnLzT+q5tCXaUaFQeguuRVssNCsQMDdj xGxnKUeg128sCav5PyhGblUxyD6nHQ+w8Qsm202IVnx2WMtSTtAZregDbY7JtbKKx4z0 qyVLEV2n+2AM2G3jF7MCkua6YTVj1LRMl1d67KhTiIwo2A2LfVOFd8Aq7yBfBEvbstrJ thUTwAM+LobxEI2N2Sq7u4Iba1l7mIQzV4d1WrWjQnPHZR2qzGsjj4vmRUpTtPUb8UIN TZBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IBKlEJWV; 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 t15-20020a1709067c0f00b007aa8a5131a3si1390973ejo.181.2022.11.30.11.21.31; Wed, 30 Nov 2022 11:21:53 -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=IBKlEJWV; 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 S230003AbiK3S7I (ORCPT + 84 others); Wed, 30 Nov 2022 13:59:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229840AbiK3S7E (ORCPT ); Wed, 30 Nov 2022 13:59:04 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A80BF54446 for ; Wed, 30 Nov 2022 10:59:03 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 43EC261D41 for ; Wed, 30 Nov 2022 18:59:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DCF1C433C1; Wed, 30 Nov 2022 18:59:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669834742; bh=3TD1S3j9pGxF2WpgRYYO4Ir4fNQvcwgiHdn38dgmJmo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IBKlEJWVE64uTEoiocu6EdVYn+nHHv5GLr/eSq1E0BoTx2zhNrMxlde8mWA4/CEE9 tSkXF4g6jdhw3GJh2aEwaTzQzTlQBVZkZb9WPeubQ44OxfQYDsgQG6AdvfKxAD4/Ay t5g1gME4rzxlwwXNpg9eUkgiSNExMfgLL0zpdsAp1WhwkQxNM0GJ7b2mQB1HeOiQiB qe5lmQ189cKLjBmn0uHie/PziNW8xfQ5zgMfKVaCmOsbxUrR/xLJqH9QmfJifCkqF8 eSATxDTOTsS0+8/Nyf7VyIspTP2LL0WF95CXRoWvoc1Oyq1amPo/X1cLDcMI7GWaKx q26s2gbTrTxUA== Date: Wed, 30 Nov 2022 18:59:01 +0000 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: 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 On Wed, Nov 30, 2022 at 11:04:23AM +0100, Jason A. Donenfeld wrote: > > > 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? > > Maybe things are different for ____cacheline_aligned, which is 64 bytes. > Reading that thread, it looks like it was a case of trying to align the > stack to 16 bytes, but gcc assumed 16 bytes already while the kernel > only gave it 8. So gcc didn't think it needed to emit any code to align > it. Here, though, it's 64, and gcc certainly isn't assuming 64-byte > stack alignment. > > Looking at the codegen, gcc appears to doing `rsp = (rsp & ~63) - 64`, > which appears correct. Well, if gcc thinks the stack is already 16-byte aligned, then it would be perfectly within its rights to do 'rsp = (rsp & ~47) - 64', right? You probably don't want to be relying on an implementation detail of gcc codegen... - Eric