Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp9254ybl; Mon, 12 Aug 2019 10:48:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqx6zVT5QfshVQhvjn9d9eQVQr569dddYP0MTxN31VWu9I87gkJ/ZVka9EqSjGHgpd/0BQBG X-Received: by 2002:a65:64c6:: with SMTP id t6mr31890001pgv.323.1565632125598; Mon, 12 Aug 2019 10:48:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565632125; cv=none; d=google.com; s=arc-20160816; b=irIu2m/mDvk8V61lQ8nmt0L2dytzoahx5ELJrcE3c7NndtuxWp7gZw+QjFNY3JC60i s7myPrUTgTR2pjHWLKY314rDX1Sa9VydbqJ+tptNGzCW69b0Ga+3vj0QdZhedPXzJJrn droc6Yv1zfTzt71myWhWaGr6qG17gN+WUUqcrW0tCAGJYCMwNUiTQF1zj46RjLkZOD7w 3FSt+EvsyBgZ+8h5+PjS/txibld/WZikQZaGvmQ+Yh9xhR2FoDv1r37Eb7ooXBLof+El pCVMPGEA1IxkM3Eb4+BnOWkDleA+8oxfOymyVnHAG32SYtL+t5I+J9N8af9+7ovKG6Ty Qy9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=LVxEDKrf04Xopgme4UW2pTYkpgrPm8vtbBKdwKPRb9c=; b=RUK+tWb85weMv/eTyqtCZUquoxBJO59p6VklPfpyn5f3NAPubM/wJyzpOoZah4oXQu hdE3D6A/PQ25cYl3XBM5+MFOt3jBIHGWOz5ho1SAv5yCzPMgXpqXBWC5EPwN8CtA23vC VJlVhQqGnORitb+4WmsF+qkil0bkG9j+jJPPX0Q5YBsx0DLLSoU1eKscFOrbQgjCeMEz Nj1KN3sETCNBgI5sKcB59V8dRGg2vlq5Lw3gIljz59wCc1PnU3roVNrFVOkv5ijUpXUS t0e6gUrsdQpczqoxiIY7kApD3CCVoYmrEy+N5jsUqbrScR9ZiFuDVj671xqE760btyXc hK0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KCSyHIgG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id w9si137618pjv.67.2019.08.12.10.48.29; Mon, 12 Aug 2019 10:48:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KCSyHIgG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727160AbfHLRqW (ORCPT + 99 others); Mon, 12 Aug 2019 13:46:22 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:45323 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726144AbfHLRqW (ORCPT ); Mon, 12 Aug 2019 13:46:22 -0400 Received: by mail-qt1-f196.google.com with SMTP id k13so6381605qtm.12 for ; Mon, 12 Aug 2019 10:46:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LVxEDKrf04Xopgme4UW2pTYkpgrPm8vtbBKdwKPRb9c=; b=KCSyHIgGOsuO8VlJboapGrv3uhEopskXPDsFu7H1p9LYYyS2CGX6Vrw/1AhAqUASy7 S3MODho1pvt3/WGIDnCuXZR+zweI0QhhmUL3NhHq/nPbNc9BJ4M4XBZShrlMpGWBor0G veS6Z92NKz/8JQUXJryAP553TL7cfe+X6Fc3fjbgP3YmZsfw/pdY2jvA5ogkpvPaWpCg ulxbnezJQUw8xPfIPYQ5T+aOp88nk4ELGkDN9FUiHX2pPeiPaf7m0jwbCDqQ8kEcaqXj 9I4nSuC0vDo6Zlo0e93FMP4xeuhnZIxWGkWL4YdgmLpNfD8oUuz8Hq3LrQkjaGUvBGL5 CxJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LVxEDKrf04Xopgme4UW2pTYkpgrPm8vtbBKdwKPRb9c=; b=gG+PdMF77qXx2pDl45yWodrOBFlU/cKO4AsTLPGXzGP1us/6t3cmlOayjJjjgZ57YW UtTofzJePRw6vMZceIGCxY6Q+v/oj05/M4L7ADR0cAF9XYxd5MBsD8oDgNNlTZ9H/3iY EMzrF2dfBsVOdARsoZpqff0XvSOlI80dVulCsjQiiC5QF0kTGEB0ksP6XCqKzWq91OER 8/4dAg/gtdVFjDGOjWw7SL2xKzGe5QlM/HS60bbjbmyB5sct5LGmYJFr5IIHRWuZX6vk 4C/VwGOv4R+44FcHKm7cBx7Thle7Ehq9RzxUPvLa6n/KlA+7Y612T2npspqWsHOyDaji nYLA== X-Gm-Message-State: APjAAAX7U5thTwNhuFV6Ih1LqAGIq16L8XKljAyFJzRG/rvQdm6l8n9B g53pEX3xA32PFGkeTPMOgVjTwKJIsFUACl/gJwU= X-Received: by 2002:ac8:1e9b:: with SMTP id c27mr24683751qtm.171.1565631980750; Mon, 12 Aug 2019 10:46:20 -0700 (PDT) MIME-Version: 1.0 References: <20190809214642.12078-1-dxu@dxuuu.xyz> <20190809214642.12078-5-dxu@dxuuu.xyz> In-Reply-To: <20190809214642.12078-5-dxu@dxuuu.xyz> From: Andrii Nakryiko Date: Mon, 12 Aug 2019 10:46:09 -0700 Message-ID: Subject: Re: [PATCH v2 bpf-next 4/4] tracing/probe: Add self test for PERF_EVENT_IOC_QUERY_PROBE To: Daniel Xu Cc: Song Liu , Yonghong Song , Andrii Nakryiko , peterz@infraded.org, Ingo Molnar , Arnaldo Carvalho de Melo , Alexei Starovoitov , alexander.shishkin@linux.intel.com, Jiri Olsa , Namhyung Kim , open list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 9, 2019 at 2:49 PM Daniel Xu wrote: > > Signed-off-by: Daniel Xu > --- Getting verbose, we might want to rethink this test checks at some point, but I think it's fine for now. Please fix typos below, but overall: Acked-by: Andrii Nakryiko > .../selftests/bpf/prog_tests/attach_probe.c | 102 ++++++++++++++++++ > 1 file changed, 102 insertions(+) > > diff --git a/tools/testing/selftests/bpf/prog_tests/attach_probe.c b/tools/testing/selftests/bpf/prog_tests/attach_probe.c > index 5ecc267d98b0..bb53103ddb66 100644 > --- a/tools/testing/selftests/bpf/prog_tests/attach_probe.c > +++ b/tools/testing/selftests/bpf/prog_tests/attach_probe.c > @@ -27,17 +27,27 @@ void test_attach_probe(void) > const char *kretprobe_name = "kretprobe/sys_nanosleep"; > const char *uprobe_name = "uprobe/trigger_func"; > const char *uretprobe_name = "uretprobe/trigger_func"; > + struct perf_event_query_probe kprobe_query = {}; > + struct perf_event_query_probe kretprobe_query = {}; > + struct perf_event_query_probe uprobe_query = {}; > + struct perf_event_query_probe uretprobe_query = {}; > const int kprobe_idx = 0, kretprobe_idx = 1; > const int uprobe_idx = 2, uretprobe_idx = 3; > const char *file = "./test_attach_probe.o"; > struct bpf_program *kprobe_prog, *kretprobe_prog; > struct bpf_program *uprobe_prog, *uretprobe_prog; > struct bpf_object *obj; > + const struct bpf_link_fd *kprobe_fd_link; > + const struct bpf_link_fd *kretprobe_fd_link; > + const struct bpf_link_fd *uprobe_fd_link; > + const struct bpf_link_fd *uretprobe_fd_link; > int err, prog_fd, duration = 0, res; > struct bpf_link *kprobe_link = NULL; > struct bpf_link *kretprobe_link = NULL; > struct bpf_link *uprobe_link = NULL; > struct bpf_link *uretprobe_link = NULL; > + int kprobe_fd, kretprobe_fd; > + int uprobe_fd, uretprobe_fd; > int results_map_fd; > size_t uprobe_offset; > ssize_t base_addr; > @@ -116,6 +126,52 @@ void test_attach_probe(void) > /* trigger & validate kprobe && kretprobe */ > usleep(1); > > + kprobe_fd_link = bpf_link__as_fd(kprobe_link); > + if (CHECK(!kprobe_fd_link, "kprobe_link_as_fd", > + "failed to cast link to fd link\n")) > + goto cleanup; > + > + kprobe_fd = bpf_link_fd__fd(kprobe_fd_link); > + if (CHECK(kprobe_fd < 0, "kprobe_get_perf_fd", > + "failed to get perf fd from kprobe link\n")) > + goto cleanup; > + > + kretprobe_fd_link = bpf_link__as_fd(kretprobe_link); > + if (CHECK(!kretprobe_fd_link, "kretprobe_link_as_fd", > + "failed to cast link to fd link\n")) > + goto cleanup; > + > + kretprobe_fd = bpf_link_fd__fd(kretprobe_fd_link); > + if (CHECK(kretprobe_fd < 0, "kretprobe_get_perf_fd", > + "failed to get perf fd from kretprobe link\n")) > + goto cleanup; > + > + err = ioctl(kprobe_fd, PERF_EVENT_IOC_QUERY_PROBE, &kprobe_query); > + if (CHECK(err, "get_kprobe_ioctl", > + "failed to issue kprobe query ioctl\n")) > + goto cleanup; > + if (CHECK(kprobe_query.nmissed > 0, "get_kprobe_ioctl", > + "read incorect nmissed from kprobe_ioctl: %llu\n", typo: incorrect > + kprobe_query.nmissed)) > + goto cleanup; > + if (CHECK(kprobe_query.nhit == 0, "get_kprobe_ioctl", > + "read incorect nhit from kprobe_ioctl: %llu\n", typo: incorrect > + kprobe_query.nhit)) > + goto cleanup; > + > + err = ioctl(kretprobe_fd, PERF_EVENT_IOC_QUERY_PROBE, &kretprobe_query); > + if (CHECK(err, "get_kretprobe_ioctl", > + "failed to issue kretprobe query ioctl\n")) > + goto cleanup; > + if (CHECK(kretprobe_query.nmissed > 0, "get_kretprobe_ioctl", > + "read incorect nmissed from kretprobe_ioctl: %llu\n", same typo :) > + kretprobe_query.nmissed)) > + goto cleanup; > + if (CHECK(kretprobe_query.nhit <= 0, "get_kretprobe_ioctl", > + "read incorect nhit from kretprobe_ioctl: %llu\n", the power of copy/paste! :) > + kretprobe_query.nhit)) > + goto cleanup; > + > err = bpf_map_lookup_elem(results_map_fd, &kprobe_idx, &res); > if (CHECK(err, "get_kprobe_res", > "failed to get kprobe res: %d\n", err)) > @@ -135,6 +191,52 @@ void test_attach_probe(void) > /* trigger & validate uprobe & uretprobe */ > get_base_addr(); > > + uprobe_fd_link = bpf_link__as_fd(uprobe_link); > + if (CHECK(!uprobe_fd_link, "uprobe_link_as_fd", > + "failed to cast link to fd link\n")) > + goto cleanup; > + > + uprobe_fd = bpf_link_fd__fd(uprobe_fd_link); > + if (CHECK(uprobe_fd < 0, "uprobe_get_perf_fd", > + "failed to get perf fd from uprobe link\n")) > + goto cleanup; > + > + uretprobe_fd_link = bpf_link__as_fd(uretprobe_link); > + if (CHECK(!uretprobe_fd_link, "uretprobe_link_as_fd", > + "failed to cast link to fd link\n")) > + goto cleanup; > + > + uretprobe_fd = bpf_link_fd__fd(uretprobe_fd_link); > + if (CHECK(uretprobe_fd < 0, "uretprobe_get_perf_fd", > + "failed to get perf fd from uretprobe link\n")) > + goto cleanup; > + > + err = ioctl(uprobe_fd, PERF_EVENT_IOC_QUERY_PROBE, &uprobe_query); > + if (CHECK(err, "get_uprobe_ioctl", > + "failed to issue uprobe query ioctl\n")) > + goto cleanup; > + if (CHECK(uprobe_query.nmissed > 0, "get_uprobe_ioctl", > + "read incorect nmissed from uprobe_ioctl: %llu\n", > + uprobe_query.nmissed)) > + goto cleanup; > + if (CHECK(uprobe_query.nhit == 0, "get_uprobe_ioctl", > + "read incorect nhit from uprobe_ioctl: %llu\n", > + uprobe_query.nhit)) > + goto cleanup; > + > + err = ioctl(uretprobe_fd, PERF_EVENT_IOC_QUERY_PROBE, &uretprobe_query); > + if (CHECK(err, "get_uretprobe_ioctl", > + "failed to issue uretprobe query ioctl\n")) > + goto cleanup; > + if (CHECK(uretprobe_query.nmissed > 0, "get_uretprobe_ioctl", > + "read incorect nmissed from uretprobe_ioctl: %llu\n", > + uretprobe_query.nmissed)) > + goto cleanup; > + if (CHECK(uretprobe_query.nhit <= 0, "get_uretprobe_ioctl", > + "read incorect nhit from uretprobe_ioctl: %llu\n", > + uretprobe_query.nhit)) > + goto cleanup; > + same typos > err = bpf_map_lookup_elem(results_map_fd, &uprobe_idx, &res); > if (CHECK(err, "get_uprobe_res", > "failed to get uprobe res: %d\n", err)) > -- > 2.20.1 >