[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Ygaa89GFi1VAQmsk@sultan-box.localdomain>
Date: Fri, 11 Feb 2022 09:20:51 -0800
From: Sultan Alsawaf <sultan@...neltoast.com>
To: "Jason A. Donenfeld" <Jason@...c4.com>
Cc: Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
LKML <linux-kernel@...r.kernel.org>,
Linux Crypto Mailing List <linux-crypto@...r.kernel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Peter Zijlstra <peterz@...radead.org>,
Theodore Ts'o <tytso@....edu>,
Jonathan Neuschäfer <j.neuschaefer@....net>,
Dominik Brodowski <linux@...inikbrodowski.net>
Subject: Re: [PATCH v7] random: defer fast pool mixing to worker
On Fri, Feb 11, 2022 at 06:07:32PM +0100, Jason A. Donenfeld wrote:
> On PREEMPT_RT, it's problematic to take spinlocks from hard irq
> handlers. We can fix this by deferring to a workqueue the dumping of
> the fast pool into the input pool.
>
> We accomplish this with some careful rules on fast_pool->count:
>
> - When it's incremented to >= 64, we schedule the work.
> - If the top bit is set, we never schedule the work, even if >= 64.
> - The worker is responsible for setting it back to 0 when it's done.
>
> There are two small issues around using workqueues for this purpose that
> we work around.
>
> The first issue is that mix_interrupt_randomness() might be migrated to
> another CPU during CPU hotplug. This issue is rectified by checking that
> it hasn't been migrated (after disabling irqs). If it has been migrated,
> then we set the count to zero, so that when the CPU comes online again,
> it can requeue the work. As part of this, we switch to using an
> atomic_t, so that the increment in the irq handler doesn't wipe out the
> zeroing if the CPU comes back online while this worker is running.
>
> The second issue is that, though relatively minor in effect, we probably
> want to make sure we get a consistent view of the pool onto the stack,
> in case it's interrupted by an irq while reading. To do this, we don't
> reenable irqs until after the copy. There are only 18 instructions
> between the cli and sti, so this is a pretty tiny window.
>
> Cc: Sebastian Andrzej Siewior <bigeasy@...utronix.de>
> Cc: Thomas Gleixner <tglx@...utronix.de>
> Cc: Peter Zijlstra <peterz@...radead.org>
> Cc: Theodore Ts'o <tytso@....edu>
> Cc: Sultan Alsawaf <sultan@...neltoast.com>
> Cc: Jonathan Neuschäfer <j.neuschaefer@....net>
> Reviewed-by: Dominik Brodowski <linux@...inikbrodowski.net>
> Signed-off-by: Jason A. Donenfeld <Jason@...c4.com>
> ---
> Sebastian - as requested, we now disable irqs for a very short 18
> instructions rather than fishing into migrate_disable() and upsetting
> PeterZ. Might this be the lucky patch? -Jason
I think this might be the lucky patch.
Reviewed-by: Sultan Alsawaf <sultan@...neltoast.com>
Sultan
Powered by blists - more mailing lists