Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp947373pxj; Fri, 11 Jun 2021 16:23:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQEaopEtFOyZsurUhCmQb5x2ptV8oBybrfAEyfQMIK8IrrIqqtD1KUveHPRfAgX6VPstyW X-Received: by 2002:aa7:cf08:: with SMTP id a8mr6053399edy.6.1623453794635; Fri, 11 Jun 2021 16:23:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623453794; cv=none; d=google.com; s=arc-20160816; b=UpG1qByZ3/colyANmLkABHw7fYsN95QAxVP/pjM504SdXDdViAXBlCfCKrOMymL2Rr 6DPInwt/2SokENw6kFdvlW+nK1bml7/JT8quAKBL73c2oJJ80aEQbi97IjaYbHlxQGrC Dxp0RBJ7vXh6STI8EAuoE/FK1Zm447AviOn2DEPU9nofFXvq/+QSXD+y+2/ojjRyBOU3 CtluBFe6x2UHoEoLgMssF/KJUg2360FC2D368gFtLF45Tbd6JhqyPm52zsc1+i5/2kHw nAQqFi4LzJ7//DdGVCUjLkJz87aMf402Txz1fAaYtp1d+gBJItp++XSCu4m8CEc5W1V7 XJ6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:ironport-sdr :ironport-sdr; bh=Hc1nKylzw6llGdtrrz1WK1SOFqrLAMS1Osaf+uhEyD0=; b=vOHhkfrUX+EOuZbFUeVoKbadobvJ51AGDDLDdy49Ix323BBo681aeDIc5iinVYkum/ ZIuTMqEq5p11qDPnGwcHsvoNFZBm1xH3ILFalCyJoHErnyPac8dAjyvFFPHotXPDBr6U m7VvBf+ru1XVT5zJyr3u764JGvPMLVU/90x39zY1di8KuZUti88EIlny6oCZDGPwr8DX BeIvng3z0LPOIKvPBfIl9FI9TyzYD7It0OyFo0F+fqGgyYyCX208kSOp5er0zvJ0nqmE AS6qqKbqE9SQAtn7W42kE3z4WkALnuVcEIG6sdbQByubJ9xpJTWitwTbCcOpeToGjVRE LB7A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n14si6507623ejl.488.2021.06.11.16.22.51; Fri, 11 Jun 2021 16:23:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229976AbhFKXXF (ORCPT + 99 others); Fri, 11 Jun 2021 19:23:05 -0400 Received: from mga09.intel.com ([134.134.136.24]:5796 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229942AbhFKXXE (ORCPT ); Fri, 11 Jun 2021 19:23:04 -0400 IronPort-SDR: RIaAOYTLlaH703+eMTO/j+m+JIRy3DV8ZJfpj5oZyppsHHjpUqb+1sBC8guVUOaRQj8Jaz6057 lcUjrPMlpZMA== X-IronPort-AV: E=McAfee;i="6200,9189,10012"; a="205588712" X-IronPort-AV: E=Sophos;i="5.83,267,1616482800"; d="scan'208";a="205588712" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jun 2021 16:21:04 -0700 IronPort-SDR: H7VNDr3DD5lRcuC7dJ5j85CbKfebbPTI+qb7FD3EwErvtUnOdJjF/DA5OxJsTJF5H4cYF0pupB R98h9WCMznyA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,267,1616482800"; d="scan'208";a="477843656" Received: from gupta-dev2.jf.intel.com (HELO gupta-dev2.localdomain) ([10.54.74.119]) by FMSMGA003.fm.intel.com with ESMTP; 11 Jun 2021 16:21:03 -0700 Date: Fri, 11 Jun 2021 16:21:14 -0700 From: Pawan Gupta To: Borislav Petkov Cc: Thomas Gleixner , Jonathan Corbet , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , x86@kernel.org, "H. Peter Anvin" , "Paul E. McKenney" , Randy Dunlap , Andrew Morton , "Maciej W. Rozycki" , Viresh Kumar , Vlastimil Babka , Tony Luck , Paolo Bonzini , Sean Christopherson , Kyung Min Park , Fenghua Yu , Ricardo Neri , Tom Lendacky , Juergen Gross , Krish Sadhukhan , Kan Liang , Joerg Roedel , Victor Ding , Srinivas Pandruvada , Brijesh Singh , Dave Hansen , Mike Rapoport , Anthony Steinhauser , Anand K Mistry , Andi Kleen , Miguel Ojeda , Joe Perches , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: Re: [PATCH 2/4] perf/x86/intel: Do not deploy workaround when TSX is deprecated Message-ID: <20210611232114.3dmmkpkkcqg5orhw@gupta-dev2.localdomain> References: <4926973a8b0b2ed78217add01b5c459a92f0d511.1623272033.git-series.pawan.kumar.gupta@linux.intel.com> <20210611213443.ira5gc65jlafz7pu@gupta-dev2.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12.06.2021 00:01, Borislav Petkov wrote: >On Fri, Jun 11, 2021 at 02:34:43PM -0700, Pawan Gupta wrote: >> > > diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c >> > > index e28892270c58..b5953e1e59a2 100644 >> > > --- a/arch/x86/events/intel/core.c >> > > +++ b/arch/x86/events/intel/core.c >> > > @@ -6016,10 +6016,24 @@ __init int intel_pmu_init(void) >> > > intel_pmu_pebs_data_source_skl(pmem); >> > > >> > > if (boot_cpu_has(X86_FEATURE_TSX_FORCE_ABORT)) { >> > > - x86_pmu.flags |= PMU_FL_TFA; >> > > - x86_pmu.get_event_constraints = tfa_get_event_constraints; >> > > - x86_pmu.enable_all = intel_tfa_pmu_enable_all; >> > > - x86_pmu.commit_scheduling = intel_tfa_commit_scheduling; >> > > + u64 msr; >> > > + >> > > + rdmsrl(MSR_TSX_FORCE_ABORT, msr); >> > > + /* Systems that enumerate CPUID.RTM_ALWAYS_ABORT or >> > > + * support MSR_TSX_FORCE_ABORT[SDV_ENABLE_RTM] bit have >> > > + * TSX deprecated by default. TSX force abort hooks are >> > > + * not required on these systems. >> > >> > So if they're not required, why aren't you simply disabling the force >> > abort "workaround" by clearing the feature flag? >> >> Feature flag also enumerates MSR_TSX_FORCE_ABORT, which is still present >> after the microcode update. Patch 3/4 in this series clears the TSX >> CPUID bits using MSR_TSX_FORCE_ABORT. So we do need the feature flag >> X86_FEATURE_TSX_FORCE_ABORT. > >So it seems to me then, the if test above should be changed to: > > if (boot_cpu_has(X86_FEATURE_TSX_FORCE_ABORT) && > !boot_cpu_has(X86_FEATURE_RTM_ALWAYS_ABORT)) { > ... > >and no need for the MSR read. > >Please don't tell me there are configurations >where CPUID.RTM_ALWAYS_ABORT is clear but the >MSR_TSX_FORCE_ABORT[SDV_ENABLE_RTM] is there?! MSR_TSX_FORCE_ABORT[SDV_ENABLE_RTM]=1 actually clears CPUID.RTM_ALWAYS_ABORT, because in this case RTM is enabled and doesn't always aborts. As the code above is only executed at bootup and BIOS is not expected to set it. So at bootup SDV_ENABLE_RTM will be clear (if we ignore kexec) then yes, MSR read can avoided. > >This > >"A new CPUID bit CPUID.RTM_ALWAYS_ABORT (CPUID 7.EDX[11]) is added to >indicate the status of always abort behavior." > >tells me that the CPUID bit is always set by the microcode so we should >be ok. Yes, but MSR_TSX_FORCE_ABORT[SDV_ENABLE_RTM]=1 clears it. As SDV_ENABLE_RTM is expected to be set only by developers (e.g. using msr-tools), it should be fine in most other user cases. So we can avoid reading the MSR. > >If not, you should read that MSR early and do Isn't the MSR read early enough already: early_initcall() init_hw_perf_events() intel_pmu_init() MSR read Anyways, we can avoid reading the MSR completely and rely on CPUID.RTM_ALWAYS_ABORT. I will change it in the next version. Thanks, Pawan > > setup_force_cpu_cap(X86_FEATURE_RTM_ALWAYS_ABORT) > >so that this "always abort" flag is always set when TSX transactions are >always aborted.