diff mbox

[4/7] x86/viridian: get rid of the magic numbers in CPUID leaves 1 and 2

Message ID 1489744633-28760-5-git-send-email-paul.durrant@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Paul Durrant March 17, 2017, 9:57 a.m. UTC
The numbers correspond to ASCII characters so just use appropriate
character strings directly.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
---
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
---
 xen/arch/x86/hvm/viridian.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Jan Beulich March 20, 2017, 12:15 p.m. UTC | #1
>>> On 17.03.17 at 10:57, <paul.durrant@citrix.com> wrote:
> --- a/xen/arch/x86/hvm/viridian.c
> +++ b/xen/arch/x86/hvm/viridian.c
> @@ -119,14 +119,16 @@ void cpuid_viridian_leaves(const struct vcpu *v, uint32_t leaf,
>      switch ( leaf )
>      {
>      case 0:
> +        /* See section 2.4.1 of the specification */
>          res->a = 0x40000006; /* Maximum leaf */
> -        res->b = 0x7263694d; /* Magic numbers  */
> -        res->c = 0x666F736F;
> -        res->d = 0x76482074;
> +        res->b = *(uint32_t *)"Micr";
> +        res->c = *(uint32_t *)"osof";
> +        res->d = *(uint32_t *)"t Hv";
>          break;
>  
>      case 1:
> -        res->a = 0x31237648; /* Version number */
> +        /* See section 2.4.2 of the specification */
> +        res->a = *(uint32_t *)"Hv#1";
>          break;

You're the maintainer of the code, so I can't really reject this, but
(ugly) casts don't seem any better to me, the more that they cast
away constness. Would

        memcpy(&res->a, "Hv#1", 4);

etc be acceptable to you?

Jan
Paul Durrant March 20, 2017, 12:56 p.m. UTC | #2
> -----Original Message-----
> From: Jan Beulich [mailto:JBeulich@suse.com]
> Sent: 20 March 2017 12:15
> To: Paul Durrant <Paul.Durrant@citrix.com>
> Cc: Andrew Cooper <Andrew.Cooper3@citrix.com>; xen-
> devel@lists.xenproject.org
> Subject: Re: [PATCH 4/7] x86/viridian: get rid of the magic numbers in CPUID
> leaves 1 and 2
> 
> >>> On 17.03.17 at 10:57, <paul.durrant@citrix.com> wrote:
> > --- a/xen/arch/x86/hvm/viridian.c
> > +++ b/xen/arch/x86/hvm/viridian.c
> > @@ -119,14 +119,16 @@ void cpuid_viridian_leaves(const struct vcpu *v,
> uint32_t leaf,
> >      switch ( leaf )
> >      {
> >      case 0:
> > +        /* See section 2.4.1 of the specification */
> >          res->a = 0x40000006; /* Maximum leaf */
> > -        res->b = 0x7263694d; /* Magic numbers  */
> > -        res->c = 0x666F736F;
> > -        res->d = 0x76482074;
> > +        res->b = *(uint32_t *)"Micr";
> > +        res->c = *(uint32_t *)"osof";
> > +        res->d = *(uint32_t *)"t Hv";
> >          break;
> >
> >      case 1:
> > -        res->a = 0x31237648; /* Version number */
> > +        /* See section 2.4.2 of the specification */
> > +        res->a = *(uint32_t *)"Hv#1";
> >          break;
> 
> You're the maintainer of the code, so I can't really reject this, but
> (ugly) casts don't seem any better to me, the more that they cast
> away constness. Would
> 
>         memcpy(&res->a, "Hv#1", 4);
> 
> etc be acceptable to you?

I'm ok with that.

  Paul

> 
> Jan
diff mbox

Patch

diff --git a/xen/arch/x86/hvm/viridian.c b/xen/arch/x86/hvm/viridian.c
index 433035e..4151ba5 100644
--- a/xen/arch/x86/hvm/viridian.c
+++ b/xen/arch/x86/hvm/viridian.c
@@ -119,14 +119,16 @@  void cpuid_viridian_leaves(const struct vcpu *v, uint32_t leaf,
     switch ( leaf )
     {
     case 0:
+        /* See section 2.4.1 of the specification */
         res->a = 0x40000006; /* Maximum leaf */
-        res->b = 0x7263694d; /* Magic numbers  */
-        res->c = 0x666F736F;
-        res->d = 0x76482074;
+        res->b = *(uint32_t *)"Micr";
+        res->c = *(uint32_t *)"osof";
+        res->d = *(uint32_t *)"t Hv";
         break;
 
     case 1:
-        res->a = 0x31237648; /* Version number */
+        /* See section 2.4.2 of the specification */
+        res->a = *(uint32_t *)"Hv#1";
         break;
 
     case 2: