Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2905903rwb; Wed, 30 Nov 2022 12:32:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf6vwTS6MyKT6pESb7yxUot/oce/qTUu5GB9ARGvlW96oBai/7uADEhu8oA0zpKZV89kuNG1 X-Received: by 2002:a17:906:aec1:b0:7c0:a04b:6795 with SMTP id me1-20020a170906aec100b007c0a04b6795mr3463869ejb.16.1669840343841; Wed, 30 Nov 2022 12:32:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669840343; cv=none; d=google.com; s=arc-20160816; b=P8fGaC5rgkKKB4rf5QPHcJTt7LaZ/kRHp3BZE7GxI7m4ix3LyAsVtEA0Q35LHXPVZn 07hgmVVykB1AY0txbedzFzm0e1J8+d78/NFy09Wd0n61QDb/5BkOjbzHMd0f9Q8HHHU3 ENEJQQLOtVk8orj1RVRC77Kf/olLS5GbB40x0ECsWgLUuh1/dpn4frAqNBmMU0dQB3c6 H0fRbY3UfGUHhh3VVnfeP0BgE5vowpYFmISGrsqzoZe1WtCDYuB6+ydywgImAfE/25KW kecOcA2uY74Zm24xpwE+0jtOEWek7ge4BIf6BNKyAcEn7glGwP328du+2DBypAw3oaR+ ko3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=8ScMaAIgcavRwlnc4K5Bo/PJrf8VIf6mrT3T2oiNawk=; b=QOvqcVqR+uk2gaowm8aX+3NcAbvNuflyDgicKFJdYNtYirb+Aktya1zkZ1LvS0j/EN C9vpd4/hU14Vc5a4ozoM4sAU1imWNsDzOeELrmtjtfENYUYB7aLb7EFk2pNAhfz0Bgis Sbi+/PgYuMd+N2AcIbAwp153k4WUcJCOj2Z4jH/eezRHf1QNG2te5+NFmtlqdky1EeYy uN7m+tlLj7yiRJyMhLVMP0ho8Sqvd8Ep6wgEWIxoa/bpzUukSni4IJz4asdImPAUkgD7 ejSQ5YsW2l2DW8wdjqg/z3fxyDjJKXTRmJ+4Qivat7udpSJzfdXgTO/B5WMfJ812RHGI dTFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=HMBhsAXD; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he41-20020a1709073da900b0073d8e4e8c77si2205321ejc.1005.2022.11.30.12.32.03; Wed, 30 Nov 2022 12:32:23 -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=@zx2c4.com header.s=20210105 header.b=HMBhsAXD; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229683AbiK3Tbv (ORCPT + 83 others); Wed, 30 Nov 2022 14:31:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbiK3Tbu (ORCPT ); Wed, 30 Nov 2022 14:31:50 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85FAF86A14 for ; Wed, 30 Nov 2022 11:31:49 -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 1FEF461D96 for ; Wed, 30 Nov 2022 19:31:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 264D8C4347C for ; Wed, 30 Nov 2022 19:31:48 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="HMBhsAXD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1669836706; 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=8ScMaAIgcavRwlnc4K5Bo/PJrf8VIf6mrT3T2oiNawk=; b=HMBhsAXD/2ls5hHnyzrHsZvKaX/qCCBffiYotopqAyrtFIDFROcOxzr8Uk0ANLTiOApN2r 5Qxb+6ZD/hKMXj4eceBkY8IYC8F3i5AhQojD9sc920IADnc3vUI9aeY8fbtLYblhWHKY9g AP3+6/l40UZOJ4OGTGxSwI1/43q02yw= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 5d16cd9d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 30 Nov 2022 19:31:45 +0000 (UTC) Received: by mail-vs1-f44.google.com with SMTP id m4so18354225vsc.6 for ; Wed, 30 Nov 2022 11:31:45 -0800 (PST) X-Gm-Message-State: ANoB5pmeBIcStCwrErBDJHMUwa1kSJnSpHcV3QG3T6cRG15SLaly4V9Q eGGHEV8VpHwMWM6cMjMyBB0X9HdrDKxQVJlt+uQ= X-Received: by 2002:a05:6102:30bc:b0:3b0:93af:fc3f with SMTP id y28-20020a05610230bc00b003b093affc3fmr10983840vsd.55.1669836704982; Wed, 30 Nov 2022 11:31:44 -0800 (PST) MIME-Version: 1.0 References: <20221130020815.283814-1-Jason@zx2c4.com> In-Reply-To: From: "Jason A. Donenfeld" Date: Wed, 30 Nov 2022 20:31:33 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] random: align entropy_timer_state to cache line To: Eric Biggers Cc: linux-kernel@vger.kernel.org, Sultan Alsawaf Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, 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 7:59 PM Eric Biggers wrote: > > 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... The really pathological one would be ~48, which would just clear those two extra bits. I can't imagine gcc or clang ever deciding to do that. But I guess they could? What would you recommend here? kmalloc'ing it instead? Keeping things as is with ____cacheline_aligned, since this has always been broken, and it's not the end of the world? Something else? Jason