From patchwork Wed Aug 18 23:41:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 12445543 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E4E2C4338F for ; Wed, 18 Aug 2021 23:41:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E76760EBC for ; Wed, 18 Aug 2021 23:41:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234889AbhHRXmb (ORCPT ); Wed, 18 Aug 2021 19:42:31 -0400 Received: from new4-smtp.messagingengine.com ([66.111.4.230]:57505 "EHLO new4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232885AbhHRXma (ORCPT ); Wed, 18 Aug 2021 19:42:30 -0400 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailnew.nyi.internal (Postfix) with ESMTP id 6E4CE580E03; Wed, 18 Aug 2021 19:41:54 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Wed, 18 Aug 2021 19:41:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm1; bh=hFvEoVWwSCuTh+jP7I60pj2evE WcEGXz9qnhOKOKqxA=; b=W1xshOxYDoRTbnyH9NBniCWY7B8A6XItrnkOCFACma DPEGYs8iDPiqiXCmMEQFmNz3IsYSQk90qnW7Mph/lQ3wUqraVYc/GLus65gsZhqV t9Kvs92F11oBWhrNB7OEEmCsGHacKEIr9+dCc6sK8bZQK4+5N+LTp5PN+SX4gLYn 0ut164v925TzszwGO3MI9DAGB/jhnRBH8midGMDSLa6wzwWGcziXjCXxu+dTgvp5 z5qZg4PHK/F+LjiARFtvBeKtpOUxgXTYuy76ifggKcFjJPy5+TeLBXRmAwP1zAZr 993OZEBvckT+3Nd9VsLwuplSM97mwCcnZMYiiyIdU3Pg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=hFvEoVWwSCuTh+jP7 I60pj2evEWcEGXz9qnhOKOKqxA=; b=jJn9P1bERLvQZT2LKLfRgx9qd2+NW0pZ0 MDahjBQ5iejDast4AzcnHBUsaECFdqMKnWJ7bj54UNZ0RjgLLHOOsCPzwVTnrCmp AxpZUX4FEOFzB5IitXqnnPEpacRdSQsVDAQ8+TQTUNoSfMrX3H6pMMRLzqte5GSC tVU8I5AUbBiG/EPsPvQcYIQGCnf9ExhWsro+b9MeWSmiDhxL+Zp5kkiYqOyedrIw +k5ff2wgnb/wtDcuwvlxkfk8QXteOXd8XWj/vmHlKVlvzSoOdtNe+doUOiQA4Ca3 mDchsAFoqpgMfQttGUgbrhXdb6gsY2M64H7BrR6e1CX7hXNZ9Icuw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrleeigddvgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculddvfedmnegovehorghsthgrlh dqhfeguddvqddtvdculdduhedtmdenucfjughrpefhvffufffkofgggfestdekredtredt tdenucfhrhhomhepffgrnhhivghlucgiuhcuoegugihusegugihuuhhurdighiiiqeenuc ggtffrrghtthgvrhhnpeefgeehudeljeegueeguedvgeeuveelieetudffgfdvkeelheek vdejfffhfeefjeenucffohhmrghinheplhhkmhhlrdhorhhgpdhgihhthhhusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegugihu segugihuuhhurdighiii X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 18 Aug 2021 19:41:53 -0400 (EDT) From: Daniel Xu To: bpf@vger.kernel.org, yhs@fb.com, andriin@fb.com Cc: Daniel Xu , kernel-team@fb.com, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 0/2] Add bpf_task_pt_regs() helper Date: Wed, 18 Aug 2021 16:41:40 -0700 Message-Id: X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The motivation behind this helper is to access userspace pt_regs in a kprobe handler. uprobe's ctx is the userspace pt_regs. kprobe's ctx is the kernelspace pt_regs. bpf_task_pt_regs() allows accessing userspace pt_regs in a kprobe handler. The final case (kernelspace pt_regs in uprobe) is pretty rare (usermode helper) so I think that can be solved later if necessary. More concretely, this helper is useful in doing BPF-based DWARF stack unwinding. Currently the kernel can only do framepointer based stack unwinds for userspace code. This is because the DWARF state machines are too fragile to be computed in kernelspace [0]. The idea behind DWARF-based stack unwinds w/ BPF is to copy a chunk of the userspace stack (while in prog context) and send it up to userspace for unwinding (probably with libunwind) [1]. This would effectively enable profiling applications with -fomit-frame-pointer using kprobes and uprobes. [0]: https://lkml.org/lkml/2012/2/10/356 [1]: https://github.com/danobi/bpf-dwarf-walk Daniel Xu (2): bpf: Add bpf_task_pt_regs() helper bpf: selftests: Add bpf_task_pt_regs() selftest include/uapi/linux/bpf.h | 7 +++ kernel/trace/bpf_trace.c | 20 ++++++++ tools/include/uapi/linux/bpf.h | 7 +++ .../selftests/bpf/prog_tests/task_pt_regs.c | 50 +++++++++++++++++++ .../selftests/bpf/progs/test_task_pt_regs.c | 29 +++++++++++ 5 files changed, 113 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/task_pt_regs.c create mode 100644 tools/testing/selftests/bpf/progs/test_task_pt_regs.c