From nobody Thu Oct 2 19:27:58 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 270D02C11F2 for ; Fri, 12 Sep 2025 23:23:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757719420; cv=none; b=Zs8rVdIcc/ZDF1aHRa2eCLP5tjkR4rScvcxhzk3poUm7eMuqCbj/kSxvEShHv7elDiX4fdFRUESkjbNCC+q7/LUt2KM8uwSSIe4XCFJPGbskma+lJZY390L2McSzF6pKFJnK41eeZCP5gOL0oHH+q/UnV6x90RyIGgD9JoSZhyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757719420; c=relaxed/simple; bh=tDtb6e36U1RgnYsYAJL/llcn1rOU/XJ+a6g/XspMzJ8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=p9nG/GZ+zBcDLIUQ2AJZEsvswSxbt/xe1s0TFfW5zQZeN7FZV0rlPH8nJKLo5QPaouJZLUSTS0v99ryX2sTg+jbRdsk1WPTRUKxCP6NCkwicBDRGEig2lNqjcr8JTWO9psj7i4xmoozTecHStciCVMNPAMVYUB0FxlbRjF/byZI= 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=pnuhhq+d; arc=none smtp.client-ip=209.85.216.73 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="pnuhhq+d" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-32df93c787fso830777a91.3 for ; Fri, 12 Sep 2025 16:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1757719418; x=1758324218; 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=bOB6PMzdos0m9DY8NnoO+hTec7qvi6LO9WIPoeRpOTU=; b=pnuhhq+d0CJK/8+DBDpvgyd4TMldMFNQFlUSxzNX10ghP9dqS3r1E5+wMHi6EAJ3G1 i4ZqaM5as43pC5jr7z9Q/nT4uvmIJfj1KIugm+7ZhIioGUDbcMKeTFMU/6Z7iwWlgg7n WXG+POdXXUjwhxSObxSrRp5OChOYlLMeDALNaj1S2dHj0RiRmq4ccJH/8bAKlzZmLLrB LWqmPZ1oQSS0K+wtZedKf4Dt4synd/UYwUwjTcOiiwJu2+POkQge/HMA8Iz3xEo0xGOy koWPNQfAspe8P4IMSCXbggU8mLCx+morRCc/ysIsAXEklCQyqMTBtSo6ryRuLHax8jLc /WEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757719418; x=1758324218; 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=bOB6PMzdos0m9DY8NnoO+hTec7qvi6LO9WIPoeRpOTU=; b=B6atwXi1ruYAEgwd10r5QZ4arLTwkB46twBUGKlFoby9JmBb2+KG1gtsUWnvnPvaPF 6YEErKgm0F+kyFvJ5t8e40G5x8Yi/x2xVzgWBU4BAE7U9Bj3eND1TgcYMkLUqnEQMsLC gaWDBRZTABtXWlWQG+dJWP3ZjsjBAxLLxnn5qDmZJfHfJABc9PX6phJg9ce2ZBJN0h4t kNA1M6fSdgVa2/1Pe6OdcbSL3HlZFl64sWkjlP5xeXhEjVpRhrcjCVtUbwlyRUJGWX1s 2ajZLePyuIzWVa3RrDFqj13VEFjD3fJqhpSGD8NJIc/Inv7aTQQ+gM5C5kA23YuK+KUv wzDg== X-Forwarded-Encrypted: i=1; AJvYcCVqe8iTz0zMX1e7tMQ0KN0i8FY7c/Kc2I89aW2RCOEUemZzODLwy1arreo4UGQx9vQyCftkedo8IMIGBh0=@vger.kernel.org X-Gm-Message-State: AOJu0YzvZHEkDoZDDzzq2fDwhttvBb7aayvRaRJ+NNTb2HStLsJLMini sWNNEJEAPsP87KPDsnSt6FeWyx5nrFPpEYn1UURspZqe3tuPPMWQRK00pKdFqSloyRxu6jKqnzW W5vG1bA== X-Google-Smtp-Source: AGHT+IGHJ98Z8UORppHkGQhWL9lJ0tt/CZzti4qasW9DOcRHrkUwEpSYwwio4pFVSdwtqIjRnwHW6lWan6c= X-Received: from pjbpx10.prod.google.com ([2002:a17:90b:270a:b0:327:be52:966d]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1dd1:b0:32d:a721:8cc7 with SMTP id 98e67ed59e1d1-32de4f90629mr5198540a91.35.1757719418603; Fri, 12 Sep 2025 16:23:38 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 12 Sep 2025 16:22:46 -0700 In-Reply-To: <20250912232319.429659-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: <20250912232319.429659-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog Message-ID: <20250912232319.429659-9-seanjc@google.com> Subject: [PATCH v15 08/41] KVM: x86: Initialize kvm_caps.supported_xss From: Sean Christopherson To: Paolo Bonzini , Sean Christopherson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Tom Lendacky , Mathias Krause , John Allen , Rick Edgecombe , Chao Gao , Maxim Levitsky , Xiaoyao Li , Zhang Yi Z Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yang Weijiang Set original kvm_caps.supported_xss to (host_xss & KVM_SUPPORTED_XSS) if XSAVES is supported. host_xss contains the host supported xstate feature bits for thread FPU context switch, KVM_SUPPORTED_XSS includes all KVM enabled XSS feature bits, the resulting value represents the supervisor xstates that are available to guest and are backed by host FPU framework for swapping {guest,host} XSAVE-managed registers/MSRs. Signed-off-by: Yang Weijiang Reviewed-by: Maxim Levitsky Reviewed-by: Chao Gao Tested-by: Mathias Krause Tested-by: John Allen Tested-by: Rick Edgecombe Reviewed-by: Xiaoyao Li Signed-off-by: Chao Gao [sean: relocate and enhance comment about PT / XSS[8] ] Signed-off-by: Sean Christopherson Reviewed-by: Binbin Wu --- arch/x86/kvm/x86.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 519d58b82f7f..c5e38d6943fe 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -217,6 +217,14 @@ static struct kvm_user_return_msrs __percpu *user_retu= rn_msrs; | XFEATURE_MASK_BNDCSR | XFEATURE_MASK_AVX512 \ | XFEATURE_MASK_PKRU | XFEATURE_MASK_XTILE) =20 +/* + * Note, KVM supports exposing PT to the guest, but does not support conte= xt + * switching PT via XSTATE (KVM's PT virtualization relies on perf; swappi= ng + * PT via guest XSTATE would clobber perf state), i.e. KVM doesn't support + * IA32_XSS[bit 8] (guests can/must use RDMSR/WRMSR to save/restore PT MSR= s). + */ +#define KVM_SUPPORTED_XSS 0 + bool __read_mostly allow_smaller_maxphyaddr =3D 0; EXPORT_SYMBOL_GPL(allow_smaller_maxphyaddr); =20 @@ -3986,11 +3994,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct= msr_data *msr_info) case MSR_IA32_XSS: if (!guest_cpuid_has(vcpu, X86_FEATURE_XSAVES)) return KVM_MSR_RET_UNSUPPORTED; - /* - * KVM supports exposing PT to the guest, but does not support - * IA32_XSS[bit 8]. Guests have to use RDMSR/WRMSR rather than - * XSAVES/XRSTORS to save/restore PT MSRs. - */ + if (data & ~vcpu->arch.guest_supported_xss) return 1; if (vcpu->arch.ia32_xss =3D=3D data) @@ -9818,14 +9822,17 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *op= s) kvm_host.xcr0 =3D xgetbv(XCR_XFEATURE_ENABLED_MASK); kvm_caps.supported_xcr0 =3D kvm_host.xcr0 & KVM_SUPPORTED_XCR0; } + + if (boot_cpu_has(X86_FEATURE_XSAVES)) { + rdmsrq(MSR_IA32_XSS, kvm_host.xss); + kvm_caps.supported_xss =3D kvm_host.xss & KVM_SUPPORTED_XSS; + } + kvm_caps.supported_quirks =3D KVM_X86_VALID_QUIRKS; kvm_caps.inapplicable_quirks =3D KVM_X86_CONDITIONAL_QUIRKS; =20 rdmsrq_safe(MSR_EFER, &kvm_host.efer); =20 - if (boot_cpu_has(X86_FEATURE_XSAVES)) - rdmsrq(MSR_IA32_XSS, kvm_host.xss); - kvm_init_pmu_capability(ops->pmu_ops); =20 if (boot_cpu_has(X86_FEATURE_ARCH_CAPABILITIES)) --=20 2.51.0.384.g4c02a37b29-goog