public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: i686 quirk for AMD Geode
@ 2009-11-06 15:49 Martin Schleier
  2009-11-06 15:59 ` Alan Cox
  0 siblings, 1 reply; 137+ messages in thread
From: Martin Schleier @ 2009-11-06 15:49 UTC (permalink / raw)
  To: Matteo Croce, mingo; +Cc: linux-kernel, hpa

On Fri, 6 Nov 2009 15:59:16 +0100 Matteo Croce wrote:
> On Sat, Oct 3, 2009 at 8:21 AM, Ingo Molnar <mingo@elte.hu> wrote:
> >
> > * Matteo Croce <technoboy85@gmail.com> wrote:
[snip]
> > Looks good, but your signoff line is missing.
> >
> >        Ingo
> >
> 
> The AMD Geode LX has an x86 id of 5 (i586) tought it's technically an
> i686:
> 
> root@alix:~# egrep '^(cpu family|model name|flags)' /proc/cpuinfo
> cpu family      : 5
> model name      : Geode(TM) Integrated Processor by AMD PCS
> flags           : fpu de pse tsc msr cx8 sep pge cmov clflush mmx
> mmxext 3dnowext 3dnow
> 
> indeed it has MMX, MMXEXT and CMOV, just lacks the long NOP instruction
> (NOPL).
> This patch adds a quirck to promote the Geode to an i686 and emulates
> the NOPL in the do_invalid_op trap, so the userspace never notices.
> Emulating the NOPL has minimum performance loss, emulating a NOPL
> takes 0.5 usecs
> and they are rarely used in x86
> 
> Signed-off-by: Matteo Croce <technoboy85@gmail.com>
> 
> --- a/arch/x86/kernel/Makefile	2009-11-06 15:06:52.246223989 +0100
> +++ b/arch/x86/kernel/Makefile	2009-11-06 15:07:04.294054613 +0100
> @@ -89,7 +89,7 @@
>  obj-$(CONFIG_HPET_TIMER) 	+= hpet.o
> 
>  obj-$(CONFIG_K8_NB)		+= k8.o
> -obj-$(CONFIG_MGEODE_LX)		+= geode_32.o mfgpt_32.o
> +obj-$(CONFIG_MGEODE_LX)		+= geode_32.o mfgpt_32.o nopl_emu.o
>  obj-$(CONFIG_DEBUG_RODATA_TEST)	+= test_rodata.o
>  obj-$(CONFIG_DEBUG_NX_TEST)	+= test_nx.o
> 
> --- a/arch/x86/kernel/cpu/amd.c	2009-11-06 15:06:52.254223805 +0100
> +++ b/arch/x86/kernel/cpu/amd.c	2009-11-06 15:07:04.294054613 +0100
> @@ -138,8 +138,10 @@
>  	}
> 
>  	if (c->x86_model == 10) {
> -		/* AMD Geode LX is model 10 */
> -		/* placeholder for any needed mods */
> +		/* Geode only lacks the NOPL instruction to be i686,
> +		   but we can emulate it in the exception handler
> +		   and promote it to a class 6 cpu */
> +		boot_cpu_data.x86 = 6;
>  		return;
>  	}
>  }
> --- a/arch/x86/kernel/entry_32.S	2009-11-06 15:06:52.258224172 +0100
> +++ b/arch/x86/kernel/entry_32.S	2009-11-06 15:07:04.306230613 +0100
> @@ -901,7 +901,11 @@
>  	RING0_INT_FRAME
>  	pushl $0
>  	CFI_ADJUST_CFA_OFFSET 4
> +#ifdef CONFIG_MGEODE_LX
> +	pushl $do_nopl_emu
> +#else
>  	pushl $do_invalid_op
> +#endif
>  	CFI_ADJUST_CFA_OFFSET 4
>  	jmp error_code
>  	CFI_ENDPROC
> --- /dev/null	1970-01-01 00:00:00.000000000 +0000
> +++ b/arch/x86/kernel/nopl_emu.c	2009-11-06 15:07:33.537723795 +0100
> @@ -0,0 +1,102 @@
> +/*
> + *  linux/arch/x86/kernel/nopl_emu.c
> + *
> + *  Copyright (C) 2002  Willy Tarreau
> + *  Copyright (C) 2009  Matteo Croce
> + */
> +
> +#include <linux/sched.h>
> +#include <linux/linkage.h>
> +#include <linux/preempt.h>
> +#include <linux/types.h>
> +
> +void do_invalid_op(struct pt_regs *regs, long error_code);
> +
> +/* This code can be used to allow the AMD Geode to hopefully correctly
> execute
> + * some code which was originally compiled for an i686, by emulating
> NOPL,
> + * the only missing i686 instruction in the CPU
> + *
> + * Willy Tarreau <willy@meta-x.org>
> + * Matteo Croce <technoboy85@gmail.com>
> + */
> +
> +static inline int do_1f(u8 *ip)
> +{
> +	int length = 3;
> +	switch(*ip) {
> +		case 0x84:if(!ip[5])
> +				length++;
> +			else
> +				return 0;
> +		case 0x80:if(!ip[4] && !ip[3])
> +				length += 2;
> +			else
> +				return 0;
> +		case 0x44:if(!ip[2])
> +				length++;
> +			else
> +				return 0;
> +		case 0x40:if(!ip[1])
> +				length++;
> +			else
> +				return 0;
> +		case 0x00:return length;
> +		default: return 0;
> +	}
> +	return length;
> +}
> +
> +static inline int do_0f(u8 *ip)
> +{
> +	if(*ip == 0x1f)
> +		return do_1f(ip + 1);
> +	return 0;
> +}
> +
> +static inline int do_66(u8 *ip)
> +{
> +	if(*ip == 0x90)
> +		return 2;
> +	if(*ip == 0x0f) {
> +		int res = do_0f(ip + 1);
> +		if(res)
> +			return res + 1;
> +		else
> +			return 0;
> +	}
> +	return 0;
> +}
> +
> +static inline int do_start(u8 *ip)
> +{
> +	if(*ip == 0x0f)
> +		return do_0f(ip + 1);
> +	if(*ip == 0x66)
> +		return do_66(ip + 1);
> +	return 0;
> +}
> +
> +/* [do_nopl_emu] is called by exception 6 after an invalid opcode has
> been
> + * encountered. It will try to emulate it by doing nothing,
> + * and will send a SIGILL or SIGSEGV to the process if not possible.
> + * the NOPL can have variable length opcodes:
> +
> +bytes number	opcode
> +	2	66 90
> +	3	0f 1f 00
> +	4	0f 1f 40 00
> +	5	0f 1f 44 00 00
> +	6	66 0f 1f 44 00 00
> +	7	0f 1f 80 00 00 00 00
> +	8	0f 1f 84 00 00 00 00 00
> +	9	66 0f 1f 84 00 00 00 00 00
> +*/
> +void do_nopl_emu(struct pt_regs *regs, long error_code)
> +{
> +	int res = do_start((u8*)regs->ip);
> +
> +	if(res)
> +		regs->ip += res;
> +	else
> +		do_invalid_op(regs, error_code);
> +}
> --

Looks good? checkpatch.pl has a very different opinion.

WARNING: externs should be avoided in .c files
#56: FILE: arch/x86/kernel/nopl_emu.c:13:
+void do_invalid_op(struct pt_regs *regs, long error_code);

ERROR: switch and case should be at the same indent
#69: FILE: arch/x86/kernel/nopl_emu.c:26:
+	switch(*ip) {
+		case 0x84:if(!ip[5])
[...]
+		case 0x80:if(!ip[4] && !ip[3])
[...]
+		case 0x44:if(!ip[2])
[...]
+		case 0x40:if(!ip[1])
[...]
+		case 0x00:return length;
+		default: return 0;

ERROR: space required before the open parenthesis '('
#69: FILE: arch/x86/kernel/nopl_emu.c:26:
+	switch(*ip) {

ERROR: space required before the open parenthesis '('
#70: FILE: arch/x86/kernel/nopl_emu.c:27:
+		case 0x84:if(!ip[5])

ERROR: trailing statements should be on next line
#70: FILE: arch/x86/kernel/nopl_emu.c:27:
+		case 0x84:if(!ip[5])

ERROR: space required before the open parenthesis '('
#74: FILE: arch/x86/kernel/nopl_emu.c:31:
+		case 0x80:if(!ip[4] && !ip[3])

ERROR: trailing statements should be on next line
#74: FILE: arch/x86/kernel/nopl_emu.c:31:
+		case 0x80:if(!ip[4] && !ip[3])

ERROR: space required before the open parenthesis '('
#78: FILE: arch/x86/kernel/nopl_emu.c:35:
+		case 0x44:if(!ip[2])

ERROR: trailing statements should be on next line
#78: FILE: arch/x86/kernel/nopl_emu.c:35:
+		case 0x44:if(!ip[2])

ERROR: space required before the open parenthesis '('
#82: FILE: arch/x86/kernel/nopl_emu.c:39:
+		case 0x40:if(!ip[1])

ERROR: trailing statements should be on next line
#82: FILE: arch/x86/kernel/nopl_emu.c:39:
+		case 0x40:if(!ip[1])

ERROR: space required before the open parenthesis '('
#94: FILE: arch/x86/kernel/nopl_emu.c:51:
+	if(*ip == 0x1f)

ERROR: space required before the open parenthesis '('
#101: FILE: arch/x86/kernel/nopl_emu.c:58:
+	if(*ip == 0x90)

ERROR: space required before the open parenthesis '('
#103: FILE: arch/x86/kernel/nopl_emu.c:60:
+	if(*ip == 0x0f) {

ERROR: space required before the open parenthesis '('
#105: FILE: arch/x86/kernel/nopl_emu.c:62:
+		if(res)

ERROR: space required before the open parenthesis '('
#115: FILE: arch/x86/kernel/nopl_emu.c:72:
+	if(*ip == 0x0f)

ERROR: space required before the open parenthesis '('
#117: FILE: arch/x86/kernel/nopl_emu.c:74:
+	if(*ip == 0x66)

ERROR: "(foo*)" should be "(foo *)"
#139: FILE: arch/x86/kernel/nopl_emu.c:96:
+	int res = do_start((u8*)regs->ip);

ERROR: space required before the open parenthesis '('
#141: FILE: arch/x86/kernel/nopl_emu.c:98:
+	if(res)

ERROR: Missing Signed-off-by: line(s)

total: 19 errors, 1 warnings, 133 lines checked

This patch has style problems, please review.
If any of these errors are false positives report them
to the maintainer, see CHECKPATCH in MAINTAINERS.

-- 
DSL-Preisknaller: DSL Komplettpakete von GMX schon für 
16,99 Euro mtl.!* Hier klicken: http://portal.gmx.net/de/go/dsl02

^ permalink raw reply	[flat|nested] 137+ messages in thread
* Re: i686 quirk for AMD Geode
@ 2009-11-08 22:10 H. Peter Anvin
  2009-11-09  0:22 ` Alan Cox
  0 siblings, 1 reply; 137+ messages in thread
From: H. Peter Anvin @ 2009-11-08 22:10 UTC (permalink / raw)
  To: Alan Cox, Pavel Machek
  Cc: Matteo Croce, Sven-Haegar Koch, Ingo Molnar, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1164 bytes --]

Keep in mind that if we end up running that on code with any kind of significant fraction of CMOV it will utterly suck.  Count 500-odd cycles per emulated instruction.  It *is* still useful in some cases - which is why we have x87 emulation already, for example.  The question is mostly where the point of diminishing returns go.  In theory we could provide a full x86 interpreter (perhaps shared with KVM?) which would allow any instruction at all to be executed.

"Alan Cox" <alan@lxorguk.ukuu.org.uk> wrote:

>> > Better to be sure that a NOPL whouldn't SIGILL your program, isn't
>> > it?
>> 
>> SIGILL is easier to debug than NOPL mysteriously taking 100x time it
>> should, sorry.
>
>And a working 686 distribution is a great deal more useful to end users,
>who outnumber you by a few million to one. It's a very sensible patch, or
>perhaps you'd prefer we didn't say. And you forget the user "debug" for
>a Geode + i686 without this will be "it hangs when I try and boot the
>install CD"
>
>It would probably also be worth having cmov fixups for the VIA C3 as well.
>
>Alan

--
Sent from my mobile phone. Please excuse any lack of formatting.

^ permalink raw reply	[flat|nested] 137+ messages in thread
* i686 quirk for AMD Geode
@ 2009-10-03  2:12 Matteo Croce
  2009-10-03  2:34 ` H. Peter Anvin
                   ` (3 more replies)
  0 siblings, 4 replies; 137+ messages in thread
From: Matteo Croce @ 2009-10-03  2:12 UTC (permalink / raw)
  To: H. Peter Anvin; +Cc: linux-kernel

Hi,

the AMD GEode LX has an x86 id of 5 (i586) tought it's technically an i686:

root@alix:/usr/src# cat /proc/cpuinfo
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 5
model           : 10
model name      : Geode(TM) Integrated Processor by AMD PCS
stepping        : 2
cpu MHz         : 498.060
cache size      : 128 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 1
wp              : yes
flags           : fpu de pse tsc msr cx8 sep pge cmov clflush mmx
mmxext 3dnowext 3dnow
bogomips        : 996.12
clflush size    : 32
cache_alignment : 32
address sizes   : 32 bits physical, 32 bits virtual
power management:

indeed it has mmx, mmxext and cmov.
So I added the quirk below and I can confirm that the system is running fine.
I did an x264 encode to trigger any SIGILL due to missing opcodes, but
it worked.

I also did this simple test which gives a ~2.5x speed boost:
http://pastebin.ca/1590089

I wish some feedback from someone, I really dunno why AMD set the
cpuid value to 5

--- a/arch/x86/kernel/cpu/bugs.c	2009-10-03 03:43:02.399323313 +0200
+++ b/arch/x86/kernel/cpu/bugs.c	2009-10-03 03:54:22.582205090 +0200
@@ -151,6 +151,12 @@
 #endif
 }

+static void __init check_geode_i586(void)
+{
+	if(boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
+	   boot_cpu_data.x86_model == 10 && boot_cpu_data.x86 == 5)
+		boot_cpu_data.x86 = 6;
+}

 void __init check_bugs(void)
 {
@@ -163,6 +169,7 @@
 	check_fpu();
 	check_hlt();
 	check_popad();
+	check_geode_i586();
 	init_utsname()->machine[1] =
 		'0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
 	alternative_instructions();

^ permalink raw reply	[flat|nested] 137+ messages in thread

end of thread, other threads:[~2009-11-23 20:03 UTC | newest]

Thread overview: 137+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-06 15:49 i686 quirk for AMD Geode Martin Schleier
2009-11-06 15:59 ` Alan Cox
2009-11-06 16:42   ` Matteo Croce
2009-11-06 16:57   ` Martin Schleier
2009-11-06 18:22     ` Alan Cox
2009-11-06 20:06       ` Martin Schleier
     [not found]         ` <20091106210259.290b281a@lxorguk.ukuu.org.uk>
2009-11-06 22:33           ` Martin Schleier
2009-11-06 23:05         ` Krzysztof Halasa
2009-11-07  0:05           ` Martin Schleier
2009-11-07 10:37             ` Krzysztof Halasa
2009-11-07 13:43               ` SubmittingPatches guidelines (was: Re: i686 quirk for AMD Geode) Martin Schleier
2009-11-07 22:30                 ` Krzysztof Halasa
2009-11-07 11:11             ` i686 quirk for AMD Geode Matteo Croce
2009-11-08  2:14               ` H. Peter Anvin
2009-11-08 16:05               ` Andres Salomon
2009-11-08 18:04                 ` Matteo Croce
2009-11-08 18:46                   ` Andres Salomon
2009-11-08 18:22                 ` Matteo Croce
2009-11-08 18:47                   ` Andres Salomon
2009-11-10  5:58                     ` Willy Tarreau
  -- strict thread matches above, loose matches on Subject: below --
2009-11-08 22:10 H. Peter Anvin
2009-11-09  0:22 ` Alan Cox
2009-10-03  2:12 Matteo Croce
2009-10-03  2:34 ` H. Peter Anvin
2009-10-03  3:08   ` Matteo Croce
2009-10-03  2:35 ` H. Peter Anvin
2009-10-03  7:21 ` Ingo Molnar
2009-10-03  9:53   ` Matteo Croce
2009-10-03 14:12     ` H. Peter Anvin
2009-10-03 14:56       ` Matteo Croce
2009-11-06 14:59   ` Matteo Croce
2009-11-06 16:44     ` H. Peter Anvin
2009-11-06 22:18       ` Matteo Croce
2009-11-07  0:49         ` Alan Cox
2009-11-08 17:37         ` Pavel Machek
2009-11-08 17:40           ` Matteo Croce
2009-11-08 18:10             ` Pavel Machek
2009-11-08 18:13               ` Matteo Croce
2009-11-08 19:29               ` Sven-Haegar Koch
2009-11-08 19:36                 ` Pavel Machek
2009-11-08 19:47                   ` Matteo Croce
2009-11-08 19:51                     ` Pavel Machek
2009-11-08 20:08                       ` Alan Cox
2009-11-10  5:27                         ` Willy Tarreau
2009-11-10  6:02                           ` H. Peter Anvin
2009-11-10 10:41                             ` Avi Kivity
2009-11-10 10:56                               ` Alan Cox
2009-11-10 17:08                                 ` H. Peter Anvin
2009-11-10 17:24                                   ` Alan Cox
2009-11-10 18:49                                     ` H. Peter Anvin
2009-11-10 19:50                                       ` Avi Kivity
2009-11-10 20:01                                         ` H. Peter Anvin
2009-11-10 20:16                                           ` Willy Tarreau
2009-11-10 20:25                                             ` H. Peter Anvin
2009-11-10 20:34                                               ` Willy Tarreau
2009-11-10 20:54                                             ` Pavel Machek
2009-11-10 21:12                                               ` Willy Tarreau
2009-11-10 21:19                                                 ` H. Peter Anvin
2009-11-10 22:06                                                   ` Willy Tarreau
2009-11-10 22:15                                                     ` H. Peter Anvin
2009-11-10 22:20                                                       ` Ingo Molnar
2009-11-10 22:42                                                         ` Willy Tarreau
2009-11-10 22:47                                                           ` H. Peter Anvin
2009-11-11  5:52                                                             ` Willy Tarreau
2009-11-11  6:15                                                               ` H. Peter Anvin
2009-11-11  6:36                                                                 ` Willy Tarreau
2009-11-11  7:57                                                                   ` H. Peter Anvin
2009-11-11  9:32                                                                     ` Willy Tarreau
2009-11-12  2:23                                                                       ` Matt Thrailkill
2009-11-12  5:27                                                                         ` Willy Tarreau
2009-11-12  5:31                                                                           ` H. Peter Anvin
2009-11-12  5:40                                                                             ` Willy Tarreau
2009-11-23 19:27                                                                               ` Eric W. Biederman
2009-11-23 19:35                                                                                 ` H. Peter Anvin
2009-11-23 20:03                                                                                   ` Eric W. Biederman
2009-11-11 10:03                                                                 ` Alan Cox
2009-11-11  8:17                                                               ` Pavel Machek
2009-11-10 22:21                                                       ` Willy Tarreau
2009-11-11 10:21                                                     ` Alan Cox
2009-11-11 10:43                                                       ` Willy Tarreau
2009-11-11 16:15                                                         ` H. Peter Anvin
2009-11-10 22:27                                                   ` Lennart Sorensen
2009-11-10 22:29                                                     ` H. Peter Anvin
2009-11-10 22:34                                                       ` Lennart Sorensen
2009-11-10 22:38                                                         ` H. Peter Anvin
2009-11-10 22:54                                                           ` Lennart Sorensen
2009-11-11  8:03                                                 ` Pavel Machek
2009-11-11  9:35                                                   ` Willy Tarreau
2009-11-10 21:21                                               ` Matt Thrailkill
2009-11-10 21:26                                                 ` H. Peter Anvin
2009-11-10 22:01                                               ` Matteo Croce
2009-11-10 22:10                                                 ` Willy Tarreau
2009-11-11 10:54                                               ` Bernd Petrovitsch
2009-11-12  0:51                                       ` Daniel Pittman
2009-11-12  1:00                                         ` H. Peter Anvin
2009-11-10 16:29                               ` H. Peter Anvin
2009-11-08 19:46                 ` Matteo Croce
2009-11-08 19:50                   ` Pavel Machek
2009-11-08 20:41                 ` Krzysztof Halasa
2009-11-08 18:42       ` Matteo Croce
2009-11-09 20:16         ` Lennart Sorensen
2009-11-09 21:03           ` Matteo Croce
2009-11-09 21:17           ` H. Peter Anvin
2009-11-09 21:23             ` Lennart Sorensen
2009-11-12 12:18               ` Pavel Machek
2009-11-13  2:03                 ` Andres Salomon
2009-11-13 10:50                 ` Alan Cox
2009-11-13 16:23                 ` Lennart Sorensen
2009-11-13 16:57                   ` Alan Cox
2009-11-13 19:24                     ` Lennart Sorensen
2009-11-13 21:21                       ` Alan Cox
2009-11-16 17:50                         ` Lennart Sorensen
2009-11-17 11:59                           ` Alan Cox
2009-11-17 14:34                             ` Lennart Sorensen
2009-11-17 16:43                               ` H. Peter Anvin
2009-11-17 17:10                                 ` Lennart Sorensen
2009-11-17 16:48                             ` Valdis.Kletnieks
2009-11-17 17:25                               ` Lennart Sorensen
2009-11-17 17:33                                 ` H. Peter Anvin
2009-11-17 18:33                                   ` Lennart Sorensen
2009-11-18 20:21                                     ` Lennart Sorensen
2009-11-18 20:59                                       ` H. Peter Anvin
2009-11-18 21:11                                         ` Lennart Sorensen
2009-11-19  0:41                                           ` Lennart Sorensen
2009-11-13  5:55               ` Yuhong Bao
2009-11-13 16:24                 ` Lennart Sorensen
2009-11-13 13:33               ` Pádraig Brady
2009-11-13 16:25                 ` Lennart Sorensen
2009-11-08 17:35     ` Pavel Machek
2009-10-03 18:05 ` Arjan van de Ven
2009-10-03 22:04   ` Matteo Croce
2009-10-03 22:32     ` Gabor Gombas
2009-10-03 22:54       ` Matteo Croce
2009-10-04  7:29         ` Gabor Gombas
2009-10-04  2:25     ` Arjan van de Ven
2009-10-04 14:58       ` Alan Cox
2009-11-09 21:14         ` H. Peter Anvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox