Skip to content

Commit e6348c9

Browse files
committed
KVM: TDX: Return -EIO, not -EINVAL, on a KVM_BUG_ON() condition
Return -EIO when a KVM_BUG_ON() is tripped, as KVM's ABI is to return -EIO when a VM has been killed due to a KVM bug, not -EINVAL. Note, many (all?) of the affected paths never propagate the error code to userspace, i.e. this is about internal consistency more than anything else. Reviewed-by: Rick Edgecombe <rick.p.edgecombe@intel.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com> Reviewed-by: Kai Huang <kai.huang@intel.com> Reviewed-by: Yan Zhao <yan.y.zhao@intel.com> Tested-by: Yan Zhao <yan.y.zhao@intel.com> Tested-by: Kai Huang <kai.huang@intel.com> Link: https://patch.msgid.link/20251030200951.3402865-10-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent ce7b569 commit e6348c9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

arch/x86/kvm/vmx/tdx.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,7 @@ static int tdx_mem_page_record_premap_cnt(struct kvm *kvm, gfn_t gfn,
16211621
struct kvm_tdx *kvm_tdx = to_kvm_tdx(kvm);
16221622

16231623
if (KVM_BUG_ON(kvm->arch.pre_fault_allowed, kvm))
1624-
return -EINVAL;
1624+
return -EIO;
16251625

16261626
/* nr_premapped will be decreased when tdh_mem_page_add() is called. */
16271627
atomic64_inc(&kvm_tdx->nr_premapped);
@@ -1635,7 +1635,7 @@ static int tdx_sept_set_private_spte(struct kvm *kvm, gfn_t gfn,
16351635

16361636
/* TODO: handle large pages. */
16371637
if (KVM_BUG_ON(level != PG_LEVEL_4K, kvm))
1638-
return -EINVAL;
1638+
return -EIO;
16391639

16401640
/*
16411641
* Read 'pre_fault_allowed' before 'kvm_tdx->state'; see matching
@@ -1658,10 +1658,10 @@ static int tdx_sept_drop_private_spte(struct kvm *kvm, gfn_t gfn,
16581658

16591659
/* TODO: handle large pages. */
16601660
if (KVM_BUG_ON(level != PG_LEVEL_4K, kvm))
1661-
return -EINVAL;
1661+
return -EIO;
16621662

16631663
if (KVM_BUG_ON(!is_hkid_assigned(kvm_tdx), kvm))
1664-
return -EINVAL;
1664+
return -EIO;
16651665

16661666
/*
16671667
* When zapping private page, write lock is held. So no race condition
@@ -1846,7 +1846,7 @@ static int tdx_sept_free_private_spt(struct kvm *kvm, gfn_t gfn,
18461846
* and slot move/deletion.
18471847
*/
18481848
if (KVM_BUG_ON(is_hkid_assigned(kvm_tdx), kvm))
1849-
return -EINVAL;
1849+
return -EIO;
18501850

18511851
/*
18521852
* The HKID assigned to this TD was already freed and cache was
@@ -1867,7 +1867,7 @@ static int tdx_sept_remove_private_spte(struct kvm *kvm, gfn_t gfn,
18671867
* there can't be anything populated in the private EPT.
18681868
*/
18691869
if (KVM_BUG_ON(!is_hkid_assigned(to_kvm_tdx(kvm)), kvm))
1870-
return -EINVAL;
1870+
return -EIO;
18711871

18721872
ret = tdx_sept_zap_private_spte(kvm, gfn, level, page);
18731873
if (ret <= 0)

0 commit comments

Comments
 (0)