Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2386920pxj; Mon, 10 May 2021 01:27:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0Q647gfJiLMJ5YA4vtvXFbNo6Z8qirWKefBZQxi4PhMphfvlqACUGfL5o9vqjL+vLkNOB X-Received: by 2002:a05:6e02:58f:: with SMTP id c15mr21780159ils.277.1620635249411; Mon, 10 May 2021 01:27:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620635249; cv=none; d=google.com; s=arc-20160816; b=ZIucqE9vZ6MsuaATeqCvgzsWfYcaP/JfbHAOv5sOFiAsOW6f+CnpEFR7rJfdji6e2p nZEgTW0lTZWfepuremfHvf0t9a9iSUFklol+0LiwMaKnP2GuBXnzfmh7PXinbAy1+GjJ Sq8MeJPF30WDwkzlCskGsSrWrG/QClyhMEZA9yF735G1pNBt2vskWBdHVzpHWoRgN/m7 cCAR9r3oabmYV/1ZWLsMnjXDlXhc2QOEjShrlIzdKJt9JbV/5kD2rdN2pCSlmC8wePY8 Kb5H5dCPfEt2swy64/ORuJCgUJGSFhRDt+EIOhIfuTR6KwrnlUmf4xn7yCO9KJ4EQKj0 6n1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=sWcIao3fyIb+rZwFq38FUEtAAU/boSjtt1gdDYbHnw8=; b=xzm0tpBuLX45RX1CkGzFoSH7zjgY19B/sq7kmzyUdQZY5/5RTE5r8tBSL0tAd0AmUx /k5JGzmVJrXF0cm+AaYWzy7vOGBb8Y4zOZhVYOD9xFeOURU9X4Y39GLAK+JK1wTY/6ZH awnclY/k3liNpAspib/Xe93Q1XMu7thqt7DppQ+jwuaL+64FezyY17zkf2ETIJqMr2Ob Bd3k8M4rQ0l1TCxhrDup3ibhG9FeMp6wsNtYw39UQ0htOpjuS0tauJifRE1gMfyaS5nk 4NANICeb7MpoiVGUmlrzKhnAb9M1O/Xb9kUb/GrNL6Ugs6bmKaVYJvbw7fZPCs9OyNnC zbog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MtASAx5a; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q4si15535129jas.111.2021.05.10.01.27.17; Mon, 10 May 2021 01:27:29 -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=@redhat.com header.s=mimecast20190719 header.b=MtASAx5a; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230185AbhEJI1o (ORCPT + 99 others); Mon, 10 May 2021 04:27:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53955 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230153AbhEJI1n (ORCPT ); Mon, 10 May 2021 04:27:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620635199; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sWcIao3fyIb+rZwFq38FUEtAAU/boSjtt1gdDYbHnw8=; b=MtASAx5aTcQogaeSsOjvgq0jMsD6ieZdf1LiEFPm+6u8qdVzIQumSjuCvs9yLkDC4PxrCe eVNMk3DiPLq7u36M/gnOyOXAHTZroFOy9yiXrPLVzS4acbQFNwWLzrGp2DsBFrQ0HcEM+p GK+qRMiSrjeTpOid+7ExWUhxZ1wDAXI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-248-618f1OB5MduTzUi6JbqDsg-1; Mon, 10 May 2021 04:26:37 -0400 X-MC-Unique: 618f1OB5MduTzUi6JbqDsg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3F6A01883520; Mon, 10 May 2021 08:26:36 +0000 (UTC) Received: from starship (unknown [10.40.194.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id F36B317253; Mon, 10 May 2021 08:26:32 +0000 (UTC) Message-ID: Subject: Re: [PATCH 11/15] KVM: VMX: Disable loading of TSX_CTRL MSR the more conventional way From: Maxim Levitsky To: Sean Christopherson , Paolo Bonzini Cc: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Xiaoyao Li , Reiji Watanabe Date: Mon, 10 May 2021 11:26:31 +0300 In-Reply-To: <20210504171734.1434054-12-seanjc@google.com> References: <20210504171734.1434054-1-seanjc@google.com> <20210504171734.1434054-12-seanjc@google.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2021-05-04 at 10:17 -0700, Sean Christopherson wrote: > 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); I also agree that commit message should be updated as Paolo said, but other than that: Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky