Re: [PATCH v6 3/3] perf/core: Clear the whole branch entry in perf_clear_branch_entry()

Puranjay Mohan <[email protected]>
Newsgroups org.kernel.vger.linux-perf-users,org.infradead.lists.linux-arm-kernel,org.kernel.vger.bpf,org.kernel.vger.linux-kernel
Message-ID <CANk7y0gxiQdKsGKrF2xhp5nS7Vc6zGBVVSb_US_x_Eb6vyZjhg@mail.gmail.com>
On Fri, Aug 7, 2026 at 11:29 AM Peter Zijlstra <[email protected]> wrote:
>
> On Thu, Aug 06, 2026 at 06:52:23AM -0700, Puranjay Mohan wrote:
> > perf_clear_branch_entry_bitfields() clears the bitfields of struct
> > perf_branch_entry one by one and leaves from/to alone, since callers
> > overwrite those straight away. The list has to be kept in sync with the
> > struct by hand and has already fallen behind: new_type and priv were
> > added to perf_branch_entry and never added here.
> >
> > Only BRBE writes those two, and neither is written for every record.
> > brbe_set_perf_entry_type() leaves new_type alone for a branch type it
> > does not recognise, and priv is not set for source-only records.
> > arm_pmuv3.c allocates the per-CPU branch stack with kmalloc(), so such a
> > record carries whatever the slot held: uninitialised kmalloc() data on
> > the first pass over the buffer, the previous record's values after that.
> > Both reach userspace through the branch stack. Nothing under
> > arch/x86/events/ writes either field, so x86 is unaffected.
> >
> > Clear the entry with a single struct assignment instead:
> >
> >       *br = (struct perf_branch_entry){ };
> >
> > The bitfields add up to exactly 64 bits, so there is no padding, and
> > every caller assigns from/to immediately afterwards, so zeroing those as
> > well changes nothing. PERF_BR_SPEC_NA is 0, so dropping the explicit
> > spec assignment leaves the behaviour unchanged. Nothing needs keeping in
> > sync when a field is added.
> >
> > The helper no longer touches only bitfields, so rename it to
> > perf_clear_branch_entry().
>
> Fair enough I suppose, but then why not write it like so?

Yes, that is better. I will use your version in v7.

Thanks,
Puranjay
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.