All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Liang He" <windhl@126.com>
To: "Simon Horman" <simon.horman@corigine.com>
Cc: "Jakub Kicinski" <kuba@kernel.org>,
	davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
	netdev@vger.kernel.org
Subject: Re:Re: [PATCH] rionet: Fix refcounting bugs
Date: Thu, 30 Mar 2023 10:09:42 +0800 (CST)	[thread overview]
Message-ID: <f9af1c5.1a76.187304726fd.Coremail.windhl@126.com> (raw)
In-Reply-To: <ZCR+5p8TGvS+GQsP@corigine.com>



At 2023-03-30 02:09:42, "Simon Horman" <simon.horman@corigine.com> wrote:
>On Wed, Mar 29, 2023 at 02:01:30PM +0800, Liang He wrote:
>> 
>> Hi, Jakub,
>> 
>> First, thanks for you reviewing our patch again.
>> 
>> At 2023-03-29 10:10:51, "Jakub Kicinski" <kuba@kernel.org> wrote:
>> >On Tue, 28 Mar 2023 12:50:06 +0800 Liang He wrote:
>> >> In rionet_start_xmit(), we should put the refcount_inc()
>> >> before we add *skb* into the queue, otherwise it may cause
>> >> the consumer to prematurely call refcount_dec().
>> >
>> >Are you sure the race can happen? Look around the code, please.
>> 
>> We commit this patch based on the pattern we learned from these commits,
>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v6.3-rc4&id=bb765d1c331f62b59049d35607ed2e365802bef9
>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v6.3-rc4&id=47a017f33943278570c072bc71681809b2567b3a
>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v6.3-rc4&id=b780d7415aacec855e2f2370cbf98f918b224903
>> 
>> If it is indeed in different context which makes our pattern failed, please kindly pointing out it.
>
>The difference is that these are not start_xmit callbacks.
>See below.
>
>> >> Besides, before the next rionet_queue_tx_msg() when we
>> >> meet the 'RIONET_MAC_MATCH', we should also call
>> >> refcount_inc() before the skb is added into the queue.
>> >
>> >And why is that?
>> 
>> We think it should be better to keep the consistent refcounting-operation
>> when we put the *skb* into the queue.
>
>It's subjective.
>Due to the locking of the code in question there is no race.
>The code you modify is protected by &rnet->tx_lock.

Thanks for your reply, we get it.

>As is the code that will decrement (and free) the skb.
>
>> >As far as I can tell your patch reorders something that doesn't matter
>> >and then adds a bug :|
>> 
>> If there is any bug, can you kindly tell us?
>
>We are dealing with a start_xmit NDO callback.
>To simplify things, let us only consider cases where
>NETDEV_TX_OK is returned, which is the case for the code you modify.
>In such cases the callback should consume the skb, which already
>has a reference taken on it. This is done in the driver by a call
>to dev_kfree_skb_irq() which is executed indirectly via
>rionet_queue_tx_msg().
>
>So currently the reference count handling is correct.
>By taking an extra reference, it will never reach zero,
>and thus the resources of the skb will be leaked.

Sorry for our trouble.

      reply	other threads:[~2023-03-30  2:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-28  4:50 [PATCH] rionet: Fix refcounting bugs Liang He
2023-03-29  2:10 ` Jakub Kicinski
2023-03-29  6:01   ` Liang He
2023-03-29 18:09     ` Simon Horman
2023-03-30  2:09       ` Liang He [this message]

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=f9af1c5.1a76.187304726fd.Coremail.windhl@126.com \
    --to=windhl@126.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=simon.horman@corigine.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.