PATCH [BZ #17259]: sysdeps/x86_64/cacheinfo.c:intel_check_word may corrupt rbx

Message ID 20140812160827.GA14354@intel.com
State Committed
Headers

Commit Message

Lu, Hongjiu Aug. 12, 2014, 4:08 p.m. UTC
  intel_check_word has

	      asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1"
			    : "=a" (eax), "=r" (ebx), "=c" (ecx), "=d" (edx)
			    : "0" (4), "2" (round));

The only register compiler isn't aware of is RBX.  No other registers are
impacted.  We are lucky that it doesn't cause any problems since RBX
is also used by compiler for other purposes so that RBX is saved and
restored in intel_check_word.  This patch uses __cpuid_count instead.
Tested on x86 and x86-64.  OK to install?

Thanks.


H.J.
---
2014-08-12  H.J. Lu  <hongjiu.lu@intel.com>

	[BZ #17259]
	* sysdeps/x86_64/cacheinfo.c (intel_check_word): Replace cpuid
	asm statement with __cpuid_count.
  

Comments

Roland McGrath Aug. 12, 2014, 4:56 p.m. UTC | #1
That looks fine and I think is wise to do despite the freeze.
But Allan will have to approve it now.
  
H.J. Lu Aug. 12, 2014, 5:05 p.m. UTC | #2
On Tue, Aug 12, 2014 at 9:56 AM, Roland McGrath <roland@hack.frob.com> wrote:
> That looks fine and I think is wise to do despite the freeze.
> But Allan will have to approve it now.

Hi Allan,

Is this OK for 2.20?

Thanks.
  
Allan McRae Aug. 12, 2014, 11:32 p.m. UTC | #3
On 13/08/14 03:05, H.J. Lu wrote:
> On Tue, Aug 12, 2014 at 9:56 AM, Roland McGrath <roland@hack.frob.com> wrote:
>> That looks fine and I think is wise to do despite the freeze.
>> But Allan will have to approve it now.
> 
> Hi Allan,
> 
> Is this OK for 2.20?
> 

OK to commit.

Thanks,
Allan
  
H.J. Lu Aug. 13, 2014, 12:06 a.m. UTC | #4
On Tue, Aug 12, 2014 at 4:32 PM, Allan McRae <allan@archlinux.org> wrote:
> On 13/08/14 03:05, H.J. Lu wrote:
>> On Tue, Aug 12, 2014 at 9:56 AM, Roland McGrath <roland@hack.frob.com> wrote:
>>> That looks fine and I think is wise to do despite the freeze.
>>> But Allan will have to approve it now.
>>
>> Hi Allan,
>>
>> Is this OK for 2.20?
>>
>
> OK to commit.
>
> Thanks,
> Allan

Done.  Thanks.
  

Patch

diff --git a/sysdeps/x86_64/cacheinfo.c b/sysdeps/x86_64/cacheinfo.c
index 163af2a..ca13a53 100644
--- a/sysdeps/x86_64/cacheinfo.c
+++ b/sysdeps/x86_64/cacheinfo.c
@@ -191,9 +191,7 @@  intel_check_word (int name, unsigned int value, bool *has_level_2,
 	  unsigned int round = 0;
 	  while (1)
 	    {
-	      asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1"
-			    : "=a" (eax), "=r" (ebx), "=c" (ecx), "=d" (edx)
-			    : "0" (4), "2" (round));
+	      __cpuid_count (4, round, eax, ebx, ecx, edx);
 
 	      enum { null = 0, data = 1, inst = 2, uni = 3 } type = eax & 0x1f;
 	      if (type == null)