Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1109439lqo; Fri, 17 May 2024 10:55:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXOej/vh3HLuSJoYOfn6zl0P3iYwZih0rlH93zuqc5RDe+Y8jht02t5jf6pgTv9pw8MR4lj1mE6ffgt4cvOfdzOg1rO91dTJ2JuQ9/kiA== X-Google-Smtp-Source: AGHT+IEg1fpZj0ycoCLpxWktzSYBTmsxpdAlddhiP4F9qAPHV43ub9GMgKYetlQceHvm56dZ8XPs X-Received: by 2002:a17:906:b2d6:b0:a59:dba0:1544 with SMTP id a640c23a62f3a-a5a2d318e22mr1659109266b.31.1715968510283; Fri, 17 May 2024 10:55:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715968510; cv=pass; d=google.com; s=arc-20160816; b=uwW8JPfjjM14d2ImP94AI9ofYXhauS0sLNt9U9dnGG/3Vp1UCrQNnkyJclogQDYkq1 E7jBQdTSuhpDxRDgfaWNtseX0akUI5T+Qd8Zr541EcWCAOIUAjYpK/lC0p0nl/NBCnDF nUZepId50DLKP3Z30hz0WBDW59kBU5wZVga8AtP4yu760Hw0tC9M8SYbOaqHSEvrojnj WvZTxzLrRjnxsgdjreSxNsqB+TnURET4vLp9ISHNAbo3q2m3Y+Ccm6gs6ld/+p+mYtHk 4+yPFqSwUXtF1QaG1Ze7HS3ypt1qLquVtYoQ3xQCTDLu2PO/obgeitm8tT5sVTcqj+MF mgNw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=k9HN6+T1kQpxqp89cuzhx9jHoM7BiF89qZB9gdOCtKM=; fh=AunRZiPj/JPOj0vIF6qoNko6a3hasU3JtXLoz4TD+1M=; b=yAwlyXHX53ixhHJAQYQj+wA1kUUyf3CPFYslE6U4kgr7xuTVyanMfLqReSKa94ZLaQ R4F26j12/PU+cEHTTPfLNius4mPXDeAI1+gTuQEiYTLocIhdfX86F7JJJ/VkX6w3KNV4 AsWs9xUz3P+Hy5uOsIi4V0WrIK7ASwFtakfzFzrclXUNLxEGkc6YgTa+n0+yPajO4zoG OOIj7LD5nXyvABM5JgPUF2P+ED4gbpMUnA9+jKhnryqvv+hrVMQ7c9HL+xesdHn2sy/w DjmalmW1epAMDFiXd2Hmg3Jj/dfK5t0OI/W2rQWNogmOopppM6mpIly7adj3Jh3WHPrZ V3iw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="Tn+/7Arg"; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-182476-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182476-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17945d74si1021436666b.58.2024.05.17.10.55.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 10:55:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-182476-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="Tn+/7Arg"; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-182476-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-182476-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AADA61F24E0D for ; Fri, 17 May 2024 17:52:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 472AC158A34; Fri, 17 May 2024 17:41:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Tn+/7Arg" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 18509158A02 for ; Fri, 17 May 2024 17:41:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715967667; cv=none; b=aNYOWONCChumZ9Lh6xN+bG8CqvUVXVHZ9I7s9O/+6OTGgupMa3pf/36AJ+oG3iNk07n8lgW2v35ctmA5et6y4eL/S6t0IGETiTFxt4QgJZdCSOsaTeF+N81pQJSrFBEfXts9IhtdT6Clr59f0REHaU+d+8kd9bKny7pyZj6FOE0= 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.128.201 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 Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61be8f9ca09so160793557b3.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=syrkbR6SgtXeSaYoRYIGXZzhFS/O+EUuA/Uj2jKW9PX22N6a0fu1IfKqfETujeCqHY Efyi0aY+/vd1ZAMCs6nCWMpdVeXSybpuhwhi6sJmF69KEVKZFacTqU+aiRaCwz0CZzSY eoq9Vlg7hh0G1ndJ773TyxLVvUDBeFwzfcMrjd5+Hc2bH9zF9L1ZhSPoXtUl9imeGUmA 4Sg9bwIYEgQw0E74nVSTB2i3oXiHkEVHl4fGwnvP9N3aGhVO4MaUFl3P8HbCLqKRMEMc 4agKJTLiAKywUD8RZWfwYV18BImuwsdyHWdfXDOVq5ztp3uBA+ipHFjPYVCSrkUz5yNX Jiig== X-Forwarded-Encrypted: i=1; AJvYcCWJdzz9mYDb5+heeMXi30FawVYTK9pS+Hf1uNpmwkj+3x1NziMfYf7LlbUOPwAAElNJ1U/z5hA/Qt4gkRpiY+J8Xp5IqaTuZU2GIgbl X-Gm-Message-State: AOJu0YyXbHKlKVm7d0ydIXWMGo+1unDNa5pNMR+Ghk/1HBz6knOM6pyD DYhjjvxLq8uovq/hEfLfGj3Gp0UOZVzkaXL4QT60s88ktShxuP/n+WCfrUOhNfxHsnq/oEfpIli Q6Q== 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: linux-kernel@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 Content-Type: text/plain; charset="UTF-8" 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 --- 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)); -- 2.45.0.215.g3402c0e53f-goog