Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/sys Revert "ksyms: Use pserialize(9) for kernel access t...
details: https://anonhg.NetBSD.org/src/rev/640a1103368d
branches: trunk
changeset: 1023444:640a1103368d
user: riastradh <riastradh%NetBSD.org@localhost>
date: Tue Sep 07 16:56:13 2021 +0000
description:
Revert "ksyms: Use pserialize(9) for kernel access to ksyms."
diffstat:
sys/arch/sparc64/sparc64/machdep.c | 14 +----
sys/kern/kern_ksyms.c | 92 ++++++++++---------------------------
sys/kern/subr_csan.c | 8 +--
sys/kern/subr_msan.c | 10 +---
sys/sys/ksyms.h | 10 +---
5 files changed, 35 insertions(+), 99 deletions(-)
diffs (truncated from 446 to 300 lines):
diff -r 5afecb3df5c0 -r 640a1103368d sys/arch/sparc64/sparc64/machdep.c
--- a/sys/arch/sparc64/sparc64/machdep.c Tue Sep 07 13:29:41 2021 +0000
+++ b/sys/arch/sparc64/sparc64/machdep.c Tue Sep 07 16:56:13 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.301 2021/09/07 11:00:02 riastradh Exp $ */
+/* $NetBSD: machdep.c,v 1.302 2021/09/07 16:56:13 riastradh Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2019 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.301 2021/09/07 11:00:02 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.302 2021/09/07 16:56:13 riastradh Exp $");
#include "opt_ddb.h"
#include "opt_multiprocessor.h"
@@ -102,7 +102,6 @@
#include <sys/cpu.h>
#include <sys/module.h>
#include <sys/ksyms.h>
-#include <sys/pserialize.h>
#include <sys/exec_aout.h>
@@ -837,22 +836,17 @@
{
static char symbuf[256];
unsigned long symaddr;
- int s, error;
#if NKSYMS || defined(DDB) || defined(MODULAR)
- s = pserialize_read_enter();
if (ksyms_getname(mod, sym, pc,
KSYMS_CLOSEST|KSYMS_PROC|KSYMS_ANY) == 0) {
- error = ksyms_getval(*mod, *sym, &symaddr,
- KSYMS_CLOSEST|KSYMS_PROC|KSYMS_ANY);
- pserialize_read_exit(s);
- if (error)
+ if (ksyms_getval(*mod, *sym, &symaddr,
+ KSYMS_CLOSEST|KSYMS_PROC|KSYMS_ANY) != 0)
goto failed;
*offset = (vaddr_t)(pc - symaddr);
return;
}
- pserialize_read_exit(s);
#endif
failed:
snprintf(symbuf, sizeof symbuf, "%llx", (unsigned long long)pc);
diff -r 5afecb3df5c0 -r 640a1103368d sys/kern/kern_ksyms.c
--- a/sys/kern/kern_ksyms.c Tue Sep 07 13:29:41 2021 +0000
+++ b/sys/kern/kern_ksyms.c Tue Sep 07 16:56:13 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_ksyms.c,v 1.100 2021/09/07 11:00:02 riastradh Exp $ */
+/* $NetBSD: kern_ksyms.c,v 1.101 2021/09/07 16:56:13 riastradh Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.100 2021/09/07 11:00:02 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.101 2021/09/07 16:56:13 riastradh Exp $");
#if defined(_KERNEL) && defined(_KERNEL_OPT)
#include "opt_copy_symtab.h"
@@ -94,7 +94,6 @@
#include <sys/ksyms.h>
#include <sys/kernel.h>
#include <sys/intr.h>
-#include <sys/pserialize.h>
#ifdef DDB
#include <ddb/db_output.h>
@@ -119,7 +118,6 @@
static bool ksyms_loaded;
static kmutex_t ksyms_lock __cacheline_aligned;
static kcondvar_t ksyms_cv;
-static pserialize_t ksyms_psz __read_mostly;
static struct ksyms_symtab kernel_symtab;
static void ksyms_hdr_init(const void *);
@@ -148,7 +146,6 @@
int ksyms_ctfsz; /* this is not currently used by savecore(8) */
TAILQ_HEAD(ksyms_symtab_queue, ksyms_symtab) ksyms_symtabs =
TAILQ_HEAD_INITIALIZER(ksyms_symtabs);
-static struct pslist_head ksyms_symtabs_psz = PSLIST_INITIALIZER;
static int
ksyms_verify(const void *symstart, const void *strstart)
@@ -250,7 +247,6 @@
if (!ksyms_initted) {
mutex_init(&ksyms_lock, MUTEX_DEFAULT, IPL_NONE);
cv_init(&ksyms_cv, "ksyms");
- ksyms_psz = pserialize_create();
ksyms_initted = true;
}
}
@@ -453,19 +449,9 @@
/*
* Publish the symtab. Do this at splhigh to ensure ddb never
* witnesses an inconsistent state of the queue, unless memory
- * is so corrupt that we crash in PSLIST_WRITER_INSERT_AFTER or
- * TAILQ_INSERT_TAIL.
+ * is so corrupt that we crash in TAILQ_INSERT_TAIL.
*/
- PSLIST_ENTRY_INIT(tab, sd_pslist);
s = splhigh();
- if (TAILQ_EMPTY(&ksyms_symtabs)) {
- PSLIST_WRITER_INSERT_HEAD(&ksyms_symtabs_psz, tab, sd_pslist);
- } else {
- struct ksyms_symtab *last;
-
- last = TAILQ_LAST(&ksyms_symtabs, ksyms_symtab_queue);
- PSLIST_WRITER_INSERT_AFTER(last, tab, sd_pslist);
- }
TAILQ_INSERT_TAIL(&ksyms_symtabs, tab, sd_queue);
splx(s);
@@ -601,9 +587,7 @@
* "val" is a pointer to the corresponding value, if call succeeded.
* Returns 0 if success or ENOENT if no such entry.
*
- * If symp is nonnull, caller must hold ksyms_lock or module_lock, have
- * ksyms_opencnt nonzero, be in a pserialize read section, be in ddb
- * with all other CPUs quiescent.
+ * Call with ksyms_lock, unless known that the symbol table can't change.
*/
int
ksyms_getval_unlocked(const char *mod, const char *sym, Elf_Sym **symp,
@@ -611,61 +595,51 @@
{
struct ksyms_symtab *st;
Elf_Sym *es;
- int s, error = ENOENT;
#ifdef KSYMS_DEBUG
if (ksyms_debug & FOLLOW_CALLS)
printf("%s: mod %s sym %s valp %p\n", __func__, mod, sym, val);
#endif
- s = pserialize_read_enter();
- PSLIST_READER_FOREACH(st, &ksyms_symtabs_psz, struct ksyms_symtab,
- sd_pslist) {
+ TAILQ_FOREACH(st, &ksyms_symtabs, sd_queue) {
if (mod != NULL && strcmp(st->sd_name, mod))
continue;
if ((es = findsym(sym, st, type)) != NULL) {
*val = es->st_value;
if (symp)
*symp = es;
- error = 0;
- break;
+ return 0;
}
}
- pserialize_read_exit(s);
- return error;
+ return ENOENT;
}
int
ksyms_getval(const char *mod, const char *sym, unsigned long *val, int type)
{
+ int rc;
if (!ksyms_loaded)
return ENOENT;
- /* No locking needed -- we read the table pserialized. */
- return ksyms_getval_unlocked(mod, sym, NULL, val, type);
+ mutex_enter(&ksyms_lock);
+ rc = ksyms_getval_unlocked(mod, sym, NULL, val, type);
+ mutex_exit(&ksyms_lock);
+ return rc;
}
-/*
- * ksyms_get_mod(mod)
- *
- * Return the symtab for the given module name. Caller must ensure
- * that the module cannot be unloaded until after this returns.
- */
struct ksyms_symtab *
ksyms_get_mod(const char *mod)
{
struct ksyms_symtab *st;
- int s;
- s = pserialize_read_enter();
- PSLIST_READER_FOREACH(st, &ksyms_symtabs_psz, struct ksyms_symtab,
- sd_pslist) {
+ mutex_enter(&ksyms_lock);
+ TAILQ_FOREACH(st, &ksyms_symtabs, sd_queue) {
if (mod != NULL && strcmp(st->sd_name, mod))
continue;
break;
}
- pserialize_read_exit(s);
+ mutex_exit(&ksyms_lock);
return st;
}
@@ -721,9 +695,7 @@
* Get "mod" and "symbol" associated with an address.
* Returns 0 if success or ENOENT if no such entry.
*
- * Caller must hold ksyms_lock or module_lock, have ksyms_opencnt
- * nonzero, be in a pserialize read section, or be in ddb with all
- * other CPUs quiescent.
+ * Call with ksyms_lock, unless known that the symbol table can't change.
*/
int
ksyms_getname(const char **mod, const char **sym, vaddr_t v, int f)
@@ -738,8 +710,7 @@
if (!ksyms_loaded)
return ENOENT;
- PSLIST_READER_FOREACH(st, &ksyms_symtabs_psz, struct ksyms_symtab,
- sd_pslist) {
+ TAILQ_FOREACH(st, &ksyms_symtabs, sd_queue) {
if (v < st->sd_minsym || v > st->sd_maxsym)
continue;
sz = st->sd_symsize/sizeof(Elf_Sym);
@@ -824,21 +795,12 @@
/*
* Remove the symtab. Do this at splhigh to ensure ddb never
* witnesses an inconsistent state of the queue, unless memory
- * is so corrupt that we crash in TAILQ_REMOVE or
- * PSLIST_WRITER_REMOVE.
+ * is so corrupt that we crash in TAILQ_REMOVE.
*/
s = splhigh();
TAILQ_REMOVE(&ksyms_symtabs, st, sd_queue);
- PSLIST_WRITER_REMOVE(st, sd_pslist);
splx(s);
- /*
- * And wait a grace period, in case there are any pserialized
- * readers in flight.
- */
- pserialize_perform(ksyms_psz);
- PSLIST_ENTRY_DESTROY(st, sd_pslist);
-
/* Recompute the ksyms sizes now that we've removed st. */
ksyms_sizes_calc();
mutex_exit(&ksyms_lock);
@@ -1180,7 +1142,7 @@
unsigned long val;
int error = 0;
char *str = NULL;
- int len, s;
+ int len;
/* Read ksyms_maxlen only once while not holding the lock. */
len = ksyms_maxlen;
@@ -1211,9 +1173,8 @@
* Use the in-kernel symbol lookup code for fast
* retreival of a symbol.
*/
- s = pserialize_read_enter();
- PSLIST_READER_FOREACH(st, &ksyms_symtabs_psz,
- struct ksyms_symtab, sd_pslist) {
+ mutex_enter(&ksyms_lock);
+ TAILQ_FOREACH(st, &ksyms_symtabs, sd_queue) {
if ((sym = findsym(str, st, KSYMS_ANY)) == NULL)
continue;
#ifdef notdef
@@ -1227,10 +1188,10 @@
}
if (sym != NULL) {
memcpy(©, sym, sizeof(copy));
- pserialize_read_exit(s);
+ mutex_exit(&ksyms_lock);
error = copyout(©, okg->kg_sym, sizeof(Elf_Sym));
} else {
- pserialize_read_exit(s);
+ mutex_exit(&ksyms_lock);
error = ENOENT;
}
kmem_free(str, len);
@@ -1252,9 +1213,8 @@
* Use the in-kernel symbol lookup code for fast
* retreival of a symbol.
*/
- s = pserialize_read_enter();
- PSLIST_READER_FOREACH(st, &ksyms_symtabs_psz,
- struct ksyms_symtab, sd_pslist) {
+ mutex_enter(&ksyms_lock);
+ TAILQ_FOREACH(st, &ksyms_symtabs, sd_queue) {
if ((sym = findsym(str, st, KSYMS_ANY)) == NULL)
continue;
#ifdef notdef
@@ -1271,7 +1231,7 @@
} else {
error = ENOENT;
}
Home |
Main Index |
Thread Index |
Old Index