[PATCH V4 4/4] x86/tdx: Remove TDX specific idle routine

Vishal Annapurve posted 4 patches 10 months, 1 week ago
[PATCH V4 4/4] x86/tdx: Remove TDX specific idle routine
Posted by Vishal Annapurve 10 months, 1 week ago
With explicit dependency on CONFIG_PARAVIRT and TDX specific
halt()/safe_halt() routines in place, default_idle() is safe to execute for
TDX VMs. Remove TDX specific idle routine override which is now
redundant.

Signed-off-by: Vishal Annapurve <vannapurve@google.com>
---
 arch/x86/coco/tdx/tdx.c    | 2 +-
 arch/x86/include/asm/tdx.h | 2 --
 arch/x86/kernel/process.c  | 3 ---
 3 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c
index 54baf93d9218..3578f7f7a502 100644
--- a/arch/x86/coco/tdx/tdx.c
+++ b/arch/x86/coco/tdx/tdx.c
@@ -407,7 +407,7 @@ static int handle_halt(struct ve_info *ve)
 	return ve_instr_len(ve);
 }
 
-void __cpuidle tdx_halt(void)
+static void __cpuidle tdx_halt(void)
 {
 	const bool irq_disabled = false;
 
diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h
index 393ee2dfaab1..6769d1da4c80 100644
--- a/arch/x86/include/asm/tdx.h
+++ b/arch/x86/include/asm/tdx.h
@@ -58,8 +58,6 @@ void tdx_get_ve_info(struct ve_info *ve);
 
 bool tdx_handle_virt_exception(struct pt_regs *regs, struct ve_info *ve);
 
-void tdx_halt(void);
-
 bool tdx_early_handle_ve(struct pt_regs *regs);
 
 int tdx_mcall_get_report0(u8 *reportdata, u8 *tdreport);
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index d11956a178df..9b21989c283b 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -932,9 +932,6 @@ void __init select_idle_routine(void)
 	if (prefer_mwait_c1_over_halt()) {
 		pr_info("using mwait in idle threads\n");
 		static_call_update(x86_idle, mwait_idle);
-	} else if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) {
-		pr_info("using TDX aware idle routine\n");
-		static_call_update(x86_idle, tdx_halt);
 	} else {
 		static_call_update(x86_idle, default_idle);
 	}
-- 
2.48.1.502.g6dc24dfdaf-goog
Re: [PATCH V4 4/4] x86/tdx: Remove TDX specific idle routine
Posted by Kirill A. Shutemov 10 months, 1 week ago
On Wed, Feb 12, 2025 at 12:07:47AM +0000, Vishal Annapurve wrote:
> With explicit dependency on CONFIG_PARAVIRT and TDX specific
> halt()/safe_halt() routines in place, default_idle() is safe to execute for
> TDX VMs. Remove TDX specific idle routine override which is now
> redundant.

I am not convinced that it is good idea.

It adds two needless flipping of IF in the hot path: first enabling
interrupts in tdx_safe_halt() and disabling it back in default_idle().

-- 
  Kiryl Shutsemau / Kirill A. Shutemov
Re: [PATCH V4 4/4] x86/tdx: Remove TDX specific idle routine
Posted by Vishal Annapurve 10 months, 1 week ago
On Wed, Feb 12, 2025 at 5:03 AM Kirill A. Shutemov <kirill@shutemov.name> wrote:
>
> On Wed, Feb 12, 2025 at 12:07:47AM +0000, Vishal Annapurve wrote:
> > With explicit dependency on CONFIG_PARAVIRT and TDX specific
> > halt()/safe_halt() routines in place, default_idle() is safe to execute for
> > TDX VMs. Remove TDX specific idle routine override which is now
> > redundant.
>
> I am not convinced that it is good idea.
>
> It adds two needless flipping of IF in the hot path: first enabling
> interrupts in tdx_safe_halt() and disabling it back in default_idle().
>

IIUC, the aspect of flipping IF in the hot path twice is also
applicable to default_idle() that gets executed for non-confidential
VMs. I agree that it's redundant for TDX VMs and if there is strong
consensus here, I can drop this cleanup in the next version.

> --
>   Kiryl Shutsemau / Kirill A. Shutemov