[PATCH v9 06/22] x86/cea: Export __this_cpu_ist_top_va() to KVM

Xin Li (Intel) posted 22 patches 3 months, 2 weeks ago
[PATCH v9 06/22] x86/cea: Export __this_cpu_ist_top_va() to KVM
Posted by Xin Li (Intel) 3 months, 2 weeks ago
Export __this_cpu_ist_top_va() to allow KVM to retrieve the per-CPU
exception stack top.

FRED introduced new fields in the host-state area of the VMCS for stack
levels 1->3 (HOST_IA32_FRED_RSP[123]), each respectively corresponding to
per-CPU exception stacks for #DB, NMI and #DF.  KVM must populate these
fields each time a vCPU is loaded onto a CPU.

Signed-off-by: Xin Li (Intel) <xin@zytor.com>
---
 arch/x86/mm/cpu_entry_area.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/x86/mm/cpu_entry_area.c b/arch/x86/mm/cpu_entry_area.c
index b3d90f9cfbb1..e507621d5c20 100644
--- a/arch/x86/mm/cpu_entry_area.c
+++ b/arch/x86/mm/cpu_entry_area.c
@@ -19,6 +19,11 @@ static DEFINE_PER_CPU_PAGE_ALIGNED(struct exception_stacks, exception_stacks);
 DEFINE_PER_CPU(struct cea_exception_stacks*, cea_exception_stacks);
 
 /*
+ * FRED introduced new fields in the host-state area of the VMCS for
+ * stack levels 1->3 (HOST_IA32_FRED_RSP[123]), each respectively
+ * corresponding to per CPU stacks for #DB, NMI and #DF.  KVM must
+ * populate these each time a vCPU is loaded onto a CPU.
+ *
  * Typically invoked by entry code, so must be noinstr.
  */
 noinstr unsigned long __this_cpu_ist_bottom_va(enum exception_stack_ordering stack)
@@ -36,6 +41,7 @@ noinstr unsigned long __this_cpu_ist_top_va(enum exception_stack_ordering stack)
 {
 	return __this_cpu_ist_bottom_va(stack) + EXCEPTION_STKSZ;
 }
+EXPORT_SYMBOL_FOR_MODULES(__this_cpu_ist_top_va, "kvm-intel");
 
 static DEFINE_PER_CPU_READ_MOSTLY(unsigned long, _cea_offset);
 
-- 
2.51.0
Re: [PATCH v9 06/22] x86/cea: Export __this_cpu_ist_top_va() to KVM
Posted by Borislav Petkov 1 week, 2 days ago
On Sun, Oct 26, 2025 at 01:18:54PM -0700, Xin Li (Intel) wrote:
> @@ -36,6 +41,7 @@ noinstr unsigned long __this_cpu_ist_top_va(enum exception_stack_ordering stack)
>  {
>  	return __this_cpu_ist_bottom_va(stack) + EXCEPTION_STKSZ;
>  }
> +EXPORT_SYMBOL_FOR_MODULES(__this_cpu_ist_top_va, "kvm-intel");

Why is this function name still kept with the "__" prefix but it is being
exported at the same time?

It looks to me like we're exporting the wrong thing as the "__" kinda says it
is an internal helper.

Just drop the prefix and call it something more sensible please. The caller
couldn't care less about "ist_top_va".

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
Re: [PATCH v9 06/22] x86/cea: Export __this_cpu_ist_top_va() to KVM
Posted by Xin Li 1 week, 2 days ago

> On Jan 30, 2026, at 5:46 AM, Borislav Petkov <bp@alien8.de> wrote:
> 
> On Sun, Oct 26, 2025 at 01:18:54PM -0700, Xin Li (Intel) wrote:
>> @@ -36,6 +41,7 @@ noinstr unsigned long __this_cpu_ist_top_va(enum exception_stack_ordering stack)
>> {
>> return __this_cpu_ist_bottom_va(stack) + EXCEPTION_STKSZ;
>> }
>> +EXPORT_SYMBOL_FOR_MODULES(__this_cpu_ist_top_va, "kvm-intel");
> 
> Why is this function name still kept with the "__" prefix but it is being
> exported at the same time?
> 
> It looks to me like we're exporting the wrong thing as the "__" kinda says it
> is an internal helper.
> 
> Just drop the prefix and call it something more sensible please. The caller
> couldn't care less about "ist_top_va".

Right, the “__” prefix no longer makes sense.

What is the right order of rename and refactor?

I think we usually do renames in the first patch and then refactor in a following patch.
Re: [PATCH v9 06/22] x86/cea: Export __this_cpu_ist_top_va() to KVM
Posted by Borislav Petkov 1 week, 2 days ago
On Fri, Jan 30, 2026 at 08:35:50AM -0800, Xin Li wrote:
> What is the right order of rename and refactor?

You can rename it when you do the export. The name should be more sensible, as
said.

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
Re: [PATCH v9 06/22] x86/cea: Export __this_cpu_ist_top_va() to KVM
Posted by Dave Hansen 3 months, 2 weeks ago
On 10/26/25 13:18, Xin Li (Intel) wrote:
> Export __this_cpu_ist_top_va() to allow KVM to retrieve the per-CPU
> exception stack top.
> 
> FRED introduced new fields in the host-state area of the VMCS for stack
> levels 1->3 (HOST_IA32_FRED_RSP[123]), each respectively corresponding to
> per-CPU exception stacks for #DB, NMI and #DF.  KVM must populate these
> fields each time a vCPU is loaded onto a CPU.

Acked-by: Dave Hansen <dave.hansen@linux.intel.com>