Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2729040pxv; Mon, 12 Jul 2021 00:04:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0O6bft57MzDep0+OT6zG6o8PNTVz2GTMdUcJaAhXQtJHv3XIIPgeqmNUr5n+sp9KW3xcp X-Received: by 2002:a92:d3c7:: with SMTP id c7mr8864480ilh.59.1626073442932; Mon, 12 Jul 2021 00:04:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626073442; cv=none; d=google.com; s=arc-20160816; b=i7VPR9Leja2J+6e/4RizbyCy8df//oSAIbfXhMOtotGgosIfYpU8YU9xWEY/vwjbFN AWbFVyuqb9mpnEoIJ1T0qsG/HXPijRhuh8bUVWGAzAINtfsCh1dehb+NRc/6avqbOMOR 2XzwSnSp2/zfURKE57Qp8Q66TMhwa5D9sbxhL7OhANAJ1yHEEGijHQzPxLYi/Euk/LFx WcvfhzJZ71eRxgGo63kE5lLW92ix5VzI9od8hZZNrGEMlJaoj1FkL0RBh5v5ZdfixIAq cGdDm6PxwT1VGYJKZ8A9o+ppuyvVUMTFfHV9Ix7mH5283Y+VS9qnkOvALY++0Y91Kn+x EDoA== 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=r9u6IHiEFFZ4aXhwbscd05SBdtVVxLXAgvYIZ6MWacs=; b=c5AUUeM4x3ElyZPOXer+C6FDngeP1W7JtuI3/SPhJ9BlViQla5v0ukfm2yYBs7f9H+ 9oQ13vP0aX6KHiUwVasOdJfvdjDRuSNG4e1AxdzbUQ/jnC+sj2Lyj9o8Fw2q3gU8SAu/ 0iYToMz+wJ1BVxxuadPTHG2nTETQutdwWqKEQXzInvdq8nCcO+j2qmVqRzo3V6hjqmt9 t3gyMBFvJY4sVz22vMH2VLEQc7bpPhyW2sdZuGKzv3kNHeclrc6sNgjr6C4uWJzojbEH u82ubYrCPvKeRSoIkUkgbWwyLtNhqdC813PQx8bIzK/GH0wle68eYwvxuhohXDiwFJYL pAeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=x3o0eeyv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s13si15854923ioj.45.2021.07.12.00.03.51; Mon, 12 Jul 2021 00:04:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=x3o0eeyv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S242804AbhGLHEM (ORCPT + 99 others); Mon, 12 Jul 2021 03:04:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:41512 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238036AbhGLGqt (ORCPT ); Mon, 12 Jul 2021 02:46:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E0FFF61182; Mon, 12 Jul 2021 06:42:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626072149; bh=1v/lxlfsq3aIurd1LXINS1a003bGmjCaGiYheyhQpNE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x3o0eeyvCx3zI+K+Rfn9h55miuViF3RKh0+FY6HCp5j5pKeWDYpgjwgaM0wyfV140 14UDho+OBmIlVSgMFshpNAwShfdG22GkZ6uigygZfSE+F8GtL44emnRZ8jS3sDimX4 vJl1xEfoRPU5dHy5H9F+piIaCPmFWKkzIfhPpsNI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yunsheng Lin , Jakub Kicinski , "David S. Miller" , Sasha Levin Subject: [PATCH 5.10 374/593] net: sched: add barrier to ensure correct ordering for lockless qdisc Date: Mon, 12 Jul 2021 08:08:54 +0200 Message-Id: <20210712060927.935537282@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yunsheng Lin [ Upstream commit 89837eb4b2463c556a123437f242d6c2bc62ce81 ] The spin_trylock() was assumed to contain the implicit barrier needed to ensure the correct ordering between STATE_MISSED setting/clearing and STATE_MISSED checking in commit a90c57f2cedd ("net: sched: fix packet stuck problem for lockless qdisc"). But it turns out that spin_trylock() only has load-acquire semantic, for strongly-ordered system(like x86), the compiler barrier implicitly contained in spin_trylock() seems enough to ensure the correct ordering. But for weakly-orderly system (like arm64), the store-release semantic is needed to ensure the correct ordering as clear_bit() and test_bit() is store operation, see queued_spin_lock(). So add the explicit barrier to ensure the correct ordering for the above case. Fixes: a90c57f2cedd ("net: sched: fix packet stuck problem for lockless qdisc") Signed-off-by: Yunsheng Lin Acked-by: Jakub Kicinski Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- include/net/sch_generic.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h index 4dd2c9e34976..f8631ad3c868 100644 --- a/include/net/sch_generic.h +++ b/include/net/sch_generic.h @@ -163,6 +163,12 @@ static inline bool qdisc_run_begin(struct Qdisc *qdisc) if (spin_trylock(&qdisc->seqlock)) goto nolock_empty; + /* Paired with smp_mb__after_atomic() to make sure + * STATE_MISSED checking is synchronized with clearing + * in pfifo_fast_dequeue(). + */ + smp_mb__before_atomic(); + /* If the MISSED flag is set, it means other thread has * set the MISSED flag before second spin_trylock(), so * we can return false here to avoid multi cpus doing @@ -180,6 +186,12 @@ static inline bool qdisc_run_begin(struct Qdisc *qdisc) */ set_bit(__QDISC_STATE_MISSED, &qdisc->state); + /* spin_trylock() only has load-acquire semantic, so use + * smp_mb__after_atomic() to ensure STATE_MISSED is set + * before doing the second spin_trylock(). + */ + smp_mb__after_atomic(); + /* Retry again in case other CPU may not see the new flag * after it releases the lock at the end of qdisc_run_end(). */ -- 2.30.2