Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1947914pxb; Mon, 18 Jan 2021 04:25:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJybAKUltXD7rx/iYXM6wDmrrZFwhFb1nhbRhTkuaSfEjeRC1q+LBCtiTA8d7bC+1QXwDhTh X-Received: by 2002:a17:906:1d0f:: with SMTP id n15mr16314674ejh.26.1610972717875; Mon, 18 Jan 2021 04:25:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610972717; cv=none; d=google.com; s=arc-20160816; b=cQ+qRf+h10NSeQMgQgKbzaFC03e/RUSCkF/2a4s0+QEZW0OSsLjAdMzQT2JujNvJsj mD2KTFoMlOALzN0DlGL90GU29wr5t7rtQfEeSjqWYE8FPabjHWGl5RtzDA3HMCtoleiS ERR8sa1msDPiXmP4tuGzm3Qz9UONfJP9c7FK06ymUzrt9ukhwvve6t0e/4U4jwR9q50E kS9uS6mn3kswaY1eHaQUR88uEs8eWPoTshSk9wdb7+JSJEZlq3Z+fOiLkeWPOW4U0n2U lagXcl8nDWV4bXlMllJneB9nw+qhDqSgnf8HciOW3MOM//dfB4Z+WjnHbpq/jTdxX00v /atA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=1aEoxcXP/1MlaCCSh2W+FKsC0EdlUgvbMWUUF6jvzKY=; b=yMwQ9csMX+bNdH7a26es1ZU2zhdWXZx6A75eF0Y6OK0Jp+szk1UB/iG0XPFym0CTjA EKKOHKT6tcU7lERL6G+kuVtsg/HZCOkhtV6t9Or8J3jF3jNwDIbwL4XYelkbrqKBPHez b0Er3lataoEWvNAB5boHJXRHuCUH61zig2YGpAxGVpm9O47RvyANe6kOXXbfenLXPcx4 NIPEynF3z8CCcfQcbeVG6hTpDV7vEIG85efuMgyoMynxbO3IP/9O9px3PGuqdxlM3NNk 20B4BWZTOoif8dFUPA+jGGbNOr7W2rCNxVOASeIUcjcCwmzFPd5f99bT5r6MwYN3B9vt TUFQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o9si5804100ejr.665.2021.01.18.04.24.54; Mon, 18 Jan 2021 04:25:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391432AbhARMWU (ORCPT + 99 others); Mon, 18 Jan 2021 07:22:20 -0500 Received: from foss.arm.com ([217.140.110.172]:34462 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391341AbhARMTI (ORCPT ); Mon, 18 Jan 2021 07:19:08 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1DBB031B; Mon, 18 Jan 2021 04:18:22 -0800 (PST) Received: from e107158-lin (unknown [10.1.194.78]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DCF403F719; Mon, 18 Jan 2021 04:18:20 -0800 (PST) Date: Mon, 18 Jan 2021 12:18:18 +0000 From: Qais Yousef To: Yonghong Song Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Steven Rostedt , "Peter Zijlstra (Intel)" , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 bpf-next 2/2] selftests: bpf: Add a new test for bare tracepoints Message-ID: <20210118121818.muifeogh4hvakfeb@e107158-lin> References: <20210116182133.2286884-1-qais.yousef@arm.com> <20210116182133.2286884-3-qais.yousef@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/16/21 18:11, Yonghong Song wrote: > > > On 1/16/21 10:21 AM, Qais Yousef wrote: > > Reuse module_attach infrastructure to add a new bare tracepoint to check > > we can attach to it as a raw tracepoint. > > > > Signed-off-by: Qais Yousef > > --- > > .../bpf/bpf_testmod/bpf_testmod-events.h | 6 +++++ > > .../selftests/bpf/bpf_testmod/bpf_testmod.c | 21 ++++++++++++++- > > .../selftests/bpf/bpf_testmod/bpf_testmod.h | 6 +++++ > > .../selftests/bpf/prog_tests/module_attach.c | 27 +++++++++++++++++++ > > .../selftests/bpf/progs/test_module_attach.c | 10 +++++++ > > 5 files changed, 69 insertions(+), 1 deletion(-) > > > > diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h > > index b83ea448bc79..89c6d58e5dd6 100644 > > --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h > > +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h > > @@ -28,6 +28,12 @@ TRACE_EVENT(bpf_testmod_test_read, > > __entry->pid, __entry->comm, __entry->off, __entry->len) > > ); > > +/* A bare tracepoint with no event associated with it */ > > +DECLARE_TRACE(bpf_testmod_test_write_bare, > > + TP_PROTO(struct task_struct *task, struct bpf_testmod_test_write_ctx *ctx), > > + TP_ARGS(task, ctx) > > +); > > + > > #endif /* _BPF_TESTMOD_EVENTS_H */ > > #undef TRACE_INCLUDE_PATH > > diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c > > index 2df19d73ca49..e900adad2276 100644 > > --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c > > +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c > > @@ -28,9 +28,28 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj, > > EXPORT_SYMBOL(bpf_testmod_test_read); > > ALLOW_ERROR_INJECTION(bpf_testmod_test_read, ERRNO); > > +noinline ssize_t > > +bpf_testmod_test_write(struct file *file, struct kobject *kobj, > > + struct bin_attribute *bin_attr, > > + char *buf, loff_t off, size_t len) > > +{ > > + struct bpf_testmod_test_write_ctx ctx = { > > + .buf = buf, > > + .off = off, > > + .len = len, > > + }; > > + > > + trace_bpf_testmod_test_write_bare(current, &ctx); > > + > > + return -EIO; /* always fail */ > > +} > > +EXPORT_SYMBOL(bpf_testmod_test_write); > > +ALLOW_ERROR_INJECTION(bpf_testmod_test_write, ERRNO); > > + > > static struct bin_attribute bin_attr_bpf_testmod_file __ro_after_init = { > > Do we need to remove __ro_after_init? I don't think so. The structure should still remain RO AFAIU. > > > - .attr = { .name = "bpf_testmod", .mode = 0444, }, > > + .attr = { .name = "bpf_testmod", .mode = 0666, }, > > .read = bpf_testmod_test_read, > > + .write = bpf_testmod_test_write, > > }; > > static int bpf_testmod_init(void) > > diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.h b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.h > > index b81adfedb4f6..b3892dc40111 100644 > > --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.h > > +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.h > > @@ -11,4 +11,10 @@ struct bpf_testmod_test_read_ctx { > > size_t len; > > }; > > +struct bpf_testmod_test_write_ctx { > > + char *buf; > > + loff_t off; > > + size_t len; > > +}; > > + > > #endif /* _BPF_TESTMOD_H */ > > diff --git a/tools/testing/selftests/bpf/prog_tests/module_attach.c b/tools/testing/selftests/bpf/prog_tests/module_attach.c > > index 50796b651f72..e4605c0b5af1 100644 > > --- a/tools/testing/selftests/bpf/prog_tests/module_attach.c > > +++ b/tools/testing/selftests/bpf/prog_tests/module_attach.c > > @@ -21,9 +21,34 @@ static int trigger_module_test_read(int read_sz) > > return 0; > > } > > +static int trigger_module_test_write(int write_sz) > > +{ > > + int fd, err; > > Init err = 0? I don't see what difference this makes. > > > + char *buf = malloc(write_sz); > > + > > + if (!buf) > > + return -ENOMEM; > > Looks like we already non-negative value, so return ENOMEM? We already set err=-errno. So shouldn't we return negative too? > > > + > > + memset(buf, 'a', write_sz); > > + buf[write_sz-1] = '\0'; > > + > > + fd = open("/sys/kernel/bpf_testmod", O_WRONLY); > > + err = -errno; > > + if (CHECK(fd < 0, "testmod_file_open", "failed: %d\n", err)) > > + goto out; > > Change the above to > fd = open("/sys/kernel/bpf_testmod", O_WRONLY); > if (CHECK(fd < 0, "testmod_file_open", "failed: %d\n", errno)) { > err = -errno; > goto out; > } I kept the code consistent with the definition of trigger_module_test_read(). I'll leave it up to the maintainer to pick up the style changes if they prefer it this way. Thanks for the ack and for the review. Cheers -- Qais Yousef