Re: [PATCH net-next] net: devmem: add netdev_has_dmabuf_binding() helper
From: Dragos Tatulea
Date: Tue Aug 11 2026 - 03:31:47 EST
On 11.08.26 00:17, bobbyeshleman wrote:
> On Mon, Aug 10, 2026 at 08:54:45PM +0300, Dragos Tatulea wrote:> [...]
>> +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
>>
>
> I think netdev_has_dmabuf_binding() can return false even when there
> exists one or more in-flight skbs (e.g., in sk_write_queue) backed by
> the txq binding (won't technically be inactive until the final reference
> is dropped and the binding is freed)? If so, can this still detect when
> it is safe to swap the underlying dma dev?
>
Oh, good point! I didn't realize that the binding is refcounted and can
outlive its xarray slot.
Thanks,
Dragos