Re: [PATCH v4 11/11] KVM: X86: Use common code for PV IPIs in linux guest
From: Sean Christopherson
Date: Fri Aug 16 2024 - 09:52:13 EST
"x86/kvm:" for the scope. "KVM: x86:" is for host-side KVM, this is guest code.
On Tue, Jul 09, 2024, Jacob Pan wrote:
> The paravirtual APIC hooks in KVM, some of which are used for sending PV
> IPIs, can reuse common code for ICR preparation. This shared code also
> encompasses NMI-source reporting when in effect.
Please state what the patch actually does, not what it can do. For folks that
aren't intimately familiar with FRED (read: me), that second sentence in particular
is wildly unhelpful. I had to download yet another version of the FRED spec, and
decipher the poorly documented software-defined encoding scheme introduced by this
series just to understand what this patch does.
And the order of patches in this series is broken. Overloading the vector *before*
switching the PV IPI code to __prepare_ICR() will result in KVM sending garbage
to the host. I.e. _all_ IPI implementations need to be made safe before the NMI
source reporting code can be introduced.
> Originally-by: Zeng Guang <guang.zeng@xxxxxxxxx>
> Signed-off-by: Jacob Pan <jacob.jun.pan@xxxxxxxxxxxxxxx>
> ---
> v4: Refine comments, no functional change.
> ---
> arch/x86/kernel/kvm.c | 10 +---------
> 1 file changed, 1 insertion(+), 9 deletions(-)
>
> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> index 263f8aed4e2c..a45d60aa0302 100644
> --- a/arch/x86/kernel/kvm.c
> +++ b/arch/x86/kernel/kvm.c
> @@ -516,15 +516,7 @@ static void __send_ipi_mask(const struct cpumask *mask, int vector)
>
> local_irq_save(flags);
>
> - switch (vector) {
> - default:
> - icr = APIC_DM_FIXED | vector;
> - break;
> - case NMI_VECTOR:
> - icr = APIC_DM_NMI;
> - break;
> - }
> -
> + icr = __prepare_ICR(0, vector, 0);
Rather than force KVM to throw in junk dest+shorthand, what about adding a
__prepare_ICR_vector()? Then KVM doesn't need to arbitrarily pass zeroes, and
even __prepare_ICR() itself benefits (IMO), e.g. this is nice and easy to read:
static inline unsigned int __prepare_ICR(unsigned int shortcut, int vector,
unsigned int dest)
{
return shortcut | dest | __prepare_ICR_vector(vector);
}