1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-22 07:27:59 -08:00

Push kernel lock down to net_sysctl().

All except PF_MPLS paths are mp-safe:
- net_link_sysctl() and following net_ifiq_sysctl() only return
  EOPNOTSUPP;
- uipc_sysctl() - mp-safe atomic access to integers;
- bpf_sysctl() - mp-safe atomic access to integers;
- pflow_sysctl() - returns statistics from per-CPU counters;
- pipex_sysctl() - mp-safe atomic access to integer;

Push kernel lock down to mpls_sysctl(). sysctl_int_bounded() do copying
with local variable, so context switch is safe. No need to wire memory
or take `sysctl_lock' rwlock(9).

Keep protocols locked as they was include pages wiring. Copying will not
sleep - no network slowdown while doing it with net lock held.

ok bluhm
This commit is contained in:
mvs 2024-08-14 17:52:47 +00:00
parent 03650efb1a
commit 7af15f03da
3 changed files with 23 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: kern_sysctl.c,v 1.438 2024/08/14 13:54:08 mvs Exp $ */ /* $OpenBSD: kern_sysctl.c,v 1.439 2024/08/14 17:52:47 mvs Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*- /*-
@ -252,6 +252,7 @@ sys_sysctl(struct proc *p, void *v, register_t *retval)
fn = uvm_sysctl; fn = uvm_sysctl;
break; break;
case CTL_NET: case CTL_NET:
dolock = 0;
fn = net_sysctl; fn = net_sysctl;
break; break;
case CTL_FS: case CTL_FS:

View File

@ -1,4 +1,4 @@
/* $OpenBSD: uipc_domain.c,v 1.66 2024/08/12 11:25:27 bluhm Exp $ */ /* $OpenBSD: uipc_domain.c,v 1.67 2024/08/14 17:52:47 mvs Exp $ */
/* $NetBSD: uipc_domain.c,v 1.14 1996/02/09 19:00:44 christos Exp $ */ /* $NetBSD: uipc_domain.c,v 1.14 1996/02/09 19:00:44 christos Exp $ */
/* /*
@ -236,9 +236,18 @@ net_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
return (EISDIR); /* overloaded */ return (EISDIR); /* overloaded */
protocol = name[1]; protocol = name[1];
for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
if (pr->pr_protocol == protocol && pr->pr_sysctl) if (pr->pr_protocol == protocol && pr->pr_sysctl) {
return ((*pr->pr_sysctl)(name + 2, namelen - 2, size_t savelen = *oldlenp;
oldp, oldlenp, newp, newlen)); int error;
if ((error = sysctl_vslock(oldp, savelen)))
return (error);
error = (*pr->pr_sysctl)(name + 2, namelen - 2,
oldp, oldlenp, newp, newlen);
sysctl_vsunlock(oldp, savelen);
return (error);
}
return (ENOPROTOOPT); return (ENOPROTOOPT);
} }

View File

@ -1,4 +1,4 @@
/* $OpenBSD: mpls_raw.c,v 1.20 2024/04/29 00:29:48 jsg Exp $ */ /* $OpenBSD: mpls_raw.c,v 1.21 2024/08/14 17:52:47 mvs Exp $ */
/* /*
* Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project. * Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project.
@ -58,6 +58,12 @@ int
mpls_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, mpls_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
size_t newlen) size_t newlen)
{ {
return sysctl_bounded_arr(mplsctl_vars, nitems(mplsctl_vars), int error;
KERNEL_LOCK();
error = sysctl_bounded_arr(mplsctl_vars, nitems(mplsctl_vars),
name, namelen, oldp, oldlenp, newp, newlen); name, namelen, oldp, oldlenp, newp, newlen);
KERNEL_UNLOCK();
return error;
} }