Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp177623pxb; Wed, 11 Nov 2020 00:22:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJxBXuUGxKQtDg6MApLLRvlu0XTjQWYpX/7rxE4G3JagKm9+YDimdrpv9Fb3xRoRmgZ+67/n X-Received: by 2002:a05:6402:c8d:: with SMTP id cm13mr3584854edb.340.1605082923775; Wed, 11 Nov 2020 00:22:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605082923; cv=none; d=google.com; s=arc-20160816; b=axFFnjLLEIe5SBOmQmwNCRuuALui6MLn+qcOemUn9tbSmTKUwtja+rsFBZv91Kyf1+ SYaEjT+yhxeFNXZb4DDTCRbUb4MYZptQcwYUaSNoqa37TOPWJ93RPigSMgHeZ8NEtF/v lo47R9nC2MOemXgwIOdgVMV78mpgtl205Tuw/0/XuKOV3UF584H+s+3/0uiUFzUpjYpk 1dWuLm3CSC0Fv9Oy+NgbGL52BXVh0KZf6eFprkvtAbjr+H5CiGpG/tpMuV/Vof8t5npo lGb7E/l6pTJqLd9FPSBB0u8nfqieQXw4HfMm+wwysjB9YQzRBqqHinIX0TKTHqlSFxlX qBmQ== 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=yjjKth6zUJP5F1i3BUaquLgciG+Jb2eWJBgXRFNttDc=; b=ev36rCdc93p6gfNVEP3ONslLuXx9V1beAmZnjcbtC3osmgZH3L1Kt5oXFbVDRu3SSa qssBaz8/h12dSjZjjVa64IQO9K+wug5P2UeWnKKo70kqV1Z02xzMipcXWgivwd2X7qG1 D/vP9xQ5+3JiCPEqFMqw3/l6WmhGwIOKnMyPyC2U3BTieuecZma7SfVk09LgS1vI63ym KAiuNUUWxlNhqpLEDc4QhtBwc02pqO/+OV2mhjgPGmGnpC1dGgzBTPg+7tShoTW63z/6 8+8Ym3rEZSZCII0VEhqGZ/xbkyUQH7kxuE9OZerQMJ/QovKLvIRtW2O0FOdL3gXfqrUh G2IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KA7zNR+u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id co26si998997edb.209.2020.11.11.00.21.39; Wed, 11 Nov 2020 00:22:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KA7zNR+u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726038AbgKKITw (ORCPT + 99 others); Wed, 11 Nov 2020 03:19:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:33378 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725922AbgKKITv (ORCPT ); Wed, 11 Nov 2020 03:19:51 -0500 Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7389D206F1 for ; Wed, 11 Nov 2020 08:19:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605082790; bh=ZZg3ce0I9kb7RvrZB81ioGubRheIgY8FQSfSNiZ77ls=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=KA7zNR+ubQoN49Cidw7v0kyFL1RV4hqeOfWOUUy8k0zLXcnHBDrSh1juS1onz6nr1 fmQAedlr+XCWr/iqLaS4ahSDvlu63cPk3FgPvgW4n5xQWEjDPvrIVpTTDRRc7aQkMF zwI8oXB3yWva+nAQpQ9s4zHAdrR4G6x4mB09FIlc= Received: by mail-oi1-f169.google.com with SMTP id q206so1253334oif.13 for ; Wed, 11 Nov 2020 00:19:50 -0800 (PST) X-Gm-Message-State: AOAM531N0+y6xOhIvErmlWtgMIhsQPm8a2heK+oIYVWfTWmtQoiZqp8t XH+S3oKLeb4+UP4CgTKemUFjcKqJRmdvapPdiig= X-Received: by 2002:aca:c60c:: with SMTP id w12mr1550315oif.174.1605082789688; Wed, 11 Nov 2020 00:19:49 -0800 (PST) MIME-Version: 1.0 References: <20201105152944.16953-1-ardb@kernel.org> In-Reply-To: <20201105152944.16953-1-ardb@kernel.org> From: Ard Biesheuvel Date: Wed, 11 Nov 2020 09:19:37 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] random: avoid arch_get_random_seed_long() when collecting IRQ randomness To: "Theodore Y. Ts'o" , Eric Biggers Cc: Linux Kernel Mailing List , Linux ARM , Marc Zyngier , Mark Rutland , Mark Brown , Andre Przywara Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org (+ Eric) On Thu, 5 Nov 2020 at 16:29, Ard Biesheuvel wrote: > > When reseeding the CRNG periodically, arch_get_random_seed_long() is > called to obtain entropy from an architecture specific source if one > is implemented. In most cases, these are special instructions, but in > some cases, such as on ARM, we may want to back this using firmware > calls, which are considerably more expensive. > > Another call to arch_get_random_seed_long() exists in the CRNG driver, > in add_interrupt_randomness(), which collects entropy by capturing > inter-interrupt timing and relying on interrupt jitter to provide > random bits. This is done by keeping a per-CPU state, and mixing in > the IRQ number, the cycle counter and the return address every time an > interrupt is taken, and mixing this per-CPU state into the entropy pool > every 64 invocations, or at least once per second. The entropy that is > gathered this way is credited as 1 bit of entropy. Every time this > happens, arch_get_random_seed_long() is invoked, and the result is > mixed in as well, and also credited with 1 bit of entropy. > > This means that arch_get_random_seed_long() is called at least once > per second on every CPU, which seems excessive, and doesn't really > scale, especially in a virtualization scenario where CPUs may be > oversubscribed: in cases where arch_get_random_seed_long() is backed > by an instruction that actually goes back to a shared hardware entropy > source (such as RNDRRS on ARM), we will end up hitting it hundreds of > times per second. > > So let's drop the call to arch_get_random_seed_long() from > add_interrupt_randomness(), and instead, rely on crng_reseed() to call > the arch hook to get random seed material from the platform. > > Signed-off-by: Ard Biesheuvel > --- > drivers/char/random.c | 15 +-------------- > 1 file changed, 1 insertion(+), 14 deletions(-) > > diff --git a/drivers/char/random.c b/drivers/char/random.c > index 2a41b21623ae..a9c393c1466d 100644 > --- a/drivers/char/random.c > +++ b/drivers/char/random.c > @@ -1261,8 +1261,6 @@ void add_interrupt_randomness(int irq, int irq_flags) > cycles_t cycles = random_get_entropy(); > __u32 c_high, j_high; > __u64 ip; > - unsigned long seed; > - int credit = 0; > > if (cycles == 0) > cycles = get_reg(fast_pool, regs); > @@ -1298,23 +1296,12 @@ void add_interrupt_randomness(int irq, int irq_flags) > > fast_pool->last = now; > __mix_pool_bytes(r, &fast_pool->pool, sizeof(fast_pool->pool)); > - > - /* > - * If we have architectural seed generator, produce a seed and > - * add it to the pool. For the sake of paranoia don't let the > - * architectural seed generator dominate the input from the > - * interrupt noise. > - */ > - if (arch_get_random_seed_long(&seed)) { > - __mix_pool_bytes(r, &seed, sizeof(seed)); > - credit = 1; > - } > spin_unlock(&r->lock); > > fast_pool->count = 0; > > /* award one bit for the contents of the fast pool */ > - credit_entropy_bits(r, credit + 1); > + credit_entropy_bits(r, 1); > } > EXPORT_SYMBOL_GPL(add_interrupt_randomness); > > -- > 2.17.1 >