socket.c added support for unix domain socket datagram transport

2021-04-22 Thread Ralph Schmieder
Hey...  new to this list.  I was looking for a way to use Unix domain sockets 
as a network transport between local VMs.

I'm part of a team where we run dozens if not hundreds of VMs on a single 
compute instance which are highly interconnected.

In the current implementation, I use UDP sockets (e.g. something like 

-netdev id=bla,type=socket,udp=localhost:1234,localaddr=localhost:5678) 

which works great.

The downside of this approach is that I need to keep track of all the UDP ports 
in use and that there's a potential for clashes.  Clearly, having Unix domain 
sockets where I could store the sockets in the VM's directory would be much 
easier to manage.

However, even though there is some AF_UNIX support in net/socket.c, it's

- not configurable
- it doesn't work

As a side note, I tried to pass in an already open FD, but that didn't work 
either.

So, I added some code which does work for me... e.g.

- can specify the socket paths like -netdev 
id=bla,type=socket,unix=/tmp/in:/tmp/out
- it does forward packets between two Qemu instances running back-to-back

I'm wondering if this is of interest for the wider community and, if so, how to 
proceed.

Thanks,
-ralph

Commit 
https://github.com/rschmied/qemu/commit/73f02114e718ec898c7cd8e855d0d5d5d7abe362




Re: s390-ccw: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]

2021-04-22 Thread Christian Borntraeger




On 23.04.21 08:40, Stefano Garzarella wrote:

On Thu, Apr 22, 2021 at 06:54:21PM +0200, Philippe Mathieu-Daudé wrote:

On 4/22/21 6:07 PM, Thomas Huth wrote:

On 22/04/2021 17.52, Stefano Garzarella wrote:

On Thu, Apr 22, 2021 at 05:38:26PM +0200, Thomas Huth wrote:

On 22/04/2021 16.31, Philippe Mathieu-Daudé wrote:

On 4/22/21 2:41 PM, Christian Borntraeger wrote:

On 22.04.21 13:47, Thomas Huth wrote:

On 22/04/2021 13.24, Philippe Mathieu-Daudé wrote:

On 4/22/21 12:30 PM, Peter Maydell wrote:

On Thu, 22 Apr 2021 at 11:18, Daniel P. Berrangé
 wrote:



This silents the warning however:

-- >8 --
diff --git a/pc-bios/s390-ccw/libc.h b/pc-bios/s390-ccw/libc.h
index bcdc45732d..2dea399904 100644
--- a/pc-bios/s390-ccw/libc.h
+++ b/pc-bios/s390-ccw/libc.h
@@ -19,6 +19,8 @@ typedef unsigned short uint16_t;
  typedef unsigned int   uint32_t;
  typedef unsigned long long uint64_t;

+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-overflow"
  static inline void *memset(void *s, int c, size_t n)
  {
  size_t i;
@@ -30,6 +32,7 @@ static inline void *memset(void *s, int c,
size_t n)

  return s;
  }
+#pragma GCC diagnostic pop


Honestly, that compiler "bug" sounds like it could trigger at any
other spot in the bios code, too, since we are doing lots of direct
accesses to low memory there. I think it's likely best if we shut it
off with -Wno-stringop-overflow in the pc-bios/s390-ccw/Makefile ...
could you please try to add it there?




We are good with:

-- >8 --
diff --git a/pc-bios/s390-ccw/Makefile b/pc-bios/s390-ccw/Makefile
index 29fd9019b8..dcec09b6f9 100644
--- a/pc-bios/s390-ccw/Makefile
+++ b/pc-bios/s390-ccw/Makefile
@@ -8,6 +8,9 @@ CFLAGS = -O2 -g
 quiet-command = $(if $(V),$1,$(if $(2),@printf "  %-7s %s\n" $2 $3 &&
$1, @$1))
 cc-option = $(if $(shell $(CC) $1 -S -o /dev/null -xc /dev/null >
/dev/null \
  2>&1 && echo OK), $1, $2)
+cc-c-option = $(if $(shell $(CC) $1 $2 -c -o /dev/null -xc /dev/null \
+    >/dev/null 2>&1 && echo OK), $2, $3)

 VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.sh %.rc Kconfig% %.json.in
 set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath
$(PATTERN) $1)))
@@ -30,6 +33,7 @@ OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o
menu.o \
  virtio.o virtio-scsi.o virtio-blkdev.o libc.o cio.o
dasd-ipl.o

 QEMU_CFLAGS := -Wall $(filter -W%, $(QEMU_CFLAGS))
+QEMU_CFLAGS += $(call cc-c-option, $(QEMU_CFLAGS),
-Wno-stringop-overflow)
 QEMU_CFLAGS += -ffreestanding -fno-delete-null-pointer-checks


I think you don't need the "cc-c-option" magic here. Just add the
-Wno-stringop-overflow. All supported versions of GCC and Clang
simply silently ignore unknown -Wno-something options (try e.g. "gcc
-Wno-yadayadayada" on the command line).


Clang seems not to like it. It's always a mess to do anything for gcc
and clang :-(


I didn't know we could build s390-ccw with clang.

Not with clang-12:

clang version 12.0.0 (Fedora 12.0.0-0.3.rc1.fc34)

warning: unknown warning option '-Wold-style-declaration'; did you mean
'-Wout-of-line-declaration'? [-Wunknown-warning-option]
warning: unknown warning option '-Wimplicit-fallthrough=2'; did you mean
'-Wimplicit-fallthrough'? [-Wunknown-warning-option]
warning: unknown warning option '-Wno-stringop-overflow'; did you mean
'-Wno-shift-overflow'? [-Wunknown-warning-option]
warning: unknown warning option '-Wold-style-declaration'; did you mean
'-Wout-of-line-declaration'? [-Wunknown-warning-option]
warning: unknown warning option '-Wimplicit-fallthrough=2'; did you mean
'-Wimplicit-fallthrough'? [-Wunknown-warning-option]
warning: unknown warning option '-Wno-stringop-overflow'; did you mean
'-Wno-shift-overflow'? [-Wunknown-warning-option]
error: unknown target CPU 'z900'
note: valid target CPU values are: arch8, z10, arch9, z196, arch10,
zEC12, arch11, z13, arch12, z14, arch13, z15


Ah, I didn't know that, I just tried the unknown -Wno-yadayadayada :-)



We can of course discuss if we compile the BIOS for z10 instead of z900. TCG
in the mean time can handle up to z13 and z10 is now also 13 years old.



Re: [PATCH 0/9] hw/block: m25p80: Fix the mess of dummy bytes needed for fast read commands

2021-04-22 Thread Bin Meng
On Mon, Feb 8, 2021 at 10:41 PM Bin Meng  wrote:
>
> On Thu, Jan 21, 2021 at 10:18 PM Francisco Iglesias
>  wrote:
> >
> > Hi Bin,
> >
> > On [2021 Jan 21] Thu 16:59:51, Bin Meng wrote:
> > > Hi Francisco,
> > >
> > > On Thu, Jan 21, 2021 at 4:50 PM Francisco Iglesias
> > >  wrote:
> > > >
> > > > Dear Bin,
> > > >
> > > > On [2021 Jan 20] Wed 22:20:25, Bin Meng wrote:
> > > > > Hi Francisco,
> > > > >
> > > > > On Tue, Jan 19, 2021 at 9:01 PM Francisco Iglesias
> > > > >  wrote:
> > > > > >
> > > > > > Hi Bin,
> > > > > >
> > > > > > On [2021 Jan 18] Mon 20:32:19, Bin Meng wrote:
> > > > > > > Hi Francisco,
> > > > > > >
> > > > > > > On Mon, Jan 18, 2021 at 6:06 PM Francisco Iglesias
> > > > > > >  wrote:
> > > > > > > >
> > > > > > > > Hi Bin,
> > > > > > > >
> > > > > > > > On [2021 Jan 15] Fri 22:38:18, Bin Meng wrote:
> > > > > > > > > Hi Francisco,
> > > > > > > > >
> > > > > > > > > On Fri, Jan 15, 2021 at 8:26 PM Francisco Iglesias
> > > > > > > > >  wrote:
> > > > > > > > > >
> > > > > > > > > > Hi Bin,
> > > > > > > > > >
> > > > > > > > > > On [2021 Jan 15] Fri 10:07:52, Bin Meng wrote:
> > > > > > > > > > > Hi Francisco,
> > > > > > > > > > >
> > > > > > > > > > > On Fri, Jan 15, 2021 at 2:13 AM Francisco Iglesias
> > > > > > > > > > >  wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Hi Bin,
> > > > > > > > > > > >
> > > > > > > > > > > > On [2021 Jan 14] Thu 23:08:53, Bin Meng wrote:
> > > > > > > > > > > > > From: Bin Meng 
> > > > > > > > > > > > >
> > > > > > > > > > > > > The m25p80 model uses s->needed_bytes to indicate how 
> > > > > > > > > > > > > many follow-up
> > > > > > > > > > > > > bytes are expected to be received after it receives a 
> > > > > > > > > > > > > command. For
> > > > > > > > > > > > > example, depending on the address mode, either 3-byte 
> > > > > > > > > > > > > address or
> > > > > > > > > > > > > 4-byte address is needed.
> > > > > > > > > > > > >
> > > > > > > > > > > > > For fast read family commands, some dummy cycles are 
> > > > > > > > > > > > > required after
> > > > > > > > > > > > > sending the address bytes, and the dummy cycles need 
> > > > > > > > > > > > > to be counted
> > > > > > > > > > > > > in s->needed_bytes. This is where the mess began.
> > > > > > > > > > > > >
> > > > > > > > > > > > > As the variable name (needed_bytes) indicates, the 
> > > > > > > > > > > > > unit is in byte.
> > > > > > > > > > > > > It is not in bit, or cycle. However for some reason 
> > > > > > > > > > > > > the model has
> > > > > > > > > > > > > been using the number of dummy cycles for 
> > > > > > > > > > > > > s->needed_bytes. The right
> > > > > > > > > > > > > approach is to convert the number of dummy cycles to 
> > > > > > > > > > > > > bytes based on
> > > > > > > > > > > > > the SPI protocol, for example, 6 dummy cycles for the 
> > > > > > > > > > > > > Fast Read Quad
> > > > > > > > > > > > > I/O (EBh) should be converted to 3 bytes per the 
> > > > > > > > > > > > > formula (6 * 4 / 8).
> > > > > > > > > > > >
> > > > > > > > > > > > While not being the original implementor I must assume 
> > > > > > > > > > > > that above solution was
> > > > > > > > > > > > considered but not chosen by the developers due to it 
> > > > > > > > > > > > is inaccuracy (it
> > > > > > > > > > > > wouldn't be possible to model exacly 6 dummy cycles, 
> > > > > > > > > > > > only a multiple of 8,
> > > > > > > > > > > > meaning that if the controller is wrongly programmed to 
> > > > > > > > > > > > generate 7 the error
> > > > > > > > > > > > wouldn't be caught and the controller will still be 
> > > > > > > > > > > > considered "correct"). Now
> > > > > > > > > > > > that we have this detail in the implementation I'm in 
> > > > > > > > > > > > favor of keeping it, this
> > > > > > > > > > > > also because the detail is already in use for catching 
> > > > > > > > > > > > exactly above error.
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > I found no clue from the commit message that my proposed 
> > > > > > > > > > > solution here
> > > > > > > > > > > was ever considered, otherwise all SPI controller models 
> > > > > > > > > > > supporting
> > > > > > > > > > > software generation should have been found out seriously 
> > > > > > > > > > > broken long
> > > > > > > > > > > time ago!
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > The controllers you are referring to might lack support for 
> > > > > > > > > > commands requiring
> > > > > > > > > > dummy clock cycles but I really hope they work with the 
> > > > > > > > > > other commands? If so I
> > > > > > > > >
> > > > > > > > > I am not sure why you view dummy clock cycles as something 
> > > > > > > > > special
> > > > > > > > > that needs some special support from the SPI controller. For 
> > > > > > > > > the case
> > > > > > > > > 1 controller, it's nothing special from the controller 
> > > > > > > > > perspective,
> > > > > > > > > just like sending out a command, or

Re: s390-ccw: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]

2021-04-22 Thread Stefano Garzarella

On Thu, Apr 22, 2021 at 06:54:21PM +0200, Philippe Mathieu-Daudé wrote:

On 4/22/21 6:07 PM, Thomas Huth wrote:

On 22/04/2021 17.52, Stefano Garzarella wrote:

On Thu, Apr 22, 2021 at 05:38:26PM +0200, Thomas Huth wrote:

On 22/04/2021 16.31, Philippe Mathieu-Daudé wrote:

On 4/22/21 2:41 PM, Christian Borntraeger wrote:

On 22.04.21 13:47, Thomas Huth wrote:

On 22/04/2021 13.24, Philippe Mathieu-Daudé wrote:

On 4/22/21 12:30 PM, Peter Maydell wrote:

On Thu, 22 Apr 2021 at 11:18, Daniel P. Berrangé
 wrote:



This silents the warning however:

-- >8 --
diff --git a/pc-bios/s390-ccw/libc.h b/pc-bios/s390-ccw/libc.h
index bcdc45732d..2dea399904 100644
--- a/pc-bios/s390-ccw/libc.h
+++ b/pc-bios/s390-ccw/libc.h
@@ -19,6 +19,8 @@ typedef unsigned short uint16_t;
  typedef unsigned int   uint32_t;
  typedef unsigned long long uint64_t;

+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-overflow"
  static inline void *memset(void *s, int c, size_t n)
  {
  size_t i;
@@ -30,6 +32,7 @@ static inline void *memset(void *s, int c,
size_t n)

  return s;
  }
+#pragma GCC diagnostic pop


Honestly, that compiler "bug" sounds like it could trigger at any
other spot in the bios code, too, since we are doing lots of direct
accesses to low memory there. I think it's likely best if we shut it
off with -Wno-stringop-overflow in the pc-bios/s390-ccw/Makefile ...
could you please try to add it there?




We are good with:

-- >8 --
diff --git a/pc-bios/s390-ccw/Makefile b/pc-bios/s390-ccw/Makefile
index 29fd9019b8..dcec09b6f9 100644
--- a/pc-bios/s390-ccw/Makefile
+++ b/pc-bios/s390-ccw/Makefile
@@ -8,6 +8,9 @@ CFLAGS = -O2 -g
 quiet-command = $(if $(V),$1,$(if $(2),@printf "  %-7s %s\n" $2 $3 &&
$1, @$1))
 cc-option = $(if $(shell $(CC) $1 -S -o /dev/null -xc /dev/null >
/dev/null \
  2>&1 && echo OK), $1, $2)
+cc-c-option = $(if $(shell $(CC) $1 $2 -c -o /dev/null -xc /dev/null \
+    >/dev/null 2>&1 && echo OK), $2, $3)

 VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.sh %.rc Kconfig% %.json.in
 set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath
$(PATTERN) $1)))
@@ -30,6 +33,7 @@ OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o
menu.o \
  virtio.o virtio-scsi.o virtio-blkdev.o libc.o cio.o
dasd-ipl.o

 QEMU_CFLAGS := -Wall $(filter -W%, $(QEMU_CFLAGS))
+QEMU_CFLAGS += $(call cc-c-option, $(QEMU_CFLAGS),
-Wno-stringop-overflow)
 QEMU_CFLAGS += -ffreestanding -fno-delete-null-pointer-checks


I think you don't need the "cc-c-option" magic here. Just add the
-Wno-stringop-overflow. All supported versions of GCC and Clang
simply silently ignore unknown -Wno-something options (try e.g. "gcc
-Wno-yadayadayada" on the command line).


Clang seems not to like it. It's always a mess to do anything for gcc
and clang :-(


I didn't know we could build s390-ccw with clang.

Not with clang-12:

clang version 12.0.0 (Fedora 12.0.0-0.3.rc1.fc34)

warning: unknown warning option '-Wold-style-declaration'; did you mean
'-Wout-of-line-declaration'? [-Wunknown-warning-option]
warning: unknown warning option '-Wimplicit-fallthrough=2'; did you mean
'-Wimplicit-fallthrough'? [-Wunknown-warning-option]
warning: unknown warning option '-Wno-stringop-overflow'; did you mean
'-Wno-shift-overflow'? [-Wunknown-warning-option]
warning: unknown warning option '-Wold-style-declaration'; did you mean
'-Wout-of-line-declaration'? [-Wunknown-warning-option]
warning: unknown warning option '-Wimplicit-fallthrough=2'; did you mean
'-Wimplicit-fallthrough'? [-Wunknown-warning-option]
warning: unknown warning option '-Wno-stringop-overflow'; did you mean
'-Wno-shift-overflow'? [-Wunknown-warning-option]
error: unknown target CPU 'z900'
note: valid target CPU values are: arch8, z10, arch9, z196, arch10,
zEC12, arch11, z13, arch12, z14, arch13, z15


Ah, I didn't know that, I just tried the unknown -Wno-yadayadayada :-)




Maybe we can set also `-Wno-unknown-warning-option`.

$ clang -Wno-stringop-overflow -Werror main.c
error: unknown warning option '-Wno-stringop-overflow'; did you mean
'-Wno-shift-overflow'? [-Werror,-Wunknown-warning-option]


D'oh, I was pretty sure that Clang behaves the same with regards to
-Wno-something, but seems I was wrong, sorry.


Np :-) I'm always confused between gcc and clang...



So I think we should simply keep this v1 of Philippe's patch.



Yep, I agree.

Thanks,
Stefano




Re: [PATCH for 6.0] net: check the existence of peer before trying to pad

2021-04-22 Thread Jason Wang



在 2021/4/23 下午1:42, Stefan Weil 写道:

Am 23.04.21 um 05:18 schrieb Jason Wang:


There could be case that peer is NULL. This can happen when during
network device hot-add where net device needs to be added first. So
the patch check the existence of peer before trying to do the pad.

Fixes: 969e50b61a285 ("net: Pad short frames to minimum size before 
sending from SLiRP/TAP")

Signed-off-by: Jason Wang 
---
  include/net/net.h | 5 +
  net/slirp.c   | 2 +-
  net/tap-win32.c   | 2 +-
  net/tap.c | 2 +-
  4 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/include/net/net.h b/include/net/net.h
index eff24519d2..1ef536d771 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -241,4 +241,9 @@ uint32_t net_crc32_le(const uint8_t *p, int len);
  .offset = vmstate_offset_macaddr(_state, _field), 

\

  }
  +static inline bool net_peer_needs_padding(NetClientState *nc)
+{
+  return nc->peer && !nc->peer->do_not_pad;
+}
+
  #endif
diff --git a/net/slirp.c b/net/slirp.c
index a01a0fccd3..7a4e96db5c 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -119,7 +119,7 @@ static ssize_t net_slirp_send_packet(const void 
*pkt,size_t pkt_len,

  uint8_t min_pkt[ETH_ZLEN];
  size_t min_pktsz = sizeof(min_pkt);
  -    if (!s->nc.peer->do_not_pad) {
+    if (net_peer_needs_padding(&s->nc)) {
  if (eth_pad_short_frame(min_pkt, &min_pktsz, pkt, pkt_len)) {
  pkt = min_pkt;
  pkt_len = min_pktsz;
diff --git a/net/tap-win32.c b/net/tap-win32.c
index 897bd18e32..6096972f5d 100644
--- a/net/tap-win32.c
+++ b/net/tap-win32.c
@@ -696,7 +696,7 @@ static void tap_win32_send(void *opaque)
  if (size > 0) {
  orig_buf = buf;
  -    if (!s->nc.peer->do_not_pad) {
+    if (net_peer_needs_padding(&s->nc)) {
  if (eth_pad_short_frame(min_pkt, &min_pktsz, buf, size)) {
  buf = min_pkt;
  size = min_pktsz;
diff --git a/net/tap.c b/net/tap.c
index 7d53cedaec..820872fde8 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -203,7 +203,7 @@ static void tap_send(void *opaque)
  size -= s->host_vnet_hdr_len;
  }
  -    if (!s->nc.peer->do_not_pad) {
+    if (net_peer_needs_padding(&s->nc)) {
  if (eth_pad_short_frame(min_pkt, &min_pktsz, buf, size)) {
  buf = min_pkt;
  size = min_pktsz;



I assume that you had a test case which triggered that null pointer 
access?



Yes, it's simple to trigger by just adding a tap device and assign an IP 
to that.


Thanks



If yes, than this should indeed be applied before releasing 6.0.

The modification is simple enough for a last minute change.

Reviewed-by: Stefan Weil 









Re: [PATCH RFC 0/1] To add HMP interface to dump PCI MSI-X table/PBA

2021-04-22 Thread Jason Wang



在 2021/4/23 下午12:47, Dongli Zhang 写道:

This is inspired by the discussion with Jason on below patchset.

https://lists.gnu.org/archive/html/qemu-devel/2021-03/msg09020.html

The new HMP command is introduced to dump the MSI-X table and PBA.

Initially, I was going to add new option to "info pci". However, as the
number of entries is not determined and the output of MSI-X table is much
more similar to the output of hmp_info_tlb()/hmp_info_mem(), this patch
adds interface for only HMP.

The patch is tagged with RFC because I am looking for suggestions on:

1. Is it fine to add new "info msix " command?



I wonder the reason for not simply reusing "info pci"?




2. Is there any issue with output format?



If it's not for QMP, I guess it's not a part of ABI so it should be fine.




3. Is it fine to add only for HMP, but not QMP?



I think so.

Thanks




Thank you very much!

Dongli Zhang








constant_tsc support for SVM guest

2021-04-22 Thread Wei Huang
There was a customer request for const_tsc support on AMD guests. Right 
now this feature is turned off by default for QEMU x86 CPU types (in 
CPUID_Fn8007_EDX[8]). However we are seeing a discrepancy in guest 
VM behavior between Intel and AMD.


In Linux kernel, Intel x86 code enables X86_FEATURE_CONSTANT_TSC based 
on vCPU's family & model. So it ignores CPUID_Fn8007_EDX[8] and 
guest VMs have const_tsc enabled. On AMD, however, the kernel checks 
CPUID_Fn8007_EDX[8]. So const_tsc is disabled on AMD by default.


I am thinking turning on invtsc for EPYC CPU types (see example below). 
Most AMD server CPUs have supported invariant TSC for a long time. So 
this change is compatible with the hardware behavior. The only problem 
is live migration support, which will be blocked because of invtsc. 
However this problem should be considered very minor because most server 
CPUs support TscRateMsr (see CPUID_Fn800A_EDX[4]), allowing VMs to 
migrate among CPUs with different TSC rates. This live migration 
restriction can be lifted as long as the destination supports TscRateMsr 
or has the same frequency as the source (QEMU/libvirt do it).


[BTW I believe this migration limitation might be unnecessary because it 
is apparently OK for Intel guests to ignore invtsc while claiming 
const_tsc. Have anyone reported issues?]


Do I miss anything here? Any comments about the proposal?

Thanks,
-Wei

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index ad99cad0e7..3c48266884 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -4077,6 +4076,21 @@ static X86CPUDefinition builtin_x86_defs[] = {
 { /* end of list */ }
 }
 },
+{
+.version = 4,
+.alias = "EPYC-IBPB",
+.props = (PropValue[]) {
+{ "ibpb", "on" },
+{ "perfctr-core", "on" },
+{ "clzero", "on" },
+{ "xsaveerptr", "on" },
+{ "xsaves", "on" },
+{ "invtsc", "on" },
+{ "model-id",
+  "AMD EPYC Processor" },
+{ /* end of list */ }
+}
+},
 { /* end of list */ }
 }
 },
@@ -4189,6 +4203,15 @@ static X86CPUDefinition builtin_x86_defs[] = {
 { /* end of list */ }
 }
 },
+{
+.version = 3,
+.props = (PropValue[]) {
+{ "ibrs", "on" },
+{ "amd-ssbd", "on" },
+{ "invtsc", "on" },
+{ /* end of list */ }
+}
+},
 { /* end of list */ }
 }
 },
@@ -4246,6 +4269,17 @@ static X86CPUDefinition builtin_x86_defs[] = {
 .xlevel = 0x801E,
 .model_id = "AMD EPYC-Milan Processor",
 .cache_info = &epyc_milan_cache_info,
+.versions = (X86CPUVersionDefinition[]) {
+{ .version = 1 },
+{
+.version = 2,
+.props = (PropValue[]) {
+{ "invtsc", "on" },
+{ /* end of list */ }
+}
+},
+{ /* end of list */ }
+}



Re: [PATCH for 6.0] net: check the existence of peer before trying to pad

2021-04-22 Thread Stefan Weil

Am 23.04.21 um 05:18 schrieb Jason Wang:


There could be case that peer is NULL. This can happen when during
network device hot-add where net device needs to be added first. So
the patch check the existence of peer before trying to do the pad.

Fixes: 969e50b61a285 ("net: Pad short frames to minimum size before sending from 
SLiRP/TAP")
Signed-off-by: Jason Wang 
---
  include/net/net.h | 5 +
  net/slirp.c   | 2 +-
  net/tap-win32.c   | 2 +-
  net/tap.c | 2 +-
  4 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/include/net/net.h b/include/net/net.h
index eff24519d2..1ef536d771 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -241,4 +241,9 @@ uint32_t net_crc32_le(const uint8_t *p, int len);
  .offset = vmstate_offset_macaddr(_state, _field),   

\

  }
  
+static inline bool net_peer_needs_padding(NetClientState *nc)

+{
+  return nc->peer && !nc->peer->do_not_pad;
+}
+
  #endif
diff --git a/net/slirp.c b/net/slirp.c
index a01a0fccd3..7a4e96db5c 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -119,7 +119,7 @@ static ssize_t net_slirp_send_packet(const void *pkt, 
size_t pkt_len,
  uint8_t min_pkt[ETH_ZLEN];
  size_t min_pktsz = sizeof(min_pkt);
  
-if (!s->nc.peer->do_not_pad) {

+if (net_peer_needs_padding(&s->nc)) {
  if (eth_pad_short_frame(min_pkt, &min_pktsz, pkt, pkt_len)) {
  pkt = min_pkt;
  pkt_len = min_pktsz;
diff --git a/net/tap-win32.c b/net/tap-win32.c
index 897bd18e32..6096972f5d 100644
--- a/net/tap-win32.c
+++ b/net/tap-win32.c
@@ -696,7 +696,7 @@ static void tap_win32_send(void *opaque)
  if (size > 0) {
  orig_buf = buf;
  
-if (!s->nc.peer->do_not_pad) {

+if (net_peer_needs_padding(&s->nc)) {
  if (eth_pad_short_frame(min_pkt, &min_pktsz, buf, size)) {
  buf = min_pkt;
  size = min_pktsz;
diff --git a/net/tap.c b/net/tap.c
index 7d53cedaec..820872fde8 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -203,7 +203,7 @@ static void tap_send(void *opaque)
  size -= s->host_vnet_hdr_len;
  }
  
-if (!s->nc.peer->do_not_pad) {

+if (net_peer_needs_padding(&s->nc)) {
  if (eth_pad_short_frame(min_pkt, &min_pktsz, buf, size)) {
  buf = min_pkt;
  size = min_pktsz;



I assume that you had a test case which triggered that null pointer 
access? If yes, than this should indeed be applied before releasing 6.0.


The modification is simple enough for a last minute change.

Reviewed-by: Stefan Weil 






[PATCH for-6.0 v2 1/2] hw/block/nvme: fix invalid msix exclusive uninit

2021-04-22 Thread Klaus Jensen
From: Klaus Jensen 

Commit 1901b4967c3f changed the nvme device from using a bar exclusive
for MSI-x to sharing it on bar0.

Unfortunately, the msix_uninit_exclusive_bar() call remains in
nvme_exit() which causes havoc when the device is removed with, say,
device_del. Fix this.

Additionally, a subregion is added but it is not removed on exit which
causes a reference to linger and the drive to never be unlocked.

Fixes: 1901b4967c3f ("hw/block/nvme: move msix table and pba to BAR 0")
Signed-off-by: Klaus Jensen 
---
 hw/block/nvme.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 624a1431d072..5fe082ec34c5 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -6235,7 +6235,8 @@ static void nvme_exit(PCIDevice *pci_dev)
 if (n->pmr.dev) {
 host_memory_backend_set_mapped(n->pmr.dev, false);
 }
-msix_uninit_exclusive_bar(pci_dev);
+msix_uninit(pci_dev, &n->bar0, &n->bar0);
+memory_region_del_subregion(&n->bar0, &n->iomem);
 }
 
 static Property nvme_props[] = {
-- 
2.31.1




[PATCH for-6.0 v2 2/2] hw/block/nvme: disable hotplugging for subsystem-linked controllers

2021-04-22 Thread Klaus Jensen
From: Klaus Jensen 

If a controller is linked to a subsystem, do not allow it to be
hotplugged since this will mess up the (possibly shared) namespaces.

Signed-off-by: Klaus Jensen 
---
 hw/block/nvme.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 5fe082ec34c5..7606b58a39b9 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -6140,12 +6140,16 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice 
*pci_dev)
 
 static int nvme_init_subsys(NvmeCtrl *n, Error **errp)
 {
+DeviceClass *dc;
 int cntlid;
 
 if (!n->subsys) {
 return 0;
 }
 
+dc = DEVICE_GET_CLASS(n);
+dc->hotpluggable = false;
+
 cntlid = nvme_subsys_register_ctrl(n, errp);
 if (cntlid < 0) {
 return -1;
-- 
2.31.1




[PATCH for-6.0 v2 0/2] hw/block/nvme: fix msix uninit

2021-04-22 Thread Klaus Jensen
From: Klaus Jensen 

First patch fixes a regression where msix is not correctly uninit'ed
when an nvme device is hotplugged with device_del. When viewed in
conjunction with the commit that introduced the bug (commit
1901b4967c3f), I think the fix looks relatively obvious.

Second patch disables hotplugging for nvme controllers that are
connected to subsystems since the way namespaces are connected to the
nvme controller bus is messed up by removing the device. This bug causes
a segfault but is *not* a regression and is related to an experimental
feature.

v2:
  - remove memory subregion as well
  - add (possible) patch to disable hotplugging on subsystem connected
controllers

Klaus Jensen (2):
  hw/block/nvme: fix invalid msix exclusive uninit
  hw/block/nvme: disable hotplugging for subsystem-linked controllers

 hw/block/nvme.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

-- 
2.31.1




[PATCH RFC 1/1] msix: add hmp interface to dump MSI-X info

2021-04-22 Thread Dongli Zhang
This patch is to add the HMP interface to dump MSI-X table and PBA, in
order to help diagnose the loss of IRQ issue in VM (e.g., if an MSI-X
vector is erroneously masked permanently). Here is the example with
vhost-scsi:

(qemu) info msix /machine/peripheral/vscsi0
MSI-X Table
0xfee01004 0x 0x0022 0x
0xfee02004 0x 0x0023 0x
0xfee01004 0x 0x0023 0x
0xfee01004 0x 0x0021 0x
0xfee02004 0x 0x0022 0x
0x 0x 0x 0x0001
0x 0x 0x 0x0001
MSI-X PBA
0 0 0 0 0 0 0

Since the number of MSI-X entries is not determined and might be very
large, it is sometimes inappropriate to dump via QMP.

Therefore, this patch dumps MSI-X information only via HMP, which is
similar to the implementation of hmp_info_mem().

Cc: Jason Wang 
Cc: Joe Jin 
Signed-off-by: Dongli Zhang 
---
 hmp-commands-info.hx   | 13 +++
 hw/pci/msix.c  | 49 ++
 include/hw/pci/msix.h  |  2 ++
 include/monitor/hmp.h  |  1 +
 softmmu/qdev-monitor.c | 25 +
 5 files changed, 90 insertions(+)

diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index ab0c7aa5ee..cbd056442b 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -221,6 +221,19 @@ SRST
 Show PCI information.
 ERST
 
+{
+.name   = "msix",
+.args_type  = "dev:s",
+.params = "dev",
+.help   = "dump MSI-X information",
+.cmd= hmp_info_msix,
+},
+
+SRST
+  ``info msix`` *dev*
+Dump MSI-X information for device *dev*.
+ERST
+
 #if defined(TARGET_I386) || defined(TARGET_SH4) || defined(TARGET_SPARC) || \
 defined(TARGET_PPC) || defined(TARGET_XTENSA) || defined(TARGET_M68K)
 {
diff --git a/hw/pci/msix.c b/hw/pci/msix.c
index ae9331cd0b..a93d31da9f 100644
--- a/hw/pci/msix.c
+++ b/hw/pci/msix.c
@@ -22,6 +22,7 @@
 #include "sysemu/xen.h"
 #include "migration/qemu-file-types.h"
 #include "migration/vmstate.h"
+#include "monitor/monitor.h"
 #include "qemu/range.h"
 #include "qapi/error.h"
 #include "trace.h"
@@ -669,3 +670,51 @@ const VMStateDescription vmstate_msix = {
 VMSTATE_END_OF_LIST()
 }
 };
+
+static void msix_dump_table(Monitor *mon, PCIDevice *dev)
+{
+int vector, i, offset;
+uint32_t val;
+
+monitor_printf(mon, "MSI-X Table\n");
+
+for (vector = 0; vector < dev->msix_entries_nr; vector++) {
+for (i = 0; i < 4; i++) {
+offset = vector * PCI_MSIX_ENTRY_SIZE + i * 4;
+val = pci_get_long(dev->msix_table + offset);
+
+monitor_printf(mon, "0x%08x ", val);
+}
+monitor_printf(mon, "\n");
+}
+}
+
+static void msix_dump_pba(Monitor *mon, PCIDevice *dev)
+{
+int vector;
+
+monitor_printf(mon, "MSI-X PBA\n");
+
+for (vector = 0; vector < dev->msix_entries_nr; vector++) {
+monitor_printf(mon, "%d ", !!msix_is_pending(dev, vector));
+
+if (vector % 16 == 15) {
+monitor_printf(mon, "\n");
+}
+}
+
+if (vector % 16 != 15) {
+monitor_printf(mon, "\n");
+}
+}
+
+void msix_dump_info(Monitor *mon, PCIDevice *dev, Error **errp)
+{
+if (!msix_present(dev)) {
+error_setg(errp, "MSI-X not available");
+return;
+}
+
+msix_dump_table(mon, dev);
+msix_dump_pba(mon, dev);
+}
diff --git a/include/hw/pci/msix.h b/include/hw/pci/msix.h
index 4c4a60c739..10a4500295 100644
--- a/include/hw/pci/msix.h
+++ b/include/hw/pci/msix.h
@@ -47,6 +47,8 @@ int msix_set_vector_notifiers(PCIDevice *dev,
   MSIVectorPollNotifier poll_notifier);
 void msix_unset_vector_notifiers(PCIDevice *dev);
 
+void msix_dump_info(Monitor *mon, PCIDevice *dev, Error **errp);
+
 extern const VMStateDescription vmstate_msix;
 
 #define VMSTATE_MSIX_TEST(_field, _state, _test) {   \
diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h
index 605d57287a..46e0efc213 100644
--- a/include/monitor/hmp.h
+++ b/include/monitor/hmp.h
@@ -36,6 +36,7 @@ void hmp_info_irq(Monitor *mon, const QDict *qdict);
 void hmp_info_pic(Monitor *mon, const QDict *qdict);
 void hmp_info_rdma(Monitor *mon, const QDict *qdict);
 void hmp_info_pci(Monitor *mon, const QDict *qdict);
+void hmp_info_msix(Monitor *mon, const QDict *qdict);
 void hmp_info_tpm(Monitor *mon, const QDict *qdict);
 void hmp_info_iothreads(Monitor *mon, const QDict *qdict);
 void hmp_quit(Monitor *mon, const QDict *qdict);
diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
index a9955b97a0..2a37d03fb7 100644
--- a/softmmu/qdev-monitor.c
+++ b/softmmu/qdev-monitor.c
@@ -19,6 +19,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/sysbus.h"
+#include "hw/pci/msix.h"
 #include "monitor/hmp.h"
 #include "monitor/monitor.h"
 #include "monitor/qdev.h"
@@ -1006,3 +1007,27 @@ bool qmp_command_available(const QmpCommand *cmd, Error 
**errp)
 }
 return tru

[PATCH RFC 0/1] To add HMP interface to dump PCI MSI-X table/PBA

2021-04-22 Thread Dongli Zhang
This is inspired by the discussion with Jason on below patchset.

https://lists.gnu.org/archive/html/qemu-devel/2021-03/msg09020.html

The new HMP command is introduced to dump the MSI-X table and PBA.

Initially, I was going to add new option to "info pci". However, as the
number of entries is not determined and the output of MSI-X table is much
more similar to the output of hmp_info_tlb()/hmp_info_mem(), this patch
adds interface for only HMP.

The patch is tagged with RFC because I am looking for suggestions on:

1. Is it fine to add new "info msix " command?

2. Is there any issue with output format?

3. Is it fine to add only for HMP, but not QMP?

Thank you very much!

Dongli Zhang





[Bug 1580459] Re: Windows (10?) guest freezes entire host on shutdown if using PCI passthrough

2021-04-22 Thread Thomas Huth
Ok, thanks for answering! So I'm closing this issue now. In case anybody
still has similar issues, please open a new bug ticket instead.

** Changed in: qemu
   Status: Incomplete => Fix Released

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1580459

Title:
  Windows (10?) guest freezes entire host on shutdown if using PCI
  passthrough

Status in libvirt:
  New
Status in QEMU:
  Fix Released
Status in Arch Linux:
  New
Status in Debian:
  New
Status in Fedora:
  New

Bug description:
  Problem: after leaving a Windows VM that uses PCI passthrough (as we
  do for gaming graphics cards, sound cards, and in my case, a USB card)
  running for some amount of time between 1 and 2 hours (it's not
  consistent with exactly how long), and for any amount of time longer
  than that, shutting down that guest will, right as it finishes
  shutting down, freeze the host computer, making it require a hard
  reboot. Unbinding (or in the other user's case, unbinding and THEN
  binding) any PCI device in sysfs, even one that has nothing to do with
  the VM, also has the same effect as shutting down the VM (if the VM
  has been running long enough). So, it's probably an issue related to
  unbinding and binding PCI devices.

  There's a lot of info on this problem over at 
https://bbs.archlinux.org/viewtopic.php?id=206050
  Here's a better-organized list of main details:
  -at least 2 confirmed victims of this bug; 2 (including me) have provided 
lots of info in the link
  -I'm on Arch Linux and the other one is on Gentoo (distro-nonspecific)
  -issue affects my Windows 10 guest and others' Windows guests, but not my 
Arch Linux guest (the others don't have non-Windows guests to test)
  -I'm using libvirt but the other user is not, so it's not an issue with 
libvirt
  -It seems to be version non-specific, too. I first noticed it at, or when 
testing versions still had the issue at (whichever version is lower), Linux 4.1 
and qemu 2.4.0. It still persists in all releases of both since, including the 
newest ones.
  -I can't track down exactly what package downgrade can fix it, as downgrading 
further than Linux 4.1 and qemu 2.4.0 requires Herculean and system-destroying 
changes such as downgrading ncurses, meaning I don't know whether it's a bug in 
QEMU, the Linux kernel, or some weird seemingly unrelated thing.
  -According to the other user, "graphics intensive gameplay (GTA V) can cause 
the crash to happen sooner," as soon as "15 minutes"
  -Also, "bringing up a second passthrough VM with separate hardware will cause 
the same crash," and "bringing up another VM before the two-hour mark will not 
result in a crash," further cementing that it's triggered by the un/binding of 
PCI devices.
  -This is NOT related to the very similar bug that can be worked around by not 
passing through the HDMI device or sound card. Even when we removed all traces 
of any sort of sound card from the VM, it still had the same behavior.

To manage notifications about this bug go to:
https://bugs.launchpad.net/libvirt/+bug/1580459/+subscriptions



[Bug 1395217] Re: Networking in qemu 2.0.0 and beyond is not compatible with Open Solaris (Illumos) 5.11

2021-04-22 Thread Launchpad Bug Tracker
[Expired for QEMU because there has been no activity for 60 days.]

** Changed in: qemu
   Status: Incomplete => Expired

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1395217

Title:
  Networking in qemu 2.0.0 and beyond is not compatible with Open
  Solaris (Illumos) 5.11

Status in QEMU:
  Expired

Bug description:
  The networking code in qemu in versions 2.0.0 and beyond is non-
  functional with Solaris/Illumos 5.11 images.

  Building 1.7.1, 2.0.0, 2.0.2, 2.1.2,and 2.2.0rc1with the following
  standard Slackware config:

  # From Slackware build tree . . . 
  ./configure \
--prefix=/usr \
--libdir=/usr/lib64 \
--sysconfdir=/etc \
--localstatedir=/var \
--enable-gtk \
--enable-system \
--enable-kvm \
--disable-debug-info \
--enable-virtfs \
--enable-sdl \
--audio-drv-list=alsa,oss,sdl,esd \
--enable-libusb \
--disable-vnc \
--target-list=x86_64-linux-user,i386-linux-user,x86_64-softmmu,i386-softmmu 
\
--enable-spice \
--enable-usb-redir 

  
  And attempting to run the same VM image with the following command (or via 
virt-manager):

  macaddress="DE:AD:BE:EF:3F:A4"

  qemu-system-x86_64 nex4x -cdrom /dev/cdrom -name "Nex41" -cpu Westmere
  -machine accel=kvm -smp 2 -m 4000 -net nic,macaddr=$macaddress  -net 
bridge,br=b
  r0 -net dump,file=/usr1/tmp/ -drive file=nex4x_d1 -drive 
file=nex4x_d2
   -enable-kvm

  Gives success on 1.7.1, and a deaf VM on all subsequent versions.

  Notable in validating my config, is that a Windows 7 image runs
  cleanly with networking on *all* builds, so my configuration appears
  to be good - qemu just hates Solaris at this point.

  Watching with wireshark (as well as pulling network traces from qemu
  as noted above) it appears that the notable difference in the two
  configs is that for some reason, Solaris gets stuck arping for it's
  own interface on startup, and never really comes on line on the
  network.  If other hosts attempt to ping the Solaris instance, they
  can successfully arp the bad VM, but not the other way around.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1395217/+subscriptions



[Bug 1778966] Re: Windows 1803 and later crashes on KVM

2021-04-22 Thread Launchpad Bug Tracker
[Expired for QEMU because there has been no activity for 60 days.]

** Changed in: qemu
   Status: Incomplete => Expired

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1778966

Title:
  Windows 1803 and later crashes on KVM

Status in QEMU:
  Expired

Bug description:
  For a bionic host, using the current public kvm modules, KVM is not
  capable of booting a WindowsInsider or msdn Windows 1803 Windows
  Server iso. In snstalling from an ISO from a started windows 2016
  guest results in an unbootable and unrepairable guest.

  The hardware is a threadripper 1920x with 32GB of main memory, disk
  mydigital BPX SSD and WD based 4 column RAID 5 via mdadm.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1778966/+subscriptions



[Bug 1615212] Re: SDL UI switching to monitor half-broken and scrolling broken

2021-04-22 Thread Launchpad Bug Tracker
[Expired for QEMU because there has been no activity for 60 days.]

** Changed in: qemu
   Status: Incomplete => Expired

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1615212

Title:
  SDL UI switching to monitor half-broken and scrolling broken

Status in QEMU:
  Expired

Bug description:
  ctrl+alt+2 must be pressed 2 or more times for the monitor console
  window to appear with -sdl, the window flashes and disappears also
  before finally staying open

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1615212/+subscriptions



[Bug 1725707] Re: QEMU sends excess VNC data to websockify even when network is poor

2021-04-22 Thread Launchpad Bug Tracker
[Expired for QEMU because there has been no activity for 60 days.]

** Changed in: qemu
   Status: Incomplete => Expired

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1725707

Title:
  QEMU sends excess VNC data to websockify even when network is poor

Status in QEMU:
  Expired

Bug description:
  Description of problem
  -
  In my latest topic, I reported a bug relate to QEMU's websocket:
  https://bugs.launchpad.net/qemu/+bug/1718964

  It has been fixed but someone mentioned that he met the same problem when 
using QEMU with a standalone websocket proxy.
  That makes me confused because in that scenario QEMU will get a "RAW" VNC 
connection.
  So I did a test and found that there indeed existed some problems. The 
problem is:

  When the client's network is poor (on a low speed WAN), QEMU still
  sends a lot of data to the websocket proxy, then the client get stuck.
  It seems that only QEMU has this problem, other VNC servers works
  fine.

  Environment
  -
  All of the following versions have been tested:

  QEMU: 2.8.1.1 / 2.9.1 / 2.10.1 / master (Up to date)
  Host OS: Ubuntu 16.04 Server LTS / CentOS 7 x86_64_1611
  Websocket Proxy: websockify 0.6.0 / 0.7.0 / 0.8.0 / master
  VNC Web Client: noVNC 0.5.1 / 0.61 / 0.62 / master
  Other VNC Servers: TigerVNC 1.8 / x11vnc 0.9.13 / TightVNC 2.8.8

  Steps to reproduce:
  -
  100% reproducible.

  1. Launch a QEMU instance (No need websocket option):
  qemu-system-x86_64 -enable-kvm -m 6G ./win_x64.qcow2 -vnc :0

  2. Launch websockify on a separate host and connect to QEMU's VNC port

  3. Open VNC Web Client (noVNC/vnc.html) in browser and connect to
  websockify

  4. Play a video (e.g. Watch YouTube) on VM (To produce a lot of frame
  buffer update)

  5. Limit (e.g. Use NetLimiter) the client inbound bandwidth to 300KB/S
  (To simulate a low speed WAN)

  6. Then client's output gets stuck(less than 1 fps), the cursor is
  almost impossible to move

  7. Monitor network traffic on the proxy server

  Current result:
  -
  Monitor Downlink/Uplink network traffic on the proxy server
  (Refer to the attachments for more details).

  1. Used with QEMU
  - D: 5.9 MB/s U: 5.7 MB/s (Client on LAN)
  - D: 4.3 MB/s U: 334 KB/s (Client on WAN)

  2. Used with other VNC servers
  - D: 5.9 MB/s U: 5.6 MB/s (Client on LAN)
  - D: 369 KB/s U: 328 KB/s (Client on WAN)

  It is found that when the client's network is poor, all the VNC
  servers (tigervnc/x11vnc/tightvnc) will reduce the VNC data send to
  websocket proxy (uplink and downlink symmetry), but QEMU never drop
  any frames and still sends a lot of data to websockify, the client has
  no capacity to accept so much data, more and more data are accumulated
  in the websockify, then it crashes.

  Expected results:
  -
  When the client's network is poor (WAN), QEMU will reduce the VNC data send 
to websocket proxy.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1725707/+subscriptions



[Bug 1820247] Re: QEMU random crash caused by libspice-server

2021-04-22 Thread Launchpad Bug Tracker
[Expired for QEMU because there has been no activity for 60 days.]

** Changed in: qemu
   Status: Incomplete => Expired

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1820247

Title:
  QEMU random crash caused by libspice-server

Status in QEMU:
  Expired

Bug description:
  Hi,

  One of our OpenStack instances crashed. It seems there was some
  problem related to SPICE. Attaching what we had in qemu log. Also
  sending our versions:

  Linux pre-node1 4.18.0-13-generic #14~18.04.1-Ubuntu SMP Thu Dec 6
  14:09:52 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

  QEMU emulator version 2.11.1(Debian 1:2.11+dfsg-1ubuntu7.9)
  Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers

  
  root@pre-node1:~# cat /var/log/libvirt/qemu/instance-0038.log 
  2019-03-10 20:39:36.510+: starting up libvirt version: 4.0.0, package: 
1ubuntu8.6 (Christian Ehrhardt  Fri, 09 Nov 
2018 07:42:01 +0100), qemu version: 2.11.1(Debian 1:2.11+dfsg-1ubuntu7.9), 
hostname: pre-node1
  LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 
QEMU_AUDIO_DRV=spice /usr/bin/kvm-spice -name 
guest=instance-0038,debug-threads=on -S -object 
secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-5-instance-0038/master-key.aes
 -machine pc-i440fx-bionic,accel=kvm,usb=off,dump-guest-core=off,mem-merge=off 
-cpu 
Skylake-Server-IBRS,ss=on,hypervisor=on,tsc_adjust=on,clflushopt=on,pku=on,ssbd=on,xsaves=on
 -m 2048 -realtime mlock=on -smp 2,sockets=1,cores=1,threads=2 -object 
memory-backend-file,id=ram-node0,prealloc=yes,mem-path=/dev/hugepages/libvirt/qemu/5-instance-0038,share=yes,size=2147483648,host-nodes=0,policy=bind
 -numa node,nodeid=0,cpus=0-1,memdev=ram-node0 -uuid 
3c3d04f3-4b25-4ea5-8836-0e06eef9dcb7 -smbios 'type=1,manufacturer=OpenStack 
Foundation,product=OpenStack 
Nova,version=18.1.1,serial=93fa1a55-ba3a-4a99-80b3-3a7bb4e964af,uuid=3c3d04f3-4b25-4ea5-8836-0e06eef9dcb7,family=Virtual
 Machine' -no-user-config -nodefaults -chardev 
socket,id=charmonitor,path=/var/lib/libvirt/qemu/domain-5-instance-0038/monitor.sock,server,nowait
 -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc,driftfix=slew 
-global kvm-pit.lost_tick_policy=delay -no-hpet -no-shutdown -boot strict=on 
-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -device 
virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x3 -drive 
file=/var/lib/nova/instances/3c3d04f3-4b25-4ea5-8836-0e06eef9dcb7/disk,format=qcow2,if=none,id=drive-virtio-disk0,cache=none,discard=ignore,throttling.iops-read=5000,throttling.iops-write=5000
 -device 
virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1
 -add-fd set=0,fd=29 -chardev 
pty,id=charserial0,logfile=/dev/fdset/0,logappend=on -device 
isa-serial,chardev=charserial0,id=serial0 -chardev 
spicevmc,id=charchannel0,name=vdagent -device 
virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=com.redhat.spice.0
 -spice port=5900,addr=10.252.0.101,disable-ticketing,seamless-migration=on 
-device 
qxl-vga,id=video0,ram_size=67108864,vram_size=67108864,vram64_size_mb=0,vgamem_mb=16,max_outputs=1,bus=pci.0,addr=0x2
 -device vfio-pci,host=25:04.1,id=hostdev0,bus=pci.0,addr=0x5 -device 
virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6 -msg timestamp=on
  2019-03-10T20:39:36.568276Z qemu-system-x86_64: -chardev 
pty,id=charserial0,logfile=/dev/fdset/0,logappend=on: char device redirected to 
/dev/pts/2 (label charserial0)
  inputs_channel_detach_tablet: 
  main_channel_link: add main channel client
  main_channel_client_handle_pong: net test: latency 32.76 ms, bitrate 
33384953 bps (31.838372 Mbps)
  red_qxl_set_cursor_peer: 
  inputs_connect: inputs channel client create

  (process:65324): Spice-WARNING **: 16:35:23.769: Failed to create channel 
client: Client 0x55e7c157e970: duplicate channel type 2 id 0
  red_qxl_set_cursor_peer: 

  (process:65324): Spice-WARNING **: 16:35:24.142: Failed to create
  channel client: Client 0x55e7c157e970: duplicate channel type 4 id 0

  (process:65324): Spice-CRITICAL **: 16:35:24.142: 
cursor-channel.c:353:cursor_channel_connect: condition `ccc != NULL' failed
  2019-03-13 15:35:31.785+: shutting down, reason=crashed


  
  I am also attaching some gdb information extracted from qemu crash dump file. 
These are backtraces of particular threads within the crashed QEMU process.

  
  Thread 9 (Thread 0x7f69649ea5c0 (LWP 65324)):
  #0  0x7f695f02d2b7 in __libc_write (fd=26, buf=0x7ffc33f5b330, nbytes=56) 
at ../sysdeps/unix/sysv/linux/write.c:27
  #1  0x7f695ff30ed3 in  () at 
/usr/lib/x86_64-linux-gnu/libspice-server.so.1
  #2  0x7f695ff316ce in  () at 
/usr/lib/x86_64-linux-gnu/libspice-server.so.1
  #3  0x7f695ff52db6 in  () at 
/usr/lib/x86_64-linux-gnu/libspice-server.so.1
  #4  0x7f695ff58e38 in  () at 
/usr/lib/x86_64-linux-gnu

[Bug 1879425] Re: The thread of "CPU 0 /KVM" keeping 99.9%CPU

2021-04-22 Thread Launchpad Bug Tracker
[Expired for QEMU because there has been no activity for 60 days.]

** Changed in: qemu
   Status: Incomplete => Expired

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1879425

Title:
  The thread of "CPU 0 /KVM" keeping 99.9%CPU

Status in QEMU:
  Expired

Bug description:
  Hi Expert:

  The VM is hung here after (2, or 3, or 5 and the longest time is 10 hours) by 
qemu-kvm.
  Notes:
  for VM:
    OS: RHEL8.1
    CPU: 1
    MEM:4G
  For qemu-kvm(host kernel RHEL7):
    1) version:
   /usr/libexec/qemu-kvm -version
   QEMU emulator version 2.10.0(qemu-kvm-ev-2.10.0-21.el7_5.4.1)
    2) once the issue is occurred, the CPU of "CPU0 /KVM" is more than 99% by 
com "top -p VM_pro_ID"
  PID  UDER   PR NI RES   S  % CPU %MEM  TIME+COMMAND
  872067   qemu   20 0  1.6g  R   99.9  0.6  37:08.87 CPU 0/KVM
    3) use "pstack 493307" and below is function trace
  Thread 1 (Thread 0x7f2572e73040 (LWP 872067)):
  #0  0x7f256cad8fcf in ppoll () from /lib64/libc.so.6
  #1  0x55ff34bdf4a9 in qemu_poll_ns ()
  #2  0x55ff34be02a8 in main_loop_wait ()
  #3  0x55ff348bfb1a in main ()
    4) use strace "strace -tt -ff -p 872067 -o cfx" and below log keep printing
  21:24:02.977833 ppoll([{fd=4, events=POLLIN}, {fd=6, events=POLLIN}, {fd=8, 
events=POLLIN}, {fd=9, events=POLLIN}, {fd=80, events=POLLIN}, {fd=82, 
events=POLLIN}, {fd=84, events=POLLIN}, {fd=115, events=POLLIN}, {fd=121, 
events=POLLIN}], 9, {0, 0}, NULL, 8) = 0 (Timeout)
  21:24:02.977918 ppoll([{fd=4, events=POLLIN}, {fd=6, events=POLLIN}, {fd=8, 
events=POLLIN}, {fd=9, events=POLLIN}, {fd=80, events=POLLIN}, {fd=82, 
events=POLLIN}, {fd=84, events=POLLIN}, {fd=115, events=POLLIN}, {fd=121, 
events=POLLIN}], 9, {0, 911447}, NULL, 8) = 0 (Timeout)
  21:24:02.978945 ppoll([{fd=4, events=POLLIN}, {fd=6, events=POLLIN}, {fd=8, 
events=POLLIN}, {fd=9, events=POLLIN}, {fd=80, events=POLLIN}, {fd=82, 
events=POLLIN}, {fd=84, events=POLLIN}, {fd=115, events=POLLIN}, {fd=121, 
events=POLLIN}], 9, {0, 0}, NULL, 8) = 0 (Timeout)
  Therefore, I think the thread "CPU 0/KVM" is in tight loop.
    5) use reset can recover this issue. however, it will reoccurred again.
  Current work around is increase one CPU for this VM, then issue is gone.

  thanks
  Cliff

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1879425/+subscriptions



[Bug 1642421] Re: qemu-system-x86_64: ipv6 and dns is broken with netdev user

2021-04-22 Thread Launchpad Bug Tracker
[Expired for QEMU because there has been no activity for 60 days.]

** Changed in: qemu
   Status: Incomplete => Expired

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1642421

Title:
  qemu-system-x86_64: ipv6 and dns is broken with netdev user

Status in QEMU:
  Expired

Bug description:
  Hi,

  dhcp inside qemu returns an ipv6 address as dns-server. However this is not
  working. If i replace it with the ipv4 address '10.0.0.2' dns is working
  again. I would expect that the qemu emulated dhcp server responds either an
  ipv4 configuration that is working or its dns server/forwarder listens on the
  ipv6 address returned by the emulated dhcp server.

  I used latest qemu from git (
  b0bcc86d2a87456f5a276f941dc775b265b309cf) and used the following
  commands:

  $ ./qemu-system-x86_64 -enable-kvm -M pc -device virtio-rng-pci -device
  virtio-net-pci,netdev=user.0 -drive file=buildenv.img,if=virtio,bus=1,unit=0
  -no-reboot -netdev 
user,id=user.0,hostfwd=tcp::5022-:22,hostfwd=tcp::7587-:7588
  -m 1024 -usb -nographic -smp 4

  buildenv.img is a debian jessie amd64 installation.

  Inside qemu the network is configured to use dhcp:

  $ cat /etc/network/interfaces
  allow-hotplug eth0
  iface eth0 inet dhcp

  $ ifconfig eth0
  eth0  Link encap:Ethernet  HWaddr 52:54:00:12:34:56
inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
inet6 addr: fe80::5054:ff:fe12:3456/64 Scope:Link
inet6 addr: fec0::5054:ff:fe12:3456/64 Scope:Site
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:10 errors:0 dropped:0 overruns:0 frame:0
TX packets:28 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3215 (3.1 KiB)  TX bytes:3638 (3.5 KiB)

  $ cat /etc/resolv.conf
  nameserver fec0::3

  $ arp google.de
  google.de: Host name lookup failure

  $ strace -f arp google.de
  ...
  socket(PF_INET6, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 4
  connect(4, {sa_family=AF_INET6, sin6_port=htons(53), inet_pton(AF_INET6, 
"fec0::3", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = 0
  poll([{fd=4, events=POLLOUT}], 1, 0)= 1 ([{fd=4, revents=POLLOUT}])
  sendto(4, "\17\320\1\0\0\1\0\0\0\0\0\0\6google\2de\0\0\1\0\1", 27, 
MSG_NOSIGNAL, NULL, 0) = 27
  poll([{fd=4, events=POLLIN}], 1, 5000)  = 0 (Timeout)
  poll([{fd=4, events=POLLOUT}], 1, 0)= 1 ([{fd=4, revents=POLLOUT}])
  sendto(4, "\17\320\1\0\0\1\0\0\0\0\0\0\6google\2de\0\0\1\0\1", 27, 
MSG_NOSIGNAL, NULL, 0) = 27
  poll([{fd=4, events=POLLIN}], 1, 5000)  = 0 (Timeout)
  close(4)= 0
  ...

  $ echo nameserver 10.0.0.2 > /etc/resolv.conf

  $ arp google.de
  google.de (216.58.208.35) -- no entry

  Note: I reported this bug also to debian: https://bugs.debian.org/cgi-
  bin/bugreport.cgi?bug=844566

  Regards,

Manuel

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1642421/+subscriptions



Re: [PATCH 1/4] target/ppc: Code motion required to build disabling tcg

2021-04-22 Thread David Gibson
On Thu, Apr 22, 2021 at 04:35:34PM -0300, Fabiano Rosas wrote:
> Bruno Piazera Larsen  writes:
> 
> >> > You are correct! I've just tweaked the code that defines spr_register and
> >> > it should be working now. I'm still working in splitting the SPR 
> >> > functions
> >> > from translate_init, since I think it would make it easier to prepare the
> >> > !TCG case and for adding new architectures in the future, and I found a
> >> > few more problems:
> >>
> >> Actually looking at the stuff below, I suspect that separating our
> >> "spr" logic specifically might be a bad idea.  At least some of the
> >> SPRs control pretty fundamental things about how the processor
> >> operates, and I suspect separating it from the main translation logic
> >> may be more trouble than it's worth.
> 
> I disagree with the code proximity argument. Having TCG code clearly
> separate from common code seems more important to me than having the SPR
> callbacks close to the init_proc functions.

Hmm.. I may be misinterpreting what you're intending here.  I
certainly agree that separating TCG only code from common code is a
good idea.  My point, though, is that the vast majority of the SPR
code *is* TCG specific - there are just a relatively few cases where
SPRs have a common path.  That basically only happens when a) the SPR
can be affected by means other than the guest executing instructions
specifically to do that (i.e. usually by hypercalls) and b) accessing
the SPR has some side effects that need to be handled in both TCG and
KVM cases

From the descriptions it sounded like you were trying to separate
*all* SPR code, not just these specific cases from the translation
core, and that's what I'm saying is a bad idea.

> But maybe we should take a look at this RFC before we start discussing
> personal preference too much.
> 
> > Well, all the errors that I got were related to to read/write functions, 
> > which
> > I was already separating into a spr_tcg file. The solutions I can see are to
> > include this file in translate.c, and either have the read/write functions 
> > not be
> > static, or include the spr_common.c in translate as well, but only for TCG
> > builds. Both solutions sound pretty bad imo, but the first sounds less bad,
> > because it's a bit less complexity in the build process.
> 
> It would be helpful if we could apply these patches and do some
> experimentation before recommending a solution. So I would pick the less
> bad for now. Mention it in the cover letter and then we can discuss
> looking at something more concrete.
> 

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [PATCH for 6.0] net: check the existence of peer before trying to pad

2021-04-22 Thread Bin Meng
On Fri, Apr 23, 2021 at 11:18 AM Jason Wang  wrote:
>
> There could be case that peer is NULL. This can happen when during
> network device hot-add where net device needs to be added first. So
> the patch check the existence of peer before trying to do the pad.
>
> Fixes: 969e50b61a285 ("net: Pad short frames to minimum size before sending 
> from SLiRP/TAP")
> Signed-off-by: Jason Wang 
> ---
>  include/net/net.h | 5 +
>  net/slirp.c   | 2 +-
>  net/tap-win32.c   | 2 +-
>  net/tap.c | 2 +-
>  4 files changed, 8 insertions(+), 3 deletions(-)
>

Reviewed-by: Bin Meng 



[PATCH for 6.0] net: check the existence of peer before trying to pad

2021-04-22 Thread Jason Wang
There could be case that peer is NULL. This can happen when during
network device hot-add where net device needs to be added first. So
the patch check the existence of peer before trying to do the pad.

Fixes: 969e50b61a285 ("net: Pad short frames to minimum size before sending 
from SLiRP/TAP")
Signed-off-by: Jason Wang 
---
 include/net/net.h | 5 +
 net/slirp.c   | 2 +-
 net/tap-win32.c   | 2 +-
 net/tap.c | 2 +-
 4 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/include/net/net.h b/include/net/net.h
index eff24519d2..1ef536d771 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -241,4 +241,9 @@ uint32_t net_crc32_le(const uint8_t *p, int len);
 .offset = vmstate_offset_macaddr(_state, _field),\
 }
 
+static inline bool net_peer_needs_padding(NetClientState *nc)
+{
+  return nc->peer && !nc->peer->do_not_pad;
+}
+
 #endif
diff --git a/net/slirp.c b/net/slirp.c
index a01a0fccd3..7a4e96db5c 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -119,7 +119,7 @@ static ssize_t net_slirp_send_packet(const void *pkt, 
size_t pkt_len,
 uint8_t min_pkt[ETH_ZLEN];
 size_t min_pktsz = sizeof(min_pkt);
 
-if (!s->nc.peer->do_not_pad) {
+if (net_peer_needs_padding(&s->nc)) {
 if (eth_pad_short_frame(min_pkt, &min_pktsz, pkt, pkt_len)) {
 pkt = min_pkt;
 pkt_len = min_pktsz;
diff --git a/net/tap-win32.c b/net/tap-win32.c
index 897bd18e32..6096972f5d 100644
--- a/net/tap-win32.c
+++ b/net/tap-win32.c
@@ -696,7 +696,7 @@ static void tap_win32_send(void *opaque)
 if (size > 0) {
 orig_buf = buf;
 
-if (!s->nc.peer->do_not_pad) {
+if (net_peer_needs_padding(&s->nc)) {
 if (eth_pad_short_frame(min_pkt, &min_pktsz, buf, size)) {
 buf = min_pkt;
 size = min_pktsz;
diff --git a/net/tap.c b/net/tap.c
index 7d53cedaec..820872fde8 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -203,7 +203,7 @@ static void tap_send(void *opaque)
 size -= s->host_vnet_hdr_len;
 }
 
-if (!s->nc.peer->do_not_pad) {
+if (net_peer_needs_padding(&s->nc)) {
 if (eth_pad_short_frame(min_pkt, &min_pktsz, buf, size)) {
 buf = min_pkt;
 size = min_pktsz;
-- 
2.25.1




[PATCH RESEND 1/2] target/i386: add "-cpu, lbr-fmt=*" support to enable guest LBR

2021-04-22 Thread Like Xu
The last branch recording (LBR) is a performance monitor unit (PMU)
feature on Intel processors that records a running trace of the most
recent branches taken by the processor in the LBR stack. The QEMU
could configure whether it's enabled or not for each guest via CLI.

The LBR feature would be enabled on the guest if:
- the KVM is enabled and the PMU is enabled and,
- the msr-based-feature IA32_PERF_CAPABILITIES is supporterd on KVM and,
- the supported returned value for lbr_fmt from this msr is not zero and,
- the requested guest vcpu model does support FEAT_1_ECX.CPUID_EXT_PDCM,
- the configured lbr-fmt value is the same as the host lbr_fmt value
  or use the QEMU option "-cpu host,migratable=no".

Cc: Eduardo Habkost 
Cc: Paolo Bonzini 
Signed-off-by: Like Xu 
---
 target/i386/cpu.c | 16 
 target/i386/cpu.h | 10 ++
 target/i386/kvm/kvm.c |  5 +++--
 3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index ad99cad0e7..eee6da3ad8 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6627,6 +6627,13 @@ static void x86_cpu_filter_features(X86CPU *cpu, bool 
verbose)
 x86_cpu_get_supported_feature_word(w, false);
 uint64_t requested_features = env->features[w];
 uint64_t unavailable_features = requested_features & ~host_feat;
+if (kvm_enabled() && w == FEAT_PERF_CAPABILITIES &&
+(requested_features & PERF_CAP_LBR_FMT)) {
+if ((host_feat & PERF_CAP_LBR_FMT) !=
+(requested_features & PERF_CAP_LBR_FMT)) {
+unavailable_features |= PERF_CAP_LBR_FMT;
+}
+}
 mark_unavailable_features(cpu, w, unavailable_features, prefix);
 }
 
@@ -6734,6 +6741,14 @@ static void x86_cpu_realizefn(DeviceState *dev, Error 
**errp)
 }
 }
 
+if (cpu->lbr_fmt) {
+if (!cpu->enable_pmu) {
+error_setg(errp, "LBR is unsupported since guest PMU is 
disabled.");
+return;
+}
+env->features[FEAT_PERF_CAPABILITIES] |= cpu->lbr_fmt;
+}
+
 /* mwait extended info: needed for Core compatibility */
 /* We always wake on interrupt even if host does not have the capability */
 cpu->mwait.ecx |= CPUID_MWAIT_EMX | CPUID_MWAIT_IBE;
@@ -7300,6 +7315,7 @@ static Property x86_cpu_properties[] = {
 #endif
 DEFINE_PROP_INT32("node-id", X86CPU, node_id, CPU_UNSET_NUMA_NODE_ID),
 DEFINE_PROP_BOOL("pmu", X86CPU, enable_pmu, false),
+DEFINE_PROP_UINT8("lbr-fmt", X86CPU, lbr_fmt, 0),
 
 DEFINE_PROP_UINT32("hv-spinlocks", X86CPU, hyperv_spinlock_attempts,
HYPERV_SPINLOCK_NEVER_NOTIFY),
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 570f916878..b12c879fc4 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -354,6 +354,7 @@ typedef enum X86Seg {
 #define ARCH_CAP_TSX_CTRL_MSR  (1<<7)
 
 #define MSR_IA32_PERF_CAPABILITIES  0x345
+#define PERF_CAP_LBR_FMT  0x3f
 
 #define MSR_IA32_TSX_CTRL  0x122
 #define MSR_IA32_TSCDEADLINE0x6e0
@@ -1726,6 +1727,15 @@ struct X86CPU {
  */
 bool enable_pmu;
 
+/*
+ * Configure LBR_FMT bits on IA32_PERF_CAPABILITIES MSR.
+ * This can't be enabled by default yet because it doesn't have
+ * ABI stability guarantees, as it is only allowed to pass all
+ * LBR_FMT bits returned by kvm_arch_get_supported_msr_feature()
+ * (that depends on host CPU and kernel capabilities) to the guest.
+ */
+uint8_t lbr_fmt;
+
 /* LMCE support can be enabled/disabled via cpu option 'lmce=on/off'. It is
  * disabled by default to avoid breaking migration between QEMU with
  * different LMCE configurations.
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 7fe9f52710..4d842d32a6 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -2732,8 +2732,9 @@ static void kvm_msr_entry_add_perf(X86CPU *cpu, 
FeatureWordArray f)
MSR_IA32_PERF_CAPABILITIES);
 
 if (kvm_perf_cap) {
-kvm_msr_entry_add(cpu, MSR_IA32_PERF_CAPABILITIES,
-kvm_perf_cap & f[FEAT_PERF_CAPABILITIES]);
+kvm_perf_cap = cpu->migratable ?
+(kvm_perf_cap & f[FEAT_PERF_CAPABILITIES]) : kvm_perf_cap;
+kvm_msr_entry_add(cpu, MSR_IA32_PERF_CAPABILITIES, kvm_perf_cap);
 }
 }
 
-- 
2.30.2




[PATCH RESEND 2/2] target/i386: add kvm_exact_match_flags to FeatureWordInfo

2021-04-22 Thread Like Xu
Instead of hardcoding the PERF_CAPABILITIES rules in this loop,
this could become a FeatureWordInfo field. It would be very useful
for other features like intel-pt, where we need some bits to match
the host bits too.

Suggested-by: Eduardo Habkost 
Signed-off-by: Like Xu 
---
 target/i386/cpu.c | 21 +++--
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index eee6da3ad8..56a486b498 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -708,6 +708,8 @@ typedef struct FeatureWordInfo {
 uint64_t migratable_flags; /* Feature flags known to be migratable */
 /* Features that shouldn't be auto-enabled by "-cpu host" */
 uint64_t no_autoenable_flags;
+/* Bits that must match host exactly when using KVM */
+uint64_t kvm_exact_match_flags;
 } FeatureWordInfo;
 
 static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
@@ -1147,6 +1149,11 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] 
= {
 .msr = {
 .index = MSR_IA32_PERF_CAPABILITIES,
 },
+/*
+ * KVM is not able to emulate a VCPU with LBR_FMT different
+ * from the host, so LBR_FMT must match the host exactly.
+ */
+.kvm_exact_match_flags = PERF_CAP_LBR_FMT,
 },
 
 [FEAT_VMX_PROCBASED_CTLS] = {
@@ -6623,16 +6630,18 @@ static void x86_cpu_filter_features(X86CPU *cpu, bool 
verbose)
 }
 
 for (w = 0; w < FEATURE_WORDS; w++) {
+FeatureWordInfo *fi = &feature_word_info[w];
+uint64_t match_flags = fi->kvm_exact_match_flags;
 uint64_t host_feat =
 x86_cpu_get_supported_feature_word(w, false);
 uint64_t requested_features = env->features[w];
 uint64_t unavailable_features = requested_features & ~host_feat;
-if (kvm_enabled() && w == FEAT_PERF_CAPABILITIES &&
-(requested_features & PERF_CAP_LBR_FMT)) {
-if ((host_feat & PERF_CAP_LBR_FMT) !=
-(requested_features & PERF_CAP_LBR_FMT)) {
-unavailable_features |= PERF_CAP_LBR_FMT;
-}
+if (kvm_enabled() && match_flags) {
+uint64_t mismatches = (requested_features & match_flags) &&
+(requested_features ^ host_feat) & match_flags;
+mark_unavailable_features(cpu, w,
+mismatches, "feature doesn't match host");
+unavailable_features &= ~match_flags;
 }
 mark_unavailable_features(cpu, w, unavailable_features, prefix);
 }
-- 
2.30.2




Re: [PATCH v2] i386: Add ratelimit for bus locks acquired in guest

2021-04-22 Thread Chenyi Qiang




On 4/21/2021 11:18 PM, Eduardo Habkost wrote:

On Wed, Apr 21, 2021 at 10:50:10PM +0800, Xiaoyao Li wrote:

On 4/21/2021 10:12 PM, Eduardo Habkost wrote:

On Wed, Apr 21, 2021 at 02:26:42PM +0800, Chenyi Qiang wrote:

Hi, Eduardo, thanks for your comments!


On 4/21/2021 12:34 AM, Eduardo Habkost wrote:

Hello,

Thanks for the patch.  Comments below:

On Tue, Apr 20, 2021 at 05:37:36PM +0800, Chenyi Qiang wrote:

Virtual Machines can exploit bus locks to degrade the performance of
system. To address this kind of performance DOS attack, bus lock VM exit
is introduced in KVM and it will report the bus locks detected in guest,
which can help userspace to enforce throttling policies.



Is there anything today that would protect the system from
similar attacks from userspace with access to /dev/kvm?



I can't fully understand your meaning for "similar attack with access to
/dev/kvm". But there are some similar associated detection features on bare
metal.


What I mean is: you say guests can make a performance DoS attack
on the host, and your patch mitigates that.

What would be the available methods to prevent untrusted
userspace running on the host with access to /dev/kvm from making
a similar DoS attack on the host?


Thanks for all the clarifications below.  Considering them,
what's the answer to the question above?



Hi Eduardo,

Just make it more clear.

Bus lock detection contains two sub-features. One is bus lock debug 
exception, and the other is bus lock VM exit.


Bus lock #DB exception can help detect the bus locks acquired in user 
space and bus lock VM exit detects the bus locks insides VMs. To address 
the attacks from non-VM userspace attackers against VM, Bus lock #DB 
exception can help.


The Bus lock #DB exception support 
(https://lore.kernel.org/lkml/20210322135325.682257-3-fenghua...@intel.com/) 
extends the  existing kernel command line parameter "split_lock_detect=" 
also applying to non-wb bus lock.
For example, split_lock_detect=fatal will send SIGBUS to the attackers 
once this kind of #DB is detected.






1. Split lock 
detection:https://lore.kernel.org/lkml/158031147976.396.8941798847364718785.tip-bot2@tip-bot2/
Some CPUs can raise an #AC trap when a split lock is attempted.


Would split_lock_detect=fatal be enough to prevent the above attacks?


NO.

There are two types bus lock:
1. split lock - lock on cacheable memory while the memory across two cache
lines.
2. non-wb lock - lock on non-writableback memory (you can find it on Intel
ISE chapter 8, 
https://software.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html)

split lock detection can only prevent 1)


Is split_lock_detect=fatal the only available way to prevent them?


as above, 2) non-wb lock can be prevented by "non-wb lock disable" feature


Bus lock VM exit applies to both 1 and 2, correct?







2. Bus lock Debug Exception:
https://lore.kernel.org/lkml/20210322135325.682257-1-fenghua...@intel.com/
The kernel can be notified by an #DB trap after a user instruction acquires
a bus lock and is executed.


I see a rate limit option mentioned at the above URL.  Would a
host kernel bus lock rate limit option make this QEMU patch
redundant?



No. Bus lock Debug exception cannot be used to detect the bus lock happens
in guest (vmx non-root mode).

We have patch to virtualize this feature for guest
https://lore.kernel.org/kvm/20210202090433.13441-1-chenyi.qi...@intel.com/

that guest will have its own setting of bus lock debug exception on or off.

What's more important is that, even we force set the
MSR_DEBUGCTL.BUS_LOCK_DETECT for guest, guest still can escape from it.
Because bus lock #DB is a trap which is delivered after the instruction
completes. If the instruction acquires bus lock subsequently faults e.g.,
#PF, then no bus lock #DB generated. But the bus lock does happen.

But with bus lock VM exit, even the instruction faults, it will cause a BUS
LOCK VM exit.








Re: [PATCH-for-6.0] net: tap: fix crash on hotplug

2021-04-22 Thread Jason Wang



在 2021/4/23 上午5:34, Cole Robinson 写道:

On 4/22/21 5:42 AM, Bin Meng wrote:

On Thu, Apr 22, 2021 at 5:36 PM Peter Maydell  wrote:

On Thu, 22 Apr 2021 at 05:29, Bin Meng  wrote:

On Thu, Apr 22, 2021 at 12:36 AM Philippe Mathieu-Daudé
 wrote:

Cc'ing Bin.

On 4/21/21 5:22 PM, Cole Robinson wrote:

Attempting to hotplug a tap nic with libvirt will crash qemu:

$ sudo virsh attach-interface f32 network default
error: Failed to attach interface
error: Unable to read from monitor: Connection reset by peer

0x55875b7f3a99 in tap_send (opaque=0x55875e39eae0) at ../net/tap.c:206
206   if (!s->nc.peer->do_not_pad) {
gdb$ bt

s->nc.peer may not be set at this point. This seems to be an
expected case, as qemu_send_packet_* explicitly checks for NULL
s->nc.peer later.

Fix it by checking for s->nc.peer here too. Padding is applied if
s->nc.peer is not set.

https://bugzilla.redhat.com/show_bug.cgi?id=1949786
Fixes: 969e50b61a2

Signed-off-by: Cole Robinson 
---
* Or should we skip padding if nc.peer is unset? I didn't dig into it
* tap-win3.c and slirp.c may need a similar fix, but the slirp case
   didn't crash in a simple test.

  net/tap.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/tap.c b/net/tap.c
index dd42ac6134..937559dbb8 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -203,7 +203,7 @@ static void tap_send(void *opaque)
  size -= s->host_vnet_hdr_len;
  }

-if (!s->nc.peer->do_not_pad) {
+if (!s->nc.peer || !s->nc.peer->do_not_pad) {

I think we should do:

if (s->nc.peer && !s->nc.peer->do_not_pad)

Yes. If there is no peer then the qemu_send_packet() that we're about
to do is going to discard the packet anyway, so there's no point in
padding it.

Maybe consider

static inline bool net_peer_needs_padding(NetClientState *nc)
{
 return nc->peer && !nc->peer->do_not_pad;
}

since we want the same check in three places ?

Sounds good to me.


I did not get to this today. Bin/Jason/anyone want to write the patch,



I will send a patch soon.

Thanks



I
will test it tomorrow (US EDT time). If not I'll write the patch tomorrow.

Thanks,
Cole







Re: [PATCH v6 10/18] cpu: Move CPUClass::vmsd to SysemuCPUOps

2021-04-22 Thread Richard Henderson

On 4/22/21 12:38 PM, Philippe Mathieu-Daudé wrote:

Migration is specific to system emulation.

- Move the CPUClass::vmsd field to SysemuCPUOps,
- restrict VMSTATE_CPU() macro to sysemu,
- vmstate_dummy is now unused, remove it.

Signed-off-by: Philippe Mathieu-Daudé 
---


Reviewed-by: Richard Henderson 


  #ifndef CONFIG_USER_ONLY
  static const struct SysemuCPUOps riscv_sysemu_ops = {
+/* For now, mark unmigratable: */
+.legacy_vmsd = &vmstate_riscv_cpu,
  };
  #endif
  
@@ -628,8 +630,6 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)

  cc->disas_set_info = riscv_cpu_disas_set_info;
  #ifndef CONFIG_USER_ONLY
  cc->get_phys_page_debug = riscv_cpu_get_phys_page_debug;
-/* For now, mark unmigratable: */
-cc->legacy_vmsd = &vmstate_riscv_cpu;


I'll note that the comment has been incorrect since f7697f0e629.


r~


  cc->sysemu_ops = &riscv_sysemu_ops;
  cc->write_elf64_note = riscv_cpu_write_elf64_note;
  cc->write_elf32_note = riscv_cpu_write_elf32_note;
diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c
index 7503b9e0c8b..131e7dfdf82 100644
--- a/target/s390x/cpu.c
+++ b/target/s390x/cpu.c
@@ -479,6 +479,7 @@ static void s390_cpu_reset_full(DeviceState *dev)
  
  #ifndef CONFIG_USER_ONLY

  static const struct SysemuCPUOps s390_sysemu_ops = {
+.legacy_vmsd = &vmstate_s390_cpu,
  };
  #endif
  
@@ -522,7 +523,6 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)

  cc->gdb_write_register = s390_cpu_gdb_write_register;
  #ifndef CONFIG_USER_ONLY
  cc->get_phys_page_debug = s390_cpu_get_phys_page_debug;
-cc->legacy_vmsd = &vmstate_s390_cpu;
  cc->get_crash_info = s390_cpu_get_crash_info;
  cc->write_elf64_note = s390_cpu_write_elf64_note;
  cc->sysemu_ops = &s390_sysemu_ops;
diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
index 743a7287a4f..543853c24dc 100644
--- a/target/sparc/cpu.c
+++ b/target/sparc/cpu.c
@@ -850,6 +850,7 @@ static Property sparc_cpu_properties[] = {
  
  #ifndef CONFIG_USER_ONLY

  static const struct SysemuCPUOps sparc_sysemu_ops = {
+.legacy_vmsd = &vmstate_sparc_cpu,
  };
  #endif
  
@@ -894,7 +895,6 @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data)

  cc->gdb_write_register = sparc_cpu_gdb_write_register;
  #ifndef CONFIG_USER_ONLY
  cc->get_phys_page_debug = sparc_cpu_get_phys_page_debug;
-cc->legacy_vmsd = &vmstate_sparc_cpu;
  cc->sysemu_ops = &sparc_sysemu_ops;
  #endif
  cc->disas_set_info = cpu_sparc_disas_set_info;
diff --git a/target/ppc/translate_init.c.inc b/target/ppc/translate_init.c.inc
index b15abc36851..e3f2f2fefa3 100644
--- a/target/ppc/translate_init.c.inc
+++ b/target/ppc/translate_init.c.inc
@@ -10880,6 +10880,7 @@ static Property ppc_cpu_properties[] = {
  
  #ifndef CONFIG_USER_ONLY

  static const struct SysemuCPUOps ppc_sysemu_ops = {
+.legacy_vmsd = &vmstate_ppc_cpu,
  };
  #endif
  
@@ -10925,7 +10926,6 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)

  cc->gdb_write_register = ppc_cpu_gdb_write_register;
  #ifndef CONFIG_USER_ONLY
  cc->get_phys_page_debug = ppc_cpu_get_phys_page_debug;
-cc->legacy_vmsd = &vmstate_ppc_cpu;
  cc->sysemu_ops = &ppc_sysemu_ops;
  #endif
  #if defined(CONFIG_SOFTMMU)






Re: [PATCH v6 08/18] cpu/{avr, lm32, moxie}: Set DeviceClass vmsd field (not CPUClass one)

2021-04-22 Thread Richard Henderson

On 4/22/21 12:38 PM, Philippe Mathieu-Daudé wrote:

See rationale in previous commit. Targets should use the vmsd field
of DeviceClass, not CPUClass. As migration is not important on the
avr/lm32/moxie targets, break the migration compatibility and set
the DeviceClass vmsd field.

Signed-off-by: Philippe Mathieu-Daudé
---
  target/avr/cpu.c   | 2 +-
  target/lm32/cpu.c  | 2 +-
  target/moxie/cpu.c | 2 +-
  3 files changed, 3 insertions(+), 3 deletions(-)


Do you not have to increment the vmstate versions?

Though I can't see how the version numbers would even get compared, since we're 
looking for them in different locations?



r~



Re: [PATCH v6 07/18] cpu: Rename CPUClass vmsd -> legacy_vmsd

2021-04-22 Thread Richard Henderson

On 4/22/21 12:38 PM, Philippe Mathieu-Daudé wrote:

Quoting Peter Maydell [*]:

   There are two ways to handle migration for
   a CPU object:

   (1) like any other device, so it has a dc->vmsd that covers
   migration for the whole object. As usual for objects that are a
   subclass of a parent that has state, the first entry in the
   VMStateDescription field list is VMSTATE_CPU(), which migrates
   the cpu_common fields, followed by whatever the CPU's own migration
   fields are.

   (2) a backwards-compatible mechanism for CPUs that were
   originally migrated using manual "write fields to the migration
   stream structures". The on-the-wire migration format
   for those is based on the 'env' pointer (which isn't a QOM object),
   and the cpu_common part of the migration data is elsewhere.

   cpu_exec_realizefn() handles both possibilities:

   * for type 1, dc->vmsd is set and cc->vmsd is not,
 so cpu_exec_realizefn() does nothing, and the standard
 "register dc->vmsd for a device" code does everything needed

   * for type 2, dc->vmsd is NULL and so we register the
 vmstate_cpu_common directly to handle the cpu-common fields,
 and the cc->vmsd to handle the per-CPU stuff

   You can't change a CPU from one type to the other without breaking
   migration compatibility, which is why some guest architectures
   are stuck on the cc->vmsd form. New targets should use dc->vmsd.

To avoid new targets to start using type (2), rename cc->vmsd as
cc->legacy_vmsd. The correct field to implement is dc->vmsd (the
DeviceClass one).

See also commit b170fce3dd0 ("cpu: Register VMStateDescription
through CPUState") for historic background.

[*]https://www.mail-archive.com/qemu-devel@nongnu.org/msg800849.html

Cc: Peter Maydell
Signed-off-by: Philippe Mathieu-Daudé
---
  include/hw/core/cpu.h   |  5 +++--
  cpu.c   | 12 ++--
  target/arm/cpu.c|  2 +-
  target/avr/cpu.c|  2 +-
  target/i386/cpu.c   |  2 +-
  target/lm32/cpu.c   |  2 +-
  target/mips/cpu.c   |  2 +-
  target/moxie/cpu.c  |  2 +-
  target/riscv/cpu.c  |  2 +-
  target/s390x/cpu.c  |  2 +-
  target/sparc/cpu.c  |  2 +-
  target/ppc/translate_init.c.inc |  2 +-
  12 files changed, 19 insertions(+), 18 deletions(-)


Reviewed-by: Richard Henderson 

r~



Re: [PATCH v6 06/18] cpu: Assert DeviceClass::vmsd is NULL on user emulation

2021-04-22 Thread Richard Henderson

On 4/22/21 12:38 PM, Philippe Mathieu-Daudé wrote:

Migration is specific to system emulation.

Restrict current DeviceClass::vmsd to sysemu using #ifdef'ry,
and assert in cpu_exec_realizefn() that dc->vmsd not set under
user emulation.

Signed-off-by: Philippe Mathieu-Daudé
---
  cpu.c  | 1 +
  target/sh4/cpu.c   | 5 +++--
  target/unicore32/cpu.c | 4 
  target/xtensa/cpu.c| 4 +++-
  4 files changed, 11 insertions(+), 3 deletions(-)


Reviewed-by: Richard Henderson 

r~



Re: [PATCH v2 0/7] linux-user: sigaction fixes/cleanups

2021-04-22 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20210422230227.314751-1-richard.hender...@linaro.org/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20210422230227.314751-1-richard.hender...@linaro.org
Subject: [PATCH v2 0/7] linux-user: sigaction fixes/cleanups

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag] 
patchew/20210422230227.314751-1-richard.hender...@linaro.org -> 
patchew/20210422230227.314751-1-richard.hender...@linaro.org
Switched to a new branch 'test'
9eee746 linux-user: Tidy TARGET_NR_rt_sigaction
46c2541 linux-user/alpha: Share code for TARGET_NR_sigaction
c69776b linux-user/alpha: Define TARGET_ARCH_HAS_KA_RESTORER
de9e5c2 linux-user: Honor TARGET_ARCH_HAS_SA_RESTORER in do_syscall
57bd960 linux-user: Pass ka_restorer to do_sigaction
ef4054e linux-user/alpha: Rename the sigaction restorer field
df4fac9 linux-user/alpha: Fix rt sigframe return

=== OUTPUT BEGIN ===
1/7 Checking commit df4fac977c4c (linux-user/alpha: Fix rt sigframe return)
2/7 Checking commit ef4054e42574 (linux-user/alpha: Rename the sigaction 
restorer field)
3/7 Checking commit 57bd9604ef18 (linux-user: Pass ka_restorer to do_sigaction)
ERROR: code indent should never use tabs
#64: FILE: linux-user/syscall.c:9019:
+^Iret = get_errno(do_sigaction(arg1, pact, &oact, 0));$

total: 1 errors, 0 warnings, 97 lines checked

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

4/7 Checking commit de9e5c267f85 (linux-user: Honor TARGET_ARCH_HAS_SA_RESTORER 
in do_syscall)
5/7 Checking commit c69776bf2b07 (linux-user/alpha: Define 
TARGET_ARCH_HAS_KA_RESTORER)
6/7 Checking commit 46c2541b617d (linux-user/alpha: Share code for 
TARGET_NR_sigaction)
7/7 Checking commit 9eee7464d318 (linux-user: Tidy TARGET_NR_rt_sigaction)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20210422230227.314751-1-richard.hender...@linaro.org/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

[PATCH v2 7/7] linux-user: Tidy TARGET_NR_rt_sigaction

2021-04-22 Thread Richard Henderson
Initialize variables instead of elses.
Use an else instead of a goto.
Add braces.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall.c | 32 +---
 1 file changed, 13 insertions(+), 19 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 9bcd485423..c7c3257f40 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -9060,32 +9060,26 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 target_ulong sigsetsize = arg4;
 target_ulong restorer = 0;
 #endif
-struct target_sigaction *act;
-struct target_sigaction *oact;
+struct target_sigaction *act = NULL;
+struct target_sigaction *oact = NULL;
 
 if (sigsetsize != sizeof(target_sigset_t)) {
 return -TARGET_EINVAL;
 }
-if (arg2) {
-if (!lock_user_struct(VERIFY_READ, act, arg2, 1)) {
-return -TARGET_EFAULT;
-}
-} else {
-act = NULL;
+if (arg2 && !lock_user_struct(VERIFY_READ, act, arg2, 1)) {
+return -TARGET_EFAULT;
 }
-if (arg3) {
-if (!lock_user_struct(VERIFY_WRITE, oact, arg3, 0)) {
-ret = -TARGET_EFAULT;
-goto rt_sigaction_fail;
+if (arg3 && !lock_user_struct(VERIFY_WRITE, oact, arg3, 0)) {
+ret = -TARGET_EFAULT;
+} else {
+ret = get_errno(do_sigaction(arg1, act, oact, restorer));
+if (oact) {
+unlock_user_struct(oact, arg3, 1);
 }
-} else
-oact = NULL;
-ret = get_errno(do_sigaction(arg1, act, oact, restorer));
-   rt_sigaction_fail:
-if (act)
+}
+if (act) {
 unlock_user_struct(act, arg2, 0);
-if (oact)
-unlock_user_struct(oact, arg3, 1);
+}
 }
 return ret;
 #ifdef TARGET_NR_sgetmask /* not on alpha */
-- 
2.25.1




[PATCH v2 4/7] linux-user: Honor TARGET_ARCH_HAS_SA_RESTORER in do_syscall

2021-04-22 Thread Richard Henderson
Do not access a field that may not be present.  This will
become an issue when sharing more code in the next patch.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 36169a0ded..89d641856c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -9038,7 +9038,9 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 act._sa_handler = old_act->_sa_handler;
 target_siginitset(&act.sa_mask, old_act->sa_mask);
 act.sa_flags = old_act->sa_flags;
+#ifdef TARGET_ARCH_HAS_SA_RESTORER
 act.sa_restorer = old_act->sa_restorer;
+#endif
 unlock_user_struct(old_act, arg2, 0);
 pact = &act;
 } else {
@@ -9051,7 +9053,9 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 old_act->_sa_handler = oact._sa_handler;
 old_act->sa_mask = oact.sa_mask.sig[0];
 old_act->sa_flags = oact.sa_flags;
+#ifdef TARGET_ARCH_HAS_SA_RESTORER
 old_act->sa_restorer = oact.sa_restorer;
+#endif
 unlock_user_struct(old_act, arg3, 1);
 }
 #endif
-- 
2.25.1




[PATCH v2 3/7] linux-user: Pass ka_restorer to do_sigaction

2021-04-22 Thread Richard Henderson
The value of ka_restorer needs to be saved in sigact_table.
At the moment, the attempt to save it in do_syscall is
improperly clobbering user memory.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall_defs.h |  2 +-
 linux-user/signal.c   |  5 -
 linux-user/syscall.c  | 19 ++-
 3 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 693d4f3788..e4aaf8412f 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -492,7 +492,7 @@ void target_to_host_old_sigset(sigset_t *sigset,
const abi_ulong *old_sigset);
 struct target_sigaction;
 int do_sigaction(int sig, const struct target_sigaction *act,
- struct target_sigaction *oact);
+ struct target_sigaction *oact, abi_ulong ka_restorer);
 
 #include "target_signal.h"
 
diff --git a/linux-user/signal.c b/linux-user/signal.c
index 7eecec46c4..44a5012930 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -830,7 +830,7 @@ out:
 
 /* do_sigaction() return target values and host errnos */
 int do_sigaction(int sig, const struct target_sigaction *act,
- struct target_sigaction *oact)
+ struct target_sigaction *oact, abi_ulong ka_restorer)
 {
 struct target_sigaction *k;
 struct sigaction act1;
@@ -863,6 +863,9 @@ int do_sigaction(int sig, const struct target_sigaction 
*act,
 __get_user(k->sa_flags, &act->sa_flags);
 #ifdef TARGET_ARCH_HAS_SA_RESTORER
 __get_user(k->sa_restorer, &act->sa_restorer);
+#endif
+#ifdef TARGET_ARCH_HAS_KA_RESTORER
+k->ka_restorer = ka_restorer;
 #endif
 /* To be swapped in target_to_host_sigset.  */
 k->sa_mask = act->sa_mask;
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ee21eb5e6f..36169a0ded 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8989,11 +8989,10 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 act._sa_handler = old_act->_sa_handler;
 target_siginitset(&act.sa_mask, old_act->sa_mask);
 act.sa_flags = old_act->sa_flags;
-act.ka_restorer = 0;
 unlock_user_struct(old_act, arg2, 0);
 pact = &act;
 }
-ret = get_errno(do_sigaction(arg1, pact, &oact));
+ret = get_errno(do_sigaction(arg1, pact, &oact, 0));
 if (!is_error(ret) && arg3) {
 if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0))
 return -TARGET_EFAULT;
@@ -9017,7 +9016,7 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
pact = NULL;
}
 
-   ret = get_errno(do_sigaction(arg1, pact, &oact));
+   ret = get_errno(do_sigaction(arg1, pact, &oact, 0));
 
if (!is_error(ret) && arg3) {
 if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0))
@@ -9040,15 +9039,12 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 target_siginitset(&act.sa_mask, old_act->sa_mask);
 act.sa_flags = old_act->sa_flags;
 act.sa_restorer = old_act->sa_restorer;
-#ifdef TARGET_ARCH_HAS_KA_RESTORER
-act.ka_restorer = 0;
-#endif
 unlock_user_struct(old_act, arg2, 0);
 pact = &act;
 } else {
 pact = NULL;
 }
-ret = get_errno(do_sigaction(arg1, pact, &oact));
+ret = get_errno(do_sigaction(arg1, pact, &oact, 0));
 if (!is_error(ret) && arg3) {
 if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0))
 return -TARGET_EFAULT;
@@ -9085,11 +9081,10 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 act._sa_handler = rt_act->_sa_handler;
 act.sa_mask = rt_act->sa_mask;
 act.sa_flags = rt_act->sa_flags;
-act.ka_restorer = arg5;
 unlock_user_struct(rt_act, arg2, 0);
 pact = &act;
 }
-ret = get_errno(do_sigaction(arg1, pact, &oact));
+ret = get_errno(do_sigaction(arg1, pact, &oact, arg5));
 if (!is_error(ret) && arg3) {
 if (!lock_user_struct(VERIFY_WRITE, rt_act, arg3, 0))
 return -TARGET_EFAULT;
@@ -9104,6 +9099,7 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 target_ulong sigsetsize = arg5;
 #else
 target_ulong sigsetsize = arg4;
+target_ulong restorer = 0;
 #endif
 struct target_sigaction *act;
 struct target_sigaction *oact;
@@ -9115,9 +9111,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 if (!lock_user_struct(VERIFY_READ, act, arg2, 1)) {
 return -TARGET_EFA

[PATCH v2 2/7] linux-user/alpha: Rename the sigaction restorer field

2021-04-22 Thread Richard Henderson
Use ka_restorer, in line with TARGET_ARCH_HAS_KA_RESTORER
vs TARGET_ARCH_HAS_SA_RESTORER, since Alpha passes this
field as a syscall argument.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall_defs.h | 2 +-
 linux-user/alpha/signal.c | 8 
 linux-user/syscall.c  | 4 ++--
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 25be414727..693d4f3788 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -519,7 +519,7 @@ struct target_sigaction {
 abi_ulong _sa_handler;
 abi_ulong sa_flags;
 target_sigset_t sa_mask;
-abi_ulong sa_restorer;
+abi_ulong ka_restorer;
 };
 #elif defined(TARGET_MIPS)
 struct target_sigaction {
diff --git a/linux-user/alpha/signal.c b/linux-user/alpha/signal.c
index 86f5d2276d..3aa4b339a4 100644
--- a/linux-user/alpha/signal.c
+++ b/linux-user/alpha/signal.c
@@ -138,8 +138,8 @@ void setup_frame(int sig, struct target_sigaction *ka,
 
 setup_sigcontext(&frame->sc, env, frame_addr, set);
 
-if (ka->sa_restorer) {
-r26 = ka->sa_restorer;
+if (ka->ka_restorer) {
+r26 = ka->ka_restorer;
 } else {
 __put_user(INSN_MOV_R30_R16, &frame->retcode[0]);
 __put_user(INSN_LDI_R0 + TARGET_NR_sigreturn,
@@ -192,8 +192,8 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
 __put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]);
 }
 
-if (ka->sa_restorer) {
-r26 = ka->sa_restorer;
+if (ka->ka_restorer) {
+r26 = ka->ka_restorer;
 } else {
 __put_user(INSN_MOV_R30_R16, &frame->retcode[0]);
 __put_user(INSN_LDI_R0 + TARGET_NR_rt_sigreturn,
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 95d79ddc43..ee21eb5e6f 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8989,7 +8989,7 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 act._sa_handler = old_act->_sa_handler;
 target_siginitset(&act.sa_mask, old_act->sa_mask);
 act.sa_flags = old_act->sa_flags;
-act.sa_restorer = 0;
+act.ka_restorer = 0;
 unlock_user_struct(old_act, arg2, 0);
 pact = &act;
 }
@@ -9085,7 +9085,7 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 act._sa_handler = rt_act->_sa_handler;
 act.sa_mask = rt_act->sa_mask;
 act.sa_flags = rt_act->sa_flags;
-act.sa_restorer = arg5;
+act.ka_restorer = arg5;
 unlock_user_struct(rt_act, arg2, 0);
 pact = &act;
 }
-- 
2.25.1




[PATCH v2 6/7] linux-user/alpha: Share code for TARGET_NR_sigaction

2021-04-22 Thread Richard Henderson
There's no longer a difference between the alpha code and
the generic code.

There is a type difference in target_old_sigaction.sa_flags,
which can be resolved with a very much smaller ifdef, which
allows us to finish sharing the target_sigaction definition.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall_defs.h | 21 ++---
 linux-user/syscall.c  | 23 +--
 2 files changed, 7 insertions(+), 37 deletions(-)

diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 7a1d3b239c..18b031a2f6 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -501,21 +501,12 @@ int do_sigaction(int sig, const struct target_sigaction 
*act,
 #endif
 
 #if defined(TARGET_ALPHA)
-struct target_old_sigaction {
-abi_ulong _sa_handler;
-abi_ulong sa_mask;
-int32_t sa_flags;
-};
+typedef int32_t target_old_sa_flags;
+#else
+typedef abi_ulong target_old_sa_flags;
+#endif
 
-/* This is the struct used inside the kernel.  The ka_restorer
-   field comes from the 5th argument to sys_rt_sigaction.  */
-struct target_sigaction {
-abi_ulong _sa_handler;
-abi_ulong sa_flags;
-target_sigset_t sa_mask;
-abi_ulong ka_restorer;
-};
-#elif defined(TARGET_MIPS)
+#if defined(TARGET_MIPS)
 struct target_sigaction {
uint32_tsa_flags;
 #if defined(TARGET_ABI_MIPSN32)
@@ -533,7 +524,7 @@ struct target_sigaction {
 struct target_old_sigaction {
 abi_ulong _sa_handler;
 abi_ulong sa_mask;
-abi_ulong sa_flags;
+target_old_sa_flags sa_flags;
 #ifdef TARGET_ARCH_HAS_SA_RESTORER
 abi_ulong sa_restorer;
 #endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 216ee4ca47..9bcd485423 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8980,28 +8980,7 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 #ifdef TARGET_NR_sigaction
 case TARGET_NR_sigaction:
 {
-#if defined(TARGET_ALPHA)
-struct target_sigaction act, oact, *pact = 0;
-struct target_old_sigaction *old_act;
-if (arg2) {
-if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1))
-return -TARGET_EFAULT;
-act._sa_handler = old_act->_sa_handler;
-target_siginitset(&act.sa_mask, old_act->sa_mask);
-act.sa_flags = old_act->sa_flags;
-unlock_user_struct(old_act, arg2, 0);
-pact = &act;
-}
-ret = get_errno(do_sigaction(arg1, pact, &oact, 0));
-if (!is_error(ret) && arg3) {
-if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0))
-return -TARGET_EFAULT;
-old_act->_sa_handler = oact._sa_handler;
-old_act->sa_mask = oact.sa_mask.sig[0];
-old_act->sa_flags = oact.sa_flags;
-unlock_user_struct(old_act, arg3, 1);
-}
-#elif defined(TARGET_MIPS)
+#if defined(TARGET_MIPS)
struct target_sigaction act, oact, *pact, *old_act;
 
if (arg2) {
-- 
2.25.1




[PATCH v2 5/7] linux-user/alpha: Define TARGET_ARCH_HAS_KA_RESTORER

2021-04-22 Thread Richard Henderson
This means that we can share the TARGET_NR_rt_sigaction code,
and the target_rt_sigaction structure is unused.  Untangling
the ifdefs so that target_sigaction can be shared will wait
until the next patch.

Signed-off-by: Richard Henderson 
---
 linux-user/alpha/target_signal.h |  1 +
 linux-user/syscall_defs.h|  6 --
 linux-user/syscall.c | 37 ++--
 3 files changed, 7 insertions(+), 37 deletions(-)

diff --git a/linux-user/alpha/target_signal.h b/linux-user/alpha/target_signal.h
index 0b90d3a897..250642913e 100644
--- a/linux-user/alpha/target_signal.h
+++ b/linux-user/alpha/target_signal.h
@@ -92,6 +92,7 @@ typedef struct target_sigaltstack {
 #define TARGET_GEN_SUBRNG7 -25
 
 #define TARGET_ARCH_HAS_SETUP_FRAME
+#define TARGET_ARCH_HAS_KA_RESTORER
 
 /* bit-flags */
 #define TARGET_SS_AUTODISARM (1U << 31) /* disable sas during sighandling */
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index e4aaf8412f..7a1d3b239c 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -507,12 +507,6 @@ struct target_old_sigaction {
 int32_t sa_flags;
 };
 
-struct target_rt_sigaction {
-abi_ulong _sa_handler;
-abi_ulong sa_flags;
-target_sigset_t sa_mask;
-};
-
 /* This is the struct used inside the kernel.  The ka_restorer
field comes from the 5th argument to sys_rt_sigaction.  */
 struct target_sigaction {
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 89d641856c..216ee4ca47 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -9064,41 +9064,17 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 #endif
 case TARGET_NR_rt_sigaction:
 {
-#if defined(TARGET_ALPHA)
-/* For Alpha and SPARC this is a 5 argument syscall, with
+/*
+ * For Alpha and SPARC this is a 5 argument syscall, with
  * a 'restorer' parameter which must be copied into the
  * sa_restorer field of the sigaction struct.
  * For Alpha that 'restorer' is arg5; for SPARC it is arg4,
  * and arg5 is the sigsetsize.
- * Alpha also has a separate rt_sigaction struct that it uses
- * here; SPARC uses the usual sigaction struct.
  */
-struct target_rt_sigaction *rt_act;
-struct target_sigaction act, oact, *pact = 0;
-
-if (arg4 != sizeof(target_sigset_t)) {
-return -TARGET_EINVAL;
-}
-if (arg2) {
-if (!lock_user_struct(VERIFY_READ, rt_act, arg2, 1))
-return -TARGET_EFAULT;
-act._sa_handler = rt_act->_sa_handler;
-act.sa_mask = rt_act->sa_mask;
-act.sa_flags = rt_act->sa_flags;
-unlock_user_struct(rt_act, arg2, 0);
-pact = &act;
-}
-ret = get_errno(do_sigaction(arg1, pact, &oact, arg5));
-if (!is_error(ret) && arg3) {
-if (!lock_user_struct(VERIFY_WRITE, rt_act, arg3, 0))
-return -TARGET_EFAULT;
-rt_act->_sa_handler = oact._sa_handler;
-rt_act->sa_mask = oact.sa_mask;
-rt_act->sa_flags = oact.sa_flags;
-unlock_user_struct(rt_act, arg3, 1);
-}
-#else
-#ifdef TARGET_SPARC
+#if defined(TARGET_ALPHA)
+target_ulong sigsetsize = arg4;
+target_ulong restorer = arg5;
+#elif defined(TARGET_SPARC)
 target_ulong restorer = arg4;
 target_ulong sigsetsize = arg5;
 #else
@@ -9131,7 +9107,6 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 unlock_user_struct(act, arg2, 0);
 if (oact)
 unlock_user_struct(oact, arg3, 1);
-#endif
 }
 return ret;
 #ifdef TARGET_NR_sgetmask /* not on alpha */
-- 
2.25.1




[PATCH v2 0/7] linux-user: sigaction fixes/cleanups

2021-04-22 Thread Richard Henderson
Alpha had two bugs, one with the non-ka_restorer fallback
using the wrong offset, and the other with the ka_restorer
value getting lost in do_sigaction.

Sparc had another bug, where the ka_restorer field was
written to user memory.

Version 2 splits patch 2 into 6.


r~


Richard Henderson (7):
  linux-user/alpha: Fix rt sigframe return
  linux-user/alpha: Rename the sigaction restorer field
  linux-user: Pass ka_restorer to do_sigaction
  linux-user: Honor TARGET_ARCH_HAS_SA_RESTORER in do_syscall
  linux-user/alpha: Define TARGET_ARCH_HAS_KA_RESTORER
  linux-user/alpha: Share code for TARGET_NR_sigaction
  linux-user: Tidy TARGET_NR_rt_sigaction

 linux-user/alpha/target_signal.h |   1 +
 linux-user/syscall_defs.h|  29 ++---
 linux-user/alpha/signal.c|  10 +--
 linux-user/signal.c  |   5 +-
 linux-user/syscall.c | 107 ---
 5 files changed, 43 insertions(+), 109 deletions(-)

-- 
2.25.1




[PATCH v2 1/7] linux-user/alpha: Fix rt sigframe return

2021-04-22 Thread Richard Henderson
We incorrectly used the offset of the non-rt sigframe.

Reviewed-by: Laurent Vivier 
Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Richard Henderson 
---
 linux-user/alpha/signal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/alpha/signal.c b/linux-user/alpha/signal.c
index c5c27ce084..86f5d2276d 100644
--- a/linux-user/alpha/signal.c
+++ b/linux-user/alpha/signal.c
@@ -200,7 +200,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
&frame->retcode[1]);
 __put_user(INSN_CALLSYS, &frame->retcode[2]);
 /* imb(); */
-r26 = frame_addr + offsetof(struct target_sigframe, retcode);
+r26 = frame_addr + offsetof(struct target_rt_sigframe, retcode);
 }
 
 if (err) {
-- 
2.25.1




Re: [Bug 1743191] Re: Interacting with NetBSD serial console boot blocks no longer works

2021-04-22 Thread Ottavio Caruso
On Thu, 22 Apr 2021 at 18:23, Andreas Gustafsson
<1743...@bugs.launchpad.net> wrote:
>
> Ottavio Caruso wrote:
> > I am currently using:
> >
> > $ qemu-system-x86_64 --version
> > QEMU emulator version 5.2.0
> >
> > And I have no problem selecting from menu in serial console, so I
> > assume this is fixed for me. This is my command line:
> >
> > $ cat opt/bin/boot-netbsd-virtio
> > #!/bin/sh
> > qemu-system-x86_64 \
> > -drive if=virtio,file=/home/oc/VM/img/netbsd.image,index=0,media=disk \
> > -drive if=virtio,file=/home/oc/VM/img/netbsd.image.old,index=1,media=disk \
> > -M q35,accel=kvm -m 250M -cpu host -smp $(nproc) \
> > -nic user,hostfwd=tcp:127.0.0.1:-:22,model=virtio-net-pci,ipv6=off  \
> > -daemonize -display none  -vga none \
> > -serial mon:telnet:127.0.0.1:6665,server,nowait \
> > -pidfile /home/oc/VM/pid/netbsd-pid -nodefaults
> >
> > telnet 127.0.0.1 6665
>
> Have you tried the test case in the original bug report?
> --
> Andreas Gustafsson, g...@gson.org

You're right. Using the boot-com install image, the problem persists.


-- 
Ottavio Caruso

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1743191

Title:
  Interacting with NetBSD serial console boot blocks no longer works

Status in QEMU:
  New

Bug description:
  The NetBSD boot blocks display a menu allowing the user to make a
  selection using the keyboard.  For example, when booting a NetBSD
  installation CD-ROM, the menu looks like this:

   1. Install NetBSD
   2. Install NetBSD (no ACPI)
   3. Install NetBSD (no ACPI, no SMP)
   4. Drop to boot prompt

  Choose an option; RETURN for default; SPACE to stop countdown.
  Option 1 will be chosen in 30 seconds.

  When booting NetBSD in a recent qemu using an emulated serial console,
  making this menu selection no longer works: when you type the selected
  number, the keyboard input is ignored, and the 30-second countdown
  continues.  In older versions of qemu, it works.

  To reproduce the problem, run:

 wget 
http://ftp.netbsd.org/pub/NetBSD/NetBSD-7.1.1/amd64/installation/cdrom/boot-com.iso
 qemu-system-x86_64 -nographic -cdrom boot-com.iso

  During the 30-second countdown, press 4

  Expected behavior: The countdown stops and you get a ">" prompt

  Incorrect behavior: The countdown continues

  There may also be some corruption of the terminal output; for example,
  "Option 1 will be chosen in 30 seconds" may be displayed as "Option 1
  will be chosen in p0 seconds".

  Using bisection, I have determined that the problem appeared with qemu
  commit 083fab0290f2c40d3d04f7f22eed9c8f2d5b6787, in which seabios was
  updated to 1.11 prerelease, and the problem is still there as of
  commit 7398166ddf7c6dbbc9cae6ac69bb2feda14b40ac.  The host operating
  system used for the tests was Debian 9 x86_64.

  Credit for discovering this bug goes to Paul Goyette.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1743191/+subscriptions



[PULL 2/2] x86: acpi: use offset instead of pointer when using build_header()

2021-04-22 Thread Michael S. Tsirkin
From: Igor Mammedov 

Do the same as in commit
 (4d027afeb3a97 Virt: ACPI: fix qemu assert due to re-assigned table data 
address)
for remaining tables that happen to use saved at
the beginning pointer to build header to avoid assert
when table_data is relocated due to implicit re-size.

In this case user is trying to start Windows 10 and getting assert at
 hw/acpi/bios-linker-loader.c:239:
  bios_linker_loader_add_checksum: Assertion `start_offset < file->blob->len' 
failed.

Fixes: https://bugs.launchpad.net/bugs/1923497
Signed-off-by: Igor Mammedov 
Message-Id: <20210414084356.3792113-1-imamm...@redhat.com>
Cc: m...@redhat.com, qemu-sta...@nongnu.org
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/acpi/aml-build.c  | 15 +--
 hw/i386/acpi-build.c |  8 ++--
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index d33ce8954a..f0035d2b4a 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -1830,6 +1830,7 @@ build_rsdt(GArray *table_data, BIOSLinker *linker, GArray 
*table_offsets,
 int i;
 unsigned rsdt_entries_offset;
 AcpiRsdtDescriptorRev1 *rsdt;
+int rsdt_start = table_data->len;
 const unsigned table_data_len = (sizeof(uint32_t) * table_offsets->len);
 const unsigned rsdt_entry_size = sizeof(rsdt->table_offset_entry[0]);
 const size_t rsdt_len = sizeof(*rsdt) + table_data_len;
@@ -1846,7 +1847,8 @@ build_rsdt(GArray *table_data, BIOSLinker *linker, GArray 
*table_offsets,
 ACPI_BUILD_TABLE_FILE, ref_tbl_offset);
 }
 build_header(linker, table_data,
- (void *)rsdt, "RSDT", rsdt_len, 1, oem_id, oem_table_id);
+ (void *)(table_data->data + rsdt_start),
+ "RSDT", rsdt_len, 1, oem_id, oem_table_id);
 }
 
 /* Build xsdt table */
@@ -1857,6 +1859,7 @@ build_xsdt(GArray *table_data, BIOSLinker *linker, GArray 
*table_offsets,
 int i;
 unsigned xsdt_entries_offset;
 AcpiXsdtDescriptorRev2 *xsdt;
+int xsdt_start = table_data->len;
 const unsigned table_data_len = (sizeof(uint64_t) * table_offsets->len);
 const unsigned xsdt_entry_size = sizeof(xsdt->table_offset_entry[0]);
 const size_t xsdt_len = sizeof(*xsdt) + table_data_len;
@@ -1873,7 +1876,8 @@ build_xsdt(GArray *table_data, BIOSLinker *linker, GArray 
*table_offsets,
 ACPI_BUILD_TABLE_FILE, ref_tbl_offset);
 }
 build_header(linker, table_data,
- (void *)xsdt, "XSDT", xsdt_len, 1, oem_id, oem_table_id);
+ (void *)(table_data->data + xsdt_start),
+ "XSDT", xsdt_len, 1, oem_id, oem_table_id);
 }
 
 void build_srat_memory(AcpiSratMemoryAffinity *numamem, uint64_t base,
@@ -2053,10 +2057,9 @@ void build_tpm2(GArray *table_data, BIOSLinker *linker, 
GArray *tcpalog,
 uint64_t control_area_start_address;
 TPMIf *tpmif = tpm_find();
 uint32_t start_method;
-void *tpm2_ptr;
 
 tpm2_start = table_data->len;
-tpm2_ptr = acpi_data_push(table_data, sizeof(AcpiTableHeader));
+acpi_data_push(table_data, sizeof(AcpiTableHeader));
 
 /* Platform Class */
 build_append_int_noprefix(table_data, TPM2_ACPI_CLASS_CLIENT, 2);
@@ -2095,8 +2098,8 @@ void build_tpm2(GArray *table_data, BIOSLinker *linker, 
GArray *tcpalog,
log_addr_offset, 8,
ACPI_BUILD_TPMLOG_FILE, 0);
 build_header(linker, table_data,
- tpm2_ptr, "TPM2", table_data->len - tpm2_start, 4, oem_id,
- oem_table_id);
+ (void *)(table_data->data + tpm2_start),
+ "TPM2", table_data->len - tpm2_start, 4, oem_id, 
oem_table_id);
 }
 
 Aml *build_crs(PCIHostState *host, CrsRangeSet *range_set, uint32_t io_offset,
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index de98750aef..daaf8f473e 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1816,6 +1816,7 @@ build_hpet(GArray *table_data, BIOSLinker *linker, const 
char *oem_id,
const char *oem_table_id)
 {
 Acpi20Hpet *hpet;
+int hpet_start = table_data->len;
 
 hpet = acpi_data_push(table_data, sizeof(*hpet));
 /* Note timer_block_id value must be kept in sync with value advertised by
@@ -1824,13 +1825,15 @@ build_hpet(GArray *table_data, BIOSLinker *linker, 
const char *oem_id,
 hpet->timer_block_id = cpu_to_le32(0x8086a201);
 hpet->addr.address = cpu_to_le64(HPET_BASE);
 build_header(linker, table_data,
- (void *)hpet, "HPET", sizeof(*hpet), 1, oem_id, oem_table_id);
+ (void *)(table_data->data + hpet_start),
+ "HPET", sizeof(*hpet), 1, oem_id, oem_table_id);
 }
 
 static void
 build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog,
const char *oem_id, const char *oem_table_id)
 {
+int tcpa_start = table_data->len;
 Acpi20Tcpa *tcpa = acpi_data_push(tabl

[PULL 0/2] pc: last minute bugfixes

2021-04-22 Thread Michael S. Tsirkin
The following changes since commit d83f46d189a26fa32434139954d264326f199a45:

  virtio-pci: compat page aligned ATS (2021-04-06 07:11:36 -0400)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream

for you to fetch changes up to 9106db1038bf3db5e4f8007038b3a1962018fa07:

  x86: acpi: use offset instead of pointer when using build_header() 
(2021-04-22 18:22:01 -0400)


pc: last minute bugfixes

Two bugfixes - both seem pretty obvious and safe ...

Signed-off-by: Michael S. Tsirkin 


Igor Mammedov (1):
  x86: acpi: use offset instead of pointer when using build_header()

Jean-Philippe Brucker (1):
  amd_iommu: Fix pte_override_page_mask()

 hw/acpi/aml-build.c  | 15 +--
 hw/i386/acpi-build.c |  8 ++--
 hw/i386/amd_iommu.c  |  4 ++--
 3 files changed, 17 insertions(+), 10 deletions(-)




[PULL 1/2] amd_iommu: Fix pte_override_page_mask()

2021-04-22 Thread Michael S. Tsirkin
From: Jean-Philippe Brucker 

AMD IOMMU PTEs have a special mode allowing to specify an arbitrary page
size. Quoting the AMD IOMMU specification: "When the Next Level bits [of
a pte] are 7h, the size of the page is determined by the first zero bit
in the page address, starting from bit 12."

So if the lowest bits of the page address is 0, the page is 8kB. If the
lowest bits are 011, the page is 32kB. Currently pte_override_page_mask()
doesn't compute the right value for this page size and amdvi_translate()
can return the wrong guest-physical address. With a Linux guest, DMA
from SATA devices accesses the wrong memory and causes probe failure:

qemu-system-x86_64 ... -device amd-iommu -drive id=hd1,file=foo.bin,if=none \
-device ahci,id=ahci -device ide-hd,drive=hd1,bus=ahci.0
[6.613093] ata1.00: qc timeout (cmd 0xec)
[6.615062] ata1.00: failed to IDENTIFY (I/O error, err_mask=0x4)

Fix the page mask.

Signed-off-by: Jean-Philippe Brucker 
Message-Id: <20210421084007.1190546-1-jean-phili...@linaro.org>
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/i386/amd_iommu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index 74a93a5d93..43b6e9bf51 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -860,8 +860,8 @@ static inline uint8_t get_pte_translation_mode(uint64_t pte)
 
 static inline uint64_t pte_override_page_mask(uint64_t pte)
 {
-uint8_t page_mask = 12;
-uint64_t addr = (pte & AMDVI_DEV_PT_ROOT_MASK) ^ AMDVI_DEV_PT_ROOT_MASK;
+uint8_t page_mask = 13;
+uint64_t addr = (pte & AMDVI_DEV_PT_ROOT_MASK) >> 12;
 /* find the first zero bit */
 while (addr & 1) {
 page_mask++;
-- 
MST




[Bug 1925512] Re: UNDEFINED case for instruction BLX

2021-04-22 Thread Richard Henderson
The complete imm32 is computed by

%imm24   26:s1 13:1 11:1 16:10 0:11 !function=t32_branch24

so that H appears at bit 1 in a->imm in trans_BLX_i.

Returning false from any trans_* function means that the trans
function did not match.  In some cases, this means that the next
possible matching pattern is tested.  But in most cases, such as
this one, we return all the way to disas_thumb2_insn, where we
do in fact call unallocated_encoding.

If you have a test case that fails, please provide it.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1925512

Title:
  UNDEFINED case for instruction BLX

Status in QEMU:
  Invalid

Bug description:
  Hi

  I refer to the instruction BLX imm (T2 encoding) in ARMv7 (Thumb
  mode).

  0 S imm10H  11 J1 0 J2 imm10L H

  
  if H == '1' then UNDEFINED;
  I1 = NOT(J1 EOR S);  I2 = NOT(J2 EOR S);  imm32 = 
SignExtend(S:I1:I2:imm10H:imm10L:'00', 32);
  targetInstrSet = InstrSet_A32;
  if InITBlock() && !LastInITBlock() then UNPREDICTABLE;

  According to the manual, if H equals to 1, this instruction should be
  an UNDEFINED instruction. However, it seems QEMU does not check this
  constraint in function trans_BLX_i. Thanks

  Regards
  Muhui

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1925512/+subscriptions



Re: [PATCH-for-6.0] net: tap: fix crash on hotplug

2021-04-22 Thread Cole Robinson
On 4/22/21 5:42 AM, Bin Meng wrote:
> On Thu, Apr 22, 2021 at 5:36 PM Peter Maydell  
> wrote:
>>
>> On Thu, 22 Apr 2021 at 05:29, Bin Meng  wrote:
>>>
>>> On Thu, Apr 22, 2021 at 12:36 AM Philippe Mathieu-Daudé
>>>  wrote:

 Cc'ing Bin.

 On 4/21/21 5:22 PM, Cole Robinson wrote:
> Attempting to hotplug a tap nic with libvirt will crash qemu:
>
> $ sudo virsh attach-interface f32 network default
> error: Failed to attach interface
> error: Unable to read from monitor: Connection reset by peer
>
> 0x55875b7f3a99 in tap_send (opaque=0x55875e39eae0) at ../net/tap.c:206
> 206   if (!s->nc.peer->do_not_pad) {
> gdb$ bt
>
> s->nc.peer may not be set at this point. This seems to be an
> expected case, as qemu_send_packet_* explicitly checks for NULL
> s->nc.peer later.
>
> Fix it by checking for s->nc.peer here too. Padding is applied if
> s->nc.peer is not set.
>
> https://bugzilla.redhat.com/show_bug.cgi?id=1949786
> Fixes: 969e50b61a2
>
> Signed-off-by: Cole Robinson 
> ---
> * Or should we skip padding if nc.peer is unset? I didn't dig into it
> * tap-win3.c and slirp.c may need a similar fix, but the slirp case
>   didn't crash in a simple test.
>
>  net/tap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/tap.c b/net/tap.c
> index dd42ac6134..937559dbb8 100644
> --- a/net/tap.c
> +++ b/net/tap.c
> @@ -203,7 +203,7 @@ static void tap_send(void *opaque)
>  size -= s->host_vnet_hdr_len;
>  }
>
> -if (!s->nc.peer->do_not_pad) {
> +if (!s->nc.peer || !s->nc.peer->do_not_pad) {
>>>
>>> I think we should do:
>>>
>>> if (s->nc.peer && !s->nc.peer->do_not_pad)
>>
>> Yes. If there is no peer then the qemu_send_packet() that we're about
>> to do is going to discard the packet anyway, so there's no point in
>> padding it.
>>
>> Maybe consider
>>
>> static inline bool net_peer_needs_padding(NetClientState *nc)
>> {
>> return nc->peer && !nc->peer->do_not_pad;
>> }
>>
>> since we want the same check in three places ?
> 
> Sounds good to me.
> 

I did not get to this today. Bin/Jason/anyone want to write the patch, I
will test it tomorrow (US EDT time). If not I'll write the patch tomorrow.

Thanks,
Cole




qemu/kvm tianocore restart stuck

2021-04-22 Thread VoidCC
Hello,

I'm hitting a hard wall with qemu and efi.
I'm running multiple windows server 2019 vms which usually reboot on
updates.

The issue is, efi breaks on reboot.
It randomly(race condition?, does not occur consistently) ends up in a
blackscreen: no bootloader, no efi screen and the only way to get out of
that state is to destroy the vm.
moving the host mouse cursor above the console in virt-manager results in a
flashing mouse cursor.
there are no physical devices attached and there is currently no virtio
attachment in use (os has virtio drivers installed)


Machine is Q35 with tianocore/ovmf efi.
I managed to reproduce the same behaviour on rhel 8.3 as well as
voidlinux (kernel 5.11)

gdb output of qemu is showing nothing worrisome, else ive compiled ovmf
manually for debug output.
libvirt logs don't show any issues.

root · Slexy.org Pastebin 


Re: [PATCH 2/2] linux-user: Clean up sigaction ka_restorer

2021-04-22 Thread Richard Henderson

On 4/22/21 11:08 AM, Richard Henderson wrote:

Pass the ka_restorer value as an argument to do_sigaction,
and put it into the sigaction table.

Drop the separate TARGET_ALPHA struct target_rt_sigaction
and define TARGET_ARCH_HAS_KA_RESTORER.

Tidy up TARGET_NR_rt_sigaction, merging TARGET_ALPHA, and
TARGET_SPARC into common code.

Signed-off-by: Richard Henderson 


I'm going to split this patch further.
I should be able to clean up alpha further as well.


r~



Re: [RFC PATCH 0/4] hw/ppc: remove call to tcg-only function

2021-04-22 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20210422193131.22560-1-lucas.ara...@eldorado.org.br/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20210422193131.22560-1-lucas.ara...@eldorado.org.br
Subject: [RFC PATCH 0/4] hw/ppc: remove call to tcg-only function

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag] 
patchew/20210422193131.22560-1-lucas.ara...@eldorado.org.br -> 
patchew/20210422193131.22560-1-lucas.ara...@eldorado.org.br
Switched to a new branch 'test'
1d1179f target/ppc: transfered functions to non-tcg-only files
a938556 hw/ppc: updated build rules to use new file
bed5362 hw/ppc: Add kvm-only file spapr_hcall_tcg_stub.c
7725f72 target/ppc: updated build options

=== OUTPUT BEGIN ===
1/4 Checking commit 7725f72d37a7 (target/ppc: updated build options)
2/4 Checking commit bed5362bcfdb (hw/ppc: Add kvm-only file 
spapr_hcall_tcg_stub.c)
Use of uninitialized value $acpi_testexpected in string eq at 
./scripts/checkpatch.pl line 1529.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#24: 
new file mode 100644

ERROR: spaces required around that '*' (ctx:VxV)
#172: FILE: hw/ppc/spapr_hcall_tcg_stub.c:144:
+target_ulong *tsh = &args[i*2];
^

ERROR: spaces required around that '*' (ctx:VxV)
#173: FILE: hw/ppc/spapr_hcall_tcg_stub.c:145:
+target_ulong tsl = args[i*2 + 1];
  ^

WARNING: Block comments use a leading /* on a separate line
#244: FILE: hw/ppc/spapr_hcall_tcg_stub.c:216:
+/* These fields are private to the preparation thread if

WARNING: Block comments use a trailing */ on a separate line
#245: FILE: hw/ppc/spapr_hcall_tcg_stub.c:217:
+ * !complete, otherwise protected by the BQL */

WARNING: Block comments use a leading /* on a separate line
#307: FILE: hw/ppc/spapr_hcall_tcg_stub.c:279:
+/* Convert a return code from the KVM ioctl()s implementing resize HPT

WARNING: Block comments use a trailing */ on a separate line
#308: FILE: hw/ppc/spapr_hcall_tcg_stub.c:280:
+ * into a PAPR hypercall return code */

WARNING: Block comments use a leading /* on a separate line
#377: FILE: hw/ppc/spapr_hcall_tcg_stub.c:349:
+/* We only allow the guest to allocate an HPT one order above what

WARNING: Block comments use a trailing */ on a separate line
#379: FILE: hw/ppc/spapr_hcall_tcg_stub.c:351:
+ * chunk of resources in the HPT */

WARNING: Block comments use a leading /* on a separate line
#420: FILE: hw/ppc/spapr_hcall_tcg_stub.c:392:
+/* In theory we could estimate the time more accurately based on

WARNING: Block comments use a trailing */ on a separate line
#421: FILE: hw/ppc/spapr_hcall_tcg_stub.c:393:
+ * the new size, but there's not much point */

ERROR: spaces required around that '*' (ctx:VxV)
#984: FILE: hw/ppc/spapr_hcall_tcg_stub.c:956:
+   nret, rtas_r3 + 12 + 4*nargs);
  ^

WARNING: line over 80 characters
#1424: FILE: hw/ppc/spapr_hcall_tcg_stub.c:1396:
+warn_report("guest has multiple active vCPUs at CAS, which is not 
allowed");

WARNING: Block comments use a leading /* on a separate line
#1445: FILE: hw/ppc/spapr_hcall_tcg_stub.c:1417:
+/* We fail to set compat mode (likely because running with KVM PR),

WARNING: Block comments use a leading /* on a separate line
#1504: FILE: hw/ppc/spapr_hcall_tcg_stub.c:1476:
+/* Guest doesn't know about HPT resizing, so we

WARNING: Block comments use a trailing */ on a separate line
#1507: FILE: hw/ppc/spapr_hcall_tcg_stub.c:1479:
+ * entered into the existing HPT */

WARNING: Block comments use a leading /* on a separate line
#1513: FILE: hw/ppc/spapr_hcall_tcg_stub.c:1485:
+/* NOTE: there are actually a number of ov5 bits where input from the

WARNING: line over 80 characters
#1729: FILE: hw/ppc/spapr_hcall_tcg_stub.c:1701:
+static spapr_hcall_fn kvmppc_hypercall_table[KVMPPC_HCALL_MAX - 
KVMPPC_HCALL_BASE + 1];

WARNING: line over 80 characters
#1730: FILE: hw/ppc/spapr_hcall_tcg_stub.c:1702:
+static spapr_hcall_fn svm_hypercall_table[(SVM_HCALL_MAX - SVM_HCALL_BASE) / 4 
+ 1];

WARNING: Block comments use a leading /* on a separate line
#1830: FILE: hw/ppc/spapr_hcall_tcg_stub.c:1802:
+/* "debugger" hcalls (also used by SLOF). Note: We do -not- differenciate

total: 3 errors, 17 warnings, 1824 lines checked

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

3/4 Checking commit a938556

[RFC PATCH 0/4] hw/ppc: remove call to tcg-only function

2021-04-22 Thread Lucas Mateus Castro (alqotel)
Hi,

I'm working with Bruno Larsen (billionai) to enable the disable-tcg
option for PowerPC, right now I'm aiming at removing call to tcg-only
functions from hw/ppc, there is still some work to be done in
target/ppc.

This patch creates a spapr_hcall_tcg_stub.c file
that has the same hcalls as spapr_hcall except those that call tcg-only
functions, said functions now only trip a fatal error.

The functions ppc_store_lpcr and ppc_hash64_filter_pagesizes were in
tcg-only files but as their logic is necessary they have been moved to a
non-tcg-only file.

This is still a work in progress and this patches focuses on the
spapr* calls, as there will still be some undefined references to
functions in tcg-only files and include to tcg-only .h, mostly on
target/ppc.

Comments are welcome, thanks,
Lucas Mateus.

Lucas Mateus Castro (alqotel) (4):
  target/ppc: updated build options
  hw/ppc: Add kvm-only file spapr_hcall_tcg_stub.c
  hw/ppc: updated build rules to use new file
  target/ppc: transfered functions to non-tcg-only files

 hw/ppc/meson.build|   10 +-
 hw/ppc/spapr.c|1 +
 hw/ppc/spapr_caps.c   |1 +
 hw/ppc/spapr_cpu_core.c   |1 +
 hw/ppc/spapr_hcall.c  |1 +
 hw/ppc/spapr_hcall_tcg_stub.c | 1825 +
 hw/ppc/spapr_rtas.c   |1 +
 target/ppc/common-misc.c  |   86 ++
 target/ppc/common-misc.h  |   13 +
 target/ppc/int_helper.c   |   10 +-
 target/ppc/meson.build|   21 +-
 target/ppc/mmu-hash64.c   |   67 +-
 target/ppc/mmu-hash64.h   |4 -
 13 files changed, 1957 insertions(+), 84 deletions(-)
 create mode 100644 hw/ppc/spapr_hcall_tcg_stub.c
 create mode 100644 target/ppc/common-misc.c
 create mode 100644 target/ppc/common-misc.h

-- 
2.17.1




[RFC PATCH 3/4] hw/ppc: updated build rules to use new file

2021-04-22 Thread Lucas Mateus Castro (alqotel)
Updated meson.build to compile spapr_hcall_tcg_stub.c instead of
spapr_hcall.c when disable-tcg option is used

Signed-off-by: Lucas Mateus Castro (alqotel) 
---
 hw/ppc/meson.build | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/hw/ppc/meson.build b/hw/ppc/meson.build
index 218631c883..8b9b537c37 100644
--- a/hw/ppc/meson.build
+++ b/hw/ppc/meson.build
@@ -14,7 +14,6 @@ ppc_ss.add(when: 'CONFIG_PSERIES', if_true: files(
   'spapr_caps.c',
   'spapr_vio.c',
   'spapr_events.c',
-  'spapr_hcall.c',
   'spapr_iommu.c',
   'spapr_rtas.c',
   'spapr_pci.c',
@@ -29,6 +28,15 @@ ppc_ss.add(when: 'CONFIG_PSERIES', if_true: files(
   'spapr_numa.c',
   'pef.c',
 ))
+tcg_ss = ss.source_set()
+tcg_ss.add(when: 'CONFIG_TCG', if_true: files(
+  'spapr_hcall.c',
+), if_false: files(
+  'spapr_hcall_tcg_stub.c',
+))
+
+ppc_ss.add_all(when: 'CONFIG_PSERIES', if_true: tcg_ss)
+
 ppc_ss.add(when: 'CONFIG_SPAPR_RNG', if_true: files('spapr_rng.c'))
 ppc_ss.add(when: ['CONFIG_PSERIES', 'CONFIG_LINUX'], if_true: files(
   'spapr_pci_vfio.c',
-- 
2.17.1




[RFC PATCH 2/4] hw/ppc: Add kvm-only file spapr_hcall_tcg_stub.c

2021-04-22 Thread Lucas Mateus Castro (alqotel)
This file should be used instead of spapr_hcall.c when compiling
without tcg (--disable-tcg) as it does not call tcg-only functions and
trips fatal error when invalid functions are called

As of right now some functions are repeated here and in spapr_hcall.c,
as they are static, is some other method to deal with this recommended?
Also some functions should only cause a fatal error as KVM should
intercept and handle their call, but as I'm not sure which ones I just
did this to functions that called tcg-only code.

Signed-off-by: Lucas Mateus Castro (alqotel) 
---
 hw/ppc/spapr_hcall_tcg_stub.c | 1824 +
 1 file changed, 1824 insertions(+)
 create mode 100644 hw/ppc/spapr_hcall_tcg_stub.c

diff --git a/hw/ppc/spapr_hcall_tcg_stub.c b/hw/ppc/spapr_hcall_tcg_stub.c
new file mode 100644
index 00..6682279b6e
--- /dev/null
+++ b/hw/ppc/spapr_hcall_tcg_stub.c
@@ -0,0 +1,1824 @@
+#include "qemu/osdep.h"
+#include "qemu/cutils.h"
+#include "qapi/error.h"
+#include "sysemu/hw_accel.h"
+#include "sysemu/runstate.h"
+#include "qemu/log.h"
+#include "qemu/main-loop.h"
+#include "qemu/module.h"
+#include "qemu/error-report.h"
+#include "cpu.h"
+#include "exec/exec-all.h"
+#include "helper_regs.h"
+#include "hw/ppc/spapr.h"
+#include "hw/ppc/spapr_cpu_core.h"
+#include "mmu-hash64.h"
+#include "cpu-models.h"
+#include "trace.h"
+#include "kvm_ppc.h"
+#include "hw/ppc/fdt.h"
+#include "hw/ppc/spapr_ovec.h"
+#include "mmu-book3s-v3.h"
+#include "hw/mem/memory-device.h"
+
+static bool has_spr(PowerPCCPU *cpu, int spr)
+{
+/* We can test whether the SPR is defined by checking for a valid name */
+return cpu->env.spr_cb[spr].name != NULL;
+}
+
+static inline bool valid_ptex(PowerPCCPU *cpu, target_ulong ptex)
+{
+/*
+ * hash value/pteg group index is normalized by HPT mask
+ */
+if (((ptex & ~7ULL) / HPTES_PER_GROUP) & ~ppc_hash64_hpt_mask(cpu)) {
+return false;
+}
+return true;
+}
+
+static bool is_ram_address(SpaprMachineState *spapr, hwaddr addr)
+{
+MachineState *machine = MACHINE(spapr);
+DeviceMemoryState *dms = machine->device_memory;
+
+if (addr < machine->ram_size) {
+return true;
+}
+if ((addr >= dms->base)
+&& ((addr - dms->base) < memory_region_size(&dms->mr))) {
+return true;
+}
+
+return false;
+}
+
+static target_ulong h_enter(PowerPCCPU *cpu, SpaprMachineState *spapr,
+target_ulong opcode, target_ulong *args)
+{
+/*
+ * FATAL ERROR
+ */
+g_assert_not_reached();
+return 0;
+}
+
+typedef enum {
+REMOVE_SUCCESS = 0,
+REMOVE_NOT_FOUND = 1,
+REMOVE_PARM = 2,
+REMOVE_HW = 3,
+} RemoveResult;
+
+static RemoveResult remove_hpte(PowerPCCPU *cpu
+, target_ulong ptex,
+target_ulong avpn,
+target_ulong flags,
+target_ulong *vp, target_ulong *rp)
+{
+/*
+ * FATAL ERROR
+ */
+*rp = 0;
+g_assert_not_reached();
+return 0;
+}
+
+static target_ulong h_remove(PowerPCCPU *cpu, SpaprMachineState *spapr,
+ target_ulong opcode, target_ulong *args)
+{
+CPUPPCState *env = &cpu->env;
+target_ulong flags = args[0];
+target_ulong ptex = args[1];
+target_ulong avpn = args[2];
+RemoveResult ret;
+
+ret = remove_hpte(cpu, ptex, avpn, flags,
+  &args[0], &args[1]);
+
+switch (ret) {
+case REMOVE_SUCCESS:
+check_tlb_flush(env, true);
+return H_SUCCESS;
+
+case REMOVE_NOT_FOUND:
+return H_NOT_FOUND;
+
+case REMOVE_PARM:
+return H_PARAMETER;
+
+case REMOVE_HW:
+return H_HARDWARE;
+}
+
+g_assert_not_reached();
+}
+
+#define H_BULK_REMOVE_TYPE 0xc000ULL
+#define   H_BULK_REMOVE_REQUEST0x4000ULL
+#define   H_BULK_REMOVE_RESPONSE   0x8000ULL
+#define   H_BULK_REMOVE_END0xc000ULL
+#define H_BULK_REMOVE_CODE 0x3000ULL
+#define   H_BULK_REMOVE_SUCCESS0xULL
+#define   H_BULK_REMOVE_NOT_FOUND  0x1000ULL
+#define   H_BULK_REMOVE_PARM   0x2000ULL
+#define   H_BULK_REMOVE_HW 0x3000ULL
+#define H_BULK_REMOVE_RC   0x0c00ULL
+#define H_BULK_REMOVE_FLAGS0x0300ULL
+#define   H_BULK_REMOVE_ABSOLUTE   0xULL
+#define   H_BULK_REMOVE_ANDCOND0x0100ULL
+#define   H_BULK_REMOVE_AVPN   0x0200ULL
+#define H_BULK_REMOVE_PTEX 0x00ffULL
+
+#define H_BULK_REMOVE_MAX_BATCH4
+
+static target_ulong h_bulk_remove(PowerPCCPU *cpu, SpaprMachineState *spapr,
+  target_ulong opcode, target_ulong *args)
+{
+CPUPPCState *env = &cpu->env;
+int

[PATCH v6 18/18] cpu: Restrict "hw/core/sysemu-cpu-ops.h" to target/cpu.c

2021-04-22 Thread Philippe Mathieu-Daudé
Somehow similar to commit 78271684719 ("cpu: tcg_ops: move to
tcg-cpu-ops.h, keep a pointer in CPUClass"):

We cannot in principle make the SysEmu Operations field definitions
conditional on CONFIG_SOFTMMU in code that is included by both
common_ss and specific_ss modules.

Therefore, what we can do safely to restrict the SysEmu fields to
system emulation builds, is to move all sysemu operations into a
separate header file, which is only included by system-specific code.

This leaves just a NULL pointer in the cpu.h for the user-mode builds.

Inspired-by: Claudio Fontana 
Reviewed-by: Taylor Simpson 
Reviewed-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/core/cpu.h   | 3 ++-
 target/alpha/cpu.h  | 3 +++
 target/arm/cpu.h| 3 +++
 target/avr/cpu.h| 1 +
 target/cris/cpu.h   | 3 +++
 target/hexagon/cpu.h| 3 +++
 target/hppa/cpu.h   | 3 +++
 target/i386/cpu.h   | 3 +++
 target/lm32/cpu.h   | 3 +++
 target/m68k/cpu.h   | 3 +++
 target/microblaze/cpu.h | 1 +
 target/mips/cpu.h   | 3 +++
 target/moxie/cpu.h  | 3 +++
 target/nios2/cpu.h  | 1 +
 target/openrisc/cpu.h   | 3 +++
 target/ppc/cpu.h| 3 +++
 target/riscv/cpu.h  | 3 +++
 target/rx/cpu.h | 1 +
 target/s390x/cpu.h  | 3 +++
 target/sh4/cpu.h| 3 +++
 target/sparc/cpu.h  | 3 +++
 target/tricore/cpu.h| 3 +++
 target/unicore32/cpu.h  | 3 +++
 target/xtensa/cpu.h | 3 +++
 cpu.c   | 1 +
 hw/core/cpu.c   | 1 +
 26 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index d0187798eea..3422d405b49 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -80,7 +80,8 @@ struct TCGCPUOps;
 /* see accel-cpu.h */
 struct AccelCPUClass;
 
-#include "hw/core/sysemu-cpu-ops.h"
+/* see sysemu-cpu-ops.h */
+struct SysemuCPUOps;
 
 /**
  * CPUClass:
diff --git a/target/alpha/cpu.h b/target/alpha/cpu.h
index 82df108967b..f1218a27706 100644
--- a/target/alpha/cpu.h
+++ b/target/alpha/cpu.h
@@ -22,6 +22,9 @@
 
 #include "cpu-qom.h"
 #include "exec/cpu-defs.h"
+#ifndef CONFIG_USER_ONLY
+#include "hw/core/sysemu-cpu-ops.h"
+#endif
 
 /* Alpha processors have a weak memory model */
 #define TCG_GUEST_DEFAULT_MO  (0)
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 193a49ec7fa..d9228d1d990 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -25,6 +25,9 @@
 #include "cpu-qom.h"
 #include "exec/cpu-defs.h"
 #include "qapi/qapi-types-common.h"
+#ifndef CONFIG_USER_ONLY
+#include "hw/core/sysemu-cpu-ops.h"
+#endif
 
 /* ARM processors have a weak memory model */
 #define TCG_GUEST_DEFAULT_MO  (0)
diff --git a/target/avr/cpu.h b/target/avr/cpu.h
index d148e8c75a4..e0419649fa7 100644
--- a/target/avr/cpu.h
+++ b/target/avr/cpu.h
@@ -23,6 +23,7 @@
 
 #include "cpu-qom.h"
 #include "exec/cpu-defs.h"
+#include "hw/core/sysemu-cpu-ops.h"
 
 #ifdef CONFIG_USER_ONLY
 #error "AVR 8-bit does not support user mode"
diff --git a/target/cris/cpu.h b/target/cris/cpu.h
index d3b64929096..4450f2268ea 100644
--- a/target/cris/cpu.h
+++ b/target/cris/cpu.h
@@ -23,6 +23,9 @@
 
 #include "cpu-qom.h"
 #include "exec/cpu-defs.h"
+#ifndef CONFIG_USER_ONLY
+#include "hw/core/sysemu-cpu-ops.h"
+#endif
 
 #define EXCP_NMI1
 #define EXCP_GURU   2
diff --git a/target/hexagon/cpu.h b/target/hexagon/cpu.h
index e04eac591c8..2a878e77f08 100644
--- a/target/hexagon/cpu.h
+++ b/target/hexagon/cpu.h
@@ -26,6 +26,9 @@ typedef struct CPUHexagonState CPUHexagonState;
 #include "qemu-common.h"
 #include "exec/cpu-defs.h"
 #include "hex_regs.h"
+#ifndef CONFIG_USER_ONLY
+#include "hw/core/sysemu-cpu-ops.h"
+#endif
 
 #define NUM_PREGS 4
 #define TOTAL_PER_THREAD_REGS 64
diff --git a/target/hppa/cpu.h b/target/hppa/cpu.h
index 61178fa6a2a..94d2d4701c4 100644
--- a/target/hppa/cpu.h
+++ b/target/hppa/cpu.h
@@ -23,6 +23,9 @@
 #include "cpu-qom.h"
 #include "exec/cpu-defs.h"
 #include "exec/memory.h"
+#ifndef CONFIG_USER_ONLY
+#include "hw/core/sysemu-cpu-ops.h"
+#endif
 
 /* PA-RISC 1.x processors have a strong memory model.  */
 /* ??? While we do not yet implement PA-RISC 2.0, those processors have
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 570f916878f..2f520cb6fc1 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -25,6 +25,9 @@
 #include "kvm/hyperv-proto.h"
 #include "exec/cpu-defs.h"
 #include "qapi/qapi-types-common.h"
+#ifndef CONFIG_USER_ONLY
+#include "hw/core/sysemu-cpu-ops.h"
+#endif
 
 /* The x86 has a strong memory model with some store-after-load re-ordering */
 #define TCG_GUEST_DEFAULT_MO  (TCG_MO_ALL & ~TCG_MO_ST_LD)
diff --git a/target/lm32/cpu.h b/target/lm32/cpu.h
index ea7c01ca8b0..034183dad30 100644
--- a/target/lm32/cpu.h
+++ b/target/lm32/cpu.h
@@ -22,6 +22,9 @@
 
 #include "cpu-qom.h"
 #include "exec/cpu-defs.h"
+#ifndef CONFIG_USER_ONLY
+#include "hw/core/sysemu-cpu-ops.h"
+#endif
 
 typedef struct CPULM32State CPULM32State;
 
diff --

[PATCH v6 15/18] cpu: Move CPUClass::get_phys_page_debug to SysemuCPUOps

2021-04-22 Thread Philippe Mathieu-Daudé
Reviewed-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/core/cpu.h|  8 
 include/hw/core/sysemu-cpu-ops.h | 13 +
 hw/core/cpu.c|  6 +++---
 target/alpha/cpu.c   |  2 +-
 target/arm/cpu.c |  2 +-
 target/avr/cpu.c |  2 +-
 target/cris/cpu.c|  2 +-
 target/hppa/cpu.c|  2 +-
 target/i386/cpu.c|  2 +-
 target/lm32/cpu.c|  2 +-
 target/m68k/cpu.c|  2 +-
 target/microblaze/cpu.c  |  2 +-
 target/mips/cpu.c|  2 +-
 target/moxie/cpu.c   |  2 +-
 target/nios2/cpu.c   |  2 +-
 target/openrisc/cpu.c|  2 +-
 target/riscv/cpu.c   |  2 +-
 target/rx/cpu.c  |  2 +-
 target/s390x/cpu.c   |  2 +-
 target/sh4/cpu.c |  2 +-
 target/sparc/cpu.c   |  2 +-
 target/tricore/cpu.c |  2 +-
 target/unicore32/cpu.c   |  2 +-
 target/xtensa/cpu.c  |  2 +-
 target/ppc/translate_init.c.inc  |  2 +-
 25 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 28c4fc541a2..88a0a90ac7b 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -103,11 +103,6 @@ struct AccelCPUClass;
  *   If the target behaviour here is anything other than "set
  *   the PC register to the value passed in" then the target must
  *   also implement the synchronize_from_tb hook.
- * @get_phys_page_debug: Callback for obtaining a physical address.
- * @get_phys_page_attrs_debug: Callback for obtaining a physical address and 
the
- *   associated memory transaction attributes to use for the access.
- *   CPUs which use memory transaction attributes should implement this
- *   instead of get_phys_page_debug.
  * @gdb_read_register: Callback for letting GDB read a register.
  * @gdb_write_register: Callback for letting GDB write a register.
  * @gdb_num_core_regs: Number of core registers accessible to GDB.
@@ -146,9 +141,6 @@ struct CPUClass {
 void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list,
Error **errp);
 void (*set_pc)(CPUState *cpu, vaddr value);
-hwaddr (*get_phys_page_debug)(CPUState *cpu, vaddr addr);
-hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu, vaddr addr,
-MemTxAttrs *attrs);
 int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg);
 int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg);
 
diff --git a/include/hw/core/sysemu-cpu-ops.h b/include/hw/core/sysemu-cpu-ops.h
index 52a05ea9b3e..4be4a4b4da7 100644
--- a/include/hw/core/sysemu-cpu-ops.h
+++ b/include/hw/core/sysemu-cpu-ops.h
@@ -16,6 +16,19 @@
  * struct SysemuCPUOps: System operations specific to a CPU class
  */
 typedef struct SysemuCPUOps {
+/**
+ * @get_phys_page_debug: Callback for obtaining a physical address.
+ */
+hwaddr (*get_phys_page_debug)(CPUState *cpu, vaddr addr);
+/**
+ * @get_phys_page_attrs_debug: Callback for obtaining a physical address
+ *   and the associated memory transaction attributes to use for the
+ *   access.
+ * CPUs which use memory transaction attributes should implement this
+ * instead of get_phys_page_debug.
+ */
+hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu, vaddr addr,
+MemTxAttrs *attrs);
 /**
  * @asidx_from_attrs: Callback to return the CPU AddressSpace to use for
  *   a memory access with the specified memory transaction attributes.
diff --git a/hw/core/cpu.c b/hw/core/cpu.c
index c44229205ff..6932781425a 100644
--- a/hw/core/cpu.c
+++ b/hw/core/cpu.c
@@ -96,12 +96,12 @@ hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr 
addr,
 {
 CPUClass *cc = CPU_GET_CLASS(cpu);
 
-if (cc->get_phys_page_attrs_debug) {
-return cc->get_phys_page_attrs_debug(cpu, addr, attrs);
+if (cc->sysemu_ops->get_phys_page_attrs_debug) {
+return cc->sysemu_ops->get_phys_page_attrs_debug(cpu, addr, attrs);
 }
 /* Fallback for CPUs which don't implement the _attrs_ hook */
 *attrs = MEMTXATTRS_UNSPECIFIED;
-return cc->get_phys_page_debug(cpu, addr);
+return cc->sysemu_ops->get_phys_page_debug(cpu, addr);
 }
 
 hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c
index cd01d34d92f..979a4c0be1e 100644
--- a/target/alpha/cpu.c
+++ b/target/alpha/cpu.c
@@ -208,6 +208,7 @@ static void alpha_cpu_initfn(Object *obj)
 
 #ifndef CONFIG_USER_ONLY
 static const struct SysemuCPUOps alpha_sysemu_ops = {
+.get_phys_page_debug = alpha_cpu_get_phys_page_debug,
 };
 #endif
 
@@ -241,7 +242,6 @@ static void alpha_cpu_class_init(ObjectClass *oc, void 
*data)
 cc->gdb_read_registe

[RFC PATCH 1/4] target/ppc: updated build options

2021-04-22 Thread Lucas Mateus Castro (alqotel)
updated meson.build to not compile tcg-only files

Signed-off-by: Lucas Mateus Castro (alqotel) 
---
 target/ppc/meson.build | 20 ++--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/target/ppc/meson.build b/target/ppc/meson.build
index bbfef90e08..b369a6bcd0 100644
--- a/target/ppc/meson.build
+++ b/target/ppc/meson.build
@@ -2,10 +2,17 @@ ppc_ss = ss.source_set()
 ppc_ss.add(files(
   'cpu-models.c',
   'cpu.c',
+  'gdbstub.c',
+))
+
+ppc_ss.add(libdecnumber)
+
+ppc_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c'), if_false: 
files('kvm-stub.c'))
+ppc_ss.add(when: 'CONFIG_USER_ONLY', if_true: files('user_only_helper.c'))
+ppc_ss.add(when: 'CONFIG_TCG', if_true: files(
   'dfp_helper.c',
   'excp_helper.c',
   'fpu_helper.c',
-  'gdbstub.c',
   'int_helper.c',
   'mem_helper.c',
   'misc_helper.c',
@@ -13,21 +20,22 @@ ppc_ss.add(files(
   'translate.c',
 ))
 
-ppc_ss.add(libdecnumber)
-
-ppc_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c'), if_false: 
files('kvm-stub.c'))
-ppc_ss.add(when: 'CONFIG_USER_ONLY', if_true: files('user_only_helper.c'))
 
 ppc_softmmu_ss = ss.source_set()
 ppc_softmmu_ss.add(files(
   'arch_dump.c',
   'machine.c',
+  'monitor.c',
+))
+ppc_softmmu_ss.add(when: 'CONFIG_TCG', if_true: files(
   'mmu-hash32.c',
   'mmu_helper.c',
-  'monitor.c',
 ))
+
 ppc_softmmu_ss.add(when: 'TARGET_PPC64', if_true: files(
   'compat.c',
+))
+ppc_softmmu_ss.add(when: ['TARGET_PPC64', 'CONFIG_TCG'], if_true: files(
   'mmu-book3s-v3.c',
   'mmu-hash64.c',
   'mmu-radix64.c',
-- 
2.17.1




[PATCH v6 13/18] cpu: Move CPUClass::write_elf* to SysemuCPUOps

2021-04-22 Thread Philippe Mathieu-Daudé
The write_elf*() handlers are used to dump vmcore images.
This feature is only meaningful for system emulation.

Reviewed-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/core/cpu.h| 17 -
 include/hw/core/sysemu-cpu-ops.h | 24 
 hw/core/cpu.c| 16 
 target/arm/cpu.c |  4 ++--
 target/i386/cpu.c|  8 
 target/riscv/cpu.c   |  4 ++--
 target/s390x/cpu.c   |  2 +-
 target/ppc/translate_init.c.inc  |  6 ++
 8 files changed, 43 insertions(+), 38 deletions(-)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 4289cd0d78a..b7095bc4192 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -112,14 +112,6 @@ struct AccelCPUClass;
  *   a memory access with the specified memory transaction attributes.
  * @gdb_read_register: Callback for letting GDB read a register.
  * @gdb_write_register: Callback for letting GDB write a register.
- * @write_elf64_note: Callback for writing a CPU-specific ELF note to a
- * 64-bit VM coredump.
- * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
- * note to a 32-bit VM coredump.
- * @write_elf32_note: Callback for writing a CPU-specific ELF note to a
- * 32-bit VM coredump.
- * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
- * note to a 32-bit VM coredump.
  * @gdb_num_core_regs: Number of core registers accessible to GDB.
  * @gdb_core_xml_file: File name for core registers GDB XML description.
  * @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop
@@ -163,15 +155,6 @@ struct CPUClass {
 int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg);
 int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg);
 
-int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu,
-int cpuid, void *opaque);
-int (*write_elf64_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
-void *opaque);
-int (*write_elf32_note)(WriteCoreDumpFunction f, CPUState *cpu,
-int cpuid, void *opaque);
-int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
-void *opaque);
-
 const char *gdb_core_xml_file;
 gchar * (*gdb_arch_name)(CPUState *cpu);
 const char * (*gdb_get_dynamic_xml)(CPUState *cpu, const char *xmlname);
diff --git a/include/hw/core/sysemu-cpu-ops.h b/include/hw/core/sysemu-cpu-ops.h
index f7a91a66e06..bdc76d580e9 100644
--- a/include/hw/core/sysemu-cpu-ops.h
+++ b/include/hw/core/sysemu-cpu-ops.h
@@ -21,6 +21,30 @@ typedef struct SysemuCPUOps {
  * GUEST_PANICKED events.
  */
 GuestPanicInformation* (*get_crash_info)(CPUState *cpu);
+/**
+ * @write_elf32_note: Callback for writing a CPU-specific ELF note to a
+ * 32-bit VM coredump.
+ */
+int (*write_elf32_note)(WriteCoreDumpFunction f, CPUState *cpu,
+int cpuid, void *opaque);
+/**
+ * @write_elf64_note: Callback for writing a CPU-specific ELF note to a
+ * 64-bit VM coredump.
+ */
+int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu,
+int cpuid, void *opaque);
+/**
+ * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
+ * note to a 32-bit VM coredump.
+ */
+int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
+void *opaque);
+/**
+ * @write_elf64_qemunote: Callback for writing a CPU- and QEMU-specific ELF
+ * note to a 64-bit VM coredump.
+ */
+int (*write_elf64_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
+void *opaque);
 /**
  * @virtio_is_big_endian: Callback to return %true if a CPU which supports
  *   runtime configurable endianness is currently big-endian.
diff --git a/hw/core/cpu.c b/hw/core/cpu.c
index 0aebc18c41f..c74390aafbf 100644
--- a/hw/core/cpu.c
+++ b/hw/core/cpu.c
@@ -151,10 +151,10 @@ int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, 
CPUState *cpu,
 {
 CPUClass *cc = CPU_GET_CLASS(cpu);
 
-if (!cc->write_elf32_qemunote) {
+if (!cc->sysemu_ops->write_elf32_qemunote) {
 return 0;
 }
-return (*cc->write_elf32_qemunote)(f, cpu, opaque);
+return (*cc->sysemu_ops->write_elf32_qemunote)(f, cpu, opaque);
 }
 
 int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
@@ -162,10 +162,10 @@ int cpu_write_elf32_note(WriteCoreDumpFunction f, 
CPUState *cpu,
 {
 CPUClass *cc = CPU_GET_CLASS(cpu);
 
-if (!cc->write_elf32_note) {
+if (!cc->sysemu_ops->write_elf32_note) {
 return -1;
 }
-return (*cc->write_elf32_note)(f, cpu, cpuid, opaque);
+return (*cc->sysemu_ops->write_elf32_note)(f, cpu, cpuid, opaque);
 }
 
 int cpu_write_

[PATCH v6 17/18] cpu: Move CPUClass::get_paging_enabled to SysemuCPUOps

2021-04-22 Thread Philippe Mathieu-Daudé
Reviewed-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/core/cpu.h| 2 --
 include/hw/core/sysemu-cpu-ops.h | 4 
 hw/core/cpu.c| 4 ++--
 target/i386/cpu.c| 4 +++-
 4 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 6dd60c3ada4..d0187798eea 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -93,7 +93,6 @@ struct AccelCPUClass;
  * @dump_state: Callback for dumping state.
  * @dump_statistics: Callback for dumping statistics.
  * @get_arch_id: Callback for getting architecture-dependent CPU ID.
- * @get_paging_enabled: Callback for inquiring whether paging is enabled.
  * @set_pc: Callback for setting the Program Counter register. This
  *   should have the semantics used by the target architecture when
  *   setting the PC from a source such as an ELF file entry point;
@@ -136,7 +135,6 @@ struct CPUClass {
 void (*dump_state)(CPUState *cpu, FILE *, int flags);
 void (*dump_statistics)(CPUState *cpu, int flags);
 int64_t (*get_arch_id)(CPUState *cpu);
-bool (*get_paging_enabled)(const CPUState *cpu);
 void (*set_pc)(CPUState *cpu, vaddr value);
 int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg);
 int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg);
diff --git a/include/hw/core/sysemu-cpu-ops.h b/include/hw/core/sysemu-cpu-ops.h
index 344561b7827..f0707f012b4 100644
--- a/include/hw/core/sysemu-cpu-ops.h
+++ b/include/hw/core/sysemu-cpu-ops.h
@@ -21,6 +21,10 @@ typedef struct SysemuCPUOps {
  */
 void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list,
Error **errp);
+/**
+ * @get_paging_enabled: Callback for inquiring whether paging is enabled.
+ */
+bool (*get_paging_enabled)(const CPUState *cpu);
 /**
  * @get_phys_page_debug: Callback for obtaining a physical address.
  */
diff --git a/hw/core/cpu.c b/hw/core/cpu.c
index 339bdfadd7a..7a8487d468f 100644
--- a/hw/core/cpu.c
+++ b/hw/core/cpu.c
@@ -71,8 +71,8 @@ bool cpu_paging_enabled(const CPUState *cpu)
 {
 CPUClass *cc = CPU_GET_CLASS(cpu);
 
-if (cc->get_paging_enabled) {
-return cc->get_paging_enabled(cpu);
+if (cc->sysemu_ops->get_paging_enabled) {
+return cc->sysemu_ops->get_paging_enabled(cpu);
 }
 
 return false;
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 5d35d8e329f..abdebdfe9b8 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -7162,12 +7162,14 @@ static int64_t x86_cpu_get_arch_id(CPUState *cs)
 return cpu->apic_id;
 }
 
+#if !defined(CONFIG_USER_ONLY)
 static bool x86_cpu_get_paging_enabled(const CPUState *cs)
 {
 X86CPU *cpu = X86_CPU(cs);
 
 return cpu->env.cr[0] & CR0_PG_MASK;
 }
+#endif /* !CONFIG_USER_ONLY */
 
 static void x86_cpu_set_pc(CPUState *cs, vaddr value)
 {
@@ -7394,6 +7396,7 @@ static Property x86_cpu_properties[] = {
 #ifndef CONFIG_USER_ONLY
 static const struct SysemuCPUOps i386_sysemu_ops = {
 .get_memory_mapping = x86_cpu_get_memory_mapping,
+.get_paging_enabled = x86_cpu_get_paging_enabled,
 .get_phys_page_attrs_debug = x86_cpu_get_phys_page_attrs_debug,
 .asidx_from_attrs = x86_asidx_from_attrs,
 .get_crash_info = x86_cpu_get_crash_info,
@@ -7434,7 +7437,6 @@ static void x86_cpu_common_class_init(ObjectClass *oc, 
void *data)
 cc->gdb_read_register = x86_cpu_gdb_read_register;
 cc->gdb_write_register = x86_cpu_gdb_write_register;
 cc->get_arch_id = x86_cpu_get_arch_id;
-cc->get_paging_enabled = x86_cpu_get_paging_enabled;
 
 #ifndef CONFIG_USER_ONLY
 cc->sysemu_ops = &i386_sysemu_ops;
-- 
2.26.3




[RFC PATCH 4/4] target/ppc: transfered functions to non-tcg-only files

2021-04-22 Thread Lucas Mateus Castro (alqotel)
moved the functions ppc_store_lpcr and ppc_hash64_filter_pagesizes to
common-misc.c so they can be used in a disable-tcg build and added the
necessary includes to files that call them. Created
ppc_(store|load)_vscr to be used by both tcg and kvm.

Signed-off-by: Lucas Mateus Castro (alqotel) 
---
 hw/ppc/spapr.c|  1 +
 hw/ppc/spapr_caps.c   |  1 +
 hw/ppc/spapr_cpu_core.c   |  1 +
 hw/ppc/spapr_hcall.c  |  1 +
 hw/ppc/spapr_hcall_tcg_stub.c |  1 +
 hw/ppc/spapr_rtas.c   |  1 +
 target/ppc/common-misc.c  | 86 +++
 target/ppc/common-misc.h  | 13 ++
 target/ppc/int_helper.c   | 10 ++--
 target/ppc/meson.build|  1 +
 target/ppc/mmu-hash64.c   | 67 +--
 target/ppc/mmu-hash64.h   |  4 --
 12 files changed, 110 insertions(+), 77 deletions(-)
 create mode 100644 target/ppc/common-misc.c
 create mode 100644 target/ppc/common-misc.h

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index e4be00b732..f41accd5ec 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -52,6 +52,7 @@
 #include "mmu-hash64.h"
 #include "mmu-book3s-v3.h"
 #include "cpu-models.h"
+#include "common-misc.h"
 #include "hw/core/cpu.h"
 
 #include "hw/boards.h"
diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
index 9ea7ddd1e9..1bf55459b0 100644
--- a/hw/ppc/spapr_caps.c
+++ b/hw/ppc/spapr_caps.c
@@ -34,6 +34,7 @@
 #include "kvm_ppc.h"
 #include "migration/vmstate.h"
 #include "sysemu/tcg.h"
+#include "common-misc.h"
 
 #include "hw/ppc/spapr.h"
 
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index 4f316a6f9d..62f19700f5 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -24,6 +24,7 @@
 #include "sysemu/reset.h"
 #include "sysemu/hw_accel.h"
 #include "qemu/error-report.h"
+#include "common-misc.h"
 
 static void spapr_reset_vcpu(PowerPCCPU *cpu)
 {
diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index 7b5cd3553c..e8a9bfbcbb 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -20,6 +20,7 @@
 #include "hw/ppc/spapr_ovec.h"
 #include "mmu-book3s-v3.h"
 #include "hw/mem/memory-device.h"
+#include "common-misc.h"
 
 static bool has_spr(PowerPCCPU *cpu, int spr)
 {
diff --git a/hw/ppc/spapr_hcall_tcg_stub.c b/hw/ppc/spapr_hcall_tcg_stub.c
index 6682279b6e..7dca9ff2a9 100644
--- a/hw/ppc/spapr_hcall_tcg_stub.c
+++ b/hw/ppc/spapr_hcall_tcg_stub.c
@@ -20,6 +20,7 @@
 #include "hw/ppc/spapr_ovec.h"
 #include "mmu-book3s-v3.h"
 #include "hw/mem/memory-device.h"
+#include "common-misc.h"
 
 static bool has_spr(PowerPCCPU *cpu, int spr)
 {
diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
index 8a79f9c628..8c8c50e498 100644
--- a/hw/ppc/spapr_rtas.c
+++ b/hw/ppc/spapr_rtas.c
@@ -35,6 +35,7 @@
 #include "sysemu/hw_accel.h"
 #include "sysemu/runstate.h"
 #include "kvm_ppc.h"
+#include "common-misc.h"
 
 #include "hw/ppc/spapr.h"
 #include "hw/ppc/spapr_vio.h"
diff --git a/target/ppc/common-misc.c b/target/ppc/common-misc.c
new file mode 100644
index 00..5e860d6245
--- /dev/null
+++ b/target/ppc/common-misc.c
@@ -0,0 +1,86 @@
+#include "qemu/osdep.h"
+#include "common-misc.h"
+#include "mmu-hash64.h"
+#include "fpu/softfloat-helpers.h"
+
+void ppc_store_vscr(CPUPPCState *env, uint64_t vscr)
+{
+env->vscr = vscr & ~(1u << VSCR_SAT);
+/* Which bit we set is completely arbitrary, but clear the rest.  */
+env->vscr_sat.u64[0] = vscr & (1u << VSCR_SAT);
+env->vscr_sat.u64[1] = 0;
+set_flush_to_zero((vscr >> VSCR_NJ) & 1, &env->vec_status);
+}
+
+uint32_t ppc_load_vscr(CPUPPCState *env)
+{
+uint32_t sat = (env->vscr_sat.u64[0] | env->vscr_sat.u64[1]) != 0;
+return env->vscr | (sat << VSCR_SAT);
+}
+
+void ppc_store_lpcr(PowerPCCPU *cpu, target_ulong val)
+{
+PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
+CPUPPCState *env = &cpu->env;
+
+env->spr[SPR_LPCR] = val & pcc->lpcr_mask;
+}
+
+void ppc_hash64_filter_pagesizes(PowerPCCPU *cpu,
+ bool (*cb)(void *, uint32_t, uint32_t),
+ void *opaque)
+{
+PPCHash64Options *opts = cpu->hash64_opts;
+int i;
+int n = 0;
+bool ci_largepage = false;
+
+assert(opts);
+
+n = 0;
+for (i = 0; i < ARRAY_SIZE(opts->sps); i++) {
+PPCHash64SegmentPageSizes *sps = &opts->sps[i];
+int j;
+int m = 0;
+
+assert(n <= i);
+
+if (!sps->page_shift) {
+break;
+}
+
+for (j = 0; j < ARRAY_SIZE(sps->enc); j++) {
+PPCHash64PageSize *ps = &sps->enc[j];
+
+assert(m <= j);
+if (!ps->page_shift) {
+break;
+}
+
+if (cb(opaque, sps->page_shift, ps->page_shift)) {
+if (ps->page_shift >= 16) {
+ci_largepage = true;
+}
+sps->enc[m++] = *ps;
+}
+}
+
+/* Clear rest of the row */
+for (j = m

[PATCH v6 09/18] cpu: Introduce SysemuCPUOps structure

2021-04-22 Thread Philippe Mathieu-Daudé
Introduce a structure to hold handler specific to sysemu.

Reviewed-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/core/cpu.h|  5 +
 include/hw/core/sysemu-cpu-ops.h | 21 +
 target/alpha/cpu.c   |  6 ++
 target/arm/cpu.c |  6 ++
 target/avr/cpu.c |  4 
 target/cris/cpu.c|  6 ++
 target/hppa/cpu.c|  6 ++
 target/i386/cpu.c|  6 ++
 target/lm32/cpu.c|  6 ++
 target/m68k/cpu.c|  6 ++
 target/microblaze/cpu.c  |  6 ++
 target/mips/cpu.c|  6 ++
 target/moxie/cpu.c   |  4 
 target/nios2/cpu.c   |  6 ++
 target/openrisc/cpu.c|  6 ++
 target/riscv/cpu.c   |  6 ++
 target/rx/cpu.c  |  8 
 target/s390x/cpu.c   |  6 ++
 target/sh4/cpu.c |  4 
 target/sparc/cpu.c   |  6 ++
 target/tricore/cpu.c |  4 
 target/unicore32/cpu.c   |  4 
 target/xtensa/cpu.c  |  4 
 target/ppc/translate_init.c.inc  |  6 ++
 24 files changed, 148 insertions(+)
 create mode 100644 include/hw/core/sysemu-cpu-ops.h

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 10dd16531ba..23b718a4a51 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -80,6 +80,8 @@ struct TCGCPUOps;
 /* see accel-cpu.h */
 struct AccelCPUClass;
 
+#include "hw/core/sysemu-cpu-ops.h"
+
 /**
  * CPUClass:
  * @class_by_name: Callback to map -cpu command line model name to an
@@ -191,6 +193,9 @@ struct CPUClass {
 bool gdb_stop_before_watchpoint;
 struct AccelCPUClass *accel_cpu;
 
+/* when system emulation is not available, this pointer is NULL */
+const struct SysemuCPUOps *sysemu_ops;
+
 /* when TCG is not available, this pointer is NULL */
 struct TCGCPUOps *tcg_ops;
 };
diff --git a/include/hw/core/sysemu-cpu-ops.h b/include/hw/core/sysemu-cpu-ops.h
new file mode 100644
index 000..e54a08ea25e
--- /dev/null
+++ b/include/hw/core/sysemu-cpu-ops.h
@@ -0,0 +1,21 @@
+/*
+ * CPU operations specific to system emulation
+ *
+ * Copyright (c) 2012 SUSE LINUX Products GmbH
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef SYSEMU_CPU_OPS_H
+#define SYSEMU_CPU_OPS_H
+
+#include "hw/core/cpu.h"
+
+/*
+ * struct SysemuCPUOps: System operations specific to a CPU class
+ */
+typedef struct SysemuCPUOps {
+} SysemuCPUOps;
+
+#endif /* SYSEMU_CPU_OPS_H */
diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c
index 27192b62e22..cd01d34d92f 100644
--- a/target/alpha/cpu.c
+++ b/target/alpha/cpu.c
@@ -206,6 +206,11 @@ static void alpha_cpu_initfn(Object *obj)
 #endif
 }
 
+#ifndef CONFIG_USER_ONLY
+static const struct SysemuCPUOps alpha_sysemu_ops = {
+};
+#endif
+
 #include "hw/core/tcg-cpu-ops.h"
 
 static struct TCGCPUOps alpha_tcg_ops = {
@@ -238,6 +243,7 @@ static void alpha_cpu_class_init(ObjectClass *oc, void 
*data)
 #ifndef CONFIG_USER_ONLY
 cc->get_phys_page_debug = alpha_cpu_get_phys_page_debug;
 dc->vmsd = &vmstate_alpha_cpu;
+cc->sysemu_ops = &alpha_sysemu_ops;
 #endif
 cc->disas_set_info = alpha_cpu_disas_set_info;
 
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 3062e8c702e..c1943194cf1 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -1943,6 +1943,11 @@ static gchar *arm_gdb_arch_name(CPUState *cs)
 return g_strdup("arm");
 }
 
+#ifndef CONFIG_USER_ONLY
+static const struct SysemuCPUOps arm_sysemu_ops = {
+};
+#endif
+
 #ifdef CONFIG_TCG
 static struct TCGCPUOps arm_tcg_ops = {
 .initialize = arm_translate_init,
@@ -1986,6 +1991,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void 
*data)
 cc->virtio_is_big_endian = arm_cpu_virtio_is_big_endian;
 cc->write_elf64_note = arm_cpu_write_elf64_note;
 cc->write_elf32_note = arm_cpu_write_elf32_note;
+cc->sysemu_ops = &arm_sysemu_ops;
 #endif
 cc->gdb_num_core_regs = 26;
 cc->gdb_core_xml_file = "arm-core.xml";
diff --git a/target/avr/cpu.c b/target/avr/cpu.c
index 3353bcb9fc7..5c8bb9b3fec 100644
--- a/target/avr/cpu.c
+++ b/target/avr/cpu.c
@@ -184,6 +184,9 @@ static void avr_cpu_dump_state(CPUState *cs, FILE *f, int 
flags)
 qemu_fprintf(f, "\n");
 }
 
+static const struct SysemuCPUOps avr_sysemu_ops = {
+};
+
 #include "hw/core/tcg-cpu-ops.h"
 
 static struct TCGCPUOps avr_tcg_ops = {
@@ -214,6 +217,7 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data)
 cc->memory_rw_debug = avr_cpu_memory_rw_debug;
 cc->get_phys_page_debug = avr_cpu_get_phys_page_debug;
 dc->vmsd = &vms_avr_cpu;
+cc->sysemu_ops = &avr_sysemu_ops;
 cc->disas_set_info = avr_cpu_disas_set_info;
 cc->gdb_read_register = avr_cpu_gdb_read_register;
 cc->gdb_write_re

[PATCH v6 12/18] cpu: Move CPUClass::get_crash_info to SysemuCPUOps

2021-04-22 Thread Philippe Mathieu-Daudé
cpu_get_crash_info() is called on GUEST_PANICKED events,
which only occur in system emulation.

Reviewed-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/core/cpu.h| 1 -
 include/hw/core/sysemu-cpu-ops.h | 5 +
 hw/core/cpu.c| 4 ++--
 target/i386/cpu.c| 2 +-
 target/s390x/cpu.c   | 2 +-
 5 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index e3c702b8b74..4289cd0d78a 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -150,7 +150,6 @@ struct CPUClass {
 int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
uint8_t *buf, int len, bool is_write);
 void (*dump_state)(CPUState *cpu, FILE *, int flags);
-GuestPanicInformation* (*get_crash_info)(CPUState *cpu);
 void (*dump_statistics)(CPUState *cpu, int flags);
 int64_t (*get_arch_id)(CPUState *cpu);
 bool (*get_paging_enabled)(const CPUState *cpu);
diff --git a/include/hw/core/sysemu-cpu-ops.h b/include/hw/core/sysemu-cpu-ops.h
index 1c325d62b94..f7a91a66e06 100644
--- a/include/hw/core/sysemu-cpu-ops.h
+++ b/include/hw/core/sysemu-cpu-ops.h
@@ -16,6 +16,11 @@
  * struct SysemuCPUOps: System operations specific to a CPU class
  */
 typedef struct SysemuCPUOps {
+/**
+ * @get_crash_info: Callback for reporting guest crash information in
+ * GUEST_PANICKED events.
+ */
+GuestPanicInformation* (*get_crash_info)(CPUState *cpu);
 /**
  * @virtio_is_big_endian: Callback to return %true if a CPU which supports
  *   runtime configurable endianness is currently big-endian.
diff --git a/hw/core/cpu.c b/hw/core/cpu.c
index 09eaa3fa49f..0aebc18c41f 100644
--- a/hw/core/cpu.c
+++ b/hw/core/cpu.c
@@ -220,8 +220,8 @@ GuestPanicInformation *cpu_get_crash_info(CPUState *cpu)
 CPUClass *cc = CPU_GET_CLASS(cpu);
 GuestPanicInformation *res = NULL;
 
-if (cc->get_crash_info) {
-res = cc->get_crash_info(cpu);
+if (cc->sysemu_ops->get_crash_info) {
+res = cc->sysemu_ops->get_crash_info(cpu);
 }
 return res;
 }
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index eb96dd42556..ab0c07fe9b4 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -7393,6 +7393,7 @@ static Property x86_cpu_properties[] = {
 
 #ifndef CONFIG_USER_ONLY
 static const struct SysemuCPUOps i386_sysemu_ops = {
+.get_crash_info = x86_cpu_get_crash_info,
 .legacy_vmsd = &vmstate_x86_cpu,
 };
 #endif
@@ -7432,7 +7433,6 @@ static void x86_cpu_common_class_init(ObjectClass *oc, 
void *data)
 cc->asidx_from_attrs = x86_asidx_from_attrs;
 cc->get_memory_mapping = x86_cpu_get_memory_mapping;
 cc->get_phys_page_attrs_debug = x86_cpu_get_phys_page_attrs_debug;
-cc->get_crash_info = x86_cpu_get_crash_info;
 cc->write_elf64_note = x86_cpu_write_elf64_note;
 cc->write_elf64_qemunote = x86_cpu_write_elf64_qemunote;
 cc->write_elf32_note = x86_cpu_write_elf32_note;
diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c
index 131e7dfdf82..55d7a727602 100644
--- a/target/s390x/cpu.c
+++ b/target/s390x/cpu.c
@@ -479,6 +479,7 @@ static void s390_cpu_reset_full(DeviceState *dev)
 
 #ifndef CONFIG_USER_ONLY
 static const struct SysemuCPUOps s390_sysemu_ops = {
+.get_crash_info = s390_cpu_get_crash_info,
 .legacy_vmsd = &vmstate_s390_cpu,
 };
 #endif
@@ -523,7 +524,6 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)
 cc->gdb_write_register = s390_cpu_gdb_write_register;
 #ifndef CONFIG_USER_ONLY
 cc->get_phys_page_debug = s390_cpu_get_phys_page_debug;
-cc->get_crash_info = s390_cpu_get_crash_info;
 cc->write_elf64_note = s390_cpu_write_elf64_note;
 cc->sysemu_ops = &s390_sysemu_ops;
 #endif
-- 
2.26.3




[PATCH v6 08/18] cpu/{avr, lm32, moxie}: Set DeviceClass vmsd field (not CPUClass one)

2021-04-22 Thread Philippe Mathieu-Daudé
See rationale in previous commit. Targets should use the vmsd field
of DeviceClass, not CPUClass. As migration is not important on the
avr/lm32/moxie targets, break the migration compatibility and set
the DeviceClass vmsd field.

Signed-off-by: Philippe Mathieu-Daudé 
---
 target/avr/cpu.c   | 2 +-
 target/lm32/cpu.c  | 2 +-
 target/moxie/cpu.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/target/avr/cpu.c b/target/avr/cpu.c
index 37a8ebcc86f..3353bcb9fc7 100644
--- a/target/avr/cpu.c
+++ b/target/avr/cpu.c
@@ -213,7 +213,7 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data)
 cc->set_pc = avr_cpu_set_pc;
 cc->memory_rw_debug = avr_cpu_memory_rw_debug;
 cc->get_phys_page_debug = avr_cpu_get_phys_page_debug;
-cc->legacy_vmsd = &vms_avr_cpu;
+dc->vmsd = &vms_avr_cpu;
 cc->disas_set_info = avr_cpu_disas_set_info;
 cc->gdb_read_register = avr_cpu_gdb_read_register;
 cc->gdb_write_register = avr_cpu_gdb_write_register;
diff --git a/target/lm32/cpu.c b/target/lm32/cpu.c
index c0388142528..e27c1a8bc97 100644
--- a/target/lm32/cpu.c
+++ b/target/lm32/cpu.c
@@ -241,7 +241,7 @@ static void lm32_cpu_class_init(ObjectClass *oc, void *data)
 cc->gdb_write_register = lm32_cpu_gdb_write_register;
 #ifndef CONFIG_USER_ONLY
 cc->get_phys_page_debug = lm32_cpu_get_phys_page_debug;
-cc->legacy_vmsd = &vmstate_lm32_cpu;
+dc->vmsd = &vmstate_lm32_cpu;
 #endif
 cc->gdb_num_core_regs = 32 + 7;
 cc->gdb_stop_before_watchpoint = true;
diff --git a/target/moxie/cpu.c b/target/moxie/cpu.c
index 3c81a088eaa..e5da3fa3f17 100644
--- a/target/moxie/cpu.c
+++ b/target/moxie/cpu.c
@@ -122,7 +122,7 @@ static void moxie_cpu_class_init(ObjectClass *oc, void 
*data)
 cc->set_pc = moxie_cpu_set_pc;
 #ifndef CONFIG_USER_ONLY
 cc->get_phys_page_debug = moxie_cpu_get_phys_page_debug;
-cc->legacy_vmsd = &vmstate_moxie_cpu;
+dc->vmsd = &vmstate_moxie_cpu;
 #endif
 cc->disas_set_info = moxie_cpu_disas_set_info;
 cc->tcg_ops = &moxie_tcg_ops;
-- 
2.26.3




[PATCH v6 14/18] cpu: Move CPUClass::asidx_from_attrs to SysemuCPUOps

2021-04-22 Thread Philippe Mathieu-Daudé
Reviewed-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/core/cpu.h| 3 ---
 include/hw/core/sysemu-cpu-ops.h | 5 +
 hw/core/cpu.c| 4 ++--
 target/arm/cpu.c | 2 +-
 target/i386/cpu.c| 2 +-
 5 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index b7095bc4192..28c4fc541a2 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -108,8 +108,6 @@ struct AccelCPUClass;
  *   associated memory transaction attributes to use for the access.
  *   CPUs which use memory transaction attributes should implement this
  *   instead of get_phys_page_debug.
- * @asidx_from_attrs: Callback to return the CPU AddressSpace to use for
- *   a memory access with the specified memory transaction attributes.
  * @gdb_read_register: Callback for letting GDB read a register.
  * @gdb_write_register: Callback for letting GDB write a register.
  * @gdb_num_core_regs: Number of core registers accessible to GDB.
@@ -151,7 +149,6 @@ struct CPUClass {
 hwaddr (*get_phys_page_debug)(CPUState *cpu, vaddr addr);
 hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu, vaddr addr,
 MemTxAttrs *attrs);
-int (*asidx_from_attrs)(CPUState *cpu, MemTxAttrs attrs);
 int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg);
 int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg);
 
diff --git a/include/hw/core/sysemu-cpu-ops.h b/include/hw/core/sysemu-cpu-ops.h
index bdc76d580e9..52a05ea9b3e 100644
--- a/include/hw/core/sysemu-cpu-ops.h
+++ b/include/hw/core/sysemu-cpu-ops.h
@@ -16,6 +16,11 @@
  * struct SysemuCPUOps: System operations specific to a CPU class
  */
 typedef struct SysemuCPUOps {
+/**
+ * @asidx_from_attrs: Callback to return the CPU AddressSpace to use for
+ *   a memory access with the specified memory transaction attributes.
+ */
+int (*asidx_from_attrs)(CPUState *cpu, MemTxAttrs attrs);
 /**
  * @get_crash_info: Callback for reporting guest crash information in
  * GUEST_PANICKED events.
diff --git a/hw/core/cpu.c b/hw/core/cpu.c
index c74390aafbf..c44229205ff 100644
--- a/hw/core/cpu.c
+++ b/hw/core/cpu.c
@@ -116,8 +116,8 @@ int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
 CPUClass *cc = CPU_GET_CLASS(cpu);
 int ret = 0;
 
-if (cc->asidx_from_attrs) {
-ret = cc->asidx_from_attrs(cpu, attrs);
+if (cc->sysemu_ops->asidx_from_attrs) {
+ret = cc->sysemu_ops->asidx_from_attrs(cpu, attrs);
 assert(ret < cpu->num_ases && ret >= 0);
 }
 return ret;
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index cbfdb9d0b70..e030890c11b 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -1945,6 +1945,7 @@ static gchar *arm_gdb_arch_name(CPUState *cs)
 
 #ifndef CONFIG_USER_ONLY
 static const struct SysemuCPUOps arm_sysemu_ops = {
+.asidx_from_attrs = arm_asidx_from_attrs,
 .write_elf32_note = arm_cpu_write_elf32_note,
 .write_elf64_note = arm_cpu_write_elf64_note,
 .virtio_is_big_endian = arm_cpu_virtio_is_big_endian,
@@ -1990,7 +1991,6 @@ static void arm_cpu_class_init(ObjectClass *oc, void 
*data)
 cc->gdb_write_register = arm_cpu_gdb_write_register;
 #ifndef CONFIG_USER_ONLY
 cc->get_phys_page_attrs_debug = arm_cpu_get_phys_page_attrs_debug;
-cc->asidx_from_attrs = arm_asidx_from_attrs;
 cc->sysemu_ops = &arm_sysemu_ops;
 #endif
 cc->gdb_num_core_regs = 26;
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index fd7788907ea..70b0108b748 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -7393,6 +7393,7 @@ static Property x86_cpu_properties[] = {
 
 #ifndef CONFIG_USER_ONLY
 static const struct SysemuCPUOps i386_sysemu_ops = {
+.asidx_from_attrs = x86_asidx_from_attrs,
 .get_crash_info = x86_cpu_get_crash_info,
 .write_elf32_note = x86_cpu_write_elf32_note,
 .write_elf64_note = x86_cpu_write_elf64_note,
@@ -7434,7 +7435,6 @@ static void x86_cpu_common_class_init(ObjectClass *oc, 
void *data)
 cc->get_paging_enabled = x86_cpu_get_paging_enabled;
 
 #ifndef CONFIG_USER_ONLY
-cc->asidx_from_attrs = x86_asidx_from_attrs;
 cc->get_memory_mapping = x86_cpu_get_memory_mapping;
 cc->get_phys_page_attrs_debug = x86_cpu_get_phys_page_attrs_debug;
 cc->sysemu_ops = &i386_sysemu_ops;
-- 
2.26.3




[PATCH v6 16/18] cpu: Move CPUClass::get_memory_mapping to SysemuCPUOps

2021-04-22 Thread Philippe Mathieu-Daudé
Reviewed-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/core/cpu.h| 3 ---
 include/hw/core/sysemu-cpu-ops.h | 5 +
 hw/core/cpu.c| 4 ++--
 target/i386/cpu.c| 2 +-
 4 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 88a0a90ac7b..6dd60c3ada4 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -94,7 +94,6 @@ struct AccelCPUClass;
  * @dump_statistics: Callback for dumping statistics.
  * @get_arch_id: Callback for getting architecture-dependent CPU ID.
  * @get_paging_enabled: Callback for inquiring whether paging is enabled.
- * @get_memory_mapping: Callback for obtaining the memory mappings.
  * @set_pc: Callback for setting the Program Counter register. This
  *   should have the semantics used by the target architecture when
  *   setting the PC from a source such as an ELF file entry point;
@@ -138,8 +137,6 @@ struct CPUClass {
 void (*dump_statistics)(CPUState *cpu, int flags);
 int64_t (*get_arch_id)(CPUState *cpu);
 bool (*get_paging_enabled)(const CPUState *cpu);
-void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list,
-   Error **errp);
 void (*set_pc)(CPUState *cpu, vaddr value);
 int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg);
 int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg);
diff --git a/include/hw/core/sysemu-cpu-ops.h b/include/hw/core/sysemu-cpu-ops.h
index 4be4a4b4da7..344561b7827 100644
--- a/include/hw/core/sysemu-cpu-ops.h
+++ b/include/hw/core/sysemu-cpu-ops.h
@@ -16,6 +16,11 @@
  * struct SysemuCPUOps: System operations specific to a CPU class
  */
 typedef struct SysemuCPUOps {
+/**
+ * @get_memory_mapping: Callback for obtaining the memory mappings.
+ */
+void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list,
+   Error **errp);
 /**
  * @get_phys_page_debug: Callback for obtaining a physical address.
  */
diff --git a/hw/core/cpu.c b/hw/core/cpu.c
index 6932781425a..339bdfadd7a 100644
--- a/hw/core/cpu.c
+++ b/hw/core/cpu.c
@@ -83,8 +83,8 @@ void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList 
*list,
 {
 CPUClass *cc = CPU_GET_CLASS(cpu);
 
-if (cc->get_memory_mapping) {
-cc->get_memory_mapping(cpu, list, errp);
+if (cc->sysemu_ops->get_memory_mapping) {
+cc->sysemu_ops->get_memory_mapping(cpu, list, errp);
 return;
 }
 
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index ead0aafd9d1..5d35d8e329f 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -7393,6 +7393,7 @@ static Property x86_cpu_properties[] = {
 
 #ifndef CONFIG_USER_ONLY
 static const struct SysemuCPUOps i386_sysemu_ops = {
+.get_memory_mapping = x86_cpu_get_memory_mapping,
 .get_phys_page_attrs_debug = x86_cpu_get_phys_page_attrs_debug,
 .asidx_from_attrs = x86_asidx_from_attrs,
 .get_crash_info = x86_cpu_get_crash_info,
@@ -7436,7 +7437,6 @@ static void x86_cpu_common_class_init(ObjectClass *oc, 
void *data)
 cc->get_paging_enabled = x86_cpu_get_paging_enabled;
 
 #ifndef CONFIG_USER_ONLY
-cc->get_memory_mapping = x86_cpu_get_memory_mapping;
 cc->sysemu_ops = &i386_sysemu_ops;
 #endif /* !CONFIG_USER_ONLY */
 
-- 
2.26.3




[PATCH v6 06/18] cpu: Assert DeviceClass::vmsd is NULL on user emulation

2021-04-22 Thread Philippe Mathieu-Daudé
Migration is specific to system emulation.

Restrict current DeviceClass::vmsd to sysemu using #ifdef'ry,
and assert in cpu_exec_realizefn() that dc->vmsd not set under
user emulation.

Signed-off-by: Philippe Mathieu-Daudé 
---
 cpu.c  | 1 +
 target/sh4/cpu.c   | 5 +++--
 target/unicore32/cpu.c | 4 
 target/xtensa/cpu.c| 4 +++-
 4 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/cpu.c b/cpu.c
index bfbe5a66f95..4fed04219df 100644
--- a/cpu.c
+++ b/cpu.c
@@ -138,6 +138,7 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp)
 #endif /* CONFIG_TCG */
 
 #ifdef CONFIG_USER_ONLY
+assert(qdev_get_vmsd(DEVICE(cpu)) == NULL);
 assert(cc->vmsd == NULL);
 #else
 if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c
index ac65c88f1f8..35d4251aaf3 100644
--- a/target/sh4/cpu.c
+++ b/target/sh4/cpu.c
@@ -218,10 +218,12 @@ static void superh_cpu_initfn(Object *obj)
 env->movcal_backup_tail = &(env->movcal_backup);
 }
 
+#ifndef CONFIG_USER_ONLY
 static const VMStateDescription vmstate_sh_cpu = {
 .name = "cpu",
 .unmigratable = 1,
 };
+#endif
 
 #include "hw/core/tcg-cpu-ops.h"
 
@@ -257,12 +259,11 @@ static void superh_cpu_class_init(ObjectClass *oc, void 
*data)
 cc->gdb_write_register = superh_cpu_gdb_write_register;
 #ifndef CONFIG_USER_ONLY
 cc->get_phys_page_debug = superh_cpu_get_phys_page_debug;
+dc->vmsd = &vmstate_sh_cpu;
 #endif
 cc->disas_set_info = superh_cpu_disas_set_info;
 
 cc->gdb_num_core_regs = 59;
-
-dc->vmsd = &vmstate_sh_cpu;
 cc->tcg_ops = &superh_tcg_ops;
 }
 
diff --git a/target/unicore32/cpu.c b/target/unicore32/cpu.c
index 0258884f845..a74ac7b6140 100644
--- a/target/unicore32/cpu.c
+++ b/target/unicore32/cpu.c
@@ -115,10 +115,12 @@ static void uc32_cpu_initfn(Object *obj)
 #endif
 }
 
+#ifndef CONFIG_USER_ONLY
 static const VMStateDescription vmstate_uc32_cpu = {
 .name = "cpu",
 .unmigratable = 1,
 };
+#endif
 
 #include "hw/core/tcg-cpu-ops.h"
 
@@ -146,7 +148,9 @@ static void uc32_cpu_class_init(ObjectClass *oc, void *data)
 cc->dump_state = uc32_cpu_dump_state;
 cc->set_pc = uc32_cpu_set_pc;
 cc->get_phys_page_debug = uc32_cpu_get_phys_page_debug;
+#ifndef CONFIG_USER_ONLY
 dc->vmsd = &vmstate_uc32_cpu;
+#endif
 cc->tcg_ops = &uc32_tcg_ops;
 }
 
diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c
index e2b2c7a71c1..a66527e2d45 100644
--- a/target/xtensa/cpu.c
+++ b/target/xtensa/cpu.c
@@ -176,10 +176,12 @@ static void xtensa_cpu_initfn(Object *obj)
 #endif
 }
 
+#ifndef CONFIG_USER_ONLY
 static const VMStateDescription vmstate_xtensa_cpu = {
 .name = "cpu",
 .unmigratable = 1,
 };
+#endif
 
 #include "hw/core/tcg-cpu-ops.h"
 
@@ -216,9 +218,9 @@ static void xtensa_cpu_class_init(ObjectClass *oc, void 
*data)
 cc->gdb_stop_before_watchpoint = true;
 #ifndef CONFIG_USER_ONLY
 cc->get_phys_page_debug = xtensa_cpu_get_phys_page_debug;
+dc->vmsd = &vmstate_xtensa_cpu;
 #endif
 cc->disas_set_info = xtensa_cpu_disas_set_info;
-dc->vmsd = &vmstate_xtensa_cpu;
 cc->tcg_ops = &xtensa_tcg_ops;
 }
 
-- 
2.26.3




[PATCH v6 07/18] cpu: Rename CPUClass vmsd -> legacy_vmsd

2021-04-22 Thread Philippe Mathieu-Daudé
Quoting Peter Maydell [*]:

  There are two ways to handle migration for
  a CPU object:

  (1) like any other device, so it has a dc->vmsd that covers
  migration for the whole object. As usual for objects that are a
  subclass of a parent that has state, the first entry in the
  VMStateDescription field list is VMSTATE_CPU(), which migrates
  the cpu_common fields, followed by whatever the CPU's own migration
  fields are.

  (2) a backwards-compatible mechanism for CPUs that were
  originally migrated using manual "write fields to the migration
  stream structures". The on-the-wire migration format
  for those is based on the 'env' pointer (which isn't a QOM object),
  and the cpu_common part of the migration data is elsewhere.

  cpu_exec_realizefn() handles both possibilities:

  * for type 1, dc->vmsd is set and cc->vmsd is not,
so cpu_exec_realizefn() does nothing, and the standard
"register dc->vmsd for a device" code does everything needed

  * for type 2, dc->vmsd is NULL and so we register the
vmstate_cpu_common directly to handle the cpu-common fields,
and the cc->vmsd to handle the per-CPU stuff

  You can't change a CPU from one type to the other without breaking
  migration compatibility, which is why some guest architectures
  are stuck on the cc->vmsd form. New targets should use dc->vmsd.

To avoid new targets to start using type (2), rename cc->vmsd as
cc->legacy_vmsd. The correct field to implement is dc->vmsd (the
DeviceClass one).

See also commit b170fce3dd0 ("cpu: Register VMStateDescription
through CPUState") for historic background.

[*] https://www.mail-archive.com/qemu-devel@nongnu.org/msg800849.html

Cc: Peter Maydell 
Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/core/cpu.h   |  5 +++--
 cpu.c   | 12 ++--
 target/arm/cpu.c|  2 +-
 target/avr/cpu.c|  2 +-
 target/i386/cpu.c   |  2 +-
 target/lm32/cpu.c   |  2 +-
 target/mips/cpu.c   |  2 +-
 target/moxie/cpu.c  |  2 +-
 target/riscv/cpu.c  |  2 +-
 target/s390x/cpu.c  |  2 +-
 target/sparc/cpu.c  |  2 +-
 target/ppc/translate_init.c.inc |  2 +-
 12 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 08af2c383a5..10dd16531ba 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -122,7 +122,8 @@ struct AccelCPUClass;
  * 32-bit VM coredump.
  * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
  * note to a 32-bit VM coredump.
- * @vmsd: State description for migration.
+ * @legacy_vmsd: Legacy state description for migration.
+ *   Do not use in new targets, use #DeviceClass::vmsd instead.
  * @gdb_num_core_regs: Number of core registers accessible to GDB.
  * @gdb_core_xml_file: File name for core registers GDB XML description.
  * @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop
@@ -177,7 +178,7 @@ struct CPUClass {
 int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
 void *opaque);
 
-const VMStateDescription *vmsd;
+const VMStateDescription *legacy_vmsd;
 const char *gdb_core_xml_file;
 gchar * (*gdb_arch_name)(CPUState *cpu);
 const char * (*gdb_get_dynamic_xml)(CPUState *cpu, const char *xmlname);
diff --git a/cpu.c b/cpu.c
index 4fed04219df..c1c9cdebc3e 100644
--- a/cpu.c
+++ b/cpu.c
@@ -139,13 +139,13 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp)
 
 #ifdef CONFIG_USER_ONLY
 assert(qdev_get_vmsd(DEVICE(cpu)) == NULL);
-assert(cc->vmsd == NULL);
+assert(cc->legacy_vmsd == NULL);
 #else
 if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
 vmstate_register(NULL, cpu->cpu_index, &vmstate_cpu_common, cpu);
 }
-if (cc->vmsd != NULL) {
-vmstate_register(NULL, cpu->cpu_index, cc->vmsd, cpu);
+if (cc->legacy_vmsd != NULL) {
+vmstate_register(NULL, cpu->cpu_index, cc->legacy_vmsd, cpu);
 }
 #endif /* CONFIG_USER_ONLY */
 }
@@ -155,10 +155,10 @@ void cpu_exec_unrealizefn(CPUState *cpu)
 CPUClass *cc = CPU_GET_CLASS(cpu);
 
 #ifdef CONFIG_USER_ONLY
-assert(cc->vmsd == NULL);
+assert(cc->legacy_vmsd == NULL);
 #else
-if (cc->vmsd != NULL) {
-vmstate_unregister(NULL, cc->vmsd, cpu);
+if (cc->legacy_vmsd != NULL) {
+vmstate_unregister(NULL, cc->legacy_vmsd, cpu);
 }
 if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
 vmstate_unregister(NULL, &vmstate_cpu_common, cpu);
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 0dd623e5909..3062e8c702e 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -1982,7 +1982,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void 
*data)
 #ifndef CONFIG_USER_ONLY
 cc->get_phys_page_attrs_debug = arm_cpu_get_phys_page_attrs_debug;
 cc->asidx_from_attrs = arm_asidx_from_attrs;
-cc->vmsd = &vmstate_arm_c

[PATCH v6 10/18] cpu: Move CPUClass::vmsd to SysemuCPUOps

2021-04-22 Thread Philippe Mathieu-Daudé
Migration is specific to system emulation.

- Move the CPUClass::vmsd field to SysemuCPUOps,
- restrict VMSTATE_CPU() macro to sysemu,
- vmstate_dummy is now unused, remove it.

Signed-off-by: Philippe Mathieu-Daudé 
---
Since v3: Merged in patch 1 (Eduardo)
therefore removed Richard R-b.

'vmsd' is not a 'system operation' prototype but a const
pointer field, so it belongs to a const structure,
but maybe this structure could be better named than SysemuCPUOps?

This field comes from:

commit b170fce3dd06372f7bfec9a780ebcb1fce6d57e4
Author: Andreas Färber 
Date:   Sun Jan 20 20:23:22 2013 +0100

cpu: Register VMStateDescription through CPUState

In comparison to DeviceClass::vmsd, CPU VMState is split in two,
"cpu_common" and "cpu", and uses cpu_index as instance_id instead of -1.
Therefore add a CPU-specific CPUClass::vmsd field.

Unlike the legacy CPUArchState registration, rather register CPUState.
---
 include/hw/core/cpu.h|  8 ++--
 include/hw/core/sysemu-cpu-ops.h |  5 +
 include/migration/vmstate.h  |  2 --
 cpu.c| 15 +++
 stubs/vmstate.c  |  2 --
 target/arm/cpu.c |  2 +-
 target/i386/cpu.c|  2 +-
 target/mips/cpu.c|  2 +-
 target/riscv/cpu.c   |  4 ++--
 target/s390x/cpu.c   |  2 +-
 target/sparc/cpu.c   |  2 +-
 target/ppc/translate_init.c.inc  |  2 +-
 12 files changed, 22 insertions(+), 26 deletions(-)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 23b718a4a51..bdc702894bf 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -124,8 +124,6 @@ struct AccelCPUClass;
  * 32-bit VM coredump.
  * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
  * note to a 32-bit VM coredump.
- * @legacy_vmsd: Legacy state description for migration.
- *   Do not use in new targets, use #DeviceClass::vmsd instead.
  * @gdb_num_core_regs: Number of core registers accessible to GDB.
  * @gdb_core_xml_file: File name for core registers GDB XML description.
  * @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop
@@ -180,7 +178,6 @@ struct CPUClass {
 int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
 void *opaque);
 
-const VMStateDescription *legacy_vmsd;
 const char *gdb_core_xml_file;
 gchar * (*gdb_arch_name)(CPUState *cpu);
 const char * (*gdb_get_dynamic_xml)(CPUState *cpu, const char *xmlname);
@@ -1058,10 +1055,8 @@ bool target_words_bigendian(void);
 #ifdef NEED_CPU_H
 
 #ifdef CONFIG_SOFTMMU
+
 extern const VMStateDescription vmstate_cpu_common;
-#else
-#define vmstate_cpu_common vmstate_dummy
-#endif
 
 #define VMSTATE_CPU() { \
 .name = "parent_obj",   \
@@ -1070,6 +1065,7 @@ extern const VMStateDescription vmstate_cpu_common;
 .flags = VMS_STRUCT,\
 .offset = 0,\
 }
+#endif /* CONFIG_SOFTMMU */
 
 #endif /* NEED_CPU_H */
 
diff --git a/include/hw/core/sysemu-cpu-ops.h b/include/hw/core/sysemu-cpu-ops.h
index e54a08ea25e..a10d9fbdd16 100644
--- a/include/hw/core/sysemu-cpu-ops.h
+++ b/include/hw/core/sysemu-cpu-ops.h
@@ -16,6 +16,11 @@
  * struct SysemuCPUOps: System operations specific to a CPU class
  */
 typedef struct SysemuCPUOps {
+/**
+ * @legacy_vmsd: Legacy state for migration.
+ *   Do not use in new targets, use #DeviceClass::vmsd instead.
+ */
+const VMStateDescription *legacy_vmsd;
 } SysemuCPUOps;
 
 #endif /* SYSEMU_CPU_OPS_H */
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 075ee800960..8df7b69f389 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -194,8 +194,6 @@ struct VMStateDescription {
 const VMStateDescription **subsections;
 };
 
-extern const VMStateDescription vmstate_dummy;
-
 extern const VMStateInfo vmstate_info_bool;
 
 extern const VMStateInfo vmstate_info_int8;
diff --git a/cpu.c b/cpu.c
index c1c9cdebc3e..47eb8c40775 100644
--- a/cpu.c
+++ b/cpu.c
@@ -126,7 +126,9 @@ const VMStateDescription vmstate_cpu_common = {
 
 void cpu_exec_realizefn(CPUState *cpu, Error **errp)
 {
+#ifndef CONFIG_USER_ONLY
 CPUClass *cc = CPU_GET_CLASS(cpu);
+#endif
 
 cpu_list_add(cpu);
 
@@ -139,26 +141,23 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp)
 
 #ifdef CONFIG_USER_ONLY
 assert(qdev_get_vmsd(DEVICE(cpu)) == NULL);
-assert(cc->legacy_vmsd == NULL);
 #else
 if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
 vmstate_register(NULL, cpu->cpu_index, &vmstate_cpu_common, cpu);
 }
-if (cc->legacy_vmsd != NULL) {
-vmstate_register(NULL, cpu->cpu_index, cc->legacy_vmsd, cpu);
+if (cc->sysemu_ops->legacy

[PATCH v6 11/18] cpu: Move CPUClass::virtio_is_big_endian to SysemuCPUOps

2021-04-22 Thread Philippe Mathieu-Daudé
VirtIO devices are only meaningful with system emulation.

Reviewed-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/core/cpu.h| 5 -
 include/hw/core/sysemu-cpu-ops.h | 8 
 hw/core/cpu.c| 4 ++--
 target/arm/cpu.c | 2 +-
 target/ppc/translate_init.c.inc  | 4 +---
 5 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index bdc702894bf..e3c702b8b74 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -89,10 +89,6 @@ struct AccelCPUClass;
  * @parse_features: Callback to parse command line arguments.
  * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
  * @has_work: Callback for checking if there is work to do.
- * @virtio_is_big_endian: Callback to return %true if a CPU which supports
- * runtime configurable endianness is currently big-endian. Non-configurable
- * CPUs can use the default implementation of this method. This method should
- * not be used by any callers other than the pre-1.0 virtio devices.
  * @memory_rw_debug: Callback for GDB memory access.
  * @dump_state: Callback for dumping state.
  * @dump_statistics: Callback for dumping statistics.
@@ -151,7 +147,6 @@ struct CPUClass {
 
 int reset_dump_flags;
 bool (*has_work)(CPUState *cpu);
-bool (*virtio_is_big_endian)(CPUState *cpu);
 int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
uint8_t *buf, int len, bool is_write);
 void (*dump_state)(CPUState *cpu, FILE *, int flags);
diff --git a/include/hw/core/sysemu-cpu-ops.h b/include/hw/core/sysemu-cpu-ops.h
index a10d9fbdd16..1c325d62b94 100644
--- a/include/hw/core/sysemu-cpu-ops.h
+++ b/include/hw/core/sysemu-cpu-ops.h
@@ -16,6 +16,14 @@
  * struct SysemuCPUOps: System operations specific to a CPU class
  */
 typedef struct SysemuCPUOps {
+/**
+ * @virtio_is_big_endian: Callback to return %true if a CPU which supports
+ *   runtime configurable endianness is currently big-endian.
+ * Non-configurable CPUs can use the default implementation of this method.
+ * This method should not be used by any callers other than the pre-1.0
+ * virtio devices.
+ */
+bool (*virtio_is_big_endian)(CPUState *cpu);
 /**
  * @legacy_vmsd: Legacy state for migration.
  *   Do not use in new targets, use #DeviceClass::vmsd instead.
diff --git a/hw/core/cpu.c b/hw/core/cpu.c
index 5abf8bed2e4..09eaa3fa49f 100644
--- a/hw/core/cpu.c
+++ b/hw/core/cpu.c
@@ -204,8 +204,8 @@ bool cpu_virtio_is_big_endian(CPUState *cpu)
 {
 CPUClass *cc = CPU_GET_CLASS(cpu);
 
-if (cc->virtio_is_big_endian) {
-return cc->virtio_is_big_endian(cpu);
+if (cc->sysemu_ops->virtio_is_big_endian) {
+return cc->sysemu_ops->virtio_is_big_endian(cpu);
 }
 return target_words_bigendian();
 }
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 9b598bf10a8..d071ae72ba3 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -1945,6 +1945,7 @@ static gchar *arm_gdb_arch_name(CPUState *cs)
 
 #ifndef CONFIG_USER_ONLY
 static const struct SysemuCPUOps arm_sysemu_ops = {
+.virtio_is_big_endian = arm_cpu_virtio_is_big_endian,
 .legacy_vmsd = &vmstate_arm_cpu,
 };
 #endif
@@ -1988,7 +1989,6 @@ static void arm_cpu_class_init(ObjectClass *oc, void 
*data)
 #ifndef CONFIG_USER_ONLY
 cc->get_phys_page_attrs_debug = arm_cpu_get_phys_page_attrs_debug;
 cc->asidx_from_attrs = arm_asidx_from_attrs;
-cc->virtio_is_big_endian = arm_cpu_virtio_is_big_endian;
 cc->write_elf64_note = arm_cpu_write_elf64_note;
 cc->write_elf32_note = arm_cpu_write_elf32_note;
 cc->sysemu_ops = &arm_sysemu_ops;
diff --git a/target/ppc/translate_init.c.inc b/target/ppc/translate_init.c.inc
index e3f2f2fefa3..8d6bc6c0087 100644
--- a/target/ppc/translate_init.c.inc
+++ b/target/ppc/translate_init.c.inc
@@ -10880,6 +10880,7 @@ static Property ppc_cpu_properties[] = {
 
 #ifndef CONFIG_USER_ONLY
 static const struct SysemuCPUOps ppc_sysemu_ops = {
+.virtio_is_big_endian = ppc_cpu_is_big_endian,
 .legacy_vmsd = &vmstate_ppc_cpu,
 };
 #endif
@@ -10948,9 +10949,6 @@ static void ppc_cpu_class_init(ObjectClass *oc, void 
*data)
 cc->gdb_core_xml_file = "power64-core.xml";
 #else
 cc->gdb_core_xml_file = "power-core.xml";
-#endif
-#ifndef CONFIG_USER_ONLY
-cc->virtio_is_big_endian = ppc_cpu_is_big_endian;
 #endif
 cc->disas_set_info = ppc_disas_set_info;
 
-- 
2.26.3




[PATCH v6 04/18] cpu: Directly use get_paging_enabled() fallback handlers in place

2021-04-22 Thread Philippe Mathieu-Daudé
No code uses CPUClass::get_paging_enabled() outside of hw/core/cpu.c:

  $ git grep -F -- '->get_paging_enabled'
  hw/core/cpu.c:74:return cc->get_paging_enabled(cpu);
  hw/core/cpu.c:438:k->get_paging_enabled = cpu_common_get_paging_enabled;
  target/i386/cpu.c:7418:cc->get_paging_enabled = 
x86_cpu_get_paging_enabled;

Check the handler presence in place and remove the common fallback code.

Reviewed-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/core/cpu.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/hw/core/cpu.c b/hw/core/cpu.c
index a9ee2c74ec5..1de00bbb474 100644
--- a/hw/core/cpu.c
+++ b/hw/core/cpu.c
@@ -71,11 +71,10 @@ bool cpu_paging_enabled(const CPUState *cpu)
 {
 CPUClass *cc = CPU_GET_CLASS(cpu);
 
-return cc->get_paging_enabled(cpu);
-}
+if (cc->get_paging_enabled) {
+return cc->get_paging_enabled(cpu);
+}
 
-static bool cpu_common_get_paging_enabled(const CPUState *cpu)
-{
 return false;
 }
 
@@ -420,7 +419,6 @@ static void cpu_class_init(ObjectClass *klass, void *data)
 k->parse_features = cpu_common_parse_features;
 k->get_arch_id = cpu_common_get_arch_id;
 k->has_work = cpu_common_has_work;
-k->get_paging_enabled = cpu_common_get_paging_enabled;
 k->get_memory_mapping = cpu_common_get_memory_mapping;
 k->gdb_read_register = cpu_common_gdb_read_register;
 k->gdb_write_register = cpu_common_gdb_write_register;
-- 
2.26.3




[PATCH v6 03/18] cpu: Directly use cpu_write_elf*() fallback handlers in place

2021-04-22 Thread Philippe Mathieu-Daudé
No code directly accesses CPUClass::write_elf*() handlers out
of hw/core/cpu.c (the rest are assignation in target/ code):

  $ git grep -F -- '->write_elf'
  hw/core/cpu.c:157:return (*cc->write_elf32_qemunote)(f, cpu, opaque);
  hw/core/cpu.c:171:return (*cc->write_elf32_note)(f, cpu, cpuid, opaque);
  hw/core/cpu.c:186:return (*cc->write_elf64_qemunote)(f, cpu, opaque);
  hw/core/cpu.c:200:return (*cc->write_elf64_note)(f, cpu, cpuid, opaque);
  hw/core/cpu.c:440:k->write_elf32_qemunote = 
cpu_common_write_elf32_qemunote;
  hw/core/cpu.c:441:k->write_elf32_note = cpu_common_write_elf32_note;
  hw/core/cpu.c:442:k->write_elf64_qemunote = 
cpu_common_write_elf64_qemunote;
  hw/core/cpu.c:443:k->write_elf64_note = cpu_common_write_elf64_note;
  target/arm/cpu.c:2304:cc->write_elf64_note = arm_cpu_write_elf64_note;
  target/arm/cpu.c:2305:cc->write_elf32_note = arm_cpu_write_elf32_note;
  target/i386/cpu.c:7425:cc->write_elf64_note = x86_cpu_write_elf64_note;
  target/i386/cpu.c:7426:cc->write_elf64_qemunote = 
x86_cpu_write_elf64_qemunote;
  target/i386/cpu.c:7427:cc->write_elf32_note = x86_cpu_write_elf32_note;
  target/i386/cpu.c:7428:cc->write_elf32_qemunote = 
x86_cpu_write_elf32_qemunote;
  target/ppc/translate_init.c.inc:10891:cc->write_elf64_note = 
ppc64_cpu_write_elf64_note;
  target/ppc/translate_init.c.inc:10892:cc->write_elf32_note = 
ppc32_cpu_write_elf32_note;
  target/s390x/cpu.c:522:cc->write_elf64_note = s390_cpu_write_elf64_note;

Check the handler presence in place and remove the common fallback code.

Reviewed-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/core/cpu.c | 43 ---
 1 file changed, 12 insertions(+), 31 deletions(-)

diff --git a/hw/core/cpu.c b/hw/core/cpu.c
index daaff56a79e..a9ee2c74ec5 100644
--- a/hw/core/cpu.c
+++ b/hw/core/cpu.c
@@ -154,60 +154,45 @@ int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, 
CPUState *cpu,
 {
 CPUClass *cc = CPU_GET_CLASS(cpu);
 
+if (!cc->write_elf32_qemunote) {
+return 0;
+}
 return (*cc->write_elf32_qemunote)(f, cpu, opaque);
 }
 
-static int cpu_common_write_elf32_qemunote(WriteCoreDumpFunction f,
-   CPUState *cpu, void *opaque)
-{
-return 0;
-}
-
 int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
  int cpuid, void *opaque)
 {
 CPUClass *cc = CPU_GET_CLASS(cpu);
 
+if (!cc->write_elf32_note) {
+return -1;
+}
 return (*cc->write_elf32_note)(f, cpu, cpuid, opaque);
 }
 
-static int cpu_common_write_elf32_note(WriteCoreDumpFunction f,
-   CPUState *cpu, int cpuid,
-   void *opaque)
-{
-return -1;
-}
-
 int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
  void *opaque)
 {
 CPUClass *cc = CPU_GET_CLASS(cpu);
 
+if (!cc->write_elf64_qemunote) {
+return 0;
+}
 return (*cc->write_elf64_qemunote)(f, cpu, opaque);
 }
 
-static int cpu_common_write_elf64_qemunote(WriteCoreDumpFunction f,
-   CPUState *cpu, void *opaque)
-{
-return 0;
-}
-
 int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
  int cpuid, void *opaque)
 {
 CPUClass *cc = CPU_GET_CLASS(cpu);
 
+if (!cc->write_elf64_note) {
+return -1;
+}
 return (*cc->write_elf64_note)(f, cpu, cpuid, opaque);
 }
 
-static int cpu_common_write_elf64_note(WriteCoreDumpFunction f,
-   CPUState *cpu, int cpuid,
-   void *opaque)
-{
-return -1;
-}
-
-
 static int cpu_common_gdb_read_register(CPUState *cpu, GByteArray *buf, int 
reg)
 {
 return 0;
@@ -437,10 +422,6 @@ static void cpu_class_init(ObjectClass *klass, void *data)
 k->has_work = cpu_common_has_work;
 k->get_paging_enabled = cpu_common_get_paging_enabled;
 k->get_memory_mapping = cpu_common_get_memory_mapping;
-k->write_elf32_qemunote = cpu_common_write_elf32_qemunote;
-k->write_elf32_note = cpu_common_write_elf32_note;
-k->write_elf64_qemunote = cpu_common_write_elf64_qemunote;
-k->write_elf64_note = cpu_common_write_elf64_note;
 k->gdb_read_register = cpu_common_gdb_read_register;
 k->gdb_write_register = cpu_common_gdb_write_register;
 set_bit(DEVICE_CATEGORY_CPU, dc->categories);
-- 
2.26.3




[PATCH v6 05/18] cpu: Directly use get_memory_mapping() fallback handlers in place

2021-04-22 Thread Philippe Mathieu-Daudé
No code uses CPUClass::get_memory_mapping() outside of hw/core/cpu.c:

  $ git grep -F -- '->get_memory_mapping'
  hw/core/cpu.c:87:cc->get_memory_mapping(cpu, list, errp);
  hw/core/cpu.c:439:k->get_memory_mapping = cpu_common_get_memory_mapping;
  target/i386/cpu.c:7422:cc->get_memory_mapping = 
x86_cpu_get_memory_mapping;

Check the handler presence in place and remove the common fallback code.

Reviewed-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/core/cpu.c | 11 ---
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/hw/core/cpu.c b/hw/core/cpu.c
index 1de00bbb474..5abf8bed2e4 100644
--- a/hw/core/cpu.c
+++ b/hw/core/cpu.c
@@ -83,13 +83,11 @@ void cpu_get_memory_mapping(CPUState *cpu, 
MemoryMappingList *list,
 {
 CPUClass *cc = CPU_GET_CLASS(cpu);
 
-cc->get_memory_mapping(cpu, list, errp);
-}
+if (cc->get_memory_mapping) {
+cc->get_memory_mapping(cpu, list, errp);
+return;
+}
 
-static void cpu_common_get_memory_mapping(CPUState *cpu,
-  MemoryMappingList *list,
-  Error **errp)
-{
 error_setg(errp, "Obtaining memory mappings is unsupported on this CPU.");
 }
 
@@ -419,7 +417,6 @@ static void cpu_class_init(ObjectClass *klass, void *data)
 k->parse_features = cpu_common_parse_features;
 k->get_arch_id = cpu_common_get_arch_id;
 k->has_work = cpu_common_has_work;
-k->get_memory_mapping = cpu_common_get_memory_mapping;
 k->gdb_read_register = cpu_common_gdb_read_register;
 k->gdb_write_register = cpu_common_gdb_write_register;
 set_bit(DEVICE_CATEGORY_CPU, dc->categories);
-- 
2.26.3




[PATCH v6 01/18] cpu: Un-inline cpu_get_phys_page_debug and cpu_asidx_from_attrs

2021-04-22 Thread Philippe Mathieu-Daudé
To be able to later extract the cpu_get_phys_page_debug() and
cpu_asidx_from_attrs() handlers from CPUClass, un-inline them
from "hw/core/cpu.h".

Reviewed-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/core/cpu.h | 33 -
 hw/core/cpu.c | 32 
 2 files changed, 36 insertions(+), 29 deletions(-)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index c68bc3ba8af..9338e80aa4b 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -580,18 +580,8 @@ void cpu_dump_statistics(CPUState *cpu, int flags);
  *
  * Returns: Corresponding physical page address or -1 if no page found.
  */
-static inline hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
-   MemTxAttrs *attrs)
-{
-CPUClass *cc = CPU_GET_CLASS(cpu);
-
-if (cc->get_phys_page_attrs_debug) {
-return cc->get_phys_page_attrs_debug(cpu, addr, attrs);
-}
-/* Fallback for CPUs which don't implement the _attrs_ hook */
-*attrs = MEMTXATTRS_UNSPECIFIED;
-return cc->get_phys_page_debug(cpu, addr);
-}
+hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
+ MemTxAttrs *attrs);
 
 /**
  * cpu_get_phys_page_debug:
@@ -603,12 +593,7 @@ static inline hwaddr 
cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
  *
  * Returns: Corresponding physical page address or -1 if no page found.
  */
-static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
-{
-MemTxAttrs attrs = {};
-
-return cpu_get_phys_page_attrs_debug(cpu, addr, &attrs);
-}
+hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 
 /** cpu_asidx_from_attrs:
  * @cpu: CPU
@@ -617,17 +602,7 @@ static inline hwaddr cpu_get_phys_page_debug(CPUState 
*cpu, vaddr addr)
  * Returns the address space index specifying the CPU AddressSpace
  * to use for a memory access with the given transaction attributes.
  */
-static inline int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
-{
-CPUClass *cc = CPU_GET_CLASS(cpu);
-int ret = 0;
-
-if (cc->asidx_from_attrs) {
-ret = cc->asidx_from_attrs(cpu, attrs);
-assert(ret < cpu->num_ases && ret >= 0);
-}
-return ret;
-}
+int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs);
 
 #endif /* CONFIG_USER_ONLY */
 
diff --git a/hw/core/cpu.c b/hw/core/cpu.c
index 00330ba07de..4dce35f832f 100644
--- a/hw/core/cpu.c
+++ b/hw/core/cpu.c
@@ -94,6 +94,38 @@ static void cpu_common_get_memory_mapping(CPUState *cpu,
 error_setg(errp, "Obtaining memory mappings is unsupported on this CPU.");
 }
 
+hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
+   MemTxAttrs *attrs)
+{
+CPUClass *cc = CPU_GET_CLASS(cpu);
+
+if (cc->get_phys_page_attrs_debug) {
+return cc->get_phys_page_attrs_debug(cpu, addr, attrs);
+}
+/* Fallback for CPUs which don't implement the _attrs_ hook */
+*attrs = MEMTXATTRS_UNSPECIFIED;
+return cc->get_phys_page_debug(cpu, addr);
+}
+
+hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
+{
+MemTxAttrs attrs = {};
+
+return cpu_get_phys_page_attrs_debug(cpu, addr, &attrs);
+}
+
+int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
+{
+CPUClass *cc = CPU_GET_CLASS(cpu);
+int ret = 0;
+
+if (cc->asidx_from_attrs) {
+ret = cc->asidx_from_attrs(cpu, attrs);
+assert(ret < cpu->num_ases && ret >= 0);
+}
+return ret;
+}
+
 /* Resetting the IRQ comes from across the code base so we take the
  * BQL here if we need to.  cpu_interrupt assumes it is held.*/
 void cpu_reset_interrupt(CPUState *cpu, int mask)
-- 
2.26.3




[PATCH v6 02/18] cpu: Introduce cpu_virtio_is_big_endian()

2021-04-22 Thread Philippe Mathieu-Daudé
Introduce the cpu_virtio_is_big_endian() generic helper to avoid
calling CPUClass internal virtio_is_big_endian() one.

Similarly to commit bf7663c4bd8 ("cpu: introduce
CPUClass::virtio_is_big_endian()"), we keep 'virtio' in the method
name to hint this handler shouldn't be called anywhere but from the
virtio code.

Reviewed-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/core/cpu.h | 9 +
 hw/core/cpu.c | 8 ++--
 hw/virtio/virtio.c| 4 +---
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 9338e80aa4b..08af2c383a5 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -604,6 +604,15 @@ hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
  */
 int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs);
 
+/**
+ * cpu_virtio_is_big_endian:
+ * @cpu: CPU
+
+ * Returns %true if a CPU which supports runtime configurable endianness
+ * is currently big-endian.
+ */
+bool cpu_virtio_is_big_endian(CPUState *cpu);
+
 #endif /* CONFIG_USER_ONLY */
 
 /**
diff --git a/hw/core/cpu.c b/hw/core/cpu.c
index 4dce35f832f..daaff56a79e 100644
--- a/hw/core/cpu.c
+++ b/hw/core/cpu.c
@@ -218,8 +218,13 @@ static int cpu_common_gdb_write_register(CPUState *cpu, 
uint8_t *buf, int reg)
 return 0;
 }
 
-static bool cpu_common_virtio_is_big_endian(CPUState *cpu)
+bool cpu_virtio_is_big_endian(CPUState *cpu)
 {
+CPUClass *cc = CPU_GET_CLASS(cpu);
+
+if (cc->virtio_is_big_endian) {
+return cc->virtio_is_big_endian(cpu);
+}
 return target_words_bigendian();
 }
 
@@ -438,7 +443,6 @@ static void cpu_class_init(ObjectClass *klass, void *data)
 k->write_elf64_note = cpu_common_write_elf64_note;
 k->gdb_read_register = cpu_common_gdb_read_register;
 k->gdb_write_register = cpu_common_gdb_write_register;
-k->virtio_is_big_endian = cpu_common_virtio_is_big_endian;
 set_bit(DEVICE_CATEGORY_CPU, dc->categories);
 dc->realize = cpu_common_realizefn;
 dc->unrealize = cpu_common_unrealizefn;
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 07f4e60b309..8a364496fd5 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -1973,9 +1973,7 @@ static enum virtio_device_endian 
virtio_default_endian(void)
 
 static enum virtio_device_endian virtio_current_cpu_endian(void)
 {
-CPUClass *cc = CPU_GET_CLASS(current_cpu);
-
-if (cc->virtio_is_big_endian(current_cpu)) {
+if (cpu_virtio_is_big_endian(current_cpu)) {
 return VIRTIO_DEVICE_ENDIAN_BIG;
 } else {
 return VIRTIO_DEVICE_ENDIAN_LITTLE;
-- 
2.26.3




[PATCH v6 00/18] cpu: Introduce SysemuCPUOps structure

2021-04-22 Thread Philippe Mathieu-Daudé
Missing review: patch 6, 7, 8, 10

Hi,

This series is inspired on Claudio TCG work.

Instead of separate TCG from other accelerators, here we
separate sysemu operations (system VS user).

Patches 1-5 are generic cleanups.
Patches 6-14 move from CPUClass to SysemuCPUOps
Patch   15 restricts SysemuCPUOps to sysemu

Since v5:
- Rework patch 10 after Peter Maydell explanation on v3:
  https://www.mail-archive.com/qemu-devel@nongnu.org/msg800849.html

Since v4:
- Removed watchpoint patches (need more work) (Richard)
- Merged patch 1 & 7 "Move CPUClass::vmsd to SysemuCPUOps" (Eduardo)
- Reworded cpu_virtio_is_big_endian description (Greg)
- Move write_elf() in target/riscv/cpu.c (rebased on top of 43a965888)
- Added R-b tags

Since v3:
- SysemuCPUOps const (Richard)
- added missing xtensa #ifdef'ry
- added missing aa64/sve #ifdef'ry
- added Laurent R-b

Since v2:
- fixed lm32/unicore32
- remove USER_ONLY ifdef'ry from "cpu.h" (Claudio)

Since v1:
- Name 'sysemu' (Claudio)
- change each field progressively (Richard)

$ git backport-diff
Key:
[] : patches are identical
[] : number of functional differences between upstream/downstream patch
[down] : patch is downstream-only
The flags [FC] indicate (F)unctional and (C)ontextual differences, respective=
ly

001/18:[] [--] 'cpu: Un-inline cpu_get_phys_page_debug and cpu_asidx_from=
_attrs'
002/18:[] [--] 'cpu: Introduce cpu_virtio_is_big_endian()'
003/18:[] [--] 'cpu: Directly use cpu_write_elf*() fallback handlers in p=
lace'
004/18:[] [--] 'cpu: Directly use get_paging_enabled() fallback handlers =
in place'
005/18:[] [--] 'cpu: Directly use get_memory_mapping() fallback handlers =
in place'
006/18:[down] 'cpu: Assert DeviceClass::vmsd is NULL on user emulation'
007/18:[down] 'cpu: Rename CPUClass vmsd -> legacy_vmsd'
008/18:[down] 'cpu/{avr,lm32,moxie}: Set DeviceClass vmsd field (not CPUClass=
 one)'
009/18:[0010] [FC] 'cpu: Introduce SysemuCPUOps structure'
010/18:[0118] [FC] 'cpu: Move CPUClass::vmsd to SysemuCPUOps'
011/18:[] [-C] 'cpu: Move CPUClass::virtio_is_big_endian to SysemuCPUOps'
012/18:[] [-C] 'cpu: Move CPUClass::get_crash_info to SysemuCPUOps'
013/18:[] [-C] 'cpu: Move CPUClass::write_elf* to SysemuCPUOps'
014/18:[] [--] 'cpu: Move CPUClass::asidx_from_attrs to SysemuCPUOps'
015/18:[0002] [FC] 'cpu: Move CPUClass::get_phys_page_debug to SysemuCPUOps'
016/18:[] [--] 'cpu: Move CPUClass::get_memory_mapping to SysemuCPUOps'
017/18:[] [--] 'cpu: Move CPUClass::get_paging_enabled to SysemuCPUOps'
018/18:[] [--] 'cpu: Restrict "hw/core/sysemu-cpu-ops.h" to target/cpu.c'

CI: https://gitlab.com/philmd/qemu/-/pipelines/290833005

Regards,

Phil.

Philippe Mathieu-Daud=C3=A9 (18):
  cpu: Un-inline cpu_get_phys_page_debug and cpu_asidx_from_attrs
  cpu: Introduce cpu_virtio_is_big_endian()
  cpu: Directly use cpu_write_elf*() fallback handlers in place
  cpu: Directly use get_paging_enabled() fallback handlers in place
  cpu: Directly use get_memory_mapping() fallback handlers in place
  cpu: Assert DeviceClass::vmsd is NULL on user emulation
  cpu: Rename CPUClass vmsd -> legacy_vmsd
  cpu/{avr,lm32,moxie}: Set DeviceClass vmsd field (not CPUClass one)
  cpu: Introduce SysemuCPUOps structure
  cpu: Move CPUClass::vmsd to SysemuCPUOps
  cpu: Move CPUClass::virtio_is_big_endian to SysemuCPUOps
  cpu: Move CPUClass::get_crash_info to SysemuCPUOps
  cpu: Move CPUClass::write_elf* to SysemuCPUOps
  cpu: Move CPUClass::asidx_from_attrs to SysemuCPUOps
  cpu: Move CPUClass::get_phys_page_debug to SysemuCPUOps
  cpu: Move CPUClass::get_memory_mapping to SysemuCPUOps
  cpu: Move CPUClass::get_paging_enabled to SysemuCPUOps
  cpu: Restrict "hw/core/sysemu-cpu-ops.h" to target/cpu.c

 include/hw/core/cpu.h|  92 ++---
 include/hw/core/sysemu-cpu-ops.h |  90 
 include/migration/vmstate.h  |   2 -
 target/alpha/cpu.h   |   3 +
 target/arm/cpu.h |   3 +
 target/avr/cpu.h |   1 +
 target/cris/cpu.h|   3 +
 target/hexagon/cpu.h |   3 +
 target/hppa/cpu.h|   3 +
 target/i386/cpu.h|   3 +
 target/lm32/cpu.h|   3 +
 target/m68k/cpu.h|   3 +
 target/microblaze/cpu.h  |   1 +
 target/mips/cpu.h|   3 +
 target/moxie/cpu.h   |   3 +
 target/nios2/cpu.h   |   1 +
 target/openrisc/cpu.h|   3 +
 target/ppc/cpu.h |   3 +
 target/riscv/cpu.h   |   3 +
 target/rx/cpu.h  |   1 +
 target/s390x/cpu.h   |   3 +
 target/sh4/cpu.h |   3 +
 target/sparc/cpu.h   |   3 +
 target/tricore/cpu.h |   3 +
 target/unicore32/cpu.h   |   3 +
 target/xtensa/cpu.h  |   3 +
 cpu.c|  17 ++---
 hw/core/cpu.c| 113 +---

RE: [PATCH 1/4] target/ppc: Code motion required to build disabling tcg

2021-04-22 Thread Fabiano Rosas
Bruno Piazera Larsen  writes:

>> > You are correct! I've just tweaked the code that defines spr_register and
>> > it should be working now. I'm still working in splitting the SPR functions
>> > from translate_init, since I think it would make it easier to prepare the
>> > !TCG case and for adding new architectures in the future, and I found a
>> > few more problems:
>>
>> Actually looking at the stuff below, I suspect that separating our
>> "spr" logic specifically might be a bad idea.  At least some of the
>> SPRs control pretty fundamental things about how the processor
>> operates, and I suspect separating it from the main translation logic
>> may be more trouble than it's worth.

I disagree with the code proximity argument. Having TCG code clearly
separate from common code seems more important to me than having the SPR
callbacks close to the init_proc functions.

But maybe we should take a look at this RFC before we start discussing
personal preference too much.

> Well, all the errors that I got were related to to read/write functions, which
> I was already separating into a spr_tcg file. The solutions I can see are to
> include this file in translate.c, and either have the read/write functions 
> not be
> static, or include the spr_common.c in translate as well, but only for TCG
> builds. Both solutions sound pretty bad imo, but the first sounds less bad,
> because it's a bit less complexity in the build process.

It would be helpful if we could apply these patches and do some
experimentation before recommending a solution. So I would pick the less
bad for now. Mention it in the cover letter and then we can discuss
looking at something more concrete.




[Bug 1925512] Re: UNDEFINED case for instruction BLX

2021-04-22 Thread JIANG Muhui
Hi

I still feel QEMU's implementation is not right. Could you please check
it again.

According to https://developer.arm.com/documentation/ddi0406/c
/Application-Level-Architecture/Instruction-Details/Alphabetical-list-
of-instructions/BL--BLX--immediate-?lang=en

The encoding T2 for BLX is below:

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 
 1  1  1  1  0  S |   imm10H | 1  1 J1  0 J2 |   imm10L  |H

In the ASL of ARM,  we have  H == '1' then UNDEFINED;

Symbol *H* represents the last bit of this instruction. I am not sure
whether a->imm includes the symbol *H*. I double checked the file
`t32.decode` and it seems so (It would be great if you can tell me what
a->imm indeed represents in BLX).

However, UNDEFINED means unallocated encoding in ARM manual. The right
behavior might be something like below:

if (s->thumb && (a->imm & 2)) {
unallocated_encoding(s);
return true;
}

Correct me if I am wrong. I can also provide test case if you need. Many
Thanks

Regards
Muhui

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1925512

Title:
  UNDEFINED case for instruction BLX

Status in QEMU:
  Invalid

Bug description:
  Hi

  I refer to the instruction BLX imm (T2 encoding) in ARMv7 (Thumb
  mode).

  0 S imm10H  11 J1 0 J2 imm10L H

  
  if H == '1' then UNDEFINED;
  I1 = NOT(J1 EOR S);  I2 = NOT(J2 EOR S);  imm32 = 
SignExtend(S:I1:I2:imm10H:imm10L:'00', 32);
  targetInstrSet = InstrSet_A32;
  if InITBlock() && !LastInITBlock() then UNPREDICTABLE;

  According to the manual, if H equals to 1, this instruction should be
  an UNDEFINED instruction. However, it seems QEMU does not check this
  constraint in function trans_BLX_i. Thanks

  Regards
  Muhui

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1925512/+subscriptions



Re: [PATCH 1/2] linux-user/alpha: Fix rt sigframe return

2021-04-22 Thread Philippe Mathieu-Daudé
On 4/22/21 8:08 PM, Richard Henderson wrote:
> We incorrectly used the offset of the non-rt sigframe.
> 
> Signed-off-by: Richard Henderson 
> ---
>  linux-user/alpha/signal.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé 




Re: [PATCH for-6.0? 0/1] hw/block/nvme: fix msix uninit

2021-04-22 Thread Klaus Jensen

On Apr 22 19:58, Peter Maydell wrote:

On Thu, 22 Apr 2021 at 15:07, Klaus Jensen  wrote:


On Apr 22 15:58, Klaus Jensen wrote:
>From: Klaus Jensen 
>
>Hi Peter,
>
>The commit message on the patch describes the issue. This is a QEMU
>crashing bug in -rc4 that I introduced early in the cycle and never
>found in time. Lack of testing device hotplugging is the cause for that.
>
>I'm not sure what to say other than I'm terribly sorry for introducing
>this and if this means an -rc5 needs to be rolled, then I'm even more
>sorry.
>
>I think an acceptance test could have caught this, and I am already
>working on an acceptance test suite for the nvme device, so I'll add
>something that test this as well. But, well, it doesn't help now.



As far as I can tell, to cause this crash, monitor access is required,
so I am not sure if we can get away with a note on this in the release
notes and fix this in a potential stable release or next.


Is this a regression since 5.2 ?



Yes.


signature.asc
Description: PGP signature


Re: [Bug 1743191] Re: Interacting with NetBSD serial console boot blocks no longer works

2021-04-22 Thread Andreas Gustafsson
Ottavio Caruso wrote:
> I am currently using:
> 
> $ qemu-system-x86_64 --version
> QEMU emulator version 5.2.0
> 
> And I have no problem selecting from menu in serial console, so I
> assume this is fixed for me. This is my command line:
> 
> $ cat opt/bin/boot-netbsd-virtio
> #!/bin/sh
> qemu-system-x86_64 \
> -drive if=virtio,file=/home/oc/VM/img/netbsd.image,index=0,media=disk \
> -drive if=virtio,file=/home/oc/VM/img/netbsd.image.old,index=1,media=disk \
> -M q35,accel=kvm -m 250M -cpu host -smp $(nproc) \
> -nic user,hostfwd=tcp:127.0.0.1:-:22,model=virtio-net-pci,ipv6=off  \
> -daemonize -display none  -vga none \
> -serial mon:telnet:127.0.0.1:6665,server,nowait \
> -pidfile /home/oc/VM/pid/netbsd-pid -nodefaults
> 
> telnet 127.0.0.1 6665

Have you tried the test case in the original bug report?
-- 
Andreas Gustafsson, g...@gson.org

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1743191

Title:
  Interacting with NetBSD serial console boot blocks no longer works

Status in QEMU:
  New

Bug description:
  The NetBSD boot blocks display a menu allowing the user to make a
  selection using the keyboard.  For example, when booting a NetBSD
  installation CD-ROM, the menu looks like this:

   1. Install NetBSD
   2. Install NetBSD (no ACPI)
   3. Install NetBSD (no ACPI, no SMP)
   4. Drop to boot prompt

  Choose an option; RETURN for default; SPACE to stop countdown.
  Option 1 will be chosen in 30 seconds.

  When booting NetBSD in a recent qemu using an emulated serial console,
  making this menu selection no longer works: when you type the selected
  number, the keyboard input is ignored, and the 30-second countdown
  continues.  In older versions of qemu, it works.

  To reproduce the problem, run:

 wget 
http://ftp.netbsd.org/pub/NetBSD/NetBSD-7.1.1/amd64/installation/cdrom/boot-com.iso
 qemu-system-x86_64 -nographic -cdrom boot-com.iso

  During the 30-second countdown, press 4

  Expected behavior: The countdown stops and you get a ">" prompt

  Incorrect behavior: The countdown continues

  There may also be some corruption of the terminal output; for example,
  "Option 1 will be chosen in 30 seconds" may be displayed as "Option 1
  will be chosen in p0 seconds".

  Using bisection, I have determined that the problem appeared with qemu
  commit 083fab0290f2c40d3d04f7f22eed9c8f2d5b6787, in which seabios was
  updated to 1.11 prerelease, and the problem is still there as of
  commit 7398166ddf7c6dbbc9cae6ac69bb2feda14b40ac.  The host operating
  system used for the tests was Debian 9 x86_64.

  Credit for discovering this bug goes to Paul Goyette.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1743191/+subscriptions



[Bug 1725707] Re: QEMU sends excess VNC data to websockify even when network is poor

2021-04-22 Thread Thomas Huth
** Bug watch removed: github.com/novnc/noVNC/issues #431
   https://github.com/novnc/noVNC/issues/431

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1725707

Title:
  QEMU sends excess VNC data to websockify even when network is poor

Status in QEMU:
  Incomplete

Bug description:
  Description of problem
  -
  In my latest topic, I reported a bug relate to QEMU's websocket:
  https://bugs.launchpad.net/qemu/+bug/1718964

  It has been fixed but someone mentioned that he met the same problem when 
using QEMU with a standalone websocket proxy.
  That makes me confused because in that scenario QEMU will get a "RAW" VNC 
connection.
  So I did a test and found that there indeed existed some problems. The 
problem is:

  When the client's network is poor (on a low speed WAN), QEMU still
  sends a lot of data to the websocket proxy, then the client get stuck.
  It seems that only QEMU has this problem, other VNC servers works
  fine.

  Environment
  -
  All of the following versions have been tested:

  QEMU: 2.8.1.1 / 2.9.1 / 2.10.1 / master (Up to date)
  Host OS: Ubuntu 16.04 Server LTS / CentOS 7 x86_64_1611
  Websocket Proxy: websockify 0.6.0 / 0.7.0 / 0.8.0 / master
  VNC Web Client: noVNC 0.5.1 / 0.61 / 0.62 / master
  Other VNC Servers: TigerVNC 1.8 / x11vnc 0.9.13 / TightVNC 2.8.8

  Steps to reproduce:
  -
  100% reproducible.

  1. Launch a QEMU instance (No need websocket option):
  qemu-system-x86_64 -enable-kvm -m 6G ./win_x64.qcow2 -vnc :0

  2. Launch websockify on a separate host and connect to QEMU's VNC port

  3. Open VNC Web Client (noVNC/vnc.html) in browser and connect to
  websockify

  4. Play a video (e.g. Watch YouTube) on VM (To produce a lot of frame
  buffer update)

  5. Limit (e.g. Use NetLimiter) the client inbound bandwidth to 300KB/S
  (To simulate a low speed WAN)

  6. Then client's output gets stuck(less than 1 fps), the cursor is
  almost impossible to move

  7. Monitor network traffic on the proxy server

  Current result:
  -
  Monitor Downlink/Uplink network traffic on the proxy server
  (Refer to the attachments for more details).

  1. Used with QEMU
  - D: 5.9 MB/s U: 5.7 MB/s (Client on LAN)
  - D: 4.3 MB/s U: 334 KB/s (Client on WAN)

  2. Used with other VNC servers
  - D: 5.9 MB/s U: 5.6 MB/s (Client on LAN)
  - D: 369 KB/s U: 328 KB/s (Client on WAN)

  It is found that when the client's network is poor, all the VNC
  servers (tigervnc/x11vnc/tightvnc) will reduce the VNC data send to
  websocket proxy (uplink and downlink symmetry), but QEMU never drop
  any frames and still sends a lot of data to websockify, the client has
  no capacity to accept so much data, more and more data are accumulated
  in the websockify, then it crashes.

  Expected results:
  -
  When the client's network is poor (WAN), QEMU will reduce the VNC data send 
to websocket proxy.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1725707/+subscriptions



[Bug 1615212] Re: SDL UI switching to monitor half-broken and scrolling broken

2021-04-22 Thread Thomas Huth
** Bug watch removed: bugzilla.libsdl.org/ #3287
   http://bugzilla.libsdl.org/show_bug.cgi?id=3287

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1615212

Title:
  SDL UI switching to monitor half-broken and scrolling broken

Status in QEMU:
  Incomplete

Bug description:
  ctrl+alt+2 must be pressed 2 or more times for the monitor console
  window to appear with -sdl, the window flashes and disappears also
  before finally staying open

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1615212/+subscriptions



[Bug 1395217] Re: Networking in qemu 2.0.0 and beyond is not compatible with Open Solaris (Illumos) 5.11

2021-04-22 Thread Thomas Huth
** Bug watch removed: Red Hat Bugzilla #1040500
   https://bugzilla.redhat.com/show_bug.cgi?id=1040500

** Bug watch removed: Red Hat Bugzilla #1262093
   https://bugzilla.redhat.com/show_bug.cgi?id=1262093

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1395217

Title:
  Networking in qemu 2.0.0 and beyond is not compatible with Open
  Solaris (Illumos) 5.11

Status in QEMU:
  Incomplete

Bug description:
  The networking code in qemu in versions 2.0.0 and beyond is non-
  functional with Solaris/Illumos 5.11 images.

  Building 1.7.1, 2.0.0, 2.0.2, 2.1.2,and 2.2.0rc1with the following
  standard Slackware config:

  # From Slackware build tree . . . 
  ./configure \
--prefix=/usr \
--libdir=/usr/lib64 \
--sysconfdir=/etc \
--localstatedir=/var \
--enable-gtk \
--enable-system \
--enable-kvm \
--disable-debug-info \
--enable-virtfs \
--enable-sdl \
--audio-drv-list=alsa,oss,sdl,esd \
--enable-libusb \
--disable-vnc \
--target-list=x86_64-linux-user,i386-linux-user,x86_64-softmmu,i386-softmmu 
\
--enable-spice \
--enable-usb-redir 

  
  And attempting to run the same VM image with the following command (or via 
virt-manager):

  macaddress="DE:AD:BE:EF:3F:A4"

  qemu-system-x86_64 nex4x -cdrom /dev/cdrom -name "Nex41" -cpu Westmere
  -machine accel=kvm -smp 2 -m 4000 -net nic,macaddr=$macaddress  -net 
bridge,br=b
  r0 -net dump,file=/usr1/tmp/ -drive file=nex4x_d1 -drive 
file=nex4x_d2
   -enable-kvm

  Gives success on 1.7.1, and a deaf VM on all subsequent versions.

  Notable in validating my config, is that a Windows 7 image runs
  cleanly with networking on *all* builds, so my configuration appears
  to be good - qemu just hates Solaris at this point.

  Watching with wireshark (as well as pulling network traces from qemu
  as noted above) it appears that the notable difference in the two
  configs is that for some reason, Solaris gets stuck arping for it's
  own interface on startup, and never really comes on line on the
  network.  If other hosts attempt to ping the Solaris instance, they
  can successfully arp the bad VM, but not the other way around.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1395217/+subscriptions



[Bug 1642421] Re: qemu-system-x86_64: ipv6 and dns is broken with netdev user

2021-04-22 Thread Thomas Huth
** Bug watch removed: Sourceware.org Bugzilla #5475
   https://sourceware.org/bugzilla/show_bug.cgi?id=5475

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1642421

Title:
  qemu-system-x86_64: ipv6 and dns is broken with netdev user

Status in QEMU:
  Incomplete

Bug description:
  Hi,

  dhcp inside qemu returns an ipv6 address as dns-server. However this is not
  working. If i replace it with the ipv4 address '10.0.0.2' dns is working
  again. I would expect that the qemu emulated dhcp server responds either an
  ipv4 configuration that is working or its dns server/forwarder listens on the
  ipv6 address returned by the emulated dhcp server.

  I used latest qemu from git (
  b0bcc86d2a87456f5a276f941dc775b265b309cf) and used the following
  commands:

  $ ./qemu-system-x86_64 -enable-kvm -M pc -device virtio-rng-pci -device
  virtio-net-pci,netdev=user.0 -drive file=buildenv.img,if=virtio,bus=1,unit=0
  -no-reboot -netdev 
user,id=user.0,hostfwd=tcp::5022-:22,hostfwd=tcp::7587-:7588
  -m 1024 -usb -nographic -smp 4

  buildenv.img is a debian jessie amd64 installation.

  Inside qemu the network is configured to use dhcp:

  $ cat /etc/network/interfaces
  allow-hotplug eth0
  iface eth0 inet dhcp

  $ ifconfig eth0
  eth0  Link encap:Ethernet  HWaddr 52:54:00:12:34:56
inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
inet6 addr: fe80::5054:ff:fe12:3456/64 Scope:Link
inet6 addr: fec0::5054:ff:fe12:3456/64 Scope:Site
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:10 errors:0 dropped:0 overruns:0 frame:0
TX packets:28 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3215 (3.1 KiB)  TX bytes:3638 (3.5 KiB)

  $ cat /etc/resolv.conf
  nameserver fec0::3

  $ arp google.de
  google.de: Host name lookup failure

  $ strace -f arp google.de
  ...
  socket(PF_INET6, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 4
  connect(4, {sa_family=AF_INET6, sin6_port=htons(53), inet_pton(AF_INET6, 
"fec0::3", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = 0
  poll([{fd=4, events=POLLOUT}], 1, 0)= 1 ([{fd=4, revents=POLLOUT}])
  sendto(4, "\17\320\1\0\0\1\0\0\0\0\0\0\6google\2de\0\0\1\0\1", 27, 
MSG_NOSIGNAL, NULL, 0) = 27
  poll([{fd=4, events=POLLIN}], 1, 5000)  = 0 (Timeout)
  poll([{fd=4, events=POLLOUT}], 1, 0)= 1 ([{fd=4, revents=POLLOUT}])
  sendto(4, "\17\320\1\0\0\1\0\0\0\0\0\0\6google\2de\0\0\1\0\1", 27, 
MSG_NOSIGNAL, NULL, 0) = 27
  poll([{fd=4, events=POLLIN}], 1, 5000)  = 0 (Timeout)
  close(4)= 0
  ...

  $ echo nameserver 10.0.0.2 > /etc/resolv.conf

  $ arp google.de
  google.de (216.58.208.35) -- no entry

  Note: I reported this bug also to debian: https://bugs.debian.org/cgi-
  bin/bugreport.cgi?bug=844566

  Regards,

Manuel

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1642421/+subscriptions



[Bug 1703506] Re: SMT not supported by QEMU on AMD Ryzen CPU

2021-04-22 Thread Thomas Huth
** Bug watch removed: Red Hat Bugzilla #1135772
   https://bugzilla.redhat.com/show_bug.cgi?id=1135772

** Bug watch removed: Red Hat Bugzilla #1592276
   https://bugzilla.redhat.com/show_bug.cgi?id=1592276

** Changed in: qemu
 Assignee: Eduardo Habkost (ehabkost) => (unassigned)

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1703506

Title:
  SMT not supported by QEMU on AMD Ryzen CPU

Status in QEMU:
  Incomplete

Bug description:
  HyperThreading/SMT is supported by AMD Ryzen CPUs but results in this
  message when setting the topology to threads=2:

  qemu-system-x86_64: AMD CPU doesn't support hyperthreading. Please
  configure -smp options properly.

  Checking in a Windows 10 guest reveals that SMT is not enabled, and
  from what I understand, QEMU converts the topology from threads to
  cores internally on AMD CPUs. This appears to cause performance
  problems in the guest perhaps because programs are assuming that these
  threads are actual cores.

  Software: Linux 4.12, qemu 2.9.0 host with KVM enabled, Windows 10 pro
  guest

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1703506/+subscriptions



[Bug 1766841] Re: QEMU 2.12 Running Problem in Windows 7 Installation

2021-04-22 Thread Thomas Huth
** Changed in: qemu
 Assignee: Stefan Weil (ubuntu-weilnetz) => (unassigned)

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1766841

Title:
  QEMU 2.12 Running Problem in Windows 7 Installation

Status in QEMU:
  Incomplete

Bug description:
  QEMU Version: 2.12 (Binary installer qemu-w64-setup-20180424.exe  from Stefan 
Weil's website so I am not sure I should report it to Weil by email or by this 
bug report system.)
  Host System: Windows 7 64bit
  Guest System: 9front 6350 (Codename“CONTENTS, MAINTAINED, STABLE”, Release 
2018/02/02)

  QEMU Command:
  qemu-system-x86_64 -usb -device usb-mouse -hda plan9.qcow2.img -cdrom 
9front-6350.iso -boot d

  QEMU warning: 
  (qemu-system-x86_64.exe:8844): GdkPixbuf-WARNING **: Cannot open pixbuf 
loader module file 'D:\qemu\lib\gdk-pixbuf-2.0\2.10.0\loaders.cache': No such 
file or directory

  This likely means that your installation is broken.
  Try running the command
gdk-pixbuf-query-loaders > D:\qemu\lib\gdk-pixbuf-2.0\2.10.0\loaders.cache
  to make things work again for the time being.

  (qemu-system-x86_64.exe:8844): Gtk-WARNING **: Could not find the icon 
'window-minimize-symbolic-ltr'. The 'hicolor' theme was not found either, 
perhaps you need to install it.
  You can get a copy from:
  http://icon-theme.freedesktop.org/releases

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1766841/+subscriptions



[Bug 1778966] Re: Windows 1803 and later crashes on KVM

2021-04-22 Thread Thomas Huth
** Bug watch removed: Red Hat Bugzilla #1592276
   https://bugzilla.redhat.com/show_bug.cgi?id=1592276

** Bug watch removed: Red Hat Bugzilla #1593190
   https://bugzilla.redhat.com/show_bug.cgi?id=1593190

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1778966

Title:
  Windows 1803 and later crashes on KVM

Status in QEMU:
  Incomplete

Bug description:
  For a bionic host, using the current public kvm modules, KVM is not
  capable of booting a WindowsInsider or msdn Windows 1803 Windows
  Server iso. In snstalling from an ISO from a started windows 2016
  guest results in an unbootable and unrepairable guest.

  The hardware is a threadripper 1920x with 32GB of main memory, disk
  mydigital BPX SSD and WD based 4 column RAID 5 via mdadm.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1778966/+subscriptions



[Bug 1820247] Re: QEMU random crash caused by libspice-server

2021-04-22 Thread Thomas Huth
** Bug watch removed: Red Hat Bugzilla #980714
   https://bugzilla.redhat.com/show_bug.cgi?id=980714

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1820247

Title:
  QEMU random crash caused by libspice-server

Status in QEMU:
  Incomplete

Bug description:
  Hi,

  One of our OpenStack instances crashed. It seems there was some
  problem related to SPICE. Attaching what we had in qemu log. Also
  sending our versions:

  Linux pre-node1 4.18.0-13-generic #14~18.04.1-Ubuntu SMP Thu Dec 6
  14:09:52 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

  QEMU emulator version 2.11.1(Debian 1:2.11+dfsg-1ubuntu7.9)
  Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers

  
  root@pre-node1:~# cat /var/log/libvirt/qemu/instance-0038.log 
  2019-03-10 20:39:36.510+: starting up libvirt version: 4.0.0, package: 
1ubuntu8.6 (Christian Ehrhardt  Fri, 09 Nov 
2018 07:42:01 +0100), qemu version: 2.11.1(Debian 1:2.11+dfsg-1ubuntu7.9), 
hostname: pre-node1
  LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 
QEMU_AUDIO_DRV=spice /usr/bin/kvm-spice -name 
guest=instance-0038,debug-threads=on -S -object 
secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-5-instance-0038/master-key.aes
 -machine pc-i440fx-bionic,accel=kvm,usb=off,dump-guest-core=off,mem-merge=off 
-cpu 
Skylake-Server-IBRS,ss=on,hypervisor=on,tsc_adjust=on,clflushopt=on,pku=on,ssbd=on,xsaves=on
 -m 2048 -realtime mlock=on -smp 2,sockets=1,cores=1,threads=2 -object 
memory-backend-file,id=ram-node0,prealloc=yes,mem-path=/dev/hugepages/libvirt/qemu/5-instance-0038,share=yes,size=2147483648,host-nodes=0,policy=bind
 -numa node,nodeid=0,cpus=0-1,memdev=ram-node0 -uuid 
3c3d04f3-4b25-4ea5-8836-0e06eef9dcb7 -smbios 'type=1,manufacturer=OpenStack 
Foundation,product=OpenStack 
Nova,version=18.1.1,serial=93fa1a55-ba3a-4a99-80b3-3a7bb4e964af,uuid=3c3d04f3-4b25-4ea5-8836-0e06eef9dcb7,family=Virtual
 Machine' -no-user-config -nodefaults -chardev 
socket,id=charmonitor,path=/var/lib/libvirt/qemu/domain-5-instance-0038/monitor.sock,server,nowait
 -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc,driftfix=slew 
-global kvm-pit.lost_tick_policy=delay -no-hpet -no-shutdown -boot strict=on 
-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -device 
virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x3 -drive 
file=/var/lib/nova/instances/3c3d04f3-4b25-4ea5-8836-0e06eef9dcb7/disk,format=qcow2,if=none,id=drive-virtio-disk0,cache=none,discard=ignore,throttling.iops-read=5000,throttling.iops-write=5000
 -device 
virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1
 -add-fd set=0,fd=29 -chardev 
pty,id=charserial0,logfile=/dev/fdset/0,logappend=on -device 
isa-serial,chardev=charserial0,id=serial0 -chardev 
spicevmc,id=charchannel0,name=vdagent -device 
virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=com.redhat.spice.0
 -spice port=5900,addr=10.252.0.101,disable-ticketing,seamless-migration=on 
-device 
qxl-vga,id=video0,ram_size=67108864,vram_size=67108864,vram64_size_mb=0,vgamem_mb=16,max_outputs=1,bus=pci.0,addr=0x2
 -device vfio-pci,host=25:04.1,id=hostdev0,bus=pci.0,addr=0x5 -device 
virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6 -msg timestamp=on
  2019-03-10T20:39:36.568276Z qemu-system-x86_64: -chardev 
pty,id=charserial0,logfile=/dev/fdset/0,logappend=on: char device redirected to 
/dev/pts/2 (label charserial0)
  inputs_channel_detach_tablet: 
  main_channel_link: add main channel client
  main_channel_client_handle_pong: net test: latency 32.76 ms, bitrate 
33384953 bps (31.838372 Mbps)
  red_qxl_set_cursor_peer: 
  inputs_connect: inputs channel client create

  (process:65324): Spice-WARNING **: 16:35:23.769: Failed to create channel 
client: Client 0x55e7c157e970: duplicate channel type 2 id 0
  red_qxl_set_cursor_peer: 

  (process:65324): Spice-WARNING **: 16:35:24.142: Failed to create
  channel client: Client 0x55e7c157e970: duplicate channel type 4 id 0

  (process:65324): Spice-CRITICAL **: 16:35:24.142: 
cursor-channel.c:353:cursor_channel_connect: condition `ccc != NULL' failed
  2019-03-13 15:35:31.785+: shutting down, reason=crashed


  
  I am also attaching some gdb information extracted from qemu crash dump file. 
These are backtraces of particular threads within the crashed QEMU process.

  
  Thread 9 (Thread 0x7f69649ea5c0 (LWP 65324)):
  #0  0x7f695f02d2b7 in __libc_write (fd=26, buf=0x7ffc33f5b330, nbytes=56) 
at ../sysdeps/unix/sysv/linux/write.c:27
  #1  0x7f695ff30ed3 in  () at 
/usr/lib/x86_64-linux-gnu/libspice-server.so.1
  #2  0x7f695ff316ce in  () at 
/usr/lib/x86_64-linux-gnu/libspice-server.so.1
  #3  0x7f695ff52db6 in  () at 
/usr/lib/x86_64-linux-gnu/libspice-server.so.1
  #4  0x7f695ff58e38 in  () at 
/usr/lib/x86_64-linux-gnu/libspice-server.so.1

[Bug 1879425] Re: The thread of "CPU 0 /KVM" keeping 99.9%CPU

2021-04-22 Thread Thomas Huth
** Bug watch removed: bugs.centos.org/ #17385
   https://bugs.centos.org/view.php?id=17385

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1879425

Title:
  The thread of "CPU 0 /KVM" keeping 99.9%CPU

Status in QEMU:
  Incomplete

Bug description:
  Hi Expert:

  The VM is hung here after (2, or 3, or 5 and the longest time is 10 hours) by 
qemu-kvm.
  Notes:
  for VM:
    OS: RHEL8.1
    CPU: 1
    MEM:4G
  For qemu-kvm(host kernel RHEL7):
    1) version:
   /usr/libexec/qemu-kvm -version
   QEMU emulator version 2.10.0(qemu-kvm-ev-2.10.0-21.el7_5.4.1)
    2) once the issue is occurred, the CPU of "CPU0 /KVM" is more than 99% by 
com "top -p VM_pro_ID"
  PID  UDER   PR NI RES   S  % CPU %MEM  TIME+COMMAND
  872067   qemu   20 0  1.6g  R   99.9  0.6  37:08.87 CPU 0/KVM
    3) use "pstack 493307" and below is function trace
  Thread 1 (Thread 0x7f2572e73040 (LWP 872067)):
  #0  0x7f256cad8fcf in ppoll () from /lib64/libc.so.6
  #1  0x55ff34bdf4a9 in qemu_poll_ns ()
  #2  0x55ff34be02a8 in main_loop_wait ()
  #3  0x55ff348bfb1a in main ()
    4) use strace "strace -tt -ff -p 872067 -o cfx" and below log keep printing
  21:24:02.977833 ppoll([{fd=4, events=POLLIN}, {fd=6, events=POLLIN}, {fd=8, 
events=POLLIN}, {fd=9, events=POLLIN}, {fd=80, events=POLLIN}, {fd=82, 
events=POLLIN}, {fd=84, events=POLLIN}, {fd=115, events=POLLIN}, {fd=121, 
events=POLLIN}], 9, {0, 0}, NULL, 8) = 0 (Timeout)
  21:24:02.977918 ppoll([{fd=4, events=POLLIN}, {fd=6, events=POLLIN}, {fd=8, 
events=POLLIN}, {fd=9, events=POLLIN}, {fd=80, events=POLLIN}, {fd=82, 
events=POLLIN}, {fd=84, events=POLLIN}, {fd=115, events=POLLIN}, {fd=121, 
events=POLLIN}], 9, {0, 911447}, NULL, 8) = 0 (Timeout)
  21:24:02.978945 ppoll([{fd=4, events=POLLIN}, {fd=6, events=POLLIN}, {fd=8, 
events=POLLIN}, {fd=9, events=POLLIN}, {fd=80, events=POLLIN}, {fd=82, 
events=POLLIN}, {fd=84, events=POLLIN}, {fd=115, events=POLLIN}, {fd=121, 
events=POLLIN}], 9, {0, 0}, NULL, 8) = 0 (Timeout)
  Therefore, I think the thread "CPU 0/KVM" is in tight loop.
    5) use reset can recover this issue. however, it will reoccurred again.
  Current work around is increase one CPU for this VM, then issue is gone.

  thanks
  Cliff

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1879425/+subscriptions



[Bug 1925512] Re: UNDEFINED case for instruction BLX

2021-04-22 Thread Richard Henderson
It's right there in trans_BLX_i:

if (s->thumb && (a->imm & 2)) {
return false;
}


** Changed in: qemu
   Status: New => Invalid

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1925512

Title:
  UNDEFINED case for instruction BLX

Status in QEMU:
  Invalid

Bug description:
  Hi

  I refer to the instruction BLX imm (T2 encoding) in ARMv7 (Thumb
  mode).

  0 S imm10H  11 J1 0 J2 imm10L H

  
  if H == '1' then UNDEFINED;
  I1 = NOT(J1 EOR S);  I2 = NOT(J2 EOR S);  imm32 = 
SignExtend(S:I1:I2:imm10H:imm10L:'00', 32);
  targetInstrSet = InstrSet_A32;
  if InITBlock() && !LastInITBlock() then UNPREDICTABLE;

  According to the manual, if H equals to 1, this instruction should be
  an UNDEFINED instruction. However, it seems QEMU does not check this
  constraint in function trans_BLX_i. Thanks

  Regards
  Muhui

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1925512/+subscriptions



[Bug 1925417] Re: Cannot boot from EFI image on aarch64

2021-04-22 Thread Ravishankar
When i try to do it manually using the instructions provided here:

https://mricher.fr/post/boot-from-an-efi-shell/

I see that

Mapping table
  FS0: Alias(s):HD0m:;BLK4:
  
VenHw(837DCA9E-E874-4D82-B29A-23FE0E23D1E2,003E000A)/HD(12,GPT,49037CF8-B2EF-5B4B-8CCE-EF5803A9E8B3,0x3D000,0x1)
BLK13: Alias(s):
  VenHw(93E34C7E-B5


BLK4 is not having any EFI file.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1925417

Title:
  Cannot boot from EFI image on aarch64

Status in QEMU:
  New

Bug description:
  I am unable to boot from a EFI disk image on aarch64 qemu.

  I have qemu built and installed from sources on a jetson-nano

  qemu-system-aarch64 -version
  QEMU emulator version 5.2.50 (v5.2.0-3234-gbdee969c0e)
  Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers

  KVM and and virtio are enabled in host kernel.

  Now I want to boot a ChromiumOS image. I have the image downloaded
  from here:

  https://chromium.arnoldthebat.co.uk/?dir=daily

  The image looks fine:

  rreddy78@jetson-nano:~/Downloads$ fdisk -lu chromiumos_image.bin 
  Disk chromiumos_image.bin: 6.2 GiB, 6606109184 bytes, 12902557 sectors
  Units: sectors of 1 * 512 = 512 bytes
  Sector size (logical/physical): 512 bytes / 512 bytes
  I/O size (minimum/optimal): 512 bytes / 512 bytes
  Disklabel type: gpt
  Disk identifier: C5B6CA94-0AF1-374E-90B5-A5CF4DC1FF51

  Device   Start  End Sectors  Size Type
  chromiumos_image.bin1  4513792 12902508 83887174G Linux filesystem
  chromiumos_image.bin22048053247   32768   16M ChromeOS kernel
  chromiumos_image.bin3   319488  4513791 41943042G ChromeOS root fs
  chromiumos_image.bin45324886015   32768   16M ChromeOS kernel
  chromiumos_image.bin5   315392   31948740962M ChromeOS root fs
  chromiumos_image.bin61644816448   1  512B ChromeOS kernel
  chromiumos_image.bin71644916449   1  512B ChromeOS root fs
  chromiumos_image.bin886016   118783   32768   16M Linux filesystem
  chromiumos_image.bin91645016450   1  512B ChromeOS reserved
  chromiumos_image.bin10   1645116451   1  512B ChromeOS reserved
  chromiumos_image.bin11  6416447   163848M unknown
  chromiumos_image.bin12  249856   315391   65536   32M EFI System

  Partition table entries are not in disk order.

  Now I try booting like this:

  qemu-system-aarch64 -M virt -m 2048 -smp 2 -cpu host -enable-kvm  \
  -device usb-ehci -device usb-kbd  -device usb-mouse -usb -serial stdio  \
  -device virtio-gpu-pci,virgl=on,xres=1600,yres=900 -display sdl,gl=on \
  -device virtio-blk-device,drive=hd \
  -drive if=none,file=chromiumos_image.bin,format=raw,id=hd   \
  -netdev user,id=mynet   \
  -device virtio-net-device,netdev=mynet \
  -bios edk2-aarch64-code.fd -no-reboot

  But I am unable to boot.

  Memory Type Information settings change.
  [Bds]Booting UEFI Misc Device
   BlockSize : 262144 
   LastBlock : FF 
  [Bds] Expand VenHw(93E34C7E-B50E-11DF-9223-2443DFD72085,00) -> 
  BdsDxe: failed to load Boot0001 "UEFI Misc Device" from 
VenHw(93E34C7E-B50E-11DF-9223-2443DFD72085,00): Not Found

  
  and 

  
  [Bds] Expand VenHw(837DCA9E-E874-4D82-B29A-23FE0E23D1E2,003E000A) -> 

  BdsDxe: failed to load Boot0002 "UEFI Misc Device 2" from 
VenHw(837DCA9E-E874-4D82-B29A-23FE0E23D1E2,003E000A): Not Found

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1925417/+subscriptions



Re: [PATCH for-6.0? 0/1] hw/block/nvme: fix msix uninit

2021-04-22 Thread Peter Maydell
On Thu, 22 Apr 2021 at 15:07, Klaus Jensen  wrote:
>
> On Apr 22 15:58, Klaus Jensen wrote:
> >From: Klaus Jensen 
> >
> >Hi Peter,
> >
> >The commit message on the patch describes the issue. This is a QEMU
> >crashing bug in -rc4 that I introduced early in the cycle and never
> >found in time. Lack of testing device hotplugging is the cause for that.
> >
> >I'm not sure what to say other than I'm terribly sorry for introducing
> >this and if this means an -rc5 needs to be rolled, then I'm even more
> >sorry.
> >
> >I think an acceptance test could have caught this, and I am already
> >working on an acceptance test suite for the nvme device, so I'll add
> >something that test this as well. But, well, it doesn't help now.

> As far as I can tell, to cause this crash, monitor access is required,
> so I am not sure if we can get away with a note on this in the release
> notes and fix this in a potential stable release or next.

Is this a regression since 5.2 ?

thanks
-- PMM



Re: [PATCH v2 1/2] block: Add BDRV_O_NO_SHARE for blk_new_open()

2021-04-22 Thread Eric Blake
On 4/22/21 11:43 AM, Kevin Wolf wrote:
> Normally, blk_new_open() just shares all permissions. This was fine
> originally when permissions only protected against uses in the same
> process because no other part of the code would actually get to access
> the block nodes opened with blk_new_open(). However, since we use it for
> file locking now, unsharing permissions becomes desirable.
> 
> Add a new BDRV_O_NO_SHARE flag that is used in blk_new_open() to unshare
> any permissions that can be unshared.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  include/block/block.h |  1 +
>  block/block-backend.c | 19 +--
>  2 files changed, 14 insertions(+), 6 deletions(-)

> 
> diff --git a/include/block/block.h b/include/block/block.h
> index b3f6e509d4..735db05a39 100644
> --- a/include/block/block.h
> +++ b/include/block/block.h
> @@ -101,6 +101,7 @@ typedef struct HDGeometry {
>  uint32_t cylinders;
>  } HDGeometry;
>  
> +#define BDRV_O_NO_SHARE0x0001 /* don't share permissons */

permissions


With the typo fix,

Reviewed-by: Eric Blake 


-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH 1/2] linux-user/alpha: Fix rt sigframe return

2021-04-22 Thread Laurent Vivier
Le 22/04/2021 à 20:08, Richard Henderson a écrit :
> We incorrectly used the offset of the non-rt sigframe.
> 
> Signed-off-by: Richard Henderson 
> ---
>  linux-user/alpha/signal.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/linux-user/alpha/signal.c b/linux-user/alpha/signal.c
> index c5c27ce084..86f5d2276d 100644
> --- a/linux-user/alpha/signal.c
> +++ b/linux-user/alpha/signal.c
> @@ -200,7 +200,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
> &frame->retcode[1]);
>  __put_user(INSN_CALLSYS, &frame->retcode[2]);
>  /* imb(); */
> -r26 = frame_addr + offsetof(struct target_sigframe, retcode);
> +r26 = frame_addr + offsetof(struct target_rt_sigframe, retcode);
>  }
>  
>  if (err) {
> 

Reviewed-by: Laurent Vivier 



Re: [PATCH 0/2] linux-user: sigaction fixes/cleanups

2021-04-22 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20210422180819.252121-1-richard.hender...@linaro.org/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20210422180819.252121-1-richard.hender...@linaro.org
Subject: [PATCH 0/2] linux-user: sigaction fixes/cleanups

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 - [tag update]  patchew/20210422154427.13038-1-alex.ben...@linaro.org -> 
patchew/20210422154427.13038-1-alex.ben...@linaro.org
 * [new tag] 
patchew/20210422180819.252121-1-richard.hender...@linaro.org -> 
patchew/20210422180819.252121-1-richard.hender...@linaro.org
Switched to a new branch 'test'
0bea0eb linux-user: Clean up sigaction ka_restorer
edde716 linux-user/alpha: Fix rt sigframe return

=== OUTPUT BEGIN ===
1/2 Checking commit edde716f548d (linux-user/alpha: Fix rt sigframe return)
2/2 Checking commit 0bea0eb16300 (linux-user: Clean up sigaction ka_restorer)
ERROR: code indent should never use tabs
#107: FILE: linux-user/syscall.c:9021:
+^Iret = get_errno(do_sigaction(arg1, pact, &oact, 0));$

ERROR: space prohibited between function name and open parenthesis '('
#173: FILE: linux-user/syscall.c:9075:
+#elif defined (TARGET_SPARC)

total: 2 errors, 0 warnings, 214 lines checked

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

=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20210422180819.252121-1-richard.hender...@linaro.org/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

[PATCH 1/2] linux-user/alpha: Fix rt sigframe return

2021-04-22 Thread Richard Henderson
We incorrectly used the offset of the non-rt sigframe.

Signed-off-by: Richard Henderson 
---
 linux-user/alpha/signal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/alpha/signal.c b/linux-user/alpha/signal.c
index c5c27ce084..86f5d2276d 100644
--- a/linux-user/alpha/signal.c
+++ b/linux-user/alpha/signal.c
@@ -200,7 +200,7 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
&frame->retcode[1]);
 __put_user(INSN_CALLSYS, &frame->retcode[2]);
 /* imb(); */
-r26 = frame_addr + offsetof(struct target_sigframe, retcode);
+r26 = frame_addr + offsetof(struct target_rt_sigframe, retcode);
 }
 
 if (err) {
-- 
2.25.1




[PATCH 2/2] linux-user: Clean up sigaction ka_restorer

2021-04-22 Thread Richard Henderson
Pass the ka_restorer value as an argument to do_sigaction,
and put it into the sigaction table.

Drop the separate TARGET_ALPHA struct target_rt_sigaction
and define TARGET_ARCH_HAS_KA_RESTORER.

Tidy up TARGET_NR_rt_sigaction, merging TARGET_ALPHA, and
TARGET_SPARC into common code.

Signed-off-by: Richard Henderson 
---
 linux-user/syscall_defs.h | 17 +++-
 linux-user/alpha/signal.c |  8 ++--
 linux-user/signal.c   |  4 +-
 linux-user/syscall.c  | 90 ---
 4 files changed, 41 insertions(+), 78 deletions(-)

diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 25be414727..226379fc9b 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -492,7 +492,7 @@ void target_to_host_old_sigset(sigset_t *sigset,
const abi_ulong *old_sigset);
 struct target_sigaction;
 int do_sigaction(int sig, const struct target_sigaction *act,
- struct target_sigaction *oact);
+ struct target_sigaction *oact, abi_ulong ka_restorer);
 
 #include "target_signal.h"
 
@@ -507,19 +507,16 @@ struct target_old_sigaction {
 int32_t sa_flags;
 };
 
-struct target_rt_sigaction {
-abi_ulong _sa_handler;
-abi_ulong sa_flags;
-target_sigset_t sa_mask;
-};
-
-/* This is the struct used inside the kernel.  The ka_restorer
-   field comes from the 5th argument to sys_rt_sigaction.  */
+#define TARGET_ARCH_HAS_KA_RESTORER 1
 struct target_sigaction {
 abi_ulong _sa_handler;
 abi_ulong sa_flags;
 target_sigset_t sa_mask;
-abi_ulong sa_restorer;
+/*
+ * This is used inside the kernel.  The ka_restorer field comes
+ * from the 5th argument to sys_rt_sigaction.
+ */
+abi_ulong ka_restorer;
 };
 #elif defined(TARGET_MIPS)
 struct target_sigaction {
diff --git a/linux-user/alpha/signal.c b/linux-user/alpha/signal.c
index 86f5d2276d..3aa4b339a4 100644
--- a/linux-user/alpha/signal.c
+++ b/linux-user/alpha/signal.c
@@ -138,8 +138,8 @@ void setup_frame(int sig, struct target_sigaction *ka,
 
 setup_sigcontext(&frame->sc, env, frame_addr, set);
 
-if (ka->sa_restorer) {
-r26 = ka->sa_restorer;
+if (ka->ka_restorer) {
+r26 = ka->ka_restorer;
 } else {
 __put_user(INSN_MOV_R30_R16, &frame->retcode[0]);
 __put_user(INSN_LDI_R0 + TARGET_NR_sigreturn,
@@ -192,8 +192,8 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
 __put_user(set->sig[i], &frame->uc.tuc_sigmask.sig[i]);
 }
 
-if (ka->sa_restorer) {
-r26 = ka->sa_restorer;
+if (ka->ka_restorer) {
+r26 = ka->ka_restorer;
 } else {
 __put_user(INSN_MOV_R30_R16, &frame->retcode[0]);
 __put_user(INSN_LDI_R0 + TARGET_NR_rt_sigreturn,
diff --git a/linux-user/signal.c b/linux-user/signal.c
index 7eecec46c4..de97cb8829 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -830,7 +830,7 @@ out:
 
 /* do_sigaction() return target values and host errnos */
 int do_sigaction(int sig, const struct target_sigaction *act,
- struct target_sigaction *oact)
+ struct target_sigaction *oact, abi_ulong ka_restorer)
 {
 struct target_sigaction *k;
 struct sigaction act1;
@@ -863,6 +863,8 @@ int do_sigaction(int sig, const struct target_sigaction 
*act,
 __get_user(k->sa_flags, &act->sa_flags);
 #ifdef TARGET_ARCH_HAS_SA_RESTORER
 __get_user(k->sa_restorer, &act->sa_restorer);
+#elif defined(TARGET_ARCH_HAS_KA_RESTORER)
+k->ka_restorer = ka_restorer;
 #endif
 /* To be swapped in target_to_host_sigset.  */
 k->sa_mask = act->sa_mask;
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 95d79ddc43..7c36650cbc 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8984,19 +8984,20 @@ static abi_long do_syscall1(void *cpu_env, int num, 
abi_long arg1,
 struct target_sigaction act, oact, *pact = 0;
 struct target_old_sigaction *old_act;
 if (arg2) {
-if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1))
+if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1)) {
 return -TARGET_EFAULT;
+}
 act._sa_handler = old_act->_sa_handler;
 target_siginitset(&act.sa_mask, old_act->sa_mask);
 act.sa_flags = old_act->sa_flags;
-act.sa_restorer = 0;
 unlock_user_struct(old_act, arg2, 0);
 pact = &act;
 }
-ret = get_errno(do_sigaction(arg1, pact, &oact));
+ret = get_errno(do_sigaction(arg1, pact, &oact, 0));
 if (!is_error(ret) && arg3) {
-if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0))
+if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0)) {
 return -TARGET_EFAULT;
+}
 old_act->_sa_handler = oact._sa_han

[PATCH 0/2] linux-user: sigaction fixes/cleanups

2021-04-22 Thread Richard Henderson
Alpha had two bugs, one with the non-ka_restorer fallback
using the wrong offset, and the other with the ka_restorer
value getting lost in do_sigaction.

Because do_sigaction didn't see TARGET_ARCH_HAS_SA_RESTORER
(which is correct for alpha, as the field isn't present in
the structure), we didn't copy the field into our syscall
table.  Which meant that the extra code present in do_syscall
to stash the ka_restorer value was wasted.

I believe that Sparc has a similar bug, but this one was
worse because it was modifying the user's sigaction struct
that was passed in.


r~


Richard Henderson (2):
  linux-user/alpha: Fix rt sigframe return
  linux-user: Clean up sigaction ka_restorer

 linux-user/syscall_defs.h | 17 +++-
 linux-user/alpha/signal.c | 10 ++---
 linux-user/signal.c   |  4 +-
 linux-user/syscall.c  | 90 ---
 4 files changed, 42 insertions(+), 79 deletions(-)

-- 
2.25.1




[RFC] tcg plugin: Additional plugin interface

2021-04-22 Thread Min-Yih Hsu
Hi Alex and QEMU developers,

Recently I was working with the TCG plugin. I found that
`qemu_plugin_cb_flags` seems to reserve the functionality to read / write
CPU register state, I'm wondering if you can share some roadmap or thoughts
on this feature?

Personally I see reading the CPU register state as (kind of) low-hanging
fruit. The most straightforward way to implement it will be adding another
function that can be called by insn_exec callbacks to read (v)CPU register
values. What do you think about this?

Thank you
-Min
-- 
Min-Yih Hsu
Ph.D Student in ICS Department, University of California, Irvine (UCI).


[PATCH 5/5] vhost-user-blk: Check that num-queues is supported by backend

2021-04-22 Thread Kevin Wolf
Creating a device with a number of queues that isn't supported by the
backend is pointless, the device won't work properly and the error
messages are rather confusing.

Just fail to create the device if num-queues is higher than what the
backend supports.

Since the relationship between num-queues and the number of virtqueues
depends on the specific device, this is an additional value that needs
to be initialised by the device. For convenience, allow leaving it 0 if
the check should be skipped. This makes sense for vhost-user-net where
separate vhost devices are used for the queues and custom initialisation
code is needed to perform the check.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1935031
Signed-off-by: Kevin Wolf 
---
 include/hw/virtio/vhost.h | 2 ++
 hw/block/vhost-user-blk.c | 1 +
 hw/virtio/vhost-user.c| 5 +
 3 files changed, 8 insertions(+)

diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
index 4a8bc75415..21a9a52088 100644
--- a/include/hw/virtio/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -74,6 +74,8 @@ struct vhost_dev {
 int nvqs;
 /* the first virtqueue which would be used by this vhost dev */
 int vq_index;
+/* if non-zero, minimum required value for max_queues */
+int num_queues;
 uint64_t features;
 uint64_t acked_features;
 uint64_t backend_features;
diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
index b6f4bb3f6f..ac2193abef 100644
--- a/hw/block/vhost-user-blk.c
+++ b/hw/block/vhost-user-blk.c
@@ -324,6 +324,7 @@ static int vhost_user_blk_connect(DeviceState *dev, Error 
**errp)
 }
 s->connected = true;
 
+s->dev.num_queues = s->num_queues;
 s->dev.nvqs = s->num_queues;
 s->dev.vqs = s->vhost_vqs;
 s->dev.vq_index = 0;
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index ded0c10453..ee57abe045 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -1909,6 +1909,11 @@ static int vhost_user_backend_init(struct vhost_dev 
*dev, void *opaque)
 return err;
 }
 }
+if (dev->num_queues && dev->max_queues < dev->num_queues) {
+error_report("The maximum number of queues supported by the "
+ "backend is %" PRIu64, dev->max_queues);
+return -EINVAL;
+}
 
 if (virtio_has_feature(features, VIRTIO_F_IOMMU_PLATFORM) &&
 !(virtio_has_feature(dev->protocol_features,
-- 
2.30.2




[PATCH 3/5] vhost-user-blk: Get more feature flags from vhost device

2021-04-22 Thread Kevin Wolf
VIRTIO_F_RING_PACKED and VIRTIO_F_IOMMU_PLATFORM need to be supported by
the vhost device, otherwise advertising it to the guest doesn't result
in a working configuration. They are currently not supported by the
vhost-user-blk export in QEMU.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1935020
Signed-off-by: Kevin Wolf 
---
 hw/block/vhost-user-blk.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
index 8422a29470..b6f4bb3f6f 100644
--- a/hw/block/vhost-user-blk.c
+++ b/hw/block/vhost-user-blk.c
@@ -47,6 +47,8 @@ static const int user_feature_bits[] = {
 VIRTIO_RING_F_INDIRECT_DESC,
 VIRTIO_RING_F_EVENT_IDX,
 VIRTIO_F_NOTIFY_ON_EMPTY,
+VIRTIO_F_RING_PACKED,
+VIRTIO_F_IOMMU_PLATFORM,
 VHOST_INVALID_FEATURE_BIT
 };
 
-- 
2.30.2




  1   2   3   4   >