Re: [PATCH 01/10] python/aqmp: add explicit GPLv2 license to legacy.py

2022-03-23 Thread John Snow
On Mon, Mar 21, 2022 at 5:08 PM John Snow  wrote:
>
> The legacy.py module is heavily based on the QMP module by Luiz
> Capitulino (et al) which is licensed as explicit GPLv2-only. The async
> QMP package is currently licensed similarly, but I intend to relicense
> the async package to the more flexible GPLv2+.
>
> In preparation for that change, make the license on legacy.py explicit.
>
> Signed-off-by: John Snow 
> ---
>  python/qemu/aqmp/legacy.py | 11 +++
>  1 file changed, 11 insertions(+)
>
> diff --git a/python/qemu/aqmp/legacy.py b/python/qemu/aqmp/legacy.py
> index 46026e9fdc..f86cb29804 100644
> --- a/python/qemu/aqmp/legacy.py
> +++ b/python/qemu/aqmp/legacy.py
> @@ -4,6 +4,17 @@
>  This class pretends to be qemu.qmp.QEMUMonitorProtocol.
>  """
>
> +#
> +# Copyright (C) 2009-2022 Red Hat Inc.
> +#
> +# Authors:
> +#  Luiz Capitulino 
> +#  John Snow 
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2.  See
> +# the COPYING file in the top-level directory.
> +#
> +
>  import asyncio
>  from typing import (
>  Any,
> --
> 2.34.1
>

Anyone have any strong feelings on me doing this? CC'ing people with
known strong feelings on licenses.

I'm:

(1) Re-affirming that the legacy interface for async QMP is GPLv2
(like the classic QMP library is), because the interface and
docstrings here are largely copy-pasted from that library. It's
heavily remixed and modified, but it is undeniably derivative. (This
patch)

(2) Re-licensing async QMP as GPLv2+. (Next patch)

(3) Someday, eventually, adding a different sync interface that
doesn't re-mix this specific compatibility interface and will provide
better event-waiting primitives and so on. legacy.py will get dropped
at that point and the sub-project will become wholly GPLv2+. Until
then, it will be mixed.

--js




Re: [PATCH 09/10] python: rename qemu.aqmp to qemu.qmp

2022-03-23 Thread John Snow
On Wed, Mar 23, 2022 at 2:20 PM Hanna Reitz  wrote:
>
> On 21.03.22 22:08, John Snow wrote:
> > Now that we are fully switched over to the new QMP library, move it back
> > over the old namespace. This is being done primarily so that we may
> > upload this package simply as "qemu.qmp" without introducing confusion
> > over whether or not "aqmp" is a new protocol or not.
> >
> > The trade-off is increased confusion inside the QEMU developer
> > tree. Sorry!
> >
> > Note: the 'private' member "_aqmp" in legacy.py also changes to "_qmp";
> > not out of necessity, but just to remove any traces of the "aqmp"
> > name.
> >
> > Signed-off-by: John Snow 
> > Reviewed-by: Beraldo Leal 
> > ---
>
> I guess this is the one for which I’m CC-ed?

Probably.

>
> [...]
>
> > diff --git a/scripts/render_block_graph.py b/scripts/render_block_graph.py
> > index b33fb70d5e..8f731a5cfe 100755
> > --- a/scripts/render_block_graph.py
> > +++ b/scripts/render_block_graph.py
> > @@ -25,8 +25,8 @@
> >   from graphviz import Digraph
> >
> >   sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'python'))
> > -from qemu.aqmp import QMPError
> > -from qemu.aqmp.legacy import QEMUMonitorProtocol
> > +from qemu.qmp import QMPError
> > +from qemu.qmp.legacy import QEMUMonitorProtocol
> >
> >
> >   def perm(arr):
> > diff --git a/scripts/simplebench/bench_block_job.py 
> > b/scripts/simplebench/bench_block_job.py
> > index af9d1646a4..56191db44b 100755
> > --- a/scripts/simplebench/bench_block_job.py
> > +++ b/scripts/simplebench/bench_block_job.py
> > @@ -27,7 +27,7 @@
> >
> >   sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 
> > 'python'))
> >   from qemu.machine import QEMUMachine
> > -from qemu.aqmp import ConnectError
> > +from qemu.qmp import ConnectError
> >
> >
> >   def bench_block_job(cmd, cmd_args, qemu_args):
> > diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> > index 8760e2c310..9563749709 100644
> > --- a/tests/qemu-iotests/iotests.py
> > +++ b/tests/qemu-iotests/iotests.py
> > @@ -38,7 +38,7 @@
> >   from contextlib import contextmanager
> >
> >   from qemu.machine import qtest
> > -from qemu.aqmp.legacy import QMPMessage, QEMUMonitorProtocol
> > +from qemu.qmp.legacy import QMPMessage, QEMUMonitorProtocol
>
> (Rebasing will change the order of imports; you fixed the (alphabetic)
> ordering in 2882ccf86a9, now you’re going to have to restore the
> original ordering here :))

I'll probably just fix stuff like this on merge when I go to send my
PR for this. Too fiddly otherwise.

>
> >   # Use this logger for logging messages directly from the iotests module
> >   logger = logging.getLogger('qemu.iotests')
> > diff --git a/tests/qemu-iotests/tests/mirror-top-perms 
> > b/tests/qemu-iotests/tests/mirror-top-perms
> > index 223f3c1620..d538579961 100755
> > --- a/tests/qemu-iotests/tests/mirror-top-perms
> > +++ b/tests/qemu-iotests/tests/mirror-top-perms
> > @@ -99,7 +99,7 @@ class TestMirrorTopPerms(iotests.QMPTestCase):
> >   self.vm_b.add_device('virtio-blk,drive=drive0,share-rw=on')
> >   try:
> >   # Silence AQMP logging errors temporarily.
>
> Probably should just be “QMP” now, too.  Anyway:

Yep, oops. I didn't refresh this series as much as I should have. It
was good the last time I checked it, I swear! ... three months ago.

>
> Acked-by: Hanna Reitz 

Thanks.

>
> > -with change_log_level('qemu.aqmp'):
> > +with change_log_level('qemu.qmp'):
> >   self.vm_b.launch()
> >   print('ERROR: VM B launched successfully, '
> > 'this should not have happened')
>




Re: [PATCH 06/10] python/aqmp: copy qmp docstrings to qemu.aqmp.legacy

2022-03-23 Thread John Snow
On Wed, Mar 23, 2022 at 2:24 PM Hanna Reitz  wrote:
>
> On 21.03.22 22:08, John Snow wrote:
> > Copy the docstrings out of qemu.qmp, adjusting them as necessary to
> > more accurately reflect the current state of this class.
> >
> > (Licensing: This is copying and modifying GPLv2-only licensed docstrings
> > into a GPLv2-only file.)
> >
> > Signed-off-by: John Snow 
> > Reviewed-by: Vladimir Sementsov-Ogievskiy 
> > Reviewed-by: Beraldo Leal 
> > ---
> >   python/qemu/aqmp/legacy.py | 102 ++---
> >   1 file changed, 94 insertions(+), 8 deletions(-)
> >
> > diff --git a/python/qemu/aqmp/legacy.py b/python/qemu/aqmp/legacy.py
> > index 10c7c99c4f..20ffdd8956 100644
> > --- a/python/qemu/aqmp/legacy.py
> > +++ b/python/qemu/aqmp/legacy.py
>
> [...]
>
> > @@ -60,6 +63,21 @@ class QMPBadPortError(QMPError):
> >
> >
> >   class QEMUMonitorProtocol:
> > +"""
> > +Provide an API to connect to QEMU via QEMU Monitor Protocol (QMP)
> > +and then allow to handle commands and events.
> > +
> > +:param address:  QEMU address, can be either a unix socket path 
> > (string)
> > + or a tuple in the form ( address, port ) for a TCP
> > + connection
> > +:param server:   Deprecated, ignored. (See 'accept')
>
> Can’t help but notice that this is (technically) just wrong, because it
> isn’t ignored.  Are you afraid people might not be sufficiently
> dissuaded by the “deprecated” keyword?  (I mean, if that were the case,
> I’d suggest you write “Deprecated, because setting this to true might
> make your computer explode” instead.)
>

Oops, this is outdated. I *did* drop this parameter. once. And then I
re-added it.

Thanks for noticing.

--js




Re: [PATCH 24/32] include: move progress API to qemu-progress.h

2022-03-23 Thread Richard Henderson

On 3/23/22 08:57, marcandre.lur...@redhat.com wrote:

+++ b/include/qemu/qemu-progress.h
@@ -0,0 +1,8 @@
+#ifndef QEMU_PROGRESS_H


All files must have copyright header.

r~



Re: [PATCH 06/10] python/aqmp: copy qmp docstrings to qemu.aqmp.legacy

2022-03-23 Thread Hanna Reitz

On 21.03.22 22:08, John Snow wrote:

Copy the docstrings out of qemu.qmp, adjusting them as necessary to
more accurately reflect the current state of this class.

(Licensing: This is copying and modifying GPLv2-only licensed docstrings
into a GPLv2-only file.)

Signed-off-by: John Snow 
Reviewed-by: Vladimir Sementsov-Ogievskiy 
Reviewed-by: Beraldo Leal 
---
  python/qemu/aqmp/legacy.py | 102 ++---
  1 file changed, 94 insertions(+), 8 deletions(-)

diff --git a/python/qemu/aqmp/legacy.py b/python/qemu/aqmp/legacy.py
index 10c7c99c4f..20ffdd8956 100644
--- a/python/qemu/aqmp/legacy.py
+++ b/python/qemu/aqmp/legacy.py


[...]


@@ -60,6 +63,21 @@ class QMPBadPortError(QMPError):
  
  
  class QEMUMonitorProtocol:

+"""
+Provide an API to connect to QEMU via QEMU Monitor Protocol (QMP)
+and then allow to handle commands and events.
+
+:param address:  QEMU address, can be either a unix socket path (string)
+ or a tuple in the form ( address, port ) for a TCP
+ connection
+:param server:   Deprecated, ignored. (See 'accept')


Can’t help but notice that this is (technically) just wrong, because it 
isn’t ignored.  Are you afraid people might not be sufficiently 
dissuaded by the “deprecated” keyword?  (I mean, if that were the case, 
I’d suggest you write “Deprecated, because setting this to true might 
make your computer explode” instead.)


Hanna


+:param nickname: Optional nickname used for logging.
+
+..note::
+No connection is established during `__init__`, this is done by
+the `connect()` or `accept()` methods.
+"""
+
  def __init__(self, address: SocketAddrT,
   server: bool = False,
   nickname: Optional[str] = None):





Re: [PATCH 09/10] python: rename qemu.aqmp to qemu.qmp

2022-03-23 Thread Hanna Reitz

On 21.03.22 22:08, John Snow wrote:

Now that we are fully switched over to the new QMP library, move it back
over the old namespace. This is being done primarily so that we may
upload this package simply as "qemu.qmp" without introducing confusion
over whether or not "aqmp" is a new protocol or not.

The trade-off is increased confusion inside the QEMU developer
tree. Sorry!

Note: the 'private' member "_aqmp" in legacy.py also changes to "_qmp";
not out of necessity, but just to remove any traces of the "aqmp"
name.

Signed-off-by: John Snow 
Reviewed-by: Beraldo Leal 
---


I guess this is the one for which I’m CC-ed?

[...]


diff --git a/scripts/render_block_graph.py b/scripts/render_block_graph.py
index b33fb70d5e..8f731a5cfe 100755
--- a/scripts/render_block_graph.py
+++ b/scripts/render_block_graph.py
@@ -25,8 +25,8 @@
  from graphviz import Digraph
  
  sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'python'))

-from qemu.aqmp import QMPError
-from qemu.aqmp.legacy import QEMUMonitorProtocol
+from qemu.qmp import QMPError
+from qemu.qmp.legacy import QEMUMonitorProtocol
  
  
  def perm(arr):

diff --git a/scripts/simplebench/bench_block_job.py 
b/scripts/simplebench/bench_block_job.py
index af9d1646a4..56191db44b 100755
--- a/scripts/simplebench/bench_block_job.py
+++ b/scripts/simplebench/bench_block_job.py
@@ -27,7 +27,7 @@
  
  sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))

  from qemu.machine import QEMUMachine
-from qemu.aqmp import ConnectError
+from qemu.qmp import ConnectError
  
  
  def bench_block_job(cmd, cmd_args, qemu_args):

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 8760e2c310..9563749709 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -38,7 +38,7 @@
  from contextlib import contextmanager
  
  from qemu.machine import qtest

-from qemu.aqmp.legacy import QMPMessage, QEMUMonitorProtocol
+from qemu.qmp.legacy import QMPMessage, QEMUMonitorProtocol


(Rebasing will change the order of imports; you fixed the (alphabetic) 
ordering in 2882ccf86a9, now you’re going to have to restore the 
original ordering here :))



  # Use this logger for logging messages directly from the iotests module
  logger = logging.getLogger('qemu.iotests')
diff --git a/tests/qemu-iotests/tests/mirror-top-perms 
b/tests/qemu-iotests/tests/mirror-top-perms
index 223f3c1620..d538579961 100755
--- a/tests/qemu-iotests/tests/mirror-top-perms
+++ b/tests/qemu-iotests/tests/mirror-top-perms
@@ -99,7 +99,7 @@ class TestMirrorTopPerms(iotests.QMPTestCase):
  self.vm_b.add_device('virtio-blk,drive=drive0,share-rw=on')
  try:
  # Silence AQMP logging errors temporarily.


Probably should just be “QMP” now, too.  Anyway:

Acked-by: Hanna Reitz 


-with change_log_level('qemu.aqmp'):
+with change_log_level('qemu.qmp'):
  self.vm_b.launch()
  print('ERROR: VM B launched successfully, '
'this should not have happened')





[PATCH 24/32] include: move progress API to qemu-progress.h

2022-03-23 Thread marcandre . lureau
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 include/qemu-common.h| 4 
 include/qemu/qemu-progress.h | 8 
 qemu-img.c   | 1 +
 util/qemu-progress.c | 2 +-
 4 files changed, 10 insertions(+), 5 deletions(-)
 create mode 100644 include/qemu/qemu-progress.h

diff --git a/include/qemu-common.h b/include/qemu-common.h
index bc73daecb4e9..fee2181af218 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -24,10 +24,6 @@
 int qemu_main(int argc, char **argv, char **envp);
 #endif
 
-
-void qemu_progress_init(int enabled, float min_skip);
-void qemu_progress_end(void);
-void qemu_progress_print(float delta, int max);
 const char *qemu_get_vm_name(void);
 
 /* OS specific functions */
diff --git a/include/qemu/qemu-progress.h b/include/qemu/qemu-progress.h
new file mode 100644
index ..137e1c316fd0
--- /dev/null
+++ b/include/qemu/qemu-progress.h
@@ -0,0 +1,8 @@
+#ifndef QEMU_PROGRESS_H
+#define QEMU_PROGRESS_H
+
+void qemu_progress_init(int enabled, float min_skip);
+void qemu_progress_end(void);
+void qemu_progress_print(float delta, int max);
+
+#endif /* QEMU_PROGRESS_H */
diff --git a/qemu-img.c b/qemu-img.c
index 1caddfb23a71..13cb2ec72fbd 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -26,6 +26,7 @@
 #include 
 
 #include "qemu-common.h"
+#include "qemu/qemu-progress.h"
 #include "qemu-version.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-block-core.h"
diff --git a/util/qemu-progress.c b/util/qemu-progress.c
index 20d51f8c128b..aa994668f1c4 100644
--- a/util/qemu-progress.c
+++ b/util/qemu-progress.c
@@ -23,7 +23,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "qemu-common.h"
+#include "qemu/qemu-progress.h"
 
 struct progress_state {
 float current;
-- 
2.35.1.273.ge6ebfd0e8cbb




[PATCH 32/32] Remove qemu-common.h include from most units

2022-03-23 Thread marcandre . lureau
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 include/qemu-common.h| 9 -
 accel/hvf/hvf-all.c  | 1 -
 accel/tcg/cpu-exec.c | 1 -
 accel/tcg/tcg-accel-ops-icount.c | 1 -
 accel/tcg/tcg-accel-ops-mttcg.c  | 1 -
 accel/tcg/tcg-accel-ops-rr.c | 1 -
 accel/tcg/tcg-accel-ops.c| 1 -
 accel/tcg/tcg-all.c  | 1 -
 accel/tcg/translate-all.c| 1 -
 audio/audio_win_int.c| 1 -
 backends/hostmem-epc.c   | 1 -
 backends/tpm/tpm_passthrough.c   | 1 -
 block/file-posix.c   | 1 -
 block/io_uring.c | 1 -
 bsd-user/freebsd/os-syscall.c| 1 -
 bsd-user/mmap.c  | 1 -
 chardev/char-fd.c| 1 -
 chardev/char-pipe.c  | 1 -
 chardev/char-pty.c   | 1 -
 cpu.c| 1 -
 crypto/cipher-afalg.c| 1 -
 crypto/hash-afalg.c  | 1 -
 dump/dump.c  | 1 -
 dump/win_dump.c  | 1 -
 fsdev/virtfs-proxy-helper.c  | 1 -
 gdbstub.c| 1 -
 hw/9pfs/9p-proxy.c   | 1 -
 hw/alpha/dp264.c | 1 -
 hw/avr/boot.c| 1 -
 hw/core/loader.c | 1 -
 hw/display/artist.c  | 1 -
 hw/display/cg3.c | 1 -
 hw/display/tcx.c | 1 -
 hw/display/virtio-gpu-udmabuf.c  | 1 -
 hw/dma/pl330.c   | 1 -
 hw/hppa/machine.c| 1 -
 hw/i386/pc_sysfw.c   | 1 -
 hw/i386/x86.c| 1 -
 hw/input/vhost-user-input.c  | 1 -
 hw/intc/xics_kvm.c   | 1 -
 hw/m68k/mcf5208.c| 1 -
 hw/m68k/q800.c   | 1 -
 hw/m68k/virt.c   | 1 -
 hw/microblaze/boot.c | 1 -
 hw/mips/fuloong2e.c  | 1 -
 hw/mips/jazz.c   | 1 -
 hw/mips/loongson3_virt.c | 1 -
 hw/mips/malta.c  | 1 -
 hw/mips/mipssim.c| 1 -
 hw/misc/sbsa_ec.c| 1 -
 hw/net/fsl_etsec/etsec.c | 1 -
 hw/net/fsl_etsec/rings.c | 1 -
 hw/net/msf2-emac.c   | 1 -
 hw/net/npcm7xx_emc.c | 1 -
 hw/nios2/boot.c  | 1 -
 hw/nios2/generic_nommu.c | 1 -
 hw/nvram/fw_cfg.c| 1 -
 hw/pci-host/mv64361.c| 1 -
 hw/pci-host/pnv_phb3.c   | 1 -
 hw/pci-host/pnv_phb3_msi.c   | 1 -
 hw/pci-host/pnv_phb3_pbcq.c  | 1 -
 hw/pci-host/pnv_phb4.c   | 1 -
 hw/pci-host/pnv_phb4_pec.c   | 1 -
 hw/pci-host/raven.c  | 1 -
 hw/pci-host/remote.c | 1 -
 hw/pci/pci.c | 1 -
 hw/ppc/e500.c| 1 -
 hw/ppc/mac_newworld.c| 1 -
 hw/ppc/mac_oldworld.c| 1 -
 hw/ppc/pegasos2.c| 1 -
 hw/ppc/pnv.c | 1 -
 hw/ppc/pnv_bmc.c | 1 -
 hw/ppc/ppc405_boards.c   | 1 -
 hw/ppc/ppc440_bamboo.c   | 1 -
 hw/ppc/sam460ex.c| 1 -
 hw/ppc/spapr.c   | 1 -
 hw/ppc/spapr_numa.c  | 1 -
 hw/ppc/spapr_pci_nvlink2.c   | 1 -
 hw/ppc/spapr_tpm_proxy.c | 1 -
 hw/ppc/spapr_vof.c   | 1 -
 hw/ppc/virtex_ml507.c| 1 -
 hw/ppc/vof.c | 1 -
 hw/remote/iohub.c| 1 -
 hw/remote/machine.c  | 1 -
 hw/remote/memory.c   | 1 -
 hw/remote/message.c  | 1 -
 hw/remote/mpqemu-link.c  | 1 -
 hw/remote/proxy-memory-listener.c| 1 -
 hw/remote/proxy.c| 1 -
 hw/remote/remote-obj.c   | 1 -
 hw/riscv/boot.c  | 1 -
 hw/rx/rx-gdbsim.c| 1 -
 hw/s390x/ipl.c   | 1 -
 hw/sd/sd.c   | 1 -
 hw/sparc/leon3.c | 1 -
 hw/sparc/sun4m.c | 1 -
 hw/sparc64/sun4u.c   | 1 -
 hw/usb/dev-mtp.c | 1 -
 hw/virtio/virtio-iommu.c | 1 -
 hw/virtio/virtio-mem.c   | 1 -
 hw/virtio/virtio-pmem.c  | 1 -
 io/channel-socket.c  | 1 -
 linux-user/aarch64/cpu_loop.c 

[PATCH 25/32] include: move qemu_get_vm_name() to sysemu.h

2022-03-23 Thread marcandre . lureau
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 include/qemu-common.h   | 2 --
 include/sysemu/sysemu.h | 2 ++
 audio/audio.c   | 2 +-
 block/iscsi.c   | 2 +-
 stubs/get-vm-name.c | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/qemu-common.h b/include/qemu-common.h
index fee2181af218..1fbc20e4bcf7 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -24,8 +24,6 @@
 int qemu_main(int argc, char **argv, char **envp);
 #endif
 
-const char *qemu_get_vm_name(void);
-
 /* OS specific functions */
 void os_setup_early_signal_handling(void);
 int os_parse_cmd_args(int index, const char *optarg);
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index b9421e03ffdd..10e283c17064 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -13,6 +13,8 @@ extern const char *qemu_name;
 extern QemuUUID qemu_uuid;
 extern bool qemu_uuid_set;
 
+const char *qemu_get_vm_name(void);
+
 void qemu_add_exit_notifier(Notifier *notify);
 void qemu_remove_exit_notifier(Notifier *notify);
 
diff --git a/audio/audio.c b/audio/audio.c
index 1c98964eb843..9e91a5a4f2b8 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -32,7 +32,7 @@
 #include "qapi/qapi-visit-audio.h"
 #include "qemu/cutils.h"
 #include "qemu/module.h"
-#include "qemu-common.h"
+#include "sysemu/sysemu.h"
 #include "sysemu/replay.h"
 #include "sysemu/runstate.h"
 #include "ui/qemu-spice.h"
diff --git a/block/iscsi.c b/block/iscsi.c
index 51f2a5eeaa80..d707d0b35435 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -28,7 +28,7 @@
 #include 
 #include 
 #include 
-#include "qemu-common.h"
+#include "sysemu/sysemu.h"
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
 #include "qemu/bitops.h"
diff --git a/stubs/get-vm-name.c b/stubs/get-vm-name.c
index fa990136b068..0906303f7306 100644
--- a/stubs/get-vm-name.c
+++ b/stubs/get-vm-name.c
@@ -1,5 +1,5 @@
 #include "qemu/osdep.h"
-#include "qemu-common.h"
+#include "sysemu/sysemu.h"
 
 const char *qemu_get_vm_name(void)
 {
-- 
2.35.1.273.ge6ebfd0e8cbb




[PATCH 11/32] Replace qemu_real_host_page variables with inlined functions

2022-03-23 Thread marcandre . lureau
From: Marc-André Lureau 

Replace the global variables with inlined helper functions. getpagesize() is 
very
likely annotated with a "const" function attribute (at least with glibc), and 
thus
optimization should apply even better.

This avoids the need for a constructor initialization too.

Signed-off-by: Marc-André Lureau 
---
 include/exec/cpu-common.h  |  2 +-
 include/exec/ram_addr.h|  2 +-
 include/qemu/osdep.h   | 15 +++
 accel/hvf/hvf-accel-ops.c  |  2 +-
 accel/kvm/kvm-all.c| 20 ++--
 backends/hostmem.c |  2 +-
 block.c|  4 ++--
 block/file-posix.c |  6 +++---
 block/io.c |  2 +-
 block/nvme.c   | 22 +++---
 block/parallels.c  |  2 +-
 block/qcow2-cache.c|  2 +-
 bsd-user/elfload.c |  2 +-
 bsd-user/mmap.c|  2 +-
 contrib/vhost-user-gpu/vugbm.c |  2 +-
 cpu.c  |  2 +-
 hw/display/qxl.c   |  2 +-
 hw/intc/s390_flic_kvm.c|  2 +-
 hw/nvram/fw_cfg.c  |  6 +++---
 hw/ppc/mac_newworld.c  |  2 +-
 hw/ppc/spapr_pci.c |  2 +-
 hw/rdma/vmw/pvrdma_main.c  |  2 +-
 hw/scsi/scsi-generic.c |  2 +-
 hw/tpm/tpm_ppi.c   |  2 +-
 hw/vfio/common.c   | 24 
 hw/vfio/pci.c  | 10 +-
 hw/vfio/spapr.c|  8 
 hw/virtio/vhost-iova-tree.c|  4 ++--
 hw/virtio/vhost-shadow-virtqueue.c |  8 
 hw/virtio/vhost-user.c |  4 ++--
 hw/virtio/vhost-vdpa.c |  6 +++---
 hw/virtio/virtio-mem.c | 10 +-
 linux-user/elfload.c   |  4 ++--
 linux-user/mmap.c  |  2 +-
 migration/migration.c  |  2 +-
 migration/postcopy-ram.c   |  4 ++--
 monitor/misc.c |  2 +-
 softmmu/physmem.c  |  6 +++---
 target/i386/hax/hax-mem.c  | 10 +-
 target/i386/nvmm/nvmm-all.c|  8 
 target/i386/whpx/whpx-all.c|  8 
 target/ppc/kvm.c   |  2 +-
 tcg/region.c   |  8 
 tests/vhost-user-bridge.c  |  8 
 util/cutils.c  |  4 ++--
 util/mmap-alloc.c  | 10 +-
 util/osdep.c   |  4 ++--
 util/oslib-posix.c |  8 
 util/oslib-win32.c |  2 +-
 util/pagesize.c| 18 --
 util/vfio-helpers.c| 14 +++---
 scripts/checkpatch.pl  |  4 ++--
 util/meson.build   |  1 -
 53 files changed, 150 insertions(+), 162 deletions(-)
 delete mode 100644 util/pagesize.c

diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index c7d50fac955c..5979fc1f8e1b 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -26,7 +26,7 @@ extern uintptr_t qemu_host_page_size;
 extern intptr_t qemu_host_page_mask;
 
 #define HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_host_page_size)
-#define REAL_HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_real_host_page_size)
+#define REAL_HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_real_host_page_size())
 
 /* The CPU list lock nests outside page_(un)lock or mmap_(un)lock */
 void qemu_init_cpu_list(void);
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index 64fb936c7c74..f3e0c78161d1 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -343,7 +343,7 @@ static inline void 
cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
 hwaddr addr;
 ram_addr_t ram_addr;
 unsigned long len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
-unsigned long hpratio = qemu_real_host_page_size / TARGET_PAGE_SIZE;
+unsigned long hpratio = qemu_real_host_page_size() / TARGET_PAGE_SIZE;
 unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS);
 
 /* start address is aligned at the start of a word? */
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 95a14914d13b..240b48707ecc 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -431,9 +431,9 @@ extern int madvise(char *, size_t, int);
/* Use 1 MiB (segment size) alignment so gmap can be used by KVM. */
 #  define QEMU_VMALLOC_ALIGN (256 * 4096)
 #elif defined(__linux__) && defined(__sparc__)
-#  define QEMU_VMALLOC_ALIGN MAX(qemu_real_host_page_size, SHMLBA)
+#  define QEMU_VMALLOC_ALIGN MAX(qemu_real_host_page_size(), SHMLBA)
 #else
-#  define QEMU_VMALLOC_ALIGN qemu_real_host_page_size
+#  define QEMU_VMALLOC_ALIGN qemu_real_host_page_size()
 #endif
 
 #ifdef CONFIG_POSIX
@@ -590,8 +590,15 @@ pid_t qemu_fork(Error **errp);
 /* Using intptr_t ensures that qemu_*_page_mask is sign-extended 

[PATCH 06/32] Replace config-time define HOST_WORDS_BIGENDIAN

2022-03-23 Thread marcandre . lureau
From: Marc-André Lureau 

Replace a config-time define with a compile time condition
define (compatible with clang and gcc) that must be declared prior to
its usage. This avoids having a global configure time define, but also
prevents from bad usage, if the config header wasn't included before.

This can help to make some code independent from qemu too.

gcc supports __BYTE_ORDER__ from about 4.6 and clang from 3.2.

Signed-off-by: Marc-André Lureau 
[ For the s390x parts I'm involved in ]
Acked-by: Halil Pasic 
Reviewed-by: Philippe Mathieu-Daudé 
---
 meson.build |  1 -
 accel/tcg/atomic_template.h |  4 +-
 audio/audio.h   |  2 +-
 hw/display/pl110_template.h |  6 +--
 hw/net/can/ctucan_core.h|  2 +-
 hw/net/vmxnet3.h|  4 +-
 include/exec/cpu-all.h  |  7 ++--
 include/exec/cpu-common.h   |  2 +-
 include/exec/memop.h|  2 +-
 include/exec/memory.h   |  2 +-
 include/fpu/softfloat-types.h   |  2 +-
 include/hw/core/cpu.h   |  2 +-
 include/hw/i386/intel_iommu.h   |  6 +--
 include/hw/i386/x86-iommu.h |  4 +-
 include/hw/virtio/virtio-access.h   |  6 +--
 include/hw/virtio/virtio-gpu-bswap.h|  2 +-
 include/libdecnumber/dconfig.h  |  2 +-
 include/net/eth.h   |  2 +-
 include/qemu/bswap.h|  8 ++--
 include/qemu/host-utils.h   |  2 +-
 include/qemu/int128.h   |  2 +-
 include/ui/qemu-pixman.h|  2 +-
 net/util.h  |  2 +-
 target/arm/cpu.h|  8 ++--
 target/arm/translate-a64.h  |  2 +-
 target/arm/vec_internal.h   |  2 +-
 target/i386/cpu.h   |  2 +-
 target/mips/cpu.h   |  2 +-
 target/ppc/cpu.h|  2 +-
 target/s390x/tcg/vec.h  |  2 +-
 target/xtensa/cpu.h |  2 +-
 tests/fp/platform.h |  4 +-
 accel/kvm/kvm-all.c |  4 +-
 audio/dbusaudio.c   |  2 +-
 disas.c |  2 +-
 hw/core/loader.c|  4 +-
 hw/display/artist.c |  6 +--
 hw/display/pxa2xx_lcd.c |  2 +-
 hw/display/vga.c| 12 +++---
 hw/display/virtio-gpu-gl.c  |  2 +-
 hw/s390x/event-facility.c   |  2 +-
 hw/virtio/vhost.c   |  2 +-
 linux-user/arm/nwfpe/double_cpdo.c  |  4 +-
 linux-user/arm/nwfpe/fpa11_cpdt.c   |  4 +-
 linux-user/ppc/signal.c |  3 +-
 linux-user/syscall.c|  6 +--
 net/net.c   |  4 +-
 target/alpha/translate.c|  2 +-
 target/arm/crypto_helper.c  |  2 +-
 target/arm/helper.c |  2 +-
 target/arm/kvm64.c  |  4 +-
 target/arm/neon_helper.c|  2 +-
 target/arm/sve_helper.c |  4 +-
 target/arm/translate-sve.c  |  6 +--
 target/arm/translate-vfp.c  |  2 +-
 target/arm/translate.c  |  2 +-
 target/hppa/translate.c |  2 +-
 target/i386/tcg/translate.c |  2 +-
 target/mips/tcg/lmmi_helper.c   |  2 +-
 target/mips/tcg/msa_helper.c| 54 -
 target/ppc/arch_dump.c  |  2 +-
 target/ppc/int_helper.c | 22 +-
 target/ppc/kvm.c|  4 +-
 target/ppc/mem_helper.c |  2 +-
 target/riscv/vector_helper.c|  2 +-
 target/s390x/tcg/translate.c|  2 +-
 target/sparc/vis_helper.c   |  4 +-
 tcg/tcg-op.c|  4 +-
 tcg/tcg.c   | 12 +++---
 tests/qtest/vhost-user-blk-test.c   |  2 +-
 tests/qtest/virtio-blk-test.c   |  2 +-
 ui/vdagent.c|  2 +-
 ui/vnc.c|  2 +-
 util/bitmap.c   |  2 +-
 util/host-utils.c   |  2 +-
 target/ppc/translate/vmx-impl.c.inc |  4 +-
 target/ppc/translate/vsx-impl.c.inc |  2 +-
 target/riscv/insn_trans/trans_rvv.c.inc |  4 +-
 target/s390x/tcg/translate_vx.c.inc |  2 +-
 tcg/aarch64/tcg-target.c.inc|  4 +-
 tcg/arm/tcg-target.c.inc|  4 +-
 tcg/mips/tcg-target.c.inc   |  2 +-
 tcg/ppc/tcg-target.c.inc| 10 ++---
 tcg/riscv/tcg-target.c.inc  |  4 +-
 84 files changed, 173 insertions(+), 174 deletions(-)

diff --git a/meson.build b/meson.build
index dc17d37e461b..7828f6537813 100644
--- a/meson.build
+++ b/meson.build
@@ -1592,7 +1592,6 @@ config_host_data.set('QEMU_VERSION_MICRO', 

Re: [PATCH-for-7.0 1/2] block: Fix misleading hexadecimal format

2022-03-23 Thread Denis V. Lunev

On 23.03.2022 14:47, Philippe Mathieu-Daudé wrote:

From: Philippe Mathieu-Daudé 

"0x%u" format is very misleading, replace by "0x%x".

Found running:

   $ git grep -E '0x%[0-9]*([lL]*|" ?PRI)[dDuU]' block/

Inspired-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
  block/parallels-ext.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/parallels-ext.c b/block/parallels-ext.c
index cb22a427d7..5122f67ac2 100644
--- a/block/parallels-ext.c
+++ b/block/parallels-ext.c
@@ -261,7 +261,7 @@ static int 
parallels_parse_format_extension(BlockDriverState *bs,
  break;
  
  default:

-error_setg(errp, "Unknown feature: 0x%" PRIu64, fh.magic);
+error_setg(errp, "Unknown feature: 0x%" PRIx64, fh.magic);
  goto fail;
  }
  

Reviewed-by: Denis V. Lunev 



Re: [PATCH-for-7.0 2/2] hw: Fix misleading hexadecimal format

2022-03-23 Thread Daniel P . Berrangé
On Wed, Mar 23, 2022 at 12:47:18PM +0100, Philippe Mathieu-Daudé wrote:
> From: Philippe Mathieu-Daudé 
> 
> "0x%u" format is very misleading, replace by "0x%x".
> 
> Found running:
> 
>   $ git grep -E '0x%[0-9]*([lL]*|" ?PRI)[dDuU]' hw/
> 
> Inspired-by: Richard Henderson 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/i386/sgx.c| 2 +-
>  hw/i386/trace-events | 6 +++---
>  hw/misc/trace-events | 4 ++--
>  hw/scsi/trace-events | 4 ++--
>  4 files changed, 8 insertions(+), 8 deletions(-)

Reviewed-by: Daniel P. Berrangé 


With regards,
Daniel
-- 
|: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-https://fstop138.berrange.com :|
|: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|




Re: [PATCH] iotests: update test owner contact information

2022-03-23 Thread Hanna Reitz

On 23.03.22 09:39, Thomas Huth wrote:

On 22/03/2022 18.42, John Snow wrote:

Quite a few of these tests have stale contact information. This patch
updates the stale ones that I happen to be aware of at the moment.

Signed-off-by: John Snow 
---
  tests/qemu-iotests/025 | 2 +-
  tests/qemu-iotests/027 | 2 +-
  tests/qemu-iotests/028 | 2 +-
  tests/qemu-iotests/036 | 2 +-
  tests/qemu-iotests/039 | 2 +-
  tests/qemu-iotests/059 | 2 +-
  tests/qemu-iotests/060 | 2 +-
  tests/qemu-iotests/061 | 2 +-
  tests/qemu-iotests/062 | 2 +-
  tests/qemu-iotests/064 | 2 +-
  tests/qemu-iotests/066 | 2 +-
  tests/qemu-iotests/068 | 2 +-
  tests/qemu-iotests/069 | 2 +-
  tests/qemu-iotests/070 | 2 +-
  tests/qemu-iotests/071 | 2 +-
  tests/qemu-iotests/072 | 2 +-
  tests/qemu-iotests/074 | 2 +-
  tests/qemu-iotests/084 | 2 +-
  tests/qemu-iotests/085 | 2 +-
  tests/qemu-iotests/089 | 2 +-
  tests/qemu-iotests/090 | 2 +-
  tests/qemu-iotests/091 | 2 +-
  tests/qemu-iotests/094 | 2 +-
  tests/qemu-iotests/095 | 2 +-
  tests/qemu-iotests/097 | 2 +-
  tests/qemu-iotests/098 | 2 +-
  tests/qemu-iotests/099 | 2 +-
  tests/qemu-iotests/102 | 2 +-
  tests/qemu-iotests/103 | 2 +-
  tests/qemu-iotests/105 | 2 +-
  tests/qemu-iotests/106 | 2 +-
  tests/qemu-iotests/107 | 2 +-
  tests/qemu-iotests/108 | 2 +-
  tests/qemu-iotests/110 | 2 +-
  tests/qemu-iotests/111 | 2 +-
  tests/qemu-iotests/112 | 2 +-
  tests/qemu-iotests/113 | 2 +-
  tests/qemu-iotests/115 | 2 +-
  tests/qemu-iotests/117 | 2 +-
  tests/qemu-iotests/119 | 2 +-
  tests/qemu-iotests/120 | 2 +-
  tests/qemu-iotests/121 | 2 +-
  tests/qemu-iotests/123 | 2 +-
  tests/qemu-iotests/125 | 2 +-
  tests/qemu-iotests/126 | 2 +-
  tests/qemu-iotests/127 | 2 +-
  tests/qemu-iotests/135 | 2 +-
  tests/qemu-iotests/138 | 2 +-
  tests/qemu-iotests/140 | 2 +-
  tests/qemu-iotests/141 | 2 +-
  tests/qemu-iotests/143 | 2 +-
  tests/qemu-iotests/144 | 2 +-
  tests/qemu-iotests/146 | 2 +-
  tests/qemu-iotests/150 | 2 +-
  tests/qemu-iotests/153 | 2 +-
  tests/qemu-iotests/156 | 2 +-
  tests/qemu-iotests/162 | 2 +-
  tests/qemu-iotests/173 | 2 +-
  tests/qemu-iotests/176 | 2 +-
  tests/qemu-iotests/182 | 2 +-
  tests/qemu-iotests/192 | 2 +-
  tests/qemu-iotests/200 | 2 +-
  tests/qemu-iotests/216 | 2 +-
  tests/qemu-iotests/218 | 2 +-
  tests/qemu-iotests/224 | 2 +-
  tests/qemu-iotests/225 | 2 +-
  tests/qemu-iotests/228 | 2 +-
  tests/qemu-iotests/229 | 2 +-
  tests/qemu-iotests/231 | 2 +-
  tests/qemu-iotests/250 | 2 +-
  tests/qemu-iotests/251 | 2 +-
  tests/qemu-iotests/252 | 2 +-
  tests/qemu-iotests/258 | 2 +-
  tests/qemu-iotests/259 | 2 +-
  tests/qemu-iotests/261 | 2 +-
  tests/qemu-iotests/310 | 2 +-
  76 files changed, 76 insertions(+), 76 deletions(-)

diff --git a/tests/qemu-iotests/025 b/tests/qemu-iotests/025
index 80686a30d5..5771ea9200 100755
--- a/tests/qemu-iotests/025
+++ b/tests/qemu-iotests/025
@@ -20,7 +20,7 @@
  #
    # creator
-owner=stefa...@linux.vnet.ibm.com
+owner=stefa...@redhat.com


Wow, these were really old ones ... I wonder whether these "owner" 
lines really still make that much sense if they are neglected that 
much, or whether the information should maybe rather be captured in 
MAINTAINERS instead?


Or maybe we should just drop the whole concept of ownership in the 
iotests altogether, I can’t remember it ever coming up.  If a test 
fails, it never mattered to me who the “owner” is, I just did my best to 
fix it myself, usually.  If I couldn’t, I used git-blame to figure out 
who to ask, because tests tend to be written by multiple people anyway.


Anyway, that’d be more difficult, I suppose, because dropping ownership 
information would (I guess) require consent from everyone, so this is 
simpler for now.


Thanks for the patch, I’ve applied it to my block branch:

https://gitlab.com/hreitz/qemu/-/commits/block

Hanna




Re: [PATCH v3 1/3] iotests.py: Add supports_qcow2_zstd_compression()

2022-03-23 Thread Vladimir Sementsov-Ogievskiy

23.03.2022 13:55, Hanna Reitz wrote:

Suggested-by: Vladimir Sementsov-Ogievskiy 
Signed-off-by: Hanna Reitz 
---
  tests/qemu-iotests/iotests.py | 20 
  1 file changed, 20 insertions(+)

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index fcec3e51e5..fe10a6cf05 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -1471,6 +1471,26 @@ def verify_working_luks():
  if not working:
  notrun(reason)
  
+def supports_qcow2_zstd_compression() -> bool:

+img_file = f'{test_dir}/qcow2-zstd-test.qcow2'
+res = qemu_img('create', '-f', 'qcow2', '-o', 'compression_type=zstd',
+   img_file, '0',
+   check=False)


check=False may be squashed into previous line


+try:
+os.remove(img_file)
+except OSError:
+pass
+
+if res.returncode == 1 and \
+"'compression-type' does not accept value 'zstd'" in res.stdout:
+return False
+else:
+return True


May be:

return not(res.returncode == 1 and
   "'compression-type' does not accept value 'zstd'" in res.stdout)


+
+def verify_qcow2_zstd_compression():
+if not supports_qcow2_zstd_compression():
+notrun('zstd compression not supported')
+
  def qemu_pipe(*args: str) -> str:
  """
  Run qemu with an option to print something and exit (e.g. a help option).


anyway:
Reviewed-by: Vladimir Sementsov-Ogievskiy 

--
Best regards,
Vladimir



[PATCH-for-7.0 0/2] misc: Fix misleading hexadecimal format

2022-03-23 Thread Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé 

Fix 0x%d misleading format reported here:
https://lore.kernel.org/qemu-devel/dab530d9-53d2-3d7d-c9ac-44906ba9b...@linaro.org/

Philippe Mathieu-Daudé (2):
  block: Fix misleading hexadecimal format
  hw: Fix misleading hexadecimal format

 block/parallels-ext.c | 2 +-
 hw/i386/sgx.c | 2 +-
 hw/i386/trace-events  | 6 +++---
 hw/misc/trace-events  | 4 ++--
 hw/scsi/trace-events  | 4 ++--
 5 files changed, 9 insertions(+), 9 deletions(-)

-- 
2.35.1




Re: [PATCH-for-7.0 1/2] block: Fix misleading hexadecimal format

2022-03-23 Thread Daniel P . Berrangé
On Wed, Mar 23, 2022 at 12:47:17PM +0100, Philippe Mathieu-Daudé wrote:
> From: Philippe Mathieu-Daudé 
> 
> "0x%u" format is very misleading, replace by "0x%x".
> 
> Found running:
> 
>   $ git grep -E '0x%[0-9]*([lL]*|" ?PRI)[dDuU]' block/
> 
> Inspired-by: Richard Henderson 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  block/parallels-ext.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Daniel P. Berrangé 


With regards,
Daniel
-- 
|: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-https://fstop138.berrange.com :|
|: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|




Re: [PATCH-for-7.0 1/2] block: Fix misleading hexadecimal format

2022-03-23 Thread Hanna Reitz

On 23.03.22 12:47, Philippe Mathieu-Daudé wrote:

From: Philippe Mathieu-Daudé 

"0x%u" format is very misleading, replace by "0x%x".

Found running:

   $ git grep -E '0x%[0-9]*([lL]*|" ?PRI)[dDuU]' block/

Inspired-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
  block/parallels-ext.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)


Reviewed-by: Hanna Reitz 




[PATCH-for-7.0 1/2] block: Fix misleading hexadecimal format

2022-03-23 Thread Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé 

"0x%u" format is very misleading, replace by "0x%x".

Found running:

  $ git grep -E '0x%[0-9]*([lL]*|" ?PRI)[dDuU]' block/

Inspired-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
 block/parallels-ext.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/parallels-ext.c b/block/parallels-ext.c
index cb22a427d7..5122f67ac2 100644
--- a/block/parallels-ext.c
+++ b/block/parallels-ext.c
@@ -261,7 +261,7 @@ static int 
parallels_parse_format_extension(BlockDriverState *bs,
 break;
 
 default:
-error_setg(errp, "Unknown feature: 0x%" PRIu64, fh.magic);
+error_setg(errp, "Unknown feature: 0x%" PRIx64, fh.magic);
 goto fail;
 }
 
-- 
2.35.1




Re: [PATCH v3 2/3] iotests/065: Check for zstd support

2022-03-23 Thread Vladimir Sementsov-Ogievskiy

23.03.2022 13:55, Hanna Reitz wrote:

Some test cases run in iotest 065 want to run with zstd compression just
for added coverage.  Run them with zlib if there is no zstd support
compiled in.

Reported-by: Thomas Huth
Fixes: 12a936171d71f839dc907ff ("iotest 065: explicit compression type")
Signed-off-by: Hanna Reitz


Reviewed-by: Vladimir Sementsov-Ogievskiy 

--
Best regards,
Vladimir



[PATCH-for-7.0 2/2] hw: Fix misleading hexadecimal format

2022-03-23 Thread Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé 

"0x%u" format is very misleading, replace by "0x%x".

Found running:

  $ git grep -E '0x%[0-9]*([lL]*|" ?PRI)[dDuU]' hw/

Inspired-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/i386/sgx.c| 2 +-
 hw/i386/trace-events | 6 +++---
 hw/misc/trace-events | 4 ++--
 hw/scsi/trace-events | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/i386/sgx.c b/hw/i386/sgx.c
index a2b318dd93..a44d66ba2a 100644
--- a/hw/i386/sgx.c
+++ b/hw/i386/sgx.c
@@ -315,7 +315,7 @@ void pc_machine_init_sgx_epc(PCMachineState *pcms)
 }
 
 if ((sgx_epc->base + sgx_epc->size) < sgx_epc->base) {
-error_report("Size of all 'sgx-epc' =0x%"PRIu64" causes EPC to wrap",
+error_report("Size of all 'sgx-epc' =0x%"PRIx64" causes EPC to wrap",
  sgx_epc->size);
 exit(EXIT_FAILURE);
 }
diff --git a/hw/i386/trace-events b/hw/i386/trace-events
index 5bf7e52bf5..e49814dd64 100644
--- a/hw/i386/trace-events
+++ b/hw/i386/trace-events
@@ -33,15 +33,15 @@ vtd_fault_disabled(void) "Fault processing disabled for 
context entry"
 vtd_replay_ce_valid(const char *mode, uint8_t bus, uint8_t dev, uint8_t fn, 
uint16_t domain, uint64_t hi, uint64_t lo) "%s: replay valid context device 
%02"PRIx8":%02"PRIx8".%02"PRIx8" domain 0x%"PRIx16" hi 0x%"PRIx64" lo 0x%"PRIx64
 vtd_replay_ce_invalid(uint8_t bus, uint8_t dev, uint8_t fn) "replay invalid 
context device %02"PRIx8":%02"PRIx8".%02"PRIx8
 vtd_page_walk_level(uint64_t addr, uint32_t level, uint64_t start, uint64_t 
end) "walk (base=0x%"PRIx64", level=%"PRIu32") iova range 0x%"PRIx64" - 
0x%"PRIx64
-vtd_page_walk_one(uint16_t domain, uint64_t iova, uint64_t gpa, uint64_t mask, 
int perm) "domain 0x%"PRIu16" iova 0x%"PRIx64" -> gpa 0x%"PRIx64" mask 
0x%"PRIx64" perm %d"
+vtd_page_walk_one(uint16_t domain, uint64_t iova, uint64_t gpa, uint64_t mask, 
int perm) "domain 0x%"PRIx16" iova 0x%"PRIx64" -> gpa 0x%"PRIx64" mask 
0x%"PRIx64" perm %d"
 vtd_page_walk_one_skip_map(uint64_t iova, uint64_t mask, uint64_t translated) 
"iova 0x%"PRIx64" mask 0x%"PRIx64" translated 0x%"PRIx64
 vtd_page_walk_one_skip_unmap(uint64_t iova, uint64_t mask) "iova 0x%"PRIx64" 
mask 0x%"PRIx64
 vtd_page_walk_skip_read(uint64_t iova, uint64_t next) "Page walk skip iova 
0x%"PRIx64" - 0x%"PRIx64" due to unable to read"
 vtd_page_walk_skip_reserve(uint64_t iova, uint64_t next) "Page walk skip iova 
0x%"PRIx64" - 0x%"PRIx64" due to rsrv set"
 vtd_switch_address_space(uint8_t bus, uint8_t slot, uint8_t fn, bool on) 
"Device %02x:%02x.%x switching address space (iommu enabled=%d)"
 vtd_as_unmap_whole(uint8_t bus, uint8_t slot, uint8_t fn, uint64_t iova, 
uint64_t size) "Device %02x:%02x.%x start 0x%"PRIx64" size 0x%"PRIx64
-vtd_translate_pt(uint16_t sid, uint64_t addr) "source id 0x%"PRIu16", iova 
0x%"PRIx64
-vtd_pt_enable_fast_path(uint16_t sid, bool success) "sid 0x%"PRIu16" %d"
+vtd_translate_pt(uint16_t sid, uint64_t addr) "source id 0x%"PRIx16", iova 
0x%"PRIx64
+vtd_pt_enable_fast_path(uint16_t sid, bool success) "sid 0x%"PRIx16" %d"
 vtd_irq_generate(uint64_t addr, uint64_t data) "addr 0x%"PRIx64" data 
0x%"PRIx64
 vtd_reg_read(uint64_t addr, uint64_t size) "addr 0x%"PRIx64" size 0x%"PRIx64
 vtd_reg_write(uint64_t addr, uint64_t size, uint64_t val) "addr 0x%"PRIx64" 
size 0x%"PRIx64" value 0x%"PRIx64
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
index bd52cfc110..4e0c7973a4 100644
--- a/hw/misc/trace-events
+++ b/hw/misc/trace-events
@@ -1,7 +1,7 @@
 # See docs/devel/tracing.rst for syntax documentation.
 
 # allwinner-cpucfg.c
-allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, 
reset_addr 0x%" PRIu32
+allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, 
reset_addr 0x%" PRIx32
 allwinner_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "offset 
0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
 allwinner_cpucfg_write(uint64_t offset, uint64_t data, unsigned size) "offset 
0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
 
@@ -93,7 +93,7 @@ imx7_gpr_write(uint64_t offset, uint64_t value) "addr 0x%08" 
PRIx64 "value 0x%08
 
 # mos6522.c
 mos6522_set_counter(int index, unsigned int val) "T%d.counter=%d"
-mos6522_get_next_irq_time(uint16_t latch, int64_t d, int64_t delta) "latch=%d 
counter=0x%"PRId64 " delta_next=0x%"PRId64
+mos6522_get_next_irq_time(uint16_t latch, int64_t d, int64_t delta) "latch=%d 
counter=0x%"PRIx64 " delta_next=0x%"PRIx64
 mos6522_set_sr_int(void) "set sr_int"
 mos6522_write(uint64_t addr, const char *name, uint64_t val) "reg=0x%"PRIx64 " 
[%s] val=0x%"PRIx64
 mos6522_read(uint64_t addr, const char *name, unsigned val) "reg=0x%"PRIx64 " 
[%s] val=0x%x"
diff --git a/hw/scsi/trace-events b/hw/scsi/trace-events
index ae8551f279..20fb0dc162 100644
--- a/hw/scsi/trace-events
+++ b/hw/scsi/trace-events
@@ -249,7 +249,7 @@ lsi_bad_phase_interrupt(void) "Phase mismatch interrupt"
 lsi_bad_selection(uint32_t id) "Selected absent 

[RFC 8/8] virtio-blk: use BDRV_REQ_REGISTERED_BUF optimization hint

2022-03-23 Thread Stefan Hajnoczi
Register guest RAM using BlockRAMRegistrar and set the
BDRV_REQ_REGISTERED_BUF flag so block drivers can optimize memory
accesses in I/O requests.

This is for vdpa-blk, vhost-user-blk, and other I/O interfaces that rely
on DMA mapping/unmapping.

Signed-off-by: Stefan Hajnoczi 
---
 include/hw/virtio/virtio-blk.h |  2 ++
 hw/block/virtio-blk.c  | 13 +
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h
index d311c57cca..7f589b4146 100644
--- a/include/hw/virtio/virtio-blk.h
+++ b/include/hw/virtio/virtio-blk.h
@@ -19,6 +19,7 @@
 #include "hw/block/block.h"
 #include "sysemu/iothread.h"
 #include "sysemu/block-backend.h"
+#include "sysemu/block-ram-registrar.h"
 #include "qom/object.h"
 
 #define TYPE_VIRTIO_BLK "virtio-blk-device"
@@ -64,6 +65,7 @@ struct VirtIOBlock {
 struct VirtIOBlockDataPlane *dataplane;
 uint64_t host_features;
 size_t config_size;
+BlockRAMRegistrar blk_ram_registrar;
 };
 
 typedef struct VirtIOBlockReq {
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 540c38f829..a18cf05f14 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -21,6 +21,7 @@
 #include "hw/block/block.h"
 #include "hw/qdev-properties.h"
 #include "sysemu/blockdev.h"
+#include "sysemu/block-ram-registrar.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/runstate.h"
 #include "hw/virtio/virtio-blk.h"
@@ -421,11 +422,13 @@ static inline void submit_requests(BlockBackend *blk, 
MultiReqBuffer *mrb,
 }
 
 if (is_write) {
-blk_aio_pwritev(blk, sector_num << BDRV_SECTOR_BITS, qiov, 0,
-virtio_blk_rw_complete, mrb->reqs[start]);
+blk_aio_pwritev(blk, sector_num << BDRV_SECTOR_BITS, qiov,
+BDRV_REQ_REGISTERED_BUF, virtio_blk_rw_complete,
+mrb->reqs[start]);
 } else {
-blk_aio_preadv(blk, sector_num << BDRV_SECTOR_BITS, qiov, 0,
-   virtio_blk_rw_complete, mrb->reqs[start]);
+blk_aio_preadv(blk, sector_num << BDRV_SECTOR_BITS, qiov,
+   BDRV_REQ_REGISTERED_BUF, virtio_blk_rw_complete,
+   mrb->reqs[start]);
 }
 }
 
@@ -1228,6 +1231,7 @@ static void virtio_blk_device_realize(DeviceState *dev, 
Error **errp)
 }
 
 s->change = qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s);
+blk_ram_registrar_init(>blk_ram_registrar, s->blk);
 blk_set_dev_ops(s->blk, _block_ops, s);
 blk_set_guest_block_size(s->blk, s->conf.conf.logical_block_size);
 
@@ -1255,6 +1259,7 @@ static void virtio_blk_device_unrealize(DeviceState *dev)
 }
 qemu_coroutine_decrease_pool_batch_size(conf->num_queues * conf->queue_size
 / 2);
+blk_ram_registrar_destroy(>blk_ram_registrar);
 qemu_del_vm_change_state_handler(s->change);
 blockdev_mark_auto_del(s->blk);
 virtio_cleanup(vdev);
-- 
2.35.1




Re: [PATCH v3 0/4] Improve integration of iotests in the meson test harness

2022-03-23 Thread Hanna Reitz

On 21.03.22 18:26, Thomas Huth wrote:

On 21/03/2022 17.14, Hanna Reitz wrote:

On 23.02.22 10:38, Thomas Huth wrote:

Though "make check-block" is currently already run via the meson test
runner, it still looks like an oddball in the output of "make 
check". It
would be nicer if the iotests would show up like the other tests 
suites.


My original plan was to add each iotests individually from meson.build,
but I did not get that done reliably yet [*], so here's now a cut-down
version to improve the situation at least a little bit: The first three
patches are preparation for the clean-up (long-term goal is to get rid
of check-block.sh, though we're not quite there yet), and the final
patch adds the iotests not as separate test target in the meson test
harness anymore. This way, we can now finally get the output of failed
tests on the console again (unless you're running meson test in verbose
mode, where meson only puts this to the log file - for incomprehensible
reasons), so this should hopefully help to diagnose problems with the
iotests in most cases more easily.

[*] See v2 here:
https://lists.gnu.org/archive/html/qemu-devel/2022-02/msg01942.html

Thomas Huth (4):
   tests/qemu-iotests: Rework the checks and spots using GNU sed
   tests/qemu-iotests/meson.build: Improve the indentation
   tests/qemu-iotests: Move the bash and sanitizer checks to 
meson.build
   tests: Do not treat the iotests as separate meson test target 
anymore


What’s the status of this series?  I wonder why you split it apart, 
mainly.


I've mainly split the fourth patch apart since Paolo mentioned that 
the commit message should mention the meson bug (IIRC), and since QEMU 
was entering soft-freeze, thus I doubt that a patch like "Move the 
bash and sanitizer checks to meson.build" is still acceptable at this 
point in time. The meson.build clean-up is rather something for 7.1 
instead.


Patch 1 was already merged, and I took patch 4 today.  So what about 
patches 2 and 3?  They look sensible to me, but is this series still 
relevant and fresh, considering you sent new versions of patches 1 
and 4?


If you think they are still ok for 7.0, you can certainly also pick 
the 2nd and 3rd patch ... otherwise I'll respin them later for 7.1.


That sounds like you don’t really need to respin, so I’ve taken them to 
my block-next branch for 7.1:


https://gitlab.com/hreitz/qemu/-/commits/block-next

Thanks!

Hanna




[RFC 7/8] blkio: implement BDRV_REQ_REGISTERED_BUF optimization

2022-03-23 Thread Stefan Hajnoczi
Avoid bounce buffers when QEMUIOVector elements are within previously
registered bdrv_register_buf() buffers.

The idea is that emulated storage controllers will register guest RAM
using bdrv_register_buf() and set the BDRV_REQ_REGISTERED_BUF on I/O
requests. Therefore no blkio_add_mem_region() calls are necessary in the
performance-critical I/O code path.

This optimization doesn't apply if the I/O buffer is internally
allocated by QEMU (e.g. qcow2 metadata). There we still take the slow
path because BDRV_REQ_REGISTERED_BUF is not set.

Signed-off-by: Stefan Hajnoczi 
---
 block/blkio.c | 108 --
 1 file changed, 104 insertions(+), 4 deletions(-)

diff --git a/block/blkio.c b/block/blkio.c
index dd2308b967..78f4ca5f49 100644
--- a/block/blkio.c
+++ b/block/blkio.c
@@ -1,7 +1,9 @@
 #include "qemu/osdep.h"
 #include 
 #include "block/block_int.h"
+#include "exec/memory.h"
 #include "qapi/error.h"
+#include "qemu/error-report.h"
 #include "qapi/qmp/qdict.h"
 #include "qemu/module.h"
 
@@ -26,6 +28,9 @@ typedef struct {
 /* Can we skip adding/deleting blkio_mem_regions? */
 bool needs_mem_regions;
 
+/* Are file descriptors necessary for blkio_mem_regions? */
+bool needs_mem_region_fd;
+
 /*
  * blkio_completion_fd_poll() stashes the next completion for
  * blkio_completion_fd_poll_ready().
@@ -170,6 +175,8 @@ static BlockAIOCB *blkio_aio_preadv(BlockDriverState *bs, 
int64_t offset,
 BlockCompletionFunc *cb, void *opaque)
 {
 BDRVBlkioState *s = bs->opaque;
+bool needs_mem_regions =
+s->needs_mem_regions && !(flags & BDRV_REQ_REGISTERED_BUF);
 struct iovec *iov = qiov->iov;
 int iovcnt = qiov->niov;
 BlkioAIOCB *acb;
@@ -179,7 +186,7 @@ static BlockAIOCB *blkio_aio_preadv(BlockDriverState *bs, 
int64_t offset,
 
 acb = blkio_aiocb_get(bs, cb, opaque);
 
-if (s->needs_mem_regions) {
+if (needs_mem_regions) {
 if (blkio_aiocb_init_mem_region_locked(acb, bytes) < 0) {
 qemu_aio_unref(>common);
 return NULL;
@@ -194,7 +201,7 @@ static BlockAIOCB *blkio_aio_preadv(BlockDriverState *bs, 
int64_t offset,
 
 ret = blkioq_readv(s->blkioq, offset, iov, iovcnt, acb, 0);
 if (ret < 0) {
-if (s->needs_mem_regions) {
+if (needs_mem_regions) {
 blkio_free_mem_region(s->blkio, >mem_region);
 qemu_iovec_destroy(>qiov);
 }
@@ -215,6 +222,8 @@ static BlockAIOCB *blkio_aio_pwritev(BlockDriverState *bs, 
int64_t offset,
 {
 uint32_t blkio_flags = (flags & BDRV_REQ_FUA) ? BLKIO_REQ_FUA : 0;
 BDRVBlkioState *s = bs->opaque;
+bool needs_mem_regions =
+s->needs_mem_regions && !(flags & BDRV_REQ_REGISTERED_BUF);
 struct iovec *iov = qiov->iov;
 int iovcnt = qiov->niov;
 BlkioAIOCB *acb;
@@ -224,7 +233,7 @@ static BlockAIOCB *blkio_aio_pwritev(BlockDriverState *bs, 
int64_t offset,
 
 acb = blkio_aiocb_get(bs, cb, opaque);
 
-if (s->needs_mem_regions) {
+if (needs_mem_regions) {
 if (blkio_aiocb_init_mem_region_locked(acb, bytes) < 0) {
 qemu_aio_unref(>common);
 return NULL;
@@ -238,7 +247,7 @@ static BlockAIOCB *blkio_aio_pwritev(BlockDriverState *bs, 
int64_t offset,
 
 ret = blkioq_writev(s->blkioq, offset, iov, iovcnt, acb, blkio_flags);
 if (ret < 0) {
-if (s->needs_mem_regions) {
+if (needs_mem_regions) {
 blkio_free_mem_region(s->blkio, >mem_region);
 }
 qemu_aio_unref(>common);
@@ -286,6 +295,83 @@ static void blkio_io_unplug(BlockDriverState *bs)
 }
 }
 
+static void blkio_register_buf(BlockDriverState *bs, void *host, size_t size)
+{
+BDRVBlkioState *s = bs->opaque;
+char *errmsg;
+int ret;
+struct blkio_mem_region region = (struct blkio_mem_region){
+.addr = host,
+.len = size,
+.fd = -1,
+};
+
+if (((uintptr_t)host | size) % s->mem_region_alignment) {
+error_report_once("%s: skipping unaligned buf %p with size %zu",
+  __func__, host, size);
+return; /* skip unaligned */
+}
+
+/* Attempt to find the fd for a MemoryRegion */
+if (s->needs_mem_region_fd) {
+int fd = -1;
+ram_addr_t offset;
+MemoryRegion *mr;
+
+/*
+ * bdrv_register_buf() is called with the BQL held so mr lives at least
+ * until this function returns.
+ */
+mr = memory_region_from_host(host, );
+if (mr) {
+fd = memory_region_get_fd(mr);
+}
+if (fd == -1) {
+error_report_once("%s: skipping fd-less buf %p with size %zu",
+  __func__, host, size);
+return; /* skip if there is no fd */
+}
+
+region.fd = fd;
+region.fd_offset = offset;
+}
+
+WITH_QEMU_LOCK_GUARD(>lock) {
+ret = blkio_add_mem_region(s->blkio, , );
+}
+
+if (ret < 

[RFC 4/8] block: add BDRV_REQ_REGISTERED_BUF request flag

2022-03-23 Thread Stefan Hajnoczi
Block drivers may optimize I/O requests accessing buffers previously
registered with bdrv_register_buf(). Checking whether all elements of a
request's QEMUIOVector are within previously registered buffers is
expensive, so we need a hint from the user to avoid costly checks.

Add a BDRV_REQ_REGISTERED_BUF request flag to indicate that all
QEMUIOVector elements in an I/O request are known to be within
previously registered buffers.

bdrv_aligned_preadv() is strict in validating supported read flags and
its assertions fail when it sees BDRV_REQ_REGISTERED_BUF. There is no
harm in passing BDRV_REQ_REGISTERED_BUF to block drivers that do not
support it, so update the assertions to ignore BDRV_REQ_REGISTERED_BUF.

Care must be taken to clear the flag when the block layer or filter
drivers replace QEMUIOVector elements with bounce buffers since these
have not been registered with bdrv_register_buf(). A lot of the changes
in this commit deal with clearing the flag in those cases.

Ensuring that the flag is cleared properly is somewhat invasive to
implement across the block layer and it's hard to spot when future code
changes accidentally break it. Another option might be to add a flag to
QEMUIOVector itself and clear it in qemu_iovec_*() functions that modify
elements. That is more robust but somewhat of a layering violation, so I
haven't attempted that.

Signed-off-by: Stefan Hajnoczi 
---
 include/block/block-common.h |  9 +
 block/blkverify.c|  4 ++--
 block/crypto.c   |  2 ++
 block/io.c   | 30 +++---
 block/mirror.c   |  2 ++
 block/raw-format.c   |  2 ++
 6 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/include/block/block-common.h b/include/block/block-common.h
index fdb7306e78..061606e867 100644
--- a/include/block/block-common.h
+++ b/include/block/block-common.h
@@ -80,6 +80,15 @@ typedef enum {
  */
 BDRV_REQ_MAY_UNMAP  = 0x4,
 
+/*
+ * An optimization hint when all QEMUIOVector elements are within
+ * previously registered bdrv_register_buf() memory ranges.
+ *
+ * Code that replaces the user's QEMUIOVector elements with bounce buffers
+ * must take care to clear this flag.
+ */
+BDRV_REQ_REGISTERED_BUF = 0x8,
+
 BDRV_REQ_FUA= 0x10,
 BDRV_REQ_WRITE_COMPRESSED   = 0x20,
 
diff --git a/block/blkverify.c b/block/blkverify.c
index e4a37af3b2..d624f4fd05 100644
--- a/block/blkverify.c
+++ b/block/blkverify.c
@@ -235,8 +235,8 @@ blkverify_co_preadv(BlockDriverState *bs, int64_t offset, 
int64_t bytes,
 qemu_iovec_init(_qiov, qiov->niov);
 qemu_iovec_clone(_qiov, qiov, buf);
 
-ret = blkverify_co_prwv(bs, , offset, bytes, qiov, _qiov, flags,
-false);
+ret = blkverify_co_prwv(bs, , offset, bytes, qiov, _qiov,
+flags & ~BDRV_REQ_REGISTERED_BUF, false);
 
 cmp_offset = qemu_iovec_compare(qiov, _qiov);
 if (cmp_offset != -1) {
diff --git a/block/crypto.c b/block/crypto.c
index 1ba82984ef..c900355adb 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -473,6 +473,8 @@ block_crypto_co_pwritev(BlockDriverState *bs, int64_t 
offset, int64_t bytes,
 uint64_t sector_size = qcrypto_block_get_sector_size(crypto->block);
 uint64_t payload_offset = qcrypto_block_get_payload_offset(crypto->block);
 
+flags &= ~BDRV_REQ_REGISTERED_BUF;
+
 assert(!(flags & ~BDRV_REQ_FUA));
 assert(payload_offset < INT64_MAX);
 assert(QEMU_IS_ALIGNED(offset, sector_size));
diff --git a/block/io.c b/block/io.c
index a8a7920e29..139e36c2e1 100644
--- a/block/io.c
+++ b/block/io.c
@@ -1556,11 +1556,14 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild 
*child,
 max_transfer = QEMU_ALIGN_DOWN(MIN_NON_ZERO(bs->bl.max_transfer, INT_MAX),
align);
 
-/* TODO: We would need a per-BDS .supported_read_flags and
+/*
+ * TODO: We would need a per-BDS .supported_read_flags and
  * potential fallback support, if we ever implement any read flags
  * to pass through to drivers.  For now, there aren't any
- * passthrough flags.  */
-assert(!(flags & ~(BDRV_REQ_COPY_ON_READ | BDRV_REQ_PREFETCH)));
+ * passthrough flags except the BDRV_REQ_REGISTERED_BUF optimization hint.
+ */
+assert(!(flags & ~(BDRV_REQ_COPY_ON_READ | BDRV_REQ_PREFETCH |
+   BDRV_REQ_REGISTERED_BUF)));
 
 /* Handle Copy on Read and associated serialisation */
 if (flags & BDRV_REQ_COPY_ON_READ) {
@@ -1601,7 +1604,7 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild 
*child,
 goto out;
 }
 
-assert(!(flags & ~bs->supported_read_flags));
+assert(!(flags & ~(bs->supported_read_flags | BDRV_REQ_REGISTERED_BUF)));
 
 max_bytes = ROUND_UP(MAX(0, total_bytes - offset), align);
 if (bytes <= max_bytes && bytes <= max_transfer) {
@@ -1790,7 +1793,8 @@ static void 

[RFC 5/8] block: add BlockRAMRegistrar

2022-03-23 Thread Stefan Hajnoczi
Emulated devices and other BlockBackend users wishing to take advantage
of blk_register_buf() all have the same repetitive job: register
RAMBlocks with the BlockBackend using RAMBlockNotifier.

Add a BlockRAMRegistrar API to do this. A later commit will use this
from hw/block/virtio-blk.c.

Signed-off-by: Stefan Hajnoczi 
---
 MAINTAINERS  |  1 +
 include/sysemu/block-ram-registrar.h | 30 +
 block/block-ram-registrar.c  | 39 
 block/meson.build|  1 +
 4 files changed, 71 insertions(+)
 create mode 100644 include/sysemu/block-ram-registrar.h
 create mode 100644 block/block-ram-registrar.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 0fb08dd4f7..da6ec4d79b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2462,6 +2462,7 @@ F: block*
 F: block/
 F: hw/block/
 F: include/block/
+F: include/sysemu/block-*.h
 F: qemu-img*
 F: docs/tools/qemu-img.rst
 F: qemu-io*
diff --git a/include/sysemu/block-ram-registrar.h 
b/include/sysemu/block-ram-registrar.h
new file mode 100644
index 00..09d63f64b2
--- /dev/null
+++ b/include/sysemu/block-ram-registrar.h
@@ -0,0 +1,30 @@
+/*
+ * BlockBackend RAM Registrar
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef BLOCK_RAM_REGISTRAR_H
+#define BLOCK_RAM_REGISTRAR_H
+
+#include "exec/ramlist.h"
+
+/**
+ * struct BlockRAMRegistrar:
+ *
+ * Keeps RAMBlock memory registered with a BlockBackend using
+ * blk_register_buf() including hotplugged memory.
+ *
+ * Emulated devices or other BlockBackend users initialize a BlockRAMRegistrar
+ * with blk_ram_registrar_init() before submitting I/O requests with the
+ * BLK_REQ_REGISTERED_BUF flag set.
+ */
+typedef struct {
+BlockBackend *blk;
+RAMBlockNotifier notifier;
+} BlockRAMRegistrar;
+
+void blk_ram_registrar_init(BlockRAMRegistrar *r, BlockBackend *blk);
+void blk_ram_registrar_destroy(BlockRAMRegistrar *r);
+
+#endif /* BLOCK_RAM_REGISTRAR_H */
diff --git a/block/block-ram-registrar.c b/block/block-ram-registrar.c
new file mode 100644
index 00..32a14b69ae
--- /dev/null
+++ b/block/block-ram-registrar.c
@@ -0,0 +1,39 @@
+/*
+ * BlockBackend RAM Registrar
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "sysemu/block-backend.h"
+#include "sysemu/block-ram-registrar.h"
+
+static void ram_block_added(RAMBlockNotifier *n, void *host, size_t size,
+size_t max_size)
+{
+BlockRAMRegistrar *r = container_of(n, BlockRAMRegistrar, notifier);
+blk_register_buf(r->blk, host, max_size);
+}
+
+static void ram_block_removed(RAMBlockNotifier *n, void *host, size_t size,
+  size_t max_size)
+{
+BlockRAMRegistrar *r = container_of(n, BlockRAMRegistrar, notifier);
+blk_unregister_buf(r->blk, host, max_size);
+}
+
+void blk_ram_registrar_init(BlockRAMRegistrar *r, BlockBackend *blk)
+{
+r->blk = blk;
+r->notifier = (RAMBlockNotifier){
+.ram_block_added = ram_block_added,
+.ram_block_removed = ram_block_removed,
+};
+
+ram_block_notifier_add(>notifier);
+}
+
+void blk_ram_registrar_destroy(BlockRAMRegistrar *r)
+{
+ram_block_notifier_remove(>notifier);
+}
diff --git a/block/meson.build b/block/meson.build
index 787667384a..b315593054 100644
--- a/block/meson.build
+++ b/block/meson.build
@@ -46,6 +46,7 @@ block_ss.add(files(
 ), zstd, zlib, gnutls)
 
 softmmu_ss.add(when: 'CONFIG_TCG', if_true: files('blkreplay.c'))
+softmmu_ss.add(files('block-ram-registrar.c'))
 
 if get_option('qcow1').allowed()
   block_ss.add(files('qcow.c'))
-- 
2.35.1




[RFC 6/8] stubs: add memory_region_from_host() and memory_region_get_fd()

2022-03-23 Thread Stefan Hajnoczi
The blkio block driver will need to look up the file descriptor for a
given pointer. This is possible in softmmu builds where the memory API
is available for querying guest RAM.

Add stubs so tools like qemu-img that link the block layer still build
successfully. In this case there is no guest RAM but that is fine.
Bounce buffers and their file descriptors will be allocated with
libblkio's blkio_alloc_mem_region() so we won't rely on QEMU's
memory_region_get_fd() in that case.

Signed-off-by: Stefan Hajnoczi 
---
 stubs/memory.c| 13 +
 stubs/meson.build |  1 +
 2 files changed, 14 insertions(+)
 create mode 100644 stubs/memory.c

diff --git a/stubs/memory.c b/stubs/memory.c
new file mode 100644
index 00..e9ec4e384b
--- /dev/null
+++ b/stubs/memory.c
@@ -0,0 +1,13 @@
+#include "qemu/osdep.h"
+#include "exec/memory.h"
+
+MemoryRegion *memory_region_from_host(void *host, ram_addr_t *offset)
+{
+return NULL;
+}
+
+int memory_region_get_fd(MemoryRegion *mr)
+{
+return -1;
+}
+
diff --git a/stubs/meson.build b/stubs/meson.build
index 6f80fec761..1e274d2db2 100644
--- a/stubs/meson.build
+++ b/stubs/meson.build
@@ -25,6 +25,7 @@ stub_ss.add(files('is-daemonized.c'))
 if libaio.found()
   stub_ss.add(files('linux-aio.c'))
 endif
+stub_ss.add(files('memory.c'))
 stub_ss.add(files('migr-blocker.c'))
 stub_ss.add(files('module-opts.c'))
 stub_ss.add(files('monitor.c'))
-- 
2.35.1




[RFC 3/8] block: pass size to bdrv_unregister_buf()

2022-03-23 Thread Stefan Hajnoczi
The only implementor of bdrv_register_buf() is block/nvme.c, where the
size is not needed when unregistering a buffer. This is because
util/vfio-helpers.c can look up mappings by address.

Future block drivers that implement bdrv_register_buf() may not be able
to do their job given only the buffer address. Add a size argument to
bdrv_unregister_buf().

Also document the assumptions about
bdrv_register_buf()/bdrv_unregister_buf() calls. The same 
values that were given to bdrv_register_buf() must be given to
bdrv_unregister_buf().

gcc 11.2.1 emits a spurious warning that img_bench()'s buf_size local
variable might be uninitialized, so it's necessary to silence the
compiler.

Signed-off-by: Stefan Hajnoczi 
---
 include/block/block-global-state.h  | 5 -
 include/block/block_int-common.h| 2 +-
 include/sysemu/block-backend-global-state.h | 2 +-
 block/block-backend.c   | 4 ++--
 block/io.c  | 6 +++---
 block/nvme.c| 2 +-
 qemu-img.c  | 4 ++--
 7 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/include/block/block-global-state.h 
b/include/block/block-global-state.h
index 25bb69bbef..2295a7c767 100644
--- a/include/block/block-global-state.h
+++ b/include/block/block-global-state.h
@@ -244,9 +244,12 @@ void bdrv_del_child(BlockDriverState *parent, BdrvChild 
*child, Error **errp);
  * Register/unregister a buffer for I/O. For example, VFIO drivers are
  * interested to know the memory areas that would later be used for I/O, so
  * that they can prepare IOMMU mapping etc., to get better performance.
+ *
+ * Buffers must not overlap and they must be unregistered with the same  values that they were registered with.
  */
 void bdrv_register_buf(BlockDriverState *bs, void *host, size_t size);
-void bdrv_unregister_buf(BlockDriverState *bs, void *host);
+void bdrv_unregister_buf(BlockDriverState *bs, void *host, size_t size);
 
 void bdrv_cancel_in_flight(BlockDriverState *bs);
 
diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h
index 8947abab76..b7a7cbd3a5 100644
--- a/include/block/block_int-common.h
+++ b/include/block/block_int-common.h
@@ -435,7 +435,7 @@ struct BlockDriver {
  * DMA mapping for hot buffers.
  */
 void (*bdrv_register_buf)(BlockDriverState *bs, void *host, size_t size);
-void (*bdrv_unregister_buf)(BlockDriverState *bs, void *host);
+void (*bdrv_unregister_buf)(BlockDriverState *bs, void *host, size_t size);
 
 /*
  * This field is modified only under the BQL, and is part of
diff --git a/include/sysemu/block-backend-global-state.h 
b/include/sysemu/block-backend-global-state.h
index 2e93a74679..989ec0364b 100644
--- a/include/sysemu/block-backend-global-state.h
+++ b/include/sysemu/block-backend-global-state.h
@@ -107,7 +107,7 @@ void blk_io_limits_update_group(BlockBackend *blk, const 
char *group);
 void blk_set_force_allow_inactivate(BlockBackend *blk);
 
 void blk_register_buf(BlockBackend *blk, void *host, size_t size);
-void blk_unregister_buf(BlockBackend *blk, void *host);
+void blk_unregister_buf(BlockBackend *blk, void *host, size_t size);
 
 const BdrvChild *blk_root(BlockBackend *blk);
 
diff --git a/block/block-backend.c b/block/block-backend.c
index e0e1aff4b1..8af00d8a36 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -2591,10 +2591,10 @@ void blk_register_buf(BlockBackend *blk, void *host, 
size_t size)
 bdrv_register_buf(blk_bs(blk), host, size);
 }
 
-void blk_unregister_buf(BlockBackend *blk, void *host)
+void blk_unregister_buf(BlockBackend *blk, void *host, size_t size)
 {
 GLOBAL_STATE_CODE();
-bdrv_unregister_buf(blk_bs(blk), host);
+bdrv_unregister_buf(blk_bs(blk), host, size);
 }
 
 int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,
diff --git a/block/io.c b/block/io.c
index 3280144a17..a8a7920e29 100644
--- a/block/io.c
+++ b/block/io.c
@@ -3365,16 +3365,16 @@ void bdrv_register_buf(BlockDriverState *bs, void 
*host, size_t size)
 }
 }
 
-void bdrv_unregister_buf(BlockDriverState *bs, void *host)
+void bdrv_unregister_buf(BlockDriverState *bs, void *host, size_t size)
 {
 BdrvChild *child;
 
 GLOBAL_STATE_CODE();
 if (bs->drv && bs->drv->bdrv_unregister_buf) {
-bs->drv->bdrv_unregister_buf(bs, host);
+bs->drv->bdrv_unregister_buf(bs, host, size);
 }
 QLIST_FOREACH(child, >children, next) {
-bdrv_unregister_buf(child->bs, host);
+bdrv_unregister_buf(child->bs, host, size);
 }
 }
 
diff --git a/block/nvme.c b/block/nvme.c
index 552029931d..88485e77f1 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -1592,7 +1592,7 @@ static void nvme_register_buf(BlockDriverState *bs, void 
*host, size_t size)
 }
 }
 
-static void nvme_unregister_buf(BlockDriverState *bs, void *host)
+static void nvme_unregister_buf(BlockDriverState *bs, void *host, size_t 

[RFC 0/8] blkio: add libblkio BlockDriver

2022-03-23 Thread Stefan Hajnoczi
This patch series adds a QEMU BlockDriver for libblkio
(https://gitlab.com/libblkio/libblkio/), a library for high-performance block
device I/O. Currently libblkio has basic io_uring support with additional
drivers in development.

The first patch adds the core BlockDriver and most of the libblkio API usage.
The remainder of the patch series reworks the existing QEMU bdrv_register_buf()
API so virtio-blk emulation efficiently map guest RAM for libblkio - some
libblkio drivers require that I/O buffer memory is pre-registered (think VFIO,
vhost, etc).

This block driver is incomplete because bdrv_refresh_limits() and several other
APIs are not yet implemented. You can already boot a guest though. Once the
missing gaps have been filled in I will send a non-RFC patch series.

Regarding the design: each libblkio driver is a separately named BlockDriver.
That means there is an "io_uring" BlockDriver and not a generic "libblkio"
BlockDriver. In the future there will be additional BlockDrivers, all defined
in block/blkio.c. This way QAPI and open parameters are type-safe and mandatory
parameters can be checked by QEMU.

Stefan Hajnoczi (8):
  blkio: add io_uring block driver using libblkio
  numa: call ->ram_block_removed() in ram_block_notifer_remove()
  block: pass size to bdrv_unregister_buf()
  block: add BDRV_REQ_REGISTERED_BUF request flag
  block: add BlockRAMRegistrar
  stubs: add memory_region_from_host() and memory_region_get_fd()
  blkio: implement BDRV_REQ_REGISTERED_BUF optimization
  virtio-blk: use BDRV_REQ_REGISTERED_BUF optimization hint

 MAINTAINERS |   7 +
 meson_options.txt   |   2 +
 qapi/block-core.json|  18 +-
 meson.build |   9 +
 include/block/block-common.h|   9 +
 include/block/block-global-state.h  |   5 +-
 include/block/block_int-common.h|   2 +-
 include/hw/virtio/virtio-blk.h  |   2 +
 include/sysemu/block-backend-global-state.h |   2 +-
 include/sysemu/block-ram-registrar.h|  30 ++
 block/blkio.c   | 560 
 block/blkverify.c   |   4 +-
 block/block-backend.c   |   4 +-
 block/block-ram-registrar.c |  39 ++
 block/crypto.c  |   2 +
 block/io.c  |  36 +-
 block/mirror.c  |   2 +
 block/nvme.c|   2 +-
 block/raw-format.c  |   2 +
 hw/block/virtio-blk.c   |  13 +-
 hw/core/numa.c  |  17 +
 qemu-img.c  |   4 +-
 stubs/memory.c  |  13 +
 tests/qtest/modules-test.c  |   3 +
 util/vfio-helpers.c |   5 +-
 block/meson.build   |   2 +
 scripts/meson-buildoptions.sh   |   3 +
 stubs/meson.build   |   1 +
 28 files changed, 772 insertions(+), 26 deletions(-)
 create mode 100644 include/sysemu/block-ram-registrar.h
 create mode 100644 block/blkio.c
 create mode 100644 block/block-ram-registrar.c
 create mode 100644 stubs/memory.c

-- 
2.35.1





[RFC 2/8] numa: call ->ram_block_removed() in ram_block_notifer_remove()

2022-03-23 Thread Stefan Hajnoczi
When a RAMBlockNotifier is added, ->ram_block_added() is called with all
existing RAMBlocks. There is no equivalent ->ram_block_removed() call
when a RAMBlockNotifier is removed.

The util/vfio-helpers.c code (the sole user of RAMBlockNotifier) is fine
with this asymmetry because it does not rely on RAMBlockNotifier for
cleanup. It walks its internal list of DMA mappings and unmaps them by
itself.

Future users of RAMBlockNotifier may not have an internal data structure
that records added RAMBlocks so they will need ->ram_block_removed()
callbacks.

This patch makes ram_block_notifier_remove() symmetric with respect to
callbacks. Now util/vfio-helpers.c needs to unmap remaining DMA mappings
after ram_block_notifier_remove() has been called. This is necessary
since users like block/nvme.c may create additional DMA mappings that do
not originate from the RAMBlockNotifier.

Cc: David Hildenbrand 
Signed-off-by: Stefan Hajnoczi 
---
 hw/core/numa.c  | 17 +
 util/vfio-helpers.c |  5 -
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/hw/core/numa.c b/hw/core/numa.c
index 1aa05dcf42..6bf9694d20 100644
--- a/hw/core/numa.c
+++ b/hw/core/numa.c
@@ -822,6 +822,19 @@ static int ram_block_notify_add_single(RAMBlock *rb, void 
*opaque)
 return 0;
 }
 
+static int ram_block_notify_remove_single(RAMBlock *rb, void *opaque)
+{
+const ram_addr_t max_size = qemu_ram_get_max_length(rb);
+const ram_addr_t size = qemu_ram_get_used_length(rb);
+void *host = qemu_ram_get_host_addr(rb);
+RAMBlockNotifier *notifier = opaque;
+
+if (host) {
+notifier->ram_block_removed(notifier, host, size, max_size);
+}
+return 0;
+}
+
 void ram_block_notifier_add(RAMBlockNotifier *n)
 {
 QLIST_INSERT_HEAD(_list.ramblock_notifiers, n, next);
@@ -835,6 +848,10 @@ void ram_block_notifier_add(RAMBlockNotifier *n)
 void ram_block_notifier_remove(RAMBlockNotifier *n)
 {
 QLIST_REMOVE(n, next);
+
+if (n->ram_block_removed) {
+qemu_ram_foreach_block(ram_block_notify_remove_single, n);
+}
 }
 
 void ram_block_notify_add(void *host, size_t size, size_t max_size)
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
index b037d5faa5..dc90496592 100644
--- a/util/vfio-helpers.c
+++ b/util/vfio-helpers.c
@@ -847,10 +847,13 @@ void qemu_vfio_close(QEMUVFIOState *s)
 if (!s) {
 return;
 }
+
+ram_block_notifier_remove(>ram_notifier);
+
 for (i = 0; i < s->nr_mappings; ++i) {
 qemu_vfio_undo_mapping(s, >mappings[i], NULL);
 }
-ram_block_notifier_remove(>ram_notifier);
+
 g_free(s->usable_iova_ranges);
 s->nb_iova_ranges = 0;
 qemu_vfio_reset(s);
-- 
2.35.1




[RFC 1/8] blkio: add io_uring block driver using libblkio

2022-03-23 Thread Stefan Hajnoczi
libblkio (https://gitlab.com/libblkio/libblkio/) is a library for
high-performance disk I/O. It currently supports io_uring with
additional drivers planned.

One of the reasons for developing libblkio is that other applications
besides QEMU can use it. This will be particularly useful for
vhost-user-blk which applications may wish to use for connecting to
qemu-storage-daemon.

libblkio also gives us an opportunity to develop in Rust behind a C API
that is easy to consume from QEMU.

This commit adds an io_uring BlockDriver to QEMU using libblkio. For now
I/O buffers are copied through bounce buffers if the libblkio driver
requires it. Later commits add an optimization for pre-registering guest
RAM to avoid bounce buffers. It will be easy to add other libblkio
drivers since they will share the majority of code.

Signed-off-by: Stefan Hajnoczi 
---
 MAINTAINERS   |   6 +
 meson_options.txt |   2 +
 qapi/block-core.json  |  18 +-
 meson.build   |   9 +
 block/blkio.c | 460 ++
 tests/qtest/modules-test.c|   3 +
 block/meson.build |   1 +
 scripts/meson-buildoptions.sh |   3 +
 8 files changed, 501 insertions(+), 1 deletion(-)
 create mode 100644 block/blkio.c

diff --git a/MAINTAINERS b/MAINTAINERS
index cc364afef7..0fb08dd4f7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3349,6 +3349,12 @@ L: qemu-block@nongnu.org
 S: Maintained
 F: block/vdi.c
 
+blkio
+M: Stefan Hajnoczi 
+L: qemu-block@nongnu.org
+S: Maintained
+F: block/blkio.c
+
 iSCSI
 M: Ronnie Sahlberg 
 M: Paolo Bonzini 
diff --git a/meson_options.txt b/meson_options.txt
index 52b11cead4..1e82e770e7 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -101,6 +101,8 @@ option('bzip2', type : 'feature', value : 'auto',
description: 'bzip2 support for DMG images')
 option('cap_ng', type : 'feature', value : 'auto',
description: 'cap_ng support')
+option('blkio', type : 'feature', value : 'auto',
+   description: 'libblkio block device driver')
 option('bpf', type : 'feature', value : 'auto',
 description: 'eBPF support')
 option('cocoa', type : 'feature', value : 'auto',
diff --git a/qapi/block-core.json b/qapi/block-core.json
index e89f2dfb5b..d9bb283108 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -2924,7 +2924,9 @@
 'file', 'snapshot-access', 'ftp', 'ftps', 'gluster',
 {'name': 'host_cdrom', 'if': 'HAVE_HOST_BLOCK_DEVICE' },
 {'name': 'host_device', 'if': 'HAVE_HOST_BLOCK_DEVICE' },
-'http', 'https', 'iscsi',
+'http', 'https',
+{ 'name': 'io_uring', 'if': 'CONFIG_BLKIO' },
+'iscsi',
 'luks', 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels',
 'preallocate', 'qcow', 'qcow2', 'qed', 'quorum', 'raw', 'rbd',
 { 'name': 'replication', 'if': 'CONFIG_REPLICATION' },
@@ -3656,6 +3658,18 @@
 '*debug': 'int',
 '*logfile': 'str' } }
 
+##
+# @BlockdevOptionsIoUring:
+#
+# Driver specific block device options for the io_uring backend.
+#
+# @filename: path to the image file
+#
+# Since: 6.3
+##
+{ 'struct': 'BlockdevOptionsIoUring',
+  'data': { 'filename': 'str' } }
+
 ##
 # @IscsiTransport:
 #
@@ -4254,6 +4268,8 @@
'if': 'HAVE_HOST_BLOCK_DEVICE' },
   'http':   'BlockdevOptionsCurlHttp',
   'https':  'BlockdevOptionsCurlHttps',
+  'io_uring':   { 'type': 'BlockdevOptionsIoUring',
+  'if': 'CONFIG_BLKIO' },
   'iscsi':  'BlockdevOptionsIscsi',
   'luks':   'BlockdevOptionsLUKS',
   'nbd':'BlockdevOptionsNbd',
diff --git a/meson.build b/meson.build
index aef724ad3c..d52f542b2e 100644
--- a/meson.build
+++ b/meson.build
@@ -636,6 +636,13 @@ if not get_option('virglrenderer').auto() or have_system 
or have_vhost_user_gpu
  required: get_option('virglrenderer'),
  kwargs: static_kwargs)
 endif
+blkio = not_found
+if not get_option('blkio').auto() or have_block
+  blkio = dependency('blkio',
+ method: 'pkg-config',
+ required: get_option('blkio'),
+ kwargs: static_kwargs)
+endif
 curl = not_found
 if not get_option('curl').auto() or have_block
   curl = dependency('libcurl', version: '>=7.29.0',
@@ -1519,6 +1526,7 @@ config_host_data.set('CONFIG_LIBUDEV', libudev.found())
 config_host_data.set('CONFIG_LZO', lzo.found())
 config_host_data.set('CONFIG_MPATH', mpathpersist.found())
 config_host_data.set('CONFIG_MPATH_NEW_API', mpathpersist_new_api)
+config_host_data.set('CONFIG_BLKIO', blkio.found())
 config_host_data.set('CONFIG_CURL', curl.found())
 config_host_data.set('CONFIG_CURSES', curses.found())
 config_host_data.set('CONFIG_GBM', gbm.found())
@@ -3672,6 +3680,7 @@ summary_info += {'PAM':   pam}
 summary_info += {'iconv support': iconv}
 

[PATCH v3 3/3] iotests/303: Check for zstd support

2022-03-23 Thread Hanna Reitz
303 runs two test cases, one of which requires zstd support.
Unfortunately, given that this is not a unittest-style test, we cannot
easily skip that single case, and instead can only skip the whole test.

(Alternatively, we could split this test into a zlib and a zstd part,
but that seems excessive, given that this test is not in auto and thus
likely only run by developers who have zstd support compiled in.)

Fixes: 677e0bae686e7c670a71d1f ("iotest 303: explicit compression type")
Signed-off-by: Hanna Reitz 
Reviewed-by: Vladimir Sementsov-Ogievskiy 
---
 tests/qemu-iotests/303 | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tests/qemu-iotests/303 b/tests/qemu-iotests/303
index 93aa5ce9b7..40e947f26c 100755
--- a/tests/qemu-iotests/303
+++ b/tests/qemu-iotests/303
@@ -21,10 +21,12 @@
 
 import iotests
 import subprocess
-from iotests import qemu_img_create, qemu_io, file_path, log, filter_qemu_io
+from iotests import qemu_img_create, qemu_io, file_path, log, filter_qemu_io, \
+verify_qcow2_zstd_compression
 
 iotests.script_initialize(supported_fmts=['qcow2'],
   unsupported_imgopts=['refcount_bits', 'compat'])
+verify_qcow2_zstd_compression()
 
 disk = file_path('disk')
 chunk = 1024 * 1024
-- 
2.35.1




[PATCH v3 2/3] iotests/065: Check for zstd support

2022-03-23 Thread Hanna Reitz
Some test cases run in iotest 065 want to run with zstd compression just
for added coverage.  Run them with zlib if there is no zstd support
compiled in.

Reported-by: Thomas Huth 
Fixes: 12a936171d71f839dc907ff ("iotest 065: explicit compression type")
Signed-off-by: Hanna Reitz 
---
 tests/qemu-iotests/065 | 24 ++--
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/tests/qemu-iotests/065 b/tests/qemu-iotests/065
index ba94e19349..b724c89c7c 100755
--- a/tests/qemu-iotests/065
+++ b/tests/qemu-iotests/065
@@ -24,7 +24,7 @@ import os
 import re
 import json
 import iotests
-from iotests import qemu_img, qemu_img_info
+from iotests import qemu_img, qemu_img_info, supports_qcow2_zstd_compression
 import unittest
 
 test_img = os.path.join(iotests.test_dir, 'test.img')
@@ -95,11 +95,17 @@ class TestQCow2(TestQemuImgInfo):
 
 class TestQCow3NotLazy(TestQemuImgInfo):
 '''Testing a qcow2 version 3 image with lazy refcounts disabled'''
-img_options = 'compat=1.1,lazy_refcounts=off,compression_type=zstd'
+if supports_qcow2_zstd_compression():
+compression_type = 'zstd'
+else:
+compression_type = 'zlib'
+
+img_options = 'compat=1.1,lazy_refcounts=off'
+img_options += f',compression_type={compression_type}'
 json_compare = { 'compat': '1.1', 'lazy-refcounts': False,
  'refcount-bits': 16, 'corrupt': False,
- 'compression-type': 'zstd', 'extended-l2': False }
-human_compare = [ 'compat: 1.1', 'compression type: zstd',
+ 'compression-type': compression_type, 'extended-l2': 
False }
+human_compare = [ 'compat: 1.1', f'compression type: {compression_type}',
   'lazy refcounts: false', 'refcount bits: 16',
   'corrupt: false', 'extended l2: false' ]
 
@@ -126,11 +132,17 @@ class TestQCow3NotLazyQMP(TestQMP):
 class TestQCow3LazyQMP(TestQMP):
 '''Testing a qcow2 version 3 image with lazy refcounts enabled, opening
with lazy refcounts disabled'''
-img_options = 'compat=1.1,lazy_refcounts=on,compression_type=zstd'
+if supports_qcow2_zstd_compression():
+compression_type = 'zstd'
+else:
+compression_type = 'zlib'
+
+img_options = 'compat=1.1,lazy_refcounts=on'
+img_options += f',compression_type={compression_type}'
 qemu_options = 'lazy-refcounts=off'
 compare = { 'compat': '1.1', 'lazy-refcounts': True,
 'refcount-bits': 16, 'corrupt': False,
-'compression-type': 'zstd', 'extended-l2': False }
+'compression-type': compression_type, 'extended-l2': False }
 
 TestImageInfoSpecific = None
 TestQemuImgInfo = None
-- 
2.35.1




[PATCH v3 1/3] iotests.py: Add supports_qcow2_zstd_compression()

2022-03-23 Thread Hanna Reitz
Suggested-by: Vladimir Sementsov-Ogievskiy 
Signed-off-by: Hanna Reitz 
---
 tests/qemu-iotests/iotests.py | 20 
 1 file changed, 20 insertions(+)

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index fcec3e51e5..fe10a6cf05 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -1471,6 +1471,26 @@ def verify_working_luks():
 if not working:
 notrun(reason)
 
+def supports_qcow2_zstd_compression() -> bool:
+img_file = f'{test_dir}/qcow2-zstd-test.qcow2'
+res = qemu_img('create', '-f', 'qcow2', '-o', 'compression_type=zstd',
+   img_file, '0',
+   check=False)
+try:
+os.remove(img_file)
+except OSError:
+pass
+
+if res.returncode == 1 and \
+"'compression-type' does not accept value 'zstd'" in res.stdout:
+return False
+else:
+return True
+
+def verify_qcow2_zstd_compression():
+if not supports_qcow2_zstd_compression():
+notrun('zstd compression not supported')
+
 def qemu_pipe(*args: str) -> str:
 """
 Run qemu with an option to print something and exit (e.g. a help option).
-- 
2.35.1




[PATCH v3 0/3] iotests: Check for zstd support

2022-03-23 Thread Hanna Reitz
Hi,

v1 cover letter:
https://lists.nongnu.org/archive/html/qemu-devel/2022-02/msg04592.html

v2 cover letter:
https://lists.nongnu.org/archive/html/qemu-block/2022-03/msg00041.html

Thanks a lot for the review and testing on v2; but I missed that I’d
have to send v3 because qemu_img_pipe_and_status() has just been
removed, which was used in patch 1 of v2. :/


v3:
- Patch 1: Use qemu_img(check=False) instead of
   qemu_img_pipe_and_status()
- Patch 2: Rebase-caused import conflict


git backport-diff against v2:

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, respectively

001/3:[0011] [FC] 'iotests.py: Add supports_qcow2_zstd_compression()'
002/3:[0004] [FC] 'iotests/065: Check for zstd support'
003/3:[] [--] 'iotests/303: Check for zstd support'


Hanna Reitz (3):
  iotests.py: Add supports_qcow2_zstd_compression()
  iotests/065: Check for zstd support
  iotests/303: Check for zstd support

 tests/qemu-iotests/065| 24 ++--
 tests/qemu-iotests/303|  4 +++-
 tests/qemu-iotests/iotests.py | 20 
 3 files changed, 41 insertions(+), 7 deletions(-)

-- 
2.35.1




Re: [PATCH v2 0/3] iotests: Check for zstd support

2022-03-23 Thread Hanna Reitz

On 02.03.22 13:45, Hanna Reitz wrote:

Hi,

v1 cover letter:

https://lists.nongnu.org/archive/html/qemu-devel/2022-02/msg04592.html

We have two tests (as far as I know) that use compression_type=zstd for
qcow2 but do not check whether that is actually supported.  Thomas
reported this for 065, but it’s also the case for 303.

This series makes 303 be skipped when zstd is not compiled in, and has
065 use zlib for each of its test cases then (it was made to use zstd
just to improve on coverage, so using zlib as a fallback is perfectly
fine).


Thanks a lot for the quick replies to my ping!

Regrettably, I forgot to consider that John’s recent changes would 
remove qemu_img_pipe_and_status(), which is used in patch 1...  I’m 
sorry, but I’ll have to send a v3. :/


Hanna




Re: [PATCH] iotests: update test owner contact information

2022-03-23 Thread Thomas Huth

On 22/03/2022 18.42, John Snow wrote:

Quite a few of these tests have stale contact information. This patch
updates the stale ones that I happen to be aware of at the moment.

Signed-off-by: John Snow 
---
  tests/qemu-iotests/025 | 2 +-
  tests/qemu-iotests/027 | 2 +-
  tests/qemu-iotests/028 | 2 +-
  tests/qemu-iotests/036 | 2 +-
  tests/qemu-iotests/039 | 2 +-
  tests/qemu-iotests/059 | 2 +-
  tests/qemu-iotests/060 | 2 +-
  tests/qemu-iotests/061 | 2 +-
  tests/qemu-iotests/062 | 2 +-
  tests/qemu-iotests/064 | 2 +-
  tests/qemu-iotests/066 | 2 +-
  tests/qemu-iotests/068 | 2 +-
  tests/qemu-iotests/069 | 2 +-
  tests/qemu-iotests/070 | 2 +-
  tests/qemu-iotests/071 | 2 +-
  tests/qemu-iotests/072 | 2 +-
  tests/qemu-iotests/074 | 2 +-
  tests/qemu-iotests/084 | 2 +-
  tests/qemu-iotests/085 | 2 +-
  tests/qemu-iotests/089 | 2 +-
  tests/qemu-iotests/090 | 2 +-
  tests/qemu-iotests/091 | 2 +-
  tests/qemu-iotests/094 | 2 +-
  tests/qemu-iotests/095 | 2 +-
  tests/qemu-iotests/097 | 2 +-
  tests/qemu-iotests/098 | 2 +-
  tests/qemu-iotests/099 | 2 +-
  tests/qemu-iotests/102 | 2 +-
  tests/qemu-iotests/103 | 2 +-
  tests/qemu-iotests/105 | 2 +-
  tests/qemu-iotests/106 | 2 +-
  tests/qemu-iotests/107 | 2 +-
  tests/qemu-iotests/108 | 2 +-
  tests/qemu-iotests/110 | 2 +-
  tests/qemu-iotests/111 | 2 +-
  tests/qemu-iotests/112 | 2 +-
  tests/qemu-iotests/113 | 2 +-
  tests/qemu-iotests/115 | 2 +-
  tests/qemu-iotests/117 | 2 +-
  tests/qemu-iotests/119 | 2 +-
  tests/qemu-iotests/120 | 2 +-
  tests/qemu-iotests/121 | 2 +-
  tests/qemu-iotests/123 | 2 +-
  tests/qemu-iotests/125 | 2 +-
  tests/qemu-iotests/126 | 2 +-
  tests/qemu-iotests/127 | 2 +-
  tests/qemu-iotests/135 | 2 +-
  tests/qemu-iotests/138 | 2 +-
  tests/qemu-iotests/140 | 2 +-
  tests/qemu-iotests/141 | 2 +-
  tests/qemu-iotests/143 | 2 +-
  tests/qemu-iotests/144 | 2 +-
  tests/qemu-iotests/146 | 2 +-
  tests/qemu-iotests/150 | 2 +-
  tests/qemu-iotests/153 | 2 +-
  tests/qemu-iotests/156 | 2 +-
  tests/qemu-iotests/162 | 2 +-
  tests/qemu-iotests/173 | 2 +-
  tests/qemu-iotests/176 | 2 +-
  tests/qemu-iotests/182 | 2 +-
  tests/qemu-iotests/192 | 2 +-
  tests/qemu-iotests/200 | 2 +-
  tests/qemu-iotests/216 | 2 +-
  tests/qemu-iotests/218 | 2 +-
  tests/qemu-iotests/224 | 2 +-
  tests/qemu-iotests/225 | 2 +-
  tests/qemu-iotests/228 | 2 +-
  tests/qemu-iotests/229 | 2 +-
  tests/qemu-iotests/231 | 2 +-
  tests/qemu-iotests/250 | 2 +-
  tests/qemu-iotests/251 | 2 +-
  tests/qemu-iotests/252 | 2 +-
  tests/qemu-iotests/258 | 2 +-
  tests/qemu-iotests/259 | 2 +-
  tests/qemu-iotests/261 | 2 +-
  tests/qemu-iotests/310 | 2 +-
  76 files changed, 76 insertions(+), 76 deletions(-)

diff --git a/tests/qemu-iotests/025 b/tests/qemu-iotests/025
index 80686a30d5..5771ea9200 100755
--- a/tests/qemu-iotests/025
+++ b/tests/qemu-iotests/025
@@ -20,7 +20,7 @@
  #
  
  # creator

-owner=stefa...@linux.vnet.ibm.com
+owner=stefa...@redhat.com


Wow, these were really old ones ... I wonder whether these "owner" lines 
really still make that much sense if they are neglected that much, or 
whether the information should maybe rather be captured in MAINTAINERS instead?


Anyway:
Reviewed-by: Thomas Huth 




[RFC PATCH v4] hw/nvme:Adding Support for namespace management

2022-03-23 Thread Naveen
From: Naveen Nagar 

This patch supports namespace management : create and delete operations
This patch has been tested with the following command and size of image
file for unallocated namespaces is taken as 0GB. nvme_namespace_create
will look into the list of unallocated namespaces and it will initialize 
and return the nsid of the same. A new mandatory field has been added
called tnvmcap and we have ensured that the total capacity of namespace 
created does not exceed tnvmcap

-device nvme-subsys,id=subsys0,tnvmcap=8
-device nvme,serial=foo,id=nvme0,subsys=subsys0
-device nvme,serial=bar,id=nvme1,subsys=subsys0

-drive id=ns1,file=ns1.img,if=none
-device nvme-ns,drive=ns1,bus=nvme0,nsid=1,zoned=false,shared=true
-drive id=ns2,file=ns2.img,if=none
-device nvme-ns,drive=ns2,bus=nvme0,nsid=2,zoned=false,shared=true
-drive id=ns3,file=ns3.img,if=none
-device nvme-ns,drive=ns3,bus=nvme0,nsid=3,zoned=false,shared=true
-drive id=ns4,file=ns4.img,if=none
-device nvme-ns,drive=ns4,bus=nvme0,nsid=4,zoned=false,shared=true

Please review and suggest if any changes are required.

Signed-off-by: Naveen Nagar 

Since v3:
-Lukasz Maniak found a bug related to unvmcap support and proposed
 solution is added

---
 hw/nvme/ctrl.c   | 257 ---
 hw/nvme/ns.c |  80 +-
 hw/nvme/nvme.h   |   7 +-
 hw/nvme/subsys.c |   3 +
 include/block/nvme.h |  18 ++-
 5 files changed, 317 insertions(+), 48 deletions(-)

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 03760ddeae..5c5b915dc6 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -222,6 +222,7 @@ static const uint32_t nvme_cse_acs[256] = {
 [NVME_ADM_CMD_SET_FEATURES] = NVME_CMD_EFF_CSUPP,
 [NVME_ADM_CMD_GET_FEATURES] = NVME_CMD_EFF_CSUPP,
 [NVME_ADM_CMD_ASYNC_EV_REQ] = NVME_CMD_EFF_CSUPP,
+[NVME_ADM_CMD_NS_MANAGEMENT]= NVME_CMD_EFF_CSUPP | NVME_CMD_EFF_NIC,
 [NVME_ADM_CMD_NS_ATTACHMENT]= NVME_CMD_EFF_CSUPP | NVME_CMD_EFF_NIC,
 [NVME_ADM_CMD_FORMAT_NVM]   = NVME_CMD_EFF_CSUPP | NVME_CMD_EFF_LBCC,
 };
@@ -4715,11 +4716,19 @@ static uint16_t nvme_identify_ns(NvmeCtrl *n, 
NvmeRequest *req, bool active)
 NvmeNamespace *ns;
 NvmeIdentify *c = (NvmeIdentify *)>cmd;
 uint32_t nsid = le32_to_cpu(c->nsid);
+NvmeIdNs *id_ns = NULL;
+uint16_t ret;
 
 trace_pci_nvme_identify_ns(nsid);
 
-if (!nvme_nsid_valid(n, nsid) || nsid == NVME_NSID_BROADCAST) {
+if (!nvme_nsid_valid(n, nsid)) {
 return NVME_INVALID_NSID | NVME_DNR;
+} else if (nsid == NVME_NSID_BROADCAST) {
+id_ns = g_new0(NvmeIdNs, 1);
+nvme_ns_identify_common(id_ns);
+ret = nvme_c2h(n, (uint8_t *)id_ns, sizeof(NvmeIdNs), req);
+g_free(id_ns);
+return ret;
 }
 
 ns = nvme_ns(n, nsid);
@@ -5475,9 +5484,208 @@ static void nvme_select_iocs_ns(NvmeCtrl *n, 
NvmeNamespace *ns)
 }
 }
 
+static int nvme_blk_truncate(BlockBackend *blk, size_t len, Error **errp)
+{
+int ret;
+uint64_t perm, shared_perm;
+
+blk_get_perm(blk, , _perm);
+
+ret = blk_set_perm(blk, perm | BLK_PERM_RESIZE, shared_perm, errp);
+if (ret < 0) {
+return ret;
+}
+
+ret = blk_truncate(blk, len, false, PREALLOC_MODE_OFF, 0, errp);
+if (ret < 0) {
+return ret;
+}
+
+ret = blk_set_perm(blk, perm, shared_perm, errp);
+if (ret < 0) {
+return ret;
+}
+
+return 0;
+}
+
+static uint32_t nvme_allocate_nsid(NvmeCtrl *n)
+{
+uint32_t nsid = 0;
+for (int i = 1; i <= NVME_MAX_NAMESPACES; i++) {
+if (nvme_ns(n, i) || nvme_subsys_ns(n->subsys, i)) {
+continue;
+}
+
+nsid = i;
+return nsid;
+}
+return nsid;
+}
+
+static uint16_t nvme_namespace_create(NvmeCtrl *n, NvmeRequest *req)
+{
+uint32_t ret;
+NvmeIdNs id_ns_host;
+NvmeSubsystem *subsys = n->subsys;
+Error *err = NULL;
+uint8_t flbas_host;
+uint64_t ns_size;
+int lba_index;
+NvmeNamespace *ns;
+NvmeCtrl *ctrl;
+NvmeIdNs *id_ns;
+
+ret = nvme_h2c(n, (uint8_t *)_ns_host, sizeof(id_ns_host), req);
+if (ret) {
+return ret;
+}
+
+if (id_ns_host.ncap < id_ns_host.nsze) {
+return NVME_THIN_PROVISION_NO_SUPP | NVME_DNR;
+} else if (id_ns_host.ncap > id_ns_host.nsze) {
+return NVME_INVALID_FIELD | NVME_DNR;
+}
+
+if (!id_ns_host.nsze) {
+return NVME_INVALID_FIELD | NVME_DNR;
+}
+
+if (QSLIST_EMPTY(>unallocated_namespaces)) {
+return NVME_NS_ID_UNAVAILABLE;
+}
+
+ns = QSLIST_FIRST(>unallocated_namespaces);
+id_ns = >id_ns;
+flbas_host = (id_ns_host.flbas) & (0xF);
+
+if (flbas_host > id_ns->nlbaf) {
+return NVME_INVALID_FORMAT | NVME_DNR;
+}
+
+ret = nvme_ns_setup(ns, );
+if (ret) {
+return ret;
+}
+
+id_ns->flbas = id_ns_host.flbas;
+id_ns->dps = id_ns_host.dps;
+id_ns->nmic = id_ns_host.nmic;
+
+lba_index =