[libvirt] [PATCH 2/2] qemu: Remove host-passthrough validation check for host-phys-bits=on

Lin Ma posted 2 patches 3 years, 5 months ago
[libvirt] [PATCH 2/2] qemu: Remove host-passthrough validation check for host-phys-bits=on
Posted by Lin Ma 3 years, 5 months ago
Besides the -cpu host, The host-phys-bits=on applies to custom or max
cpu model, So the host-passthrough validation check is unnecessary for
maxphysaddr with mode='passthrough'.

Signed-off-by: Lin Ma <lma@suse.com>
---
 src/qemu/qemu_validate.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 6e457f3814..e60575d8a0 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -344,13 +344,6 @@ qemuValidateDomainDefCpu(virQEMUDriver *driver,
 
         switch (addr->mode) {
         case VIR_CPU_MAX_PHYS_ADDR_MODE_PASSTHROUGH:
-            if (def->cpu->mode != VIR_CPU_MODE_HOST_PASSTHROUGH) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                               _("CPU maximum physical address bits mode '%s' can only be used with '%s' CPUs"),
-                               virCPUMaxPhysAddrModeTypeToString(addr->mode),
-                               virCPUModeTypeToString(VIR_CPU_MODE_HOST_PASSTHROUGH));
-                return -1;
-            }
             if (addr->bits != -1) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                                _("CPU maximum physical address bits number specification cannot be used with mode='%s'"),
-- 
2.26.2
Re: [libvirt] [PATCH 2/2] qemu: Remove host-passthrough validation check for host-phys-bits=on
Posted by Claudio Fontana 3 years, 5 months ago
On 8/17/22 10:19, Lin Ma wrote:
> Besides the -cpu host, The host-phys-bits=on applies to custom or max
> cpu model, So the host-passthrough validation check is unnecessary for
> maxphysaddr with mode='passthrough'.
> 
> Signed-off-by: Lin Ma <lma@suse.com>
> ---
>  src/qemu/qemu_validate.c | 7 -------
>  1 file changed, 7 deletions(-)
> 
> diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
> index 6e457f3814..e60575d8a0 100644
> --- a/src/qemu/qemu_validate.c
> +++ b/src/qemu/qemu_validate.c
> @@ -344,13 +344,6 @@ qemuValidateDomainDefCpu(virQEMUDriver *driver,
>  
>          switch (addr->mode) {
>          case VIR_CPU_MAX_PHYS_ADDR_MODE_PASSTHROUGH:
> -            if (def->cpu->mode != VIR_CPU_MODE_HOST_PASSTHROUGH) {
> -                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> -                               _("CPU maximum physical address bits mode '%s' can only be used with '%s' CPUs"),
> -                               virCPUMaxPhysAddrModeTypeToString(addr->mode),
> -                               virCPUModeTypeToString(VIR_CPU_MODE_HOST_PASSTHROUGH));
> -                return -1;
> -            }
>              if (addr->bits != -1) {
>                  virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
>                                 _("CPU maximum physical address bits number specification cannot be used with mode='%s'"),

Hmm what was the reason for this, maybe Dario knows?

In my view we definitely do not want to restrict this to VIR_CPU_MODE_HOST_PASSTHROUGH only,
but this should be restricted in my view to QEMU hw accelerators that use host cpuid (as per accel_uses_host_cpuid() -> true),
which are KVM and HVF.

Not sure how to properly check that?

Ciao,

CLaudio
Re: [libvirt] [PATCH 2/2] qemu: Remove host-passthrough validation check for host-phys-bits=on
Posted by Jim Fehlig 3 years, 5 months ago
On 8/17/22 02:19, Lin Ma wrote:
> Besides the -cpu host, The host-phys-bits=on applies to custom or max
> cpu model, So the host-passthrough validation check is unnecessary for
> maxphysaddr with mode='passthrough'.

I wonder why Dario added the check? He even added a test for it: 
cpu-phys-bits-passthrough2 in qemuxml2argvtest. He is off now, so we'll have to 
await his return for an answer.

> Signed-off-by: Lin Ma <lma@suse.com>
> ---
>   src/qemu/qemu_validate.c | 7 -------
>   1 file changed, 7 deletions(-)
> 
> diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
> index 6e457f3814..e60575d8a0 100644
> --- a/src/qemu/qemu_validate.c
> +++ b/src/qemu/qemu_validate.c
> @@ -344,13 +344,6 @@ qemuValidateDomainDefCpu(virQEMUDriver *driver,
>   
>           switch (addr->mode) {
>           case VIR_CPU_MAX_PHYS_ADDR_MODE_PASSTHROUGH:
> -            if (def->cpu->mode != VIR_CPU_MODE_HOST_PASSTHROUGH) {
> -                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> -                               _("CPU maximum physical address bits mode '%s' can only be used with '%s' CPUs"),
> -                               virCPUMaxPhysAddrModeTypeToString(addr->mode),
> -                               virCPUModeTypeToString(VIR_CPU_MODE_HOST_PASSTHROUGH));
> -                return -1;
> -            }

If the check is removed the above mentioned test needs removed too.

Regards,
Jim

>               if (addr->bits != -1) {
>                   virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
>                                  _("CPU maximum physical address bits number specification cannot be used with mode='%s'"),
Re: [libvirt] [PATCH 2/2] qemu: Remove host-passthrough validation check for host-phys-bits=on
Posted by Jim Fehlig 3 years, 5 months ago
On 8/17/22 08:47, Jim Fehlig wrote:
> On 8/17/22 02:19, Lin Ma wrote:
>> Besides the -cpu host, The host-phys-bits=on applies to custom or max
>> cpu model, So the host-passthrough validation check is unnecessary for
>> maxphysaddr with mode='passthrough'.
> 
> I wonder why Dario added the check? He even added a test for it: 
> cpu-phys-bits-passthrough2 in qemuxml2argvtest. He is off now, so we'll have to 
> await his return for an answer.

BTW, I'm not doubting your analysis. In fact, I tested with one of the known CPU 
models (-cpu Cascadelake-Server,...,host-phys-bits=on) and it worked fine with a 
7TB VM. I'd still like to know why Dario added the check. Perhaps he encountered 
some problematic corner cases.

Thanks!
Jim

> 
>> Signed-off-by: Lin Ma <lma@suse.com>
>> ---
>>   src/qemu/qemu_validate.c | 7 -------
>>   1 file changed, 7 deletions(-)
>>
>> diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
>> index 6e457f3814..e60575d8a0 100644
>> --- a/src/qemu/qemu_validate.c
>> +++ b/src/qemu/qemu_validate.c
>> @@ -344,13 +344,6 @@ qemuValidateDomainDefCpu(virQEMUDriver *driver,
>>           switch (addr->mode) {
>>           case VIR_CPU_MAX_PHYS_ADDR_MODE_PASSTHROUGH:
>> -            if (def->cpu->mode != VIR_CPU_MODE_HOST_PASSTHROUGH) {
>> -                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
>> -                               _("CPU maximum physical address bits mode '%s' 
>> can only be used with '%s' CPUs"),
>> -                               virCPUMaxPhysAddrModeTypeToString(addr->mode),
>> -                               
>> virCPUModeTypeToString(VIR_CPU_MODE_HOST_PASSTHROUGH));
>> -                return -1;
>> -            }
> 
> If the check is removed the above mentioned test needs removed too.
> 
> Regards,
> Jim
> 
>>               if (addr->bits != -1) {
>>                   virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
>>                                  _("CPU maximum physical address bits number 
>> specification cannot be used with mode='%s'"),
> 
Re: [libvirt] [PATCH 2/2] qemu: Remove host-passthrough validation check for host-phys-bits=on
Posted by Dario Faggioli 3 years, 5 months ago
On Wed, 2022-08-17 at 11:18 -0600, Jim Fehlig wrote:
> On 8/17/22 08:47, Jim Fehlig wrote:
> > On 8/17/22 02:19, Lin Ma wrote:
> > > Besides the -cpu host, The host-phys-bits=on applies to custom or
> > > max
> > > cpu model, So the host-passthrough validation check is
> > > unnecessary for
> > > maxphysaddr with mode='passthrough'.
> > 
> > I wonder why Dario added the check? He even added a test for it: 
> > cpu-phys-bits-passthrough2 in qemuxml2argvtest. He is off now, so
> > we'll have to 
> > await his return for an answer.
> 
> BTW, I'm not doubting your analysis. In fact, I tested with one of
> the known CPU 
> models (-cpu Cascadelake-Server,...,host-phys-bits=on) and it worked
> fine with a 
> 7TB VM. I'd still like to know why Dario added the check. Perhaps he
> encountered 
> some problematic corner cases.
>
Not really, no. IIRC, QEMU was behaving differently than how it work
this days, when I wrote this, but even back then host-phys-bits=on was
fine with -cpu != host.

The check is there just because I thought that, if you're using a
specific CPU model, and not host-passthrough, that's probably because
you don't want the host details to "leak" into the VM (for migration or
whatever). Hence, you shouldn't use phys-bits passthrough either.

Like, you need the CPU to be CascadeLake-Server for migration purposes,
your host has 52 bits and you know you need a large VM so instead of
wasting time doing the math, you just go for passthrough (for the phys
bits, of course). Then you migrate on an host with 46 bits, which would
also have been fine for the size VM, but now, since you've basically
used 52, it's a problem.

But maybe this is not something that should be solved at this level, as
it's probably the job of `virsh cpu-baseline`? Does that includes and
takes into account this aspect (phys-bits) already?

So, yeah, if that check was too much policying, I think it's fine to
get rid of it. Nothing should explode :-)

Thanks and Regards
-- 
Dario Faggioli, Ph.D
http://about.me/dario.faggioli
Virtualization Software Engineer
SUSE Labs, SUSE https://www.suse.com/
-------------------------------------------------------------------
<<This happens because _I_ choose it to happen!>> (Raistlin Majere)
Re: [libvirt] [PATCH 2/2] qemu: Remove host-passthrough validation check for host-phys-bits=on
Posted by Jim Fehlig 3 years, 5 months ago
On 9/2/22 08:50, Dario Faggioli wrote:
> On Wed, 2022-08-17 at 11:18 -0600, Jim Fehlig wrote:
>> On 8/17/22 08:47, Jim Fehlig wrote:
>>> On 8/17/22 02:19, Lin Ma wrote:
>>>> Besides the -cpu host, The host-phys-bits=on applies to custom or
>>>> max
>>>> cpu model, So the host-passthrough validation check is
>>>> unnecessary for
>>>> maxphysaddr with mode='passthrough'.
>>>
>>> I wonder why Dario added the check? He even added a test for it:
>>> cpu-phys-bits-passthrough2 in qemuxml2argvtest. He is off now, so
>>> we'll have to
>>> await his return for an answer.
>>
>> BTW, I'm not doubting your analysis. In fact, I tested with one of
>> the known CPU
>> models (-cpu Cascadelake-Server,...,host-phys-bits=on) and it worked
>> fine with a
>> 7TB VM. I'd still like to know why Dario added the check. Perhaps he
>> encountered
>> some problematic corner cases.
>>
> Not really, no. IIRC, QEMU was behaving differently than how it work
> this days, when I wrote this, but even back then host-phys-bits=on was
> fine with -cpu != host.
> 
> The check is there just because I thought that, if you're using a
> specific CPU model, and not host-passthrough, that's probably because
> you don't want the host details to "leak" into the VM (for migration or
> whatever). Hence, you shouldn't use phys-bits passthrough either.

Hmm, an interesting point...

> Like, you need the CPU to be CascadeLake-Server for migration purposes,
> your host has 52 bits and you know you need a large VM so instead of
> wasting time doing the math, you just go for passthrough (for the phys
> bits, of course). Then you migrate on an host with 46 bits, which would
> also have been fine for the size VM, but now, since you've basically
> used 52, it's a problem.

but at least for the migration case we have that covered by the ABI stability check

https://gitlab.com/libvirt/libvirt/-/blob/master/src/conf/cpu_conf.c#L1113

> But maybe this is not something that should be solved at this level, as
> it's probably the job of `virsh cpu-baseline`? Does that includes and
> takes into account this aspect (phys-bits) already?

No, it doesn't. Could be added as a separate patch if desired.

> So, yeah, if that check was too much policying, I think it's fine to
> get rid of it. Nothing should explode :-)

Based on my somewhat limited testing, I think it is fine too. Hopefully others 
on the list will speak up if they know of a reason to keep this check. In the 
meantime, @Lin, I suggest sending a V2 of this patch with the now failing test 
removed.

Thanks,
Jim
Re: [libvirt] [PATCH 2/2] qemu: Remove host-passthrough validation check for host-phys-bits=on
Posted by Jim Fehlig 3 years, 5 months ago
On 9/2/22 09:24, Jim Fehlig wrote:
> On 9/2/22 08:50, Dario Faggioli wrote:
>> On Wed, 2022-08-17 at 11:18 -0600, Jim Fehlig wrote:
>>> On 8/17/22 08:47, Jim Fehlig wrote:
>>>> On 8/17/22 02:19, Lin Ma wrote:
>>>>> Besides the -cpu host, The host-phys-bits=on applies to custom or
>>>>> max
>>>>> cpu model, So the host-passthrough validation check is
>>>>> unnecessary for
>>>>> maxphysaddr with mode='passthrough'.
>>>>
>>>> I wonder why Dario added the check? He even added a test for it:
>>>> cpu-phys-bits-passthrough2 in qemuxml2argvtest. He is off now, so
>>>> we'll have to
>>>> await his return for an answer.
>>>
>>> BTW, I'm not doubting your analysis. In fact, I tested with one of
>>> the known CPU
>>> models (-cpu Cascadelake-Server,...,host-phys-bits=on) and it worked
>>> fine with a
>>> 7TB VM. I'd still like to know why Dario added the check. Perhaps he
>>> encountered
>>> some problematic corner cases.
>>>
>> Not really, no. IIRC, QEMU was behaving differently than how it work
>> this days, when I wrote this, but even back then host-phys-bits=on was
>> fine with -cpu != host.
>>
>> The check is there just because I thought that, if you're using a
>> specific CPU model, and not host-passthrough, that's probably because
>> you don't want the host details to "leak" into the VM (for migration or
>> whatever). Hence, you shouldn't use phys-bits passthrough either.
> 
> Hmm, an interesting point...
> 
>> Like, you need the CPU to be CascadeLake-Server for migration purposes,
>> your host has 52 bits and you know you need a large VM so instead of
>> wasting time doing the math, you just go for passthrough (for the phys
>> bits, of course). Then you migrate on an host with 46 bits, which would
>> also have been fine for the size VM, but now, since you've basically
>> used 52, it's a problem.
> 
> but at least for the migration case we have that covered by the ABI stability check
> 
> https://gitlab.com/libvirt/libvirt/-/blob/master/src/conf/cpu_conf.c#L1113

Wait, that just checks the stability of any config changes provided by the user 
when starting the migration. It doesn't check such differences between hosts 
involved in the migration. IIRC that's done elsewhere in the qemu driver, but 
I'll need to refresh my memory...

Regards,
Jim