From 91afdc872fc385dceac799d2693b4a5e40e4abcc Mon Sep 17 00:00:00 2001 From: bluhm Date: Fri, 5 Aug 2022 13:57:16 +0000 Subject: [PATCH] The netlock for SIOCSIFMEDIA and SIOCGIFMEDIA ioctl is not necessary. Legacy drivers run with kernel lock, interface media is MP safe or has kernel lock. Assert kernel lock in ix(4) and ixl(4). OK kettenis@ --- sys/dev/pci/if_ix.c | 5 ++++- sys/dev/pci/if_ixl.c | 9 ++++++--- sys/net/if.c | 12 ++++++++++-- sys/net/if_media.c | 4 ++-- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/sys/dev/pci/if_ix.c b/sys/dev/pci/if_ix.c index cb233034d23..ed50868e3ac 100644 --- a/sys/dev/pci/if_ix.c +++ b/sys/dev/pci/if_ix.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_ix.c,v 1.186 2022/06/27 15:11:23 jan Exp $ */ +/* $OpenBSD: if_ix.c,v 1.187 2022/08/05 13:57:16 bluhm Exp $ */ /****************************************************************************** @@ -1576,6 +1576,9 @@ ixgbe_update_link_status(struct ix_softc *sc) struct ifnet *ifp = &sc->arpcom.ac_if; int link_state = LINK_STATE_DOWN; + splassert(IPL_NET); + KERNEL_ASSERT_LOCKED(); + ixgbe_check_link(&sc->hw, &sc->link_speed, &sc->link_up, 0); ifp->if_baudrate = 0; diff --git a/sys/dev/pci/if_ixl.c b/sys/dev/pci/if_ixl.c index deeb6e566a8..8af9473bc25 100644 --- a/sys/dev/pci/if_ixl.c +++ b/sys/dev/pci/if_ixl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_ixl.c,v 1.83 2022/03/11 18:00:45 mpi Exp $ */ +/* $OpenBSD: if_ixl.c,v 1.84 2022/08/05 13:57:16 bluhm Exp $ */ /* * Copyright (c) 2013-2015, Intel Corporation @@ -2069,7 +2069,7 @@ ixl_media_status(struct ifnet *ifp, struct ifmediareq *ifm) { struct ixl_softc *sc = ifp->if_softc; - NET_ASSERT_LOCKED(); + KERNEL_ASSERT_LOCKED(); ifm->ifm_status = sc->sc_media_status; ifm->ifm_active = sc->sc_media_active; @@ -3517,7 +3517,9 @@ ixl_link_state_update_iaq(struct ixl_softc *sc, void *arg) return; } + KERNEL_LOCK(); link_state = ixl_set_link_status(sc, iaq); + KERNEL_UNLOCK(); mtx_enter(&sc->sc_link_state_mtx); if (ifp->if_link_state != link_state) { ifp->if_link_state = link_state; @@ -4488,6 +4490,8 @@ ixl_set_link_status(struct ixl_softc *sc, const struct ixl_aq_desc *iaq) const struct ixl_aq_link_status *status; const struct ixl_phy_type *itype; + KERNEL_ASSERT_LOCKED(); + uint64_t ifm_active = IFM_ETHER; uint64_t ifm_status = IFM_AVALID; int link_state = LINK_STATE_DOWN; @@ -4513,7 +4517,6 @@ ixl_set_link_status(struct ixl_softc *sc, const struct ixl_aq_desc *iaq) baudrate = ixl_search_link_speed(status->link_speed); done: - /* NET_ASSERT_LOCKED() except during attach */ sc->sc_media_active = ifm_active; sc->sc_media_status = ifm_status; sc->sc_ac.ac_if.if_baudrate = baudrate; diff --git a/sys/net/if.c b/sys/net/if.c index 81d4efaea69..edd4aa69997 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.660 2022/07/29 08:23:40 visa Exp $ */ +/* $OpenBSD: if.c,v 1.661 2022/08/05 13:57:16 bluhm Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -2305,6 +2305,15 @@ forceup: error = ((*ifp->if_ioctl)(ifp, cmd, data)); break; + case SIOCSIFMEDIA: + if ((error = suser(p)) != 0) + break; + /* FALLTHROUGH */ + case SIOCGIFMEDIA: + /* net lock is not needed */ + error = ((*ifp->if_ioctl)(ifp, cmd, data)); + break; + case SIOCSETKALIVE: case SIOCDIFPHYADDR: case SIOCSLIFPHYADDR: @@ -2314,7 +2323,6 @@ forceup: case SIOCSLIFPHYECN: case SIOCADDMULTI: case SIOCDELMULTI: - case SIOCSIFMEDIA: case SIOCSVNETID: case SIOCDVNETID: case SIOCSVNETFLOWID: diff --git a/sys/net/if_media.c b/sys/net/if_media.c index 15669186417..34beefcdfd5 100644 --- a/sys/net/if_media.c +++ b/sys/net/if_media.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_media.c,v 1.36 2022/07/14 13:46:25 bluhm Exp $ */ +/* $OpenBSD: if_media.c,v 1.37 2022/08/05 13:57:16 bluhm Exp $ */ /* $NetBSD: if_media.c,v 1.10 2000/03/13 23:52:39 soren Exp $ */ /*- @@ -312,7 +312,7 @@ ifmedia_ioctl(struct ifnet *ifp, struct ifreq *ifr, struct ifmedia *ifm, /* * Get list of available media and current media on interface. */ - case SIOCGIFMEDIA: + case SIOCGIFMEDIA: { struct ifmediareq *ifmr = (struct ifmediareq *) ifr; size_t nwords; -- 2.20.1