include/net/netmem.h | 19 +++++++++++++++++++ net/core/devmem.c | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+)
Currently there is no way to check if there is a dmabuf bound on a TX
queue. RX side has netif_rxq_has_unreadable_mp() which gives a hint of
it.
To help with that, this patch add a helper to check whether a devmem
dmabuf binding is active on a given netdev, optionally filtered by the
DMA device the dmabuf was mapped against.
This API is necessary for the upcoming support of data direct in mlx5e
to allow blocking accidental swapping of DMA devices while devmem is active.
Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
---
include/net/netmem.h | 19 +++++++++++++++++++
net/core/devmem.c | 20 ++++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/include/net/netmem.h b/include/net/netmem.h
index bccacd21b6c3..0e332e04ea16 100644
--- a/include/net/netmem.h
+++ b/include/net/netmem.h
@@ -363,16 +363,35 @@ static inline unsigned long netmem_get_dma_addr(netmem_ref netmem)
return netmem_to_nmdesc(netmem)->dma_addr;
}
+struct net_device;
+
#if defined(CONFIG_NET_DEVMEM)
static inline bool net_is_devmem_iov(const struct net_iov *niov)
{
return niov->type == NET_IOV_DMABUF;
}
+
+/**
+ * netdev_has_dmabuf_binding - is there a dmabuf binding for a
+ * given @dev and @dma_dev
+ *
+ * @dev: netdev to check bindings
+ * @dma_dev: dma device to check, when NULL it will not be checked
+ *
+ * Return: true if a binding is found under @dev and possibily @dma_dev
+ */
+bool netdev_has_dmabuf_binding(struct net_device *dev, struct device *dma_dev);
#else
static inline bool net_is_devmem_iov(const struct net_iov *niov)
{
return false;
}
+
+static inline bool netdev_has_dmabuf_binding(struct net_device *dev,
+ struct device *dma_dev)
+{
+ return false;
+}
#endif
void __get_netmem(netmem_ref netmem);
diff --git a/net/core/devmem.c b/net/core/devmem.c
index 957d6b96216b..f13a0e343684 100644
--- a/net/core/devmem.c
+++ b/net/core/devmem.c
@@ -364,6 +364,26 @@ struct net_devmem_dmabuf_binding *net_devmem_lookup_dmabuf(u32 id)
return binding;
}
+bool netdev_has_dmabuf_binding(struct net_device *dev, struct device *dma_dev)
+{
+ struct net_devmem_dmabuf_binding *binding;
+ unsigned long id;
+ bool found = false;
+
+ rcu_read_lock();
+ xa_for_each(&net_devmem_dmabuf_bindings, id, binding) {
+ if (READ_ONCE(binding->dev) == dev &&
+ (!dma_dev || binding->attachment->dev == dma_dev)) {
+ found = true;
+ break;
+ }
+ }
+ rcu_read_unlock();
+
+ return found;
+}
+EXPORT_SYMBOL_GPL(netdev_has_dmabuf_binding);
+
void net_devmem_get_net_iov(struct net_iov *niov)
{
net_devmem_dmabuf_binding_get(net_devmem_iov_binding(niov));
--
2.54.0
On Mon, Aug 10, 2026 at 1:59 PM Dragos Tatulea <dtatulea@nvidia.com> wrote:
>
> Currently there is no way to check if there is a dmabuf bound on a TX
> queue. RX side has netif_rxq_has_unreadable_mp() which gives a hint of
> it.
>
> To help with that, this patch add a helper to check whether a devmem
> dmabuf binding is active on a given netdev, optionally filtered by the
> DMA device the dmabuf was mapped against.
>
> This API is necessary for the upcoming support of data direct in mlx5e
> to allow blocking accidental swapping of DMA devices while devmem is active.
>
> Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
> ---
> include/net/netmem.h | 19 +++++++++++++++++++
> net/core/devmem.c | 20 ++++++++++++++++++++
> 2 files changed, 39 insertions(+)
>
> diff --git a/include/net/netmem.h b/include/net/netmem.h
> index bccacd21b6c3..0e332e04ea16 100644
> --- a/include/net/netmem.h
> +++ b/include/net/netmem.h
> @@ -363,16 +363,35 @@ static inline unsigned long netmem_get_dma_addr(netmem_ref netmem)
> return netmem_to_nmdesc(netmem)->dma_addr;
> }
>
> +struct net_device;
> +
> #if defined(CONFIG_NET_DEVMEM)
> static inline bool net_is_devmem_iov(const struct net_iov *niov)
> {
> return niov->type == NET_IOV_DMABUF;
> }
> +
> +/**
> + * netdev_has_dmabuf_binding - is there a dmabuf binding for a
> + * given @dev and @dma_dev
> + *
> + * @dev: netdev to check bindings
> + * @dma_dev: dma device to check, when NULL it will not be checked
> + *
> + * Return: true if a binding is found under @dev and possibily @dma_dev
> + */
> +bool netdev_has_dmabuf_binding(struct net_device *dev, struct device *dma_dev);
> #else
> static inline bool net_is_devmem_iov(const struct net_iov *niov)
> {
> return false;
> }
> +
> +static inline bool netdev_has_dmabuf_binding(struct net_device *dev,
> + struct device *dma_dev)
> +{
> + return false;
> +}
> #endif
>
> void __get_netmem(netmem_ref netmem);
> diff --git a/net/core/devmem.c b/net/core/devmem.c
> index 957d6b96216b..f13a0e343684 100644
> --- a/net/core/devmem.c
> +++ b/net/core/devmem.c
> @@ -364,6 +364,26 @@ struct net_devmem_dmabuf_binding *net_devmem_lookup_dmabuf(u32 id)
> return binding;
> }
>
> +bool netdev_has_dmabuf_binding(struct net_device *dev, struct device *dma_dev)
> +{
> + struct net_devmem_dmabuf_binding *binding;
> + unsigned long id;
> + bool found = false;
> +
> + rcu_read_lock();
Why do you need rcu locking? I thought xarrays handle concurrency
inside their helpers.
--
Thanks,
Mina
On 11.08.26 19:25, Mina Almasry wrote:
> On Mon, Aug 10, 2026 at 1:59 PM Dragos Tatulea <dtatulea@nvidia.com> wrote:
>>
>> Currently there is no way to check if there is a dmabuf bound on a TX
>> queue. RX side has netif_rxq_has_unreadable_mp() which gives a hint of
>> it.
>>
>> To help with that, this patch add a helper to check whether a devmem
>> dmabuf binding is active on a given netdev, optionally filtered by the
>> DMA device the dmabuf was mapped against.
>>
>> This API is necessary for the upcoming support of data direct in mlx5e
>> to allow blocking accidental swapping of DMA devices while devmem is active.
>>
>> Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
>> ---
>> include/net/netmem.h | 19 +++++++++++++++++++
>> net/core/devmem.c | 20 ++++++++++++++++++++
>> 2 files changed, 39 insertions(+)
>>
>> diff --git a/include/net/netmem.h b/include/net/netmem.h
>> index bccacd21b6c3..0e332e04ea16 100644
>> --- a/include/net/netmem.h
>> +++ b/include/net/netmem.h
>> @@ -363,16 +363,35 @@ static inline unsigned long netmem_get_dma_addr(netmem_ref netmem)
>> return netmem_to_nmdesc(netmem)->dma_addr;
>> }
>>
>> +struct net_device;
>> +
>> #if defined(CONFIG_NET_DEVMEM)
>> static inline bool net_is_devmem_iov(const struct net_iov *niov)
>> {
>> return niov->type == NET_IOV_DMABUF;
>> }
>> +
>> +/**
>> + * netdev_has_dmabuf_binding - is there a dmabuf binding for a
>> + * given @dev and @dma_dev
>> + *
>> + * @dev: netdev to check bindings
>> + * @dma_dev: dma device to check, when NULL it will not be checked
>> + *
>> + * Return: true if a binding is found under @dev and possibily @dma_dev
>> + */
>> +bool netdev_has_dmabuf_binding(struct net_device *dev, struct device *dma_dev);
>> #else
>> static inline bool net_is_devmem_iov(const struct net_iov *niov)
>> {
>> return false;
>> }
>> +
>> +static inline bool netdev_has_dmabuf_binding(struct net_device *dev,
>> + struct device *dma_dev)
>> +{
>> + return false;
>> +}
>> #endif
>>
>> void __get_netmem(netmem_ref netmem);
>> diff --git a/net/core/devmem.c b/net/core/devmem.c
>> index 957d6b96216b..f13a0e343684 100644
>> --- a/net/core/devmem.c
>> +++ b/net/core/devmem.c
>> @@ -364,6 +364,26 @@ struct net_devmem_dmabuf_binding *net_devmem_lookup_dmabuf(u32 id)
>> return binding;
>> }
>>
>> +bool netdev_has_dmabuf_binding(struct net_device *dev, struct device *dma_dev)
>> +{
>> + struct net_devmem_dmabuf_binding *binding;
>> + unsigned long id;
>> + bool found = false;
>> +
>> + rcu_read_lock();
>
> Why do you need rcu locking? I thought xarrays handle concurrency
> inside their helpers.
>
Not needed. Monkey see monkey do from net_devmem_lookup_dmabuf(). Will drop.
Thank,
Dragos
On 08/10, Dragos Tatulea wrote:
> Currently there is no way to check if there is a dmabuf bound on a TX
> queue. RX side has netif_rxq_has_unreadable_mp() which gives a hint of
> it.
>
> To help with that, this patch add a helper to check whether a devmem
> dmabuf binding is active on a given netdev, optionally filtered by the
> DMA device the dmabuf was mapped against.
>
> This API is necessary for the upcoming support of data direct in mlx5e
> to allow blocking accidental swapping of DMA devices while devmem is active.
>
> Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
> ---
> include/net/netmem.h | 19 +++++++++++++++++++
> net/core/devmem.c | 20 ++++++++++++++++++++
> 2 files changed, 39 insertions(+)
>
> diff --git a/include/net/netmem.h b/include/net/netmem.h
> index bccacd21b6c3..0e332e04ea16 100644
> --- a/include/net/netmem.h
> +++ b/include/net/netmem.h
> @@ -363,16 +363,35 @@ static inline unsigned long netmem_get_dma_addr(netmem_ref netmem)
> return netmem_to_nmdesc(netmem)->dma_addr;
> }
>
> +struct net_device;
> +
> #if defined(CONFIG_NET_DEVMEM)
> static inline bool net_is_devmem_iov(const struct net_iov *niov)
> {
> return niov->type == NET_IOV_DMABUF;
> }
> +
> +/**
> + * netdev_has_dmabuf_binding - is there a dmabuf binding for a
> + * given @dev and @dma_dev
> + *
> + * @dev: netdev to check bindings
> + * @dma_dev: dma device to check, when NULL it will not be checked
> + *
> + * Return: true if a binding is found under @dev and possibily @dma_dev
> + */
> +bool netdev_has_dmabuf_binding(struct net_device *dev, struct device *dma_dev);
> #else
> static inline bool net_is_devmem_iov(const struct net_iov *niov)
> {
> return false;
> }
> +
> +static inline bool netdev_has_dmabuf_binding(struct net_device *dev,
> + struct device *dma_dev)
> +{
> + return false;
> +}
> #endif
>
> void __get_netmem(netmem_ref netmem);
> diff --git a/net/core/devmem.c b/net/core/devmem.c
> index 957d6b96216b..f13a0e343684 100644
> --- a/net/core/devmem.c
> +++ b/net/core/devmem.c
> @@ -364,6 +364,26 @@ struct net_devmem_dmabuf_binding *net_devmem_lookup_dmabuf(u32 id)
> return binding;
> }
>
> +bool netdev_has_dmabuf_binding(struct net_device *dev, struct device *dma_dev)
> +{
> + struct net_devmem_dmabuf_binding *binding;
> + unsigned long id;
> + bool found = false;
xmas tree. Other than that LGTM. Presumably it's better to ship via your
upcoming series to show the actual usage?
On 11.08.26 02:25, Stanislav Fomichev wrote:
> On 08/10, Dragos Tatulea wrote:
>> Currently there is no way to check if there is a dmabuf bound on a TX
>> queue. RX side has netif_rxq_has_unreadable_mp() which gives a hint of
>> it.
>>
>> To help with that, this patch add a helper to check whether a devmem
>> dmabuf binding is active on a given netdev, optionally filtered by the
>> DMA device the dmabuf was mapped against.
>>
>> This API is necessary for the upcoming support of data direct in mlx5e
>> to allow blocking accidental swapping of DMA devices while devmem is active.
>>
>> Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com>
>> ---
>> include/net/netmem.h | 19 +++++++++++++++++++
>> net/core/devmem.c | 20 ++++++++++++++++++++
>> 2 files changed, 39 insertions(+)
>>
>> diff --git a/include/net/netmem.h b/include/net/netmem.h
>> index bccacd21b6c3..0e332e04ea16 100644
>> --- a/include/net/netmem.h
>> +++ b/include/net/netmem.h
>> @@ -363,16 +363,35 @@ static inline unsigned long netmem_get_dma_addr(netmem_ref netmem)
>> return netmem_to_nmdesc(netmem)->dma_addr;
>> }
>>
>> +struct net_device;
>> +
>> #if defined(CONFIG_NET_DEVMEM)
>> static inline bool net_is_devmem_iov(const struct net_iov *niov)
>> {
>> return niov->type == NET_IOV_DMABUF;
>> }
>> +
>> +/**
>> + * netdev_has_dmabuf_binding - is there a dmabuf binding for a
>> + * given @dev and @dma_dev
>> + *
>> + * @dev: netdev to check bindings
>> + * @dma_dev: dma device to check, when NULL it will not be checked
>> + *
>> + * Return: true if a binding is found under @dev and possibily @dma_dev
>> + */
>> +bool netdev_has_dmabuf_binding(struct net_device *dev, struct device *dma_dev);
>> #else
>> static inline bool net_is_devmem_iov(const struct net_iov *niov)
>> {
>> return false;
>> }
>> +
>> +static inline bool netdev_has_dmabuf_binding(struct net_device *dev,
>> + struct device *dma_dev)
>> +{
>> + return false;
>> +}
>> #endif
>>
>> void __get_netmem(netmem_ref netmem);
>> diff --git a/net/core/devmem.c b/net/core/devmem.c
>> index 957d6b96216b..f13a0e343684 100644
>> --- a/net/core/devmem.c
>> +++ b/net/core/devmem.c
>> @@ -364,6 +364,26 @@ struct net_devmem_dmabuf_binding *net_devmem_lookup_dmabuf(u32 id)
>> return binding;
>> }
>>
>> +bool netdev_has_dmabuf_binding(struct net_device *dev, struct device *dma_dev)
>> +{
>> + struct net_devmem_dmabuf_binding *binding;
>> + unsigned long id;
>> + bool found = false;
>
> xmas tree. Other than that LGTM.
Seems like Bobby found a valid corner case that needs to be handled.
> Presumably it's better to ship via your upcoming series to show the actual usage?
I will do that eventually, but would like to get some ACKs about this bit
so that Tariq doesn't have to re-send the whole series every time.
Thanks,
Dragos
© 2016 - 2026 Red Hat, Inc.