Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp603942iog; Mon, 13 Jun 2022 09:00:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQxkY3Q5zU6dDFBFfIL4F2yKJA+qo9bQ5UCJNCLKcE4Xbem4Y8KITO9k8bGbX/MK2qlA/w X-Received: by 2002:a17:90b:1c0d:b0:1e8:7596:f20 with SMTP id oc13-20020a17090b1c0d00b001e875960f20mr16808790pjb.35.1655136010287; Mon, 13 Jun 2022 09:00:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655136010; cv=none; d=google.com; s=arc-20160816; b=TgMED+pd9Ls/mEzPV1bxWVu6jTXy12aGCF/dz4mtVVBglT9+7VSnjoMABrMrS7urfl T2/3hkGR6KOu/nVvO4hS0LEpufXf6uPA0bwvUmTtpdqUo8JLPFcPdknoBRm0KDlNWacy o/Wx1QvkZnwiARmKnPBf+LnDLTU3qYRpg59egKjqOZ5sb8pGeVtyrZe6c6UB9uPq4I4U TLYrgCAzXp1k1YO+9tex97QovDbUzmUJnYFsa+MDcC3/Ig5hu6txFyoim44G3lXGClS7 VvmVO0LcdHKX+XrN0TZqms+CVvna0yvVJTOwJCBSufX2Aitl/uqyqO9OjC6gWbmoWPtk zaZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ojwXXJ+LydtMzKnr41LI3hF2AJ/9pDJrph2+02hj96M=; b=PbsQQZMpL0YaBHBfyLhv+12wHQj31PXAAp998saNXtZNiaJY69rg8wVq24Sbn6PZwR oZkKbAExCWlOmfPy+2c+UBLyCZlRibbbV5RrCob1DtAHj6GDg7DNJbGEwxT3l5Sr3K0U H3sHc3RkGMQWrJeBp3Qxc2w9t+yD/E0G1DCoXAzIXZpIkyzEu5kxumISEO17QhTrJLex 7roSkuv6FIk5uzY3h55ACFrpj4CDwNVw3lzFXqgC+2stj1T1DDUTOUgFqAJqXFUXAQpY Z0gUKfez/n2IrOlhR6oVQ/4V/HS5Hm9AETkapkdUDOtbG9x6UGbjFICLDT8TLdgPOHIy 69sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vK2MsvvJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x3-20020a170902ec8300b00168a4ef6a67si11980266plg.17.2022.06.13.08.59.56; Mon, 13 Jun 2022 09:00:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vK2MsvvJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358420AbiFMNGz (ORCPT + 99 others); Mon, 13 Jun 2022 09:06:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354182AbiFMMzi (ORCPT ); Mon, 13 Jun 2022 08:55:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6140B10FF0; Mon, 13 Jun 2022 04:16:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DA91060B60; Mon, 13 Jun 2022 11:16:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E823CC34114; Mon, 13 Jun 2022 11:16:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655118984; bh=g9IIzdz8fFZu4zLpGSUu9Qx+xG/NwPMEEzYsxd6wuio=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vK2MsvvJTEgCvFzdl7wdVdZBA3FiAAsDcgdMzQRLZ/8pqiVs1oasGOnB8ZXUv1Ktk kYTJnaplERr9I2Mv9bAHeRcDLjlFLdaBNTr3KGUm0e83YGKqZsFpaIZxSkoK13My71 HQBYDhiQb35GG3pC4FQ7uBx/Rjpptjrc9jRU3yuo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guoju Fang , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 098/247] net: sched: add barrier to fix packet stuck problem for lockless qdisc Date: Mon, 13 Jun 2022 12:10:00 +0200 Message-Id: <20220613094925.927928910@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094922.843438024@linuxfoundation.org> References: <20220613094922.843438024@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Guoju Fang [ Upstream commit 2e8728c955ce0624b958eee6e030a37aca3a5d86 ] In qdisc_run_end(), the spin_unlock() only has store-release semantic, which guarantees all earlier memory access are visible before it. But the subsequent test_bit() has no barrier semantics so may be reordered ahead of the spin_unlock(). The store-load reordering may cause a packet stuck problem. The concurrent operations can be described as below, CPU 0 | CPU 1 qdisc_run_end() | qdisc_run_begin() . | . ----> /* may be reorderd here */ | . | . | . | spin_unlock() | set_bit() | . | smp_mb__after_atomic() ---- test_bit() | spin_trylock() . | . Consider the following sequence of events: CPU 0 reorder test_bit() ahead and see MISSED = 0 CPU 1 calls set_bit() CPU 1 calls spin_trylock() and return fail CPU 0 executes spin_unlock() At the end of the sequence, CPU 0 calls spin_unlock() and does nothing because it see MISSED = 0. The skb on CPU 1 has beed enqueued but no one take it, until the next cpu pushing to the qdisc (if ever ...) will notice and dequeue it. This patch fix this by adding one explicit barrier. As spin_unlock() and test_bit() ordering is a store-load ordering, a full memory barrier smp_mb() is needed here. Fixes: a90c57f2cedd ("net: sched: fix packet stuck problem for lockless qdisc") Signed-off-by: Guoju Fang Link: https://lore.kernel.org/r/20220528101628.120193-1-gjfang@linux.alibaba.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- include/net/sch_generic.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h index 9e9ff13adda8..1958d1260fe9 100644 --- a/include/net/sch_generic.h +++ b/include/net/sch_generic.h @@ -202,6 +202,12 @@ static inline void qdisc_run_end(struct Qdisc *qdisc) if (qdisc->flags & TCQ_F_NOLOCK) { spin_unlock(&qdisc->seqlock); + /* spin_unlock() only has store-release semantic. The unlock + * and test_bit() ordering is a store-load ordering, so a full + * memory barrier is needed here. + */ + smp_mb(); + if (unlikely(test_bit(__QDISC_STATE_MISSED, &qdisc->state))) __netif_schedule(qdisc); -- 2.35.1