From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA7C8C433B4 for ; Mon, 12 Apr 2021 01:24:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E4F761001 for ; Mon, 12 Apr 2021 01:24:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236513AbhDLBYv (ORCPT ); Sun, 11 Apr 2021 21:24:51 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:3524 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236329AbhDLBYu (ORCPT ); Sun, 11 Apr 2021 21:24:50 -0400 Received: from DGGEML401-HUB.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4FJWDz2M80zRc3N; Mon, 12 Apr 2021 09:22:27 +0800 (CST) Received: from dggpemm500005.china.huawei.com (7.185.36.74) by DGGEML401-HUB.china.huawei.com (10.3.17.32) with Microsoft SMTP Server (TLS) id 14.3.498.0; Mon, 12 Apr 2021 09:24:31 +0800 Received: from [127.0.0.1] (10.69.30.204) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2106.2; Mon, 12 Apr 2021 09:24:31 +0800 Subject: Re: [PATCH net v3] net: sched: fix packet stuck problem for lockless qdisc To: Hillf Danton , Juergen Gross CC: , , Jiri Kosina References: <1616641991-14847-1-git-send-email-linyunsheng@huawei.com> <20210409090909.1767-1-hdanton@sina.com> From: Yunsheng Lin Message-ID: <9cb8d8e3-89e5-2b00-ad16-43f34d6b1340@huawei.com> Date: Mon, 12 Apr 2021 09:24:30 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <20210409090909.1767-1-hdanton@sina.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.69.30.204] X-ClientProxiedBy: dggeme708-chm.china.huawei.com (10.1.199.104) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 2021/4/9 17:09, Hillf Danton wrote: > On Fri, 9 Apr 2021 07:31:03 Juergen Gross wrote: >> On 25.03.21 04:13, Yunsheng Lin wrote: >> I have a setup which is able to reproduce the issue quite reliably: >> >> In a Xen guest I'm mounting 8 NFS shares and run sysbench fileio on >> each of them. The average latency reported by sysbench is well below >> 1 msec, but at least once per hour I get latencies in the minute >> range. >> >> With this patch I don't see these high latencies any longer (test >> is running for more than 20 hours now). >> >> So you can add my: >> >> Tested-by: Juergen Gross >> > > If retry is allowed in the dequeue method then a simple seqcount can do the > work of serializing enqueuer and dequeuer. IIUC it was not attempted last year. At the first glance, I do not think the below patch fix the data race described in the commit log, as it does not handle the time window between dequeuing and q->seqlock releasing, as below: The cpu1 may not see the qdisc->pad changed after pfifo_fast_dequeue(), and cpu2 is not able to take the q->seqlock yet because cpu1 do not release the q->seqlock. > > --- x/net/sched/sch_generic.c > +++ y/net/sched/sch_generic.c > @@ -632,6 +632,9 @@ static int pfifo_fast_enqueue(struct sk_ > return qdisc_drop(skb, qdisc, to_free); > } > > + qdisc->pad++; > + smp_wmb(); > + > qdisc_update_stats_at_enqueue(qdisc, pkt_len); > return NET_XMIT_SUCCESS; > } > @@ -641,6 +644,11 @@ static struct sk_buff *pfifo_fast_dequeu > struct pfifo_fast_priv *priv = qdisc_priv(qdisc); > struct sk_buff *skb = NULL; > int band; > + int seq; > + > +again: > + seq = READ_ONCE(qdisc->pad); > + smp_rmb(); > > for (band = 0; band < PFIFO_FAST_BANDS && !skb; band++) { > struct skb_array *q = band2list(priv, band); > @@ -652,10 +660,15 @@ static struct sk_buff *pfifo_fast_dequeu > } > if (likely(skb)) { > qdisc_update_stats_at_dequeue(qdisc, skb); > - } else { > - WRITE_ONCE(qdisc->empty, true); > + return skb; > } > > + smp_rmb(); > + if (seq != READ_ONCE(qdisc->pad)) > + goto again; > + > + WRITE_ONCE(qdisc->empty, true); > + > return skb; > } > > > . >