Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1362673pxb; Fri, 21 Jan 2022 16:33:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJwdx6Hru2EHsE83e+3DVP1YJJJ2295+ieoRsktJNoXGtt8RxY4Yt931ipxPNkFfzet1slAr X-Received: by 2002:a63:2b8b:: with SMTP id r133mr4447370pgr.265.1642811601759; Fri, 21 Jan 2022 16:33:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642811601; cv=none; d=google.com; s=arc-20160816; b=rmSWzdLSHH8O1QXrLV7QBg8JOI5WfwYeAC/7JqN85QmcgSXQSxSKOhT/5eKWAElJJf Hv9M0OdP5sQR4QSBGwm3/mc1jAxs7RgUSLeOk0vqvfU7lsT2SuqqieMq9f/aE/1WyXlX cfNF6/sP15eXuVRuvrp2U/o3R41sEncFYWZJaC7SGLEyzr519qhH+uE5trUB1gfLjpuF IHZuEGiGtme+zzPk929u4EYtviBAP35QQsCJzZtf36lsaIdxQP6LlNAvh1lD70zMXQ1x h9SUCI/vPip8YZutJr8elEPYK83Un3v9DRIbL9PKn02hRsMenYUzlYboQvqdWEiBXMUr FzYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=GE5TNu2f8uh1KqkgXFLXfRojZen3EAFTuFBKFaAEDmI=; b=haFhJan+xAiuV4bjRUI8SD9zyGiJJUrujPahQwNUH09lVj9ObsouTv2rTku0gbhTTv +2yj/bGrO8sz6BsTbkNN34W2o/9ne+1+ieW5vUk5y85undxSniLXAsugsYNyiuQtn7Pc hLmxq9DzY5mLwRM02mh5X3vnooHOTw3q0pELK0De9jeGjsKKX+bnd8EHOV5OGwI6dV09 78/nE4smy+24sUHPiawMJOxrSn9gFskiBAPBh1/6HL7zV7VLFKiRD1vIyooZG55wGL00 jvxjmPJ40ji17dJZ7GaNmmYduNRaFEF2XRJMbwFYb7FX8gCnRcSkGNRgH1FS1BDJ1R/B KsPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=O4HndrDB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w5si7423853pfu.214.2022.01.21.16.33.10; Fri, 21 Jan 2022 16:33:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=O4HndrDB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348665AbiAUFgR (ORCPT + 99 others); Fri, 21 Jan 2022 00:36:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348639AbiAUFgO (ORCPT ); Fri, 21 Jan 2022 00:36:14 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B436C061574; Thu, 20 Jan 2022 21:36:14 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id i65so7893776pfc.9; Thu, 20 Jan 2022 21:36:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GE5TNu2f8uh1KqkgXFLXfRojZen3EAFTuFBKFaAEDmI=; b=O4HndrDB2hRWx29Z1BfOyNHzNOSAer2GSHwD8YLsxLgWdcJO/8EC77Y5/GWMoQ5aoR LGsy6IROTHYiLeM9O8ah47QWa0aFcDhaTVBNdmV6E1q4Y0dOZdrSYFtXDuteUPjctsRn ctaKhBUjZjnuqJK+vS5fogMmfLGxEtM7IshmtugoxMSFJMJvkp7vwCMBy7IJfzlysuXK i3EQFOXfd8RSLvjHV2bZAjmapoo4IfY1Lh8xAfQXHxxJelW13tAIJdFLWVF2kLSkk/m3 5Cf8I0BQO83WAd9Crk79xHCU1CPVsd1OlN3HXNTchWqEdxrvzJldnE8rk0Bby1No9YLZ DO3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GE5TNu2f8uh1KqkgXFLXfRojZen3EAFTuFBKFaAEDmI=; b=K821G0YyAps5/QgQj3R4whYFYjkFInL/3nG34gViNBUj47YYkSR95e6miDadBcjXr1 p2gI2D2KXe+JoIosaURPo6HG0FAnqGW2m1/R5FwGDBfDTx11pxEPe35A8jS750d4gYTl ghDRvW01/drCkfi3Zg04fHDtf/CzSMs7qPggxZ9xoy5smG7ZGl2RM1Bu1yMo62kgWRHp iZmbeFL67RZAlVbUzMRkybQpYkdHESh7ROrgkGr8Jj/nw53vNXJLgvMwwvm9A3Mce+cH me5xEqSwU67wr0G679xd53XeTh6/cYshTc7SUNGq6ySiHWzlDZx6yp+4J3OupBr3X7mk gWoA== X-Gm-Message-State: AOAM530s5aRYTBMQC1CdqQTKh9qiKLXM/G4m7jXGtsqBAxLSrU9IA/y/ Ki4l/N9v0pVXv8P8HPnARum3BAS7Xkafia6jXjI= X-Received: by 2002:aa7:888d:0:b0:4c2:7965:950d with SMTP id z13-20020aa7888d000000b004c27965950dmr2598484pfe.46.1642743373935; Thu, 20 Jan 2022 21:36:13 -0800 (PST) MIME-Version: 1.0 References: <20220119014005.1209-1-zhudi2@huawei.com> <20220119014005.1209-2-zhudi2@huawei.com> In-Reply-To: <20220119014005.1209-2-zhudi2@huawei.com> From: Alexei Starovoitov Date: Thu, 20 Jan 2022 21:36:02 -0800 Message-ID: Subject: Re: [PATCH bpf-next v6 2/2] selftests: bpf: test BPF_PROG_QUERY for progs attached to sockmap To: Di Zhu Cc: Andrii Nakryiko , Alexei Starovoitov , "David S. Miller" , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Jakub Sitnicki , bpf , LKML , luzhihao@huawei.com, rose.chen@huawei.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 18, 2022 at 5:40 PM Di Zhu wrote: > > Add test for querying progs attached to sockmap. we use an existing > libbpf query interface to query prog cnt before and after progs > attaching to sockmap and check whether the queried prog id is right. > > Signed-off-by: Di Zhu > Acked-by: Yonghong Song > --- > .../selftests/bpf/prog_tests/sockmap_basic.c | 66 +++++++++++++++++++ > .../bpf/progs/test_sockmap_progs_query.c | 24 +++++++ > 2 files changed, 90 insertions(+) > create mode 100644 tools/testing/selftests/bpf/progs/test_sockmap_progs_query.c > > diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c > index 85db0f4cdd95..1ab57cdc4ae4 100644 > --- a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c > +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c > @@ -8,6 +8,7 @@ > #include "test_sockmap_update.skel.h" > #include "test_sockmap_invalid_update.skel.h" > #include "test_sockmap_skb_verdict_attach.skel.h" > +#include "test_sockmap_progs_query.skel.h" > #include "bpf_iter_sockmap.skel.h" > > #define TCP_REPAIR 19 /* TCP sock is under repair right now */ > @@ -315,6 +316,63 @@ static void test_sockmap_skb_verdict_attach(enum bpf_attach_type first, > test_sockmap_skb_verdict_attach__destroy(skel); > } > > +static __u32 query_prog_id(int prog_fd) > +{ > + struct bpf_prog_info info = {}; > + __u32 info_len = sizeof(info); > + int err; > + > + err = bpf_obj_get_info_by_fd(prog_fd, &info, &info_len); > + if (!ASSERT_OK(err, "bpf_obj_get_info_by_fd") || > + !ASSERT_EQ(info_len, sizeof(info), "bpf_obj_get_info_by_fd")) > + return 0; > + > + return info.id; > +} > + > +static void test_sockmap_progs_query(enum bpf_attach_type attach_type) > +{ > + struct test_sockmap_progs_query *skel; > + int err, map_fd, verdict_fd, duration = 0; The 'duration' is unused. You should have seen a warning while compiling the selftests? Anyway. I've fixed it while applying.