From patchwork Thu Oct 13 17:52:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 2184 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp408177wrs; Thu, 13 Oct 2022 11:03:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM64MyFLZsbOyyYhJOE59SAydUHcH2aUfQiRYZ20FHLajAsfU+YTkftoOoEm5l2JBFOKZVEh X-Received: by 2002:a17:90b:4b8e:b0:20a:f240:9b23 with SMTP id lr14-20020a17090b4b8e00b0020af2409b23mr1088694pjb.19.1665684188919; Thu, 13 Oct 2022 11:03:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665684188; cv=none; d=google.com; s=arc-20160816; b=UjKSTXjHjUaEuusBE+XFIfSJWkxoe/ryvBuQmZ0jnFnzce8ac8YqzWOdSzGiY/CK4x 9P7VdD689QGXuCAhPu5aHjOPOFRhlc6Wg2UsDw8DdsnX18nA3OUV/+jgkrCzapUqgwMi KmUYVL8M3768mdR/vhE7c1/UfWOUDYq8Ez8XjPueyqxV6Ux226UWdkaLLIvfH1RcWX92 cQpUER43WfXzoSU1ZZZrWnkG8cr73xfXtAZGRT+us5UHqvi6dR1lT/e8PyDDJl9POhxI +Qdt7N52ywbjGIZSJZFyxq39cyeEBMuuuKlnPlWWcbbYy/bhzpbx5JccZR1W3oUNjPbl 8MkQ== 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=be4krze8fi3jrAWps/1TqsPhv0IlBqBO/1heeMPclsY=; b=IAs/QzpdJdR8pwIoiiKDvSClpd2Vjki9pnSfpWH11QwyWaG97/NXlUxBNQuLWe8hOr 1yjGBKoQ4nZOuC1mj66Zc2DnX230ODkCn3FioG4c+JINaga3qCVd9TFwFqbnnNDPlA6O /IE+J+kNtwWF1eqYzJCpH1iPyO2yTrG+q76pEBgsbr41Fn8SIhMwM1IRMWM92i+c9Yns VcXcj4MIGEfRkfBoDuRDjS+ccM2gbUa+gHEJfgIcA+1j3iQhKYFLcNbzY7oEPk3Xfh8F he22Bi2aJjt2dquhxWrKfrqj74FJCF24gNQ5bHAWImjEB1D2d+3mmq7+76DBHVzL2H7w aAtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=X8kWtT6W; 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 s16-20020a63e810000000b0046248881576si80118pgh.157.2022.10.13.11.02.49; Thu, 13 Oct 2022 11:03:08 -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=X8kWtT6W; 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 S230433AbiJMSCL (ORCPT + 99 others); Thu, 13 Oct 2022 14:02:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230384AbiJMSBs (ORCPT ); Thu, 13 Oct 2022 14:01:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62595160EDF; Thu, 13 Oct 2022 11:01:25 -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 281516192D; Thu, 13 Oct 2022 17:57:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30B6EC433C1; Thu, 13 Oct 2022 17:57:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1665683855; bh=uIlkY5Zeiam6CYpFKVqUgIhLspxK9NxVICIPnnLsybs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X8kWtT6WKEzCMZbkPgJ82m8le34k7usL7pfm8iF1FVl1LOY5Hq2Yuf4yzZXGtCHy7 /rlH+71TLCAzLctgaME4w7oP06OyBAto8i5jKeB+xLF7nzYZw78KdupufLHPGMfqRj mbSjeSJOhOx8vb4PovHiw8TI5mMHGhDtX85hzVYs= 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.15 14/27] random: avoid reading two cache lines on irq randomness Date: Thu, 13 Oct 2022 19:52:43 +0200 Message-Id: <20221013175144.060241859@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221013175143.518476113@linuxfoundation.org> References: <20221013175143.518476113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746596464121320055?= X-GMAIL-MSGID: =?utf-8?q?1746596464121320055?= 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 @@ -894,10 +894,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) = {