From patchwork Mon Oct 24 11:29:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8532 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp416514wru; Mon, 24 Oct 2022 05:11:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM608ViqfDq0aWmR9ZCKbwRJ+MbXVy02BOmiac38acXe6098rx9fQcdsvYWVY8bZqgc7d7UT X-Received: by 2002:a05:6a02:18f:b0:44a:3972:898d with SMTP id bj15-20020a056a02018f00b0044a3972898dmr27584733pgb.525.1666613509400; Mon, 24 Oct 2022 05:11:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666613509; cv=none; d=google.com; s=arc-20160816; b=S6RKlTJ4reC3RTN45Buf3f2i/DylHijPh4jNsK+rxFd+JBFgNuglMGSghxyDB4emIo j5Z/XOHxm6hbhP/u6pnM8hg181ghKCZTlMQ0cyZmCLgM1rH9ytBpBeNzYOuOUcDgXCcw JxUOn59qGElWodz0dLUSHzOO0fSqK6sMqMJfj/ZbMXXxUmdQFka+ITRQbh78CiTaiVZH 9Axxwm2ZbGhIrXMOYleHTuFIvaRoE/GzwOeaUwP2q1kO2ODloi857Exv9Id7x3vgUZZ1 GW7cDqYHU9BPYKMyuD1hKZRKWfZFke16d3Any+uTEel1GlfEWcjdNEb2rgidSPLgKx+W V8bA== 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=WIR2DLtrEX0dj9NkuFSYbj1Dtbakne4q5wM7kqmAms0=; b=aEKF2KJlt9/xqzxfwycu1xYoD/NcAcf9hjxF6TKUgv2DqIsTaJeuWAFHT59XbFokpv A3gdUC7xt+Kkzi0uFeKqjODJnoRpvfGXGFAJnXu8Ed4CoG8cROxM4x1qg3O/vPlbizRk di1A2K3PgEb/MBGz0KTOJDiKlRoKPQiypS2u86XeWu3hf3DUFuN8z4Y1f6srcgoWg7tc OdzJvmX5GhH/CODQ8EhaNwA/DaK8+dAkCow36BB8I9WBSJgMogGKb8qMmYlecshuJOnx o2QLbI13f/w4J1gT7N2tZgwj2v9o4Otmz6jj2JQIFxb+zcs8vnh1BGC4NVeagc2xTToi YxyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mEepv6Hd; 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 v24-20020a17090a899800b0021311a385c3si2993440pjn.46.2022.10.24.05.11.31; Mon, 24 Oct 2022 05:11:49 -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=mEepv6Hd; 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 S232376AbiJXL6j (ORCPT + 99 others); Mon, 24 Oct 2022 07:58:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232372AbiJXL5p (ORCPT ); Mon, 24 Oct 2022 07:57:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FA3527CC0; Mon, 24 Oct 2022 04:47:15 -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 ams.source.kernel.org (Postfix) with ESMTPS id 66E76B8113E; Mon, 24 Oct 2022 11:47:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBFE0C433C1; Mon, 24 Oct 2022 11:47:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612033; bh=HvNQLbDFpQyKb6hj8OG6baMZ1QDProYxanDCjhbgJvM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mEepv6HdZeQNBz/rBs/aquBX05uRDqiFz/7Xuu2klhYj5/lCUyTtUlwZI01qqbnKQ IQRRVUVfYTu1W6ghmZIOVtAXm0QFNNRNpYqKnwBYdbT610uVzd1xpZNaEyW/Ht3vyH doMSIk39oT0yUjz4DgGIc9zfonSY0VipndQ+kySM= 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.14 045/210] random: avoid reading two cache lines on irq randomness Date: Mon, 24 Oct 2022 13:29:22 +0200 Message-Id: <20221024112958.456405677@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@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?1747570927323658904?= X-GMAIL-MSGID: =?utf-8?q?1747570927323658904?= 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 @@ -890,10 +890,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) = {