[libvirt PATCH 4/5] qemu: probe for "-cpu max" support

Pavel Hrdina phrdina at redhat.com
Tue Feb 9 16:35:45 UTC 2021


On Tue, Feb 09, 2021 at 04:25:06PM +0000, Daniel P. Berrangé wrote:
> On Tue, Feb 09, 2021 at 05:23:35PM +0100, Pavel Hrdina wrote:
> > On Tue, Feb 09, 2021 at 01:59:00PM +0000, Daniel P. Berrangé wrote:
> > > This is a special CPU model similar to "-cpu host", so won't use our
> > > normal CPU model detection logic.
> > > 
> > > Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
> > > ---
> > >  src/qemu/qemu_capabilities.c | 11 +++++++++++
> > >  src/qemu/qemu_capabilities.h |  1 +
> > >  2 files changed, 12 insertions(+)
> > > 
> > > diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
> > > index d0378f94bc..ecfb313d0a 100644
> > > --- a/src/qemu/qemu_capabilities.c
> > > +++ b/src/qemu/qemu_capabilities.c
> > > @@ -614,6 +614,7 @@ VIR_ENUM_IMPL(virQEMUCaps,
> > >  
> > >                /* 390 */
> > >                "vhost-user-blk",
> > > +              "cpu-max",
> > >      );
> > >  
> > >  
> > > @@ -2984,12 +2985,22 @@ virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr qemuCaps,
> > >                                    virQEMUCapsAccelPtr accel,
> > >                                    qemuMonitorPtr mon)
> > >  {
> > > +    qemuMonitorCPUDefsPtr defs = accel->cpuModels;
> > 
> > accel->cpuModels is NULL here ... [0]
> > 
> > > +    size_t i;
> > > +
> > >      if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_DEFINITIONS))
> > >          return 0;
> > >  
> > >      if (virQEMUCapsFetchCPUDefinitions(mon, qemuCaps->arch, &accel->cpuModels) < 0)
> > >          return -1;
> > >  
> > > +    for (i = 0; i < defs->ncpus; i++) {
> > 
> > [0] ... so here it will crash.
> > 
> > > +        if (STREQ_NULLABLE(defs->cpus[i].name, "max")) {
> > > +            virQEMUCapsSet(qemuCaps, QEMU_CAPS_CPU_MAX);
> > > +            break;
> > > +        }
> > > +    }
> > > +
> > 
> > Do we trust QEMU that if accel=kvm supports cpu-max that accel=tcg
> > supports it as well and is that true on all architectures?
> 
> Yes, it would be considered a bug if that wasn't the case, because the
> whole point of "max" is that it works for KVM and TCG. 

OK, in that case if you move the fix for the crash from previous patch
here

Reviewed-by: Pavel Hrdina <phrdina at redhat.com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20210209/c8133f52/attachment-0001.sig>


More information about the libvir-list mailing list