[Qemu-devel] [PATCH] Workaround to the real-mode/protected-mode conflict in GDB.

2012-01-24 Thread Laurent Vivier
When qemu is started with '-S' to freeze at startup and gdb is connected to
inner gdb server, gdb is using by default 16-bit real-mode. Then if we put
a breakpoint inside kernel linux, the CPU is switched to 32/64-bit protected
mode but GDB is always in 16 bit real-mode. The size of the registers dump
differs and GDB is not able to manage it.

See the following thread for more details:

"Failed to use gdb with qemu 15.1 (with and without kvm support)"
http://permalink.gmane.org/gmane.comp.emulators.qemu/133120

By adding a breakpoint at startup, we can connect GDB to qemu gdb server
when CPU is already in protected mode.

Example:

- find the address of the symbol to stop on.

  $ nm ../linux/vmlinux | grep start_kernel
81ad391f T start_kernel
81ad334a T x86_64_start_kernel
81ad6a9c T xen_start_kernel

- Then start qemu with the breakpoint option (-hb):

  ./x86_64-softmmu/qemu-system-x86_64 -kernel ../linux/arch/x86/boot/bzImage \
  -append console=ttyS0 -nographic \
  -hb 0x81ad391f

- and now start GDB:

  $ gdb
  (gdb) set arch i386:x86-64
  The target architecture is assumed to be i386:x86-64
  (gdb) sym vmlinux
  Reading symbols   from /home/laurent/linux/vmlinux...done.
  (gdb) target remote :1234
  Remote debugging using :1234
  start_kernel () at init/main.c:468
  468   {
  (gdb) x/i $pc
  => 0x81ad391f : push   %rbp
  (gdb) c

Signed-off-by: Laurent Vivier 
---
 gdbstub.c   |5 -
 gdbstub.h   |2 +-
 monitor.c   |2 +-
 qemu-options.hx |   10 ++
 vl.c|   11 ++-
 5 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index 640cf4e..e27c262 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2860,7 +2860,7 @@ static void gdb_sigterm_handler(int signal)
 }
 #endif
 
-int gdbserver_start(const char *device)
+int gdbserver_start(const char *device, unsigned long long hbreak)
 {
 GDBState *s;
 char gdbstub_device_name[128];
@@ -2916,6 +2916,9 @@ int gdbserver_start(const char *device)
 s->state = chr ? RS_IDLE : RS_INACTIVE;
 s->mon_chr = mon_chr;
 
+if (hbreak != (unsigned long long)-1) {
+gdb_breakpoint_insert(hbreak, 1, GDB_BREAKPOINT_HW);
+}
 return 0;
 }
 #endif
diff --git a/gdbstub.h b/gdbstub.h
index d82334f..25d34ed 100644
--- a/gdbstub.h
+++ b/gdbstub.h
@@ -35,7 +35,7 @@ void gdb_register_coprocessor(CPUState *env,
 #ifdef CONFIG_USER_ONLY
 int gdbserver_start(int);
 #else
-int gdbserver_start(const char *port);
+int gdbserver_start(const char *port, unsigned long long hbreak);
 #endif
 
 /* in gdbstub-xml.c, generated by scripts/feature_to_c.sh */
diff --git a/monitor.c b/monitor.c
index 1be222e..208624b 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1137,7 +1137,7 @@ static void do_gdbserver(Monitor *mon, const QDict *qdict)
 const char *device = qdict_get_try_str(qdict, "device");
 if (!device)
 device = "tcp::" DEFAULT_GDBSTUB_PORT;
-if (gdbserver_start(device) < 0) {
+if (gdbserver_start(device, -1) < 0) {
 monitor_printf(mon, "Could not open gdbserver on device '%s'\n",
device);
 } else if (strcmp(device, "none") == 0) {
diff --git a/qemu-options.hx b/qemu-options.hx
index b3db10c..c0d2435 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2194,6 +2194,16 @@ Shorthand for -gdb tcp::1234, i.e. open a gdbserver on 
TCP port 1234
 (@pxref{gdb_usage}).
 ETEXI
 
+DEF("hb", HAS_ARG, QEMU_OPTION_breakpoint, \
+"-hb addrset an hardware breakpoint at address addr\n",
+QEMU_ARCH_ALL)
+STEXI
+@item -hb @var{addr}
+@findex -hb
+Set an hardware breakpoint at address @var{addr}, by default implies "-s".
+ETEXI
+
+
 DEF("d", HAS_ARG, QEMU_OPTION_d, \
 "-d item1,...output log to /tmp/qemu.log (use -d ? for a list of log 
items)\n",
 QEMU_ARCH_ALL)
diff --git a/vl.c b/vl.c
index 5372a96..9e5dc64 100644
--- a/vl.c
+++ b/vl.c
@@ -188,6 +188,7 @@ int mem_prealloc = 0; /* force preallocation of physical 
target memory */
 int nb_nics;
 NICInfo nd_table[MAX_NICS];
 int autostart;
+unsigned long long hbreak;
 static int rtc_utc = 1;
 static int rtc_date_offset = -1; /* -1 means no change */
 QEMUClock *rtc_clock;
@@ -,6 +2223,7 @@ int main(int argc, char **argv, char **envp)
 nb_nics = 0;
 
 autostart= 1;
+hbreak = -1;
 
 /* first pass of option parsing */
 optind = 1;
@@ -2582,6 +2584,13 @@ int main(int argc, char **argv, char **envp)
 case QEMU_OPTION_S:
 autostart = 0;
 break;
+case QEMU_OPTION_breakpoint:
+   hbreak = strtoull(optarg, NULL, 0);
+/* hbreak needs a gdb server */
+if (gdbstub_dev == NULL) {
+   gdbstub_dev = 

Re: [Qemu-devel] [PATCH 0/4] linux-user: A serie of patches to set default CPU

2012-01-31 Thread Laurent Vivier
Le mardi 31 janvier 2012 à 22:01 +0200, Riku Voipio a écrit :
> On Sun, Jan 22, 2012 at 01:27:13PM +0100, Laurent Vivier wrote:
> > This serie of patches has already been sent, more or less, several time,
> > last time in july 2011.
>  
> > For chrooted environment, it allows to define the default cpu model as we 
> > can't use '-cpu' argument.
> 
> We now can, with QEMU_CPU enviroment variable. 

Yes, but to define the default CPU is also interesting, it avoids to set
the variable if we know we always want to run the same CPU.

Regards,
Laurent





[Qemu-devel] [PATCH] linux-user: convert /proc/net/route when endianess differs between target and host.

2012-12-08 Thread Laurent Vivier
Signed-off-by: Laurent Vivier 
---
 linux-user/syscall.c |   42 ++
 1 file changed, 42 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e4291ed..0415135 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5085,6 +5085,45 @@ static int open_self_auxv(void *cpu_env, int fd)
 return 0;
 }
 
+#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
+static int open_net_route(void *cpu_env, int fd)
+{
+FILE *fp;
+char *line = NULL;
+size_t len = 0;
+ssize_t read;
+
+fp = fopen("/proc/net/route", "r");
+if (fp == NULL) {
+return -EACCES;
+}
+
+/* read header */
+
+read = getline(&line, &len, fp);
+dprintf(fd, "%s", line);
+
+/* read routes */
+
+while ((read = getline(&line, &len, fp)) != -1) {
+char iface[16];
+uint32_t dest, gw, mask;
+unsigned int flags, refcnt, use, metric, mtu, window, irtt;
+sscanf(line, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n",
+ iface, &dest, &gw, &flags, &refcnt, &use, &metric,
+ &mask, &mtu, &window, &irtt);
+dprintf(fd, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n",
+iface, tswap32(dest), tswap32(gw), flags, refcnt, use,
+metric, tswap32(mask), mtu, window, irtt);
+}
+
+free(line);
+fclose(fp);
+
+return 0;
+}
+#endif
+
 static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
 {
 struct fake_open {
@@ -5096,6 +5135,9 @@ static int do_open(void *cpu_env, const char *pathname, 
int flags, mode_t mode)
 { "/proc/self/maps", open_self_maps },
 { "/proc/self/stat", open_self_stat },
 { "/proc/self/auxv", open_self_auxv },
+#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
+{ "/proc/net/route", open_net_route },
+#endif
 { NULL, NULL }
 };
 
-- 
1.7.10.4




[Qemu-devel] [PATCH] linux-user: correctly align types in thunking code

2012-12-08 Thread Laurent Vivier
Signed-off-by: Laurent Vivier 
---
 thunk.h |   22 +-
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/thunk.h b/thunk.h
index 87025c3..d3e9f3d 100644
--- a/thunk.h
+++ b/thunk.h
@@ -151,20 +151,32 @@ static inline int thunk_type_align(const argtype 
*type_ptr, int is_host)
 case TYPE_CHAR:
 return 1;
 case TYPE_SHORT:
-return 2;
+if (is_host) {
+return __alignof__(short);
+} else {
+return TARGET_SHORT_ALIGNMENT;
+}
 case TYPE_INT:
-return 4;
+if (is_host) {
+return __alignof__(int);
+} else {
+return TARGET_INT_ALIGNMENT;
+}
 case TYPE_LONGLONG:
 case TYPE_ULONGLONG:
-return 8;
+if (is_host) {
+return __alignof__(long long);
+} else {
+return TARGET_LLONG_ALIGNMENT;
+}
 case TYPE_LONG:
 case TYPE_ULONG:
 case TYPE_PTRVOID:
 case TYPE_PTR:
 if (is_host) {
-return sizeof(void *);
+return __alignof__(long);
 } else {
-return TARGET_ABI_BITS / 8;
+return TARGET_LONG_ALIGNMENT;
 }
 break;
 case TYPE_OLDDEVT:
-- 
1.7.10.4




[Qemu-devel] [PATCH] linux-user: add string type in rtentry struct             to be able to pass the device name

2012-12-08 Thread Laurent Vivier
Signed-off-by: Laurent Vivier 
---
 linux-user/syscall.c   |   64 
 linux-user/syscall_types.h |4 ++-
 2 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 0415135..849fc7a 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3691,6 +3691,70 @@ static IOCTLEntry ioctl_entries[] = {
 { 0, 0, },
 };
 
+static void target_to_host_string (void *dst, const void *src)
+{
+#if HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 32
+if (*(uint32_t*)src == 0) {
+*(uint32_t*)dst = 0;
+   return;
+}
+*(uint32_t *)dst = (uint32_t)g2h(tswap32(*(uint32_t *)src));
+#elif HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 32
+if (*(uint32_t*)src == 0) {
+*(uint64_t*)dst = 0;
+   return;
+}
+*(uint64_t *)dst = (uint64_t)g2h(tswap32(*(uint32_t *)src));
+#elif HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64
+if (*(uint64_t*)src == 0) {
+*(uint64_t*)dst = 0;
+   return;
+}
+*(uint64_t *)dst = (uint64_t)g2h(tswap64(*(uint64_t *)src));
+#elif HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 64
+if (*(uint64_t*)src == 0) {
+*(uint32_t*)dst = 0;
+   return;
+}
+*(uint32_t *)dst = (uint32_t)g2h(tswap64(*(uint64_t *)src));
+#endif
+}
+
+static void host_to_target_string (void *dst, const void *src)
+{
+#if HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 32
+if (*(uint32_t*)src == 0) {
+*(uint32_t*)dst = 0;
+   return;
+}
+*(uint32_t *)dst = tswap32(h2g(*(uint32_t *)src));
+#elif HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 32
+if (*(uint64_t*)src == 0) {
+*(uint32_t*)dst = 0;
+   return;
+}
+*(uint32_t *)dst = tswap32(h2g(*(uint64_t *)src));
+#elif HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64
+if (*(uint64_t*)src == 0) {
+*(uint64_t*)dst = 0;
+   return;
+}
+*(uint64_t *)dst = tswap64(h2g(*(uint64_t *)src));
+#elif HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 64
+if (*(uint32_t*)src == 0) {
+*(uint64_t*)dst = 0;
+   return;
+}
+*(uint64_t *)dst = tswap64(h2g(*(uint32_t *)src));
+#endif
+}
+
+static const StructEntry struct_string_def = {
+.convert = { host_to_target_string, target_to_host_string },
+.size = { sizeof(target_long), sizeof(long) },
+.align = { __alignof__(target_long), __alignof__(long) },
+};
+
 /* ??? Implement proper locking for ioctls.  */
 /* do_ioctl() Must return target values and target errnos. */
 static abi_long do_ioctl(int fd, abi_long cmd, abi_long arg)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 44b6a58..51fc023 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -14,9 +14,11 @@ STRUCT(serial_icounter_struct,
 STRUCT(sockaddr,
TYPE_SHORT, MK_ARRAY(TYPE_CHAR, 14))
 
+STRUCT_SPECIAL(string)
+
 STRUCT(rtentry,
TYPE_ULONG, MK_STRUCT(STRUCT_sockaddr), MK_STRUCT(STRUCT_sockaddr), 
MK_STRUCT(STRUCT_sockaddr),
-   TYPE_SHORT, TYPE_SHORT, TYPE_ULONG, TYPE_PTRVOID, TYPE_SHORT, 
TYPE_PTRVOID,
+   TYPE_SHORT, TYPE_SHORT, TYPE_ULONG, TYPE_PTRVOID, TYPE_SHORT, 
MK_STRUCT(STRUCT_string),
TYPE_ULONG, TYPE_ULONG, TYPE_SHORT)
 
 STRUCT(ifmap,
-- 
1.7.10.4




[Qemu-devel] [PATCH] linux-user: allow to use sudo in guest qemu must have suid/gid bit and root owner/group

2012-12-08 Thread Laurent Vivier
Signed-off-by: Laurent Vivier 
---
 linux-user/linuxload.c |   12 +++-
 linux-user/main.c  |3 +++
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c
index 381ab89..0fccf58 100644
--- a/linux-user/linuxload.c
+++ b/linux-user/linuxload.c
@@ -58,11 +58,6 @@ static int prepare_binprm(struct linux_binprm *bprm)
 bprm->e_uid = geteuid();
 bprm->e_gid = getegid();
 
-/* Set-uid? */
-if(mode & S_ISUID) {
-   bprm->e_uid = st.st_uid;
-}
-
 /* Set-gid? */
 /*
  * If setgid is set but no group execute bit then this
@@ -72,6 +67,13 @@ static int prepare_binprm(struct linux_binprm *bprm)
 if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
bprm->e_gid = st.st_gid;
 }
+setresgid(getgid(), bprm->e_gid, bprm->e_gid);
+
+/* Set-uid? */
+if(mode & S_ISUID) {
+   bprm->e_uid = st.st_uid;
+}
+setresuid(getuid(), bprm->e_uid, bprm->e_uid);
 
 retval = read(bprm->fd, bprm->buf, BPRM_BUF_SIZE);
 if (retval < 0) {
diff --git a/linux-user/main.c b/linux-user/main.c
index 25e35cd..3cddb2e 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3400,6 +3400,9 @@ int main(int argc, char **argv, char **envp)
 int i;
 int ret;
 
+seteuid(getuid());
+setegid(getgid());
+
 module_call_init(MODULE_INIT_QOM);
 
 qemu_cache_utils_init(envp);
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH] linux-user: correctly align types in thunking code

2012-12-08 Thread Laurent Vivier
Le samedi 08 décembre 2012 à 16:40 +, Peter Maydell a écrit :
> On 8 December 2012 15:18, Laurent Vivier  wrote:
> > Signed-off-by: Laurent Vivier 
> 
> This kind of patch really needs an explanation (and ideally
> test case) of what the bug is that it is attempting to fix...

Yes... of course, but sometime no one reads my patches, so I was
lazy ;-)

The 3 first patches I sent today allow to run netstat and route in a
linux container with qemu linux-user (qemu-m68k in my case).

The first one, obviously, allows to have IP addresses in correct order
in the case of "netstat -nr".

The second one, allows to use the command "route". This is a follow up
of patch:

commit c2e3dee6e03527baf8698698cce76b1a3174969a
Author: Laurent Vivier 
Date:   Sun Feb 13 23:37:34 2011 +0100

linux-user: Define target alignment size

In my case m68k aligns "int" on 2 not 4. You can check this with the
following program:

#include 
#include 
#include 

int main(void)
{
struct rtentry rt;
printf("rt_pad1 %ld %zd\n", offsetof(struct rtentry, rt_pad1),
sizeof(rt.rt_pad1));
printf("rt_dst %ld %zd\n", offsetof(struct rtentry, rt_dst),
sizeof(rt.rt_dst));
printf("rt_gateway %ld %zd\n", offsetof(struct rtentry, rt_gateway),
sizeof(rt.rt_gateway));
printf("rt_genmask %ld %zd\n", offsetof(struct rtentry, rt_genmask),
sizeof(rt.rt_genmask));
printf("rt_flags %ld %zd\n", offsetof(struct rtentry, rt_flags),
sizeof(rt.rt_flags));
printf("rt_pad2 %ld %zd\n", offsetof(struct rtentry, rt_pad2),
sizeof(rt.rt_pad2));
printf("rt_pad3 %ld %zd\n", offsetof(struct rtentry, rt_pad3),
sizeof(rt.rt_pad3));
printf("rt_pad4 %ld %zd\n", offsetof(struct rtentry, rt_pad4),
sizeof(rt.rt_pad4));
printf("rt_metric %ld %zd\n", offsetof(struct rtentry, rt_metric),
sizeof(rt.rt_metric));
printf("rt_dev %ld %zd\n", offsetof(struct rtentry, rt_dev),
sizeof(rt.rt_dev));
}

On x86_64:

rt_pad1 0 8
rt_dst 8 16
rt_gateway 24 16
rt_genmask 40 16
rt_flags 56 2
rt_pad2 58 2
rt_pad3 64 8
rt_pad4 74 6
rt_metric 80 2
rt_dev 88 8

on m68k:

rt_pad1 0 4
rt_dst 4 16
rt_gateway 20 16
rt_genmask 36 16
rt_flags 52 2
rt_pad2 54 2
rt_pad3 56 4
rt_pad4 62 2
rt_metric 64 2
rt_dev 66 4


The third one, allows to set the interface for the command "route", for
instance : route add -net default gw 10.0.3.1 eth0

Obviously, If patches seem correct for everyone, I can resend them with
comments and in a serie.

Bonus: To test this, find attached a little script that will compile
qemu-m68k, install debian etch-m68k in a linux container. Then you will
be able to run debian m68k system with "sudo lxc-start -n virtm68k".
(tested on an ubuntu 12.10, you should check that lxc creates a lxcbr0
bridge with IP address 10.0.3.1). Check variable at the beginning for
the paths used.

Regards,
Laurent
--
"Just play. Have fun. Enjoy the game."


create-m68k-lxc.sh
Description: application/shellscript


Re: [Qemu-devel] [PATCH] linux-user: correctly align types in thunking code

2012-12-08 Thread Laurent Vivier
Le samedi 08 décembre 2012 à 17:55 +0100, Andreas Färber a écrit :
> Am 08.12.2012 16:18, schrieb Laurent Vivier:
> > Signed-off-by: Laurent Vivier 
> > ---
> >  thunk.h |   22 +-
> >  1 file changed, 17 insertions(+), 5 deletions(-)
> > 
> > diff --git a/thunk.h b/thunk.h
> > index 87025c3..d3e9f3d 100644
> > --- a/thunk.h
> > +++ b/thunk.h
> > @@ -151,20 +151,32 @@ static inline int thunk_type_align(const argtype 
> > *type_ptr, int is_host)
> >  case TYPE_CHAR:
> >  return 1;
> >  case TYPE_SHORT:
> > -return 2;
> > +if (is_host) {
> > +return __alignof__(short);
> 
> Might __alignof__() depend on a certain GCC version? Is it supported by
> clang?

I'm a big fan of copy&paste: I took them from linux-user/syscall.c :

static const StructEntry struct_termios_def = {
.convert = { host_to_target_termios, target_to_host_termios },
.size = { sizeof(struct target_termios), sizeof(struct host_termios) },
.align = { __alignof__(struct target_termios), __alignof__(struct 
host_termios) },
};

Regards,
Laurent




[Qemu-devel] [PATCH] linux-user: convert /proc/net/route when endianess differs

2012-12-20 Thread Laurent Vivier
This patch allows to have IP addresses in correct order
in the case of "netstat -nr" when the endianess of the
guest differs from one of the host.

For instance, an m68k guest on an x86_64 host:

WITHOUT this patch:

$ netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags   MSS Window  irtt Iface
0.0.0.0 1.3.0.100.0.0.0 UG0 0  0 eth0
0.3.0.100.0.0.0 0.255.255.255   U 0 0  0 eth0
$ cat /proc/net/route
Iface   Destination Gateway Flags   RefCnt  Use Metric  Mask
MTU Window  IRTT

eth00103000A00030   0   0   
0   0   0
eth00003000A00010   0   0   
00FF0   0   0

WITH this patch:

$ netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags   MSS Window  irtt Iface
0.0.0.0 10.0.3.10.0.0.0 UG0 0  0 eth0
10.0.3.00.0.0.0 255.255.255.0   U 0 0  0 eth0
$ cat /proc/net/route
Iface   Destination Gateway Flags   RefCnt  Use Metric  Mask
MTU Window  IRTT
eth00a00030100030   0   0   
0   0   0
eth00a00030000010   0   0   
ff000   0   0

Signed-off-by: Laurent Vivier 
---
 linux-user/syscall.c |   42 ++
 1 file changed, 42 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e99adab..501002b 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5085,6 +5085,45 @@ static int open_self_auxv(void *cpu_env, int fd)
 return 0;
 }
 
+#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
+static int open_net_route(void *cpu_env, int fd)
+{
+FILE *fp;
+char *line = NULL;
+size_t len = 0;
+ssize_t read;
+
+fp = fopen("/proc/net/route", "r");
+if (fp == NULL) {
+return -EACCES;
+}
+
+/* read header */
+
+read = getline(&line, &len, fp);
+dprintf(fd, "%s", line);
+
+/* read routes */
+
+while ((read = getline(&line, &len, fp)) != -1) {
+char iface[16];
+uint32_t dest, gw, mask;
+unsigned int flags, refcnt, use, metric, mtu, window, irtt;
+sscanf(line, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n",
+ iface, &dest, &gw, &flags, &refcnt, &use, &metric,
+ &mask, &mtu, &window, &irtt);
+dprintf(fd, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n",
+iface, tswap32(dest), tswap32(gw), flags, refcnt, use,
+metric, tswap32(mask), mtu, window, irtt);
+}
+
+free(line);
+fclose(fp);
+
+return 0;
+}
+#endif
+
 static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
 {
 struct fake_open {
@@ -5096,6 +5135,9 @@ static int do_open(void *cpu_env, const char *pathname, 
int flags, mode_t mode)
 { "/proc/self/maps", open_self_maps },
 { "/proc/self/stat", open_self_stat },
 { "/proc/self/auxv", open_self_auxv },
+#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
+{ "/proc/net/route", open_net_route },
+#endif
 { NULL, NULL }
 };
 
-- 
1.7.10.4




[Qemu-devel] [PATCH] linux-user: correctly align types in thunking code

2012-12-20 Thread Laurent Vivier
This is a follow up
of patch:

commit c2e3dee6e03527baf8698698cce76b1a3174969a
Author: Laurent Vivier 
Date:   Sun Feb 13 23:37:34 2011 +0100

linux-user: Define target alignment size

In my case m68k aligns "int" on 2 not 4. You can check this with the
following program:

int main(void)
{
struct rtentry rt;
printf("rt_pad1 %ld %zd\n", offsetof(struct rtentry, rt_pad1),
sizeof(rt.rt_pad1));
printf("rt_dst %ld %zd\n", offsetof(struct rtentry, rt_dst),
sizeof(rt.rt_dst));
printf("rt_gateway %ld %zd\n", offsetof(struct rtentry, rt_gateway),
sizeof(rt.rt_gateway));
printf("rt_genmask %ld %zd\n", offsetof(struct rtentry, rt_genmask),
sizeof(rt.rt_genmask));
printf("rt_flags %ld %zd\n", offsetof(struct rtentry, rt_flags),
sizeof(rt.rt_flags));
printf("rt_pad2 %ld %zd\n", offsetof(struct rtentry, rt_pad2),
sizeof(rt.rt_pad2));
printf("rt_pad3 %ld %zd\n", offsetof(struct rtentry, rt_pad3),
sizeof(rt.rt_pad3));
printf("rt_pad4 %ld %zd\n", offsetof(struct rtentry, rt_pad4),
sizeof(rt.rt_pad4));
printf("rt_metric %ld %zd\n", offsetof(struct rtentry, rt_metric),
sizeof(rt.rt_metric));
printf("rt_dev %ld %zd\n", offsetof(struct rtentry, rt_dev),
sizeof(rt.rt_dev));
printf("rt_mtu %ld %zd\n", offsetof(struct rtentry, rt_mtu),
sizeof(rt.rt_mtu));
printf("rt_window %ld %zd\n", offsetof(struct rtentry, rt_window),
sizeof(rt.rt_window));
printf("rt_irtt %ld %zd\n", offsetof(struct rtentry, rt_irtt),
sizeof(rt.rt_irtt));
}

And result is :

i386

rt_pad1 0 4
rt_dst 4 16
rt_gateway 20 16
rt_genmask 36 16
rt_flags 52 2
rt_pad2 54 2
rt_pad3 56 4
rt_pad4 62 2
rt_metric 64 2
rt_dev 68 4
rt_mtu 72 4
rt_window 76 4
rt_irtt 80 2

m68k

rt_pad1 0 4
rt_dst 4 16
rt_gateway 20 16
rt_genmask 36 16
rt_flags 52 2
rt_pad2 54 2
rt_pad3 56 4
rt_pad4 62 2
rt_metric 64 2
rt_dev 66 4
rt_mtu 70 4
rt_window 74 4
rt_irtt 78 2

This affects the "route" command :

WITHOUT this patch:

$ sudo route add -net default gw 10.0.3.1 window 1024 irtt 2 eth0
$ netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags   MSS Window  irtt Iface
0.0.0.0 10.0.3.10.0.0.0 UG0 67108866  32768 eth0
10.0.3.00.0.0.0 255.255.255.0   U 0 0  0 eth0

WITH this patch:

$ sudo route add -net default gw 10.0.3.1 window 1024 irtt 2 eth0
$ netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags   MSS Window  irtt Iface
0.0.0.0 10.0.3.1    0.0.0.0 UG0 1024   2 eth0
10.0.3.00.0.0.0 255.255.255.0   U 0 0  0 eth0

Signed-off-by: Laurent Vivier 
---
 include/exec/user/thunk.h |   22 +-
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/include/exec/user/thunk.h b/include/exec/user/thunk.h
index 87025c3..d3e9f3d 100644
--- a/include/exec/user/thunk.h
+++ b/include/exec/user/thunk.h
@@ -151,20 +151,32 @@ static inline int thunk_type_align(const argtype 
*type_ptr, int is_host)
 case TYPE_CHAR:
 return 1;
 case TYPE_SHORT:
-return 2;
+if (is_host) {
+return __alignof__(short);
+} else {
+return TARGET_SHORT_ALIGNMENT;
+}
 case TYPE_INT:
-return 4;
+if (is_host) {
+return __alignof__(int);
+} else {
+return TARGET_INT_ALIGNMENT;
+}
 case TYPE_LONGLONG:
 case TYPE_ULONGLONG:
-return 8;
+if (is_host) {
+return __alignof__(long long);
+} else {
+return TARGET_LLONG_ALIGNMENT;
+}
 case TYPE_LONG:
 case TYPE_ULONG:
 case TYPE_PTRVOID:
 case TYPE_PTR:
 if (is_host) {
-return sizeof(void *);
+return __alignof__(long);
 } else {
-return TARGET_ABI_BITS / 8;
+return TARGET_LONG_ALIGNMENT;
 }
 break;
 case TYPE_OLDDEVT:
-- 
1.7.10.4




[Qemu-devel] [PATCH] linux-user: allow to use sudo in guest

2012-12-20 Thread Laurent Vivier
When qemu-linux-user is used in a linux container or chroot,
if it needs to load binaries with SUID/SGID bits, it needs to
have root rights to be able to change UID/GID. To do that, we
need to install it with SUID bits and root owner.
Then, if the SUID bit is not set on the binary to load,
qemu will set its UID to the saved UID (the current user ID).

To be able to retrieve unsecure environment variables (LD_PRELOAD,
LD_LIBRARY_PATH) with SUID bit, we need to disable "unsetenv()".
Otherwise libc unsets these variables before entering in main()

To enable this feature, add "--suid-able" to the configure parameters.

You can check all is working fine with :

- install qemu- in your  root filesystem environment
  and chown root:root ... and chmow +s ...

- check sudo in this environment (chroot or linux container) :

laurent@m68k $ id
uid=1000(laurent) gid=1000(laurent) groups=1000(laurent)
laurent@m68k $ sudo id
Password:
uid=0(root) gid=0(root) groups=0(root)

- check LD_PRELOAD is available (debian fakeroot is my testcase) :

laurent@m68k $ fakeroot id
uid=0(root) gid=0(root) groups=1000(laurent)
laurent@m68k $ rm -f toto
laurent@m68k $ fakeroot
root@m68k # touch toto
root@m68k # ls -l toto
-rw-r--r-- 1 root root 0 2012-12-18 22:50 toto
root@m68k # exit
exit
root@m68k # ls -l toto
-rw-r--r-- 1 laurent laurent 0 2012-12-18 22:50 toto

Signed-off-by: Laurent Vivier 
---
 configure  |   15 +++
 linux-user/linuxload.c |   16 +++-
 linux-user/main.c  |   20 
 3 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/configure b/configure
index b101d5c..2322387 100755
--- a/configure
+++ b/configure
@@ -111,6 +111,7 @@ source_path=`dirname "$0"`
 cpu=""
 interp_prefix="/usr/gnemul/qemu-%M"
 static="no"
+suidable="no"
 cross_prefix=""
 audio_drv_list=""
 audio_card_list="ac97 es1370 sb16 hda"
@@ -624,6 +625,9 @@ for opt do
 LDFLAGS="-static $LDFLAGS"
 QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
   ;;
+  --suid-able)
+suidable="yes"
+  ;;
   --mandir=*) mandir="$optarg"
   ;;
   --bindir=*) bindir="$optarg"
@@ -885,6 +889,11 @@ for opt do
   esac
 done
 
+if test "$suidable" = "yes" -a "$static" = "no" ; then
+echo "ERROR: --suid-able needs --static"
+exit 1
+fi
+
 case "$cpu" in
 sparc)
LDFLAGS="-m32 $LDFLAGS"
@@ -1014,6 +1023,7 @@ echo "  --install=INSTALLuse specified install 
[$install]"
 echo "  --python=PYTHON  use specified python [$python]"
 echo "  --smbd=SMBD  use specified smbd [$smbd]"
 echo "  --static enable static build [$static]"
+echo "  --suid-able  allow to use qemu with SUID bit [$suidable]"
 echo "  --mandir=PATHinstall man pages in PATH"
 echo "  --datadir=PATH   install firmware in PATH$confsuffix"
 echo "  --docdir=PATHinstall documentation in PATH$confsuffix"
@@ -3196,6 +3206,7 @@ echo "sparse enabled$sparse"
 echo "strip binaries$strip_opt"
 echo "profiler  $profiler"
 echo "static build  $static"
+echo "suid-able $suidable"
 echo "-Werror enabled   $werror"
 if test "$darwin" = "yes" ; then
 echo "Cocoa support $cocoa"
@@ -4160,6 +4171,10 @@ if test "$target_linux_user" = "yes" -o 
"$target_bsd_user" = "yes" ; then
 ;;
   esac
 fi
+if test "$target_linux_user" = "yes" -a "$suidable" = "yes" ; then
+  ldflags="$ldflags -Wl,--wrap=__unsetenv"
+  echo "CONFIG_SUIDABLE=y"  >> $config_target_mak
+fi
 
 echo "LDFLAGS+=$ldflags" >> $config_target_mak
 echo "QEMU_CFLAGS+=$cflags" >> $config_target_mak
diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c
index 381ab89..783afce 100644
--- a/linux-user/linuxload.c
+++ b/linux-user/linuxload.c
@@ -58,11 +58,6 @@ static int prepare_binprm(struct linux_binprm *bprm)
 bprm->e_uid = geteuid();
 bprm->e_gid = getegid();
 
-/* Set-uid? */
-if(mode & S_ISUID) {
-   bprm->e_uid = st.st_uid;
-}
-
 /* Set-gid? */
 /*
  * If setgid is set but no group execute bit then this
@@ -72,6 +67,17 @@ static int prepare_binprm(struct linux_binprm *bprm)
 if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
bprm->e_gid = st.st_gid;
 }
+#if defined(CONFIG_SUIDABLE)
+setresgid(getgid(), bprm->e_gid, bprm->e_gid);
+#endif
+
+/* Set-uid? */
+if(mode &a

[Qemu-devel] [PATCH] linux-user: add string type in rtentry struct

2012-12-20 Thread Laurent Vivier
This allows to pass the device name.

You can test this with the "route" command.

WITHOUT this patch:

$ sudo route add -net default gw 10.0.3.1 eth0
SIOCADDRT: Bad address
$ netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags   MSS Window  irtt Iface
10.0.3.00.0.0.0 255.255.255.0   U 0 0  0 eth0

WITH this patch:

$ sudo route add -net default gw 10.0.3.1 eth0
$ netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags   MSS Window  irtt Iface
0.0.0.0 10.0.3.10.0.0.0 UG0 0  0 eth0
10.0.3.00.0.0.0 255.255.255.0   U 0 0  0 eth0

Signed-off-by: Laurent Vivier 
---
 linux-user/syscall.c   |   64 
 linux-user/syscall_types.h |4 ++-
 2 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 501002b..c2a2343 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3691,6 +3691,70 @@ static IOCTLEntry ioctl_entries[] = {
 { 0, 0, },
 };
 
+static void target_to_host_string (void *dst, const void *src)
+{
+#if HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 32
+if (*(uint32_t*)src == 0) {
+*(uint32_t*)dst = 0;
+   return;
+}
+*(uint32_t *)dst = (uint32_t)g2h(tswap32(*(uint32_t *)src));
+#elif HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 32
+if (*(uint32_t*)src == 0) {
+*(uint64_t*)dst = 0;
+   return;
+}
+*(uint64_t *)dst = (uint64_t)g2h(tswap32(*(uint32_t *)src));
+#elif HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64
+if (*(uint64_t*)src == 0) {
+*(uint64_t*)dst = 0;
+   return;
+}
+*(uint64_t *)dst = (uint64_t)g2h(tswap64(*(uint64_t *)src));
+#elif HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 64
+if (*(uint64_t*)src == 0) {
+*(uint32_t*)dst = 0;
+   return;
+}
+*(uint32_t *)dst = (uint32_t)g2h(tswap64(*(uint64_t *)src));
+#endif
+}
+
+static void host_to_target_string (void *dst, const void *src)
+{
+#if HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 32
+if (*(uint32_t*)src == 0) {
+*(uint32_t*)dst = 0;
+   return;
+}
+*(uint32_t *)dst = tswap32(h2g(*(uint32_t *)src));
+#elif HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 32
+if (*(uint64_t*)src == 0) {
+*(uint32_t*)dst = 0;
+   return;
+}
+*(uint32_t *)dst = tswap32(h2g(*(uint64_t *)src));
+#elif HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64
+if (*(uint64_t*)src == 0) {
+*(uint64_t*)dst = 0;
+   return;
+}
+*(uint64_t *)dst = tswap64(h2g(*(uint64_t *)src));
+#elif HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 64
+if (*(uint32_t*)src == 0) {
+*(uint64_t*)dst = 0;
+   return;
+}
+*(uint64_t *)dst = tswap64(h2g(*(uint32_t *)src));
+#endif
+}
+
+static const StructEntry struct_string_def = {
+.convert = { host_to_target_string, target_to_host_string },
+.size = { sizeof(target_long), sizeof(long) },
+.align = { __alignof__(target_long), __alignof__(long) },
+};
+
 /* ??? Implement proper locking for ioctls.  */
 /* do_ioctl() Must return target values and target errnos. */
 static abi_long do_ioctl(int fd, abi_long cmd, abi_long arg)
diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
index 44b6a58..51fc023 100644
--- a/linux-user/syscall_types.h
+++ b/linux-user/syscall_types.h
@@ -14,9 +14,11 @@ STRUCT(serial_icounter_struct,
 STRUCT(sockaddr,
TYPE_SHORT, MK_ARRAY(TYPE_CHAR, 14))
 
+STRUCT_SPECIAL(string)
+
 STRUCT(rtentry,
TYPE_ULONG, MK_STRUCT(STRUCT_sockaddr), MK_STRUCT(STRUCT_sockaddr), 
MK_STRUCT(STRUCT_sockaddr),
-   TYPE_SHORT, TYPE_SHORT, TYPE_ULONG, TYPE_PTRVOID, TYPE_SHORT, 
TYPE_PTRVOID,
+   TYPE_SHORT, TYPE_SHORT, TYPE_ULONG, TYPE_PTRVOID, TYPE_SHORT, 
MK_STRUCT(STRUCT_string),
TYPE_ULONG, TYPE_ULONG, TYPE_SHORT)
 
 STRUCT(ifmap,
-- 
1.7.10.4




[Qemu-devel] [PATCH] linux-user: correct semctl() and shmctl()

2012-12-20 Thread Laurent Vivier
The parameter "union semun" of semctl() is not a value
but a pointer to the value.

Moreover, all fields of target_su must be swapped (if needed).

The third argument of shmctl is a pointer.

WITHOUT this patch:

$ ipcs

kernel not configured for shared memory

qemu: uncaught target signal 11 (Segmentation fault) - core dumped

WITH this patch:

$ ipcs

-- Shared Memory Segments 
keyshmid  owner  perms  bytes  nattch status
0x4e545030 0  root  60096 1
0x4e545031 32769  root  60096 1
0x4e545032 65538  root  66696 1
0x4e545033 98307  root  66696 1
0x47505344 131076 root  6668240   1
0x3c81b7f5 163845 laurent   6664096   0
0x 729513990  laurent   600393216 2  dest
0x 729546759  laurent   600393216 2  dest
0x 1879179273 laurent   600393216 2  dest

-- Semaphore Arrays 
keysemid  owner  perms  nsems
0x3c81b7f6 32768  laurent   6661
0x1c44ac47 6586369laurent   6001

-- Message Queues 
keymsqid  owner  perms  used-bytes   messages
0x1c44ac45 458752 laurent60000
0x1c44ac46 491521 laurent60000

Signed-off-by: Laurent Vivier 
---
 linux-user/syscall.c |   37 ++---
 1 file changed, 26 insertions(+), 11 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index c2a2343..7bab006 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2656,24 +2656,26 @@ static inline abi_long do_semctl(int semid, int semnum, 
int cmd,
 break;
case GETALL:
case SETALL:
-err = target_to_host_semarray(semid, &array, target_su.array);
+err = target_to_host_semarray(semid, &array,
+  tswapal(target_su.array));
 if (err)
 return err;
 arg.array = array;
 ret = get_errno(semctl(semid, semnum, cmd, arg));
-err = host_to_target_semarray(semid, target_su.array, &array);
+err = host_to_target_semarray(semid, tswapal(target_su.array),
+  &array);
 if (err)
 return err;
 break;
case IPC_STAT:
case IPC_SET:
case SEM_STAT:
-err = target_to_host_semid_ds(&dsarg, target_su.buf);
+err = target_to_host_semid_ds(&dsarg, tswapal(target_su.buf));
 if (err)
 return err;
 arg.buf = &dsarg;
 ret = get_errno(semctl(semid, semnum, cmd, arg));
-err = host_to_target_semid_ds(target_su.buf, &dsarg);
+err = host_to_target_semid_ds(tswapal(target_su.buf), &dsarg);
 if (err)
 return err;
 break;
@@ -2681,7 +2683,7 @@ static inline abi_long do_semctl(int semid, int semnum, 
int cmd,
case SEM_INFO:
 arg.__buf = &seminfo;
 ret = get_errno(semctl(semid, semnum, cmd, arg));
-err = host_to_target_seminfo(target_su.__buf, &seminfo);
+err = host_to_target_seminfo(tswapal(target_su.__buf), &seminfo);
 if (err)
 return err;
 break;
@@ -3161,10 +3163,16 @@ static abi_long do_ipc(unsigned int call, int first,
 ret = get_errno(semget(first, second, third));
 break;
 
-case IPCOP_semctl:
-ret = do_semctl(first, second, third, (union target_semun)(abi_ulong) 
ptr);
+case IPCOP_semctl: {
+union target_semun *target_su;
+if (!lock_user_struct(VERIFY_READ, target_su, ptr, 1)) {
+ret = -TARGET_EFAULT;
+break;
+}
+ret = do_semctl(first, second, third, *target_su);
+unlock_user_struct(target_su, ptr, 0);
 break;
-
+}
 case IPCOP_msgget:
 ret = get_errno(msgget(first, second));
 break;
@@ -3229,7 +3237,7 @@ static abi_long do_ipc(unsigned int call, int first,
 
/* IPC_* and SHM_* command values are the same on all linux platforms */
 case IPCOP_shmctl:
-ret = do_shmctl(first, second, third);
+ret = do_shmctl(first, second, ptr);
 break;
 default:
gemu_log("Unsupported ipc call: %d (version %d)\n", call, version);
@@ -6996,9 +7004,16 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 break;
 #endif
 #ifdef TARGET_NR_semctl
-case TARGET_NR_semctl:
-ret = do_semctl(arg1, arg2, arg3, (union target_semun)(abi_ulong)arg4);
+case TARGET_NR_semctl: {
+union target_semun *target_su;
+if (!lock_user_struct(VERIFY_READ, target_su, arg4, 1)) {
+ 

[Qemu-devel] [PATCH] linux-user: correct msgrcv()

2012-12-20 Thread Laurent Vivier
All parameters must be swapped before the call of do_msgrcv().

Allow faked (debian fakeroot daemon) to work properly.

WITHOUT this patch:

$ faked-sysv --foreground --debug
using 1723744788 as msg key
msg_key=1723744788
1723744788:431
FAKEROOT: msg=131072, key=1723744788
FAKEROOT: r=-1, received message type=-150996052, message=-160219330
FAKEROOT, get_msg: Bad address
r=14, EINTR=4
fakeroot: clearing up message queues and semaphores, signal=-1
fakeroot: database save FAILED

WITH this patch:

$ faked-sysv --foreground --debug
using 1569385744 as msg key
msg_key=1569385744
1569385744:424
FAKEROOT: msg=0, key=1569385744
^C
fakeroot: clearing up message queues and semaphores, signal=2
fakeroot: database save FAILED

Signed-off-by: Laurent Vivier 
---
 linux-user/syscall.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 7bab006..78cb764 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2901,7 +2901,7 @@ static inline abi_long do_msgrcv(int msqid, abi_long msgp,
 return -TARGET_EFAULT;
 
 host_mb = g_malloc(msgsz+sizeof(long));
-ret = get_errno(msgrcv(msqid, host_mb, msgsz, tswapal(msgtyp), msgflg));
+ret = get_errno(msgrcv(msqid, host_mb, msgsz, msgtyp, msgflg));
 
 if (ret > 0) {
 abi_ulong target_mtext_addr = msgp + sizeof(abi_ulong);
@@ -3199,7 +3199,7 @@ static abi_long do_ipc(unsigned int call, int first,
 break;
 }
 
-ret = do_msgrcv(first, tmp->msgp, second, tmp->msgtyp, third);
+ret = do_msgrcv(first, tswapal(tmp->msgp), second, 
tswapal(tmp->msgtyp), third);
 
 unlock_user_struct(tmp, ptr, 0);
 break;
-- 
1.7.10.4




[Qemu-devel] [PATCH 0/2] linux-user: dhclient support

2012-12-31 Thread Laurent Vivier
This two patches allow to use dhclient to configure IP addresses
in a linux container running the linux-user version of qemu.

[PATCH 1/2] linux-user: Add setsockopt(SO_ATTACH_FILTER)
[PATCH 2/2] linux-user: SOCK_PACKET uses network endian to encode



[Qemu-devel] [PATCH 1/2] linux-user: Add setsockopt(SO_ATTACH_FILTER)

2012-12-31 Thread Laurent Vivier
This is needed to be able to run dhclient.

Signed-off-by: Laurent Vivier 
---
 linux-user/syscall.c  |   34 +-
 linux-user/syscall_defs.h |   12 
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e99adab..000b640 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -98,6 +98,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,
 #include 
 #include 
 #include 
+#include 
 #include "linux_loop.h"
 #include "cpu-uname.h"
 
@@ -1491,6 +1492,38 @@ static abi_long do_setsockopt(int sockfd, int level, int 
optname,
 break;
 case TARGET_SOL_SOCKET:
 switch (optname) {
+case TARGET_SO_ATTACH_FILTER: {
+struct target_sock_fprog *tfprog;
+struct target_sock_filter *tfilter;
+struct sock_fprog fprog;
+struct sock_filter *filter;
+int i;
+
+if (optlen != sizeof(*tfprog))
+return -TARGET_EINVAL;
+if (!lock_user_struct(VERIFY_READ, tfprog, optval_addr, 0))
+return -TARGET_EFAULT;
+if (!lock_user_struct(VERIFY_READ, tfilter,
+  tswapal(tfprog->filter), 0))
+return -TARGET_EFAULT;
+
+fprog.len = tswap16(tfprog->len);
+filter = alloca(fprog.len * sizeof(*filter));
+for (i = 0; i < fprog.len; i ++) {
+filter[i].code = tswap16(tfilter[i].code);
+filter[i].jt = tfilter[i].jt;
+filter[i].jf = tfilter[i].jf;
+filter[i].k = tswap32(tfilter[i].k);
+}
+fprog.filter = filter;
+
+ret = get_errno(setsockopt(sockfd, SOL_SOCKET,
+SO_ATTACH_FILTER, &fprog, sizeof(fprog)));
+
+unlock_user_struct(tfilter, tfprog->filter, 1);
+unlock_user_struct(tfprog, optval_addr, 1);
+return ret;
+}
 /* Options with 'int' argument.  */
 case TARGET_SO_DEBUG:
optname = SO_DEBUG;
@@ -1548,7 +1581,6 @@ static abi_long do_setsockopt(int sockfd, int level, int 
optname,
 case TARGET_SO_SNDTIMEO:
optname = SO_SNDTIMEO;
break;
-break;
 default:
 goto unimplemented;
 }
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index d4589e7..501735f 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -119,6 +119,18 @@ struct target_sockaddr {
 uint8_t sa_data[14];
 };
 
+struct target_sock_filter {
+target_ushort code;
+uint8_t jt;
+uint8_t jf;
+target_uint k;
+};
+
+struct target_sock_fprog {
+target_ushort len;
+abi_ulong filter;
+};
+
 struct target_in_addr {
 uint32_t s_addr; /* big endian */
 };
-- 
1.7.10.4




[Qemu-devel] [PATCH 2/2] linux-user: SOCK_PACKET uses network endian to encode protocol in socket()

2012-12-31 Thread Laurent Vivier
From: Laurent Vivier 

in PACKET(7) :
 protocol is the  IEEE  802.3  protocol
number in network order.  See the  include file for a
list of allowed protocols.  When protocol is  set  to  htons(ETH_P_ALL)
then all protocols are received.  All incoming packets of that protocol
type will be passed to the packet socket before they are passed to  the
protocols implemented in the kernel.

Signed-off-by: Laurent Vivier 
---
 include/exec/user/abitypes.h |   22 ++
 linux-user/syscall.c |8 +++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/include/exec/user/abitypes.h b/include/exec/user/abitypes.h
index fe7f662..f4f526a 100644
--- a/include/exec/user/abitypes.h
+++ b/include/exec/user/abitypes.h
@@ -15,6 +15,15 @@ static inline abi_ulong tswapal(abi_ulong v)
 return tswap32(v);
 }
 
+static inline abi_ulong abi_ntohl(abi_ulong v)
+{
+#if defined(HOST_BIG_ENDIAN)
+return v;
+#else
+return bswap_32(v);
+#endif
+}
+
 #else
 typedef target_ulong abi_ulong;
 typedef target_long abi_long;
@@ -32,5 +41,18 @@ static inline abi_ulong tswapal(abi_ulong v)
 return tswapl(v);
 }
 
+static inline abi_ulong abi_ntohl(abi_ulong v)
+{
+#if defined(HOST_BIG_ENDIAN)
+return v;
+#else
+#if TARGET_LONG_SIZE == 4
+return bswap_32(v);
+#else
+return bswap_64(v);
+#endif
+#endif
+}
+
 #endif
 #endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 000b640..29151a6 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1874,7 +1874,7 @@ static void unlock_iovec(struct iovec *vec, abi_ulong 
target_addr,
 }
 
 /* do_socket() Must return target values and target errnos. */
-static abi_long do_socket(int domain, int type, int protocol)
+static abi_long do_socket(int domain, int type, abi_ulong protocol)
 {
 #if defined(TARGET_MIPS)
 switch(type) {
@@ -1900,6 +1900,12 @@ static abi_long do_socket(int domain, int type, int 
protocol)
 #endif
 if (domain == PF_NETLINK)
 return -EAFNOSUPPORT; /* do not NETLINK socket connections possible */
+if (type == SOCK_PACKET) {
+/* in this case, socket() needs a network endian short */
+protocol = tswapal(protocol); /* restore network endian long */
+protocol = abi_ntohl(protocol); /* a host endian long */
+protocol = htons(protocol); /* network endian short */
+}
 return get_errno(socket(domain, type, protocol));
 }
 
-- 
1.7.10.4




[Qemu-devel] [PATCH] linux-user: correct print_timeval() swap tv_sec and tv_usec

2012-12-31 Thread Laurent Vivier
From: Laurent Vivier 

Signed-off-by: Laurent Vivier 
---
 linux-user/strace.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 6ec90e8..4e91a6e 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -682,7 +682,7 @@ print_timeval(abi_ulong tv_addr, int last)
 if (!tv)
 return;
 gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
-tv->tv_sec, tv->tv_usec, get_comma(last));
+tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
 unlock_user(tv, tv_addr, 0);
 } else
 gemu_log("NULL%s", get_comma(last));
-- 
1.7.10.4




[Qemu-devel] [PATCH] linux-user: correct setsockopt() SO_SNDTIMEO and SO_RCVTIMEO take a struct timeval, not an int

2012-12-31 Thread Laurent Vivier
From: Laurent Vivier 

Signed-off-by: Laurent Vivier 
---
 linux-user/syscall.c |   26 +++---
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e99adab..1530c8f 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1491,6 +1491,25 @@ static abi_long do_setsockopt(int sockfd, int level, int 
optname,
 break;
 case TARGET_SOL_SOCKET:
 switch (optname) {
+case TARGET_SO_RCVTIMEO: {
+struct timeval tv;
+
+   optname = SO_RCVTIMEO;
+
+set_timeout:
+if (optlen != sizeof(struct target_timeval))
+return -TARGET_EINVAL;
+
+if (copy_from_user_timeval(&tv, optval_addr))
+return -TARGET_EFAULT;
+
+   ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname,
+&tv, sizeof(tv)));
+   return ret;
+}
+case TARGET_SO_SNDTIMEO:
+   optname = SO_SNDTIMEO;
+   goto set_timeout;
 /* Options with 'int' argument.  */
 case TARGET_SO_DEBUG:
optname = SO_DEBUG;
@@ -1542,13 +1561,6 @@ static abi_long do_setsockopt(int sockfd, int level, int 
optname,
 case TARGET_SO_RCVLOWAT:
optname = SO_RCVLOWAT;
break;
-case TARGET_SO_RCVTIMEO:
-   optname = SO_RCVTIMEO;
-   break;
-case TARGET_SO_SNDTIMEO:
-   optname = SO_SNDTIMEO;
-   break;
-break;
 default:
 goto unimplemented;
 }
-- 
1.7.10.4




[Qemu-devel] [PATCH] linux-user: improve print_fcntl()

2012-12-31 Thread Laurent Vivier
From: Laurent Vivier 

Signed-off-by: Laurent Vivier 
---
 linux-user/strace.c |   97 +--
 1 file changed, 79 insertions(+), 18 deletions(-)

diff --git a/linux-user/strace.c b/linux-user/strace.c
index 6ec90e8..039fee8 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -462,18 +462,6 @@ UNUSED static struct flags mmap_flags[] = {
 FLAG_END,
 };
 
-UNUSED static struct flags fcntl_flags[] = {
-FLAG_TARGET(F_DUPFD),
-FLAG_TARGET(F_GETFD),
-FLAG_TARGET(F_SETFD),
-FLAG_TARGET(F_GETFL),
-FLAG_TARGET(F_SETFL),
-FLAG_TARGET(F_GETLK),
-FLAG_TARGET(F_SETLK),
-FLAG_TARGET(F_SETLKW),
-FLAG_END,
-};
-
 UNUSED static struct flags clone_flags[] = {
 FLAG_GENERIC(CLONE_VM),
 FLAG_GENERIC(CLONE_FS),
@@ -867,12 +855,85 @@ print_fcntl(const struct syscallname *name,
 {
 print_syscall_prologue(name);
 print_raw_param("%d", arg0, 0);
-print_flags(fcntl_flags, arg1, 0);
-/*
- * TODO: check flags and print following argument only
- *   when needed.
- */
-print_pointer(arg2, 1);
+switch(arg1) {
+case TARGET_F_DUPFD:
+gemu_log("F_DUPFD,");
+print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
+break;
+case TARGET_F_GETFD:
+gemu_log("F_GETFD");
+break;
+case TARGET_F_SETFD:
+gemu_log("F_SETFD,");
+print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
+break;
+case TARGET_F_GETFL:
+gemu_log("F_GETFL");
+break;
+case TARGET_F_SETFL:
+gemu_log("F_SETFL,");
+print_open_flags(arg2, 1);
+break;
+case TARGET_F_GETLK:
+gemu_log("F_GETLK,");
+print_pointer(arg2, 1);
+break;
+case TARGET_F_SETLK:
+gemu_log("F_SETLK,");
+print_pointer(arg2, 1);
+break;
+case TARGET_F_SETLKW:
+gemu_log("F_SETLKW,");
+print_pointer(arg2, 1);
+break;
+case TARGET_F_GETOWN:
+gemu_log("F_GETOWN");
+break;
+case TARGET_F_SETOWN:
+gemu_log("F_SETOWN,");
+print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
+break;
+case TARGET_F_GETSIG:
+gemu_log("F_GETSIG");
+break;
+case TARGET_F_SETSIG:
+gemu_log("F_SETSIG,");
+print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
+break;
+#if TARGET_ABI_BITS == 32
+case TARGET_F_GETLK64:
+gemu_log("F_GETLK64,");
+print_pointer(arg2, 1);
+break;
+case TARGET_F_SETLK64:
+gemu_log("F_SETLK64,");
+print_pointer(arg2, 1);
+break;
+case TARGET_F_SETLKW64:
+gemu_log("F_SETLKW64,");
+print_pointer(arg2, 1);
+break;
+#endif
+case TARGET_F_SETLEASE:
+gemu_log("F_SETLEASE,");
+print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
+break;
+case TARGET_F_GETLEASE:
+gemu_log("F_GETLEASE");
+break;
+case TARGET_F_DUPFD_CLOEXEC:
+gemu_log("F_DUPFD_CLOEXEC,");
+print_raw_param(TARGET_ABI_FMT_ld, arg2, 1);
+break;
+case TARGET_F_NOTIFY:
+gemu_log("F_NOTIFY,");
+print_raw_param(TARGET_ABI_FMT_ld, arg2, 0);
+break;
+default:
+print_raw_param(TARGET_ABI_FMT_ld, arg1, 0);
+print_pointer(arg2, 1);
+break;
+}
 print_syscall_epilogue(name);
 }
 #define print_fcntl64   print_fcntl
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH 2/2] linux-user: SOCK_PACKET uses network endian to encode protocol in socket()

2012-12-31 Thread Laurent Vivier
Le lundi 31 décembre 2012 à 21:32 +, Peter Maydell a écrit :
> On 31 December 2012 19:38, Laurent Vivier  wrote:
> > @@ -1900,6 +1900,12 @@ static abi_long do_socket(int domain, int type, int 
> > protocol)
> >  #endif
> >  if (domain == PF_NETLINK)
> >  return -EAFNOSUPPORT; /* do not NETLINK socket connections 
> > possible */
> > +if (type == SOCK_PACKET) {
> > +/* in this case, socket() needs a network endian short */
> > +protocol = tswapal(protocol); /* restore network endian long */
> > +protocol = abi_ntohl(protocol); /* a host endian long */
> > +protocol = htons(protocol); /* network endian short */
> > +}
> 
> Are you sure this is correct for little endian guests? I've only
> desk-checked it rather than running a test program, but it looks
> to me like you end up passing the wrong value to socket().

I tried to find a solution working in every case.

> Also it seems rather involved since we swap things three times and
> have an entirely new abi_* function. Either I'm completely confused
> or it should be enough to just have
> 
> if (type == SOCK_PACKET) {
>   protocol = tswap16(protocol);
> }

works... sometime. In fact, work if target endianess is network endianess.

Correct me if I'm wrong.

target  host
little endian / big endian

memory   00 00 00 03
protocol 0300
tswap16   -> don't work

tswapal()   0003
abi_ntohl() 0003
htons() 0003 -> work

big endian / little endian:

memory00 00 00 03
protocol  0003
tswap16() 0300 -> work

tswapal() 0300
abi_ntohl() 0003
htons() 0300 -> work

little endian/little endian:

memory: 00 00 00 03 (network endian)
protocol : 0300
tswap16() :  -> don't work

tswapal() 0300
abi_ntohl() 0003
htons() 0300 -> work

big endian / big endian

memory 00 00 00 03
protocol 0003
tswap16() 0003 -> work

tswapal() 0003
abi_ntohl() 0003
htons() 0003 -> work

Laurent

-- 
"Just play. Have fun. Enjoy the game."
- Michael Jordan




Re: [Qemu-devel] [PATCH 2/2] linux-user: SOCK_PACKET uses network endian to encode protocol in socket()

2013-01-01 Thread Laurent Vivier
Le mardi 01 janvier 2013 à 15:03 +, Peter Maydell a écrit :
> On 31 December 2012 22:19, Laurent Vivier  wrote:
> > Le lundi 31 décembre 2012 à 21:32 +, Peter Maydell a écrit :
> >> Also it seems rather involved since we swap things three times and
> >> have an entirely new abi_* function. Either I'm completely confused
> >> or it should be enough to just have
> >>
> >> if (type == SOCK_PACKET) {
> >>   protocol = tswap16(protocol);
> >> }
> 
> Looking more carefully at packet(7) this is actually the wrong
> guard anyway. You need to check for
>  (domain == AF_PACKET) || (type == SOCK_PACKET)

I agree.

> since SOCK_PACKET is the obsolete Linux 2.0 way of doing packet sockets.

But dhclient is always using this...

> > works... sometime. In fact, work if target endianess is network endianess.
> >
> > Correct me if I'm wrong.
> >
> > target  host
> > little endian / big endian
> >
> > memory   00 00 00 03
> 
> Syscall arguments aren't generally passed in memory, they're
> in registers (and if they were pased in memory for some architecture
> then that arch would do a load-and-swap-from-memory in main.c).
> So the value you see in do_socket() is always "the integer passed
> as a syscall parameter, as a host-order integer".

Yes, I missed that.

> So in this case, with a simple guest program:
> #include 
> #include 
> #include 
> #include 
> 
> int main(void) {
>return socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
> }
> 
> you will find that do_socket() in QEMU is passed either 0x3 [if the
> guest is bigendian and the guest htons() is a no-op] or 0x0300
> [if the guest is littleendian]. Since what we want to pass to the
> host socket() call is 0x3 if the host is bigendian and 0x0300 if
> the host is little endian, this amounts to needing to do a 16 bit
> byteswap if the host and guest are different endianness, which
> is exactly what tswap16() does. I checked with i386-to-i386
> that do_socket() gets passed 0x300 and we correctly send it
> through to the host socket().

Yes, I agree. I correct the patch.

Thank you,
Laurent

-- 
"Just play. Have fun. Enjoy the game."
- Michael Jordan




[Qemu-devel] [PATCH][v2] linux-user: correct setsockopt()

2013-01-01 Thread Laurent Vivier
From: Laurent Vivier 

SO_SNDTIMEO and SO_RCVTIMEO take a struct timeval, not an int

To test this, you can use :

QEMU_STRACE= ping localhost 2>&1 |grep TIMEO
568 setsockopt(3,SOL_SOCKET,SO_SNDTIMEO,{1,0},8) = 0
568 setsockopt(3,SOL_SOCKET,SO_RCVTIMEO,{1,0},8) = 0

Signed-off-by: Laurent Vivier 
---
v2: pass checkpatch.pl

 linux-user/syscall.c |   28 ++--
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e99adab..2b2bd2b 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1491,6 +1491,28 @@ static abi_long do_setsockopt(int sockfd, int level, int 
optname,
 break;
 case TARGET_SOL_SOCKET:
 switch (optname) {
+case TARGET_SO_RCVTIMEO:
+{
+struct timeval tv;
+
+optname = SO_RCVTIMEO;
+
+set_timeout:
+if (optlen != sizeof(struct target_timeval)) {
+return -TARGET_EINVAL;
+}
+
+if (copy_from_user_timeval(&tv, optval_addr)) {
+return -TARGET_EFAULT;
+}
+
+ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname,
+&tv, sizeof(tv)));
+return ret;
+}
+case TARGET_SO_SNDTIMEO:
+optname = SO_SNDTIMEO;
+goto set_timeout;
 /* Options with 'int' argument.  */
 case TARGET_SO_DEBUG:
optname = SO_DEBUG;
@@ -1542,12 +1564,6 @@ static abi_long do_setsockopt(int sockfd, int level, int 
optname,
 case TARGET_SO_RCVLOWAT:
optname = SO_RCVLOWAT;
break;
-case TARGET_SO_RCVTIMEO:
-   optname = SO_RCVTIMEO;
-   break;
-case TARGET_SO_SNDTIMEO:
-   optname = SO_SNDTIMEO;
-   break;
 break;
 default:
 goto unimplemented;
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH 2/2] linux-user: SOCK_PACKET uses network endian to encode protocol in socket()

2013-01-01 Thread Laurent Vivier
Le mardi 01 janvier 2013 à 18:27 +0100, Laurent Vivier a écrit :
> Le mardi 01 janvier 2013 à 15:03 +, Peter Maydell a écrit :
> > On 31 December 2012 22:19, Laurent Vivier  wrote:
> > > works... sometime. In fact, work if target endianess is network endianess.
> > >
> > > Correct me if I'm wrong.
> > >
> > > target  host
> > > little endian / big endian
> > >
> > > memory   00 00 00 03
> > 
> > Syscall arguments aren't generally passed in memory, they're
> > in registers (and if they were pased in memory for some architecture
> > then that arch would do a load-and-swap-from-memory in main.c).
> > So the value you see in do_socket() is always "the integer passed
> > as a syscall parameter, as a host-order integer".
> 
> Yes, I missed that.

But, in fact, for socketcall(), they are read from memory :

static abi_long do_socketcall(int num, abi_ulong vptr)
{
abi_long ret;
const int n = sizeof(abi_ulong);

switch(num) {
case SOCKOP_socket:
{
abi_ulong domain, type, protocol;

if (get_user_ual(domain, vptr)
|| get_user_ual(type, vptr + n)
|| get_user_ual(protocol, vptr + 2 * n))
return -TARGET_EFAULT;

ret = do_socket(domain, type, protocol);
}
break;


So, I don't know if "tswap16()" is always correct. It works for
m68k-to-x86_64, but I don't understand how it can works for
i386-to-i386.

Your opinion ?

Regards,
Laurent

-- 
"Just play. Have fun. Enjoy the game."
- Michael Jordan




Re: [Qemu-devel] [PATCH 2/2] linux-user: SOCK_PACKET uses network endian to encode protocol in socket()

2013-01-01 Thread Laurent Vivier
Le mardi 01 janvier 2013 à 19:45 +, Peter Maydell a écrit :
> On 1 January 2013 18:37, Laurent Vivier  wrote:
> > Le mardi 01 janvier 2013 à 18:27 +0100, Laurent Vivier a écrit :
> >> Le mardi 01 janvier 2013 à 15:03 +, Peter Maydell a écrit :
> >> > On 31 December 2012 22:19, Laurent Vivier  wrote:
> >> > > works... sometime. In fact, work if target endianess is network 
> >> > > endianess.
> >> > >
> >> > > Correct me if I'm wrong.
> >> > >
> >> > > target  host
> >> > > little endian / big endian
> >> > >
> >> > > memory   00 00 00 03
> >> >
> >> > Syscall arguments aren't generally passed in memory, they're
> >> > in registers (and if they were pased in memory for some architecture
> >> > then that arch would do a load-and-swap-from-memory in main.c).
> >> > So the value you see in do_socket() is always "the integer passed
> >> > as a syscall parameter, as a host-order integer".
> >>
> >> Yes, I missed that.
> >
> > But, in fact, for socketcall(), they are read from memory :
> 
> Yes, this is because socketcall is weird. The actual kernel
> implementation also reads them from memory:
>   http://lxr.linux.no/#linux+v3.7.1/net/socket.c#L2443
> as an array of unsigned longs. So as long as qemu also reads
> them out of memory as an array of target abi_ulongs (which as
> you can see we do) then we'll retrieve the same value (0x3 or
> 0x300) to pass to do_socket() as the guest program wrote into
> its guest view of memory (since it should have written an
> unsigned long). (What is happening here is that the guest
> binary writes the protocol value to memory as an unsigned
> long, so it goes in as 4 bytes in whichever order the guest uses;
> qemu's get_user_ual() then rereads those 4 bytes, swapping
> the value back so we get the same integer value the guest
> program stored. Note that the guest doesn't write the protocol
> argument as a 2 byte value!)
> 
> I would encourage you to write some simple test programs
> and check them using strace (both of the native program and
> of qemu running the program).

OK, I will... but I think we will fall back to my original patch ;-)

Regards,
Laurent

-- 
"Just play. Have fun. Enjoy the game."
- Michael Jordan




Re: [Qemu-devel] [PATCH] linux-user: convert /proc/net/route when endianess differs

2013-01-01 Thread Laurent Vivier
Ping !


Le jeudi 20 décembre 2012 à 21:53 +0100, Laurent Vivier a écrit :
> This patch allows to have IP addresses in correct order
> in the case of "netstat -nr" when the endianess of the
> guest differs from one of the host.
> 
> For instance, an m68k guest on an x86_64 host:
> 
> WITHOUT this patch:
> 
> $ netstat -nr
> Kernel IP routing table
> Destination Gateway Genmask Flags   MSS Window  irtt Iface
> 0.0.0.0 1.3.0.100.0.0.0 UG0 0  0 eth0
> 0.3.0.100.0.0.0 0.255.255.255   U 0 0  0 eth0
> $ cat /proc/net/route
> Iface Destination Gateway Flags   RefCnt  Use Metric  Mask
> MTU Window  IRTT
> 
> eth0  0103000A00030   0   0   
> 0   0   0
> eth0  0003000A00010   0   0   
> 00FF0   0   0
> 
> WITH this patch:
> 
> $ netstat -nr
> Kernel IP routing table
> Destination Gateway Genmask Flags   MSS Window  irtt Iface
> 0.0.0.0 10.0.3.10.0.0.0 UG0 0  0 eth0
> 10.0.3.00.0.0.0 255.255.255.0   U 0 0  0 eth0
> $ cat /proc/net/route
> Iface Destination Gateway Flags   RefCnt  Use Metric  Mask
> MTU Window  IRTT
> eth0  0a00030100030   0   0   
> 0   0   0
> eth0  0a00030000010   0   0   
> ff000   0   0
> 
> Signed-off-by: Laurent Vivier 
> ---
>  linux-user/syscall.c |   42 ++
>  1 file changed, 42 insertions(+)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index e99adab..501002b 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -5085,6 +5085,45 @@ static int open_self_auxv(void *cpu_env, int fd)
>  return 0;
>  }
>  
> +#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
> +static int open_net_route(void *cpu_env, int fd)
> +{
> +FILE *fp;
> +char *line = NULL;
> +size_t len = 0;
> +ssize_t read;
> +
> +fp = fopen("/proc/net/route", "r");
> +if (fp == NULL) {
> +return -EACCES;
> +}
> +
> +/* read header */
> +
> +read = getline(&line, &len, fp);
> +dprintf(fd, "%s", line);
> +
> +/* read routes */
> +
> +while ((read = getline(&line, &len, fp)) != -1) {
> +char iface[16];
> +uint32_t dest, gw, mask;
> +unsigned int flags, refcnt, use, metric, mtu, window, irtt;
> +sscanf(line, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n",
> + iface, &dest, &gw, &flags, &refcnt, &use, &metric,
> + &mask, &mtu, &window, &irtt);
> +dprintf(fd, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n",
> +iface, tswap32(dest), tswap32(gw), flags, refcnt, use,
> +metric, tswap32(mask), mtu, window, irtt);
> +}
> +
> +free(line);
> +fclose(fp);
> +
> +return 0;
> +}
> +#endif
> +
>  static int do_open(void *cpu_env, const char *pathname, int flags, mode_t 
> mode)
>  {
>  struct fake_open {
> @@ -5096,6 +5135,9 @@ static int do_open(void *cpu_env, const char *pathname, 
> int flags, mode_t mode)
>  { "/proc/self/maps", open_self_maps },
>  { "/proc/self/stat", open_self_stat },
>  { "/proc/self/auxv", open_self_auxv },
> +#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
> +{ "/proc/net/route", open_net_route },
> +#endif
>  { NULL, NULL }
>  };
>  

-- 
"Just play. Have fun. Enjoy the game."
- Michael Jordan
"Just play. Have fun. Enjoy the game."
- Michael Jordan




Re: [Qemu-devel] [PATCH] linux-user: correctly align types in thunking code

2013-01-01 Thread Laurent Vivier
Ping !

Le jeudi 20 décembre 2012 à 21:55 +0100, Laurent Vivier a écrit :
> This is a follow up
> of patch:
> 
> commit c2e3dee6e03527baf8698698cce76b1a3174969a
>     Author: Laurent Vivier 
> Date:   Sun Feb 13 23:37:34 2011 +0100
> 
> linux-user: Define target alignment size
> 
> In my case m68k aligns "int" on 2 not 4. You can check this with the
> following program:
> 
> int main(void)
> {
> struct rtentry rt;
> printf("rt_pad1 %ld %zd\n", offsetof(struct rtentry, rt_pad1),
> sizeof(rt.rt_pad1));
> printf("rt_dst %ld %zd\n", offsetof(struct rtentry, rt_dst),
> sizeof(rt.rt_dst));
> printf("rt_gateway %ld %zd\n", offsetof(struct rtentry, rt_gateway),
> sizeof(rt.rt_gateway));
> printf("rt_genmask %ld %zd\n", offsetof(struct rtentry, rt_genmask),
> sizeof(rt.rt_genmask));
> printf("rt_flags %ld %zd\n", offsetof(struct rtentry, rt_flags),
> sizeof(rt.rt_flags));
> printf("rt_pad2 %ld %zd\n", offsetof(struct rtentry, rt_pad2),
> sizeof(rt.rt_pad2));
> printf("rt_pad3 %ld %zd\n", offsetof(struct rtentry, rt_pad3),
> sizeof(rt.rt_pad3));
> printf("rt_pad4 %ld %zd\n", offsetof(struct rtentry, rt_pad4),
> sizeof(rt.rt_pad4));
> printf("rt_metric %ld %zd\n", offsetof(struct rtentry, rt_metric),
> sizeof(rt.rt_metric));
> printf("rt_dev %ld %zd\n", offsetof(struct rtentry, rt_dev),
> sizeof(rt.rt_dev));
> printf("rt_mtu %ld %zd\n", offsetof(struct rtentry, rt_mtu),
> sizeof(rt.rt_mtu));
> printf("rt_window %ld %zd\n", offsetof(struct rtentry, rt_window),
> sizeof(rt.rt_window));
> printf("rt_irtt %ld %zd\n", offsetof(struct rtentry, rt_irtt),
> sizeof(rt.rt_irtt));
> }
> 
> And result is :
> 
> i386
> 
> rt_pad1 0 4
> rt_dst 4 16
> rt_gateway 20 16
> rt_genmask 36 16
> rt_flags 52 2
> rt_pad2 54 2
> rt_pad3 56 4
> rt_pad4 62 2
> rt_metric 64 2
> rt_dev 68 4
> rt_mtu 72 4
> rt_window 76 4
> rt_irtt 80 2
> 
> m68k
> 
> rt_pad1 0 4
> rt_dst 4 16
> rt_gateway 20 16
> rt_genmask 36 16
> rt_flags 52 2
> rt_pad2 54 2
> rt_pad3 56 4
> rt_pad4 62 2
> rt_metric 64 2
> rt_dev 66 4
> rt_mtu 70 4
> rt_window 74 4
> rt_irtt 78 2
> 
> This affects the "route" command :
> 
> WITHOUT this patch:
> 
> $ sudo route add -net default gw 10.0.3.1 window 1024 irtt 2 eth0
> $ netstat -nr
> Kernel IP routing table
> Destination Gateway Genmask Flags   MSS Window  irtt Iface
> 0.0.0.0 10.0.3.10.0.0.0 UG0 67108866  32768 
> eth0
> 10.0.3.00.0.0.0 255.255.255.0   U 0 0      0 eth0
> 
> WITH this patch:
> 
> $ sudo route add -net default gw 10.0.3.1 window 1024 irtt 2 eth0
> $ netstat -nr
> Kernel IP routing table
> Destination Gateway Genmask Flags   MSS Window  irtt Iface
> 0.0.0.0 10.0.3.10.0.0.0 UG0 1024   2 eth0
> 10.0.3.00.0.0.0 255.255.255.0   U 0 0  0 eth0
> 
> Signed-off-by: Laurent Vivier 
> ---
>  include/exec/user/thunk.h |   22 +-
>  1 file changed, 17 insertions(+), 5 deletions(-)
> 
> diff --git a/include/exec/user/thunk.h b/include/exec/user/thunk.h
> index 87025c3..d3e9f3d 100644
> --- a/include/exec/user/thunk.h
> +++ b/include/exec/user/thunk.h
> @@ -151,20 +151,32 @@ static inline int thunk_type_align(const argtype 
> *type_ptr, int is_host)
>  case TYPE_CHAR:
>  return 1;
>  case TYPE_SHORT:
> -return 2;
> +if (is_host) {
> +return __alignof__(short);
> +} else {
> +return TARGET_SHORT_ALIGNMENT;
> +}
>  case TYPE_INT:
> -return 4;
> +if (is_host) {
> +return __alignof__(int);
> +} else {
> +return TARGET_INT_ALIGNMENT;
> +}
>  case TYPE_LONGLONG:
>  case TYPE_ULONGLONG:
> -return 8;
> +if (is_host) {
> +return __alignof__(long long);
> +} else {
> +return TARGET_LLONG_ALIGNMENT;
> +}
>  case TYPE_LONG:
>  case TYPE_ULONG:
>  case TYPE_PTRVOID:
>  case TYPE_PTR:
>  if (is_host) {
> -return sizeof(void *);
> +return __alignof__(long);
>  } else {
> -return TARGET_ABI_BITS / 8;
> +return TARGET_LONG_ALIGNMENT;
>  }
>  break;
>  case TYPE_OLDDEVT:

-- 
"Just play. Have fun. Enjoy the game."
- Michael Jordan
"Just play. Have fun. Enjoy the game."
- Michael Jordan




Re: [Qemu-devel] [PATCH] linux-user: add string type in rtentry struct

2013-01-01 Thread Laurent Vivier
Ping !

Le jeudi 20 décembre 2012 à 21:56 +0100, Laurent Vivier a écrit :
> This allows to pass the device name.
> 
> You can test this with the "route" command.
> 
> WITHOUT this patch:
> 
> $ sudo route add -net default gw 10.0.3.1 eth0
> SIOCADDRT: Bad address
> $ netstat -nr
> Kernel IP routing table
> Destination Gateway Genmask Flags   MSS Window  irtt Iface
> 10.0.3.00.0.0.0 255.255.255.0   U 0 0  0 eth0
> 
> WITH this patch:
> 
> $ sudo route add -net default gw 10.0.3.1 eth0
> $ netstat -nr
> Kernel IP routing table
> Destination Gateway Genmask Flags   MSS Window  irtt Iface
> 0.0.0.0 10.0.3.10.0.0.0 UG0 0  0 eth0
> 10.0.3.00.0.0.0     255.255.255.0   U 0 0  0 eth0
> 
> Signed-off-by: Laurent Vivier 
> ---
>  linux-user/syscall.c   |   64 
> 
>  linux-user/syscall_types.h |4 ++-
>  2 files changed, 67 insertions(+), 1 deletion(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 501002b..c2a2343 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -3691,6 +3691,70 @@ static IOCTLEntry ioctl_entries[] = {
>  { 0, 0, },
>  };
>  
> +static void target_to_host_string (void *dst, const void *src)
> +{
> +#if HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 32
> +if (*(uint32_t*)src == 0) {
> +*(uint32_t*)dst = 0;
> + return;
> +}
> +*(uint32_t *)dst = (uint32_t)g2h(tswap32(*(uint32_t *)src));
> +#elif HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 32
> +if (*(uint32_t*)src == 0) {
> +*(uint64_t*)dst = 0;
> + return;
> +}
> +*(uint64_t *)dst = (uint64_t)g2h(tswap32(*(uint32_t *)src));
> +#elif HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64
> +if (*(uint64_t*)src == 0) {
> +*(uint64_t*)dst = 0;
> + return;
> +}
> +*(uint64_t *)dst = (uint64_t)g2h(tswap64(*(uint64_t *)src));
> +#elif HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 64
> +if (*(uint64_t*)src == 0) {
> +*(uint32_t*)dst = 0;
> + return;
> +}
> +*(uint32_t *)dst = (uint32_t)g2h(tswap64(*(uint64_t *)src));
> +#endif
> +}
> +
> +static void host_to_target_string (void *dst, const void *src)
> +{
> +#if HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 32
> +if (*(uint32_t*)src == 0) {
> +*(uint32_t*)dst = 0;
> + return;
> +}
> +*(uint32_t *)dst = tswap32(h2g(*(uint32_t *)src));
> +#elif HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 32
> +if (*(uint64_t*)src == 0) {
> +*(uint32_t*)dst = 0;
> + return;
> +}
> +*(uint32_t *)dst = tswap32(h2g(*(uint64_t *)src));
> +#elif HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64
> +if (*(uint64_t*)src == 0) {
> +*(uint64_t*)dst = 0;
> + return;
> +}
> +*(uint64_t *)dst = tswap64(h2g(*(uint64_t *)src));
> +#elif HOST_LONG_BITS == 32 && TARGET_ABI_BITS == 64
> +if (*(uint32_t*)src == 0) {
> +*(uint64_t*)dst = 0;
> + return;
> +}
> +*(uint64_t *)dst = tswap64(h2g(*(uint32_t *)src));
> +#endif
> +}
> +
> +static const StructEntry struct_string_def = {
> +.convert = { host_to_target_string, target_to_host_string },
> +.size = { sizeof(target_long), sizeof(long) },
> +.align = { __alignof__(target_long), __alignof__(long) },
> +};
> +
>  /* ??? Implement proper locking for ioctls.  */
>  /* do_ioctl() Must return target values and target errnos. */
>  static abi_long do_ioctl(int fd, abi_long cmd, abi_long arg)
> diff --git a/linux-user/syscall_types.h b/linux-user/syscall_types.h
> index 44b6a58..51fc023 100644
> --- a/linux-user/syscall_types.h
> +++ b/linux-user/syscall_types.h
> @@ -14,9 +14,11 @@ STRUCT(serial_icounter_struct,
>  STRUCT(sockaddr,
> TYPE_SHORT, MK_ARRAY(TYPE_CHAR, 14))
>  
> +STRUCT_SPECIAL(string)
> +
>  STRUCT(rtentry,
> TYPE_ULONG, MK_STRUCT(STRUCT_sockaddr), MK_STRUCT(STRUCT_sockaddr), 
> MK_STRUCT(STRUCT_sockaddr),
> -   TYPE_SHORT, TYPE_SHORT, TYPE_ULONG, TYPE_PTRVOID, TYPE_SHORT, 
> TYPE_PTRVOID,
> +   TYPE_SHORT, TYPE_SHORT, TYPE_ULONG, TYPE_PTRVOID, TYPE_SHORT, 
> MK_STRUCT(STRUCT_string),
> TYPE_ULONG, TYPE_ULONG, TYPE_SHORT)
>  
>  STRUCT(ifmap,

-- 
"Just play. Have fun. Enjoy the game."
- Michael Jordan
"Just play. Have fun. Enjoy the game."
- Michael Jordan




Re: [Qemu-devel] [PATCH] linux-user: allow to use sudo in guest

2013-01-01 Thread Laurent Vivier
Ping !

Le jeudi 20 décembre 2012 à 21:56 +0100, Laurent Vivier a écrit :
> When qemu-linux-user is used in a linux container or chroot,
> if it needs to load binaries with SUID/SGID bits, it needs to
> have root rights to be able to change UID/GID. To do that, we
> need to install it with SUID bits and root owner.
> Then, if the SUID bit is not set on the binary to load,
> qemu will set its UID to the saved UID (the current user ID).
> 
> To be able to retrieve unsecure environment variables (LD_PRELOAD,
> LD_LIBRARY_PATH) with SUID bit, we need to disable "unsetenv()".
> Otherwise libc unsets these variables before entering in main()
> 
> To enable this feature, add "--suid-able" to the configure parameters.
> 
> You can check all is working fine with :
> 
> - install qemu- in your  root filesystem environment
>   and chown root:root ... and chmow +s ...
> 
> - check sudo in this environment (chroot or linux container) :
> 
> laurent@m68k $ id
> uid=1000(laurent) gid=1000(laurent) groups=1000(laurent)
> laurent@m68k $ sudo id
> Password:
> uid=0(root) gid=0(root) groups=0(root)
> 
> - check LD_PRELOAD is available (debian fakeroot is my testcase) :
> 
> laurent@m68k $ fakeroot id
> uid=0(root) gid=0(root) groups=1000(laurent)
> laurent@m68k $ rm -f toto
> laurent@m68k $ fakeroot
> root@m68k # touch toto
> root@m68k # ls -l toto
> -rw-r--r-- 1 root root 0 2012-12-18 22:50 toto
> root@m68k # exit
> exit
> root@m68k # ls -l toto
> -rw-r--r-- 1 laurent laurent 0 2012-12-18 22:50 toto
> 
> Signed-off-by: Laurent Vivier 
> ---
>  configure  |   15 +++
>  linux-user/linuxload.c |   16 +++-
>  linux-user/main.c  |   20 
>  3 files changed, 46 insertions(+), 5 deletions(-)
> 
> diff --git a/configure b/configure
> index b101d5c..2322387 100755
> --- a/configure
> +++ b/configure
> @@ -111,6 +111,7 @@ source_path=`dirname "$0"`
>  cpu=""
>  interp_prefix="/usr/gnemul/qemu-%M"
>  static="no"
> +suidable="no"
>  cross_prefix=""
>  audio_drv_list=""
>  audio_card_list="ac97 es1370 sb16 hda"
> @@ -624,6 +625,9 @@ for opt do
>  LDFLAGS="-static $LDFLAGS"
>  QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
>;;
> +  --suid-able)
> +suidable="yes"
> +  ;;
>--mandir=*) mandir="$optarg"
>;;
>--bindir=*) bindir="$optarg"
> @@ -885,6 +889,11 @@ for opt do
>esac
>  done
>  
> +if test "$suidable" = "yes" -a "$static" = "no" ; then
> +echo "ERROR: --suid-able needs --static"
> +exit 1
> +fi
> +
>  case "$cpu" in
>  sparc)
> LDFLAGS="-m32 $LDFLAGS"
> @@ -1014,6 +1023,7 @@ echo "  --install=INSTALLuse specified install 
> [$install]"
>  echo "  --python=PYTHON  use specified python [$python]"
>  echo "  --smbd=SMBD  use specified smbd [$smbd]"
>  echo "  --static enable static build [$static]"
> +echo "  --suid-able  allow to use qemu with SUID bit [$suidable]"
>  echo "  --mandir=PATHinstall man pages in PATH"
>  echo "  --datadir=PATH   install firmware in PATH$confsuffix"
>  echo "  --docdir=PATHinstall documentation in PATH$confsuffix"
> @@ -3196,6 +3206,7 @@ echo "sparse enabled$sparse"
>  echo "strip binaries$strip_opt"
>  echo "profiler  $profiler"
>  echo "static build  $static"
> +echo "suid-able $suidable"
>  echo "-Werror enabled   $werror"
>  if test "$darwin" = "yes" ; then
>  echo "Cocoa support $cocoa"
> @@ -4160,6 +4171,10 @@ if test "$target_linux_user" = "yes" -o 
> "$target_bsd_user" = "yes" ; then
>  ;;
>esac
>  fi
> +if test "$target_linux_user" = "yes" -a "$suidable" = "yes" ; then
> +  ldflags="$ldflags -Wl,--wrap=__unsetenv"
> +  echo "CONFIG_SUIDABLE=y"  >> $config_target_mak
> +fi
>  
>  echo "LDFLAGS+=$ldflags" >> $config_target_mak
>  echo "QEMU_CFLAGS+=$cflags" >> $config_target_mak
> diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c
> index 381ab89..783afce 100644
> --- a/linux-user/linuxload.c
> +++ b/linux-user/lin

Re: [Qemu-devel] [PATCH] linux-user: correct semctl() and shmctl()

2013-01-01 Thread Laurent Vivier
Ping !

Le jeudi 20 décembre 2012 à 21:58 +0100, Laurent Vivier a écrit :
> The parameter "union semun" of semctl() is not a value
> but a pointer to the value.
> 
> Moreover, all fields of target_su must be swapped (if needed).
> 
> The third argument of shmctl is a pointer.
> 
> WITHOUT this patch:
> 
> $ ipcs
> 
> kernel not configured for shared memory
> 
> qemu: uncaught target signal 11 (Segmentation fault) - core dumped
> 
> WITH this patch:
> 
> $ ipcs
> 
> -- Shared Memory Segments 
> keyshmid  owner  perms  bytes  nattch status
> 0x4e545030 0  root  60096 1
> 0x4e545031 32769  root  60096 1
> 0x4e545032 65538  root  66696 1
> 0x4e545033 98307  root  66696 1
> 0x47505344 131076 root  6668240   1
> 0x3c81b7f5 163845 laurent   6664096   0
> 0x 729513990  laurent   600393216 2  dest
> 0x 729546759  laurent   600393216 2  dest
> 0x 1879179273 laurent   600393216 2  dest
> 
> -- Semaphore Arrays 
> keysemid  owner  perms  nsems
> 0x3c81b7f6 32768  laurent   6661
> 0x1c44ac47 6586369laurent   6001
> 
> -- Message Queues 
> keymsqid  owner  perms  used-bytes   messages
> 0x1c44ac45 458752     laurent60000
> 0x1c44ac46 491521 laurent60000
> 
> Signed-off-by: Laurent Vivier 
> ---
>  linux-user/syscall.c |   37 ++---
>  1 file changed, 26 insertions(+), 11 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index c2a2343..7bab006 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -2656,24 +2656,26 @@ static inline abi_long do_semctl(int semid, int 
> semnum, int cmd,
>  break;
>   case GETALL:
>   case SETALL:
> -err = target_to_host_semarray(semid, &array, target_su.array);
> +err = target_to_host_semarray(semid, &array,
> +  tswapal(target_su.array));
>  if (err)
>  return err;
>  arg.array = array;
>  ret = get_errno(semctl(semid, semnum, cmd, arg));
> -err = host_to_target_semarray(semid, target_su.array, &array);
> +err = host_to_target_semarray(semid, tswapal(target_su.array),
> +  &array);
>  if (err)
>  return err;
>  break;
>   case IPC_STAT:
>   case IPC_SET:
>   case SEM_STAT:
> -err = target_to_host_semid_ds(&dsarg, target_su.buf);
> +err = target_to_host_semid_ds(&dsarg, tswapal(target_su.buf));
>  if (err)
>  return err;
>  arg.buf = &dsarg;
>  ret = get_errno(semctl(semid, semnum, cmd, arg));
> -err = host_to_target_semid_ds(target_su.buf, &dsarg);
> +err = host_to_target_semid_ds(tswapal(target_su.buf), &dsarg);
>  if (err)
>  return err;
>  break;
> @@ -2681,7 +2683,7 @@ static inline abi_long do_semctl(int semid, int semnum, 
> int cmd,
>   case SEM_INFO:
>  arg.__buf = &seminfo;
>  ret = get_errno(semctl(semid, semnum, cmd, arg));
> -err = host_to_target_seminfo(target_su.__buf, &seminfo);
> +err = host_to_target_seminfo(tswapal(target_su.__buf), &seminfo);
>  if (err)
>  return err;
>  break;
> @@ -3161,10 +3163,16 @@ static abi_long do_ipc(unsigned int call, int first,
>  ret = get_errno(semget(first, second, third));
>  break;
>  
> -case IPCOP_semctl:
> -ret = do_semctl(first, second, third, (union 
> target_semun)(abi_ulong) ptr);
> +case IPCOP_semctl: {
> +union target_semun *target_su;
> +if (!lock_user_struct(VERIFY_READ, target_su, ptr, 1)) {
> +ret = -TARGET_EFAULT;
> +break;
> +}
> +ret = do_semctl(first, second, third, *target_su);
> +unlock_user_struct(target_su, ptr, 0);
>  break;
> -
> +}
>  case IPCOP_msgget:
>  ret = get_errno(msgget(first, second));
>  break;
> @@ -3229,7 +3237,7 @@ static abi_long do_ipc(unsigned int call, int first,
>  
>   /* IPC_* and SHM_* command values are the same on all 

Re: [Qemu-devel] [PATCH] linux-user: correct msgrcv()

2013-01-01 Thread Laurent Vivier
Ping !

Le jeudi 20 décembre 2012 à 22:00 +0100, Laurent Vivier a écrit :
> All parameters must be swapped before the call of do_msgrcv().
> 
> Allow faked (debian fakeroot daemon) to work properly.
> 
> WITHOUT this patch:
> 
> $ faked-sysv --foreground --debug
> using 1723744788 as msg key
> msg_key=1723744788
> 1723744788:431
> FAKEROOT: msg=131072, key=1723744788
> FAKEROOT: r=-1, received message type=-150996052, message=-160219330
> FAKEROOT, get_msg: Bad address
> r=14, EINTR=4
> fakeroot: clearing up message queues and semaphores, signal=-1
> fakeroot: database save FAILED
> 
> WITH this patch:
> 
> $ faked-sysv --foreground --debug
> using 1569385744 as msg key
> msg_key=1569385744
> 1569385744:424
> FAKEROOT: msg=0, key=1569385744
> ^C
> fakeroot: clearing up message queues and semaphores, signal=2
> fakeroot: database save FAILED
> 
> Signed-off-by: Laurent Vivier 
> ---
>  linux-user/syscall.c |4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 7bab006..78cb764 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -2901,7 +2901,7 @@ static inline abi_long do_msgrcv(int msqid, abi_long 
> msgp,
>  return -TARGET_EFAULT;
>  
>  host_mb = g_malloc(msgsz+sizeof(long));
> -ret = get_errno(msgrcv(msqid, host_mb, msgsz, tswapal(msgtyp), msgflg));
> +ret = get_errno(msgrcv(msqid, host_mb, msgsz, msgtyp, msgflg));
>  
>  if (ret > 0) {
>  abi_ulong target_mtext_addr = msgp + sizeof(abi_ulong);
> @@ -3199,7 +3199,7 @@ static abi_long do_ipc(unsigned int call, int first,
>  break;
>  }
>  
> -ret = do_msgrcv(first, tmp->msgp, second, tmp->msgtyp, 
> third);
> +ret = do_msgrcv(first, tswapal(tmp->msgp), second, 
> tswapal(tmp->msgtyp), third);
>  
>  unlock_user_struct(tmp, ptr, 0);
>  break;

-- 
"Just play. Have fun. Enjoy the game."
- Michael Jordan
"Just play. Have fun. Enjoy the game."
- Michael Jordan




Re: [Qemu-devel] [PATCH] linux-user: allow to use sudo in guest

2013-01-02 Thread Laurent Vivier
Le mercredi 02 janvier 2013 à 01:16 +, Peter Maydell a écrit :
> On 20 December 2012 20:56, Laurent Vivier  wrote:
> > When qemu-linux-user is used in a linux container or chroot,
> > if it needs to load binaries with SUID/SGID bits, it needs to
> > have root rights to be able to change UID/GID. To do that, we
> > need to install it with SUID bits and root owner.
> 
> I suspect a suid qemu binary is a big fat security hole...

This is why this feature is disabled by default and must be enabled with
configure. Moreover this is only for qemu-linux-user and the first thing
done in main() is to set euid/egid to real uid/gid.

> > Then, if the SUID bit is not set on the binary to load,
> > qemu will set its UID to the saved UID (the current user ID).
> >
> > To be able to retrieve unsecure environment variables (LD_PRELOAD,
> > LD_LIBRARY_PATH) with SUID bit, we need to disable "unsetenv()".
> > Otherwise libc unsets these variables before entering in main()
> 
> This is basically deliberately disabling a glibc security check.

Yes, but this security check is mainly to avoid to load unsecure
library. To avoid this too, we force the "--static" mode. This is not
perfect but bring to qemu-linux-user an interesting feature.

> Needs careful thought and review (which I don't have time for
> just now I'm afraid) before this can be committed.
> 
> -- PMM

-- 
"Just play. Have fun. Enjoy the game."
- Michael Jordan




[Qemu-devel] [PATCH][v2] linux-user: correct semctl() and shmctl()

2013-01-02 Thread Laurent Vivier
The parameter "union semun" of semctl() is not a value
but a pointer to the value.

Moreover, all fields of target_su must be swapped (if needed).

The third argument of shmctl is a pointer.

WITHOUT this patch:

$ ipcs

kernel not configured for shared memory

qemu: uncaught target signal 11 (Segmentation fault) - core dumped

WITH this patch:

$ ipcs

-- Shared Memory Segments 
keyshmid  owner  perms  bytes  nattch status
0x4e545030 0  root  60096 1
0x4e545031 32769  root  60096 1
0x4e545032 65538  root  66696 1
0x4e545033 98307  root  66696 1
0x47505344 131076 root  6668240   1
0x3c81b7f5 163845 laurent   6664096   0
0x 729513990  laurent   600393216 2  dest
0x 729546759  laurent   600393216 2  dest
0x 1879179273 laurent   600393216 2  dest

-- Semaphore Arrays 
keysemid  owner  perms  nsems
0x3c81b7f6 32768  laurent   6661
0x1c44ac47 6586369laurent   6001

-- Message Queues 
keymsqid  owner  perms  used-bytes   messages
0x1c44ac45 458752 laurent60000
0x1c44ac46 491521 laurent60000

Signed-off-by: Laurent Vivier 
---
[v2] move lock_user_struct() in do_semctl()

 linux-user/syscall.c |   39 ---
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e99adab..b2687e1 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2637,8 +2637,9 @@ static inline abi_long host_to_target_semarray(int semid, 
abi_ulong target_addr,
 }
 
 static inline abi_long do_semctl(int semid, int semnum, int cmd,
- union target_semun target_su)
+ abi_ulong ptr)
 {
+union target_semun *target_su;
 union semun arg;
 struct semid_ds dsarg;
 unsigned short *array = NULL;
@@ -2647,43 +2648,42 @@ static inline abi_long do_semctl(int semid, int semnum, 
int cmd,
 abi_long err;
 cmd &= 0xff;
 
+if (!lock_user_struct(VERIFY_READ, target_su, ptr, 1)) {
+return -TARGET_EFAULT;
+}
 switch( cmd ) {
case GETVAL:
case SETVAL:
-arg.val = tswap32(target_su.val);
+arg.val = tswap32(target_su->val);
 ret = get_errno(semctl(semid, semnum, cmd, arg));
-target_su.val = tswap32(arg.val);
+target_su->val = tswap32(arg.val);
 break;
case GETALL:
case SETALL:
-err = target_to_host_semarray(semid, &array, target_su.array);
+err = target_to_host_semarray(semid, &array,
+  tswapal(target_su->array));
 if (err)
-return err;
+break;
 arg.array = array;
 ret = get_errno(semctl(semid, semnum, cmd, arg));
-err = host_to_target_semarray(semid, target_su.array, &array);
-if (err)
-return err;
+err = host_to_target_semarray(semid, tswapal(target_su->array),
+  &array);
 break;
case IPC_STAT:
case IPC_SET:
case SEM_STAT:
-err = target_to_host_semid_ds(&dsarg, target_su.buf);
+err = target_to_host_semid_ds(&dsarg, tswapal(target_su->buf));
 if (err)
-return err;
+break;
 arg.buf = &dsarg;
 ret = get_errno(semctl(semid, semnum, cmd, arg));
-err = host_to_target_semid_ds(target_su.buf, &dsarg);
-if (err)
-return err;
+err = host_to_target_semid_ds(tswapal(target_su->buf), &dsarg);
 break;
case IPC_INFO:
case SEM_INFO:
 arg.__buf = &seminfo;
 ret = get_errno(semctl(semid, semnum, cmd, arg));
-err = host_to_target_seminfo(target_su.__buf, &seminfo);
-if (err)
-return err;
+err = host_to_target_seminfo(tswapal(target_su->__buf), &seminfo);
 break;
case IPC_RMID:
case GETPID:
@@ -2692,6 +2692,7 @@ static inline abi_long do_semctl(int semid, int semnum, 
int cmd,
 ret = get_errno(semctl(semid, semnum, cmd, NULL));
 break;
 }
+unlock_user_struct(target_su, ptr, 0);
 
 return ret;
 }
@@ -3162,7 +3163,7 @@ static abi_long do_ipc(unsigned int call, int first,
 break;
 
 case IPCOP_semctl:
-ret = do_semctl(first, second, third, (union target_semun)(abi_ulong) 
ptr);
+ret = do_semctl(first, second, 

Re: [Qemu-devel] [PATCH 1/3] scripts: extract ELF magics from qemu-binfmt-conf.sh

2013-01-24 Thread Laurent Vivier
Le jeudi 24 janvier 2013 à 19:07 +0100, Alexander Graf a écrit :
> On 20.01.2013, at 00:20, Laurent Vivier wrote:
> 
> > Signed-off-by: Laurent Vivier 
[...]
> > index 0da2618..6235637
> > --- a/scripts/qemu-binfmt-conf.sh
> > +++ b/scripts/qemu-binfmt-conf.sh
> > @@ -1,69 +1,59 @@
> > #!/bin/sh
> > # enable automatic i386/ARM/M68K/MIPS/SPARC/PPC/s390 program execution by 
> > the kernel
> > 
> > +MAGIC=$(dirname $(readlink -f "$0"))/binfmts-magic
> 
> Wouldn't that break with $0 is in PATH?

Yes, it breaks. But the purpose of this script is not to be installed
but to help Qemu developers to create runnable linux root file system.
If this script is installed, the good way to do this is to use the
install base prefix.

Regards,
Laurent
-- 
"Just play. Have fun. Enjoy the game."
- Michael Jordan




Re: [Qemu-devel] [PATCH 3/3] scripts: A script to create linux container using qemu-linux-user.

2013-01-24 Thread Laurent Vivier
Le jeudi 24 janvier 2013 à 19:05 +0100, Alexander Graf a écrit :
> On 20.01.2013, at 00:21, Laurent Vivier wrote:
[...]
> > +create_root() {
> > +   # sanity check
> > +
> > +   if [ $(readlink -f ${CONTAINER_PATH}/) = "/" ]
> > +   then
> > +   echo "ERROR: invalid path ${CONTAINER_PATH}" 1>&2
> > +   exit 1
> > +   fi
> > +
> > +   # check directory
> > +
> > +   if [ -e "${CONTAINER_PATH}" ]
> > +   then
> > +   echo "${CONTAINER_PATH} already exists" 1>&2
> > +   echo "Please, remove it" 1>&2
> > +   exit 1
> > +   fi
> > +
> > +   # Debian bootstrap
> > +
> > +   mkdir -p "${CONTAINER_PATH}"
> > +   debootstrap --foreign \
> 
> I don't think anything running debootstrap belongs in generically
> sounding QEMU source code.

Why ?
As I said, these scripts are helper scripts for developers. If someone
wants to use this with Fedora/RHEL distro, it is to him to add the
"febootstrap" part. BTW, I don't know if there is this kind of tool for
SUSE.

Regards,
Laurent
-- 
"Just play. Have fun. Enjoy the game."
- Michael Jordan




Re: [Qemu-devel] [PATCH] linux-user: convert /proc/net/route when endianess differs

2013-01-26 Thread Laurent Vivier
Le mercredi 02 janvier 2013 à 00:08 +0100, Laurent Vivier a écrit :
> Ping !

ping

> Le jeudi 20 décembre 2012 à 21:53 +0100, Laurent Vivier a écrit :
> > This patch allows to have IP addresses in correct order
> > in the case of "netstat -nr" when the endianess of the
> > guest differs from one of the host.
> > 
> > For instance, an m68k guest on an x86_64 host:
> > 
> > WITHOUT this patch:
> > 
> > $ netstat -nr
> > Kernel IP routing table
> > Destination Gateway Genmask Flags   MSS Window  irtt 
> > Iface
> > 0.0.0.0 1.3.0.100.0.0.0 UG0 0  0 
> > eth0
> > 0.3.0.100.0.0.0 0.255.255.255   U 0 0  0 
> > eth0
> > $ cat /proc/net/route
> > Iface   Destination Gateway Flags   RefCnt  Use Metric  
> > MaskMTU Window  IRTT
> > 
> > eth00103000A00030   0   0   
> > 0   0   0
> > eth00003000A00010   0   0   
> > 00FF0   0   0
> > 
> > WITH this patch:
> > 
> > $ netstat -nr
> > Kernel IP routing table
> > Destination Gateway Genmask Flags   MSS Window  irtt 
> > Iface
> > 0.0.0.0 10.0.3.10.0.0.0 UG0 0  0 
> > eth0
> > 10.0.3.00.0.0.0 255.255.255.0   U 0 0  0 
> > eth0
> > $ cat /proc/net/route
> > Iface   Destination Gateway Flags   RefCnt  Use Metric  
> > MaskMTU Window  IRTT
> > eth0    0a00030100030   0   0   
> > 0   0   0
> > eth00a00030000010   0   0   
> > ff000   0   0
> > 
> > Signed-off-by: Laurent Vivier 
> > ---
> >  linux-user/syscall.c |   42 ++
> >  1 file changed, 42 insertions(+)
> > 
> > diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> > index e99adab..501002b 100644
> > --- a/linux-user/syscall.c
> > +++ b/linux-user/syscall.c
> > @@ -5085,6 +5085,45 @@ static int open_self_auxv(void *cpu_env, int fd)
> >  return 0;
> >  }
> >  
> > +#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
> > +static int open_net_route(void *cpu_env, int fd)
> > +{
> > +FILE *fp;
> > +char *line = NULL;
> > +size_t len = 0;
> > +ssize_t read;
> > +
> > +fp = fopen("/proc/net/route", "r");
> > +if (fp == NULL) {
> > +return -EACCES;
> > +}
> > +
> > +/* read header */
> > +
> > +read = getline(&line, &len, fp);
> > +dprintf(fd, "%s", line);
> > +
> > +/* read routes */
> > +
> > +while ((read = getline(&line, &len, fp)) != -1) {
> > +char iface[16];
> > +uint32_t dest, gw, mask;
> > +unsigned int flags, refcnt, use, metric, mtu, window, irtt;
> > +sscanf(line, 
> > "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n",
> > + iface, &dest, &gw, &flags, &refcnt, &use, &metric,
> > + &mask, &mtu, &window, &irtt);
> > +dprintf(fd, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n",
> > +iface, tswap32(dest), tswap32(gw), flags, refcnt, use,
> > +metric, tswap32(mask), mtu, window, irtt);
> > +}
> > +
> > +free(line);
> > +fclose(fp);
> > +
> > +return 0;
> > +}
> > +#endif
> > +
> >  static int do_open(void *cpu_env, const char *pathname, int flags, mode_t 
> > mode)
> >  {
> >  struct fake_open {
> > @@ -5096,6 +5135,9 @@ static int do_open(void *cpu_env, const char 
> > *pathname, int flags, mode_t mode)
> >  { "/proc/self/maps", open_self_maps },
> >  { "/proc/self/stat", open_self_stat },
> >  { "/proc/self/auxv", open_self_auxv },
> > +#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
> > +{ "/proc/net/route", open_net_route },
> > +#endif
> >  { NULL, NULL }
> >  };
> >  
> 

-- 
"Just play. Have fun. Enjoy the game."
- Michael Jordan
"Just play. Have fun. Enjoy the game."
- Michael Jordan




Re: [Qemu-devel] [PATCH] linux-user: correctly align types in thunking code

2013-01-26 Thread Laurent Vivier
Le mercredi 02 janvier 2013 à 00:08 +0100, Laurent Vivier a écrit :
> Ping !

ping

> Le jeudi 20 décembre 2012 à 21:55 +0100, Laurent Vivier a écrit :
> > This is a follow up
> > of patch:
> > 
> > commit c2e3dee6e03527baf8698698cce76b1a3174969a
> > Author: Laurent Vivier 
> > Date:   Sun Feb 13 23:37:34 2011 +0100
> > 
> > linux-user: Define target alignment size
> > 
> > In my case m68k aligns "int" on 2 not 4. You can check this with the
> > following program:
> > 
> > int main(void)
> > {
> > struct rtentry rt;
> > printf("rt_pad1 %ld %zd\n", offsetof(struct rtentry, rt_pad1),
> > sizeof(rt.rt_pad1));
> > printf("rt_dst %ld %zd\n", offsetof(struct rtentry, rt_dst),
> > sizeof(rt.rt_dst));
> > printf("rt_gateway %ld %zd\n", offsetof(struct rtentry, rt_gateway),
> > sizeof(rt.rt_gateway));
> > printf("rt_genmask %ld %zd\n", offsetof(struct rtentry, rt_genmask),
> > sizeof(rt.rt_genmask));
> > printf("rt_flags %ld %zd\n", offsetof(struct rtentry, rt_flags),
> > sizeof(rt.rt_flags));
> > printf("rt_pad2 %ld %zd\n", offsetof(struct rtentry, rt_pad2),
> > sizeof(rt.rt_pad2));
> > printf("rt_pad3 %ld %zd\n", offsetof(struct rtentry, rt_pad3),
> > sizeof(rt.rt_pad3));
> > printf("rt_pad4 %ld %zd\n", offsetof(struct rtentry, rt_pad4),
> > sizeof(rt.rt_pad4));
> > printf("rt_metric %ld %zd\n", offsetof(struct rtentry, rt_metric),
> > sizeof(rt.rt_metric));
> > printf("rt_dev %ld %zd\n", offsetof(struct rtentry, rt_dev),
> > sizeof(rt.rt_dev));
> > printf("rt_mtu %ld %zd\n", offsetof(struct rtentry, rt_mtu),
> > sizeof(rt.rt_mtu));
> > printf("rt_window %ld %zd\n", offsetof(struct rtentry, rt_window),
> > sizeof(rt.rt_window));
> > printf("rt_irtt %ld %zd\n", offsetof(struct rtentry, rt_irtt),
> > sizeof(rt.rt_irtt));
> > }
> > 
> > And result is :
> > 
> > i386
> > 
> > rt_pad1 0 4
> > rt_dst 4 16
> > rt_gateway 20 16
> > rt_genmask 36 16
> > rt_flags 52 2
> > rt_pad2 54 2
> > rt_pad3 56 4
> > rt_pad4 62 2
> > rt_metric 64 2
> > rt_dev 68 4
> > rt_mtu 72 4
> > rt_window 76 4
> > rt_irtt 80 2
> > 
> > m68k
> > 
> > rt_pad1 0 4
> > rt_dst 4 16
> > rt_gateway 20 16
> > rt_genmask 36 16
> > rt_flags 52 2
> > rt_pad2 54 2
> > rt_pad3 56 4
> > rt_pad4 62 2
> > rt_metric 64 2
> > rt_dev 66 4
> > rt_mtu 70 4
> > rt_window 74 4
> > rt_irtt 78 2
> > 
> > This affects the "route" command :
> > 
> > WITHOUT this patch:
> > 
> > $ sudo route add -net default gw 10.0.3.1 window 1024 irtt 2 eth0
> > $ netstat -nr
> > Kernel IP routing table
> > Destination Gateway Genmask     Flags   MSS Window  irtt 
> > Iface
> > 0.0.0.0 10.0.3.10.0.0.0 UG0 67108866  32768 
> > eth0
> > 10.0.3.00.0.0.0 255.255.255.0   U 0 0  0 
> > eth0
> > 
> > WITH this patch:
> > 
> > $ sudo route add -net default gw 10.0.3.1 window 1024 irtt 2 eth0
> > $ netstat -nr
> > Kernel IP routing table
> > Destination Gateway Genmask Flags   MSS Window  irtt 
> > Iface
> > 0.0.0.0 10.0.3.10.0.0.0 UG0 1024   2 
> > eth0
> > 10.0.3.00.0.0.0 255.255.255.0   U 0 0  0 
> > eth0
> > 
> > Signed-off-by: Laurent Vivier 
> > ---
> >  include/exec/user/thunk.h |   22 +-
> >  1 file changed, 17 insertions(+), 5 deletions(-)
> > 
> > diff --git a/include/exec/user/thunk.h b/include/exec/user/thunk.h
> > index 87025c3..d3e9f3d 100644
> > --- a/include/exec/user/thunk.h
> > +++ b/include/exec/user/thunk.h
> > @@ -151,20 +151,32 @@ static inline int thunk_type_align(const argtype 
> > *type_ptr, int is_host)
> >  case TYPE_CHAR:
> >  return 1;
> >  case TYPE_SHORT:
> > -return 2;
> > +if (is_host) {
> > +retur

Re: [Qemu-devel] [PATCH][v3] linux-user: correct semctl() and shmctl()

2013-01-26 Thread Laurent Vivier
Ping

Le lundi 21 janvier 2013 à 07:25 +0100, Laurent Vivier a écrit :
> The parameter "union semun" of semctl() is not a value
> but a pointer to the value.
> 
> Moreover, all fields of target_su must be swapped (if needed).
> 
> The third argument of shmctl is a pointer.
> 
> WITHOUT this patch:
> 
> $ ipcs
> 
> kernel not configured for shared memory
> 
> qemu: uncaught target signal 11 (Segmentation fault) - core dumped
> 
> WITH this patch:
> 
> $ ipcs
> 
> -- Shared Memory Segments 
> keyshmid  owner  perms  bytes  nattch status
> 0x4e545030 0  root  60096 1
> 0x4e545031 32769  root  60096 1
> 0x4e545032 65538  root  66696 1
> 0x4e545033 98307  root  66696 1
> 0x47505344 131076 root  6668240   1
> 0x3c81b7f5 163845 laurent   6664096   0
> 0x 729513990  laurent   600393216 2  dest
> 0x 729546759  laurent   600393216 2  dest
> 0x 1879179273 laurent   600393216 2  dest
> 
> -- Semaphore Arrays 
> keysemid  owner  perms  nsems
> 0x3c81b7f6 32768  laurent   6661
> 0x1c44ac47 6586369laurent   6001
> 
> -- Message Queues 
> keymsqid  owner  perms  used-bytes   messages
> 0x1c44ac45 458752     laurent60000
> 0x1c44ac46 491521 laurent60000
> 
> Signed-off-by: Laurent Vivier 
> ---
> v2: move lock_user_struct() in do_semctl()
> v3: correctly set the return value
> 
>  linux-user/syscall.c |   49 +
>  1 file changed, 33 insertions(+), 16 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 693e66f..d44558d 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -2635,8 +2635,9 @@ static inline abi_long host_to_target_semarray(int 
> semid, abi_ulong target_addr,
>  }
>  
>  static inline abi_long do_semctl(int semid, int semnum, int cmd,
> - union target_semun target_su)
> + abi_ulong ptr)
>  {
> +union target_semun *target_su;
>  union semun arg;
>  struct semid_ds dsarg;
>  unsigned short *array = NULL;
> @@ -2645,43 +2646,58 @@ static inline abi_long do_semctl(int semid, int 
> semnum, int cmd,
>  abi_long err;
>  cmd &= 0xff;
>  
> +if (!lock_user_struct(VERIFY_READ, target_su, ptr, 1)) {
> +return -TARGET_EFAULT;
> +}
>  switch( cmd ) {
>   case GETVAL:
>   case SETVAL:
> -arg.val = tswap32(target_su.val);
> +arg.val = tswap32(target_su->val);
>  ret = get_errno(semctl(semid, semnum, cmd, arg));
> -target_su.val = tswap32(arg.val);
> +target_su->val = tswap32(arg.val);
>  break;
>   case GETALL:
>   case SETALL:
> -err = target_to_host_semarray(semid, &array, target_su.array);
> -if (err)
> +err = target_to_host_semarray(semid, &array,
> +  tswapal(target_su->array));
> +if (err) {
> +unlock_user_struct(target_su, ptr, 0);
>  return err;
> +}
>  arg.array = array;
>  ret = get_errno(semctl(semid, semnum, cmd, arg));
> -err = host_to_target_semarray(semid, target_su.array, &array);
> -if (err)
> +err = host_to_target_semarray(semid, tswapal(target_su->array),
> +  &array);
> +if (err) {
> +unlock_user_struct(target_su, ptr, 0);
>  return err;
> +}
>  break;
>   case IPC_STAT:
>   case IPC_SET:
>   case SEM_STAT:
> -err = target_to_host_semid_ds(&dsarg, target_su.buf);
> -if (err)
> +err = target_to_host_semid_ds(&dsarg, tswapal(target_su->buf));
> +if (err) {
> +unlock_user_struct(target_su, ptr, 0);
>  return err;
> +}
>  arg.buf = &dsarg;
>  ret = get_errno(semctl(semid, semnum, cmd, arg));
> -err = host_to_target_semid_ds(target_su.buf, &dsarg);
> -if (err)
> +err = host_to_target_semid_ds(tswapal(target_su->buf), &dsarg);
> +if (err) {
> +  

Re: [Qemu-devel] [PATCH] linux-user: correct msgrcv()

2013-01-26 Thread Laurent Vivier
Ping

Le dimanche 20 janvier 2013 à 00:29 +0100, Laurent Vivier a écrit :
> Le mercredi 02 janvier 2013 à 00:03 +, Peter Maydell a écrit :
> > On 20 December 2012 21:00, Laurent Vivier  wrote:
> > > All parameters must be swapped before the call of do_msgrcv().
> > > --- a/linux-user/syscall.c
> > > +++ b/linux-user/syscall.c
> > > @@ -2901,7 +2901,7 @@ static inline abi_long do_msgrcv(int msqid, 
> > > abi_long msgp,
> > >  return -TARGET_EFAULT;
> > >
> > >  host_mb = g_malloc(msgsz+sizeof(long));
> > > -ret = get_errno(msgrcv(msqid, host_mb, msgsz, tswapal(msgtyp), 
> > > msgflg));
> > > +ret = get_errno(msgrcv(msqid, host_mb, msgsz, msgtyp, msgflg));
> > >
> > >  if (ret > 0) {
> > >  abi_ulong target_mtext_addr = msgp + sizeof(abi_ulong);
> > > @@ -3199,7 +3199,7 @@ static abi_long do_ipc(unsigned int call, int first,
> > >  break;
> > >  }
> > >
> > > -ret = do_msgrcv(first, tmp->msgp, second, tmp->msgtyp, 
> > > third);
> > > +ret = do_msgrcv(first, tswapal(tmp->msgp), second, 
> > > tswapal(tmp->msgtyp), third);
> > >
> > >  unlock_user_struct(tmp, ptr, 0);
> > >  break;
> > 
> > Untested but looks right.
> > Reviewed-by: Peter Maydell 
> 
> ping ?
> 
> Laurent

-- 
"Just play. Have fun. Enjoy the game."
- Michael Jordan
"Just play. Have fun. Enjoy the game."
- Michael Jordan




Re: [Qemu-devel] [PATCH] linux-user: correct print_timeval() swap tv_sec and tv_usec

2013-01-26 Thread Laurent Vivier
ping

Le lundi 31 décembre 2012 à 20:45 +0100, Laurent Vivier a écrit :
> From: Laurent Vivier 
> 
> Signed-off-by: Laurent Vivier 
> ---
>  linux-user/strace.c |2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/linux-user/strace.c b/linux-user/strace.c
> index 6ec90e8..4e91a6e 100644
> --- a/linux-user/strace.c
> +++ b/linux-user/strace.c
> @@ -682,7 +682,7 @@ print_timeval(abi_ulong tv_addr, int last)
>  if (!tv)
>  return;
>  gemu_log("{" TARGET_ABI_FMT_ld "," TARGET_ABI_FMT_ld "}%s",
> -tv->tv_sec, tv->tv_usec, get_comma(last));
> +tswapal(tv->tv_sec), tswapal(tv->tv_usec), get_comma(last));
>  unlock_user(tv, tv_addr, 0);
>  } else
>  gemu_log("NULL%s", get_comma(last));

-- 
"Just play. Have fun. Enjoy the game."
- Michael Jordan
"Just play. Have fun. Enjoy the game."
- Michael Jordan




Re: [Qemu-devel] [PATCH][v2] linux-user: correct setsockopt()

2013-01-26 Thread Laurent Vivier
Le dimanche 20 janvier 2013 à 00:32 +0100, Laurent Vivier a écrit :
> ping ?

ping

> Le mardi 01 janvier 2013 à 19:24 +0100, Laurent Vivier a écrit :
> > From: Laurent Vivier 
> > 
> > SO_SNDTIMEO and SO_RCVTIMEO take a struct timeval, not an int
> > 
> > To test this, you can use :
> > 
> > QEMU_STRACE= ping localhost 2>&1 |grep TIMEO
> > 568 setsockopt(3,SOL_SOCKET,SO_SNDTIMEO,{1,0},8) = 0
> > 568 setsockopt(3,SOL_SOCKET,SO_RCVTIMEO,{1,0},8) = 0
> > 
> > Signed-off-by: Laurent Vivier 
> > ---
> > v2: pass checkpatch.pl
> > 
> >  linux-user/syscall.c |   28 ++--
> >  1 file changed, 22 insertions(+), 6 deletions(-)
> > 
> > diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> > index e99adab..2b2bd2b 100644
> > --- a/linux-user/syscall.c
> > +++ b/linux-user/syscall.c
> > @@ -1491,6 +1491,28 @@ static abi_long do_setsockopt(int sockfd, int level, 
> > int optname,
> >  break;
> >  case TARGET_SOL_SOCKET:
> >  switch (optname) {
> > +case TARGET_SO_RCVTIMEO:
> > +{
> > +struct timeval tv;
> > +
> > +optname = SO_RCVTIMEO;
> > +
> > +set_timeout:
> > +if (optlen != sizeof(struct target_timeval)) {
> > +return -TARGET_EINVAL;
> > +}
> > +
> > +if (copy_from_user_timeval(&tv, optval_addr)) {
> > +return -TARGET_EFAULT;
> > +}
> > +
> > +ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname,
> > +&tv, sizeof(tv)));
> > +return ret;
> > +}
> > +case TARGET_SO_SNDTIMEO:
> > +optname = SO_SNDTIMEO;
> > +goto set_timeout;
> >  /* Options with 'int' argument.  */
> >  case TARGET_SO_DEBUG:
> > optname = SO_DEBUG;
> > @@ -1542,12 +1564,6 @@ static abi_long do_setsockopt(int sockfd, int level, 
> > int optname,
> >  case TARGET_SO_RCVLOWAT:
> > optname = SO_RCVLOWAT;
> > break;
> > -case TARGET_SO_RCVTIMEO:
> > -   optname = SO_RCVTIMEO;
> > -   break;
> > -case TARGET_SO_SNDTIMEO:
> > -   optname = SO_SNDTIMEO;
> > -   break;
> >  break;
> >  default:
> >  goto unimplemented;
> 

-- 
"Just play. Have fun. Enjoy the game."
- Michael Jordan
"Just play. Have fun. Enjoy the game."
- Michael Jordan




Re: [Qemu-devel] [PATCH][v2] linux-user: correct reboot()

2013-01-26 Thread Laurent Vivier
ping

Le dimanche 20 janvier 2013 à 00:26 +0100, Laurent Vivier a écrit :
> Le lundi 07 janvier 2013 à 21:46 +, Peter Maydell a écrit :
> > On 7 January 2013 21:40, Laurent Vivier  wrote:
> > > According to man reboot(2), the 4th argument is only used with
> > > LINUX_REBOOT_CMD_RESTART2. In other cases, trying to convert
> > > the value can generate EFAULT.
> > >
> > > Signed-off-by: Laurent Vivier 
> > 
> > Reviewed-by: Peter Maydell 
> 
> ping ?
> 
> Laurent
> 

-- 
"Just play. Have fun. Enjoy the game."
- Michael Jordan
"Just play. Have fun. Enjoy the game."
- Michael Jordan




Re: [Qemu-devel] [PATCH] linux-user: allow to use sudo in guest

2013-01-26 Thread Laurent Vivier
In fact, this patch is useless as binfmt_mist provides a flag to manage
credentials and security token.

A new patch follows...

Regards,
Laurent

Le jeudi 20 décembre 2012 à 21:56 +0100, Laurent Vivier a écrit :
> When qemu-linux-user is used in a linux container or chroot,
> if it needs to load binaries with SUID/SGID bits, it needs to
> have root rights to be able to change UID/GID. To do that, we
> need to install it with SUID bits and root owner.
> Then, if the SUID bit is not set on the binary to load,
> qemu will set its UID to the saved UID (the current user ID).
> 
> To be able to retrieve unsecure environment variables (LD_PRELOAD,
> LD_LIBRARY_PATH) with SUID bit, we need to disable "unsetenv()".
> Otherwise libc unsets these variables before entering in main()
> 
> To enable this feature, add "--suid-able" to the configure parameters.
> 
> You can check all is working fine with :
> 
> - install qemu- in your  root filesystem environment
>   and chown root:root ... and chmow +s ...
> 
> - check sudo in this environment (chroot or linux container) :
> 
> laurent@m68k $ id
> uid=1000(laurent) gid=1000(laurent) groups=1000(laurent)
> laurent@m68k $ sudo id
> Password:
> uid=0(root) gid=0(root) groups=0(root)
> 
> - check LD_PRELOAD is available (debian fakeroot is my testcase) :
> 
> laurent@m68k $ fakeroot id
> uid=0(root) gid=0(root) groups=1000(laurent)
> laurent@m68k $ rm -f toto
> laurent@m68k $ fakeroot
> root@m68k # touch toto
> root@m68k # ls -l toto
> -rw-r--r-- 1 root root 0 2012-12-18 22:50 toto
> root@m68k # exit
> exit
> root@m68k # ls -l toto
> -rw-r--r-- 1 laurent laurent 0 2012-12-18 22:50 toto
> 
> Signed-off-by: Laurent Vivier 
> ---
>  configure  |   15 +++
>  linux-user/linuxload.c |   16 +++-
>  linux-user/main.c  |   20 
>  3 files changed, 46 insertions(+), 5 deletions(-)
> 
> diff --git a/configure b/configure
> index b101d5c..2322387 100755
> --- a/configure
> +++ b/configure
> @@ -111,6 +111,7 @@ source_path=`dirname "$0"`
>  cpu=""
>  interp_prefix="/usr/gnemul/qemu-%M"
>  static="no"
> +suidable="no"
>  cross_prefix=""
>  audio_drv_list=""
>  audio_card_list="ac97 es1370 sb16 hda"
> @@ -624,6 +625,9 @@ for opt do
>  LDFLAGS="-static $LDFLAGS"
>  QEMU_PKG_CONFIG_FLAGS="--static $QEMU_PKG_CONFIG_FLAGS"
>;;
> +  --suid-able)
> +suidable="yes"
> +  ;;
>--mandir=*) mandir="$optarg"
>;;
>--bindir=*) bindir="$optarg"
> @@ -885,6 +889,11 @@ for opt do
>esac
>  done
>  
> +if test "$suidable" = "yes" -a "$static" = "no" ; then
> +echo "ERROR: --suid-able needs --static"
> +exit 1
> +fi
> +
>  case "$cpu" in
>  sparc)
> LDFLAGS="-m32 $LDFLAGS"
> @@ -1014,6 +1023,7 @@ echo "  --install=INSTALLuse specified install 
> [$install]"
>  echo "  --python=PYTHON  use specified python [$python]"
>  echo "  --smbd=SMBD  use specified smbd [$smbd]"
>  echo "  --static enable static build [$static]"
> +echo "  --suid-able  allow to use qemu with SUID bit [$suidable]"
>  echo "  --mandir=PATHinstall man pages in PATH"
>  echo "  --datadir=PATH   install firmware in PATH$confsuffix"
>  echo "  --docdir=PATHinstall documentation in PATH$confsuffix"
> @@ -3196,6 +3206,7 @@ echo "sparse enabled$sparse"
>  echo "strip binaries$strip_opt"
>  echo "profiler  $profiler"
>  echo "static build  $static"
> +echo "suid-able $suidable"
>  echo "-Werror enabled   $werror"
>  if test "$darwin" = "yes" ; then
>  echo "Cocoa support $cocoa"
> @@ -4160,6 +4171,10 @@ if test "$target_linux_user" = "yes" -o 
> "$target_bsd_user" = "yes" ; then
>  ;;
>esac
>  fi
> +if test "$target_linux_user" = "yes" -a "$suidable" = "yes" ; then
> +  ldflags="$ldflags -Wl,--wrap=__unsetenv"
> +  echo "CONFIG_SUIDABLE=y"  >> $config_target_mak
> +fi
>  
>  echo "LDFLAGS+=$ldflags" >> $config_target_mak
>  echo "QEMU_CFLAGS+=$cflags" >> $config_target_mak
> diff --git a/l

[Qemu-devel] [PATCH] linux-user: add support of binfmt_misc 'O' flag

2013-01-26 Thread Laurent Vivier
The binfmt_misc module can calculate the credentials and security
token according to the binary instead of to the interpreter if the
'C' flag is enabled.

To be able to execute non-readable binaries, this flag implies 'O'
flag. When 'O' flag is enabled, bintfmt_misc opens the file for
reading and pass the file descriptor to the interpreter.

References:
linux/Documentation/binfmt_misc.txt  ['O' and 'C' description]
linux/fs/binfmt_misc.c linux/fs/binfmt_elf.c [ AT_EXECFD usage ]

Signed-off-by: Laurent Vivier 
---
 linux-user/linuxload.c |8 ++--
 linux-user/main.c  |   32 +++-
 linux-user/qemu.h  |2 +-
 3 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c
index 381ab89..2c3ec58 100644
--- a/linux-user/linuxload.c
+++ b/linux-user/linuxload.c
@@ -130,7 +130,7 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong 
sp,
 return sp;
 }
 
-int loader_exec(const char * filename, char ** argv, char ** envp,
+int loader_exec(int fdexec, const char *filename, char **argv, char **envp,
  struct target_pt_regs * regs, struct image_info *infop,
  struct linux_binprm *bprm)
 {
@@ -139,11 +139,7 @@ int loader_exec(const char * filename, char ** argv, char 
** envp,
 
 bprm->p = TARGET_PAGE_SIZE*MAX_ARG_PAGES-sizeof(unsigned int);
 memset(bprm->page, 0, sizeof(bprm->page));
-retval = open(filename, O_RDONLY);
-if (retval < 0) {
-return -errno;
-}
-bprm->fd = retval;
+bprm->fd = fdexec;
 bprm->filename = (char *)filename;
 bprm->argc = count(argv);
 bprm->argv = argv;
diff --git a/linux-user/main.c b/linux-user/main.c
index fcbeaca..e2ed210 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3385,6 +3385,26 @@ static int parse_args(int argc, char **argv)
 return optind;
 }
 
+static int get_execfd(char **envp)
+{
+typedef struct {
+long a_type;
+long a_val;
+} auxv_t;
+auxv_t *auxv;
+
+while (*envp++ != NULL) {
+;
+}
+
+for (auxv = (auxv_t *)envp; auxv->a_type != AT_NULL; auxv++) {
+if (auxv->a_type == AT_EXECFD) {
+return auxv->a_val;
+}
+}
+return -1;
+}
+
 int main(int argc, char **argv, char **envp)
 {
 const char *log_file = DEBUG_LOGFILE;
@@ -3399,6 +3419,7 @@ int main(int argc, char **argv, char **envp)
 int target_argc;
 int i;
 int ret;
+int execfd;
 
 module_call_init(MODULE_INIT_QOM);
 
@@ -3543,7 +3564,16 @@ int main(int argc, char **argv, char **envp)
 env->opaque = ts;
 task_settid(ts);
 
-ret = loader_exec(filename, target_argv, target_environ, regs,
+execfd = get_execfd(envp);
+if (execfd < 0) {
+execfd = open(filename, O_RDONLY);
+}
+if (execfd < 0) {
+printf("Error while loading %s: %s\n", filename, strerror(-execfd));
+_exit(1);
+}
+
+ret = loader_exec(execfd, filename, target_argv, target_environ, regs,
 info, &bprm);
 if (ret != 0) {
 printf("Error while loading %s: %s\n", filename, strerror(-ret));
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index eb5ca6d..981ef2c 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -179,7 +179,7 @@ struct linux_binprm {
 void do_init_thread(struct target_pt_regs *regs, struct image_info *infop);
 abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
   abi_ulong stringp, int push_ptr);
-int loader_exec(const char * filename, char ** argv, char ** envp,
+int loader_exec(int fdexec, const char *filename, char **argv, char **envp,
  struct target_pt_regs * regs, struct image_info *infop,
  struct linux_binprm *);
 
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH][v2] linux-user: correct setsockopt()

2013-01-30 Thread Laurent Vivier

Le 30 janvier 2013 à 11:42, Peter Maydell  a écrit :
> On 30 January 2013 08:45, Riku Voipio  wrote:
> > On Sat, Jan 26, 2013 at 12:24:56PM +0100, Laurent Vivier wrote:
> >> Le dimanche 20 janvier 2013 à 00:32 +0100, Laurent Vivier a écrit :
> >> > ping ?
> >>
> >> ping
> >
> > I'm really not managing to find time for qemu linux-user maintainance
> > at the moment. I suggest you send the patches directly as pull request.
>
> ...but only the ones somebody has reviewed, please.
>

Yes, I will ask for a pull only patches with a Reviewed-by .

Regards,
Laurent

[Qemu-devel] [PULL 0/4] generic linux-user patches

2013-01-30 Thread Laurent Vivier
Hi,


Please pull this linux-user patches queue into master.

All these patches have already been sent and reviewed on the mailing list.

The following changes since commit 4c37ef022381e777251d7084591978a4dc622efe:

host-utils: add ffsl (2013-01-25 18:18:32 +0100)

are available in the git repository at:

https://git.gitorious.org/qemu-m68k/qemu-m68k.git for-linux-user

for you to fetch changes up to c07ecc6866f8c5eb2e0b23ba20214000310355e0:

linux-user: correct reboot() (2013-01-30 12:13:21 +0100)


Laurent Vivier (4):
linux-user: correct msgrcv()
linux-user: correct print_timeval() swap tv_sec and tv_usec
linux-user: correct setsockopt()
linux-user: correct reboot()

linux-user/strace.c | 2 +-
linux-user/syscall.c | 48 
2 files changed, 37 insertions(+), 13 deletions(-)

[Qemu-devel] [PATCH][v4] linux-user: correct semctl() and shmctl()

2013-01-31 Thread Laurent Vivier
The parameter "union semun" of semctl() is not a value
but a pointer to the value.

Moreover, all fields of target_su must be swapped (if needed).

The third argument of shmctl is a pointer.

WITHOUT this patch:

$ ipcs

kernel not configured for shared memory

qemu: uncaught target signal 11 (Segmentation fault) - core dumped

WITH this patch:

$ ipcs

-- Shared Memory Segments 
keyshmid  owner  perms  bytes  nattch status
0x4e545030 0  root  60096 1
0x4e545031 32769  root  60096 1
0x4e545032 65538  root  66696 1
0x4e545033 98307  root  66696 1
0x47505344 131076 root  6668240   1
0x3c81b7f5 163845 laurent   6664096   0
0x 729513990  laurent   600393216 2  dest
0x 729546759  laurent   600393216 2  dest
0x 1879179273 laurent   600393216 2  dest

-- Semaphore Arrays 
keysemid  owner  perms  nsems
0x3c81b7f6 32768  laurent   6661
0x1c44ac47 6586369laurent   6001

-- Message Queues 
keymsqid  owner  perms  used-bytes   messages
0x1c44ac45 458752 laurent60000
0x1c44ac46 491521 laurent60000

Signed-off-by: Laurent Vivier 
---
v2: move lock_user_struct() in do_semctl()
v3: correctly set the return value
v3: don't duplicat unlock_user_struct(), set err to ret instead

 linux-user/syscall.c |   44 +++-
 1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 08538fc..1aef535 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2652,8 +2652,9 @@ static inline abi_long host_to_target_semarray(int semid, 
abi_ulong target_addr,
 }
 
 static inline abi_long do_semctl(int semid, int semnum, int cmd,
- union target_semun target_su)
+ abi_ulong ptr)
 {
+union target_semun *target_su;
 union semun arg;
 struct semid_ds dsarg;
 unsigned short *array = NULL;
@@ -2662,43 +2663,51 @@ static inline abi_long do_semctl(int semid, int semnum, 
int cmd,
 abi_long err;
 cmd &= 0xff;
 
+if (!lock_user_struct(VERIFY_READ, target_su, ptr, 1)) {
+return -TARGET_EFAULT;
+}
 switch( cmd ) {
case GETVAL:
case SETVAL:
-arg.val = tswap32(target_su.val);
+arg.val = tswap32(target_su->val);
 ret = get_errno(semctl(semid, semnum, cmd, arg));
-target_su.val = tswap32(arg.val);
+target_su->val = tswap32(arg.val);
 break;
case GETALL:
case SETALL:
-err = target_to_host_semarray(semid, &array, target_su.array);
+err = target_to_host_semarray(semid, &array,
+  tswapal(target_su->array));
 if (err)
 return err;
 arg.array = array;
 ret = get_errno(semctl(semid, semnum, cmd, arg));
-err = host_to_target_semarray(semid, target_su.array, &array);
-if (err)
-return err;
+err = host_to_target_semarray(semid, tswapal(target_su->array),
+  &array);
+if (err) {
+ret = err;
+}
 break;
case IPC_STAT:
case IPC_SET:
case SEM_STAT:
-err = target_to_host_semid_ds(&dsarg, target_su.buf);
+err = target_to_host_semid_ds(&dsarg, tswapal(target_su->buf));
 if (err)
 return err;
 arg.buf = &dsarg;
 ret = get_errno(semctl(semid, semnum, cmd, arg));
-err = host_to_target_semid_ds(target_su.buf, &dsarg);
-if (err)
-return err;
+err = host_to_target_semid_ds(tswapal(target_su->buf), &dsarg);
+if (err) {
+ret = err;
+}
 break;
case IPC_INFO:
case SEM_INFO:
 arg.__buf = &seminfo;
 ret = get_errno(semctl(semid, semnum, cmd, arg));
-err = host_to_target_seminfo(target_su.__buf, &seminfo);
-if (err)
-return err;
+err = host_to_target_seminfo(tswapal(target_su->__buf), &seminfo);
+if (err) {
+ret = err;
+}
 break;
case IPC_RMID:
case GETPID:
@@ -2707,6 +2716,7 @@ static inline abi_long do_semctl(int semid, int semnum, 
int cmd,
 ret = get_errno(semctl(semid, semnum, cmd, NULL));
 break;
 }
+unlock_user_struct(target_su, ptr, 0);
 
 

Re: [Qemu-devel] [PATCH][v4] linux-user: correct semctl() and shmctl()

2013-01-31 Thread Laurent Vivier
Sorry, this one is wrong, I missed some returns...

Regards,
LAurent

Le jeudi 31 janvier 2013 à 20:36 +0100, Laurent Vivier a écrit :
> The parameter "union semun" of semctl() is not a value
> but a pointer to the value.
> 
> Moreover, all fields of target_su must be swapped (if needed).
> 
> The third argument of shmctl is a pointer.
> 
> WITHOUT this patch:
> 
> $ ipcs
> 
> kernel not configured for shared memory
> 
> qemu: uncaught target signal 11 (Segmentation fault) - core dumped
> 
> WITH this patch:
> 
> $ ipcs
> 
> -- Shared Memory Segments 
> keyshmid  owner  perms  bytes  nattch status
> 0x4e545030 0  root  60096 1
> 0x4e545031 32769  root  60096 1
> 0x4e545032 65538  root  66696 1
> 0x4e545033 98307  root  66696 1
> 0x47505344 131076 root  6668240   1
> 0x3c81b7f5 163845 laurent   6664096   0
> 0x 729513990  laurent   600393216 2  dest
> 0x 729546759  laurent   600393216 2  dest
> 0x 1879179273 laurent   600393216 2  dest
> 
> -- Semaphore Arrays 
> keysemid  owner  perms  nsems
> 0x3c81b7f6 32768  laurent   6661
> 0x1c44ac47 6586369laurent   6001
> 
> -- Message Queues 
> keymsqid  owner  perms  used-bytes   messages
> 0x1c44ac45 458752     laurent60000
> 0x1c44ac46 491521 laurent60000
> 
> Signed-off-by: Laurent Vivier 
> ---
> v2: move lock_user_struct() in do_semctl()
> v3: correctly set the return value
> v3: don't duplicat unlock_user_struct(), set err to ret instead
> 
>  linux-user/syscall.c |   44 +++-
>  1 file changed, 27 insertions(+), 17 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 08538fc..1aef535 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -2652,8 +2652,9 @@ static inline abi_long host_to_target_semarray(int 
> semid, abi_ulong target_addr,
>  }
>  
>  static inline abi_long do_semctl(int semid, int semnum, int cmd,
> - union target_semun target_su)
> + abi_ulong ptr)
>  {
> +union target_semun *target_su;
>  union semun arg;
>  struct semid_ds dsarg;
>  unsigned short *array = NULL;
> @@ -2662,43 +2663,51 @@ static inline abi_long do_semctl(int semid, int 
> semnum, int cmd,
>  abi_long err;
>  cmd &= 0xff;
>  
> +if (!lock_user_struct(VERIFY_READ, target_su, ptr, 1)) {
> +return -TARGET_EFAULT;
> +}
>  switch( cmd ) {
>   case GETVAL:
>   case SETVAL:
> -arg.val = tswap32(target_su.val);
> +arg.val = tswap32(target_su->val);
>  ret = get_errno(semctl(semid, semnum, cmd, arg));
> -target_su.val = tswap32(arg.val);
> +target_su->val = tswap32(arg.val);
>  break;
>   case GETALL:
>   case SETALL:
> -err = target_to_host_semarray(semid, &array, target_su.array);
> +err = target_to_host_semarray(semid, &array,
> +  tswapal(target_su->array));
>  if (err)
>  return err;
>  arg.array = array;
>  ret = get_errno(semctl(semid, semnum, cmd, arg));
> -err = host_to_target_semarray(semid, target_su.array, &array);
> -if (err)
> -return err;
> +err = host_to_target_semarray(semid, tswapal(target_su->array),
> +  &array);
> +if (err) {
> +ret = err;
> +}
>  break;
>   case IPC_STAT:
>   case IPC_SET:
>   case SEM_STAT:
> -err = target_to_host_semid_ds(&dsarg, target_su.buf);
> +err = target_to_host_semid_ds(&dsarg, tswapal(target_su->buf));
>  if (err)
>  return err;
>  arg.buf = &dsarg;
>  ret = get_errno(semctl(semid, semnum, cmd, arg));
> -err = host_to_target_semid_ds(target_su.buf, &dsarg);
> -if (err)
> -return err;
> +err = host_to_target_semid_ds(tswapal(target_su->buf), &dsarg);
> +if (err) {
> +ret = err;
> +}
>

[Qemu-devel] [PATCH][v5] linux-user: correct semctl() and shmctl()

2013-01-31 Thread Laurent Vivier
The parameter "union semun" of semctl() is not a value
but a pointer to the value.

Moreover, all fields of target_su must be swapped (if needed).

The third argument of shmctl is a pointer.

WITHOUT this patch:

$ ipcs

kernel not configured for shared memory

qemu: uncaught target signal 11 (Segmentation fault) - core dumped

WITH this patch:

$ ipcs

-- Shared Memory Segments 
keyshmid  owner  perms  bytes  nattch status
0x4e545030 0  root  60096 1
0x4e545031 32769  root  60096 1
0x4e545032 65538  root  66696 1
0x4e545033 98307  root  66696 1
0x47505344 131076 root  6668240   1
0x3c81b7f5 163845 laurent   6664096   0
0x 729513990  laurent   600393216 2  dest
0x 729546759  laurent   600393216 2  dest
0x 1879179273 laurent   600393216 2  dest

-- Semaphore Arrays 
keysemid  owner  perms  nsems
0x3c81b7f6 32768  laurent   6661
0x1c44ac47 6586369laurent   6001

-- Message Queues 
keymsqid  owner  perms  used-bytes   messages
0x1c44ac45 458752 laurent60000
0x1c44ac46 491521 laurent60000

Signed-off-by: Laurent Vivier 
---
v2: move lock_user_struct() in do_semctl()
v3: correctly set the return value
v3: don't duplicate unlock_user_struct(), set err to ret instead
v4: replace all return by if (err) { ret = err; break; }

 linux-user/syscall.c |   56 +++---
 1 file changed, 35 insertions(+), 21 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 08538fc..6610c24 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2652,8 +2652,9 @@ static inline abi_long host_to_target_semarray(int semid, 
abi_ulong target_addr,
 }
 
 static inline abi_long do_semctl(int semid, int semnum, int cmd,
- union target_semun target_su)
+ abi_ulong ptr)
 {
+union target_semun *target_su;
 union semun arg;
 struct semid_ds dsarg;
 unsigned short *array = NULL;
@@ -2662,43 +2663,55 @@ static inline abi_long do_semctl(int semid, int semnum, 
int cmd,
 abi_long err;
 cmd &= 0xff;
 
+if (!lock_user_struct(VERIFY_READ, target_su, ptr, 1)) {
+return -TARGET_EFAULT;
+}
 switch( cmd ) {
case GETVAL:
case SETVAL:
-arg.val = tswap32(target_su.val);
+arg.val = tswap32(target_su->val);
 ret = get_errno(semctl(semid, semnum, cmd, arg));
-target_su.val = tswap32(arg.val);
+target_su->val = tswap32(arg.val);
 break;
case GETALL:
case SETALL:
-err = target_to_host_semarray(semid, &array, target_su.array);
-if (err)
-return err;
+err = target_to_host_semarray(semid, &array,
+  tswapal(target_su->array));
+if (err) {
+ret = err;
+break;
+}
 arg.array = array;
 ret = get_errno(semctl(semid, semnum, cmd, arg));
-err = host_to_target_semarray(semid, target_su.array, &array);
-if (err)
-return err;
+err = host_to_target_semarray(semid, tswapal(target_su->array),
+  &array);
+if (err) {
+ret = err;
+}
 break;
case IPC_STAT:
case IPC_SET:
case SEM_STAT:
-err = target_to_host_semid_ds(&dsarg, target_su.buf);
-if (err)
-return err;
+err = target_to_host_semid_ds(&dsarg, tswapal(target_su->buf));
+if (err) {
+ret = err;
+break;
+}
 arg.buf = &dsarg;
 ret = get_errno(semctl(semid, semnum, cmd, arg));
-err = host_to_target_semid_ds(target_su.buf, &dsarg);
-if (err)
-return err;
+err = host_to_target_semid_ds(tswapal(target_su->buf), &dsarg);
+if (err) {
+ret = err;
+}
 break;
case IPC_INFO:
case SEM_INFO:
 arg.__buf = &seminfo;
 ret = get_errno(semctl(semid, semnum, cmd, arg));
-err = host_to_target_seminfo(target_su.__buf, &seminfo);
-if (err)
-return err;
+err = host_to_target_seminfo(tswapal(target_su->__buf), &seminfo);
+if (err) {
+ret = err;
+}
 break;
case IPC_RMID:
  

Re: [Qemu-devel] [PATCH][v5] linux-user: correct semctl() and shmctl()

2013-02-04 Thread Laurent Vivier
Le lundi 04 février 2013 à 15:16 +, Peter Maydell a écrit :
> On 31 January 2013 19:50, Laurent Vivier  wrote:
> > The parameter "union semun" of semctl() is not a value
> > but a pointer to the value.
> 
> Hi. For your next patch could you make sure you send it as
> a fresh email rather than a followup to the previous version?
> Anthony's patch-handling tools don't really like followups.

OK

> > --- a/linux-user/syscall.c
> > +++ b/linux-user/syscall.c
> > @@ -2652,8 +2652,9 @@ static inline abi_long host_to_target_semarray(int 
> > semid, abi_ulong target_addr,
> >  }
> >
> >  static inline abi_long do_semctl(int semid, int semnum, int cmd,
> > - union target_semun target_su)
> > + abi_ulong ptr)
> >  {
> > +union target_semun *target_su;
> >  union semun arg;
> >  struct semid_ds dsarg;
> >  unsigned short *array = NULL;
> > @@ -2662,43 +2663,55 @@ static inline abi_long do_semctl(int semid, int 
> > semnum, int cmd,
> >  abi_long err;
> >  cmd &= 0xff;
> >
> > +if (!lock_user_struct(VERIFY_READ, target_su, ptr, 1)) {
> > +return -TARGET_EFAULT;
> > +}
> 
> This breaks x86_64 linux-user. The fourth argument to semctl()
> is a union of pointers, not a pointer to a union. That means that

In fact, it depends on the architecture. After a look in the kernel
sources, it seems compat_sys_semctl() uses a pointer, sys_semctl() an
union. compat_sys_semctl() seems to be used by mips32, pp32, sparc32 and
x86_32.

> the lock_user_struct/whatever has to be done differently for the
> individual cases, depending on how we are supposed to interpret
> the argument (which field of the union we're using).
> 
> My testcase is simple:
> 
> QEMU_STRACE=1 ./x86_64-linux-user/qemu-x86_64 /usr/bin/ipcs
> 
> which before your patch does this:
> 
> 14654 semctl(0,0,SEM_INFO,0x004000800490) = 0
> 14654 write(1,0x10d4000,33)-- Semaphore Arrays 
>  = 33
> 
> (ie we successfully get back the info)
> 
> 14654 write(1,0x10d4000,55)keysemid  owner  perms
> nsems
>  = 55
> 14654 semctl(0,0,SEM_STAT,0x004000800420) = -1 errno=22 (Invalid argument)
> 14654 write(1,0x10d4000,1)
>  = 1
> 
> and afterwards does this:
> 
> 14723 semctl(0,0,SEM_INFO,0x004000800490) = -1 errno=14 (Bad address)
> 14723 write(1,0x10d4000,37)kernel not configured for semaphores
>  = 37
> 
> (SEM_INFO fails and ipcs prints a failure message)
> 
> because we end up with target_su->__buf == 11 which isn't a
> valid address to pass to host_to_target_seminfo().

Thank you for your help,
Laurent

-- 
"Just play. Have fun. Enjoy the game."
- Michael Jordan




[Qemu-devel] [PATCH 2/6] linux-user: Add setsockopt(SO_ATTACH_FILTER)

2013-08-29 Thread Laurent Vivier
This is needed to be able to run dhclient.

Signed-off-by: Laurent Vivier 
---
 linux-user/syscall.c  | 44 
 linux-user/syscall_defs.h | 12 
 2 files changed, 56 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index b19f712..9acc4f5 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -106,6 +106,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,
 #include 
 #include 
 #include 
+#include 
 #include "linux_loop.h"
 #include "cpu-uname.h"
 
@@ -1357,6 +1358,49 @@ set_timeout:
 case TARGET_SO_SNDTIMEO:
 optname = SO_SNDTIMEO;
 goto set_timeout;
+case TARGET_SO_ATTACH_FILTER:
+{
+struct target_sock_fprog *tfprog;
+struct target_sock_filter *tfilter;
+struct sock_fprog fprog;
+struct sock_filter *filter;
+int i;
+
+if (optlen != sizeof(*tfprog)) {
+return -TARGET_EINVAL;
+}
+if (!lock_user_struct(VERIFY_READ, tfprog, optval_addr, 0)) {
+return -TARGET_EFAULT;
+}
+if (!lock_user_struct(VERIFY_READ, tfilter,
+  tswapal(tfprog->filter), 0)) {
+unlock_user_struct(tfprog, optval_addr, 1);
+return -TARGET_EFAULT;
+}
+
+fprog.len = tswap16(tfprog->len);
+filter = malloc(fprog.len * sizeof(*filter));
+if (filter == NULL) {
+unlock_user_struct(tfilter, tfprog->filter, 1);
+unlock_user_struct(tfprog, optval_addr, 1);
+return -TARGET_ENOMEM;
+}
+for (i = 0; i < fprog.len; i++) {
+filter[i].code = tswap16(tfilter[i].code);
+filter[i].jt = tfilter[i].jt;
+filter[i].jf = tfilter[i].jf;
+filter[i].k = tswap32(tfilter[i].k);
+}
+fprog.filter = filter;
+
+ret = get_errno(setsockopt(sockfd, SOL_SOCKET,
+SO_ATTACH_FILTER, &fprog, sizeof(fprog)));
+free(filter);
+
+unlock_user_struct(tfilter, tfprog->filter, 1);
+unlock_user_struct(tfprog, optval_addr, 1);
+return ret;
+}
 /* Options with 'int' argument.  */
 case TARGET_SO_DEBUG:
optname = SO_DEBUG;
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 086fbff..b0630ca 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -119,6 +119,18 @@ struct target_sockaddr {
 uint8_t sa_data[14];
 };
 
+struct target_sock_filter {
+abi_ushort code;
+uint8_t jt;
+uint8_t jf;
+abi_uint k;
+};
+
+struct target_sock_fprog {
+abi_ushort len;
+abi_ulong filter;
+};
+
 struct target_in_addr {
 uint32_t s_addr; /* big endian */
 };
-- 
1.8.1.2




[Qemu-devel] [PATCH 0/6] linux-user: Misc patches for linux container compatibility

2013-08-29 Thread Laurent Vivier
I bring with me this serie of patches for some months now.

They allow to boot and use a linux-user mode qemu in a linux container.
Some of them have been already sent to the mailing list with no result.

Please review, comments are welcome, and apply.

Laurent Vivier (6):
  linux-user: convert /proc/net/route when endianess differs
  linux-user: Add setsockopt(SO_ATTACH_FILTER)
  linux-user: allow use of TIOCGSID
  linux-user: add some IPV6 commands in setsockop()
  linux-user: add support of binfmt_misc 'O' flag
  scripts: create a template to use with lxc-create

 linux-user/ioctls.h   |   1 +
 linux-user/linuxload.c|   8 +-
 linux-user/main.c |  32 -
 linux-user/qemu.h |   2 +-
 linux-user/syscall.c  | 122 +++-
 linux-user/syscall_defs.h |  12 ++
 scripts/lxc-cross-debian  | 353 ++
 7 files changed, 517 insertions(+), 13 deletions(-)
 create mode 100755 scripts/lxc-cross-debian

-- 
1.8.1.2




[Qemu-devel] [PATCH 1/6] linux-user: convert /proc/net/route when endianess differs

2013-08-29 Thread Laurent Vivier
This patch allows to have IP addresses in correct order
in the case of "netstat -nr" when the endianess of the
guest differs from one of the host.

For instance, an m68k guest on an x86_64 host:

WITHOUT this patch:

$ netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags   MSS Window  irtt Iface
0.0.0.0 1.3.0.100.0.0.0 UG0 0  0 eth0
0.3.0.100.0.0.0 0.255.255.255   U 0 0  0 eth0
$ cat /proc/net/route
Iface   Destination Gateway Flags   RefCnt  Use Metric  Mask
MTU Window  IRTT

eth00103000A00030   0   0   
0   0   0
eth00003000A00010   0   0   
00FF0   0   0

WITH this patch:

$ netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags   MSS Window  irtt Iface
0.0.0.0 10.0.3.10.0.0.0 UG0 0  0 eth0
10.0.3.00.0.0.0 255.255.255.0   U 0 0  0 eth0
$ cat /proc/net/route
Iface   Destination Gateway Flags   RefCnt  Use Metric  Mask
MTU Window  IRTT
eth00a00030100030   0   0   
0   0   0
eth00a00030000010   0   0   
ff000   0   0

Signed-off-by: Laurent Vivier 
---
 linux-user/syscall.c | 58 +++-
 1 file changed, 53 insertions(+), 5 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index f986548..b19f712 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5037,22 +5037,70 @@ static int is_proc_myself(const char *filename, const 
char *entry)
 return 0;
 }
 
+#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
+static int is_proc(const char *filename, const char *entry)
+{
+return strcmp(filename, entry) == 0;
+}
+
+static int open_net_route(void *cpu_env, int fd)
+{
+FILE *fp;
+char *line = NULL;
+size_t len = 0;
+ssize_t read;
+
+fp = fopen("/proc/net/route", "r");
+if (fp == NULL) {
+return -EACCES;
+}
+
+/* read header */
+
+read = getline(&line, &len, fp);
+dprintf(fd, "%s", line);
+
+/* read routes */
+
+while ((read = getline(&line, &len, fp)) != -1) {
+char iface[16];
+uint32_t dest, gw, mask;
+unsigned int flags, refcnt, use, metric, mtu, window, irtt;
+sscanf(line, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n",
+ iface, &dest, &gw, &flags, &refcnt, &use, &metric,
+ &mask, &mtu, &window, &irtt);
+dprintf(fd, "%s\t%08x\t%08x\t%04x\t%d\t%d\t%d\t%08x\t%d\t%u\t%u\n",
+iface, tswap32(dest), tswap32(gw), flags, refcnt, use,
+metric, tswap32(mask), mtu, window, irtt);
+}
+
+free(line);
+fclose(fp);
+
+return 0;
+}
+#endif
+
 static int do_open(void *cpu_env, const char *pathname, int flags, mode_t mode)
 {
 struct fake_open {
 const char *filename;
 int (*fill)(void *cpu_env, int fd);
+int (*cmp)(const char *s1, const char *s2);
 };
 const struct fake_open *fake_open;
 static const struct fake_open fakes[] = {
-{ "maps", open_self_maps },
-{ "stat", open_self_stat },
-{ "auxv", open_self_auxv },
-{ NULL, NULL }
+{ "maps", open_self_maps, is_proc_myself },
+{ "stat", open_self_stat, is_proc_myself },
+{ "auxv", open_self_auxv, is_proc_myself },
+#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
+{ "/proc/net/route", open_net_route, is_proc },
+#endif
+{ NULL, NULL, NULL }
 };
 
 for (fake_open = fakes; fake_open->filename; fake_open++) {
-if (is_proc_myself(pathname, fake_open->filename)) {
+if (fake_open->cmp(pathname, fake_open->filename)) {
 break;
 }
 }
-- 
1.8.1.2




[Qemu-devel] [PATCH 4/6] linux-user: add some IPV6 commands in setsockop()

2013-08-29 Thread Laurent Vivier
Signed-off-by: Laurent Vivier 
---
 linux-user/syscall.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 9acc4f5..b32bff0 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1315,6 +1315,26 @@ static abi_long do_setsockopt(int sockfd, int level, int 
optname,
 goto unimplemented;
 }
 break;
+case SOL_IPV6:
+switch (optname) {
+case IPV6_MTU_DISCOVER:
+case IPV6_MTU:
+case IPV6_V6ONLY:
+case IPV6_RECVPKTINFO:
+val = 0;
+if (optlen < sizeof(uint32_t)) {
+return -TARGET_EINVAL;
+}
+if (get_user_u32(val, optval_addr)) {
+return -TARGET_EFAULT;
+}
+ret = get_errno(setsockopt(sockfd, level, optname,
+   &val, sizeof(val)));
+break;
+default:
+goto unimplemented;
+}
+break;
 case SOL_RAW:
 switch (optname) {
 case ICMP_FILTER:
-- 
1.8.1.2




[Qemu-devel] [PATCH 3/6] linux-user: allow use of TIOCGSID

2013-08-29 Thread Laurent Vivier
Signed-off-by: Laurent Vivier 
---
 linux-user/ioctls.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 439c2a9..7381012 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -20,6 +20,7 @@
  IOCTL(TIOCSCTTY, 0, TYPE_INT)
  IOCTL(TIOCGPGRP, IOC_R, MK_PTR(TYPE_INT))
  IOCTL(TIOCSPGRP, IOC_W, MK_PTR(TYPE_INT))
+ IOCTL(TIOCGSID, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(TIOCOUTQ, IOC_R, MK_PTR(TYPE_INT))
  IOCTL(TIOCSTI, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(TIOCMGET, IOC_R, MK_PTR(TYPE_INT))
-- 
1.8.1.2




[Qemu-devel] [PATCH 6/6] scripts: create a template to use with lxc-create

2013-08-29 Thread Laurent Vivier
Signed-off-by: Laurent Vivier 
---
 scripts/lxc-cross-debian | 353 +++
 1 file changed, 353 insertions(+)
 create mode 100755 scripts/lxc-cross-debian

diff --git a/scripts/lxc-cross-debian b/scripts/lxc-cross-debian
new file mode 100755
index 000..aded1d3
--- /dev/null
+++ b/scripts/lxc-cross-debian
@@ -0,0 +1,353 @@
+#!/bin/bash
+#
+# Some parts from lxc-debian, Daniel Lezcano 
+#
+# Copy this script to /usr/share/lxc/templates
+#
+# and use it with
+# lxc-create -t cross-debian -n   -- --arch xxx --interpreter-path 
/a/b/c/qemu-xxx
+#
+
+SUITE=${SUITE:-stable}
+MIRROR=${MIRROR:-http://ftp.debian.org/debian}
+
+find_interpreter() {
+qemu=$(basename "$1")
+
+if [ ! -d /proc/sys/fs/binfmt_misc/ ] ; then
+return 1
+fi
+for file in /proc/sys/fs/binfmt_misc/* ; do
+if [ "$file" = "/proc/sys/fs/binfmt_misc/register" -o \
+ "$file" = "/proc/sys/fs/binfmt_misc/status" ] ; then
+continue
+fi
+interpreter_path=$(sed -n "/^interpreter/s/interpreter 
\([^[:space:]]*\)/\1/p" "$file")
+interpreter=$(basename $interpreter_path)
+if [ "$qemu" = "$interpreter" ] ; then
+echo "$interpreter_path"
+return 0
+fi
+done
+return 1
+}
+
+download_debian()
+{
+cache="$1"
+arch="$2"
+
+if [ ! -d "$cache/archives-$SUITE-$arch" ]; then
+if ! mkdir -p "$cache/archives-$SUITE-$arch" ; then
+echo "Failed to create '$cache/archives-$SUITE-$arch' directory"
+return 1
+fi
+fi
+
+echo "Downloading debian $SUITE $arch..."
+if ! debootstrap --download-only \
+ --no-check-gpg \
+ --arch=$arch \
+ --include="locales" \
+ ${SUITE} "$cache/archives-$SUITE-$arch" \
+ ${MIRROR} ; then
+echo "ERROR: failed to download to $cache/archives-$SUITE-$arch" 1>&2
+exit 1
+fi
+echo "Download complete."
+trap EXIT
+trap SIGINT
+trap SIGTERM
+trap SIGHUP
+
+return 0
+}
+
+copy_debian()
+{
+cache=$1
+arch=$2
+rootfs=$3
+
+echo -n "Copying rootfs to $rootfs..."
+mkdir -p $rootfs
+rsync -Ha "$cache/archives-$SUITE-$arch"/ $rootfs/ || return 1
+echo "Copy complete."
+return 0
+}
+
+install_debian()
+{
+cache="/var/cache/lxc/debian"
+rootfs="$1"
+arch="$2"
+
+mkdir -p /var/lock/subsys/
+(
+if ! flock -x 200 ; then
+echo "Cache repository is busy."
+return 1
+fi
+
+if ! download_debian $cache $arch ; then
+echo "Failed to download 'debian base'"
+return 1
+fi
+
+if ! copy_debian $cache $arch $rootfs ; then
+echo "Failed to copy rootfs"
+return 1
+fi
+
+return 0
+
+) 200>/var/lock/subsys/lxc-debian
+
+return $?
+}
+
+create_root() {
+
+rootfs="$1"
+hostname="$2"
+qemu="$3"
+arch="$4"
+interpreter_path="$5"
+include="$6"
+
+if ! install_debian "$rootfs" "$arch" ; then
+echo "ERROR: failed to update cache" 1>&2
+exit 1
+fi
+
+if [ "${include}" = "" ] ; then
+  include="locales"
+else
+  include="locales,${include}"
+fi
+
+# Debian bootstrap
+
+if ! debootstrap --no-check-gpg --foreign \
+ --arch=$arch \
+ --include="${include}" \
+ ${SUITE} "$rootfs" \
+ ${MIRROR} ; then
+echo "ERROR: failed to debootstrap to $rootfs" 1>&2
+exit 1
+fi
+
+# adding qemu binary
+
+if ! cp "$qemu" "$rootfs/$interpreter_path" ; then
+echo "ERROR: failed to copy $qemu to $rootfs/$interpreter_path" 1>&2
+exit 1
+fi
+
+# debian bootstrap second stage
+
+chroot "$rootfs" debootstrap/debootstrap --second-stage
+}
+
+configure_debian() {
+
+rootfs="$1"
+hostname="$2"
+debian_sign="$3"
+
+# set timezone
+
+cat /etc/timezone > "$rootfs/etc/timezone"
+chroot $rootfs dpkg-reconfigure -fnoninteractive tzdata
+
+# configuration
+
+cat >> "$rootfs/etc/fstab" <   
+devpts /dev/ptsdevpts  nodev,noexec,nosuid 0   1
+!EOF
+
+echo "$hostname" > "$rootfs/

[Qemu-devel] [PATCH 5/6] linux-user: add support of binfmt_misc 'O' flag

2013-08-29 Thread Laurent Vivier
The binfmt_misc module can calculate the credentials and security
token according to the binary instead of to the interpreter if the
'C' flag is enabled.

To be able to execute non-readable binaries, this flag implies 'O'
flag. When 'O' flag is enabled, bintfmt_misc opens the file for
reading and pass the file descriptor to the interpreter.

References:
linux/Documentation/binfmt_misc.txt  ['O' and 'C' description]
linux/fs/binfmt_misc.c linux/fs/binfmt_elf.c [ AT_EXECFD usage ]

Signed-off-by: Laurent Vivier 
---
 linux-user/linuxload.c |  8 ++--
 linux-user/main.c  | 32 +++-
 linux-user/qemu.h  |  2 +-
 3 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c
index 5cd6d91..a1fe5ed 100644
--- a/linux-user/linuxload.c
+++ b/linux-user/linuxload.c
@@ -131,7 +131,7 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong 
sp,
 return sp;
 }
 
-int loader_exec(const char * filename, char ** argv, char ** envp,
+int loader_exec(int fdexec, const char *filename, char **argv, char **envp,
  struct target_pt_regs * regs, struct image_info *infop,
  struct linux_binprm *bprm)
 {
@@ -140,11 +140,7 @@ int loader_exec(const char * filename, char ** argv, char 
** envp,
 
 bprm->p = TARGET_PAGE_SIZE*MAX_ARG_PAGES-sizeof(unsigned int);
 memset(bprm->page, 0, sizeof(bprm->page));
-retval = open(filename, O_RDONLY);
-if (retval < 0) {
-return -errno;
-}
-bprm->fd = retval;
+bprm->fd = fdexec;
 bprm->filename = (char *)filename;
 bprm->argc = count(argv);
 bprm->argv = argv;
diff --git a/linux-user/main.c b/linux-user/main.c
index 03859bc..0223b93 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3532,6 +3532,26 @@ static int parse_args(int argc, char **argv)
 return optind;
 }
 
+static int get_execfd(char **envp)
+{
+typedef struct {
+long a_type;
+long a_val;
+} auxv_t;
+auxv_t *auxv;
+
+while (*envp++ != NULL) {
+;
+}
+
+for (auxv = (auxv_t *)envp; auxv->a_type != AT_NULL; auxv++) {
+if (auxv->a_type == AT_EXECFD) {
+return auxv->a_val;
+}
+}
+return -1;
+}
+
 int main(int argc, char **argv, char **envp)
 {
 struct target_pt_regs regs1, *regs = ®s1;
@@ -3546,6 +3566,7 @@ int main(int argc, char **argv, char **envp)
 int target_argc;
 int i;
 int ret;
+int execfd;
 
 module_call_init(MODULE_INIT_QOM);
 
@@ -3721,7 +3742,16 @@ int main(int argc, char **argv, char **envp)
 env->opaque = ts;
 task_settid(ts);
 
-ret = loader_exec(filename, target_argv, target_environ, regs,
+execfd = get_execfd(envp);
+if (execfd < 0) {
+execfd = open(filename, O_RDONLY);
+}
+if (execfd < 0) {
+printf("Error while loading %s: %s\n", filename, strerror(-execfd));
+_exit(1);
+}
+
+ret = loader_exec(execfd, filename, target_argv, target_environ, regs,
 info, &bprm);
 if (ret != 0) {
 printf("Error while loading %s: %s\n", filename, strerror(-ret));
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 4a16e8f..111251b 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -172,7 +172,7 @@ struct linux_binprm {
 void do_init_thread(struct target_pt_regs *regs, struct image_info *infop);
 abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
   abi_ulong stringp, int push_ptr);
-int loader_exec(const char * filename, char ** argv, char ** envp,
+int loader_exec(int fdexec, const char *filename, char **argv, char **envp,
  struct target_pt_regs * regs, struct image_info *infop,
  struct linux_binprm *);
 
-- 
1.8.1.2




Re: [Qemu-devel] [PULL 00/24] Linux-user updates

2014-08-18 Thread Laurent Vivier

> Le 18 août 2014 à 14:45, Peter Maydell  a écrit :
>
>
> On 18 August 2014 13:38, Joakim Tjernlund 
> wrote:
> > Peter Maydell  wrote on 2014/08/18 12:58:48:
> >> Well, binfmt-misc works fine for me as it is and presumably
> >> for most people or we'd have had more complaints. So
> >> breaking all those existing working setups is really something
> >> we should avoid as much as possible.
> >
> > How do you use it? With LXC booting a VM with traditional init?
>
> No. Just a straightforward chroot environment with a
> statically linked qemu in it, and a binfmt_misc config like:
>
> e104462:trusty:qemu$ cat /proc/sys/fs/binfmt_misc/qemu-arm
> enabled
> interpreter /usr/bin/qemu-arm-static
> flags: OC
> offset 0
> magic 7f454c460101010002002800
> mask ff00feff
>
> This works fine for the things I try to run in the chroot
> (mostly test programs, also bash and basic command
> line utilities).
>
> > There are complaints which dists had to solve because QEMU didn't. Usually
> > this is a separate static QEMU package/hack with a binfmt wrapper.
> > Gentoo used to have one but this got removed.
>
> I'm sure there are cases which don't work; but we should try
> to find a way which allows us to make those work (with a
> recommended change to binfmt misc registration) which
> doesn't break the old configs in the process.

If it can help:

I'm using qemu-linux-user in LXC containers for more than a year now without any
problem and with nor wrapper neither modifications in the distro I install (to
be honest, only debian etch-m68k and previous).
I like this approach because it avoids to have to maintain gcc cross-compiler
(and tools). It's 10 times slower than the cross compiler but works fine.

I've a script in my qemu-m68k repo that can create containers for several archs
(search in QEMU mailing list archives... or ask)

Regards,
Laurent

Re: [Qemu-devel] [PATCH v2] linux-user: Simplify timerid checks on g_posix_timers range

2014-08-22 Thread Laurent Vivier
Hi,

as in the kernel timer_t is an "int" (as said PMM), you should cast to "int" to
remove garbage on 64bit hosts and check sign ...

Regards,
Laurent

> Le 22 août 2014 à 13:56, Alexander Graf  a écrit :
>
>
> We check whether the passed in timer id is negative on all calls
> that involve g_posix_timers.
>
> However, these checks are bogus. First off we limit the timer_id to
> 16 bits which is not what Linux does. Then we check whether it's negative
> which it can't be because we masked it.
>
> We can safely remove the masking. For the negativity check we can just
> treat the timerid as unsigned and only check for upper boundaries.
>
> Signed-off-by: Alexander Graf 
>
> ---
>
> v1 -> v2:
>
> - drop 0x mask
> - explicitly cast to unsigned because the mask is missing now
>
> ---
> linux-user/syscall.c | 30 +-
> 1 file changed, 17 insertions(+), 13 deletions(-)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index f6c887f..92b6a38 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -9508,11 +9508,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long
> arg1,
> {
> /* args: timer_t timerid, int flags, const struct itimerspec *new_value,
> * struct itimerspec * old_value */
> - arg1 &= 0x;
> - if (arg3 == 0 || arg1 < 0 || arg1 >= ARRAY_SIZE(g_posix_timers)) {
> + target_ulong timerid = arg1;
> +
> + if (arg3 == 0 || timerid >= ARRAY_SIZE(g_posix_timers)) {
> ret = -TARGET_EINVAL;
> } else {
> - timer_t htimer = g_posix_timers[arg1];
> + timer_t htimer = g_posix_timers[timerid];
> struct itimerspec hspec_new = {{0},}, hspec_old = {{0},};
>
> target_to_host_itimerspec(&hspec_new, arg3);
> @@ -9528,13 +9529,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long
> arg1,
> case TARGET_NR_timer_gettime:
> {
> /* args: timer_t timerid, struct itimerspec *curr_value */
> - arg1 &= 0x;
> + target_ulong timerid = arg1;
> +
> if (!arg2) {
> return -TARGET_EFAULT;
> - } else if (arg1 < 0 || arg1 >= ARRAY_SIZE(g_posix_timers)) {
> + } else if (timerid >= ARRAY_SIZE(g_posix_timers)) {
> ret = -TARGET_EINVAL;
> } else {
> - timer_t htimer = g_posix_timers[arg1];
> + timer_t htimer = g_posix_timers[timerid];
> struct itimerspec hspec;
> ret = get_errno(timer_gettime(htimer, &hspec));
>
> @@ -9550,11 +9552,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long
> arg1,
> case TARGET_NR_timer_getoverrun:
> {
> /* args: timer_t timerid */
> - arg1 &= 0x;
> - if (arg1 < 0 || arg1 >= ARRAY_SIZE(g_posix_timers)) {
> + target_ulong timerid = arg1;
> +
> + if (timerid >= ARRAY_SIZE(g_posix_timers)) {
> ret = -TARGET_EINVAL;
> } else {
> - timer_t htimer = g_posix_timers[arg1];
> + timer_t htimer = g_posix_timers[timerid];
> ret = get_errno(timer_getoverrun(htimer));
> }
> break;
> @@ -9565,13 +9568,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long
> arg1,
> case TARGET_NR_timer_delete:
> {
> /* args: timer_t timerid */
> - arg1 &= 0x;
> - if (arg1 < 0 || arg1 >= ARRAY_SIZE(g_posix_timers)) {
> + target_ulong timerid = arg1;
> +
> + if (timerid >= ARRAY_SIZE(g_posix_timers)) {
> ret = -TARGET_EINVAL;
> } else {
> - timer_t htimer = g_posix_timers[arg1];
> + timer_t htimer = g_posix_timers[timerid];
> ret = get_errno(timer_delete(htimer));
> - g_posix_timers[arg1] = 0;
> + g_posix_timers[timerid] = 0;
> }
> break;
> }
> --
> 1.7.12.4
>
>

Re: [Qemu-devel] [PATCH v2] linux-user: Simplify timerid checks on g_posix_timers range

2014-08-22 Thread Laurent Vivier

> Le 22 août 2014 à 14:29, Alexander Graf  a écrit :
>
>
>
>
> On 22.08.14 14:25, Peter Maydell wrote:
> > On 22 August 2014 13:12, Alexander Graf  wrote:
> >> In Linux, the timer id is a "key" into a hash table that the kernel
> >> searches to find its timer. In QEMU it's an offset into an array.
> >>
> >> In both cases the syscall user receives it as a token from a create
> >> function and should treat it as opaque.
> >>
> >> So in the QEMU case it is unsigned, regardless of what the kernel allows
> >> it to be, because it's an array offset.
> >
> > It's a number between 0 and 32. That doesn't imply that it has
> > to be an unsigned variable, and we already have it in a
> > signed variable arg1...
>
> Yes, so the end result will be the same. What's the point of this bike
> shedding?

On some archs, we can imagine libc/gcc filling only the 32 lower bits (= int) of
the register during the syscall, and without modifying the 32 upper bits (=
garbage). You must ignore the 32 upper bits (but you can ignore the sign too). I
think you can let the mask but remove the sign checking -> your patch v1 was
good ...

Regards,
Laurent

Re: [Qemu-devel] linux-user: enabling binfmt P flag

2014-08-25 Thread Laurent Vivier

> Le 25 août 2014 à 14:46, Alexander Graf  a écrit :
>
>
>
>
> On 25.08.14 14:42, Riku Voipio wrote:
> > On Mon, Aug 25, 2014 at 11:14:58AM +0200, Alexander Graf wrote:
> >>
> >>
> >> On 25.08.14 11:09, Riku Voipio wrote:
> >>> Hi,
> >>>
> >>> After weekend, I think the solution to using the P flag is to
> >>> go back to Joakim's original patch:
> >>>
> >>> http://lists.gnu.org/archive/html/qemu-devel/2014-07/msg02269.html
> >>>
> >>> With this, we get:
> >>>
> >>> If you continue to use qemu-x-static in your binfmt_misc registration,
> >>> nothing changes - both old and new qemu work using the old binfmt
> >>> registration.
> >>>
> >>> If you rename the binary qemu-x-binfmt, you need to update the
> >>> binfmt_misc register to have P flag and new binary - you get correct
> >>> argv with new qemu. Any old qemu you still have around, will stop
> >>> working. But with "file not found" error rather than obscurely eating
> >>> one of the arguments and running regardless.
> >>>
> >>> This leaves us with one case - people who are used to running
> >>> qemu-x-static ./binary to test single binaries. Distro's will need
> >>> leave a symlink from qemu-x-binfmt qemu-x-static. The "-binfmt" string
> >>> check doesn't trigger, and qemu works as before.
> >>>
> >>> The key point: this way nobody's working setup will break, unless they
> >>> update binfmt registration. As long as the change is done by users
> >>> them self (I need correct argv0 -> I will update binfmt), there is very
> >>> little surprise for anyone.
> >>>
> >>> There will be some fallout once *distributions* change the binfmt - users
> >>> will notice their existing qemu chroots stop working with a "file not
> >>> found" error for any binary they try to run.
> >>>
> >>> If we find even this breakage too much, I'm not sure this can be fixed.
> >
> >> I would very much prefer if we could stick with only a single binary.
> >> And yes, switching semantics when you use binfmt wrappers will hurt for
> >> a short while, but after that everyone will have their setups changed
> >> and we're safe for the future.
> >
> > I don't really the unpredictable nature of the breakage. Take
> > $ rm a b c
> >
> > With P flag: /bin/rm rm a b c
> > Without P flag: /bin/rm a b c
> >
> > If we use old qemu with P flag: qemu will run /bin/rm with argv: "/bin/rm rm
> > a b c"
> > -> tries to delete "rm"
> > If we use new qemu without P flag, qemu will run /bin/rm with argv: "a b c"
> > -> fails to delete "a"
> >
> > This is the black magic errors that drive users nuts when they try to debug
> > what
> > is happening... "File not found" when the qemu binary is not in the
> > right place is confusing enough.
>
> Yes, but is anyone actually using the "P" flag? We've never advertised
> anywhere that QEMU supports it.
>
> Maybe we should just make the next version be 3.0 and declare it a major
> ABI breakage ;).

You can also add the feature and let's the configure manages if it must be
enabled or not.

Regards,
Laurent

[Qemu-devel] [PATCH 4/4] linux-user,arm: display default cpu

2012-01-22 Thread Laurent Vivier
Signed-off-by: Laurent Vivier 
---
 target-arm/helper.c |7 ++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/target-arm/helper.c b/target-arm/helper.c
index 00458fc..7be315f 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -438,7 +438,12 @@ void arm_cpu_list(FILE *f, fprintf_function cpu_fprintf)
 
 (*cpu_fprintf)(f, "Available CPUs:\n");
 for (i = 0; arm_cpu_names[i].name; i++) {
-(*cpu_fprintf)(f, "  %s\n", arm_cpu_names[i].name);
+if (strcmp(arm_cpu_names[i].name, TARGET_DEFAULT_CPU) == 0) {
+(*cpu_fprintf)(f, " >");
+} else {
+(*cpu_fprintf)(f, "  ");
+}
+(*cpu_fprintf)(f, "%s\n", arm_cpu_names[i].name);
 }
 }
 
-- 
1.7.5.4




[Qemu-devel] [PATCH 0/4] linux-user: A serie of patches to set default CPU

2012-01-22 Thread Laurent Vivier
This serie of patches has already been sent, more or less, several time,
last time in july 2011.

For chrooted environment, it allows to define the default cpu model as we can't 
use '-cpu' argument.

For instance:

 ./configure --target-list=m68k-linux-user,arm-linux-user \
   --m68k-default-cpu=m5206 --arm-default-cpu=sa1100
  ./m68k-linux-user/qemu-m68k -cpu ?
 >m5206
  m5208
  cfv4e
  any
 ./arm-linux-user/qemu-arm -cpu ?
Available CPUs:
  arm926
  arm946
  arm1026
  arm1136
  arm1136-r2
  arm1176
  arm11mpcore
  cortex-m3
  cortex-a8
  cortex-a9
  ti925t
  pxa250
 >sa1100
  sa1110
  pxa255
  pxa260
  pxa261
  pxa262
  pxa270
  pxa270-a0
  pxa270-a1
  pxa270-b0
  pxa270-b1
  pxa270-c0
  pxa270-c5
  any

[PATCH 1/4] linux-user: define default cpu model in configure
[PATCH 2/4] linux-user: specify the cpu model during configure
[PATCH 3/4] linux-user,m68k: display default cpu
[PATCH 4/4] linux-user,arm: display default cpu



[Qemu-devel] [PATCH 2/4] linux-user: specify the cpu model during configure

2012-01-22 Thread Laurent Vivier
From: Laurent Vivier 

This patch allows to set the default cpu model for a given architecture,
for instance:

 ./configure --target-list=m68k-linux-user,arm-linux-user \
   --m68k-default-cpu=m68040 --arm-default-cpu=sa1100

Signed-off-by: Laurent Vivier 
---
 configure |9 +
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/configure b/configure
index c251df2..98acce1 100755
--- a/configure
+++ b/configure
@@ -544,6 +544,10 @@ for opt do
   ;;
   --target-list=*) target_list="$optarg"
   ;;
+  --*-default-cpu=*)
+tmp=`expr "x$opt" : 'x--\(.*\)-default-cpu=.*'`
+eval ${tmp}_default_cpu="$optarg"
+  ;;
   --enable-trace-backend=*) trace_backend="$optarg"
   ;;
   --with-trace-file=*) trace_file="$optarg"
@@ -951,6 +955,7 @@ echo "   use %M for cpu name 
[$interp_prefix]"
 echo "  --target-list=LIST   set target list (default: build everything)"
 echo "Available targets: $default_target_list" | \
 fold -s -w 53 | sed -e 's/^/   /'
+echo "  --ARCH-default-cpu=CPU   set the default cpu for a given architecture"
 echo ""
 echo "Advanced options (experts only):"
 echo "  --source-path=PATH   path of source code [$source_path]"
@@ -3531,6 +3536,10 @@ case "$target_arch2" in
 exit 1
   ;;
 esac
+tmp_target_default_cpu=`eval echo \\$${target_arch2}_default_cpu`
+if [ "x$tmp_target_default_cpu" != "x" ] ; then
+  target_default_cpu="$tmp_target_default_cpu"
+fi
 echo "TARGET_SHORT_ALIGNMENT=$target_short_alignment" >> $config_target_mak
 echo "TARGET_INT_ALIGNMENT=$target_int_alignment" >> $config_target_mak
 echo "TARGET_LONG_ALIGNMENT=$target_long_alignment" >> $config_target_mak
-- 
1.7.5.4




[Qemu-devel] [PATCH 3/4] linux-user,m68k: display default cpu

2012-01-22 Thread Laurent Vivier
From: Laurent Vivier 

Signed-off-by: Laurent Vivier 
---
 target-m68k/helper.c |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/target-m68k/helper.c b/target-m68k/helper.c
index 674c8e6..ede5180 100644
--- a/target-m68k/helper.c
+++ b/target-m68k/helper.c
@@ -57,6 +57,11 @@ void m68k_cpu_list(FILE *f, fprintf_function cpu_fprintf)
 unsigned int i;
 
 for (i = 0; m68k_cpu_defs[i].name; i++) {
+if (strcmp(m68k_cpu_defs[i].name, TARGET_DEFAULT_CPU) == 0) {
+(*cpu_fprintf)(f, " >");
+} else {
+(*cpu_fprintf)(f, "  ");
+}
 (*cpu_fprintf)(f, "%s\n", m68k_cpu_defs[i].name);
 }
 }
-- 
1.7.5.4




[Qemu-devel] [PATCH 1/4] linux-user: define default cpu model in configure instead of linux-user/main.c

2012-01-22 Thread Laurent Vivier
From: Laurent Vivier 

Signed-off-by: Laurent Vivier 
---
 configure |   14 ++
 linux-user/main.c |   34 +-
 2 files changed, 15 insertions(+), 33 deletions(-)

diff --git a/configure b/configure
index 467e87b..c251df2 100755
--- a/configure
+++ b/configure
@@ -3313,6 +3313,7 @@ target_dir="$target"
 config_target_mak=$target_dir/config-target.mak
 target_arch2=`echo $target | cut -d '-' -f 1`
 target_bigendian="no"
+target_default_cpu="any"
 
 case "$target_arch2" in
   
armeb|lm32|m68k|microblaze|mips|mipsn32|mips64|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus|xtensaeb)
@@ -3388,11 +3389,13 @@ TARGET_ABI_DIR=""
 case "$target_arch2" in
   i386)
 target_phys_bits=64
+target_default_cpu="qemu32"
   ;;
   x86_64)
 TARGET_BASE_ARCH=i386
 target_phys_bits=64
 target_long_alignment=8
+target_default_cpu="qemu64"
   ;;
   alpha)
 target_phys_bits=64
@@ -3435,12 +3438,14 @@ case "$target_arch2" in
 echo "TARGET_ABI_MIPSO32=y" >> $config_target_mak
 target_nptl="yes"
 target_phys_bits=64
+target_default_cpu="24Kf"
   ;;
   mipsn32|mipsn32el)
 TARGET_ARCH=mipsn32
 TARGET_BASE_ARCH=mips
 echo "TARGET_ABI_MIPSN32=y" >> $config_target_mak
 target_phys_bits=64
+target_default_cpu="20Kc"
   ;;
   mips64|mips64el)
 TARGET_ARCH=mips64
@@ -3448,12 +3453,14 @@ case "$target_arch2" in
 echo "TARGET_ABI_MIPSN64=y" >> $config_target_mak
 target_phys_bits=64
 target_long_alignment=8
+target_default_cpu="20Kc"
   ;;
   ppc)
 gdb_xml_files="power-core.xml power-fpu.xml power-altivec.xml 
power-spe.xml"
 target_phys_bits=64
 target_nptl="yes"
 target_libs_softmmu="$fdt_libs"
+target_default_cpu="750"
   ;;
   ppcemb)
 TARGET_BASE_ARCH=ppc
@@ -3462,6 +3469,7 @@ case "$target_arch2" in
 target_phys_bits=64
 target_nptl="yes"
 target_libs_softmmu="$fdt_libs"
+target_default_cpu="750"
   ;;
   ppc64)
 TARGET_BASE_ARCH=ppc
@@ -3470,6 +3478,7 @@ case "$target_arch2" in
 target_phys_bits=64
 target_long_alignment=8
 target_libs_softmmu="$fdt_libs"
+target_default_cpu="970fx"
   ;;
   ppc64abi32)
 TARGET_ARCH=ppc64
@@ -3479,6 +3488,7 @@ case "$target_arch2" in
 gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml 
power-spe.xml"
 target_phys_bits=64
 target_libs_softmmu="$fdt_libs"
+target_default_cpu="750"
   ;;
   sh4|sh4eb)
 TARGET_ARCH=sh4
@@ -3488,11 +3498,13 @@ case "$target_arch2" in
   ;;
   sparc)
 target_phys_bits=64
+target_default_cpu="Fujitsu MB86904"
   ;;
   sparc64)
 TARGET_BASE_ARCH=sparc
 target_phys_bits=64
 target_long_alignment=8
+target_default_cpu="TI UltraSparc II"
   ;;
   sparc32plus)
 TARGET_ARCH=sparc64
@@ -3500,6 +3512,7 @@ case "$target_arch2" in
 TARGET_ABI_DIR=sparc
 echo "TARGET_ABI32=y" >> $config_target_mak
 target_phys_bits=64
+target_default_cpu="Fujitsu MB86904"
   ;;
   s390x)
 target_nptl="yes"
@@ -3522,6 +3535,7 @@ echo "TARGET_SHORT_ALIGNMENT=$target_short_alignment" >> 
$config_target_mak
 echo "TARGET_INT_ALIGNMENT=$target_int_alignment" >> $config_target_mak
 echo "TARGET_LONG_ALIGNMENT=$target_long_alignment" >> $config_target_mak
 echo "TARGET_LLONG_ALIGNMENT=$target_llong_alignment" >> $config_target_mak
+echo "TARGET_DEFAULT_CPU=\"$target_default_cpu\"" >> $config_target_mak
 echo "TARGET_ARCH=$TARGET_ARCH" >> $config_target_mak
 target_arch_name="`echo $TARGET_ARCH | tr '[:lower:]' '[:upper:]'`"
 echo "TARGET_$target_arch_name=y" >> $config_target_mak
diff --git a/linux-user/main.c b/linux-user/main.c
index 64d2208..25dc0eb 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3322,39 +3322,7 @@ int main(int argc, char **argv, char **envp)
 init_paths(interp_prefix);
 
 if (cpu_model == NULL) {
-#if defined(TARGET_I386)
-#ifdef TARGET_X86_64
-cpu_model = "qemu64";
-#else
-cpu_model = "qemu32";
-#endif
-#elif defined(TARGET_ARM)
-cpu_model = "any";
-#elif defined(TARGET_UNICORE32)
-cpu_model = "any";
-#elif defined(TARGET_M68K)
-cpu_model = "any";
-#elif defined(TARGET_SPARC)
-#ifdef TARGET_SPARC64
-cpu_model = "TI UltraSparc II";
-#else
-cpu_model = "Fujitsu MB86904";
-#endif
-#elif defined(TARGET_MIPS)
-#if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64)
-cpu_model = "20Kc";
-#else
-cpu_model = "24Kf";
-#endif
-#elif defined(TARGET_PPC)
-#ifdef TARGET_PPC64
-cpu_model = "970fx";
-#else
-cpu_model = "750";
-#endif
-#else
-cpu_model = "any";
-#endif
+cpu_model = TARGET_DEFAULT_CPU;
 }
 tcg_exec_init(0);
 cpu_exec_init_all();
-- 
1.7.5.4




Re: [Qemu-devel] Failed to set a breakpoint on start_kernel

2012-03-17 Thread Laurent Vivier
Le samedi 17 mars 2012 à 09:53 +0100, Jan Kiszka a écrit :
> On 2012-03-16 03:43, Wei Yang wrote:
> > All
> > 
> > I like qemu very much and know it could debug the kernel.
> > 
> > I tried what I searched on web but couldn't stop at the break point.
> > Below is what I did.
> > 
> > 1. Both host and guest installed the same OS, Fedora16 x86_64.
> > 
> > 2. Compile the qemu with
> > ./configure --target-list=x86_64-softmmu --enable-kvm
> > --enable-debug-tcg --enable-debug --enable-trace-backend=simple
> > 
> > 3. With this command I can boot up my guest.
> > ./../qemu/x86_64-softmmu/qemu-system-x86_64 -enable-kvm -smp 4 -m
> > 1024  -boot dc fedora16.img -monitor stdio
> > 
> > 4. I git clone the kernel source in the guest and make a new kernel and 
> > initrd.
> > I start the guest with this new kernel successfully
> > 
> > 5. I copy out the initrd.img and the .config of kernel to host.
> > compile the kernel on host.
> > the kernel source code is identical on host and gueset,
> > 
> > 6. I start the guest with the kernel and initrd on host
> > ./../qemu/x86_64-softmmu/qemu-system-x86_64 -enable-kvm -smp 4 -m
> > 1024  -boot dc fedora16.img -monitor stdio -kernel
> > ~/git/linux-yinghai/arch/x86_64/boot/bzImage -initrd
> > ~/git/debug/initramfs-3.0.0.img -append
> > "root=/dev/mapper/vg_wizard-lv_root ro rd.lvm.lv=vg_wizard/lv_root
> > rd.md=0 rd.lvm.lv=vg_wizard/lv_swap"
> > 
> > This works fine.
> > 
> > 7. Then I start the guest with gdbstub option
> > ./../qemu/x86_64-softmmu/qemu-system-x86_64 -enable-kvm -smp 4 -m
> > 1024  -boot dc fedora16.img -monitor stdio -kernel
> > /home/ywywyang/git/linux-yinghai/arch/x86_64/boot/bzImage -initrd
> > /home/ywywyang/git/debug/initramfs-3.0.0.img -append
> > "root=/dev/mapper/vg_wizard-lv_root ro rd.lvm.lv=vg_wizard/lv_root
> > rd.md=0 rd.lvm.lv=vg_wizard/lv_swap" -S -gdb tcp::4321
> > 
> > Then the guest stop at the beginning.
> > 
> > 8. Attach the gdb in the kernel source directory
> > gdb
> > file vmlinux
> > target remote localhost:4321
> > b start_kernel
> > c
> > 
> >Then the guest will run very happily
> > 
> > Also use the "info b " could show the break point is set.
> > 
> > Which step I made a mistake?
> 
> Two major issues with this procedure:
> 
> 1. When using kvm, a soft breakpoint (as set by 'b') will inject a trap
> instruction into the guest image - which is not yet loaded after the
> bios ran. You need to use a hardware breakpoint in this case.
> 
> 2. Due to gdb limitations, you cannot switch between 16/32-bit mode (the
> CPU starts in 16 bit) and the 64-bit mode of kernel within the same gdb
> session. Therefore:
>  - let the target run into Linux is active
>  - attach gdb
>  - issue "hw start_kernel"
>  - reboot (e.g. "monitor system_reset")
>  - you will hit the breakpoint, and gdb will be usable

You can also try my patch :

http://patchwork.ozlabs.org/patch/137543/

Laurent




[Qemu-devel] [PATCH 0/4] Set of patches for chrooted environment

2011-07-28 Thread Laurent Vivier
This set of patches helps to use qemu-linux-user in a chrooted environment.

It mostly allows to define the default cpu model as we can't use '-cpu' 
argument.
The last one defines enviromnent variables to be able to use log file and 
gdb server  ('-d' and '-g' arguments).

NOTE: I saw some comments in the mailing list about environment variables,
if patch #4 dislikes, I've also a patch providing a "qemu-wrapper" with the 
same behavior.

[PATCH 1/4] linux-user: define default cpu model in configure instead of 
linux-user/main.c
[PATCH 2/4] linux-user: specify the cpu model during configure
[PATCH 3/4] linux-user,m68k: display default cpu
[PATCH 4/4] linux-user: define new environment variables



[Qemu-devel] [PATCH 2/4] linux-user: specify the cpu model during configure

2011-07-28 Thread Laurent Vivier
This patch allows to set the default cpu model for a given architecture,
for instance:

 configure --target-list=m68k-linux-user --m68k-default-cpu=m68040

Signed-off-by: Laurent Vivier 
---
 configure |9 +
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/configure b/configure
index c74a5f9..d54f0ed 100755
--- a/configure
+++ b/configure
@@ -527,6 +527,10 @@ for opt do
   ;;
   --target-list=*) target_list="$optarg"
   ;;
+  --*-default-cpu=*)
+tmp=`expr "x$opt" : 'x--\(.*\)-default-cpu=.*'`
+eval ${tmp}_default_cpu="$optarg"
+  ;;
   --enable-trace-backend=*) trace_backend="$optarg"
   ;;
   --with-trace-file=*) trace_file="$optarg"
@@ -916,6 +920,7 @@ echo "   use %M for cpu name 
[$interp_prefix]"
 echo "  --target-list=LIST   set target list (default: build everything)"
 echo "Available targets: $default_target_list" | \
 fold -s -w 53 | sed -e 's/^/   /'
+echo "  --ARCH-default-cpu=CPU   set the default cpu for a given architecture"
 echo ""
 echo "Advanced options (experts only):"
 echo "  --source-path=PATH   path of source code [$source_path]"
@@ -3291,6 +3296,10 @@ case "$target_arch2" in
 exit 1
   ;;
 esac
+tmp_target_default_cpu=`eval echo \\$${target_arch2}_default_cpu`
+if [ "x$tmp_target_default_cpu" != "x" ] ; then
+  target_default_cpu="$tmp_target_default_cpu"
+fi
 echo "TARGET_SHORT_ALIGNMENT=$target_short_alignment" >> $config_target_mak
 echo "TARGET_INT_ALIGNMENT=$target_int_alignment" >> $config_target_mak
 echo "TARGET_LONG_ALIGNMENT=$target_long_alignment" >> $config_target_mak
-- 
1.7.4.1




[Qemu-devel] [PATCH 3/4] linux-user,m68k: display default cpu

2011-07-28 Thread Laurent Vivier
Signed-off-by: Laurent Vivier 
---
 target-m68k/helper.c |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/target-m68k/helper.c b/target-m68k/helper.c
index a936fe7..f5d33cd 100644
--- a/target-m68k/helper.c
+++ b/target-m68k/helper.c
@@ -57,6 +57,11 @@ void m68k_cpu_list(FILE *f, fprintf_function cpu_fprintf)
 unsigned int i;
 
 for (i = 0; m68k_cpu_defs[i].name; i++) {
+if (strcmp(m68k_cpu_defs[i].name, TARGET_DEFAULT_CPU) == 0) {
+(*cpu_fprintf)(f, " >");
+} else {
+(*cpu_fprintf)(f, "  ");
+}
 (*cpu_fprintf)(f, "%s\n", m68k_cpu_defs[i].name);
 }
 }
-- 
1.7.4.1




[Qemu-devel] [PATCH 4/4] linux-user: define new environment variables

2011-07-28 Thread Laurent Vivier
QEMU_GDB=port allows to define gdb server port to wait on.
QEMU_DEBUG=options allows to activate log file (like -d options)

Signed-off-by: Laurent Vivier 
---
 linux-user/main.c |   11 ---
 qemu-doc.texi |4 
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 7180cee..ff1720b 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -2815,8 +2815,10 @@ static void usage(void)
"-strace  log system calls\n"
"\n"
"Environment variables:\n"
-   "QEMU_STRACE   Print system calls and arguments similar to 
the\n"
-   "  'strace' program.  Enable by setting to any 
value.\n"
+   "QEMU_STRACEPrint system calls and arguments similar to 
the\n"
+   "   'strace' program.  Enable by setting to any 
value.\n"
+   "QEMU_DEBUG=options Activate log. Use same options as '-d' 
options\n"
+   "QEMU_GDB=port  Wait gdb connection to port\n"
"You can use -E and -U options to set/unset environment variables\n"
"for target process.  It is possible to provide several variables\n"
"by repeating the option.  For example:\n"
@@ -2872,7 +2874,7 @@ int main(int argc, char **argv, char **envp)
 const char *filename;
 const char *cpu_model;
 const char *log_file = DEBUG_LOGFILE;
-const char *log_mask = NULL;
+const char *log_mask = getenv("QEMU_DEBUG");
 struct target_pt_regs regs1, *regs = ®s1;
 struct image_info info1, *info = &info1;
 struct linux_binprm bprm;
@@ -2919,6 +2921,9 @@ int main(int argc, char **argv, char **envp)
 #if defined(cpudef_setup)
 cpudef_setup(); /* parse cpu definitions in target config file (TBD) */
 #endif
+if (getenv("QEMU_GDB")) {
+  gdbstub_port = atoi(getenv("QEMU_GDB"));
+}
 
 optind = 1;
 for(;;) {
diff --git a/qemu-doc.texi b/qemu-doc.texi
index 47e1991..330f9d0 100644
--- a/qemu-doc.texi
+++ b/qemu-doc.texi
@@ -2285,6 +2285,10 @@ space emulator hasn't implemented ptrace).  At the 
moment this is
 incomplete.  All system calls that don't have a specific argument
 format are printed with information for six arguments.  Many
 flag-style arguments don't have decoders and will show up as numbers.
+@item QEMU_DEBUG=options
+Activate log. Use same options as '-d' options.
+@item QEMU_GDB=port
+Wait gdb connection to port.
 @end table
 
 @node Other binaries
-- 
1.7.4.1




[Qemu-devel] [PATCH 1/4] linux-user: define default cpu model in configure instead of linux-user/main.c

2011-07-28 Thread Laurent Vivier
Signed-off-by: Laurent Vivier 
---
 configure |   15 +++
 linux-user/main.c |   34 +-
 2 files changed, 16 insertions(+), 33 deletions(-)

diff --git a/configure b/configure
index fb8819b..c74a5f9 100755
--- a/configure
+++ b/configure
@@ -3075,6 +3075,7 @@ target_dir="$target"
 config_target_mak=$target_dir/config-target.mak
 target_arch2=`echo $target | cut -d '-' -f 1`
 target_bigendian="no"
+target_default_cpu="any"
 
 case "$target_arch2" in
   
armeb|lm32|m68k|microblaze|mips|mipsn32|mips64|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus)
@@ -3151,11 +3152,13 @@ TARGET_ABI_DIR=""
 case "$target_arch2" in
   i386)
 target_phys_bits=64
+target_default_cpu="qemu32"
   ;;
   x86_64)
 TARGET_BASE_ARCH=i386
 target_phys_bits=64
 target_long_alignment=8
+target_default_cpu="qemu64"
   ;;
   alpha)
 target_phys_bits=64
@@ -3173,6 +3176,7 @@ case "$target_arch2" in
   cris)
 target_nptl="yes"
 target_phys_bits=32
+target_default_cpu=""
   ;;
   lm32)
 target_phys_bits=32
@@ -3198,12 +3202,14 @@ case "$target_arch2" in
 echo "TARGET_ABI_MIPSO32=y" >> $config_target_mak
 target_nptl="yes"
 target_phys_bits=64
+target_default_cpu="24Kf"
   ;;
   mipsn32|mipsn32el)
 TARGET_ARCH=mipsn32
 TARGET_BASE_ARCH=mips
 echo "TARGET_ABI_MIPSN32=y" >> $config_target_mak
 target_phys_bits=64
+target_default_cpu="20Kc"
   ;;
   mips64|mips64el)
 TARGET_ARCH=mips64
@@ -3211,12 +3217,14 @@ case "$target_arch2" in
 echo "TARGET_ABI_MIPSN64=y" >> $config_target_mak
 target_phys_bits=64
 target_long_alignment=8
+target_default_cpu="20Kc"
   ;;
   ppc)
 gdb_xml_files="power-core.xml power-fpu.xml power-altivec.xml 
power-spe.xml"
 target_phys_bits=32
 target_nptl="yes"
 target_libs_softmmu="$fdt_libs"
+target_default_cpu="750"
   ;;
   ppcemb)
 TARGET_BASE_ARCH=ppc
@@ -3225,6 +3233,7 @@ case "$target_arch2" in
 target_phys_bits=64
 target_nptl="yes"
 target_libs_softmmu="$fdt_libs"
+target_default_cpu="750"
   ;;
   ppc64)
 TARGET_BASE_ARCH=ppc
@@ -3233,6 +3242,7 @@ case "$target_arch2" in
 target_phys_bits=64
 target_long_alignment=8
 target_libs_softmmu="$fdt_libs"
+target_default_cpu="970fx"
   ;;
   ppc64abi32)
 TARGET_ARCH=ppc64
@@ -3242,6 +3252,7 @@ case "$target_arch2" in
 gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml 
power-spe.xml"
 target_phys_bits=64
 target_libs_softmmu="$fdt_libs"
+target_default_cpu="750"
   ;;
   sh4|sh4eb)
 TARGET_ARCH=sh4
@@ -3251,11 +3262,13 @@ case "$target_arch2" in
   ;;
   sparc)
 target_phys_bits=64
+target_default_cpu="Fujitsu MB86904"
   ;;
   sparc64)
 TARGET_BASE_ARCH=sparc
 target_phys_bits=64
 target_long_alignment=8
+target_default_cpu="TI UltraSparc II"
   ;;
   sparc32plus)
 TARGET_ARCH=sparc64
@@ -3263,6 +3276,7 @@ case "$target_arch2" in
 TARGET_ABI_DIR=sparc
 echo "TARGET_ABI32=y" >> $config_target_mak
 target_phys_bits=64
+target_default_cpu="Fujitsu MB86904"
   ;;
   s390x)
 target_nptl="yes"
@@ -3281,6 +3295,7 @@ echo "TARGET_SHORT_ALIGNMENT=$target_short_alignment" >> 
$config_target_mak
 echo "TARGET_INT_ALIGNMENT=$target_int_alignment" >> $config_target_mak
 echo "TARGET_LONG_ALIGNMENT=$target_long_alignment" >> $config_target_mak
 echo "TARGET_LLONG_ALIGNMENT=$target_llong_alignment" >> $config_target_mak
+echo "TARGET_DEFAULT_CPU=\"$target_default_cpu\"" >> $config_target_mak
 echo "TARGET_ARCH=$TARGET_ARCH" >> $config_target_mak
 target_arch_name="`echo $TARGET_ARCH | tr '[:lower:]' '[:upper:]'`"
 echo "TARGET_$target_arch_name=y" >> $config_target_mak
diff --git a/linux-user/main.c b/linux-user/main.c
index 2135b9c..7180cee 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3082,39 +3082,7 @@ int main(int argc, char **argv, char **envp)
 init_paths(interp_prefix);
 
 if (cpu_model == NULL) {
-#if defined(TARGET_I386)
-#ifdef TARGET_X86_64
-cpu_model = "qemu64";
-#else
-cpu_model = "qemu32";
-#endif
-#elif defined(TARGET_ARM)
-cpu_model = "any";
-#elif defined(TARGET_UNICORE32)
-cpu_model = "any";
-#elif defined(TARGET_M68K)
-cpu_model = "any";
-#elif defined(TARGET_SPARC)
-#ifdef TARGET_SPARC64
-cpu_model = "TI UltraSparc II";
-#else
-cpu_model = "Fujitsu MB86904";
-#endif
-#elif defined(TARGET_MIPS)
-#if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64)
-cpu_model = "20Kc";
-#else
-cpu_model = "24Kf";
-#endif
-#elif defined(TARGET_PPC)
-#ifdef TARGET_PPC64
-cpu_model = "970fx";
-#else
-cpu_model = "750";
-#endif
-#else
-cpu_model = "any";
-#endif
+cpu_model = TARGET_DEFAULT_CPU;
 }
 cpu_exec_init_all(0);
 /* NOTE: we need to init the CPU at this stage to get
-- 
1.7.4.1




Re: [Qemu-devel] [RFC][PATCH 000/111] QEMU m68k core additions

2011-08-18 Thread Laurent Vivier
Le mercredi 17 août 2011 à 17:35 -0500, Anthony Liguori a écrit :
> On 08/17/2011 03:46 PM, Bryce Lanham wrote:
> > These patches greatly expand Motorola 68k emulation within qemu, and are 
> > what I used as a basis for my
> > Google Summer of Code project to add NeXT hardware support to QEMU.
> 
> Please don't crap flood the list with a series of 100 patches.
> 
> Split things into logical chunks such that a series can be reasonably 
> reviewed and applied.

And I'm not sure this series of patches is ready for inclusion in qemu
mainline as it should break existing m68k emulation...

Bryce, you should only post your patches, refering to the repository on
which they apply, i.e. git://gitorious.org/qemu-m68k/qemu-m68k.git ,
master branch.

Regards,
Laurent

> Regards,
> 
> Anthony Liguori
> 
> >
> > Bryce Lanham
> >
> > Alexander Paramonov (1):
> >linux-user: Signals processing is not thread-safe.
> >
> > Andreas Schwab (3):
> >m68k: add cas
> >m68k: define fcntl constants
> >m68k: add DBcc instruction.
> >
> > Laurent Vivier (106):
> >linux-user: add qemu-wrapper
> >linux-user: define default cpu model in configure instead of
> >  linux-user/main.c
> >linux-user: specify the cpu model during configure
> >linux-user,m68k: display default cpu
> >linux-user: define new environment variables
> >linux-user: define a script to set binfmt using debian flavored tools
> >linux-user: define default cpu model in configure instead of
> >  linux-user/main.c
> >m68k: add tcg_gen_debug_insn_start()
> >m68k: define m680x0 CPUs and features
> >m68k: add missing accessing modes for some instructions.
> >m68k: add Motorola 680x0 family common instructions.
> >m68k: add Scc instruction with memory operand.
> >m68k: add DBcc instruction.
> >m68k: modify movem instruction to manage word
> >m68k: add 64bit divide.
> >m68k: add 32bit and 64bit multiply
> >m68k: add word data size for suba/adda
> >m68k: add fpu
> >m68k: add "byte", "word" and memory shift
> >m68k: add "byte", "word" and memory rotate.
> >m68k: add bitfield_mem, bitfield_reg
> >m68k: add variable offset/width to bitfield_reg/bitfield_mem
> >m68k: add cas
> >m68k: allow fpu to manage double data type.
> >m68k: allow fpu to manage double data type with fmove to
> >m68k: add FScc instruction
> >m68k: add single data type to gen_ea
> >m68k: add linkl instruction
> >m68k: Add fmovecr
> >m68k: correct typo on f64_to_i32() return type.
> >m68k: improve CC_OP_LOGIC
> >m68k: correct neg condition code flags computation
> >Correct invalid use of "const void *" with "const uint8_t *"
> >m68k: add EA support for negx
> >m68k: add abcd instruction
> >m68k: add sbcd instruction
> >mm68k: add nbcd instruction
> >m68k: set X flag according size of operand Set X flag correctly
> >  for addsub, arith_im, addsubq.
> >m68k: on 0 bit shift, don't update X flag
> >m68k: improve addx instructions Add (byte, word) opsize Add
> >  memory access
> >m68k: improve subx,negx instructions Add (byte, word) opsize
> >  Add memory access (subx)
> >m68k: improve asl/asr evaluate correclty the missing V flag
> >m68k: use read_imm1() when it is possible
> >m68k: correct shift side effect for roxrl and roxll
> >m68k: asl/asr, clear C flag if shift count is 0
> >m68k: lsl/lsr, clear C flag if shift count is 0
> >m68k: correct divs.w and divu.w
> >m68k: correct flags with negl
> >m68k: for bitfield opcodes, correct operands corruption
> >m68k: Correct bfclr in register case.
> >m68k-linux-user: add '--enable-emulop'
> >m68k: correctly compute divsl
> >m68k: correctly compute divul
> >m68k: add m68030 definition
> >m68k: remove dead code
> >m68k: remove useless file m68k-qreg.h
> >m68k: FPU rework (draft)
> >m68k: some FPU debugging macros
> >m68k: more tests
> >m68k: correct compute gen_bitfield_cc()
> >m68k: add fgetexp
> >m68k: add fscale
> >m68k: correct addsubq
> >m68k: add fetox and flogn
> >m68k: initialize FRegs, define pickNaN()
> >m68k: correct cmpa comparison datatype
> >m68k: add flog10
> >m68k: add cmpm instruction
> >m68k:

Re: [Qemu-devel] [RFC][PATCH 000/111] QEMU m68k core additions

2011-08-18 Thread Laurent Vivier


 


Le 18 août 2011 à 13:12, "François Revol"  a écrit :

> Le -10/01/-28163 20:59, Laurent Vivier a écrit :
> > Le mercredi 17 août 2011 à 17:35 -0500, Anthony Liguori a écrit :
> >> On 08/17/2011 03:46 PM, Bryce Lanham wrote:
> >>> These patches greatly expand Motorola 68k emulation within qemu, and are
> >>> what I used as a basis for my
> >>> Google Summer of Code project to add NeXT hardware support to QEMU.
> >>
> >> Please don't crap flood the list with a series of 100 patches.
> >>
> >> Split things into logical chunks such that a series can be reasonably
> >> reviewed and applied.
> >
> > And I'm not sure this series of patches is ready for inclusion in qemu
> > mainline as it should break existing m68k emulation...
> >
> > Bryce, you should only post your patches, refering to the repository on
> > which they apply, i.e. git://gitorious.org/qemu-m68k/qemu-m68k.git ,
> > master branch.
> >
>
> Btw, are you planning on merging it back someday?
> 
Yes... when it will work correctly.
 
I have at least, to rework 680x0 FPU part (80bit fpu) to not break the existing
one (64bit fpu).
I have to check modified instructions don't break existing m68k emulation.
 
Currently, I'm trying to port some parts of BasiliskII into Qemu to be able to
boot MacOS 7.6.
 
Regards,
Laurent

Re: [Qemu-devel] [RFC][PATCH 000/111] QEMU m68k core additions

2011-08-18 Thread Laurent Vivier
Le jeudi 18 août 2011 à 20:42 +0100, Natalia Portillo a écrit :
> Hi Laurent,

Hi Natalia,

> El 18/08/2011, a las 15:02, Laurent Vivier escribió:
> 
> >  
> > 
> > 
> > Le 18 août 2011 à 13:12, "François Revol"  a écrit : 
> > 
> > > Le -10/01/-28163 20:59, Laurent Vivier a écrit : 
> > > > Le mercredi 17 août 2011 à 17:35 -0500, Anthony Liguori a
> > écrit : 
> > > >> On 08/17/2011 03:46 PM, Bryce Lanham wrote: 
> > > >>> These patches greatly expand Motorola 68k emulation within
> > qemu, and are what I used as a basis for my 
> > > >>> Google Summer of Code project to add NeXT hardware support to
> > QEMU. 
> > > >> 
> > > >> Please don't crap flood the list with a series of 100 patches. 
> > > >> 
> > > >> Split things into logical chunks such that a series can be
> > reasonably 
> > > >> reviewed and applied. 
> > > > 
> > > > And I'm not sure this series of patches is ready for inclusion
> > in qemu 
> > > > mainline as it should break existing m68k emulation... 
> > > > 
> > > > Bryce, you should only post your patches, refering to the
> > repository on 
> > > > which they apply, i.e.
> > git://gitorious.org/qemu-m68k/qemu-m68k.git , 
> > > > master branch. 
> > > > 
> > > 
> > > Btw, are you planning on merging it back someday? 
> > > 
> >  
> > 
> > Yes... when it will work correctly.
> >  
> > 
> > I have at least, to rework 680x0 FPU part (80bit fpu) to not break
> > the existing one (64bit fpu).
> > I have to check modified instructions don't break existing m68k
> > emulation.
> 
> 
> Maybe Bryce can help you

I don't know if he is courageous enough to review and push 111
patches ;-)

> > Currently, I'm trying to port some parts of BasiliskII into Qemu to
> > be able to boot MacOS 7.6.
> 
> 
> Why are you planning to port a hack instead of making a full machine
> emulation?

Because I'm lazy and dumb: the work is already done, I like cut'n'paste.

Regards,
Laurent





Re: [Qemu-devel] [RFC][PATCH 000/111] QEMU m68k core additions

2011-08-18 Thread Laurent Vivier
Le jeudi 18 août 2011 à 21:13 +0100, Natalia Portillo a écrit :
> Hi Laurent,
> 
> El 18/08/2011, a las 20:57, Laurent Vivier escribió:
> 
> > Le jeudi 18 août 2011 à 20:42 +0100, Natalia Portillo a écrit :
> >> Hi Laurent,
> > 
> > Hi Natalia,
> > 
> >> El 18/08/2011, a las 15:02, Laurent Vivier escribió:
> >> 
> >>> 
> >>> 
> >>> 
> >>> Le 18 août 2011 à 13:12, "François Revol"  a écrit : 
> >>> 
> >>>> Le -10/01/-28163 20:59, Laurent Vivier a écrit : 
> >>>>> Le mercredi 17 août 2011 à 17:35 -0500, Anthony Liguori a
> >>> écrit : 
> >>>>>> On 08/17/2011 03:46 PM, Bryce Lanham wrote: 
> >>>>>>> These patches greatly expand Motorola 68k emulation within
> >>> qemu, and are what I used as a basis for my 
> >>>>>>> Google Summer of Code project to add NeXT hardware support to
> >>> QEMU. 
> >>>>>> 
> >>>>>> Please don't crap flood the list with a series of 100 patches. 
> >>>>>> 
> >>>>>> Split things into logical chunks such that a series can be
> >>> reasonably 
> >>>>>> reviewed and applied. 
> >>>>> 
> >>>>> And I'm not sure this series of patches is ready for inclusion
> >>> in qemu 
> >>>>> mainline as it should break existing m68k emulation... 
> >>>>> 
> >>>>> Bryce, you should only post your patches, refering to the
> >>> repository on 
> >>>>> which they apply, i.e.
> >>> git://gitorious.org/qemu-m68k/qemu-m68k.git , 
> >>>>> master branch. 
> >>>>> 
> >>>> 
> >>>> Btw, are you planning on merging it back someday? 
> >>>> 
> >>> 
> >>> 
> >>> Yes... when it will work correctly.
> >>> 
> >>> 
> >>> I have at least, to rework 680x0 FPU part (80bit fpu) to not break
> >>> the existing one (64bit fpu).
> >>> I have to check modified instructions don't break existing m68k
> >>> emulation.
> >> 
> >> 
> >> Maybe Bryce can help you
> > 
> > I don't know if he is courageous enough to review and push 111
> > patches ;-)
> 
> He worked on emulating an abandoned, strange, difficult to get, and 
> undocumented hardware, using your 111 patches, and finished it before the 
> wholy more experienced MESS team.

The next-cube emulation is really working ?

> He is! xD

There is no problem for me, he can do...

> >>> Currently, I'm trying to port some parts of BasiliskII into Qemu to
> >>> be able to boot MacOS 7.6.
> >> 
> >> 
> >> Why are you planning to port a hack instead of making a full machine
> >> emulation?
> > 
> > Because I'm lazy and dumb: the work is already done, I like cut'n'paste.
> 
> Yeah, you said it!
> The work is already done, we have all the hardware emulation that Basilisk 
> substitutes for hacks.

I'm not sure of that... no MMU emulation, no Nubus, no ethernet card, no
video card, no SWIM, no SCSI, ... useless with a patched ROM.

You know, nights are not long enough...

> We only lack the 68k cpu (oh! your patches!!!) and the glue :p

this part is not working well as well ... gcc cannot compile linux
kernel, some demos fail in gtk-demo, ...

> Please don't port Basilisk on top of TCG, I beg to you in the name of some 
> god of your own choice :(

I believe only in Santa Claus, and it's not Christmas.

> (1000 Mb floppies patching .sony instead of implementing SCSI and SWIM, no 
> ethernet controller but a working TCP/IP, oh hell, it's not a Mac, it's a 
> Match!)

Regards,
Laurent




Re: [Qemu-devel] [PATCH 0/8] *** SUBJECT HERE ***

2011-08-19 Thread Laurent Vivier
Bryce,
 
please, run scripts/checkpatch.pl before submitting them to check the style.

Then, IMHO, you can put all next-cube stuff in one patch (hw/next-* +
Makefile.target),
then make one patch by m68k feature/instruction added or m68k default corrected.
 
And remember, to be able to bisect, each patch must be able to be compiled and
run.
 
Good Luck,
Laurent

 


Le 18 août 2011 à 00:09, Bryce Lanham  a écrit :

> *** BLURB HERE ***
>
> Bryce Lanham (8):
>   added next source files to Makefile.target
>   main next driver, needs a bit of cleanup
>   next framebuffer driver, very basic, only supports running under 32
>     bit color at the moment
>   next keyboard driver, only supports a subset of modifier keys
>   partially working network driver, needs more comparison with real
>     hardware before it can be made fully working
>   adds SFC, DFC, MMU TC, access control register, and user stack
>     pointer acces to movec_to/from
>   added move16, cinva, pflush instructions, and disabled abort on
>     execution of frestore/fsave
>   added mmu tc, sfc, dfc, and access control registers to the cpu
>     header
>
>  Makefile.target         |    2 +
>  hw/next-cube.c          |  471 +++
>  hw/next-fb.c            |  102 ++
>  hw/next-fb.h            |   14 ++
>  hw/next-kbd.c           |  243 ++
>  hw/next-kbd.h           |    2 +
>  hw/next-net.c           |  513
>+++
>  hw/next-net.h           |    2 +
>  target-m68k/cpu.h       |   12 +-
>  target-m68k/helper.c    |   44 -
>  target-m68k/translate.c |  108 +-
>  11 files changed, 1491 insertions(+), 22 deletions(-)
>  create mode 100644 hw/next-cube.c
>  create mode 100644 hw/next-fb.c
>  create mode 100644 hw/next-fb.h
>  create mode 100644 hw/next-kbd.c
>  create mode 100644 hw/next-kbd.h
>  create mode 100644 hw/next-net.c
>  create mode 100644 hw/next-net.h
>
> --
> 1.7.2.3
>
>

Re: [Qemu-devel] [RFC][PATCH 000/111] QEMU m68k core additions

2011-08-19 Thread Laurent Vivier


 


Le 19 août 2011 à 17:52, Natalia Portillo  a écrit :

>
> El 19/08/2011, a las 09:55, François Revol escribió:
[snip]
> > Release early, release often :p
>
> +1Ok, Ok, I think all m68k core can be submitted except some bitfield
> operations and fpu instructions.
 
Just need to know how Anthony and Paul want I proceed...
 
Regards,
Laurent

Re: [Qemu-devel] [RFC][PATCH 000/111] QEMU m68k core additions

2011-08-20 Thread Laurent Vivier
Le samedi 20 août 2011 à 15:57 -0500, Rob Landley a écrit :
> On 08/18/2011 06:12 AM, François Revol wrote:
> > Le -10/01/-28163 20:59, Laurent Vivier a écrit :
> >> Le mercredi 17 août 2011 à 17:35 -0500, Anthony Liguori a écrit :
> >>> On 08/17/2011 03:46 PM, Bryce Lanham wrote:
> >>>> These patches greatly expand Motorola 68k emulation within qemu, and
> >>>> are what I used as a basis for my
> >>>> Google Summer of Code project to add NeXT hardware support to QEMU.
> >>>
> >>> Please don't crap flood the list with a series of 100 patches.
> >>>
> >>> Split things into logical chunks such that a series can be reasonably
> >>> reviewed and applied.
> >>
> >> And I'm not sure this series of patches is ready for inclusion in qemu
> >> mainline as it should break existing m68k emulation...
> >>
> >> Bryce, you should only post your patches, refering to the repository on
> >> which they apply, i.e. git://gitorious.org/qemu-m68k/qemu-m68k.git ,
> >> master branch.
> >>
> > 
> > Btw, are you planning on merging it back someday?
> > 
> > François.
> 
> I note that I pulled that this morning, did "./configure
> --disable-werror --target-list=m68k-softmmu", and then ran make, which
> generated 4 header files and considered itself done.
> 
> I.E. m68k system emulation doesn't seem to be building in that tree.

first off all, this branch is only able to build m68k-linux-user qemu/,
then try:

cd qemu
mkdir build-test
cd build-test
../configure --disable-werror --target-list=m68k-softmmu
make

and let me know what happens...

Regards,
Laurent




Re: [Qemu-devel] [RFC][PATCH 000/111] QEMU m68k core additions

2011-08-21 Thread Laurent Vivier
Le samedi 20 août 2011 à 18:42 -0500, Rob Landley a écrit :
> On 08/20/2011 06:17 PM, Natalia Portillo wrote:
> >> or ancient macintosh support
> > 
> > Most of the hardware (but a few required ones like SWIM) is already
> > in QEMU, you need to glue everything, make Toolbox be VERY happy
> > about its environment, make Mac OS boot so it can second-boot Linux
> > (the direct-booter is so buggy it may introduce phantom bugs on the
> > emulation) and implement the MMU.
> 
> I haven't got a copy of ancient MacOS.
> 
> Why is the direct booter buggy?  I'm happy to track down and isolate
> phantom bugs, either in the kernel or in qemu.  (One nice thing about
> emulators is you can get deterministic regression tests reasonably
> easily. :)
> 
> How do I _use_ the direct booter, anyway?  I built mac_defconfig in 3.0
> but it only gave me a vmlinux, which faulted on the instruction at
> address 0.  I tried m68k-objdump -O binary vmlinux vmlinux.bin but that
> wouldnt' bot at all (qemu -kernel refused to load it).

For the moment, q800 is not working. 

Master branch is for m68k-linux-user target.

I'm working on m68k-softmmu on the macrom-branch by porting the
basiliskII stuff.
[Natalia: this allows me to debug the CPU by comparing traces from
BasiliskII and traces from qemu, I've found several in supervisor mode] 

but a ROM will not be required to boot it as the bootloader has the role
to collect information from the ROM to pass it the kernel.
Qemu will be able to do it and boot directly the kernel (with option
--kernel). We can cut&paste parts from the EMILE bootloader.

A real machine emulation will require a ROM. But for this part we can
have a look to executore (https://github.com/ctm/executor).

> >> that Linux could boot on?  (I.E. I'm interested in Linux system 
> >> emulation of non-coldfire m68k.  So far that means "use aranym".)
> > 
> > Linux requires the MMU and an almost complete hardware emulation. 
> > Standard m68k emulations (UAE, Aranym and specially BasiliskII) try
> > to patch the OS to work.
> 
> That's kinda sad.  Is there a web page anywhere that elaborates on this?
> 
> > Indeed BasiliskII is anything but a real macintosh emulator, as it
> > patches heavily the Toolbox and Mac OS (that's why Linux and A/UX
> > will never work on it)
> 
> I believe toolbox is the ancient mac bios, correct?  Does Linux need/use
> it at all?

No

Regards,
Laurent





Re: [Qemu-devel] Poking at m68k gitorious branch.

2012-04-19 Thread Laurent Vivier
Hi Rob,

you need to do a fresh clone because I rebase the branch frequently on the
qemu/master instead of merging it. It is easier to manage for me.

BTW, qemu-system-m68k is not working currently. I'm working on it on the
branch q800 to emulate a macintosh quadra 800. I'm able to boot until the
first process (1), then I have some issues with the MMU. The serial line is
working (ttyS0 is in fact the second port, use "-serial none -serial stdio"
to see it), the framebuffer too. The ADB emulation needs some more work to
be correctly attached to m68k VIA instead of PPC CUDA. For the SCSI, we can
use ESP, but the pseudo-dma mode used by q800 is not implemented.

To compile my m68k kernel I use a chroot and the m68k linux-user qemu mode,
that seems to work well... perhaps you can test your tools inside this.

Regards,
Laurent


Le 19 avril 2012 à 01:24, Rob Landley  a écrit :

> My aboriginal linux project has bootable system images for a bunch of
> targets (see http://landley.net/aboriginal/bin) and I want to add m68k.
> For years it's been building a stub m68k system image, but the
> run-emulator.sh script that should theoretically launch it is just a
stub.
>
> A user once got my m68k root filesystem running under the Aranym
> emulator, so I know my cross compiler and root filesystem work. But I
> haven't got an m68k kernel qemu can boot, or a qemu that can boot it.
>
> A year or so back I poked at the m68k gitorious branch:
>
>   git://gitorious.org/qemu-m68k/qemu-m68k
>
> But it wasn't finished and I got distracted.
>
> I just did a fresh clone of the branch (for some reason pull said I'd
> diverged by ~100 commits and there was a conflict?  I'm guessing the
> patch series that got posted here, maybe?), built a kernel with the
> attached .config and the cross-compiler-m68k from the above aboriginal
> binary directory url, and took a wild guess at qemu/kernel command line
> arguments, currently just trying to get boot messages on the serial
console:
>
>   qemu-system-m68k -nographic -no-reboot -kernel vmlinux \
> -append "console=ttyS0 panic=1"
>
> The result was:
>
> QEMU 1.0,1 monitor - type 'help' for more information
> (qemu) QEMU 1.0,1 monitor - type 'help' for more information
> (qemu) qemu: fatal: Illegal instruction: 7f45 @ 
> D0 = 0808   A0 = 0021e744   F0 = 7fff 
> D1 = c4653600   A1 = 0021e6ae   F1 = 7fff 
> D2 = 2721   A2 = 1000   F2 = 7fff 
> D3 = e768002c   A3 = 00233000   F3 = 7fff 
> D4 =    A4 =    F4 = 7fff 
> D5 =    A5 =    F5 = 7fff 
> D6 =    A6 = 0ff8   F6 = 7fff 
> D7 = 0022db50   A7 = 0ff0   F7 = 7fff 
> PC =    SR = 2700 - Aborted
>
> Which is a bit of a dead end. I'd guess that "vmlinux" isn't the right
> binary, except there isn't an arch/m68k/boot directory...
>
> Laurent: do you have any hints for me?
>
> Thanks,
>
> Rob
> --
> GNU/Linux isn't: Linux=GPLv2, GNU=GPLv3+, they can't share code.
> Either it's "mere aggregation", or a license violation.  Pick one.

Re: [Qemu-devel] [PATCH v2 0/4] QOM'ify Motorola 68k CPU

2012-04-21 Thread Laurent Vivier
Le samedi 21 avril 2012 à 08:08 +0200, Andreas Färber a écrit :
> Am 15.04.2012 05:10, schrieb Andreas Färber:
> > Hello,
> > 
> > This series splits up my m68k QOM'ification patch from the qom-cpu-others 
> > RFC series.
> > CPU models are now modelled as subclasses with their own initfns, leaving 
> > the
> > setting of feature flags imperative.
> > 
> > Please review and apply.
> 
> Ping!
> 
> Laurent, did you get around to reviewing this or testing your tree on
> top? Hard Freeze for 1.1 is coming up (also if you have any fixes to
> upstream yourself, obviously).

I'm sorry,  I can't test it with my branch: my branch is based on 1.0.1
and when I rebase it something else is broken, so I can't test... and I
don't have any time to do more.

Anyway, patches seem OK.

Reviewed-by: Laurent Vivier 


> If there are no comments, I'll send out a PULL mid next week.
> 
> Andreas
> 
> > 
> > Available from:
> > git://github.com/afaerber/qemu-cpu.git qom-cpu-m68k.v2
> > https://github.com/afaerber/qemu-cpu/commits/qom-cpu-m68k.v2
> > 
> > Regards,
> > Andreas
> > 
> > Cc: Paul Brook 
> > Cc: Laurent Vivier 
> > 
> > v1 -> v2:
> > * Split off from qom-cpu-others series, rebased and split into multiple 
> > steps.
> > * Update argument/variable naming to avoid "klass".
> > * Instead of transforming feature flag setup into declarative M68kCPUInfo 
> > fields
> >   move the original code into initfns, following Peter's model for ARM.
> >   As a side effect, we can't move cpu_reset() into the main initfn.
> > 
> > Andreas Färber (4):
> >   target-m68k: QOM'ify CPU
> >   target-m68k: QOM'ify CPU reset
> >   target-m68k: Start QOM'ifying CPU init
> >   target-m68k: Add QOM CPU subclasses
> > 
> >  Makefile.target   |1 +
> >  target-m68k/cpu-qom.h |   70 
> >  target-m68k/cpu.c |  170 
> > +
> >  target-m68k/cpu.h |3 +-
> >  target-m68k/helper.c  |  159 +++---
> >  5 files changed, 294 insertions(+), 109 deletions(-)
> >  create mode 100644 target-m68k/cpu-qom.h
> >  create mode 100644 target-m68k/cpu.c
> > 
> 
> 





Re: [Qemu-devel] [PATCH v2 0/4] QOM'ify Motorola 68k CPU

2012-04-21 Thread Laurent Vivier
Le dimanche 22 avril 2012 à 01:17 +0200, Laurent Vivier a écrit :
> Le samedi 21 avril 2012 à 08:08 +0200, Andreas Färber a écrit :
> > Am 15.04.2012 05:10, schrieb Andreas Färber:
> > > Hello,
> > > 
> > > This series splits up my m68k QOM'ification patch from the qom-cpu-others 
> > > RFC series.
> > > CPU models are now modelled as subclasses with their own initfns, leaving 
> > > the
> > > setting of feature flags imperative.
> > > 
> > > Please review and apply.
> > 
> > Ping!
> > 
> > Laurent, did you get around to reviewing this or testing your tree on
> > top? Hard Freeze for 1.1 is coming up (also if you have any fixes to
> > upstream yourself, obviously).
> 
> I'm sorry,  I can't test it with my branch: my branch is based on 1.0.1
> and when I rebase it something else is broken, so I can't test... and I
> don't have any time to do more.
> 
> Anyway, patches seem OK.
> 
> Reviewed-by: Laurent Vivier 

I've been able to test it, so:

Tested-by: Laurent Vivier 

> 
> > If there are no comments, I'll send out a PULL mid next week.
> > 
> > Andreas
> > 
> > > 
> > > Available from:
> > > git://github.com/afaerber/qemu-cpu.git qom-cpu-m68k.v2
> > > https://github.com/afaerber/qemu-cpu/commits/qom-cpu-m68k.v2
> > > 
> > > Regards,
> > > Andreas
> > > 
> > > Cc: Paul Brook 
> > > Cc: Laurent Vivier 
> > > 
> > > v1 -> v2:
> > > * Split off from qom-cpu-others series, rebased and split into multiple 
> > > steps.
> > > * Update argument/variable naming to avoid "klass".
> > > * Instead of transforming feature flag setup into declarative M68kCPUInfo 
> > > fields
> > >   move the original code into initfns, following Peter's model for ARM.
> > >   As a side effect, we can't move cpu_reset() into the main initfn.
> > > 
> > > Andreas Färber (4):
> > >   target-m68k: QOM'ify CPU
> > >   target-m68k: QOM'ify CPU reset
> > >   target-m68k: Start QOM'ifying CPU init
> > >   target-m68k: Add QOM CPU subclasses
> > > 
> > >  Makefile.target   |1 +
> > >  target-m68k/cpu-qom.h |   70 
> > >  target-m68k/cpu.c |  170 
> > > +
> > >  target-m68k/cpu.h |3 +-
> > >  target-m68k/helper.c  |  159 
> > > +++---
> > >  5 files changed, 294 insertions(+), 109 deletions(-)
> > >  create mode 100644 target-m68k/cpu-qom.h
> > >  create mode 100644 target-m68k/cpu.c
> > > 
> > 
> > 
> 
> 
> 





[Qemu-devel] NBD broken ?

2012-03-03 Thread Laurent Vivier
Hi,

since commit ae255e523, qemu with NBD hangs at startup (when it tries to
access the disk):

commit ae255e523c256cf0708f1c16cb946ff96340a800
Author: Paolo Bonzini 
Date:   Thu Sep 8 14:28:59 2011 +0200

nbd: switch to asynchronous operation

Signed-off-by: Paolo Bonzini 


Reverting this patch corrects the problem.

My system is an Ubuntu 11.04 x86_64 (But the bug is also seen on RHEL6).

qemu is configured only with "--target-list=x86_64-softmmu".

My test case is:

./qemu-nbd -k /tmp/nbd-socket -t /ISO/ubuntu-11.04-desktop-i386.iso

./x86_64-softmmu/qemu-system-x86_64 -cdrom nbd:unix:/tmp/nbd-socket

Same problem with a TCP socket, with/without KVM, with an x86_64 guest, with 
-hda...
 
Regards,
Laurent




[Qemu-devel] [PATCH] ppc: move ADB stuff from ppc_mac.h to adb.h

2011-09-04 Thread Laurent Vivier
Allow to use ADB in non-ppc macintosh

Signed-off-by: Laurent Vivier 
---
 hw/adb.c  |2 +-
 hw/adb.h  |   67 +
 hw/cuda.c |1 +
 hw/ppc_mac.h  |   42 -
 hw/ppc_newworld.c |1 +
 hw/ppc_oldworld.c |1 +
 6 files changed, 71 insertions(+), 43 deletions(-)
 create mode 100644 hw/adb.h

diff --git a/hw/adb.c b/hw/adb.c
index 8dedbf8..aa15f55 100644
--- a/hw/adb.c
+++ b/hw/adb.c
@@ -22,7 +22,7 @@
  * THE SOFTWARE.
  */
 #include "hw.h"
-#include "ppc_mac.h"
+#include "adb.h"
 #include "console.h"
 
 /* debug ADB */
diff --git a/hw/adb.h b/hw/adb.h
new file mode 100644
index 000..b2a591c
--- /dev/null
+++ b/hw/adb.h
@@ -0,0 +1,67 @@
+/*
+ * QEMU ADB emulation shared definitions and prototypes
+ *
+ * Copyright (c) 2004-2007 Fabrice Bellard
+ * Copyright (c) 2007 Jocelyn Mayer
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#if !defined(__ADB_H__)
+#define __ADB_H__
+
+#define MAX_ADB_DEVICES 16
+
+#define ADB_MAX_OUT_LEN 16
+
+typedef struct ADBDevice ADBDevice;
+
+/* buf = NULL means polling */
+typedef int ADBDeviceRequest(ADBDevice *d, uint8_t *buf_out,
+  const uint8_t *buf, int len);
+typedef int ADBDeviceReset(ADBDevice *d);
+
+struct ADBDevice {
+struct ADBBusState *bus;
+int devaddr;
+int handler;
+ADBDeviceRequest *devreq;
+ADBDeviceReset *devreset;
+void *opaque;
+};
+
+typedef struct ADBBusState {
+ADBDevice devices[MAX_ADB_DEVICES];
+int nb_devices;
+int poll_index;
+} ADBBusState;
+
+int adb_request(ADBBusState *s, uint8_t *buf_out,
+const uint8_t *buf, int len);
+int adb_poll(ADBBusState *s, uint8_t *buf_out);
+
+ADBDevice *adb_register_device(ADBBusState *s, int devaddr,
+   ADBDeviceRequest *devreq,
+   ADBDeviceReset *devreset,
+   void *opaque);
+void adb_kbd_init(ADBBusState *bus);
+void adb_mouse_init(ADBBusState *bus);
+
+extern ADBBusState adb_bus;
+#endif /* !defined(__ADB_H__) */
diff --git a/hw/cuda.c b/hw/cuda.c
index 5c92d81..6f05975 100644
--- a/hw/cuda.c
+++ b/hw/cuda.c
@@ -24,6 +24,7 @@
  */
 #include "hw.h"
 #include "ppc_mac.h"
+#include "adb.h"
 #include "qemu-timer.h"
 #include "sysemu.h"
 
diff --git a/hw/ppc_mac.h b/hw/ppc_mac.h
index 7351bb6..af75e45 100644
--- a/hw/ppc_mac.h
+++ b/hw/ppc_mac.h
@@ -77,46 +77,4 @@ void macio_nvram_setup_bar(MacIONVRAMState *s, MemoryRegion 
*bar,
 void pmac_format_nvram_partition (MacIONVRAMState *nvr, int len);
 uint32_t macio_nvram_read (void *opaque, uint32_t addr);
 void macio_nvram_write (void *opaque, uint32_t addr, uint32_t val);
-
-/* adb.c */
-
-#define MAX_ADB_DEVICES 16
-
-#define ADB_MAX_OUT_LEN 16
-
-typedef struct ADBDevice ADBDevice;
-
-/* buf = NULL means polling */
-typedef int ADBDeviceRequest(ADBDevice *d, uint8_t *buf_out,
-  const uint8_t *buf, int len);
-typedef int ADBDeviceReset(ADBDevice *d);
-
-struct ADBDevice {
-struct ADBBusState *bus;
-int devaddr;
-int handler;
-ADBDeviceRequest *devreq;
-ADBDeviceReset *devreset;
-void *opaque;
-};
-
-typedef struct ADBBusState {
-ADBDevice devices[MAX_ADB_DEVICES];
-int nb_devices;
-int poll_index;
-} ADBBusState;
-
-int adb_request(ADBBusState *s, uint8_t *buf_out,
-const uint8_t *buf, int len);
-int adb_poll(ADBBusState *s, uint8_t *buf_out);
-
-ADBDevice *adb_register_device(ADBBusState *s, int devaddr,
-   ADBDeviceRequest *devreq,
-   ADBDeviceReset *devreset,
-   void *opaque);
-void adb_kbd_init(ADBBusState *bus);
-void adb_mouse_init(ADBBusState *bus);
-
-extern ADBBusState adb

Re: [Qemu-devel] [PATCH] ppc: move ADB stuff from ppc_mac.h to adb.h

2011-09-07 Thread Laurent Vivier

Hi,
 


Le 7 septembre 2011 à 14:05, Alexander Graf  a écrit :

>
> On 04.09.2011, at 20:41, Laurent Vivier wrote:
>
> > Allow to use ADB in non-ppc macintosh
>
> What exactly do you need this for? Not saying I'm opposed to the change - it
> looks reasonable to have adb export its own interfaces using its own header -
> but I'd like to understand where you're heading here. Is this for m68k? 
Yes, I'm working on a quadra 800 emulation and ADB is attached to VIA.
So, it seems reasonable to move it out of ppc.
 
There will be more changes in the futur, but for the moment I'd like to merge
only obvious and generic changes.
 

> Btw - I applied the patch nevertheless.
> 
Thank you,
 
Regards,
Laurent

Re: [Qemu-devel] [PATCH] Add iSCSI support for QEMU

2011-09-17 Thread Laurent Vivier
Le jeudi 15 septembre 2011 à 08:06 +0200, Paolo Bonzini a écrit :
> On 09/14/2011 06:36 PM, Orit Wasserman wrote:
> > >  I think NBD would be fine, especially with a flush command.
> >  I think NBD would be fine, especially with a flush command.
> > If I remember correctly , there is a problem with NBD with an image with
> > a backing file chain . NBD client only displays a single file image.
> > With ISCSI we can use different luns per image file.
> 
> The NBD protocol supports multiple named exports, just not QEMU's 
> implementation.

Named exports are supported since commit
1d45f8b542f6b80b24c44533ef0dd9e1a3b17ea5

Regards,
Laurent




[Qemu-devel] [PATCH 0/4] Set of patches for chrooted environment

2011-09-18 Thread Laurent Vivier
This set of patches helps to use qemu-linux-user in a chrooted environment.

It mostly allows to define the default cpu model as we can't use '-cpu' 
argument.
The last one defines enviromnent variables to be able to use log file and 
gdb server  ('-d' and '-g' arguments).

[PATCH 1/4] linux-user: define default cpu model in configure instead of 
linux-user/main.c
[PATCH 2/4] linux-user: specify the cpu model during configure
[PATCH 3/4] linux-user,m68k: display default cpu
[PATCH 4/4] linux-user: define new environment variables



[Qemu-devel] [PATCH 2/4] linux-user: specify the cpu model during configure

2011-09-18 Thread Laurent Vivier
From: Laurent Vivier 

This patch allows to set the default cpu model for a given architecture,
for instance:

 configure --target-list=m68k-linux-user --m68k-default-cpu=m68040

Signed-off-by: Laurent Vivier 
---
 configure |9 +
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/configure b/configure
index 5e10055..5f2c073 100755
--- a/configure
+++ b/configure
@@ -536,6 +536,10 @@ for opt do
   ;;
   --target-list=*) target_list="$optarg"
   ;;
+  --*-default-cpu=*)
+tmp=`expr "x$opt" : 'x--\(.*\)-default-cpu=.*'`
+eval ${tmp}_default_cpu="$optarg"
+  ;;
   --enable-trace-backend=*) trace_backend="$optarg"
   ;;
   --with-trace-file=*) trace_file="$optarg"
@@ -932,6 +936,7 @@ echo "   use %M for cpu name 
[$interp_prefix]"
 echo "  --target-list=LIST   set target list (default: build everything)"
 echo "Available targets: $default_target_list" | \
 fold -s -w 53 | sed -e 's/^/   /'
+echo "  --ARCH-default-cpu=CPU   set the default cpu for a given architecture"
 echo ""
 echo "Advanced options (experts only):"
 echo "  --source-path=PATH   path of source code [$source_path]"
@@ -3369,6 +3374,10 @@ case "$target_arch2" in
 exit 1
   ;;
 esac
+tmp_target_default_cpu=`eval echo \\$${target_arch2}_default_cpu`
+if [ "x$tmp_target_default_cpu" != "x" ] ; then
+  target_default_cpu="$tmp_target_default_cpu"
+fi
 echo "TARGET_SHORT_ALIGNMENT=$target_short_alignment" >> $config_target_mak
 echo "TARGET_INT_ALIGNMENT=$target_int_alignment" >> $config_target_mak
 echo "TARGET_LONG_ALIGNMENT=$target_long_alignment" >> $config_target_mak
-- 
1.7.1




[Qemu-devel] [PATCH 3/4] linux-user,m68k: display default cpu

2011-09-18 Thread Laurent Vivier
From: Laurent Vivier 

Signed-off-by: Laurent Vivier 
---
 target-m68k/helper.c |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/target-m68k/helper.c b/target-m68k/helper.c
index 674c8e6..ede5180 100644
--- a/target-m68k/helper.c
+++ b/target-m68k/helper.c
@@ -57,6 +57,11 @@ void m68k_cpu_list(FILE *f, fprintf_function cpu_fprintf)
 unsigned int i;
 
 for (i = 0; m68k_cpu_defs[i].name; i++) {
+if (strcmp(m68k_cpu_defs[i].name, TARGET_DEFAULT_CPU) == 0) {
+(*cpu_fprintf)(f, " >");
+} else {
+(*cpu_fprintf)(f, "  ");
+}
 (*cpu_fprintf)(f, "%s\n", m68k_cpu_defs[i].name);
 }
 }
-- 
1.7.1




[Qemu-devel] [PATCH 1/4] linux-user: define default cpu model in configure instead of linux-user/main.c

2011-09-18 Thread Laurent Vivier
From: Laurent Vivier 

Signed-off-by: Laurent Vivier 
---
 configure |   14 ++
 linux-user/main.c |   34 +-
 2 files changed, 15 insertions(+), 33 deletions(-)

diff --git a/configure b/configure
index ad924c4..5e10055 100755
--- a/configure
+++ b/configure
@@ -3150,6 +3150,7 @@ target_dir="$target"
 config_target_mak=$target_dir/config-target.mak
 target_arch2=`echo $target | cut -d '-' -f 1`
 target_bigendian="no"
+target_default_cpu="any"
 
 case "$target_arch2" in
   
armeb|lm32|m68k|microblaze|mips|mipsn32|mips64|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus|xtensaeb)
@@ -3226,11 +3227,13 @@ TARGET_ABI_DIR=""
 case "$target_arch2" in
   i386)
 target_phys_bits=64
+target_default_cpu="qemu32"
   ;;
   x86_64)
 TARGET_BASE_ARCH=i386
 target_phys_bits=64
 target_long_alignment=8
+target_default_cpu="qemu64"
   ;;
   alpha)
 target_phys_bits=64
@@ -3273,12 +3276,14 @@ case "$target_arch2" in
 echo "TARGET_ABI_MIPSO32=y" >> $config_target_mak
 target_nptl="yes"
 target_phys_bits=64
+target_default_cpu="24Kf"
   ;;
   mipsn32|mipsn32el)
 TARGET_ARCH=mipsn32
 TARGET_BASE_ARCH=mips
 echo "TARGET_ABI_MIPSN32=y" >> $config_target_mak
 target_phys_bits=64
+target_default_cpu="20Kc"
   ;;
   mips64|mips64el)
 TARGET_ARCH=mips64
@@ -3286,12 +3291,14 @@ case "$target_arch2" in
 echo "TARGET_ABI_MIPSN64=y" >> $config_target_mak
 target_phys_bits=64
 target_long_alignment=8
+target_default_cpu="20Kc"
   ;;
   ppc)
 gdb_xml_files="power-core.xml power-fpu.xml power-altivec.xml 
power-spe.xml"
 target_phys_bits=32
 target_nptl="yes"
 target_libs_softmmu="$fdt_libs"
+target_default_cpu="750"
   ;;
   ppcemb)
 TARGET_BASE_ARCH=ppc
@@ -3300,6 +3307,7 @@ case "$target_arch2" in
 target_phys_bits=64
 target_nptl="yes"
 target_libs_softmmu="$fdt_libs"
+target_default_cpu="750"
   ;;
   ppc64)
 TARGET_BASE_ARCH=ppc
@@ -3308,6 +3316,7 @@ case "$target_arch2" in
 target_phys_bits=64
 target_long_alignment=8
 target_libs_softmmu="$fdt_libs"
+target_default_cpu="970fx"
   ;;
   ppc64abi32)
 TARGET_ARCH=ppc64
@@ -3317,6 +3326,7 @@ case "$target_arch2" in
 gdb_xml_files="power64-core.xml power-fpu.xml power-altivec.xml 
power-spe.xml"
 target_phys_bits=64
 target_libs_softmmu="$fdt_libs"
+target_default_cpu="750"
   ;;
   sh4|sh4eb)
 TARGET_ARCH=sh4
@@ -3326,11 +3336,13 @@ case "$target_arch2" in
   ;;
   sparc)
 target_phys_bits=64
+target_default_cpu="Fujitsu MB86904"
   ;;
   sparc64)
 TARGET_BASE_ARCH=sparc
 target_phys_bits=64
 target_long_alignment=8
+target_default_cpu="TI UltraSparc II"
   ;;
   sparc32plus)
 TARGET_ARCH=sparc64
@@ -3338,6 +3350,7 @@ case "$target_arch2" in
 TARGET_ABI_DIR=sparc
 echo "TARGET_ABI32=y" >> $config_target_mak
 target_phys_bits=64
+target_default_cpu="Fujitsu MB86904"
   ;;
   s390x)
 target_nptl="yes"
@@ -3360,6 +3373,7 @@ echo "TARGET_SHORT_ALIGNMENT=$target_short_alignment" >> 
$config_target_mak
 echo "TARGET_INT_ALIGNMENT=$target_int_alignment" >> $config_target_mak
 echo "TARGET_LONG_ALIGNMENT=$target_long_alignment" >> $config_target_mak
 echo "TARGET_LLONG_ALIGNMENT=$target_llong_alignment" >> $config_target_mak
+echo "TARGET_DEFAULT_CPU=\"$target_default_cpu\"" >> $config_target_mak
 echo "TARGET_ARCH=$TARGET_ARCH" >> $config_target_mak
 target_arch_name="`echo $TARGET_ARCH | tr '[:lower:]' '[:upper:]'`"
 echo "TARGET_$target_arch_name=y" >> $config_target_mak
diff --git a/linux-user/main.c b/linux-user/main.c
index 89a51d7..40d76b4 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3090,39 +3090,7 @@ int main(int argc, char **argv, char **envp)
 init_paths(interp_prefix);
 
 if (cpu_model == NULL) {
-#if defined(TARGET_I386)
-#ifdef TARGET_X86_64
-cpu_model = "qemu64";
-#else
-cpu_model = "qemu32";
-#endif
-#elif defined(TARGET_ARM)
-cpu_model = "any";
-#elif defined(TARGET_UNICORE32)
-cpu_model = "any";
-#elif defined(TARGET_M68K)
-cpu_model = "any";
-#elif defined(TARGET_SPARC)
-#ifdef TARGET_SPARC64
-cpu_model = "TI UltraSparc II";
-#else
-cpu_model = "Fujitsu MB86904";
-#endif
-#elif defined(TARGET_MIPS)
-#if defined(TARGET_ABI_MIPSN32) || defined(TARGET_ABI_MIPSN64)
-cpu_model = "20Kc";
-#else
-cpu_model = "24Kf";
-#endif
-#elif defined(TARGET_PPC)
-#ifdef TARGET_PPC64
-cpu_model = "970fx";
-#else
-cpu_model = "750";
-#endif
-#else
-cpu_model = "any";
-#endif
+cpu_model = TARGET_DEFAULT_CPU;
 }
 tcg_exec_init(0);
 cpu_exec_init_all();
-- 
1.7.1




[Qemu-devel] [PATCH 4/4] linux-user: define new environment variables

2011-09-18 Thread Laurent Vivier
From: Laurent Vivier 

QEMU_GDB=port allows to define gdb server port to wait on.
QEMU_DEBUG=options allows to activate log file (like -d options)

Signed-off-by: Laurent Vivier 
---
 linux-user/main.c |   14 +++---
 qemu-doc.texi |4 
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 40d76b4..9d161c4 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -2822,8 +2822,10 @@ static void usage(void)
"-strace  log system calls\n"
"\n"
"Environment variables:\n"
-   "QEMU_STRACE   Print system calls and arguments similar to 
the\n"
-   "  'strace' program.  Enable by setting to any 
value.\n"
+   "QEMU_STRACEPrint system calls and arguments similar to 
the\n"
+   "   'strace' program.  Enable by setting to any 
value.\n"
+   "QEMU_DEBUG=options Activate log. Use same options as '-d' 
options\n"
+   "QEMU_GDB=port  Wait gdb connection to port\n"
"You can use -E and -U options to set/unset environment variables\n"
"for target process.  It is possible to provide several variables\n"
"by repeating the option.  For example:\n"
@@ -2879,7 +2881,7 @@ int main(int argc, char **argv, char **envp)
 const char *filename;
 const char *cpu_model;
 const char *log_file = DEBUG_LOGFILE;
-const char *log_mask = NULL;
+const char *log_mask = getenv("QEMU_DEBUG");
 struct target_pt_regs regs1, *regs = ®s1;
 struct image_info info1, *info = &info1;
 struct linux_binprm bprm;
@@ -2926,6 +2928,12 @@ int main(int argc, char **argv, char **envp)
 #if defined(cpudef_setup)
 cpudef_setup(); /* parse cpu definitions in target config file (TBD) */
 #endif
+if (getenv("QEMU_GDB")) {
+  gdbstub_port = atoi(getenv("QEMU_GDB"));
+}
+/* don't propagate QEMU_DEBUG and _GDB to children */
+unsetenv("QEMU_DEBUG");
+unsetenv("QEMU_GDB");
 
 optind = 1;
 for(;;) {
diff --git a/qemu-doc.texi b/qemu-doc.texi
index 31199f6..2193463 100644
--- a/qemu-doc.texi
+++ b/qemu-doc.texi
@@ -2293,6 +2293,10 @@ space emulator hasn't implemented ptrace).  At the 
moment this is
 incomplete.  All system calls that don't have a specific argument
 format are printed with information for six arguments.  Many
 flag-style arguments don't have decoders and will show up as numbers.
+@item QEMU_DEBUG=options
+Activate log. Use same options as '-d' options.
+@item QEMU_GDB=port
+Wait gdb connection to port.
 @end table
 
 @node Other binaries
-- 
1.7.1




Re: [Qemu-devel] [PATCH resend] linux-user: Support the accept4 socketcall

2014-01-06 Thread Laurent Vivier

> Le 6 janvier 2014 à 02:57, André Hentschel  a écrit :
>
>
> From: André Hentschel 
> Cc: Riku Voipio 
> Signed-off-by: André Hentschel 
[...]
> diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
> index cf08db5..b36f99c 100644
> --- a/linux-user/syscall_defs.h
> +++ b/linux-user/syscall_defs.h
> @@ -27,6 +27,9 @@
> #define SOCKOP_getsockopt 15
> #define SOCKOP_sendmsg 16
> #define SOCKOP_recvmsg 17
> +#define SOCKOP_accept4 18
> +#define SOCKOP_recvmmsg 19
> +#define SOCKOP_sendmmsg 20

Don't add these both defines here as they are not used in this patch.

Regards,
Laurent

Re: [Qemu-devel] [PATCH resend] linux-user: Support the accept4 socketcall

2014-01-06 Thread Laurent Vivier

> Le 6 janvier 2014 à 10:14, Peter Maydell  a écrit :
>
>
> On 6 January 2014 08:45, Laurent Vivier  wrote:
> >
> >> Le 6 janvier 2014 à 02:57, André Hentschel  a écrit :
> >> diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
> >> index cf08db5..b36f99c 100644
> >> --- a/linux-user/syscall_defs.h
> >> +++ b/linux-user/syscall_defs.h
> >> @@ -27,6 +27,9 @@
> >> #define SOCKOP_getsockopt 15
> >> #define SOCKOP_sendmsg 16
> >> #define SOCKOP_recvmsg 17
> >> +#define SOCKOP_accept4 18
> >> +#define SOCKOP_recvmmsg 19
> >> +#define SOCKOP_sendmmsg 20
> >
> > Don't add these both defines here as they are not used in this patch.
>
> It doesn't seem that unreasonable to add them. We add things
> to the main syscall number #define list even if we aren't
> actually implementing them, for example.

IMHO, you should not : if you implement these syscalls and then revert this
patch (because it is broken, for instance), you will break the build. The
defines must come with the implementation.

Regards,
Laurent

Re: [Qemu-devel] [PATCH v2] linux-user: Support the accept4 socketcall

2014-01-06 Thread Laurent Vivier

> Le 6 janvier 2014 à 17:15, André Hentschel  a écrit :
>
>
> From: André Hentschel 
> Cc: Riku Voipio 
> Signed-off-by: André Hentschel 
> ---
> See
> https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/net.h
> for the value.
>
> linux-user/syscall.c | 16 
> linux-user/syscall_defs.h | 1 +
> 2 files changed, 17 insertions(+)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index efd1453..1a848a6 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -2245,6 +2245,22 @@ static abi_long do_socketcall(int num, abi_ulong vptr)
> ret = do_accept4(sockfd, target_addr, target_addrlen, 0);
> }
> break;
> + case SOCKOP_accept4:
> + {
> + abi_ulong sockfd;
> + abi_ulong target_addr, target_addrlen;
> + int flags;
> +
> + if (get_user_ual(sockfd, vptr)
> + || get_user_ual(target_addr, vptr + n)
> + || get_user_ual(target_addrlen, vptr + 2 * n)
> + || get_user_ual(flags, vptr + 3 * n)) {

I'm not sure, but I think as get_user_ual() get an abi_ulong, flags should be an
abi_ulong. Peter ?

> + return -TARGET_EFAULT;
> + }
> +
> + ret = do_accept4(sockfd, target_addr, target_addrlen, flags);
> + }
> + break;
> case SOCKOP_getsockname:
> {
> abi_ulong sockfd;
> diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
> index cf08db5..ae30476 100644
> --- a/linux-user/syscall_defs.h
> +++ b/linux-user/syscall_defs.h
> @@ -27,6 +27,7 @@
> #define SOCKOP_getsockopt 15
> #define SOCKOP_sendmsg 16
> #define SOCKOP_recvmsg 17
> +#define SOCKOP_accept4 18
>
> #define IPCOP_semop 1
> #define IPCOP_semget 2
> --
> 1.8.1.2
>
>

Re: [Qemu-devel] [PATCH v3] linux-user: Support the accept4 socketcall

2014-01-07 Thread Laurent Vivier

Le 06/01/2014 20:18, André Hentschel a écrit :

From: André Hentschel 
Cc: Riku Voipio 
Signed-off-by: André Hentschel 


Reviewed-by: Laurent Vivier 



Re: [Qemu-devel] [PATCH 29/51] linux-user: pass correct parameter to do_shmctl()

2014-02-21 Thread Laurent Vivier

> Le 21 février 2014 à 09:17, Michael Roth  a écrit :
>
>
> From: Petar Jovanovic 
>
> Fix shmctl issue by passing correct parameter buf to do_shmctl().
>
> Signed-off-by: Petar Jovanovic 
> Signed-off-by: Riku Voipio 
> (cherry picked from commit a29267846a52b4ca294ba3a962b74b67df7ce6d2)
>
> Signed-off-by: Michael Roth 
> ---
> linux-user/syscall.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index eaaf00d..a3575e7 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -3216,7 +3216,7 @@ static abi_long do_ipc(unsigned int call, int first,
>
> /* IPC_* and SHM_* command values are the same on all linux platforms */
> case IPCOP_shmctl:
> - ret = do_shmctl(first, second, third);
> + ret = do_shmctl(first, second, ptr);
> break;
> default:
> gemu_log("Unsupported ipc call: %d (version %d)\n", call, version);
>

I though this one was already applied :
 


Regards,
Laurent



Re: [Qemu-devel] [PATCH] Update MAINTAINERS

2013-10-02 Thread Laurent Vivier

Le 02/10/2013 20:42, Rob Landley a écrit :

On 10/02/2013 12:09:58 PM, Anthony Liguori wrote:

All of Paul's emails are bouncing and he hasn't been active for
some time.

...

 M68K
-M: Paul Brook 
-S: Odd Fixes
+S: Orphan
 F: target-m68k/
 F: hw/m68k/


Laurent Vivier has an m68k gitorious branch to add the q800 target, 
which I've occasionally tested and would really really like to see 
finished and merged.


Alas, last time I tested it the sucker died during the kernel boot as 
soon as mmu setup tried to enable the page tables. But before that I 
got three lines printk'd!  (Woo! Progress!)
Now, kernel is able to try to load its first userspace process but fails 
in ld.so somewhere when it is trying  to map process memory (another MMU 
bug...)



Still: possible m68k guy? Maybe? If he's interested?


Yes, I can do that. There is not a lot of activity on this, anyway.

Regards,
Laurent




Re: [Qemu-devel] [PATCH 29/43] linux-user: Fix broken m68k signal handling on 64 bit hosts

2015-02-25 Thread Laurent Vivier
Hi,
 
I think you should use abi_long instead of  uint32_t.
 
abi_long has an "aligned" attribute, and on m68k long are aligned on a short
boundary.
 

#ifdef TARGET_M68K
#define ABI_INT_ALIGNMENT 2
#define ABI_LONG_ALIGNMENT 2
#define ABI_LLONG_ALIGNMENT 2
#endif

typedef uint32_t abi_ulong __attribute__((aligned(ABI_LONG_ALIGNMENT)));

Regards,
Laurent

> Le 24 février 2015 à 22:48, Michael Roth  a écrit :
>
>
> From: Peter Maydell 
>
> The m68k signal frame setup code which writes the signal return
> trampoline code to the stack was assuming that a 'long' was 32 bits;
> on 64 bit systems this meant we would end up writing the 32 bit
> (2 insn) trampoline sequence to retaddr+4,retaddr+6 instead of
> the intended retaddr+0,retaddr+2, resulting in a guest crash when
> it tried to execute the invalid zero-bytes at retaddr+0.
> Fix by using uint32_t instead; also use uint16_t rather than short
> for consistency. This fixes bug LP:1404690.
>
> Reported-by: Michel Boaventura
> Signed-off-by: Peter Maydell 
> Signed-off-by: Riku Voipio 
> (cherry picked from commit 1669add752d9f29283f8ebf6a863d7b1e2d0f146)
> Signed-off-by: Michael Roth 
> ---
> linux-user/signal.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/linux-user/signal.c b/linux-user/signal.c
> index e11b208..a324fd1 100644
> --- a/linux-user/signal.c
> +++ b/linux-user/signal.c
> @@ -5091,7 +5091,7 @@ static void setup_frame(int sig, struct target_sigaction
> *ka,
> /* moveq #,d0; trap #0 */
>
> __put_user(0x70004e40 + (TARGET_NR_sigreturn << 16),
> - (long *)(frame->retcode));
> + (uint32_t *)(frame->retcode));
>
> /* Set up to return from userspace */
>
> @@ -5225,8 +5225,8 @@ static void setup_rt_frame(int sig, struct
> target_sigaction *ka,
> /* moveq #,d0; notb d0; trap #0 */
>
> __put_user(0x70004600 + ((TARGET_NR_rt_sigreturn ^ 0xff) << 16),
> - (long *)(frame->retcode + 0));
> - __put_user(0x4e40, (short *)(frame->retcode + 4));
> + (uint32_t *)(frame->retcode + 0));
> + __put_user(0x4e40, (uint16_t *)(frame->retcode + 4));
>
> if (err)
> goto give_sigsegv;
> --
> 1.9.1
>
>

Re: [Qemu-devel] [PATCH 29/43] linux-user: Fix broken m68k signal handling on 64 bit hosts

2015-02-25 Thread Laurent Vivier

> Le 25 février 2015 à 12:28, Peter Maydell  a écrit :
>
>
> On 25 February 2015 at 17:39, Laurent Vivier  wrote:
> > Hi,
> >
> > I think you should use abi_long instead of uint32_t.
> >
> > abi_long has an "aligned" attribute, and on m68k long are aligned on a short
> > boundary.
> >
> >
> > #ifdef TARGET_M68K
> > #define ABI_INT_ALIGNMENT 2
> > #define ABI_LONG_ALIGNMENT 2
> > #define ABI_LLONG_ALIGNMENT 2
> > #endif
> >
> > typedef uint32_t abi_ulong __attribute__((aligned(ABI_LONG_ALIGNMENT)));
>
> In this instance it doesn't matter because get_sigframe() aligns
> the pointer we're going to write the sigframe to, and the elements
> in the struct before retcode[] won't make it worse than 4-aligned,
> I think?

Yes, I agree. But the aim of the abi_* types is to define the target ABI. Thus,
for consistency it should better to use the abi_long (or abi_ulong) instead of
uint32_t.
 
Regards,
Laurent

  1   2   3   4   5   6   7   8   9   10   >