freebsd-dev/sys/dev/cxgbe
John Baldwin fb3bc59600 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
..
common cxgbe/t4_tom: Add a "TCB history" feature that samples hardware state 2019-04-22 17:48:10 +00:00
crypto Add support for AES-CCM to ccr(4). 2019-04-24 23:31:46 +00:00
cudbg cxgbe(4): Fix unsafe mailbox access in cudbg. 2017-11-21 01:18:58 +00:00
cxgbei Extract eventfilter declarations to sys/_eventfilter.h 2019-05-20 00:38:23 +00:00
firmware cxgbe(4): Treat the viid as an opaque identifier. 2019-03-20 17:27:11 +00:00
iw_cxgbe iw_cxgbe: Remove unused smac_idx from the ep structure. 2019-03-19 19:11:44 +00:00
tom Extract eventfilter declarations to sys/_eventfilter.h 2019-05-20 00:38:23 +00:00
adapter.h cxgbe(4): Count and clear interrupts generated at the software's request. 2019-03-28 21:22:28 +00:00
if_cc.c cxgbe(4): Attach to cards with the Terminator 6 ASIC. T6 cards will 2016-09-16 00:08:37 +00:00
if_ccv.c cxgbe(4): Attach to cards with the Terminator 6 ASIC. T6 cards will 2016-09-16 00:08:37 +00:00
if_cxl.c
if_cxlv.c Chelsio T4/T5 VF driver. 2016-09-07 18:13:57 +00:00
offload.h cxgbe/t4_tom: Catch up with r344433, which removed tcb_autorcvbuf_inc. 2019-03-29 16:43:24 +00:00
osdep.h cxgbe(4): Add adapter information to messages logged by the OS-agnostic 2019-01-29 00:49:12 +00:00
t4_clip.c cxgbe(4): Do not issue mbox commands after t4_fw_bye. 2018-12-19 19:21:29 +00:00
t4_clip.h Move CLIP table handling out of TOM and into the base driver. 2018-11-29 01:15:53 +00:00
t4_filter.c cxgbe(4): Clear the reply-pending status of a hashfilter when the reply 2019-01-20 23:30:16 +00:00
t4_if.m Use the port device name for the iov device for Chelsio T4/T5 cards. 2016-08-03 17:11:08 +00:00
t4_ioctl.h cxgbe(4): Allow "pass" filters to distribute matching traffic using a 2018-10-25 14:37:26 +00:00
t4_iov.c cxgbe(4): Update the VF device ids too. This should have been part 2017-05-05 16:52:25 +00:00
t4_l2t.c cxgbe(4): Reuse existing "switching" L2T entries when possible. 2018-09-22 01:24:30 +00:00
t4_l2t.h cxgbe(4): Reuse existing "switching" L2T entries when possible. 2018-09-22 01:24:30 +00:00
t4_main.c Restructure mbuf send tags to provide stronger guarantees. 2019-05-24 22:30:40 +00:00
t4_mp_ring.c cxgbe(4): Use fcmpset instead of cmpset when appropriate. 2018-08-23 16:24:27 +00:00
t4_mp_ring.h
t4_netmap.c cxgbe: revert r309725 2018-11-28 15:29:58 +00:00
t4_sched.c Restructure mbuf send tags to provide stronger guarantees. 2019-05-24 22:30:40 +00:00
t4_sge.c Restructure mbuf send tags to provide stronger guarantees. 2019-05-24 22:30:40 +00:00
t4_smt.c cxgbe(4): Move all control queues to the adapter. 2018-08-11 21:10:08 +00:00
t4_smt.h cxgbe(4): Retire an old check. 2018-06-01 01:05:34 +00:00
t4_tracer.c sys/dev: further adoption of SPDX licensing ID tags. 2017-11-27 14:52:40 +00:00
t4_vf.c cxgbev(4): Enable 32b port capabilities in the VF driver. 2019-03-02 04:39:59 +00:00