Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3882094ybf; Tue, 3 Mar 2020 14:59:13 -0800 (PST) X-Google-Smtp-Source: ADFU+vuHjLaLXGxI/eisrYBqQZhAmOTFuLAMps35Mgs3Jc/1K2S7wyTP7P9V+CEK1WLXIznz/wFz X-Received: by 2002:a9d:6f14:: with SMTP id n20mr58375otq.271.1583276353552; Tue, 03 Mar 2020 14:59:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583276353; cv=none; d=google.com; s=arc-20160816; b=fxPLeASk3C03bMRUpL0EtuRnHa6QhP5WKaR64ddRkGpUtXo7v2T7zKXU05Rg+HO20J U6NGkmBjSJty7NETnI+b8LhqaYZkDyMDGEaKDOe1U3Y8e0m2g2TQpMjBVFjWCOcGPPPc gs8U5qxBMn/PZ+LleRcF7b6uX41TJoMwdZ4mfYAA9JBqgAVHl02b7GaJkNqXfzFeL11k pMVr/iJyTMLgmWXewvcHwhDeOka0V5uK/7ZdN2w4/kJimggvrvhDlO3vgTfUxA3D+Qha bPSFPBoIiWTGyBTrK2S+zJIyLb6eOxWnFOi2HUMuLXI+jdAFkk0kKYPVL06japRRn6SH MhfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:date:from:dkim-signature; bh=54j0J9wFM5XCN2h3a4/n6MI0UxekhSzsh9zn+5s01fI=; b=tLYsdhfJeZDsOUm5Su7hAwhxK6OUz1Lo4vOi+CvIRFVc2FM7Jxybz7JXGz/sCmK0aF tH06Ncd/iGH+H2SHh5EfDhLaGXjGW19d/xyjn3H/0H5/WMq8jmnT1ARV2l5MaAxkssvP VIlkcNeJ37o3+9y+b69J7VMRe823/LMcbRPFsRh4YCzIGjUFLPppSaKkClnfpSfL+g7Q WWaGOjK4ogs0ciLtSYceSJ9TiVUlx+jBLnLaqVxAo9cs/muHBmChoSb2O/r6seqVjLNh CEut8RGf7hQryg1tm7qn0ER1gWkiSiS+dNDOZpmVTBqQzdyooA7dKPQPlWBZ+t1MhIxf dE9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="aMR1AfI/"; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d6si128687oig.49.2020.03.03.14.59.02; Tue, 03 Mar 2020 14:59:13 -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=@chromium.org header.s=google header.b="aMR1AfI/"; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727942AbgCCW5x (ORCPT + 99 others); Tue, 3 Mar 2020 17:57:53 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:40280 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727026AbgCCW5x (ORCPT ); Tue, 3 Mar 2020 17:57:53 -0500 Received: by mail-wr1-f67.google.com with SMTP id r17so21564wrj.7 for ; Tue, 03 Mar 2020 14:57:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=54j0J9wFM5XCN2h3a4/n6MI0UxekhSzsh9zn+5s01fI=; b=aMR1AfI/uh9tcuspjHvQTh6bkMCuUpZ1gGxcEZb4DdaQj8Z1+R8/RSj8Qu9s3CGSKO yozHGQclqvRMEaxYv3ZoiKoa7KQ8UvwPMo0rCriaUASfrZq19+WIEtfcoOx7kJArWK+E qQpB1P3e4ZG6yD0MzEuhwLJc6FfqjJx8RueQE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=54j0J9wFM5XCN2h3a4/n6MI0UxekhSzsh9zn+5s01fI=; b=Yt9Vi84+smPbbF5Uevet6NxLP1a55PkUEhqqzpxOUljfbeejoSWgvQo5XDQmrB6S+4 Mez8nOXcNU9i/s0PtJ7ROwpGXoVd4eR0vTTJeWFGWFMfLRQpYfkGcGyH/IMpIJn4WB+7 nFYP2ETbu/wFHa4G64dk86w6sONqu5pFXB2zmcRuJw8Ia+b+oZGu6Y50UfI++IAikCu4 VixjLedV+KQU5gFNQQbYjZlyRzFyHlz9OtQ6+92L3Rj2LqmeC9ZkoA0dT9LhBMwccQyP H6dhIXzUjF774qiXXjwSmVzivCrKCYRsyQ5pGbCXD0JXe1vXgr+xUbkkVng5wHg0+HpB iFSA== X-Gm-Message-State: ANhLgQ2NQPalCl9IwGi9zneE7Dl8Y6/OCT5G0Vr9cu1VSxcA3wLTh1Rh k7pkMBgjvQZF/geT0RyovI20wA== X-Received: by 2002:a05:6000:104f:: with SMTP id c15mr265851wrx.376.1583276270414; Tue, 03 Mar 2020 14:57:50 -0800 (PST) Received: from chromium.org (77-56-209-237.dclient.hispeed.ch. [77.56.209.237]) by smtp.gmail.com with ESMTPSA id j205sm902562wma.42.2020.03.03.14.57.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 14:57:49 -0800 (PST) From: KP Singh X-Google-Original-From: KP Singh Date: Tue, 3 Mar 2020 23:57:48 +0100 To: Andrii Nakryiko Cc: open list , bpf , Alexei Starovoitov , Daniel Borkmann , Paul Turner , Florent Revest , Brendan Jackman Subject: Re: [PATCH bpf-next 6/7] bpf: Add test ops for BPF_PROG_TYPE_TRACING Message-ID: <20200303225748.GA14735@chromium.org> References: <20200303140950.6355-1-kpsingh@chromium.org> <20200303140950.6355-7-kpsingh@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03-M?r 14:51, Andrii Nakryiko wrote: > 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? Oops :) Fixed. Thanks! Artifacts of renaming. > > > > > Also, clean up the fexit test to use the generated skeleton. > > > > Signed-off-by: KP Singh > > --- > > Nice clean up for fexit_test, thank you! It was very satisfying :) > > > 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? Ah yes, we trace it not ony for erroneous cases. Changed it to setting err = 0 and falling through to the trace_bpf_test_finish. - KP > > > + > > + 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); > > [...]