freebsd-skq/sys
jhb 5518ae8169 Restructure mbuf send tags to provide stronger guarantees.
- Perform ifp mismatch checks (to determine if a send tag is allocated
  for a different ifp than the one the packet is being output on), in
  ip_output() and ip6_output().  This avoids sending packets with send
  tags to ifnet drivers that don't support send tags.

  Since we are now checking for ifp mismatches before invoking
  if_output, we can now try to allocate a new tag before invoking
  if_output sending the original packet on the new tag if allocation
  succeeds.

  To avoid code duplication for the fragment and unfragmented cases,
  add ip_output_send() and ip6_output_send() as wrappers around
  if_output and nd6_output_ifp, respectively.  All of the logic for
  setting send tags and dealing with send tag-related errors is done
  in these wrapper functions.

  For pseudo interfaces that wrap other network interfaces (vlan and
  lagg), wrapper send tags are now allocated so that ip*_output see
  the wrapper ifp as the ifp in the send tag.  The if_transmit
  routines rewrite the send tags after performing an ifp mismatch
  check.  If an ifp mismatch is detected, the transmit routines fail
  with EAGAIN.

- To provide clearer life cycle management of send tags, especially
  in the presence of vlan and lagg wrapper tags, add a reference count
  to send tags managed via m_snd_tag_ref() and m_snd_tag_rele().
  Provide a helper function (m_snd_tag_init()) for use by drivers
  supporting send tags.  m_snd_tag_init() takes care of the if_ref
  on the ifp meaning that code alloating send tags via if_snd_tag_alloc
  no longer has to manage that manually.  Similarly, m_snd_tag_rele
  drops the refcount on the ifp after invoking if_snd_tag_free when
  the last reference to a send tag is dropped.

  This also closes use after free races if there are pending packets in
  driver tx rings after the socket is closed (e.g. from tcpdrop).

  In order for m_free to work reliably, add a new CSUM_SND_TAG flag in
  csum_flags to indicate 'snd_tag' is set (rather than 'rcvif').
  Drivers now also check this flag instead of checking snd_tag against
  NULL.  This avoids false positive matches when a forwarded packet
  has a non-NULL rcvif that was treated as a send tag.

- cxgbe was relying on snd_tag_free being called when the inp was
  detached so that it could kick the firmware to flush any pending
  work on the flow.  This is because the driver doesn't require ACK
  messages from the firmware for every request, but instead does a
  kind of manual interrupt coalescing by only setting a flag to
  request a completion on a subset of requests.  If all of the
  in-flight requests don't have the flag when the tag is detached from
  the inp, the flow might never return the credits.  The current
  snd_tag_free command issues a flush command to force the credits to
  return.  However, the credit return is what also frees the mbufs,
  and since those mbufs now hold references on the tag, this meant
  that snd_tag_free would never be called.

  To fix, explicitly drop the mbuf's reference on the snd tag when the
  mbuf is queued in the firmware work queue.  This means that once the
  inp's reference on the tag goes away and all in-flight mbufs have
  been queued to the firmware, tag's refcount will drop to zero and
  snd_tag_free will kick in and send the flush request.  Note that we
  need to avoid doing this in the middle of ethofld_tx(), so the
  driver grabs a temporary reference on the tag around that loop to
  defer the free to the end of the function in case it sends the last
  mbuf to the queue after the inp has dropped its reference on the
  tag.

- mlx5 preallocates send tags and was using the ifp pointer even when
  the send tag wasn't in use.  Explicitly use the ifp from other data
  structures instead.

- Sprinkle some assertions in various places to assert that received
  packets don't have a send tag, and that other places that overwrite
  rcvif (e.g. 802.11 transmit) don't clobber a send tag pointer.

Reviewed by:	gallatin, hselasky, rgrimes, ae
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D20117
2019-05-24 22:30:40 +00:00
..
amd64 Fix a corner case in demotion of kernel mappings. 2019-05-24 17:19:06 +00:00
arm arm: allwinner: Remove frac mode from NM clk 2019-05-23 17:36:55 +00:00
arm64 Include ktr.h in more compilation units 2019-05-21 20:38:48 +00:00
bsm Create new EINTEGRITY error with message "Integrity check failed". 2019-01-17 06:35:45 +00:00
cam Simplify math added in r310524. 2019-05-22 15:39:35 +00:00
cddl Allocate buffers smaller then ABD chunk size as linear. 2019-05-22 18:43:48 +00:00
compat Do not leak sa in linux_recvmsg() call if kern_recvit() fails. 2019-05-21 18:08:19 +00:00
conf Use ACPI SPCR on x86 2019-05-23 19:55:53 +00:00
contrib Extract eventfilter declarations to sys/_eventfilter.h 2019-05-20 00:38:23 +00:00
crypto Extract eventfilter declarations to sys/_eventfilter.h 2019-05-20 00:38:23 +00:00
ddb Extract eventfilter declarations to sys/_eventfilter.h 2019-05-20 00:38:23 +00:00
dev Restructure mbuf send tags to provide stronger guarantees. 2019-05-24 22:30:40 +00:00
dts arm64: Add support for NanoPI NEO2 2019-05-02 12:56:13 +00:00
fs Remove "struct ucred*" argument from vtruncbuf 2019-05-24 20:27:50 +00:00
gdb
geom Add deprecation warnings for weaker algorithms to geli(4). 2019-05-23 22:31:55 +00:00
gnu dts: Import files from Linux 5.1 2019-05-08 19:27:30 +00:00
i386 Fix a corner case in demotion of kernel mappings. 2019-05-24 17:19:06 +00:00
isa
kern Restructure mbuf send tags to provide stronger guarantees. 2019-05-24 22:30:40 +00:00
kgssapi * Handle SIGPIPE in gssd 2019-02-21 01:30:37 +00:00
libkern random(4): depessimize arc4random 2019-05-12 06:32:46 +00:00
mips Display CPU model in dmesg on mips targets 2019-05-24 01:43:35 +00:00
modules Add common support functions for USB devices configured via FDT data. 2019-05-19 16:56:59 +00:00
net Restructure mbuf send tags to provide stronger guarantees. 2019-05-24 22:30:40 +00:00
net80211 Restructure mbuf send tags to provide stronger guarantees. 2019-05-24 22:30:40 +00:00
netgraph Remove 'dir' argument in ng_ipfw_input, since ip_fw_args now has this info. 2019-03-14 22:30:05 +00:00
netinet Restructure mbuf send tags to provide stronger guarantees. 2019-05-24 22:30:40 +00:00
netinet6 Restructure mbuf send tags to provide stronger guarantees. 2019-05-24 22:30:40 +00:00
netipsec Add deprecation warnings for IPsec algorithms deprecated in RFC 8221. 2019-05-23 22:06:57 +00:00
netpfil Restructure mbuf send tags to provide stronger guarantees. 2019-05-24 22:30:40 +00:00
netsmb Remove unused argument to priv_check_cred. 2018-12-11 19:32:16 +00:00
nfs
nfsclient
nfsserver
nlm
ofed Include eventhandler.h in more compilation units 2019-05-21 01:18:43 +00:00
opencrypto cryptodeflate: Drop z_stream zbuf.state->dummy from SDT probe. 2019-05-24 02:44:15 +00:00
powerpc Add snd_hda(4) to GENERIC64 used by powerpc64. 2019-05-24 20:01:59 +00:00
riscv Include ktr.h in more compilation units 2019-05-21 20:38:48 +00:00
rpc Fix malloc stats for the RPCSEC_GSS server code when DEBUG is enabled. 2019-04-04 01:23:06 +00:00
security Extract eventfilter declarations to sys/_eventfilter.h 2019-05-20 00:38:23 +00:00
sparc64 FCP-101: Remove wb(4) 2019-05-17 15:24:34 +00:00
sys Restructure mbuf send tags to provide stronger guarantees. 2019-05-24 22:30:40 +00:00
teken Attempt to complete fixing programmable function keys for syscons. 2019-02-20 02:14:41 +00:00
tests Regularize the Netflix copyright 2019-02-04 21:28:25 +00:00
tools Avoid literal @generated tag in file-generating scripts 2019-05-08 13:35:51 +00:00
ufs Remove "struct ucred*" argument from vtruncbuf 2019-05-24 20:27:50 +00:00
vm Fix typo from r348128: _func__ -> __func__ 2019-05-23 02:10:41 +00:00
x86 Add a constant for the LS config MSR on AMD CPUs. 2019-05-23 23:37:11 +00:00
xdr
xen xen: introduce a new way to setup event channel upcall 2019-01-30 11:34:52 +00:00
Makefile