summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Christopherson <seanjc@google.com>2026-02-14 04:27:00 +0300
committerSean Christopherson <seanjc@google.com>2026-03-04 19:53:08 +0300
commitafe31de159bf218d6e92db6a4495f715f0a4e38c (patch)
treef8ad2a72d04c6e773089dcf55be8a701c156c3d7
parenteac90a5ba0aa40f6d81def241bd78d2a5cc5e08b (diff)
downloadlinux-afe31de159bf218d6e92db6a4495f715f0a4e38c.tar.xz
x86/virt/tdx: Use ida_is_empty() to detect if any TDs may be running
Drop nr_configured_hkid and instead use ida_is_empty() to detect if any HKIDs have been allocated/configured. Suggested-by: Dan Williams <dan.j.williams@intel.com> Reviewed-by: Dan Williams <dan.j.williams@intel.com> Reviewed-by: Chao Gao <chao.gao@intel.com> Tested-by: Chao Gao <chao.gao@intel.com> Tested-by: Sagi Shahar <sagis@google.com> Link: https://patch.msgid.link/20260214012702.2368778-15-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
-rw-r--r--arch/x86/virt/vmx/tdx/tdx.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
index 3a1dddec6843..cb9b3210ab71 100644
--- a/arch/x86/virt/vmx/tdx/tdx.c
+++ b/arch/x86/virt/vmx/tdx/tdx.c
@@ -59,8 +59,6 @@ static LIST_HEAD(tdx_memlist);
static struct tdx_sys_info tdx_sysinfo __ro_after_init;
static bool tdx_module_initialized __ro_after_init;
-static atomic_t nr_configured_hkid;
-
typedef void (*sc_err_func_t)(u64 fn, u64 err, struct tdx_module_args *args);
static inline void seamcall_err(u64 fn, u64 err, struct tdx_module_args *args)
@@ -191,7 +189,7 @@ static int tdx_offline_cpu(unsigned int cpu)
int i;
/* No TD is running. Allow any cpu to be offline. */
- if (!atomic_read(&nr_configured_hkid))
+ if (ida_is_empty(&tdx_guest_keyid_pool))
goto done;
/*
@@ -1542,22 +1540,15 @@ EXPORT_SYMBOL_FOR_KVM(tdx_get_nr_guest_keyids);
int tdx_guest_keyid_alloc(void)
{
- int ret;
-
- ret = ida_alloc_range(&tdx_guest_keyid_pool, tdx_guest_keyid_start,
- tdx_guest_keyid_start + tdx_nr_guest_keyids - 1,
- GFP_KERNEL);
- if (ret >= 0)
- atomic_inc(&nr_configured_hkid);
-
- return ret;
+ return ida_alloc_range(&tdx_guest_keyid_pool, tdx_guest_keyid_start,
+ tdx_guest_keyid_start + tdx_nr_guest_keyids - 1,
+ GFP_KERNEL);
}
EXPORT_SYMBOL_FOR_KVM(tdx_guest_keyid_alloc);
void tdx_guest_keyid_free(unsigned int keyid)
{
ida_free(&tdx_guest_keyid_pool, keyid);
- atomic_dec(&nr_configured_hkid);
}
EXPORT_SYMBOL_FOR_KVM(tdx_guest_keyid_free);