From nobody Sun Feb 8 20:35:02 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDA7624291A for ; Fri, 7 Mar 2025 18:41:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741372892; cv=none; b=uxUhjVBtE4IENeVGQktsMOzeZCW0GBNOzNOEhQ2E6/6xol6RwGNJFeplvKds8lTrRd6HoaEraRlIrcvwhZU5NP6G6rWetMbPEZb6Rxep5d3zXyS3mVX40T13o/5OLJQB8AoiH9CDzxxDWpZ7xT/izYVQ/qRxjcGFWBP90CgJszQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741372892; c=relaxed/simple; bh=UvzmKRZnWS5qe6wJ9VUtUGmpd7ZB6tEvtI1phepadOs=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=U9HKven6Z886gMBsyW/PhvtxMoDncD8y1OLR7UuZ3K57/1EzdqENyiLwRMGoZwO+XRd4a1zNFOa72EqXV9t4oiPkCESkcs+UMcjzu1R5wDv6d+d5+ZTjuM9mix/MV0jd9oqpr/3cOdvASf/v1nVMymgkDlW2flYBY0IamDGmKrE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=MqTISKuN; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MqTISKuN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741372889; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+7l1kWaVWNu6icMwRM4pO8CVq1CxSt3kSWCinAdGCUw=; b=MqTISKuNIBWkDw3zgqgzvZ5JyxVuSmH+SuJNwWfV3JSoTE96ouwqjOp2a1YBAV7loU85ck Oen7txP2FeFY97ly6VNMkHcatQqrHZOOc24vZL5wUOPCvrDZ53PbHYfCt0ik2R1UpoCouv JYM0ox4lO5wDqOhzLlYPQiC3WXxbAbQ= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-615-j1M1fCBeP7yETzgBdqeVyw-1; Fri, 07 Mar 2025 13:41:28 -0500 X-MC-Unique: j1M1fCBeP7yETzgBdqeVyw-1 X-Mimecast-MFC-AGG-ID: j1M1fCBeP7yETzgBdqeVyw_1741372887 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 403F51955D4B; Fri, 7 Mar 2025 18:41:27 +0000 (UTC) Received: from virtlab1023.lab.eng.rdu2.redhat.com (virtlab1023.lab.eng.rdu2.redhat.com [10.8.1.187]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B461D1956095; Fri, 7 Mar 2025 18:41:26 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH] KVM: x86: Forbid the use of kvm_load_host_xsave_state() with guest_state_protected Date: Fri, 7 Mar 2025 13:41:25 -0500 Message-ID: <20250307184125.2947143-1-pbonzini@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Content-Type: text/plain; charset="utf-8" kvm_load_host_xsave_state() uses guest save state that is not accessible when guest_state_protected is true. Forbid access to it. For consistency, do the same for kvm_load_guest_xsave_state(). Signed-off-by: Paolo Bonzini --- arch/x86/kvm/svm/svm.c | 7 +++++-- arch/x86/kvm/x86.c | 5 ++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 2c291f0e89c7..51cfef44b58d 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4251,7 +4251,9 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_= vcpu *vcpu, svm_set_dr6(vcpu, DR6_ACTIVE_LOW); =20 clgi(); - kvm_load_guest_xsave_state(vcpu); + + if (!vcpu->arch.guest_state_protected) + kvm_load_guest_xsave_state(vcpu); =20 kvm_wait_lapic_expire(vcpu); =20 @@ -4280,7 +4282,8 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_= vcpu *vcpu, if (unlikely(svm->vmcb->control.exit_code =3D=3D SVM_EXIT_NMI)) kvm_before_interrupt(vcpu, KVM_HANDLING_NMI); =20 - kvm_load_host_xsave_state(vcpu); + if (!vcpu->arch.guest_state_protected) + kvm_load_host_xsave_state(vcpu); stgi(); =20 /* Any pending NMI will happen here */ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index b416eec5c167..03db366e794a 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1182,11 +1182,10 @@ EXPORT_SYMBOL_GPL(kvm_lmsw); =20 void kvm_load_guest_xsave_state(struct kvm_vcpu *vcpu) { - if (vcpu->arch.guest_state_protected) + if (WARN_ON_ONCE(vcpu->arch.guest_state_protected)) return; =20 if (kvm_is_cr4_bit_set(vcpu, X86_CR4_OSXSAVE)) { - if (vcpu->arch.xcr0 !=3D kvm_host.xcr0) xsetbv(XCR_XFEATURE_ENABLED_MASK, vcpu->arch.xcr0); =20 @@ -1205,7 +1204,7 @@ EXPORT_SYMBOL_GPL(kvm_load_guest_xsave_state); =20 void kvm_load_host_xsave_state(struct kvm_vcpu *vcpu) { - if (vcpu->arch.guest_state_protected) + if (WARN_ON_ONCE(vcpu->arch.guest_state_protected)) return; =20 if (cpu_feature_enabled(X86_FEATURE_PKU) && --=20 2.43.5