From patchwork Mon Oct 24 11:29:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8413 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp400181wru; Mon, 24 Oct 2022 04:46:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4CV+g9SogieDEnf8auZPGqNt7YYJ56hsP3xNf9Iffl4EKRU+3ax/MDZYtQCSi7hYw4Ca0A X-Received: by 2002:a17:907:7203:b0:7a5:b062:2338 with SMTP id dr3-20020a170907720300b007a5b0622338mr5978492ejc.8.1666611991299; Mon, 24 Oct 2022 04:46:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666611991; cv=none; d=google.com; s=arc-20160816; b=t6sVk+dkLamkoUnO6PUMSiWyK2jqJbJusIO2LGX2Qws6ExieJpw4ncC6KDfDAqbJkx 0BYFroX/6OVTcGt6Lse688tTd1rhOHQqFz8IKJPbnITjHwsdEiRmqQajwAk5stEoW21F 1/oRDxRca+x/Y33z91y2g6UiFdHsHFDzR1RUqUQQwOe2cCeEHZu/qchY2fAKAmVG4UwR GOtnZv6EzJk+WJ1VD7Cc+ey090evdoVX25qhfHXl9NVipRoaaqThgkD2nr8wrFiyBcDo u7zAKrv5PX7Y4wC5dkBOt0dGkooxzy14zAPf8aGJqeHSynb45LgHT26lbagj+9BJ2VDQ uZqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SxJP2RhnXZfsR6nKWVHDhJ8EImfh03iiuzd0AqNkBgI=; b=Kozuogxl7DRV80mORnJkuDIS32/EzfmxE0tesUBqBVbqNTSmGjI6+2mCastD4uw9vM +hK5cF6T34Z1qcWYNBsPfeHlNxVnjBik9zGKl9bYn02iU6iW1QeE8UluOMfutu5HmnpA zFAk4GlbU0mLkPxrhQmdYNrBVhyscgpALhkcFKQGY9jwYCPMsMqlqoNTzAXEHTTkrwv+ rkEc+GnbFoboxrzqu4WkdihunlgDytImfPq2il7fDB1DlNK4mDefQGll8o75plnM/awE c5VR1rhSaq26cdiu+5SVmdpOwa0xqEOv9Ut3r5lE1fKEv23aFMXubCRzt+6M3TJp86l4 /D5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="a/QMcWoX"; 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=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dt19-20020a170907729300b0078168566b26si27647617ejc.356.2022.10.24.04.46.06; Mon, 24 Oct 2022 04:46:31 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b="a/QMcWoX"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231489AbiJXLpk (ORCPT + 99 others); Mon, 24 Oct 2022 07:45:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231573AbiJXLoC (ORCPT ); Mon, 24 Oct 2022 07:44:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 636E873C23; Mon, 24 Oct 2022 04:41:24 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 5DA5561278; Mon, 24 Oct 2022 11:39:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CEF8C433D7; Mon, 24 Oct 2022 11:39:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611588; bh=0uhDIdfk1epcziMHFK+ZKD1E2NsUZQU+n1FAp35sSls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a/QMcWoXEiUs/kSOhgiA93hC7/VVYohdgIvVsWfhJsjF+f64RC7hSnJ5F5fqGR9IQ pgO+fKt7tqt9jPawRqn2qi7dzSZ+pjopOcYHWjVe/Zc+MbF6iJ4mzasTQkSNEDKhfn mpnmRyOASCzTXXBEmDsfsvDnup95kFXYwTCde/pc= 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 4.9 035/159] random: avoid reading two cache lines on irq randomness Date: Mon, 24 Oct 2022 13:29:49 +0200 Message-Id: <20221024112950.680129573@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747569335520964464?= X-GMAIL-MSGID: =?utf-8?q?1747569335520964464?= 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 @@ -891,10 +891,10 @@ void __init add_bootloader_randomness(co } struct fast_pool { - struct work_struct mix; unsigned long pool[4]; unsigned long last; unsigned int count; + struct work_struct mix; }; static DEFINE_PER_CPU(struct fast_pool, irq_randomness) = {