Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1097009lqm; Thu, 2 May 2024 05:25:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXE+aHFWPJbq+3m0xME4Ubjra51m3tm00B45UhryhS+Rlk3vK65nGTjf/vXzsCK5T9172DUAM56azh7KM4R1fuvw0sRLlQuaCz6HnyBFA== X-Google-Smtp-Source: AGHT+IESlgWat66zx6h1wqLbOow8j24vpK1Zv+8JtUEvNyET3Ol49qVi2+EjVHg7LW7S2DLNo4Kc X-Received: by 2002:a05:6830:3a0f:b0:6ee:203f:b877 with SMTP id di15-20020a0568303a0f00b006ee203fb877mr1973887otb.4.1714652735895; Thu, 02 May 2024 05:25:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714652735; cv=pass; d=google.com; s=arc-20160816; b=BaJ4mLu/cUAFg1o3G49MZPdK3ho7hqwWTzzVB4/4y3GgF85/VS4CvAjerGSdxzZ26A HaBcv1uOTQmIcDps8aP3fEtzFtTQntURJAGOMi1WMcv6s2cZm1SZGrWVSsdPcKqe2Ejs oAjq8+jXVTK+AoGmwHkidCuIz5MBwB378MHtDyDSIE1XIX4ulJ6WHw8nLo0NL/q3N/LC cxfFBv/4iEWkL7sM/kkiSlQzZYt1n+q07mgUw+amBEEE4c2lV0Z5p1UxnTIByVMdu1I6 35bWpmz4G+gqMDyPs4ezRg3cLnR2eVmPBvUbf42fUXvmvWEY/RcKR942LnoILSN+6zji pG0Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=qnRxOamirYaPGfwRj54sU4Tq67nQJJ+kV3TO2wjoIXo=; fh=u6oFqhax+rdToeRfofEe2lYdipIB9IHQSSbHp+u1raI=; b=qyqOnjTk4W1twETqhQEqZkMJxUVy8xLv9PP6FxmnyvfyRN9l6WFRCEg3RUlZaOcJjA tVGu5I87osrqD8XkF+5x77diaScGYfAYloHJ5kRSakgfg50yV20atzotjn6Den7bwfRY VXbb5MATsavW+ZyghZCqpdpHEzhMHlDP99iuwm8ybkBaY/5SLJhZn+hQ0E7d5BffBnLo /a5rg0uh1BYR/oF+BYQlEqEx0B/5q11U5yccnw+C1k7PRn8uN13vDFvFd5sj/1UHXTYC uJ10vZqnXwvVoX+Atlvb/mK3fQHCdxiIM1SHb5sjiv5idyWdHVF3CDMKY7S6UP0AkjAU YS3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TbXXD2nd; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-166445-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166445-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l4-20020a05620a28c400b0078ef418ec3fsi857267qkp.229.2024.05.02.05.25.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 05:25:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-166445-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TbXXD2nd; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-166445-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166445-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8E2081C20E68 for ; Thu, 2 May 2024 12:25:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EA76583CD7; Thu, 2 May 2024 12:24:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="TbXXD2nd" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEE847E572; Thu, 2 May 2024 12:24:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714652675; cv=none; b=f/ac9ZNawswJ6aCeWYqr62LZgGDH3WQd/019rLESutNPlAS5my2P6MNTRWmx8e5FKSqfCjwMQ016FzHRRKy6yp5LkvkFUprMFhRwiwIz6P7MMSCQ/Hrrwz3xFf+RNLtCs9b8UaPZHErB4yAD4QCVc1+2yOkbdeHxvtN73gQRxSo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714652675; c=relaxed/simple; bh=mWPTncrHfcSbvk7ZrPHsoF82D8w6WmakvxUwocjd27M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ePJcvcNf76cuHFZjtgsqCKi9BwLxPp0UYpztJ/2erL3XTR4pzpxZSAkc5/DGmuQDSEbDCIttgCt0YlTbbpUUmDPAeRkeT52k8ADUTuNufxoKm/hrU0IFMXhqcroMMffDhvU6dw46TizHsimTkVu1T90w7xEGa3aiLExuTgYeeqU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TbXXD2nd; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39765C113CC; Thu, 2 May 2024 12:24:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714652674; bh=mWPTncrHfcSbvk7ZrPHsoF82D8w6WmakvxUwocjd27M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TbXXD2ndjyF0VwzzJ33+q4aW9IuxGR3i4LXarga1ddjMHZMdyE9xEHaaeJlc5fq/C Hyls2SCrN7ksHsKoUr5HiS6+3a+xOFZijobc1/mfRrQ7G+AvJPBaE8FsPNOJQuDQ+m lcxItl84dO6Vb21H5ON4ykueoD4d50b+xiM+CQ43sHM8OJqy2CgJGBOYJjMRGLubfm p1NJSwuD0nBJD2OptcgOTnj0UEJi3hy46Qxx1TXt1mHaHJqTdpE28zbiLo7G5UZfhF DEllKFNsvCQNEKnyiuJW02605jxMCtZckBPHiHUXOwhKiS8qxp/gn6jv9YE+HYuW1i UnPn2N7xajkUQ== From: Jiri Olsa To: Steven Rostedt , Masami Hiramatsu , Oleg Nesterov , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-man@vger.kernel.org, x86@kernel.org, bpf@vger.kernel.org, Song Liu , Yonghong Song , John Fastabend , Peter Zijlstra , Thomas Gleixner , "Borislav Petkov (AMD)" , Ingo Molnar , Andy Lutomirski Subject: [PATCHv4 bpf-next 6/7] selftests/bpf: Add uretprobe compat test Date: Thu, 2 May 2024 14:23:12 +0200 Message-ID: <20240502122313.1579719-7-jolsa@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240502122313.1579719-1-jolsa@kernel.org> References: <20240502122313.1579719-1-jolsa@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Adding test that adds return uprobe inside 32-bit task and verify the return uprobe and attached bpf programs get properly executed. Reviewed-by: Masami Hiramatsu (Google) Signed-off-by: Jiri Olsa --- tools/testing/selftests/bpf/.gitignore | 1 + tools/testing/selftests/bpf/Makefile | 7 ++- .../selftests/bpf/prog_tests/uprobe_syscall.c | 60 +++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/.gitignore b/tools/testing/selftests/bpf/.gitignore index f1aebabfb017..69d71223c0dd 100644 --- a/tools/testing/selftests/bpf/.gitignore +++ b/tools/testing/selftests/bpf/.gitignore @@ -45,6 +45,7 @@ test_cpp /veristat /sign-file /uprobe_multi +/uprobe_compat *.ko *.tmp xskxceiver diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index 82247aeef857..a94352162290 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -133,7 +133,7 @@ TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \ xskxceiver xdp_redirect_multi xdp_synproxy veristat xdp_hw_metadata \ xdp_features bpf_test_no_cfi.ko -TEST_GEN_FILES += liburandom_read.so urandom_read sign-file uprobe_multi +TEST_GEN_FILES += liburandom_read.so urandom_read sign-file uprobe_multi uprobe_compat ifneq ($(V),1) submake_extras := feature_display=0 @@ -631,6 +631,7 @@ TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko \ $(OUTPUT)/xdp_synproxy \ $(OUTPUT)/sign-file \ $(OUTPUT)/uprobe_multi \ + $(OUTPUT)/uprobe_compat \ ima_setup.sh \ verify_sig_setup.sh \ $(wildcard progs/btf_dump_test_case_*.c) \ @@ -752,6 +753,10 @@ $(OUTPUT)/uprobe_multi: uprobe_multi.c $(call msg,BINARY,,$@) $(Q)$(CC) $(CFLAGS) -O0 $(LDFLAGS) $^ $(LDLIBS) -o $@ +$(OUTPUT)/uprobe_compat: + $(call msg,BINARY,,$@) + $(Q)echo "int main() { return 0; }" | $(CC) $(CFLAGS) -xc -m32 -O0 - -o $@ + EXTRA_CLEAN := $(SCRATCH_DIR) $(HOST_SCRATCH_DIR) \ prog_tests/tests.h map_tests/tests.h verifier/tests.h \ feature bpftool \ diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c b/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c index c6fdb8c59ea3..bfea9a0368a4 100644 --- a/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c +++ b/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c @@ -5,6 +5,7 @@ #ifdef __x86_64__ #include +#include #include #include #include @@ -297,6 +298,58 @@ static void test_uretprobe_syscall_call(void) close(go[1]); close(go[0]); } + +static void test_uretprobe_compat(void) +{ + LIBBPF_OPTS(bpf_uprobe_multi_opts, opts, + .retprobe = true, + ); + struct uprobe_syscall_executed *skel; + int err, go[2], pid, c, status; + + if (pipe(go)) + return; + + skel = uprobe_syscall_executed__open_and_load(); + if (!ASSERT_OK_PTR(skel, "uprobe_syscall_executed__open_and_load")) + goto cleanup; + + pid = fork(); + if (pid < 0) + goto cleanup; + + /* child */ + if (pid == 0) { + close(go[1]); + + /* wait for parent's kick */ + err = read(go[0], &c, 1); + if (err != 1) + exit(-1); + execl("./uprobe_compat", "./uprobe_compat", NULL); + exit(-1); + } + + skel->links.test = bpf_program__attach_uprobe_multi(skel->progs.test, pid, + "./uprobe_compat", "main", &opts); + if (!ASSERT_OK_PTR(skel->links.test, "bpf_program__attach_uprobe_multi")) + goto cleanup; + + /* kick the child */ + write(go[1], &c, 1); + err = waitpid(pid, &status, 0); + ASSERT_EQ(err, pid, "waitpid"); + + /* verify the child exited normally and the bpf program got executed */ + ASSERT_EQ(WIFEXITED(status), 1, "WIFEXITED"); + ASSERT_EQ(WEXITSTATUS(status), 0, "WEXITSTATUS"); + ASSERT_EQ(skel->bss->executed, 1, "executed"); + +cleanup: + uprobe_syscall_executed__destroy(skel); + close(go[0]); + close(go[1]); +} #else static void test_uretprobe_regs_equal(void) { @@ -312,6 +365,11 @@ static void test_uretprobe_syscall_call(void) { test__skip(); } + +static void test_uretprobe_compat(void) +{ + test__skip(); +} #endif void test_uprobe_syscall(void) @@ -322,4 +380,6 @@ void test_uprobe_syscall(void) test_uretprobe_regs_change(); if (test__start_subtest("uretprobe_syscall_call")) test_uretprobe_syscall_call(); + if (test__start_subtest("uretprobe_compat")) + test_uretprobe_compat(); } -- 2.44.0