Module Name:    src
Committed By:   riastradh
Date:           Wed Mar 16 23:56:55 UTC 2022

Modified Files:
        src/sys/kern: kern_entropy.c

Log Message:
entropy(9): Forbid entropy_extract in hard interrupt context.

With a little additional work, this will let us reduce the global
entropy pool lock so it never blocks interrupts.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/kern/kern_entropy.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_entropy.c
diff -u src/sys/kern/kern_entropy.c:1.34 src/sys/kern/kern_entropy.c:1.35
--- src/sys/kern/kern_entropy.c:1.34	Fri Mar  4 21:12:03 2022
+++ src/sys/kern/kern_entropy.c	Wed Mar 16 23:56:55 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_entropy.c,v 1.34 2022/03/04 21:12:03 andvar Exp $	*/
+/*	$NetBSD: kern_entropy.c,v 1.35 2022/03/16 23:56:55 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.34 2022/03/04 21:12:03 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.35 2022/03/16 23:56:55 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -211,9 +211,6 @@ EVCNT_ATTACH_STATIC(entropy_partial_evcn
 static struct evcnt entropy_consolidate_evcnt =
     EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "entropy", "consolidate");
 EVCNT_ATTACH_STATIC(entropy_consolidate_evcnt);
-static struct evcnt entropy_extract_intr_evcnt =
-    EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "entropy", "extract intr");
-EVCNT_ATTACH_STATIC(entropy_extract_intr_evcnt);
 static struct evcnt entropy_extract_fail_evcnt =
     EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "entropy", "extract fail");
 EVCNT_ATTACH_STATIC(entropy_extract_fail_evcnt);
@@ -1278,14 +1275,13 @@ entropy_extract(void *buf, size_t len, i
 		    "can't wait for entropy until warm");
 	}
 
+	/* Refuse to operate in interrupt context.  */
+	KASSERT(!cpu_intr_p());
+
 	/* Acquire the global lock to get at the global pool.  */
 	if (E->stage >= ENTROPY_WARM)
 		mutex_enter(&E->lock);
 
-	/* Count up request for entropy in interrupt context.  */
-	if (cpu_intr_p())
-		entropy_extract_intr_evcnt.ev_count++;
-
 	/* Wait until there is enough entropy in the system.  */
 	error = 0;
 	while (E->needed) {

Reply via email to