Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp241748pxj; Thu, 20 May 2021 08:24:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwL5fKqr0mpND4lqxdSBi5pff1+8sKAqnmcmmHVV8bhySijpuGxW6Kk5+6A65dMVpshgNP3 X-Received: by 2002:a5d:9d16:: with SMTP id j22mr5783483ioj.92.1621524279932; Thu, 20 May 2021 08:24:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621524279; cv=none; d=google.com; s=arc-20160816; b=JuLd/D5tERLDoKHAvYoLPC/qryRVNdV41BxE6HUTWZ94nRqsM1Kb3YAUvgmDlHErxL dwrv22+wOvG92R8BlDbUnOlZO6Rn+it6b9kZlO/WXfo87Y4L52XffWZVonzwQQfHhL+A ElD1IrgQ1xFyww1Optx6tdB37IFjKIqhaD7KAuzCgY+H2sJljF6nIwUCBEB+6hpT7hQO a1w+OHi6kRfP3nuZxCBu1ce9eqhJlzgCnbbreis2O4bIL6j/5WzR9LxKOpoaq+VFEyAw w6ra6RbSu40TGGV59orj9KgnNv9Vwz7HLK9+3MtU+DJxat4oVZOd7HDvOM8awCcF6Ten DTUA== 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=E+C7Jwyrr/OxOcjlqTW1tqmpsFjwOqLD0+jOc/KPOFU=; b=JVbz1YLOfFDX8FwACbdIHc04/yg1oQQX9FtQ48RlmYdQRjN5W5NdojTYQM6JjUDWi8 LqEOXgoy69lM39TcQM8oF6UGz+gY4HgWtOliXVkLEwadkggF+F/xDq9TrMD/NHwEy+p9 9DUG2QJvOf7yNUhKmov+HDp+nAEghEOTpnNI6uIa/9YVx3Q0zR29Xz7sppAdvquSl0el yVnOO+HsKPQRTAzlhIVJ2/jqWWc5mPicyP2NoA0Jzyo7CsT1b08LFLz8xOIuzOt/JxGG CubBWqhoEuzhKAoynzeNHyRmlXDNVEGAm9ZXyvOEwFpafeANxYvaCl0aiLOY2GufWev9 ys6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oyBhxENm; 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 z1si2760683ilh.23.2021.05.20.08.24.26; Thu, 20 May 2021 08:24:39 -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=oyBhxENm; 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 S232166AbhETJfX (ORCPT + 99 others); Thu, 20 May 2021 05:35:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:33284 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231640AbhETJcj (ORCPT ); Thu, 20 May 2021 05:32:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1FB4E613F1; Thu, 20 May 2021 09:28:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621502907; bh=7i+KjgdqmmVBDqYkkzPiP9M1fqyyU969MSb7jd+wSW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oyBhxENm9LrNfIaGUhNRFzvZH56A7rDYEnD4NRCVraQC6wrFyXF77pScxxiGJ4RA/ LxyUrlRtKwtghxvyhjshf0vBEhzAoHQONfW5vj8bZ/IEXNLrL47bnwSuzTxtNmd4e0 i06cB20qcZQiQOHi3FKbuqn+HwUPirSA2Ud6UURI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Magnus Karlsson , Alexei Starovoitov , Sasha Levin Subject: [PATCH 5.4 07/37] xsk: Simplify detection of empty and full rings Date: Thu, 20 May 2021 11:22:28 +0200 Message-Id: <20210520092052.506301027@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092052.265851579@linuxfoundation.org> References: <20210520092052.265851579@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: Magnus Karlsson [ Upstream commit 11cc2d21499cabe7e7964389634ed1de3ee91d33 ] In order to set the correct return flags for poll, the xsk code has to check if the Rx queue is empty and if the Tx queue is full. This code was unnecessarily large and complex as it used the functions that are used to update the local state from the global state (xskq_nb_free and xskq_nb_avail). Since we are not doing this nor updating any data dependent on this state, we can simplify the functions. Another benefit from this is that we can also simplify the xskq_nb_free and xskq_nb_avail functions in a later commit. Signed-off-by: Magnus Karlsson Signed-off-by: Alexei Starovoitov Link: https://lore.kernel.org/bpf/1576759171-28550-3-git-send-email-magnus.karlsson@intel.com Signed-off-by: Sasha Levin --- net/xdp/xsk_queue.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h index eddae4688862..ee3f8c857dd8 100644 --- a/net/xdp/xsk_queue.h +++ b/net/xdp/xsk_queue.h @@ -363,12 +363,15 @@ static inline void xskq_produce_flush_desc(struct xsk_queue *q) static inline bool xskq_full_desc(struct xsk_queue *q) { - return xskq_nb_avail(q, q->nentries) == q->nentries; + /* No barriers needed since data is not accessed */ + return READ_ONCE(q->ring->producer) - READ_ONCE(q->ring->consumer) == + q->nentries; } static inline bool xskq_empty_desc(struct xsk_queue *q) { - return xskq_nb_free(q, q->prod_tail, q->nentries) == q->nentries; + /* No barriers needed since data is not accessed */ + return READ_ONCE(q->ring->consumer) == READ_ONCE(q->ring->producer); } void xskq_set_umem(struct xsk_queue *q, u64 size, u64 chunk_mask); -- 2.30.2