Re: [PATCH net-next v9 3/5] net: devmem: implement autorelease token management
On Wed, Jan 14, 2026 at 12:54:44PM -0800, Stanislav Fomichev wrote: > On 01/12, Bobby Eshleman wrote: > > On Sun, Jan 11, 2026 at 11:12:19AM -0800, Mina Almasry wrote: > > > On Fri, Jan 9, 2026 at 6:19 PM Bobby Eshleman > > > wrote: > > > > > > > > From: Bobby Eshleman > > > > > > > > Add support for autorelease toggling of tokens using a static branch to > > > > control system-wide behavior. This allows applications to choose between > > > > two memory management modes: > > > > > > > > 1. Autorelease on: Leaked tokens are automatically released when the > > > >socket closes. > > > > > > > > 2. Autorelease off: Leaked tokens are released during dmabuf unbind. > > > > > > > > The autorelease mode is requested via the NETDEV_A_DMABUF_AUTORELEASE > > > > attribute of the NETDEV_CMD_BIND_RX message. Having separate modes per > > > > binding is disallowed and is rejected by netlink. The system will be > > > > "locked" into the mode that the first binding is set to. It can only be > > > > changed again once there are zero bindings on the system. > > > > > > > > Disabling autorelease offers ~13% improvement in CPU utilization. > > > > > > > > Static branching is used to limit the system to one mode or the other. > > > > > > > > Signed-off-by: Bobby Eshleman > > > > --- > > > > Changes in v9: > > > > - Add missing stub for net_devmem_dmabuf_binding_get() when NET_DEVMEM=n > > > > - Add wrapper around tcp_devmem_ar_key accesses so that it may be > > > > stubbed out when NET_DEVMEM=n > > > > - only dec rx binding count for rx bindings in free (v8 did not exclude > > > > TX bindings) > > > > > > > > Changes in v8: > > > > - Only reset static key when bindings go to zero, defaulting back to > > > > disabled (Stan). > > > > - Fix bad usage of xarray spinlock for sleepy static branch switching, > > > > use mutex instead. > > > > - Access pp_ref_count via niov->desc instead of niov directly. > > > > - Move reset of static key to __net_devmem_dmabuf_binding_free() so that > > > > the static key can not be changed while there are outstanding tokens > > > > (free is only called when reference count reaches zero). > > > > - Add net_devmem_dmabuf_rx_bindings_count because tokens may be active > > > > even after xa_erase(), so static key changes must wait until all > > > > RX bindings are finally freed (not just when xarray is empty). A > > > > counter is a simple way to track this. > > > > - socket takes reference on the binding, to avoid use-after-free on > > > > sk_devmem_info.binding in the case that user releases all tokens, > > > > unbinds, then issues SO_DEVMEM_DONTNEED again (with bad token). > > > > - removed some comments that were unnecessary > > > > > > > > Changes in v7: > > > > - implement autorelease with static branch (Stan) > > > > - use netlink instead of sockopt (Stan) > > > > - merge uAPI and implementation patches into one patch (seemed less > > > > confusing) > > > > > > > > Changes in v6: > > > > - remove sk_devmem_info.autorelease, using binding->autorelease instead > > > > - move binding->autorelease check to outside of > > > > net_devmem_dmabuf_binding_put_urefs() (Mina) > > > > - remove overly defensive net_is_devmem_iov() (Mina) > > > > - add comment about multiple urefs mapping to a single netmem ref (Mina) > > > > - remove overly defense netmem NULL and netmem_is_net_iov checks (Mina) > > > > - use niov without casting back and forth with netmem (Mina) > > > > - move the autorelease flag from per-binding to per-socket (Mina) > > > > - remove the batching logic in sock_devmem_dontneed_manual_release() > > > > (Mina) > > > > - move autorelease check inside tcp_xa_pool_commit() (Mina) > > > > - remove single-binding restriction for autorelease mode (Mina) > > > > - unbind always checks for leaked urefs > > > > > > > > Changes in v5: > > > > - remove unused variables > > > > - introduce autorelease flag, preparing for future patch toggle new > > > > behavior > > > > > > > > Changes in v3: > > > > - make urefs per-binding instead of per-socket, reducing memory > > > > footprint > > > > - fallback to cleaning up references in dmabuf unbind if socket leaked > > > > tokens > > > > - drop ethtool patch > > > > > > > > Changes in v2: > > > > - always use GFP_ZERO for binding->vec (Mina) > > > > - remove WARN for changed binding (Mina) > > > > - remove extraneous binding ref get (Mina) > > > > - remove WARNs on invalid user input (Mina) > > > > - pre-assign niovs in binding->vec for RX case (Mina) > > > > - use atomic_set(, 0) to initialize sk_user_frags.urefs > > > > - fix length of alloc for urefs > > > > --- > > > > Documentation/netlink/specs/netdev.yaml | 12 > > > > include/net/netmem.h| 1 + > > > > include/net/sock.h | 7 ++- > > > > include/uapi/linux/netdev.h | 1 + > > > > net/core/devmem.c | 104 > > > > > > > > net/core/devmem.h
Re: [PATCH net-next v9 3/5] net: devmem: implement autorelease token management
On 01/12, Bobby Eshleman wrote: > On Sun, Jan 11, 2026 at 11:12:19AM -0800, Mina Almasry wrote: > > On Fri, Jan 9, 2026 at 6:19 PM Bobby Eshleman > > wrote: > > > > > > From: Bobby Eshleman > > > > > > Add support for autorelease toggling of tokens using a static branch to > > > control system-wide behavior. This allows applications to choose between > > > two memory management modes: > > > > > > 1. Autorelease on: Leaked tokens are automatically released when the > > >socket closes. > > > > > > 2. Autorelease off: Leaked tokens are released during dmabuf unbind. > > > > > > The autorelease mode is requested via the NETDEV_A_DMABUF_AUTORELEASE > > > attribute of the NETDEV_CMD_BIND_RX message. Having separate modes per > > > binding is disallowed and is rejected by netlink. The system will be > > > "locked" into the mode that the first binding is set to. It can only be > > > changed again once there are zero bindings on the system. > > > > > > Disabling autorelease offers ~13% improvement in CPU utilization. > > > > > > Static branching is used to limit the system to one mode or the other. > > > > > > Signed-off-by: Bobby Eshleman > > > --- > > > Changes in v9: > > > - Add missing stub for net_devmem_dmabuf_binding_get() when NET_DEVMEM=n > > > - Add wrapper around tcp_devmem_ar_key accesses so that it may be > > > stubbed out when NET_DEVMEM=n > > > - only dec rx binding count for rx bindings in free (v8 did not exclude > > > TX bindings) > > > > > > Changes in v8: > > > - Only reset static key when bindings go to zero, defaulting back to > > > disabled (Stan). > > > - Fix bad usage of xarray spinlock for sleepy static branch switching, > > > use mutex instead. > > > - Access pp_ref_count via niov->desc instead of niov directly. > > > - Move reset of static key to __net_devmem_dmabuf_binding_free() so that > > > the static key can not be changed while there are outstanding tokens > > > (free is only called when reference count reaches zero). > > > - Add net_devmem_dmabuf_rx_bindings_count because tokens may be active > > > even after xa_erase(), so static key changes must wait until all > > > RX bindings are finally freed (not just when xarray is empty). A > > > counter is a simple way to track this. > > > - socket takes reference on the binding, to avoid use-after-free on > > > sk_devmem_info.binding in the case that user releases all tokens, > > > unbinds, then issues SO_DEVMEM_DONTNEED again (with bad token). > > > - removed some comments that were unnecessary > > > > > > Changes in v7: > > > - implement autorelease with static branch (Stan) > > > - use netlink instead of sockopt (Stan) > > > - merge uAPI and implementation patches into one patch (seemed less > > > confusing) > > > > > > Changes in v6: > > > - remove sk_devmem_info.autorelease, using binding->autorelease instead > > > - move binding->autorelease check to outside of > > > net_devmem_dmabuf_binding_put_urefs() (Mina) > > > - remove overly defensive net_is_devmem_iov() (Mina) > > > - add comment about multiple urefs mapping to a single netmem ref (Mina) > > > - remove overly defense netmem NULL and netmem_is_net_iov checks (Mina) > > > - use niov without casting back and forth with netmem (Mina) > > > - move the autorelease flag from per-binding to per-socket (Mina) > > > - remove the batching logic in sock_devmem_dontneed_manual_release() > > > (Mina) > > > - move autorelease check inside tcp_xa_pool_commit() (Mina) > > > - remove single-binding restriction for autorelease mode (Mina) > > > - unbind always checks for leaked urefs > > > > > > Changes in v5: > > > - remove unused variables > > > - introduce autorelease flag, preparing for future patch toggle new > > > behavior > > > > > > Changes in v3: > > > - make urefs per-binding instead of per-socket, reducing memory > > > footprint > > > - fallback to cleaning up references in dmabuf unbind if socket leaked > > > tokens > > > - drop ethtool patch > > > > > > Changes in v2: > > > - always use GFP_ZERO for binding->vec (Mina) > > > - remove WARN for changed binding (Mina) > > > - remove extraneous binding ref get (Mina) > > > - remove WARNs on invalid user input (Mina) > > > - pre-assign niovs in binding->vec for RX case (Mina) > > > - use atomic_set(, 0) to initialize sk_user_frags.urefs > > > - fix length of alloc for urefs > > > --- > > > Documentation/netlink/specs/netdev.yaml | 12 > > > include/net/netmem.h| 1 + > > > include/net/sock.h | 7 ++- > > > include/uapi/linux/netdev.h | 1 + > > > net/core/devmem.c | 104 > > > > > > net/core/devmem.h | 27 - > > > net/core/netdev-genl-gen.c | 5 +- > > > net/core/netdev-genl.c | 10 ++- > > > net/core/sock.c | 57 +++-- > > > net/ipv4/tcp.c | 76 ++
Re: [PATCH net-next v9 3/5] net: devmem: implement autorelease token management
On Tue, Jan 13, 2026 at 12:42:50PM -0800, Mina Almasry wrote: > On Tue, Jan 13, 2026 at 12:32 PM Bobby Eshleman > wrote: > > > > On Tue, Jan 13, 2026 at 11:27:38AM -0800, Mina Almasry wrote: > > > On Mon, Jan 12, 2026 at 8:24 AM Bobby Eshleman > > > wrote: > > > > > > > > On Sun, Jan 11, 2026 at 11:12:19AM -0800, Mina Almasry wrote: > > > > > On Fri, Jan 9, 2026 at 6:19 PM Bobby Eshleman > > > > > wrote: > > > > > > > > > > > > From: Bobby Eshleman > > > > > > > > > > > > Add support for autorelease toggling of tokens using a static > > > > > > branch to > > > > > > control system-wide behavior. This allows applications to choose > > > > > > between > > > > > > two memory management modes: > > > > > > > > > > > > 1. Autorelease on: Leaked tokens are automatically released when the > > > > > >socket closes. > > > > > > > > > > > > 2. Autorelease off: Leaked tokens are released during dmabuf unbind. > > > > > > > > > > > > The autorelease mode is requested via the > > > > > > NETDEV_A_DMABUF_AUTORELEASE > > > > > > attribute of the NETDEV_CMD_BIND_RX message. Having separate modes > > > > > > per > > > > > > binding is disallowed and is rejected by netlink. The system will be > > > > > > "locked" into the mode that the first binding is set to. It can > > > > > > only be > > > > > > changed again once there are zero bindings on the system. > > > > > > > > > > > > Disabling autorelease offers ~13% improvement in CPU utilization. > > > > > > > > > > > > Static branching is used to limit the system to one mode or the > > > > > > other. > > > > > > > > > > > > Signed-off-by: Bobby Eshleman > > > > > > --- > > > > > > Changes in v9: > > > > > > - Add missing stub for net_devmem_dmabuf_binding_get() when > > > > > > NET_DEVMEM=n > > > > > > - Add wrapper around tcp_devmem_ar_key accesses so that it may be > > > > > > stubbed out when NET_DEVMEM=n > > > > > > - only dec rx binding count for rx bindings in free (v8 did not > > > > > > exclude > > > > > > TX bindings) > > > > > > > > > > > > Changes in v8: > > > > > > - Only reset static key when bindings go to zero, defaulting back to > > > > > > disabled (Stan). > > > > > > - Fix bad usage of xarray spinlock for sleepy static branch > > > > > > switching, > > > > > > use mutex instead. > > > > > > - Access pp_ref_count via niov->desc instead of niov directly. > > > > > > - Move reset of static key to __net_devmem_dmabuf_binding_free() so > > > > > > that > > > > > > the static key can not be changed while there are outstanding > > > > > > tokens > > > > > > (free is only called when reference count reaches zero). > > > > > > - Add net_devmem_dmabuf_rx_bindings_count because tokens may be > > > > > > active > > > > > > even after xa_erase(), so static key changes must wait until all > > > > > > RX bindings are finally freed (not just when xarray is empty). A > > > > > > counter is a simple way to track this. > > > > > > - socket takes reference on the binding, to avoid use-after-free on > > > > > > sk_devmem_info.binding in the case that user releases all tokens, > > > > > > unbinds, then issues SO_DEVMEM_DONTNEED again (with bad token). > > > > > > - removed some comments that were unnecessary > > > > > > > > > > > > Changes in v7: > > > > > > - implement autorelease with static branch (Stan) > > > > > > - use netlink instead of sockopt (Stan) > > > > > > - merge uAPI and implementation patches into one patch (seemed less > > > > > > confusing) > > > > > > > > > > > > Changes in v6: > > > > > > - remove sk_devmem_info.autorelease, using binding->autorelease > > > > > > instead > > > > > > - move binding->autorelease check to outside of > > > > > > net_devmem_dmabuf_binding_put_urefs() (Mina) > > > > > > - remove overly defensive net_is_devmem_iov() (Mina) > > > > > > - add comment about multiple urefs mapping to a single netmem ref > > > > > > (Mina) > > > > > > - remove overly defense netmem NULL and netmem_is_net_iov checks > > > > > > (Mina) > > > > > > - use niov without casting back and forth with netmem (Mina) > > > > > > - move the autorelease flag from per-binding to per-socket (Mina) > > > > > > - remove the batching logic in sock_devmem_dontneed_manual_release() > > > > > > (Mina) > > > > > > - move autorelease check inside tcp_xa_pool_commit() (Mina) > > > > > > - remove single-binding restriction for autorelease mode (Mina) > > > > > > - unbind always checks for leaked urefs > > > > > > > > > > > > Changes in v5: > > > > > > - remove unused variables > > > > > > - introduce autorelease flag, preparing for future patch toggle new > > > > > > behavior > > > > > > > > > > > > Changes in v3: > > > > > > - make urefs per-binding instead of per-socket, reducing memory > > > > > > footprint > > > > > > - fallback to cleaning up references in dmabuf unbind if socket > > > > > > leaked > > > > > > tokens > > > > > > - drop ethtool patch > > > > > > > > > > > > Changes in v2: > > > > > > - always use GF
Re: [PATCH net-next v9 3/5] net: devmem: implement autorelease token management
On Tue, Jan 13, 2026 at 12:42:50PM -0800, Mina Almasry wrote: > On Tue, Jan 13, 2026 at 12:32 PM Bobby Eshleman > wrote: > > > > On Tue, Jan 13, 2026 at 11:27:38AM -0800, Mina Almasry wrote: > > > On Mon, Jan 12, 2026 at 8:24 AM Bobby Eshleman > > > wrote: > > > > > > > > On Sun, Jan 11, 2026 at 11:12:19AM -0800, Mina Almasry wrote: > > > > > On Fri, Jan 9, 2026 at 6:19 PM Bobby Eshleman > > > > > wrote: > > > > > > > > > > > > From: Bobby Eshleman > > > > > > > > > > > > Add support for autorelease toggling of tokens using a static > > > > > > branch to > > > > > > control system-wide behavior. This allows applications to choose > > > > > > between > > > > > > two memory management modes: > > > > > > > > > > > > 1. Autorelease on: Leaked tokens are automatically released when the > > > > > >socket closes. > > > > > > > > > > > > 2. Autorelease off: Leaked tokens are released during dmabuf unbind. > > > > > > > > > > > > The autorelease mode is requested via the > > > > > > NETDEV_A_DMABUF_AUTORELEASE > > > > > > attribute of the NETDEV_CMD_BIND_RX message. Having separate modes > > > > > > per > > > > > > binding is disallowed and is rejected by netlink. The system will be > > > > > > "locked" into the mode that the first binding is set to. It can > > > > > > only be > > > > > > changed again once there are zero bindings on the system. > > > > > > > > > > > > Disabling autorelease offers ~13% improvement in CPU utilization. > > > > > > > > > > > > Static branching is used to limit the system to one mode or the > > > > > > other. > > > > > > > > > > > > Signed-off-by: Bobby Eshleman > > > > > > --- > > > > > > Changes in v9: > > > > > > - Add missing stub for net_devmem_dmabuf_binding_get() when > > > > > > NET_DEVMEM=n > > > > > > - Add wrapper around tcp_devmem_ar_key accesses so that it may be > > > > > > stubbed out when NET_DEVMEM=n > > > > > > - only dec rx binding count for rx bindings in free (v8 did not > > > > > > exclude > > > > > > TX bindings) > > > > > > > > > > > > Changes in v8: > > > > > > - Only reset static key when bindings go to zero, defaulting back to > > > > > > disabled (Stan). > > > > > > - Fix bad usage of xarray spinlock for sleepy static branch > > > > > > switching, > > > > > > use mutex instead. > > > > > > - Access pp_ref_count via niov->desc instead of niov directly. > > > > > > - Move reset of static key to __net_devmem_dmabuf_binding_free() so > > > > > > that > > > > > > the static key can not be changed while there are outstanding > > > > > > tokens > > > > > > (free is only called when reference count reaches zero). > > > > > > - Add net_devmem_dmabuf_rx_bindings_count because tokens may be > > > > > > active > > > > > > even after xa_erase(), so static key changes must wait until all > > > > > > RX bindings are finally freed (not just when xarray is empty). A > > > > > > counter is a simple way to track this. > > > > > > - socket takes reference on the binding, to avoid use-after-free on > > > > > > sk_devmem_info.binding in the case that user releases all tokens, > > > > > > unbinds, then issues SO_DEVMEM_DONTNEED again (with bad token). > > > > > > - removed some comments that were unnecessary > > > > > > > > > > > > Changes in v7: > > > > > > - implement autorelease with static branch (Stan) > > > > > > - use netlink instead of sockopt (Stan) > > > > > > - merge uAPI and implementation patches into one patch (seemed less > > > > > > confusing) > > > > > > > > > > > > Changes in v6: > > > > > > - remove sk_devmem_info.autorelease, using binding->autorelease > > > > > > instead > > > > > > - move binding->autorelease check to outside of > > > > > > net_devmem_dmabuf_binding_put_urefs() (Mina) > > > > > > - remove overly defensive net_is_devmem_iov() (Mina) > > > > > > - add comment about multiple urefs mapping to a single netmem ref > > > > > > (Mina) > > > > > > - remove overly defense netmem NULL and netmem_is_net_iov checks > > > > > > (Mina) > > > > > > - use niov without casting back and forth with netmem (Mina) > > > > > > - move the autorelease flag from per-binding to per-socket (Mina) > > > > > > - remove the batching logic in sock_devmem_dontneed_manual_release() > > > > > > (Mina) > > > > > > - move autorelease check inside tcp_xa_pool_commit() (Mina) > > > > > > - remove single-binding restriction for autorelease mode (Mina) > > > > > > - unbind always checks for leaked urefs > > > > > > > > > > > > Changes in v5: > > > > > > - remove unused variables > > > > > > - introduce autorelease flag, preparing for future patch toggle new > > > > > > behavior > > > > > > > > > > > > Changes in v3: > > > > > > - make urefs per-binding instead of per-socket, reducing memory > > > > > > footprint > > > > > > - fallback to cleaning up references in dmabuf unbind if socket > > > > > > leaked > > > > > > tokens > > > > > > - drop ethtool patch > > > > > > > > > > > > Changes in v2: > > > > > > - always use GF
Re: [PATCH net-next v9 3/5] net: devmem: implement autorelease token management
On Tue, Jan 13, 2026 at 12:32 PM Bobby Eshleman wrote: > > On Tue, Jan 13, 2026 at 11:27:38AM -0800, Mina Almasry wrote: > > On Mon, Jan 12, 2026 at 8:24 AM Bobby Eshleman > > wrote: > > > > > > On Sun, Jan 11, 2026 at 11:12:19AM -0800, Mina Almasry wrote: > > > > On Fri, Jan 9, 2026 at 6:19 PM Bobby Eshleman > > > > wrote: > > > > > > > > > > From: Bobby Eshleman > > > > > > > > > > Add support for autorelease toggling of tokens using a static branch > > > > > to > > > > > control system-wide behavior. This allows applications to choose > > > > > between > > > > > two memory management modes: > > > > > > > > > > 1. Autorelease on: Leaked tokens are automatically released when the > > > > >socket closes. > > > > > > > > > > 2. Autorelease off: Leaked tokens are released during dmabuf unbind. > > > > > > > > > > The autorelease mode is requested via the NETDEV_A_DMABUF_AUTORELEASE > > > > > attribute of the NETDEV_CMD_BIND_RX message. Having separate modes per > > > > > binding is disallowed and is rejected by netlink. The system will be > > > > > "locked" into the mode that the first binding is set to. It can only > > > > > be > > > > > changed again once there are zero bindings on the system. > > > > > > > > > > Disabling autorelease offers ~13% improvement in CPU utilization. > > > > > > > > > > Static branching is used to limit the system to one mode or the other. > > > > > > > > > > Signed-off-by: Bobby Eshleman > > > > > --- > > > > > Changes in v9: > > > > > - Add missing stub for net_devmem_dmabuf_binding_get() when > > > > > NET_DEVMEM=n > > > > > - Add wrapper around tcp_devmem_ar_key accesses so that it may be > > > > > stubbed out when NET_DEVMEM=n > > > > > - only dec rx binding count for rx bindings in free (v8 did not > > > > > exclude > > > > > TX bindings) > > > > > > > > > > Changes in v8: > > > > > - Only reset static key when bindings go to zero, defaulting back to > > > > > disabled (Stan). > > > > > - Fix bad usage of xarray spinlock for sleepy static branch switching, > > > > > use mutex instead. > > > > > - Access pp_ref_count via niov->desc instead of niov directly. > > > > > - Move reset of static key to __net_devmem_dmabuf_binding_free() so > > > > > that > > > > > the static key can not be changed while there are outstanding tokens > > > > > (free is only called when reference count reaches zero). > > > > > - Add net_devmem_dmabuf_rx_bindings_count because tokens may be active > > > > > even after xa_erase(), so static key changes must wait until all > > > > > RX bindings are finally freed (not just when xarray is empty). A > > > > > counter is a simple way to track this. > > > > > - socket takes reference on the binding, to avoid use-after-free on > > > > > sk_devmem_info.binding in the case that user releases all tokens, > > > > > unbinds, then issues SO_DEVMEM_DONTNEED again (with bad token). > > > > > - removed some comments that were unnecessary > > > > > > > > > > Changes in v7: > > > > > - implement autorelease with static branch (Stan) > > > > > - use netlink instead of sockopt (Stan) > > > > > - merge uAPI and implementation patches into one patch (seemed less > > > > > confusing) > > > > > > > > > > Changes in v6: > > > > > - remove sk_devmem_info.autorelease, using binding->autorelease > > > > > instead > > > > > - move binding->autorelease check to outside of > > > > > net_devmem_dmabuf_binding_put_urefs() (Mina) > > > > > - remove overly defensive net_is_devmem_iov() (Mina) > > > > > - add comment about multiple urefs mapping to a single netmem ref > > > > > (Mina) > > > > > - remove overly defense netmem NULL and netmem_is_net_iov checks > > > > > (Mina) > > > > > - use niov without casting back and forth with netmem (Mina) > > > > > - move the autorelease flag from per-binding to per-socket (Mina) > > > > > - remove the batching logic in sock_devmem_dontneed_manual_release() > > > > > (Mina) > > > > > - move autorelease check inside tcp_xa_pool_commit() (Mina) > > > > > - remove single-binding restriction for autorelease mode (Mina) > > > > > - unbind always checks for leaked urefs > > > > > > > > > > Changes in v5: > > > > > - remove unused variables > > > > > - introduce autorelease flag, preparing for future patch toggle new > > > > > behavior > > > > > > > > > > Changes in v3: > > > > > - make urefs per-binding instead of per-socket, reducing memory > > > > > footprint > > > > > - fallback to cleaning up references in dmabuf unbind if socket leaked > > > > > tokens > > > > > - drop ethtool patch > > > > > > > > > > Changes in v2: > > > > > - always use GFP_ZERO for binding->vec (Mina) > > > > > - remove WARN for changed binding (Mina) > > > > > - remove extraneous binding ref get (Mina) > > > > > - remove WARNs on invalid user input (Mina) > > > > > - pre-assign niovs in binding->vec for RX case (Mina) > > > > > - use atomic_set(, 0) to initialize sk_user_frags.urefs > > > > > - fix length of alloc for urefs
Re: [PATCH net-next v9 3/5] net: devmem: implement autorelease token management
On Tue, Jan 13, 2026 at 11:27:38AM -0800, Mina Almasry wrote: > On Mon, Jan 12, 2026 at 8:24 AM Bobby Eshleman > wrote: > > > > On Sun, Jan 11, 2026 at 11:12:19AM -0800, Mina Almasry wrote: > > > On Fri, Jan 9, 2026 at 6:19 PM Bobby Eshleman > > > wrote: > > > > > > > > From: Bobby Eshleman > > > > > > > > Add support for autorelease toggling of tokens using a static branch to > > > > control system-wide behavior. This allows applications to choose between > > > > two memory management modes: > > > > > > > > 1. Autorelease on: Leaked tokens are automatically released when the > > > >socket closes. > > > > > > > > 2. Autorelease off: Leaked tokens are released during dmabuf unbind. > > > > > > > > The autorelease mode is requested via the NETDEV_A_DMABUF_AUTORELEASE > > > > attribute of the NETDEV_CMD_BIND_RX message. Having separate modes per > > > > binding is disallowed and is rejected by netlink. The system will be > > > > "locked" into the mode that the first binding is set to. It can only be > > > > changed again once there are zero bindings on the system. > > > > > > > > Disabling autorelease offers ~13% improvement in CPU utilization. > > > > > > > > Static branching is used to limit the system to one mode or the other. > > > > > > > > Signed-off-by: Bobby Eshleman > > > > --- > > > > Changes in v9: > > > > - Add missing stub for net_devmem_dmabuf_binding_get() when NET_DEVMEM=n > > > > - Add wrapper around tcp_devmem_ar_key accesses so that it may be > > > > stubbed out when NET_DEVMEM=n > > > > - only dec rx binding count for rx bindings in free (v8 did not exclude > > > > TX bindings) > > > > > > > > Changes in v8: > > > > - Only reset static key when bindings go to zero, defaulting back to > > > > disabled (Stan). > > > > - Fix bad usage of xarray spinlock for sleepy static branch switching, > > > > use mutex instead. > > > > - Access pp_ref_count via niov->desc instead of niov directly. > > > > - Move reset of static key to __net_devmem_dmabuf_binding_free() so that > > > > the static key can not be changed while there are outstanding tokens > > > > (free is only called when reference count reaches zero). > > > > - Add net_devmem_dmabuf_rx_bindings_count because tokens may be active > > > > even after xa_erase(), so static key changes must wait until all > > > > RX bindings are finally freed (not just when xarray is empty). A > > > > counter is a simple way to track this. > > > > - socket takes reference on the binding, to avoid use-after-free on > > > > sk_devmem_info.binding in the case that user releases all tokens, > > > > unbinds, then issues SO_DEVMEM_DONTNEED again (with bad token). > > > > - removed some comments that were unnecessary > > > > > > > > Changes in v7: > > > > - implement autorelease with static branch (Stan) > > > > - use netlink instead of sockopt (Stan) > > > > - merge uAPI and implementation patches into one patch (seemed less > > > > confusing) > > > > > > > > Changes in v6: > > > > - remove sk_devmem_info.autorelease, using binding->autorelease instead > > > > - move binding->autorelease check to outside of > > > > net_devmem_dmabuf_binding_put_urefs() (Mina) > > > > - remove overly defensive net_is_devmem_iov() (Mina) > > > > - add comment about multiple urefs mapping to a single netmem ref (Mina) > > > > - remove overly defense netmem NULL and netmem_is_net_iov checks (Mina) > > > > - use niov without casting back and forth with netmem (Mina) > > > > - move the autorelease flag from per-binding to per-socket (Mina) > > > > - remove the batching logic in sock_devmem_dontneed_manual_release() > > > > (Mina) > > > > - move autorelease check inside tcp_xa_pool_commit() (Mina) > > > > - remove single-binding restriction for autorelease mode (Mina) > > > > - unbind always checks for leaked urefs > > > > > > > > Changes in v5: > > > > - remove unused variables > > > > - introduce autorelease flag, preparing for future patch toggle new > > > > behavior > > > > > > > > Changes in v3: > > > > - make urefs per-binding instead of per-socket, reducing memory > > > > footprint > > > > - fallback to cleaning up references in dmabuf unbind if socket leaked > > > > tokens > > > > - drop ethtool patch > > > > > > > > Changes in v2: > > > > - always use GFP_ZERO for binding->vec (Mina) > > > > - remove WARN for changed binding (Mina) > > > > - remove extraneous binding ref get (Mina) > > > > - remove WARNs on invalid user input (Mina) > > > > - pre-assign niovs in binding->vec for RX case (Mina) > > > > - use atomic_set(, 0) to initialize sk_user_frags.urefs > > > > - fix length of alloc for urefs > > > > --- > > > > Documentation/netlink/specs/netdev.yaml | 12 > > > > include/net/netmem.h| 1 + > > > > include/net/sock.h | 7 ++- > > > > include/uapi/linux/netdev.h | 1 + > > > > net/core/devmem.c | 104 > > > > > > > >
Re: [PATCH net-next v9 3/5] net: devmem: implement autorelease token management
On Mon, Jan 12, 2026 at 8:24 AM Bobby Eshleman wrote: > > On Sun, Jan 11, 2026 at 11:12:19AM -0800, Mina Almasry wrote: > > On Fri, Jan 9, 2026 at 6:19 PM Bobby Eshleman > > wrote: > > > > > > From: Bobby Eshleman > > > > > > Add support for autorelease toggling of tokens using a static branch to > > > control system-wide behavior. This allows applications to choose between > > > two memory management modes: > > > > > > 1. Autorelease on: Leaked tokens are automatically released when the > > >socket closes. > > > > > > 2. Autorelease off: Leaked tokens are released during dmabuf unbind. > > > > > > The autorelease mode is requested via the NETDEV_A_DMABUF_AUTORELEASE > > > attribute of the NETDEV_CMD_BIND_RX message. Having separate modes per > > > binding is disallowed and is rejected by netlink. The system will be > > > "locked" into the mode that the first binding is set to. It can only be > > > changed again once there are zero bindings on the system. > > > > > > Disabling autorelease offers ~13% improvement in CPU utilization. > > > > > > Static branching is used to limit the system to one mode or the other. > > > > > > Signed-off-by: Bobby Eshleman > > > --- > > > Changes in v9: > > > - Add missing stub for net_devmem_dmabuf_binding_get() when NET_DEVMEM=n > > > - Add wrapper around tcp_devmem_ar_key accesses so that it may be > > > stubbed out when NET_DEVMEM=n > > > - only dec rx binding count for rx bindings in free (v8 did not exclude > > > TX bindings) > > > > > > Changes in v8: > > > - Only reset static key when bindings go to zero, defaulting back to > > > disabled (Stan). > > > - Fix bad usage of xarray spinlock for sleepy static branch switching, > > > use mutex instead. > > > - Access pp_ref_count via niov->desc instead of niov directly. > > > - Move reset of static key to __net_devmem_dmabuf_binding_free() so that > > > the static key can not be changed while there are outstanding tokens > > > (free is only called when reference count reaches zero). > > > - Add net_devmem_dmabuf_rx_bindings_count because tokens may be active > > > even after xa_erase(), so static key changes must wait until all > > > RX bindings are finally freed (not just when xarray is empty). A > > > counter is a simple way to track this. > > > - socket takes reference on the binding, to avoid use-after-free on > > > sk_devmem_info.binding in the case that user releases all tokens, > > > unbinds, then issues SO_DEVMEM_DONTNEED again (with bad token). > > > - removed some comments that were unnecessary > > > > > > Changes in v7: > > > - implement autorelease with static branch (Stan) > > > - use netlink instead of sockopt (Stan) > > > - merge uAPI and implementation patches into one patch (seemed less > > > confusing) > > > > > > Changes in v6: > > > - remove sk_devmem_info.autorelease, using binding->autorelease instead > > > - move binding->autorelease check to outside of > > > net_devmem_dmabuf_binding_put_urefs() (Mina) > > > - remove overly defensive net_is_devmem_iov() (Mina) > > > - add comment about multiple urefs mapping to a single netmem ref (Mina) > > > - remove overly defense netmem NULL and netmem_is_net_iov checks (Mina) > > > - use niov without casting back and forth with netmem (Mina) > > > - move the autorelease flag from per-binding to per-socket (Mina) > > > - remove the batching logic in sock_devmem_dontneed_manual_release() > > > (Mina) > > > - move autorelease check inside tcp_xa_pool_commit() (Mina) > > > - remove single-binding restriction for autorelease mode (Mina) > > > - unbind always checks for leaked urefs > > > > > > Changes in v5: > > > - remove unused variables > > > - introduce autorelease flag, preparing for future patch toggle new > > > behavior > > > > > > Changes in v3: > > > - make urefs per-binding instead of per-socket, reducing memory > > > footprint > > > - fallback to cleaning up references in dmabuf unbind if socket leaked > > > tokens > > > - drop ethtool patch > > > > > > Changes in v2: > > > - always use GFP_ZERO for binding->vec (Mina) > > > - remove WARN for changed binding (Mina) > > > - remove extraneous binding ref get (Mina) > > > - remove WARNs on invalid user input (Mina) > > > - pre-assign niovs in binding->vec for RX case (Mina) > > > - use atomic_set(, 0) to initialize sk_user_frags.urefs > > > - fix length of alloc for urefs > > > --- > > > Documentation/netlink/specs/netdev.yaml | 12 > > > include/net/netmem.h| 1 + > > > include/net/sock.h | 7 ++- > > > include/uapi/linux/netdev.h | 1 + > > > net/core/devmem.c | 104 > > > > > > net/core/devmem.h | 27 - > > > net/core/netdev-genl-gen.c | 5 +- > > > net/core/netdev-genl.c | 10 ++- > > > net/core/sock.c | 57 +++-- > > > net/ipv4/tcp.c
Re: [PATCH net-next v9 3/5] net: devmem: implement autorelease token management
On Sun, Jan 11, 2026 at 11:27:14AM -0800, Mina Almasry wrote: > On Sun, Jan 11, 2026 at 11:12 AM Mina Almasry wrote: > > > > On Fri, Jan 9, 2026 at 6:19 PM Bobby Eshleman > > wrote: > > > > > > From: Bobby Eshleman > > > > > > Add support for autorelease toggling of tokens using a static branch to > > > control system-wide behavior. This allows applications to choose between > > > two memory management modes: > > > > > > 1. Autorelease on: Leaked tokens are automatically released when the > > >socket closes. > > > > > > 2. Autorelease off: Leaked tokens are released during dmabuf unbind. > > > > > > The autorelease mode is requested via the NETDEV_A_DMABUF_AUTORELEASE > > > attribute of the NETDEV_CMD_BIND_RX message. Having separate modes per > > > binding is disallowed and is rejected by netlink. The system will be > > > "locked" into the mode that the first binding is set to. It can only be > > > changed again once there are zero bindings on the system. > > > > > > Disabling autorelease offers ~13% improvement in CPU utilization. > > > > > > Static branching is used to limit the system to one mode or the other. > > > > > > Signed-off-by: Bobby Eshleman > > > --- > > > Changes in v9: > > > - Add missing stub for net_devmem_dmabuf_binding_get() when NET_DEVMEM=n > > > - Add wrapper around tcp_devmem_ar_key accesses so that it may be > > > stubbed out when NET_DEVMEM=n > > > - only dec rx binding count for rx bindings in free (v8 did not exclude > > > TX bindings) > > > > > > Changes in v8: > > > - Only reset static key when bindings go to zero, defaulting back to > > > disabled (Stan). > > > - Fix bad usage of xarray spinlock for sleepy static branch switching, > > > use mutex instead. > > > - Access pp_ref_count via niov->desc instead of niov directly. > > > - Move reset of static key to __net_devmem_dmabuf_binding_free() so that > > > the static key can not be changed while there are outstanding tokens > > > (free is only called when reference count reaches zero). > > > - Add net_devmem_dmabuf_rx_bindings_count because tokens may be active > > > even after xa_erase(), so static key changes must wait until all > > > RX bindings are finally freed (not just when xarray is empty). A > > > counter is a simple way to track this. > > > - socket takes reference on the binding, to avoid use-after-free on > > > sk_devmem_info.binding in the case that user releases all tokens, > > > unbinds, then issues SO_DEVMEM_DONTNEED again (with bad token). > > > - removed some comments that were unnecessary > > > > > > Changes in v7: > > > - implement autorelease with static branch (Stan) > > > - use netlink instead of sockopt (Stan) > > > - merge uAPI and implementation patches into one patch (seemed less > > > confusing) > > > > > > Changes in v6: > > > - remove sk_devmem_info.autorelease, using binding->autorelease instead > > > - move binding->autorelease check to outside of > > > net_devmem_dmabuf_binding_put_urefs() (Mina) > > > - remove overly defensive net_is_devmem_iov() (Mina) > > > - add comment about multiple urefs mapping to a single netmem ref (Mina) > > > - remove overly defense netmem NULL and netmem_is_net_iov checks (Mina) > > > - use niov without casting back and forth with netmem (Mina) > > > - move the autorelease flag from per-binding to per-socket (Mina) > > > - remove the batching logic in sock_devmem_dontneed_manual_release() > > > (Mina) > > > - move autorelease check inside tcp_xa_pool_commit() (Mina) > > > - remove single-binding restriction for autorelease mode (Mina) > > > - unbind always checks for leaked urefs > > > > > > Changes in v5: > > > - remove unused variables > > > - introduce autorelease flag, preparing for future patch toggle new > > > behavior > > > > > > Changes in v3: > > > - make urefs per-binding instead of per-socket, reducing memory > > > footprint > > > - fallback to cleaning up references in dmabuf unbind if socket leaked > > > tokens > > > - drop ethtool patch > > > > > > Changes in v2: > > > - always use GFP_ZERO for binding->vec (Mina) > > > - remove WARN for changed binding (Mina) > > > - remove extraneous binding ref get (Mina) > > > - remove WARNs on invalid user input (Mina) > > > - pre-assign niovs in binding->vec for RX case (Mina) > > > - use atomic_set(, 0) to initialize sk_user_frags.urefs > > > - fix length of alloc for urefs > > > --- > > > Documentation/netlink/specs/netdev.yaml | 12 > > > include/net/netmem.h| 1 + > > > include/net/sock.h | 7 ++- > > > include/uapi/linux/netdev.h | 1 + > > > net/core/devmem.c | 104 > > > > > > net/core/devmem.h | 27 - > > > net/core/netdev-genl-gen.c | 5 +- > > > net/core/netdev-genl.c | 10 ++- > > > net/core/sock.c | 57 +++-- > > > net/ipv4/tcp.c
Re: [PATCH net-next v9 3/5] net: devmem: implement autorelease token management
On Sun, Jan 11, 2026 at 11:12:19AM -0800, Mina Almasry wrote: > On Fri, Jan 9, 2026 at 6:19 PM Bobby Eshleman wrote: > > > > From: Bobby Eshleman > > > > Add support for autorelease toggling of tokens using a static branch to > > control system-wide behavior. This allows applications to choose between > > two memory management modes: > > > > 1. Autorelease on: Leaked tokens are automatically released when the > >socket closes. > > > > 2. Autorelease off: Leaked tokens are released during dmabuf unbind. > > > > The autorelease mode is requested via the NETDEV_A_DMABUF_AUTORELEASE > > attribute of the NETDEV_CMD_BIND_RX message. Having separate modes per > > binding is disallowed and is rejected by netlink. The system will be > > "locked" into the mode that the first binding is set to. It can only be > > changed again once there are zero bindings on the system. > > > > Disabling autorelease offers ~13% improvement in CPU utilization. > > > > Static branching is used to limit the system to one mode or the other. > > > > Signed-off-by: Bobby Eshleman > > --- > > Changes in v9: > > - Add missing stub for net_devmem_dmabuf_binding_get() when NET_DEVMEM=n > > - Add wrapper around tcp_devmem_ar_key accesses so that it may be > > stubbed out when NET_DEVMEM=n > > - only dec rx binding count for rx bindings in free (v8 did not exclude > > TX bindings) > > > > Changes in v8: > > - Only reset static key when bindings go to zero, defaulting back to > > disabled (Stan). > > - Fix bad usage of xarray spinlock for sleepy static branch switching, > > use mutex instead. > > - Access pp_ref_count via niov->desc instead of niov directly. > > - Move reset of static key to __net_devmem_dmabuf_binding_free() so that > > the static key can not be changed while there are outstanding tokens > > (free is only called when reference count reaches zero). > > - Add net_devmem_dmabuf_rx_bindings_count because tokens may be active > > even after xa_erase(), so static key changes must wait until all > > RX bindings are finally freed (not just when xarray is empty). A > > counter is a simple way to track this. > > - socket takes reference on the binding, to avoid use-after-free on > > sk_devmem_info.binding in the case that user releases all tokens, > > unbinds, then issues SO_DEVMEM_DONTNEED again (with bad token). > > - removed some comments that were unnecessary > > > > Changes in v7: > > - implement autorelease with static branch (Stan) > > - use netlink instead of sockopt (Stan) > > - merge uAPI and implementation patches into one patch (seemed less > > confusing) > > > > Changes in v6: > > - remove sk_devmem_info.autorelease, using binding->autorelease instead > > - move binding->autorelease check to outside of > > net_devmem_dmabuf_binding_put_urefs() (Mina) > > - remove overly defensive net_is_devmem_iov() (Mina) > > - add comment about multiple urefs mapping to a single netmem ref (Mina) > > - remove overly defense netmem NULL and netmem_is_net_iov checks (Mina) > > - use niov without casting back and forth with netmem (Mina) > > - move the autorelease flag from per-binding to per-socket (Mina) > > - remove the batching logic in sock_devmem_dontneed_manual_release() > > (Mina) > > - move autorelease check inside tcp_xa_pool_commit() (Mina) > > - remove single-binding restriction for autorelease mode (Mina) > > - unbind always checks for leaked urefs > > > > Changes in v5: > > - remove unused variables > > - introduce autorelease flag, preparing for future patch toggle new > > behavior > > > > Changes in v3: > > - make urefs per-binding instead of per-socket, reducing memory > > footprint > > - fallback to cleaning up references in dmabuf unbind if socket leaked > > tokens > > - drop ethtool patch > > > > Changes in v2: > > - always use GFP_ZERO for binding->vec (Mina) > > - remove WARN for changed binding (Mina) > > - remove extraneous binding ref get (Mina) > > - remove WARNs on invalid user input (Mina) > > - pre-assign niovs in binding->vec for RX case (Mina) > > - use atomic_set(, 0) to initialize sk_user_frags.urefs > > - fix length of alloc for urefs > > --- > > Documentation/netlink/specs/netdev.yaml | 12 > > include/net/netmem.h| 1 + > > include/net/sock.h | 7 ++- > > include/uapi/linux/netdev.h | 1 + > > net/core/devmem.c | 104 > > > > net/core/devmem.h | 27 - > > net/core/netdev-genl-gen.c | 5 +- > > net/core/netdev-genl.c | 10 ++- > > net/core/sock.c | 57 +++-- > > net/ipv4/tcp.c | 76 ++- > > net/ipv4/tcp_ipv4.c | 11 +++- > > net/ipv4/tcp_minisocks.c| 3 +- > > tools/include/uapi/linux/netdev.h | 1 + > > 13 files changed, 269 insertions(+), 46 deletions(-) >
Re: [PATCH net-next v9 3/5] net: devmem: implement autorelease token management
On Sun, Jan 11, 2026 at 11:12 AM Mina Almasry wrote: > > On Fri, Jan 9, 2026 at 6:19 PM Bobby Eshleman wrote: > > > > From: Bobby Eshleman > > > > Add support for autorelease toggling of tokens using a static branch to > > control system-wide behavior. This allows applications to choose between > > two memory management modes: > > > > 1. Autorelease on: Leaked tokens are automatically released when the > >socket closes. > > > > 2. Autorelease off: Leaked tokens are released during dmabuf unbind. > > > > The autorelease mode is requested via the NETDEV_A_DMABUF_AUTORELEASE > > attribute of the NETDEV_CMD_BIND_RX message. Having separate modes per > > binding is disallowed and is rejected by netlink. The system will be > > "locked" into the mode that the first binding is set to. It can only be > > changed again once there are zero bindings on the system. > > > > Disabling autorelease offers ~13% improvement in CPU utilization. > > > > Static branching is used to limit the system to one mode or the other. > > > > Signed-off-by: Bobby Eshleman > > --- > > Changes in v9: > > - Add missing stub for net_devmem_dmabuf_binding_get() when NET_DEVMEM=n > > - Add wrapper around tcp_devmem_ar_key accesses so that it may be > > stubbed out when NET_DEVMEM=n > > - only dec rx binding count for rx bindings in free (v8 did not exclude > > TX bindings) > > > > Changes in v8: > > - Only reset static key when bindings go to zero, defaulting back to > > disabled (Stan). > > - Fix bad usage of xarray spinlock for sleepy static branch switching, > > use mutex instead. > > - Access pp_ref_count via niov->desc instead of niov directly. > > - Move reset of static key to __net_devmem_dmabuf_binding_free() so that > > the static key can not be changed while there are outstanding tokens > > (free is only called when reference count reaches zero). > > - Add net_devmem_dmabuf_rx_bindings_count because tokens may be active > > even after xa_erase(), so static key changes must wait until all > > RX bindings are finally freed (not just when xarray is empty). A > > counter is a simple way to track this. > > - socket takes reference on the binding, to avoid use-after-free on > > sk_devmem_info.binding in the case that user releases all tokens, > > unbinds, then issues SO_DEVMEM_DONTNEED again (with bad token). > > - removed some comments that were unnecessary > > > > Changes in v7: > > - implement autorelease with static branch (Stan) > > - use netlink instead of sockopt (Stan) > > - merge uAPI and implementation patches into one patch (seemed less > > confusing) > > > > Changes in v6: > > - remove sk_devmem_info.autorelease, using binding->autorelease instead > > - move binding->autorelease check to outside of > > net_devmem_dmabuf_binding_put_urefs() (Mina) > > - remove overly defensive net_is_devmem_iov() (Mina) > > - add comment about multiple urefs mapping to a single netmem ref (Mina) > > - remove overly defense netmem NULL and netmem_is_net_iov checks (Mina) > > - use niov without casting back and forth with netmem (Mina) > > - move the autorelease flag from per-binding to per-socket (Mina) > > - remove the batching logic in sock_devmem_dontneed_manual_release() > > (Mina) > > - move autorelease check inside tcp_xa_pool_commit() (Mina) > > - remove single-binding restriction for autorelease mode (Mina) > > - unbind always checks for leaked urefs > > > > Changes in v5: > > - remove unused variables > > - introduce autorelease flag, preparing for future patch toggle new > > behavior > > > > Changes in v3: > > - make urefs per-binding instead of per-socket, reducing memory > > footprint > > - fallback to cleaning up references in dmabuf unbind if socket leaked > > tokens > > - drop ethtool patch > > > > Changes in v2: > > - always use GFP_ZERO for binding->vec (Mina) > > - remove WARN for changed binding (Mina) > > - remove extraneous binding ref get (Mina) > > - remove WARNs on invalid user input (Mina) > > - pre-assign niovs in binding->vec for RX case (Mina) > > - use atomic_set(, 0) to initialize sk_user_frags.urefs > > - fix length of alloc for urefs > > --- > > Documentation/netlink/specs/netdev.yaml | 12 > > include/net/netmem.h| 1 + > > include/net/sock.h | 7 ++- > > include/uapi/linux/netdev.h | 1 + > > net/core/devmem.c | 104 > > > > net/core/devmem.h | 27 - > > net/core/netdev-genl-gen.c | 5 +- > > net/core/netdev-genl.c | 10 ++- > > net/core/sock.c | 57 +++-- > > net/ipv4/tcp.c | 76 ++- > > net/ipv4/tcp_ipv4.c | 11 +++- > > net/ipv4/tcp_minisocks.c| 3 +- > > tools/include/uapi/linux/netdev.h | 1 + > > 13 files changed, 269 insertions(+), 46 deletions(-) > > > >
Re: [PATCH net-next v9 3/5] net: devmem: implement autorelease token management
On Fri, Jan 9, 2026 at 6:19 PM Bobby Eshleman wrote: > > From: Bobby Eshleman > > Add support for autorelease toggling of tokens using a static branch to > control system-wide behavior. This allows applications to choose between > two memory management modes: > > 1. Autorelease on: Leaked tokens are automatically released when the >socket closes. > > 2. Autorelease off: Leaked tokens are released during dmabuf unbind. > > The autorelease mode is requested via the NETDEV_A_DMABUF_AUTORELEASE > attribute of the NETDEV_CMD_BIND_RX message. Having separate modes per > binding is disallowed and is rejected by netlink. The system will be > "locked" into the mode that the first binding is set to. It can only be > changed again once there are zero bindings on the system. > > Disabling autorelease offers ~13% improvement in CPU utilization. > > Static branching is used to limit the system to one mode or the other. > > Signed-off-by: Bobby Eshleman > --- > Changes in v9: > - Add missing stub for net_devmem_dmabuf_binding_get() when NET_DEVMEM=n > - Add wrapper around tcp_devmem_ar_key accesses so that it may be > stubbed out when NET_DEVMEM=n > - only dec rx binding count for rx bindings in free (v8 did not exclude > TX bindings) > > Changes in v8: > - Only reset static key when bindings go to zero, defaulting back to > disabled (Stan). > - Fix bad usage of xarray spinlock for sleepy static branch switching, > use mutex instead. > - Access pp_ref_count via niov->desc instead of niov directly. > - Move reset of static key to __net_devmem_dmabuf_binding_free() so that > the static key can not be changed while there are outstanding tokens > (free is only called when reference count reaches zero). > - Add net_devmem_dmabuf_rx_bindings_count because tokens may be active > even after xa_erase(), so static key changes must wait until all > RX bindings are finally freed (not just when xarray is empty). A > counter is a simple way to track this. > - socket takes reference on the binding, to avoid use-after-free on > sk_devmem_info.binding in the case that user releases all tokens, > unbinds, then issues SO_DEVMEM_DONTNEED again (with bad token). > - removed some comments that were unnecessary > > Changes in v7: > - implement autorelease with static branch (Stan) > - use netlink instead of sockopt (Stan) > - merge uAPI and implementation patches into one patch (seemed less > confusing) > > Changes in v6: > - remove sk_devmem_info.autorelease, using binding->autorelease instead > - move binding->autorelease check to outside of > net_devmem_dmabuf_binding_put_urefs() (Mina) > - remove overly defensive net_is_devmem_iov() (Mina) > - add comment about multiple urefs mapping to a single netmem ref (Mina) > - remove overly defense netmem NULL and netmem_is_net_iov checks (Mina) > - use niov without casting back and forth with netmem (Mina) > - move the autorelease flag from per-binding to per-socket (Mina) > - remove the batching logic in sock_devmem_dontneed_manual_release() > (Mina) > - move autorelease check inside tcp_xa_pool_commit() (Mina) > - remove single-binding restriction for autorelease mode (Mina) > - unbind always checks for leaked urefs > > Changes in v5: > - remove unused variables > - introduce autorelease flag, preparing for future patch toggle new > behavior > > Changes in v3: > - make urefs per-binding instead of per-socket, reducing memory > footprint > - fallback to cleaning up references in dmabuf unbind if socket leaked > tokens > - drop ethtool patch > > Changes in v2: > - always use GFP_ZERO for binding->vec (Mina) > - remove WARN for changed binding (Mina) > - remove extraneous binding ref get (Mina) > - remove WARNs on invalid user input (Mina) > - pre-assign niovs in binding->vec for RX case (Mina) > - use atomic_set(, 0) to initialize sk_user_frags.urefs > - fix length of alloc for urefs > --- > Documentation/netlink/specs/netdev.yaml | 12 > include/net/netmem.h| 1 + > include/net/sock.h | 7 ++- > include/uapi/linux/netdev.h | 1 + > net/core/devmem.c | 104 > > net/core/devmem.h | 27 - > net/core/netdev-genl-gen.c | 5 +- > net/core/netdev-genl.c | 10 ++- > net/core/sock.c | 57 +++-- > net/ipv4/tcp.c | 76 ++- > net/ipv4/tcp_ipv4.c | 11 +++- > net/ipv4/tcp_minisocks.c| 3 +- > tools/include/uapi/linux/netdev.h | 1 + > 13 files changed, 269 insertions(+), 46 deletions(-) > > diff --git a/Documentation/netlink/specs/netdev.yaml > b/Documentation/netlink/specs/netdev.yaml > index 596c306ce52b..7cbe9e7b9ee5 100644 > --- a/Documentation/netlink/specs/netdev.yaml > +++ b/Documentation/netlink/specs/netdev.yaml > @@ -562,6 +562,17 @@ attribute-sets:
