From patchwork Fri May 17 17:39:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13667264 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A9EC158A03 for ; Fri, 17 May 2024 17:41:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715967667; cv=none; b=dwXgEev+0PYpXx7f/sIrAA23H2r0VifAzNaJ2/fIgsrcxoo3QOGndcuk/gBsex3IYypRH+5BikPe/eCU6RIAjcpx4hMvE/TEzI/ozVeoYOSxfC76EjzXZUY2H2nrydKSCFSzSvcSlHqDHVlMhQqZnmKdwQ22Gs7qecBgwLLgAIc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715967667; c=relaxed/simple; bh=3zUzzzxucQZAbr71D0DmujeOsv7diMSfzYKvmLSrt/g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=V50D+raw6vXcwXW5vZClKDIOwr5adyKrHTUgYyIfe94FkXH4w7BoGKt9JKAklX+U0IaZSg1rgJpw7kEIcvejQ5DoPSsAuq0IpeIGslFme5VfrJvScLERNOBxuVKpkp+C6JnCrJdjffwG59VJiiSc+jO4HVDBmIzkB92WYnerbBo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Tn+/7Arg; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Tn+/7Arg" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6dbdcfd39so17822977276.2 for ; Fri, 17 May 2024 10:41:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715967665; x=1716572465; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=k9HN6+T1kQpxqp89cuzhx9jHoM7BiF89qZB9gdOCtKM=; b=Tn+/7ArggweaWW9nQLt3knMmriZ/g/+PyJbCtKEQk3l/a75rs0T7taGn7TYN/VCLJs F1f60XeG86uOESCVLl4hpWZ2/bcXqCc/iU+MdFhmvdeCgHHBQhN07heYquKCt6pcnrEo JnE5Q/2aDBwyqKd2FijWqV1/ZgDg8mYu0pPJZp8ibbY62PxkxBQwR0Kf9hLOLS3KpQ/v lZ9V7ArGSTTn0oK2ld1MjFLImbpwZQPvTDZyTAO09qfSU4hl5aMUBSn1aPD27YJdNLKd 7E4hCrJ5R1i3L/GlpdNBdLPRtq6S9vemGQhwFOzsYKQIt7oSqEJNJJxPJVOY+4RAjUp4 1G6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715967665; x=1716572465; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=k9HN6+T1kQpxqp89cuzhx9jHoM7BiF89qZB9gdOCtKM=; b=N11inv1UZ0FcTdVMduBd2jHT4xitQXFV8Hh/IPk69MMJLAEjlECLuavEQUL9yivG0d cyLXcPZdfbWilfUNWTr0JsWnH6vFbofLdg+qMmYKDv21VllZsT9D9WrP0AaIGA1FXPHW PX+weefh5Ma2gP0ZO5QKe9PrVgnTLZ1FTRpdIa8FpMfQ15hsY6346ayEj2CI4vAQWq75 TSdW6My07CnNl+a5dcYGUvPvAH8iVKMJGNxqoO0uK7ySq3f96Z8eiVleC3cYsCnEJidb fSFYjvJPSPCcAM6gDB34IL38CblDdSHnQHa38UTWKw4erqzp5sRyVvbFCXSX5NTLD9gH Vlhg== X-Gm-Message-State: AOJu0Ywqx1zhWmofuORGfYch4Zx3JnrWjlvQijvUbhEj0fZEWAXOiFFn Gh0bLgGYmB5BLt+27BhffY80yPEQjEwr7kbk3YNSsq+VNVvIw/JGepJGUsv/CBqNnizbt2TPinZ 7bQ== X-Google-Smtp-Source: AGHT+IGHKMItbnVB37cVRqK29X+EjhtNIMWRmqgByCNxynwG28s4Mm9qr1xFC5xEY8Pk4mtu5ts0LMTnP54= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:c05:b0:de5:2b18:3b74 with SMTP id 3f1490d57ef6-dee4f33cb2bmr6152009276.2.1715967665318; Fri, 17 May 2024 10:41:05 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 17 May 2024 10:39:20 -0700 In-Reply-To: <20240517173926.965351-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240517173926.965351-1-seanjc@google.com> X-Mailer: git-send-email 2.45.0.215.g3402c0e53f-goog Message-ID: <20240517173926.965351-44-seanjc@google.com> Subject: [PATCH v2 43/49] KVM: x86: Update OS{XSAVE,PKE} bits in guest CPUID irrespective of host support From: Sean Christopherson To: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Hou Wenlong , Kechen Lu , Oliver Upton , Maxim Levitsky , Binbin Wu , Yang Weijiang , Robert Hoo When making runtime CPUID updates, change OSXSAVE and OSPKE even if their respective base features (XSAVE, PKU) are not supported by the host. KVM already incorporates host support in the vCPU's effective reserved CR4 bits. I.e. OSXSAVE and OSPKE can be set if and only if the host supports them. And conversely, since KVM's ABI is that KVM owns the dynamic OS feature flags, clearing them when they obviously aren't supported and thus can't be enabled is arguably a fix. Signed-off-by: Sean Christopherson Reviewed-by: Maxim Levitsky --- arch/x86/kvm/cpuid.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 8256fc657c6b..552e65ba5efa 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -336,10 +336,8 @@ void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu) best = kvm_find_cpuid_entry(vcpu, 1); if (best) { - /* Update OSXSAVE bit */ - if (boot_cpu_has(X86_FEATURE_XSAVE)) - cpuid_entry_change(best, X86_FEATURE_OSXSAVE, - kvm_is_cr4_bit_set(vcpu, X86_CR4_OSXSAVE)); + cpuid_entry_change(best, X86_FEATURE_OSXSAVE, + kvm_is_cr4_bit_set(vcpu, X86_CR4_OSXSAVE)); cpuid_entry_change(best, X86_FEATURE_APIC, vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE); @@ -351,7 +349,7 @@ void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu) } best = kvm_find_cpuid_entry_index(vcpu, 7, 0); - if (best && boot_cpu_has(X86_FEATURE_PKU)) + if (best) cpuid_entry_change(best, X86_FEATURE_OSPKE, kvm_is_cr4_bit_set(vcpu, X86_CR4_PKE));