LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] random: fix possible sleeping allocation from irq context
@ 2018-04-24  3:41 Theodore Ts'o
  2018-04-25  0:46 ` Tetsuo Handa
  0 siblings, 1 reply; 4+ messages in thread
From: Theodore Ts'o @ 2018-04-24  3:41 UTC (permalink / raw)
  To: penguin-kernel; +Cc: linux-kernel, stable, Theodore Ts'o

We can do a sleeping allocation from an irq context when CONFIG_NUMA
is enabled.  Fix this by initializing the NUMA crng instances in a
workqueue.

Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reported-by: syzbot+9de458f6a5e713ee8c1a@syzkaller.appspotmail.com
Fixes: 8ef35c866f8862df ("random: set up the NUMA crng instances...")
Cc: stable@vger.kernel.org
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
 drivers/char/random.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 3cd3aae24d6d..e182cca7e6cd 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -789,7 +789,7 @@ static void crng_initialize(struct crng_state *crng)
 }
 
 #ifdef CONFIG_NUMA
-static void numa_crng_init(void)
+static void do_numa_crng_init(struct work_struct *work)
 {
 	int i;
 	struct crng_state *crng;
@@ -810,6 +810,13 @@ static void numa_crng_init(void)
 		kfree(pool);
 	}
 }
+
+DECLARE_WORK(numa_crng_init_work, do_numa_crng_init);
+
+static void numa_crng_init(void)
+{
+	schedule_work(&numa_crng_init_work);
+}
 #else
 static void numa_crng_init(void) {}
 #endif
-- 
2.16.1.72.g5be1f00a9a

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] random: fix possible sleeping allocation from irq context
  2018-04-24  3:41 [PATCH] random: fix possible sleeping allocation from irq context Theodore Ts'o
@ 2018-04-25  0:46 ` Tetsuo Handa
  2018-04-25  6:00   ` Theodore Y. Ts'o
  0 siblings, 1 reply; 4+ messages in thread
From: Tetsuo Handa @ 2018-04-25  0:46 UTC (permalink / raw)
  To: "\"Theodore Ts'o\""; +Cc: linux-kernel, stable

Theodore Ts\'o wrote:
> We can do a sleeping allocation from an irq context when CONFIG_NUMA
> is enabled.  Fix this by initializing the NUMA crng instances in a
> workqueue.

Offloading to workqueue context itself would be OK,
but this patch makes linux.git unbootable because

	if (crng == &primary_crng && crng_init < 2) {
		invalidate_batched_entropy();
		numa_crng_init(); // <= Deferred to workqueue context.
		crng_init = 2; // <= Not waiting for workqueue context, and oops before console becomes ready. ;-)
		process_random_ready_list();
		wake_up_interruptible(&crng_init_wait);
		pr_notice(\"random: crng init done\\n\");
	}

Please don\'t pretend rng_ready() before workqueue context is processed.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] random: fix possible sleeping allocation from irq context
  2018-04-25  0:46 ` Tetsuo Handa
@ 2018-04-25  6:00   ` Theodore Y. Ts'o
  2018-04-25 10:47     ` Tetsuo Handa
  0 siblings, 1 reply; 4+ messages in thread
From: Theodore Y. Ts'o @ 2018-04-25  6:00 UTC (permalink / raw)
  To: Tetsuo Handa; +Cc: linux-kernel, stable

On Wed, Apr 25, 2018 at 09:46:42AM +0900, Tetsuo Handa wrote:
> Theodore Ts\'o wrote:
> > We can do a sleeping allocation from an irq context when CONFIG_NUMA
> > is enabled.  Fix this by initializing the NUMA crng instances in a
> > workqueue.
> 
> Offloading to workqueue context itself would be OK,
> but this patch makes linux.git unbootable because
> 
> 	if (crng == &primary_crng && crng_init < 2) {
> 		invalidate_batched_entropy();
> 		numa_crng_init(); // <= Deferred to workqueue context.
> 		crng_init = 2; // <= Not waiting for workqueue context, and oops before console becomes ready. ;-)
> 		process_random_ready_list();
> 		wake_up_interruptible(&crng_init_wait);
> 		pr_notice(\"random: crng init done\\n\");
> 	}
> 
> Please don\'t pretend rng_ready() before workqueue context is processed.

Where's the oops?  It's not oopsing for me, and if the NUMA crng is
not initailized, the code in extract_entropy returns falls back to
using the primary_crng:

static void extract_crng(__u32 out[CHACHA20_BLOCK_WORDS])
{
	struct crng_state *crng = NULL;

#ifdef CONFIG_NUMA
	if (crng_node_pool)
		crng = crng_node_pool[numa_node_id()];
	if (crng == NULL)
#endif
		crng = &primary_crng;
	_extract_crng(crng, out);
}

						- Ted
						

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] random: fix possible sleeping allocation from irq context
  2018-04-25  6:00   ` Theodore Y. Ts'o
@ 2018-04-25 10:47     ` Tetsuo Handa
  0 siblings, 0 replies; 4+ messages in thread
From: Tetsuo Handa @ 2018-04-25 10:47 UTC (permalink / raw)
  To: tytso; +Cc: linux-kernel, stable

Theodore Y. Ts'o wrote:
> On Wed, Apr 25, 2018 at 09:46:42AM +0900, Tetsuo Handa wrote:
> > Theodore Ts'o wrote:
> > > We can do a sleeping allocation from an irq context when CONFIG_NUMA
> > > is enabled.  Fix this by initializing the NUMA crng instances in a
> > > workqueue.
> > 
> > Offloading to workqueue context itself would be OK,
> > but this patch makes linux.git unbootable because
> > 
> > 	if (crng == &primary_crng && crng_init < 2) {
> > 		invalidate_batched_entropy();
> > 		numa_crng_init(); // <= Deferred to workqueue context.
> > 		crng_init = 2; // <= Not waiting for workqueue context, and oops before console becomes ready. ;-)
> > 		process_random_ready_list();
> > 		wake_up_interruptible(&crng_init_wait);
> > 		pr_notice("random: crng init done\n");
> > 	}
> > 
> > Please don't pretend rng_ready() before workqueue context is processed.
> 
> Where's the oops?

I assumed an oops happened, for the kernel did not start printing messages even
after 1 minute from guest's power on, and CPU usage (seen from host side) says
that 1 CPU is busy-looping; which is a phenomenon that the kernel panic()ed at
very early stage. And reverting only your patch solved the problem.

But I can no longer reproduce it. I should have saved the kernel config...
So, if nobody sees regression, please go with your patch.

-DECLARE_WORK(numa_crng_init_work, do_numa_crng_init);
+static DECLARE_WORK(numa_crng_init_work, do_numa_crng_init);

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-04-25 10:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-24  3:41 [PATCH] random: fix possible sleeping allocation from irq context Theodore Ts'o
2018-04-25  0:46 ` Tetsuo Handa
2018-04-25  6:00   ` Theodore Y. Ts'o
2018-04-25 10:47     ` Tetsuo Handa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).