Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2711360pxv; Sun, 11 Jul 2021 23:29:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoZccvT2bxHw2QCVJTnaqrFuPy/8vWCmaabE8XhSpbYW+C6MxbBeR4aVjF9M0YcddjfrrI X-Received: by 2002:a05:6402:35cf:: with SMTP id z15mr63521780edc.208.1626071383528; Sun, 11 Jul 2021 23:29:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626071383; cv=none; d=google.com; s=arc-20160816; b=CSglQeXoHGikVHxMsCaUZokqzHNvfVLUrjF95e1+zvBn+lpPlgWokNEvQjwMiGkT0k Qxg01odrDaP4N/swkuOfkx+w3/vCBupLZCFMFSsXn+fYCmiBMeZDZk+FVnfdwwwl6NQE lkT6lDdlep6BhFWXJlgwC9FMVwwVsaN88o8MuxKkeqUm79AT0HF5OkgmNxy7eGH9w+yg ROwlCe/t0nai3hcMHwLsoxDHXFp4pbHEl5IP4N3k4vZNThTeIJvLX3rU0f+FBMySyjTu 3govKsdveEtUVzmMOpje9GIXnND7FKf6DbnqZARKTHOPVOXYQnDO+StLHBnyf+UKhuWy l6/A== 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=QJX0FqAd/q40DYwHE6Skyh+jXAJwxtv8RNUB2uZ9z1E=; b=OZZnR0ucPuN0GciwGV1HwNkwNq36tMFfO9TeHuU2GJ1XpU/E7VxCk9PfEUO+cKsWy+ pSc19/g5uAP062z09LY/i2Y6QoxtEUTV/pIQ9S6IMQ0Q+aLxxPdBdbjDTNVl5OPkOW5E mdgPKZjppKRDkA/clcG/6crf8r71WdEwmuUyWvl1Yl6A6GGSG0TMb3GeLmq5gleHCjlX AAfBfRLj2Tven7vcZ2JCNzJAPZvR5n8B5SUNEF8egHPVb//ipnrAPFsMG/50slSoidsS XSWz/RWPv9y7gNKO/IUdejtk8fY1j4Odynu4cMhBPDPaEoBEmAc7uHIN+zsce6/7LHxc HJ5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2EQcPAU+; 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 cw28si12667985edb.299.2021.07.11.23.29.20; Sun, 11 Jul 2021 23:29:43 -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=2EQcPAU+; 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 S236463AbhGLGaM (ORCPT + 99 others); Mon, 12 Jul 2021 02:30:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:46026 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234795AbhGLGZ6 (ORCPT ); Mon, 12 Jul 2021 02:25:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3CB666115C; Mon, 12 Jul 2021 06:22:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626070973; bh=UmSGOiZVN2BZcaFMNMeQp4ABHSZA4Qxowtk2Jfxqxjs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2EQcPAU+g2vkDYLHbAHfssl5ZIYrZCyT4EqFIUvRDzlIHS7eEyfSvh3AoRJmeWcp6 EY0HoXFNuLh1aBWLoTTRecr1kzRE7ObakYO/nLpYfvBCYZdeagVIVNehe09eXWLzd4 OOLmYvQr9kRUdQi7+h1mfIi9DINoitoFPSQk9ads= 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.4 221/348] net: sched: add barrier to ensure correct ordering for lockless qdisc Date: Mon, 12 Jul 2021 08:10:05 +0200 Message-Id: <20210712060731.018723515@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060659.886176320@linuxfoundation.org> References: <20210712060659.886176320@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 0852f3e51360..0cb0a4bcb544 100644 --- a/include/net/sch_generic.h +++ b/include/net/sch_generic.h @@ -160,6 +160,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 @@ -177,6 +183,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