qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Claudio Fontana <cfontana@suse.de>,
	"peter.maydell@linaro.org" <peter.maydell@linaro.org>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>
Cc: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"alxndr@bu.edu" <alxndr@bu.edu>,
	"philmd@redhat.com" <philmd@redhat.com>,
	"ehabkost@redhat.com" <ehabkost@redhat.com>,
	"lovemrd@gmail.com" <lovemrd@gmail.com>
Subject: Re: [PATCH for-6.1 v2] i386: do not call cpudef-only models functions for max, host, base
Date: Mon, 29 Nov 2021 17:17:13 +0000	[thread overview]
Message-ID: <d579bf46d0babc9eece1dc3e8ec63c43b311b022.camel@infradead.org> (raw)
In-Reply-To: <b613015e-3285-8d30-292f-6bf9816b1912@suse.de>

[-- Attachment #1: Type: text/plain, Size: 5275 bytes --]

On Mon, 2021-11-29 at 17:57 +0100, Claudio Fontana wrote:
> On 11/29/21 4:11 PM, David Woodhouse wrote:
> > On Mon, 2021-11-29 at 15:14 +0100, Claudio Fontana wrote:
> > > On 11/29/21 12:39 PM, Woodhouse, David wrote:
> > > > On Fri, 2021-07-23 at 13:29 +0200, Claudio Fontana wrote:
> > > > >  static void kvm_cpu_instance_init(CPUState *cs)
> > > > >  {
> > > > >      X86CPU *cpu = X86_CPU(cs);
> > > > > +    X86CPUClass *xcc = X86_CPU_GET_CLASS(cpu);
> > > > > 
> > > > >      host_cpu_instance_init(cpu);
> > > > > 
> > > > > -    if (!kvm_irqchip_in_kernel()) {
> > > > > -        x86_cpu_change_kvm_default("x2apic", "off");
> > > > > -    } else if (kvm_irqchip_is_split() && kvm_enable_x2apic()) {
> > > > > -        x86_cpu_change_kvm_default("kvm-msi-ext-dest-id", "on");
> > > > > -    }
> > > > > -
> > > > > -    /* Special cases not set in the X86CPUDefinition structs: */
> > > > > +    if (xcc->model) {
> > > > > +        /* only applies to builtin_x86_defs cpus */
> > > > > +        if (!kvm_irqchip_in_kernel()) {
> > > > > +            x86_cpu_change_kvm_default("x2apic", "off");
> > > > > +        } else if (kvm_irqchip_is_split() && kvm_enable_x2apic()) {
> > > > > +            x86_cpu_change_kvm_default("kvm-msi-ext-dest-id", "on");
> > > > > +        }
> > > > > 
> > > > > -    x86_cpu_apply_props(cpu, kvm_default_props);
> > > > > +        /* Special cases not set in the X86CPUDefinition structs: */
> > > > > +        x86_cpu_apply_props(cpu, kvm_default_props);
> > > > > +    }
> > > > > 
> > > > 
> > > > I think this causes a regression in x2apic and kvm-msi-ext-dest-id
> > > > support. If you start qemu thus:
> > > 
> > > If I recall correctly, this change just tries to restore the behavior prior to
> > > commit f5cc5a5c168674f84bf061cdb307c2d25fba5448 ,
> > > 
> > > fixing the issue introduced with the refactoring at that time.
> > > 
> > > Can you try bisecting prior to
> > > f5cc5a5c168674f84bf061cdb307c2d25fba5448 , to see if the actual
> > > breakage comes from somewhere else?
> > 
> > Hm, so it looks like it never worked for '-cpu host' *until* commit
> > f5cc5a5c16.
> 
> Right, so here we are talking about properly supporting this for the first time.
> 
> The fact that it works with f5cc5a5c16 is more an accident than anything else, that commit was clearly broken
> (exemplified by reports of failed boots).
> 
> So we need to find the proper solution, ie, exactly which features should be enabled for which cpu classes and models.
> 
> > 
> > It didn't matter before c1bb5418e3 because you couldn't enable that
> > many vCPUs without an IOMMU, and the *IOMMU* setup would call
> > kvm_enable_x2apic().
> > 
> > But after that, nothing ever called kvm_enable_x2apic() in the '-cpu
> > host' case until commit f5cc5a5c16, which fixed it... until you
> > restored the previous behaviour :)
> > 
> > This "works" to fix this case, but presumably isn't correct:
> 
> Right, we cannot just enable all this code, or the original refactor would have been right.
> 
> These kvm default properties have been as far as I know intended for the cpu actual models (builtin_x86_defs),
> and not for the special cpu classes max, host and base. This is what the revert addresses.
> 
> I suspect what we actually need here is to review exactly in which specific cases kvm_enable_x2apic() should be called in the end.
> 
> The code there is mixing changes to the kvm_default_props that are then applied using x86_cpu_apply_props (and that part should be only for xcc->model != NULL),
> with the actual enablement of the kvm x2apic using kvm_vm_enable_cap(s, KVM_CAP_X2APIC_API, 0, flags) via kvm_enable_x2apic().
> 
> One way is to ignore this detail and just move out those checks, since changes to kvm_default_props are harmless once we skip the x86_cpu_apply_props call,
> as such: 
> 
> ------
> 
> static void kvm_cpu_instance_init(CPUState *cs)
> {
>     X86CPU *cpu = X86_CPU(cs);
>     X86CPUClass *xcc = X86_CPU_GET_CLASS(cpu);
> 
>     host_cpu_instance_init(cpu);
> 
>     /* only applies to builtin_x86_defs cpus */
>     if (!kvm_irqchip_in_kernel()) {
>         x86_cpu_change_kvm_default("x2apic", "off");
>     } else if (kvm_irqchip_is_split() && kvm_enable_x2apic()) {
>         x86_cpu_change_kvm_default("kvm-msi-ext-dest-id", "on");
>     }
> 
>     if (xcc->model) {
>         /* Special cases not set in the X86CPUDefinition structs: */
>         x86_cpu_apply_props(cpu, kvm_default_props);
>     }
> 

I don't believe that works in the case when kvm_enable_x2apic() fails
on an older kernel. Although it sets the defaults, it still doesn't
then *apply* them so it makes no difference.

How about this:

--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -739,9 +739,9 @@ void pc_machine_done(Notifier *notifier, void *data)
 
 
     if (x86ms->apic_id_limit > 255 && !xen_enabled() &&
-        !kvm_irqchip_in_kernel()) {
+        (!kvm_irqchip_in_kernel() || !kvm_enable_x2apic())) {
         error_report("current -smp configuration requires kernel "
-                     "irqchip support.");
+                     "irqchip and X2APIC API support.");
         exit(EXIT_FAILURE);
     }
 }


[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5174 bytes --]

  parent reply	other threads:[~2021-11-29 17:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-23 11:29 [PATCH for-6.1 v2] i386: do not call cpudef-only models functions for max, host, base Claudio Fontana
2021-11-29 11:39 ` Woodhouse, David
2021-11-29 14:14   ` Claudio Fontana
2021-11-29 15:11     ` David Woodhouse
2021-11-29 16:57       ` Claudio Fontana
2021-11-29 17:03         ` Claudio Fontana
2021-11-29 17:17         ` David Woodhouse [this message]
2021-11-29 19:10           ` Claudio Fontana
2021-11-29 19:19             ` David Woodhouse
2021-11-29 19:55               ` Claudio Fontana
2021-11-29 20:29                 ` David Woodhouse
2021-11-30  9:00                   ` Claudio Fontana
2021-11-30 12:13                     ` David Woodhouse
2021-11-30 13:42                       ` [PATCH 1/2] target/i386: Fix sanity check on max APIC ID / X2APIC enablement David Woodhouse
2021-11-30 13:42                       ` [PATCH 2/2] intel_iommu: Fix irqchip / X2APIC configuration checks David Woodhouse
2021-11-30 14:31                         ` Claudio Fontana

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d579bf46d0babc9eece1dc3e8ec63c43b311b022.camel@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=alxndr@bu.edu \
    --cc=cfontana@suse.de \
    --cc=ehabkost@redhat.com \
    --cc=lovemrd@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).