Re: [Qemu-devel] [PULL v2 43/60] i386: drop FDC in pc-q35-2.4+ if neither it nor floppy drives are wanted

2015-06-19 Thread Markus Armbruster
"Michael S. Tsirkin"  writes:

> From: Laszlo Ersek 
>
> It is Very annoying to carry forward an outdatEd coNtroller with a mOdern
> Machine type.
>
> Hence, let us not instantiate the FDC when all of the following apply:
> - the machine type is pc-q35-2.4 or later,
> - "-device isa-fdc" is not passed on the command line (nor in the config
>   file),
> - no "-drive if=floppy,..." is requested.
>
> Cc: Markus Armbruster 
> Cc: Paolo Bonzini 
> Cc: Gerd Hoffmann 
> Cc: John Snow 
> Cc: "Gabriel L. Somlo" 
> Cc: "Michael S. Tsirkin" 
> Cc: Kevin Wolf 
> Cc: qemu-bl...@nongnu.org
> Suggested-by: Markus Armbruster 
> Signed-off-by: Laszlo Ersek 
> Acked-by: Paolo Bonzini 
> Reviewed-by: Michael S. Tsirkin 
> Signed-off-by: Michael S. Tsirkin 
> Reviewed-by: Markus Armbruster 
> ---
>  hw/i386/pc_q35.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
> index 9f036c8..66220b3 100644
> --- a/hw/i386/pc_q35.c
> +++ b/hw/i386/pc_q35.c
> @@ -392,6 +392,7 @@ static void pc_q35_2_4_machine_options(MachineClass *m)
>  pc_q35_machine_options(m);
>  m->default_machine_opts = "firmware=bios-256k.bin";
>  m->default_display = "std";
> +m->no_floppy = 1;
>  m->alias = "q35";
>  }

Botched merge, see [PATCH] q35: Re-enable FDC on pc-q35-2.3 and older.

Your merge is closer to a rewrite than to conflict resolution, rendering
my R-by totally meaningless.

In the future, please either fully test such a merge, or ask the
submitter / reviewers to review and test.

For comparison, this is the patch that got actually reviewed and tested:

diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index ad014e7..671ae69 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -424,7 +424,8 @@ static void pc_q35_init_1_4(MachineState *machine)
 #define PC_Q35_2_4_MACHINE_OPTIONS  \
 PC_Q35_MACHINE_OPTIONS, \
 .default_machine_opts = "firmware=bios-256k.bin",   \
-.default_display = "std"
+.default_display = "std",   \
+.no_floppy = 1
 
 static QEMUMachine pc_q35_machine_v2_4 = {
 PC_Q35_2_4_MACHINE_OPTIONS,
@@ -433,7 +434,10 @@ static QEMUMachine pc_q35_machine_v2_4 = {
 .init = pc_q35_init,
 };
 
-#define PC_Q35_2_3_MACHINE_OPTIONS PC_Q35_2_4_MACHINE_OPTIONS
+#define PC_Q35_2_3_MACHINE_OPTIONS  \
+PC_Q35_MACHINE_OPTIONS, \
+.default_machine_opts = "firmware=bios-256k.bin",   \
+.default_display = "std"
 
 static QEMUMachine pc_q35_machine_v2_3 = {
 PC_Q35_2_3_MACHINE_OPTIONS,



Re: [Qemu-devel] [PATCH v3 00/11] implement dynamic endianness switching

2015-06-19 Thread Paolo Bonzini


On 18/06/2015 22:24, Peter Crosthwaite wrote:
>> >
>> > I'm pushing everything I have to tcg-arm-setend on my github repo.
>> >
> Already found that branch and have rebased it. It looks like since
> yesterday your merge base has changed but is not fully up to date.

Yes, the one before was tested but older.  This one is not tested but
includes the EL2/EL3 chanes.

> I have rebased to the latest. Anything to look out for specifically
> other than than the regime_el change?

I can't think of anything else.

Paolo



Re: [Qemu-devel] m68k orphaned?

2015-06-19 Thread Peter Maydell
On 19 June 2015 at 06:00, Greg Ungerer  wrote:
> Hi All,
>
> I see in the MAINTAINERS file that pretty much everything related
> to the m68k architecture is listed as "Orphan".
>
> I have some patches that have been around for quite a while (posted
> here twice) to fix some issues with the ColdFire support.
> [See https://lists.nongnu.org/archive/html/qemu-devel/2014-08/msg03224.html]
>
> They are still relevant, still apply, and are still needed.
> Does anyone have any suggestions how I can get them pushed into
> mainline qemu?

If you make the minor fixes Peter C has suggested, rebase
them onto current master and resend with the relevant
reviewed-by: tags in the commit messages, I'll apply
them to master.

If you're interested in taking on maintenance of m68k
longer-term we can discuss that, but right now let's
just get the fixes in.

thanks
-- PMM



Re: [Qemu-devel] m68k orphaned?

2015-06-19 Thread Greg Ungerer
Hi Peter,

On 19/06/15 15:53, Peter Crosthwaite wrote:
> On Thu, Jun 18, 2015 at 10:00 PM, Greg Ungerer  wrote:
>> Hi All,
>>
>> I see in the MAINTAINERS file that pretty much everything related
>> to the m68k architecture is listed as "Orphan".
>>
>> I have some patches that have been around for quite a while (posted
>> here twice) to fix some issues with the ColdFire support.
>> [See https://lists.nongnu.org/archive/html/qemu-devel/2014-08/msg03224.html]
>>
> 
> I found a 3 patch series and did a review. I see RTH put and RB to
> patch 2 so I skipped over that.
> 
>> They are still relevant, still apply, and are still needed.
>> Does anyone have any suggestions how I can get them pushed into
>> mainline qemu?
>>
> 
> It suggests that you are the closest thing we have to a maintainer.
> You could try sending a PULL as there is  no submaintainer that is
> going to actively pick this up. The other alternative is the trivial
> patches queue, although they are a little non-trivial due to
> functional change.

Thanks for the advice. Do I send the request to Peter Maydell?

I don't currently have a public git tree for this, can I just
send the patches?  I can always set up a git hub tree if that
is a must.

Regards
Greg





Re: [Qemu-devel] m68k orphaned?

2015-06-19 Thread Greg Ungerer
Hi Peter,

On 19/06/15 17:12, Peter Maydell wrote:
> On 19 June 2015 at 06:00, Greg Ungerer  wrote:
>> Hi All,
>>
>> I see in the MAINTAINERS file that pretty much everything related
>> to the m68k architecture is listed as "Orphan".
>>
>> I have some patches that have been around for quite a while (posted
>> here twice) to fix some issues with the ColdFire support.
>> [See https://lists.nongnu.org/archive/html/qemu-devel/2014-08/msg03224.html]
>>
>> They are still relevant, still apply, and are still needed.
>> Does anyone have any suggestions how I can get them pushed into
>> mainline qemu?
> 
> If you make the minor fixes Peter C has suggested, rebase
> them onto current master and resend with the relevant
> reviewed-by: tags in the commit messages, I'll apply
> them to master.

Thats great, thanks. I'll update them and get them to you.


> If you're interested in taking on maintenance of m68k
> longer-term we can discuss that, but right now let's
> just get the fixes in.

Sounds good, thanks.

Regards
Greg






Re: [Qemu-devel] m68k orphaned?

2015-06-19 Thread Peter Maydell
On 19 June 2015 at 08:17, Greg Ungerer  wrote:
> Hi Peter,
>
> On 19/06/15 17:12, Peter Maydell wrote:
>> If you make the minor fixes Peter C has suggested, rebase
>> them onto current master and resend with the relevant
>> reviewed-by: tags in the commit messages, I'll apply
>> them to master.
>
> Thats great, thanks. I'll update them and get them to you.

I mean "send to the list and cc me", just to be clear.

-- PMM



[Qemu-devel] [PATCH] CODING_STYLE: update line length and mixed declaration rules

2015-06-19 Thread Paolo Bonzini
1) Line lengths above 80 characters do exist.  They are rare, but
they happen from time to time.  An ignored rule is worse than an
exception to the rule, so do the latter.

2) Mixed declarations also do exist at the top of #ifdef blocks.
Remark on this particular usage and suggest an alternative.

Cc: Andreas Faerber 
Cc: Markus Armbruster 
Cc: Eduardo Habkost 
Signed-off-by: Paolo Bonzini 
---
 CODING_STYLE  | 21 -
 scripts/checkpatch.pl |  9 ++---
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/CODING_STYLE b/CODING_STYLE
index d46cfa5..d013cb8 100644
--- a/CODING_STYLE
+++ b/CODING_STYLE
@@ -31,7 +31,11 @@ Do not leave whitespace dangling off the ends of lines.
 
 2. Line width
 
-Lines are 80 characters; not longer.
+Lines should be 80 characters; try not to make them longer.
+
+Sometimes it is hard to do, especially when dealing with QEMU subsystems
+that use long function or symbol names.  Even in that case, do not make
+lines _much_ longer than 80 characters.
 
 Rationale:
  - Some people like to tile their 24" screens with a 6x4 matrix of 80x24
@@ -39,6 +43,8 @@ Rationale:
let them keep doing it.
  - Code and especially patches is much more readable if limited to a sane
line length.  Eighty is traditional.
+ - The four-space indentation makes the most common excuse ("But look
+   at all that white space on the left!") moot.
  - It is the QEMU coding style.
 
 3. Naming
@@ -87,10 +93,15 @@ Furthermore, it is the QEMU coding style.
 
 5. Declarations
 
-Mixed declarations (interleaving statements and declarations within blocks)
-are not allowed; declarations should be at the beginning of blocks.  In other
-words, the code should not generate warnings if using GCC's
--Wdeclaration-after-statement option.
+Mixed declarations (interleaving statements and declarations within
+blocks) are generally not allowed; declarations should be at the beginning
+of blocks.
+
+Every now and then, an exception is made for declarations inside a
+#ifdef or #ifndef block: if the code looks nicer, such declarations can
+be placed at the top of the block even if there are statements above.
+On the other hand, however, it's often best to move that #ifdef/#ifndef
+block to a separate function altogether.
 
 6. Conditional statements
 
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 7f0aae9..f4e7050 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1470,10 +1470,13 @@ sub process {
if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ &&
$rawline !~ /^.\s*\*\s*\@$Ident\s/ &&
!($line =~ 
/^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:,|\)\s*;)\s*$/
 ||
-   $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) &&
-   $length > 80)
+   $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/))
{
-   WARN("line over 80 characters\n" . $herecurr);
+   if ($length > 90) {
+   ERROR("line over 90 characters\n" . $herecurr);
+   } if ($length > 80) {
+   WARN("line over 80 characters\n" . $herecurr);
+   }
}
 
 # check for spaces before a quoted newline
-- 
2.4.3




Re: [Qemu-devel] [RFC PATCH V3] Use atomic cmpxchg to atomically check the exclusive value in a STREX

2015-06-19 Thread Mark Burton

> On 18 Jun 2015, at 21:53, Peter Maydell  wrote:
> 
> On 18 June 2015 at 19:32, Mark Burton  wrote:
>> for the 1<> a little worrying - I’ll check.
>> 
>>> On 18 Jun 2015, at 17:56, Peter Maydell  wrote:
>>> 
>>> On 18 June 2015 at 16:44,   wrote:
 +uint64_t oldval, *p;
 +p = address_space_map(cs->as, paddr, &len, true);
 +if (len == 8 << size) {
 +oldval = (uint64_t)env->exclusive_val;
 +result = (atomic_cmpxchg(p, oldval, (uint64_t)newval) == 
 oldval);
>>> 
>>> You can't do an atomic operation on a type that's larger than
>>> the pointer size of the host system. That means that for
>>> code that isn't host specific, like this, in practice you
>>> can't do an atomic operation on a larger size than 4 bytes.
>>> 
>> 
>> I thought they were polymorphic across all types, I didn’t notice
>> the caveat of the size, sorry about that. That makes things more
>> entertaining :-)
> 
> It's polymorphic across most types... It's been suggested
> that the macros should refuse types with size > ptrsize
> on all systems, so you don't have to get bitten by a
> ppc32 compile failure after the fact, but I don't think that
> anybody's written the patch yet.
> 

That would be sensible.

In the meantime, 
It looks to me like (most implementations of) 32 bit x86 support double word 
cmpxchg - but I dont know if the library uses that, and I’d have to find a 
machine to try it on… 
In any case, we could support that relatively easily it seems.
So, we’re talking about 64bit ARM ldrex/strex, being run, in multi-thread mode, 
on a multi-core 32bit probably non x86 host…..
We can add mutex’s around the ld/strex, and effectively implement the mechanism 
as it is upstream today, (fixing where the address/data is stored). That would 
give some protection, but it would not have the advantage of the atomicity that 
gives us somewhat better protection against a non exclusive store breaking the 
lock.

If we were to do that, we would be saying - on multi-host 32 bit non x86 hosts, 
with a 64 bit multi-core, multi thread arm guest, and a guest that uses normal 
stores to break an exclusive lock, we would have a race condition.

I’m minded to say that we should simply not support that case for now. I 
propose that the multi-thread switch will only allow you to switch into 
multi-thread mode if the maximum cmpxchg that can be supported is the same or 
bigger than the guest ptrsize. 

Does that seem reasonable?

Do you have a better idea?

Does anybody know if the current atomic_cmpxchg will support 64 bit on a 
(normal) 32 bit x86, or do we need to special case that with cmpxchg8b ? (I get 
the impression that it will automatically use cmpxchg8b, but not cmpxchg16b - 
but I’m by no means sure).

Cheers

Mark.


> -- PMM


 +44 (0)20 7100 3485 x 210
 +33 (0)5 33 52 01 77x 210

+33 (0)603762104
mark.burton




Re: [Qemu-devel] [RFC PATCH V3] Use atomic cmpxchg to atomically check the exclusive value in a STREX

2015-06-19 Thread Paolo Bonzini


On 19/06/2015 09:29, Mark Burton wrote:
> Does anybody know if the current atomic_cmpxchg will support 64 bit
> on a (normal) 32 bit x86, or do we need to special case that with
> cmpxchg8b ? (I get the impression that it will automatically use
> cmpxchg8b, but not cmpxchg16b - but I’m by no means sure).

Both cmpxchg8b and cmpxchg16b are used, respectively on 32-bit and
64-bit x86.

Paolo



Re: [Qemu-devel] [PULL 00/10] virtio, pci fixes, enhancements

2015-06-19 Thread Michael S. Tsirkin
On Thu, Jun 18, 2015 at 05:29:23PM +0100, Peter Maydell wrote:
> On 18 June 2015 at 12:14, Michael S. Tsirkin  wrote:
> > On Thu, Jun 18, 2015 at 11:36:26AM +0100, Peter Maydell wrote:
> >> Hi. I'm afraid this fails to build for OSX:
> >>
> >>   LINK  arm-softmmu/qemu-system-arm
> >> Undefined symbols for architecture x86_64:
> >>   "_tap_fd_set_vnet_be", referenced from:
> >>   _tap_set_vnet_be in tap.o
> >>   "_tap_fd_set_vnet_le", referenced from:
> >>   _tap_set_vnet_le in tap.o
> >>
> 
> > Will fix, thanks!
> 
> The updated version of this tag seems to build OK -- did you want me to
> apply it? (Are the differences only trivial?)
> 
> thanks
> -- PMM

They are trivial - a single patch on top that adds stubs for missing
platforms.  And I think breaking bisect on non-linux isn't a big deal.
If you agree, please apply.

-- 
MST



Re: [Qemu-devel] [RFC PATCH V3] Use atomic cmpxchg to atomically check the exclusive value in a STREX

2015-06-19 Thread Mark Burton

> On 19 Jun 2015, at 09:31, Paolo Bonzini  wrote:
> 
> 
> 
> On 19/06/2015 09:29, Mark Burton wrote:
>> Does anybody know if the current atomic_cmpxchg will support 64 bit
>> on a (normal) 32 bit x86, or do we need to special case that with
>> cmpxchg8b ? (I get the impression that it will automatically use
>> cmpxchg8b, but not cmpxchg16b - but I’m by no means sure).
> 
> Both cmpxchg8b and cmpxchg16b are used, respectively on 32-bit and
> 64-bit x86.
> 

Thanks Paolo, so  we are OK for x86, but we would need to disable multi-thread 
for other 32 bit hosts, and provide a correct implementation for non 
multi-thread…
You dont happen to know of a convenient macro we can use to test for ’32 bit 
hosts that dont support 64bit cmpxchg ….’

Cheers

Mark.



> Paolo



 +44 (0)20 7100 3485 x 210
 +33 (0)5 33 52 01 77x 210

+33 (0)603762104
mark.burton




Re: [Qemu-devel] [RFC PATCH V3] Use atomic cmpxchg to atomically check the exclusive value in a STREX

2015-06-19 Thread Paolo Bonzini


On 19/06/2015 09:40, Mark Burton wrote:
>> On 19/06/2015 09:29, Mark Burton wrote:
>>> Does anybody know if the current atomic_cmpxchg will support
>>> 64 bit on a (normal) 32 bit x86, or do we need to special
>>> case that with cmpxchg8b ? (I get the impression that it will
>>> automatically use cmpxchg8b, but not cmpxchg16b - but I’m by
>>> no means sure).
>> 
>> Both cmpxchg8b and cmpxchg16b are used, respectively on 32-bit
>> and 64-bit x86.
> 
> Thanks Paolo, so  we are OK for x86, but we would need to disable
> multi-thread for other 32 bit hosts, and provide a correct
> implementation for non multi-thread…

But Alvise's implementation for example would work there.  It is just
this optimization (that is also not architecturally correct on ARM) that
is problematic.

Paolo

> You dont happen to know of a
> convenient macro we can use to test for ’32 bit hosts that dont
> support 64bit cmpxchg ….’




[Qemu-devel] [PATCH] tap: fix non-linux build

2015-06-19 Thread Michael S. Tsirkin
tap_fd_set_vnet_le/tap_fd_set_vnet_be was missing,
fix it up.

Signed-off-by: Michael S. Tsirkin 
---
 net/tap-aix.c | 10 ++
 net/tap-bsd.c | 10 ++
 net/tap-haiku.c   | 10 ++
 net/tap-solaris.c | 10 ++
 net/tap-win32.c   | 10 ++
 5 files changed, 50 insertions(+)

diff --git a/net/tap-aix.c b/net/tap-aix.c
index 18fdbf3..e84fc39 100644
--- a/net/tap-aix.c
+++ b/net/tap-aix.c
@@ -55,6 +55,16 @@ void tap_fd_set_vnet_hdr_len(int fd, int len)
 {
 }
 
+int tap_fd_set_vnet_le(int fd, int is_le)
+{
+return -EINVAL;
+}
+
+int tap_fd_set_vnet_be(int fd, int is_be)
+{
+return -EINVAL;
+}
+
 void tap_fd_set_offload(int fd, int csum, int tso4,
 int tso6, int ecn, int ufo)
 {
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
index 5889920..7028d9b 100644
--- a/net/tap-bsd.c
+++ b/net/tap-bsd.c
@@ -196,6 +196,16 @@ void tap_fd_set_vnet_hdr_len(int fd, int len)
 {
 }
 
+int tap_fd_set_vnet_le(int fd, int is_le)
+{
+return -EINVAL;
+}
+
+int tap_fd_set_vnet_be(int fd, int is_be)
+{
+return -EINVAL;
+}
+
 void tap_fd_set_offload(int fd, int csum, int tso4,
 int tso6, int ecn, int ufo)
 {
diff --git a/net/tap-haiku.c b/net/tap-haiku.c
index d18590c..2e738ec 100644
--- a/net/tap-haiku.c
+++ b/net/tap-haiku.c
@@ -55,6 +55,16 @@ void tap_fd_set_vnet_hdr_len(int fd, int len)
 {
 }
 
+int tap_fd_set_vnet_le(int fd, int is_le)
+{
+return -EINVAL;
+}
+
+int tap_fd_set_vnet_be(int fd, int is_be)
+{
+return -EINVAL;
+}
+
 void tap_fd_set_offload(int fd, int csum, int tso4,
 int tso6, int ecn, int ufo)
 {
diff --git a/net/tap-solaris.c b/net/tap-solaris.c
index 90b2fd1..0f60f78 100644
--- a/net/tap-solaris.c
+++ b/net/tap-solaris.c
@@ -223,6 +223,16 @@ void tap_fd_set_vnet_hdr_len(int fd, int len)
 {
 }
 
+int tap_fd_set_vnet_le(int fd, int is_le)
+{
+return -EINVAL;
+}
+
+int tap_fd_set_vnet_be(int fd, int is_be)
+{
+return -EINVAL;
+}
+
 void tap_fd_set_offload(int fd, int csum, int tso4,
 int tso6, int ecn, int ufo)
 {
diff --git a/net/tap-win32.c b/net/tap-win32.c
index f6fc961..625d53c 100644
--- a/net/tap-win32.c
+++ b/net/tap-win32.c
@@ -688,6 +688,16 @@ void tap_fd_set_vnet_hdr_len(int fd, int len)
 {
 }
 
+int tap_fd_set_vnet_le(int fd, int is_le)
+{
+return -EINVAL;
+}
+
+int tap_fd_set_vnet_be(int fd, int is_be)
+{
+return -EINVAL;
+}
+
 static void tap_using_vnet_hdr(NetClientState *nc, bool using_vnet_hdr)
 {
 }
-- 
MST



Re: [Qemu-devel] [RFC PATCH V3] Use atomic cmpxchg to atomically check the exclusive value in a STREX

2015-06-19 Thread Mark Burton

> On 19 Jun 2015, at 09:42, Paolo Bonzini  wrote:
> 
> 
> 
> On 19/06/2015 09:40, Mark Burton wrote:
>>> On 19/06/2015 09:29, Mark Burton wrote:
 Does anybody know if the current atomic_cmpxchg will support
 64 bit on a (normal) 32 bit x86, or do we need to special
 case that with cmpxchg8b ? (I get the impression that it will
 automatically use cmpxchg8b, but not cmpxchg16b - but I’m by
 no means sure).
>>> 
>>> Both cmpxchg8b and cmpxchg16b are used, respectively on 32-bit
>>> and 64-bit x86.
>> 
>> Thanks Paolo, so  we are OK for x86, but we would need to disable
>> multi-thread for other 32 bit hosts, and provide a correct
>> implementation for non multi-thread…
> 
> But Alvise's implementation for example would work there.  It is just
> this optimization (that is also not architecturally correct on ARM) that
> is problematic.

Yes, that is exactly correct.
Cheers
Mark.

> 
> Paolo
> 
>> You dont happen to know of a
>> convenient macro we can use to test for ’32 bit hosts that dont
>> support 64bit cmpxchg ….’
> 


 +44 (0)20 7100 3485 x 210
 +33 (0)5 33 52 01 77x 210

+33 (0)603762104
mark.burton




[Qemu-devel] [PULL 06/15] i8254: fix out-of-bounds memory access in pit_ioport_read()

2015-06-19 Thread Paolo Bonzini
From: Petr Matousek 

Due converting PIO to the new memory read/write api we no longer provide
separate I/O region lenghts for read and write operations. As a result,
reading from PIT Mode/Command register will end with accessing
pit->channels with invalid index.

Fix this by ignoring read from the Mode/Command register.

This is CVE-2015-3214.

Reported-by: Matt Tait 
Fixes: 0505bcdec8228d8de39ab1a02644e71999e7c052
Cc: qemu-sta...@nongnu.org
Signed-off-by: Petr Matousek 
Signed-off-by: Paolo Bonzini 
---
 hw/timer/i8254.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/hw/timer/i8254.c b/hw/timer/i8254.c
index 3450c98..9b65a33 100644
--- a/hw/timer/i8254.c
+++ b/hw/timer/i8254.c
@@ -196,6 +196,12 @@ static uint64_t pit_ioport_read(void *opaque, hwaddr addr,
 PITChannelState *s;
 
 addr &= 3;
+
+if (addr == 3) {
+/* Mode/Command register is write only, read is ignored */
+return 0;
+}
+
 s = &pit->channels[addr];
 if (s->status_latched) {
 s->status_latched = 0;
-- 
2.4.3





[Qemu-devel] [PULL 00/15] Timer, virtio-scsi-test, build, memory changes for 2015-06-19

2015-06-19 Thread Paolo Bonzini
The following changes since commit 93f6d1c16036aaf34055d16f54ea770fb8d6d280:

  Merge remote-tracking branch 'remotes/kraxel/tags/pull-vga-20150615-1' into 
staging (2015-06-16 10:35:43 +0100)

are available in the git repository at:

  git://github.com/bonzini/qemu.git tags/for-upstream

for you to fetch changes up to 4e6ab89110c85f7163b875d9e900e97ab0a175b0:

  exec: clamp accesses against the MemoryRegionSection (2015-06-19 09:06:04 
+0200)


* i8254 security fix
* Avoid long 100% CPU wait after restarting guests that use the periodic timer
* Fixes for access clamping (WinXP, MIPS)
* wixl/.msi support for qemu-ga on Windows


Fam Zheng (5):
  tests: Link libqos virtio object to virtio-scsi-test
  libqos: Allow calling guest_free on NULL pointer
  libqos: Complete virtio device ID definition list
  tests: virtio-scsi: Move start/stop to individual test functions
  tests: virtio-scsi: Add test for unaligned WRITE SAME

Paolo Bonzini (2):
  exec: do not clamp accesses to MMIO regions
  exec: clamp accesses against the MemoryRegionSection

Paul Donohue (2):
  qemu-timer: Call clock reset notifiers on forward jumps
  mc146818rtc: Reset the periodic timer on load

Petr Matousek (1):
  i8254: fix out-of-bounds memory access in pit_ioport_read()

Pranith Kumar (1):
  qemu-log: Open file for logging when specified

Yossi Hindin (4):
  qemu-ga: adding vss-[un]install options
  qemu-ga: debug printouts to help troubleshoot installation
  qemu-ga: Introduce Windows MSI script
  qemu-ga: Building Windows MSI installation with configure/Makefile

 Makefile  |  24 +-
 configure |  66 +++
 exec.c|   8 +-
 hw/timer/i8254.c  |   6 ++
 hw/timer/mc146818rtc.c|   6 ++
 include/qemu/timer.h  |   9 +++
 qemu-timer.c  |   2 +-
 qga/channel-win32.c   |   2 +-
 qga/commands-win32.c  |   1 +
 qga/installer/qemu-ga.wxs | 145 +
 qga/main.c|  10 ++-
 tests/Makefile|   2 +-
 tests/libqos/malloc.c |   3 +
 tests/libqos/virtio.h |  10 ++-
 tests/virtio-scsi-test.c  | 201 --
 vl.c  |  13 ++-
 16 files changed, 485 insertions(+), 23 deletions(-)
 create mode 100644 qga/installer/qemu-ga.wxs
-- 
2.4.3




[Qemu-devel] [PULL 09/15] libqos: Complete virtio device ID definition list

2015-06-19 Thread Paolo Bonzini
From: Fam Zheng 

Signed-off-by: Fam Zheng 
Signed-off-by: Paolo Bonzini 
---
 tests/libqos/virtio.h | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h
index 2449fee..0101278 100644
--- a/tests/libqos/virtio.h
+++ b/tests/libqos/virtio.h
@@ -19,8 +19,14 @@
 #define QVIRTIO_DRIVER  0x2
 #define QVIRTIO_DRIVER_OK   0x4
 
-#define QVIRTIO_NET_DEVICE_ID   0x1
-#define QVIRTIO_BLK_DEVICE_ID   0x2
+#define QVIRTIO_NET_DEVICE_ID   0x1
+#define QVIRTIO_BLK_DEVICE_ID   0x2
+#define QVIRTIO_CONSOLE_DEVICE_ID   0x3
+#define QVIRTIO_RNG_DEVICE_ID   0x4
+#define QVIRTIO_BALLOON_DEVICE_ID   0x5
+#define QVIRTIO_RPMSG_DEVICE_ID 0x7
+#define QVIRTIO_SCSI_DEVICE_ID  0x8
+#define QVIRTIO_9P_DEVICE_ID0x9
 
 #define QVIRTIO_F_NOTIFY_ON_EMPTY   0x0100
 #define QVIRTIO_F_ANY_LAYOUT0x0800
-- 
2.4.3





[Qemu-devel] [PULL 07/15] tests: Link libqos virtio object to virtio-scsi-test

2015-06-19 Thread Paolo Bonzini
From: Fam Zheng 

Signed-off-by: Fam Zheng 
Signed-off-by: Paolo Bonzini 
---
 tests/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/Makefile b/tests/Makefile
index c5e4744..9ac7ac2 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -370,7 +370,7 @@ tests/virtio-balloon-test$(EXESUF): 
tests/virtio-balloon-test.o
 tests/virtio-blk-test$(EXESUF): tests/virtio-blk-test.o $(libqos-virtio-obj-y)
 tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o $(libqos-pc-obj-y)
 tests/virtio-rng-test$(EXESUF): tests/virtio-rng-test.o $(libqos-pc-obj-y)
-tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o
+tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o 
$(libqos-virtio-obj-y)
 tests/virtio-9p-test$(EXESUF): tests/virtio-9p-test.o
 tests/virtio-serial-test$(EXESUF): tests/virtio-serial-test.o
 tests/virtio-console-test$(EXESUF): tests/virtio-console-test.o
-- 
2.4.3





[Qemu-devel] [PULL 05/15] qemu-ga: Building Windows MSI installation with configure/Makefile

2015-06-19 Thread Paolo Bonzini
From: Yossi Hindin 

New options were added to enable Windows MSI installation package
creation:

Option --enable-guest-agent-msi, like the name suggests, enables building
Windows MSI package for QEMU guest agent; option --disable-guest-agent-msi
disables MSI package creation; by default, no MSI package is created

Signed-off-by: Yossi Hindin 
Message-Id: <1430913460-13174-5-git-send-email-yhin...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 Makefile  | 24 ++-
 configure | 66 +++
 2 files changed, 89 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 3f97904..e7c5c3a 100644
--- a/Makefile
+++ b/Makefile
@@ -74,7 +74,7 @@ Makefile: ;
 configure: ;
 
 .PHONY: all clean cscope distclean dvi html info install install-doc \
-   pdf recurse-all speed test dist
+   pdf recurse-all speed test dist msi
 
 $(call set-vpath, $(SRC_PATH))
 
@@ -287,10 +287,32 @@ $(qga-obj-y) qemu-ga.o: $(QGALIB_GEN)
 qemu-ga$(EXESUF): $(qga-obj-y) libqemuutil.a libqemustub.a
$(call LINK, $^)
 
+ifdef QEMU_GA_MSI_ENABLED
+QEMU_GA_MSI=qemu-ga-$(ARCH).msi
+
+msi: ${QEMU_GA_MSI}
+
+$(QEMU_GA_MSI): qemu-ga.exe
+
+ifdef QEMU_GA_MSI_WITH_VSS
+$(QEMU_GA_MSI): qga/vss-win32/qga-vss.dll
+endif
+
+$(QEMU_GA_MSI): config-host.mak
+
+$(QEMU_GA_MSI):  qga/installer/qemu-ga.wxs
+   $(call quiet-command,QEMU_GA_VERSION="$(QEMU_GA_VERSION)" 
QEMU_GA_MANUFACTURER="$(QEMU_GA_MANUFACTURER)" 
QEMU_GA_DISTRO="$(QEMU_GA_DISTRO)" \
+   wixl -o $@ $(QEMU_GA_MSI_ARCH) $(QEMU_GA_MSI_WITH_VSS) 
$(QEMU_GA_MSI_MINGW_DLL_PATH) $<, "  WIXL  $@")
+else
+msi:
+   @echo MSI build not configured or dependency resolution failed 
(reconfigure with --enable-guest-agent-msi option)
+endif
+
 clean:
 # avoid old build problems by removing potentially incorrect old files
rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h 
gen-op-arm.h
rm -f qemu-options.def
+   rm -f *.msi
find . \( -name '*.l[oa]' -o -name '*.so' -o -name '*.dll' -o -name 
'*.mo' -o -name '*.[oda]' \) -type f -exec rm {} +
rm -f $(filter-out %.tlb,$(TOOLS)) $(HELPERS-y) qemu-ga TAGS cscope.* 
*.pod *~ */*~
rm -f fsdev/*.pod
diff --git a/configure b/configure
index 222694f..6fed07b 100755
--- a/configure
+++ b/configure
@@ -315,6 +315,7 @@ snappy=""
 bzip2=""
 guest_agent=""
 guest_agent_with_vss="no"
+guest_agent_msi=""
 vss_win32_sdk=""
 win_sdk="no"
 want_tools="yes"
@@ -1078,6 +1079,10 @@ for opt do
   ;;
   --disable-guest-agent) guest_agent="no"
   ;;
+  --enable-guest-agent-msi) guest_agent_msi="yes"
+  ;;
+  --disable-guest-agent-msi) guest_agent_msi="no"
+  ;;
   --with-vss-sdk) vss_win32_sdk=""
   ;;
   --with-vss-sdk=*) vss_win32_sdk="$optarg"
@@ -1394,6 +1399,8 @@ Advanced options (experts only):
reading bzip2-compressed dmg images)
   --disable-guest-agentdisable building of the QEMU Guest Agent
   --enable-guest-agent enable building of the QEMU Guest Agent
+  --enable-guest-agent-msi enable building guest agent Windows MSI 
installation package
+  --disable-guest-agent-msi disable building guest agent Windows MSI 
installation
   --with-vss-sdk=SDK-path  enable Windows VSS support in QEMU Guest Agent
   --with-win-sdk=SDK-path  path to Windows Platform SDK (to build VSS .tlb)
   --disable-seccompdisable seccomp support
@@ -3862,6 +3869,56 @@ if test "$mingw32" = "yes" -a "$guest_agent" != "no" -a 
"$guest_agent_with_vss"
 fi
 
 ##
+# Guest agent Window MSI  package
+
+if test "$guest_agent" != yes; then
+  if test "$guest_agent_msi" = yes; then
+error_exit "MSI guest agent package requires guest agent enabled"
+  fi
+  guest_agent_msi=no
+elif test "$mingw32" != "yes"; then
+  if test "$guest_agent_msi" = "yes"; then
+error_exit "MSI guest agent package is available only for MinGW Windows 
cross-compilation"
+  fi
+  guest_agent_msi=no
+elif ! has wixl; then
+  if test "$guest_agent_msi" = "yes"; then
+error_exit "MSI guest agent package requires wixl tool installed ( usually 
from msitools package )"
+  fi
+  guest_agent_msi=no
+fi
+
+if test "$guest_agent_msi" != "no"; then
+  if test "$guest_agent_with_vss" = "yes"; then
+QEMU_GA_MSI_WITH_VSS="-D InstallVss"
+  fi
+
+  if test "$QEMU_GA_MANUFACTURER" = ""; then
+QEMU_GA_MANUFACTURER=QEMU
+  fi
+
+  if test "$QEMU_GA_DISTRO" = ""; then
+QEMU_GA_DISTRO=Linux
+  fi
+
+  if test "$QEMU_GA_VERSION" = ""; then
+  QEMU_GA_VERSION=`cat $source_path/VERSION`
+  fi
+
+  QEMU_GA_MSI_MINGW_DLL_PATH="-D Mingw_dlls=`$pkg_config --variable=prefix 
glib-2.0`/bin"
+  
+  case "$cpu" in
+  x86_64)
+QEMU_GA_MSI_ARCH="-a x64 -D Arch=64"
+;;
+  i386)
+QEMU_GA_MSI_ARCH="-D Arch=32"
+;;
+  *)
+error_exit "CPU $cpu not supported for building installation package"
+;;
+  esac
+fi
 
 ##
 # check if we have

[Qemu-devel] [PULL 10/15] tests: virtio-scsi: Move start/stop to individual test functions

2015-06-19 Thread Paolo Bonzini
From: Fam Zheng 

Signed-off-by: Fam Zheng 
Signed-off-by: Paolo Bonzini 
---
 tests/virtio-scsi-test.c | 28 ++--
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c
index 989f825..ba119c1 100644
--- a/tests/virtio-scsi-test.c
+++ b/tests/virtio-scsi-test.c
@@ -12,15 +12,36 @@
 #include "libqtest.h"
 #include "qemu/osdep.h"
 
+static void qvirtio_scsi_start(const char *extra_opts)
+{
+char *cmdline;
+
+cmdline = g_strdup_printf(
+"-drive id=drv0,if=none,file=/dev/null,format=raw "
+"-device virtio-scsi-pci,id=vs0 "
+"-device scsi-hd,bus=vs0.0,drive=drv0 %s",
+extra_opts ? : "");
+qtest_start(cmdline);
+g_free(cmdline);
+}
+
+static void qvirtio_scsi_stop(void)
+{
+qtest_end();
+}
+
 /* Tests only initialization so far. TODO: Replace with functional tests */
 static void pci_nop(void)
 {
+qvirtio_scsi_start(NULL);
+qvirtio_scsi_stop();
 }
 
 static void hotplug(void)
 {
 QDict *response;
 
+qvirtio_scsi_start("-drive id=drv1,if=none,file=/dev/null,format=raw");
 response = qmp("{\"execute\": \"device_add\","
" \"arguments\": {"
"   \"driver\": \"scsi-hd\","
@@ -42,6 +63,7 @@ static void hotplug(void)
 g_assert(qdict_haskey(response, "event"));
 g_assert(!strcmp(qdict_get_str(response, "event"), "DEVICE_DELETED"));
 QDECREF(response);
+qvirtio_scsi_stop();
 }
 
 int main(int argc, char **argv)
@@ -52,13 +74,7 @@ int main(int argc, char **argv)
 qtest_add_func("/virtio/scsi/pci/nop", pci_nop);
 qtest_add_func("/virtio/scsi/pci/hotplug", hotplug);
 
-qtest_start("-drive id=drv0,if=none,file=/dev/null,format=raw "
-"-drive id=drv1,if=none,file=/dev/null,format=raw "
-"-device virtio-scsi-pci,id=vscsi0 "
-"-device scsi-hd,bus=vscsi0.0,drive=drv0");
 ret = g_test_run();
 
-qtest_end();
-
 return ret;
 }
-- 
2.4.3





[Qemu-devel] [PULL 01/15] qemu-log: Open file for logging when specified

2015-06-19 Thread Paolo Bonzini
From: Pranith Kumar 

qemu-log defaults to stderr when there is no '-D' option mentioned on command
line. When '-D' option is specified, we also need to specify '-d' option for it
to use the specified logfile. When using monitor to enable logging this is
troublesome since there will be no '-d' option because of which monitor dumps
the logs to stderr.

Fix this by opening the log file when '-D' is specified on the command line.
Also fix an ancient comment which does not hold true since changing location and
log level has now been streamlined.

Signed-off-by: Pranith Kumar 
CC: Paolo Bonzini 
CC: Luiz Capitulino 
CC: Markus Armbruster 
CC: Peter Maydell 
Message-Id: <1433946024-18439-1-git-send-email-bobby.pr...@gmail.com>
Signed-off-by: Paolo Bonzini 
---
 vl.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/vl.c b/vl.c
index 2201e27..63ce07f 100644
--- a/vl.c
+++ b/vl.c
@@ -3916,17 +3916,14 @@ int main(int argc, char **argv, char **envp)
 exit(0);
 }
 
-/* Open the logfile at this point, if necessary. We can't open the logfile
- * when encountering either of the logging options (-d or -D) because the
- * other one may be encountered later on the command line, changing the
- * location or level of logging.
+/* Open the logfile at this point and set the log mask if necessary.
  */
+if (log_file) {
+qemu_set_log_filename(log_file);
+}
+
 if (log_mask) {
 int mask;
-if (log_file) {
-qemu_set_log_filename(log_file);
-}
-
 mask = qemu_str_to_log_mask(log_mask);
 if (!mask) {
 qemu_print_log_usage(stdout);
-- 
2.4.3





[Qemu-devel] [PULL 03/15] qemu-ga: debug printouts to help troubleshoot installation

2015-06-19 Thread Paolo Bonzini
From: Yossi Hindin 

Debug printouts extended, helps installation troubleshooting

Signed-off-by: Yossi Hindin 
Message-Id: <1430913460-13174-3-git-send-email-yhin...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 qga/channel-win32.c  | 2 +-
 qga/commands-win32.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/qga/channel-win32.c b/qga/channel-win32.c
index 0d5e5f5..04fa5e4 100644
--- a/qga/channel-win32.c
+++ b/qga/channel-win32.c
@@ -306,7 +306,7 @@ static gboolean ga_channel_open(GAChannel *c, 
GAChannelMethod method,
OPEN_EXISTING,
FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, 
NULL);
 if (c->handle == INVALID_HANDLE_VALUE) {
-g_critical("error opening path");
+g_critical("error opening path %s", newpath);
 return false;
 }
 
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 3ef0549..d0aaec7 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -721,6 +721,7 @@ GList *ga_command_blacklist_init(GList *blacklist)
 }
 
 if (!vss_init(true)) {
+g_debug("vss_init failed, vss commands are going to be disabled");
 const char *list[] = {
 "guest-get-fsinfo", "guest-fsfreeze-status",
 "guest-fsfreeze-freeze", "guest-fsfreeze-thaw", NULL};
-- 
2.4.3





[Qemu-devel] [PULL 08/15] libqos: Allow calling guest_free on NULL pointer

2015-06-19 Thread Paolo Bonzini
From: Fam Zheng 

Signed-off-by: Fam Zheng 
Reviewed-by: John Snow 
Signed-off-by: Paolo Bonzini 
---
 tests/libqos/malloc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tests/libqos/malloc.c b/tests/libqos/malloc.c
index 8276130..82b9df5 100644
--- a/tests/libqos/malloc.c
+++ b/tests/libqos/malloc.c
@@ -285,6 +285,9 @@ uint64_t guest_alloc(QGuestAllocator *allocator, size_t 
size)
 
 void guest_free(QGuestAllocator *allocator, uint64_t addr)
 {
+if (!addr) {
+return;
+}
 mlist_free(allocator, addr);
 if (allocator->opts & ALLOC_PARANOID) {
 mlist_check(allocator);
-- 
2.4.3





[Qemu-devel] [PULL 14/15] exec: do not clamp accesses to MMIO regions

2015-06-19 Thread Paolo Bonzini
It is common for MMIO registers to overlap, for example a 4 byte register
at 0xcf8 (totally random choice... :)) and a 1 byte register at 0xcf9.
If these registers are implemented via separate MemoryRegions, it is
wrong to clamp the accesses as the value written would be truncated.

Hence for these regions the effects of commit 23820db (exec: Respect
as_translate_internal length clamp, 2015-03-16, previously applied as
commit c3c1bb99) must be skipped.

Tested-by: Hervé Poussineau 
Tested-by: Mark Cave-Ayland 
Signed-off-by: Paolo Bonzini 
---
 exec.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/exec.c b/exec.c
index 76bfc4a..d00e017 100644
--- a/exec.c
+++ b/exec.c
@@ -341,6 +341,7 @@ address_space_translate_internal(AddressSpaceDispatch *d, 
hwaddr addr, hwaddr *x
  hwaddr *plen, bool resolve_subpage)
 {
 MemoryRegionSection *section;
+MemoryRegion *mr;
 Int128 diff;
 
 section = address_space_lookup_region(d, addr, resolve_subpage);
@@ -350,8 +351,11 @@ address_space_translate_internal(AddressSpaceDispatch *d, 
hwaddr addr, hwaddr *x
 /* Compute offset within MemoryRegion */
 *xlat = addr + section->offset_within_region;
 
-diff = int128_sub(section->mr->size, int128_make64(addr));
-*plen = int128_get64(int128_min(diff, int128_make64(*plen)));
+mr = section->mr;
+if (memory_region_is_ram(mr)) {
+diff = int128_sub(mr->size, int128_make64(addr));
+*plen = int128_get64(int128_min(diff, int128_make64(*plen)));
+}
 return section;
 }
 
-- 
2.4.3





[Qemu-devel] [PULL 04/15] qemu-ga: Introduce Windows MSI script

2015-06-19 Thread Paolo Bonzini
From: Yossi Hindin 

The script enables building Windows MSI installation package on Linux with wixl 
tool.

Signed-off-by: Yossi Hindin 
Message-Id: <1430913460-13174-4-git-send-email-yhin...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 qga/installer/qemu-ga.wxs | 145 ++
 1 file changed, 145 insertions(+)
 create mode 100644 qga/installer/qemu-ga.wxs

diff --git a/qga/installer/qemu-ga.wxs b/qga/installer/qemu-ga.wxs
new file mode 100644
index 000..2c43f1b
--- /dev/null
+++ b/qga/installer/qemu-ga.wxs
@@ -0,0 +1,145 @@
+
+http://schemas.microsoft.com/wix/2006/wi";>
+  
+
+  
+
+  
+
+  
+
+  
+
+  
+
+  
+
+  
+
+  
+
+  
+
+
+  
+
+  
+
+  
+
+
+  
+
+  
+
+
+  
+
+  
+
+  
+
+  
+
+NOT VersionNT64
+
+
+
+1
+
+
+  
+
+
+
+  
+
+  
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+  
+
+  
+
+  
+  
+
+  
+
+  
+
+
+
+
+
+
+
+
+
+
+
+  
+  
+
+
+
+  
+  
+  NOT 
Installed
+  Installed
+  
+
+  
+
-- 
2.4.3





[Qemu-devel] [PULL 11/15] tests: virtio-scsi: Add test for unaligned WRITE SAME

2015-06-19 Thread Paolo Bonzini
From: Fam Zheng 

This is an exercise for virtio-scsi tests using the libqos virtio
library. A few common routines are added to facilitate future extensions
of the test set.

The added test case is a regression test for the bug in d7f4b1999e.

Signed-off-by: Fam Zheng 
Signed-off-by: Paolo Bonzini 
---
 tests/virtio-scsi-test.c | 173 +++
 1 file changed, 173 insertions(+)

diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c
index ba119c1..91fdfef 100644
--- a/tests/virtio-scsi-test.c
+++ b/tests/virtio-scsi-test.c
@@ -2,6 +2,7 @@
  * QTest testcase for VirtIO SCSI
  *
  * Copyright (c) 2014 SUSE LINUX Products GmbH
+ * Copyright (c) 2015 Red Hat Inc.
  *
  * This work is licensed under the terms of the GNU GPL, version 2 or later.
  * See the COPYING file in the top-level directory.
@@ -11,6 +12,46 @@
 #include 
 #include "libqtest.h"
 #include "qemu/osdep.h"
+#include 
+#include "libqos/virtio.h"
+#include "libqos/virtio-pci.h"
+#include "libqos/pci-pc.h"
+#include "libqos/malloc.h"
+#include "libqos/malloc-pc.h"
+#include "libqos/malloc-generic.h"
+
+#define PCI_SLOT0x02
+#define PCI_FN  0x00
+#define QVIRTIO_SCSI_TIMEOUT_US (1 * 1000 * 1000)
+#define CDB_SIZE 32
+
+#define MAX_NUM_QUEUES 64
+
+typedef struct {
+QVirtioDevice *dev;
+QGuestAllocator *alloc;
+QPCIBus *bus;
+int num_queues;
+QVirtQueue *vq[MAX_NUM_QUEUES + 2];
+} QVirtIOSCSI;
+
+typedef struct {
+uint8_t lun[8];
+int64_t tag;
+uint8_t task_attr;
+uint8_t prio;
+uint8_t crn;
+uint8_t cdb[CDB_SIZE];
+} QEMU_PACKED QVirtIOSCSICmdReq;
+
+typedef struct {
+uint32_t sense_len;
+uint32_t resid;
+uint16_t status_qualifier;
+uint8_t status;
+uint8_t response;
+uint8_t sense[96];
+} QEMU_PACKED QVirtIOSCSICmdResp;
 
 static void qvirtio_scsi_start(const char *extra_opts)
 {
@@ -30,6 +71,116 @@ static void qvirtio_scsi_stop(void)
 qtest_end();
 }
 
+static QVirtIOSCSI *qvirtio_scsi_pci_init(int slot)
+{
+QVirtIOSCSI *vs;
+QVirtioPCIDevice *dev;
+uint64_t addr;
+int i;
+
+vs = g_new0(QVirtIOSCSI, 1);
+vs->alloc = pc_alloc_init();
+vs->bus = qpci_init_pc();
+
+dev = qvirtio_pci_device_find(vs->bus, QVIRTIO_SCSI_DEVICE_ID);
+vs->dev = (QVirtioDevice *)dev;
+g_assert(dev != NULL);
+g_assert_cmphex(vs->dev->device_type, ==, QVIRTIO_SCSI_DEVICE_ID);
+
+qvirtio_pci_device_enable(dev);
+qvirtio_reset(&qvirtio_pci, vs->dev);
+qvirtio_set_acknowledge(&qvirtio_pci, vs->dev);
+qvirtio_set_driver(&qvirtio_pci, vs->dev);
+
+
+addr = (uint64_t)dev->addr + QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX;
+vs->num_queues = qvirtio_config_readl(&qvirtio_pci, vs->dev, addr);
+
+g_assert_cmpint(vs->num_queues, <, MAX_NUM_QUEUES);
+
+for (i = 0; i < vs->num_queues + 2; i++) {
+vs->vq[i] = qvirtqueue_setup(&qvirtio_pci, vs->dev, vs->alloc, i);
+}
+
+return vs;
+}
+
+static void qvirtio_scsi_pci_free(QVirtIOSCSI *vs)
+{
+int i;
+
+for (i = 0; i < vs->num_queues + 2; i++) {
+guest_free(vs->alloc, vs->vq[i]->desc);
+}
+pc_alloc_uninit(vs->alloc);
+qvirtio_pci_device_disable(container_of(vs->dev, QVirtioPCIDevice, vdev));
+g_free(vs->dev);
+qpci_free_pc(vs->bus);
+}
+
+static uint64_t qvirtio_scsi_alloc(QVirtIOSCSI *vs, size_t alloc_size,
+   const void *data)
+{
+uint64_t addr;
+
+addr = guest_alloc(vs->alloc, alloc_size);
+if (data) {
+memwrite(addr, data, alloc_size);
+}
+
+return addr;
+}
+
+static uint8_t virtio_scsi_do_command(QVirtIOSCSI *vs, const uint8_t *cdb,
+  const uint8_t *data_in,
+  size_t data_in_len,
+  uint8_t *data_out, size_t data_out_len)
+{
+QVirtQueue *vq;
+QVirtIOSCSICmdReq req = { { 0 } };
+QVirtIOSCSICmdResp resp = { .response = 0xff, .status = 0xff };
+uint64_t req_addr, resp_addr, data_in_addr = 0, data_out_addr = 0;
+uint8_t response;
+uint32_t free_head;
+
+vq = vs->vq[2];
+
+req.lun[0] = 1; /* Select LUN */
+req.lun[1] = 1; /* Select target 1 */
+memcpy(req.cdb, cdb, CDB_SIZE);
+
+/* XXX: Fix endian if any multi-byte field in req/resp is used */
+
+/* Add request header */
+req_addr = qvirtio_scsi_alloc(vs, sizeof(req), &req);
+free_head = qvirtqueue_add(vq, req_addr, sizeof(req), false, true);
+
+if (data_out_len) {
+data_out_addr = qvirtio_scsi_alloc(vs, data_out_len, data_out);
+qvirtqueue_add(vq, data_out_addr, data_out_len, false, true);
+}
+
+/* Add response header */
+resp_addr = qvirtio_scsi_alloc(vs, sizeof(resp), &resp);
+qvirtqueue_add(vq, resp_addr, sizeof(resp), true, !!data_in_len);
+
+if (data_in_len) {
+data_in_addr = qvirtio_scsi_alloc(vs, data_in_len, data_in);
+qvirtqueue_add(vq, 

[Qemu-devel] [PULL 15/15] exec: clamp accesses against the MemoryRegionSection

2015-06-19 Thread Paolo Bonzini
Because the clamping was done against the MemoryRegion,
address_space_rw was effectively broken if a write spanned
multiple sections that are not linear in underlying memory
(with the memory not being under an IOMMU).

This is visible with the MIPS rc4030 IOMMU, which is implemented
as a series of alias memory regions that point to the actual RAM.

Tested-by: Hervé Poussineau 
Tested-by: Mark Cave-Ayland 
Signed-off-by: Paolo Bonzini 
---
 exec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/exec.c b/exec.c
index d00e017..f7883d2 100644
--- a/exec.c
+++ b/exec.c
@@ -353,7 +353,7 @@ address_space_translate_internal(AddressSpaceDispatch *d, 
hwaddr addr, hwaddr *x
 
 mr = section->mr;
 if (memory_region_is_ram(mr)) {
-diff = int128_sub(mr->size, int128_make64(addr));
+diff = int128_sub(section->size, int128_make64(addr));
 *plen = int128_get64(int128_min(diff, int128_make64(*plen)));
 }
 return section;
-- 
2.4.3




[Qemu-devel] [PULL 02/15] qemu-ga: adding vss-[un]install options

2015-06-19 Thread Paolo Bonzini
From: Yossi Hindin 

Existing command line options include '-s install' and '-s uninstall'.
These options install/uninstall both Windows QEMU GA service
and optional VSS COM server. The QEMU GA Windows service allows
always-on serving guest agent's QMP commands and VSS COM server
enables guest agent integration with Volume Shadow Service.

This commit introdices new options '-s vss-install' and '-s vss-uninstall',
affecting only GA VSS COM server registration. The new options are useful
for registering and unregistering the COM server during MSI installation,
upgrade and uninstallation.

Signed-off-by: Yossi Hindin 
Message-Id: <1430913460-13174-2-git-send-email-yhin...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 qga/main.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/qga/main.c b/qga/main.c
index 9939a2b..7e1e438 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -211,7 +211,7 @@ static void usage(const char *cmd)
 "  -V, --version print version information and exit\n"
 "  -d, --daemonize   become a daemon\n"
 #ifdef _WIN32
-"  -s, --service service commands: install, uninstall\n"
+"  -s, --service service commands: install, uninstall, vss-install, 
vss-uninstall\n"
 #endif
 "  -b, --blacklist   comma-separated list of RPCs to disable (no spaces, 
\"?\"\n"
 "to list available RPCs)\n"
@@ -1036,6 +1036,14 @@ int main(int argc, char **argv)
 } else if (strcmp(service, "uninstall") == 0) {
 ga_uninstall_vss_provider();
 return ga_uninstall_service();
+} else if (strcmp(service, "vss-install") == 0) {
+if (ga_install_vss_provider()) {
+return EXIT_FAILURE;
+}
+return EXIT_SUCCESS;
+} else if (strcmp(service, "vss-uninstall") == 0) {
+ga_uninstall_vss_provider();
+return EXIT_SUCCESS;
 } else {
 printf("Unknown service command.\n");
 return EXIT_FAILURE;
-- 
2.4.3





Re: [Qemu-devel] [PULL 1/1] virtio-input: evdev passthrough

2015-06-19 Thread Michael S. Tsirkin
On Thu, Jun 18, 2015 at 05:44:48PM +0200, Gerd Hoffmann wrote:
>   Hi,
> 
> > > +static Property virtio_input_host_pci_properties[] = {
> > > +DEFINE_VIRTIO_INPUT_PROPERTIES(VirtIOInputPCI, vdev.input),
> > > +DEFINE_PROP_STRING("evdev", VirtIOInputHostPCI, vdev.evdev),
> > > +DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
> > > +DEFINE_PROP_END_OF_LIST(),
> > > +};
> > > +
> > 
> > Hmm I only noticed this now: I think properties
> > should all move into virtio input, there is
> > no reason to make them pci specific.
> 
> Hmm, looking into this.  Can't figure how this works.  For virtio-net a
> bunch of properties are defined for virtio-net-device.  But they show up
> (using -device $dev,?) on both virtio-net-device and virtio-net-pci.
> 
> Trying to do the same for the (already merged) virtio-input hid devices.
> Not working.  Patch below.  Any clues?
> 
> thanks,
>   Gerd
> 


I think the missing magic is virtio_instance_init_common
which calls qdev_alias_all_properties.


> diff --git a/hw/input/virtio-input-hid.c b/hw/input/virtio-input-hid.c
> index f7c6bc9..55998a2 100644
> --- a/hw/input/virtio-input-hid.c
> +++ b/hw/input/virtio-input-hid.c
> @@ -337,10 +337,17 @@ static void virtio_input_hid_handle_status(VirtIOInput 
> *vinput,
>  }
>  }
>  
> +static Property virtio_input_hid_properties[] = {
> +DEFINE_VIRTIO_INPUT_PROPERTIES(VirtIOInput, input),
> +DEFINE_PROP_END_OF_LIST(),
> +};
> +
>  static void virtio_input_hid_class_init(ObjectClass *klass, void *data)
>  {
> +DeviceClass *dc = DEVICE_CLASS(klass);
>  VirtIOInputClass *vic = VIRTIO_INPUT_CLASS(klass);
>  
> +dc->props  = virtio_input_hid_properties;
>  vic->realize   = virtio_input_hid_realize;
>  vic->unrealize = virtio_input_hid_unrealize;
>  vic->change_active = virtio_input_hid_change_active;
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index 2c053c7..46dc77a 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -1901,7 +1901,6 @@ static const TypeInfo virtio_rng_pci_info = {
>  /* virtio-input-pci */
>  
>  static Property virtio_input_hid_pci_properties[] = {
> -DEFINE_VIRTIO_INPUT_PROPERTIES(VirtIOInputPCI, vdev.input),
>  DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
>  DEFINE_PROP_END_OF_LIST(),
>  };




[Qemu-devel] [PULL 12/15] qemu-timer: Call clock reset notifiers on forward jumps

2015-06-19 Thread Paolo Bonzini
From: Paul Donohue 

Commit 691a0c9c introduced a mechanism by which QEMU_CLOCK_HOST can
notify other parts of the emulator when the host clock has jumped
backward.  This is used to avoid stalling timers that were scheduled
based on the host clock.

However, if the host clock jumps forward, then timers that were
scheduled based on the host clock may fire rapidly and cause other
problems.  For example, the mc146818rtc periodic timer will block
execution of the VM and consume host CPU while firing every interrupt
for the time period that was skipped by the host clock.

To correct that problem, this commit fires the reset notification if the
host clock jumps forward by more than a hard-coded limit.  The limit is
currently set to a value of 60 seconds, which should be small enough to
prevent excessive timer loops, but large enough to avoid frequent resets
in idle VMs.

Signed-off-by: Paul Donohue 
Message-Id: <20150612140845.gd2...@topquark.net>
Signed-off-by: Paolo Bonzini 
---
 include/qemu/timer.h | 9 +
 qemu-timer.c | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index e5bd494..9e4f90f 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -787,6 +787,15 @@ static inline int64_t get_ticks_per_sec(void)
 return 10LL;
 }
 
+static inline int64_t get_max_clock_jump(void)
+{
+/* This should be small enough to prevent excessive interrupts from being
+ * generated by the RTC on clock jumps, but large enough to avoid frequent
+ * unnecessary resets in idle VMs.
+ */
+return 60 * get_ticks_per_sec();
+}
+
 /*
  * Low level clock functions
  */
diff --git a/qemu-timer.c b/qemu-timer.c
index 5741f0d..aa6757e 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -573,7 +573,7 @@ int64_t qemu_clock_get_ns(QEMUClockType type)
 now = get_clock_realtime();
 last = clock->last;
 clock->last = now;
-if (now < last) {
+if (now < last || now > (last + get_max_clock_jump())) {
 notifier_list_notify(&clock->reset_notifiers, &now);
 }
 return now;
-- 
2.4.3





Re: [Qemu-devel] [PATCH] CODING_STYLE: update line length and mixed declaration rules

2015-06-19 Thread Thomas Huth
On Fri, 19 Jun 2015 09:29:04 +0200
Paolo Bonzini  wrote:

> 1) Line lengths above 80 characters do exist.  They are rare, but
> they happen from time to time.  An ignored rule is worse than an
> exception to the rule, so do the latter.
> 
> 2) Mixed declarations also do exist at the top of #ifdef blocks.
> Remark on this particular usage and suggest an alternative.
> 
> Cc: Andreas Faerber 
> Cc: Markus Armbruster 
> Cc: Eduardo Habkost 
> Signed-off-by: Paolo Bonzini 
> ---
>  CODING_STYLE  | 21 -
>  scripts/checkpatch.pl |  9 ++---
>  2 files changed, 22 insertions(+), 8 deletions(-)
> 
> diff --git a/CODING_STYLE b/CODING_STYLE
> index d46cfa5..d013cb8 100644
> --- a/CODING_STYLE
> +++ b/CODING_STYLE
> @@ -31,7 +31,11 @@ Do not leave whitespace dangling off the ends of lines.
>  
>  2. Line width
>  
> -Lines are 80 characters; not longer.
> +Lines should be 80 characters; try not to make them longer.
> +
> +Sometimes it is hard to do, especially when dealing with QEMU subsystems
> +that use long function or symbol names.  Even in that case, do not make
> +lines _much_ longer than 80 characters.

Good idea ... this very, very strict 80 characters limit often drove me
crazy already. If the code is more readable with a 81 or 82 characters
line, that's IMHO a much better way to write code than to break it
artificially just to satisfy that rule.

...
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 7f0aae9..f4e7050 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -1470,10 +1470,13 @@ sub process {
>   if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ &&
>   $rawline !~ /^.\s*\*\s*\@$Ident\s/ &&
>   !($line =~ 
> /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:,|\)\s*;)\s*$/
>  ||
> - $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) &&
> - $length > 80)
> + $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/))
>   {
> - WARN("line over 80 characters\n" . $herecurr);
> + if ($length > 90) {
> + ERROR("line over 90 characters\n" . $herecurr);
> + } if ($length > 80) {

Did you mean to use "elsif" here instead (because you've put the if on
the same line as the "}")?

> + WARN("line over 80 characters\n" . $herecurr);
> + }
>   }
>  

 Thomas



[Qemu-devel] [PULL 13/15] mc146818rtc: Reset the periodic timer on load

2015-06-19 Thread Paolo Bonzini
From: Paul Donohue 

When loading a VM from a snapshot or migration, clock changes can cause
the periodic timer to stall or loop rapidly.

qemu-timer has a reset notifier mechanism that is used to avoid timer
stalls or loops if the host clock changes while the VM is running when
using QEMU_CLOCK_HOST.  However, when loading a snapshot or migration,
qemu-timer is initialized and fires the reset notifier before
mc146818rtc is initialized and has registered its reset handler.  In
addition, this mechanism isn't used when using QEMU_CLOCK_REALTIME,
which might also change when loading a snapshot or migration.

To correct that problem, this commit resets the periodic timer after
loading from a snapshot or migration if the clock has either jumped
backward or has jumped forward by more than the clock jump limit that
is used by the reset notifier code in qemu-timer.

Signed-off-by: Paul Donohue 
Message-Id: <20150612141013.ge2...@topquark.net>
Signed-off-by: Paolo Bonzini 
---
 hw/timer/mc146818rtc.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
index 3204825..2e3ffc8 100644
--- a/hw/timer/mc146818rtc.c
+++ b/hw/timer/mc146818rtc.c
@@ -723,6 +723,12 @@ static int rtc_post_load(void *opaque, int version_id)
 check_update_timer(s);
 }
 
+uint64_t now = qemu_clock_get_ns(rtc_clock);
+if (now < s->next_periodic_time ||
+now > (s->next_periodic_time + get_max_clock_jump())) {
+periodic_timer_update(s, qemu_clock_get_ns(rtc_clock));
+}
+
 #ifdef TARGET_I386
 if (version_id >= 2) {
 if (s->lost_tick_policy == LOST_TICK_POLICY_SLEW) {
-- 
2.4.3





Re: [Qemu-devel] [PATCH] CODING_STYLE: update line length and mixed declaration rules

2015-06-19 Thread Paolo Bonzini


On 19/06/2015 09:53, Thomas Huth wrote:
> > -   WARN("line over 80 characters\n" . $herecurr);
> > +   if ($length > 90) {
> > +   ERROR("line over 90 characters\n" . $herecurr);
> > +   } if ($length > 80) {
> 
> Did you mean to use "elsif" here instead (because you've put the if on
> the same line as the "}")?

Yes, and this patch was really meant as little more than RFC.

Paolo



Re: [Qemu-devel] [PATCH] CODING_STYLE: update line length and mixed declaration rules

2015-06-19 Thread Andreas Färber
Am 19.06.2015 um 09:29 schrieb Paolo Bonzini:
> 1) Line lengths above 80 characters do exist.  They are rare, but
> they happen from time to time.  An ignored rule is worse than an
> exception to the rule, so do the latter.
> 
> 2) Mixed declarations also do exist at the top of #ifdef blocks.
> Remark on this particular usage and suggest an alternative.
> 
> Cc: Andreas Faerber 
> Cc: Markus Armbruster 
> Cc: Eduardo Habkost 
> Signed-off-by: Paolo Bonzini 
> ---
>  CODING_STYLE  | 21 -
>  scripts/checkpatch.pl |  9 ++---
>  2 files changed, 22 insertions(+), 8 deletions(-)
> 
> diff --git a/CODING_STYLE b/CODING_STYLE
> index d46cfa5..d013cb8 100644
> --- a/CODING_STYLE
> +++ b/CODING_STYLE
> @@ -31,7 +31,11 @@ Do not leave whitespace dangling off the ends of lines.
>  
>  2. Line width
>  
> -Lines are 80 characters; not longer.
> +Lines should be 80 characters; try not to make them longer.
> +
> +Sometimes it is hard to do, especially when dealing with QEMU subsystems
> +that use long function or symbol names.  Even in that case, do not make
> +lines _much_ longer than 80 characters.

Anthony had always allowed sensible exceptions to that rule, so +1 for
reformulating it here.

However, I would suggest that in that case we should lower the
recommendation/warning to 78 chars, with the rationale of not only the
actual code but also two-way diffs (79 chars plus +/-/space) and
three-way diffs (78 chars plus 2x +/-/space) fitting into standard 80x24
windows.

Either way, can you please decouple the two changes?

Regards,
Andreas

>  
>  Rationale:
>   - Some people like to tile their 24" screens with a 6x4 matrix of 80x24
> @@ -39,6 +43,8 @@ Rationale:
> let them keep doing it.
>   - Code and especially patches is much more readable if limited to a sane
> line length.  Eighty is traditional.
> + - The four-space indentation makes the most common excuse ("But look
> +   at all that white space on the left!") moot.
>   - It is the QEMU coding style.
>  
>  3. Naming
[snip]

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
21284 (AG Nürnberg)



Re: [Qemu-devel] Adding new migration-parameters - any easier way?

2015-06-19 Thread Markus Armbruster
zhanghailiang  writes:

> Hi,
>
> Is there any news about this discussion?
> Is anyone working on it? ;)
>
> Since the 'hard feature freeze' time is closer, we'd better to fix it in 2.4
> before libvirt uses it.
>
> I have sent a RFC patch "[RFC] migration: Re-implement 
> 'migrate-set-parameters' to make it easily for extension"
> http://patchwork.ozlabs.org/patch/482125/
> Which just changes qmp command to
>  '{ "execute": "migrate-set-parameters" , "arguments":
>  { "compression": { "compress-level": 1 } } }',
> Compared with its original way, it seems to be more easy for reading and 
> extension, but
> it can't address most problems discussed here...

>From a QMP wire protocol point of view, @migrate-set-parameters is just
fine as it is:

#
# @migrate-set-parameters
#
# Set the following migration parameters
#
# @compress-level: compression level
#
# @compress-threads: compression thread count
#
# @decompress-threads: decompression thread count
#
# Since: 2.4
##
{ 'command': 'migrate-set-parameters',
  'data': { '*compress-level': 'int',
'*compress-threads': 'int',
'*decompress-threads': 'int'} }

However, as the number of parameters grows, the generated C interface
becomes more and more unwieldy:

void qmp_migrate_set_parameters(bool has_compress_level,
int64_t compress_level,
bool has_compress_threads,
int64_t compress_threads,
bool has_decompress_threads,
int64_t decompress_threads,
... more ...
Error **errp)

Your [RFC PATCH] hides away some of the parameters in a separate
MigrationCompressParameter (misnamed, should be plural).  Leads to

void qmp_migrate_set_parameters(bool has_compress,
MigrationCompressParameters *compress,
... more ...
Error **errp)

Makes the QMP wire protocol more complex, because now you have to
collect some parameters in extra curlies.

Note the two levels of optionalness: one for the wrapping struct, one
for each of its members.  If you made the members non-optional, we'd
have to specify none or all, which is not what we want.  If you made the
wrapping struct non-optional, you'd have to add a stupid 'compress': {}
when you want to set something else.  So we need both.

In C, the relatively simple test has_compress_level becomes compress &&
compress->has_level.

If we ever want to set migration parameters from the command line, the
nesting will be in the way.  Our tool to parse command line into
QAPI-generated data types (OptsVisitor) by design doesn't cope with
nested structs.

Perhaps the extra complexity is worthwhile, but it's certainly not
obvious.

If all we want is making adding new parameters easier (this thread's
stated subject), then I guess having the function take a single struct
parameter for all its arguments would do:

void qmp_migrate_set_parameters(MigrationParameters *parms,
Error **errp)

To get that from the current QAPI code generator, we'd have to do
something like

{ 'command': 'migrate-set-parameters',
  'data': { 'parms': 'MigrationParameters' } }

Trouble is this messes up the QMP wire interface: you now have to wrap
the actual arguments in two curlies instead of one.

Not a backward-compatibility issue, because the command is new.

Ugly all the same.  

To avoid the ugliness, we could change the QAPI generator.  Currently,

{ 'command': 'migrate-set-parameters',
  'data': 'MigrationParameters' }

generates the same interface as when you inline MigrationParameters,
namely

void qmp_migrate_set_parameters(bool has_compress_level,
int64_t compress_level,
bool has_compress_threads,
int64_t compress_threads,
bool has_decompress_threads,
int64_t decompress_threads,
... more ...
Error **errp)

It could instead generate

void qmp_migrate_set_parameters(MigrationParameters *parms,
Error **errp)

No change to the wire protocol.  Fairly big, but relatively mechanical
change to the handler functions.  I'd be willing to give it a shot and
see how it turns out, but I can't do it for 2.4, sorry.



Re: [Qemu-devel] [PATCH] tap: fix non-linux build

2015-06-19 Thread Thomas Huth
On Fri, 19 Jun 2015 09:44:00 +0200
"Michael S. Tsirkin"  wrote:

> tap_fd_set_vnet_le/tap_fd_set_vnet_be was missing,
> fix it up.
> 
> Signed-off-by: Michael S. Tsirkin 
> ---
>  net/tap-aix.c | 10 ++
>  net/tap-bsd.c | 10 ++
>  net/tap-haiku.c   | 10 ++
>  net/tap-solaris.c | 10 ++
>  net/tap-win32.c   | 10 ++
>  5 files changed, 50 insertions(+)
> 
> diff --git a/net/tap-aix.c b/net/tap-aix.c
> index 18fdbf3..e84fc39 100644
> --- a/net/tap-aix.c
> +++ b/net/tap-aix.c
> @@ -55,6 +55,16 @@ void tap_fd_set_vnet_hdr_len(int fd, int len)
>  {
>  }
>  
> +int tap_fd_set_vnet_le(int fd, int is_le)
> +{
> +return -EINVAL;
> +}
> +
> +int tap_fd_set_vnet_be(int fd, int is_be)
> +{
> +return -EINVAL;
> +}
> +
>  void tap_fd_set_offload(int fd, int csum, int tso4,
>  int tso6, int ecn, int ufo)
>  {
> diff --git a/net/tap-bsd.c b/net/tap-bsd.c
> index 5889920..7028d9b 100644
> --- a/net/tap-bsd.c
> +++ b/net/tap-bsd.c
> @@ -196,6 +196,16 @@ void tap_fd_set_vnet_hdr_len(int fd, int len)
>  {
>  }
>  
> +int tap_fd_set_vnet_le(int fd, int is_le)
> +{
> +return -EINVAL;
> +}
> +
> +int tap_fd_set_vnet_be(int fd, int is_be)
> +{
> +return -EINVAL;
> +}
> +
>  void tap_fd_set_offload(int fd, int csum, int tso4,
>  int tso6, int ecn, int ufo)
>  {
> diff --git a/net/tap-haiku.c b/net/tap-haiku.c
> index d18590c..2e738ec 100644
> --- a/net/tap-haiku.c
> +++ b/net/tap-haiku.c
> @@ -55,6 +55,16 @@ void tap_fd_set_vnet_hdr_len(int fd, int len)
>  {
>  }
>  
> +int tap_fd_set_vnet_le(int fd, int is_le)
> +{
> +return -EINVAL;
> +}
> +
> +int tap_fd_set_vnet_be(int fd, int is_be)
> +{
> +return -EINVAL;
> +}
> +
>  void tap_fd_set_offload(int fd, int csum, int tso4,
>  int tso6, int ecn, int ufo)
>  {
> diff --git a/net/tap-solaris.c b/net/tap-solaris.c
> index 90b2fd1..0f60f78 100644
> --- a/net/tap-solaris.c
> +++ b/net/tap-solaris.c
> @@ -223,6 +223,16 @@ void tap_fd_set_vnet_hdr_len(int fd, int len)
>  {
>  }
>  
> +int tap_fd_set_vnet_le(int fd, int is_le)
> +{
> +return -EINVAL;
> +}
> +
> +int tap_fd_set_vnet_be(int fd, int is_be)
> +{
> +return -EINVAL;
> +}
> +
>  void tap_fd_set_offload(int fd, int csum, int tso4,
>  int tso6, int ecn, int ufo)
>  {
> diff --git a/net/tap-win32.c b/net/tap-win32.c
> index f6fc961..625d53c 100644
> --- a/net/tap-win32.c
> +++ b/net/tap-win32.c
> @@ -688,6 +688,16 @@ void tap_fd_set_vnet_hdr_len(int fd, int len)
>  {
>  }
>  
> +int tap_fd_set_vnet_le(int fd, int is_le)
> +{
> +return -EINVAL;
> +}
> +
> +int tap_fd_set_vnet_be(int fd, int is_be)
> +{
> +return -EINVAL;
> +}
> +
>  static void tap_using_vnet_hdr(NetClientState *nc, bool using_vnet_hdr)
>  {
>  }

Reviewed-by: Thomas Huth 



Re: [Qemu-devel] [PATCH v2 0/3] Fix exceptions handling for MIPS and i386

2015-06-19 Thread Aurelien Jarno
On 2015-06-19 08:09, Pavel Dovgaluk wrote:
> > From: Aurelien Jarno [mailto:aurel...@aurel32.net]
> > On 2015-06-18 12:02, Paolo Bonzini wrote:
> > >
> > > TCG can then use them to fill in an array stored inside the
> > > TranslationBlock, together with the host PC.  Since the gen_opc_pc,
> > > gen_opc_instr_start, gen_opc_icount arrays are inside tcg_ctx, it may be
> > > a good idea to store the checkpoint information compressed in a byte
> > > array (e.g. as a series of ULEB128 values---the host and target PCs can
> > > even be stored as deltas from the last value).
> > 
> > Either as deltas to the last value or as delta from the start of the
> > TB. What I am worried about is the size of the checkpoint information,
> > even if we do some compression, we might have one per guest instruction.
> > I have implemented a naive version of that without compression, storing
> > the checkpoint data at the end of the generated code, and it's about 30%
> > of the size of the TB for MIPS. It's probably smaller on architectures
> > storing only the PC. Also it's size is quite variable. That's why it's
> > probably not a good idea to store it directly in the TranslationBlock.
> > I don't like storing it directly in the generated code either,
> > especially given this part is supposed to be executable.
> > 
> > > As a first step, gen_intermediate_code_pc and tcg_gen_code_search_pc can
> > > then be merged into a single target-independent function that
> > > uncompresses the byte array up to the required host PC into tcg_ctx.
> > > Later you can optimize them to remove the tcg_ctx arrays altogether.
> > >
> > > So the patches could be something like this:
> > >
> > > 1) SPARC: put the jump target information directly in gen_opc_* without
> > > using gen_opc_jump_pc (not trivial)
> > >
> > > 2) a few targets: instead of gen_opc_* arrays, use a new generic member
> > > of tcg_ctx (similar to how csbase is used generically), e.g.
> > > tcg_ctx.gen_opc_target1[] and tcg_ctx.gen_opc_target2[].
> > >
> > > 3) all targets: always fill in tcg_ctx.gen_*, even if search_pc is false
> > >
> > > 4) TCG: add support for a checkpoint operation, make it fill in
> > > tcg_ctx.gen_*
> > >
> > > 5) all targets: change explicit filling of tcg_ctx.gen_* to use the
> > > checkpoint operation
> > >
> > > 6) TCG/translate-all: convert gen_intermediate_code_pc as outlined above
> > 
> > That's sounds like a plan when I have more time ;-)
> 
> Doesn't this approach still require my fixes to work correctly?

Yes it does. 

Aurélien

-- 
Aurelien Jarno  GPG: 4096R/1DDD8C9B
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PULL 00/10] virtio, pci fixes, enhancements

2015-06-19 Thread Peter Maydell
On 19 June 2015 at 08:30, Michael S. Tsirkin  wrote:
> They are trivial - a single patch on top that adds stubs for missing
> platforms.  And I think breaking bisect on non-linux isn't a big deal.
> If you agree, please apply.

I would prefer the fix folded in to the correct point in the
patchset, please. We have the opportunity to avoid breaking
OSX bisection, we should take it.

-- PMM



Re: [Qemu-devel] Greate difference of disk I/O performance for guest on Qemu-2.30 of CentOS.

2015-06-19 Thread Paolo Bonzini


On 19/06/2015 03:03, cauchy-love wrote:
> I have tried your qemu cammand line but got no luck (the embedded os
> have no virtio support but this is not the problem i think). The
> problem probably lies in the host kernel version as it is the only
> difference for my tests. I traced the guest kernel and found the ATA
> drivers always used non-DMA mode (CentOS 7 and CentOS 6.5 are the
> same at this point).

You can use perf to see what's the difference.

Perhaps CentOS 6.5 used ext4 and 7 uses XFS?  Though in general XFS is
the faster one...

Paolo



Re: [Qemu-devel] [PATCH] CODING_STYLE: update line length and mixed declaration rules

2015-06-19 Thread Paolo Bonzini


On 19/06/2015 10:09, Andreas Färber wrote:
>> > -Lines are 80 characters; not longer.
>> > +Lines should be 80 characters; try not to make them longer.
>> > +
>> > +Sometimes it is hard to do, especially when dealing with QEMU subsystems
>> > +that use long function or symbol names.  Even in that case, do not make
>> > +lines _much_ longer than 80 characters.
> Anthony had always allowed sensible exceptions to that rule, so +1 for
> reformulating it here.
> 
> However, I would suggest that in that case we should lower the
> recommendation/warning to 78 chars, with the rationale of not only the
> actual code but also two-way diffs (79 chars plus ±/space) and
> three-way diffs (78 chars plus 2x ±/space) fitting into standard 80x24
> windows.

Good idea.

> Either way, can you please decouple the two changes?

Sure, didn't want to spam people with a series on what is mostly an RFC.

Paolo



[Qemu-devel] [PATCH for-2.4 0/3] virtio-input: property fixes, add passthrough

2015-06-19 Thread Gerd Hoffmann
  Hi,

This little series updates the virtio-input devices to follow latest
practices, so device properties are handled properly.  It also adds
evdev passthrough device for virtio-input (patch has updated property
handling too), and finally a MAINTAINERS entry for virtio-input.

please review,
  Gerd

Gerd Hoffmann (3):
  virtio-input: move properties, use virtio_instance_init_common
  virtio-input: evdev passthrough
  Add MAINTAINERS entry for virtio-input

 MAINTAINERS  |   6 ++
 hw/input/Makefile.objs   |   1 +
 hw/input/virtio-input-host.c | 188 +++
 hw/input/virtio-input.c  |   8 +-
 hw/virtio/virtio-pci.c   |  43 +
 hw/virtio/virtio-pci.h   |  10 +++
 include/hw/virtio/virtio-input.h |  20 +++--
 7 files changed, 252 insertions(+), 24 deletions(-)
 create mode 100644 hw/input/virtio-input-host.c

-- 
1.8.3.1




[Qemu-devel] [PATCH for-2.4 3/3] Add MAINTAINERS entry for virtio-input

2015-06-19 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
---
 MAINTAINERS | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 32c7ca4..9e06082 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -727,6 +727,12 @@ S: Supported
 F: hw/s390x/virtio-ccw.[hc]
 T: git git://github.com/cohuck/qemu virtio-ccw-upstr
 
+virtio-input
+M: Gerd Hoffmann 
+S: Maintained
+F: hw/input/virtio-input*.c
+F: include/hw/virtio/virtio-input.h
+
 virtio-serial
 M: Amit Shah 
 S: Supported
-- 
1.8.3.1




[Qemu-devel] [PATCH for-2.4 1/3] virtio-input: move properties, use virtio_instance_init_common

2015-06-19 Thread Gerd Hoffmann
Move properties from virtio-*-pci to virtio-*-device.
Also make better use of QOM and attach common properties
to the abstract parent classes (virtio-input-device and
virtio-input-pci-device).

Switch the hid device instance init functions over to use
virtio_instance_init_common, so we get the properties of the
virtio device aliased properly to the virtio pci proxy.

Signed-off-by: Gerd Hoffmann 
---
 hw/input/virtio-input.c  |  8 +++-
 hw/virtio/virtio-pci.c   | 27 +++
 include/hw/virtio/virtio-input.h |  9 +
 3 files changed, 19 insertions(+), 25 deletions(-)

diff --git a/hw/input/virtio-input.c b/hw/input/virtio-input.c
index c4f4b3c..7f5b8d6 100644
--- a/hw/input/virtio-input.c
+++ b/hw/input/virtio-input.c
@@ -216,7 +216,7 @@ static void virtio_input_device_realize(DeviceState *dev, 
Error **errp)
 }
 
 virtio_input_idstr_config(vinput, VIRTIO_INPUT_CFG_ID_SERIAL,
-  vinput->input.serial);
+  vinput->serial);
 
 QTAILQ_FOREACH(cfg, &vinput->cfg_list, node) {
 if (vinput->cfg_size < cfg->config.size) {
@@ -248,11 +248,17 @@ static void virtio_input_device_unrealize(DeviceState 
*dev, Error **errp)
 virtio_cleanup(vdev);
 }
 
+static Property virtio_input_properties[] = {
+DEFINE_PROP_STRING("serial", VirtIOInput, serial),
+DEFINE_PROP_END_OF_LIST(),
+};
+
 static void virtio_input_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
 VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
 
+dc->props  = virtio_input_properties;
 set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
 vdc->realize  = virtio_input_device_realize;
 vdc->unrealize= virtio_input_device_unrealize;
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index d7cf34c..1187a58 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1900,8 +1900,7 @@ static const TypeInfo virtio_rng_pci_info = {
 
 /* virtio-input-pci */
 
-static Property virtio_input_hid_pci_properties[] = {
-DEFINE_VIRTIO_INPUT_PROPERTIES(VirtIOInputPCI, vdev.input),
+static Property virtio_input_pci_properties[] = {
 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
 DEFINE_PROP_END_OF_LIST(),
 };
@@ -1924,19 +1923,13 @@ static void virtio_input_pci_class_init(ObjectClass 
*klass, void *data)
 VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
 
+dc->props = virtio_input_pci_properties;
 k->realize = virtio_input_pci_realize;
 set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
 
 pcidev_k->class_id = PCI_CLASS_INPUT_OTHER;
 }
 
-static void virtio_input_hid_pci_class_init(ObjectClass *klass, void *data)
-{
-DeviceClass *dc = DEVICE_CLASS(klass);
-
-dc->props = virtio_input_hid_pci_properties;
-}
-
 static void virtio_input_hid_kbd_pci_class_init(ObjectClass *klass, void *data)
 {
 PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
@@ -1955,22 +1948,25 @@ static void 
virtio_input_hid_mouse_pci_class_init(ObjectClass *klass,
 static void virtio_keyboard_initfn(Object *obj)
 {
 VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
-object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_KEYBOARD);
-object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+
+virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
+TYPE_VIRTIO_KEYBOARD);
 }
 
 static void virtio_mouse_initfn(Object *obj)
 {
 VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
-object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_MOUSE);
-object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+
+virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
+TYPE_VIRTIO_MOUSE);
 }
 
 static void virtio_tablet_initfn(Object *obj)
 {
 VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
-object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_TABLET);
-object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+
+virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
+TYPE_VIRTIO_TABLET);
 }
 
 static const TypeInfo virtio_input_pci_info = {
@@ -1985,7 +1981,6 @@ static const TypeInfo virtio_input_hid_pci_info = {
 .name  = TYPE_VIRTIO_INPUT_HID_PCI,
 .parent= TYPE_VIRTIO_INPUT_PCI,
 .instance_size = sizeof(VirtIOInputHIDPCI),
-.class_init= virtio_input_hid_pci_class_init,
 .abstract  = true,
 };
 
diff --git a/include/hw/virtio/virtio-input.h b/include/hw/virtio/virtio-input.h
index 8134178..8160dd6 100644
--- a/include/hw/virtio/virtio-input.h
+++ b/include/hw/virtio/virtio-input.h
@@ -50,18 +50,11 @@ typedef struct virtio_input_event virtio_input_event;
 #define VIRTIO_INPUT_HID_GET_PARENT_CLASS(obj) \

Re: [Qemu-devel] [PULL 1/1] virtio-input: evdev passthrough

2015-06-19 Thread Gerd Hoffmann
  Hi,

> > Hmm, looking into this.  Can't figure how this works.  For virtio-net a
> > bunch of properties are defined for virtio-net-device.  But they show up
> > (using -device $dev,?) on both virtio-net-device and virtio-net-pci.
> > 
> > Trying to do the same for the (already merged) virtio-input hid devices.
> > Not working.  Patch below.  Any clues?
> > 
> > thanks,
> >   Gerd
> > 
> 
> 
> I think the missing magic is virtio_instance_init_common
> which calls qdev_alias_all_properties.

Yes, that was it.  Figured it meanwhile, new patches just sent to the
list.

cheers,
  Gerd





[Qemu-devel] [PATCH for-2.4 2/3] virtio-input: evdev passthrough

2015-06-19 Thread Gerd Hoffmann
This allows to assign host input devices to the guest:

qemu -device virtio-input-host-pci,evdev=/dev/input/event

The guest gets exclusive access to the input device, so be careful
with assigning the keyboard if you have only one connected to your
machine.

Signed-off-by: Gerd Hoffmann 
---
 hw/input/Makefile.objs   |   1 +
 hw/input/virtio-input-host.c | 188 +++
 hw/virtio/virtio-pci.c   |  16 
 hw/virtio/virtio-pci.h   |  10 +++
 include/hw/virtio/virtio-input.h |  13 +++
 5 files changed, 228 insertions(+)
 create mode 100644 hw/input/virtio-input-host.c

diff --git a/hw/input/Makefile.objs b/hw/input/Makefile.objs
index 0dae710..624ba7e 100644
--- a/hw/input/Makefile.objs
+++ b/hw/input/Makefile.objs
@@ -11,6 +11,7 @@ common-obj-$(CONFIG_VMMOUSE) += vmmouse.o
 ifeq ($(CONFIG_LINUX),y)
 common-obj-$(CONFIG_VIRTIO) += virtio-input.o
 common-obj-$(CONFIG_VIRTIO) += virtio-input-hid.o
+common-obj-$(CONFIG_VIRTIO) += virtio-input-host.o
 endif
 
 obj-$(CONFIG_MILKYMIST) += milkymist-softusb.o
diff --git a/hw/input/virtio-input-host.c b/hw/input/virtio-input-host.c
new file mode 100644
index 000..f7e3d84
--- /dev/null
+++ b/hw/input/virtio-input-host.c
@@ -0,0 +1,188 @@
+/*
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * (at your option) any later version.  See the COPYING file in the
+ * top-level directory.
+ */
+
+#include "qemu-common.h"
+#include "qemu/sockets.h"
+
+#include "hw/qdev.h"
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-input.h"
+
+#include "standard-headers/linux/input.h"
+
+/* - */
+
+static struct virtio_input_config virtio_input_host_config[] = {
+{ /* empty list */ },
+};
+
+static void virtio_input_host_event(void *opaque)
+{
+VirtIOInputHost *vih = opaque;
+VirtIOInput *vinput = VIRTIO_INPUT(vih);
+struct virtio_input_event virtio;
+struct input_event evdev;
+int rc;
+
+for (;;) {
+rc = read(vih->fd, &evdev, sizeof(evdev));
+if (rc != sizeof(evdev)) {
+break;
+}
+
+virtio.type  = cpu_to_le16(evdev.type);
+virtio.code  = cpu_to_le16(evdev.code);
+virtio.value = cpu_to_le32(evdev.value);
+virtio_input_send(vinput, &virtio);
+}
+}
+
+static void virtio_input_bits_config(VirtIOInputHost *vih,
+ int type, int count)
+{
+virtio_input_config bits;
+int rc, i, size = 0;
+
+memset(&bits, 0, sizeof(bits));
+rc = ioctl(vih->fd, EVIOCGBIT(type, count/8), bits.u.bitmap);
+if (rc < 0) {
+return;
+}
+
+for (i = 0; i < count/8; i++) {
+if (bits.u.bitmap[i]) {
+size = i+1;
+}
+}
+if (size == 0) {
+return;
+}
+
+bits.select = VIRTIO_INPUT_CFG_EV_BITS;
+bits.subsel = type;
+bits.size   = size;
+virtio_input_add_config(VIRTIO_INPUT(vih), &bits);
+}
+
+static void virtio_input_host_realize(DeviceState *dev, Error **errp)
+{
+VirtIOInputHost *vih = VIRTIO_INPUT_HOST(dev);
+VirtIOInput *vinput = VIRTIO_INPUT(dev);
+virtio_input_config id;
+struct input_id ids;
+int rc, ver;
+
+if (!vih->evdev) {
+error_setg(errp, "evdev property is required");
+return;
+}
+
+vih->fd = open(vih->evdev, O_RDWR);
+if (vih->fd < 0)  {
+error_setg_file_open(errp, errno, vih->evdev);
+return;
+}
+qemu_set_nonblock(vih->fd);
+
+rc = ioctl(vih->fd, EVIOCGVERSION, &ver);
+if (rc < 0) {
+error_setg(errp, "%s: is not an evdev device", vih->evdev);
+goto err_close;
+}
+
+rc = ioctl(vih->fd, EVIOCGRAB, 1);
+if (rc < 0) {
+error_setg_errno(errp, errno, "%s: failed to get exclusive access",
+ vih->evdev);
+goto err_close;
+}
+
+memset(&id, 0, sizeof(id));
+ioctl(vih->fd, EVIOCGNAME(sizeof(id.u.string)-1), id.u.string);
+id.select = VIRTIO_INPUT_CFG_ID_NAME;
+id.size = strlen(id.u.string);
+virtio_input_add_config(vinput, &id);
+
+if (ioctl(vih->fd, EVIOCGID, &ids) == 0) {
+memset(&id, 0, sizeof(id));
+id.select = VIRTIO_INPUT_CFG_ID_DEVIDS;
+id.size = sizeof(struct virtio_input_devids);
+id.u.ids.bustype = cpu_to_le16(ids.bustype);
+id.u.ids.vendor  = cpu_to_le16(ids.vendor);
+id.u.ids.product = cpu_to_le16(ids.product);
+id.u.ids.version = cpu_to_le16(ids.version);
+virtio_input_add_config(vinput, &id);
+}
+
+virtio_input_bits_config(vih, EV_KEY, KEY_CNT);
+virtio_input_bits_config(vih, EV_REL, REL_CNT);
+virtio_input_bits_config(vih, EV_ABS, ABS_CNT);
+virtio_input_bits_config(vih, EV_MSC, MSC_CNT);
+virtio_input_bits_config(vih, EV_SW,  SW_CNT);
+
+qemu_set_fd_handler(vih->fd, virtio_input_host_event, NULL, vih);
+return;
+
+err_close:
+close(vih->fd);
+  

Re: [Qemu-devel] [PULL v2 00/12] QOM devices patch queue 2015-05-27

2015-06-19 Thread Andreas Färber
Am 28.05.2015 um 13:46 schrieb Peter Maydell:
> On 27 May 2015 at 19:20, Andreas Färber  wrote:
>> Hello Peter,
>>
>> This is my QOM (devices) patch queue. Please pull.
>>
>> v2 contains changes that hopefully fix warnings on gcc 4.7.
> 
> Hi. I'm afraid this doesn't build on our minimum glib version (2.22):
> 
> /Users/pm215/src/qemu/tests/check-qom-proplist.c:235:5: warning: implicit
>   declaration of function 'g_assert_null' is invalid in C99
>   [-Wimplicit-function-declaration]
> g_assert_null(dobj);
> ^
> /Users/pm215/src/qemu/tests/check-qom-proplist.c:236:5: warning: implicit
>   declaration of function 'g_assert_nonnull' is invalid in C99
>   [-Wimplicit-function-declaration]
> g_assert_nonnull(err);
> ^
> 
> g_assert_nonnull() first appears in glib 2.38.

Holy crap... :/

I could've sworn that Anthony did not apply the same minimum-glib
version for make check as for the actual code, and macros should be easy
to add to our glib-compat.h, but let's get this in first and consider
refactorings then.

Unfortunately the pull no longer applies cleanly due to QemuOpts changes
in vl.c, looking into it.

Regards,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
21284 (AG Nürnberg)



Re: [Qemu-devel] [PULL v2 00/12] QOM devices patch queue 2015-05-27

2015-06-19 Thread Peter Maydell
On 19 June 2015 at 09:45, Andreas Färber  wrote:
> Am 28.05.2015 um 13:46 schrieb Peter Maydell:
>> On 27 May 2015 at 19:20, Andreas Färber  wrote:
>>> Hello Peter,
>>>
>>> This is my QOM (devices) patch queue. Please pull.
>>>
>>> v2 contains changes that hopefully fix warnings on gcc 4.7.
>>
>> Hi. I'm afraid this doesn't build on our minimum glib version (2.22):
>>
>> /Users/pm215/src/qemu/tests/check-qom-proplist.c:235:5: warning: implicit
>>   declaration of function 'g_assert_null' is invalid in C99
>>   [-Wimplicit-function-declaration]
>> g_assert_null(dobj);
>> ^
>> /Users/pm215/src/qemu/tests/check-qom-proplist.c:236:5: warning: implicit
>>   declaration of function 'g_assert_nonnull' is invalid in C99
>>   [-Wimplicit-function-declaration]
>> g_assert_nonnull(err);
>> ^
>>
>> g_assert_nonnull() first appears in glib 2.38.
>
> Holy crap... :/
>
> I could've sworn that Anthony did not apply the same minimum-glib
> version for make check as for the actual code

Historically we didn't, because the whole gtester infrastructure
we use wasn't in the ancient glib requirement we had for RHEL5;
so it wasn't practical to insist that test code run on that.
One of the advantages of now using 2.22 as our minimum is that
you can actually run 'make check' on every version of glib we
support (though 2.22 has a signal race in gtester which means you
need to have a little helper script that does a 'killall -CHLD
gtester' every so often to unwedge it...)

Even before we moved to 2.22, I would have spotted and asked
for fixes for failure of "make check" on a 2.22 glib, because
one of my main build-for-pullreqs systems is a 2.22 one.

thanks
-- PMM



Re: [Qemu-devel] [PATCH 5/6] vhost-net: tell tap backend about the vnet endianness

2015-06-19 Thread Thomas Huth

 Hi,

On Wed, 17 Jun 2015 15:23:49 +0200
Greg Kurz  wrote:

> The default behaviour for TAP/MACVTAP is to consider vnet as native endian.
> 
> This patch handles the cases when this is not true:
> - virtio 1.0: always little-endian
> - legacy cross-endian
> 
> Signed-off-by: Greg Kurz 
> ---
>  hw/net/vhost_net.c |   33 -
>  1 file changed, 32 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> index 1c55517e3611..8cbb2f618c1c 100644
> --- a/hw/net/vhost_net.c
> +++ b/hw/net/vhost_net.c
...
> @@ -365,6 +394,8 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState 
> *ncs,
>  fflush(stderr);
>  }
>  assert(r >= 0);
> +
> +assert(vhost_net_set_vnet_endian(dev, ncs[0].peer, false) >= 0);
>  }

Putting the vhost_net_set_vnet_endian() within the assert statement
looks somewhat wrong to me. assert() gets defined to nothing in case
NDEBUG is defined, so the call would then simply be dropped.
I guess you rather want something like this here:

r = vhost_net_set_vnet_endian(dev, ncs[0].peer, false);
assert(r >= 0);

?

 Thomas



Re: [Qemu-devel] [PATCH] tap: fix non-linux build

2015-06-19 Thread Greg Kurz
On Fri, 19 Jun 2015 09:44:00 +0200
"Michael S. Tsirkin"  wrote:
> tap_fd_set_vnet_le/tap_fd_set_vnet_be was missing,
> fix it up.
> 
> Signed-off-by: Michael S. Tsirkin 
> ---
>  net/tap-aix.c | 10 ++
>  net/tap-bsd.c | 10 ++
>  net/tap-haiku.c   | 10 ++
>  net/tap-solaris.c | 10 ++
>  net/tap-win32.c   | 10 ++
>  5 files changed, 50 insertions(+)
> 
> diff --git a/net/tap-aix.c b/net/tap-aix.c
> index 18fdbf3..e84fc39 100644
> --- a/net/tap-aix.c
> +++ b/net/tap-aix.c
> @@ -55,6 +55,16 @@ void tap_fd_set_vnet_hdr_len(int fd, int len)
>  {
>  }
> 
> +int tap_fd_set_vnet_le(int fd, int is_le)
> +{
> +return -EINVAL;
> +}
> +
> +int tap_fd_set_vnet_be(int fd, int is_be)
> +{
> +return -EINVAL;
> +}
> +
>  void tap_fd_set_offload(int fd, int csum, int tso4,
>  int tso6, int ecn, int ufo)
>  {
> diff --git a/net/tap-bsd.c b/net/tap-bsd.c
> index 5889920..7028d9b 100644
> --- a/net/tap-bsd.c
> +++ b/net/tap-bsd.c
> @@ -196,6 +196,16 @@ void tap_fd_set_vnet_hdr_len(int fd, int len)
>  {
>  }
> 
> +int tap_fd_set_vnet_le(int fd, int is_le)
> +{
> +return -EINVAL;
> +}
> +
> +int tap_fd_set_vnet_be(int fd, int is_be)
> +{
> +return -EINVAL;
> +}
> +
>  void tap_fd_set_offload(int fd, int csum, int tso4,
>  int tso6, int ecn, int ufo)
>  {
> diff --git a/net/tap-haiku.c b/net/tap-haiku.c
> index d18590c..2e738ec 100644
> --- a/net/tap-haiku.c
> +++ b/net/tap-haiku.c
> @@ -55,6 +55,16 @@ void tap_fd_set_vnet_hdr_len(int fd, int len)
>  {
>  }
> 
> +int tap_fd_set_vnet_le(int fd, int is_le)
> +{
> +return -EINVAL;
> +}
> +
> +int tap_fd_set_vnet_be(int fd, int is_be)
> +{
> +return -EINVAL;
> +}
> +
>  void tap_fd_set_offload(int fd, int csum, int tso4,
>  int tso6, int ecn, int ufo)
>  {
> diff --git a/net/tap-solaris.c b/net/tap-solaris.c
> index 90b2fd1..0f60f78 100644
> --- a/net/tap-solaris.c
> +++ b/net/tap-solaris.c
> @@ -223,6 +223,16 @@ void tap_fd_set_vnet_hdr_len(int fd, int len)
>  {
>  }
> 
> +int tap_fd_set_vnet_le(int fd, int is_le)
> +{
> +return -EINVAL;
> +}
> +
> +int tap_fd_set_vnet_be(int fd, int is_be)
> +{
> +return -EINVAL;
> +}
> +
>  void tap_fd_set_offload(int fd, int csum, int tso4,
>  int tso6, int ecn, int ufo)
>  {
> diff --git a/net/tap-win32.c b/net/tap-win32.c
> index f6fc961..625d53c 100644
> --- a/net/tap-win32.c
> +++ b/net/tap-win32.c
> @@ -688,6 +688,16 @@ void tap_fd_set_vnet_hdr_len(int fd, int len)
>  {
>  }
> 
> +int tap_fd_set_vnet_le(int fd, int is_le)
> +{
> +return -EINVAL;
> +}
> +
> +int tap_fd_set_vnet_be(int fd, int is_be)
> +{
> +return -EINVAL;
> +}
> +
>  static void tap_using_vnet_hdr(NetClientState *nc, bool using_vnet_hdr)
>  {
>  }

I couldn't setup a build environment on a non-linux platform (tried AIX
but I miss to many packages), so I won't give a Tested-by... patch is trivial
though so:

Reviewed-by: Greg Kurz 




Re: [Qemu-devel] [PATCH] q35: Re-enable FDC on pc-q35-2.3 and older

2015-06-19 Thread Peter Maydell
On 19 June 2015 at 07:43, Markus Armbruster  wrote:
> Laszlo Ersek  writes:
>
>> On 06/18/15 18:49, Eduardo Habkost wrote:
>>> commit ea96bc629cbd52be98b2967a4b4f72e91dfc3ee4 doesn't match the patch
>>> submitted by Laszlo to qemu-devel. We reuse pc_q35_2_4_machine_options()
>>> inside pc_q35_2_3_machine_options(), so we need to undo the no_floppy
>>> change in pc_q35_2_3_machine_options().
>>>
>>> This restores the previous behavior where all the 2.3 and older machines
>>> had no_floppy=0.
>
> Mentioning it was a botched merge, not a review failure wouldn't hurt.
>
>>>
>>> Reported-by: Ján Tomko 
>>> Cc: Laszlo Ersek 
>>> Signed-off-by: Eduardo Habkost 
>>> ---
>>>  hw/i386/pc_q35.c | 1 +
>>>  1 file changed, 1 insertion(+)
>>>
>>> diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
>>> index b68263d..082cd93 100644
>>> --- a/hw/i386/pc_q35.c
>>> +++ b/hw/i386/pc_q35.c
>>> @@ -403,6 +403,7 @@ DEFINE_Q35_MACHINE(v2_4, "pc-q35-2.4", NULL,
>>>  static void pc_q35_2_3_machine_options(MachineClass *m)
>>>  {
>>>  pc_q35_2_4_machine_options(m);
>>> +m->no_floppy = 0;
>>>  m->alias = NULL;
>>>  SET_MACHINE_COMPAT(m, PC_COMPAT_2_3);
>>>  }
>>>
>>
>> Looks good to me, thanks! In fact I'm just learning that under the new
>> "machine type knobs" infrastructure, it's idiomatic to override settings
>> (ie. to assign the same field several times). Resetting m->alias to NULL
>> is an example.
>>
>> Reviewed-by: Laszlo Ersek 
>
> Peter, could you pick this up directly as a regression fix?

Sure; applied to master (with a note about it being a bad merge).

thanks
-- PMM



[Qemu-devel] [PATCH v2 1/1] vvfat: add a label option

2015-06-19 Thread Wolfgang Bumiller
Until now the vvfat volume label was hardcoded to be
"QEMU VVFAT", now you can pass a file.label=labelname option
to the -drive to change it.

The FAT structure defines the volume label to be limited to
11 bytes and is filled up spaces when shorter than that. The
trailing spaces however aren't exposed to the user by
operating systems.

Signed-off-by: Wolfgang Bumiller 
---
 block/vvfat.c| 25 ++---
 qapi/block-core.json |  6 +-
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/block/vvfat.c b/block/vvfat.c
index e803589..1f8a240 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -322,6 +322,7 @@ typedef struct BDRVVVFATState {
 
 int fat_type; /* 16 or 32 */
 array_t fat,directory,mapping;
+char volume_label[11];
 
 unsigned int cluster_size;
 unsigned int sectors_per_cluster;
@@ -859,7 +860,7 @@ static int init_directories(BDRVVVFATState* s,
 {
direntry_t* entry=array_get_next(&(s->directory));
entry->attributes=0x28; /* archive | volume label */
-memcpy(entry->name, "QEMU VVFAT ", sizeof(entry->name));
+memcpy(entry->name, s->volume_label, sizeof(entry->name));
 }
 
 /* Now build FAT, and write back information into directory */
@@ -968,7 +969,8 @@ static int init_directories(BDRVVVFATState* s,
 bootsector->u.fat16.signature=0x29;
 bootsector->u.fat16.id=cpu_to_le32(0xfabe1afd);
 
-memcpy(bootsector->u.fat16.volume_label,"QEMU VVFAT ",11);
+memcpy(bootsector->u.fat16.volume_label, s->volume_label,
+   sizeof(bootsector->u.fat16.volume_label));
 memcpy(bootsector->fat_type,(s->fat_type==12?"FAT12   
":s->fat_type==16?"FAT16   ":"FAT32   "),8);
 bootsector->magic[0]=0x55; bootsector->magic[1]=0xaa;
 
@@ -1008,6 +1010,11 @@ static QemuOptsList runtime_opts = {
 .help = "Create a floppy rather than a hard disk image",
 },
 {
+.name = "label",
+.type = QEMU_OPT_STRING,
+.help = "Use a volume label other than QEMU VVFAT",
+},
+{
 .name = "rw",
 .type = QEMU_OPT_BOOL,
 .help = "Make the image writable",
@@ -1069,7 +1076,7 @@ static int vvfat_open(BlockDriverState *bs, QDict 
*options, int flags,
 BDRVVVFATState *s = bs->opaque;
 int cyls, heads, secs;
 bool floppy;
-const char *dirname;
+const char *dirname, *label;
 QemuOpts *opts;
 Error *local_err = NULL;
 int ret;
@@ -1096,6 +1103,18 @@ static int vvfat_open(BlockDriverState *bs, QDict 
*options, int flags,
 s->fat_type = qemu_opt_get_number(opts, "fat-type", 0);
 floppy = qemu_opt_get_bool(opts, "floppy", false);
 
+memset(s->volume_label, ' ', sizeof(s->volume_label));
+label = qemu_opt_get(opts, "label");
+if (label) {
+size_t label_length = strlen(label);
+if (label_length > 11) {
+error_setg(errp, "vvfat label cannot be longer than 11 bytes");
+ret = -EINVAL;
+goto fail;
+}
+memcpy(s->volume_label, label, label_length);
+}
+
 if (floppy) {
 /* 1.44MB or 2.88MB floppy.  2.88MB can be FAT12 (default) or FAT16. */
 if (!s->fat_type) {
diff --git a/qapi/block-core.json b/qapi/block-core.json
index afa9d3d..feb9e4f 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -1453,13 +1453,17 @@
 # @fat-type:#optional FAT type: 12, 16 or 32
 # @floppy:  #optional whether to export a floppy image (true) or
 #   partitioned hard disk (false; default)
+# @label:   #optional set the volume label, limited to 11 bytes. FAT16 and
+FAT32 traditionally have some restrictions on labels, which are
+ignored by most operating systems. Defaults to "QEMU VVFAT".
+(since 2.4)
 # @rw:  #optional whether to allow write operations (default: false)
 #
 # Since: 1.7
 ##
 { 'struct': 'BlockdevOptionsVVFAT',
   'data': { 'dir': 'str', '*fat-type': 'int', '*floppy': 'bool',
-'*rw': 'bool' } }
+'*label': 'str', '*rw': 'bool' } }
 
 ##
 # @BlockdevOptionsGenericFormat
-- 
2.1.4





[Qemu-devel] [PATCH v2 0/1] vvfat label option updated

2015-06-19 Thread Wolfgang Bumiller
* Till/Until changed
* Added (since 2.4) to json file
* Added the 11-byte limit description. Without mentioning the trailing
  spaces in the json file since the guest OS doesn't expose them to
  the user. However, I mentioned it in the commit message.

The limit comes from the FAT structure, but for completeness' sake I
looked up the FAT descriptions a little more.  Turns out at least
FAT32 labels are "supposed" to be stored with uppercase letters, and
seem to have some theoretical restrictions on the used characters, but
neither linux nor windows guests seem to care on the OS side. And at
least mkfs.vfat's -n option only warns about lowercase letters, but
doesn't error. Theoretically you're also not allowed to start a label
with a space, while mkfs.vfat neither warns nor errors about this.
So I decided to not add any additional checks and only mentioned it in
the json's doc string.

Wolfgang Bumiller (1):
  vvfat: add a label option

 block/vvfat.c| 25 ++---
 qapi/block-core.json |  6 +-
 2 files changed, 27 insertions(+), 4 deletions(-)

-- 
2.1.4





Re: [Qemu-devel] [PATCH v3] cocoa.m: machine menu device menu items

2015-06-19 Thread Peter Maydell
On 15 June 2015 at 02:53, Programmingkid  wrote:
> Adds all removable devices to the Machine menu as a Change and Eject menu
> item pair. ide-cd0 would have a "Change ide-cd0..." and "Eject ide-cd0"
> menu items.
>
> Signed-off-by: John Arbuckle 
>
> ---
> Removed depreciated code from QEMU_Alert().
> Unified supported image file extensions into one array.
> Replaced depreciated filename method for URLs method in NSOpenPanel code.
> Replaced free() with qapi_free_BlockInfoList().

Thanks, applied to cocoa.next.

PS: it would be nice if you could get your mail client to send
plain text patches (ideally, just use git format-patch/git send-email).
Something about this one seems to confuse the "patches" tooling I use
to apply patches, though I think previous patches from you have been OK.

-- PMM



Re: [Qemu-devel] [PATCH 5/6] vhost-net: tell tap backend about the vnet endianness

2015-06-19 Thread Greg Kurz
On Fri, 19 Jun 2015 11:16:35 +0200
Thomas Huth  wrote:

> 
>  Hi,
> 
> On Wed, 17 Jun 2015 15:23:49 +0200
> Greg Kurz  wrote:
> 
> > The default behaviour for TAP/MACVTAP is to consider vnet as native endian.
> > 
> > This patch handles the cases when this is not true:
> > - virtio 1.0: always little-endian
> > - legacy cross-endian
> > 
> > Signed-off-by: Greg Kurz 
> > ---
> >  hw/net/vhost_net.c |   33 -
> >  1 file changed, 32 insertions(+), 1 deletion(-)
> > 
> > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> > index 1c55517e3611..8cbb2f618c1c 100644
> > --- a/hw/net/vhost_net.c
> > +++ b/hw/net/vhost_net.c
> ...
> > @@ -365,6 +394,8 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState 
> > *ncs,
> >  fflush(stderr);
> >  }
> >  assert(r >= 0);
> > +
> > +assert(vhost_net_set_vnet_endian(dev, ncs[0].peer, false) >= 0);
> >  }
> 
> Putting the vhost_net_set_vnet_endian() within the assert statement
> looks somewhat wrong to me. assert() gets defined to nothing in case
> NDEBUG is defined, so the call would then simply be dropped.
> I guess you rather want something like this here:
> 
> r = vhost_net_set_vnet_endian(dev, ncs[0].peer, false);
> assert(r >= 0);
> 
> ?
> 
>  Thomas
> 

Oops you're right... I'll send a fix.

--
Greg




Re: [Qemu-devel] [PATCH 2/2] target-i386: automatically raise cpuid level to 0xd

2015-06-19 Thread Radim Krčmář
2015-06-18 12:50-0300, Eduardo Habkost:
> On Thu, Jun 18, 2015 at 05:24:24PM +0200, Radim Krčmář wrote:
> > We already bump to level 7 if features there are requested, so do the
> > same for 0xD.
> > 
> > Signed-off-by: Radim Krčmář 
> 
> This breaks guest ABI and live-migration, as CPUID data is not part of
> the migration stream (although we have considered including it in the
> future).
> 
> If we are going to add more special cases like this, we must provide a
> way to make QEMU honour an explicit "level" option from the config file
> or command-line.

Thanks, I'll drop this patch.

> I have considered introducing "min-[x]level" and "max-{x]level"
> properties to control automatic increasing of level/xlevel. The existing
> X86CPUDefinition.level field could just control min_level, while
> explicit "level=" on the command-line or config file would explicitly
> force a specific value. Probably setting "max-level" on machine-type
> compat code would be enough to restore the previous behavior.

We'd need to set min-level at least to 7, to capture the raising we do
now, but a feature in level between default and 7 would result in a
different behavior, so we need to make it much uglier :/
We can add 'compat-level' bit for old machine types and raise to highest
habited function otherwise, optionally with controls you described.



Re: [Qemu-devel] [PATCH 2/2] target-i386: automatically raise cpuid level to 0xd

2015-06-19 Thread Radim Krčmář
2015-06-19 11:47+0200, Radim Krčmář:
> 2015-06-18 12:50-0300, Eduardo Habkost:
> > I have considered introducing "min-[x]level" and "max-{x]level"
> > properties to control automatic increasing of level/xlevel. The existing
> > X86CPUDefinition.level field could just control min_level, while
> > explicit "level=" on the command-line or config file would explicitly
> > force a specific value. Probably setting "max-level" on machine-type
> > compat code would be enough to restore the previous behavior.
> 
> We'd need to set min-level at least to 7, to capture the raising we do
   ^

Should have been max-level.

(The alcohol level doesn't drop fast enough.)

> now, but a feature in level between default and 7 would result in a
> different behavior, so we need to make it much uglier :/
> We can add 'compat-level' bit for old machine types and raise to highest
> habited function otherwise, optionally with controls you described.



[Qemu-devel] [PATCH] vhost_net: fix misuse of assert()

2015-06-19 Thread Greg Kurz
In case NDEBUG is defined, assert() expands to nothing and
vhost_net_set_vnet_endian() doesn't get called...

Suggested-by: Thomas Huth 
Signed-off-by: Greg Kurz 
---
 hw/net/vhost_net.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Michael,

Yet another fix for the cross-endian vhost series... please
apply.

--
Greg

diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index f505c91d420a..6d3b7879f8ef 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -376,7 +376,8 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs,
 }
 assert(r >= 0);
 
-assert(vhost_net_set_vnet_endian(dev, ncs[0].peer, false) >= 0);
+r = vhost_net_set_vnet_endian(dev, ncs[0].peer, false);
+assert(r >= 0);
 }
 
 void vhost_net_cleanup(struct vhost_net *net)




Re: [Qemu-devel] [PULL v2 07/12] vl: Create (most) objects before creating chardev backends

2015-06-19 Thread Andreas Färber
Am 27.05.2015 um 20:20 schrieb Andreas Färber:
> From: "Daniel P. Berrange" 
> 
> Some types of object must be created before chardevs, other types of
> object must be created after chardevs. As such there is no option but
> to create objects in two phases.
> 
> This takes the decision to create as many object types as possible
> right away before anyother backends are created, and only delay
> creation of those few which have an explicit dependency on the
> chardevs. Hopefully the set which need delaying will remain small
> over time.
> 
> Signed-off-by: Daniel P. Berrange 
> Reviewed-by: Paolo Bonzini 
> Signed-off-by: Andreas Färber 
> ---
>  vl.c | 40 +++-
>  1 file changed, 39 insertions(+), 1 deletion(-)

Rebasing my queue, I needed the attached changes to make it apply and
build. Second pairs of eyes welcome.

Regards,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Dilip Upmanyu, Graham Norton; HRB
21284 (AG Nürnberg)
diff --cc vl.c
index 2201e27,b7c7511..000
--- a/vl.c
+++ b/vl.c
@@@ -2671,7 -2601,34 +2671,34 @@@ static int machine_set_property(void *o
  return 0;
  }
  
+ 
+ /*
+  * Initial object creation happens before all other
+  * QEMU data types are created. The majority of objects
+  * can be created at this point. The rng-egd object
+  * cannot be created here, as it depends on the chardev
+  * already existing.
+  */
+ static bool object_create_initial(const char *type)
+ {
+ if (g_str_equal(type, "rng-egd")) {
+ return false;
+ }
+ return true;
+ }
+ 
+ 
+ /*
+  * The remainder of object creation happens after the
+  * creation of chardev, fsdev and device data types.
+  */
+ static bool object_create_delayed(const char *type)
+ {
+ return !object_create_initial(type);
+ }
+ 
+ 
 -static int object_create(QemuOpts *opts, void *opaque)
 +static int object_create(void *opaque, QemuOpts *opts, Error **errp)
  {
  Error *err = NULL;
  char *type = NULL;
@@@ -4114,14 -4062,16 +4145,20 @@@ int main(int argc, char **argv, char **
  
  socket_init();
  
+ if (qemu_opts_foreach(qemu_find_opts("object"),
+   object_create,
 -  object_create_initial, 0) != 0) {
++  object_create_initial, NULL)) {
+ exit(1);
+ }
+ 
 -if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, 1) != 0)
 +if (qemu_opts_foreach(qemu_find_opts("chardev"),
 +  chardev_init_func, NULL, NULL)) {
  exit(1);
 +}
 +
  #ifdef CONFIG_VIRTFS
 -if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 1) != 0) {
 +if (qemu_opts_foreach(qemu_find_opts("fsdev"),
 +  fsdev_init_func, NULL, NULL)) {
  exit(1);
  }
  #endif
@@@ -4137,7 -4087,8 +4174,8 @@@
  }
  
  if (qemu_opts_foreach(qemu_find_opts("object"),
-   object_create, NULL, NULL)) {
+   object_create,
 -  object_create_delayed, 0) != 0) {
++  object_create_delayed, NULL)) {
  exit(1);
  }
  


Re: [Qemu-devel] [PULL v2 07/12] vl: Create (most) objects before creating chardev backends

2015-06-19 Thread Paolo Bonzini


On 19/06/2015 12:03, Andreas Färber wrote:
> Am 27.05.2015 um 20:20 schrieb Andreas Färber:
>> From: "Daniel P. Berrange" 
>>
>> Some types of object must be created before chardevs, other types of
>> object must be created after chardevs. As such there is no option but
>> to create objects in two phases.
>>
>> This takes the decision to create as many object types as possible
>> right away before anyother backends are created, and only delay
>> creation of those few which have an explicit dependency on the
>> chardevs. Hopefully the set which need delaying will remain small
>> over time.
>>
>> Signed-off-by: Daniel P. Berrange 
>> Reviewed-by: Paolo Bonzini 
>> Signed-off-by: Andreas Färber 
>> ---
>>  vl.c | 40 +++-
>>  1 file changed, 39 insertions(+), 1 deletion(-)
> 
> Rebasing my queue, I needed the attached changes to make it apply and
> build. Second pairs of eyes welcome.

Looks good.

Paolo



Re: [Qemu-devel] [PATCH] vhost_net: fix misuse of assert()

2015-06-19 Thread Michael S. Tsirkin
On Fri, Jun 19, 2015 at 12:00:53PM +0200, Greg Kurz wrote:
> In case NDEBUG is defined, assert() expands to nothing and
> vhost_net_set_vnet_endian() doesn't get called...
> 
> Suggested-by: Thomas Huth 
> Signed-off-by: Greg Kurz 

Not sure what the point is.
We don't support building with NDEBUG.

> ---
>  hw/net/vhost_net.c |3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> Michael,
> 
> Yet another fix for the cross-endian vhost series... please
> apply.
> 
> --
> Greg
> 
> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> index f505c91d420a..6d3b7879f8ef 100644
> --- a/hw/net/vhost_net.c
> +++ b/hw/net/vhost_net.c
> @@ -376,7 +376,8 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState 
> *ncs,
>  }
>  assert(r >= 0);
>  
> -assert(vhost_net_set_vnet_endian(dev, ncs[0].peer, false) >= 0);
> +r = vhost_net_set_vnet_endian(dev, ncs[0].peer, false);
> +assert(r >= 0);
>  }
>  
>  void vhost_net_cleanup(struct vhost_net *net)



[Qemu-devel] [PATCH v3 1/5] include/softmmu-semi.h: Make semihosting support 64-bit clean

2015-06-19 Thread Leon Alrae
From: "Maciej W. Rozycki" 

Correct addresses passed around in semihosting to use a data type suitable
for both 32-bit and 64-bit targets.

Signed-off-by: Maciej W. Rozycki 
Signed-off-by: Leon Alrae 
---
 include/exec/softmmu-semi.h | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/include/exec/softmmu-semi.h b/include/exec/softmmu-semi.h
index 8401f7d..1819cc2 100644
--- a/include/exec/softmmu-semi.h
+++ b/include/exec/softmmu-semi.h
@@ -9,14 +9,14 @@
 #ifndef SOFTMMU_SEMI_H
 #define SOFTMMU_SEMI_H 1
 
-static inline uint32_t softmmu_tget32(CPUArchState *env, uint32_t addr)
+static inline uint32_t softmmu_tget32(CPUArchState *env, target_ulong addr)
 {
 uint32_t val;
 
 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, (uint8_t *)&val, 4, 0);
 return tswap32(val);
 }
-static inline uint32_t softmmu_tget8(CPUArchState *env, uint32_t addr)
+static inline uint32_t softmmu_tget8(CPUArchState *env, target_ulong addr)
 {
 uint8_t val;
 
@@ -28,7 +28,8 @@ static inline uint32_t softmmu_tget8(CPUArchState *env, 
uint32_t addr)
 #define get_user_u8(arg, p) ({ arg = softmmu_tget8(env, p) ; 0; })
 #define get_user_ual(arg, p) get_user_u32(arg, p)
 
-static inline void softmmu_tput32(CPUArchState *env, uint32_t addr, uint32_t 
val)
+static inline void softmmu_tput32(CPUArchState *env,
+  target_ulong addr, uint32_t val)
 {
 val = tswap32(val);
 cpu_memory_rw_debug(ENV_GET_CPU(env), addr, (uint8_t *)&val, 4, 1);
@@ -36,8 +37,8 @@ static inline void softmmu_tput32(CPUArchState *env, uint32_t 
addr, uint32_t val
 #define put_user_u32(arg, p) ({ softmmu_tput32(env, p, arg) ; 0; })
 #define put_user_ual(arg, p) put_user_u32(arg, p)
 
-static void *softmmu_lock_user(CPUArchState *env, uint32_t addr, uint32_t len,
-   int copy)
+static void *softmmu_lock_user(CPUArchState *env,
+   target_ulong addr, target_ulong len, int copy)
 {
 uint8_t *p;
 /* TODO: Make this something that isn't fixed size.  */
@@ -48,7 +49,7 @@ static void *softmmu_lock_user(CPUArchState *env, uint32_t 
addr, uint32_t len,
 return p;
 }
 #define lock_user(type, p, len, copy) softmmu_lock_user(env, p, len, copy)
-static char *softmmu_lock_user_string(CPUArchState *env, uint32_t addr)
+static char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr)
 {
 char *p;
 char *s;



[Qemu-devel] [PATCH v3 2/5] hw/mips: Do not clear BEV for MIPS malta kernel load

2015-06-19 Thread Leon Alrae
From: Matthew Fortune 

The BEV flag controls whether the boot exception vector is still
in place when starting a kernel.  When cleared the exception vector
at EBASE (or hard coded address of 0x8000) is used instead.

The early stages of the linux kernel would benefit from BEV still
being set to ensure any faults get handled by the boot rom exception
handlers.  This is a moot point for system qemu as there aren't really
any BEV handlers, but there are other good reasons to change this...

The UHI (semi-hosting interface) defines special behaviours depending
on whether an application starts in an environment with BEV set or
cleared. When BEV is set then UHI assumes that a bootloader is
relatively dumb and has no advanced exception handling logic.
However, when BEV is cleared then UHI assumes that the bootloader
has the ability to handle UHI exceptions with its exception handlers
and will unwind and forward UHI SYSCALL exceptions to the exception
vector that was installed prior to running the application.

Signed-off-by: Matthew Fortune 
Signed-off-by: Leon Alrae 
---
 hw/mips/mips_malta.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
index 786a8f0..a5d64d5 100644
--- a/hw/mips/mips_malta.c
+++ b/hw/mips/mips_malta.c
@@ -887,7 +887,7 @@ static void main_cpu_reset(void *opaque)
read only location. The kernel location and the arguments table
location does not change. */
 if (loaderparams.kernel_filename) {
-env->CP0_Status &= ~((1 << CP0St_BEV) | (1 << CP0St_ERL));
+env->CP0_Status &= ~(1 << CP0St_ERL);
 }
 
 malta_mips_config(cpu);



[Qemu-devel] [PATCH v3 0/5] target-mips: add UHI semihosting support

2015-06-19 Thread Leon Alrae
This series introduces the Unified Hosting Interface support to QEMU.
Version 3 of this patchset contains just minor cleanup and corrections
in mips-semi.c comparing to previous version.

It has been on the mailing list for a while and given that command line
option responsible for passing semihosting arguments is clarified I'm
planning to apply this patch series to mips-next soon.

Patches apply on top of:
https://lists.gnu.org/archive/html/qemu-devel/2015-06/msg05013.html

Simple example for those who would like to give it a try:

Bare Metal Toolchain containing UHI support can be obtained from:
http://codescape-mips-sdk.imgtec.com/components/toolchain/2015.01-7/

* Source file:
  #include 

  int main(int argc, char *argv[])
  {
  int i;
  for (i = 0; i < argc; i++) {
  printf("argv[%d] = %s\n", i, argv[i]);
  }
  return 0;
  }

* Build:
  $ mips-img-elf-gcc -mips64r6 -mabi=64 -EL -Tuhi64_64.ld main.c

* Run
  $ qemu-system-mips64el -cpu mips64r6-generic -M malta -nographic -kernel 
a.out -semihosting-config arg=a.out,arg=foo,arg="bar baz"
  argv[0] = a.out
  argv[1] = foo
  argv[2] = bar baz

Regards,
Leon

v3:
* remove useless #ifndef CONFIG_USER_ONLY
* correct errno in copy_stat_to_target(), write_to_file() and read_from_file()

v2:
* use new -semihosting arg option
* if semihosting args are not present, then fall back to old-style
  -kernel/-append
* clean up SDBBP and remove identical code in different branch
* fix overlooked microMIPS SDBBP
* translate errno values which don't map 1:1
* update dates in the licence header
* return -1 and fake errno when lock_user() fails in write_to_file() and
  read_from_file()

Leon Alrae (3):
  target-mips: remove identical code in different branch
  target-mips: add Unified Hosting Interface (UHI) support
  target-mips: convert host to MIPS errno values when required

Maciej W. Rozycki (1):
  include/softmmu-semi.h: Make semihosting support 64-bit clean

Matthew Fortune (1):
  hw/mips: Do not clear BEV for MIPS malta kernel load

 hw/mips/mips_malta.c|  11 +-
 include/exec/softmmu-semi.h |  13 +-
 qemu-options.hx |  10 +-
 target-mips/Makefile.objs   |   2 +-
 target-mips/helper.h|   2 +
 target-mips/mips-semi.c | 358 
 target-mips/translate.c |  68 +
 7 files changed, 426 insertions(+), 38 deletions(-)
 create mode 100644 target-mips/mips-semi.c




Re: [Qemu-devel] [Qemu-block] [PATCH v7 00/11] Support streaming to an intermediate layer

2015-06-19 Thread Alberto Garcia
On Thu 18 Jun 2015 02:36:13 PM CEST, Eric Blake wrote:

   [Detecting support for intermediate block streaming]
>> One possibility is to try to stream to an intermediate node and see
>> if it fails.
>> 
>> Example: in a chain like [A] <- [B] <- [C], streaming to [B] using
>> [A] as the 'base' parameter is a no-op (there's even a test for that
>> in iotest 030).
>> 
>> If QEMU does support streaming to [B], the operation will succeed but
>> do nothing. Otherwise the operation will fail with a DeviceNotFound
>> error.

> In general, if a feature addition doesn't change API, but merely
> converts what was previously an error into something that works, then
> libvirt is probably okay with just trying the feature, and reporting
> the error message if it fails (assuming the qemu error message is
> sane).

With the example I gave above you should be able to detect easily if the
feature is present, but from what you say I understand that strictly
speaking you wouldn't even need to do that.

If you try to stream to a node and QEMU does not support that you will
get a 'device not found' error, which is I guess the kind of error that
you would expect. Since the only thing that changes with this feature is
the 'device' parameter I don't think there's any room for ambiguity.

Berto



[Qemu-devel] [PATCH v3 4/5] target-mips: add Unified Hosting Interface (UHI) support

2015-06-19 Thread Leon Alrae
Add UHI semihosting support for MIPS. QEMU run with "-semihosting" option
will alter the behaviour of SDBBP 1 instruction -- UHI operation will be
called instead of generating a debug exception.

Also tweak Malta's pseudo-bootloader. On CPU reset the $4 register is set
to -1 if semihosting arguments are passed to indicate that the UHI
operations should be used to obtain input arguments.

Signed-off-by: Leon Alrae 
---
 hw/mips/mips_malta.c  |   9 +-
 qemu-options.hx   |  10 +-
 target-mips/Makefile.objs |   2 +-
 target-mips/helper.h  |   2 +
 target-mips/mips-semi.c   | 336 ++
 target-mips/translate.c   |  75 ---
 6 files changed, 408 insertions(+), 26 deletions(-)
 create mode 100644 target-mips/mips-semi.c

diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
index a5d64d5..3082e75 100644
--- a/hw/mips/mips_malta.c
+++ b/hw/mips/mips_malta.c
@@ -53,6 +53,7 @@
 #include "qemu/error-report.h"
 #include "hw/empty_slot.h"
 #include "sysemu/kvm.h"
+#include "exec/semihost.h"
 
 //#define DEBUG_BOARD_INIT
 
@@ -634,7 +635,13 @@ static void write_bootloader (CPUMIPSState *env, uint8_t 
*base,
 
 /* Second part of the bootloader */
 p = (uint32_t *) (base + 0x580);
-stl_p(p++, 0x24040002);  /* addiu a0, 
zero, 2 */
+
+if (semihosting_get_argc()) {
+/* Preserve a0 content as arguments have been passed */
+stl_p(p++, 0x); /* nop */
+} else {
+stl_p(p++, 0x24040002); /* addiu a0, zero, 2 */
+}
 stl_p(p++, 0x3c1d | (((ENVP_ADDR - 64) >> 16) & 0x)); /* lui sp, 
high(ENVP_ADDR) */
 stl_p(p++, 0x37bd | ((ENVP_ADDR - 64) & 0x));/* ori sp, 
sp, low(ENVP_ADDR) */
 stl_p(p++, 0x3c05 | ((ENVP_ADDR >> 16) & 0x));   /* lui a1, 
high(ENVP_ADDR) */
diff --git a/qemu-options.hx b/qemu-options.hx
index 7959dd0..5243aee 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -3344,20 +3344,22 @@ Set OpenBIOS nvram @var{variable} to given @var{value} 
(PPC, SPARC only).
 ETEXI
 DEF("semihosting", 0, QEMU_OPTION_semihosting,
 "-semihostingsemihosting mode\n",
-QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA | QEMU_ARCH_LM32)
+QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA | QEMU_ARCH_LM32 |
+QEMU_ARCH_MIPS)
 STEXI
 @item -semihosting
 @findex -semihosting
-Enable semihosting mode (ARM, M68K, Xtensa only).
+Enable semihosting mode (ARM, M68K, Xtensa, MIPS only).
 ETEXI
 DEF("semihosting-config", HAS_ARG, QEMU_OPTION_semihosting_config,
 "-semihosting-config 
[enable=on|off][,target=native|gdb|auto][,arg=str[,...]]\n" \
 "semihosting configuration\n",
-QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA | QEMU_ARCH_LM32)
+QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA | QEMU_ARCH_LM32 |
+QEMU_ARCH_MIPS)
 STEXI
 @item -semihosting-config 
[enable=on|off][,target=native|gdb|auto][,arg=str[,...]]
 @findex -semihosting-config
-Enable and configure semihosting (ARM, M68K, Xtensa only).
+Enable and configure semihosting (ARM, M68K, Xtensa, MIPS only).
 @table @option
 @item target=@code{native|gdb|auto}
 Defines where the semihosting calls will be addressed, to QEMU (@code{native})
diff --git a/target-mips/Makefile.objs b/target-mips/Makefile.objs
index 108fd9b..bc5ed85 100644
--- a/target-mips/Makefile.objs
+++ b/target-mips/Makefile.objs
@@ -1,4 +1,4 @@
 obj-y += translate.o dsp_helper.o op_helper.o lmi_helper.o helper.o cpu.o
-obj-y += gdbstub.o msa_helper.o
+obj-y += gdbstub.o msa_helper.o mips-semi.o
 obj-$(CONFIG_SOFTMMU) += machine.o
 obj-$(CONFIG_KVM) += kvm.o
diff --git a/target-mips/helper.h b/target-mips/helper.h
index 8df98c7..2b28e87 100644
--- a/target-mips/helper.h
+++ b/target-mips/helper.h
@@ -1,6 +1,8 @@
 DEF_HELPER_3(raise_exception_err, noreturn, env, i32, int)
 DEF_HELPER_2(raise_exception, noreturn, env, i32)
 
+DEF_HELPER_1(do_semihosting, void, env)
+
 #ifdef TARGET_MIPS64
 DEF_HELPER_4(sdl, void, env, tl, tl, int)
 DEF_HELPER_4(sdr, void, env, tl, tl, int)
diff --git a/target-mips/mips-semi.c b/target-mips/mips-semi.c
new file mode 100644
index 000..6944e98
--- /dev/null
+++ b/target-mips/mips-semi.c
@@ -0,0 +1,336 @@
+/*
+ * Unified Hosting Interface syscalls.
+ *
+ * Copyright (c) 2015 Imagination Technologies
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * Lic

[Qemu-devel] [PATCH v3 3/5] target-mips: remove identical code in different branch

2015-06-19 Thread Leon Alrae
Signed-off-by: Leon Alrae 
---
 target-mips/translate.c | 25 -
 1 file changed, 4 insertions(+), 21 deletions(-)

diff --git a/target-mips/translate.c b/target-mips/translate.c
index 1d128ee..6fd6dd9 100644
--- a/target-mips/translate.c
+++ b/target-mips/translate.c
@@ -11852,11 +11852,7 @@ static int decode_mips16_opc (CPUMIPSState *env, 
DisasContext *ctx)
  *  when in debug mode...
  */
 check_insn(ctx, ISA_MIPS32);
-if (!(ctx->hflags & MIPS_HFLAG_DM)) {
-generate_exception(ctx, EXCP_DBp);
-} else {
-generate_exception(ctx, EXCP_DBp);
-}
+generate_exception(ctx, EXCP_DBp);
 break;
 case RR_SLT:
 gen_slt(ctx, OPC_SLT, 24, rx, ry);
@@ -12707,11 +12703,7 @@ static void gen_pool16c_insn(DisasContext *ctx)
  *  when in debug mode...
  */
 check_insn(ctx, ISA_MIPS32);
-if (!(ctx->hflags & MIPS_HFLAG_DM)) {
-generate_exception(ctx, EXCP_DBp);
-} else {
-generate_exception(ctx, EXCP_DBp);
-}
+generate_exception(ctx, EXCP_DBp);
 break;
 case JRADDIUSP + 0:
 case JRADDIUSP + 1:
@@ -13076,11 +13068,7 @@ static void gen_pool32axf (CPUMIPSState *env, 
DisasContext *ctx, int rt, int rs)
 break;
 case SDBBP:
 check_insn(ctx, ISA_MIPS32);
-if (!(ctx->hflags & MIPS_HFLAG_DM)) {
-generate_exception(ctx, EXCP_DBp);
-} else {
-generate_exception(ctx, EXCP_DBp);
-}
+generate_exception(ctx, EXCP_DBp);
 break;
 default:
 goto pool32axf_invalid;
@@ -16849,12 +16837,7 @@ static void decode_opc_special2_legacy(CPUMIPSState 
*env, DisasContext *ctx)
  *  when in debug mode...
  */
 check_insn(ctx, ISA_MIPS32);
-if (!(ctx->hflags & MIPS_HFLAG_DM)) {
-generate_exception(ctx, EXCP_DBp);
-} else {
-generate_exception(ctx, EXCP_DBp);
-}
-/* Treat as NOP. */
+generate_exception(ctx, EXCP_DBp);
 break;
 #if defined(TARGET_MIPS64)
 case OPC_DCLO:



[Qemu-devel] [PATCH v3 5/5] target-mips: convert host to MIPS errno values when required

2015-06-19 Thread Leon Alrae
Convert only errno values which can be returned by system calls in
mips-semi.c and are not generic to all archs.

Signed-off-by: Leon Alrae 
---
 target-mips/mips-semi.c | 44 +---
 1 file changed, 33 insertions(+), 11 deletions(-)

diff --git a/target-mips/mips-semi.c b/target-mips/mips-semi.c
index 6944e98..1162c76 100644
--- a/target-mips/mips-semi.c
+++ b/target-mips/mips-semi.c
@@ -72,6 +72,28 @@ enum UHIOpenFlags {
 UHIOpen_EXCL   = 0x800
 };
 
+/* Errno values taken from asm-mips/errno.h */
+static uint16_t host_to_mips_errno[] = {
+[ENAMETOOLONG] = 78,
+#ifdef EOVERFLOW
+[EOVERFLOW]= 79,
+#endif
+#ifdef ELOOP
+[ELOOP]= 90,
+#endif
+};
+
+static int errno_mips(int err)
+{
+if (err < 0 || err >= ARRAY_SIZE(host_to_mips_errno)) {
+return EINVAL;
+} else if (host_to_mips_errno[err]) {
+return host_to_mips_errno[err];
+} else {
+return err;
+}
+}
+
 static int copy_stat_to_target(CPUMIPSState *env, const struct stat *src,
target_ulong vaddr)
 {
@@ -223,7 +245,7 @@ void helper_do_semihosting(CPUMIPSState *env)
 gpr[2] = 2;
 } else {
 gpr[2] = open(p, get_open_flags(gpr[5]), gpr[6]);
-gpr[3] = errno;
+gpr[3] = errno_mips(errno);
 }
 FREE_TARGET_STRING(p, gpr[4]);
 break;
@@ -234,24 +256,24 @@ void helper_do_semihosting(CPUMIPSState *env)
 goto uhi_done;
 }
 gpr[2] = close(gpr[4]);
-gpr[3] = errno;
+gpr[3] = errno_mips(errno);
 break;
 case UHI_read:
 gpr[2] = read_from_file(env, gpr[4], gpr[5], gpr[6], 0);
-gpr[3] = errno;
+gpr[3] = errno_mips(errno);
 break;
 case UHI_write:
 gpr[2] = write_to_file(env, gpr[4], gpr[5], gpr[6], 0);
-gpr[3] = errno;
+gpr[3] = errno_mips(errno);
 break;
 case UHI_lseek:
 gpr[2] = lseek(gpr[4], gpr[5], gpr[6]);
-gpr[3] = errno;
+gpr[3] = errno_mips(errno);
 break;
 case UHI_unlink:
 GET_TARGET_STRING(p, gpr[4]);
 gpr[2] = remove(p);
-gpr[3] = errno;
+gpr[3] = errno_mips(errno);
 FREE_TARGET_STRING(p, gpr[4]);
 break;
 case UHI_fstat:
@@ -259,12 +281,12 @@ void helper_do_semihosting(CPUMIPSState *env)
 struct stat sbuf;
 memset(&sbuf, 0, sizeof(sbuf));
 gpr[2] = fstat(gpr[4], &sbuf);
-gpr[3] = errno;
+gpr[3] = errno_mips(errno);
 if (gpr[2]) {
 goto uhi_done;
 }
 gpr[2] = copy_stat_to_target(env, &sbuf, gpr[5]);
-gpr[3] = errno;
+gpr[3] = errno_mips(errno);
 }
 break;
 case UHI_argc:
@@ -311,18 +333,18 @@ void helper_do_semihosting(CPUMIPSState *env)
 break;
 case UHI_pread:
 gpr[2] = read_from_file(env, gpr[4], gpr[5], gpr[6], gpr[7]);
-gpr[3] = errno;
+gpr[3] = errno_mips(errno);
 break;
 case UHI_pwrite:
 gpr[2] = write_to_file(env, gpr[4], gpr[5], gpr[6], gpr[7]);
-gpr[3] = errno;
+gpr[3] = errno_mips(errno);
 break;
 #ifndef _WIN32
 case UHI_link:
 GET_TARGET_STRING(p, gpr[4]);
 GET_TARGET_STRING(p2, gpr[5]);
 gpr[2] = link(p, p2);
-gpr[3] = errno;
+gpr[3] = errno_mips(errno);
 FREE_TARGET_STRING(p2, gpr[5]);
 FREE_TARGET_STRING(p, gpr[4]);
 break;



[Qemu-devel] [PATCH] [RfC] fw_cfg file sort

2015-06-19 Thread Gerd Hoffmann
This is what it takes to have a sorted fw_cfg file directory.
Entries are inserted at the correct place instead of being
appended to the end in case sorting is enabled.

Compatibility fluff (enable sorting for new machine types only)
isn't there yet.

Signed-off-by: Gerd Hoffmann 
---
 hw/nvram/fw_cfg.c | 30 --
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index 0f35931..83205e0 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -639,7 +639,7 @@ void fw_cfg_add_file_callback(FWCfgState *s,  const char 
*filename,
   FWCfgReadCallback callback, void 
*callback_opaque,
   void *data, size_t len)
 {
-int i, index;
+int i, index, count;
 size_t dsize;
 
 if (!s->files) {
@@ -648,13 +648,31 @@ void fw_cfg_add_file_callback(FWCfgState *s,  const char 
*filename,
 fw_cfg_add_bytes(s, FW_CFG_FILE_DIR, s->files, dsize);
 }
 
-index = be32_to_cpu(s->files->count);
-assert(index < FW_CFG_FILE_SLOTS);
+count = be32_to_cpu(s->files->count);
+assert(count < FW_CFG_FILE_SLOTS);
+
+index = count;
+if (1 /* sort entries */) {
+while (index > 0 && strcmp(filename, s->files->f[index-1].name) < 0) {
+s->files->f[index] =
+s->files->f[index - 1];
+s->files->f[index].select =
+cpu_to_be16(FW_CFG_FILE_FIRST + index);
+s->entries[0][FW_CFG_FILE_FIRST + index] =
+s->entries[0][FW_CFG_FILE_FIRST + index - 1];
+index--;
+}
+memset(&s->files->f[index],
+   0, sizeof(FWCfgFile));
+memset(&s->entries[0][FW_CFG_FILE_FIRST + index],
+   0, sizeof(FWCfgEntry));
+}
 
 pstrcpy(s->files->f[index].name, sizeof(s->files->f[index].name),
 filename);
-for (i = 0; i < index; i++) {
-if (strcmp(s->files->f[index].name, s->files->f[i].name) == 0) {
+for (i = 0; i <= count; i++) {
+if (i != index &&
+strcmp(s->files->f[index].name, s->files->f[i].name) == 0) {
 error_report("duplicate fw_cfg file name: %s",
  s->files->f[index].name);
 exit(1);
@@ -668,7 +686,7 @@ void fw_cfg_add_file_callback(FWCfgState *s,  const char 
*filename,
 s->files->f[index].select = cpu_to_be16(FW_CFG_FILE_FIRST + index);
 trace_fw_cfg_add_file(s, index, s->files->f[index].name, len);
 
-s->files->count = cpu_to_be32(index+1);
+s->files->count = cpu_to_be32(count+1);
 }
 
 void fw_cfg_add_file(FWCfgState *s,  const char *filename,
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH] vhost_net: fix misuse of assert()

2015-06-19 Thread Peter Maydell
On 19 June 2015 at 11:07, Michael S. Tsirkin  wrote:
> On Fri, Jun 19, 2015 at 12:00:53PM +0200, Greg Kurz wrote:
>> In case NDEBUG is defined, assert() expands to nothing and
>> vhost_net_set_vnet_endian() doesn't get called...
>>
>> Suggested-by: Thomas Huth 
>> Signed-off-by: Greg Kurz 
>
> Not sure what the point is.
> We don't support building with NDEBUG.

Putting functional behaviour inside an assert() is still a really
bad idea. If you're reading the code you probably skim over the
assert() as not functionally relevant...

-- PMM



Re: [Qemu-devel] [PATCH] vhost_net: fix misuse of assert()

2015-06-19 Thread Michael S. Tsirkin
On Fri, Jun 19, 2015 at 11:13:40AM +0100, Peter Maydell wrote:
> On 19 June 2015 at 11:07, Michael S. Tsirkin  wrote:
> > On Fri, Jun 19, 2015 at 12:00:53PM +0200, Greg Kurz wrote:
> >> In case NDEBUG is defined, assert() expands to nothing and
> >> vhost_net_set_vnet_endian() doesn't get called...
> >>
> >> Suggested-by: Thomas Huth 
> >> Signed-off-by: Greg Kurz 
> >
> > Not sure what the point is.
> > We don't support building with NDEBUG.
> 
> Putting functional behaviour inside an assert() is still a really
> bad idea. If you're reading the code you probably skim over the
> assert() as not functionally relevant...
> 
> -- PMM

I can apply this if commit log explains it's a readability
enhancement, not a bugfix.

-- 
MST



[Qemu-devel] [RFC PATCH v4 1/5] spapr: Initialize hotplug memory address space

2015-06-19 Thread Bharata B Rao
Initialize a hotplug memory region under which all the hotplugged
memory is accommodated. Also enable memory hotplug by setting
CONFIG_MEM_HOTPLUG.

Modelled on i386 memory hotplug.

Signed-off-by: Bharata B Rao 
---
 default-configs/ppc64-softmmu.mak |  1 +
 hw/ppc/spapr.c| 28 
 include/hw/ppc/spapr.h| 12 
 3 files changed, 41 insertions(+)

diff --git a/default-configs/ppc64-softmmu.mak 
b/default-configs/ppc64-softmmu.mak
index ab62cc7..e77cb1a 100644
--- a/default-configs/ppc64-softmmu.mak
+++ b/default-configs/ppc64-softmmu.mak
@@ -52,3 +52,4 @@ CONFIG_XICS_KVM=$(and $(CONFIG_PSERIES),$(CONFIG_KVM))
 # For PReP
 CONFIG_MC146818RTC=y
 CONFIG_ISA_TESTDEV=y
+CONFIG_MEM_HOTPLUG=y
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 5ca817c..87a29dc 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1549,6 +1549,34 @@ static void ppc_spapr_init(MachineState *machine)
 memory_region_add_subregion(sysmem, 0, rma_region);
 }
 
+/* initialize hotplug memory address space */
+if (machine->ram_size < machine->maxram_size) {
+ram_addr_t hotplug_mem_size = machine->maxram_size - machine->ram_size;
+
+if (machine->ram_slots > SPAPR_MAX_RAM_SLOTS) {
+error_report("unsupported amount of memory slots: %"PRIu64,
+  machine->ram_slots);
+exit(EXIT_FAILURE);
+}
+
+spapr->hotplug_memory.base = ROUND_UP(machine->ram_size,
+  SPAPR_HOTPLUG_MEM_ALIGN);
+
+hotplug_mem_size += SPAPR_HOTPLUG_MEM_ALIGN * machine->ram_slots;
+
+if ((spapr->hotplug_memory.base + hotplug_mem_size) <
+ hotplug_mem_size) {
+error_report("unsupported amount of maximum memory: " RAM_ADDR_FMT,
+ machine->maxram_size);
+exit(EXIT_FAILURE);
+}
+
+memory_region_init(&spapr->hotplug_memory.mr, OBJECT(spapr),
+   "hotplug-memory", hotplug_mem_size);
+memory_region_add_subregion(sysmem, spapr->hotplug_memory.base,
+&spapr->hotplug_memory.mr);
+}
+
 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, "spapr-rtas.bin");
 if (!filename) {
 error_report("Could not find LPAR rtas '%s'", "spapr-rtas.bin");
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 91a61ab..8a1929b 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -5,6 +5,7 @@
 #include "hw/boards.h"
 #include "hw/ppc/xics.h"
 #include "hw/ppc/spapr_drc.h"
+#include "hw/mem/pc-dimm.h"
 
 struct VIOsPAPRBus;
 struct sPAPRPHBState;
@@ -76,6 +77,7 @@ struct sPAPRMachineState {
 
 /*< public >*/
 char *kvm_type;
+MemoryHotplugState hotplug_memory;
 };
 
 #define H_SUCCESS 0
@@ -609,4 +611,14 @@ int spapr_rtc_import_offset(DeviceState *dev, int64_t 
legacy_offset);
 
 #define SPAPR_MEMORY_BLOCK_SIZE (1 << 28) /* 256MB */
 
+/*
+ * This defines the maximum number of DIMM slots we can have for sPAPR
+ * guest. This is not defined by sPAPR but we are defining it to 32 slots
+ * based on default number of slots provided by PowerPC kernel.
+ */
+#define SPAPR_MAX_RAM_SLOTS 32
+
+/* 1GB alignment for hotplug memory region */
+#define SPAPR_HOTPLUG_MEM_ALIGN (1ULL << 30)
+
 #endif /* !defined (__HW_SPAPR_H__) */
-- 
2.1.0




[Qemu-devel] [RFC PATCH v4 3/5] spapr: Support ibm, dynamic-reconfiguration-memory

2015-06-19 Thread Bharata B Rao
Parse ibm,architecture.vec table obtained from the guest and enable
memory node configuration via ibm,dynamic-reconfiguration-memory if guest
supports it. This is in preparation to support memory hotplug for
sPAPR guests.

This changes the way memory node configuration is done. Currently all
memory nodes are built upfront. But after this patch, only memory@0 node
for RMA is built upfront. Guest kernel boots with just that and rest of
the memory nodes (via memory@XXX or ibm,dynamic-reconfiguration-memory)
are built when guest does ibm,client-architecture-support call.

Note: This patch needs a SLOF enhancement which is already part of
SLOF binary in QEMU.

Signed-off-by: Bharata B Rao 
---
 docs/specs/ppc-spapr-hotplug.txt |  48 ++
 hw/ppc/spapr.c   | 202 ++-
 hw/ppc/spapr_hcall.c |  51 --
 include/hw/ppc/spapr.h   |  15 ++-
 4 files changed, 266 insertions(+), 50 deletions(-)

diff --git a/docs/specs/ppc-spapr-hotplug.txt b/docs/specs/ppc-spapr-hotplug.txt
index 46e0719..9d574b5 100644
--- a/docs/specs/ppc-spapr-hotplug.txt
+++ b/docs/specs/ppc-spapr-hotplug.txt
@@ -302,4 +302,52 @@ consisting of ,  and .
 pseries guests use this property to note the maximum allowed CPUs for the
 guest.
 
+== ibm,dynamic-reconfiguration-memory ==
+
+ibm,dynamic-reconfiguration-memory is a device tree node that represents
+dynamically reconfigurable logical memory blocks (LMB). This node
+is generated only when the guest advertises the support for it via
+ibm,client-architecture-support call. Memory that is not dynamically
+reconfigurable is represented by /memory nodes. The properties of this
+node that are of interest to the sPAPR memory hotplug implementation
+in QEMU are described here.
+
+ibm,lmb-size
+
+This 64bit integer defines the size of each dynamically reconfigurable LMB.
+
+ibm,associativity-lookup-arrays
+
+This property defines a lookup array in which the NUMA associativity
+information for each LMB can be found. It is a property encoded array
+that begins with an integer M, the number of associativity lists followed
+by an integer N, the number of entries per associativity list and terminated
+by M associativity lists each of length N integers.
+
+This property provides the same information as given by ibm,associativity
+property in a /memory node. Each assigned LMB has an index value between
+0 and M-1 which is used as an index into this table to select which
+associativity list to use for the LMB. This index value for each LMB
+is defined in ibm,dynamic-memory property.
+
+ibm,dynamic-memory
+
+This property describes the dynamically reconfigurable memory. It is a
+property endoded array that has an integer N, the number of LMBs followed
+by N LMB list entires.
+
+Each LMB list entry consists of the following elements:
+
+- Logical address of the start of the LMB encoded as a 64bit integer. This
+  corresponds to reg property in /memory node.
+- DRC index of the LMB that corresponds to ibm,my-drc-index property
+  in a /memory node.
+- Four bytes reserved for expansion.
+- Associativity list index for the LMB that is used an index into
+  ibm,associativity-lookup-arrays property described earlier. This
+  is used to retrieve the right associativity list to be used for this
+  LMB.
+- A 32bit flags word. The bit at bit position 0x0008 defines whether
+  the LMB is assigned to the the partition as of boot time.
+
 [1] http://thread.gmane.org/gmane.linux.ports.ppc.embedded/75350/focus=106867
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index f9af89b..2389061 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -495,44 +495,7 @@ static void *spapr_create_fdt_skel(hwaddr initrd_base,
 return fdt;
 }
 
-int spapr_h_cas_compose_response(sPAPRMachineState *spapr,
- target_ulong addr, target_ulong size)
-{
-void *fdt, *fdt_skel;
-sPAPRDeviceTreeUpdateHeader hdr = { .version_id = 1 };
-
-size -= sizeof(hdr);
-
-/* Create sceleton */
-fdt_skel = g_malloc0(size);
-_FDT((fdt_create(fdt_skel, size)));
-_FDT((fdt_begin_node(fdt_skel, "")));
-_FDT((fdt_end_node(fdt_skel)));
-_FDT((fdt_finish(fdt_skel)));
-fdt = g_malloc0(size);
-_FDT((fdt_open_into(fdt_skel, fdt, size)));
-g_free(fdt_skel);
-
-/* Fix skeleton up */
-_FDT((spapr_fixup_cpu_dt(fdt, spapr)));
-
-/* Pack resulting tree */
-_FDT((fdt_pack(fdt)));
-
-if (fdt_totalsize(fdt) + sizeof(hdr) > size) {
-trace_spapr_cas_failed(size);
-return -1;
-}
-
-cpu_physical_memory_write(addr, &hdr, sizeof(hdr));
-cpu_physical_memory_write(addr + sizeof(hdr), fdt, fdt_totalsize(fdt));
-trace_spapr_cas_continue(fdt_totalsize(fdt) + sizeof(hdr));
-g_free(fdt);
-
-return 0;
-}
-
-static void spapr_populate_memory_node(void *fdt, int nodeid, hwaddr start,
+static int spapr_populate_memory_node(void *fdt, int nodeid, hwaddr start,
   

[Qemu-devel] [RFC PATCH v4 2/5] spapr: Add LMB DR connectors

2015-06-19 Thread Bharata B Rao
Enable memory hotplug for pseries 2.4 and add LMB DR connectors.
With memory hotplug, enforce NUMA node memory size and maxmem to be
a multiple of SPAPR_MEMORY_BLOCK_SIZE (256M) since that's the granularity
in which LMBs are represented and hot-added.

LMB DR connectors will be used by the memory hotplug code.

Signed-off-by: Bharata B Rao 
Signed-off-by: Michael Roth 
   [spapr_drc_reset implementation]
---
 hw/ppc/spapr.c | 78 ++
 include/hw/ppc/spapr.h |  2 ++
 2 files changed, 80 insertions(+)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 87a29dc..f9af89b 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -59,6 +59,7 @@
 #include "hw/nmi.h"
 
 #include "hw/compat.h"
+#include "qemu-common.h"
 
 #include 
 
@@ -1436,10 +1437,76 @@ static void spapr_cpu_init(sPAPRMachineState *spapr, 
PowerPCCPU *cpu)
 qemu_register_reset(spapr_cpu_reset, cpu);
 }
 
+static void spapr_drc_reset(void *opaque)
+{
+sPAPRDRConnector *drc = opaque;
+DeviceState *d = DEVICE(drc);
+
+if (d) {
+device_reset(d);
+}
+}
+
+static void spapr_create_lmb_dr_connectors(sPAPRMachineState *spapr)
+{
+MachineState *machine = MACHINE(qdev_get_machine());
+uint64_t lmb_size = SPAPR_MEMORY_BLOCK_SIZE;
+uint32_t nr_rma_lmbs = spapr->rma_size/lmb_size;
+uint32_t nr_lmbs = machine->maxram_size/lmb_size - nr_rma_lmbs;
+uint32_t nr_assigned_lmbs = machine->ram_size/lmb_size - nr_rma_lmbs;
+int i;
+
+for (i = 0; i < nr_lmbs; i++) {
+sPAPRDRConnector *drc;
+uint64_t addr;
+
+if (i < nr_assigned_lmbs) {
+addr = (i + nr_rma_lmbs) * lmb_size;
+} else {
+addr = (i - nr_assigned_lmbs) * lmb_size +
+SPAPR_MACHINE(qdev_get_machine())->hotplug_memory.base;
+}
+
+drc = spapr_dr_connector_new(qdev_get_machine(),
+SPAPR_DR_CONNECTOR_TYPE_LMB, addr/lmb_size);
+qemu_register_reset(spapr_drc_reset, drc);
+}
+}
+
+/*
+ * If LMB DR is enabled node memory size and max memory size should
+ * be a multiple of SPAPR_MEMORY_BLOCK_SIZE (256M).
+ */
+static void spapr_validate_node_memory(sPAPRMachineState *spapr)
+{
+int i;
+MachineState *machine = MACHINE(qdev_get_machine());
+
+if (!spapr->dr_lmb_enabled) {
+return;
+}
+
+if (machine->maxram_size % SPAPR_MEMORY_BLOCK_SIZE) {
+error_report("maxmem should be a multiple of %lld MB",
+  SPAPR_MEMORY_BLOCK_SIZE/M_BYTE);
+exit(EXIT_FAILURE);
+}
+
+for (i = 0; i < nb_numa_nodes; i++) {
+if (numa_info[i].node_mem &&
+numa_info[i].node_mem % SPAPR_MEMORY_BLOCK_SIZE) {
+error_report("Memory size on node %d should be a multiple "
+ "of %lld MB", i, SPAPR_MEMORY_BLOCK_SIZE/M_BYTE);
+exit(EXIT_FAILURE);
+}
+}
+}
+
 /* pSeries LPAR / sPAPR hardware init */
 static void ppc_spapr_init(MachineState *machine)
 {
 sPAPRMachineState *spapr = SPAPR_MACHINE(machine);
+sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(machine);
 const char *kernel_filename = machine->kernel_filename;
 const char *kernel_cmdline = machine->kernel_cmdline;
 const char *initrd_filename = machine->initrd_filename;
@@ -1518,6 +1585,9 @@ static void ppc_spapr_init(MachineState *machine)
smp_threads),
   XICS_IRQS);
 
+spapr->dr_lmb_enabled = smc->dr_lmb_enabled;
+spapr_validate_node_memory(spapr);
+
 /* init CPUs */
 if (machine->cpu_model == NULL) {
 machine->cpu_model = kvm_enabled() ? "host" : "POWER7";
@@ -1577,6 +1647,10 @@ static void ppc_spapr_init(MachineState *machine)
 &spapr->hotplug_memory.mr);
 }
 
+if (spapr->dr_lmb_enabled) {
+spapr_create_lmb_dr_connectors(spapr);
+}
+
 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, "spapr-rtas.bin");
 if (!filename) {
 error_report("Could not find LPAR rtas '%s'", "spapr-rtas.bin");
@@ -1850,6 +1924,7 @@ static void spapr_nmi(NMIState *n, int cpu_index, Error 
**errp)
 static void spapr_machine_class_init(ObjectClass *oc, void *data)
 {
 MachineClass *mc = MACHINE_CLASS(oc);
+sPAPRMachineClass *smc = SPAPR_MACHINE_CLASS(oc);
 FWPathProviderClass *fwc = FW_PATH_PROVIDER_CLASS(oc);
 NMIClass *nc = NMI_CLASS(oc);
 
@@ -1863,6 +1938,7 @@ static void spapr_machine_class_init(ObjectClass *oc, 
void *data)
 mc->kvm_type = spapr_kvm_type;
 mc->has_dynamic_sysbus = true;
 
+smc->dr_lmb_enabled = false;
 fwc->get_dev_path = spapr_get_fw_dev_path;
 nc->nmi_monitor_handler = spapr_nmi;
 }
@@ -1998,11 +2074,13 @@ static const TypeInfo spapr_machine_2_3_info = {
 static void spapr_machine_2_4_class_init(ObjectClass *oc, void *data)
 {
 MachineClass *mc = MACHINE_CLASS(oc);
+sPAPRMachineClass *smc = S

Re: [Qemu-devel] [PULL 00/10] virtio, pci fixes, enhancements

2015-06-19 Thread Michael S. Tsirkin
On Fri, Jun 19, 2015 at 09:32:48AM +0100, Peter Maydell wrote:
> On 19 June 2015 at 08:30, Michael S. Tsirkin  wrote:
> > They are trivial - a single patch on top that adds stubs for missing
> > platforms.  And I think breaking bisect on non-linux isn't a big deal.
> > If you agree, please apply.
> 
> I would prefer the fix folded in to the correct point in the
> patchset, please. We have the opportunity to avoid breaking
> OSX bisection, we should take it.
> 
> -- PMM

OK, done and pushed (same place). I verified that the resulting tree is
identical to the previous one, so your testing on OSX should still hold.

-- 
MST



[Qemu-devel] [RFC PATCH v4 5/5] spapr: Memory hotplug support

2015-06-19 Thread Bharata B Rao
Make use of pc-dimm infrastructure to support memory hotplug
for PowerPC.

Signed-off-by: Bharata B Rao 
---
 hw/ppc/spapr.c| 126 ++
 hw/ppc/spapr_events.c |   8 ++--
 2 files changed, 131 insertions(+), 3 deletions(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 24e5a8c..173f639 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -33,6 +33,7 @@
 #include "sysemu/block-backend.h"
 #include "sysemu/cpus.h"
 #include "sysemu/kvm.h"
+#include "sysemu/device_tree.h"
 #include "kvm_ppc.h"
 #include "mmu-hash64.h"
 #include "qom/cpu.h"
@@ -930,6 +931,10 @@ static void spapr_finalize_fdt(sPAPRMachineState *spapr,
 spapr_populate_chosen_stdout(fdt, spapr->vio_bus);
 }
 
+if (spapr->dr_lmb_enabled) {
+_FDT(spapr_drc_populate_dt(fdt, 0, NULL, SPAPR_DR_CONNECTOR_TYPE_LMB));
+}
+
 _FDT((fdt_pack(fdt)));
 
 if (fdt_totalsize(fdt) > FDT_MAX_SIZE) {
@@ -2037,12 +2042,129 @@ static void spapr_nmi(NMIState *n, int cpu_index, 
Error **errp)
 }
 }
 
+static void spapr_add_lmbs(DeviceState *dev, uint64_t addr, uint64_t size,
+   uint32_t node, Error **errp)
+{
+sPAPRDRConnector *drc;
+sPAPRDRConnectorClass *drck;
+uint32_t nr_lmbs = size/SPAPR_MEMORY_BLOCK_SIZE;
+int i, fdt_offset, fdt_size;
+void *fdt;
+Error *local_err = NULL;
+
+if (size % SPAPR_MEMORY_BLOCK_SIZE) {
+error_setg(errp, "Hotplugged memory size must be a multiple of "
+  "%lld MB", SPAPR_MEMORY_BLOCK_SIZE/M_BYTE);
+return;
+}
+
+/*
+ * Check for DRC connectors and send hotplug notification to the
+ * guest only in case of hotplugged memory. This allows cold plugged
+ * memory to be specified at boot time.
+ */
+if (!dev->hotplugged) {
+return;
+}
+
+for (i = 0; i < nr_lmbs; i++) {
+drc = spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_LMB,
+addr/SPAPR_MEMORY_BLOCK_SIZE);
+g_assert(drc);
+
+fdt = create_device_tree(&fdt_size);
+fdt_offset = spapr_populate_memory_node(fdt, node, addr,
+SPAPR_MEMORY_BLOCK_SIZE);
+
+drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
+drck->attach(drc, dev, fdt, fdt_offset, !dev->hotplugged, &local_err);
+if (local_err) {
+g_free(fdt);
+error_propagate(errp, local_err);
+return;
+}
+
+spapr_hotplug_req_add_event(drc);
+addr += SPAPR_MEMORY_BLOCK_SIZE;
+}
+}
+
+static void spapr_memory_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
+  uint32_t node, Error **errp)
+{
+Error *local_err = NULL;
+sPAPRMachineState *ms = SPAPR_MACHINE(hotplug_dev);
+PCDIMMDevice *dimm = PC_DIMM(dev);
+PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm);
+MemoryRegion *mr = ddc->get_memory_region(dimm);
+uint64_t align = memory_region_get_alignment(mr);
+uint64_t addr;
+
+pc_dimm_memory_plug(dev, &ms->hotplug_memory, mr, align, &local_err);
+if (local_err) {
+goto out;
+}
+
+addr = object_property_get_int(OBJECT(dimm), PC_DIMM_ADDR_PROP, 
&local_err);
+if (local_err) {
+goto out;
+}
+
+spapr_add_lmbs(dev, addr, memory_region_size(mr), node, &local_err);
+if (local_err) {
+goto out;
+}
+return;
+
+out:
+pc_dimm_memory_unplug(dev, &ms->hotplug_memory, mr);
+error_propagate(errp, local_err);
+}
+
+static void spapr_machine_device_plug(HotplugHandler *hotplug_dev,
+  DeviceState *dev, Error **errp)
+{
+sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
+
+if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+uint32_t node;
+
+if (!spapr->dr_lmb_enabled) {
+error_setg(errp, "Memory hotplug not supported for this machine");
+return;
+}
+node = object_property_get_int(OBJECT(dev), PC_DIMM_NODE_PROP, errp);
+if (*errp) {
+return;
+}
+spapr_memory_plug(hotplug_dev, dev, node, errp);
+}
+}
+
+static void spapr_machine_device_unplug(HotplugHandler *hotplug_dev,
+  DeviceState *dev, Error **errp)
+{
+if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+error_setg(errp, "Memory hot unplug not supported by sPAPR");
+}
+}
+
+static HotplugHandler *spapr_get_hotpug_handler(MachineState *machine,
+ DeviceState *dev)
+{
+if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
+return HOTPLUG_HANDLER(machine);
+}
+return NULL;
+}
+
 static void spapr_machine_class_init(ObjectClass *oc, void *data)
 {
 MachineClass *mc = MACHINE_CLASS(oc);
 sPAPRMachineClass *smc = SPAPR_MACHINE_CLASS(oc);
 FWPathProviderClass *fwc = FW_PATH_PROVIDER_CLASS(oc);
 NMIClass *nc = NMI_C

[Qemu-devel] [RFC PATCH v4 0/5] Memory hotplug for PowerPC sPAPR guests

2015-06-19 Thread Bharata B Rao
Hi,

This is the next version of memory hotplug support patchset for PowerPC
sPAPR guests. This is a split-out from the previous version (v3) that
was carrying CPU and memory hotplug together.

This patchset applies on spapr-next branch of David Gibson's tree with
the other prerequisite patchset applied. Pre-requistes patchset was
posted at:
https://lists.gnu.org/archive/html/qemu-devel/2015-06/msg05157.html

Changes in v4
-
- Supporting only 32 DIMM slots since PowerPC kernel supports 32.
- LMB DR connectors are now created at boot time instead of creating
  them during ibm,client-architecture-support call. This enables
  hot adding memroy to a migrated VM.
- Imposing the restriction that node memory size and max memory size
  be in multiples of SPAPR_MEMORY_BLOCK_SIZE (256M).
- Ensure memory@0 for RMA ends in the 1st node that has non-zero
  node size.
- Make hash table size dependent on maxram_size instead of ram_size.
- Allow hotplug to nodes other than NUMA node 0.
- No duplication of hotplug code from pc_dimm_plug().

v3: https://lists.nongnu.org/archive/html/qemu-devel/2015-04/msg02910.html

The memory hotplug feature requires updated version of powerpc-utils
and ppc64-diag packages in the guest.

Bharata B Rao (5):
  spapr: Initialize hotplug memory address space
  spapr: Add LMB DR connectors
  spapr: Support ibm,dynamic-reconfiguration-memory
  spapr: Make hash table size a factor of maxram_size
  spapr: Memory hotplug support

 default-configs/ppc64-softmmu.mak |   1 +
 docs/specs/ppc-spapr-hotplug.txt  |  48 +
 hw/ppc/spapr.c| 436 ++
 hw/ppc/spapr_events.c |   8 +-
 hw/ppc/spapr_hcall.c  |  51 -
 include/hw/ppc/spapr.h|  29 ++-
 6 files changed, 519 insertions(+), 54 deletions(-)

-- 
2.1.0




[Qemu-devel] [RFC PATCH v4 4/5] spapr: Make hash table size a factor of maxram_size

2015-06-19 Thread Bharata B Rao
The hash table size is dependent on ram_size, but since with hotplug
the memory can grow till maxram_size. Hence make hash table size dependent
on maxram_size.

This allows to hotplug huge amounts of memory to the guest.

Signed-off-by: Bharata B Rao 
---
 hw/ppc/spapr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 2389061..24e5a8c 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1689,7 +1689,7 @@ static void ppc_spapr_init(MachineState *machine)
  * more than needed for the Linux guests we support. */
 spapr->htab_shift = 18; /* Minimum architected size */
 while (spapr->htab_shift <= 46) {
-if ((1ULL << (spapr->htab_shift + 7)) >= machine->ram_size) {
+if ((1ULL << (spapr->htab_shift + 7)) >= machine->maxram_size) {
 break;
 }
 spapr->htab_shift++;
-- 
2.1.0




Re: [Qemu-devel] [PULL 00/15] Timer, virtio-scsi-test, build, memory changes for 2015-06-19

2015-06-19 Thread Peter Maydell
On 19 June 2015 at 08:45, Paolo Bonzini  wrote:
> The following changes since commit 93f6d1c16036aaf34055d16f54ea770fb8d6d280:
>
>   Merge remote-tracking branch 'remotes/kraxel/tags/pull-vga-20150615-1' into 
> staging (2015-06-16 10:35:43 +0100)
>
> are available in the git repository at:
>
>   git://github.com/bonzini/qemu.git tags/for-upstream
>
> for you to fetch changes up to 4e6ab89110c85f7163b875d9e900e97ab0a175b0:
>
>   exec: clamp accesses against the MemoryRegionSection (2015-06-19 09:06:04 
> +0200)
>
> 
> * i8254 security fix
> * Avoid long 100% CPU wait after restarting guests that use the periodic timer
> * Fixes for access clamping (WinXP, MIPS)
> * wixl/.msi support for qemu-ga on Windows

Hi. I'm afraid this fails to build on 32 bit:

/root/qemu/tests/virtio-scsi-test.c: In function ‘qvirtio_scsi_pci_init’:
/root/qemu/tests/virtio-scsi-test.c:96:12: error: cast from pointer to
integer of different size [-Werror=pointer-to-int-cast]

thanks
-- PMM



Re: [Qemu-devel] [PATCH for-2.4 1/3] virtio-input: move properties, use virtio_instance_init_common

2015-06-19 Thread Michael S. Tsirkin
On Fri, Jun 19, 2015 at 10:38:35AM +0200, Gerd Hoffmann wrote:
> Move properties from virtio-*-pci to virtio-*-device.
> Also make better use of QOM and attach common properties
> to the abstract parent classes (virtio-input-device and
> virtio-input-pci-device).
> 
> Switch the hid device instance init functions over to use
> virtio_instance_init_common, so we get the properties of the
> virtio device aliased properly to the virtio pci proxy.
> 
> Signed-off-by: Gerd Hoffmann 

Reviewed-by: Michael S. Tsirkin 

> ---
>  hw/input/virtio-input.c  |  8 +++-
>  hw/virtio/virtio-pci.c   | 27 +++
>  include/hw/virtio/virtio-input.h |  9 +
>  3 files changed, 19 insertions(+), 25 deletions(-)
> 
> diff --git a/hw/input/virtio-input.c b/hw/input/virtio-input.c
> index c4f4b3c..7f5b8d6 100644
> --- a/hw/input/virtio-input.c
> +++ b/hw/input/virtio-input.c
> @@ -216,7 +216,7 @@ static void virtio_input_device_realize(DeviceState *dev, 
> Error **errp)
>  }
>  
>  virtio_input_idstr_config(vinput, VIRTIO_INPUT_CFG_ID_SERIAL,
> -  vinput->input.serial);
> +  vinput->serial);
>  
>  QTAILQ_FOREACH(cfg, &vinput->cfg_list, node) {
>  if (vinput->cfg_size < cfg->config.size) {
> @@ -248,11 +248,17 @@ static void virtio_input_device_unrealize(DeviceState 
> *dev, Error **errp)
>  virtio_cleanup(vdev);
>  }
>  
> +static Property virtio_input_properties[] = {
> +DEFINE_PROP_STRING("serial", VirtIOInput, serial),
> +DEFINE_PROP_END_OF_LIST(),
> +};
> +
>  static void virtio_input_class_init(ObjectClass *klass, void *data)
>  {
>  DeviceClass *dc = DEVICE_CLASS(klass);
>  VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
>  
> +dc->props  = virtio_input_properties;
>  set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
>  vdc->realize  = virtio_input_device_realize;
>  vdc->unrealize= virtio_input_device_unrealize;
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index d7cf34c..1187a58 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -1900,8 +1900,7 @@ static const TypeInfo virtio_rng_pci_info = {
>  
>  /* virtio-input-pci */
>  
> -static Property virtio_input_hid_pci_properties[] = {
> -DEFINE_VIRTIO_INPUT_PROPERTIES(VirtIOInputPCI, vdev.input),
> +static Property virtio_input_pci_properties[] = {
>  DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
>  DEFINE_PROP_END_OF_LIST(),
>  };
> @@ -1924,19 +1923,13 @@ static void virtio_input_pci_class_init(ObjectClass 
> *klass, void *data)
>  VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
>  PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
>  
> +dc->props = virtio_input_pci_properties;
>  k->realize = virtio_input_pci_realize;
>  set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
>  
>  pcidev_k->class_id = PCI_CLASS_INPUT_OTHER;
>  }
>  
> -static void virtio_input_hid_pci_class_init(ObjectClass *klass, void *data)
> -{
> -DeviceClass *dc = DEVICE_CLASS(klass);
> -
> -dc->props = virtio_input_hid_pci_properties;
> -}
> -
>  static void virtio_input_hid_kbd_pci_class_init(ObjectClass *klass, void 
> *data)
>  {
>  PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
> @@ -1955,22 +1948,25 @@ static void 
> virtio_input_hid_mouse_pci_class_init(ObjectClass *klass,
>  static void virtio_keyboard_initfn(Object *obj)
>  {
>  VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
> -object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_KEYBOARD);
> -object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), 
> NULL);
> +
> +virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
> +TYPE_VIRTIO_KEYBOARD);
>  }
>  
>  static void virtio_mouse_initfn(Object *obj)
>  {
>  VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
> -object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_MOUSE);
> -object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), 
> NULL);
> +
> +virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
> +TYPE_VIRTIO_MOUSE);
>  }
>  
>  static void virtio_tablet_initfn(Object *obj)
>  {
>  VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
> -object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_TABLET);
> -object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), 
> NULL);
> +
> +virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
> +TYPE_VIRTIO_TABLET);
>  }
>  
>  static const TypeInfo virtio_input_pci_info = {
> @@ -1985,7 +1981,6 @@ static const TypeInfo virtio_input_hid_pci_info = {
>  .name  = TYPE_VIRTIO_INPUT_HID_PCI,
>  .parent= TYPE_VIRTIO_INPUT_PCI,
>  .instance_size = sizeof(VirtIOInputHIDPCI),
> -.class_init= virtio_input_hid_pci_cl

Re: [Qemu-devel] [PATCH 1/2] kvm/x86: Hyper-V based guest crash data handling

2015-06-19 Thread Andrey Smetanin
On Wed, 2015-06-17 at 14:44 +0200, Paolo Bonzini wrote:
> 
> On 11/06/2015 15:18, Denis V. Lunev wrote:
> > From: Andrey Smetanin 
> > 
> > Windows 2012 guests can notify hypervisor about occurred guest crash
> > (Windows bugcheck(BSOD)) by writing specific Hyper-V msrs. This patch does
> > handling of this MSR's by KVM and sending notification to user space that
> > allows to gather Windows guest crash dump by QEMU/LIBVIRT.
> > 
> > The idea is to provide functionality equal to pvpanic device without
> > QEMU guest agent for Windows.
> > 
> > The idea is borrowed from Linux HyperV bus driver and validated against
> > Windows 2k12.
> > 
> > Signed-off-by: Andrey Smetanin 
> > Signed-off-by: Denis V. Lunev 
> > CC: Gleb Natapov 
> > CC: Paolo Bonzini 
> > ---
> >  arch/x86/include/uapi/asm/hyperv.h | 10 +
> >  arch/x86/kvm/Makefile  |  2 +-
> >  arch/x86/kvm/mshv.c| 84 
> > ++
> >  arch/x86/kvm/mshv.h| 32 +++
> 
> Please use hyperv.[ch] or hyper-v.[ch] and name the functions kvm_hv_*.
>  We can later move more functions from x86.c to the new file, so it's
> better to keep the names consistent.
> 
Should we prepare a 1st patch in this series where
we move all hyper-v related code from x86.c into hyperv.c new file with
copyright extension ?
> >  arch/x86/kvm/x86.c | 25 
> >  include/linux/kvm_host.h   | 17 
> >  include/uapi/linux/kvm.h   | 11 +
> >  7 files changed, 180 insertions(+), 1 deletion(-)
> >  create mode 100644 arch/x86/kvm/mshv.c
> >  create mode 100644 arch/x86/kvm/mshv.h
> > 
> > diff --git a/arch/x86/include/uapi/asm/hyperv.h 
> > b/arch/x86/include/uapi/asm/hyperv.h
> > index ce6068d..25f3064 100644
> > --- a/arch/x86/include/uapi/asm/hyperv.h
> > +++ b/arch/x86/include/uapi/asm/hyperv.h
> > @@ -199,6 +199,16 @@
> >  #define HV_X64_MSR_STIMER3_CONFIG  0x40B6
> >  #define HV_X64_MSR_STIMER3_COUNT   0x40B7
> >  
> > +
> > +/* Hypev-V guest crash notification MSR's */
> > +#define HV_X64_MSR_CRASH_P00x4100
> > +#define HV_X64_MSR_CRASH_P10x4101
> > +#define HV_X64_MSR_CRASH_P20x4102
> > +#define HV_X64_MSR_CRASH_P30x4103
> > +#define HV_X64_MSR_CRASH_P40x4104
> > +#define HV_X64_MSR_CRASH_CTL   0x4105
> > +#define HV_CRASH_CTL_CRASH_NOTIFY  (1ULL << 63)
> > +
> >  #define HV_X64_MSR_HYPERCALL_ENABLE0x0001
> >  #define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT12
> >  #define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_MASK \
> > diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile
> > index 16e8f96..b1ec24d 100644
> > --- a/arch/x86/kvm/Makefile
> > +++ b/arch/x86/kvm/Makefile
> > @@ -12,7 +12,7 @@ kvm-y += $(KVM)/kvm_main.o 
> > $(KVM)/coalesced_mmio.o \
> >  kvm-$(CONFIG_KVM_ASYNC_PF) += $(KVM)/async_pf.o
> >  
> >  kvm-y  += x86.o mmu.o emulate.o i8259.o irq.o lapic.o \
> > -  i8254.o ioapic.o irq_comm.o cpuid.o pmu.o
> > +  i8254.o ioapic.o irq_comm.o cpuid.o pmu.o mshv.o
> >  kvm-$(CONFIG_KVM_DEVICE_ASSIGNMENT)+= assigned-dev.o iommu.o
> >  kvm-intel-y+= vmx.o
> >  kvm-amd-y  += svm.o
> > diff --git a/arch/x86/kvm/mshv.c b/arch/x86/kvm/mshv.c
> > new file mode 100644
> > index 000..ad367c44
> > --- /dev/null
> > +++ b/arch/x86/kvm/mshv.c
> > @@ -0,0 +1,84 @@
> > +/*
> > + * KVM Microsoft Hyper-V extended paravirtualization
> > + *
> > + * This work is licensed under the terms of the GNU GPL, version 2.  See
> > + * the COPYING file in the top-level directory.
> > + *
> > + * Copyright (C) 2015 Andrey Smetanin 
> > + *
> > + * Authors: Andrey Smetanin asmeta...@virtuozzo.com
> > + */
> > +
> > +#include 
> > +#include "mshv.h"
> > +
> > +int kvm_mshv_ctx_create(struct kvm *kvm)
> > +{
> > +   struct kvm_mshv_ctx *ctx;
> > +
> > +   ctx = kzalloc(sizeof(struct kvm_mshv_ctx), GFP_KERNEL);
> > +   if (!ctx)
> > +   return -ENOMEM;
> > +
> > +   ctx->kvm = kvm;
> > +   atomic_set(&ctx->crash_pending, 0);
> > +   kvm->mshv_ctx = ctx;
> > +   return 0;
> > +}
> > +
> > +void kvm_mshv_ctx_destroy(struct kvm *kvm)
> > +{
> > +   kfree(kvm->mshv_ctx);
> > +}
> > +
> > +int kvm_mshv_msr_get_crash_ctl(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
> > +{
> > +   struct kvm_mshv_ctx *ctx = kvm_vcpu_get_mshv_ctx(vcpu);
> > +
> > +   atomic_set(&ctx->crash_pending, 1);
> > +
> > +   /* Response that KVM ready to receive crash data */
> > +   *pdata = HV_CRASH_CTL_CRASH_NOTIFY;
> > +   return 0;
> > +}
> > +
> > +int kvm_mshv_msr_set_crash_ctl(struct kvm_vcpu *vcpu, u32 msr, u64 data)
> > +{
> > +   struct kvm_mshv_ctx *ctx = kvm_vcpu_get_mshv_ctx(vcpu);
> > +
> > +   if (atomic_dec_and_test(&ctx->crash_pending)) {
> > + 

[Qemu-devel] [PULL 3/3] ui/cocoa.m: Add machine menu items to change and eject removable drive media

2015-06-19 Thread Peter Maydell
From: John Arbuckle 

Adds all removable devices to the Machine menu as a Change and Eject menu
item pair. ide-cd0 would have a "Change ide-cd0..." and "Eject ide-cd0"
menu items.

Signed-off-by: John Arbuckle 
Reviewed-by: Peter Maydell 
Signed-off-by: Peter Maydell 
---
 ui/cocoa.m | 156 +++--
 1 file changed, 153 insertions(+), 3 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 559058b..334e6f6 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -30,6 +30,7 @@
 #include "ui/input.h"
 #include "sysemu/sysemu.h"
 #include "qmp-commands.h"
+#include "sysemu/blockdev.h"
 
 #ifndef MAC_OS_X_VERSION_10_5
 #define MAC_OS_X_VERSION_10_5 1050
@@ -67,6 +68,7 @@ int gArgc;
 char **gArgv;
 bool stretch_video;
 NSTextField *pauseLabel;
+NSArray * supportedImageFileTypes;
 
 // keymap conversion
 int keymap[] =
@@ -242,7 +244,24 @@ static int cocoa_keycode_to_qemu(int keycode)
 return keymap[keycode];
 }
 
+/* Displays an alert dialog box with the specified message */
+static void QEMU_Alert(NSString *message)
+{
+NSAlert *alert;
+alert = [NSAlert new];
+[alert setMessageText: message];
+[alert runModal];
+}
 
+/* Handles any errors that happen with a device transaction */
+static void handleAnyDeviceErrors(Error * err)
+{
+if (err) {
+QEMU_Alert([NSString stringWithCString: error_get_pretty(err)
+  encoding: NSASCIIStringEncoding]);
+error_free(err);
+}
+}
 
 /*
  --
@@ -808,6 +827,8 @@ QemuCocoaView *cocoaView;
 - (void)removePause;
 - (void)restartQEMU:(id)sender;
 - (void)powerDownQEMU:(id)sender;
+- (void)ejectDeviceMedia:(id)sender;
+- (void)changeDeviceMedia:(id)sender;
 @end
 
 @implementation QemuCocoaAppController
@@ -854,6 +875,10 @@ QemuCocoaView *cocoaView;
 [pauseLabel setFont: [NSFont fontWithName: @"Helvetica" size: 90]];
 [pauseLabel setTextColor: [NSColor blackColor]];
 [pauseLabel sizeToFit];
+
+// set the supported image file types that can be opened
+supportedImageFileTypes = [NSArray arrayWithObjects: @"img", @"iso", 
@"dmg",
+ @"qcow", @"qcow2", @"cloop", @"vmdk", nil];
 }
 return self;
 }
@@ -877,10 +902,8 @@ QemuCocoaView *cocoaView;
 NSOpenPanel *op = [[NSOpenPanel alloc] init];
 [op setPrompt:@"Boot image"];
 [op setMessage:@"Select the disk image you want to boot.\n\nHit the 
\"Cancel\" button to quit"];
-NSArray *filetypes = [NSArray arrayWithObjects:@"img", @"iso", @"dmg",
- @"qcow", @"qcow2", @"cloop", @"vmdk", nil];
 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
-[op setAllowedFileTypes:filetypes];
+[op setAllowedFileTypes:supportedImageFileTypes];
 [op beginSheetModalForWindow:normalWindow
 completionHandler:^(NSInteger returnCode)
 { [self openPanelDidEnd:op
@@ -1047,6 +1070,61 @@ QemuCocoaView *cocoaView;
 qmp_system_powerdown(NULL);
 }
 
+/* Ejects the media.
+ * Uses sender's tag to figure out the device to eject.
+ */
+- (void)ejectDeviceMedia:(id)sender
+{
+NSString * drive;
+drive = [sender representedObject];
+if(drive == nil) {
+NSBeep();
+QEMU_Alert(@"Failed to find drive to eject!");
+return;
+}
+
+Error *err = NULL;
+qmp_eject([drive cStringUsingEncoding: NSASCIIStringEncoding], false, 
false, &err);
+handleAnyDeviceErrors(err);
+}
+
+/* Displays a dialog box asking the user to select an image file to load.
+ * Uses sender's represented object value to figure out which drive to use.
+ */
+- (void)changeDeviceMedia:(id)sender
+{
+/* Find the drive name */
+NSString * drive;
+drive = [sender representedObject];
+if(drive == nil) {
+NSBeep();
+QEMU_Alert(@"Could not find drive!");
+return;
+}
+
+/* Display the file open dialog */
+NSOpenPanel * openPanel;
+openPanel = [NSOpenPanel openPanel];
+[openPanel setCanChooseFiles: YES];
+[openPanel setAllowsMultipleSelection: NO];
+[openPanel setAllowedFileTypes: supportedImageFileTypes];
+if([openPanel runModal] == NSFileHandlingPanelOKButton) {
+NSString * file = [[[openPanel URLs] objectAtIndex: 0] path];
+if(file == nil) {
+NSBeep();
+QEMU_Alert(@"Failed to convert URL to file path!");
+return;
+}
+
+Error *err = NULL;
+qmp_change_blockdev([drive cStringUsingEncoding: 
NSASCIIStringEncoding],
+[file cStringUsingEncoding: NSASCIIStringEncoding],
+"raw",
+&err);
+handleAnyDeviceErrors(err);
+}
+}
+
 @end
 
 
@@ -1260,6 +1338,72 @@ static void add_console_menu_entries(void)
 }
 }
 
+/* Make menu items for all removable devices.
+ * Each device is g

[Qemu-devel] [PULL 2/3] ui/cocoa.m: Add Reset and Power Down menu items to Machine menu

2015-06-19 Thread Peter Maydell
From: John Arbuckle 

Add "Reset" and "Power Down" menu items to Machine menu.

Signed-off-by: John Arbuckle 
Reviewed-by: Peter Maydell 
Signed-off-by: Peter Maydell 
---
 ui/cocoa.m | 17 +
 1 file changed, 17 insertions(+)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index d28140b..559058b 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -806,6 +806,8 @@ QemuCocoaView *cocoaView;
 - (void)resumeQEMU:(id)sender;
 - (void)displayPause;
 - (void)removePause;
+- (void)restartQEMU:(id)sender;
+- (void)powerDownQEMU:(id)sender;
 @end
 
 @implementation QemuCocoaAppController
@@ -1033,6 +1035,18 @@ QemuCocoaView *cocoaView;
 [pauseLabel removeFromSuperview];
 }
 
+/* Restarts QEMU */
+- (void)restartQEMU:(id)sender
+{
+qmp_system_reset(NULL);
+}
+
+/* Powers down QEMU */
+- (void)powerDownQEMU:(id)sender
+{
+qmp_system_powerdown(NULL);
+}
+
 @end
 
 
@@ -1099,6 +1113,9 @@ int main (int argc, const char * argv[]) {
 menuItem = [[[NSMenuItem alloc] initWithTitle: @"Resume" action: 
@selector(resumeQEMU:) keyEquivalent: @""] autorelease];
 [menu addItem: menuItem];
 [menuItem setEnabled: NO];
+[menu addItem: [NSMenuItem separatorItem]];
+[menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Reset" action: 
@selector(restartQEMU:) keyEquivalent: @""] autorelease]];
+[menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Power Down" action: 
@selector(powerDownQEMU:) keyEquivalent: @""] autorelease]];
 menuItem = [[[NSMenuItem alloc] initWithTitle: @"Machine" action:nil 
keyEquivalent:@""] autorelease];
 [menuItem setSubmenu:menu];
 [[NSApp mainMenu] addItem:menuItem];
-- 
1.9.1




[Qemu-devel] [PULL 1/3] ui/cocoa.m: Add Machine menu with pause and resume menu items

2015-06-19 Thread Peter Maydell
From: John Arbuckle 

Add Machine menu to the Macintosh interface with pause
and resume menu items. These items can either pause or
resume execution of the guest operating system.

Signed-off-by: John Arbuckle 
Message-id: 6d7ae6aa-0595-4fad-aacf-9dfab8724...@gmail.com
Reviewed-by: Peter Maydell 
Signed-off-by: Peter Maydell 
---
 ui/cocoa.m | 67 ++
 1 file changed, 67 insertions(+)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 85cb24c..d28140b 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -29,6 +29,7 @@
 #include "ui/console.h"
 #include "ui/input.h"
 #include "sysemu/sysemu.h"
+#include "qmp-commands.h"
 
 #ifndef MAC_OS_X_VERSION_10_5
 #define MAC_OS_X_VERSION_10_5 1050
@@ -65,6 +66,7 @@ static int last_buttons;
 int gArgc;
 char **gArgv;
 bool stretch_video;
+NSTextField *pauseLabel;
 
 // keymap conversion
 int keymap[] =
@@ -800,6 +802,10 @@ QemuCocoaView *cocoaView;
 - (void)showQEMUTec:(id)sender;
 - (void)zoomToFit:(id) sender;
 - (void)displayConsole:(id)sender;
+- (void)pauseQEMU:(id)sender;
+- (void)resumeQEMU:(id)sender;
+- (void)displayPause;
+- (void)removePause;
 @end
 
 @implementation QemuCocoaAppController
@@ -834,6 +840,18 @@ QemuCocoaView *cocoaView;
 [normalWindow makeKeyAndOrderFront:self];
 [normalWindow center];
 stretch_video = false;
+
+/* Used for displaying pause on the screen */
+pauseLabel = [NSTextField new];
+[pauseLabel setBezeled:YES];
+[pauseLabel setDrawsBackground:YES];
+[pauseLabel setBackgroundColor: [NSColor whiteColor]];
+[pauseLabel setEditable:NO];
+[pauseLabel setSelectable:NO];
+[pauseLabel setStringValue: @"Paused"];
+[pauseLabel setFont: [NSFont fontWithName: @"Helvetica" size: 90]];
+[pauseLabel setTextColor: [NSColor blackColor]];
+[pauseLabel sizeToFit];
 }
 return self;
 }
@@ -977,6 +995,44 @@ QemuCocoaView *cocoaView;
 {
 console_select([sender tag]);
 }
+
+/* Pause the guest */
+- (void)pauseQEMU:(id)sender
+{
+qmp_stop(NULL);
+[sender setEnabled: NO];
+[[[sender menu] itemWithTitle: @"Resume"] setEnabled: YES];
+[self displayPause];
+}
+
+/* Resume running the guest operating system */
+- (void)resumeQEMU:(id) sender
+{
+qmp_cont(NULL);
+[sender setEnabled: NO];
+[[[sender menu] itemWithTitle: @"Pause"] setEnabled: YES];
+[self removePause];
+}
+
+/* Displays the word pause on the screen */
+- (void)displayPause
+{
+/* Coordinates have to be calculated each time because the window can 
change its size */
+int xCoord, yCoord, width, height;
+xCoord = ([normalWindow frame].size.width - [pauseLabel 
frame].size.width)/2;
+yCoord = [normalWindow frame].size.height - [pauseLabel frame].size.height 
- ([pauseLabel frame].size.height * .5);
+width = [pauseLabel frame].size.width;
+height = [pauseLabel frame].size.height;
+[pauseLabel setFrame: NSMakeRect(xCoord, yCoord, width, height)];
+[cocoaView addSubview: pauseLabel];
+}
+
+/* Removes the word pause from the screen */
+- (void)removePause
+{
+[pauseLabel removeFromSuperview];
+}
+
 @end
 
 
@@ -1036,6 +1092,17 @@ int main (int argc, const char * argv[]) {
 [[NSApp mainMenu] addItem:menuItem];
 [NSApp performSelector:@selector(setAppleMenu:) withObject:menu]; // 
Workaround (this method is private since 10.4+)
 
+// Machine menu
+menu = [[NSMenu alloc] initWithTitle: @"Machine"];
+[menu setAutoenablesItems: NO];
+[menu addItem: [[[NSMenuItem alloc] initWithTitle: @"Pause" action: 
@selector(pauseQEMU:) keyEquivalent: @""] autorelease]];
+menuItem = [[[NSMenuItem alloc] initWithTitle: @"Resume" action: 
@selector(resumeQEMU:) keyEquivalent: @""] autorelease];
+[menu addItem: menuItem];
+[menuItem setEnabled: NO];
+menuItem = [[[NSMenuItem alloc] initWithTitle: @"Machine" action:nil 
keyEquivalent:@""] autorelease];
+[menuItem setSubmenu:menu];
+[[NSApp mainMenu] addItem:menuItem];
+
 // View menu
 menu = [[NSMenu alloc] initWithTitle:@"View"];
 [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter Fullscreen" 
action:@selector(doToggleFullScreen:) keyEquivalent:@"f"] autorelease]]; // 
Fullscreen
-- 
1.9.1




[Qemu-devel] [PULL 0/3] cocoa queue

2015-06-19 Thread Peter Maydell
Slightly late drain of the cocoa queue. Should be nothing more except
bugfixes til 2.4 I think.

-- PMM

The following changes since commit 473a49460db0a90bfda046b8f3662b49f94098eb:

  q35: Re-enable FDC on pc-q35-2.3 and older (2015-06-19 09:40:35 +0100)

are available in the git repository at:

  git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-cocoa-20150619-1

for you to fetch changes up to 693a3e01af8082f855094061650311fcaf3e1269:

  ui/cocoa.m: Add machine menu items to change and eject removable drive media 
(2015-06-19 11:22:31 +0100)


cocoa queue:
 * Add Machine menu, with entries for pause, resume, reset, power down, and
   media change and eject for removable drives


John Arbuckle (3):
  ui/cocoa.m: Add Machine menu with pause and resume menu items
  ui/cocoa.m: Add Reset and Power Down menu items to Machine menu
  ui/cocoa.m: Add machine menu items to change and eject removable drive 
media

 ui/cocoa.m | 240 -
 1 file changed, 237 insertions(+), 3 deletions(-)



Re: [Qemu-devel] [PATCH 1/2] kvm/x86: Hyper-V based guest crash data handling

2015-06-19 Thread Paolo Bonzini


On 19/06/2015 12:28, Andrey Smetanin wrote:
> On Wed, 2015-06-17 at 14:44 +0200, Paolo Bonzini wrote:
>>
>> On 11/06/2015 15:18, Denis V. Lunev wrote:
>>> From: Andrey Smetanin 
>>>
>>> Windows 2012 guests can notify hypervisor about occurred guest crash
>>> (Windows bugcheck(BSOD)) by writing specific Hyper-V msrs. This patch does
>>> handling of this MSR's by KVM and sending notification to user space that
>>> allows to gather Windows guest crash dump by QEMU/LIBVIRT.
>>>
>>> The idea is to provide functionality equal to pvpanic device without
>>> QEMU guest agent for Windows.
>>>
>>> The idea is borrowed from Linux HyperV bus driver and validated against
>>> Windows 2k12.
>>>
>>> Signed-off-by: Andrey Smetanin 
>>> Signed-off-by: Denis V. Lunev 
>>> CC: Gleb Natapov 
>>> CC: Paolo Bonzini 
>>> ---
>>>  arch/x86/include/uapi/asm/hyperv.h | 10 +
>>>  arch/x86/kvm/Makefile  |  2 +-
>>>  arch/x86/kvm/mshv.c| 84 
>>> ++
>>>  arch/x86/kvm/mshv.h| 32 +++
>>
>> Please use hyperv.[ch] or hyper-v.[ch] and name the functions kvm_hv_*.
>>  We can later move more functions from x86.c to the new file, so it's
>> better to keep the names consistent.
>>
> Should we prepare a 1st patch in this series where
> we move all hyper-v related code from x86.c into hyperv.c new file with
> copyright extension ?

If you want to do that, I certainly wouldn't complain.

Paolo



Re: [Qemu-devel] qapi: What does "'gen': false" actually do, and when should I use it?

2015-06-19 Thread Paolo Bonzini


On 09/06/2015 10:42, Markus Armbruster wrote:
> Part 2: When to use it?
> 
> We use 'gen': false when we can't (be bothered to) specify the exact
> type of an argument or result.
> 
> Bad example: netdev_add
> 
> We have arguments 'type': 'str' and '*props': '**'.
> 
> We should have a union tagged by network backend type.  For each
> type, the union holds the type's properties (if any).

The problem with this is that netdev_add was not type safe, because it
uses qemu_opts_from_qdict and QemuOpts is exclusively string-based.  So
you could write 'port': '123' or 'port': 123, and both would work, the
conversion to integer is done by the QemuOptsVisitor.

Note that device_add would have the same problem.

Paolo

> Better example: device_add (but that's not even QAPIfied, yet)
> 
> If QAPIfied, we'd have arguments like 'driver': 'str' and '*props':
> '**'.
> 
> Looks just like netdev_add.  The difference is that network backends
> and their properties are defined in one place, but device models and
> their properties aren't.  They get collected at run time.  As long
> as the schema is fixed at compile-time, it can't express the
> resulting tagged union.
> 
> Another good example: qom-get
> 
> We have a return value '**'.
> 
> The run time type is the type of the property identified by the
> arguments.  Therefore, the compile time type can only be the union
> of all property types, which effectively boils down to "anything".
> 
> The only way to say "anything" right now is '**'.  Requires 'gen':
> false.  I figure we could extend the generators to support '**' in a
> few places, which may let us avoid 'gen': false here.
> 
> Drawback of '**': introspection knows nothing.
> 
> Introspection knowing nothing about netdev_add's and device_add's
> acceptable properties is a big, painful gap.
> 
> Please don't invent new reasons for 'gen': false without a very
> compelling use case.  If you think you have one, we need to talk to make
> sure use of 'gen': false really beats the alternatives.  Alternatives
> may include extending the generators.
> 
> 



Re: [Qemu-devel] [PULL v2 07/12] vl: Create (most) objects before creating chardev backends

2015-06-19 Thread Daniel P. Berrange
On Fri, Jun 19, 2015 at 12:03:13PM +0200, Andreas Färber wrote:
> Am 27.05.2015 um 20:20 schrieb Andreas Färber:
> > From: "Daniel P. Berrange" 
> > 
> > Some types of object must be created before chardevs, other types of
> > object must be created after chardevs. As such there is no option but
> > to create objects in two phases.
> > 
> > This takes the decision to create as many object types as possible
> > right away before anyother backends are created, and only delay
> > creation of those few which have an explicit dependency on the
> > chardevs. Hopefully the set which need delaying will remain small
> > over time.
> > 
> > Signed-off-by: Daniel P. Berrange 
> > Reviewed-by: Paolo Bonzini 
> > Signed-off-by: Andreas Färber 
> > ---
> >  vl.c | 40 +++-
> >  1 file changed, 39 insertions(+), 1 deletion(-)
> 
> Rebasing my queue, I needed the attached changes to make it apply and
> build. Second pairs of eyes welcome.


> @@@ -4114,14 -4062,16 +4145,20 @@@ int main(int argc, char **argv, char **
>   
>   socket_init();
>   
> + if (qemu_opts_foreach(qemu_find_opts("object"),
> +   object_create,
>  -  object_create_initial, 0) != 0) {
> ++  object_create_initial, NULL)) {
> + exit(1);
> + }
> + 
>  -if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, 
> NULL, 1) != 0)
>  +if (qemu_opts_foreach(qemu_find_opts("chardev"),
>  +  chardev_init_func, NULL, NULL)) {
>   exit(1);
>  +}
>  +
>   #ifdef CONFIG_VIRTFS
>  -if (qemu_opts_foreach(qemu_find_opts("fsdev"), fsdev_init_func, NULL, 
> 1) != 0) {
>  +if (qemu_opts_foreach(qemu_find_opts("fsdev"),
>  +  fsdev_init_func, NULL, NULL)) {
>   exit(1);
>   }
>   #endif
> @@@ -4137,7 -4087,8 +4174,8 @@@
>   }
>   
>   if (qemu_opts_foreach(qemu_find_opts("object"),
> -   object_create, NULL, NULL)) {
> +   object_create,
>  -  object_create_delayed, 0) != 0) {
> ++  object_create_delayed, NULL)) {
>   exit(1);
>   }

Yep, this looks correct wrt the change of Markus' that recently
merged in vl.c

Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|



Re: [Qemu-devel] [Qemu-block] [PATCH COLO-Block v6 07/16] Add new block driver interface to connect/disconnect the remote target

2015-06-19 Thread Stefan Hajnoczi
On Fri, Jun 19, 2015 at 08:54:56AM +0800, Wen Congyang wrote:
> On 06/19/2015 12:06 AM, Stefan Hajnoczi wrote:
> > On Thu, Jun 18, 2015 at 10:36:39PM +0800, Wen Congyang wrote:
> >> At 2015/6/18 20:55, Stefan Hajnoczi Wrote:
> >>> On Thu, Jun 18, 2015 at 04:49:12PM +0800, Wen Congyang wrote:
>  +void bdrv_connect(BlockDriverState *bs, Error **errp)
>  +{
>  +BlockDriver *drv = bs->drv;
>  +
>  +if (drv && drv->bdrv_connect) {
>  +drv->bdrv_connect(bs, errp);
>  +} else if (bs->file) {
>  +bdrv_connect(bs->file, errp);
>  +} else {
>  +error_setg(errp, "this feature or command is not currently 
>  supported");
>  +}
>  +}
>  +
>  +void bdrv_disconnect(BlockDriverState *bs)
>  +{
>  +BlockDriver *drv = bs->drv;
>  +
>  +if (drv && drv->bdrv_disconnect) {
>  +drv->bdrv_disconnect(bs);
>  +} else if (bs->file) {
>  +bdrv_disconnect(bs->file);
>  +}
>  +}
> >>>
> >>> Please add doc comments describing the semantics of these commands.
> >>
> >> Where should it be documented? In the header file?
> > 
> > block.h doesn't document prototypes in the header file, please document
> > the function definition in block.c.  (QEMU is not consistent here, some
> > places do it the other way around.)
> > 
> >>> Why are these operations needed when there is already a bs->drv == NULL
> >>> case which means the BDS is not ready for read/write?
> >>>
> >>
> >> The purpos is that: don't connect to nbd server when opening a nbd client.
> >> connect/disconnect
> >> to nbd server when we need to do it.
> >>
> >> IIUC, if bs->drv is NULL, it means that the driver is ejected? Here,
> >> connect/disconnect
> >> means that connect/disconnect to remote target(The target may be in another
> >> host).
> > 
> > Connect/disconnect puts something on the QEMU command-line that isn't
> > ready at startup time.
> > 
> > How about using monitor commands to add objects when needed instead?
> > 
> > That is cleaner because it doesn't introduce a new state (which is only
> > implemented for nbd).
> > 
> 
> The problem is that, nbd client is one child of quorum, and quorum must have 
> more
> than one child. The nbd server is not ready until colo is running.

A monitor command to hot add/remove quorum children solves this problem
and could also be used in other scenarios (e.g. user decides to take a
quorum child offline).


pgpJc6Qgzwe7w.pgp
Description: PGP signature


Re: [Qemu-devel] [PATCH] vhost_net: fix misuse of assert()

2015-06-19 Thread Markus Armbruster
"Michael S. Tsirkin"  writes:

> On Fri, Jun 19, 2015 at 11:13:40AM +0100, Peter Maydell wrote:
>> On 19 June 2015 at 11:07, Michael S. Tsirkin  wrote:
>> > On Fri, Jun 19, 2015 at 12:00:53PM +0200, Greg Kurz wrote:
>> >> In case NDEBUG is defined, assert() expands to nothing and
>> >> vhost_net_set_vnet_endian() doesn't get called...
>> >>
>> >> Suggested-by: Thomas Huth 
>> >> Signed-off-by: Greg Kurz 
>> >
>> > Not sure what the point is.
>> > We don't support building with NDEBUG.
>> 
>> Putting functional behaviour inside an assert() is still a really
>> bad idea. If you're reading the code you probably skim over the
>> assert() as not functionally relevant...
>> 
>> -- PMM
>
> I can apply this if commit log explains it's a readability
> enhancement, not a bugfix.

Easy:

vhost_net: fix misuse of assert()

In case NDEBUG is defined, assert() expands to nothing and
vhost_net_set_vnet_endian() doesn't get called...

Suggested-by: Thomas Huth 
Signed-off-by: Greg Kurz 

We don't support building with NDEBUG, but putting functional behaviour
inside an assert() is still a really bad idea.  If you're reading the
code you probably skim over the assert() as not functionally relevant...

Signed-off-by: Michael S. Tsirkin" 



Re: [Qemu-devel] [PATCH 0/4] block: Improve warnings for doubly-connected drives

2015-06-19 Thread Peter Maydell
Ping?

thanks
-- PMM

On 12 June 2015 at 14:26, Peter Maydell  wrote:
> This patchset attempts to improve the warning and error messages for
> bad user command lines that attempt to connect a drive up to two
> devices. The motivation here is patch #4, which changes the default
> interface for the virt board to virtio. That will break some existing
> command lines which forgot to specify if=none, and so I would like
> us to at least diagnose that user error in a helpful way that points
> the user towards adding the missing if=none.
>
> The patchset improves some error messages, and makes some previously
> undiagnosed mistakes into warnings. The changes (with sample x86
> command lines to provoke them) are:
>
> (1) Drive specified as to be auto-connected and also manually connected
> (and the board does handle this if= type):
>
>   qemu-system-x86_64 -nodefaults -display none -drive 
> if=scsi,file=tmp.qcow2,id=foo -device ide-hd,drive=foo
>
> Previously: an error:
>   qemu-system-x86_64: -device ide-hd,drive=foo: Property 'ide-hd.drive'
>   can't take value 'foo', it's in use
>
> Now: a better error:
>   qemu-system-x86_64: -device ide-hd,drive=foo: Property 'ide-hd.drive'
>   can't be set to drive ID 'foo'; that drive has been automatically
>   connected to another device. Use if=none if you do not want that
>   automatic connection.
>
> (2) As 1, but the board does not handle this if= type:
>
> Previously: not diagnosed at all
>
> Now: a warning:
>   Warning: automatic connection of this drive requested (because if=sd
>   was specified) but it was also connected manually to a device:
>   id=foo,file=tmp.qcow2,if=sd,bus=0,unit=0
>   (If you don't want this drive auto-connected, use if=none.)
>
> [This means we now will always warn one way or another about drives which
> have an if= auto-connect specified but which the board didn't pick up: either
> they're also manually connected and get this warning, or they're not manually
> connected, and get the orphan-drive warning. If the if= was due to the
> board default rather than the user typing it specifically, the error message
> text is slightly different to reflect that.]
>
> (3) Drive specified to be manually connected in two different ways:
>
>   qemu-system-x86_64 -nodefaults -display none -drive 
> if=sd,file=tmp.qcow2,id=foo -device ide-hd,drive=foo -device ide-hd,drive=foo
>
> Previously: an error:
>   qemu-system-x86_64: -device ide-hd,drive=foo: Property 'ide-hd.drive'
>   can't take value 'foo', it's in use
>
> Now: a better error:
>   qemu-system-x86_64: -device ide-hd,drive=foo: Property 'ide-hd.drive'
>   can't be set to drive ID 'foo'; that drive has already been connected
>   to another device.
>
>
>
> In order to detect when a drive was auto-connected, we need to set a
> flag in the DriveInfo when this happens.  we do this by assuming that
> all calls to blk_by_legacy_dinfo() imply that we're about to assign
> the drive to a device.  This is a slightly ugly place to make the
> test, but simpler than trying to locate and change every place in the
> code that does automatic drive handling, and the worst case is that
> we might print out a spurious warning.
>
>
> I include patch #4 as the motivation/context but in fact it doesn't
> depend on the first 3, so if you want to take the first 3 via
> block and have me put the 4th one in target-arm that's OK.
>
> thanks
> -- PMM
>
>
> Peter Maydell (4):
>   block: Warn if an if= drive was also connected manually
>   qdev-properties-system: Change set_pointer's parse callback to use
> Error
>   qdev-properties-system: Improve error message for drive assignment
> conflict
>   hw/arm/virt: Make block devices default to virtio
>
>  block/block-backend.c|  4 
>  blockdev.c   | 39 ++
>  hw/arm/virt.c|  2 ++
>  hw/core/qdev-properties-system.c | 45 
> 
>  include/sysemu/blockdev.h|  2 ++
>  5 files changed, 79 insertions(+), 13 deletions(-)



Re: [Qemu-devel] incorrect memory size inside vm

2015-06-19 Thread Piotr Rybicki

Hello.

Actually it was my mistake.
After some time using memory in guest (find /, cp bigfine, etc), res 
size of qemu process shrinks to expected value.


Sorry for disturbing.
Now i don't see any memory waste in guest and host when using 'base' 
memory + 'dimm' memory.


Although i have one issue.

When i start qemu via libvirt with 16GB mem and 1G current mem:
(...)
  16777216
  1048576
(...)

Qemu starts, and balloon can't free memmory, so guest doesn't boot (It 
hangs or is looped in ' virtio_balloon virtio2: Out of puff! Can't get 1 
pages').
I think this is because dimm memmory is not yet onlined, and balloon 
already tries to shring memory in guest.


Best regards
Piotr Rybicki

W dniu 2015-06-18 o 23:23, Andrey Korolyov pisze:

Do You see similar results at Your side?

Best regards


Would you mind to share you argument set to an emulator? As far as I
understood you are using plain ballooning with most results from above
for which those numbers are expected. The case with 5+gig memory
consumption for deflated 1G guest looks like a bug with mixed
dimm/balloon configuration if you are tried against latest qemu, so
please describe a setup a bit more verbosely too.





[Qemu-devel] [PATCH v2] target-i386: emulate CPUID level of real hardware

2015-06-19 Thread Radim Krčmář
W10 insider has a bug where it ignores CPUID level and interprets
CPUID.(EAX=07H, ECX=0H) incorrectly, because CPUID in fact returned
CPUID.(EAX=04H, ECX=0H);  this resulted in execution of unsupported
instructions.

While it's a Windows bug, there is no reason to emulate incorrect level.

I have used http://instlatx64.atw.hu/ as a source of CPUID and checked
that it matches Penryn Xeon X5472, Westmere Xeon W3520, SandyBridge
i5-2540M, and Haswell i5-4670T.

kvm64 and qemu64 were bumped to 0xD to allow all available features for
them (and to avoid the same Windows bug).

Signed-off-by: Radim Krčmář 
---
 v2:
 * maintained compatibility for old (< 2.4) machine types [Paolo]
 * dropped automatic increase to 0xd, for compatibility [Eduardo]

 I devote this code to copy&paste.

 hw/i386/pc_piix.c | 18 
 hw/i386/pc_q35.c  | 18 
 target-i386/cpu.c | 63 ++-
 target-i386/cpu.h |  3 +++
 4 files changed, 83 insertions(+), 19 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index e142f75649d8..c335e230277b 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -307,6 +307,24 @@ static void pc_init1(MachineState *machine)
 static void pc_compat_2_3(MachineState *machine)
 {
 savevm_skip_section_footers();
+
+x86_cpu_compat_set_level("qemu64",   4);
+x86_cpu_compat_set_level("kvm64",5);
+x86_cpu_compat_set_level("pentium3", 2);
+x86_cpu_compat_set_level("n270", 5);
+x86_cpu_compat_set_level("Conroe",   4);
+x86_cpu_compat_set_level("Penryn",   4);
+x86_cpu_compat_set_level("Nehalem",  4);
+
+x86_cpu_compat_set_xlevel("n270",0x800a);
+x86_cpu_compat_set_xlevel("Penryn",  0x800a);
+x86_cpu_compat_set_xlevel("Nehalem", 0x800a);
+x86_cpu_compat_set_xlevel("Westmere",0x800a);
+x86_cpu_compat_set_xlevel("SandyBridge", 0x800a);
+x86_cpu_compat_set_xlevel("Haswell", 0x800a);
+x86_cpu_compat_set_xlevel("Haswell-noTSX",   0x800a);
+x86_cpu_compat_set_xlevel("Broadwell",   0x800a);
+x86_cpu_compat_set_xlevel("Broadwell-noTSX", 0x800a);
 }
 
 static void pc_compat_2_2(MachineState *machine)
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 082cd93bb2d7..99bfd6d6f288 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -291,6 +291,24 @@ static void pc_q35_init(MachineState *machine)
 static void pc_compat_2_3(MachineState *machine)
 {
 savevm_skip_section_footers();
+
+x86_cpu_compat_set_level("qemu64",   4);
+x86_cpu_compat_set_level("kvm64",5);
+x86_cpu_compat_set_level("pentium3", 2);
+x86_cpu_compat_set_level("n270", 5);
+x86_cpu_compat_set_level("Conroe",   4);
+x86_cpu_compat_set_level("Penryn",   4);
+x86_cpu_compat_set_level("Nehalem",  4);
+
+x86_cpu_compat_set_xlevel("n270",0x800a);
+x86_cpu_compat_set_xlevel("Penryn",  0x800a);
+x86_cpu_compat_set_xlevel("Nehalem", 0x800a);
+x86_cpu_compat_set_xlevel("Westmere",0x800a);
+x86_cpu_compat_set_xlevel("SandyBridge", 0x800a);
+x86_cpu_compat_set_xlevel("Haswell", 0x800a);
+x86_cpu_compat_set_xlevel("Haswell-noTSX",   0x800a);
+x86_cpu_compat_set_xlevel("Broadwell",   0x800a);
+x86_cpu_compat_set_xlevel("Broadwell-noTSX", 0x800a);
 }
 
 static void pc_compat_2_2(MachineState *machine)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 4e7cd57e..7dabf7de25ea 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -677,7 +677,7 @@ struct X86CPUDefinition {
 static X86CPUDefinition builtin_x86_defs[] = {
 {
 .name = "qemu64",
-.level = 4,
+.level = 0xd,
 .vendor = CPUID_VENDOR_AMD,
 .family = 6,
 .model = 6,
@@ -753,7 +753,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
 },
 {
 .name = "kvm64",
-.level = 5,
+.level = 0xd,
 .vendor = CPUID_VENDOR_INTEL,
 .family = 15,
 .model = 6,
@@ -864,7 +864,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
 },
 {
 .name = "pentium3",
-.level = 2,
+.level = 3,
 .vendor = CPUID_VENDOR_INTEL,
 .family = 6,
 .model = 7,
@@ -889,8 +889,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
 },
 {
 .name = "n270",
-/* original is on level 10 */
-.level = 5,
+.level = 10,
 .vendor = CPUID_VENDOR_INTEL,
 .family = 6,
 .model = 28,
@@ -910,12 +909,12 @@ static X86CPUDefinition builtin_x86_defs[] = {
 CPUID_EXT2_NX,
 .features[FEAT_8000_0001_ECX] =
 CPUID_EXT3_LAHF_LM,
-.xlevel = 0x800A,
+.xlevel = 0x8008,
 .model_id = "Intel(R) Atom(TM) CPU N270   @ 1.60GHz",
 },
 {
 .name = "Conroe",
-.level = 4

Re: [Qemu-devel] [PATCH 2/2] target-i386: automatically raise cpuid level to 0xd

2015-06-19 Thread Radim Krčmář
2015-06-19 11:47+0200, Radim Krčmář:
> 2015-06-18 12:50-0300, Eduardo Habkost:
> > I have considered introducing "min-[x]level" and "max-{x]level"
> > properties to control automatic increasing of level/xlevel. The existing
> > X86CPUDefinition.level field could just control min_level, while
> > explicit "level=" on the command-line or config file would explicitly
> > force a specific value. Probably setting "max-level" on machine-type
> > compat code would be enough to restore the previous behavior.
> 
> We'd need to set min-level at least to 7, to capture the raising we do
> now, but a feature in level between default and 7 would result in a
> different behavior, so we need to make it much uglier :/
> We can add 'compat-level' bit for old machine types and raise to highest
> habited function otherwise, optionally with controls you described.

No, features are only in 0x7 and 0xd, so the original solution is good.

(We should also be bumping the CPUID level when adding specific
 features, e.g. to at least 0xB when x2apic is selected.)



Re: [Qemu-devel] [PULL 00/10] virtio, pci fixes, enhancements

2015-06-19 Thread Peter Maydell
On 19 June 2015 at 11:19, Michael S. Tsirkin  wrote:
> On Fri, Jun 19, 2015 at 09:32:48AM +0100, Peter Maydell wrote:
>> On 19 June 2015 at 08:30, Michael S. Tsirkin  wrote:
>> > They are trivial - a single patch on top that adds stubs for missing
>> > platforms.  And I think breaking bisect on non-linux isn't a big deal.
>> > If you agree, please apply.
>>
>> I would prefer the fix folded in to the correct point in the
>> patchset, please. We have the opportunity to avoid breaking
>> OSX bisection, we should take it.
>>
>> -- PMM
>
> OK, done and pushed (same place). I verified that the resulting tree is
> identical to the previous one, so your testing on OSX should still hold.

Applied this version, thanks.

-- PMM



[Qemu-devel] [PATCH] configure: Add support for jemalloc

2015-06-19 Thread Alexandre Derumier
This adds "--enable-jemalloc" and "--disable-jemalloc" to allow linking
to jemalloc memory allocator.

We have already tcmalloc support,
but it seem to not working well with a lot of iothreads/disks.

The main problem is that tcmalloc use a shared thread cache of 16MB
by default.
With more threads, this cache is shared, and some bad garbage collections
can occur if the cache is too low.

It's possible to tcmalloc cache increase it with a env var:
TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES=256MB

With default 16MB, performances are  really bad with more than 2 disks.
Increasing to 256MB, it's helping but still have problem with 16 
disks/iothreads.

Jemalloc don't have performance problem with default configuration.

Here the benchmark results in iops of 1 qemu vm randread 4K iodepth=32,
with rbd block backend (librbd is doing a lot of memory allocation),
1 iothread by disk

glibc malloc


1 disk  29052
2 disks 55878
4 disks 127899
8 disks 240566
15 disks269976

jemalloc


1 disk  41278
2 disks 75781
4 disks 195351
8 disks 294241
15 disks298199

tcmalloc 2.2.1 default 16M cache


1 disk   37911
2 disks  67698
4 disks  41076
8 disks  43312
15 disks 37569

tcmalloc : 256M cache
---

1 disk 33914
2 disks58839
4 disks148205
8 disks213298
15 disks   218383

Signed-off-by: Alexandre Derumier 
---
 configure | 29 +
 1 file changed, 29 insertions(+)

diff --git a/configure b/configure
index 222694f..2fe1e05 100755
--- a/configure
+++ b/configure
@@ -336,6 +336,7 @@ vhdx=""
 quorum=""
 numa=""
 tcmalloc="no"
+jemalloc="no"
 
 # parse CC options first
 for opt do
@@ -1147,6 +1148,10 @@ for opt do
   ;;
   --enable-tcmalloc) tcmalloc="yes"
   ;;
+  --disable-jemalloc) jemalloc="no"
+  ;;
+  --enable-jemalloc) jemalloc="yes"
+  ;;
   *)
   echo "ERROR: unknown option $opt"
   echo "Try '$0 --help' for more information"
@@ -1420,6 +1425,8 @@ Advanced options (experts only):
   --enable-numaenable libnuma support
   --disable-tcmalloc   disable tcmalloc support
   --enable-tcmallocenable tcmalloc support
+  --disable-jemalloc   disable jemalloc support
+  --enable-jemallocenable jemalloc support
 
 NOTE: The object files are built at the place where configure is launched
 EOF
@@ -3344,6 +3351,11 @@ EOF
   fi
 fi
 
+if test "$tcmalloc" = "yes" && test "$jemalloc" = "yes" ; then
+echo "ERROR: tcmalloc && jemalloc can't be used at the same time"
+exit 1
+fi
+
 ##
 # tcmalloc probe
 
@@ -3361,6 +3373,22 @@ EOF
 fi
 
 ##
+# jemalloc probe
+
+if test "$jemalloc" = "yes" ; then
+  cat > $TMPC << EOF
+#include 
+int main(void) { malloc(1); return 0; }
+EOF
+
+  if compile_prog "" "-ljemalloc" ; then
+LIBS="-ljemalloc $LIBS"
+  else
+feature_not_found "jemalloc" "install jemalloc devel"
+  fi
+fi
+
+##
 # signalfd probe
 signalfd="no"
 cat > $TMPC << EOF
@@ -4499,6 +4527,7 @@ echo "snappy support$snappy"
 echo "bzip2 support $bzip2"
 echo "NUMA host support $numa"
 echo "tcmalloc support  $tcmalloc"
+echo "jemalloc support  $jemalloc"
 
 if test "$sdl_too_old" = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
-- 
2.1.4




Re: [Qemu-devel] [PATCH v2] util/hbitmap: Add an API to reset all set bits in hbitmap

2015-06-19 Thread Stefan Hajnoczi
On Fri, May 22, 2015 at 09:29:46AM +0800, Wen Congyang wrote:
> The function bdrv_clear_dirty_bitmap() is updated to use
> faster hbitmap_reset_all() call.
> 
> Signed-off-by: Wen Congyang 
> Signed-off-by: zhanghailiang 
> Signed-off-by: Gonglei 
> Acked-by: Paolo Bonzini 
> Reviewed-by: Eric Blake 
> Reviewed-by: John Snow 
> ---
>  block.c|  2 +-
>  include/qemu/hbitmap.h |  8 
>  tests/test-hbitmap.c   | 38 ++
>  util/hbitmap.c | 13 +
>  4 files changed, 60 insertions(+), 1 deletion(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan


pgpYZnSmP4NYI.pgp
Description: PGP signature


Re: [Qemu-devel] incorrect memory size inside vm

2015-06-19 Thread Andrey Korolyov
On Fri, Jun 19, 2015 at 2:14 PM, Piotr Rybicki
 wrote:
> Hello.
>
> Actually it was my mistake.
> After some time using memory in guest (find /, cp bigfine, etc), res size of
> qemu process shrinks to expected value.
>
> Sorry for disturbing.
> Now i don't see any memory waste in guest and host when using 'base' memory
> + 'dimm' memory.
>
> Although i have one issue.
>
> When i start qemu via libvirt with 16GB mem and 1G current mem:
> (...)
>   16777216
>   1048576
> (...)
>
> Qemu starts, and balloon can't free memmory, so guest doesn't boot (It hangs
> or is looped in ' virtio_balloon virtio2: Out of puff! Can't get 1 pages').
> I think this is because dimm memmory is not yet onlined, and balloon already
> tries to shring memory in guest.
>
> Best regards
> Piotr Rybicki
>
>
- libvir@

Please don`t top-post in technical mailing lists. Do you have a
crashkernel-reserved area there in the boot arguments? What
distro/guest kernel are running in this guest and what is dimm
configuration?



Re: [Qemu-devel] incorrect memory size inside vm

2015-06-19 Thread Vasiliy Tolstov
2015-06-19 15:01 GMT+03:00 Andrey Korolyov :
>
> Please don`t top-post in technical mailing lists. Do you have a
> crashkernel-reserved area there in the boot arguments? What
> distro/guest kernel are running in this guest and what is dimm
> configuration?


disabling crashkernel in my case save is about 130-150 Mb,

-- 
Vasiliy Tolstov,
e-mail: v.tols...@selfip.ru



[Qemu-devel] [PATCH v2] vhost_net: fix misuse of assert()

2015-06-19 Thread Greg Kurz
>From assert(3): "assert() is implemented as a macro; if the expression tested
has side-effects, program behavior will be different depending on whether
NDEBUG is defined."

Even if QEMU isn't compiled with NDEBUG, it is bad practice to put bits
with a relevant functionnal meaning in assert().

This is a readability enhancement. The patch does not fix any bug.

Suggested-by: Thomas Huth 
Signed-off-by: Greg Kurz 
---
 hw/net/vhost_net.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

v2: rewrote commit log

diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index f505c91d420a..6d3b7879f8ef 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -376,7 +376,8 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs,
 }
 assert(r >= 0);
 
-assert(vhost_net_set_vnet_endian(dev, ncs[0].peer, false) >= 0);
+r = vhost_net_set_vnet_endian(dev, ncs[0].peer, false);
+assert(r >= 0);
 }
 
 void vhost_net_cleanup(struct vhost_net *net)




Re: [Qemu-devel] [PULL 0/3] cocoa queue

2015-06-19 Thread Peter Maydell
On 19 June 2015 at 11:30, Peter Maydell  wrote:
> Slightly late drain of the cocoa queue. Should be nothing more except
> bugfixes til 2.4 I think.
>
> -- PMM
>
> The following changes since commit 473a49460db0a90bfda046b8f3662b49f94098eb:
>
>   q35: Re-enable FDC on pc-q35-2.3 and older (2015-06-19 09:40:35 +0100)
>
> are available in the git repository at:
>
>   git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-cocoa-20150619-1
>
> for you to fetch changes up to 693a3e01af8082f855094061650311fcaf3e1269:
>
>   ui/cocoa.m: Add machine menu items to change and eject removable drive 
> media (2015-06-19 11:22:31 +0100)
>
> 
> cocoa queue:
>  * Add Machine menu, with entries for pause, resume, reset, power down, and
>media change and eject for removable drives
>
> 

Applied, thanks.

-- PMM



  1   2   3   4   >