Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp552079ybl; Wed, 4 Dec 2019 07:09:29 -0800 (PST) X-Google-Smtp-Source: APXvYqz/NY3BbBinJOi00Knw1z6/BOu3K+4lMLmX/MdT5W/rFg+KtKM69diHeXZmDhbHm1TRHu3A X-Received: by 2002:aca:3285:: with SMTP id y127mr3008717oiy.67.1575472169762; Wed, 04 Dec 2019 07:09:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575472169; cv=none; d=google.com; s=arc-20160816; b=rp5bec1KpIBNEW6KwVQvT5PC6IOTuz+g0Dz0tDblAPbM5HTzuNpcjmvhGo5P5nH5qh yXiQ+MZSCcs3LviRPe87ursYzVRcrzzkco48jMnzwqEhao5fEwCkCqPFNO2i9bMO5TGs 6Mbh+RN2KimBw6WTx+V7NV+V/CqtjSV1E0AafgGgDlWdT+WTrQrEsXSxH2PKNCLHilPR jAIFwv7hFeqXD5BqWLuUGDcsQaKSKOTEQsFIGVuUeCuYJjS04YcY7WB4TZ041kLWeh1p gBX/4t7Qf3PWQBB59TSACz2iV1bXjR60mmwxhAFO1ad0Eo4ipAO+0c48XjObD8K5WACO C5Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=g3e9W5kaQL4X6POWuUMSB5OUbgOG6BaH8RhCg7ksu7E=; b=Z7w+gkbR3YyLetlPLRjImrezZ+DxIJEbaU9XLhwoJGH+KugAtnXd8/1U1Ch5vi/Dxl 0baRGZS3SaPcL3M56Pn2ui9e5tNMTlYK2yxcA6egjYRhobE/ly/2Cvx4yaPMGHnfSd+j WSNscDwK6MLeihq/pcz7IyGqLa98FNqhClcD2L2ggn0jQj5AZ8PqP2nsoQpzrrlXHoce ZSmTnT548zlQgSz9+6gwXf/0bj9ICr4cmDUFcEaQEb2wtdNMLlVZSs60HMdeHMy2iAKp 4UWCnimhduySDpO9TYUiJepx8tggc80DBK9ejp1co4hT/ZiyRlFr6IoTdjnWgO50O2Ah t2BQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=G+0VNTJL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x7si3137005oto.264.2019.12.04.07.09.14; Wed, 04 Dec 2019 07:09:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=G+0VNTJL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728078AbfLDPHH (ORCPT + 99 others); Wed, 4 Dec 2019 10:07:07 -0500 Received: from merlin.infradead.org ([205.233.59.134]:33632 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727828AbfLDPHH (ORCPT ); Wed, 4 Dec 2019 10:07:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=g3e9W5kaQL4X6POWuUMSB5OUbgOG6BaH8RhCg7ksu7E=; b=G+0VNTJL1IffH54gxlIhQw3MP +UPucQ9kT9oBQR8uwzaeA0iHbZ/fHGtv+u/NJDW9suAOgYrNxrPdpPi9b68fxunV2/J8mN5VPBCVs ox3QSjQAvTAUZA3bVnEJpM+82rpJLQ1KVLlowBQ9yGzo7ydmkvwxivhlkDDo1/L1bK6Rt1AIN1lGi CznjcMGGQu5vdFXs89RmhL9pdaZpZoCJEiXmVr40WW2J0mHcW8n/OidP6cMoHF5hKpzlXcfwhleUu HafFf8t5y8KO8CPeRp1K+frA4AUyBq6hLFqcjoIjLF88jK9mUStJYwp/6HYvVAJ3OyJ16DhnNI6u8 Uuv4cIH8A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1icWF0-0001Ur-Tv; Wed, 04 Dec 2019 15:06:59 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 6B9E5301A6C; Wed, 4 Dec 2019 16:05:39 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 1597220D1A240; Wed, 4 Dec 2019 16:06:56 +0100 (CET) Date: Wed, 4 Dec 2019 16:06:56 +0100 From: Peter Zijlstra To: Jiri Olsa Cc: Meelis Roos , LKML , x86@kernel.org, Arnaldo Carvalho de Melo , Jiri Olsa , Ingo Molnar , Mark Rutland Subject: Re: UBSAN: Undefined behaviour in arch/x86/events/intel/p6.c:116:29 Message-ID: <20191204150656.GX2844@hirez.programming.kicks-ass.net> References: <02f44ed5-13ac-f9c6-1f35-129c41006900@linux.ee> <20191202170633.GN2844@hirez.programming.kicks-ass.net> <0676c6ec-4475-62dc-b202-a62deaedd2dd@linux.ee> <20191204121540.GE20746@krava> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191204121540.GE20746@krava> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 = 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); /* 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;