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=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham 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 74711C5519F for ; Wed, 25 Nov 2020 09:02:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 27DEE206F9 for ; Wed, 25 Nov 2020 09:02:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727109AbgKYJCp (ORCPT ); Wed, 25 Nov 2020 04:02:45 -0500 Received: from www62.your-server.de ([213.133.104.62]:48552 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726103AbgKYJCl (ORCPT ); Wed, 25 Nov 2020 04:02:41 -0500 Received: from sslproxy03.your-server.de ([88.198.220.132]) by www62.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1khqhB-0004Nu-0C; Wed, 25 Nov 2020 10:02:37 +0100 Received: from [85.7.101.30] (helo=pc-9.home) by sslproxy03.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1khqhA-000MzQ-RB; Wed, 25 Nov 2020 10:02:36 +0100 Subject: Re: [PATCH][V2] libbpf: add support for canceling cached_cons advance To: Magnus Karlsson Cc: Li RongQing , Network Development , bpf , "Karlsson, Magnus" References: <1606202474-8119-1-git-send-email-lirongqing@baidu.com> From: Daniel Borkmann Message-ID: Date: Wed, 25 Nov 2020 10:02:36 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.102.4/25998/Tue Nov 24 14:16:50 2020) Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On 11/25/20 9:30 AM, Magnus Karlsson wrote: > On Tue, Nov 24, 2020 at 10:58 PM Daniel Borkmann wrote: >> On 11/24/20 9:12 AM, Magnus Karlsson wrote: >>> On Tue, Nov 24, 2020 at 8:33 AM Li RongQing wrote: >>>> >>>> Add a new function for returning descriptors the user received >>>> after an xsk_ring_cons__peek call. After the application has >>>> gotten a number of descriptors from a ring, it might not be able >>>> to or want to process them all for various reasons. Therefore, >>>> it would be useful to have an interface for returning or >>>> cancelling a number of them so that they are returned to the ring. >>>> >>>> This patch adds a new function called xsk_ring_cons__cancel that >>>> performs this operation on nb descriptors counted from the end of >>>> the batch of descriptors that was received through the peek call. >>>> >>>> Signed-off-by: Li RongQing >>>> [ Magnus Karlsson: rewrote changelog ] >>>> Cc: Magnus Karlsson >>>> --- >>>> diff with v1: fix the building, and rewrote changelog >>>> >>>> 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..1719a327e5f9 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) >>>> +{ >>>> + cons->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 >>> >>> Thank you RongQing. >>> >>> Acked-by: Magnus Karlsson >> >> @Magnus: shouldn't the xsk_ring_cons__cancel() nb type be '__u32 nb' instead? > > All the other interfaces have size_t as the type for "nb". It is kind > of weird as a __u32 would have made more sense, but cannot actually > remember why I chose a size_t two years ago. But for consistency with > the other interfaces, let us keep it a size_t for now. I will do some > research around the reason. It's actually a bit of a mix currently which is what got me confused: static inline __u32 xsk_prod_nb_free(struct xsk_ring_prod *r, __u32 nb) static inline __u32 xsk_cons_nb_avail(struct xsk_ring_cons *r, __u32 nb) static inline size_t xsk_ring_prod__reserve(struct xsk_ring_prod *prod, size_t nb, __u32 *idx) static inline void xsk_ring_prod__submit(struct xsk_ring_prod *prod, size_t nb) static inline size_t xsk_ring_cons__peek(struct xsk_ring_cons *cons, size_t nb, __u32 *idx) static inline void xsk_ring_cons__release(struct xsk_ring_cons *cons, size_t nb) (I can take it in as-is, but would be nice to clean it up a bit to avoid confusion.) Thanks, Daniel