From: "Jan Beulich" Subject: x86: fix rdrand asm() Date: Wed, 25 Sep 2013 16:46:52 +0100 Message-ID: <5243218C02000078000F66E5@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part00331C7C.0__=" Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VOrIN-0005rf-Aa for xen-devel@lists.xenproject.org; Wed, 25 Sep 2013 15:46:31 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Keir Fraser List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part00331C7C.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Just learned the hard way that at least for non-volatile asm()s gcc indeed does what the documentation says: It may move it across jumps (i.e. ahead of the cpu_has() check). While the documentation claims that this can also happen for volatile asm()s, if that was the case we'd have many more problems in our code (and e,g, Linux would too). Signed-off-by: Jan Beulich --- a/xen/include/asm-x86/random.h +++ b/xen/include/asm-x86/random.h @@ -8,7 +8,7 @@ static inline unsigned int arch_get_rand unsigned int val =3D 0; =20 if ( cpu_has(¤t_cpu_data, X86_FEATURE_RDRAND) ) - asm ( ".byte 0x0f,0xc7,0xf0" : "+a" (val) ); + __asm__ __volatile__ ( ".byte 0x0f,0xc7,0xf0" : "+a" (val) ); =20 return val; } --=__Part00331C7C.0__= Content-Type: text/plain; name="x86-rdrand-asm-volatile.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-rdrand-asm-volatile.patch" x86: fix rdrand asm()=0A=0AJust learned the hard way that at least for = non-volatile asm()s gcc=0Aindeed does what the documentation says: It may = move it across jumps=0A(i.e. ahead of the cpu_has() check). While the = documentation claims=0Athat this can also happen for volatile asm()s, if = that was the case=0Awe'd have many more problems in our code (and e,g, = Linux would too).=0A=0ASigned-off-by: Jan Beulich =0A=0A= --- a/xen/include/asm-x86/random.h=0A+++ b/xen/include/asm-x86/random.h=0A@= @ -8,7 +8,7 @@ static inline unsigned int arch_get_rand=0A unsigned = int val =3D 0;=0A =0A if ( cpu_has(¤t_cpu_data, X86_FEATURE_RDRAN= D) )=0A- asm ( ".byte 0x0f,0xc7,0xf0" : "+a" (val) );=0A+ = __asm__ __volatile__ ( ".byte 0x0f,0xc7,0xf0" : "+a" (val) );=0A =0A = return val;=0A }=0A --=__Part00331C7C.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part00331C7C.0__=--