Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp3809379pxy; Tue, 4 May 2021 10:21:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyy2SpasQ/oBRHkb1fl5xqeDQReNdtm2FUgNbEiWQkiv+CjZOvn8sUmyAnkfGsYYRkSERDo X-Received: by 2002:a17:902:361:b029:e9:8392:7abd with SMTP id 88-20020a1709020361b02900e983927abdmr27202937pld.8.1620148917524; Tue, 04 May 2021 10:21:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620148917; cv=none; d=google.com; s=arc-20160816; b=DLOMxcDLRTI4zOKX6u98aQf2vVBcIEHT82XacwUEi9aAgmxxBSzoTR5sm+dnD4wM5B ++5B2SzS+jW8CRIA213WB5eBlDbMHryoW9jEayIpu0tHH7PhCei164DRXdSruTqwzHgR elGqllWnpoMF8u337y6CW+OB3at+Rik+yDcNnBogpWdo5/0B5LNW+k/+dPjmTRhwuJQQ AGPWAmcMnjU9oKHKjbMvAtk/nn8YTGOzHpYoEk/1QKvfnWgnTUzeiGscMiM3ftBgL68y XSHBcw+rdaNFN6na6HB3T20Da3P8jfcj7YiJ3h/ZPMS+kMhEdPTRpFOICMTbJ5sPVacV By5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:reply-to:dkim-signature; bh=OfxrzbCyayDhIsgc+QsgzNeUTDdIWPqYIy1TjIvLC5Y=; b=g+eIWMqm+6vm8DdywmkfpEBGrk9oza3d5iRLqUvrfme+Cd4P4xG8uxA5yjO83C2MLZ Zm9hArymIw1hl56QYg+GbjmSyfeA4f3fP1J5uWSiCJ0VxZpWRjQM9WqhJ1wAb+YjIVON vlXcx1cON6BwdFXiR+fHkUMQs/gvcoGtREz4Cyj4k2ZijFUoHzoFZhj+qxY5xLUYbkWc 6s6JvX4OdaVXn9MXZ7T4EB6rQoIjH7OfWpYg/vMrCLt7vsBlXwdMcY/gV79KjnSH9/H7 BlusQiQbzW4p9P/zPtL9GU6x3TGQJSE7N6nsgbUEdL8Nd/TGzN1VPk8rbvAW7Ol8THGK KBFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=QJ3Hkp2+; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bt4si3961203pjb.108.2021.05.04.10.21.44; Tue, 04 May 2021 10:21:57 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=QJ3Hkp2+; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231708AbhEDRTb (ORCPT + 99 others); Tue, 4 May 2021 13:19:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232250AbhEDRTF (ORCPT ); Tue, 4 May 2021 13:19:05 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28D0AC061761 for ; Tue, 4 May 2021 10:18:09 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id j3-20020ac874c30000b02901bab5879d6aso4023837qtr.0 for ; Tue, 04 May 2021 10:18:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=OfxrzbCyayDhIsgc+QsgzNeUTDdIWPqYIy1TjIvLC5Y=; b=QJ3Hkp2+Ym0T9YKmjqMWJvgu3kPTtTxOSvakW/z/eVcGcwWHYaOjwvTKYbuvwTfaIF qBwf/FVLAnsMogpo9M59vB2p0NsyV4Ho3A1HW2P/t2OxEG/jq4mYRrcyhj0FYG5nzu7T FDUlut38RLct/pFsq/vDamxiVrg6s1IQksMtj/5QnP9+OHZ3iOhoz7sN2sptcSpo0Izi V16YnJ9OrgXKaz7caMvCC41x4/+ajPUOJXU7tS8c2qbwLlONrJPEct8BUgsovVUTWCDm HB0FGx9dHdGIQGcxQ2EnOMoy3ZBUzhdNm6V5zjebIi1o3CHHh9F5vA6o+t/NyRG//dO/ GlIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=OfxrzbCyayDhIsgc+QsgzNeUTDdIWPqYIy1TjIvLC5Y=; b=mZiXmINaUGQTTcPyC7TGamsy+6JeQl6RovBXADT94ecuC1cPDvfmPK1eWieSJksJZ8 zdqFmahF5+1nrGqbL/1Vx1g3ZEWRJkEXbqyG98B3NaIHHXYxxMKVItef3ladyxSeh5aG hFCleqLeBsZA/pzmcUDxU1x2w0bSpkx8sGv8kDr4JqXoaNibJB13pb/71dH4s8HuzM/n dv+E9bFFzJIDs8GkKOyzXFWaNiTYy1mhxcXjxKtamwn/APgdAdz+j/BSqNNVaeMJrdL5 yK0+xzX/zYcKMKlu/KQVoQTeybijwh1QKE51st+p9hhHvtWcIsmTj7gnaqJJRjQQBJ9u /t0w== X-Gm-Message-State: AOAM531b2zhtYXbqZMYMfiBrNFAFGeEY/cFqvv8VHDvet1dDzF8xhzrS LXWVWg6l0cpjNDPkG6xVNy1hfzYBwKQ= X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:df57:48cb:ea33:a156]) (user=seanjc job=sendgmr) by 2002:a0c:bd2b:: with SMTP id m43mr26873037qvg.52.1620148688313; Tue, 04 May 2021 10:18:08 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 4 May 2021 10:17:30 -0700 In-Reply-To: <20210504171734.1434054-1-seanjc@google.com> Message-Id: <20210504171734.1434054-12-seanjc@google.com> Mime-Version: 1.0 References: <20210504171734.1434054-1-seanjc@google.com> X-Mailer: git-send-email 2.31.1.527.g47e6f16901-goog Subject: [PATCH 11/15] KVM: VMX: Disable loading of TSX_CTRL MSR the more conventional way From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Xiaoyao Li , Reiji Watanabe Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tag TSX_CTRL as not needing to be loaded when RTM isn't supported in the host. Crushing the write mask to '0' has the same effect, but requires more mental gymnastics to understand. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 4b432d2bbd06..7a53568b34fc 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1771,7 +1771,13 @@ static void setup_msrs(struct vcpu_vmx *vmx) guest_cpuid_has(&vmx->vcpu, X86_FEATURE_RDTSCP) || guest_cpuid_has(&vmx->vcpu, X86_FEATURE_RDPID)); - vmx_setup_uret_msr(vmx, MSR_IA32_TSX_CTRL, true); + /* + * hle=0, rtm=0, tsx_ctrl=1 can be found with some combinations of new + * kernel and old userspace. If those guests run on a tsx=off host, do + * allow guests to use TSX_CTRL, but don't change the value in hardware + * so that TSX remains always disabled. + */ + vmx_setup_uret_msr(vmx, MSR_IA32_TSX_CTRL, boot_cpu_has(X86_FEATURE_RTM)); if (cpu_has_vmx_msr_bitmap()) vmx_update_msr_bitmap(&vmx->vcpu); @@ -6919,23 +6925,15 @@ static int vmx_create_vcpu(struct kvm_vcpu *vcpu) vmx->guest_uret_msrs[i].data = 0; vmx->guest_uret_msrs[i].mask = -1ull; } - tsx_ctrl = vmx_find_uret_msr(vmx, MSR_IA32_TSX_CTRL); - if (tsx_ctrl) { + if (boot_cpu_has(X86_FEATURE_RTM)) { /* * TSX_CTRL_CPUID_CLEAR is handled in the CPUID interception. * Keep the host value unchanged to avoid changing CPUID bits * under the host kernel's feet. - * - * hle=0, rtm=0, tsx_ctrl=1 can be found with some combinations - * of new kernel and old userspace. If those guests run on a - * tsx=off host, do allow guests to use TSX_CTRL, but do not - * change the value on the host so that TSX remains always - * disabled. */ - if (boot_cpu_has(X86_FEATURE_RTM)) + tsx_ctrl = vmx_find_uret_msr(vmx, MSR_IA32_TSX_CTRL); + if (tsx_ctrl) vmx->guest_uret_msrs[i].mask = ~(u64)TSX_CTRL_CPUID_CLEAR; - else - vmx->guest_uret_msrs[i].mask = 0; } err = alloc_loaded_vmcs(&vmx->vmcs01); -- 2.31.1.527.g47e6f16901-goog