Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/ic rnd(9): Omit needless locks in various HWRNG driv...
details: https://anonhg.NetBSD.org/src/rev/a95f6bd3c5fa
branches: trunk
changeset: 364364:a95f6bd3c5fa
user: riastradh <riastradh%NetBSD.org@localhost>
date: Sat Mar 19 11:55:03 2022 +0000
description:
rnd(9): Omit needless locks in various HWRNG drivers.
Now that the rnd(9) API guarantees serial callbacks, we can simplify
everything a bit more.
(Some drivers like hifn(4) and sun8icrypto(4) still use locks to
coordinate with other parts of the driver to submit requests to and
process responses from the device.)
diffstat:
sys/arch/arm/broadcom/bcm2835_rng.c | 8 ++------
sys/arch/arm/omap/am335x_trng.c | 9 ++-------
sys/arch/arm/ti/ti_rng.c | 9 ++-------
sys/arch/mips/cavium/dev/octeon_rnm.c | 18 ++++--------------
sys/arch/mips/ingenic/ingenic_rng.c | 9 ++-------
sys/dev/ic/amdccp.c | 7 ++-----
sys/dev/ic/amdccpvar.h | 3 +--
sys/dev/ic/rng200.c | 7 +------
sys/dev/ic/rng200var.h | 3 +--
9 files changed, 17 insertions(+), 56 deletions(-)
diffs (truncated from 370 to 300 lines):
diff -r b25ffbb4e9db -r a95f6bd3c5fa sys/arch/arm/broadcom/bcm2835_rng.c
--- a/sys/arch/arm/broadcom/bcm2835_rng.c Sat Mar 19 11:54:53 2022 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_rng.c Sat Mar 19 11:55:03 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bcm2835_rng.c,v 1.16 2022/03/19 11:37:05 riastradh Exp $ */
+/* $NetBSD: bcm2835_rng.c,v 1.17 2022/03/19 11:55:03 riastradh Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_rng.c,v 1.16 2022/03/19 11:37:05 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_rng.c,v 1.17 2022/03/19 11:55:03 riastradh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -58,7 +58,6 @@
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
- kmutex_t sc_lock;
krndsource_t sc_rndsource;
};
@@ -121,7 +120,6 @@
bus_space_write_4(sc->sc_iot, sc->sc_ioh, RNG_CTRL, ctrl);
/* set up an rndsource */
- mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTSERIAL);
rndsource_setcb(&sc->sc_rndsource, &bcmrng_get, sc);
rnd_attach_source(&sc->sc_rndsource, device_xname(self), RND_TYPE_RNG,
RND_FLAG_COLLECT_VALUE|RND_FLAG_HASCB);
@@ -134,7 +132,6 @@
uint32_t status, cnt;
uint32_t buf[RNG_DATA_MAX]; /* 1k on the stack */
- mutex_enter(&sc->sc_lock);
while (bytes_wanted) {
status = bus_space_read_4(sc->sc_iot, sc->sc_ioh, RNG_STATUS);
cnt = __SHIFTOUT(status, RNG_STATUS_CNT);
@@ -148,5 +145,4 @@
bytes_wanted -= MIN(bytes_wanted, (cnt * 4));
}
explicit_memset(buf, 0, sizeof(buf));
- mutex_exit(&sc->sc_lock);
}
diff -r b25ffbb4e9db -r a95f6bd3c5fa sys/arch/arm/omap/am335x_trng.c
--- a/sys/arch/arm/omap/am335x_trng.c Sat Mar 19 11:54:53 2022 +0000
+++ b/sys/arch/arm/omap/am335x_trng.c Sat Mar 19 11:55:03 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: am335x_trng.c,v 1.4 2022/03/19 11:37:05 riastradh Exp $ */
+/* $NetBSD: am335x_trng.c,v 1.5 2022/03/19 11:55:03 riastradh Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: am335x_trng.c,v 1.4 2022/03/19 11:37:05 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: am335x_trng.c,v 1.5 2022/03/19 11:55:03 riastradh Exp $");
#include "opt_omap.h"
@@ -56,7 +56,6 @@
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
- kmutex_t sc_lock;
krndsource_t sc_rndsource;
};
@@ -99,8 +98,6 @@
return;
}
- mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTSERIAL);
-
prcm_module_enable(&rng_module);
if ((TRNG_READ(sc, TRNG_CONTROL_REG) & TRNG_CONTROL_ENABLE) == 0) {
@@ -127,7 +124,6 @@
uint32_t buf[2];
u_int retry;
- mutex_enter(&sc->sc_lock);
while (bytes_wanted) {
for (retry = 10; retry > 0; retry--) {
if (TRNG_READ(sc, TRNG_STATUS_REG) & TRNG_STATUS_READY)
@@ -144,5 +140,4 @@
bytes_wanted -= MIN(bytes_wanted, sizeof(buf));
}
explicit_memset(buf, 0, sizeof(buf));
- mutex_exit(&sc->sc_lock);
}
diff -r b25ffbb4e9db -r a95f6bd3c5fa sys/arch/arm/ti/ti_rng.c
--- a/sys/arch/arm/ti/ti_rng.c Sat Mar 19 11:54:53 2022 +0000
+++ b/sys/arch/arm/ti/ti_rng.c Sat Mar 19 11:55:03 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ti_rng.c,v 1.6 2022/03/19 11:37:05 riastradh Exp $ */
+/* $NetBSD: ti_rng.c,v 1.7 2022/03/19 11:55:03 riastradh Exp $ */
/*-
* Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ti_rng.c,v 1.6 2022/03/19 11:37:05 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ti_rng.c,v 1.7 2022/03/19 11:55:03 riastradh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -51,7 +51,6 @@
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
- kmutex_t sc_lock;
krndsource_t sc_rndsource;
};
@@ -101,8 +100,6 @@
return;
}
- mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTSERIAL);
-
if ((RD4(sc, TRNG_CONTROL_REG) & TRNG_CONTROL_ENABLE) == 0) {
WR4(sc, TRNG_CONFIG_REG,
__SHIFTIN(0x21, TRNG_CONFIG_MIN_REFILL) |
@@ -127,7 +124,6 @@
uint32_t buf[2];
u_int retry;
- mutex_enter(&sc->sc_lock);
while (bytes_wanted) {
for (retry = 10; retry > 0; retry--) {
if (RD4(sc, TRNG_STATUS_REG) & TRNG_STATUS_READY)
@@ -144,5 +140,4 @@
bytes_wanted -= MIN(bytes_wanted, sizeof(buf));
}
explicit_memset(buf, 0, sizeof(buf));
- mutex_exit(&sc->sc_lock);
}
diff -r b25ffbb4e9db -r a95f6bd3c5fa sys/arch/mips/cavium/dev/octeon_rnm.c
--- a/sys/arch/mips/cavium/dev/octeon_rnm.c Sat Mar 19 11:54:53 2022 +0000
+++ b/sys/arch/mips/cavium/dev/octeon_rnm.c Sat Mar 19 11:55:03 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: octeon_rnm.c,v 1.14 2022/03/19 11:37:05 riastradh Exp $ */
+/* $NetBSD: octeon_rnm.c,v 1.15 2022/03/19 11:55:03 riastradh Exp $ */
/*
* Copyright (c) 2007 Internet Initiative Japan, Inc.
@@ -99,7 +99,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: octeon_rnm.c,v 1.14 2022/03/19 11:37:05 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: octeon_rnm.c,v 1.15 2022/03/19 11:55:03 riastradh Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -127,7 +127,6 @@
uint64_t sc_sample[RNG_FIFO_WORDS];
bus_space_tag_t sc_bust;
bus_space_handle_t sc_regh;
- kmutex_t sc_lock;
krndsource_t sc_rndsrc; /* /dev/random source */
unsigned sc_rogroup;
};
@@ -184,9 +183,6 @@
return;
}
- /* Create a mutex to serialize access to the FIFO. */
- mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTSERIAL);
-
/*
* Reset the core, enable the RNG engine without entropy, wait
* 81 cycles for it to produce a single sample, and draw the
@@ -230,7 +226,6 @@
unsigned i;
/* Sample the ring oscillators round-robin. */
- mutex_enter(&sc->sc_lock);
while (needed) {
/*
* Switch to the next RO group once we drain the FIFO.
@@ -262,14 +257,9 @@
sizeof sc->sc_sample, NBBY*sizeof(sc->sc_sample)/BPB);
needed -= MIN(needed, MAX(1, NBBY*sizeof(sc->sc_sample)/BPB));
- /* Now's a good time to yield if need. */
- if (__predict_false(preempt_needed())) {
- mutex_exit(&sc->sc_lock);
- preempt();
- mutex_enter(&sc->sc_lock);
- }
+ /* Now's a good time to yield. */
+ preempt_point();
}
- mutex_exit(&sc->sc_lock);
/* Zero the sample. */
explicit_memset(sc->sc_sample, 0, sizeof sc->sc_sample);
diff -r b25ffbb4e9db -r a95f6bd3c5fa sys/arch/mips/ingenic/ingenic_rng.c
--- a/sys/arch/mips/ingenic/ingenic_rng.c Sat Mar 19 11:54:53 2022 +0000
+++ b/sys/arch/mips/ingenic/ingenic_rng.c Sat Mar 19 11:55:03 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ingenic_rng.c,v 1.6 2022/03/19 11:37:05 riastradh Exp $ */
+/* $NetBSD: ingenic_rng.c,v 1.7 2022/03/19 11:55:03 riastradh Exp $ */
/*-
* Copyright (c) 2015 Michael McConville
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ingenic_rng.c,v 1.6 2022/03/19 11:37:05 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ingenic_rng.c,v 1.7 2022/03/19 11:55:03 riastradh Exp $");
/*
* adapted from Jared McNeill's amlogic_rng.c
@@ -59,7 +59,6 @@
bus_space_tag_t sc_bst;
bus_space_handle_t sc_bsh;
- kmutex_t sc_lock;
krndsource_t sc_rndsource;
};
@@ -94,8 +93,6 @@
return;
}
- mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTSERIAL);
-
aprint_naive(": Ingenic random number generator\n");
aprint_normal(": Ingenic random number generator\n");
@@ -110,7 +107,6 @@
struct ingenic_rng_softc * const sc = priv;
uint32_t data;
- mutex_enter(&sc->sc_lock);
while (bytes_wanted) {
data = bus_space_read_4(sc->sc_bst, sc->sc_bsh, 0);
delay(1);
@@ -119,5 +115,4 @@
bytes_wanted -= MIN(bytes_wanted, sizeof(data));
}
explicit_memset(&data, 0, sizeof(data));
- mutex_exit(&sc->sc_lock);
}
diff -r b25ffbb4e9db -r a95f6bd3c5fa sys/dev/ic/amdccp.c
--- a/sys/dev/ic/amdccp.c Sat Mar 19 11:54:53 2022 +0000
+++ b/sys/dev/ic/amdccp.c Sat Mar 19 11:55:03 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: amdccp.c,v 1.4 2022/03/19 11:37:06 riastradh Exp $ */
+/* $NetBSD: amdccp.c,v 1.5 2022/03/19 11:55:03 riastradh Exp $ */
/*
* Copyright (c) 2018 Jonathan A. Kollasch
@@ -28,7 +28,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amdccp.c,v 1.4 2022/03/19 11:37:06 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdccp.c,v 1.5 2022/03/19 11:55:03 riastradh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -45,7 +45,6 @@
amdccp_common_attach(struct amdccp_softc *sc)
{
- mutex_init(&sc->sc_rndlock, MUTEX_DEFAULT, IPL_SOFTSERIAL);
rndsource_setcb(&sc->sc_rndsource, amdccp_rnd_callback, sc);
rnd_attach_source(&sc->sc_rndsource, device_xname(sc->sc_dev),
RND_TYPE_RNG, RND_FLAG_COLLECT_VALUE|RND_FLAG_HASCB);
@@ -74,7 +73,6 @@
uint32_t buf[128];
size_t cnt;
- mutex_enter(&sc->sc_rndlock);
while (bytes_wanted) {
const size_t nbytes = MIN(bytes_wanted, sizeof(buf));
const size_t nwords = howmany(nbytes, sizeof(buf[0]));
@@ -95,5 +93,4 @@
bytes_wanted -= MIN(bytes_wanted, cntby);
}
explicit_memset(buf, 0, sizeof(buf));
- mutex_exit(&sc->sc_rndlock);
}
diff -r b25ffbb4e9db -r a95f6bd3c5fa sys/dev/ic/amdccpvar.h
--- a/sys/dev/ic/amdccpvar.h Sat Mar 19 11:54:53 2022 +0000
+++ b/sys/dev/ic/amdccpvar.h Sat Mar 19 11:55:03 2022 +0000
@@ -1,4 +1,4 @@
Home |
Main Index |
Thread Index |
Old Index