Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp445880lqh; Tue, 7 May 2024 04:19:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWL3T4jHkHXUYhtLHk+NNRJFHsOpiqg/0wJBG17G35zfTUJ6V59YY5HDS1cKM1lc4LL93flMOAd2yRFOj6MxumLcU4xWTVFgWIDPhh0+Q== X-Google-Smtp-Source: AGHT+IFOx4fG+hxjt8J1WgLdYVFOMfkPbJYTeEr6JOltZWEMQGnsLEXvH01fqwknk0X58f1CdMth X-Received: by 2002:a17:902:a60c:b0:1e4:6938:6fe3 with SMTP id u12-20020a170902a60c00b001e469386fe3mr11015976plq.58.1715080748644; Tue, 07 May 2024 04:19:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715080748; cv=pass; d=google.com; s=arc-20160816; b=egnppw7qvCf5n9n0/hDDOwMtADn52MXdDtKmR+g0vkUXYm0ZEqKiFwj7a/j7z5l6Bn nCE+Xe72zeOTw13Ftjb9n0hZVT2SDWJDIywzFukmH/wfWcsJSS48KAX7c4a3qBXH/Nmu czUuW/kOslcBFI1ejYBJV/kNLJjL2aqSaBJr0CNes4NrWVx0P9F3TnuWUX6p77TftXLK CdS/y/e0L66aWmR5UmdNOgIgvY+K8HD9idZhyYxUfkZxRIKWgPMaiYnvLKX0FLF3/1OB rGS8TUWarMTa+7e+Silt1BxwFAA9Um/mvWRaoJkUbJJWhV2im1PpV7/FO/ucVvQxNpGh lACg== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=68Uafi/R2OSOP/HfjyaG6yMlRfuMiFRXQhzaBydBGvs=; fh=nmDo0evxWwTAvBlxNELHY/fYZbxD4K9pluaUjPt1MrQ=; b=qSTrSohw3VSNVDn96wHz+H60J9axWWqrJ/W8jBIQ7ONH+gv7DkEeUR6iHkvRD5YRz/ S+lXYZpoBVzPJXSyv0hcTVr6FigU+JgmYvdO11dwPk36jEywyAivKiCCe+3Jk0L+f2Du 5+DsfVzHdRCTPmBQmcrstJ33SskE3D3SUPEmeN6clIYJWk6bFXuLimeBvzDd+SR9uRB+ 6xvWPcb/GiKLRPdQWPdgrjdfjG4qhiwZGYWcfjZuur4Q1ZVwlVvDO8o3llHSvZB7yFrg AZ9FWvYLwUb28ur9MYJcqayWgVAZ6ghcV0OaIWuSPvyNSEv7faoadO6JTJatKCTcNDV6 oYOg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sd9lJi5H; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171144-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171144-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id w6-20020a170902e88600b001eafb12eb6bsi9608415plg.534.2024.05.07.04.19.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 04:19:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171144-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sd9lJi5H; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171144-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171144-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 85AF4B25A10 for ; Tue, 7 May 2024 10:53:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8AC561514D9; Tue, 7 May 2024 10:53:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sd9lJi5H" 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 9A8D614EC77; Tue, 7 May 2024 10:53:29 +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=1715079209; cv=none; b=nOZrUeMM/Y6EIQpsk87qMqADa8QIKThtQtTyYJy3GwtAebQL+fXiz3zkzKqqFGMwDeVFEs+S72NnXXW5EysPN0+uoYftSmoDnUiX5utTr4en82MOrPGjVOmQP8MrC+K2rKVdvpNOYZ/t8FK19f/0cM/tWKZmXEZkO6CXALOw/7k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715079209; c=relaxed/simple; bh=zRCYiOQHPnfhs1z3DR2elwt2Yar4HKiZO0wVgLYg+Vg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hEqIG2sksvVU9Z7qrWCJ2ddzJKAUgJQFvs5XZXH8mOHkioRlsMc1pwr/cEYvsVbdim2kwlUzZElWQENkfYmPYQ9q4Ru95AVXSFdoPUxA4lXsKIEbL9Te8FXyfvzU/TWjpRCdqn99sDd4k6Zqsa3flon5BQVXOtFl5j18L/Xrw78= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sd9lJi5H; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2481C2BBFC; Tue, 7 May 2024 10:53:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715079209; bh=zRCYiOQHPnfhs1z3DR2elwt2Yar4HKiZO0wVgLYg+Vg=; h=From:To:Cc:Subject:Date:From; b=sd9lJi5HBDDMQcb1fyizgnog+zrbmj5jPa0DvXupXs6nqIMgdu6hI3V4VMe3GjB4f lo2xNa1OWmjwKh8uY1kkVCEeOCjtqo6YXMIyhMInI0TXtmOy7KbvyBGRkiSG7tlFZa yt8KkxFd5HryeNJ9NpGX/3djDR8zx7QkrnD3GEsTJ7Q28SdhvGw9yKAJ2XRIzDyfXg lKQsWQERWl44PwOYWS/WjAdtjfolJLSINidU0Q6tz4q+t2rLtwIUiOUnlbAg9aZFck nbfsMm+qNHypPzPGTs3Qj5BPBzZMDTLJnEcypgrn3JwbGxrF0E1emYkYDi7UKWGlJo RcZZQlVaWwAhw== 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 , "Edgecombe, Rick P" , Deepak Gupta Subject: [PATCHv5 bpf-next 0/8] uprobe: uretprobe speed up Date: Tue, 7 May 2024 12:53:13 +0200 Message-ID: <20240507105321.71524-1-jolsa@kernel.org> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit hi, as part of the effort on speeding up the uprobes [0] coming with return uprobe optimization by using syscall instead of the trap on the uretprobe trampoline. The speed up depends on instruction type that uprobe is installed and depends on specific HW type, please check patch 1 for details. Patches 1-7 are based on bpf-next/master, but path 1 and 2 are apply-able on linux-trace.git tree probes/for-next branch. Patch 8 is based on man-pages master. v5 changes: - added shadow stack support for uretprobe [peterz] - reworded man page + typos [Alejandro Colom] - added pipe ASSERT_OK [Andrii] - added acks [Andrii] - removed compat test for now before ci is fixed Also available at: https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git uretprobe_syscall thanks, jirka Notes to check list items in Documentation/process/adding-syscalls.rst: - System Call Alternatives New syscall seems like the best way in here, because we need just to quickly enter kernel with no extra arguments processing, which we'd need to do if we decided to use another syscall. - Designing the API: Planning for Extension The uretprobe syscall is very specific and most likely won't be extended in the future. At the moment it does not take any arguments and even if it does in future, it's allowed to be called only from trampoline prepared by kernel, so there'll be no broken user. - Designing the API: Other Considerations N/A because uretprobe syscall does not return reference to kernel object. - Proposing the API Wiring up of the uretprobe system call is in separate change, selftests and man page changes are part of the patchset. - Generic System Call Implementation There's no CONFIG option for the new functionality because it keeps the same behaviour from the user POV. - x86 System Call Implementation It's 64-bit syscall only. - Compatibility System Calls (Generic) N/A uretprobe syscall has no arguments and is not supported for compat processes. - Compatibility System Calls (x86) N/A uretprobe syscall is not supported for compat processes. - System Calls Returning Elsewhere N/A. - Other Details N/A. - Testing Adding new bpf selftests and ran ltp on top of this change. - Man Page Attached. - Do not call System Calls in the Kernel N/A. [0] https://lore.kernel.org/bpf/ZeCXHKJ--iYYbmLj@krava/ --- Jiri Olsa (7): uprobe: Wire up uretprobe system call uprobe: Add uretprobe syscall to speed up return probe selftests/bpf: Add uretprobe syscall test for regs integrity selftests/bpf: Add uretprobe syscall test for regs changes selftests/bpf: Add uretprobe syscall call from user space test x86/shstk: Add return uprobe support selftests/x86: Add return uprobe shadow stack test arch/x86/entry/syscalls/syscall_64.tbl | 1 + arch/x86/include/asm/shstk.h | 4 ++ arch/x86/kernel/shstk.c | 29 +++++++++ arch/x86/kernel/uprobes.c | 127 +++++++++++++++++++++++++++++++++++- include/linux/syscalls.h | 2 + include/linux/uprobes.h | 3 + include/uapi/asm-generic/unistd.h | 5 +- kernel/events/uprobes.c | 24 +++++-- kernel/sys_ni.c | 2 + tools/include/linux/compiler.h | 4 ++ tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c | 123 ++++++++++++++++++++++++++++++++++- tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c | 325 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/testing/selftests/bpf/progs/uprobe_syscall.c | 15 +++++ tools/testing/selftests/bpf/progs/uprobe_syscall_executed.c | 17 +++++ tools/testing/selftests/x86/test_shadow_stack.c | 142 ++++++++++++++++++++++++++++++++++++++++ 15 files changed, 813 insertions(+), 10 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c create mode 100644 tools/testing/selftests/bpf/progs/uprobe_syscall.c create mode 100644 tools/testing/selftests/bpf/progs/uprobe_syscall_executed.c Jiri Olsa (1): man2: Add uretprobe syscall page man2/uretprobe.2 | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 man2/uretprobe.2