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=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 8CFDCC56202 for ; Sun, 22 Nov 2020 13:20:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5AEAE20760 for ; Sun, 22 Nov 2020 13:20:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727728AbgKVNUe (ORCPT ); Sun, 22 Nov 2020 08:20:34 -0500 Received: from mx57.baidu.com ([61.135.168.57]:41196 "EHLO tc-sys-mailedm04.tc.baidu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727567AbgKVNUe (ORCPT ); Sun, 22 Nov 2020 08:20:34 -0500 X-Greylist: delayed 592 seconds by postgrey-1.27 at vger.kernel.org; Sun, 22 Nov 2020 08:20:33 EST Received: from localhost (bjhw-sys-rpm015653cc5.bjhw.baidu.com [10.227.53.39]) by tc-sys-mailedm04.tc.baidu.com (Postfix) with ESMTP id CD117236C003; Sun, 22 Nov 2020 21:10:19 +0800 (CST) From: Li RongQing To: netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH] libbpf: add support for canceling cached_cons advance Date: Sun, 22 Nov 2020 21:10:23 +0800 Message-Id: <1606050623-22963-1-git-send-email-lirongqing@baidu.com> X-Mailer: git-send-email 1.7.1 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org It is possible to fail receiving packets after calling xsk_ring_cons__peek, at this condition, cached_cons has been advanced, should be cancelled. Signed-off-by: Li RongQing --- tools/lib/bpf/xsk.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/lib/bpf/xsk.h b/tools/lib/bpf/xsk.h index 1069c46364ff..4128215c246b 100644 --- a/tools/lib/bpf/xsk.h +++ b/tools/lib/bpf/xsk.h @@ -153,6 +153,12 @@ static inline size_t xsk_ring_cons__peek(struct xsk_ring_cons *cons, return entries; } +static inline void xsk_ring_cons__cancel(struct xsk_ring_cons *cons, + size_t nb) +{ + rx->cached_cons -= nb; +} + static inline void xsk_ring_cons__release(struct xsk_ring_cons *cons, size_t nb) { /* Make sure data has been read before indicating we are done -- 2.17.3