diff mbox

tools/libxc: Properly increment ApicIdCoreSize field on AMD

Message ID 1469207641-20662-1-git-send-email-boris.ostrovsky@oracle.com (mailing list archive)
State New, archived
Headers show

Commit Message

Boris Ostrovsky July 22, 2016, 5:14 p.m. UTC
Current code incorrectly adds 1 to full register instead of
incrementing the field in bits 15:12.

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
---
 tools/libxc/xc_cpuid_x86.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Wei Liu July 22, 2016, 5:38 p.m. UTC | #1
On Fri, Jul 22, 2016 at 01:14:01PM -0400, Boris Ostrovsky wrote:
> Current code incorrectly adds 1 to full register instead of
> incrementing the field in bits 15:12.
> 
> Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>

Acked-by: Wei Liu <wei.liu2@citrix.com>

I trust your expertise in this field. :-)

> ---
>  tools/libxc/xc_cpuid_x86.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c
> index 84f4e08..fbbac9e 100644
> --- a/tools/libxc/xc_cpuid_x86.c
> +++ b/tools/libxc/xc_cpuid_x86.c
> @@ -331,7 +331,8 @@ static void amd_xc_cpuid_policy(xc_interface *xch,
>           * ECX[15:12] is ApicIdCoreSize: ECX[7:0] is NumberOfCores (minus one).
>           * Update to reflect vLAPIC_ID = vCPU_ID * 2.
>           */
> -        regs[2] = ((regs[2] & 0xf000u) + 1) | ((regs[2] & 0xffu) << 1) | 1u;
> +        regs[2] = ((regs[2] + (1u << 12)) & 0xf000u) |
> +                  ((regs[2] & 0xffu) << 1) | 1u;
>          break;
>  
>      case 0x8000000a: {
> -- 
> 1.8.3.1
>
Boris Ostrovsky July 22, 2016, 5:45 p.m. UTC | #2
On 07/22/2016 01:38 PM, Wei Liu wrote:
> On Fri, Jul 22, 2016 at 01:14:01PM -0400, Boris Ostrovsky wrote:
>> Current code incorrectly adds 1 to full register instead of
>> incrementing the field in bits 15:12.
>>
>> Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Acked-by: Wei Liu <wei.liu2@citrix.com>
>
> I trust your expertise in this field. :-)


Just in this field? The field is only 4 bits! ;-)

But this actually fixes a regression that was triggered by recent
hvmloader change on one particular processor that we have in the test farm.

-boris

>
>> ---
>>  tools/libxc/xc_cpuid_x86.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c
>> index 84f4e08..fbbac9e 100644
>> --- a/tools/libxc/xc_cpuid_x86.c
>> +++ b/tools/libxc/xc_cpuid_x86.c
>> @@ -331,7 +331,8 @@ static void amd_xc_cpuid_policy(xc_interface *xch,
>>           * ECX[15:12] is ApicIdCoreSize: ECX[7:0] is NumberOfCores (minus one).
>>           * Update to reflect vLAPIC_ID = vCPU_ID * 2.
>>           */
>> -        regs[2] = ((regs[2] & 0xf000u) + 1) | ((regs[2] & 0xffu) << 1) | 1u;
>> +        regs[2] = ((regs[2] + (1u << 12)) & 0xf000u) |
>> +                  ((regs[2] & 0xffu) << 1) | 1u;
>>          break;
>>  
>>      case 0x8000000a: {
>> -- 
>> 1.8.3.1
>>
Wei Liu July 22, 2016, 5:50 p.m. UTC | #3
On Fri, Jul 22, 2016 at 01:45:05PM -0400, Boris Ostrovsky wrote:
> On 07/22/2016 01:38 PM, Wei Liu wrote:
> > On Fri, Jul 22, 2016 at 01:14:01PM -0400, Boris Ostrovsky wrote:
> >> Current code incorrectly adds 1 to full register instead of
> >> incrementing the field in bits 15:12.
> >>
> >> Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> > Acked-by: Wei Liu <wei.liu2@citrix.com>
> >
> > I trust your expertise in this field. :-)
> 
> 
> Just in this field? The field is only 4 bits! ;-)
> 

No, it's only one bit! :-P

> But this actually fixes a regression that was triggered by recent
> hvmloader change on one particular processor that we have in the test farm.

Ian, this is a backport candidate and needs to go back as far as
possible. The bogus calculation was introduced in 2008 (!). 

Wei.

> 
> -boris
> 
> >
> >> ---
> >>  tools/libxc/xc_cpuid_x86.c | 3 ++-
> >>  1 file changed, 2 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c
> >> index 84f4e08..fbbac9e 100644
> >> --- a/tools/libxc/xc_cpuid_x86.c
> >> +++ b/tools/libxc/xc_cpuid_x86.c
> >> @@ -331,7 +331,8 @@ static void amd_xc_cpuid_policy(xc_interface *xch,
> >>           * ECX[15:12] is ApicIdCoreSize: ECX[7:0] is NumberOfCores (minus one).
> >>           * Update to reflect vLAPIC_ID = vCPU_ID * 2.
> >>           */
> >> -        regs[2] = ((regs[2] & 0xf000u) + 1) | ((regs[2] & 0xffu) << 1) | 1u;
> >> +        regs[2] = ((regs[2] + (1u << 12)) & 0xf000u) |
> >> +                  ((regs[2] & 0xffu) << 1) | 1u;
> >>          break;
> >>  
> >>      case 0x8000000a: {
> >> -- 
> >> 1.8.3.1
> >>
>
Ian Jackson July 25, 2016, 11:33 a.m. UTC | #4
Wei Liu writes ("Re: [PATCH] tools/libxc: Properly increment ApicIdCoreSize field on AMD"):
> On Fri, Jul 22, 2016 at 01:45:05PM -0400, Boris Ostrovsky wrote:
> > On 07/22/2016 01:38 PM, Wei Liu wrote:
> > But this actually fixes a regression that was triggered by recent
> > hvmloader change on one particular processor that we have in the test farm.
> 
> Ian, this is a backport candidate and needs to go back as far as
> possible. The bogus calculation was introduced in 2008 (!). 

Thanks, but:

Not queued for backport because the patch is not in staging.

Thanks,
Ian.
Wei Liu July 25, 2016, 1:22 p.m. UTC | #5
On Mon, Jul 25, 2016 at 12:33:37PM +0100, Ian Jackson wrote:
> Wei Liu writes ("Re: [PATCH] tools/libxc: Properly increment ApicIdCoreSize field on AMD"):
> > On Fri, Jul 22, 2016 at 01:45:05PM -0400, Boris Ostrovsky wrote:
> > > On 07/22/2016 01:38 PM, Wei Liu wrote:
> > > But this actually fixes a regression that was triggered by recent
> > > hvmloader change on one particular processor that we have in the test farm.
> > 
> > Ian, this is a backport candidate and needs to go back as far as
> > possible. The bogus calculation was introduced in 2008 (!). 
> 
> Thanks, but:
> 
> Not queued for backport because the patch is not in staging.
> 

Pushed to staging.
Ian Jackson July 26, 2016, 10 a.m. UTC | #6
Wei Liu writes ("Re: [PATCH] tools/libxc: Properly increment ApicIdCoreSize field on AMD"):
> On Mon, Jul 25, 2016 at 12:33:37PM +0100, Ian Jackson wrote:
> > Wei Liu writes ("Re: [PATCH] tools/libxc: Properly increment ApicIdCoreSize field on AMD"):
> > > Ian, this is a backport candidate and needs to go back as far as
> > > possible. The bogus calculation was introduced in 2008 (!). 
> 
> Pushed to staging.

Thanks, queued.

Ian.
diff mbox

Patch

diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c
index 84f4e08..fbbac9e 100644
--- a/tools/libxc/xc_cpuid_x86.c
+++ b/tools/libxc/xc_cpuid_x86.c
@@ -331,7 +331,8 @@  static void amd_xc_cpuid_policy(xc_interface *xch,
          * ECX[15:12] is ApicIdCoreSize: ECX[7:0] is NumberOfCores (minus one).
          * Update to reflect vLAPIC_ID = vCPU_ID * 2.
          */
-        regs[2] = ((regs[2] & 0xf000u) + 1) | ((regs[2] & 0xffu) << 1) | 1u;
+        regs[2] = ((regs[2] + (1u << 12)) & 0xf000u) |
+                  ((regs[2] & 0xffu) << 1) | 1u;
         break;
 
     case 0x8000000a: {