Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net/npf npf(9): Drop table lock around copyout.



details:   https://anonhg.NetBSD.org/src/rev/e4072a1e9810
branches:  trunk
changeset: 373194:e4072a1e9810
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Jan 23 13:40:04 2023 +0000

description:
npf(9): Drop table lock around copyout.

It is forbidden to hold a spin lock around copyout, and t_lock is a
spin lock.

We need t_lock in order to iterate over the list of entries.
However, during copyout itself, we only need to ensure that the
object we're copying out isn't freed by npf_table_remove or
npf_table_gc.

Fortunately, the only caller of npf_table_list, npf_table_remove, and
npf_table_gc is npfctl_table, and it serializes all of them by the
npf config lock.  So we can safely drop t_lock across copyout.

PR kern/57136
PR kern/57181

diffstat:

 sys/net/npf/npf_tableset.c |  6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diffs (31 lines):

diff -r 913132664a93 -r e4072a1e9810 sys/net/npf/npf_tableset.c
--- a/sys/net/npf/npf_tableset.c        Sun Jan 22 21:36:12 2023 +0000
+++ b/sys/net/npf/npf_tableset.c        Mon Jan 23 13:40:04 2023 +0000
@@ -46,7 +46,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_tableset.c,v 1.40 2023/01/22 18:45:43 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_tableset.c,v 1.41 2023/01/23 13:40:04 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -766,15 +766,17 @@
 }
 
 static int
-table_generic_list(const npf_table_t *t, void *ubuf, size_t len)
+table_generic_list(npf_table_t *t, void *ubuf, size_t len)
 {
        npf_tblent_t *ent;
        size_t off = 0;
        int error = 0;
 
        LIST_FOREACH(ent, &t->t_list, te_listent) {
+               mutex_exit(&t->t_lock);
                error = table_ent_copyout(&ent->te_addr,
                    ent->te_alen, ent->te_preflen, ubuf, len, &off);
+               mutex_enter(&t->t_lock);
                if (error)
                        break;
        }



Home | Main Index | Thread Index | Old Index