[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 05/17] target-i386: replace uint32_t vendor fiel
From: |
Eduardo Habkost |
Subject: |
Re: [Qemu-devel] [PATCH 05/17] target-i386: replace uint32_t vendor fields by vendor string in x86_def_t |
Date: |
Tue, 15 Jan 2013 08:53:08 -0200 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Mon, Jan 14, 2013 at 10:52:52PM +0100, Igor Mammedov wrote:
[...]
> > > @@ -987,9 +937,7 @@ static void kvm_cpu_fill_host(x86_def_t *x86_cpu_def)
> > > x86_cpu_def->vendor_override = 0;
> > >
> > > /* Call Centaur's CPUID instruction. */
> > > - if (x86_cpu_def->vendor1 == CPUID_VENDOR_VIA_1 &&
> > > - x86_cpu_def->vendor2 == CPUID_VENDOR_VIA_2 &&
> > > - x86_cpu_def->vendor3 == CPUID_VENDOR_VIA_3) {
> > > + if (!strcmp(x86_cpu_def->vendor, CPUID_VENDOR_VIA)) {
> >
> > I'd be more comfortable doing such comparisons with a length or, even
> > better, using a static inline helper doing so: In this case
> > ("CentaurHauls") it happens to work but I'm worried about setting a bad
> > example that gets copied-and-pasted.
> x86_cpu_vendor_words2str() guaranties that x86_cpu_def->vendor is nill
> terminated string, would you prefer:
>
> if (!strncmp(x86_cpu_def->vendor, CPUID_VENDOR_VIA,
> sizeof(x86_cpu_def->vendor)))
>
> instead?
I believe Andreas is worrying in case there are NUL characters in the
middle of the vendor info. e.g., this wouldn't work:
#define CPUID_VENDOR_FOOBAR "foo\0bar\0baz\0".
[...]
if (!strncmp(x86_cpu_def->vendor, CPUID_VENDOR_FOOBAR,
sizeof(x86_cpu_def->vendor)))
[...]
It's true that CPU vendors can do whatever they want and return anything
on the CPUID vendor leaf, but I believe this is never going to happen
because vendors know it would be a bad idea to do that. And if it
happens one day, we can easily add additional vendor1/vendor2/vendor3
properties to allow low-level setting of the vendor ID bytes.
[...]
> > > @@ -1616,10 +1552,8 @@ int cpu_x86_register(X86CPU *cpu, const char
> > > *cpu_model)
> > > error_setg(&error, "Invalid cpu_model string format: %s",
> > > cpu_model);
> > > goto out;
> > > }
> > > - assert(def->vendor1);
> > > - env->cpuid_vendor1 = def->vendor1;
> > > - env->cpuid_vendor2 = def->vendor2;
> > > - env->cpuid_vendor3 = def->vendor3;
> > > + assert(def->vendor[0]);
> >
> > Instead of asserting on an empty string here, we should set the Error*
> > inside the property setter.
> x86_cpuid_set_vendor() you've added some time ago, already checks for value
> to be 12 characters exactly. If it is not, it sets *Error
> Reason I've kept assert here is that after patch vendor in this place would
> represent built-in vendor value, so it would be easier to detect invalid
> default value by aborting here (it wouldn't be valid for cpu sub-classes
> though).
> But this check is really redundant, would you like it to be dropped?
Well, every assert is _supposed_ to be redundant, right? I mean: we only
add assert()s to the code when we are already confident that other parts
of the code make sure the assert is never going to fail. I would like to
keep it.
--
Eduardo
[Qemu-devel] [PATCH 07/17] target-i386: prepare cpu_x86_parse_featurestr() to return a set of key, value property pairs, Igor Mammedov, 2013/01/10
[Qemu-devel] [PATCH 08/17] target-i386: set custom 'vendor' without intermediate x86_def_t, Igor Mammedov, 2013/01/10
[Qemu-devel] [PATCH 10/17] target-i386: set custom 'xlevel' without intermediate x86_def_t, Igor Mammedov, 2013/01/10
[Qemu-devel] [PATCH 11/17] target-i386: set custom 'level' without intermediate x86_def_t, Igor Mammedov, 2013/01/10
[Qemu-devel] [PATCH 12/17] target-i386: set custom 'model-id' without intermediate x86_def_t, Igor Mammedov, 2013/01/10
[Qemu-devel] [PATCH 09/17] target-i386: print deprecated warning if xlevel < 0x80000000, Igor Mammedov, 2013/01/10
[Qemu-devel] [PATCH 13/17] target-i386: set custom 'stepping' without intermediate x86_def_t, Igor Mammedov, 2013/01/10
[Qemu-devel] [PATCH 17/17] target-i386: remove setting tsc-frequency from x86_def_t, Igor Mammedov, 2013/01/10