mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Daniel Xu" <dxu@dxuuu.xyz>
To: "Daniel Borkmann" <daniel@iogearbox.net>, <bpf@vger.kernel.org>,
	<ast@kernel.org>, <songliubraving@fb.com>, <yhs@fb.com>,
	<andriin@fb.com>
Cc: <linux-kernel@vger.kernel.org>, <kernel-team@fb.com>,
	<peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>
Subject: Re: [PATCH v6 bpf-next 1/2] bpf: Add bpf_read_branch_records() helper
Date: Mon, 27 Jan 2020 11:01:08 -0800	[thread overview]
Message-ID: <C06T0N0N8TD7.1MBJSGUZDFW0A@dlxu-fedora-R90QNFJV> (raw)
In-Reply-To: <a026ad0c-7d24-09cc-9742-c241d37fbdb0@iogearbox.net>

On Mon Jan 27, 2020 at 1:26 PM, Daniel Borkmann wrote:
[...]
> > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
> > index f1d74a2bd234..332aa433d045 100644
> > --- a/include/uapi/linux/bpf.h
> > +++ b/include/uapi/linux/bpf.h
> > @@ -2892,6 +2892,25 @@ union bpf_attr {
> >    *		Obtain the 64bit jiffies
> >    *	Return
> >    *		The 64 bit jiffies
> > + *
> > + * int bpf_read_branch_records(struct bpf_perf_event_data *ctx, void *buf, u32 buf_size, u64 flags)
>
> 
> Small nit: s/buf_size/size/, so that it matches with your BPF_CALL
> below.

Ok

> 
> +BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *,
> ctx,
> + void *, buf, u32, size, u64, flags)
>
> 
> > + *	Description
> > + *		For an eBPF program attached to a perf event, retrieve the
> > + *		branch records (struct perf_branch_entry) associated to *ctx*
> > + *		and store it in	the buffer pointed by *buf* up to size
> > + *		*buf_size* bytes.
> > + *
> > + *		The *flags* can be set to **BPF_F_GET_BRANCH_RECORDS_SIZE** to
> > + *		instead	return the number of bytes required to store all the
> > + *		branch entries. If this flag is set, *buf* may be NULL.
> > + *	Return
> > + *		On success, number of bytes written to *buf*. On error, a
> > + *		negative value.
>
> 
> Maybe pull the 2nd paragraph from above in here so that it reflects the
> description
> of the return value when flag is used also for this case in the 'Return'
> description.

Ok.

[...]
> >   
> > +BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,
> > +	   void *, buf, u32, size, u64, flags)
> > +{
> > +#ifndef CONFIG_X86
> > +	return -ENOENT;
> > +#else
> > +	struct perf_branch_stack *br_stack = ctx->data->br_stack;
> > +	u32 br_entry_size = sizeof(struct perf_branch_entry);
>
> 
> 'static const u32 br_entry_size' if we use it as such below.

Ok

>
> 
> > +	u32 to_copy;
> > +
> > +	if (unlikely(flags & ~BPF_F_GET_BRANCH_RECORDS_SIZE))
> > +		return -EINVAL;
> > +
> > +	if (unlikely(!br_stack))
> > +		return -EINVAL;
>
> 
> Why the ifdef X86? In previous thread I meant to change it into since
> it's
> implicit:
>
> 
> if (unlikely(!br_stack))
> return -ENOENT;
>
> 
> Or is there any other additional rationale?

Yeah, so br_stack can be null if the perf_event is misconfigured (branch
record not enabled). So we need to differentiate that from arch not
supporting it.

[...]


Thanks,
Daniel

  reply	other threads:[~2020-01-27 19:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-26 23:35 [PATCH v6 bpf-next 0/2] " Daniel Xu
2020-01-26 23:35 ` [PATCH v6 bpf-next 1/2] bpf: " Daniel Xu
2020-01-27 12:26   ` Daniel Borkmann
2020-01-27 19:01     ` Daniel Xu [this message]
2020-01-26 23:35 ` [PATCH v6 bpf-next 2/2] selftests/bpf: add bpf_read_branch_records() selftest Daniel Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=C06T0N0N8TD7.1MBJSGUZDFW0A@dlxu-fedora-R90QNFJV \
    --to=dxu@dxuuu.xyz \
    --cc=acme@kernel.org \
    --cc=andriin@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®