Netdev List
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Mina Almasry <almasrymina@google.com>, netdev-bot+sashiko@kernel.org
Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, horms@kernel.org, shuah@kernel.org,
	linux-kselftest@vger.kernel.org, bestswngs@gmail.com,
	daniel@iogearbox.net, razor@blackwall.org, dw@davidwei.uk,
	sdf.kernel@gmail.com, bobbyeshleman@meta.com,
	dtatulea@nvidia.com
Subject: Re: [PATCH net-next v4 5/7] net: devmem: always populate bind_dev and detach both devices on unregister
Date: Tue, 24 Nov 2026 12:26:25 +0100	[thread overview]
Message-ID: <0ccdfcf6-84c9-4b65-b3d0-b2cae7e8e559@redhat.com> (raw)
In-Reply-To: <CAHS8izOptCEaijuhQxtgj-3WAjKQxchNn2Pe62r8ihgdF9b0=Q@mail.gmail.com>

On 11/23/26 16:09, Mina Almasry wrote:
> On Sun, Nov 22, 2026 at 8:59 PM <netdev-bot+sashiko@kernel.org> wrote:
>>
>> Thank you for your contribution! Sashiko AI review found 2 potential
>> issue(s) to consider.
>>
>> Critical: 0 · High: 0 · Medium: 1 · Low: 1
>>
>> If you believe none of the issues are legitimate, please reply to each
>> issue of Medium severity or higher and explain why the AI is wrong.
>> If any of them are legitimate and you plan to respin, please let patchwork
>> know by including "pw-bot: cr" as a separate line at the end of your reply
>> (one such reply per series is enough).
>>
>> - [Medium] Undisclosed user-visible behaviour change for leased TX
>>    bindings.
>> - [Low] The commit message presents this patch as fixing 'issues' found
>>    by AI review of the earlier devmem unregister series, 'confirmed by…
>>
>> --
>>
>> net: devmem: always populate bind_dev and detach both devices on unregister
>>
>> This patch always sets binding->bind_dev to the device that bind-rx or
>> bind-tx was called on. Socket teardown, queue close and queue uninstall
>> now use bind_dev, and net_devmem_dev_unregister() handles bind_dev and
>> map_dev separately, calling synchronize_net() before unmapping when
>> map_dev unregisters. net_devmem_get_binding() also now requires map_dev
>> to be non-NULL.
>>
>>> diff --git a/net/core/devmem.c b/net/core/devmem.c
>>> index 6f85b90950f8b..80c3e149cd762 100644
>>> --- a/net/core/devmem.c
>>> +++ b/net/core/devmem.c
>>
>> [ ... ]
>>
>>> @@ -252,20 +255,33 @@ void net_devmem_dev_unregister(struct net_device *dev)
>>>
>>>        xa_lock(&net_devmem_dmabuf_bindings);
>>>        xa_for_each(&net_devmem_dmabuf_bindings, xa_idx, binding) {
>>> -             if (binding->direction == DMA_FROM_DEVICE) {
>>> -                     if (READ_ONCE(binding->map_dev) != dev ||
>>> -                         xa_get_mark(&net_devmem_dmabuf_bindings, xa_idx,
>>> -                                     NET_DEVMEM_BINDING_LIVE))
>>> -                             continue;
>>> -             } else {
>>> -                     if (READ_ONCE(binding->bind_dev) == dev)
>>> +             if (READ_ONCE(binding->bind_dev) == dev) {
>>> +                     __xa_clear_mark(&net_devmem_dmabuf_bindings, xa_idx,
>>> +                                     NET_DEVMEM_BINDING_LIVE);
>>> +                     if (xa_empty(&binding->bound_rxqs) ||
>>> +                         !netif_is_queue_leasee(dev))
>>>                                WRITE_ONCE(binding->bind_dev, NULL);
>>> -                     if (READ_ONCE(binding->map_dev) != dev)
>>> -                             continue;
>>> -                     WRITE_ONCE(binding->bind_dev, NULL);
>>> +             }
>>
>> [Severity: Medium]
>> Does this change what happens to leased TX bindings when only the virtual
>> device goes away?
>>
>> If bind-tx is called on a netkit device, netdev_find_netmem_tx_dev()
>> picks the physical NIC as map_dev, and bind_dev is now the netkit device.
>> When the netkit device is deleted and the physical NIC stays registered,
>> this first walk matches bind_dev == dev and clears
>> NET_DEVMEM_BINDING_LIVE.
>>
>> After that, net_devmem_get_binding() fails here:
>>
>>          binding = xa_find(&net_devmem_dmabuf_bindings, &xa_idx, dmabuf_id,
>>                            NET_DEVMEM_BINDING_LIVE);
>>
>> So every later devmem sendmsg with that dmabuf id returns -EINVAL, even
>> when dst_dev == map_dev.
>>
>> Before this patch, the code from ede1618064a9 ("net: devmem: detach TX
>> bindings on NETDEV_UNREGISTER") only cleared the virtual device pointer in
>> this case and left the binding live. That commit gave its reason as "only
>> clear binding->vdev so no new TX sends match the virtual device while
>> allowing in-flight TX packets on binding->dev to finish DMA safely".
>>
>> TX bindings have an empty bound_rxqs, so bind_dev is cleared here anyway.
>> net_devmem_get_binding() would then only match map_dev. Does correctness
>> need the LIVE mark to be cleared in this case?
>>
>> If the change is intended, could the commit message say that it reverses
>> the earlier design, and why? Right now it only says "first walk the
>> bindings to clear NET_DEVMEM_BINDING_LIVE to stop new lookups".
>>
>> The same goes for the synchronize_net() added further down for the
>> map_dev case. ede1618064a9 said a grace period was not needed there.
>>
>> This behaviour is still the same at the end of the series. The selftest
>> added later in the series (devmem_lease_bind_tx_unregister_check with
>> remove_virt_first) only checks the dmabuf attach count. It does not check
>> whether sends through the physical device still work.
>>
> 
> This seems like some kind of hallucination? AFAICT after this patch
> we're making the binding not live anymore, so we don't match it
> against new TX, but in validate_xmit we're checking against map_dev,
> not bind_dev, so in-flight packets should be fine as long as the
> map_dev is in tact.
> 
> Also, I'm not sure we care so much about what happens exactly to the
> in-flight TX packets when the binding is being unregistered. The
> application is probably ending tx anyway.

My reading it that clashiko complains WRT tx transmissions failing
after netkit de-registration, while previously completed successfully.

If so, I think it makes sense to rephrase the commit message outlining
the behavior change.

I must admit I find all the commit messages here hard to read, with
too much code description and lack of clarity about what the
addressed race(s) look like. A commit message rewrite would be likely
useful in any case.

Thanks,

Paolo


  reply	other threads:[~2026-11-24 11:26 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  4:59 [PATCH net-next v4 0/7] net: devmem: support leased RX and TX queues on netdev unregister Mina Almasry
2026-11-20  4:59 ` [PATCH net-next v4 1/7] net: devmem: pass net_device pointer to net_devmem_lock_dev() Mina Almasry
2026-11-20  4:59 ` [PATCH net-next v4 2/7] net: devmem: rename binding dev and vdev to map_dev and bind_dev Mina Almasry
2026-11-20  4:59 ` [PATCH net-next v4 3/7] net: guard memory provider RX queue open and close on unregister Mina Almasry
2026-11-23  4:59   ` netdev-bot+sashiko
2026-11-24 11:07   ` Paolo Abeni
2026-11-20  4:59 ` [PATCH net-next v4 4/7] net: devmem: fold net_devmem_lookup_dmabuf() into net_devmem_get_binding() Mina Almasry
2026-11-23  4:59   ` netdev-bot+sashiko
2026-11-20  4:59 ` [PATCH net-next v4 5/7] net: devmem: always populate bind_dev and detach both devices on unregister Mina Almasry
2026-11-23  4:59   ` netdev-bot+sashiko
2026-11-23 15:09     ` Mina Almasry
2026-11-24 11:26       ` Paolo Abeni [this message]
2026-11-20  4:59 ` [PATCH net-next v4 6/7] net: devmem: resolve physical map_dev for leased RX bindings Mina Almasry
2026-11-23  4:59   ` netdev-bot+sashiko
2026-11-20  4:59 ` [PATCH net-next v4 7/7] selftests: net: add leased devmem RX and TX netdev unregister tests Mina Almasry
2026-11-20 17:04 ` [PATCH net-next v4 0/7] net: devmem: support leased RX and TX queues on netdev unregister Stanislav Fomichev
2026-11-22  9:16 ` Nikolay Aleksandrov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0ccdfcf6-84c9-4b65-b3d0-b2cae7e8e559@redhat.com \
    --to=pabeni@redhat.com \
    --cc=almasrymina@google.com \
    --cc=bestswngs@gmail.com \
    --cc=bobbyeshleman@meta.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dtatulea@nvidia.com \
    --cc=dw@davidwei.uk \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=razor@blackwall.org \
    --cc=sdf.kernel@gmail.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox