Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5496193pxb; Mon, 7 Feb 2022 03:26:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJy2l105BBrZg/B2tLK+/ssb2drP9ZqCYhiACPIhZYS5gWNnbeXtPDu4iuEdjUaDgi3RcI1V X-Received: by 2002:a17:906:e13:: with SMTP id l19mr6492368eji.663.1644233191376; Mon, 07 Feb 2022 03:26:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644233191; cv=none; d=google.com; s=arc-20160816; b=P67JrI3LxP8RcVdnNejeNCWQO6DD38pC4AI56CjkSaP3KZvvxSU6LMLttwbhQ3Jrv+ wLKc/b/hryupYYOWJR5+ZW0GMcyvn8PPErU25NbVK9FqW14oxJ5NHMY3keLBNlOyfXgc 7RMN+7d3sP+zaeS03pVVemrCqSQUTblm0+jLsi/N4M0p05hlyM3hU3k+dopn6Z2q2Ejj +fula4RZjBXwpbIFvTxId+hdDarExbZC2vTjM/UAEmiU39tPX2sfQo/NK+66rs+Ru5y7 bQ/rNQYJK0c5JIB6QOrYeTwLN97Oy1oCP3oTWlusTDZ65B1p5Ichr/VFZU4BuqFQyd3U 3TxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature :dkim-signature:date; bh=hDCDwd0y2NgSOR54H9+IbLHkGAL+jpOQY8wyAtyMNj4=; b=Q5cQs85FDp64HZpGeg/vM9Zw3buhgoOFjpEE2CDHqcUmuWBTzeIyT3UeoZmwKA6VIx AMxFrCJK7qcDnXD50lDPJIDWOffWqUItEQnElRusz/jE9307wUi5R2eZld98+7zUo7GB J4p4TsCmYbYX65dfZ3Y/0GoibYiPix2nWqN7zbfr7EDe5DcTixC+Xz1SHIefLsRf02ny MU9h8wYBUvQSU13iHXTWNhqjzocJGs3/iYKf0xo+hWPeGfUosrPSNPRboVf9MF9CzpGK T+naHTOv6Es3Zftg1nu7ncoKcy+XchiDel6WzqLz7i9GwFMDIHDIBrGvWxqIuXGrjEzG kcQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=C6gRMjuz; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id do2si7345288ejc.362.2022.02.07.03.26.06; Mon, 07 Feb 2022 03:26:31 -0800 (PST) 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=@linutronix.de header.s=2020 header.b=C6gRMjuz; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238197AbiBDUxP (ORCPT + 99 others); Fri, 4 Feb 2022 15:53:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232318AbiBDUxO (ORCPT ); Fri, 4 Feb 2022 15:53:14 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DAD2C061714 for ; Fri, 4 Feb 2022 12:53:13 -0800 (PST) Date: Fri, 4 Feb 2022 21:53:10 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1644007992; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hDCDwd0y2NgSOR54H9+IbLHkGAL+jpOQY8wyAtyMNj4=; b=C6gRMjuzFom8pMLjwzorR1XCA+N9MoJHuvsUtNGiWAbj5Wl5bCgrQ7bwWQp7eU7ryCnj3/ e6o2U+Dh/qoqFgtO6D2JMsLfeQMwm9fR+MEmBy8MtouTawh5cuOysZe7hrwlyJZVBGCTbN zsvht9Imt4Ox4+g50E0b09Kon5qX+DB6YDgcGbBfs49oBE7eaUq/1wVEVqSv1xWCskQE8f QgKneQ662a+dZ7c0f6J3qhdlwndWHwpgAHj40MtfsL9/DyyGUZGHh/FUKqXSViBEFObZy9 5VOVg2viC09SeeOJ9Lb/6bdnMjXx7tVjp+cyU5/RthDbwEivlQrqCopZ7ey4Kg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1644007992; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hDCDwd0y2NgSOR54H9+IbLHkGAL+jpOQY8wyAtyMNj4=; b=I7W8pJUIcCPYYzOBZc3GAc5J1KSZX0VrHDEEjpHXiI7/CZfLhanFSQ5A9q+39X8rwxLsKJ vlfgevCC97jIRzBw== From: Sebastian Andrzej Siewior To: "Jason A. Donenfeld" Cc: LKML , Thomas Gleixner , Peter Zijlstra , Theodore Ts'o , Sultan Alsawaf , Jonathan =?utf-8?Q?Neusch=C3=A4fer?= Subject: Re: [PATCH RFC v1] random: do not take spinlocks in irq handler Message-ID: References: <20220204153149.51428-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 On 2022-02-04 16:58:58 [+0100], Jason A. Donenfeld wrote: > FWIW, the biggest issue with this > > On Fri, Feb 4, 2022 at 4:32 PM Jason A. Donenfeld wrote: > > +static void mix_interrupt_randomness(struct work_struct *work) > > +{ > [...] > > + if (unlikely(crng_init == 0)) { > > + if (crng_fast_load((u8 *)&fast_pool->pool, sizeof(fast_pool->pool)) > 0) > > + atomic_set(&fast_pool->count, 0); > > + else > > + atomic_and(~FAST_POOL_MIX_INFLIGHT, &fast_pool->count); > > + return; > > + } > [...] > > void add_interrupt_randomness(int irq) > > - if (unlikely(crng_init == 0)) { > > - if ((fast_pool->count >= 64) && > > - crng_fast_load((u8 *)fast_pool->pool, sizeof(fast_pool->pool)) > 0) { > > - fast_pool->count = 0; > > - fast_pool->last = now; > > - } > > - return; > > The point of crng_fast_load is to shuffle bytes into the crng as fast > as possible for very early boot usage. Deferring that to a workqueue > seems problematic. So I think at the very least _that_ part will have > to stay in the IRQ handler. That means we've still got a spinlock. But > at least it's a less problematic one than the input pool spinlock, and > perhaps we can deal with that some other way than this patch's > approach. RT wise we _could_ acquire that spinlock_t in IRQ context early during boot as long as system_state < SYSTEM_SCHEDULING. After that, we could dead lock. > In other words, this approach for the calls to mix_pool_bytes, and a > different approach for that call to crng_fast_load. > > Jason Sebastian