Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp6144449iog; Thu, 23 Jun 2022 12:15:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sj4ysy9FXN6fQ9wJYe3LMi065kOUWaPN3Uh2MAjDWBbMYi4dwq5wcxdXGmeG+buTKKWOpC X-Received: by 2002:a17:90b:1644:b0:1ec:e6d4:7931 with SMTP id il4-20020a17090b164400b001ece6d47931mr5552685pjb.105.1656011758847; Thu, 23 Jun 2022 12:15:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656011758; cv=none; d=google.com; s=arc-20160816; b=EAV+HCqKHXufVqpPn1DAABbpoRtdnM/6oSEe6P1a6N5Y8O9neiYwT5rtpfQ9tC+Mpy Q/ujB/cKnALNIqY9xjgehsNx5UjkmleS2/SyViomwKf5R8dDVh8qy/3n7CfJ4omfliGH NGvpgnu1SzumFSuUlj7oLNgBipydehOHpHin6Us4nLloURmUV7pT54iDq81NDG1bSODx Wx9pRmOEbdmYRy9d8j4F41eXSQE27R2W94hse7+9BG1TciSwV5N7qqZecPl9PANUG5bW 3uQ6yzXwnQCjTGBwCtuStuR/CZ5XKIzG8n0JoA7Ib5RxgzByWlqyZtUtYjJVz/GrjjqC 3S3Q== 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=xxeVo1RF1F87sq/FcBwQga8gb/WI8gHhEoSQD761+gg=; b=BAbJcs+Eh6g07gbDDpB5ZQ9ua6i0hvV2l/m8Dp4zf1ylOKhPNZkC5fES6b1ZndDrhV 7S9jp/KR+uqRf8nnXaysOSwD/H7LTlaazlij8ycxf/jyNReR17rApc8aPuwyxZqxSKuL hhYSbeflbTBM9fTFE7AcMnoo0rPMIWtIhVRgQZnkjhwNOcoO8at3O7w1ZvfQw7R2UmCY nhHpXuMR8IZlqmFddTmWao6zsiqQ6P4Dbna8fE4gU7B9oApSI3NTTFsdQmRalxmHmM02 ZSJmZJUB/skaCEi7fnEZ0Uj4nMb6Veprii7vnApzQtqAO8vC/h0H+VJgeJ9wIekcTLxQ yBqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ILtVAlOs; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w1-20020a63f501000000b003fe462f815csi29489662pgh.657.2022.06.23.12.15.47; Thu, 23 Jun 2022 12:15:58 -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=ILtVAlOs; 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 S236319AbiFWSLk (ORCPT + 99 others); Thu, 23 Jun 2022 14:11:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236317AbiFWSKI (ORCPT ); Thu, 23 Jun 2022 14:10:08 -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 8FAEBBC9A8; Thu, 23 Jun 2022 10:20:05 -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 CD35D61DB6; Thu, 23 Jun 2022 17:20:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C3417C3411B; Thu, 23 Jun 2022 17:20:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656004804; bh=7JqZO4gBFyYGQRpAT08nVxEHFtLtSadDB5BiDeLTUY0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ILtVAlOseBIELV0qYrtOx0nngbaddjCvFj8uQ56Q+qrDIO5mqxPuvM4G2EbbW3nXX n5eLwEiCGyp9cJ1TkbYHYnPk2ACWPNRXTQVGGw3P3fZOF8RdZqszGwaG00v+fFLdlG oFzayvj2GoFmswiWC2t9pleEhUSc5Vav0PfeC+x8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Jason A. Donenfeld" Subject: [PATCH 4.19 154/234] random: help compiler out with fast_mix() by using simpler arguments Date: Thu, 23 Jun 2022 18:43:41 +0200 Message-Id: <20220623164347.412717738@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623164343.042598055@linuxfoundation.org> References: <20220623164343.042598055@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 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,T_SCC_BODY_TEXT_LINE 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 From: "Jason A. Donenfeld" commit 791332b3cbb080510954a4c152ce02af8832eac9 upstream. Now that fast_mix() has more than one caller, gcc no longer inlines it. That's fine. But it also doesn't handle the compound literal argument we pass it very efficiently, nor does it handle the loop as well as it could. So just expand the code to spell out this function so that it generates the same code as it did before. Performance-wise, this now behaves as it did before the last commit. The difference in actual code size on x86 is 45 bytes, which is less than a cache line. Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1026,25 +1026,30 @@ static DEFINE_PER_CPU(struct fast_pool, * and therefore this has no security on its own. s represents the * four-word SipHash state, while v represents a two-word input. */ -static void fast_mix(unsigned long s[4], const unsigned long v[2]) +static void fast_mix(unsigned long s[4], unsigned long v1, unsigned long v2) { - size_t i; - - for (i = 0; i < 2; ++i) { - s[3] ^= v[i]; #ifdef CONFIG_64BIT - s[0] += s[1]; s[1] = rol64(s[1], 13); s[1] ^= s[0]; s[0] = rol64(s[0], 32); - s[2] += s[3]; s[3] = rol64(s[3], 16); s[3] ^= s[2]; - s[0] += s[3]; s[3] = rol64(s[3], 21); s[3] ^= s[0]; - s[2] += s[1]; s[1] = rol64(s[1], 17); s[1] ^= s[2]; s[2] = rol64(s[2], 32); +#define PERM() do { \ + s[0] += s[1]; s[1] = rol64(s[1], 13); s[1] ^= s[0]; s[0] = rol64(s[0], 32); \ + s[2] += s[3]; s[3] = rol64(s[3], 16); s[3] ^= s[2]; \ + s[0] += s[3]; s[3] = rol64(s[3], 21); s[3] ^= s[0]; \ + s[2] += s[1]; s[1] = rol64(s[1], 17); s[1] ^= s[2]; s[2] = rol64(s[2], 32); \ +} while (0) #else - s[0] += s[1]; s[1] = rol32(s[1], 5); s[1] ^= s[0]; s[0] = rol32(s[0], 16); - s[2] += s[3]; s[3] = rol32(s[3], 8); s[3] ^= s[2]; - s[0] += s[3]; s[3] = rol32(s[3], 7); s[3] ^= s[0]; - s[2] += s[1]; s[1] = rol32(s[1], 13); s[1] ^= s[2]; s[2] = rol32(s[2], 16); +#define PERM() do { \ + s[0] += s[1]; s[1] = rol32(s[1], 5); s[1] ^= s[0]; s[0] = rol32(s[0], 16); \ + s[2] += s[3]; s[3] = rol32(s[3], 8); s[3] ^= s[2]; \ + s[0] += s[3]; s[3] = rol32(s[3], 7); s[3] ^= s[0]; \ + s[2] += s[1]; s[1] = rol32(s[1], 13); s[1] ^= s[2]; s[2] = rol32(s[2], 16); \ +} while (0) #endif - s[0] ^= v[i]; - } + + s[3] ^= v1; + PERM(); + s[0] ^= v1; + s[3] ^= v2; + PERM(); + s[0] ^= v2; } #ifdef CONFIG_SMP @@ -1114,10 +1119,8 @@ void add_interrupt_randomness(int irq) struct pt_regs *regs = get_irq_regs(); unsigned int new_count; - fast_mix(fast_pool->pool, (unsigned long[2]){ - entropy, - (regs ? instruction_pointer(regs) : _RET_IP_) ^ swab(irq) - }); + fast_mix(fast_pool->pool, entropy, + (regs ? instruction_pointer(regs) : _RET_IP_) ^ swab(irq)); new_count = ++fast_pool->count; if (new_count & MIX_INFLIGHT) @@ -1157,8 +1160,7 @@ static void add_timer_randomness(struct * sometime after, so mix into the fast pool. */ if (in_irq()) { - fast_mix(this_cpu_ptr(&irq_randomness)->pool, - (unsigned long[2]){ entropy, num }); + fast_mix(this_cpu_ptr(&irq_randomness)->pool, entropy, num); } else { spin_lock_irqsave(&input_pool.lock, flags); _mix_pool_bytes(&entropy, sizeof(entropy));