Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Yunsheng Lin <linyunsheng@huawei.com>
To: Eric Dumazet <eric.dumazet@gmail.com>, <jhs@mojatatu.com>,
	<xiyou.wangcong@gmail.com>, <jiri@resnulli.us>,
	<davem@davemloft.net>, <kuba@kernel.org>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linuxarm@huawei.com>, <john.fastabend@gmail.com>
Subject: Re: [PATCH net-next] net: sch_generic: aviod concurrent reset and enqueue op for lockless qdisc
Date: Tue, 1 Sep 2020 15:27:44 +0800	[thread overview]
Message-ID: <2b60e7fd-a86a-89ab-2759-e7a83e0e28cd@huawei.com> (raw)
In-Reply-To: <2d93706f-3ba6-128b-738a-b063216eba6d@gmail.com>

On 2020/9/1 14:48, Eric Dumazet wrote:
> 
> 
> On 8/31/20 5:55 PM, Yunsheng Lin wrote:
>> Currently there is concurrent reset and enqueue operation for the
>> same lockless qdisc when there is no lock to synchronize the
>> q->enqueue() in __dev_xmit_skb() with the qdisc reset operation in
>> qdisc_deactivate() called by dev_deactivate_queue(), which may cause
>> out-of-bounds access for priv->ring[] in hns3 driver if user has
>> requested a smaller queue num when __dev_xmit_skb() still enqueue a
>> skb with a larger queue_mapping after the corresponding qdisc is
>> reset, and call hns3_nic_net_xmit() with that skb later.
>>
>> Avoid the above concurrent op by calling synchronize_rcu_tasks()
>> after assigning new qdisc to dev_queue->qdisc and before calling
>> qdisc_deactivate() to make sure skb with larger queue_mapping
>> enqueued to old qdisc will always be reset when qdisc_deactivate()
>> is called.
>>
> 
> We request Fixes: tag for fixes in networking land.

ok.

Fixes: 6b3ba9146fe6 ("net: sched: allow qdiscs to handle locking")

> 
>> Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
>> ---
>>  net/sched/sch_generic.c | 7 ++++++-
>>  1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
>> index 265a61d..6e42237 100644
>> --- a/net/sched/sch_generic.c
>> +++ b/net/sched/sch_generic.c
>> @@ -1160,8 +1160,13 @@ static void dev_deactivate_queue(struct net_device *dev,
>>  
>>  	qdisc = rtnl_dereference(dev_queue->qdisc);
>>  	if (qdisc) {
>> -		qdisc_deactivate(qdisc);
>>  		rcu_assign_pointer(dev_queue->qdisc, qdisc_default);
>> +
>> +		/* Make sure lockless qdisc enqueuing is done with the
>> +		 * old qdisc in __dev_xmit_skb().
>> +		 */
>> +		synchronize_rcu_tasks();
> 
> This seems quite wrong, there is not a single use of synchronize_rcu_tasks() in net/,
> we probably do not want this.
> 
> I bet that synchronize_net() is appropriate, if not please explain/comment why we want this instead.

Using synchronize_net() seems more appropriate here, thanks.

> 
> Adding one synchronize_net() per TX queue is a killer for devices with 128 or 256 TX queues.
> 
> I would rather find a way of not calling qdisc_reset() from qdisc_deactivate().

Without calling qdisc_reset(), it seems there will always be skb left in the old qdisc.
Is above acceptable?

How about below steps to avoid the concurrent op:
1. assign new qdisc to all queue' qdisc(which is noop_qdisc).
2. call synchronize_net().
3. calling qdisc_reset() with all queue' qdisc_sleeping.

And the synchronize_net() in dev_deactivate_many() can be reused to
ensure old qdisc is not touched any more when calling qdisc_reset().


> 
> This lockless pfifo_fast is a mess really.
> 
> 
> .
> 

  reply	other threads:[~2020-09-01  7:27 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-01  0:55 Yunsheng Lin
2020-09-01  6:48 ` Eric Dumazet
2020-09-01  7:27   ` Yunsheng Lin [this message]
2020-09-01 18:34     ` David Miller
2020-09-02  1:43       ` Yunsheng Lin
2020-09-01 18:24 ` Cong Wang
2020-09-02  1:42   ` Yunsheng Lin
2020-09-02  4:41     ` Cong Wang
2020-09-02  6:34       ` Yunsheng Lin
2020-09-02  7:32         ` Eric Dumazet
2020-09-02  8:14           ` Yunsheng Lin
2020-09-02  9:20             ` Eric Dumazet
2020-09-03  1:14               ` Yunsheng Lin
2020-09-03  7:24                 ` Eric Dumazet
2020-09-04  8:10                   ` Yunsheng Lin
2020-09-03  0:35         ` Cong Wang
2020-09-03  1:21           ` Yunsheng Lin
2020-09-03  1:48             ` Cong Wang
2020-09-03  2:22               ` Yunsheng Lin
2020-09-03  2:53                 ` Cong Wang
2020-09-04  1:30                   ` John Fastabend
2020-09-04  8:08                     ` Yunsheng Lin
2020-09-06  8:52 ` [net] 6fd0d0dede: hwsim.ap_ht40_5ghz_switch.fail kernel test robot

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=2b60e7fd-a86a-89ab-2759-e7a83e0e28cd@huawei.com \
    --to=linyunsheng@huawei.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=xiyou.wangcong@gmail.com \
    --subject='Re: [PATCH net-next] net: sch_generic: aviod concurrent reset and enqueue op for lockless qdisc' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).