Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp6132611pxb; Mon, 14 Feb 2022 16:26:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJy02yEfLPoMQHqXpLx1ee1iwafA3/dZht+xdvVRw1Bh+dh9sBxTIM0w9VKJSd2FxtEML9to X-Received: by 2002:a17:907:868a:: with SMTP id qa10mr1053907ejc.540.1644884769186; Mon, 14 Feb 2022 16:26:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644884769; cv=none; d=google.com; s=arc-20160816; b=culqRZ7+pHuenTyKb7eKaWB+nHyAZBmbyzOLibIAR6U3J9qkKIF74v/0Ec5pyzuULN Cy8JeMldHRFyci18Ul85JXnQdrdQqzYn3ZIOz3fRurr77FeGXE89LMWd1lRYQ/iq4r3B 7RIniWca7KY1u+XXYOhbLUGDfFMozARE/Ys5Lmf/qbihuFVpti5Ts2GF5gbjgC0yXKdI WGkxNJlP0cTIaGzt+Qh2ByXifMO4QXU5RA8v+TrM9UlhIlnekTyi/W0EZIcq9CAiOdWt AXWrJ//TO4aHspoCQIcTPMuAE4BXLFbwwDxIC8EPxY8IHNos5x99joXNPpX8RhT0p7g3 EggA== 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:dkim-signature; bh=/Fr7ZDScBT1KC7deV6GXyz7apXPDJ3KWx9+m9UgVrnM=; b=euAUT1S8d+x4EAFsSehHEtAorYxVnLgsprWuA9heWUP///aqL9CMEEGc+Fy8BsFGAv oo7o37CMm1Eg5wYzwNCcSQRjIkSAlun4RexGdAjM+24lpiuWs+fMcSTOzGb7U4gNaS70 tA+WquKaw5V33XeZG2g7FrApYUFCBFc4Fu7qcGMiuzUrSyVH3sk5392qMOoEA8oAGfC1 zyXB9MNbfT/lLfKDmWq8h6a7gRO3fP0IhlnPLItezVKkCdYnj/2rAtekWJWgx88NqxMX V1QQ5onCnTnyND2741A7PKg3v3TsUuN9dPv0B+ceLFePxslV+D7boUghzVStx0T4PUE3 KOCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Mi+rZCUt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v4si17289879edc.51.2022.02.14.16.25.46; Mon, 14 Feb 2022 16:26:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Mi+rZCUt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232478AbiBOAU1 (ORCPT + 99 others); Mon, 14 Feb 2022 19:20:27 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:38206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229877AbiBOAU0 (ORCPT ); Mon, 14 Feb 2022 19:20:26 -0500 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5795212D211; Mon, 14 Feb 2022 16:20:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644884417; x=1676420417; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=/KbEyiRn/Aaf8BrULpR7QEC8uKrRfLRRrv92U0AAhQQ=; b=Mi+rZCUtPqVd1wpC4ajwH3hIAkqH8vpkDKo3me02wqcaMcctGY1Ur/9m iiIZS6NXrxdi7vWPVZZorUFQCa5bVnIM0NrdCGto/9RAyaYfLlKzQzRjK jySeus5mZCb8FPb40H7j5Vt5TJ2OvqOg6IR2gsboir3wKa0oXbwVBbc8T AXKRvdytkIm2mGW7JzR/rG7+FHTmuln4Is7l7EMkdxk3HQJJ3IZA38KwN vowikLE/U6iNxQlDjyx8aoiq/DwPEeD0pXvqpa/TSfvcqmZhUcAZCch6s ZWS1b+oWEyr0gqT/m1eG/WCpdQtiNxA+MfCv5VnE3EPos+/IA77N0RLs7 w==; X-IronPort-AV: E=McAfee;i="6200,9189,10258"; a="310952320" X-IronPort-AV: E=Sophos;i="5.88,368,1635231600"; d="scan'208";a="310952320" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Feb 2022 16:20:17 -0800 X-IronPort-AV: E=Sophos;i="5.88,368,1635231600"; d="scan'208";a="496435214" Received: from guptapa-mobl1.amr.corp.intel.com ([10.212.244.212]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Feb 2022 16:20:16 -0800 Date: Mon, 14 Feb 2022 16:20:14 -0800 From: Pawan Gupta To: Borislav Petkov Cc: Thomas Gleixner , Ingo Molnar , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andi Kleen , Tony Luck , linux-kernel@vger.kernel.org, antonio.gomez.iglesias@linux.intel.com, neelima.krishnan@intel.com, stable@vger.kernel.org Subject: Re: [PATCH] x86/tsx: Use MSR_TSX_CTRL to clear CPUID bits Message-ID: <20220215002014.mb7g4y3hfefmyozx@guptapa-mobl1.amr.corp.intel.com> References: <5bd785a1d6ea0b572250add0c6617b4504bc24d1.1644440311.git.pawan.kumar.gupta@linux.intel.com> <20220214224121.ilhu23cfjdyhvahk@guptapa-mobl1.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 15.02.2022 00:28, Borislav Petkov wrote: >On Mon, Feb 14, 2022 at 02:41:21PM -0800, Pawan Gupta wrote: >> X86_FEATURE_RTM_ALWAYS_ABORT is the precondition for >> MSR_TFA_TSX_CPUID_CLEAR bit to exist. For current callers of >> tsx_clear_cpuid() this condition is met, and test for >> X86_FEATURE_RTM_ALWAYS_ABORT can be removed. But, all the future callers >> must also have this check, otherwise the MSR write will fault. > >I meant something like this (completely untested): > >diff --git a/arch/x86/kernel/cpu/tsx.c b/arch/x86/kernel/cpu/tsx.c >index c2343ea911e8..9d08a6b1726a 100644 >--- a/arch/x86/kernel/cpu/tsx.c >+++ b/arch/x86/kernel/cpu/tsx.c >@@ -84,7 +84,7 @@ static enum tsx_ctrl_states x86_get_tsx_auto_mode(void) > return TSX_CTRL_ENABLE; > } > >-void tsx_clear_cpuid(void) >+bool tsx_clear_cpuid(void) > { > u64 msr; > >@@ -97,11 +97,14 @@ void tsx_clear_cpuid(void) > rdmsrl(MSR_TSX_FORCE_ABORT, msr); > msr |= MSR_TFA_TSX_CPUID_CLEAR; > wrmsrl(MSR_TSX_FORCE_ABORT, msr); >+ return true; > } else if (tsx_ctrl_is_supported()) { > rdmsrl(MSR_IA32_TSX_CTRL, msr); > msr |= TSX_CTRL_CPUID_CLEAR; > wrmsrl(MSR_IA32_TSX_CTRL, msr); This will clear TSX CPUID when X86_FEATURE_RTM_ALWAYS_ABORT=0 also, because ... >+ return true; > } >+ return false; > } > > void __init tsx_init(void) >@@ -114,9 +117,8 @@ void __init tsx_init(void) > * RTM_ALWAYS_ABORT is set. In this case, it is better not to enumerate > * CPUID.RTM and CPUID.HLE bits. Clear them here. > */ >- if (boot_cpu_has(X86_FEATURE_RTM_ALWAYS_ABORT)) { >+ if (tsx_clear_cpuid()) { ... we are calling tsx_clear_cpuid() unconditionally. > tsx_ctrl_state = TSX_CTRL_RTM_ALWAYS_ABORT; >- tsx_clear_cpuid(); > setup_clear_cpu_cap(X86_FEATURE_RTM); > setup_clear_cpu_cap(X86_FEATURE_HLE); > return; > >--- > >but I'm guessing TSX should be disabled by default during boot only when >X86_FEATURE_RTM_ALWAYS_ABORT is set. That is correct. >If those CPUs which support only disabling TSX through MSR_IA32_TSX_CTRL >but don't have MSR_TSX_FORCE_ABORT - if those CPUs set >X86_FEATURE_RTM_ALWAYS_ABORT too, then this should work. > >> There are certain cases where this will leave the system in an >> inconsistent state, for example smt toggle after a late microcode update > >What is a "smt toggle"? Sorry, I should have been more clear. I meant: # echo off > /sys/devices/system/cpu/smt/control # echo on > /sys/devices/system/cpu/smt/control >You mean late microcode update and then offlining and onlining all >logical CPUs except the BSP which would re-detect CPUID features? That could also be the problematic case. >> that adds CPUID.RTM_ALWAYS_ABORT=1. During an smt toggle, if we >> unconditionally clear CPUID.RTM and CPUID.HLE in init_intel(), half of >> the CPUs will report TSX feature and other half will not. > >That is important and should be documented. Something like this perhaps: > >--- > >diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c >index 8321c43554a1..6c7bca9d6f2e 100644 >--- a/arch/x86/kernel/cpu/intel.c >+++ b/arch/x86/kernel/cpu/intel.c >@@ -722,6 +722,13 @@ static void init_intel(struct cpuinfo_x86 *c) > else if (tsx_ctrl_state == TSX_CTRL_DISABLE) > tsx_disable(); > else if (tsx_ctrl_state == TSX_CTRL_RTM_ALWAYS_ABORT) >+ /* >+ * This call doesn't clear RTM and HLE X86_FEATURE bits because >+ * a late microcode reload adding MSR_TSX_FORCE_ABORT can cause >+ * for those bits to get cleared - something which the kernel >+ * cannot do due to userspace potentially already using said >+ * features. >+ */ > tsx_clear_cpuid(); Thanks, I will add this comment in the next revision. Pawan