Bug#519391: libgcrypt11: SIGILL on _gcry_detect_hw_features
Hi! On Sun, 29 Nov 2009 02:04:12 +, Ben Hutchings b...@decadent.org.uk wrote: You must either change the detection code to set %0 to 0 if the condition is not met, or change =r to +r so that %0 will be initialised to the previous value of has_cpuid (i.e. 0). Thanks for this hint. It is pretty obvious. Shalom-Salam, Werner -- Die Gedanken sind frei. Ausnahmen regelt ein Bundesgesetz. -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Bug#519391: libgcrypt11: SIGILL on _gcry_detect_hw_features
On Thu, 2009-03-12 at 11:20 +0100, Werner Koch wrote: On Thu, 12 Mar 2009 09:32, dex...@debian.org said: Program received signal SIGILL, Illegal instruction. [Switching to Thread 0xb7b9c6e0 (LWP 2196)] 0xb7bae10e in _gcry_detect_hw_features () at hwfeatures.c:78 That seems to be the cpuid opcode which is not available, Linux knows about it: cpuid level : -1 but my code gets the detection wrong: /* Detect the CPUID feature by testing some undefined behaviour (16 vs 32 bit pushf/popf). */ asm volatile (pushf\n\t /* Copy flags to EAX. */ popl %%eax\n\t movl %%eax, %%ecx\n\t /* Save flags into ECX. */ xorl $0x20, %%eax\n\t /* Toggle ID bit and copy it to the flags. */ pushl %%eax\n\t popf\n\t pushf\n\t /* Copy changed flags again to EAX. */ popl %%eax\n\t pushl %%ecx\n\t /* Restore flags from ECX. */ popf\n\t xorl %%eax, %%ecx\n\t /* Compare flags against saved flags. */ jz .Lno_cpuid%=\n\t /* Toggling did not work, thus no CPUID. */ movl $1, %0\n /* Worked. true - HAS_CPUID. */ .Lno_cpuid%=:\n\t : =r (has_cpuid) [...] =r means that the code *will* write to register %0, which is then written to has_cpuid. But if this code does not detect cpuid, the register is uninitialised and probably has a non-zero value. You must either change the detection code to set %0 to 0 if the condition is not met, or change =r to +r so that %0 will be initialised to the previous value of has_cpuid (i.e. 0). Ben. -- Ben Hutchings Quantity is no substitute for quality, but it's the only one we've got. signature.asc Description: This is a digitally signed message part
Bug#519391: libgcrypt11: SIGILL on _gcry_detect_hw_features
On 2009-05-18 Piotr Roszatycki dex...@debian.org wrote: 2009/5/17 Andreas Metzler ametz...@downhill.at.eu.org: There is a second, slightly diffeent instance of the same code in boot/cpucheck.c. Does this one also prodecue the Illegal instruction error? cu and- doesn't speak ASM -reas Ping... Hi. Sorry for delay. I can't compile this code: $ gcc -o cpuid2 cpuid2.c cpuid2.c: Assembler messages: cpuid2.c:16: Error: suffix or operands invalid for `pushf' cpuid2.c:16: Error: suffix or operands invalid for `pushf' cpuid2.c:16: Error: suffix or operands invalid for `pop' cpuid2.c:16: Error: suffix or operands invalid for `push' cpuid2.c:16: Error: suffix or operands invalid for `popf' cpuid2.c:16: Error: suffix or operands invalid for `pushf' cpuid2.c:16: Error: suffix or operands invalid for `pop' cpuid2.c:16: Error: suffix or operands invalid for `popf' Perhaps you could send me binary to run? Strange, it builds for me on i486, but fails to build on amd64. Extrapolationg from that I would assume building in i386 should work. :-( cu andreas -- `What a good friend you are to him, Dr. Maturin. His other friends are so grateful to you.' `I sew his ears on from time to time, sure' -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Bug#519391: libgcrypt11: SIGILL on _gcry_detect_hw_features
2009/5/18 Andreas Metzler ametz...@downhill.at.eu.org: Perhaps you could send me binary to run? Strange, it builds for me on i486, but fails to build on amd64. Extrapolationg from that I would assume building in i386 should work. Ah, thanks. I've forgot this is i386-only code. I'm afraid this is the same as previous: $ gdb ./cpuid2 GNU gdb 6.8-debian Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type show copying and show warranty for details. This GDB was configured as i486-linux-gnu... (gdb) r Starting program: /media/FreeAgentDesktop/.home/dexter/cpuid2 This CPU has CPUID opcode Program received signal SIGILL, Illegal instruction. 0x08048464 in cpuid (op=0, eax=0xbfe3f36c, ebx=0xbfe3f368, ecx=0xbfe3f364, edx=0xbfe3f360) at cpuid2.c:41 41 __asm__(cpuid (gdb) -- .''`.Piotr Roszatycki : :' :mailto:piotr.roszaty...@gmail.com `. `' mailto:dex...@debian.org `- -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Bug#519391: libgcrypt11: SIGILL on _gcry_detect_hw_features
Hi. Sorry for delay. I can't compile this code: $ gcc -o cpuid2 cpuid2.c cpuid2.c: Assembler messages: cpuid2.c:16: Error: suffix or operands invalid for `pushf' cpuid2.c:16: Error: suffix or operands invalid for `pushf' cpuid2.c:16: Error: suffix or operands invalid for `pop' cpuid2.c:16: Error: suffix or operands invalid for `push' cpuid2.c:16: Error: suffix or operands invalid for `popf' cpuid2.c:16: Error: suffix or operands invalid for `pushf' cpuid2.c:16: Error: suffix or operands invalid for `pop' cpuid2.c:16: Error: suffix or operands invalid for `popf' Perhaps you could send me binary to run? 2009/5/17 Andreas Metzler ametz...@downhill.at.eu.org: There is a second, slightly diffeent instance of the same code in boot/cpucheck.c. Does this one also prodecue the Illegal instruction error? cu and- doesn't speak ASM -reas Ping... -- .''`.Piotr Roszatycki : :' :mailto:piotr.roszaty...@gmail.com `. `' mailto:dex...@debian.org `- -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Bug#519391: libgcrypt11: SIGILL on _gcry_detect_hw_features
On 2009-05-02 Andreas Metzler ametz...@downhill.at.eu.org wrote: On 2009-03-12 Piotr Roszatycki dex...@debian.org wrote: I read the source for kernel 2.6.24 and found that it uses similar technic for CPUID detection. I've copied to one simple test program (attached) and I worried why it doesn't work on Vortex correcty: $ ./cpuid This CPU has CPUID opcode Illegal instruction Any ideas? Would anyone be so kind and compare it to the Linux code? There is a second, slightly diffeent instance of the same code in boot/cpucheck.c. Does this one also prodecue the Illegal instruction error? cu and- doesn't speak ASM -reas Ping... -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Bug#519391: libgcrypt11: SIGILL on _gcry_detect_hw_features
On 2009-03-12 Piotr Roszatycki dex...@debian.org wrote: I read the source for kernel 2.6.24 and found that it uses similar technic for CPUID detection. I've copied to one simple test program (attached) and I worried why it doesn't work on Vortex correcty: $ ./cpuid This CPU has CPUID opcode Illegal instruction Any ideas? Would anyone be so kind and compare it to the Linux code? There is a second, slightly diffeent instance of the same code in boot/cpucheck.c. Does this one also prodecue the Illegal instruction error? cu and- doesn't speak ASM -reas -- `What a good friend you are to him, Dr. Maturin. His other friends are so grateful to you.' `I sew his ears on from time to time, sure' #include stdio.h #define __cold __attribute__((__cold__)) #define __section(S) __attribute__ ((__section__(#S))) #define __cpuinit__section(.cpuinit.text) __cold #define X86_EFLAGS_ID 0x0020 /* CPUID detection flag */ typedef unsigned int u32; static int has_eflag(u32 mask) { u32 f0, f1; asm(pushfl ; pushfl ; popl %0 ; movl %0,%1 ; xorl %2,%1 ; pushl %1 ; popfl ; pushfl ; popl %1 ; popfl : =r (f0), =r (f1) : ri (mask)); return !!((f0^f1) mask); } /* Probe for the CPUID instruction */ static int __cpuinit have_cpuid_p(void) { return has_eflag(X86_EFLAGS_ID); } /* Generix CPUID */ static inline void cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx) { __asm__(cpuid : =a (*eax), =b (*ebx), =c (*ecx), =d (*edx) : 0 (op), c(0)); } int main() { int id0, id1, id2, id3; printf(This CPU %s CPUID opcode\n, (have_cpuid_p ? has : has not)); /* Get vendor name and crash on Vortex86SX */ cpuid(0x, id0, (int *)id1, (int *)id2, (int *)id3); printf(%d %d %d\n, id0 , id1 , id2); }
Bug#519391: libgcrypt11: SIGILL on _gcry_detect_hw_features
Package: libgcrypt11 Version: 1.4.4-2 Severity: grave I've found this bug calling lpstat from cupsys: $ gdb lpstat Program received signal SIGILL, Illegal instruction. [Switching to Thread 0xb7b9c6e0 (LWP 2196)] 0xb7bae10e in _gcry_detect_hw_features () at hwfeatures.c:78 78 hwfeatures.c: No such file or directory. in hwfeatures.c It means the libgcrypt11 uses opcodes illegal on real 486-compatible machine, like Vortex86SX: $ cat /proc/cpuinfo processor : 0 vendor_id : unknown cpu family : 4 model : 0 model name : 486 stepping: unknown fdiv_bug: no hlt_bug : no f00f_bug: no coma_bug: no fpu : no fpu_exception : no cpuid level : -1 wp : yes flags : bogomips: 98.30 clflush size: 32 -- .''`.Piotr Roszatycki : :' :mailto:piotr.roszaty...@gmail.com `. `' mailto:dex...@debian.org `- -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Bug#519391: libgcrypt11: SIGILL on _gcry_detect_hw_features
On Thu, 12 Mar 2009 09:32, dex...@debian.org said: Program received signal SIGILL, Illegal instruction. [Switching to Thread 0xb7b9c6e0 (LWP 2196)] 0xb7bae10e in _gcry_detect_hw_features () at hwfeatures.c:78 That seems to be the cpuid opcode which is not available, Linux knows about it: cpuid level : -1 but my code gets the detection wrong: /* Detect the CPUID feature by testing some undefined behaviour (16 vs 32 bit pushf/popf). */ asm volatile (pushf\n\t /* Copy flags to EAX. */ popl %%eax\n\t movl %%eax, %%ecx\n\t /* Save flags into ECX. */ xorl $0x20, %%eax\n\t /* Toggle ID bit and copy it to the flags. */ pushl %%eax\n\t popf\n\t pushf\n\t /* Copy changed flags again to EAX. */ popl %%eax\n\t pushl %%ecx\n\t /* Restore flags from ECX. */ popf\n\t xorl %%eax, %%ecx\n\t /* Compare flags against saved flags. */ jz .Lno_cpuid%=\n\t /* Toggling did not work, thus no CPUID. */ movl $1, %0\n /* Worked. true - HAS_CPUID. */ .Lno_cpuid%=:\n\t : =r (has_cpuid) : : %eax, %ecx, cc ); if (!has_cpuid) return; /* No way. */ Any ideas? Would anyone be so kind and compare it to the Linux code? A workaround is to use ./configure --disable-padlock-support However, that makes it slow on VIA CPUs. Shalom-Salam, Werner -- Die Gedanken sind frei. Auschnahme regelt ein Bundeschgesetz. -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Bug#519391: libgcrypt11: SIGILL on _gcry_detect_hw_features
I read the source for kernel 2.6.24 and found that it uses similar technic for CPUID detection. I've copied to one simple test program (attached) and I worried why it doesn't work on Vortex correcty: $ ./cpuid This CPU has CPUID opcode Illegal instruction Any ideas? Would anyone be so kind and compare it to the Linux code? -- .''`.Piotr Roszatycki : :' :mailto:piotr.roszaty...@gmail.com `. `' mailto:dex...@debian.org `- #include stdio.h #define __cold __attribute__((__cold__)) #define __section(S) __attribute__ ((__section__(#S))) #define __cpuinit__section(.cpuinit.text) __cold #define X86_EFLAGS_ID 0x0020 /* CPUID detection flag */ typedef unsigned int u32; /* Standard macro to see if a specific flag is changeable */ static inline int flag_is_changeable_p(u32 flag) { u32 f1, f2; asm(pushfl\n\t pushfl\n\t popl %0\n\t movl %0,%1\n\t xorl %2,%0\n\t pushl %0\n\t popfl\n\t pushfl\n\t popl %0\n\t popfl\n\t : =r (f1), =r (f2) : ir (flag)); return ((f1^f2) flag) != 0; } /* Probe for the CPUID instruction */ static int __cpuinit have_cpuid_p(void) { return flag_is_changeable_p(X86_EFLAGS_ID); } /* Generix CPUID */ static inline void cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx) { __asm__(cpuid : =a (*eax), =b (*ebx), =c (*ecx), =d (*edx) : 0 (op), c(0)); } int main() { int id0, id1, id2, id3; printf(This CPU %s CPUID opcode\n, (have_cpuid_p ? has : has not)); /* Get vendor name and crash on Vortex86SX */ cpuid(0x, id0, (int *)id1, (int *)id2, (int *)id3); }