Re: [PATCH net-next] net: devmem: add netdev_has_dmabuf_binding() helper

Dragos Tatulea <[email protected]>
Newsgroups org.kernel.vger.netdev,org.kernel.vger.linux-kernel
Message-ID <[email protected]>

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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.