Although most of the NIC drivers are epoch ready, due to peer pressure

switch over to opt-in instead of opt-out for epoch.

Instead of IFF_NEEDSEPOCH, provide IFF_KNOWSEPOCH. If driver marks
itself with IFF_KNOWSEPOCH, then ether_input() would not enter epoch
when processing its packets.

Now this will create recursive entrance in epoch in >90% network
drivers, but will guarantee safeness of the transition.

Mark several tested drivers as IFF_KNOWSEPOCH.

Reviewed by:		hselasky, jeff, bz, gallatin
Differential Revision:	https://reviews.freebsd.org/D23674
This commit is contained in:
Gleb Smirnoff 2020-02-24 21:07:30 +00:00
parent eea248ec9a
commit e87c494015
13 changed files with 22 additions and 23 deletions

View File

@ -613,7 +613,7 @@ vtbe_attach(device_t dev)
ifp->if_softc = sc;
if_initname(ifp, device_get_name(dev), device_get_unit(dev));
ifp->if_flags = (IFF_BROADCAST | IFF_SIMPLEX |
IFF_MULTICAST | IFF_PROMISC | IFF_NEEDSEPOCH);
IFF_MULTICAST | IFF_PROMISC);
ifp->if_capabilities = IFCAP_VLAN_MTU;
ifp->if_capenable = ifp->if_capabilities;
ifp->if_start = vtbe_txstart;

View File

@ -688,7 +688,7 @@ dtsec_attach(device_t dev)
ifp->if_softc = sc;
ifp->if_mtu = ETHERMTU; /* TODO: Configure */
ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_NEEDSEPOCH;
ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST;
ifp->if_init = dtsec_if_init;
ifp->if_start = dtsec_if_start;
ifp->if_ioctl = dtsec_if_ioctl;

View File

@ -2362,8 +2362,7 @@ hn_attach(device_t dev)
*/
ifp->if_baudrate = IF_Gbps(10);
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
IFF_NEEDSEPOCH;
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
ifp->if_ioctl = hn_ioctl;
ifp->if_init = hn_init;
#ifdef HN_IFSTART_SUPPORT

View File

@ -967,8 +967,7 @@ ndis_ifattach(struct ndis_softc *sc)
if_initname(ifp, device_get_name(sc->ndis_dev),
device_get_unit(sc->ndis_dev));
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
IFF_NEEDSEPOCH;
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
ifp->if_ioctl = ndis_ifioctl;
ifp->if_start = ndis_ifstart;
ifp->if_init = ndis_init;

View File

@ -4275,7 +4275,8 @@ mlx5e_create_ifp(struct mlx5_core_dev *mdev)
if_initname(ifp, "mce", device_get_unit(mdev->pdev->dev.bsddev));
ifp->if_mtu = ETHERMTU;
ifp->if_init = mlx5e_open;
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
IFF_KNOWSEPOCH;
ifp->if_ioctl = mlx5e_ioctl;
ifp->if_transmit = mlx5e_xmit;
ifp->if_qflush = if_qflush;

View File

@ -172,8 +172,7 @@ ntb_net_attach(device_t dev)
if_setinitfn(ifp, ntb_net_init);
if_setsoftc(ifp, sc);
if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
IFF_NEEDSEPOCH);
if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
if_setioctlfn(ifp, ntb_ioctl);
if_settransmitfn(ifp, ntb_transmit);
if_setqflushfn(ifp, ntb_qflush);

View File

@ -243,8 +243,7 @@ sbni_attach(struct sbni_softc *sc, int unit, struct sbni_flags flags)
ifp->if_baudrate =
(csr0 & 0x01 ? 500000 : 2000000) / (1 << flags.rate);
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
IFF_NEEDSEPOCH;
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
mtx_init(&sc->lock, ifp->if_xname, MTX_NETWORK_LOCK, MTX_DEF);
callout_init_mtx(&sc->wch, &sc->lock, 0);

View File

@ -950,7 +950,8 @@ vtnet_setup_interface(struct vtnet_softc *sc)
if_initname(ifp, device_get_name(dev), device_get_unit(dev));
ifp->if_baudrate = IF_Gbps(10); /* Approx. */
ifp->if_softc = sc;
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
IFF_KNOWSEPOCH;
ifp->if_init = vtnet_init;
ifp->if_ioctl = vtnet_ioctl;
ifp->if_get_counter = vtnet_get_counter;

View File

@ -1052,8 +1052,7 @@ nlm_xlpge_ifinit(struct nlm_xlpge_softc *sc)
}
ifp->if_softc = sc;
if_initname(ifp, device_get_name(dev), device_get_unit(dev));
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
IFF_NEEDSEPOCH;
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
sc->if_flags = ifp->if_flags;
/*ifp->if_capabilities = IFCAP_TXCSUM | IFCAP_VLAN_HWTAGGING;*/
ifp->if_capabilities = 0;

View File

@ -551,8 +551,6 @@ if_alloc_domain(u_char type, int numa_domain)
#ifdef VIMAGE
ifp->if_vnet = curvnet;
#endif
/* XXX */
ifp->if_flags |= IFF_NEEDSEPOCH;
if (if_com_alloc[type] != NULL) {
ifp->if_l2com = if_com_alloc[type](type, ifp);
if (ifp->if_l2com == NULL) {
@ -4167,8 +4165,8 @@ if_setdrvflags(if_t ifp, int flags)
int
if_setflags(if_t ifp, int flags)
{
/* XXX Temporary */
((struct ifnet *)ifp)->if_flags = flags | IFF_NEEDSEPOCH;
ifp->if_flags = flags;
return (0);
}

View File

@ -144,7 +144,7 @@ struct if_data {
#define IFF_DEBUG 0x4 /* (n) turn on debugging */
#define IFF_LOOPBACK 0x8 /* (i) is a loopback net */
#define IFF_POINTOPOINT 0x10 /* (i) is a point-to-point link */
#define IFF_NEEDSEPOCH 0x20 /* (i) calls if_input w/o epoch */
#define IFF_KNOWSEPOCH 0x20 /* (i) calls if_input in net epoch */
#define IFF_DRV_RUNNING 0x40 /* (d) resources allocated */
#define IFF_NOARP 0x80 /* (n) no address resolution protocol */
#define IFF_PROMISC 0x100 /* (n) receive all packets */
@ -178,7 +178,7 @@ struct if_data {
#define IFF_CANTCHANGE \
(IFF_BROADCAST|IFF_POINTOPOINT|IFF_DRV_RUNNING|IFF_DRV_OACTIVE|\
IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_PROMISC|\
IFF_DYING|IFF_CANTCONFIG)
IFF_DYING|IFF_CANTCONFIG|IFF_KNOWSEPOCH)
/*
* Values for if_link_state.

View File

@ -802,6 +802,9 @@ ether_input(struct ifnet *ifp, struct mbuf *m)
{
struct epoch_tracker et;
struct mbuf *mn;
bool needs_epoch;
needs_epoch = !(ifp->if_flags & IFF_KNOWSEPOCH);
/*
* The drivers are allowed to pass in a chain of packets linked with
@ -809,7 +812,7 @@ ether_input(struct ifnet *ifp, struct mbuf *m)
* them up. This allows the drivers to amortize the receive lock.
*/
CURVNET_SET_QUIET(ifp->if_vnet);
if (__predict_false(ifp->if_flags & IFF_NEEDSEPOCH))
if (__predict_false(needs_epoch))
NET_EPOCH_ENTER(et);
while (m) {
mn = m->m_nextpkt;
@ -825,7 +828,7 @@ ether_input(struct ifnet *ifp, struct mbuf *m)
netisr_dispatch(NETISR_ETHER, m);
m = mn;
}
if (__predict_false(ifp->if_flags & IFF_NEEDSEPOCH))
if (__predict_false(needs_epoch))
NET_EPOCH_EXIT(et);
CURVNET_RESTORE();
}

View File

@ -5400,7 +5400,8 @@ iflib_register(if_ctx_t ctx)
if_settransmitfn(ifp, iflib_if_transmit);
#endif
if_setqflushfn(ifp, iflib_if_qflush);
if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST);
if_setflags(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST |
IFF_KNOWSEPOCH);
ctx->ifc_vlan_attach_event =
EVENTHANDLER_REGISTER(vlan_config, iflib_vlan_register, ctx,