From patchwork Sun Dec 29 14:37:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 1216097 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: incoming-bpf@patchwork.ozlabs.org Delivered-To: patchwork-incoming-bpf@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=bpf-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47m37w2zq1z9sPV for ; Mon, 30 Dec 2019 01:38:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726761AbfL2OiD convert rfc822-to-8bit (ORCPT ); Sun, 29 Dec 2019 09:38:03 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:54384 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726596AbfL2OiD (ORCPT ); Sun, 29 Dec 2019 09:38:03 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-252-nFGLHNO0M9S5tmLfGUf2Eg-1; Sun, 29 Dec 2019 09:37:57 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0A21110054E3; Sun, 29 Dec 2019 14:37:56 +0000 (UTC) Received: from krava.redhat.com (ovpn-204-25.brq.redhat.com [10.40.204.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 88F135DA7D; Sun, 29 Dec 2019 14:37:53 +0000 (UTC) From: Jiri Olsa To: Alexei Starovoitov , Daniel Borkmann Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Andrii Nakryiko , Yonghong Song , Martin KaFai Lau , Jakub Kicinski , David Miller Subject: [PATCH 4/5] bpf: Add bpf_get_stack_kfunc Date: Sun, 29 Dec 2019 15:37:39 +0100 Message-Id: <20191229143740.29143-5-jolsa@kernel.org> In-Reply-To: <20191229143740.29143-1-jolsa@kernel.org> References: <20191229143740.29143-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: nFGLHNO0M9S5tmLfGUf2Eg-1 X-Mimecast-Spam-Score: 0 Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Adding support to use bpf_get_stack_kfunc in BPF_TRACE_FENTRY/BPF_TRACE_FEXIT programs. Signed-off-by: Jiri Olsa --- kernel/trace/bpf_trace.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index c8e0709704f5..02979c5d6357 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -1229,6 +1229,32 @@ static const struct bpf_func_proto bpf_get_stackid_proto_kfunc = { .arg3_type = ARG_ANYTHING, }; +BPF_CALL_4(bpf_get_stack_kfunc, void*, args, + void *, buf, u32, size, u64, flags) +{ + struct pt_regs *regs = get_bpf_kfunc_regs(); + int ret; + + if (IS_ERR(regs)) + return PTR_ERR(regs); + + perf_fetch_caller_regs(regs); + ret = bpf_get_stack((unsigned long) regs, (unsigned long) buf, + (unsigned long) size, flags, 0); + put_bpf_kfunc_regs(); + return ret; +} + +static const struct bpf_func_proto bpf_get_stack_proto_kfunc = { + .func = bpf_get_stack_raw_tp, + .gpl_only = true, + .ret_type = RET_INTEGER, + .arg1_type = ARG_PTR_TO_CTX, + .arg2_type = ARG_PTR_TO_MEM, + .arg3_type = ARG_CONST_SIZE_OR_ZERO, + .arg4_type = ARG_ANYTHING, +}; + static const struct bpf_func_proto * kfunc_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) { @@ -1237,6 +1263,8 @@ kfunc_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) return &bpf_perf_event_output_proto_kfunc; case BPF_FUNC_get_stackid: return &bpf_get_stackid_proto_kfunc; + case BPF_FUNC_get_stack: + return &bpf_get_stack_proto_kfunc; default: return tracing_func_proto(func_id, prog); }