[RFC PATCH 2/6] x86/x2apic-savic: Expose x2apic_savic_update_vector()

Tianyu Lan posted 6 patches 7 months, 2 weeks ago
There is a newer version of this series
[RFC PATCH 2/6] x86/x2apic-savic: Expose x2apic_savic_update_vector()
Posted by Tianyu Lan 7 months, 2 weeks ago
From: Tianyu Lan <tiala@microsoft.com>

Expose x2apic_savic_update_vector() and device driver
arch code may update AVIC backing page to allow Hyper-V
inject associated vector.

Signed-off-by: Tianyu Lan <tiala@microsoft.com>
---
 arch/x86/include/asm/apic.h         | 9 +++++++++
 arch/x86/kernel/apic/x2apic_savic.c | 8 ++++++++
 2 files changed, 17 insertions(+)

diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
index 6aa4b8ff08a9..949389e05dd7 100644
--- a/arch/x86/include/asm/apic.h
+++ b/arch/x86/include/asm/apic.h
@@ -241,6 +241,15 @@ static inline u64 native_x2apic_icr_read(void)
 	return val;
 }
 
+#if defined(CONFIG_AMD_SECURE_AVIC)
+extern void x2apic_savic_update_vector(unsigned int cpu,
+				unsigned int vector,
+				bool set);
+#else
+static inline void x2apic_savic_update_vector(unsigned int cpu,
+					      unsigned int vector,								      bool set) { }
+#endif
+
 extern int x2apic_mode;
 extern int x2apic_phys;
 extern void __init x2apic_set_max_apicid(u32 apicid);
diff --git a/arch/x86/kernel/apic/x2apic_savic.c b/arch/x86/kernel/apic/x2apic_savic.c
index 6284d1f8dac9..0dd7e39931b0 100644
--- a/arch/x86/kernel/apic/x2apic_savic.c
+++ b/arch/x86/kernel/apic/x2apic_savic.c
@@ -321,6 +321,14 @@ static void savic_update_vector(unsigned int cpu, unsigned int vector, bool set)
 	update_vector(cpu, SAVIC_ALLOWED_IRR, vector, set);
 }
 
+void x2apic_savic_update_vector(unsigned int cpu, unsigned int vector, bool set)
+{
+	if (!cc_platform_has(CC_ATTR_SNP_SECURE_AVIC))
+		return;
+
+	savic_update_vector(cpu, vector, set);
+}
+
 static void init_apic_page(void)
 {
 	u32 apic_id;
-- 
2.25.1
Re: [RFC PATCH 2/6] x86/x2apic-savic: Expose x2apic_savic_update_vector()
Posted by Neeraj Upadhyay 7 months, 1 week ago

On 5/6/2025 6:37 PM, Tianyu Lan wrote:
> From: Tianyu Lan <tiala@microsoft.com>
> 
> Expose x2apic_savic_update_vector() and device driver
> arch code may update AVIC backing page to allow Hyper-V
> inject associated vector.
> 
> Signed-off-by: Tianyu Lan <tiala@microsoft.com>

I think this new interface is not required. Device driver arch code can call
apic_update_vector() to invoke APIC driver's update_vector() callback. 
Or is it that I am missing something? So, can you explain why this new interface
is needed?



- Neeraj

> ---
>  arch/x86/include/asm/apic.h         | 9 +++++++++
>  arch/x86/kernel/apic/x2apic_savic.c | 8 ++++++++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
> index 6aa4b8ff08a9..949389e05dd7 100644
> --- a/arch/x86/include/asm/apic.h
> +++ b/arch/x86/include/asm/apic.h
> @@ -241,6 +241,15 @@ static inline u64 native_x2apic_icr_read(void)
>  	return val;
>  }
>  
> +#if defined(CONFIG_AMD_SECURE_AVIC)
> +extern void x2apic_savic_update_vector(unsigned int cpu,
> +				unsigned int vector,
> +				bool set);
> +#else
> +static inline void x2apic_savic_update_vector(unsigned int cpu,
> +					      unsigned int vector,								      bool set) { }
> +#endif
> +
>  extern int x2apic_mode;
>  extern int x2apic_phys;
>  extern void __init x2apic_set_max_apicid(u32 apicid);
> diff --git a/arch/x86/kernel/apic/x2apic_savic.c b/arch/x86/kernel/apic/x2apic_savic.c
> index 6284d1f8dac9..0dd7e39931b0 100644
> --- a/arch/x86/kernel/apic/x2apic_savic.c
> +++ b/arch/x86/kernel/apic/x2apic_savic.c
> @@ -321,6 +321,14 @@ static void savic_update_vector(unsigned int cpu, unsigned int vector, bool set)
>  	update_vector(cpu, SAVIC_ALLOWED_IRR, vector, set);
>  }
>  
> +void x2apic_savic_update_vector(unsigned int cpu, unsigned int vector, bool set)
> +{
> +	if (!cc_platform_has(CC_ATTR_SNP_SECURE_AVIC))
> +		return;
> +
> +	savic_update_vector(cpu, vector, set);
> +}
> +
>  static void init_apic_page(void)
>  {
>  	u32 apic_id;
Re: [RFC PATCH 2/6] x86/x2apic-savic: Expose x2apic_savic_update_vector()
Posted by Tianyu Lan 7 months, 1 week ago
On Wed, May 7, 2025 at 11:57 AM Neeraj Upadhyay <Neeraj.Upadhyay@amd.com> wrote:
>
>
>
> On 5/6/2025 6:37 PM, Tianyu Lan wrote:
> > From: Tianyu Lan <tiala@microsoft.com>
> >
> > Expose x2apic_savic_update_vector() and device driver
> > arch code may update AVIC backing page to allow Hyper-V
> > inject associated vector.
> >
> > Signed-off-by: Tianyu Lan <tiala@microsoft.com>
>
> I think this new interface is not required. Device driver arch code can call
> apic_update_vector() to invoke APIC driver's update_vector() callback.
> Or is it that I am missing something? So, can you explain why this new interface
> is needed?

Hi Neeraj:
       Thank you for your review. Agree. apic_update_vector() should be enough.
Will update.

Thanks.