Re: [Qemu-devel] why does qemu i386 userspace emulation crashes when pthread used?

2011-04-22 Thread Yale Zhang
I have found the problem and fix. NEW_STACK_SIZE for clone()  should be
increased from the default 16384 (x86_64) to  256 KiB.

On Tue, Apr 19, 2011 at 6:33 PM, Yale Zhang  wrote:

> Hi. I'm want to run some pthread programs using qemu userspace emulation
> (target=i386, host=x86_64,arm), but see NPTL support isn't supported for the
> i386 target. I have applied a patch from here
> http://patchwork.ozlabs.org/patch/45206/ and used it to run a simple
> pthread fork, join program. The program is able to launch multiple threads,
> but the 1st thread that exits causes the program to crash inside the pthread
> library.
>
> What are the reasons NPTL isn't supported for i386 and was it ever
> supported in the past? I even wrote another simple program that does the
> equivalent, but with using fork(), waitpid() instead of pthread_create(),
> pthread_join(), and it works correctly. This seems to suggest thread local
> storage wasn't implemented correctly?
>
> Thanks,
> Yale
>
>


Re: [Qemu-devel] [OOT] gcc trick to help studying Qemu source

2011-04-22 Thread Mulyadi Santosa
Hi Brad :)

On Fri, Apr 22, 2011 at 14:04, Brad Hards  wrote:
> On Tuesday 19 April 2011 19:07:39 Mulyadi Santosa wrote:
>> Hopefully it's useful for everybody, especially newbie like me.
> I added a note about this to the wiki. Perhaps you may like to expand /
> enhance it:
> http://wiki.qemu.org/Documentation/GettingStartedDevelopers#Getting_to_know_the_code

Thanks a lot! :) Well, so far, the information you put there is
already brief and clear. Along with the explanation in my blog, I
think it's enough by now. But in the future, if I think something
worth to be added, I'll let you now...

-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com



Re: [Qemu-devel] tcg/tcg.c:1892: tcg fatal error

2011-04-22 Thread Igor Kovalenko
On Fri, Apr 22, 2011 at 2:39 AM, Laurent Desnogues
 wrote:
> On Thu, Apr 21, 2011 at 9:45 PM, Igor Kovalenko
>  wrote:
>> On Thu, Apr 21, 2011 at 7:44 PM, Laurent Desnogues
>>  wrote:
>>> On Thu, Apr 21, 2011 at 4:57 PM, Artyom Tarasenko  
>>> wrote:
 On Tue, Apr 12, 2011 at 4:14 AM, Igor Kovalenko
  wrote:
>>> Do you have public test case?
>>> It is possible to code this delay slot write test but real issue may
>>> be corruption elsewhere.

 The test case is trivial: it's just the two instructions, branch and wrpr.

> In theory there could be multiple issues including compiler induced ones.
> I'd prefer to see some kind of reproducible testcase.

 Ok, attached a 40 byte long test (the first 32 bytes are not used and
 needed only because the bios entry point is 0x20).

 $ git pull && make && sparc64-softmmu/qemu-system-sparc64 -bios
 test-wrpr.bin -nographic
 Already up-to-date.
 make[1]: Nothing to be done for `all'.
 /mnt/terra/projects/vanilla/qemu/tcg/tcg.c:1892: tcg fatal error
 Aborted
>>>
>>> The problem seems to be that wrpr is using a non-local
>>> TCG tmp (cpu_tmp0).
>>
>> Just tried the test case with write to %pil - seems like write itself is OK.
>> The issue appears to be with save_state() call since adding save_state
>> to %pil case provokes the same tcg abort.
>
> The problem is that cpu_tmp0, not being a local tmp, doesn't
> need to be saved across helper calls.  This results in the
> TCG "optimizer" getting rid of it even though it's later used.
> Look at the log and you'll see what I mean :-)

I'm not very comfortable with tcg yet. Would it be possible to teach
optimizer working with delay slots? Or do I look in the wrong place.

-- 
Kind regards,
Igor V. Kovalenko



[Qemu-devel] [PATCH] net/socket: remove hardcoded packet size in favor of new mtu parameter

2011-04-22 Thread Nguyễn Thái Ngọc Duy
Also mention the default value 4096.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 free new buffers in net_socket_cleanup()

 net.c   |4 
 net/socket.c|   52 
 qemu-options.hx |   11 ++-
 3 files changed, 46 insertions(+), 21 deletions(-)

diff --git a/net.c b/net.c
index 8d6a555..6746bc7 100644
--- a/net.c
+++ b/net.c
@@ -1001,6 +1001,10 @@ static const struct {
 .name = "localaddr",
 .type = QEMU_OPT_STRING,
 .help = "source address for multicast packets",
+}, {
+.name = "mtu",
+.type = QEMU_OPT_NUMBER,
+.help = "MTU size",
 },
 { /* end of list */ }
 },
diff --git a/net/socket.c b/net/socket.c
index 7337f4f..e932064 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -38,7 +38,8 @@ typedef struct NetSocketState {
 int state; /* 0 = getting length, 1 = getting data */
 unsigned int index;
 unsigned int packet_len;
-uint8_t buf[4096];
+unsigned int mtu;
+uint8_t *buf, *buf1;
 struct sockaddr_in dgram_dst; /* contains inet host and port destination 
iff connectionless (SOCK_DGRAM) */
 } NetSocketState;
 
@@ -47,6 +48,7 @@ typedef struct NetSocketListenState {
 char *model;
 char *name;
 int fd;
+unsigned int mtu;
 } NetSocketListenState;
 
 /* XXX: we consider we can send the whole packet without blocking */
@@ -73,10 +75,10 @@ static void net_socket_send(void *opaque)
 NetSocketState *s = opaque;
 int size, err;
 unsigned l;
-uint8_t buf1[4096];
+uint8_t *buf1 = s->buf1;
 const uint8_t *buf;
 
-size = recv(s->fd, (void *)buf1, sizeof(buf1), 0);
+size = recv(s->fd, (void *)buf1, s->mtu, 0);
 if (size < 0) {
 err = socket_error();
 if (err != EWOULDBLOCK)
@@ -111,7 +113,7 @@ static void net_socket_send(void *opaque)
 l = s->packet_len - s->index;
 if (l > size)
 l = size;
-if (s->index + l <= sizeof(s->buf)) {
+if (s->index + l <= s->mtu) {
 memcpy(s->buf + s->index, buf, l);
 } else {
 fprintf(stderr, "serious error: oversized packet received,"
@@ -138,7 +140,7 @@ static void net_socket_send_dgram(void *opaque)
 NetSocketState *s = opaque;
 int size;
 
-size = recv(s->fd, (void *)s->buf, sizeof(s->buf), 0);
+size = recv(s->fd, (void *)s->buf, s->mtu, 0);
 if (size < 0)
 return;
 if (size == 0) {
@@ -228,6 +230,8 @@ static void net_socket_cleanup(VLANClientState *nc)
 NetSocketState *s = DO_UPCAST(NetSocketState, nc, nc);
 qemu_set_fd_handler(s->fd, NULL, NULL, NULL);
 close(s->fd);
+qemu_free(s->buf);
+qemu_free(s->buf1);
 }
 
 static NetClientInfo net_dgram_socket_info = {
@@ -238,6 +242,7 @@ static NetClientInfo net_dgram_socket_info = {
 };
 
 static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
+unsigned int mtu,
 const char *model,
 const char *name,
 int fd, int is_connected)
@@ -288,6 +293,10 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState 
*vlan,
 
 s = DO_UPCAST(NetSocketState, nc, nc);
 
+s->mtu = mtu;
+s->buf = qemu_malloc(s->mtu);
+s->buf1 = qemu_malloc(s->mtu);
+
 s->fd = fd;
 
 qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s);
@@ -312,6 +321,7 @@ static NetClientInfo net_socket_info = {
 };
 
 static NetSocketState *net_socket_fd_init_stream(VLANState *vlan,
+ unsigned int mtu,
  const char *model,
  const char *name,
  int fd, int is_connected)
@@ -325,6 +335,10 @@ static NetSocketState *net_socket_fd_init_stream(VLANState 
*vlan,
 
 s = DO_UPCAST(NetSocketState, nc, nc);
 
+s->mtu = mtu;
+s->buf = qemu_malloc(s->mtu);
+s->buf1 = qemu_malloc(s->mtu);
+
 s->fd = fd;
 
 if (is_connected) {
@@ -335,7 +349,7 @@ static NetSocketState *net_socket_fd_init_stream(VLANState 
*vlan,
 return s;
 }
 
-static NetSocketState *net_socket_fd_init(VLANState *vlan,
+static NetSocketState *net_socket_fd_init(VLANState *vlan, unsigned int mtu,
   const char *model, const char *name,
   int fd, int is_connected)
 {
@@ -348,13 +362,13 @@ static NetSocketState *net_socket_fd_init(VLANState *vlan,
 }
 switch(so_type) {
 case SOCK_DGRAM:
-return net_socket_fd_init_dgram(vlan, model, name, fd, is_connected);
+return net_socket_fd_init_dgram(vlan, mtu, model, name, fd, 
is_connected);
 

[Qemu-devel] [PATCH] char: Allow devices to use a single multiplexed chardev.

2011-04-22 Thread Kusanagi Kouichi
This fixes regression caused by commit
2d6c1ef40f3678ab47a4d14fb5dadaa486bfcda6
("char: Prevent multiple devices opening same chardev").

Signed-off-by: Kusanagi Kouichi 
---
 hw/qdev-properties.c |4 ++--
 qemu-char.c  |5 -
 qemu-char.h  |2 +-
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 1088a26..0eed712 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -354,10 +354,10 @@ static int parse_chr(DeviceState *dev, Property *prop, 
const char *str)
 if (*ptr == NULL) {
 return -ENOENT;
 }
-if ((*ptr)->assigned) {
+if ((*ptr)->avail < 1) {
 return -EEXIST;
 }
-(*ptr)->assigned = 1;
+--(*ptr)->avail;
 return 0;
 }
 
diff --git a/qemu-char.c b/qemu-char.c
index 03858d4..f08f2b8 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -199,7 +199,7 @@ void qemu_chr_add_handlers(CharDriverState *s,
 {
 if (!opaque) {
 /* chr driver being released. */
-s->assigned = 0;
+++s->avail;
 }
 s->chr_can_read = fd_can_read;
 s->chr_read = fd_read;
@@ -2544,7 +2544,10 @@ CharDriverState *qemu_chr_open_opts(QemuOpts *opts,
 snprintf(base->label, len, "%s-base", qemu_opts_id(opts));
 chr = qemu_chr_open_mux(base);
 chr->filename = base->filename;
+chr->avail = MAX_MUX;
 QTAILQ_INSERT_TAIL(&chardevs, chr, next);
+} else {
+chr->avail = 1;
 }
 chr->label = qemu_strdup(qemu_opts_id(opts));
 return chr;
diff --git a/qemu-char.h b/qemu-char.h
index fb96eef..ebf3641 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -70,7 +70,7 @@ struct CharDriverState {
 char *label;
 char *filename;
 int opened;
-int assigned; /* chardev assigned to a device */
+int avail;
 QTAILQ_ENTRY(CharDriverState) next;
 };
 
-- 
1.7.4.4




Re: [Qemu-devel] [PATCH v2] qemu-img: Initial progress printing support

2011-04-22 Thread Paolo Bonzini

On 04/01/2011 04:58 PM, Stefan Hajnoczi wrote:

On Fri, Apr 1, 2011 at 2:41 PM, Jes Sorensen  wrote:

On 03/31/11 13:49, Stefan Hajnoczi wrote:

On Thu, Mar 31, 2011 at 12:38 PM, Kevin Wolf  wrote:

Am 31.03.2011 13:15, schrieb Jes Sorensen:

On 03/31/11 12:38, Kevin Wolf wrote:
I have been a little reluctant to do this because it will break the ABI
for tools running qemu-img from a GUI etc.


That's the reason for the "from a terminal" part. If we check for
isatty(), we should handle these cases just fine.


Yes, I think checking for a tty is enough precaution and allows users
to get the benefit of the progress bar.  TBH I'd probably forget to
add -p half the time :).


Ok, this is fine with me - however how do you suggest we offer the
option to disable it on the command line, an additional flag?


If you also check stdout/stderr for isatty (probably the progress output 
should go to stderr), "> /dev/null" is enough.


Paolo



Re: [Qemu-devel] [RFC][PATCH v2 15/17] guest agent: qemu-ga daemon

2011-04-22 Thread Jes Sorensen
On 04/22/11 11:23, Ian Molton wrote:
> On Thu, 2011-04-21 at 08:21 -0500, Michael Roth wrote:
 +switch (level&  G_LOG_LEVEL_MASK) {
 +case G_LOG_LEVEL_ERROR: return "error";
 +case G_LOG_LEVEL_CRITICAL:  return "critical";
 +case G_LOG_LEVEL_WARNING:   return "warning";
 +case G_LOG_LEVEL_MESSAGE:   return "message";
 +case G_LOG_LEVEL_INFO:  return "info";
 +case G_LOG_LEVEL_DEBUG: return "debug";
 +default:return "user";
 +}
>>>
>>> Urgh!
>>>
>>> No two statements on the same line please!
> 
> Always wondered what the logic for this one is. IMHO the above is FAR
> neater than splitting it to near double its height.
> 
> What kind of coding error does splitting this out aim to prevent?
> missing break; / return; statements? Because I dont see how it achieves
> that...

Hiding things you miss when reading the code, it's a classic for people
to do if(foo) bleh(); on the same line, and whoever reads the code will
expect the action on the next line, especially if foo is a long complex
statement.

It's one of these 'just don't do it, it bites you in the end' things.

Jes



Re: [Qemu-devel] [PATCH] target-arm: Minimal implementation of performance counters

2011-04-22 Thread Brad Hards
On Friday 22 April 2011 19:48:09 Peter Maydell wrote:
> Looking at your .rej file it seems to have lost the hardcoded tab
> characters[*] that are in the patch; I suspect something in your mailer
> is turning them back into spaces. Try downloading the patch from
> patchwork instead.
Yep, that worked. Sorry for the noise.

Brad



Re: [Qemu-devel] [PATCH] target-arm: Minimal implementation of performance counters

2011-04-22 Thread Peter Maydell
On 22 April 2011 08:23, Brad Hards  wrote:
> On Friday 22 April 2011 02:01:48 Peter Maydell wrote:
>> Newer Linux kernels assume the existence of the performance counter
>> cp15 registers. Provide a minimal implementation of these registers.
>> We support no events. This should be compliant with the ARM ARM,
>> except that we don't implement the cycle counter.

> I tried to apply this to git master, and got a reject (attached). It looks
> like that area of target-arm/helper.c hasn't been touched in a while. Is it
> possible you have other changes for this? Did I miss a pre-requisite?

Works for me:
$ git pull
Already up-to-date.
$ git log --oneline -1
ec5 target-arm: Set Invalid flag for NaN in float-to-int conversions
$ wget -O perfcounters.patch http://patchwork.ozlabs.org/patch/92423/mbox/
$ git am perfcounters.patch
Applying: target-arm: Minimal implementation of performance counters
$

Looking at your .rej file it seems to have lost the hardcoded tab
characters[*] that are in the patch; I suspect something in your mailer
is turning them back into spaces. Try downloading the patch from
patchwork instead.

[*] the tab-indents are in the existing code, the patch is removing
them for the lines it touches

-- PMM



Re: [Qemu-devel] [RFC][PATCH v2 15/17] guest agent: qemu-ga daemon

2011-04-22 Thread Ian Molton
On Thu, 2011-04-21 at 08:21 -0500, Michael Roth wrote:
> >> +switch (level&  G_LOG_LEVEL_MASK) {
> >> +case G_LOG_LEVEL_ERROR: return "error";
> >> +case G_LOG_LEVEL_CRITICAL:  return "critical";
> >> +case G_LOG_LEVEL_WARNING:   return "warning";
> >> +case G_LOG_LEVEL_MESSAGE:   return "message";
> >> +case G_LOG_LEVEL_INFO:  return "info";
> >> +case G_LOG_LEVEL_DEBUG: return "debug";
> >> +default:return "user";
> >> +}
> >
> > Urgh!
> >
> > No two statements on the same line please!

Always wondered what the logic for this one is. IMHO the above is FAR
neater than splitting it to near double its height.

What kind of coding error does splitting this out aim to prevent?
missing break; / return; statements? Because I dont see how it achieves
that...





Re: [Qemu-devel] [PATCH] target-arm: Minimal implementation of performance counters

2011-04-22 Thread Brad Hards
On Friday 22 April 2011 02:01:48 Peter Maydell wrote:
> Newer Linux kernels assume the existence of the performance counter
> cp15 registers. Provide a minimal implementation of these registers.
> We support no events. This should be compliant with the ARM ARM,
> except that we don't implement the cycle counter.
I tried to apply this to git master, and got a reject (attached). It looks 
like that area of target-arm/helper.c hasn't been touched in a while. Is it 
possible you have other changes for this? Did I miss a pre-requisite?

Brad



helper.c.rej
Description: application/reject


Re: [Qemu-devel] [OOT] gcc trick to help studying Qemu source

2011-04-22 Thread Brad Hards
On Tuesday 19 April 2011 19:07:39 Mulyadi Santosa wrote:
> Hopefully it's useful for everybody, especially newbie like me.
I added a note about this to the wiki. Perhaps you may like to expand / 
enhance it:
http://wiki.qemu.org/Documentation/GettingStartedDevelopers#Getting_to_know_the_code

Brad