From nobody Fri Dec 19 12:28:40 2025 Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (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 C10972874E9; Tue, 4 Nov 2025 20:00:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762286412; cv=none; b=uso5SVMUUigAC9wqtRQKYbaNiL3L6cjVL3S7Rcs70qoV93zwR20ZKK003ZC+W2Rn7Yk62sdIp34Afi52oHs0Qyz54BeWuNULsmTYxhoBG3BXPp8U0gQI/KcEj+V93kU4VYcmRYSlqumTjob5vREkGbtshviKIDmVM7ZSvF0Bf34= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762286412; c=relaxed/simple; bh=sXYJzjseqJuvj8NINKu5aCwyL2sAus6gfzVskW5l7H4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FwsVoLQ5PIlWgBj5378sxxiL+1nd3VchFuLX6QMHRjG6CrbxO9Yrs7217U95vKUCM7qUKCT7N2zTHWlFovcxswEfG7a9y4Udh7krOiKrZgd8MGKGDV1VIApFVRJIsjjL+4OeRLXJ9HEaQsQeQBXu9rtB73wkwXR8Mho3xf7Xn1A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=INFvzPZp; arc=none smtp.client-ip=91.218.175.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="INFvzPZp" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1762286409; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+63j098rpFjBiDSEQuayeuzFS+idIYHSpwfAxQDf2J0=; b=INFvzPZphCoN1LjY3YMVWX8xHa5AxP7EJkK4CwKs/QAqwbS2KQ2laoNGdmMo5Z7LayyyRS xtlsxOZ9DnMn8HXTQjPGJ8gqcCt4hhxV0CLYd5g5QeBxK6RaB2B4TagCDLapRNpa1gsDzn /lzH6aDT3HUsbYbIUkwcuQ/z6fhlS2Q= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Jim Mattson , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH 02/11] KVM: nSVM: Add missing consistency check for EFER, CR0, CR4, and CS Date: Tue, 4 Nov 2025 19:59:40 +0000 Message-ID: <20251104195949.3528411-3-yosry.ahmed@linux.dev> In-Reply-To: <20251104195949.3528411-1-yosry.ahmed@linux.dev> References: <20251104195949.3528411-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT According to the APM Volume #2, 15.5, Canonicalization and Consistency Checks (24593=E2=80=94Rev. 3.42=E2=80=94March 2024), the following conditio= n (among others) results in a #VMEXIT with VMEXIT_INVALID (aka SVM_EXIT_ERR): EFER.LME, CR0.PG, CR4.PAE, CS.L, and CS.D are all non-zero. Add the missing consistency check. This is functionally a nop because the nested VMRUN results in SVM_EXIT_ERR in HW, which is forwarded to L1, but KVM makes all consistency checks before a VMRUN is actually attempted. Signed-off-by: Yosry Ahmed --- arch/x86/kvm/svm/nested.c | 7 +++++++ arch/x86/kvm/svm/svm.h | 1 + 2 files changed, 8 insertions(+) diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 9a534f04bdc83..9866b2fd8f32a 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -380,6 +380,11 @@ static bool __nested_vmcb_check_save(struct kvm_vcpu *= vcpu, CC(!(save->cr0 & X86_CR0_PE)) || CC(!kvm_vcpu_is_legal_cr3(vcpu, save->cr3))) return false; + + if (CC((save->cr4 & X86_CR4_PAE) && + (save->cs.attrib & SVM_SELECTOR_L_MASK) && + (save->cs.attrib & SVM_SELECTOR_DB_MASK))) + return false; } =20 /* Note, SVM doesn't have any additional restrictions on CR4. */ @@ -473,6 +478,8 @@ static void __nested_copy_vmcb_save_to_cache(struct vmc= b_save_area_cached *to, * Copy only fields that are validated, as we need them * to avoid TOC/TOU races. */ + to->cs =3D from->cs; + to->efer =3D from->efer; to->cr0 =3D from->cr0; to->cr3 =3D from->cr3; diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 0a2908e22d746..efcf923264c55 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -142,6 +142,7 @@ struct kvm_vmcb_info { }; =20 struct vmcb_save_area_cached { + struct vmcb_seg cs; u64 efer; u64 cr4; u64 cr3; --=20 2.51.2.1026.g39e6a42477-goog