Received: from eggs.gnu.org ([2001:4830:134:3::10]:56161) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKAlA-0000Of-4o for qemu-devel@nongnu.org; Mon, 04 Jul 2016 16:46:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKAl5-0001RG-Vc for qemu-devel@nongnu.org; Mon, 04 Jul 2016 16:46:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57438) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKAl5-0001R5-Pb for qemu-devel@nongnu.org; Mon, 04 Jul 2016 16:46:23 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 44038461D3 for ; Mon, 4 Jul 2016 20:46:23 +0000 (UTC) Date: Mon, 4 Jul 2016 17:46:21 -0300 From: Eduardo Habkost Message-ID: <20160704204621.GL4131@thinpad.lan.raisama.net> References: <1467659769-15900-1-git-send-email-dgilbert@redhat.com> <1467659769-15900-7-git-send-email-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1467659769-15900-7-git-send-email-dgilbert@redhat.com> Subject: Re: [Qemu-devel] [PATCH v2 6/6] x86: Add sanity checks on phys_bits List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Dr. David Alan Gilbert (git)" Cc: qemu-devel@nongnu.org, pbonzini@redhat.com, marcel@redhat.com, mst@redhat.com, kraxel@redhat.com On Mon, Jul 04, 2016 at 08:16:09PM +0100, Dr. David Alan Gilbert (git) wrote: > From: "Dr. David Alan Gilbert" > > 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 > --- > 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