Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp837185ybl; Fri, 9 Aug 2019 14:49:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqymc1pFshRMzZTqRiOcf5898VPUVQJxoH+L8fLUO652x4yNXDa5BPreSEDraavAVe8s7n+T X-Received: by 2002:a65:4b89:: with SMTP id t9mr18964467pgq.55.1565387386908; Fri, 09 Aug 2019 14:49:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565387386; cv=none; d=google.com; s=arc-20160816; b=gNdI4TZx8Sn9UtMTzKESUivfZbg0EhLWBGAjghAM4H3z4oLVGYR/77l2v7vfnY26nM RR5mYe7uWo1jkFP9J83HCn2/1E+3c3lUC5HJPIstIu4cQ3bwnOhtQ42VVrIOfzsbtJ4P FYqDQP/wbP2hvTQbWbKmlD615lfkO7r+RC1c3uPZD/+gIkfzin2Vi/ZgVrbbZZDfh+rQ eHhY70+Ci9tk+CLMPWF3od9g5Gm/gG47xbAuH3oW14VNToAhihaGDTzODzl0E+oSY6KY xRV11ELKqA9N162/22SdLgE7gggKb/O/WfMFtLSxBqSa5ZiwOY81blpgBu9jylu+CHG5 d4sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=3HfArrsUapD2GuEhrlUoGsXRI0BRydCBwu27R8/WFUM=; b=HAKO/iuTKE0bACmukDCfP2gno2Puwzv6lVPMQfZLEhJoU+Px6e7NMk/nkwVzbCml1a 4SNrqqk3RIXlqfzpFavYJHkGtK4era8eC4sNN1y/p5wRnaNK57kc8Ku0oil2WHEngJ6+ EHB1l3SMJscdeWDA4jNlAhORKEEq7fpKvRz51POU6U+Rit5Q8oE+Qw+YhqnwV3+VqqOj YzhssSQkpXumpEnuxMXosF5y0WbPbSKKeOg8tyKuLDal3/Ef5H763coJ8LnGS3BmS8pG /NNdgtzgciHfg7rDH8wiCnPm3+VqjSR/OBodnFvE4PIVectNL5DrUWKmex7nr4ez2jxI IJfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dxuuu.xyz header.s=fm1 header.b=ABYFek7G; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=qW1zj6Bf; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q11si5345324pjb.84.2019.08.09.14.49.12; Fri, 09 Aug 2019 14:49:46 -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=@dxuuu.xyz header.s=fm1 header.b=ABYFek7G; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=qW1zj6Bf; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729285AbfHIVrl (ORCPT + 99 others); Fri, 9 Aug 2019 17:47:41 -0400 Received: from new1-smtp.messagingengine.com ([66.111.4.221]:55693 "EHLO new1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728600AbfHIVri (ORCPT ); Fri, 9 Aug 2019 17:47:38 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.nyi.internal (Postfix) with ESMTP id 9A16E20D6; Fri, 9 Aug 2019 17:47:37 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 09 Aug 2019 17:47:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=3HfArrsUapD2G uEhrlUoGsXRI0BRydCBwu27R8/WFUM=; b=ABYFek7GmunD3FEuSEnC4/edWdATL 095uTTEJdY5H0IPUQQgFHvMNuyExqM4B5/R43ubmVutBnxvRB1BeV0FRkoItZPTc kR0TZq+Zh/eR6HE22c6yTXw4FXHbJ452ZohNxUCWYflFyTJLFeqxzA8gUIg8EHVB dSyBkYuN8jI2pNz85DRZ0ToE8SD9Cr1F1Yt+wDhjUA9ulotHtGb653MGEWxpxWK4 zZ0YZlbB6bLOovvFqZS/aoi6O0uOSiNkaVqGtQGhTLWfZXspeCvo8mBI4UJlDWni 2YmR0b/4CPme3Z+RucBjabHTQ4O7Fex9ooT0+bdsw0CJyafFIzM084wbg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=3HfArrsUapD2GuEhrlUoGsXRI0BRydCBwu27R8/WFUM=; b=qW1zj6Bf +CFxTp+Pz38bdyxa+AWqOA3B0ITLmKvxXFRNeXBM8sOnuCHtm69YiSBcul6jKJ7Y 0GI1TDJ6ryd3gjrRzo3CVSvZZCWfXzDN0kPeodT7R1XS6KsO8rWqzevqsB3Lmh3C 6atkh5wT3eVnSLZpQLvsnkzkBJO70fkRNWE7KSZFcfWrEVfztEAaEh0A8TaDSyaF LYpzfJf6gds5eP7KwrKWzOVYY4AyofmOyQ5uuZ1TH0bW9zonqrcoUeBhBpqGHsPz uNKUcaNip1steZnOGj1KcBahY1l3nYHcjl/8Bgh2PZtGBp+X4mT0Vty8+aODw4MD kM4bt0D7svO/lw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddruddukedgtdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdljedtmdenucfjughrpefhvf fufffkofgjfhgggfestdekredtredttdenucfhrhhomhepffgrnhhivghlucgiuhcuoegu gihusegugihuuhhurdighiiiqeenucfkphepudelledrvddtuddrieegrddufeeknecurf grrhgrmhepmhgrihhlfhhrohhmpegugihusegugihuuhhurdighiiinecuvehluhhsthgv rhfuihiivgepud X-ME-Proxy: Received: from dlxu-fedora-R90QNFJV.thefacebook.com (unknown [199.201.64.138]) by mail.messagingengine.com (Postfix) with ESMTPA id D54B6380075; Fri, 9 Aug 2019 17:47:35 -0400 (EDT) From: Daniel Xu To: songliubraving@fb.com, yhs@fb.com, andriin@fb.com, peterz@infraded.org, mingo@redhat.com, acme@kernel.org Cc: Daniel Xu , ast@fb.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 bpf-next 4/4] tracing/probe: Add self test for PERF_EVENT_IOC_QUERY_PROBE Date: Fri, 9 Aug 2019 14:46:42 -0700 Message-Id: <20190809214642.12078-5-dxu@dxuuu.xyz> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190809214642.12078-1-dxu@dxuuu.xyz> References: <20190809214642.12078-1-dxu@dxuuu.xyz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Daniel Xu --- .../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", + kprobe_query.nmissed)) + goto cleanup; + if (CHECK(kprobe_query.nhit == 0, "get_kprobe_ioctl", + "read incorect nhit from kprobe_ioctl: %llu\n", + 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", + kretprobe_query.nmissed)) + goto cleanup; + if (CHECK(kretprobe_query.nhit <= 0, "get_kretprobe_ioctl", + "read incorect nhit from kretprobe_ioctl: %llu\n", + 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; + 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