Re: UBSAN: Undefined behaviour in arch/x86/events/intel/p6.c:116:29

From: Peter Zijlstra
Date: Wed Dec 04 2019 - 10:44:32 EST


On Wed, Dec 04, 2019 at 04:24:44PM +0100, Jiri Olsa wrote:

> > diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
> > index 9a89d98c55bd..f17417644665 100644
> > --- a/arch/x86/events/core.c
> > +++ b/arch/x86/events/core.c
> > @@ -1642,9 +1643,12 @@ static struct attribute_group x86_pmu_format_group __ro_after_init = {
> >
> > ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr, char *page)
> > {
> > - struct perf_pmu_events_attr *pmu_attr = \
> > + struct perf_pmu_events_attr *pmu_attr =
>
> ugh, did this do something weird? ;-)

No, but it's weird to explicitly concat the line outside of a macro, so
if 'fixed' it.

> > container_of(attr, struct perf_pmu_events_attr, attr);
> > - u64 config = x86_pmu.event_map(pmu_attr->id);
> > + u64 config = 0;
> > +
> > + if (pmu_attr->id < x86_pmu.max_events)
> > + x86_pmu.event_map(pmu_attr->id);
>
> hum, should this be assigned to config?
>
> config = x86_pmu.event_map(pmu_attr->id);

D'oh... Yes.

> >
> > /* string trumps id */
> > if (pmu_attr->event_str)