Skip to contentSkip to conversation

Qemu support for PPC

PATCH In review Rusty Russell 6 participants 8 messages Apr 7, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Qemu support for PPC

Paul, is this OK?

I'd like it in 2.4.21 if possible.

Thanks,
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

Name: Qemu Kernel Patch for PPC
Author: Rusty Russell
Status: Tested on 2.4.21-pre6

D: Allow (0.1.5 or above) qemu to set the personality for emulation,
D: so files in /usr/gnemul/x86-linux get looked up before normal files
D: (this is the standard way of hooking in emulation libraries, etc).

Documentation/Configure.help +11 -0
diff -urpN --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.4.21-pre6/Documentation/Configure.help working-2.4.21-pre6-wagner/Documentation/Configure.help
@@ -4123,6 +4123,19 @@ CONFIG_BINFMT_JAVA
   binaries directly.  Note: this option is obsolete and scheduled for
   removal, use CONFIG_BINFMT_MISC instead.
 
+Kernel support for Linux/Intel ELF binaries
+CONFIG_X86_EMU
+  Say Y here if you want to be able to execute Linux/Intel ELF
+  binaries just like native binaries on your PPC machine. For
+  this to work, you need to have /usr/gnemul/x86-linux populated
+  with Intel libraries. etc.
+
+  You may answer M to compile the emulation support as a module and
+  later load the module when you want to use a Linux/Intel binary. The
+  module will be called x86emu.o.  If unsure, say Y.
+
 Solaris binary emulation
 CONFIG_SOLARIS_EMUL
   This is experimental code which will enable you to run (many)
arch/ppc/config.in +1 -0
diff -urpN --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.4.21-pre6/arch/ppc/config.in working-2.4.21-pre6-wagner/arch/ppc/config.in
@@ -183,6 +183,7 @@ fi
 define_bool CONFIG_BINFMT_ELF y
 define_bool CONFIG_KERNEL_ELF y
 tristate 'Kernel support for MISC binaries' CONFIG_BINFMT_MISC
+dep_tristate 'Kernel support for Linux/Intel ELF binaries' CONFIG_X86_EMU
 
 source drivers/pci/Config.in
 
arch/ppc/kernel/Makefile +1 -0
diff -urpN --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.4.21-pre6/arch/ppc/kernel/Makefile working-2.4.21-pre6-wagner/arch/ppc/kernel/Makefile
@@ -66,6 +66,7 @@ obj-$(CONFIG_PAL4)		+= indirect_pci.o pc
 obj-$(CONFIG_SPRUCE)		+= indirect_pci.o pci_auto.o todc_time.o
 obj-$(CONFIG_8260)		+= m8260_setup.o ppc8260_pic.o
 obj-$(CONFIG_BOOTX_TEXT)	+= btext.o
+obj-$(CONFIG_X86_EMU)		+= x86emu.o
 
 include $(TOPDIR)/Rules.make
 
arch/ppc/kernel/x86emu.c +29 -0
diff -urpN --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.4.21-pre6/arch/ppc/kernel/x86emu.c working-2.4.21-pre6-wagner/arch/ppc/kernel/x86emu.c
@@ -0,0 +1,29 @@
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/personality.h>
+#include <linux/binfmts.h>
+
+struct exec_domain x86_linux_exec_domain = {
+	.name		="X86LINUX",
+	.pers_low	= PER_X86_LINUX & PER_MASK,
+	.pers_high	= PER_X86_LINUX & PER_MASK,
+	.module		= THIS_MODULE
+};
+
+static int init(void)
+{
+	return register_exec_domain(&x86_linux_exec_domain);
+}
+
+static void fini(void)
+{
+	unregister_exec_domain(&x86_linux_exec_domain);
+}
+
+module_init(init);
+module_exit(fini);
+
+MODULE_DESCRIPTION("x86 Linux execution domain");
+MODULE_LICENSE("GPL");
include/asm-ppc/namei.h +9 -6
diff -urpN --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.4.21-pre6/include/asm-ppc/namei.h working-2.4.21-pre6-wagner/include/asm-ppc/namei.h
@@ -8,12 +8,15 @@
 #ifndef __PPC_NAMEI_H
 #define __PPC_NAMEI_H
 
-/* This dummy routine maybe changed to something useful
- * for /usr/gnemul/ emulation stuff.
- * Look at asm-sparc/namei.h for details.
- */
-
-#define __emul_prefix() NULL
+static inline char *__emul_prefix(void)
+{
+	switch (current->personality) {
+	case (PER_X86_LINUX & PER_MASK):
+		return "usr/gnemul/x86-linux/";
+	default:
+		return NULL;
+	}
+}
 
 #endif /* __PPC_NAMEI_H */
 #endif /* __KERNEL__ */
include/linux/personality.h +1 -0
diff -urpN --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.4.21-pre6/include/linux/personality.h working-2.4.21-pre6-wagner/include/linux/personality.h
@@ -64,6 +64,7 @@ enum {
 	PER_UW7 =		0x000e | STICKY_TIMEOUTS | MMAP_PAGE_ZERO,
 	PER_HPUX =		0x000f,
 	PER_OSF4 =		0x0010,			 /* OSF/1 v4 */
+	PER_X86_LINUX =		0x0011 | ADDR_LIMIT_32BIT,/* QEMU */
 	PER_MASK =		0x00ff,
 };
 
#1 lore raw
Quoted 3 lines · Rusty Russell

Paul, is this OK?

I'd like it in 2.4.21 if possible.

Looks good, I'd like it too.

Just one comment:

Documentation/Configure.help CONFIG_BINFMT_JAVA · line 4136

Quoted 11 lines
Documentation/Configure.help +11 -0
+Kernel support for Linux/Intel ELF binaries
+CONFIG_X86_EMU
+  Say Y here if you want to be able to execute Linux/Intel ELF
+  binaries just like native binaries on your PPC machine. For
+  this to work, you need to have /usr/gnemul/x86-linux populated
+  with Intel libraries. etc.
+
+  You may answer M to compile the emulation support as a module and
+  later load the module when you want to use a Linux/Intel binary. The
+  module will be called x86emu.o.  If unsure, say Y.
+

This should say that you need qemu as well, and it should probably include the URL to Fabrice's qemu web page.

Paul.

#2 lore raw
In reply to Rusty Russell
Quoted 3 lines · Rusty Russell

Paul, is this OK?

I'd like it in 2.4.21 if possible.

Please use sys_personality from userland. And not, I don't think it should go into 2.4.21. Get it into 2.5 first.

#3 lore raw
Quoted 6 lines · Christoph Hellwig
Quoted 3 lines · Rusty Russell

Paul, is this OK?

I'd like it in 2.4.21 if possible.

Please use sys_personality from userland.

sys_personality will fail if there isn't an exec_domain registered for the personality you want. The *whole* *point* of Rusty's patch is to add an execution domain for x86 emulation so we *can* do sys_personality.

Did you actually look at the patch, or was your mail just a knee-jerk?

Quoted 2 lines

And not, I don't think it should
go into 2.4.21. Get it into 2.5 first.

Why? It's a well-contained patch that affects very little outside its own area, and is quite similar to other things that have been there for ages. Anyway, it's not your call.

Paul.

#4 lore raw
Quoted 2 lines · Paul Mackerras

sys_personality will fail if there isn't an exec_domain registered for the personality you want.

But there already is one registered :) Okay, you\re right.

Quoted 3 lines

Why? It's a well-contained patch that affects very little outside its own area, and is quite similar to other things that have been there for ages.

Because stuff should go into 2.5 first. And even if it looks trivial
there's an important policy decision here: do we want to clutter up
our personality system for userspace emulators? If you look at the
current list of personalities they all have kernel implementations, even if not all of them are currently merged, qemu OTOH is a purely userspace thing (and still very new!). Personally I'd rather prefer qemu doing pathname translation in userspace instead of bloating the kernel. This gets even more important when we get qemu-style emulators for other architectures - the number of personalities needed just for this ugly pathname-translation scheme will get very high.

Quoted 1 line

Anyway, it's not your call.

if you look at MAINTAINERS I'm responsible for personality handling, so maybe it actually _is_ my call?

#5 lore raw
Quoted 10 lines · Christoph Hellwig
Quoted 2 lines · Paul Mackerras

sys_personality will fail if there isn't an exec_domain registered for the personality you want.

But there already is one registered :) Okay, you\re right.

Quoted 3 lines

Why? It's a well-contained patch that affects very little outside its own area, and is quite similar to other things that have been there for ages.

Quoted 10 lines

Because stuff should go into 2.5 first. And even if it looks trivial
there's an important policy decision here: do we want to clutter up
our personality system for userspace emulators? If you look at the
current list of personalities they all have kernel implementations, even if not all of them are currently merged, qemu OTOH is a purely userspace thing (and still very new!). Personally I'd rather prefer qemu doing pathname translation in userspace instead of bloating the kernel. This gets even more important when we get qemu-style emulators for other architectures - the number of personalities needed just for this ugly pathname-translation scheme will get very high.

Well, all we really want is a way to set emul_prefix. Which I could do with a PPC-specific syscall if I had to, I guess. Doing it in userspace is possible but ugly, because you have to handle several different syscalls, plus keep track of the current directory, plus handle symlinks, etc., etc., in the emulator. The kernel has all that information readily to hand plus the data structures to keep track of it all.

Quoted 4 lines
Quoted 1 line

Anyway, it's not your call.

if you look at MAINTAINERS I'm responsible for personality handling, so maybe it actually _is_ my call?

Oh. Ah. I didn't realize it was a subsystem with a maintainer.

Paul.

#6 lore raw
Quoted 7 lines · Paul Mackerras

Well, all we really want is a way to set emul_prefix. Which I could do with a PPC-specific syscall if I had to, I guess. Doing it in userspace is possible but ugly, because you have to handle several different syscalls, plus keep track of the current directory, plus handle symlinks, etc., etc., in the emulator. The kernel has all that information readily to hand plus the data structures to keep track of it all.

Why do you need emul_prefix in the first place ? You need a different /lib for emulated binaries then use all the nice stuff Al has done and mount yourself a file system that is in your namespace but not the global one.

If you want to do overlaying then lets get the union fs for read only stuff into the kernel properly and solve the -real- problem not hack up some emulator magic again.

#7 lore raw
In reply to Rusty Russell
Quoted 3 lines · Rusty Russell

Paul, is this OK?

I'd like it in 2.4.21 if possible.

[snip]

arch/ppc/config.in fi · line 189

Quoted 11 lines

diff -urpN --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.4.21-pre6/arch/ppc/config.in working-2.4.21-pre6-wagner/arch/ppc/config.in

arch/ppc/config.in +1 -0
@@ -183,6 +183,7 @@ fi
 define_bool CONFIG_BINFMT_ELF y
 define_bool CONFIG_KERNEL_ELF y
 tristate 'Kernel support for MISC binaries' CONFIG_BINFMT_MISC
+dep_tristate 'Kernel support for Linux/Intel ELF binaries' CONFIG_X86_EMU
 
 source drivers/pci/Config.in
 

dep_tristate on what? :)

Signature · 2 lines
Tom Rini
http://gate.crashing.org/~trini/