From patchwork Thu Jan 27 23:58:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12727565 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7520C433EF for ; Thu, 27 Jan 2022 23:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344018AbiA0X6d (ORCPT ); Thu, 27 Jan 2022 18:58:33 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:10550 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240891AbiA0X6c (ORCPT ); Thu, 27 Jan 2022 18:58:32 -0500 Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 20RNalg0027480 for ; Thu, 27 Jan 2022 15:58:31 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=xHh8N/PPB/iULui+5aVxLZ40s/lOuk/q/vP+616KAEE=; b=OTxROSqygFhCKCboJqLPnGsSixV0WX8W7rg/vu1EpGnsXpK26iy6oAkAWdo47hqafxNn L+84QSX0mybEWTt1Zekonu1ryHgiPQl6D6gOnSpCbLK7JiRLUO6fEgvgRvU+0zK+P+ct yy9jfcG/7TWaMiran+2VQJX5hwq5Y81S46A= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3duv8gby88-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 27 Jan 2022 15:58:31 -0800 Received: from twshared18912.14.frc2.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c085:21d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Thu, 27 Jan 2022 15:58:29 -0800 Received: by devvm3278.frc0.facebook.com (Postfix, from userid 8598) id 9BFB31C1148A6; Thu, 27 Jan 2022 15:58:25 -0800 (PST) From: Delyan Kratunov To: , , , CC: Delyan Kratunov Subject: [PATCH bpf-next 2/3] bpftool: migrate from bpf_prog_test_run_xattr Date: Thu, 27 Jan 2022 15:58:04 -0800 Message-ID: <20220127235805.1608540-3-delyank@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220127235805.1608540-1-delyank@fb.com> References: <20220127235805.1608540-1-delyank@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: G5Btv3T9OlkDH2wz1a-VtSjTwY4s_UCU X-Proofpoint-ORIG-GUID: G5Btv3T9OlkDH2wz1a-VtSjTwY4s_UCU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-27_06,2022-01-27_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=fb_outbound_notspam policy=fb_outbound score=0 mlxlogscore=830 mlxscore=0 clxscore=1015 malwarescore=0 priorityscore=1501 bulkscore=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2201270133 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net bpf_prog_test_run_xattr is being deprecated in favor of bpf_prog_test_run_opts. Signed-off-by: Delyan Kratunov --- tools/bpf/bpftool/prog.c | 55 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index 87593f98d2d1..4f96c229ba77 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c @@ -1272,12 +1272,12 @@ static int do_run(int argc, char **argv) { char *data_fname_in = NULL, *data_fname_out = NULL; char *ctx_fname_in = NULL, *ctx_fname_out = NULL; - struct bpf_prog_test_run_attr test_attr = {0}; const unsigned int default_size = SZ_32K; void *data_in = NULL, *data_out = NULL; void *ctx_in = NULL, *ctx_out = NULL; unsigned int repeat = 1; int fd, err; + LIBBPF_OPTS(bpf_test_run_opts, topts); if (!REQ_ARGS(4)) return -1; @@ -1315,7 +1315,7 @@ static int do_run(int argc, char **argv) if (!REQ_ARGS(1)) return -1; - test_attr.data_size_out = strtoul(*argv, &endptr, 0); + topts.data_size_out = strtoul(*argv, &endptr, 0); if (*endptr) { p_err("can't parse %s as output data size", *argv); @@ -1343,7 +1343,7 @@ static int do_run(int argc, char **argv) if (!REQ_ARGS(1)) return -1; - test_attr.ctx_size_out = strtoul(*argv, &endptr, 0); + topts.ctx_size_out = strtoul(*argv, &endptr, 0); if (*endptr) { p_err("can't parse %s as output context size", *argv); @@ -1371,38 +1371,37 @@ static int do_run(int argc, char **argv) } } - err = get_run_data(data_fname_in, &data_in, &test_attr.data_size_in); + err = get_run_data(data_fname_in, &data_in, &topts.data_size_in); if (err) return -1; if (data_in) { - if (!test_attr.data_size_out) - test_attr.data_size_out = default_size; - err = alloc_run_data(&data_out, test_attr.data_size_out); + if (!topts.data_size_out) + topts.data_size_out = default_size; + err = alloc_run_data(&data_out, topts.data_size_out); if (err) goto free_data_in; } - err = get_run_data(ctx_fname_in, &ctx_in, &test_attr.ctx_size_in); + err = get_run_data(ctx_fname_in, &ctx_in, &topts.ctx_size_in); if (err) goto free_data_out; if (ctx_in) { - if (!test_attr.ctx_size_out) - test_attr.ctx_size_out = default_size; - err = alloc_run_data(&ctx_out, test_attr.ctx_size_out); + if (!topts.ctx_size_out) + topts.ctx_size_out = default_size; + err = alloc_run_data(&ctx_out, topts.ctx_size_out); if (err) goto free_ctx_in; } - test_attr.prog_fd = fd; - test_attr.repeat = repeat; - test_attr.data_in = data_in; - test_attr.data_out = data_out; - test_attr.ctx_in = ctx_in; - test_attr.ctx_out = ctx_out; + topts.repeat = repeat; + topts.data_in = data_in; + topts.data_out = data_out; + topts.ctx_in = ctx_in; + topts.ctx_out = ctx_out; - err = bpf_prog_test_run_xattr(&test_attr); + err = bpf_prog_test_run_opts(fd, &topts); if (err) { p_err("failed to run program: %s", strerror(errno)); goto free_ctx_out; @@ -1416,23 +1415,23 @@ static int do_run(int argc, char **argv) /* Do not exit on errors occurring when printing output data/context, * we still want to print return value and duration for program run. */ - if (test_attr.data_size_out) - err += print_run_output(test_attr.data_out, - test_attr.data_size_out, + if (topts.data_size_out) + err += print_run_output(topts.data_out, + topts.data_size_out, data_fname_out, "data_out"); - if (test_attr.ctx_size_out) - err += print_run_output(test_attr.ctx_out, - test_attr.ctx_size_out, + if (topts.ctx_size_out) + err += print_run_output(topts.ctx_out, + topts.ctx_size_out, ctx_fname_out, "ctx_out"); if (json_output) { - jsonw_uint_field(json_wtr, "retval", test_attr.retval); - jsonw_uint_field(json_wtr, "duration", test_attr.duration); + jsonw_uint_field(json_wtr, "retval", topts.retval); + jsonw_uint_field(json_wtr, "duration", topts.duration); jsonw_end_object(json_wtr); /* root */ } else { fprintf(stdout, "Return value: %u, duration%s: %uns\n", - test_attr.retval, - repeat > 1 ? " (average)" : "", test_attr.duration); + topts.retval, + repeat > 1 ? " (average)" : "", topts.duration); } free_ctx_out: From patchwork Thu Jan 27 23:58:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Delyan Kratunov X-Patchwork-Id: 12727566 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7966C433F5 for ; Thu, 27 Jan 2022 23:58:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344054AbiA0X6m (ORCPT ); Thu, 27 Jan 2022 18:58:42 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:59970 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240891AbiA0X6j (ORCPT ); Thu, 27 Jan 2022 18:58:39 -0500 Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 20RNafcr005594 for ; Thu, 27 Jan 2022 15:58:39 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=facebook; bh=CmHLlBUtP+5T+Zc9veGrSamajqHy5dxhw2lVZKB7H7M=; b=mrlCONCTA6sAuLDdBZjKFbn5EdXbXOJg9o7JJUufcyjxrFwEwN+4FxcOuXip8AwKAUys rPuhP+s2dfRtlqIh6UeGYBB20kra4gYiA/liC6ZYKDrsUVU2Wg+Vm9GZ26m08PLnPfUC LlNCiT1y5UmThI9yLC9eiUcv9ReOy0BCzcw= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3dujv3xfxj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 27 Jan 2022 15:58:38 -0800 Received: from twshared11487.23.frc3.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c085:21d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Thu, 27 Jan 2022 15:58:37 -0800 Received: by devvm3278.frc0.facebook.com (Postfix, from userid 8598) id A2F681C1148A8; Thu, 27 Jan 2022 15:58:25 -0800 (PST) From: Delyan Kratunov To: , , , CC: Delyan Kratunov Subject: [PATCH bpf-next 3/3] libbpf: Deprecate bpf_prog_test_run_xattr and bpf_prog_test_run Date: Thu, 27 Jan 2022 15:58:05 -0800 Message-ID: <20220127235805.1608540-4-delyank@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220127235805.1608540-1-delyank@fb.com> References: <20220127235805.1608540-1-delyank@fb.com> X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: ccu4Y52AooXMKcTpIZQIK0DgmfWTVOFc X-Proofpoint-GUID: ccu4Y52AooXMKcTpIZQIK0DgmfWTVOFc X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-27_06,2022-01-27_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=fb_outbound_notspam policy=fb_outbound score=0 lowpriorityscore=0 mlxscore=0 suspectscore=0 mlxlogscore=741 spamscore=0 phishscore=0 priorityscore=1501 clxscore=1015 adultscore=0 malwarescore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2201270132 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Closes: https://github.com/libbpf/libbpf/issues/286 Signed-off-by: Delyan Kratunov --- tools/lib/bpf/bpf.h | 8 +++++--- tools/lib/bpf/xsk.c | 11 +++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index c2e8327010f9..e3d87b35435d 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h @@ -453,13 +453,15 @@ struct bpf_prog_test_run_attr { * out: length of cxt_out */ }; -LIBBPF_API int bpf_prog_test_run_xattr(struct bpf_prog_test_run_attr *test_attr); +LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_prog_test_run_opts() instead") +int bpf_prog_test_run_xattr(struct bpf_prog_test_run_attr *test_attr); /* * bpf_prog_test_run does not check that data_out is large enough. Consider - * using bpf_prog_test_run_xattr instead. + * using bpf_prog_test_run_opts instead. */ -LIBBPF_API int bpf_prog_test_run(int prog_fd, int repeat, void *data, +LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_prog_test_run_opts() instead") +int bpf_prog_test_run(int prog_fd, int repeat, void *data, __u32 size, void *data_out, __u32 *size_out, __u32 *retval, __u32 *duration); LIBBPF_API int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id); diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c index edafe56664f3..843d03b8f58c 100644 --- a/tools/lib/bpf/xsk.c +++ b/tools/lib/bpf/xsk.c @@ -369,8 +369,7 @@ int xsk_umem__create_v0_0_2(struct xsk_umem **umem_ptr, void *umem_area, static enum xsk_prog get_xsk_prog(void) { enum xsk_prog detected = XSK_PROG_FALLBACK; - __u32 size_out, retval, duration; - char data_in = 0, data_out; + char data_in = 0; struct bpf_insn insns[] = { BPF_LD_MAP_FD(BPF_REG_1, 0), BPF_MOV64_IMM(BPF_REG_2, 0), @@ -378,6 +377,10 @@ static enum xsk_prog get_xsk_prog(void) BPF_EMIT_CALL(BPF_FUNC_redirect_map), BPF_EXIT_INSN(), }; + LIBBPF_OPTS(bpf_test_run_opts, test_opts, + .data_in = &data_in, + .data_size_in = 1, + ); int prog_fd, map_fd, ret, insn_cnt = ARRAY_SIZE(insns); map_fd = bpf_map_create(BPF_MAP_TYPE_XSKMAP, NULL, sizeof(int), sizeof(int), 1, NULL); @@ -392,8 +395,8 @@ static enum xsk_prog get_xsk_prog(void) return detected; } - ret = bpf_prog_test_run(prog_fd, 0, &data_in, 1, &data_out, &size_out, &retval, &duration); - if (!ret && retval == XDP_PASS) + ret = bpf_prog_test_run_opts(prog_fd, &test_opts); + if (!ret && test_opts.retval == XDP_PASS) detected = XSK_PROG_REDIRECT_FLAGS; close(prog_fd); close(map_fd);