On Sat, Jan 03, 2026 at 06:29:19AM +0300, Vitaliy Makkoveev wrote:
> I propose to take netlock status instead of `cmd' handrolling. This
> relocking is XXX in any case.
>
> Compile test only.
>
Please drop previous. We can't know do we hold the shared netlock or
not, so handle SIOC*MEDIA and SIOCGIFSFFPAGE cases manually.
Index: sys/dev/fdt/if_cad.c
===================================================================
RCS file: /cvs/src/sys/dev/fdt/if_cad.c,v
retrieving revision 1.16
diff -u -p -r1.16 if_cad.c
--- sys/dev/fdt/if_cad.c 17 Sep 2025 09:17:12 -0000 1.16
+++ sys/dev/fdt/if_cad.c 3 Jan 2026 03:38:34 -0000
@@ -589,22 +589,44 @@ cad_ioctl(struct ifnet *ifp, u_long cmd,
{
struct cad_softc *sc = ifp->if_softc;
struct ifreq *ifr = (struct ifreq *)data;
- int error = 0, netlock_held = 1;
+ int error = 0, netlock_status;
int s;
+ /*
+ * XXXSMP: We can't predict the netlock status. We can't
+ * know, are we the holder of shared netlock.
+ */
switch (cmd) {
case SIOCGIFMEDIA:
case SIOCSIFMEDIA:
case SIOCGIFSFFPAGE:
- netlock_held = 0;
+ netlock_status = 0;
+ break;
+ default:
+ netlock_status = rw_status(&netlock);
break;
}
- if (netlock_held)
+ switch (netlock_status) {
+ case RW_WRITE:
NET_UNLOCK();
+ break;
+ case RW_READ:
+ NET_UNLOCK_SHARED();
+ break;
+ }
+
rw_enter_write(&sc->sc_cfg_lock);
- if (netlock_held)
+
+ switch (netlock_status) {
+ case RW_WRITE:
NET_LOCK();
+ break;
+ case RW_READ:
+ NET_LOCK_SHARED();
+ break;
+ }
+
s = splnet();
switch (cmd) {