Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5754941ybv; Tue, 18 Feb 2020 03:21:02 -0800 (PST) X-Google-Smtp-Source: APXvYqwXgF/IlBojkoicxe7tf57Q1c81CC5nLPHg3pt1ehLztA3VNDCsSS67WWMKQI6sNYcuSMIX X-Received: by 2002:aca:cc07:: with SMTP id c7mr843324oig.165.1582024862313; Tue, 18 Feb 2020 03:21:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582024862; cv=none; d=google.com; s=arc-20160816; b=vFbaftG2IHSflceJMnCDp8Rpi1EpsRQPX78jljHyN19hEr30jlr0PvqTv4Fzlg0LoF HqJyzzZQpGElo421n6KsGL71UpXIx2NFUMAf0Pe0Hkl511TIDirxsKJVrDOISfrIpAMQ TabqMOUsWJ8gJNiOsWCDm/45XoCnLjHU7jLpo13TxBQYUANj+3iTUhbhuHQjB8+RfCIf YctpjcnXjuHn6wfzUVTu1R5sV6eZc04UwI/bNfZ0ldJx71puNkftTu4NLGR0JkRzO9GC 4RjHCwzlGh2mIIGm0R9C+KxDFFLLzLoNnvNaO/Lfb504mxuBaZtTUJq/eoRAzQdcQNaF RF8w== 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=F9b58Vs7WigMQN/b04m0vzggm1CyHSOGRSf6RFBXx+U=; b=RDRxRSxy1AiEwxXyGqzkui94wQqRiYdgvmwh7n9s+F9A5anH4EdnueRezz8otTTtvF vrexNO1FHy4B6C7NudyWdopFvvQyLjXbj1VXzcx3uxxCOfmjOh2AHS5JO6xMppdBr2qF aTrI66xcyD/ZtA7HAXnL4UBKonqOd+TjKciGmHGNT3R35I9wVTUy7wDKxZXgiu4rUoMi xpyJHS2KKaDdjH2/pu1BxUnsqQWofGOv4M/XUQvV1G0NqM9inJZVCtyzEUuPUhfJCP9p wkhnU2n5cx+SLmvpZEhdbSHYE664irkAA+ZhWIciPYBorHuYaTYN1eyaIgq2OXWMnDwA FqQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=HIZTip3W; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y8si7694677oih.141.2020.02.18.03.20.49; Tue, 18 Feb 2020 03:21:02 -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=pass header.i=@alien8.de header.s=dkim header.b=HIZTip3W; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726403AbgBRLUl (ORCPT + 99 others); Tue, 18 Feb 2020 06:20:41 -0500 Received: from mail.skyhub.de ([5.9.137.197]:37332 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726327AbgBRLUl (ORCPT ); Tue, 18 Feb 2020 06:20:41 -0500 Received: from zn.tnic (p200300EC2F0C1F003890503FBB74C433.dip0.t-ipconnect.de [IPv6:2003:ec:2f0c:1f00:3890:503f:bb74:c433]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 483481EC072D; Tue, 18 Feb 2020 12:20:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1582024839; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=F9b58Vs7WigMQN/b04m0vzggm1CyHSOGRSf6RFBXx+U=; b=HIZTip3WL05+D8tbjM80/64EFa7mk5nAAq5XOpnMDSiJKwZPyGmwUmKatmvdvd9SActxwR MzRcbjp79rVQ+frWosNP4r+s5/khlx46v+Y2uJKBQ68Pafvt00qFvShKdierfzAs6IFwxj h1nT9PeSDsIgI7M3Y/Iw3Cx74z9SCa4= Date: Tue, 18 Feb 2020 12:20:35 +0100 From: Borislav Petkov To: Kim Phillips Cc: Peter Zijlstra , Ingo Molnar , Ingo Molnar , Alexander Shishkin , Andi Kleen , Arnaldo Carvalho de Melo , Babu Moger , Fenghua Yu , Frank van der Linden , "H . Peter Anvin" , Huang Rui , Janakarajan Natarajan , Jan Beulich , Jiaxun Yang , Jiri Olsa , Josh Poimboeuf , Linus Torvalds , Luwei Kang , Martin =?utf-8?B?TGnFoWth?= , Matt Fleming , Michael Petlan , Namhyung Kim , Paolo Bonzini , Pawan Gupta , Suravee Suthikulpanit , Thomas Gleixner , Tom Lendacky , x86@kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v3] x86/cpu/amd: Enable the fixed Instructions Retired counter IRPERF Message-ID: <20200218112035.GB14449@zn.tnic> References: <20200214201805.13830-1-kim.phillips@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200214201805.13830-1-kim.phillips@amd.com> 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 Fri, Feb 14, 2020 at 02:18:05PM -0600, Kim Phillips wrote: > diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h > index f3327cb56edf..8979d6fcc79c 100644 > --- a/arch/x86/include/asm/cpufeatures.h > +++ b/arch/x86/include/asm/cpufeatures.h > @@ -404,5 +404,6 @@ > #define X86_BUG_SWAPGS X86_BUG(21) /* CPU is affected by speculation through SWAPGS */ > #define X86_BUG_TAA X86_BUG(22) /* CPU is affected by TSX Async Abort(TAA) */ > #define X86_BUG_ITLB_MULTIHIT X86_BUG(23) /* CPU may incur MCE during certain page attribute changes */ > +#define X86_BUG_IRPERF X86_BUG(24) /* CPU is affected by Instructions Retired counter Erratum 1054 */ Do you need this bug flag at all? If the only reason for its existence is to check it before setting the MSR bit enabling IRPERF, then you don't need it. Or is there any particular reason why it should show in /proc/cpuinfo? IOW, does this work too? --- diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index 8821697a7549..12c9684d59ba 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -521,6 +521,8 @@ #define MSR_K7_HWCR 0xc0010015 #define MSR_K7_HWCR_SMMLOCK_BIT 0 #define MSR_K7_HWCR_SMMLOCK BIT_ULL(MSR_K7_HWCR_SMMLOCK_BIT) +#define MSR_K7_HWCR_IRPERF_EN_BIT 30 +#define MSR_K7_HWCR_IRPERF_EN BIT_ULL(MSR_K7_HWCR_IRPERF_EN_BIT) #define MSR_K7_FID_VID_CTL 0xc0010041 #define MSR_K7_FID_VID_STATUS 0xc0010042 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index ac83a0fef628..1f875fbe1384 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -28,6 +28,7 @@ static const int amd_erratum_383[]; static const int amd_erratum_400[]; +static const int amd_erratum_1054[]; static bool cpu_has_amd_erratum(struct cpuinfo_x86 *cpu, const int *erratum); /* @@ -972,6 +973,15 @@ static void init_amd(struct cpuinfo_x86 *c) /* AMD CPUs don't reset SS attributes on SYSRET, Xen does. */ if (!cpu_has(c, X86_FEATURE_XENPV)) set_cpu_bug(c, X86_BUG_SYSRET_SS_ATTRS); + + /* + * Turn on the Instructions Retired free counter on machines not + * susceptible to erratum #1054 "Instructions Retired Performance + * Counter May Be Inaccurate". + */ + if (cpu_has(c, X86_FEATURE_IRPERF) && + !cpu_has_amd_erratum(c, amd_erratum_1054)) + msr_set_bit(MSR_K7_HWCR, MSR_K7_HWCR_IRPERF_EN_BIT); } #ifdef CONFIG_X86_32 @@ -1099,6 +1109,10 @@ static const int amd_erratum_400[] = static const int amd_erratum_383[] = AMD_OSVW_ERRATUM(3, AMD_MODEL_RANGE(0x10, 0, 0, 0xff, 0xf)); +/* #1054: Instructions Retired Performance Counter May Be Inaccurate */ +static const int amd_erratum_1054[] = + AMD_OSVW_ERRATUM(0, AMD_MODEL_RANGE(0x17, 0, 0, 0x2f, 0xf)); + static bool cpu_has_amd_erratum(struct cpuinfo_x86 *cpu, const int *erratum) { -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette