Re: [patch 57/58] x86/apic: Provide static call infrastructure for APIC callbacks

From: Peter Zijlstra
Date: Tue Jul 18 2023 - 05:21:06 EST


On Tue, Jul 18, 2023 at 01:16:03AM +0200, Thomas Gleixner wrote:
> Declare and define the static calls for the hotpath APIC callbacks. Note
> this deliberately uses STATIC_CALL_NULL() because otherwise it would be
> required to have the definitions in the 32bit and the 64bit default APIC
> implementations and it's hard to keep the calls in sync. The other option
> would be to have stub functions for each callback type. Not pretty either
>
> So the NULL capable calls are used and filled in during early boot after
> the static key infrastructure has been initialized. The calls will be
> static_call() except for the wait_irc_idle() callback which is valid to be
> NULL for X2APIC systems.
>
> Update the calls when a new APIC driver is installed and when a callback
> override is invoked.
>
> Export the trampolines for the two calls which are used in KVM and MCE
> error inject modules.
>
> Test the setup and let the next step convert the inline wrappers to make it
> effective.

Perhaps preserve some of that in a comment?


> --- a/arch/x86/kernel/apic/init.c
> +++ b/arch/x86/kernel/apic/init.c
> @@ -5,6 +5,28 @@
>
> #include "local.h"
>

/*
* Uses DEFINE_STATIC_CALL_NULL() to avoid having to provide a (stub)
* function at this time.
*
* All except wait_icr_idle *MUST* be set before usage.
*/

> +#define DEFINE_APIC_CALL(__cb) \
> + DEFINE_STATIC_CALL_NULL(apic_call_##__cb, *apic->__cb)
> +
> +DEFINE_APIC_CALL(eoi);
> +DEFINE_APIC_CALL(native_eoi);
> +DEFINE_APIC_CALL(icr_read);
> +DEFINE_APIC_CALL(icr_write);
> +DEFINE_APIC_CALL(read);
> +DEFINE_APIC_CALL(send_IPI);
> +DEFINE_APIC_CALL(send_IPI_mask);
> +DEFINE_APIC_CALL(send_IPI_mask_allbutself);
> +DEFINE_APIC_CALL(send_IPI_allbutself);
> +DEFINE_APIC_CALL(send_IPI_all);
> +DEFINE_APIC_CALL(send_IPI_self);
> +DEFINE_APIC_CALL(wait_icr_idle);
> +DEFINE_APIC_CALL(wakeup_secondary_cpu);
> +DEFINE_APIC_CALL(wakeup_secondary_cpu_64);
> +DEFINE_APIC_CALL(write);
> +
> +EXPORT_STATIC_CALL_TRAMP_GPL(apic_call_send_IPI_mask);
> +EXPORT_STATIC_CALL_TRAMP_GPL(apic_call_send_IPI_self);