Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3878910ybf; Tue, 3 Mar 2020 14:53:31 -0800 (PST) X-Google-Smtp-Source: ADFU+vsCNKrfHC/v+C/enVIULK/dv/32vtVsZSHTTPgpW0av/tyArjCLmVltfvCiAPGTR3iTJZBf X-Received: by 2002:aca:c7c5:: with SMTP id x188mr617724oif.130.1583276010978; Tue, 03 Mar 2020 14:53:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583276010; cv=none; d=google.com; s=arc-20160816; b=UKhtRdR3nN5OeIdshfvuAytCjY8D/IXZjJAfPBYQGokOu9ENQ/8gI6G2l9+K97L+wL yOQgM+h481sWuxlDLMWJrSFSv2U3JGXyKA4cGq5/tENxuKrsITnqY+HT5CkyLtemRwsr psP6XGXuck2yRAaziEfQ10a9ssTNjlEPZD1WjTDq43T+tcapsQ07gbLovw05Gmc+lyPl RdEfhzj6YSCB99yZ7OyIbCI3HUQAJD5xjKi25oLzGTieq7y3eRwIkT7WIu5JOenkCkO7 SUiBx78CnZYZrswNvX/VbCGLWwSiO8eVJRP2d2wvIR+NxyQXQm8pYpEV3AV/18IzD/Ul aPvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=F2T/hdztknZaZB9rKuLdx0utKPRLSLq4Mg2YsdbGcC0=; b=eaQWYRQTso2m+tSW0IOAT4A8UhmPIrQcnEedbyQNa18BuPXxyy5Li2Ym0iWwd7Hg0j n0baU8nTfGLrX5N2eVrrWzEiKjgNr+aYi99huuxmMhKh9T3Ixi4Ie+UCVfV1zmeh8a/V 1mPi7bjeOz8kq4UGbC3aFz9m+9xzqw5BruBZICFTORH0vQEqTRtPkTJQOo7KvP+a0xyr 02jYnB0ZRM4I4P92aWWIYCcgygcMp7afvUACE8ZuUZ4NXsvL6oyvqGxgtfRFW9gSO0c/ Qjtkre0oGt7LHg82MwKsmea8SL8S4y+QvxaMYyc7iuRtAwK1J4BLjw5tRGDjz2Koxyff PoEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XEwASVUm; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a185si89372oii.252.2020.03.03.14.53.17; Tue, 03 Mar 2020 14:53:30 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=XEwASVUm; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728070AbgCCWwK (ORCPT + 99 others); Tue, 3 Mar 2020 17:52:10 -0500 Received: from mail-qv1-f65.google.com ([209.85.219.65]:40584 "EHLO mail-qv1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727459AbgCCWwK (ORCPT ); Tue, 3 Mar 2020 17:52:10 -0500 Received: by mail-qv1-f65.google.com with SMTP id ea1so128231qvb.7; Tue, 03 Mar 2020 14:52:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=F2T/hdztknZaZB9rKuLdx0utKPRLSLq4Mg2YsdbGcC0=; b=XEwASVUmB4oaP3s0oDkZzi6JsecN7KwtiIEl3P5ngtN8cSWwtI2Adetpf0WAeqRkdk 3hR1tsFjYwh8mOamu8kyt/UwOgwATvv9Ew47X7/4ruist9pf59WYmIlo19LY85ZjCBQT vcqbfmN9p6VG1DuDk92PIauxQHgr3b/TPScuRl0Mg1EcCsFi0w0qQBp3lnCKsAt1rwFI 8qAAi2wfauEfpuGYZTv2RoxwlW+G39s5ZsawHsw/QZ5oTVvUTM2Uz33fH6Hmj/3kJbZq LO1uLnJAyewWR6ZRaqkvzJnAcCuUvUWmtVv3jI9/BxKLzyD7hnulU3SenJkCY3a+aDK0 paaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=F2T/hdztknZaZB9rKuLdx0utKPRLSLq4Mg2YsdbGcC0=; b=cxWQ75H8vN7ZDMbfMUH+heVQMM2QYZJYsOxsESpBlfuvjdyQsTrPUKRcr5OJNDQUSX gI+EOFrXCPQYta8FNQQ/TPOoV7CJoTnN+Vrj28MzFb0RshUOiMKnWITXjSe2YjGpp+eE BVSblQY9H54GvtkQJJP0Z5rKAMRPuRdhSZR5XjpKPH+5GBZvnakCa27eRf2lO/zPygvE yyEaAk2cVEzjvJeyj2TN2Bx9yyR/5oEiAdtEdkDolloiF4qhwxcUTkhRjjm4EXd+kwqP 9vfCPZiO4fOi1MhkvNgmOfdtU5Gk3aAczZVgZCFPRdz3xey4xCvv1fbBHk/pZq8HzZsA teqA== X-Gm-Message-State: ANhLgQ3kfMBHDsz2cByURGsv3GFPcGjOBEu9ItNmirE14xZKg/ToUwp5 2ip3SpJ+9XVA5rqmYmOl/dN7eNDvNL0+xjyA0LQ= X-Received: by 2002:a05:6214:8cb:: with SMTP id da11mr5745752qvb.228.1583275928811; Tue, 03 Mar 2020 14:52:08 -0800 (PST) MIME-Version: 1.0 References: <20200303140950.6355-1-kpsingh@chromium.org> <20200303140950.6355-7-kpsingh@chromium.org> In-Reply-To: <20200303140950.6355-7-kpsingh@chromium.org> From: Andrii Nakryiko Date: Tue, 3 Mar 2020 14:51:57 -0800 Message-ID: Subject: Re: [PATCH bpf-next 6/7] bpf: Add test ops for BPF_PROG_TYPE_TRACING To: KP Singh Cc: open list , bpf , Alexei Starovoitov , Daniel Borkmann , Paul Turner , Florent Revest , Brendan Jackman Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 3, 2020 at 6:12 AM KP Singh wrote: > > From: KP Singh > > The current fexit and fentry tests rely on a different program to > exercise the functions they attach to. Instead of doing this, implement > the test operations for tracing which will also be used for > BPF_OVERRIDE_RETURN in a subsequent patch. typo: BPF_OVERRIDE_RETURN -> BPF_MODIFY_RETURN? > > Also, clean up the fexit test to use the generated skeleton. > > Signed-off-by: KP Singh > --- Nice clean up for fexit_test, thank you! > include/linux/bpf.h | 10 +++ > kernel/trace/bpf_trace.c | 1 + > net/bpf/test_run.c | 38 +++++++--- > .../selftests/bpf/prog_tests/fentry_fexit.c | 12 +--- > .../selftests/bpf/prog_tests/fentry_test.c | 14 ++-- > .../selftests/bpf/prog_tests/fexit_test.c | 69 ++++++------------- > 6 files changed, 68 insertions(+), 76 deletions(-) > > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > index 3cfdc216a2f4..c00919025532 100644 > --- a/include/linux/bpf.h > +++ b/include/linux/bpf.h > @@ -1156,6 +1156,9 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr, > union bpf_attr __user *uattr); > int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr, > union bpf_attr __user *uattr); > +int bpf_prog_test_run_tracing(struct bpf_prog *prog, > + const union bpf_attr *kattr, > + union bpf_attr __user *uattr); > int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog, > const union bpf_attr *kattr, > union bpf_attr __user *uattr); > @@ -1313,6 +1316,13 @@ static inline int bpf_prog_test_run_skb(struct bpf_prog *prog, > return -ENOTSUPP; > } > > +static inline int bpf_prog_test_run_tracing(struct bpf_prog *prog, > + const union bpf_attr *kattr, > + union bpf_attr __user *uattr) > +{ > + return -ENOTSUPP; > +} > + > static inline int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog, > const union bpf_attr *kattr, > union bpf_attr __user *uattr) > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c > index 07764c761073..363e0a2c75cf 100644 > --- a/kernel/trace/bpf_trace.c > +++ b/kernel/trace/bpf_trace.c > @@ -1266,6 +1266,7 @@ const struct bpf_verifier_ops tracing_verifier_ops = { > }; > > const struct bpf_prog_ops tracing_prog_ops = { > + .test_run = bpf_prog_test_run_tracing, > }; > > static bool raw_tp_writable_prog_is_valid_access(int off, int size, > diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c > index 562443f94133..fb54b45285b4 100644 > --- a/net/bpf/test_run.c > +++ b/net/bpf/test_run.c > @@ -160,18 +160,38 @@ static void *bpf_test_init(const union bpf_attr *kattr, u32 size, > kfree(data); > return ERR_PTR(-EFAULT); > } > - if (bpf_fentry_test1(1) != 2 || > - bpf_fentry_test2(2, 3) != 5 || > - bpf_fentry_test3(4, 5, 6) != 15 || > - bpf_fentry_test4((void *)7, 8, 9, 10) != 34 || > - bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 || > - bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111) { > - kfree(data); > - return ERR_PTR(-EFAULT); > - } > + > return data; > } > > +int bpf_prog_test_run_tracing(struct bpf_prog *prog, > + const union bpf_attr *kattr, > + union bpf_attr __user *uattr) > +{ > + int err = -EFAULT; > + > + switch (prog->expected_attach_type) { > + case BPF_TRACE_FENTRY: > + case BPF_TRACE_FEXIT: > + if (bpf_fentry_test1(1) != 2 || > + bpf_fentry_test2(2, 3) != 5 || > + bpf_fentry_test3(4, 5, 6) != 15 || > + bpf_fentry_test4((void *)7, 8, 9, 10) != 34 || > + bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 || > + bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111) > + goto out; > + break; > + default: > + goto out; > + } No trace_bpf_test_finish here? > + > + return 0; > + > +out: > + trace_bpf_test_finish(&err); > + return err; > +} > + > static void *bpf_ctx_init(const union bpf_attr *kattr, u32 max_size) > { > void __user *data_in = u64_to_user_ptr(kattr->test.ctx_in); [...]