public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Meelis Roos <mroos@linux.ee>, LKML <linux-kernel@vger.kernel.org>,
	x86@kernel.org, Arnaldo Carvalho de Melo <acme@kernel.org>,
	Jiri Olsa <jolsa@kernel.org>, Ingo Molnar <mingo@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>
Subject: Re: UBSAN: Undefined behaviour in arch/x86/events/intel/p6.c:116:29
Date: Wed, 4 Dec 2019 16:24:44 +0100	[thread overview]
Message-ID: <20191204152444.GA15573@krava> (raw)
In-Reply-To: <20191204150656.GX2844@hirez.programming.kicks-ass.net>

On Wed, Dec 04, 2019 at 04:06:56PM +0100, Peter Zijlstra wrote:
> On Wed, Dec 04, 2019 at 01:15:40PM +0100, Jiri Olsa wrote:
> > On Tue, Dec 03, 2019 at 03:39:49PM +0200, Meelis Roos wrote:
> > > > Does something like so fix it?
> > > 
> > > Unfortunately not (tested on top of todays git):
> > 
> > hi,
> > which p6 model are you seeing this on?
> > how do you trigger that?
> 
> Triggers on any p6 model. I hacked up perf and used "qemu-system-x86_64
> -cpu pentium2".
> 
> The below seems to cure things.
> 
> ---
> 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? ;-)

>  		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);

jirka

>  
>  	/* string trumps id */
>  	if (pmu_attr->event_str)
> @@ -1713,6 +1717,9 @@ is_visible(struct kobject *kobj, struct attribute *attr, int idx)
>  {
>  	struct perf_pmu_events_attr *pmu_attr;
>  
> +	if (idx >= x86_pmu.max_events)
> +		return 0;
> +
>  	pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr.attr);
>  	/* str trumps id */
>  	return pmu_attr->event_str || x86_pmu.event_map(idx) ? attr->mode : 0;
> 


  reply	other threads:[~2019-12-04 15:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-26 17:55 UBSAN: Undefined behaviour in arch/x86/events/intel/p6.c:116:29 Meelis Roos
2019-12-02 17:06 ` Peter Zijlstra
2019-12-03 13:39   ` Meelis Roos
2019-12-04 12:15     ` Jiri Olsa
2019-12-04 15:06       ` Peter Zijlstra
2019-12-04 15:24         ` Jiri Olsa [this message]
2019-12-04 15:44           ` Peter Zijlstra
2019-12-04 19:47         ` Meelis Roos

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=20191204152444.GA15573@krava \
    --to=jolsa@redhat.com \
    --cc=acme@kernel.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@kernel.org \
    --cc=mroos@linux.ee \
    --cc=peterz@infradead.org \
    --cc=x86@kernel.org \
    /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