Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Revert "entropy(9): Nix rnd_trylock_sources."
details: https://anonhg.NetBSD.org/src/rev/ee7502a01d4c
branches: trunk
changeset: 364390:ee7502a01d4c
user: riastradh <riastradh%NetBSD.org@localhost>
date: Sun Mar 20 14:05:41 2022 +0000
description:
Revert "entropy(9): Nix rnd_trylock_sources."
Not a premature optimization after all -- this is necessary because
entropy_request can run in softint context, where the cv_wait_sig in
rnd_lock_sources is forbidden. Need to do this another way.
diffstat:
sys/kern/kern_entropy.c | 37 +++++++++++++++++++++++++++++--------
1 files changed, 29 insertions(+), 8 deletions(-)
diffs (68 lines):
diff -r 44725368cc64 -r ee7502a01d4c sys/kern/kern_entropy.c
--- a/sys/kern/kern_entropy.c Sun Mar 20 13:44:18 2022 +0000
+++ b/sys/kern/kern_entropy.c Sun Mar 20 14:05:41 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_entropy.c,v 1.47 2022/03/20 13:44:18 riastradh Exp $ */
+/* $NetBSD: kern_entropy.c,v 1.48 2022/03/20 14:05:41 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.47 2022/03/20 13:44:18 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_entropy.c,v 1.48 2022/03/20 14:05:41 riastradh Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -1702,10 +1702,30 @@
}
/*
+ * rnd_trylock_sources()
+ *
+ * Try to lock the list of sources, but if it's already locked,
+ * fail. Caller must hold the global entropy lock. If
+ * successful, no rndsource will go away until rnd_unlock_sources
+ * even while the caller releases the global entropy lock.
+ */
+static bool
+rnd_trylock_sources(void)
+{
+
+ KASSERT(E->stage == ENTROPY_COLD || mutex_owned(&E->lock));
+
+ if (E->sourcelock)
+ return false;
+ E->sourcelock = curlwp;
+ return true;
+}
+
+/*
* rnd_unlock_sources()
*
- * Unlock the list of sources after rnd_lock_sources. Caller must
- * hold the global entropy lock.
+ * Unlock the list of sources after rnd_lock_sources or
+ * rnd_trylock_sources. Caller must hold the global entropy lock.
*/
static void
rnd_unlock_sources(void)
@@ -1748,11 +1768,12 @@
KASSERT(E->stage == ENTROPY_COLD || mutex_owned(&E->lock));
/*
- * Lock the list of entropy sources to block rnd_detach_source
- * until we're done, and to serialize calls to the entropy
- * callbacks as guaranteed to drivers.
+ * If there is a request in progress, let it proceed.
+ * Otherwise, note that a request is in progress to avoid
+ * reentry and to block rnd_detach_source until we're done.
*/
- rnd_lock_sources();
+ if (!rnd_trylock_sources())
+ return;
entropy_request_evcnt.ev_count++;
/* Clamp to the maximum reasonable request. */
Home |
Main Index |
Thread Index |
Old Index