From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mail.toke.dk (Postfix) with ESMTPS id 80F3B982C61 for ; Tue, 28 Jun 2022 21:49:23 +0200 (CEST) Authentication-Results: mail.toke.dk; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=DVQlwfdC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656445763; x=1687981763; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=V/LelW6Mb5Cc8sNSdQPVZg4VOEAQ0MECgTTL8gSA07g=; b=DVQlwfdC2dWql/fHoB+ax12D3bd0N3SJaUYTB9ajWdY6lSaGQTcW1LQB 56zmXOuimLhON00GFYikgzSLtM0FF78kCHwxhBJmcFFe/pCkTaP/NoVCH nuQA/XljZBh8VGEdmVeJa1UCAQc5APGoejnbKsb6RhNNam4ImFjgUP5gG /mYYXAJYw3FJ3r22hfdm5Zx5OshbKj4rDk8r69I+J7E5hW6UR22Li8F30 v0vpCldfEzF4ozg40T+Iq4hVta9tX6PvWPSMTxqsdjraydZ73R66acEJU EijuEF/tGdvLPrzzl7XmAvsf1kRBLY2i2+jYtqSXByyC97u6C1/wF5E3N Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10392"; a="345828378" X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="345828378" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2022 12:49:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,229,1650956400"; d="scan'208";a="767288073" Received: from irvmail001.ir.intel.com ([10.43.11.63]) by orsmga005.jf.intel.com with ESMTP; 28 Jun 2022 12:49:17 -0700 Received: from newjersey.igk.intel.com (newjersey.igk.intel.com [10.102.20.203]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id 25SJmr9G022013; Tue, 28 Jun 2022 20:49:15 +0100 From: Alexander Lobakin To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Date: Tue, 28 Jun 2022 21:47:36 +0200 Message-Id: <20220628194812.1453059-17-alexandr.lobakin@intel.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220628194812.1453059-1-alexandr.lobakin@intel.com> References: <20220628194812.1453059-1-alexandr.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: E4FVJ4EIPW6GRUKQR47LFKM6ECKE5X7Q X-Message-ID-Hash: E4FVJ4EIPW6GRUKQR47LFKM6ECKE5X7Q X-MailFrom: alexandr.lobakin@intel.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Alexander Lobakin , Larysa Zaremba , Michal Swiatkowski , Jesper Dangaard Brouer , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , Toke Hoiland-Jorgensen , Lorenzo Bianconi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jesse Brandeburg , John Fastabend , Yajun Deng , Willem de Bruijn , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, xdp-hints@xdp-project.net X-Mailman-Version: 3.3.5 Precedence: list Subject: [xdp-hints] [PATCH RFC bpf-next 16/52] selftests/bpf: expand xdp_link to check that setting meta opts works List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Add a check in xdp_link to ensure that the values of btf_id and meta_thresh gotten via bpf_obj_get_info_by_fd() is the same as was passed via bpf_link_update(). Plus, that the kernel should fail to set btf_id to 0 when meta_thresh != 0. Also, use the new bpf_program__attach_xdp_opts() instead of the non-optsed version and set the initial metadata threshold value to check whether the kernel is able to process this request. When the threshold is being set via the Netlink interface, it's not being stored anywhere in the kernel core, so no test for it. Signed-off-by: Alexander Lobakin --- .../selftests/bpf/prog_tests/xdp_link.c | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_link.c b/tools/testing/selftests/bpf/prog_tests/xdp_link.c index 3e9d5c5521f0..0723278c448f 100644 --- a/tools/testing/selftests/bpf/prog_tests/xdp_link.c +++ b/tools/testing/selftests/bpf/prog_tests/xdp_link.c @@ -10,6 +10,7 @@ void serial_test_xdp_link(void) { struct test_xdp_link *skel1 = NULL, *skel2 = NULL; __u32 id1, id2, id0 = 0, prog_fd1, prog_fd2; + LIBBPF_OPTS(bpf_link_update_opts, lu_opts); LIBBPF_OPTS(bpf_xdp_attach_opts, opts); struct bpf_link_info link_info; struct bpf_prog_info prog_info; @@ -103,8 +104,16 @@ void serial_test_xdp_link(void) bpf_link__destroy(skel1->links.xdp_handler); skel1->links.xdp_handler = NULL; + opts.old_prog_fd = 0; + opts.meta_thresh = 128; + + err = libbpf_get_type_btf_id("struct xdp_meta_generic", &opts.btf_id); + if (!ASSERT_OK(err, "libbpf_get_type_btf_id")) + goto cleanup; + /* new link attach should succeed */ - link = bpf_program__attach_xdp(skel2->progs.xdp_handler, IFINDEX_LO); + link = bpf_program__attach_xdp_opts(skel2->progs.xdp_handler, + IFINDEX_LO, &opts); if (!ASSERT_OK_PTR(link, "link_attach")) goto cleanup; skel2->links.xdp_handler = link; @@ -113,11 +122,25 @@ void serial_test_xdp_link(void) if (!ASSERT_OK(err, "id2_check_err") || !ASSERT_EQ(id0, id2, "id2_check_val")) goto cleanup; + lu_opts.xdp.new_meta_thresh = 256; + lu_opts.xdp.new_btf_id = opts.btf_id; + /* updating program under active BPF link works as expected */ - err = bpf_link__update_program(link, skel1->progs.xdp_handler); + err = bpf_link_update(bpf_link__fd(link), + bpf_program__fd(skel1->progs.xdp_handler), + &lu_opts); if (!ASSERT_OK(err, "link_upd")) goto cleanup; + lu_opts.xdp.new_btf_id = 0; + + /* BTF ID can't be 0 when meta_thresh != 0, and vice versa */ + err = bpf_link_update(bpf_link__fd(link), + bpf_program__fd(skel1->progs.xdp_handler), + &lu_opts); + if (!ASSERT_ERR(err, "link_upd_fail")) + goto cleanup; + memset(&link_info, 0, sizeof(link_info)); err = bpf_obj_get_info_by_fd(bpf_link__fd(link), &link_info, &link_info_len); if (!ASSERT_OK(err, "link_info")) @@ -126,6 +149,9 @@ void serial_test_xdp_link(void) ASSERT_EQ(link_info.type, BPF_LINK_TYPE_XDP, "link_type"); ASSERT_EQ(link_info.prog_id, id1, "link_prog_id"); ASSERT_EQ(link_info.xdp.ifindex, IFINDEX_LO, "link_ifindex"); + ASSERT_EQ(link_info.xdp.btf_id, opts.btf_id, "btf_id"); + ASSERT_EQ(link_info.xdp.meta_thresh, lu_opts.xdp.new_meta_thresh, + "meta_thresh"); /* updating program under active BPF link with different type fails */ err = bpf_link__update_program(link, skel1->progs.tc_handler); -- 2.36.1