Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net/npf Avoid LOCKDEBUG pserialize panic by implementing...
details: https://anonhg.NetBSD.org/src/rev/7227d050b8bd
branches: trunk
changeset: 457129:7227d050b8bd
user: christos <christos%NetBSD.org@localhost>
date: Wed Jun 12 14:36:32 2019 +0000
description:
Avoid LOCKDEBUG pserialize panic by implementing suggestion #1 from
http://mail-index.netbsd.org/current-users/2019/02/24/msg035220.html:
Convert the mutex to spin-lock at IPL_NET (but it is excessive) and
convert the memory allocations in that code path to KM_NOSLEEP.
diffstat:
sys/net/npf/lpm.c | 23 ++++++++++++++---------
sys/net/npf/lpm.h | 2 +-
sys/net/npf/npf_tableset.c | 6 +++---
3 files changed, 18 insertions(+), 13 deletions(-)
diffs (131 lines):
diff -r e71852cbc40f -r 7227d050b8bd sys/net/npf/lpm.c
--- a/sys/net/npf/lpm.c Wed Jun 12 14:28:38 2019 +0000
+++ b/sys/net/npf/lpm.c Wed Jun 12 14:36:32 2019 +0000
@@ -38,7 +38,7 @@
#if defined(_KERNEL)
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lpm.c,v 1.5 2018/09/29 14:41:36 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lpm.c,v 1.6 2019/06/12 14:36:32 christos Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -90,6 +90,7 @@
struct lpm {
uint32_t bitmask[LPM_MAX_WORDS];
+ int flags;
void * defvals[2];
lpm_hmap_t prefix[LPM_MAX_PREFIX + 1];
};
@@ -97,9 +98,11 @@
static const uint32_t zero_address[LPM_MAX_WORDS];
lpm_t *
-lpm_create(void)
+lpm_create(int flags)
{
- return kmem_zalloc(sizeof(lpm_t), KM_SLEEP);
+ lpm_t *lpm = kmem_zalloc(sizeof(*lpm), KM_SLEEP);
+ lpm->flags = flags;
+ return lpm;
}
void
@@ -164,7 +167,7 @@
}
static bool
-hashmap_rehash(lpm_hmap_t *hmap, unsigned size)
+hashmap_rehash(lpm_hmap_t *hmap, unsigned size, int flags)
{
lpm_ent_t **bucket;
unsigned hashsize;
@@ -172,7 +175,9 @@
for (hashsize = 1; hashsize < size; hashsize <<= 1) {
continue;
}
- bucket = kmem_zalloc(hashsize * sizeof(lpm_ent_t *), KM_SLEEP);
+ bucket = kmem_zalloc(hashsize * sizeof(lpm_ent_t *), flags);
+ if (bucket == NULL)
+ return false;
for (unsigned n = 0; n < hmap->hashsize; n++) {
lpm_ent_t *list = hmap->bucket[n];
@@ -194,14 +199,14 @@
}
static lpm_ent_t *
-hashmap_insert(lpm_hmap_t *hmap, const void *key, size_t len)
+hashmap_insert(lpm_hmap_t *hmap, const void *key, size_t len, int flags)
{
const unsigned target = hmap->nitems + LPM_HASH_STEP;
const size_t entlen = offsetof(lpm_ent_t, key[len]);
uint32_t hash, i;
lpm_ent_t *entry;
- if (hmap->hashsize < target && !hashmap_rehash(hmap, target)) {
+ if (hmap->hashsize < target && !hashmap_rehash(hmap, target, flags)) {
return NULL;
}
@@ -215,7 +220,7 @@
entry = entry->next;
}
- if ((entry = kmem_alloc(entlen, KM_SLEEP)) != NULL) {
+ if ((entry = kmem_alloc(entlen, flags)) != NULL) {
memcpy(entry->key, key, len);
entry->next = hmap->bucket[i];
entry->len = len;
@@ -326,7 +331,7 @@
return 0;
}
compute_prefix(nwords, addr, preflen, prefix);
- entry = hashmap_insert(&lpm->prefix[preflen], prefix, len);
+ entry = hashmap_insert(&lpm->prefix[preflen], prefix, len, lpm->flags);
if (entry) {
const unsigned n = --preflen >> 5;
lpm->bitmask[n] |= 0x80000000U >> (preflen & 31);
diff -r e71852cbc40f -r 7227d050b8bd sys/net/npf/lpm.h
--- a/sys/net/npf/lpm.h Wed Jun 12 14:28:38 2019 +0000
+++ b/sys/net/npf/lpm.h Wed Jun 12 14:36:32 2019 +0000
@@ -32,7 +32,7 @@
typedef struct lpm lpm_t;
typedef void (*lpm_dtor_t)(void *, const void *, size_t, void *);
-lpm_t * lpm_create(void);
+lpm_t * lpm_create(int);
void lpm_destroy(lpm_t *);
void lpm_clear(lpm_t *, lpm_dtor_t, void *);
diff -r e71852cbc40f -r 7227d050b8bd sys/net/npf/npf_tableset.c
--- a/sys/net/npf/npf_tableset.c Wed Jun 12 14:28:38 2019 +0000
+++ b/sys/net/npf/npf_tableset.c Wed Jun 12 14:36:32 2019 +0000
@@ -39,7 +39,7 @@
#ifdef _KERNEL
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_tableset.c,v 1.29 2019/01/19 21:19:32 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_tableset.c,v 1.30 2019/06/12 14:36:32 christos Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -365,7 +365,7 @@
switch (type) {
case NPF_TABLE_LPM:
- t->t_lpm = lpm_create();
+ t->t_lpm = lpm_create(KM_NOSLEEP);
if (t->t_lpm == NULL) {
goto out;
}
@@ -398,7 +398,7 @@
default:
KASSERT(false);
}
- mutex_init(&t->t_lock, MUTEX_DEFAULT, IPL_NONE);
+ mutex_init(&t->t_lock, MUTEX_DEFAULT, IPL_NET);
t->t_type = type;
t->t_id = tid;
return t;
Home |
Main Index |
Thread Index |
Old Index