Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1885780pxv; Fri, 2 Jul 2021 15:09:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyflF1EpEw7oF6vXeYviTwQSPLJuGDKghEv8DO9HcXl0ytT42gDbqzknbl01D56ObAZvmJO X-Received: by 2002:a17:906:7012:: with SMTP id n18mr1950299ejj.236.1625263765780; Fri, 02 Jul 2021 15:09:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625263765; cv=none; d=google.com; s=arc-20160816; b=qJM0KWaNRHgIKxdoF2gDZ7oXrTPqDnPWYY8Od2LAc7OhVuvgAQxLaZUXrTcyISsKHg HCl1tcnJIybzNtQVxADPFMWGtYJCnf4z1YLbOGESNDpPs2y+fkc2rNT81VjVa96OV1Ek WF6M/+7hx5wFJ0sMxqtuYlWyepsEypP0MFxpunrkg2vjhRUQxxsY66I57fpNjAzyftCW PbHcu6OfS/8wOJF0TYjCJwUQ5lV8fJtWUha9VmD8z7CZUeOa2DaJklTV3PVdBuC8m1tW taSrCBvXawiPSVWOpEJk43cVMUC1mQkXxV+W2cDGRV6pQCtgm7ElAd7rL/BQ2HH9ArNK AqiQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=vWLLHvN5YVPSaIUdnvvnzZEcdiG2dS+shUgbzC0JM9k=; b=fFMlyjpJcJGNCNHqi80IQdZN2rQj8X7Wge41Xk0SK5IbaJKEGcdw2Cj5xCDXAMB/9S OHmW1IUfVwL4msh7VgsHyeryeLNpxg2ri8ehgWkDFIzwHcr9AqbZtKcvTMueEWEHqSZ3 m1KlvS9QPVMD0+2NcWwWBrqsH3Tl99HPsieSlVaKM/t9KEAocq9nz6NaIrrHGPbN7WRf idJylZmbw4XaS1V/WlJhpIxJzkDXm/wwfou47oEq7e1KcIczuaVRueadd7mZ6bCG8rGA N6S37jDJZMzF+X6iQueCdr02RnphZV1/Ic7R8JyhniFUYvRYbg6y95pnjmd56y7/i5rb gf9g== 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 gv11si4114647ejc.581.2021.07.02.15.09.03; Fri, 02 Jul 2021 15:09:25 -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 S234086AbhGBWKK (ORCPT + 99 others); Fri, 2 Jul 2021 18:10:10 -0400 Received: from mga12.intel.com ([192.55.52.136]:50197 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233134AbhGBWH6 (ORCPT ); Fri, 2 Jul 2021 18:07:58 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10033"; a="188472739" X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="188472739" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:25 -0700 X-IronPort-AV: E=Sophos;i="5.83,320,1616482800"; d="scan'208";a="642814777" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jul 2021 15:05:24 -0700 From: isaku.yamahata@intel.com To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , erdemaktas@google.com, Connor Kuehl , Sean Christopherson , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Sean Christopherson Subject: [RFC PATCH v2 32/69] KVM: x86: Allow host-initiated WRMSR to set X2APIC regardless of CPUID Date: Fri, 2 Jul 2021 15:04:38 -0700 Message-Id: <9b00cb86878e9986f47a0febce3c0d2872d91443.1625186503.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson Let userspace, or in the case of TDX, KVM itself, enable X2APIC even if X2APIC is not reported as supported in the guest's CPU model. KVM generally does not force specific ordering between ioctls(), e.g. this forces userspace to configure CPUID before MSRs. And for TDX, vCPUs will always run with X2APIC enabled, e.g. KVM will want/need to enable X2APIC from time zero. Signed-off-by: Sean Christopherson Signed-off-by: Isaku Yamahata --- arch/x86/kvm/x86.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3407870b6f44..c231a88d5946 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -437,8 +437,11 @@ int kvm_set_apic_base(struct kvm_vcpu *vcpu, struct msr_data *msr_info) { enum lapic_mode old_mode = kvm_get_apic_mode(vcpu); enum lapic_mode new_mode = kvm_apic_mode(msr_info->data); - u64 reserved_bits = kvm_vcpu_reserved_gpa_bits_raw(vcpu) | 0x2ff | - (guest_cpuid_has(vcpu, X86_FEATURE_X2APIC) ? 0 : X2APIC_ENABLE); + u64 reserved_bits = kvm_vcpu_reserved_gpa_bits_raw(vcpu) | 0x2ff; + + if (!msr_info->host_initiated && + !guest_cpuid_has(vcpu, X86_FEATURE_X2APIC)) + reserved_bits |= X2APIC_ENABLE; if ((msr_info->data & reserved_bits) != 0 || new_mode == LAPIC_MODE_INVALID) return 1; -- 2.25.1