Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/ic tpm(4): Fix disabling of rnd source if tpm is dea...
details: https://anonhg.NetBSD.org/src/rev/572a31a35b24
branches: trunk
changeset: 1029075:572a31a35b24
user: riastradh <riastradh%NetBSD.org@localhost>
date: Mon Dec 20 23:05:55 2021 +0000
description:
tpm(4): Fix disabling of rnd source if tpm is deactivated.
Nothing prevents a second worker from being queued when the first one
is about to do rnd_detach_source. Instead, just set a flag so future
requests don't bother running a new thread; if there's a concurrent
one that's already been scheduled on another CPU, well, too bad, we
get a couple extra log messages but that's fine.
A better way to do this would probably be to detect whether the tpm
is deactivated at attach time, but that requires reading more of the
tpm spec than I care to do when there are alternative ways to
procrastinate like scrubbing the toilet.
diffstat:
sys/dev/ic/tpm.c | 8 +++++---
sys/dev/ic/tpmvar.h | 3 ++-
2 files changed, 7 insertions(+), 4 deletions(-)
diffs (53 lines):
diff -r b5d323bd28da -r 572a31a35b24 sys/dev/ic/tpm.c
--- a/sys/dev/ic/tpm.c Mon Dec 20 22:40:46 2021 +0000
+++ b/sys/dev/ic/tpm.c Mon Dec 20 23:05:55 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tpm.c,v 1.22 2021/06/02 21:35:17 riastradh Exp $ */
+/* $NetBSD: tpm.c,v 1.23 2021/12/20 23:05:55 riastradh Exp $ */
/*
* Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.22 2021/06/02 21:35:17 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.23 2021/12/20 23:05:55 riastradh Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -650,7 +650,7 @@
*/
if (rv) {
device_printf(sc->sc_dev, "deactivating entropy source\n");
- rnd_detach_source(&sc->sc_rnd);
+ atomic_store_relaxed(&sc->sc_rnddisabled, true);
/* XXX worker thread can't workqueue_destroy its own queue */
}
@@ -666,6 +666,8 @@
{
struct tpm_softc *sc = cookie;
+ if (atomic_load_relaxed(&sc->sc_rnddisabled))
+ return; /* tough */
if (atomic_swap_uint(&sc->sc_rndpending, MIN(nbytes, UINT_MAX/NBBY))
== 0)
workqueue_enqueue(sc->sc_rndwq, &sc->sc_rndwk, NULL);
diff -r b5d323bd28da -r 572a31a35b24 sys/dev/ic/tpmvar.h
--- a/sys/dev/ic/tpmvar.h Mon Dec 20 22:40:46 2021 +0000
+++ b/sys/dev/ic/tpmvar.h Mon Dec 20 23:05:55 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tpmvar.h,v 1.9 2021/01/04 18:26:59 riastradh Exp $ */
+/* $NetBSD: tpmvar.h,v 1.10 2021/12/20 23:05:55 riastradh Exp $ */
/*
* Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -98,6 +98,7 @@
struct workqueue *sc_rndwq;
struct work sc_rndwk;
volatile unsigned sc_rndpending;
+ bool sc_rnddisabled;
};
bool tpm_suspend(device_t, const pmf_qual_t *);
Home |
Main Index |
Thread Index |
Old Index