qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2 6/6] x86: Add sanity checks on phys_bits


From: Eduardo Habkost
Subject: Re: [Qemu-devel] [PATCH v2 6/6] x86: Add sanity checks on phys_bits
Date: Mon, 4 Jul 2016 17:46:21 -0300
User-agent: Mutt/1.6.1 (2016-04-27)

On Mon, Jul 04, 2016 at 08:16:09PM +0100, Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" <address@hidden>
> 
> Add some sanity checks on the phys-bits setting now that
> the user can set it.
>    a) That it's in a sane range (52..32)
>    b) Warn if it mismatches the host and isn't the old default.
> 
> Signed-off-by: Dr. David Alan Gilbert <address@hidden>
> ---
>  target-i386/cpu.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/target-i386/cpu.c b/target-i386/cpu.c
> index e15abea..5402002 100644
> --- a/target-i386/cpu.c
> +++ b/target-i386/cpu.c
> @@ -2985,6 +2985,19 @@ static void x86_cpu_realizefn(DeviceState *dev, Error 
> **errp)
>              /* The user asked for us to use the host physical bits */
>              cpu->phys_bits = host_phys_bits;
>  
> +        } else if (cpu->phys_bits > 52 || cpu->phys_bits < 32) {
> +            error_setg(errp, "phys_bits should be between 32 and 52 or 0 to"
> +                             " use host size (but is %u)", cpu->phys_bits);
> +            return;
> +        }

This check belongs to patch 1/6, doesn't it?

Here we have the same magic number (52), and I don't know where
it came from. Maybe it should become a (documented) macro?

Also, won't this make the "phys_bits < 52" check added by patch
3/6 unnecessary?

> +        /* Print a warning if the user set it to a value that's not the
> +         * host value; ignore the magic value 40 because it may well just
> +         * be the old machine type.
> +         */

With this, we won't print a warning if "phys-bits=40" is set
explicitly. If we want to disable the warning only for the old
machine-types, we can add a boolean flag that disables it.

> +        if (cpu->phys_bits != host_phys_bits && cpu->phys_bits != 40) {
> +            fprintf(stderr, "Warning: Host physical bits (%u)"
> +                            " does not match phys_bits (%u)\n",
> +                            host_phys_bits, cpu->phys_bits);

Shouldn't we use error_report() for this?

Also, this prints a warning for each VCPU. This is not the first
time we want to print a warning only once (see
x86_cpu_apic_id_from_index() in hw/i386/pc.c and ht_warned in
target-i386/cpu.c). It looks like QEMU needs a warn_once()
helper.

>          }
>      } else {
>          /* For 32 bit systems don't use the user set value, but keep
> -- 
> 2.7.4
> 

-- 
Eduardo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]