From patchwork Thu Sep 14 23:11:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 13386184 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C78A0D2FC for ; Thu, 14 Sep 2023 23:12:32 +0000 (UTC) Received: from mx0b-00206402.pphosted.com (mx0b-00206402.pphosted.com [148.163.152.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19C74270E for ; Thu, 14 Sep 2023 16:12:32 -0700 (PDT) Received: from pps.filterd (m0354653.ppops.net [127.0.0.1]) by mx0b-00206402.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 38EL8nlg001980; Thu, 14 Sep 2023 23:12:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crowdstrike.com; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=default; bh=3VKnBjyqIG9ubd52IwIp0UBhKUowISe6tTaia/J8dsE=; b=kCpOh7hOdZmQ uNrQ94Z7Xbf/+bgXLfNt8DKkGNwEAhjFp7JuuVd6ckHP3rUGp8ocNZlTbbXCLkeI fEZp3TAhns2Fvk29OjU7gRiGSZz/v8wIby2y25ar5kk3jzO+R7PaoVNUtoRtnDcM JKOSmToZh/028eRg7rcOvq0+mINXfcQ0w5WhVlZHnvTj/cdUJHrPtKH5JE5/8CiN Jifw1bMma+4EoBVc+QY6Lg7/mvbYQgtM9nOcOSGESV6SXVV8tCKkth8Rj8MvK1qe 4Ei2lk1IzDN7kLowOUmmK+UbC/KSAL3cOEebijPbQbRLXzU5ZS0ubKheuBjVa8/U 8MQfZhnupQ== Received: from 04wpexch06.crowdstrike.sys (dragosx.crowdstrike.com [208.42.231.60]) by mx0b-00206402.pphosted.com (PPS) with ESMTPS id 3t2y9fpcp5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 23:12:11 +0000 (GMT) Received: from LL-556NGK3.crowdstrike.sys (10.100.11.122) by 04wpexch06.crowdstrike.sys (10.100.11.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.16; Thu, 14 Sep 2023 23:12:09 +0000 From: Martin Kelly To: CC: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Martin Kelly Subject: [PATCH bpf-next 01/14] libbpf: refactor cleanup in ring_buffer__add Date: Thu, 14 Sep 2023 16:11:10 -0700 Message-ID: <20230914231123.193901-2-martin.kelly@crowdstrike.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914231123.193901-1-martin.kelly@crowdstrike.com> References: <20230914231123.193901-1-martin.kelly@crowdstrike.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.100.11.122] X-ClientProxiedBy: 04WPEXCH12.crowdstrike.sys (10.100.11.116) To 04wpexch06.crowdstrike.sys (10.100.11.99) X-Disclaimer: USA X-Proofpoint-ORIG-GUID: tpSbVQu2kUsCcw_blFOVvPBM7F1n9TgV X-Proofpoint-GUID: tpSbVQu2kUsCcw_blFOVvPBM7F1n9TgV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_12,2023-09-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 spamscore=0 phishscore=0 mlxscore=0 bulkscore=0 malwarescore=0 adultscore=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=607 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2309140202 X-Patchwork-Delegate: bpf@iogearbox.net Refactor the cleanup code in ring_buffer__add to use a unified err_out label. This reduces code duplication, as well as plugging a potential leak if mmap_sz != (__u64)(size_t)mmap_sz (currently this would miss unmapping tmp because ringbuf_unmap_ring isn't called). Signed-off-by: Martin Kelly --- tools/lib/bpf/ringbuf.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c index 02199364db13..f2020807996c 100644 --- a/tools/lib/bpf/ringbuf.c +++ b/tools/lib/bpf/ringbuf.c @@ -118,10 +118,9 @@ int ring_buffer__add(struct ring_buffer *rb, int map_fd, /* Map writable consumer page */ tmp = mmap(NULL, rb->page_size, PROT_READ | PROT_WRITE, MAP_SHARED, map_fd, 0); if (tmp == MAP_FAILED) { - err = -errno; pr_warn("ringbuf: failed to mmap consumer page for map fd=%d: %d\n", map_fd, err); - return libbpf_err(err); + goto err_out; } r->consumer_pos = tmp; @@ -131,16 +130,15 @@ int ring_buffer__add(struct ring_buffer *rb, int map_fd, */ mmap_sz = rb->page_size + 2 * (__u64)info.max_entries; if (mmap_sz != (__u64)(size_t)mmap_sz) { + errno = E2BIG; pr_warn("ringbuf: ring buffer size (%u) is too big\n", info.max_entries); - return libbpf_err(-E2BIG); + goto err_out; } tmp = mmap(NULL, (size_t)mmap_sz, PROT_READ, MAP_SHARED, map_fd, rb->page_size); if (tmp == MAP_FAILED) { - err = -errno; - ringbuf_unmap_ring(rb, r); pr_warn("ringbuf: failed to mmap data pages for map fd=%d: %d\n", map_fd, err); - return libbpf_err(err); + goto err_out; } r->producer_pos = tmp; r->data = tmp + rb->page_size; @@ -151,15 +149,18 @@ int ring_buffer__add(struct ring_buffer *rb, int map_fd, e->events = EPOLLIN; e->data.fd = rb->ring_cnt; if (epoll_ctl(rb->epoll_fd, EPOLL_CTL_ADD, map_fd, e) < 0) { - err = -errno; - ringbuf_unmap_ring(rb, r); pr_warn("ringbuf: failed to epoll add map fd=%d: %d\n", map_fd, err); - return libbpf_err(err); + goto err_out; } rb->ring_cnt++; return 0; + +err_out: + err = -errno; + ringbuf_unmap_ring(rb, r); + return libbpf_err(err); } void ring_buffer__free(struct ring_buffer *rb) From patchwork Thu Sep 14 23:11:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 13386186 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB672D2F0 for ; Thu, 14 Sep 2023 23:12:32 +0000 (UTC) Received: from mx0a-00206402.pphosted.com (mx0a-00206402.pphosted.com [148.163.148.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19AE32709 for ; Thu, 14 Sep 2023 16:12:32 -0700 (PDT) Received: from pps.filterd (m0354651.ppops.net [127.0.0.1]) by mx0a-00206402.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 38EL8dDl002136; Thu, 14 Sep 2023 23:12:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crowdstrike.com; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=default; bh=SQP4iEAw/GljMVcq4u4y5F3eR/d7O4E/fRrndxsgaVQ=; b=UAn4d3kSzeTP XeCiNk+1TcQf/mpqoSWrCGbc7fkeu30XWu2fHeQgWO1G4XRqh12lr0OAN6DGOt0Q 9s2Q+3KmUGnOBSy8nywfiSsJULmwnMUXPcYLQQHLcO9m0OqCo9JEPzlHSQ05rTOX OoEkhDLMfX8ZpdWLCKDKZQ3O4GxNdteJmFv7pDLEcfxsqhKX2P5BtLzl/XLJg/zN Nffla6Xvgmh5/C2OeUPYNqI/aos+5QTRNjWIAK8sLIBs9BMMkIT2kaTiWIAdR8rd BDbEhpaCtnN9RLMiV0KWCXlvOl9g9N0FCU8JcTIFWUq8wn+Bf47h1PbArbVrhkw4 uRpf07al8Q== Received: from 04wpexch06.crowdstrike.sys (dragosx.crowdstrike.com [208.42.231.60]) by mx0a-00206402.pphosted.com (PPS) with ESMTPS id 3t2y9966n6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 23:12:12 +0000 (GMT) Received: from LL-556NGK3.crowdstrike.sys (10.100.11.122) by 04wpexch06.crowdstrike.sys (10.100.11.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.16; Thu, 14 Sep 2023 23:12:11 +0000 From: Martin Kelly To: CC: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Martin Kelly Subject: [PATCH bpf-next 02/14] libbpf: switch rings to array of pointers Date: Thu, 14 Sep 2023 16:11:11 -0700 Message-ID: <20230914231123.193901-3-martin.kelly@crowdstrike.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914231123.193901-1-martin.kelly@crowdstrike.com> References: <20230914231123.193901-1-martin.kelly@crowdstrike.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.100.11.122] X-ClientProxiedBy: 04WPEXCH12.crowdstrike.sys (10.100.11.116) To 04wpexch06.crowdstrike.sys (10.100.11.99) X-Disclaimer: USA X-Proofpoint-GUID: 6nRTDrdXyDj9HKa3uXF30XXMvq2fui11 X-Proofpoint-ORIG-GUID: 6nRTDrdXyDj9HKa3uXF30XXMvq2fui11 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_12,2023-09-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 phishscore=0 mlxscore=0 suspectscore=0 bulkscore=0 spamscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2309140202 X-Patchwork-Delegate: bpf@iogearbox.net Switch rb->rings to be an array of pointers instead of a contiguous block. This allows for each ring pointer to be stable after ring_buffer__add is called, which allows us to expose struct ring * to the user without gotchas. Without this change, the realloc in ring_buffer__add could invalidate a struct ring *, making it unsafe to give to the user. Signed-off-by: Martin Kelly --- tools/lib/bpf/ringbuf.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c index f2020807996c..c2c79e10cfea 100644 --- a/tools/lib/bpf/ringbuf.c +++ b/tools/lib/bpf/ringbuf.c @@ -34,7 +34,7 @@ struct ring { struct ring_buffer { struct epoll_event *events; - struct ring *rings; + struct ring **rings; size_t page_size; int epoll_fd; int ring_cnt; @@ -57,7 +57,7 @@ struct ringbuf_hdr { __u32 pad; }; -static void ringbuf_unmap_ring(struct ring_buffer *rb, struct ring *r) +static void ringbuf_free_ring(struct ring_buffer *rb, struct ring *r) { if (r->consumer_pos) { munmap(r->consumer_pos, rb->page_size); @@ -67,6 +67,8 @@ static void ringbuf_unmap_ring(struct ring_buffer *rb, struct ring *r) munmap(r->producer_pos, rb->page_size + 2 * (r->mask + 1)); r->producer_pos = NULL; } + + free(r); } /* Add extra RINGBUF maps to this ring buffer manager */ @@ -107,8 +109,10 @@ int ring_buffer__add(struct ring_buffer *rb, int map_fd, return libbpf_err(-ENOMEM); rb->events = tmp; - r = &rb->rings[rb->ring_cnt]; - memset(r, 0, sizeof(*r)); + r = calloc(1, sizeof(*r)); + if (!r) + return libbpf_err(-ENOMEM); + rb->rings[rb->ring_cnt] = r; r->map_fd = map_fd; r->sample_cb = sample_cb; @@ -159,7 +163,7 @@ int ring_buffer__add(struct ring_buffer *rb, int map_fd, err_out: err = -errno; - ringbuf_unmap_ring(rb, r); + ringbuf_free_ring(rb, r); return libbpf_err(err); } @@ -171,7 +175,7 @@ void ring_buffer__free(struct ring_buffer *rb) return; for (i = 0; i < rb->ring_cnt; ++i) - ringbuf_unmap_ring(rb, &rb->rings[i]); + ringbuf_free_ring(rb, rb->rings[i]); if (rb->epoll_fd >= 0) close(rb->epoll_fd); @@ -279,7 +283,7 @@ int ring_buffer__consume(struct ring_buffer *rb) int i; for (i = 0; i < rb->ring_cnt; i++) { - struct ring *ring = &rb->rings[i]; + struct ring *ring = rb->rings[i]; err = ringbuf_process_ring(ring); if (err < 0) @@ -306,7 +310,7 @@ int ring_buffer__poll(struct ring_buffer *rb, int timeout_ms) for (i = 0; i < cnt; i++) { __u32 ring_id = rb->events[i].data.fd; - struct ring *ring = &rb->rings[ring_id]; + struct ring *ring = rb->rings[ring_id]; err = ringbuf_process_ring(ring); if (err < 0) From patchwork Thu Sep 14 23:11:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 13386188 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0013CA64 for ; Thu, 14 Sep 2023 23:12:34 +0000 (UTC) Received: from mx0b-00206402.pphosted.com (mx0b-00206402.pphosted.com [148.163.152.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 415F4270A for ; Thu, 14 Sep 2023 16:12:34 -0700 (PDT) Received: from pps.filterd (m0354655.ppops.net [127.0.0.1]) by mx0b-00206402.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 38EL8VrW021548; Thu, 14 Sep 2023 23:12:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crowdstrike.com; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=default; bh=x83qySIrIUy/SYYqXs0puUkglIaLH27hbJ/l+sB9BaY=; b=AsMj2gwV4l7K qG4A+QDlApK/rgfxJg1aC6QlsF1VVMrb5+FlWNlB7dwZCCpXUhsqcB1yBYkn7kgF 5zRkD7VhGcPZ67EdIchjNImmjKaJriVw8pLpCCe6b9toT7+0iSoyKzAgrSc7zjFA Q3a0vBtkymqsFe+ypz7QnSVYrjRDWW5K6DTttuI+pybTi4rIZkmIPLk7shxUbz1N AxwVnwFeC6bDNIxui+/xKoXkRAqXeRNdgLx62C3UG5k09hDVXVuAjyxZE9PWCp5C im8viy30cYKzzZe9Avwk2RVIDaIDC35QMUL4mSzJmr5id1qCuQO6jYwmyfuKNTi0 paa204Wdsw== Received: from 04wpexch06.crowdstrike.sys (dragosx.crowdstrike.com [208.42.231.60]) by mx0b-00206402.pphosted.com (PPS) with ESMTPS id 3t2y9d6e8n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 23:12:14 +0000 (GMT) Received: from LL-556NGK3.crowdstrike.sys (10.100.11.122) by 04wpexch06.crowdstrike.sys (10.100.11.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.16; Thu, 14 Sep 2023 23:12:12 +0000 From: Martin Kelly To: CC: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Martin Kelly Subject: [PATCH bpf-next 03/14] libbpf: add ring_buffer__ring Date: Thu, 14 Sep 2023 16:11:12 -0700 Message-ID: <20230914231123.193901-4-martin.kelly@crowdstrike.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914231123.193901-1-martin.kelly@crowdstrike.com> References: <20230914231123.193901-1-martin.kelly@crowdstrike.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.100.11.122] X-ClientProxiedBy: 04WPEXCH12.crowdstrike.sys (10.100.11.116) To 04wpexch06.crowdstrike.sys (10.100.11.99) X-Disclaimer: USA X-Proofpoint-ORIG-GUID: gNy_2KJkj8yAX4LZX3tau46jvOfntptB X-Proofpoint-GUID: gNy_2KJkj8yAX4LZX3tau46jvOfntptB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_12,2023-09-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 phishscore=0 malwarescore=0 suspectscore=0 clxscore=1015 mlxlogscore=918 impostorscore=0 mlxscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2309140202 X-Patchwork-Delegate: bpf@iogearbox.net Add a new function ring_buffer__ring, which exposes struct ring * to the user, representing a single ringbuffer. Signed-off-by: Martin Kelly --- tools/lib/bpf/libbpf.h | 14 ++++++++++++++ tools/lib/bpf/libbpf.map | 1 + tools/lib/bpf/ringbuf.c | 8 ++++++++ 3 files changed, 23 insertions(+) diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 0e52621cba43..2d6c39e20863 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -1229,6 +1229,7 @@ LIBBPF_API int bpf_tc_query(const struct bpf_tc_hook *hook, /* Ring buffer APIs */ struct ring_buffer; +struct ring; struct user_ring_buffer; typedef int (*ring_buffer_sample_fn)(void *ctx, void *data, size_t size); @@ -1249,6 +1250,19 @@ LIBBPF_API int ring_buffer__poll(struct ring_buffer *rb, int timeout_ms); LIBBPF_API int ring_buffer__consume(struct ring_buffer *rb); LIBBPF_API int ring_buffer__epoll_fd(const struct ring_buffer *rb); +/** + * @brief **ring_buffer__ring()** returns the ring object inside a given + * ringbuffer. + * + * @param rb A ringbuffer object. + * @param idx An index into the rings contained within the ringbuffer object. + * The index is 0-based and corresponds to the order in which ring_buffer__add + * was called. + * @return A ring object on success; NULL and errno set if the index is invalid. + */ +LIBBPF_API struct ring *ring_buffer__ring(struct ring_buffer *rb, + unsigned int idx); + struct user_ring_buffer_opts { size_t sz; /* size of this struct, for forward/backward compatibility */ }; diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index 57712321490f..7a7370c2bc25 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -400,4 +400,5 @@ LIBBPF_1.3.0 { bpf_program__attach_netfilter; bpf_program__attach_tcx; bpf_program__attach_uprobe_multi; + ring_buffer__ring; } LIBBPF_1.2.0; diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c index c2c79e10cfea..2857df0f2d03 100644 --- a/tools/lib/bpf/ringbuf.c +++ b/tools/lib/bpf/ringbuf.c @@ -328,6 +328,14 @@ int ring_buffer__epoll_fd(const struct ring_buffer *rb) return rb->epoll_fd; } +struct ring *ring_buffer__ring(struct ring_buffer *rb, unsigned int idx) +{ + if (idx >= rb->ring_cnt) + return errno = ERANGE, NULL; + + return rb->rings[idx]; +} + static void user_ringbuf_unmap_ring(struct user_ring_buffer *rb) { if (rb->consumer_pos) { From patchwork Thu Sep 14 23:11:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 13386185 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E962033F2 for ; Thu, 14 Sep 2023 23:12:33 +0000 (UTC) Received: from mx0a-00206402.pphosted.com (mx0a-00206402.pphosted.com [148.163.148.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 811F92707 for ; Thu, 14 Sep 2023 16:12:33 -0700 (PDT) Received: from pps.filterd (m0354650.ppops.net [127.0.0.1]) by mx0a-00206402.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 38EL8gaX005492; Thu, 14 Sep 2023 23:12:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crowdstrike.com; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=default; bh=ab7bWV5Qt7+BdpIxfO13A0i2nk0unwWCSp+LT827bss=; b=QQc6GqA+pcWV nITLXQjNz0WUC6jEynm3oc0proNkvANM5LJ/wAYu7i5BxrFnV34ll3jndwgifCQc 4cWFnILhj2NJf6Uqn6l5BdqtiBRlaazQUE1NHKp/3trpvkkXDKj1JA+7a3xlGsGb SOGO5B/4loxSm3wDlTS7QWuMHzjAX7O8TaPyMUBSpPUKQ09gtq9SzZUfUK0Gb8aC KzBLFPGs/BlUdPI41wuZtdlqv0TTxwStFQ4sLOJRXV3Pn8ZkKfR3VN6Y3zOn32AT ZG4z/fTVWiCb36qYtFFpXvoxHbRXJzEf4+fqAdNFMy+vewViXXRbIvXvrzd9oYTp wI+yIRpa8g== Received: from 04wpexch06.crowdstrike.sys (dragosx.crowdstrike.com [208.42.231.60]) by mx0a-00206402.pphosted.com (PPS) with ESMTPS id 3t2ybue89n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 23:12:15 +0000 (GMT) Received: from LL-556NGK3.crowdstrike.sys (10.100.11.122) by 04wpexch06.crowdstrike.sys (10.100.11.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.16; Thu, 14 Sep 2023 23:12:13 +0000 From: Martin Kelly To: CC: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Martin Kelly Subject: [PATCH bpf-next 04/14] selftests/bpf: add tests for ring_buffer__ring Date: Thu, 14 Sep 2023 16:11:13 -0700 Message-ID: <20230914231123.193901-5-martin.kelly@crowdstrike.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914231123.193901-1-martin.kelly@crowdstrike.com> References: <20230914231123.193901-1-martin.kelly@crowdstrike.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.100.11.122] X-ClientProxiedBy: 04WPEXCH12.crowdstrike.sys (10.100.11.116) To 04wpexch06.crowdstrike.sys (10.100.11.99) X-Disclaimer: USA X-Proofpoint-GUID: zkZYY4iOls6n6LmK9xYBJmN6lwZ1pAlS X-Proofpoint-ORIG-GUID: zkZYY4iOls6n6LmK9xYBJmN6lwZ1pAlS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_12,2023-09-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 impostorscore=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=718 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2309140202 X-Patchwork-Delegate: bpf@iogearbox.net Add tests for the new API ring_buffer__ring. Signed-off-by: Martin Kelly --- .../selftests/bpf/prog_tests/ringbuf_multi.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c b/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c index 1455911d9fcb..f0729ffaf030 100644 --- a/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c @@ -42,6 +42,8 @@ void test_ringbuf_multi(void) { struct test_ringbuf_multi *skel; struct ring_buffer *ringbuf = NULL; + struct ring *ring_old; + struct ring *ring; int err; int page_size = getpagesize(); int proto_fd = -1; @@ -84,11 +86,25 @@ void test_ringbuf_multi(void) if (CHECK(!ringbuf, "ringbuf_create", "failed to create ringbuf\n")) goto cleanup; + /* verify ring_buffer__ring returns expected results */ + ring = ring_buffer__ring(ringbuf, 0); + if (CHECK(ring == NULL, "ringbuf_ring", "valid index returning NULL\n")) + goto cleanup; + ring_old = ring; + ring = ring_buffer__ring(ringbuf, 1); + if (CHECK(ring != NULL, "ringbuf_ring", "invalid index not rejected\n")) + goto cleanup; + err = ring_buffer__add(ringbuf, bpf_map__fd(skel->maps.ringbuf2), process_sample, (void *)(long)2); if (CHECK(err, "ringbuf_add", "failed to add another ring\n")) goto cleanup; + /* verify adding a new ring didn't invalidate our older pointer */ + ring = ring_buffer__ring(ringbuf, 0); + if (CHECK(ring != ring_old, "ringbuf_ring", "old ring invalidated\n")) + goto cleanup; + err = test_ringbuf_multi__attach(skel); if (CHECK(err, "skel_attach", "skeleton attachment failed: %d\n", err)) goto cleanup; From patchwork Thu Sep 14 23:11:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 13386189 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29ABDD50B for ; Thu, 14 Sep 2023 23:12:35 +0000 (UTC) Received: from mx0b-00206402.pphosted.com (mx0b-00206402.pphosted.com [148.163.152.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99ECF2711 for ; Thu, 14 Sep 2023 16:12:34 -0700 (PDT) Received: from pps.filterd (m0354653.ppops.net [127.0.0.1]) by mx0b-00206402.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 38EL8YFb001185; Thu, 14 Sep 2023 23:12:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crowdstrike.com; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=default; bh=weyxGZ+zIAZpTxNjkrw+h0hb9W7VWwg5fe+e8YDoqeo=; b=nxY78WPqGabZ B835BAoYTgMt4DhyzKesKlum64HTSZkwQQHRV+eOrbVscwN49TgLQvvMqDmY+WjG QR/e9KAOba8WCb2XA81i0+ju0B5+zu3M0TBJny109+YojD+kFCuhJSYPPhI3vs+D fdiBWkBTVPuKYPZ1GGfvGSRRYcCMQpsihwsDgPnrhYsvS5gxBsIBS45zW5vwdfvL 7SqYh3rPFnSsV12deK+JnctD9xgLszhBoBpfMYAxymQG0iRsVv2CzntUuRQ52A/r F4qxGjcVY8eRA5FSEkbObGF/5k1/fphAQHlEjXHc8h2F/LFlK+Vc0xCmQNbwc3Bl 3p5CUkb7Pw== Received: from 04wpexch06.crowdstrike.sys (dragosx.crowdstrike.com [208.42.231.60]) by mx0b-00206402.pphosted.com (PPS) with ESMTPS id 3t2y9fpcp7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 23:12:16 +0000 (GMT) Received: from LL-556NGK3.crowdstrike.sys (10.100.11.122) by 04wpexch06.crowdstrike.sys (10.100.11.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.16; Thu, 14 Sep 2023 23:12:14 +0000 From: Martin Kelly To: CC: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Martin Kelly Subject: [PATCH bpf-next 05/14] libbpf: add ring__producer_pos, ring__consumer_pos Date: Thu, 14 Sep 2023 16:11:14 -0700 Message-ID: <20230914231123.193901-6-martin.kelly@crowdstrike.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914231123.193901-1-martin.kelly@crowdstrike.com> References: <20230914231123.193901-1-martin.kelly@crowdstrike.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.100.11.122] X-ClientProxiedBy: 04WPEXCH12.crowdstrike.sys (10.100.11.116) To 04wpexch06.crowdstrike.sys (10.100.11.99) X-Disclaimer: USA X-Proofpoint-ORIG-GUID: sbBV6UewNuLk2BjQq2O4BY06yYWwd1y4 X-Proofpoint-GUID: sbBV6UewNuLk2BjQq2O4BY06yYWwd1y4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_12,2023-09-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 spamscore=0 phishscore=0 mlxscore=0 bulkscore=0 malwarescore=0 adultscore=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=841 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2309140202 X-Patchwork-Delegate: bpf@iogearbox.net Add APIs to get the producer and consumer position for a given ringbuffer. Signed-off-by: Martin Kelly --- tools/lib/bpf/libbpf.h | 16 ++++++++++++++++ tools/lib/bpf/libbpf.map | 2 ++ tools/lib/bpf/ringbuf.c | 14 ++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 2d6c39e20863..935162dbb3bf 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -1263,6 +1263,22 @@ LIBBPF_API int ring_buffer__epoll_fd(const struct ring_buffer *rb); LIBBPF_API struct ring *ring_buffer__ring(struct ring_buffer *rb, unsigned int idx); +/** + * @brief **ring__consumer_pos()** returns the current consumer position. + * + * @param r A ring object. + * @return The current consumer position. + */ +LIBBPF_API unsigned long ring__consumer_pos(const struct ring *r); + +/** + * @brief **ring__producer_pos()** returns the current producer position. + * + * @param r A ring object. + * @return The current producer position. + */ +LIBBPF_API unsigned long ring__producer_pos(const struct ring *r); + struct user_ring_buffer_opts { size_t sz; /* size of this struct, for forward/backward compatibility */ }; diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index 7a7370c2bc25..1c532fe7a445 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -401,4 +401,6 @@ LIBBPF_1.3.0 { bpf_program__attach_tcx; bpf_program__attach_uprobe_multi; ring_buffer__ring; + ring__consumer_pos; + ring__producer_pos; } LIBBPF_1.2.0; diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c index 2857df0f2d03..54c596db57a4 100644 --- a/tools/lib/bpf/ringbuf.c +++ b/tools/lib/bpf/ringbuf.c @@ -336,6 +336,20 @@ struct ring *ring_buffer__ring(struct ring_buffer *rb, unsigned int idx) return rb->rings[idx]; } +unsigned long ring__consumer_pos(const struct ring *r) +{ + /* Synchronizes with smp_store_release() in ringbuf_process_ring(). */ + return smp_load_acquire(r->consumer_pos); +} + +unsigned long ring__producer_pos(const struct ring *r) +{ + /* Synchronizes with smp_store_release() in __bpf_ringbuf_reserve() in + * the kernel. + */ + return smp_load_acquire(r->producer_pos); +} + static void user_ringbuf_unmap_ring(struct user_ring_buffer *rb) { if (rb->consumer_pos) { From patchwork Thu Sep 14 23:11:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 13386190 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DA6ED2F0 for ; Thu, 14 Sep 2023 23:12:37 +0000 (UTC) Received: from mx0a-00206402.pphosted.com (mx0a-00206402.pphosted.com [148.163.148.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBB7C270E for ; Thu, 14 Sep 2023 16:12:36 -0700 (PDT) Received: from pps.filterd (m0354650.ppops.net [127.0.0.1]) by mx0a-00206402.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 38EL8gFs005495; Thu, 14 Sep 2023 23:12:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crowdstrike.com; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=default; bh=7dE0tgoc6k+fmrl+soSplJRLAwsaa1MEaYoklIccHws=; b=u4Za0N/ocKkF 1NXpNN7cAU+WlIqnlXqiDC2VLOSX81EMrZdJmIevlQxTTC+3rg+aISA2AOEnkerS walPeit5iAZXMTRvUBpG1SDgZrUnphXtpA0GBZoMFsiK0TGwpDZkjgqEkhmJHHQS fLBQ6T2zGdOa2lJOAwvYW6LcqllF8PQhvW7ngF7e4/YsoAq9svONKPKH+JLwT/vL 74pjyzqZDAZS6yD5kZZPaSCnS3a9Xso1hCQwMONmzBJyO5+MIZjpRyX7oVcwaiEx fq6j2X7bIW8VrQEK0i4VpZuRgCH+oAY9lE8lsjUJQbsmG3QKLNuXF8IPheIi9rTM 3Qo0PQCgCg== Received: from 04wpexch06.crowdstrike.sys (dragosx.crowdstrike.com [208.42.231.60]) by mx0a-00206402.pphosted.com (PPS) with ESMTPS id 3t2ybue89q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 23:12:17 +0000 (GMT) Received: from LL-556NGK3.crowdstrike.sys (10.100.11.122) by 04wpexch06.crowdstrike.sys (10.100.11.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.16; Thu, 14 Sep 2023 23:12:15 +0000 From: Martin Kelly To: CC: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Martin Kelly Subject: [PATCH bpf-next 06/14] selftests/bpf: add tests for ring__*_pos Date: Thu, 14 Sep 2023 16:11:15 -0700 Message-ID: <20230914231123.193901-7-martin.kelly@crowdstrike.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914231123.193901-1-martin.kelly@crowdstrike.com> References: <20230914231123.193901-1-martin.kelly@crowdstrike.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.100.11.122] X-ClientProxiedBy: 04WPEXCH12.crowdstrike.sys (10.100.11.116) To 04wpexch06.crowdstrike.sys (10.100.11.99) X-Disclaimer: USA X-Proofpoint-GUID: 3mkhMCSKZZ1wvnO07vOR1JxYqYD9vqm6 X-Proofpoint-ORIG-GUID: 3mkhMCSKZZ1wvnO07vOR1JxYqYD9vqm6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_12,2023-09-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 impostorscore=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=970 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2309140202 X-Patchwork-Delegate: bpf@iogearbox.net Add tests for the new APIs ring__producer_pos and ring__consumer_pos. Signed-off-by: Martin Kelly --- .../testing/selftests/bpf/prog_tests/ringbuf.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c index ac104dc652e3..0400123da690 100644 --- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c @@ -91,6 +91,8 @@ static void ringbuf_subtest(void) int err, cnt, rb_fd; int page_size = getpagesize(); void *mmap_ptr, *tmp_ptr; + struct ring *ring; + unsigned long cons_pos, prod_pos; skel = test_ringbuf_lskel__open(); if (CHECK(!skel, "skel_open", "skeleton open failed\n")) @@ -162,6 +164,10 @@ static void ringbuf_subtest(void) trigger_samples(); + ring = ring_buffer__ring(ringbuf, 0); + if (CHECK(ring == NULL, "ringbuf_ring", "valid index returning NULL\n")) + goto cleanup; + /* 2 submitted + 1 discarded records */ CHECK(skel->bss->avail_data != 3 * rec_sz, "err_avail_size", "exp %ld, got %ld\n", @@ -176,6 +182,18 @@ static void ringbuf_subtest(void) "err_prod_pos", "exp %ld, got %ld\n", 3L * rec_sz, skel->bss->prod_pos); + /* verify getting this data directly via the ring object yields the same + * results + */ + cons_pos = ring__consumer_pos(ring); + CHECK(cons_pos != 0, + "err_ring_cons_pos", "exp %ld, got %ld\n", + 0L, cons_pos); + prod_pos = ring__producer_pos(ring); + CHECK(prod_pos != 3 * rec_sz, + "err_ring_prod_pos", "exp %ld, got %ld\n", + 3L * rec_sz, prod_pos); + /* poll for samples */ err = ring_buffer__poll(ringbuf, -1); From patchwork Thu Sep 14 23:11:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 13386182 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54311CA64 for ; Thu, 14 Sep 2023 23:12:32 +0000 (UTC) Received: from mx0b-00206402.pphosted.com (mx0b-00206402.pphosted.com [148.163.152.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C58A270A for ; Thu, 14 Sep 2023 16:12:31 -0700 (PDT) Received: from pps.filterd (m0354653.ppops.net [127.0.0.1]) by mx0b-00206402.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 38EL8nlh001980; Thu, 14 Sep 2023 23:12:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crowdstrike.com; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=default; bh=R4+yoAEM79jcxe8kOCqRQxtZAWTFTTDFOkFWMt9EKN4=; b=RA8xWqFybRPw 2SptNA0Jsn3JBzeq9tdKIyoyNvuNCtXMu5F7D7KHGhxG5p6wglT1kLJhzXE+H9zR VxHCk1CnCbE5JPcaUh8/IYVIyCtTpDqkUS6j98d2RXuMDxigfl02rvyUXKTIX2eP Ut/nobhJkBRzG0HSU4qGDRQ5Nxy6o9IKkuLfRoqFnxZYyiOwadofP9RJbZYdy8n1 gkQRXEESvDIuuGzYpRpN3SUiA+rIYiiR7jMHBScu3PuPJ9uDgepWe1a5Ih7aV8ha 0QZLOo69ZdOO8PRiFK1L/sAw6G8iZTzti4SK3L66sCp1Ef16VUlwS5OFn/rW6DOZ 23TawU7NBA== Received: from 04wpexch06.crowdstrike.sys (dragosx.crowdstrike.com [208.42.231.60]) by mx0b-00206402.pphosted.com (PPS) with ESMTPS id 3t2y9fpcp9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 23:12:18 +0000 (GMT) Received: from LL-556NGK3.crowdstrike.sys (10.100.11.122) by 04wpexch06.crowdstrike.sys (10.100.11.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.16; Thu, 14 Sep 2023 23:12:16 +0000 From: Martin Kelly To: CC: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Martin Kelly Subject: [PATCH bpf-next 07/14] libbpf: add ring__avail_data_size Date: Thu, 14 Sep 2023 16:11:16 -0700 Message-ID: <20230914231123.193901-8-martin.kelly@crowdstrike.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914231123.193901-1-martin.kelly@crowdstrike.com> References: <20230914231123.193901-1-martin.kelly@crowdstrike.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.100.11.122] X-ClientProxiedBy: 04WPEXCH12.crowdstrike.sys (10.100.11.116) To 04wpexch06.crowdstrike.sys (10.100.11.99) X-Disclaimer: USA X-Proofpoint-ORIG-GUID: K4PTiDE5R7MyH4LjH6Y_mRq1YbYFXebp X-Proofpoint-GUID: K4PTiDE5R7MyH4LjH6Y_mRq1YbYFXebp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_12,2023-09-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 spamscore=0 phishscore=0 mlxscore=0 bulkscore=0 malwarescore=0 adultscore=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=874 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2309140202 X-Patchwork-Delegate: bpf@iogearbox.net Add ring__avail_data_size for querying the currently available data in the ringbuffer, similar to the BPF_RB_AVAIL_DATA flag in bpf_ringbuf_query. This is racy during ongoing operations but is still useful for overall information on how a ringbuffer is behaving. Signed-off-by: Martin Kelly --- tools/lib/bpf/libbpf.h | 11 +++++++++++ tools/lib/bpf/libbpf.map | 1 + tools/lib/bpf/ringbuf.c | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 935162dbb3bf..87e3bad37737 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -1279,6 +1279,17 @@ LIBBPF_API unsigned long ring__consumer_pos(const struct ring *r); */ LIBBPF_API unsigned long ring__producer_pos(const struct ring *r); +/** + * @brief **ring__avail_data_size()** returns the number of bytes in this + * ringbuffer not yet consumed. This has no locking associated with it, so it + * can be inaccurate if operations are ongoing while this is called. However, it + * should still show the correct trend over the long-term. + * + * @param r A ring object. + * @return The number of bytes not yet consumed. + */ +LIBBPF_API size_t ring__avail_data_size(const struct ring *r); + struct user_ring_buffer_opts { size_t sz; /* size of this struct, for forward/backward compatibility */ }; diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index 1c532fe7a445..f66d7f0bc224 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -401,6 +401,7 @@ LIBBPF_1.3.0 { bpf_program__attach_tcx; bpf_program__attach_uprobe_multi; ring_buffer__ring; + ring__avail_data_size; ring__consumer_pos; ring__producer_pos; } LIBBPF_1.2.0; diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c index 54c596db57a4..f51ad1af6ab8 100644 --- a/tools/lib/bpf/ringbuf.c +++ b/tools/lib/bpf/ringbuf.c @@ -350,6 +350,11 @@ unsigned long ring__producer_pos(const struct ring *r) return smp_load_acquire(r->producer_pos); } +size_t ring__avail_data_size(const struct ring *r) +{ + return ring__producer_pos(r) - ring__consumer_pos(r); +} + static void user_ringbuf_unmap_ring(struct user_ring_buffer *rb) { if (rb->consumer_pos) { From patchwork Thu Sep 14 23:11:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 13386183 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFE69D2FF for ; Thu, 14 Sep 2023 23:12:32 +0000 (UTC) Received: from mx0a-00206402.pphosted.com (mx0a-00206402.pphosted.com [148.163.148.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BE672710 for ; Thu, 14 Sep 2023 16:12:32 -0700 (PDT) Received: from pps.filterd (m0354651.ppops.net [127.0.0.1]) by mx0a-00206402.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 38EL98Zk004048; Thu, 14 Sep 2023 23:12:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crowdstrike.com; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=default; bh=xHsuaCF+ji5JlvQ6uEDscbrgcEVIoNUmC1moDiZoHbY=; b=EtIe3b2jboAa eKflg8S2/pBvDJa3VepOv/OhuSRCl5dcVj/9wuqzPVNoSA1zMyG7sZrQNJxjNyAP nfcQ1RD5xuT10GnDaZDQJ7Pqn/KkOciYDxZyx3NRLp+d5NzFpeveepcDS1GUKLsT 7KE7eFDbHf6C6FNSLAqAIhgh34WBZkk8E5NlQidh9b1Z0Y3lR6wTjG4CoBUw3Xl2 9yzjLWEBARWhMLTH7jLJzktwrO1yn8+DBGAJY//GXsGJC/Q06zBK4N6kpUrSFzaP Wy4aJN3d0f3sTCkWclyelf9dR4cEACf1fHhoQt4jQq2I+ry1A8Ss2c9aI1rlCYuN ybGIdF6Llw== Received: from 04wpexch06.crowdstrike.sys (dragosx.crowdstrike.com [208.42.231.60]) by mx0a-00206402.pphosted.com (PPS) with ESMTPS id 3t2y9966na-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 23:12:19 +0000 (GMT) Received: from LL-556NGK3.crowdstrike.sys (10.100.11.122) by 04wpexch06.crowdstrike.sys (10.100.11.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.16; Thu, 14 Sep 2023 23:12:17 +0000 From: Martin Kelly To: CC: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Martin Kelly Subject: [PATCH bpf-next 08/14] selftests/bpf: add tests for ring__avail_data_size Date: Thu, 14 Sep 2023 16:11:17 -0700 Message-ID: <20230914231123.193901-9-martin.kelly@crowdstrike.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914231123.193901-1-martin.kelly@crowdstrike.com> References: <20230914231123.193901-1-martin.kelly@crowdstrike.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.100.11.122] X-ClientProxiedBy: 04WPEXCH12.crowdstrike.sys (10.100.11.116) To 04wpexch06.crowdstrike.sys (10.100.11.99) X-Disclaimer: USA X-Proofpoint-GUID: Qy2_Vo5qfXw3G4q-FE1W92bgas_vOg78 X-Proofpoint-ORIG-GUID: Qy2_Vo5qfXw3G4q-FE1W92bgas_vOg78 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_12,2023-09-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=955 priorityscore=1501 phishscore=0 mlxscore=0 suspectscore=0 bulkscore=0 spamscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2309140202 X-Patchwork-Delegate: bpf@iogearbox.net Add test for the new API ring__avail_data_size. Signed-off-by: Martin Kelly --- tools/testing/selftests/bpf/prog_tests/ringbuf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c index 0400123da690..e4e1171e2e4d 100644 --- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c @@ -92,7 +92,7 @@ static void ringbuf_subtest(void) int page_size = getpagesize(); void *mmap_ptr, *tmp_ptr; struct ring *ring; - unsigned long cons_pos, prod_pos; + unsigned long avail_data, cons_pos, prod_pos; skel = test_ringbuf_lskel__open(); if (CHECK(!skel, "skel_open", "skeleton open failed\n")) @@ -185,6 +185,10 @@ static void ringbuf_subtest(void) /* verify getting this data directly via the ring object yields the same * results */ + avail_data = ring__avail_data_size(ring); + CHECK(avail_data != 3 * rec_sz, + "err_ring_avail_size", "exp %ld, got %ld\n", + 3L * rec_sz, avail_data); cons_pos = ring__consumer_pos(ring); CHECK(cons_pos != 0, "err_ring_cons_pos", "exp %ld, got %ld\n", From patchwork Thu Sep 14 23:11:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 13386187 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21292D313 for ; Thu, 14 Sep 2023 23:12:33 +0000 (UTC) Received: from mx0b-00206402.pphosted.com (mx0b-00206402.pphosted.com [148.163.152.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FDF61BFA for ; Thu, 14 Sep 2023 16:12:33 -0700 (PDT) Received: from pps.filterd (m0354653.ppops.net [127.0.0.1]) by mx0b-00206402.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 38EL8ek8001454; Thu, 14 Sep 2023 23:12:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crowdstrike.com; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=default; bh=vZ+v7zLwrlmk80tgmjuy2nUvxsrDAWGMOvunLQkD9KI=; b=cYwxiguNWDud kBq++A4KJhVqg4dwm3iNabHjm4Uyd5gekAGKy7mBslKrkLEmeu66yzLrOKye1UPV S/Bzy/k5ED0yK7cbKk+rzh0MDLyn5smAY3d2D2gFKgUHEoiY5h7HaGoA8J+OkRqB v8MqogB/EalopAQHGTKdCQpFkZuGs5IdkYNDl6BoQfthTpmCQfqhDlaLE4pgDJVx Gs6405pCo9MucaABw5nuepXfKr69dwLBjBGYHNinGUoR9oV60mfTlGlqz+m9sdMr BySedxNuScqqq4aN8KiI+h+HIdCWsBsvHsQv9TVtWvqEDu89+6pJxBv02NPI2T+W Xc5Ax2EYdw== Received: from 04wpexch06.crowdstrike.sys (dragosx.crowdstrike.com [208.42.231.60]) by mx0b-00206402.pphosted.com (PPS) with ESMTPS id 3t2y9fpcpb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 23:12:20 +0000 (GMT) Received: from LL-556NGK3.crowdstrike.sys (10.100.11.122) by 04wpexch06.crowdstrike.sys (10.100.11.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.16; Thu, 14 Sep 2023 23:12:19 +0000 From: Martin Kelly To: CC: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Martin Kelly Subject: [PATCH bpf-next 09/14] libbpf: add ring__size Date: Thu, 14 Sep 2023 16:11:18 -0700 Message-ID: <20230914231123.193901-10-martin.kelly@crowdstrike.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914231123.193901-1-martin.kelly@crowdstrike.com> References: <20230914231123.193901-1-martin.kelly@crowdstrike.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.100.11.122] X-ClientProxiedBy: 04WPEXCH12.crowdstrike.sys (10.100.11.116) To 04wpexch06.crowdstrike.sys (10.100.11.99) X-Disclaimer: USA X-Proofpoint-ORIG-GUID: 0UcfJpvaw06Acdsag3o4HWERpoHebpJi X-Proofpoint-GUID: 0UcfJpvaw06Acdsag3o4HWERpoHebpJi X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_12,2023-09-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 spamscore=0 phishscore=0 mlxscore=0 bulkscore=0 malwarescore=0 adultscore=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=843 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2309140202 X-Patchwork-Delegate: bpf@iogearbox.net Add ring__size to get the total size of a given ringbuffer. Signed-off-by: Martin Kelly --- tools/lib/bpf/libbpf.h | 8 ++++++++ tools/lib/bpf/libbpf.map | 1 + tools/lib/bpf/ringbuf.c | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 87e3bad37737..299d98402ad4 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -1290,6 +1290,14 @@ LIBBPF_API unsigned long ring__producer_pos(const struct ring *r); */ LIBBPF_API size_t ring__avail_data_size(const struct ring *r); +/** + * @brief **ring__size()** returns the total size of the ringbuffer. + * + * @param r A ring object. + * @return The total size of the ringbuffer. + */ +LIBBPF_API size_t ring__size(const struct ring *r); + struct user_ring_buffer_opts { size_t sz; /* size of this struct, for forward/backward compatibility */ }; diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index f66d7f0bc224..4ca77e715667 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -404,4 +404,5 @@ LIBBPF_1.3.0 { ring__avail_data_size; ring__consumer_pos; ring__producer_pos; + ring__size; } LIBBPF_1.2.0; diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c index f51ad1af6ab8..52c385195f32 100644 --- a/tools/lib/bpf/ringbuf.c +++ b/tools/lib/bpf/ringbuf.c @@ -355,6 +355,11 @@ size_t ring__avail_data_size(const struct ring *r) return ring__producer_pos(r) - ring__consumer_pos(r); } +size_t ring__size(const struct ring *r) +{ + return r->mask + 1; +} + static void user_ringbuf_unmap_ring(struct user_ring_buffer *rb) { if (rb->consumer_pos) { From patchwork Thu Sep 14 23:11:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 13386191 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65ADBD532 for ; Thu, 14 Sep 2023 23:12:37 +0000 (UTC) Received: from mx0b-00206402.pphosted.com (mx0b-00206402.pphosted.com [148.163.152.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E83FE2707 for ; Thu, 14 Sep 2023 16:12:36 -0700 (PDT) Received: from pps.filterd (m0354653.ppops.net [127.0.0.1]) by mx0b-00206402.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 38EL8ekA001454; Thu, 14 Sep 2023 23:12:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crowdstrike.com; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=default; bh=Ch7VhHiePgS8Q0D71JWR8zQBruQX4+TcUucDmG89W98=; b=Fl6eMc1+wFUU U5xHmWHVtBzg6x4iLQrrCSOZEehqy6YclVA8FTGUExDCMsCRG5obP3nF3PsbJTRG bYlG5/uRev/kxG1vVBSUIY0iyZ8BmOYMWiRm012koTUm/6rEpZf5KXY3e1rnuf7z rJwq5I3RI2/Z0xZoDVfUfzHNHjszyMULzYW0VkGgoiX/j1AlF6VOy8gfSh38zQuV aGUGB0Hr+a0lgxTv2iHopbOFCbkzkhMJRvvvb8nVQQHVSyjWwKiky2NHR5z6xqWL WRl4CTTBD1xh/34m4JGxVWA/AsnkSZtKGBM0t4H63zfrjbHwHm++Bv/JTV+fgPST xxStOscR9A== Received: from 04wpexch06.crowdstrike.sys (dragosx.crowdstrike.com [208.42.231.60]) by mx0b-00206402.pphosted.com (PPS) with ESMTPS id 3t2y9fpcpb-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 23:12:22 +0000 (GMT) Received: from LL-556NGK3.crowdstrike.sys (10.100.11.122) by 04wpexch06.crowdstrike.sys (10.100.11.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.16; Thu, 14 Sep 2023 23:12:20 +0000 From: Martin Kelly To: CC: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Martin Kelly Subject: [PATCH bpf-next 10/14] selftests/bpf: add tests for ring__size Date: Thu, 14 Sep 2023 16:11:19 -0700 Message-ID: <20230914231123.193901-11-martin.kelly@crowdstrike.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914231123.193901-1-martin.kelly@crowdstrike.com> References: <20230914231123.193901-1-martin.kelly@crowdstrike.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.100.11.122] X-ClientProxiedBy: 04WPEXCH12.crowdstrike.sys (10.100.11.116) To 04wpexch06.crowdstrike.sys (10.100.11.99) X-Disclaimer: USA X-Proofpoint-ORIG-GUID: nSHa_Iun6sOXQKchJPEf6hLlHi4NAJFZ X-Proofpoint-GUID: nSHa_Iun6sOXQKchJPEf6hLlHi4NAJFZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_12,2023-09-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 spamscore=0 phishscore=0 mlxscore=0 bulkscore=0 malwarescore=0 adultscore=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=903 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2309140202 X-Patchwork-Delegate: bpf@iogearbox.net Add tests for the new API ring__size. Signed-off-by: Martin Kelly --- tools/testing/selftests/bpf/prog_tests/ringbuf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c index e4e1171e2e4d..962dc1bc5f3b 100644 --- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c @@ -92,7 +92,7 @@ static void ringbuf_subtest(void) int page_size = getpagesize(); void *mmap_ptr, *tmp_ptr; struct ring *ring; - unsigned long avail_data, cons_pos, prod_pos; + unsigned long avail_data, ring_size, cons_pos, prod_pos; skel = test_ringbuf_lskel__open(); if (CHECK(!skel, "skel_open", "skeleton open failed\n")) @@ -189,6 +189,10 @@ static void ringbuf_subtest(void) CHECK(avail_data != 3 * rec_sz, "err_ring_avail_size", "exp %ld, got %ld\n", 3L * rec_sz, avail_data); + ring_size = ring__size(ring); + CHECK(ring_size != page_size, + "err_ring_ring_size", "exp %ld, got %ld\n", + (long)page_size, ring_size); cons_pos = ring__consumer_pos(ring); CHECK(cons_pos != 0, "err_ring_cons_pos", "exp %ld, got %ld\n", From patchwork Thu Sep 14 23:11:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 13386192 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F36BDDA1 for ; Thu, 14 Sep 2023 23:12:38 +0000 (UTC) Received: from mx0a-00206402.pphosted.com (mx0a-00206402.pphosted.com [148.163.148.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 369991BFA for ; Thu, 14 Sep 2023 16:12:38 -0700 (PDT) Received: from pps.filterd (m0354652.ppops.net [127.0.0.1]) by mx0a-00206402.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 38EL8jj1017098; Thu, 14 Sep 2023 23:12:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crowdstrike.com; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=default; bh=+M1vRc/4xHORdUwzGt3H4oXGfvUpu2T9wLydZea1Dgg=; b=dDfU9xdtagps wIY0m4T8VZ1z7M+5I5qneSe7EmPRabx8dQi1UBOdrJT6soCvZy3/iGMUop+416fD sOsIBVq/VULsK3yN1EPkB60jIUf1tsEBiJXhP+wL0whxPJfYmR87mHmW/KlcLiVY 3vxq2v97vIXfCLeQ/WGEcY3JIqGCKDGL0Y6AqMUml9JdFGFvbl7OjJ4z22ylfdsq VZXtIjrEaBfGOn/bd0T1DO1NEAZTlCGbtzG3b9YTsvJt2wGOo6onIfIQztjIZMui nkPN7pbW88OetDqX682ZINmn7hIfomBx9sMqlI9+GE8F4eyp/gZwQTp8gH20GZ3P 4ZhYALbcDw== Received: from 04wpexch06.crowdstrike.sys (dragosx.crowdstrike.com [208.42.231.60]) by mx0a-00206402.pphosted.com (PPS) with ESMTPS id 3t2ybtx6yx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 23:12:23 +0000 (GMT) Received: from LL-556NGK3.crowdstrike.sys (10.100.11.122) by 04wpexch06.crowdstrike.sys (10.100.11.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.16; Thu, 14 Sep 2023 23:12:21 +0000 From: Martin Kelly To: CC: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Martin Kelly Subject: [PATCH bpf-next 11/14] libbpf: add ring__map_fd Date: Thu, 14 Sep 2023 16:11:20 -0700 Message-ID: <20230914231123.193901-12-martin.kelly@crowdstrike.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914231123.193901-1-martin.kelly@crowdstrike.com> References: <20230914231123.193901-1-martin.kelly@crowdstrike.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.100.11.122] X-ClientProxiedBy: 04WPEXCH12.crowdstrike.sys (10.100.11.116) To 04wpexch06.crowdstrike.sys (10.100.11.99) X-Disclaimer: USA X-Proofpoint-GUID: v4asiSnA8PU1yUlPsTqfoFeNFuet0lQk X-Proofpoint-ORIG-GUID: v4asiSnA8PU1yUlPsTqfoFeNFuet0lQk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_12,2023-09-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=943 phishscore=0 spamscore=0 mlxscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2309140201 X-Patchwork-Delegate: bpf@iogearbox.net Add ring__map_fd to get the file descriptor underlying a given ringbuffer. Signed-off-by: Martin Kelly --- tools/lib/bpf/libbpf.h | 9 +++++++++ tools/lib/bpf/libbpf.map | 1 + tools/lib/bpf/ringbuf.c | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 299d98402ad4..d2a237086c2c 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -1298,6 +1298,15 @@ LIBBPF_API size_t ring__avail_data_size(const struct ring *r); */ LIBBPF_API size_t ring__size(const struct ring *r); +/** + * @brief **ring__map_fd()** returns the file descriptor underlying the given + * ringbuffer. + * + * @param r A ring object. + * @return The underlying ringbuffer file descriptor + */ +LIBBPF_API int ring__map_fd(const struct ring *r); + struct user_ring_buffer_opts { size_t sz; /* size of this struct, for forward/backward compatibility */ }; diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index 4ca77e715667..13800b73c343 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -403,6 +403,7 @@ LIBBPF_1.3.0 { ring_buffer__ring; ring__avail_data_size; ring__consumer_pos; + ring__map_fd; ring__producer_pos; ring__size; } LIBBPF_1.2.0; diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c index 52c385195f32..2dba2836d85b 100644 --- a/tools/lib/bpf/ringbuf.c +++ b/tools/lib/bpf/ringbuf.c @@ -360,6 +360,11 @@ size_t ring__size(const struct ring *r) return r->mask + 1; } +int ring__map_fd(const struct ring *r) +{ + return r->map_fd; +} + static void user_ringbuf_unmap_ring(struct user_ring_buffer *rb) { if (rb->consumer_pos) { From patchwork Thu Sep 14 23:11:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 13386193 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2828D50B for ; Thu, 14 Sep 2023 23:12:38 +0000 (UTC) Received: from mx0a-00206402.pphosted.com (mx0a-00206402.pphosted.com [148.163.148.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B8FE2709 for ; Thu, 14 Sep 2023 16:12:38 -0700 (PDT) Received: from pps.filterd (m0354652.ppops.net [127.0.0.1]) by mx0a-00206402.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 38EL8jj2017098; Thu, 14 Sep 2023 23:12:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crowdstrike.com; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=default; bh=QBwyFplwddx7ulxwXt3kk57rIQOzdJYq+Ciie+FnD5Q=; b=mwuvRjiEQ2Sg yrTeRsPiVS8aYqASD0uT0Z9GuneW5iMJUOvWxqc6TsRe84c9CnrMGi16XM9yvm50 SZvu0eFYKHS4NVJue4nz9lhDD+MaQzDkfpDpDYnJIJOKUOgDIK1az8Sa6wPpqhLk kELHejk+j0i4M40BIHHD9G2DxHh0kZ0690KrKZyyiT1QvRGuTJ0UXCkV7Md+a6oK IqtJzdm7dbt/ejKdw2SdksgG+GnHSxi5IRNoCOOvDIe0NnNWBR4af7o8NEHRkwQn OYaUOxlBxZ8yFddLtqdgwxF00RA6Hmvt1m99MfbBOYS8+rMD6Pau0+bBP8T+aWla 1pzEcH2l7Q== Received: from 04wpexch06.crowdstrike.sys (dragosx.crowdstrike.com [208.42.231.60]) by mx0a-00206402.pphosted.com (PPS) with ESMTPS id 3t2ybtx6yx-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 23:12:24 +0000 (GMT) Received: from LL-556NGK3.crowdstrike.sys (10.100.11.122) by 04wpexch06.crowdstrike.sys (10.100.11.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.16; Thu, 14 Sep 2023 23:12:22 +0000 From: Martin Kelly To: CC: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Martin Kelly Subject: [PATCH bpf-next 12/14] selftests/bpf: add tests for ring__map_fd Date: Thu, 14 Sep 2023 16:11:21 -0700 Message-ID: <20230914231123.193901-13-martin.kelly@crowdstrike.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914231123.193901-1-martin.kelly@crowdstrike.com> References: <20230914231123.193901-1-martin.kelly@crowdstrike.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.100.11.122] X-ClientProxiedBy: 04WPEXCH12.crowdstrike.sys (10.100.11.116) To 04wpexch06.crowdstrike.sys (10.100.11.99) X-Disclaimer: USA X-Proofpoint-GUID: P8F9sMY_FOC1W3LxIHYCIlz6jz-7ecgo X-Proofpoint-ORIG-GUID: P8F9sMY_FOC1W3LxIHYCIlz6jz-7ecgo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_12,2023-09-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=923 phishscore=0 spamscore=0 mlxscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2309140201 X-Patchwork-Delegate: bpf@iogearbox.net Add tests for the new API ring__map_fd. Signed-off-by: Martin Kelly --- tools/testing/selftests/bpf/prog_tests/ringbuf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c index 962dc1bc5f3b..27149dee0e2c 100644 --- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c @@ -92,6 +92,7 @@ static void ringbuf_subtest(void) int page_size = getpagesize(); void *mmap_ptr, *tmp_ptr; struct ring *ring; + int map_fd; unsigned long avail_data, ring_size, cons_pos, prod_pos; skel = test_ringbuf_lskel__open(); @@ -168,6 +169,11 @@ static void ringbuf_subtest(void) if (CHECK(ring == NULL, "ringbuf_ring", "valid index returning NULL\n")) goto cleanup; + map_fd = ring__map_fd(ring); + CHECK(map_fd != skel->maps.ringbuf.map_fd, + "err_map_fd", "exp %d, got %d\n", + skel->maps.ringbuf.map_fd, map_fd); + /* 2 submitted + 1 discarded records */ CHECK(skel->bss->avail_data != 3 * rec_sz, "err_avail_size", "exp %ld, got %ld\n", From patchwork Thu Sep 14 23:11:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 13386194 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9F04D532 for ; Thu, 14 Sep 2023 23:12:39 +0000 (UTC) Received: from mx0a-00206402.pphosted.com (mx0a-00206402.pphosted.com [148.163.148.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F960270A for ; Thu, 14 Sep 2023 16:12:39 -0700 (PDT) Received: from pps.filterd (m0354652.ppops.net [127.0.0.1]) by mx0a-00206402.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 38EL8jj3017098; Thu, 14 Sep 2023 23:12:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crowdstrike.com; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=default; bh=z6KlbUhot5aX4xfHwIehtGPTGonPxcT2HV3daONyuWw=; b=AFYaG3ezcGQH amrMgvyMkC8CnrIbks09q0hg0b8CTAUK7EuWLWZkBWr6qiEM8r3R4dAau315dY5M YS8ub/nC10Pw/c/TKUis/K0NgM/BA5YpP630BIn5VN5dE4XaPhxuM2kaKJ5brg3X FzRY9gH+pLg89eh6DJ18fh4ptS3rFSA1dB0GrzgJGXanGK6ZkRDNGK2RPPfakgEp 7mAdmDKKxuJHDV51zMgDLGIsxAE6xNRUTcaMHppduORWd/UjhEcccNACpQKBLET5 G/Z4xFk4qprQh+PE6ziRaTQayg0tfJmqcynr3Xmj328ReZIgvfTpomxqx12XzkF5 X6X54ZEyrA== Received: from 04wpexch06.crowdstrike.sys (dragosx.crowdstrike.com [208.42.231.60]) by mx0a-00206402.pphosted.com (PPS) with ESMTPS id 3t2ybtx6yx-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 23:12:25 +0000 (GMT) Received: from LL-556NGK3.crowdstrike.sys (10.100.11.122) by 04wpexch06.crowdstrike.sys (10.100.11.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.16; Thu, 14 Sep 2023 23:12:23 +0000 From: Martin Kelly To: CC: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Martin Kelly Subject: [PATCH bpf-next 13/14] libbpf: add ring__consume Date: Thu, 14 Sep 2023 16:11:22 -0700 Message-ID: <20230914231123.193901-14-martin.kelly@crowdstrike.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914231123.193901-1-martin.kelly@crowdstrike.com> References: <20230914231123.193901-1-martin.kelly@crowdstrike.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.100.11.122] X-ClientProxiedBy: 04WPEXCH12.crowdstrike.sys (10.100.11.116) To 04wpexch06.crowdstrike.sys (10.100.11.99) X-Disclaimer: USA X-Proofpoint-GUID: AtTdPnPQNJOYWnKZlOmEuqI-IxXOio2H X-Proofpoint-ORIG-GUID: AtTdPnPQNJOYWnKZlOmEuqI-IxXOio2H X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_12,2023-09-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=804 phishscore=0 spamscore=0 mlxscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2309140201 X-Patchwork-Delegate: bpf@iogearbox.net Add ring__consume to consume a single ringbuffer, analogous to ring_buffer__consume. Signed-off-by: Martin Kelly --- tools/lib/bpf/libbpf.h | 10 ++++++++++ tools/lib/bpf/libbpf.map | 1 + tools/lib/bpf/ringbuf.c | 13 +++++++++++++ 3 files changed, 24 insertions(+) diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index d2a237086c2c..861f8b6795e9 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -1307,6 +1307,16 @@ LIBBPF_API size_t ring__size(const struct ring *r); */ LIBBPF_API int ring__map_fd(const struct ring *r); +/** + * @brief **ring__consume()** consumes available ringbuffer data without event + * polling. + * + * @param r A ring object. + * @return The number of records consumed (or INT_MAX, whichever is less), or + * a negative number if any of the callbacks return an error. + */ +LIBBPF_API int ring__consume(struct ring *r); + struct user_ring_buffer_opts { size_t sz; /* size of this struct, for forward/backward compatibility */ }; diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index 13800b73c343..4b5124bb0e1a 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -402,6 +402,7 @@ LIBBPF_1.3.0 { bpf_program__attach_uprobe_multi; ring_buffer__ring; ring__avail_data_size; + ring__consume; ring__consumer_pos; ring__map_fd; ring__producer_pos; diff --git a/tools/lib/bpf/ringbuf.c b/tools/lib/bpf/ringbuf.c index 2dba2836d85b..b7ef003366d3 100644 --- a/tools/lib/bpf/ringbuf.c +++ b/tools/lib/bpf/ringbuf.c @@ -365,6 +365,19 @@ int ring__map_fd(const struct ring *r) return r->map_fd; } +int ring__consume(struct ring *r) +{ + int64_t res; + + res = ringbuf_process_ring(r); + if (res < 0) + res = libbpf_err(res); + else if (res > INT_MAX) + res = INT_MAX; + + return res; +} + static void user_ringbuf_unmap_ring(struct user_ring_buffer *rb) { if (rb->consumer_pos) { From patchwork Thu Sep 14 23:11:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Kelly X-Patchwork-Id: 13386195 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D797CD50B for ; Thu, 14 Sep 2023 23:12:41 +0000 (UTC) Received: from mx0b-00206402.pphosted.com (mx0b-00206402.pphosted.com [148.163.152.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 670482707 for ; Thu, 14 Sep 2023 16:12:41 -0700 (PDT) Received: from pps.filterd (m0354654.ppops.net [127.0.0.1]) by mx0b-00206402.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 38EL93lT028253; Thu, 14 Sep 2023 23:12:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crowdstrike.com; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=default; bh=VrfPEWAq4OgcOa0ko6k7Jvndb7aRLhovk7zAmOOZtX4=; b=rz1BuWctLz5O TGGTR7ZgS07z9AZgR1iDpk0FxA1q3fmFRsvdi+3f0q07PXa7jr+dzfmptNth7nVY nMvB5FpsgePe6fq8v75gbZ4jD1ED9X2R7lMKs/2e92MKMrtZfib92s9PAM4THPE9 ijYZW1lEjHMrimj3JJhrjEp73+CznqavlGF7uXRhBxZXibrq+cRZPRcU9xqPKxFE UaLs7VKHX81hAaTkRxcvmRU/2503E94Njb1HZlE2Djv286qwsnEagsw2e0u0+P/i FwX1CFPSwI3exHHL+8hTtAnof/lTunC7mP6qkL5MgmeHoFMi4VXFLy3WsnbK2o/k FGyear3Mfg== Received: from 04wpexch06.crowdstrike.sys (dragosx.crowdstrike.com [208.42.231.60]) by mx0b-00206402.pphosted.com (PPS) with ESMTPS id 3t2y9dedpp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 14 Sep 2023 23:12:26 +0000 (GMT) Received: from LL-556NGK3.crowdstrike.sys (10.100.11.122) by 04wpexch06.crowdstrike.sys (10.100.11.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.16; Thu, 14 Sep 2023 23:12:24 +0000 From: Martin Kelly To: CC: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Martin Kelly Subject: [PATCH bpf-next 14/14] selftests/bpf: add tests for ring__consume Date: Thu, 14 Sep 2023 16:11:23 -0700 Message-ID: <20230914231123.193901-15-martin.kelly@crowdstrike.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914231123.193901-1-martin.kelly@crowdstrike.com> References: <20230914231123.193901-1-martin.kelly@crowdstrike.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.100.11.122] X-ClientProxiedBy: 04WPEXCH12.crowdstrike.sys (10.100.11.116) To 04wpexch06.crowdstrike.sys (10.100.11.99) X-Disclaimer: USA X-Proofpoint-GUID: U9cFYydQenEd-DUYyWCWoJoYqihWS0fv X-Proofpoint-ORIG-GUID: U9cFYydQenEd-DUYyWCWoJoYqihWS0fv X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_12,2023-09-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 suspectscore=0 phishscore=0 clxscore=1015 mlxlogscore=797 spamscore=0 malwarescore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2309140202 X-Patchwork-Delegate: bpf@iogearbox.net Add tests for new API ring__consume. Signed-off-by: Martin Kelly --- tools/testing/selftests/bpf/prog_tests/ringbuf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c index 27149dee0e2c..ccf13f0e36c7 100644 --- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c @@ -312,7 +312,11 @@ static void ringbuf_subtest(void) * samples, so consume them here to collect all the samples */ err = ring_buffer__consume(ringbuf); - CHECK(err < 0, "rb_consume", "failed: %d\b", err); + CHECK(err < 0, "ringbuffer_consume", "failed: %d\b", err); + + /* also consume using ring__consume to make sure it works the same */ + err = ring__consume(ring); + CHECK(err < 0, "ring_consume", "failed: %d\b", err); /* 3 rounds, 2 samples each */ cnt = atomic_xchg(&sample_cnt, 0);