[PATCH 2/2] ui: fix incorrect pointer position on highdpi with gtk

2021-11-21 Thread Alexander Orzechowski
Signed-off-by: Alexander Orzechowski 
---
 ui/gtk.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index d2892ea6b4..b2670142b5 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -838,10 +838,11 @@ static gboolean gd_motion_event(GtkWidget *widget, 
GdkEventMotion *motion,
 {
 VirtualConsole *vc = opaque;
 GtkDisplayState *s = vc->s;
+GdkWindow *window;
 int x, y;
 int mx, my;
 int fbh, fbw;
-int ww, wh;
+int ww, wh, ws;
 
 if (!vc->gfx.ds) {
 return TRUE;
@@ -850,8 +851,10 @@ static gboolean gd_motion_event(GtkWidget *widget, 
GdkEventMotion *motion,
 fbw = surface_width(vc->gfx.ds) * vc->gfx.scale_x;
 fbh = surface_height(vc->gfx.ds) * vc->gfx.scale_y;
 
-ww = gdk_window_get_width(gtk_widget_get_window(vc->gfx.drawing_area));
-wh = gdk_window_get_height(gtk_widget_get_window(vc->gfx.drawing_area));
+window = gtk_widget_get_window(vc->gfx.drawing_area);
+ww = gdk_window_get_width(window);
+wh = gdk_window_get_height(window);
+ws = gdk_window_get_scale_factor (window);
 
 mx = my = 0;
 if (ww > fbw) {
@@ -861,8 +864,8 @@ static gboolean gd_motion_event(GtkWidget *widget, 
GdkEventMotion *motion,
 my = (wh - fbh) / 2;
 }
 
-x = (motion->x - mx) / vc->gfx.scale_x;
-y = (motion->y - my) / vc->gfx.scale_y;
+x = (motion->x - mx) / vc->gfx.scale_x * ws;
+y = (motion->y - my) / vc->gfx.scale_y * ws;
 
 if (qemu_input_is_absolute()) {
 if (x < 0 || y < 0 ||
-- 
2.34.0




[PATCH 0/2] Fix trivial errors with highdpi/wayland

2021-11-21 Thread Alexander Orzechowski
Hi, this patch series is ment to fix two problems with highdpi/wayland
with gtk that makes the program unusuable. As it stands currently:
The virtual machine window will only render in the bottom-left quarter of the 
screen
(with 2x scaling) while using the gtk,gl=on and virtgl backend. This also
fixes the --usbdevice tablet option as before if the pointer would click
in the incorrect spot of the virtual machine then was expected.

Alexander Orzechowski (2):
  ui: fix incorrect scaling on highdpi with gtk/opengl
  ui: fix incorrect pointer position on highdpi with gtk
 
 ui/gtk-gl-area.c |  7 ---
 ui/gtk.c | 13 -
 2 files changed, 12 insertions(+), 8 deletions(-)

-- 
2.34.0




[PATCH 1/2] ui: fix incorrect scaling on highdpi with gtk/opengl

2021-11-21 Thread Alexander Orzechowski
Signed-off-by: Alexander Orzechowski 
---
 ui/gtk-gl-area.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c
index 461da7712f..d3565698ae 100644
--- a/ui/gtk-gl-area.c
+++ b/ui/gtk-gl-area.c
@@ -41,15 +41,16 @@ void gd_gl_area_draw(VirtualConsole *vc)
 #ifdef CONFIG_GBM
 QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf;
 #endif
-int ww, wh, y1, y2;
+int ww, wh, ws, y1, y2;
 
 if (!vc->gfx.gls) {
 return;
 }
 
 gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area));
-ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area);
-wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area);
+ws = gdk_window_get_scale_factor 
(gtk_widget_get_window(vc->gfx.drawing_area));
+ww = gtk_widget_get_allocated_width(vc->gfx.drawing_area) * ws;
+wh = gtk_widget_get_allocated_height(vc->gfx.drawing_area) * ws;
 
 if (vc->gfx.scanout_mode) {
 if (!vc->gfx.guest_fb.framebuffer) {
-- 
2.34.0




Re: [PATCH for-6.2 0/2] escc: fixes for STATUS_TXEMPTY and SPEC_ALLSENT

2021-11-21 Thread Mark Cave-Ayland

On 18/11/2021 18:23, Peter Maydell wrote:


On Thu, 18 Nov 2021 at 18:18, Mark Cave-Ayland
 wrote:


This is another attempt to fix booting 32-bit QEMU SPARC machines in
qemu-system-sparc using a real Sun PROM based upon further experiments and
re-reading of the ESCC datasheet from a previous patch posted at
https://lists.gnu.org/archive/html/qemu-devel/2021-11/msg00324.html.

It appears that both the Sun PROM and OpenBSD with OpenBIOS fail to send an
explicit reset command as recommended in the ESCC datasheet, which causes
hangs during serial port enumeration since the introduction of the recent
ESCC reset changes.

The first patch always sets STATUS_TXEMPTY in R_STATUS on hardware reset
which wasn't documented in the "Reset" section(s) but is documented in the
"Transmit Interrupts and Transmit Buffer Empty Bit" section, whilst the
second patch updates SPEC_ALLSENT when writing to W_TXCTRL1.

Signed-off-by: Mark Cave-Ayland 


Series
Reviewed-by: Peter Maydell 


Thanks Peter. I've added this to my qemu-sparc queue and will send a PR shortly with 
both yours and Philippe's R-B tags.



ATB,

Mark.



[PULL 0/2] qemu-sparc queue 20211121

2021-11-21 Thread Mark Cave-Ayland
The following changes since commit 8627edfb3f1fca24a96a0954148885c3241c10f8:

  Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging 
(2021-11-19 17:16:57 +0100)

are available in the Git repository at:

  git://github.com/mcayland/qemu.git tags/qemu-sparc-20211121

for you to fetch changes up to 319e89cdc32096432b578152a47d0d156033b711:

  escc: update the R_SPEC register SPEC_ALLSENT bit when writing to W_TXCTRL1 
(2021-11-21 09:56:52 +)


qemu-sparc queue
  - contains fixes for ESCC reset issues with Sun PROM and OpenBSD on SPARC32


Mark Cave-Ayland (2):
  escc: always set STATUS_TXEMPTY in R_STATUS on device reset
  escc: update the R_SPEC register SPEC_ALLSENT bit when writing to 
W_TXCTRL1

 hw/char/escc.c | 25 +
 1 file changed, 25 insertions(+)



[PULL 2/2] escc: update the R_SPEC register SPEC_ALLSENT bit when writing to W_TXCTRL1

2021-11-21 Thread Mark Cave-Ayland
The ESCC datasheet states that SPEC_ALLSENT is always set in sync mode and set
in async mode once all characters have cleared the transmitter. Since writes to
SERIAL_DATA use a synchronous chardev API, the guest can never see the state 
when
transmission is in progress so it is possible to set SPEC_ALLSENT in the
R_SPEC register unconditionally.

This fixes a hang when using the Sun PROM as it attempts to enumerate the
onboard serial devices, and a similar hang in OpenBSD SPARC32 where in both 
cases
the boot process will not proceed until SPEC_ALLSENT has been set after writing
to W_TXCTRL1.

Signed-off-by: Mark Cave-Ayland 
Message-Id: <2028181835.18497-3-mark.cave-ayl...@ilande.co.uk>
Reviewed-by: Peter Maydell 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/char/escc.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/hw/char/escc.c b/hw/char/escc.c
index a7d9050c83..8755d8d34f 100644
--- a/hw/char/escc.c
+++ b/hw/char/escc.c
@@ -586,6 +586,20 @@ static void escc_mem_write(void *opaque, hwaddr addr,
 s->wregs[s->reg] = val;
 break;
 case W_TXCTRL1:
+s->wregs[s->reg] = val;
+/*
+ * The ESCC datasheet states that SPEC_ALLSENT is always set in
+ * sync mode, and set in async mode when all characters have
+ * cleared the transmitter. Since writes to SERIAL_DATA use the
+ * blocking qemu_chr_fe_write_all() function to write each
+ * character, the guest can never see the state when async data
+ * is in the process of being transmitted so we can set this bit
+ * unconditionally regardless of the state of the W_TXCTRL1 mode
+ * bits.
+ */
+s->rregs[R_SPEC] |= SPEC_ALLSENT;
+escc_update_parameters(s);
+break;
 case W_TXCTRL2:
 s->wregs[s->reg] = val;
 escc_update_parameters(s);
-- 
2.20.1




[PULL 1/2] escc: always set STATUS_TXEMPTY in R_STATUS on device reset

2021-11-21 Thread Mark Cave-Ayland
The "Transmit Interrupts and Transmit Buffer Empty Bit" section of the ESCC
datasheet states the following about the STATUS_TXEMPTY bit: "After a hardware
reset (including a hardware reset by software), or a channel reset, this bit
is set to 1".

Update escc_reset() to set the STATUS_TXEMPTY bit in the R_STATUS register
on device reset as described which fixes a regression whereby the Sun PROM
checks this bit early on startup and gets stuck in an infinite loop if it is
not set.

Signed-off-by: Mark Cave-Ayland 
Message-Id: <2028181835.18497-2-mark.cave-ayl...@ilande.co.uk>
Reviewed-by: Peter Maydell 
---
 hw/char/escc.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/hw/char/escc.c b/hw/char/escc.c
index 0fce4f6324..a7d9050c83 100644
--- a/hw/char/escc.c
+++ b/hw/char/escc.c
@@ -354,6 +354,17 @@ static void escc_reset(DeviceState *d)
 cs->rregs[j] = 0;
 cs->wregs[j] = 0;
 }
+
+/*
+ * ...but there is an exception. The "Transmit Interrupts and Transmit
+ * Buffer Empty Bit" section on page 50 of the ESCC datasheet says of
+ * the STATUS_TXEMPTY bit in R_STATUS: "After a hardware reset
+ * (including a hardware reset by software), or a channel reset, this
+ * bit is set to 1". The Sun PROM checks this bit early on startup and
+ * gets stuck in an infinite loop if it is not set.
+ */
+cs->rregs[R_STATUS] |= STATUS_TXEMPTY;
+
 escc_reset_chn(cs);
 }
 }
-- 
2.20.1




[PATCH v4 04/10] hw/arm/virt: Support clusters on ARM virt machines

2021-11-21 Thread Yanan Wang via
In implementations of ARM64 architecture, at most there could be
a CPU topology hierarchy like "sockets/dies/clusters/cores/threads"
defined. For example, some ARM64 server chip Kunpeng 920 totally
has 2 sockets, 2 NUMA nodes (also represent CPU dies range) in each
socket, 6 clusters in each NUMA node, 4 CPU cores in each cluster.

Clusters within the same NUMA share the L3 cache data and cores
within the same cluster share a L2 cache and a L3 cache tag.
Given that designing a vCPU topology with cluster level for the
guest can gain scheduling performance improvement, let's support
this new parameter on ARM virt machines.

After this, we can define a 4-level CPU topology hierarchy like:
cpus=*,maxcpus=*,sockets=*,clusters=*,cores=*,threads=*.

Signed-off-by: Yanan Wang 
---
 hw/arm/virt.c   |  1 +
 qemu-options.hx | 10 ++
 2 files changed, 11 insertions(+)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 369552ad45..b2129f7ccd 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -2698,6 +2698,7 @@ static void virt_machine_class_init(ObjectClass *oc, void 
*data)
 hc->unplug_request = virt_machine_device_unplug_request_cb;
 hc->unplug = virt_machine_device_unplug_cb;
 mc->nvdimm_supported = true;
+mc->smp_props.clusters_supported = true;
 mc->auto_enable_numa_with_memhp = true;
 mc->auto_enable_numa_with_memdev = true;
 mc->default_ram_id = "mach-virt.ram";
diff --git a/qemu-options.hx b/qemu-options.hx
index 0f26f7dad7..74d335e4c3 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -277,6 +277,16 @@ SRST
 
 -smp 16,sockets=2,dies=2,cores=2,threads=2,maxcpus=16
 
+The following sub-option defines a CPU topology hierarchy (2 sockets
+totally on the machine, 2 clusters per socket, 2 cores per cluster,
+2 threads per core) for ARM virt machines which support sockets/clusters
+/cores/threads. Some members of the option can be omitted but their values
+will be automatically computed:
+
+::
+
+-smp 16,sockets=2,clusters=2,cores=2,threads=2,maxcpus=16
+
 Historically preference was given to the coarsest topology parameters
 when computing missing values (ie sockets preferred over cores, which
 were preferred over threads), however, this behaviour is considered
-- 
2.19.1




[PATCH v4 05/10] hw/arm/virt: Support cluster level in DT cpu-map

2021-11-21 Thread Yanan Wang via
Support one cluster level between core and physical package in the
cpu-map of Arm/virt devicetree. This is also consistent with Linux
Doc "Documentation/devicetree/bindings/cpu/cpu-topology.txt".

Signed-off-by: Yanan Wang 
---
 hw/arm/virt.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index b2129f7ccd..dfdc64c4e3 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -430,9 +430,8 @@ static void fdt_add_cpu_nodes(const VirtMachineState *vms)
  * can contain several layers of clustering within a single physical
  * package and cluster nodes can be contained in parent cluster nodes.
  *
- * Given that cluster is not yet supported in the vCPU topology,
- * we currently generate one cluster node within each socket node
- * by default.
+ * Note: currently we only support one layer of clustering within
+ * each physical package.
  */
 qemu_fdt_add_subnode(ms->fdt, "/cpus/cpu-map");
 
@@ -442,14 +441,16 @@ static void fdt_add_cpu_nodes(const VirtMachineState *vms)
 
 if (ms->smp.threads > 1) {
 map_path = g_strdup_printf(
-"/cpus/cpu-map/socket%d/cluster0/core%d/thread%d",
-cpu / (ms->smp.cores * ms->smp.threads),
+"/cpus/cpu-map/socket%d/cluster%d/core%d/thread%d",
+cpu / (ms->smp.clusters * ms->smp.cores * ms->smp.threads),
+(cpu / (ms->smp.cores * ms->smp.threads)) % 
ms->smp.clusters,
 (cpu / ms->smp.threads) % ms->smp.cores,
 cpu % ms->smp.threads);
 } else {
 map_path = g_strdup_printf(
-"/cpus/cpu-map/socket%d/cluster0/core%d",
-cpu / ms->smp.cores,
+"/cpus/cpu-map/socket%d/cluster%d/core%d",
+cpu / (ms->smp.clusters * ms->smp.cores),
+(cpu / ms->smp.cores) % ms->smp.clusters,
 cpu % ms->smp.cores);
 }
 qemu_fdt_add_path(ms->fdt, map_path);
-- 
2.19.1




[PATCH v4 09/10] hw/acpi/virt-acpi-build: Support cluster level in PPTT generation

2021-11-21 Thread Yanan Wang via
Support cluster level in generation of ACPI Processor Properties
Topology Table (PPTT) for ARM virt machines.

Signed-off-by: Yanan Wang 
---
 hw/arm/virt-acpi-build.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index bef7056213..b34f0dbee0 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -839,6 +839,21 @@ build_pptt(GArray *table_data, BIOSLinker *linker, 
VirtMachineState *vms)
 0, socket, NULL, 0);
 }
 
+length = g_queue_get_length(list);
+for (i = 0; i < length; i++) {
+int cluster;
+
+father_offset = GPOINTER_TO_UINT(g_queue_pop_head(list));
+for (cluster = 0; cluster < ms->smp.clusters; cluster++) {
+g_queue_push_tail(list,
+GUINT_TO_POINTER(table_data->len - pptt_start));
+build_processor_hierarchy_node(
+table_data,
+(0 << 0), /* not a physical package */
+father_offset, cluster, NULL, 0);
+}
+}
+
 length = g_queue_get_length(list);
 for (i = 0; i < length; i++) {
 int core;
-- 
2.19.1




[PATCH v4 00/10] ARM virt: Introduce CPU clusters topology support

2021-11-21 Thread Yanan Wang via
Hi,

This series introduces the new CPU clusters topology parameter
and enable the support for it on ARM virt machines.

Background and descriptions:
The new Cluster-Aware Scheduling support has landed in Linux 5.16,
which has been proved to benefit the scheduling performance (e.g.
load balance and wake_affine strategy) on both x86_64 and AArch64.
We can see Kernel PR [1] and the latest patch set [2] for reference.

So now in Linux 5.16 we have four-level arch-neutral CPU topology
definition like below and a new scheduler level for clusters.
struct cpu_topology {
int thread_id;
int core_id;
int cluster_id;
int package_id;
int llc_id;
cpumask_t thread_sibling;
cpumask_t core_sibling;
cpumask_t cluster_sibling;
cpumask_t llc_sibling;
}

A cluster generally means a group of CPU cores which share L2 cache
or other mid-level resources, and it is the shared resources that
is used to improve scheduler's behavior. From the point of view of
the size range, it's between CPU die and CPU core. For example, on
some ARM64 Kunpeng servers, we have 6 clusters in each NUMA node,
and 4 CPU cores in each cluster. The 4 CPU cores share a separate
L2 cache and a L3 cache tag, which brings cache affinity advantage.

[1] 
https://lore.kernel.org/lkml/163572864855.3357115.17938524897008353101.tglx@xen13/
[2] https://lkml.org/lkml/2021/9/24/178

In virtualization, on the Hosts which have pClusters, if we can
design a vCPU topology with cluster level for guest kernel and
have a dedicated vCPU pinning. A Cluster-Aware Guest kernel can
also make use of the cache affinity of CPU clusters to gain
similar scheduling performance.

This series consists of two parts:
The first part (patch 1-3):
Implement infrastructure for CPU cluster level topology support,
including the SMP documentation, configuration and parsing.

The second part (part 4-10):
Enable CPU cluster support on ARM virt machines, so that users
can specify a 4-level CPU hierarchy sockets/clusters/cores/threads.
And the 4-level topology will be described to guest kernel through
ACPI PPTT and DT cpu-map.

Changelog:
v3->v4:
- Significant change from v3 to v4, since the whole series is reworked
  based on latest QEMU SMP frame.
- v3: 
https://lore.kernel.org/qemu-devel/20210516103228.37792-1-wangyana...@huawei.com/

Yanan Wang (10):
  qemu-options: Improve readability of SMP related Docs
  hw/core/machine: Introduce CPU cluster topology support
  hw/core/machine: Wrap target specific parameters together
  hw/arm/virt: Support clusters on ARM virt machines
  hw/arm/virt: Support cluster level in DT cpu-map
  hw/acpi/aml-build: Improve scalability of PPTT generation
  hw/arm/virt-acpi-build: Make an ARM specific PPTT generator
  tests/acpi/bios-tables-test: Allow changes to virt/PPTT file
  hw/acpi/virt-acpi-build: Support cluster level in PPTT generation
  tests/acpi/bios-table-test: Update expected virt/PPTT file

 hw/acpi/aml-build.c |  66 ++
 hw/arm/virt-acpi-build.c|  92 +++-
 hw/arm/virt.c   |  16 ---
 hw/core/machine-smp.c   |  29 +---
 hw/core/machine.c   |   3 ++
 include/hw/acpi/aml-build.h |   5 +-
 include/hw/boards.h |   6 ++-
 qapi/machine.json   |   5 +-
 qemu-options.hx |  91 +++
 softmmu/vl.c|   3 ++
 tests/data/acpi/virt/PPTT   | Bin 76 -> 96 bytes
 11 files changed, 214 insertions(+), 102 deletions(-)

--
2.19.1




[PATCH v4 02/10] hw/core/machine: Introduce CPU cluster topology support

2021-11-21 Thread Yanan Wang via
The new Cluster-Aware Scheduling support has landed in Linux 5.16,
which has been proved to benefit the scheduling performance (e.g.
load balance and wake_affine strategy) on both x86_64 and AArch64.

So now in Linux 5.16 we have four-level arch-neutral CPU topology
definition like below and a new scheduler level for clusters.
struct cpu_topology {
int thread_id;
int core_id;
int cluster_id;
int package_id;
int llc_id;
cpumask_t thread_sibling;
cpumask_t core_sibling;
cpumask_t cluster_sibling;
cpumask_t llc_sibling;
}

A cluster generally means a group of CPU cores which share L2 cache
or other mid-level resources, and it is the shared resources that
is used to improve scheduler's behavior. From the point of view of
the size range, it's between CPU die and CPU core. For example, on
some ARM64 Kunpeng servers, we have 6 clusters in each NUMA node,
and 4 CPU cores in each cluster. The 4 CPU cores share a separate
L2 cache and a L3 cache tag, which brings cache affinity advantage.

In virtualization, on the Hosts which have pClusters, if we can
design a vCPU topology with cluster level for guest kernel and
have a dedicated vCPU pinning. A Cluster-Aware Guest kernel can
also make use of the cache affinity of CPU clusters to gain
similar scheduling performance.

This patch adds infrastructure for CPU cluster level topology
configuration and parsing, so that the user can specify cluster
parameter if their machines support it.

Signed-off-by: Yanan Wang 
---
 hw/core/machine-smp.c | 26 +++---
 hw/core/machine.c |  3 +++
 include/hw/boards.h   |  6 +-
 qapi/machine.json |  5 -
 qemu-options.hx   |  7 ---
 softmmu/vl.c  |  3 +++
 6 files changed, 38 insertions(+), 12 deletions(-)

diff --git a/hw/core/machine-smp.c b/hw/core/machine-smp.c
index 116a0cbbfa..87ceb45470 100644
--- a/hw/core/machine-smp.c
+++ b/hw/core/machine-smp.c
@@ -37,6 +37,10 @@ static char *cpu_hierarchy_to_string(MachineState *ms)
 g_string_append_printf(s, " * dies (%u)", ms->smp.dies);
 }
 
+if (mc->smp_props.clusters_supported) {
+g_string_append_printf(s, " * clusters (%u)", ms->smp.clusters);
+}
+
 g_string_append_printf(s, " * cores (%u)", ms->smp.cores);
 g_string_append_printf(s, " * threads (%u)", ms->smp.threads);
 
@@ -69,6 +73,7 @@ void smp_parse(MachineState *ms, SMPConfiguration *config, 
Error **errp)
 unsigned cpus= config->has_cpus ? config->cpus : 0;
 unsigned sockets = config->has_sockets ? config->sockets : 0;
 unsigned dies= config->has_dies ? config->dies : 0;
+unsigned clusters = config->has_clusters ? config->clusters : 0;
 unsigned cores   = config->has_cores ? config->cores : 0;
 unsigned threads = config->has_threads ? config->threads : 0;
 unsigned maxcpus = config->has_maxcpus ? config->maxcpus : 0;
@@ -80,6 +85,7 @@ void smp_parse(MachineState *ms, SMPConfiguration *config, 
Error **errp)
 if ((config->has_cpus && config->cpus == 0) ||
 (config->has_sockets && config->sockets == 0) ||
 (config->has_dies && config->dies == 0) ||
+(config->has_clusters && config->clusters == 0) ||
 (config->has_cores && config->cores == 0) ||
 (config->has_threads && config->threads == 0) ||
 (config->has_maxcpus && config->maxcpus == 0)) {
@@ -95,8 +101,13 @@ void smp_parse(MachineState *ms, SMPConfiguration *config, 
Error **errp)
 error_setg(errp, "dies not supported by this machine's CPU topology");
 return;
 }
+if (!mc->smp_props.clusters_supported && clusters > 1) {
+error_setg(errp, "clusters not supported by this machine's CPU 
topology");
+return;
+}
 
 dies = dies > 0 ? dies : 1;
+clusters = clusters > 0 ? clusters : 1;
 
 /* compute missing values based on the provided ones */
 if (cpus == 0 && maxcpus == 0) {
@@ -111,41 +122,42 @@ void smp_parse(MachineState *ms, SMPConfiguration 
*config, Error **errp)
 if (sockets == 0) {
 cores = cores > 0 ? cores : 1;
 threads = threads > 0 ? threads : 1;
-sockets = maxcpus / (dies * cores * threads);
+sockets = maxcpus / (dies * clusters * cores * threads);
 } else if (cores == 0) {
 threads = threads > 0 ? threads : 1;
-cores = maxcpus / (sockets * dies * threads);
+cores = maxcpus / (sockets * dies * clusters * threads);
 }
 } else {
 /* prefer cores over sockets since 6.2 */
 if (cores == 0) {
 sockets = sockets > 0 ? sockets : 1;
 threads = threads > 0 ? threads : 1;
-cores = maxcpus / (sockets * dies * threads);
+cores = maxcpus / (sockets * dies * clusters * threads);
 } else if (sockets == 0) {
 threads = threads > 0 ? threads : 1;
- 

[PATCH v4 03/10] hw/core/machine: Wrap target specific parameters together

2021-11-21 Thread Yanan Wang via
Wrap the CPU target specific parameters together into a single
variable, so that we don't need to update the other lines but
a single line when new topology parameters are introduced.

No functional change intended.

Signed-off-by: Yanan Wang 
---
 hw/core/machine-smp.c | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/hw/core/machine-smp.c b/hw/core/machine-smp.c
index 87ceb45470..2a3f16e52b 100644
--- a/hw/core/machine-smp.c
+++ b/hw/core/machine-smp.c
@@ -77,6 +77,7 @@ void smp_parse(MachineState *ms, SMPConfiguration *config, 
Error **errp)
 unsigned cores   = config->has_cores ? config->cores : 0;
 unsigned threads = config->has_threads ? config->threads : 0;
 unsigned maxcpus = config->has_maxcpus ? config->maxcpus : 0;
+unsigned others;
 
 /*
  * Specified CPU topology parameters must be greater than zero,
@@ -109,6 +110,8 @@ void smp_parse(MachineState *ms, SMPConfiguration *config, 
Error **errp)
 dies = dies > 0 ? dies : 1;
 clusters = clusters > 0 ? clusters : 1;
 
+others = dies * clusters;
+
 /* compute missing values based on the provided ones */
 if (cpus == 0 && maxcpus == 0) {
 sockets = sockets > 0 ? sockets : 1;
@@ -122,30 +125,30 @@ void smp_parse(MachineState *ms, SMPConfiguration 
*config, Error **errp)
 if (sockets == 0) {
 cores = cores > 0 ? cores : 1;
 threads = threads > 0 ? threads : 1;
-sockets = maxcpus / (dies * clusters * cores * threads);
+sockets = maxcpus / (cores * threads * others);
 } else if (cores == 0) {
 threads = threads > 0 ? threads : 1;
-cores = maxcpus / (sockets * dies * clusters * threads);
+cores = maxcpus / (sockets * threads * others);
 }
 } else {
 /* prefer cores over sockets since 6.2 */
 if (cores == 0) {
 sockets = sockets > 0 ? sockets : 1;
 threads = threads > 0 ? threads : 1;
-cores = maxcpus / (sockets * dies * clusters * threads);
+cores = maxcpus / (sockets * threads * others);
 } else if (sockets == 0) {
 threads = threads > 0 ? threads : 1;
-sockets = maxcpus / (dies * clusters * cores * threads);
+sockets = maxcpus / (cores * threads * others);
 }
 }
 
 /* try to calculate omitted threads at last */
 if (threads == 0) {
-threads = maxcpus / (sockets * dies * clusters * cores);
+threads = maxcpus / (sockets * cores * others);
 }
 }
 
-maxcpus = maxcpus > 0 ? maxcpus : sockets * dies * clusters * cores * 
threads;
+maxcpus = maxcpus > 0 ? maxcpus : sockets * cores * threads * others;
 cpus = cpus > 0 ? cpus : maxcpus;
 
 ms->smp.cpus = cpus;
@@ -157,7 +160,7 @@ void smp_parse(MachineState *ms, SMPConfiguration *config, 
Error **errp)
 ms->smp.max_cpus = maxcpus;
 
 /* sanity-check of the computed topology */
-if (sockets * dies * clusters * cores * threads != maxcpus) {
+if (sockets * cores * threads * others != maxcpus) {
 g_autofree char *topo_msg = cpu_hierarchy_to_string(ms);
 error_setg(errp, "Invalid CPU topology: "
"product of the hierarchy must match maxcpus: "
-- 
2.19.1




[PATCH v4 10/10] tests/acpi/bios-table-test: Update expected virt/PPTT file

2021-11-21 Thread Yanan Wang via
Run ./tests/data/acpi/rebuild-expected-aml.sh from build directory
to update PPTT binary. Also empty bios-tables-test-allowed-diff.h.

The disassembled differences between actual and expected PPTT:

 /*
  * Intel ACPI Component Architecture
  * AML/ASL+ Disassembler version 20180810 (64-bit version)
  * Copyright (c) 2000 - 2018 Intel Corporation
  *
- * Disassembly of tests/data/acpi/virt/PPTT, Mon Oct 25 20:24:53 2021
+ * Disassembly of /tmp/aml-BPI5B1, Mon Oct 25 20:24:53 2021
  *
  * ACPI Data Table [PPTT]
  *
  * Format: [HexOffset DecimalOffset ByteLength]  FieldName : FieldValue
  */

 [000h    4]Signature : "PPTT"[Processor Properties 
Topology Table]
-[004h 0004   4] Table Length : 004C
+[004h 0004   4] Table Length : 0060
 [008h 0008   1] Revision : 02
-[009h 0009   1] Checksum : A8
+[009h 0009   1] Checksum : 48
 [00Ah 0010   6]   Oem ID : "BOCHS "
 [010h 0016   8] Oem Table ID : "BXPC"
 [018h 0024   4] Oem Revision : 0001
 [01Ch 0028   4]  Asl Compiler ID : "BXPC"
 [020h 0032   4]Asl Compiler Revision : 0001

 [024h 0036   1]Subtable Type : 00 [Processor Hierarchy Node]
 [025h 0037   1]   Length : 14
 [026h 0038   2] Reserved : 
 [028h 0040   4]Flags (decoded below) : 0001
 Physical package : 1
  ACPI Processor ID valid : 0
 [02Ch 0044   4]   Parent : 
 [030h 0048   4]ACPI Processor ID : 
 [034h 0052   4]  Private Resource Number : 

 [038h 0056   1]Subtable Type : 00 [Processor Hierarchy Node]
 [039h 0057   1]   Length : 14
 [03Ah 0058   2] Reserved : 
-[03Ch 0060   4]Flags (decoded below) : 000A
+[03Ch 0060   4]Flags (decoded below) : 
 Physical package : 0
- ACPI Processor ID valid : 1
+ ACPI Processor ID valid : 0
 [040h 0064   4]   Parent : 0024
 [044h 0068   4]ACPI Processor ID : 
 [048h 0072   4]  Private Resource Number : 

-Raw Table Data: Length 76 (0x4C)
+[04Ch 0076   1]Subtable Type : 00 [Processor Hierarchy Node]
+[04Dh 0077   1]   Length : 14
+[04Eh 0078   2] Reserved : 
+[050h 0080   4]Flags (decoded below) : 000A
+Physical package : 0
+ ACPI Processor ID valid : 1
+[054h 0084   4]   Parent : 0038
+[058h 0088   4]ACPI Processor ID : 
+[05Ch 0092   4]  Private Resource Number : 
+
+Raw Table Data: Length 96 (0x60)

-: 50 50 54 54 4C 00 00 00 02 A8 42 4F 43 48 53 20  // PPTTL.BOCHS
+: 50 50 54 54 60 00 00 00 02 48 42 4F 43 48 53 20  // PPTT`HBOCHS
 0010: 42 58 50 43 20 20 20 20 01 00 00 00 42 58 50 43  // BXPCBXPC
 0020: 01 00 00 00 00 14 00 00 01 00 00 00 00 00 00 00  // 
-0030: 00 00 00 00 00 00 00 00 00 14 00 00 0A 00 00 00  // 
-0040: 24 00 00 00 00 00 00 00 00 00 00 00  // $...
+0030: 00 00 00 00 00 00 00 00 00 14 00 00 00 00 00 00  // 
+0040: 24 00 00 00 00 00 00 00 00 00 00 00 00 14 00 00  // $...
+0050: 0A 00 00 00 38 00 00 00 00 00 00 00 00 00 00 00  // 8...

Signed-off-by: Yanan Wang 
---
 tests/data/acpi/virt/PPTT   | Bin 76 -> 96 bytes
 tests/qtest/bios-tables-test-allowed-diff.h |   1 -
 2 files changed, 1 deletion(-)

diff --git a/tests/data/acpi/virt/PPTT b/tests/data/acpi/virt/PPTT
index 
7a1258ecf123555b24462c98ccbb76b4ac1d0c2b..f56ea63b369a604877374ad696c396e796ab1c83
 100644
GIT binary patch
delta 53
zcmV-50LuSNU

[PATCH v4 01/10] qemu-options: Improve readability of SMP related Docs

2021-11-21 Thread Yanan Wang via
We have a description in qemu-options.hx for each CPU topology
parameter to explain what it exactly means, and also an extra
declaration for the target-specific one, e.g. "for PC only"
when describing "dies", and "for PC, it's on one die" when
describing "cores".

Now we are going to introduce one more non-generic parameter
"clusters", it will make the Doc less readable and  if we still
continue to use the legacy way to describe it.

So let's at first make two tweaks of the Docs to improve the
readability and also scalability:
1) In the -help text: Delete the extra specific declaration and
   describe each topology parameter level by level. Then add a
   note to declare that different machines may support different
   subsets and the actual meaning of the supported parameters
   will vary accordingly.
2) In the rST text: List all the sub-hierarchies currently
   supported in QEMU, and correspondingly give an example of
   -smp configuration for each of them.

Signed-off-by: Yanan Wang 
---
 qemu-options.hx | 76 ++---
 1 file changed, 59 insertions(+), 17 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index ae2c6dbbfc..7a59db7764 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -207,14 +207,26 @@ ERST
 
 DEF("smp", HAS_ARG, QEMU_OPTION_smp,
 "-smp 
[[cpus=]n][,maxcpus=maxcpus][,sockets=sockets][,dies=dies][,cores=cores][,threads=threads]\n"
-"set the number of CPUs to 'n' [default=1]\n"
+"set the number of initial CPUs to 'n' [default=1]\n"
 "maxcpus= maximum number of total CPUs, including\n"
 "offline CPUs for hotplug, etc\n"
-"sockets= number of discrete sockets in the system\n"
-"dies= number of CPU dies on one socket (for PC only)\n"
-"cores= number of CPU cores on one socket (for PC, it's on 
one die)\n"
-"threads= number of threads on one CPU core\n",
-QEMU_ARCH_ALL)
+"sockets= number of sockets on the machine board\n"
+"dies= number of dies in one socket\n"
+"cores= number of cores in one die\n"
+"threads= number of threads in one core\n"
+"Note: Different machines may have different subsets of the CPU topology\n"
+"  parameters supported, so the actual meaning of the supported 
parameters\n"
+"  will vary accordingly. For example, for a machine type that 
supports a\n"
+"  three-level CPU hierarchy of sockets/cores/threads, the parameters 
will\n"
+"  sequentially mean as below:\n"
+"sockets means the number of sockets on the machine 
board\n"
+"cores means the number of cores in one socket\n"
+"threads means the number of threads in one core\n"
+"  For a particular machine type board, an expected CPU topology 
hierarchy\n"
+"  can be defined through the supported sub-option. Unsupported 
parameters\n"
+"  can also be provided in addition to the sub-option, but their 
values\n"
+"  must be set as 1 in the purpose of correct parsing.\n",
+QEMU_ARCH_ALL)
 SRST
 ``-smp 
[[cpus=]n][,maxcpus=maxcpus][,sockets=sockets][,dies=dies][,cores=cores][,threads=threads]``
 Simulate a SMP system with '\ ``n``\ ' CPUs initially present on
@@ -225,27 +237,57 @@ SRST
 initial CPU count will match the maximum number. When only one of them
 is given then the omitted one will be set to its counterpart's value.
 Both parameters may be specified, but the maximum number of CPUs must
-be equal to or greater than the initial CPU count. Both parameters are
-subject to an upper limit that is determined by the specific machine
-type chosen.
-
-To control reporting of CPU topology information, the number of sockets,
-dies per socket, cores per die, and threads per core can be specified.
-The sum `` sockets * cores * dies * threads `` must be equal to the
-maximum CPU count. CPU targets may only support a subset of the topology
-parameters. Where a CPU target does not support use of a particular
-topology parameter, its value should be assumed to be 1 for the purpose
-of computing the CPU maximum count.
+be equal to or greater than the initial CPU count. Product of the
+CPU topology hierarchy must be equal to the maximum number of CPUs.
+Both parameters are subject to an upper limit that is determined by
+the specific machine type chosen.
+
+To control reporting of CPU topology information, values of the topology
+parameters can be specified. Machines may only support a subset of the
+parameters and different machines may have different subsets supported
+which vary depending on capacity of the corresponding CPU targets. So
+for a particular machine type board, an expected topology hierarchy can
+   

[PATCH v4 08/10] tests/acpi/bios-tables-test: Allow changes to virt/PPTT file

2021-11-21 Thread Yanan Wang via
List test/data/acpi/virt/PPTT as the expected files allowed to
be changed in tests/qtest/bios-tables-test-allowed-diff.h

Signed-off-by: Yanan Wang 
---
 tests/qtest/bios-tables-test-allowed-diff.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/qtest/bios-tables-test-allowed-diff.h 
b/tests/qtest/bios-tables-test-allowed-diff.h
index dfb8523c8b..cb143a55a6 100644
--- a/tests/qtest/bios-tables-test-allowed-diff.h
+++ b/tests/qtest/bios-tables-test-allowed-diff.h
@@ -1 +1,2 @@
 /* List of comma-separated changed AML files to ignore */
+"tests/data/acpi/virt/PPTT",
-- 
2.19.1




[PATCH v4 07/10] hw/arm/virt-acpi-build: Make an ARM specific PPTT generator

2021-11-21 Thread Yanan Wang via
We have a generic build_pptt() in hw/acpi/aml-build.c but it's
currently only used in ARM acpi initialization. Now we are going
to support the new CPU cluster parameter which is currently only
supported by ARM, it won't be a very good idea to add it to the
generic build_pptt() as it will make the code complex and hard
to maintain especially when we also support CPU cache topology
hierarchy in build_pptt() too. Note that the cache topology
design also varies between different CPU targets.

So an ARM specific PPTT generator becomes necessary now. Given
that the generic one is currently only used by ARM, let's just
move build_pptt() from aml-build.c to virt-acpi-build.c with
minor update.

Signed-off-by: Yanan Wang 
---
 hw/acpi/aml-build.c | 80 ++---
 hw/arm/virt-acpi-build.c| 77 ++-
 include/hw/acpi/aml-build.h |  5 ++-
 3 files changed, 81 insertions(+), 81 deletions(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index be3851be36..040fbc9b4b 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -1968,10 +1968,9 @@ void build_slit(GArray *table_data, BIOSLinker *linker, 
MachineState *ms,
  * ACPI spec, Revision 6.3
  * 5.2.29.1 Processor hierarchy node structure (Type 0)
  */
-static void build_processor_hierarchy_node(GArray *tbl, uint32_t flags,
-   uint32_t parent, uint32_t id,
-   uint32_t *priv_rsrc,
-   uint32_t priv_num)
+void build_processor_hierarchy_node(GArray *tbl, uint32_t flags,
+uint32_t parent, uint32_t id,
+uint32_t *priv_rsrc, uint32_t priv_num)
 {
 int i;
 
@@ -1994,79 +1993,6 @@ static void build_processor_hierarchy_node(GArray *tbl, 
uint32_t flags,
 }
 }
 
-/*
- * ACPI spec, Revision 6.3
- * 5.2.29 Processor Properties Topology Table (PPTT)
- */
-void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,
-const char *oem_id, const char *oem_table_id)
-{
-GQueue *list = g_queue_new();
-guint pptt_start = table_data->len;
-guint father_offset;
-guint length, i;
-int uid = 0;
-int socket;
-AcpiTable table = { .sig = "PPTT", .rev = 2,
-.oem_id = oem_id, .oem_table_id = oem_table_id };
-
-acpi_table_begin(&table, table_data);
-
-for (socket = 0; socket < ms->smp.sockets; socket++) {
-g_queue_push_tail(list,
-GUINT_TO_POINTER(table_data->len - pptt_start));
-build_processor_hierarchy_node(
-table_data,
-/*
- * Physical package - represents the boundary
- * of a physical package
- */
-(1 << 0),
-0, socket, NULL, 0);
-}
-
-length = g_queue_get_length(list);
-for (i = 0; i < length; i++) {
-int core;
-
-father_offset = GPOINTER_TO_UINT(g_queue_pop_head(list));
-for (core = 0; core < ms->smp.cores; core++) {
-if (ms->smp.threads > 1) {
-g_queue_push_tail(list,
-GUINT_TO_POINTER(table_data->len - pptt_start));
-build_processor_hierarchy_node(
-table_data,
-(0 << 0), /* not a physical package */
-father_offset, core, NULL, 0);
-} else {
-build_processor_hierarchy_node(
-table_data,
-(1 << 1) | /* ACPI Processor ID valid */
-(1 << 3),  /* Node is a Leaf */
-father_offset, uid++, NULL, 0);
-}
-}
-}
-
-length = g_queue_get_length(list);
-for (i = 0; i < length; i++) {
-int thread;
-
-father_offset = GPOINTER_TO_UINT(g_queue_pop_head(list));
-for (thread = 0; thread < ms->smp.threads; thread++) {
-build_processor_hierarchy_node(
-table_data,
-(1 << 1) | /* ACPI Processor ID valid */
-(1 << 2) | /* Processor is a Thread */
-(1 << 3),  /* Node is a Leaf */
-father_offset, uid++, NULL, 0);
-}
-}
-
-g_queue_free(list);
-acpi_table_end(linker, &table);
-}
-
 /* build rev1/rev3/rev5.1 FADT */
 void build_fadt(GArray *tbl, BIOSLinker *linker, const AcpiFadtData *f,
 const char *oem_id, const char *oem_table_id)
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 674f902652..bef7056213 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -807,6 +807,80 @@ build_madt(GArray *table_data, BIOSLinker *linker, 
VirtMachineState *vms)
 acpi_table_end(linker, &table);
 }
 
+/*
+ * ACPI spec, Revision 6.3
+ * 5.2.29 Processor Properties Topology Table (PPTT)
+ */
+static void
+build_pptt(GArray *table_data, BIOSLinker *linker, VirtMachineStat

[PATCH v4 06/10] hw/acpi/aml-build: Improve scalability of PPTT generation

2021-11-21 Thread Yanan Wang via
Currently we generate a PPTT table of n-level processor hierarchy
with n-level loops in build_pptt(). It works fine as now there are
only three CPU topology parameters. But the code may become less
scalable with the processor hierarchy levels increasing.

This patch only improves the scalability of build_pptt by reducing
the loops, and intends to make no functional change.

Signed-off-by: Yanan Wang 
---
 hw/acpi/aml-build.c | 50 +
 1 file changed, 32 insertions(+), 18 deletions(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index b3b3310df3..be3851be36 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -2001,7 +2001,10 @@ static void build_processor_hierarchy_node(GArray *tbl, 
uint32_t flags,
 void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,
 const char *oem_id, const char *oem_table_id)
 {
-int pptt_start = table_data->len;
+GQueue *list = g_queue_new();
+guint pptt_start = table_data->len;
+guint father_offset;
+guint length, i;
 int uid = 0;
 int socket;
 AcpiTable table = { .sig = "PPTT", .rev = 2,
@@ -2010,9 +2013,8 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, 
MachineState *ms,
 acpi_table_begin(&table, table_data);
 
 for (socket = 0; socket < ms->smp.sockets; socket++) {
-uint32_t socket_offset = table_data->len - pptt_start;
-int core;
-
+g_queue_push_tail(list,
+GUINT_TO_POINTER(table_data->len - pptt_start));
 build_processor_hierarchy_node(
 table_data,
 /*
@@ -2021,35 +2023,47 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, 
MachineState *ms,
  */
 (1 << 0),
 0, socket, NULL, 0);
+}
 
-for (core = 0; core < ms->smp.cores; core++) {
-uint32_t core_offset = table_data->len - pptt_start;
-int thread;
+length = g_queue_get_length(list);
+for (i = 0; i < length; i++) {
+int core;
 
+father_offset = GPOINTER_TO_UINT(g_queue_pop_head(list));
+for (core = 0; core < ms->smp.cores; core++) {
 if (ms->smp.threads > 1) {
+g_queue_push_tail(list,
+GUINT_TO_POINTER(table_data->len - pptt_start));
 build_processor_hierarchy_node(
 table_data,
 (0 << 0), /* not a physical package */
-socket_offset, core, NULL, 0);
-
-for (thread = 0; thread < ms->smp.threads; thread++) {
-build_processor_hierarchy_node(
-table_data,
-(1 << 1) | /* ACPI Processor ID valid */
-(1 << 2) | /* Processor is a Thread */
-(1 << 3),  /* Node is a Leaf */
-core_offset, uid++, NULL, 0);
-}
+father_offset, core, NULL, 0);
 } else {
 build_processor_hierarchy_node(
 table_data,
 (1 << 1) | /* ACPI Processor ID valid */
 (1 << 3),  /* Node is a Leaf */
-socket_offset, uid++, NULL, 0);
+father_offset, uid++, NULL, 0);
 }
 }
 }
 
+length = g_queue_get_length(list);
+for (i = 0; i < length; i++) {
+int thread;
+
+father_offset = GPOINTER_TO_UINT(g_queue_pop_head(list));
+for (thread = 0; thread < ms->smp.threads; thread++) {
+build_processor_hierarchy_node(
+table_data,
+(1 << 1) | /* ACPI Processor ID valid */
+(1 << 2) | /* Processor is a Thread */
+(1 << 3),  /* Node is a Leaf */
+father_offset, uid++, NULL, 0);
+}
+}
+
+g_queue_free(list);
 acpi_table_end(linker, &table);
 }
 
-- 
2.19.1




[PATCH] linux-user: fix Coverity CID 1464101

2021-11-21 Thread Laurent Vivier
target_mmap() can fail and return -1, but we don't check for that and
instead assume it's always valid.

Fixes: db2af69d6ba8 ("linux-user: Add infrastructure for a signal trampoline 
page")
Cc: richard.hender...@linaro.org
Reported-by: Peter Maydell 
Signed-off-by: Laurent Vivier 
---
 linux-user/elfload.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 5da8c02d0822..767f54c76dc5 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -3254,9 +3254,13 @@ int load_elf_binary(struct linux_binprm *bprm, struct 
image_info *info)
  * Otherwise, allocate a private page to hold them.
  */
 if (TARGET_ARCH_HAS_SIGTRAMP_PAGE) {
-abi_ulong tramp_page = target_mmap(0, TARGET_PAGE_SIZE,
-   PROT_READ | PROT_WRITE,
-   MAP_PRIVATE | MAP_ANON, -1, 0);
+abi_long tramp_page = target_mmap(0, TARGET_PAGE_SIZE,
+  PROT_READ | PROT_WRITE,
+  MAP_PRIVATE | MAP_ANON, -1, 0);
+if (tramp_page == -1) {
+return -errno;
+}
+
 setup_sigtramp(tramp_page);
 target_mprotect(tramp_page, TARGET_PAGE_SIZE, PROT_READ | PROT_EXEC);
 }
-- 
2.31.1




Re: [PULL 0/2] qemu-sparc queue 20211121

2021-11-21 Thread Richard Henderson

On 11/21/21 10:59 AM, Mark Cave-Ayland wrote:

The following changes since commit 8627edfb3f1fca24a96a0954148885c3241c10f8:

   Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging 
(2021-11-19 17:16:57 +0100)

are available in the Git repository at:

   git://github.com/mcayland/qemu.git tags/qemu-sparc-20211121

for you to fetch changes up to 319e89cdc32096432b578152a47d0d156033b711:

   escc: update the R_SPEC register SPEC_ALLSENT bit when writing to W_TXCTRL1 
(2021-11-21 09:56:52 +)


qemu-sparc queue
   - contains fixes for ESCC reset issues with Sun PROM and OpenBSD on SPARC32


Mark Cave-Ayland (2):
   escc: always set STATUS_TXEMPTY in R_STATUS on device reset
   escc: update the R_SPEC register SPEC_ALLSENT bit when writing to 
W_TXCTRL1

  hw/char/escc.c | 25 +
  1 file changed, 25 insertions(+)


Applied, thanks.

r~




Re: [PATCH] linux-user: fix Coverity CID 1464101

2021-11-21 Thread Richard Henderson

On 11/21/21 4:17 PM, Laurent Vivier wrote:

target_mmap() can fail and return -1, but we don't check for that and
instead assume it's always valid.

Fixes: db2af69d6ba8 ("linux-user: Add infrastructure for a signal trampoline 
page")
Cc: richard.hender...@linaro.org
Reported-by: Peter Maydell 
Signed-off-by: Laurent Vivier 
---
  linux-user/elfload.c | 10 +++---
  1 file changed, 7 insertions(+), 3 deletions(-)


Reviewed-by: Richard Henderson 

r~



diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 5da8c02d0822..767f54c76dc5 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -3254,9 +3254,13 @@ int load_elf_binary(struct linux_binprm *bprm, struct 
image_info *info)
   * Otherwise, allocate a private page to hold them.
   */
  if (TARGET_ARCH_HAS_SIGTRAMP_PAGE) {
-abi_ulong tramp_page = target_mmap(0, TARGET_PAGE_SIZE,
-   PROT_READ | PROT_WRITE,
-   MAP_PRIVATE | MAP_ANON, -1, 0);
+abi_long tramp_page = target_mmap(0, TARGET_PAGE_SIZE,
+  PROT_READ | PROT_WRITE,
+  MAP_PRIVATE | MAP_ANON, -1, 0);
+if (tramp_page == -1) {
+return -errno;
+}
+
  setup_sigtramp(tramp_page);
  target_mprotect(tramp_page, TARGET_PAGE_SIZE, PROT_READ | PROT_EXEC);
  }






Re: [PATCH] migration: fix dump-vmstate with modules

2021-11-21 Thread Laurent Vivier

I think it would be good to have this in 6.2

Thanks,
Laurent

On 16/11/2021 08:28, Laurent Vivier wrote:

To work correctly -dump-vmstate and vmstate-static-checker.py need to
dump all the supported vmstates.

But as some devices can be modules, they are not loaded at startup and not
dumped. Fix that by loading all available modules before dumping the
machine vmstate.

Fixes: 7ab6e7fcce97 ("qdev: device module support")
Cc: kra...@redhat.com
Signed-off-by: Laurent Vivier 
---
  softmmu/vl.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index 1159a64bce4e..620a1f1367e2 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -3766,6 +3766,7 @@ void qemu_init(int argc, char **argv, char **envp)
  
  if (vmstate_dump_file) {

  /* dump and exit */
+module_load_qom_all();
  dump_vmstate_json_to_file(vmstate_dump_file);
  exit(0);
  }






[PATCH] ui/gtk: graphic_hw_gl_flushed after closing dmabuf->fence_fd

2021-11-21 Thread Dongwon Kim
The dmabuf often becomes invalid right after unblocking pipeline
and graphic_hw_gl_flushed in case a new scanout blob is submitted
because the dmabuf associated with the current guest scanout is
freed after swapping.

So both graphic_hw_gl_block and graphic_hw_gl_flushed should be
executed after closing fence_fd for the current dmabuf.

Cc: Gerd Hoffmann 
Cc: Vivek Kasireddy 
Signed-off-by: Dongwon Kim 
---
 ui/gtk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 7abe1a69d8..2a3a9db13f 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -589,11 +589,11 @@ void gd_hw_gl_flushed(void *vcon)
 VirtualConsole *vc = vcon;
 QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf;
 
-graphic_hw_gl_block(vc->gfx.dcl.con, false);
-graphic_hw_gl_flushed(vc->gfx.dcl.con);
 qemu_set_fd_handler(dmabuf->fence_fd, NULL, NULL, NULL);
 close(dmabuf->fence_fd);
 dmabuf->fence_fd = -1;
+graphic_hw_gl_block(vc->gfx.dcl.con, false);
+graphic_hw_gl_flushed(vc->gfx.dcl.con);
 }
 
 /** DisplayState Callbacks (opengl version) **/
-- 
2.30.2




Re: [PATCH 35/35] test/tcg/ppc64le: Add float reference files

2021-11-21 Thread Cédric Le Goater

On 11/19/21 17:05, Richard Henderson wrote:

Generated on Power9, PowerNV 9006-22P.

Signed-off-by: Richard Henderson 
---
  tests/tcg/ppc64le/float_convs.ref | 748 +
  tests/tcg/ppc64le/float_madds.ref | 768 ++
  2 files changed, 1516 insertions(+)
  create mode 100644 tests/tcg/ppc64le/float_convs.ref
  create mode 100644 tests/tcg/ppc64le/float_madds.ref

diff --git a/tests/tcg/ppc64le/float_convs.ref 
b/tests/tcg/ppc64le/float_convs.ref
new file mode 100644
index 00..6e6f636834
--- /dev/null
+++ b/tests/tcg/ppc64le/float_convs.ref
@@ -0,0 +1,748 @@
+### Rounding to nearest
+from single: f32(-nan:0xffa0)
+  to double: f64(-nan:0x00fff4) (OK)
+   to int32: -2147483648 (INVALID)
+   to int64: -9223372036854775808 (INVALID)
+  to uint32: 0 (INVALID)
+  to uint64: 0 (INVALID)



I am getting an error with this test. See below.

C.




make[2]: Leaving directory 
'/home/legoater/work/qemu/qemu-ppc-7.0.git/build/tests/tcg/ppc64le-linux-user'
(cd tests/tcg/ppc64le-linux-user && make -f ../Makefile.target 
TARGET="ppc64le-linux-user" SRC_PATH="/home/legoater/work/qemu/qemu-ppc-7.0.git" 
SPEED=quick run)
make[2]: Entering directory 
'/home/legoater/work/qemu/qemu-ppc-7.0.git/build/tests/tcg/ppc64le-linux-user'
timeout --foreground 15  
/home/legoater/work/qemu/qemu-ppc-7.0.git/build/qemu-ppc64le  float_convs > 
float_convs.out
diff -q float_convs.out 
/home/legoater/work/qemu/qemu-ppc-7.0.git/tests/tcg/ppc64le/float_convs.ref || (diff -u 
float_convs.out 
/home/legoater/work/qemu/qemu-ppc-7.0.git/tests/tcg/ppc64le/float_convs.ref | head -n 
10 && false)
Files float_convs.out and 
/home/legoater/work/qemu/qemu-ppc-7.0.git/tests/tcg/ppc64le/float_convs.ref 
differ
--- float_convs.out 2021-11-21 12:39:33.911946974 -0500
+++ /home/legoater/work/qemu/qemu-ppc-7.0.git/tests/tcg/ppc64le/float_convs.ref 
2021-11-21 09:43:12.946774006 -0500
@@ -1,6 +1,6 @@
 ### Rounding to nearest
 from single: f32(-nan:0xffa0)
-  to double: f64(-nan:0x00fff4) (INVALID)
+  to double: f64(-nan:0x00fff4) (OK)
to int32: -2147483648 (INVALID)
to int64: -9223372036854775808 (INVALID)
   to uint32: 0 (INVALID)





Re: [PATCH 02/11] dump: Remove is_zero_page()

2021-11-21 Thread Marc-André Lureau
On Fri, Nov 19, 2021 at 8:59 PM Juan Quintela  wrote:
>
> It just calls buffer_is_zero().  Just change the callers.
>
> Signed-off-by: Juan Quintela 

Reviewed-by: Marc-André Lureau 

> ---
>  dump/dump.c | 10 +-
>  1 file changed, 1 insertion(+), 9 deletions(-)
>
> diff --git a/dump/dump.c b/dump/dump.c
> index 662d0a62cd..a84d8b1598 100644
> --- a/dump/dump.c
> +++ b/dump/dump.c
> @@ -1293,14 +1293,6 @@ static size_t get_len_buf_out(size_t page_size, 
> uint32_t flag_compress)
>  return 0;
>  }
>
> -/*
> - * check if the page is all 0
> - */
> -static inline bool is_zero_page(const uint8_t *buf, size_t page_size)
> -{
> -return buffer_is_zero(buf, page_size);
> -}
> -
>  static void write_dump_pages(DumpState *s, Error **errp)
>  {
>  int ret = 0;
> @@ -1357,7 +1349,7 @@ static void write_dump_pages(DumpState *s, Error **errp)
>   */
>  while (get_next_page(&block_iter, &pfn_iter, &buf, s)) {
>  /* check zero page */
> -if (is_zero_page(buf, s->dump_info.page_size)) {
> +if (buffer_is_zero(buf, s->dump_info.page_size)) {
>  ret = write_cache(&page_desc, &pd_zero, sizeof(PageDescriptor),
>false);
>  if (ret < 0) {
> --
> 2.33.1
>




Re: [PATCH] ui/vnc-clipboard: fix adding notifier twice

2021-11-21 Thread Nikta Lapshin



On 11/10/21 13:38, Vladimir Sementsov-Ogievskiy wrote:

vnc_server_cut_text_caps() is not guaranteed to be called only once.

If it called twice, we finally call notifier_list_add() twice with same
element. Which leads to loopback QLIST. So, on next
notifier_list_notify() we'll loop forever and QEMU stuck.

So, let's only register new notifier if it's not yet registered.

Note, that similar check is used in vdagent_chr_recv_caps() (before
call qemu_clipboard_peer_register()), and also before
qemu_clipboard_peer_unregister() call in vdagent_disconnect() and in
vnc_disconnect_finish().

Signed-off-by: Vladimir Sementsov-Ogievskiy 
---

Hi all!

After backporting clipboard patches to our Rhel7-based downstream, we
faced Qemu stuck in notifier_list_notify():

 (gdb) bt
   #0  vnc_clipboard_notify (notifier=0x564427f283f8, data=0x564426c59a70) at 
ui/vnc-clipboard.c:193
   #1  0x564423455887 in notifier_list_notify (list=list@entry=0x564423d2b258 
, data=data@entry=0x564426c59a70) at util/notify.c:40
   #2  0x5644233273bf in qemu_clipboard_update 
(info=info@entry=0x564426c59a70) at ui/clipboard.c:19
   #3  0x56442334efd2 in vnc_client_cut_text_ext (vs=vs@entry=0x564427f18000, 
len=len@entry=4, flags=,
 data=data@entry=0x5644263cc00c 
"\002\f\001\251\020\377\377\377!\377\377\377\314\376\377\377\315\376\377\377 
\377\377\377\316\345\241\300\307\376\377\377\310\376\377\377\376\376\377\377\a")
 at ui/vnc-clipboard.c:256
   #4  0x56442333b172 in protocol_client_msg (vs=0x564427f18000, data=0x5644263cc000 
"\006", len=) at ui/vnc.c:2396
   #5  0x564423338af6 in vnc_client_read (vs=0x564427f18000) at 
ui/vnc.c:1537
   #6  vnc_client_io (ioc=, condition=G_IO_IN, 
opaque=0x564427f18000) at ui/vnc.c:1559
   #7  0x7f07b02cf147 in g_main_dispatch (context=0x564425546bb0) at 
gmain.c:3192
   #8  g_main_context_dispatch (context=context@entry=0x564425546bb0) at 
gmain.c:3845
   #9  0x5644234468f7 in glib_pollfds_poll () at util/main-loop.c:215
   #10 os_host_main_loop_wait (timeout=) at util/main-loop.c:238
   #11 main_loop_wait (nonblocking=nonblocking@entry=0) at util/main-loop.c:497


investigations shows, that notifier list has only one element which points to 
itself as next. So, we are in the endless loop.

Seems that it's possible, if vnc_server_cut_text_caps() called twice. Then it 
registers notifier twice and it added to QLIST twice, which leads to the 
situation.


I don't have any reproducer and not sure that bug may be reproduced on
master.

I'm not familiar with ui code - may be vnc_server_cut_text_caps() should
never be called twice? Or notifier should be removed somehow before the
second call? Maybe this patch just shadows another bug?

But what I do know, is that we should not put same element into QLIST
twice. And if the check I propose is not needed we should add an
assertion instead:

   assert(!vs->cbpeer.update.notify);


  ui/vnc-clipboard.c | 10 ++
  1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/ui/vnc-clipboard.c b/ui/vnc-clipboard.c
index 9f077965d0..67284b556c 100644
--- a/ui/vnc-clipboard.c
+++ b/ui/vnc-clipboard.c
@@ -316,8 +316,10 @@ void vnc_server_cut_text_caps(VncState *vs)
  caps[1] = 0;
  vnc_clipboard_send(vs, 2, caps);
  
-vs->cbpeer.name = "vnc";

-vs->cbpeer.update.notify = vnc_clipboard_notify;
-vs->cbpeer.request = vnc_clipboard_request;
-qemu_clipboard_peer_register(&vs->cbpeer);
+if (!vs->cbpeer.update.notify) {
+vs->cbpeer.name = "vnc";
+vs->cbpeer.update.notify = vnc_clipboard_notify;
+vs->cbpeer.request = vnc_clipboard_request;
+qemu_clipboard_peer_register(&vs->cbpeer);
+}
  }



Perhaps QLIST_IS_INSERTED will be suitable for such checks because I 
couldn't find any initialize of .notify pointer so it can potentially be UB.





Re: [PATCH for-6.2] hw/misc/sifive_u_otp: Use IF_PFLASH for the OTP device instead of IF_NONE

2021-11-21 Thread Alistair Francis
On Fri, Nov 19, 2021 at 8:27 PM Thomas Huth  wrote:
>
> Configuring a drive with "if=none" is meant for creation of a backend
> only, it should not get automatically assigned to a device frontend.
> Use "if=pflash" for the One-Time-Programmable device instead (like
> it is e.g. also done for the efuse device in hw/arm/xlnx-zcu102.c).
>
> Since the old way of configuring the device has already been published
> with the previous QEMU versions, we cannot remove this immediately, but
> have to deprecate it and support it for at least two more releases.
>
> Signed-off-by: Thomas Huth 

Thanks!

Applied to riscv-to-apply.next

Alistair

> ---
>  docs/about/deprecated.rst | 6 ++
>  hw/misc/sifive_u_otp.c| 9 -
>  2 files changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst
> index c03fcf951f..ff7488cb63 100644
> --- a/docs/about/deprecated.rst
> +++ b/docs/about/deprecated.rst
> @@ -192,6 +192,12 @@ as short-form boolean values, and passed to plugins as 
> ``arg_name=on``.
>  However, short-form booleans are deprecated and full explicit ``arg_name=on``
>  form is preferred.
>
> +``-drive if=none`` for the sifive_u OTP device (since 6.2)
> +''
> +
> +Using ``-drive if=none`` to configure the OTP device of the sifive_u
> +RISC-V machine is deprecated. Use ``-drive if=pflash`` instead.
> +
>
>  QEMU Machine Protocol (QMP) commands
>  
> diff --git a/hw/misc/sifive_u_otp.c b/hw/misc/sifive_u_otp.c
> index 18aa0bd55d..cf6098ff2c 100644
> --- a/hw/misc/sifive_u_otp.c
> +++ b/hw/misc/sifive_u_otp.c
> @@ -209,7 +209,14 @@ static void sifive_u_otp_realize(DeviceState *dev, Error 
> **errp)
>TYPE_SIFIVE_U_OTP, SIFIVE_U_OTP_REG_SIZE);
>  sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mmio);
>
> -dinfo = drive_get_next(IF_NONE);
> +dinfo = drive_get_next(IF_PFLASH);
> +if (!dinfo) {
> +dinfo = drive_get_next(IF_NONE);
> +if (dinfo) {
> +warn_report("using \"-drive if=none\" for the OTP is deprecated, 
> "
> +"use \"-drive if=pflash\" instead.");
> +}
> +}
>  if (dinfo) {
>  int ret;
>  uint64_t perm;
> --
> 2.27.0
>
>



Re: [RFC PATCH-for-6.2?] hw/misc/sifive_u_otp: Do not reset OTP content on hardware reset

2021-11-21 Thread Alistair Francis
On Fri, Nov 19, 2021 at 8:48 PM Philippe Mathieu-Daudé  wrote:
>
> Once a "One Time Programmable" is programmed, it shouldn't be reset.
>
> Do not re-initialize the OTP content in the DeviceReset handler,
> initialize it once in the DeviceRealize one.
>
> Fixes: 9fb45c62ae8 ("riscv: sifive: Implement a model for SiFive FU540 OTP")
> Signed-off-by: Philippe Mathieu-Daudé 

Thanks!

Applied to riscv-to-apply.next

Alistair

> ---
>  hw/misc/sifive_u_otp.c | 13 +
>  1 file changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/hw/misc/sifive_u_otp.c b/hw/misc/sifive_u_otp.c
> index 18aa0bd55d8..b5adcfa7cb4 100644
> --- a/hw/misc/sifive_u_otp.c
> +++ b/hw/misc/sifive_u_otp.c
> @@ -235,14 +235,10 @@ static void sifive_u_otp_realize(DeviceState *dev, 
> Error **errp)
>
>  if (blk_pread(s->blk, 0, s->fuse, filesize) != filesize) {
>  error_setg(errp, "failed to read the initial flash content");
> +return;
>  }
>  }
>  }
> -}
> -
> -static void sifive_u_otp_reset(DeviceState *dev)
> -{
> -SiFiveUOTPState *s = SIFIVE_U_OTP(dev);
>
>  /* Initialize all fuses' initial value to 0xFFs */
>  memset(s->fuse, 0xff, sizeof(s->fuse));
> @@ -259,13 +255,15 @@ static void sifive_u_otp_reset(DeviceState *dev)
>  serial_data = s->serial;
>  if (blk_pwrite(s->blk, index * SIFIVE_U_OTP_FUSE_WORD,
> &serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) {
> -error_report("write error index<%d>", index);
> +error_setg(errp, "failed to write index<%d>", index);
> +return;
>  }
>
>  serial_data = ~(s->serial);
>  if (blk_pwrite(s->blk, (index + 1) * SIFIVE_U_OTP_FUSE_WORD,
> &serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) {
> -error_report("write error index<%d>", index + 1);
> +error_setg(errp, "failed to write index<%d>", index + 1);
> +return;
>  }
>  }
>
> @@ -279,7 +277,6 @@ static void sifive_u_otp_class_init(ObjectClass *klass, 
> void *data)
>
>  device_class_set_props(dc, sifive_u_otp_properties);
>  dc->realize = sifive_u_otp_realize;
> -dc->reset = sifive_u_otp_reset;
>  }
>
>  static const TypeInfo sifive_u_otp_info = {
> --
> 2.31.1
>
>



[PATCH v2 00/11] 9p: Add support for darwin

2021-11-21 Thread Will Cohen
This is a followup to 
https://lists.gnu.org/archive/html/qemu-devel/2021-10/msg02902.html,
adding 9p server support for Darwin.

Since v1, the following changes have been made:

Submission and formatting
- Submission via git-publish
- Signed-off-by headers now reflect modifications since original submission in 
2018
- Previous reviews have been removed, retaining only the newest 
https://lists.gnu.org/archive/html/qemu-devel/2021-10/msg03426.html

Testing
- Rebased to apply to latest master
- Updated to pass Gitlab CI pipeline

Keno Fischer (11):
  9p: linux: Fix a couple Linux assumptions
  9p: Rename 9p-util -> 9p-util-linux
  9p: darwin: Handle struct stat(fs) differences
  9p: darwin: Handle struct dirent differences
  9p: darwin: Ignore O_{NOATIME, DIRECT}
  9p: darwin: Compatibility defn for XATTR_SIZE_MAX
  9p: darwin: *xattr_nofollow implementations
  9p: darwin: Compatibility for f/l*xattr
  9p: darwin: Provide fallback impl for utimensat
  9p: darwin: Implement compatibility for mknodat
  9p: darwin: meson: Allow VirtFS on Darwin

 fsdev/file-op-9p.h |   2 +-
 fsdev/meson.build  |   1 +
 hw/9pfs/9p-local.c |  21 ++-
 hw/9pfs/9p-proxy.c |  17 ++-
 hw/9pfs/9p-synth.c |   4 +
 hw/9pfs/9p-util-darwin.c   | 193 +
 hw/9pfs/{9p-util.c => 9p-util-linux.c} |  13 +-
 hw/9pfs/9p-util.h  |  29 
 hw/9pfs/9p.c   |  75 +-
 hw/9pfs/codir.c|   4 +
 hw/9pfs/meson.build|   3 +-
 include/qemu/statfs.h  |  19 +++
 include/qemu/xattr.h   |   4 +-
 meson.build|  12 +-
 14 files changed, 374 insertions(+), 23 deletions(-)
 create mode 100644 hw/9pfs/9p-util-darwin.c
 rename hw/9pfs/{9p-util.c => 9p-util-linux.c} (82%)
 create mode 100644 include/qemu/statfs.h

-- 
2.34.0




[PATCH v2 01/11] 9p: linux: Fix a couple Linux assumptions

2021-11-21 Thread Will Cohen
From: Keno Fischer 

 - Guard Linux only headers.
 - Add qemu/statfs.h header to abstract over the which
   headers are needed for struct statfs
 - Define `ENOATTR` only if not only defined
   (it's defined in system headers on Darwin).

Signed-off-by: Keno Fischer 
[Michael Roitzsch: - Rebase for NixOS]
Signed-off-by: Michael Roitzsch 
[Will Cohen: - Fix headers for Alpine]
Signed-off-by: Will Cohen 
---
 fsdev/file-op-9p.h|  2 +-
 hw/9pfs/9p-local.c|  2 ++
 hw/9pfs/9p.c  |  4 
 include/qemu/statfs.h | 19 +++
 include/qemu/xattr.h  |  4 +++-
 5 files changed, 29 insertions(+), 2 deletions(-)
 create mode 100644 include/qemu/statfs.h

diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h
index 8fd89f0447..16c1a9d9fe 100644
--- a/fsdev/file-op-9p.h
+++ b/fsdev/file-op-9p.h
@@ -16,7 +16,7 @@
 
 #include 
 #include 
-#include 
+#include "qemu/statfs.h"
 #include "qemu-fsdev-throttle.h"
 #include "p9array.h"
 
diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index 210d9e7705..1a5e3eed73 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -32,10 +32,12 @@
 #include "qemu/error-report.h"
 #include "qemu/option.h"
 #include 
+#ifdef CONFIG_LINUX
 #include 
 #ifdef CONFIG_LINUX_MAGIC_H
 #include 
 #endif
+#endif
 #include 
 
 #ifndef XFS_SUPER_MAGIC
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 15b3f4d385..9c63e14b28 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -32,7 +32,11 @@
 #include "migration/blocker.h"
 #include "qemu/xxhash.h"
 #include 
+#ifdef CONFIG_LINUX
 #include 
+#else
+#include 
+#endif
 
 int open_fd_hw;
 int total_open_fd;
diff --git a/include/qemu/statfs.h b/include/qemu/statfs.h
new file mode 100644
index 00..dde289f9bb
--- /dev/null
+++ b/include/qemu/statfs.h
@@ -0,0 +1,19 @@
+/*
+ * Host statfs header abstraction
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2, or any
+ * later version.  See the COPYING file in the top-level directory.
+ *
+ */
+#ifndef QEMU_STATFS_H
+#define QEMU_STATFS_H
+
+#ifdef CONFIG_LINUX
+# include 
+#endif
+#ifdef CONFIG_DARWIN
+# include 
+# include 
+#endif
+
+#endif
diff --git a/include/qemu/xattr.h b/include/qemu/xattr.h
index a83fe8e749..f1d0f7be74 100644
--- a/include/qemu/xattr.h
+++ b/include/qemu/xattr.h
@@ -22,7 +22,9 @@
 #ifdef CONFIG_LIBATTR
 #  include 
 #else
-#  define ENOATTR ENODATA
+#  if !defined(ENOATTR)
+#define ENOATTR ENODATA
+#  endif
 #  include 
 #endif
 
-- 
2.34.0




[PATCH v2 08/11] 9p: darwin: Compatibility for f/l*xattr

2021-11-21 Thread Will Cohen
From: Keno Fischer 

On darwin `fgetxattr` takes two extra optional arguments,
and the l* variants are not defined (in favor of an extra
flag to the regular variants.

Signed-off-by: Keno Fischer 
[Michael Roitzsch: - Rebase for NixOS]
Signed-off-by: Michael Roitzsch 
Signed-off-by: Will Cohen 
---
 hw/9pfs/9p-local.c | 12 
 hw/9pfs/9p-util.h  | 17 +
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index 1a5e3eed73..2bfff79b12 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -781,16 +781,20 @@ static int local_fstat(FsContext *fs_ctx, int fid_type,
 mode_t tmp_mode;
 dev_t tmp_dev;
 
-if (fgetxattr(fd, "user.virtfs.uid", &tmp_uid, sizeof(uid_t)) > 0) {
+if (qemu_fgetxattr(fd, "user.virtfs.uid",
+   &tmp_uid, sizeof(uid_t)) > 0) {
 stbuf->st_uid = le32_to_cpu(tmp_uid);
 }
-if (fgetxattr(fd, "user.virtfs.gid", &tmp_gid, sizeof(gid_t)) > 0) {
+if (qemu_fgetxattr(fd, "user.virtfs.gid",
+   &tmp_gid, sizeof(gid_t)) > 0) {
 stbuf->st_gid = le32_to_cpu(tmp_gid);
 }
-if (fgetxattr(fd, "user.virtfs.mode", &tmp_mode, sizeof(mode_t)) > 0) {
+if (qemu_fgetxattr(fd, "user.virtfs.mode",
+   &tmp_mode, sizeof(mode_t)) > 0) {
 stbuf->st_mode = le32_to_cpu(tmp_mode);
 }
-if (fgetxattr(fd, "user.virtfs.rdev", &tmp_dev, sizeof(dev_t)) > 0) {
+if (qemu_fgetxattr(fd, "user.virtfs.rdev",
+   &tmp_dev, sizeof(dev_t)) > 0) {
 stbuf->st_rdev = le64_to_cpu(tmp_dev);
 }
 } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h
index 627baebaba..38ef8b289d 100644
--- a/hw/9pfs/9p-util.h
+++ b/hw/9pfs/9p-util.h
@@ -19,6 +19,23 @@
 #define O_PATH_9P_UTIL 0
 #endif
 
+#ifdef CONFIG_DARWIN
+#define qemu_fgetxattr(...) fgetxattr(__VA_ARGS__, 0, 0)
+#define qemu_lgetxattr(...) getxattr(__VA_ARGS__, 0, XATTR_NOFOLLOW)
+#define qemu_llistxattr(...) listxattr(__VA_ARGS__, XATTR_NOFOLLOW)
+#define qemu_lremovexattr(...) removexattr(__VA_ARGS__, XATTR_NOFOLLOW)
+static inline int qemu_lsetxattr(const char *path, const char *name,
+ const void *value, size_t size, int flags) {
+return setxattr(path, name, value, size, 0, flags | XATTR_NOFOLLOW);
+}
+#else
+#define qemu_fgetxattr fgetxattr
+#define qemu_lgetxattr lgetxattr
+#define qemu_llistxattr llistxattr
+#define qemu_lremovexattr lremovexattr
+#define qemu_lsetxattr lsetxattr
+#endif
+
 static inline void close_preserve_errno(int fd)
 {
 int serrno = errno;
-- 
2.34.0




[PATCH v2 04/11] 9p: darwin: Handle struct dirent differences

2021-11-21 Thread Will Cohen
From: Keno Fischer 

On darwin d_seekoff exists, but is optional and does not seem to
be commonly used by file systems. Use `telldir` instead to obtain
the seek offset.

Signed-off-by: Keno Fischer 
[Michael Roitzsch: - Rebase for NixOS]
Signed-off-by: Michael Roitzsch 
Signed-off-by: Will Cohen 
---
 hw/9pfs/9p-synth.c |  2 ++
 hw/9pfs/9p.c   | 33 +++--
 hw/9pfs/codir.c|  4 
 3 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c
index 4a4a776d06..09b9c25288 100644
--- a/hw/9pfs/9p-synth.c
+++ b/hw/9pfs/9p-synth.c
@@ -222,7 +222,9 @@ static void synth_direntry(V9fsSynthNode *node,
 {
 strcpy(entry->d_name, node->name);
 entry->d_ino = node->attr->inode;
+#ifndef CONFIG_DARWIN
 entry->d_off = off + 1;
+#endif
 }
 
 static struct dirent *synth_get_dentry(V9fsSynthNode *dir,
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index f4f0c200c7..c06e8a85a0 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -2218,6 +2218,25 @@ static int v9fs_xattr_read(V9fsState *s, V9fsPDU *pdu, 
V9fsFidState *fidp,
 return offset;
 }
 
+/**
+ * Get the seek offset of a dirent. If not available from the structure itself,
+ * obtain it by calling telldir.
+ */
+static int v9fs_dent_telldir(V9fsPDU *pdu, V9fsFidState *fidp,
+ struct dirent *dent)
+{
+#ifdef CONFIG_DARWIN
+/*
+ * Darwin has d_seekoff, which appears to function similarly to d_off.
+ * However, it does not appear to be supported on all file systems,
+ * so use telldir for correctness.
+ */
+return telldir(fidp->fs.dir.stream);
+#else
+return dent->d_off;
+#endif
+}
+
 static int coroutine_fn v9fs_do_readdir_with_stat(V9fsPDU *pdu,
   V9fsFidState *fidp,
   uint32_t max_count)
@@ -2281,7 +2300,11 @@ static int coroutine_fn 
v9fs_do_readdir_with_stat(V9fsPDU *pdu,
 count += len;
 v9fs_stat_free(&v9stat);
 v9fs_path_free(&path);
-saved_dir_pos = dent->d_off;
+saved_dir_pos = v9fs_dent_telldir(pdu, fidp, dent);
+if (saved_dir_pos < 0) {
+err = saved_dir_pos;
+break;
+}
 }
 
 v9fs_readdir_unlock(&fidp->fs.dir);
@@ -2420,6 +2443,7 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu, 
V9fsFidState *fidp,
 V9fsString name;
 int len, err = 0;
 int32_t count = 0;
+off_t off;
 struct dirent *dent;
 struct stat *st;
 struct V9fsDirEnt *entries = NULL;
@@ -2480,12 +2504,17 @@ static int coroutine_fn v9fs_do_readdir(V9fsPDU *pdu, 
V9fsFidState *fidp,
 qid.version = 0;
 }
 
+off = v9fs_dent_telldir(pdu, fidp, dent);
+if (off < 0) {
+err = off;
+break;
+}
 v9fs_string_init(&name);
 v9fs_string_sprintf(&name, "%s", dent->d_name);
 
 /* 11 = 7 + 4 (7 = start offset, 4 = space for storing count) */
 len = pdu_marshal(pdu, 11 + count, "Qqbs",
-  &qid, dent->d_off,
+  &qid, off,
   dent->d_type, &name);
 
 v9fs_string_free(&name);
diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c
index 032cce04c4..78aca1d98b 100644
--- a/hw/9pfs/codir.c
+++ b/hw/9pfs/codir.c
@@ -167,7 +167,11 @@ static int do_readdir_many(V9fsPDU *pdu, V9fsFidState 
*fidp,
 }
 
 size += len;
+#ifdef CONFIG_DARWIN
+saved_dir_pos = telldir(fidp->fs.dir.stream);
+#else
 saved_dir_pos = dent->d_off;
+#endif
 }
 
 /* restore (last) saved position */
-- 
2.34.0




[PATCH v2 10/11] 9p: darwin: Implement compatibility for mknodat

2021-11-21 Thread Will Cohen
From: Keno Fischer 

Darwin does not support mknodat. However, to avoid race conditions
with later setting the permissions, we must avoid using mknod on
the full path instead. We could try to fchdir, but that would cause
problems if multiple threads try to call mknodat at the same time.
However, luckily there is a solution: Darwin as an (unexposed in the
C library) system call that sets the cwd for the current thread only.
This should suffice to use mknod safely.

Signed-off-by: Keno Fischer 
Signed-off-by: Michael Roitzsch 
[Will Cohen: - Adjust coding style]
Signed-off-by: Will Cohen 
---
 hw/9pfs/9p-local.c   |  5 +++--
 hw/9pfs/9p-util-darwin.c | 33 +
 hw/9pfs/9p-util-linux.c  |  5 +
 hw/9pfs/9p-util.h|  2 ++
 4 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index 4268703d05..42b65e143b 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -673,7 +673,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath 
*dir_path,
 
 if (fs_ctx->export_flags & V9FS_SM_MAPPED ||
 fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
-err = mknodat(dirfd, name, fs_ctx->fmode | S_IFREG, 0);
+err = qemu_mknodat(dirfd, name, fs_ctx->fmode | S_IFREG, 0);
 if (err == -1) {
 goto out;
 }
@@ -688,7 +688,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath 
*dir_path,
 }
 } else if (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH ||
fs_ctx->export_flags & V9FS_SM_NONE) {
-err = mknodat(dirfd, name, credp->fc_mode, credp->fc_rdev);
+err = qemu_mknodat(dirfd, name, credp->fc_mode, credp->fc_rdev);
 if (err == -1) {
 goto out;
 }
@@ -701,6 +701,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath 
*dir_path,
 
 err_end:
 unlinkat_preserve_errno(dirfd, name, 0);
+
 out:
 close_preserve_errno(dirfd);
 return err;
diff --git a/hw/9pfs/9p-util-darwin.c b/hw/9pfs/9p-util-darwin.c
index ac414bcbfd..25e67d5067 100644
--- a/hw/9pfs/9p-util-darwin.c
+++ b/hw/9pfs/9p-util-darwin.c
@@ -158,3 +158,36 @@ done:
 close_preserve_errno(fd);
 return ret;
 }
+
+#ifndef SYS___pthread_fchdir
+# define SYS___pthread_fchdir 349
+#endif
+
+/*
+ * This is an undocumented OS X syscall. It would be best to avoid it,
+ * but there doesn't seem to be another safe way to implement mknodat.
+ * Dear Apple, please implement mknodat before you remove this syscall.
+ */
+static int fchdir_thread_local(int fd)
+{
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+return syscall(SYS___pthread_fchdir, fd);
+#pragma clang diagnostic pop
+}
+
+int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev)
+{
+int preserved_errno, err;
+if (fchdir_thread_local(dirfd) < 0) {
+return -1;
+}
+err = mknod(filename, mode, dev);
+preserved_errno = errno;
+/* Stop using the thread-local cwd */
+fchdir_thread_local(-1);
+if (err < 0) {
+errno = preserved_errno;
+}
+return err;
+}
diff --git a/hw/9pfs/9p-util-linux.c b/hw/9pfs/9p-util-linux.c
index d54bf57a59..4f57d8c047 100644
--- a/hw/9pfs/9p-util-linux.c
+++ b/hw/9pfs/9p-util-linux.c
@@ -68,3 +68,8 @@ int utimensat_nofollow(int dirfd, const char *filename,
 {
 return utimensat(dirfd, filename, times, AT_SYMLINK_NOFOLLOW);
 }
+
+int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev)
+{
+return mknodat(dirfd, filename, mode, dev);
+}
diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h
index 1c477a0e66..cac682d335 100644
--- a/hw/9pfs/9p-util.h
+++ b/hw/9pfs/9p-util.h
@@ -105,4 +105,6 @@ ssize_t fremovexattrat_nofollow(int dirfd, const char 
*filename,
 int utimensat_nofollow(int dirfd, const char *filename,
const struct timespec times[2]);
 
+int qemu_mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev);
+
 #endif
-- 
2.34.0




[PATCH v2 02/11] 9p: Rename 9p-util -> 9p-util-linux

2021-11-21 Thread Will Cohen
From: Keno Fischer 

The current file only has the Linux versions of these functions.
Rename the file accordingly and update the Makefile to only build
it on Linux. A Darwin version of these will follow later in the
series.

Signed-off-by: Keno Fischer 
[Michael Roitzsch: - Rebase for NixOS]
Signed-off-by: Michael Roitzsch 
Signed-off-by: Will Cohen 
---
 hw/9pfs/{9p-util.c => 9p-util-linux.c} | 2 +-
 hw/9pfs/meson.build| 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
 rename hw/9pfs/{9p-util.c => 9p-util-linux.c} (97%)

diff --git a/hw/9pfs/9p-util.c b/hw/9pfs/9p-util-linux.c
similarity index 97%
rename from hw/9pfs/9p-util.c
rename to hw/9pfs/9p-util-linux.c
index 3221d9b498..398614a5d0 100644
--- a/hw/9pfs/9p-util.c
+++ b/hw/9pfs/9p-util-linux.c
@@ -1,5 +1,5 @@
 /*
- * 9p utilities
+ * 9p utilities (Linux Implementation)
  *
  * Copyright IBM, Corp. 2017
  *
diff --git a/hw/9pfs/meson.build b/hw/9pfs/meson.build
index 99be5d9119..1b28e70040 100644
--- a/hw/9pfs/meson.build
+++ b/hw/9pfs/meson.build
@@ -4,7 +4,6 @@ fs_ss.add(files(
   '9p-posix-acl.c',
   '9p-proxy.c',
   '9p-synth.c',
-  '9p-util.c',
   '9p-xattr-user.c',
   '9p-xattr.c',
   '9p.c',
@@ -14,6 +13,7 @@ fs_ss.add(files(
   'coth.c',
   'coxattr.c',
 ))
+fs_ss.add(when: 'CONFIG_LINUX', if_true: files('9p-util-linux.c'))
 fs_ss.add(when: 'CONFIG_XEN', if_true: files('xen-9p-backend.c'))
 softmmu_ss.add_all(when: 'CONFIG_FSDEV_9P', if_true: fs_ss)
 
-- 
2.34.0




[PATCH v2 11/11] 9p: darwin: meson: Allow VirtFS on Darwin

2021-11-21 Thread Will Cohen
From: Keno Fischer 

Signed-off-by: Keno Fischer 
[Michael Roitzsch: - Rebase for NixOS]
Signed-off-by: Michael Roitzsch 
[Will Cohen: - Rebase to master]
Signed-off-by: Will Cohen 
---
 fsdev/meson.build |  1 +
 meson.build   | 12 
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/fsdev/meson.build b/fsdev/meson.build
index adf57cc43e..b632b66348 100644
--- a/fsdev/meson.build
+++ b/fsdev/meson.build
@@ -7,6 +7,7 @@ fsdev_ss.add(when: ['CONFIG_FSDEV_9P'], if_true: files(
   'qemu-fsdev.c',
 ), if_false: files('qemu-fsdev-dummy.c'))
 softmmu_ss.add_all(when: 'CONFIG_LINUX', if_true: fsdev_ss)
+softmmu_ss.add_all(when: 'CONFIG_DARWIN', if_true: fsdev_ss)
 
 if have_virtfs_proxy_helper
   executable('virtfs-proxy-helper',
diff --git a/meson.build b/meson.build
index 96de1a6ef9..0f92adea52 100644
--- a/meson.build
+++ b/meson.build
@@ -1383,17 +1383,21 @@ endif
 have_host_block_device = (targetos != 'darwin' or
 cc.has_header('IOKit/storage/IOMedia.h'))
 
-have_virtfs = (targetos == 'linux' and
+if targetos == 'darwin'
+  have_virtfs = have_system
+else
+  have_virtfs = (targetos == 'linux' and
 have_system and
 libattr.found() and
 libcap_ng.found())
+endif
 
-have_virtfs_proxy_helper = have_virtfs and have_tools
+have_virtfs_proxy_helper = targetos == 'linux' and have_virtfs and have_tools
 
 if get_option('virtfs').enabled()
   if not have_virtfs
-if targetos != 'linux'
-  error('virtio-9p (virtfs) requires Linux')
+if targetos != 'linux' and targetos != 'darwin'
+  error('virtio-9p (virtfs) requires Linux or Darwin')
 elif not libcap_ng.found() or not libattr.found()
   error('virtio-9p (virtfs) requires libcap-ng-devel and libattr-devel')
 elif not have_system
-- 
2.34.0




[PATCH v2 06/11] 9p: darwin: Compatibility defn for XATTR_SIZE_MAX

2021-11-21 Thread Will Cohen
From: Keno Fischer 

Signed-off-by: Keno Fischer 
Signed-off-by: Michael Roitzsch 
[Will Cohen: - Adjust coding style]
Signed-off-by: Will Cohen 
---
 hw/9pfs/9p.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index c941b46f60..d671995aa4 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -3943,6 +3943,14 @@ out_nofid:
 v9fs_string_free(&name);
 }
 
+#if defined(CONFIG_DARWIN) && !defined(XATTR_SIZE_MAX)
+/*
+ * Darwin doesn't seem to define a maximum xattr size in its user
+ * space header, but looking at the kernel source, HFS supports
+ *  up to INT32_MAX, so use that as the maximum.
+ */
+#define XATTR_SIZE_MAX INT32_MAX
+#endif
 static void coroutine_fn v9fs_xattrcreate(void *opaque)
 {
 int flags, rflags = 0;
-- 
2.34.0




[PATCH v2 07/11] 9p: darwin: *xattr_nofollow implementations

2021-11-21 Thread Will Cohen
From: Keno Fischer 

This implements the darwin equivalent of the functions that were
moved to 9p-util(-linux) earlier in this series in the new
9p-util-darwin file.

Signed-off-by: Keno Fischer 
[Michael Roitzsch: - Rebase for NixOS]
Signed-off-by: Michael Roitzsch 
Signed-off-by: Will Cohen 
---
 hw/9pfs/9p-util-darwin.c | 64 
 hw/9pfs/meson.build  |  1 +
 2 files changed, 65 insertions(+)
 create mode 100644 hw/9pfs/9p-util-darwin.c

diff --git a/hw/9pfs/9p-util-darwin.c b/hw/9pfs/9p-util-darwin.c
new file mode 100644
index 00..cdb4c9e24c
--- /dev/null
+++ b/hw/9pfs/9p-util-darwin.c
@@ -0,0 +1,64 @@
+/*
+ * 9p utilities (Darwin Implementation)
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/xattr.h"
+#include "9p-util.h"
+
+ssize_t fgetxattrat_nofollow(int dirfd, const char *filename, const char *name,
+ void *value, size_t size)
+{
+int ret;
+int fd = openat_file(dirfd, filename,
+ O_RDONLY | O_PATH_9P_UTIL | O_NOFOLLOW, 0);
+if (fd == -1) {
+return -1;
+}
+ret = fgetxattr(fd, name, value, size, 0, 0);
+close_preserve_errno(fd);
+return ret;
+}
+
+ssize_t flistxattrat_nofollow(int dirfd, const char *filename,
+  char *list, size_t size)
+{
+int ret;
+int fd = openat_file(dirfd, filename,
+ O_RDONLY | O_PATH_9P_UTIL | O_NOFOLLOW, 0);
+if (fd == -1) {
+return -1;
+}
+ret = flistxattr(fd, list, size, 0);
+close_preserve_errno(fd);
+return ret;
+}
+
+ssize_t fremovexattrat_nofollow(int dirfd, const char *filename,
+const char *name)
+{
+int ret;
+int fd = openat_file(dirfd, filename, O_PATH_9P_UTIL | O_NOFOLLOW, 0);
+if (fd == -1) {
+return -1;
+}
+ret = fremovexattr(fd, name, 0);
+close_preserve_errno(fd);
+return ret;
+}
+
+int fsetxattrat_nofollow(int dirfd, const char *filename, const char *name,
+ void *value, size_t size, int flags)
+{
+int ret;
+int fd = openat_file(dirfd, filename, O_PATH_9P_UTIL | O_NOFOLLOW, 0);
+if (fd == -1) {
+return -1;
+}
+ret = fsetxattr(fd, name, value, size, 0, flags);
+close_preserve_errno(fd);
+return ret;
+}
diff --git a/hw/9pfs/meson.build b/hw/9pfs/meson.build
index 1b28e70040..12443b6ad5 100644
--- a/hw/9pfs/meson.build
+++ b/hw/9pfs/meson.build
@@ -14,6 +14,7 @@ fs_ss.add(files(
   'coxattr.c',
 ))
 fs_ss.add(when: 'CONFIG_LINUX', if_true: files('9p-util-linux.c'))
+fs_ss.add(when: 'CONFIG_DARWIN', if_true: files('9p-util-darwin.c'))
 fs_ss.add(when: 'CONFIG_XEN', if_true: files('xen-9p-backend.c'))
 softmmu_ss.add_all(when: 'CONFIG_FSDEV_9P', if_true: fs_ss)
 
-- 
2.34.0




[PATCH v2 05/11] 9p: darwin: Ignore O_{NOATIME, DIRECT}

2021-11-21 Thread Will Cohen
From: Keno Fischer 

Darwin doesn't have either of these flags. Darwin does have
F_NOCACHE, which is similar to O_DIRECT, but has different
enough semantics that other projects don't generally map
them automatically. In any case, we don't support O_DIRECT
on Linux at the moment either.

Signed-off-by: Keno Fischer 
[Michael Roitzsch: - Rebase for NixOS]
Signed-off-by: Michael Roitzsch 
[Will Cohen: - Adjust coding style]
Signed-off-by: Will Cohen 
---
 hw/9pfs/9p-util.h |  2 ++
 hw/9pfs/9p.c  | 13 -
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/hw/9pfs/9p-util.h b/hw/9pfs/9p-util.h
index 546f46dc7d..627baebaba 100644
--- a/hw/9pfs/9p-util.h
+++ b/hw/9pfs/9p-util.h
@@ -41,6 +41,7 @@ again:
 fd = openat(dirfd, name, flags | O_NOFOLLOW | O_NOCTTY | O_NONBLOCK,
 mode);
 if (fd == -1) {
+#ifndef CONFIG_DARWIN
 if (errno == EPERM && (flags & O_NOATIME)) {
 /*
  * The client passed O_NOATIME but we lack permissions to honor it.
@@ -53,6 +54,7 @@ again:
 flags &= ~O_NOATIME;
 goto again;
 }
+#endif
 return -1;
 }
 
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index c06e8a85a0..c941b46f60 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -137,11 +137,20 @@ static int dotl_to_open_flags(int flags)
 { P9_DOTL_NONBLOCK, O_NONBLOCK } ,
 { P9_DOTL_DSYNC, O_DSYNC },
 { P9_DOTL_FASYNC, FASYNC },
+#ifndef CONFIG_DARWIN
+{ P9_DOTL_NOATIME, O_NOATIME },
+/*
+ *  On Darwin, we could map to F_NOCACHE, which is
+ *  similar, but doesn't quite have the same
+ *  semantics. However, we don't support O_DIRECT
+ *  even on linux at the moment, so we just ignore
+ *  it here.
+ */
 { P9_DOTL_DIRECT, O_DIRECT },
+#endif
 { P9_DOTL_LARGEFILE, O_LARGEFILE },
 { P9_DOTL_DIRECTORY, O_DIRECTORY },
 { P9_DOTL_NOFOLLOW, O_NOFOLLOW },
-{ P9_DOTL_NOATIME, O_NOATIME },
 { P9_DOTL_SYNC, O_SYNC },
 };
 
@@ -170,10 +179,12 @@ static int get_dotl_openflags(V9fsState *s, int oflags)
  */
 flags = dotl_to_open_flags(oflags);
 flags &= ~(O_NOCTTY | O_ASYNC | O_CREAT);
+#ifndef CONFIG_DARWIN
 /*
  * Ignore direct disk access hint until the server supports it.
  */
 flags &= ~O_DIRECT;
+#endif
 return flags;
 }
 
-- 
2.34.0




[PATCH v2 03/11] 9p: darwin: Handle struct stat(fs) differences

2021-11-21 Thread Will Cohen
From: Keno Fischer 

Signed-off-by: Keno Fischer 
Signed-off-by: Michael Roitzsch 
Signed-off-by: Will Cohen 
---
 hw/9pfs/9p-proxy.c | 17 ++---
 hw/9pfs/9p-synth.c |  2 ++
 hw/9pfs/9p.c   | 16 ++--
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c
index 09bd9f1464..be1546c1be 100644
--- a/hw/9pfs/9p-proxy.c
+++ b/hw/9pfs/9p-proxy.c
@@ -123,10 +123,15 @@ static void prstatfs_to_statfs(struct statfs *stfs, 
ProxyStatFS *prstfs)
 stfs->f_bavail = prstfs->f_bavail;
 stfs->f_files = prstfs->f_files;
 stfs->f_ffree = prstfs->f_ffree;
+#ifdef CONFIG_DARWIN
+stfs->f_fsid.val[0] = prstfs->f_fsid[0] & 0xU;
+stfs->f_fsid.val[1] = prstfs->f_fsid[1] >> 32 & 0xU;
+#else
 stfs->f_fsid.__val[0] = prstfs->f_fsid[0] & 0xU;
 stfs->f_fsid.__val[1] = prstfs->f_fsid[1] >> 32 & 0xU;
 stfs->f_namelen = prstfs->f_namelen;
 stfs->f_frsize = prstfs->f_frsize;
+#endif
 }
 
 /* Converts proxy_stat structure to VFS stat structure */
@@ -143,12 +148,18 @@ static void prstat_to_stat(struct stat *stbuf, ProxyStat 
*prstat)
stbuf->st_size = prstat->st_size;
stbuf->st_blksize = prstat->st_blksize;
stbuf->st_blocks = prstat->st_blocks;
-   stbuf->st_atim.tv_sec = prstat->st_atim_sec;
-   stbuf->st_atim.tv_nsec = prstat->st_atim_nsec;
+   stbuf->st_atime = prstat->st_atim_sec;
stbuf->st_mtime = prstat->st_mtim_sec;
-   stbuf->st_mtim.tv_nsec = prstat->st_mtim_nsec;
stbuf->st_ctime = prstat->st_ctim_sec;
+#ifdef CONFIG_DARWIN
+   stbuf->st_atimespec.tv_nsec = prstat->st_atim_nsec;
+   stbuf->st_mtimespec.tv_nsec = prstat->st_mtim_nsec;
+   stbuf->st_ctimespec.tv_nsec = prstat->st_ctim_nsec;
+#else
+   stbuf->st_atim.tv_nsec = prstat->st_atim_nsec;
+   stbuf->st_mtim.tv_nsec = prstat->st_mtim_nsec;
stbuf->st_ctim.tv_nsec = prstat->st_ctim_nsec;
+#endif
 }
 
 /*
diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c
index b38088e066..4a4a776d06 100644
--- a/hw/9pfs/9p-synth.c
+++ b/hw/9pfs/9p-synth.c
@@ -427,7 +427,9 @@ static int synth_statfs(FsContext *s, V9fsPath *fs_path,
 stbuf->f_bsize = 512;
 stbuf->f_blocks = 0;
 stbuf->f_files = synth_node_count;
+#ifndef CONFIG_DARWIN
 stbuf->f_namelen = NAME_MAX;
+#endif
 return 0;
 }
 
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 9c63e14b28..f4f0c200c7 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -1313,11 +1313,17 @@ static int stat_to_v9stat_dotl(V9fsPDU *pdu, const 
struct stat *stbuf,
 v9lstat->st_blksize = stat_to_iounit(pdu, stbuf);
 v9lstat->st_blocks = stbuf->st_blocks;
 v9lstat->st_atime_sec = stbuf->st_atime;
-v9lstat->st_atime_nsec = stbuf->st_atim.tv_nsec;
 v9lstat->st_mtime_sec = stbuf->st_mtime;
-v9lstat->st_mtime_nsec = stbuf->st_mtim.tv_nsec;
 v9lstat->st_ctime_sec = stbuf->st_ctime;
+#ifdef CONFIG_DARWIN
+v9lstat->st_atime_nsec = stbuf->st_atimespec.tv_nsec;
+v9lstat->st_mtime_nsec = stbuf->st_mtimespec.tv_nsec;
+v9lstat->st_ctime_nsec = stbuf->st_ctimespec.tv_nsec;
+#else
+v9lstat->st_atime_nsec = stbuf->st_atim.tv_nsec;
+v9lstat->st_mtime_nsec = stbuf->st_mtim.tv_nsec;
 v9lstat->st_ctime_nsec = stbuf->st_ctim.tv_nsec;
+#endif
 /* Currently we only support BASIC fields in stat */
 v9lstat->st_result_mask = P9_STATS_BASIC;
 
@@ -3519,9 +3525,15 @@ static int v9fs_fill_statfs(V9fsState *s, V9fsPDU *pdu, 
struct statfs *stbuf)
 f_bavail = stbuf->f_bavail / bsize_factor;
 f_files  = stbuf->f_files;
 f_ffree  = stbuf->f_ffree;
+#ifdef CONFIG_DARWIN
+fsid_val = (unsigned int)stbuf->f_fsid.val[0] |
+   (unsigned long long)stbuf->f_fsid.val[1] << 32;
+f_namelen = MAXNAMLEN;
+#else
 fsid_val = (unsigned int) stbuf->f_fsid.__val[0] |
(unsigned long long)stbuf->f_fsid.__val[1] << 32;
 f_namelen = stbuf->f_namelen;
+#endif
 
 return pdu_marshal(pdu, offset, "ddqqd",
f_type, f_bsize, f_blocks, f_bfree,
-- 
2.34.0




[PATCH v2 09/11] 9p: darwin: Provide fallback impl for utimensat

2021-11-21 Thread Will Cohen
From: Keno Fischer 

This function is new in Mac OS 10.13. Provide a fallback implementation
when building against older SDKs. The complication in the definition comes
having to separately handle the used SDK version and the target OS version.

- If the SDK version is too low (__MAC_10_13 not defined), utimensat is not
  defined in the header, so we must not try to use it (doing so would error).
- Otherwise, if the targetted OS version is at least 10.13, we know this
  function is available, so we can unconditionally call it.
- Lastly, we check for the availability of the __builtin_available macro to
  potentially insert a dynamic check for this OS version. However, 
__builtin_available
  is only available with sufficiently recent versions of clang and while all
  Apple clang versions that ship with Xcode versions that support the 10.13
  SDK support with builtin, we want to allow building with compilers other
  than Apple clang that may not support this builtin.

Signed-off-by: Keno Fischer 
Signed-off-by: Michael Roitzsch 
Signed-off-by: Will Cohen 
---
 hw/9pfs/9p-local.c   |  2 +-
 hw/9pfs/9p-util-darwin.c | 96 
 hw/9pfs/9p-util-linux.c  |  6 +++
 hw/9pfs/9p-util.h|  8 
 hw/9pfs/9p.c |  1 +
 5 files changed, 112 insertions(+), 1 deletion(-)

diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index 2bfff79b12..4268703d05 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -1076,7 +1076,7 @@ static int local_utimensat(FsContext *s, V9fsPath 
*fs_path,
 goto out;
 }
 
-ret = utimensat(dirfd, name, buf, AT_SYMLINK_NOFOLLOW);
+ret = utimensat_nofollow(dirfd, name, buf);
 close_preserve_errno(dirfd);
 out:
 g_free(dirpath);
diff --git a/hw/9pfs/9p-util-darwin.c b/hw/9pfs/9p-util-darwin.c
index cdb4c9e24c..ac414bcbfd 100644
--- a/hw/9pfs/9p-util-darwin.c
+++ b/hw/9pfs/9p-util-darwin.c
@@ -62,3 +62,99 @@ int fsetxattrat_nofollow(int dirfd, const char *filename, 
const char *name,
 close_preserve_errno(fd);
 return ret;
 }
+
+#ifndef __has_builtin
+#define __has_builtin(x) 0
+#endif
+
+static int update_times_from_stat(int fd, struct timespec times[2],
+  int update0, int update1)
+{
+struct stat buf;
+int ret = fstat(fd, &buf);
+if (ret == -1) {
+return ret;
+}
+if (update0) {
+times[0] = buf.st_atimespec;
+}
+if (update1) {
+times[1] = buf.st_mtimespec;
+}
+return 0;
+}
+
+int utimensat_nofollow(int dirfd, const char *filename,
+   const struct timespec times_in[2])
+{
+int ret, fd;
+int special0, special1;
+struct timeval futimes_buf[2];
+struct timespec times[2];
+memcpy(times, times_in, 2 * sizeof(struct timespec));
+
+/* Check whether we have an SDK version that defines utimensat */
+#if defined(__MAC_10_13)
+# if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_13
+#  define UTIMENSAT_AVAILABLE 1
+# elif __has_builtin(__builtin_available)
+#  define UTIMENSAT_AVAILABLE __builtin_available(macos 10.13, *)
+# else
+#  define UTIMENSAT_AVAILABLE 0
+# endif
+if (UTIMENSAT_AVAILABLE) {
+return utimensat(dirfd, filename, times, AT_SYMLINK_NOFOLLOW);
+}
+#endif
+
+/* utimensat not available. Use futimes. */
+fd = openat_file(dirfd, filename, O_PATH_9P_UTIL | O_NOFOLLOW, 0);
+if (fd == -1) {
+return -1;
+}
+
+special0 = times[0].tv_nsec == UTIME_OMIT;
+special1 = times[1].tv_nsec == UTIME_OMIT;
+if (special0 || special1) {
+/* If both are set, nothing to do */
+if (special0 && special1) {
+ret = 0;
+goto done;
+}
+
+ret = update_times_from_stat(fd, times, special0, special1);
+if (ret < 0) {
+goto done;
+}
+}
+
+special0 = times[0].tv_nsec == UTIME_NOW;
+special1 = times[1].tv_nsec == UTIME_NOW;
+if (special0 || special1) {
+ret = futimes(fd, NULL);
+if (ret < 0) {
+goto done;
+}
+
+/* If both are set, we are done */
+if (special0 && special1) {
+ret = 0;
+goto done;
+}
+
+ret = update_times_from_stat(fd, times, special0, special1);
+if (ret < 0) {
+goto done;
+}
+}
+
+futimes_buf[0].tv_sec = times[0].tv_sec;
+futimes_buf[0].tv_usec = times[0].tv_nsec / 1000;
+futimes_buf[1].tv_sec = times[1].tv_sec;
+futimes_buf[1].tv_usec = times[1].tv_nsec / 1000;
+ret = futimes(fd, futimes_buf);
+
+done:
+close_preserve_errno(fd);
+return ret;
+}
diff --git a/hw/9pfs/9p-util-linux.c b/hw/9pfs/9p-util-linux.c
index 398614a5d0..d54bf57a59 100644
--- a/hw/9pfs/9p-util-linux.c
+++ b/hw/9pfs/9p-util-linux.c
@@ -62,3 +62,9 @@ int fsetxattrat_nofollow(int dirfd, const char *filename, 
const char *name,
 g_free(proc_path);
 return ret;
 }
+
+int utimensat_nofollow(int dirfd, const char *fil

Re: [RFC PATCH v2 1/7] target/riscv: rvk: add cfg properties for zbk* and zk*

2021-11-21 Thread Alistair Francis
On Tue, Nov 16, 2021 at 6:11 PM liweiwei  wrote:
>
> Signed-off-by: liweiwei 
> Signed-off-by: wangjunqiang 

Acked-by: Alistair Francis 

Alistair

> ---
>  target/riscv/cpu.c | 23 +++
>  target/riscv/cpu.h | 13 +
>  2 files changed, 36 insertions(+)
>
> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> index f812998123..a5ec182a86 100644
> --- a/target/riscv/cpu.c
> +++ b/target/riscv/cpu.c
> @@ -491,6 +491,29 @@ static void riscv_cpu_realize(DeviceState *dev, Error 
> **errp)
>  cpu->cfg.ext_d = true;
>  }
>
> +if (cpu->cfg.ext_zk) {
> +cpu->cfg.ext_zkn = true;
> +cpu->cfg.ext_zkr = true;
> +cpu->cfg.ext_zkt = true;
> +}
> +
> +if (cpu->cfg.ext_zkn) {
> +cpu->cfg.ext_zbkb = true;
> +cpu->cfg.ext_zbkc = true;
> +cpu->cfg.ext_zbkx = true;
> +cpu->cfg.ext_zkne = true;
> +cpu->cfg.ext_zknd = true;
> +cpu->cfg.ext_zknh = true;
> +}
> +
> +if (cpu->cfg.ext_zks) {
> +cpu->cfg.ext_zbkb = true;
> +cpu->cfg.ext_zbkc = true;
> +cpu->cfg.ext_zbkx = true;
> +cpu->cfg.ext_zksed = true;
> +cpu->cfg.ext_zksh = true;
> +}
> +
>  /* Set the ISA extensions, checks should have happened above */
>  if (cpu->cfg.ext_i) {
>  ext |= RVI;
> diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> index 0760c0af93..74e8be4847 100644
> --- a/target/riscv/cpu.h
> +++ b/target/riscv/cpu.h
> @@ -308,7 +308,20 @@ struct RISCVCPU {
>  bool ext_zba;
>  bool ext_zbb;
>  bool ext_zbc;
> +bool ext_zbkb;
> +bool ext_zbkc;
> +bool ext_zbkx;
>  bool ext_zbs;
> +bool ext_zk;
> +bool ext_zkn;
> +bool ext_zknd;
> +bool ext_zkne;
> +bool ext_zknh;
> +bool ext_zkr;
> +bool ext_zks;
> +bool ext_zksed;
> +bool ext_zksh;
> +bool ext_zkt;
>  bool ext_counters;
>  bool ext_ifencei;
>  bool ext_icsr;
> --
> 2.17.1
>
>



Re: [PATCH 2/3] virtio-net: Only enable userland vq if using tap backend

2021-11-21 Thread Jason Wang
On Fri, Nov 19, 2021 at 3:50 PM Eugenio Perez Martin
 wrote:
>
> On Fri, Nov 19, 2021 at 3:44 AM Jason Wang  wrote:
> >
> > On Thu, Nov 18, 2021 at 3:57 PM Eugenio Perez Martin
> >  wrote:
> > >
> > > On Thu, Nov 18, 2021 at 6:06 AM Jason Wang  wrote:
> > > >
> > > > On Thu, Nov 18, 2021 at 3:29 AM Eugenio Pérez  
> > > > wrote:
> > > > >
> > > > > Qemu falls back on userland handlers even if vhost-user and vhost-vdpa
> > > > > cases. These assumes a tap device can handle the packets.
> > > > >
> > > > > If a vdpa device fail to start, it can trigger a sigsegv because of
> > > > > that. Do not resort on them unless actually possible.
> > > >
> > > > It would be better to show the calltrace here then we can see the root 
> > > > cause.
> > > >
> > >
> > > Sure, I'll paste here and I'll resend to the next version:
> > > #1  0x55955f696e92 in nc_sendv_compat (flags=,
> > > iovcnt=2, iov=0x7ffe73abe300, nc=0x7fcf22d6d010) at ../net/net.c:756
> > > #2  qemu_deliver_packet_iov (sender=,
> > > opaque=0x7fcf22d6d010, iovcnt=2, iov=0x7ffe73abe300, flags= > > out>) at ../net/net.c:784
> > > #3  qemu_deliver_packet_iov (sender=, flags= > > out>, iov=0x7ffe73abe300, iovcnt=2, opaque=0x7fcf22d6d010) at
> > > ../net/net.c:763
> > > #4  0x55955f69a078 in qemu_net_queue_deliver_iov (iovcnt=2,
> > > iov=0x7ffe73abe300, flags=0, sender=0x5595631f5ac0,
> > > queue=0x559561c7baa0) at ../net/queue.c:179
> > > #5  qemu_net_queue_send_iov (queue=0x559561c7baa0,
> > > sender=0x5595631f5ac0, flags=flags@entry=0,
> > > iov=iov@entry=0x7ffe73abe300,
> > > iovcnt=iovcnt@entry=2, sent_cb=sent_cb@entry=0x55955f82ae60
> > > ) at ../net/queue.c:246
> > > #6  0x55955f697d43 in qemu_sendv_packet_async
> > > (sent_cb=0x55955f82ae60 , iovcnt=2,
> > > iov=0x7ffe73abe300,
> > > sender=) at ../net/net.c:825
> > > #7  qemu_sendv_packet_async (sender=,
> > > iov=iov@entry=0x7ffe73abe300, iovcnt=iovcnt@entry=1662966768,
> > > sent_cb=sent_cb@entry=0x55955f82ae60 ) at
> > > ../net/net.c:794
> > > #8  0x55955f82aba9 in virtio_net_flush_tx (q=0x0,
> > > q@entry=0x5595631edbf0) at ../hw/net/virtio-net.c:2577
> > > #9  0x55955f82ade8 in virtio_net_tx_bh (opaque=0x5595631edbf0) at
> > > ../hw/net/virtio-net.c:2694
> > > #10 0x55955f9e847d in aio_bh_call (bh=0x559561c7e590) at 
> > > ../util/async.c:169
> > > #11 aio_bh_poll (ctx=ctx@entry=0x559561c81650) at ../util/async.c:169
> > > #12 0x55955f9d6912 in aio_dispatch (ctx=0x559561c81650) at
> > > ../util/aio-posix.c:381
> > > #13 0x55955f9e8322 in aio_ctx_dispatch (source=,
> > > callback=, user_data=)
> > > at ../util/async.c:311
> > > #14 0x7fcf20a5495d in g_main_context_dispatch () from
> > > /lib64/libglib-2.0.so.0
> > > #15 0x55955f9f2fc0 in glib_pollfds_poll () at ../util/main-loop.c:232
> > > #16 os_host_main_loop_wait (timeout=) at 
> > > ../util/main-loop.c:255
> > > #17 main_loop_wait (nonblocking=nonblocking@entry=0) at 
> > > ../util/main-loop.c:531
> > > #18 0x55955f7eee49 in qemu_main_loop () at ../softmmu/runstate.c:726
> > > #19 0x55955f6235c2 in main (argc=, argv= > > out>, envp=) at ../softmmu/main.c:50
> > >
> > > In nc_sendv_compat, nc->info is net_vhost_vdpa_info, so
> > > nc->info->receive is NULL.
> > >
> > > > >
> > > > > Signed-off-by: Eugenio Pérez 
> > > > > ---
> > > > >  include/hw/virtio/virtio.h |  2 ++
> > > > >  hw/net/virtio-net.c|  4 
> > > > >  hw/virtio/virtio.c | 21 +
> > > > >  3 files changed, 19 insertions(+), 8 deletions(-)
> > > > >
> > > > > diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> > > > > index 8bab9cfb75..1712ba0b4c 100644
> > > > > --- a/include/hw/virtio/virtio.h
> > > > > +++ b/include/hw/virtio/virtio.h
> > > > > @@ -105,6 +105,8 @@ struct VirtIODevice
> > > > >  VMChangeStateEntry *vmstate;
> > > > >  char *bus_name;
> > > > >  uint8_t device_endian;
> > > > > +/* backend does not support userspace handler */
> > > > > +bool disable_ioeventfd_handler;
> > > > >  bool use_guest_notifier_mask;
> > > > >  AddressSpace *dma_as;
> > > > >  QLIST_HEAD(, VirtQueue) *vector_queues;
> > > > > diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> > > > > index 004acf858f..8c5c4e5a9d 100644
> > > > > --- a/hw/net/virtio-net.c
> > > > > +++ b/hw/net/virtio-net.c
> > > > > @@ -3501,6 +3501,10 @@ static void 
> > > > > virtio_net_device_realize(DeviceState *dev, Error **errp)
> > > > >  nc = qemu_get_queue(n->nic);
> > > > >  nc->rxfilter_notify_enabled = 1;
> > > > >
> > > > > +if (!nc->peer || nc->peer->info->type != NET_CLIENT_DRIVER_TAP) {
> > > > > +/* Only tap can use userspace networking */
> > > > > +vdev->disable_ioeventfd_handler = true;
> > > > > +}
> > > > >  if (nc->peer && nc->peer->info->type == 
> > > > > NET_CLIENT_DRIVER_VHOST_VDPA) {
> > > > >  struct virtio_net_config netcfg = {};
> > > > >  memcpy(&netcfg.mac, &n->nic_conf.ma

Re: [PATCH v5 3/6] net/vmnet: implement shared mode (vmnet-shared)

2021-11-21 Thread Jason Wang
On Fri, Nov 19, 2021 at 6:10 PM Vladislav Yaroshchuk
 wrote:
>
>
>
> пт, 19 нояб. 2021 г. в 05:57, Jason Wang :
>>
>> On Fri, Nov 19, 2021 at 1:12 AM Vladislav Yaroshchuk
>>  wrote:
>> >
>> >
>> >
>> > пн, 15 нояб. 2021 г. в 07:47, Jason Wang :
>> >>
>> >> On Fri, Nov 12, 2021 at 5:14 PM Vladislav Yaroshchuk
>> >>  wrote:
>> >> >
>> >> > Signed-off-by: Phillip Tennen 
>> >> > Signed-off-by: Vladislav Yaroshchuk 
>> >> > ---
>> >>
>> >> Commit log please.
>> >>
>> >>
>> >
>> > Sorry, I don't understand what you mean here.
>> > What is the 'commit log'?
>>
>> I meant the change log to describe the changes.
>>
>
> You mean more detailed commit message?

(replied twice, missing the list for the first time)

Yes, with a patch more than 300+ lines of changes, we need a good change log.

Thanks

> If not, can you please provide a short example
>
>> >
>> >>
>> >> >  net/vmnet-common.m | 305 +
>> >> >  net/vmnet-shared.c |  75 ++-
>> >> >  net/vmnet_int.h|  23 
>> >> >  3 files changed, 399 insertions(+), 4 deletions(-)
>> >> >
>> >> > diff --git a/net/vmnet-common.m b/net/vmnet-common.m
>> >> > index 532d152840..b058e1b846 100644
>> >> > --- a/net/vmnet-common.m
>> >> > +++ b/net/vmnet-common.m
>> >> > @@ -10,6 +10,8 @@
>> >> >   */
>> >> >
>> >> >  #include "qemu/osdep.h"
>> >> > +#include "qemu/main-loop.h"
>> >> > +#include "qemu/log.h"
>> >> >  #include "qapi/qapi-types-net.h"
>> >> >  #include "vmnet_int.h"
>> >> >  #include "clients.h"
>> >> > @@ -17,4 +19,307 @@
>> >> >  #include "qapi/error.h"
>> >> >
>> >> >  #include 
>> >> > +#include 
>> >> >
>> >> > +#ifdef DEBUG
>> >> > +#define D(x) x
>> >> > +#define D_LOG(...) qemu_log(__VA_ARGS__)
>> >> > +#else
>> >> > +#define D(x) do { } while (0)
>> >> > +#define D_LOG(...) do { } while (0)
>> >> > +#endif
>> >> > +
>> >> > +typedef struct vmpktdesc vmpktdesc_t;
>> >> > +typedef struct iovec iovec_t;
>> >> > +
>> >> > +static void vmnet_set_send_enabled(VmnetCommonState *s, bool enable)
>> >> > +{
>> >> > +s->send_enabled = enable;
>> >>
>> >> Is there a way to disable the event when enable is false?
>> >>
>> >
>> > It seems there's no way except setting/unsetting
>> > the callback via `vmnet_interface_set_event_callback`.
>> > I decided to drop packages using `s->send_enabled`
>> > without dealing with the callback.
>>
>> ok.
>>
>> >
>> >> > +}
>> >> > +
>> >> > +
>> >> > +static void vmnet_send_completed(NetClientState *nc, ssize_t len)
>> >> > +{
>> >> > +VmnetCommonState *s = DO_UPCAST(VmnetCommonState, nc, nc);
>> >> > +vmnet_set_send_enabled(s, true);
>> >> > +}
>> >> > +
>> >> > +
>> >> > +static void vmnet_send(NetClientState *nc,
>> >> > +   interface_event_t event_id,
>> >> > +   xpc_object_t event)
>> >> > +{
>> >> > +assert(event_id == VMNET_INTERFACE_PACKETS_AVAILABLE);
>> >> > +
>> >> > +VmnetCommonState *s;
>> >> > +uint64_t packets_available;
>> >> > +
>> >> > +struct iovec *iov;
>> >> > +struct vmpktdesc *packets;
>> >> > +int pkt_cnt;
>> >> > +int i;
>> >> > +
>> >> > +vmnet_return_t if_status;
>> >> > +ssize_t size;
>> >> > +
>> >> > +s = DO_UPCAST(VmnetCommonState, nc, nc);
>> >> > +
>> >> > +packets_available = xpc_dictionary_get_uint64(
>> >> > +event,
>> >> > +vmnet_estimated_packets_available_key
>> >> > +);
>> >> > +
>> >> > +pkt_cnt = (packets_available < VMNET_PACKETS_LIMIT) ?
>> >> > +  packets_available :
>> >> > +  VMNET_PACKETS_LIMIT;
>> >> > +
>> >> > +
>> >> > +iov = s->iov_buf;
>> >> > +packets = s->packets_buf;
>> >> > +
>> >> > +for (i = 0; i < pkt_cnt; ++i) {
>> >> > +packets[i].vm_pkt_size = s->max_packet_size;
>> >> > +packets[i].vm_pkt_iovcnt = 1;
>> >> > +packets[i].vm_flags = 0;
>> >> > +}
>> >> > +
>> >> > +if_status = vmnet_read(s->vmnet_if, packets, &pkt_cnt);
>> >> > +if (if_status != VMNET_SUCCESS) {
>> >> > +error_printf("vmnet: read failed: %s\n",
>> >> > + vmnet_status_map_str(if_status));
>> >> > +}
>> >> > +qemu_mutex_lock_iothread();
>> >> > +for (i = 0; i < pkt_cnt; ++i) {
>> >> > +size = qemu_send_packet_async(nc,
>> >> > +  iov[i].iov_base,
>> >> > +  packets[i].vm_pkt_size,
>> >> > +  vmnet_send_completed);
>> >> > +if (size == 0) {
>> >> > +vmnet_set_send_enabled(s, false);
>> >> > +} else if (size < 0) {
>> >> > +break;
>> >> > +}
>> >> > +}
>> >> > +qemu_mutex_unlock_iothread();
>> >> > +
>> >> > +}
>> >> > +
>> >> > +
>> >> > +static void vmnet_register_event_callback(VmnetCommonState *s)
>> >> > +{
>> >> > +dispatch_queue_t avail_pkt_q = dispatch_queue_create(
>> >> > +"org.qemu.vmnet.if_queue",
>> >> > +DISPATCH_QUEUE_SERI

[PATCH for-6.2] qapi/machine.json: Fix incorrect description for die-id

2021-11-21 Thread Yanan Wang via
In terms of scope, die-id should mean "the die number within
socket the CPU belongs to" instead of "the die number within
node/board the CPU belongs to". Fix it to avoid confusing
the Doc reader.

Fixes: 176d2cda0d ("i386/cpu: Consolidate die-id validity in smp context")
Signed-off-by: Yanan Wang 
---
 qapi/machine.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qapi/machine.json b/qapi/machine.json
index 067e3f5378..f1839acf20 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -867,7 +867,7 @@
 #
 # @node-id: NUMA node ID the CPU belongs to
 # @socket-id: socket number within node/board the CPU belongs to
-# @die-id: die number within node/board the CPU belongs to (Since 4.1)
+# @die-id: die number within socket the CPU belongs to (since 4.1)
 # @core-id: core number within die the CPU belongs to
 # @thread-id: thread number within core the CPU belongs to
 #
-- 
2.19.1




Re: [PATCH 2/3] vdpa: Add dummy receive callbacks

2021-11-21 Thread Jason Wang
On Fri, Nov 19, 2021 at 6:20 PM Eugenio Pérez  wrote:
>
> Qemu falls back on userland handlers even if vhost-user and vhost-vdpa
> cases. These assumes a tap device can handle the packets.
>
> If a vdpa device fail to start, it can trigger a sigsegv because of
> that. Add dummy receivers that return no progress so it can keep
> running.
>
> Fixes: 1e0a84ea49 ("vhost-vdpa: introduce vhost-vdpa net client")
> Signed-off-by: Eugenio Pérez 
> ---
>  net/vhost-vdpa.c | 16 
>  1 file changed, 16 insertions(+)
>
> diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> index 2e3c22a8c7..4c75b78304 100644
> --- a/net/vhost-vdpa.c
> +++ b/net/vhost-vdpa.c
> @@ -170,9 +170,25 @@ static bool vhost_vdpa_check_peer_type(NetClientState 
> *nc, ObjectClass *oc,
>  return true;
>  }
>
> +/** Dummy receive in case qemu falls back to userland tap networking */
> +static ssize_t vhost_vdpa_receive_iov(NetClientState *nc,
> +  const struct iovec *iov, int iovcnt)
> +{
> +return 0;
> +}
> +
> +/** Dummy receive in case qemu falls back to userland tap networking */
> +static ssize_t vhost_vdpa_receive_raw(NetClientState *nc, const uint8_t *buf,
> +  size_t size)
> +{
> +return 0;
> +}

It looks to me the .receive_raw is not need, in nc_sendv_compat() we had:

=>  if (flags & QEMU_NET_PACKET_FLAG_RAW && nc->info->receive_raw) {
ret = nc->info->receive_raw(nc, buffer, offset);
} else {
ret = nc->info->receive(nc, buffer, offset);
}

Thanks

> +
>  static NetClientInfo net_vhost_vdpa_info = {
>  .type = NET_CLIENT_DRIVER_VHOST_VDPA,
>  .size = sizeof(VhostVDPAState),
> +.receive_iov = vhost_vdpa_receive_iov,
> +.receive_raw = vhost_vdpa_receive_raw,
>  .cleanup = vhost_vdpa_cleanup,
>  .has_vnet_hdr = vhost_vdpa_has_vnet_hdr,
>  .has_ufo = vhost_vdpa_has_ufo,
> --
> 2.27.0
>




Re: [PATCH 0/3] vdpa: Fix SIGSEGV on failed vdpa devices

2021-11-21 Thread Jason Wang
On Fri, Nov 19, 2021 at 6:20 PM Eugenio Pérez  wrote:
>
> Qemu falls back on userland handlers even if vhost-user and vhost-vdpa
> cases. These assumes a tap device can handle the packets.
>
> If a vdpa device fail to start, it can trigger a sigsegv because of
> that. Add dummy receivers that return no progress so it can keep
> running.
>
> Tested with a modified version of vp_vdpa to fail negotiation.
>
> This is another bersion of the patch proposed in [1], but the subject
> didn't match the patch anymore.
>
> [1] https://lists.nongnu.org/archive/html/qemu-devel/2021-11/msg03719.html
>

As discussed, we need to consider fixing the gRARP transmission issue
on top, any idea on that?

Thanks

> Eugenio Pérez (3):
>   virtio-net: Fix indentation
>   vdpa: Add dummy receive callbacks
>   virtio-net: Fix log message
>
>  hw/net/virtio-net.c | 13 +++--
>  net/vhost-vdpa.c| 16 
>  2 files changed, 23 insertions(+), 6 deletions(-)
>
> --
> 2.27.0
>
>




Re: [PATCH V3 2/2] test/qtest/test-filter-mirror.c: Change the default vnet_hdr_support

2021-11-21 Thread Jason Wang
On Fri, Nov 19, 2021 at 1:45 PM Zhang Chen  wrote:
>
> As net filters changed default vnet_hdr_support=on.
> For this e1000 test case need to add vnet_hdr_support=off.
>
> Signed-off-by: Zhang Chen 
> ---

I squashed this into the previous patch to have a better bisection
behaviour and queue it for 7.0.

Thanks

>  tests/qtest/test-filter-mirror.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tests/qtest/test-filter-mirror.c 
> b/tests/qtest/test-filter-mirror.c
> index bc0dee64dd..7756f8cfc1 100644
> --- a/tests/qtest/test-filter-mirror.c
> +++ b/tests/qtest/test-filter-mirror.c
> @@ -45,7 +45,7 @@ static void test_mirror(void)
>  "-netdev socket,id=qtest-bn0,fd=%d "
>  "-device %s,netdev=qtest-bn0,id=qtest-e0 "
>  "-chardev socket,id=mirror0,fd=%d "
> -"-object 
> filter-mirror,id=qtest-f0,netdev=qtest-bn0,queue=tx,outdev=mirror0 "
> +"-object 
> filter-mirror,id=qtest-f0,netdev=qtest-bn0,queue=tx,outdev=mirror0,vnet_hdr_support=off
>  "
>  , send_sock[1], devstr, recv_sock[1]);
>
>  struct iovec iov[] = {
> --
> 2.25.1
>




Re: [PATCH V3 1/2] net/filter: Enable the vnet_hdr_support by default

2021-11-21 Thread Jason Wang
On Fri, Nov 19, 2021 at 1:45 PM Zhang Chen  wrote:
>
> This patch make filters and colo-compare module support vnet_hdr by
> default. And also support -device non-virtio-net(like e1000.).
> Because when enabled the support will make the vnet_hdr_len field
> become must-delivery part of filter transfer protocol(even 0 in use
> -device e1000). It fully guarantees the compatibility for management
> layer like libvirt. But it still can't avoid user manual
> configuration error between different filters connected
> when enable/disable vnet_hdr_support.
>
> Signed-off-by: Zhang Chen 

Queued for 7.0.

Thanks

> ---
>  net/colo-compare.c| 2 +-
>  net/filter-mirror.c   | 4 ++--
>  net/filter-rewriter.c | 2 +-
>  qemu-options.hx   | 9 +
>  4 files changed, 9 insertions(+), 8 deletions(-)
>
> diff --git a/net/colo-compare.c b/net/colo-compare.c
> index b966e7e514..0232249311 100644
> --- a/net/colo-compare.c
> +++ b/net/colo-compare.c
> @@ -1399,7 +1399,7 @@ static void colo_compare_init(Object *obj)
>  get_max_queue_size,
>  set_max_queue_size, NULL, NULL);
>
> -s->vnet_hdr = false;
> +s->vnet_hdr = true;
>  object_property_add_bool(obj, "vnet_hdr_support", compare_get_vnet_hdr,
>   compare_set_vnet_hdr);
>  }
> diff --git a/net/filter-mirror.c b/net/filter-mirror.c
> index f20240cc9f..adb0c6d89a 100644
> --- a/net/filter-mirror.c
> +++ b/net/filter-mirror.c
> @@ -406,14 +406,14 @@ static void filter_mirror_init(Object *obj)
>  {
>  MirrorState *s = FILTER_MIRROR(obj);
>
> -s->vnet_hdr = false;
> +s->vnet_hdr = true;
>  }
>
>  static void filter_redirector_init(Object *obj)
>  {
>  MirrorState *s = FILTER_REDIRECTOR(obj);
>
> -s->vnet_hdr = false;
> +s->vnet_hdr = true;
>  }
>
>  static void filter_mirror_fini(Object *obj)
> diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
> index bf05023dc3..5698cd39d1 100644
> --- a/net/filter-rewriter.c
> +++ b/net/filter-rewriter.c
> @@ -407,7 +407,7 @@ static void filter_rewriter_init(Object *obj)
>  {
>  RewriterState *s = FILTER_REWRITER(obj);
>
> -s->vnet_hdr = false;
> +s->vnet_hdr = true;
>  s->failover_mode = FAILOVER_MODE_OFF;
>  }
>
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 7749f59300..c40e385ede 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -4967,13 +4967,13 @@ SRST
>  ``-object 
> filter-mirror,id=id,netdev=netdevid,outdev=chardevid,queue=all|rx|tx[,vnet_hdr_support][,position=head|tail|id=][,insert=behind|before]``
>  filter-mirror on netdev netdevid,mirror net packet to
>  chardevchardevid, if it has the vnet\_hdr\_support flag,
> -filter-mirror will mirror packet with vnet\_hdr\_len.
> +filter-mirror will mirror packet with vnet\_hdr\_len(default: on).
>
>  ``-object 
> filter-redirector,id=id,netdev=netdevid,indev=chardevid,outdev=chardevid,queue=all|rx|tx[,vnet_hdr_support][,position=head|tail|id=][,insert=behind|before]``
>  filter-redirector on netdev netdevid,redirect filter's net
>  packet to chardev chardevid,and redirect indev's packet to
>  filter.if it has the vnet\_hdr\_support flag, filter-redirector
> -will redirect packet with vnet\_hdr\_len. Create a
> +will redirect packet with vnet\_hdr\_len(default: on). Create a
>  filter-redirector we need to differ outdev id from indev id, id
>  can not be the same. we can just use indev or outdev, but at
>  least one of indev or outdev need to be specified.
> @@ -4983,7 +4983,8 @@ SRST
>  packet to secondary from primary to keep secondary tcp
>  connection,and rewrite tcp packet to primary from secondary make
>  tcp packet can be handled by client.if it has the
> -vnet\_hdr\_support flag, we can parse packet with vnet header.
> +vnet\_hdr\_support flag, we can parse packet with vnet
> +header(default: on).
>
>  usage: colo secondary: -object
>  filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0 -object
> @@ -5004,7 +5005,7 @@ SRST
>  checkpoint and send primary packet to out\_dev. In order to
>  improve efficiency, we need to put the task of comparison in
>  another iothread. If it has the vnet\_hdr\_support flag,
> -colo compare will send/recv packet with vnet\_hdr\_len.
> +colo compare will send/recv packet with vnet\_hdr\_len(default: on).
>  The compare\_timeout=@var{ms} determines the maximum time of the
>  colo-compare hold the packet. The expired\_scan\_cycle=@var{ms}
>  is to set the period of scanning expired primary node network 
> packets.
> --
> 2.25.1
>




[PATCH 1/2] docs: Drop deprecated 'props' from object-add

2021-11-21 Thread Rao, Lei
From: "Rao, Lei" 

In commit 5024340745 "qapi/qom: Drop deprecated 'props' from
object-add" (v6.0.0), we also should update documents.

Signed-off-by: Lei Rao 
---
 docs/system/authz.rst   | 26 ++
 docs/throttle.txt   |  8 +++-
 docs/tools/qemu-nbd.rst |  2 +-
 3 files changed, 14 insertions(+), 22 deletions(-)

diff --git a/docs/system/authz.rst b/docs/system/authz.rst
index 942af39..55b7315 100644
--- a/docs/system/authz.rst
+++ b/docs/system/authz.rst
@@ -77,9 +77,7 @@ To create an instance of this driver via QMP:
  "arguments": {
"qom-type": "authz-simple",
"id": "authz0",
-   "props": {
- "identity": "fred"
-   }
+   "identity": "fred"
  }
}
 
@@ -110,15 +108,13 @@ To create an instance of this class via QMP:
  "arguments": {
"qom-type": "authz-list",
"id": "authz0",
-   "props": {
- "rules": [
-{ "match": "fred", "policy": "allow", "format": "exact" },
-{ "match": "bob", "policy": "allow", "format": "exact" },
-{ "match": "danb", "policy": "deny", "format": "exact" },
-{ "match": "dan*", "policy": "allow", "format": "glob" }
- ],
- "policy": "deny"
-   }
+   "rules": [
+  { "match": "fred", "policy": "allow", "format": "exact" },
+  { "match": "bob", "policy": "allow", "format": "exact" },
+  { "match": "danb", "policy": "deny", "format": "exact" },
+  { "match": "dan*", "policy": "allow", "format": "glob" }
+   ],
+   "policy": "deny"
  }
}
 
@@ -143,10 +139,8 @@ To create an instance of this class via QMP:
  "arguments": {
"qom-type": "authz-list-file",
"id": "authz0",
-   "props": {
- "filename": "/etc/qemu/myvm-vnc.acl",
- "refresh": true
-   }
+   "filename": "/etc/qemu/myvm-vnc.acl",
+   "refresh": true
  }
}
 
diff --git a/docs/throttle.txt b/docs/throttle.txt
index b5b78b7..0a0453a 100644
--- a/docs/throttle.txt
+++ b/docs/throttle.txt
@@ -273,11 +273,9 @@ A group can be created using the object-add QMP function:
  "arguments": {
"qom-type": "throttle-group",
"id": "group0",
-   "props": {
- "limits" : {
-   "iops-total": 1000
-   "bps-write": 2097152
- }
+   "limits" : {
+ "iops-total": 1000,
+ "bps-write": 2097152
}
  }
}
diff --git a/docs/tools/qemu-nbd.rst b/docs/tools/qemu-nbd.rst
index 56e54cd..726cd189 100644
--- a/docs/tools/qemu-nbd.rst
+++ b/docs/tools/qemu-nbd.rst
@@ -31,7 +31,7 @@ driver options if ``--image-opts`` is specified.
 
 *dev* is an NBD device.
 
-.. option:: --object type,id=ID,...props...
+.. option:: --object type,id=ID,...
 
   Define a new instance of the *type* object class identified by *ID*.
   See the :manpage:`qemu(1)` manual page for full details of the properties
-- 
1.8.3.1




[PATCH 2/2] docs: Use double quotes instead of single quotes for COLO

2021-11-21 Thread Rao, Lei
From: "Rao, Lei" 

Signed-off-by: Lei Rao 
---
 docs/COLO-FT.txt   | 106 ++---
 docs/block-replication.txt |  52 +++---
 2 files changed, 79 insertions(+), 79 deletions(-)

diff --git a/docs/COLO-FT.txt b/docs/COLO-FT.txt
index fd5ffcc..8ec653f 100644
--- a/docs/COLO-FT.txt
+++ b/docs/COLO-FT.txt
@@ -209,9 +209,9 @@ children.0=childs0 \
 
 
 3. On Secondary VM's QEMU monitor, issue command
-{'execute':'qmp_capabilities'}
-{'execute': 'nbd-server-start', 'arguments': {'addr': {'type': 'inet', 'data': 
{'host': '0.0.0.0', 'port': ''} } } }
-{'execute': 'nbd-server-add', 'arguments': {'device': 'parent0', 'writable': 
true } }
+{"execute":"qmp_capabilities"}
+{"execute": "nbd-server-start", "arguments": {"addr": {"type": "inet", "data": 
{"host": "0.0.0.0", "port": ""} } } }
+{"execute": "nbd-server-add", "arguments": {"device": "parent0", "writable": 
true } }
 
 Note:
   a. The qmp command nbd-server-start and nbd-server-add must be run
@@ -222,11 +222,11 @@ Note:
  will be merged into the parent disk on failover.
 
 4. On Primary VM's QEMU monitor, issue command:
-{'execute':'qmp_capabilities'}
-{'execute': 'human-monitor-command', 'arguments': {'command-line': 'drive_add 
-n buddy 
driver=replication,mode=primary,file.driver=nbd,file.host=127.0.0.2,file.port=,file.export=parent0,node-name=replication0'}}
-{'execute': 'x-blockdev-change', 'arguments':{'parent': 'colo-disk0', 'node': 
'replication0' } }
-{'execute': 'migrate-set-capabilities', 'arguments': {'capabilities': [ 
{'capability': 'x-colo', 'state': true } ] } }
-{'execute': 'migrate', 'arguments': {'uri': 'tcp:127.0.0.2:9998' } }
+{"execute":"qmp_capabilities"}
+{"execute": "human-monitor-command", "arguments": {"command-line": "drive_add 
-n buddy 
driver=replication,mode=primary,file.driver=nbd,file.host=127.0.0.2,file.port=,file.export=parent0,node-name=replication0"}}
+{"execute": "x-blockdev-change", "arguments":{"parent": "colo-disk0", "node": 
"replication0" } }
+{"execute": "migrate-set-capabilities", "arguments": {"capabilities": [ 
{"capability": "x-colo", "state": true } ] } }
+{"execute": "migrate", "arguments": {"uri": "tcp:127.0.0.2:9998" } }
 
   Note:
   a. There should be only one NBD Client for each primary disk.
@@ -249,59 +249,59 @@ if you want to resume the replication, follow "Secondary 
resume replication"
 == Primary Failover ==
 The Secondary died, resume on the Primary
 
-{'execute': 'x-blockdev-change', 'arguments':{ 'parent': 'colo-disk0', 
'child': 'children.1'} }
-{'execute': 'human-monitor-command', 'arguments':{ 'command-line': 'drive_del 
replication0' } }
-{'execute': 'object-del', 'arguments':{ 'id': 'comp0' } }
-{'execute': 'object-del', 'arguments':{ 'id': 'iothread1' } }
-{'execute': 'object-del', 'arguments':{ 'id': 'm0' } }
-{'execute': 'object-del', 'arguments':{ 'id': 'redire0' } }
-{'execute': 'object-del', 'arguments':{ 'id': 'redire1' } }
-{'execute': 'x-colo-lost-heartbeat' }
+{"execute": "x-blockdev-change", "arguments":{ "parent": "colo-disk0", 
"child": "children.1"} }
+{"execute": "human-monitor-command", "arguments":{ "command-line": "drive_del 
replication0" } }
+{"execute": "object-del", "arguments":{ "id": "comp0" } }
+{"execute": "object-del", "arguments":{ "id": "iothread1" } }
+{"execute": "object-del", "arguments":{ "id": "m0" } }
+{"execute": "object-del", "arguments":{ "id": "redire0" } }
+{"execute": "object-del", "arguments":{ "id": "redire1" } }
+{"execute": "x-colo-lost-heartbeat" }
 
 == Secondary Failover ==
 The Primary died, resume on the Secondary and prepare to become the new Primary
 
-{'execute': 'nbd-server-stop'}
-{'execute': 'x-colo-lost-heartbeat'}
+{"execute": "nbd-server-stop"}
+{"execute": "x-colo-lost-heartbeat"}
 
-{'execute': 'object-del', 'arguments':{ 'id': 'f2' } }
-{'execute': 'object-del', 'arguments':{ 'id': 'f1' } }
-{'execute': 'chardev-remove', 'arguments':{ 'id': 'red1' } }
-{'execute': 'chardev-remove', 'arguments':{ 'id': 'red0' } }
+{"execute": "object-del", "arguments":{ "id": "f2" } }
+{"execute": "object-del", "arguments":{ "id": "f1" } }
+{"execute": "chardev-remove", "arguments":{ "id": "red1" } }
+{"execute": "chardev-remove", "arguments":{ "id": "red0" } }
 
-{'execute': 'chardev-add', 'arguments':{ 'id': 'mirror0', 'backend': {'type': 
'socket', 'data': {'addr': { 'type': 'inet', 'data': { 'host': '0.0.0.0', 
'port': '9003' } }, 'server': true } } } }
-{'execute': 'chardev-add', 'arguments':{ 'id': 'compare1', 'backend': {'type': 
'socket', 'data': {'addr': { 'type': 'inet', 'data': { 'host': '0.0.0.0', 
'port': '9004' } }, 'server': true } } } }
-{'execute': 'chardev-add', 'arguments':{ 'id': 'compare0', 'backend': {'type': 
'socket', 'data': {'addr': { 'type': 'inet', 'data': { 'host': '127.0.0.1', 
'port': '9001' } }, 'server': true } } } }
-{'execute': 'chardev-add', 'arguments':{ 'id': 'compare0-0', 'backend': 
{'type': 'socket', 'data': {'addr': { 'type': '

Re: [PATCH for-7.0 v7 01/10] target/ppc: introduce PMUEventType and PMU overflow timers

2021-11-21 Thread David Gibson
On Fri, Nov 19, 2021 at 03:22:07PM -0300, Daniel Henrique Barboza wrote:
> This patch starts an IBM Power8+ compatible PMU implementation by adding
> the representation of PMU events that we are going to sample,
> PMUEventType. This enum represents a Perf event that is being sampled by
> a specific counter 'sprn'. Events that aren't available (i.e. no event
> was set in MMCR1) will be of type 'PMU_EVENT_INVALID'. Other types added
> in this patch are PMU_EVENT_CYCLES and PMU_EVENT_INSTRUCTIONS. More
> types will be added later on.
> 
> Let's also add the required PMU cycle overflow timers. They will be used
> to trigger cycle overflows when cycle events are being sampled. This
> timer will call cpu_ppc_pmu_timer_cb(), which in turn calls
> fire_PMC_interrupt().  Both functions are stubs that will be implemented
> later on when EBB support is added.
> 
> Two new helper files are created to host this new logic.
> cpu_ppc_pmu_init() will init all overflow timers during CPU init time.
> 
> Signed-off-by: Daniel Henrique Barboza 

Reviewed-by: David Gibson 

> ---
>  hw/ppc/spapr_cpu_core.c |  1 +
>  target/ppc/cpu.h| 15 +++
>  target/ppc/cpu_init.c   | 24 +
>  target/ppc/meson.build  |  1 +
>  target/ppc/power8-pmu.c | 57 +
>  target/ppc/power8-pmu.h | 25 ++
>  6 files changed, 123 insertions(+)
>  create mode 100644 target/ppc/power8-pmu.c
>  create mode 100644 target/ppc/power8-pmu.h
> 
> diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
> index 58e7341cb7..a57ba70a87 100644
> --- a/hw/ppc/spapr_cpu_core.c
> +++ b/hw/ppc/spapr_cpu_core.c
> @@ -20,6 +20,7 @@
>  #include "target/ppc/kvm_ppc.h"
>  #include "hw/ppc/ppc.h"
>  #include "target/ppc/mmu-hash64.h"
> +#include "target/ppc/power8-pmu.h"
>  #include "sysemu/numa.h"
>  #include "sysemu/reset.h"
>  #include "sysemu/hw_accel.h"
> diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
> index e946da5f3a..04ef9300af 100644
> --- a/target/ppc/cpu.h
> +++ b/target/ppc/cpu.h
> @@ -296,6 +296,15 @@ typedef struct ppc_v3_pate_t {
>  uint64_t dw1;
>  } ppc_v3_pate_t;
>  
> +/* PMU related structs and defines */
> +#define PMU_COUNTERS_NUM 6
> +#define PMU_TIMERS_NUM   (PMU_COUNTERS_NUM - 1) /* PMC5 doesn't count cycles 
> */
> +typedef enum {
> +PMU_EVENT_INVALID = 0,
> +PMU_EVENT_CYCLES,
> +PMU_EVENT_INSTRUCTIONS,
> +} PMUEventType;
> +
>  
> /*/
>  /* Machine state register bits definition
> */
>  #define MSR_SF   63 /* Sixty-four-bit modehflags 
> */
> @@ -1191,6 +1200,12 @@ struct CPUPPCState {
>  uint32_t tm_vscr;
>  uint64_t tm_dscr;
>  uint64_t tm_tar;
> +
> +/*
> + * Timers used to fire performance monitor alerts
> + * when counting cycles.
> + */
> +QEMUTimer *pmu_cyc_overflow_timers[PMU_TIMERS_NUM];
>  };
>  
>  #define SET_FIT_PERIOD(a_, b_, c_, d_)  \
> diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
> index 6695985e9b..9610e65c76 100644
> --- a/target/ppc/cpu_init.c
> +++ b/target/ppc/cpu_init.c
> @@ -45,6 +45,7 @@
>  #include "helper_regs.h"
>  #include "internal.h"
>  #include "spr_tcg.h"
> +#include "power8-pmu.h"
>  
>  /* #define PPC_DEBUG_SPR */
>  /* #define USE_APPLE_GDB */
> @@ -7377,6 +7378,20 @@ static void register_power9_mmu_sprs(CPUPPCState *env)
>  #endif
>  }
>  
> +/*
> + * Initialize PMU counter overflow timers for Power8 and
> + * newer Power chips when using TCG.
> + */
> +static void init_tcg_pmu_power8(CPUPPCState *env)
> +{
> +#if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
> +/* Init PMU overflow timers */
> +if (!kvm_enabled()) {
> +cpu_ppc_pmu_init(env);
> +}
> +#endif
> +}
> +
>  static void init_proc_book3s_common(CPUPPCState *env)
>  {
>  register_ne_601_sprs(env);
> @@ -7694,6 +7709,9 @@ static void init_proc_POWER8(CPUPPCState *env)
>  register_sdr1_sprs(env);
>  register_book3s_207_dbg_sprs(env);
>  
> +/* Common TCG PMU */
> +init_tcg_pmu_power8(env);
> +
>  /* POWER8 Specific Registers */
>  register_book3s_ids_sprs(env);
>  register_rmor_sprs(env);
> @@ -7888,6 +7906,9 @@ static void init_proc_POWER9(CPUPPCState *env)
>  init_proc_book3s_common(env);
>  register_book3s_207_dbg_sprs(env);
>  
> +/* Common TCG PMU */
> +init_tcg_pmu_power8(env);
> +
>  /* POWER8 Specific Registers */
>  register_book3s_ids_sprs(env);
>  register_amr_sprs(env);
> @@ -8104,6 +8125,9 @@ static void init_proc_POWER10(CPUPPCState *env)
>  init_proc_book3s_common(env);
>  register_book3s_207_dbg_sprs(env);
>  
> +/* Common TCG PMU */
> +init_tcg_pmu_power8(env);
> +
>  /* POWER8 Specific Registers */
>  register_book3s_ids_sprs(env);
>  register_amr_sprs(env);
> diff --git a/target/ppc/meson.build b/target/ppc/meson.build
> index b

Re: [PATCH for-7.0 v7 02/10] target/ppc: PMU basic cycle count for pseries TCG

2021-11-21 Thread David Gibson
On Fri, Nov 19, 2021 at 03:22:08PM -0300, Daniel Henrique Barboza wrote:
> This patch adds the barebones of the PMU logic by enabling cycle
> counting. The overall logic goes as follows:
> 
> - a helper is added to control the PMU state on each MMCR0 write. This
> allows for the PMU to start/stop as the frozen counter bit (MMCR0_FC)
> is cleared or set;
> 
> - MMCR0 reg initial value is set to 0x8000 (MMCR0_FC set) to avoid
> having to spin the PMU right at system init;
> 
> - to retrieve the events that are being profiled, getPMUEventType() will
> check the current MMCR1 value and return the appropriate PMUEventType.
> For PMCs 1-4, event 0x2 is the implementation dependent value of
> PMU_EVENT_INSTRUCTIONS and event 0x1E is the implementation dependent
> value of PMU_EVENT_CYCLES. These events are supported by IBM Power chips
> since Power8, at least, and the Linux Perf driver makes use of these
> events until kernel v5.15. For PMC1, event 0xF0 is the architected
> PowerISA event for cycles. Event 0xFE is the architected PowerISA event
> for instructions;
> 
> - the intended usage is to freeze the counters by setting MMCR0_FC, do
> any additional setting of events to be counted via MMCR1 and enable
> the PMU by zeroing MMCR0_FC. Software must freeze counters to read the
> results - on the fly reading of the PMCs will return the starting value
> of each one. This act of unfreezing the PMU, counting cycles and then
> freezing the PMU again is being called a cycle count session.
> 
> Given that the base CPU frequency is fixed at 1Ghz for both powernv and
> pseries clock, cycle calculation assumes that 1 nanosecond equals 1 CPU
> cycle. Cycle value is then calculated by subtracting the current time
> the PMU was frozen against the time in which the PMU started spining.
> 
> The counter specific frozen bits MMCR0_FC14 and MMCR0_FC56 were also
> added as a mean to further control which PMCs were supposed to be
> counting cycles during the session.
> 
> Signed-off-by: Daniel Henrique Barboza 
> ---
>  target/ppc/cpu.h |  20 +
>  target/ppc/cpu_init.c|   6 +-
>  target/ppc/helper.h  |   1 +
>  target/ppc/power8-pmu-regs.c.inc |  23 -
>  target/ppc/power8-pmu.c  | 149 +++
>  target/ppc/spr_tcg.h |   1 +
>  6 files changed, 196 insertions(+), 4 deletions(-)
> 
> diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
> index 04ef9300af..233fd8a9ca 100644
> --- a/target/ppc/cpu.h
> +++ b/target/ppc/cpu.h
> @@ -360,6 +360,9 @@ typedef enum {
>  #define MMCR0_FCECE  PPC_BIT(38) /* FC on Enabled Cond or Event */
>  #define MMCR0_PMCC0  PPC_BIT(44) /* PMC Control bit 0 */
>  #define MMCR0_PMCC1  PPC_BIT(45) /* PMC Control bit 1 */
> +#define MMCR0_PMCC   PPC_BITMASK(44, 45) /* PMC Control */
> +#define MMCR0_FC14   PPC_BIT(58) /* PMC Freeze Counters 1-4 bit */
> +#define MMCR0_FC56   PPC_BIT(59) /* PMC Freeze Counters 5-6 bit */
>  /* MMCR0 userspace r/w mask */
>  #define MMCR0_UREG_MASK (MMCR0_FC | MMCR0_PMAO | MMCR0_PMAE)
>  /* MMCR2 userspace r/w mask */
> @@ -372,6 +375,17 @@ typedef enum {
>  #define MMCR2_UREG_MASK (MMCR2_FC1P0 | MMCR2_FC2P0 | MMCR2_FC3P0 | \
>   MMCR2_FC4P0 | MMCR2_FC5P0 | MMCR2_FC6P0)
>  
> +#define MMCR1_EVT_SIZE 8
> +/* extract64() does a right shift before extracting */
> +#define MMCR1_PMC1SEL_START 32
> +#define MMCR1_PMC1EVT_EXTR (64 - MMCR1_PMC1SEL_START - MMCR1_EVT_SIZE)
> +#define MMCR1_PMC2SEL_START 40
> +#define MMCR1_PMC2EVT_EXTR (64 - MMCR1_PMC2SEL_START - MMCR1_EVT_SIZE)
> +#define MMCR1_PMC3SEL_START 48
> +#define MMCR1_PMC3EVT_EXTR (64 - MMCR1_PMC3SEL_START - MMCR1_EVT_SIZE)
> +#define MMCR1_PMC4SEL_START 56
> +#define MMCR1_PMC4EVT_EXTR (64 - MMCR1_PMC4SEL_START - MMCR1_EVT_SIZE)
> +
>  /* LPCR bits */
>  #define LPCR_VPM0 PPC_BIT(0)
>  #define LPCR_VPM1 PPC_BIT(1)
> @@ -1206,6 +1220,12 @@ struct CPUPPCState {
>   * when counting cycles.
>   */
>  QEMUTimer *pmu_cyc_overflow_timers[PMU_TIMERS_NUM];
> +
> +/*
> + * PMU base time value used by the PMU to calculate
> + * running cycles.
> + */
> +uint64_t pmu_base_time;
>  };
>  
>  #define SET_FIT_PERIOD(a_, b_, c_, d_)  \
> diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
> index 9610e65c76..e0b6fe4057 100644
> --- a/target/ppc/cpu_init.c
> +++ b/target/ppc/cpu_init.c
> @@ -6821,8 +6821,8 @@ static void register_book3s_pmu_sup_sprs(CPUPPCState 
> *env)
>  {
>  spr_register_kvm(env, SPR_POWER_MMCR0, "MMCR0",
>   SPR_NOACCESS, SPR_NOACCESS,
> - &spr_read_generic, &spr_write_generic,
> - KVM_REG_PPC_MMCR0, 0x);
> + &spr_read_generic, &spr_write_MMCR0,
> + KVM_REG_PPC_MMCR0, 0x8000);
>  spr_register_kvm(env, SPR_POWER_MMCR1, "MMCR1",
>   SPR_NOACCESS, SPR_NOACCESS,
> 

Re: [PATCH v5 02/18] exec/memop: Adding signed quad and octo defines

2021-11-21 Thread Alistair Francis
On Sat, Nov 13, 2021 at 1:13 AM Frédéric Pétrot
 wrote:
>
> Adding defines to handle signed 64-bit and unsigned 128-bit quantities in
> memory accesses.
>
> Signed-off-by: Frédéric Pétrot 

Reviewed-by: Alistair Francis 

Alistair

> ---
>  include/exec/memop.h | 7 +++
>  1 file changed, 7 insertions(+)
>
> diff --git a/include/exec/memop.h b/include/exec/memop.h
> index 72c2f0ff3d..2a885f3917 100644
> --- a/include/exec/memop.h
> +++ b/include/exec/memop.h
> @@ -86,28 +86,35 @@ typedef enum MemOp {
>  MO_UW= MO_16,
>  MO_UL= MO_32,
>  MO_UQ= MO_64,
> +MO_UO= MO_128,
>  MO_SB= MO_SIGN | MO_8,
>  MO_SW= MO_SIGN | MO_16,
>  MO_SL= MO_SIGN | MO_32,
> +MO_SQ= MO_SIGN | MO_64,
> +MO_SO= MO_SIGN | MO_128,
>
>  MO_LEUW  = MO_LE | MO_UW,
>  MO_LEUL  = MO_LE | MO_UL,
>  MO_LEUQ  = MO_LE | MO_UQ,
>  MO_LESW  = MO_LE | MO_SW,
>  MO_LESL  = MO_LE | MO_SL,
> +MO_LESQ  = MO_LE | MO_SQ,
>
>  MO_BEUW  = MO_BE | MO_UW,
>  MO_BEUL  = MO_BE | MO_UL,
>  MO_BEUQ  = MO_BE | MO_UQ,
>  MO_BESW  = MO_BE | MO_SW,
>  MO_BESL  = MO_BE | MO_SL,
> +MO_BESQ  = MO_BE | MO_SQ,
>
>  #ifdef NEED_CPU_H
>  MO_TEUW  = MO_TE | MO_UW,
>  MO_TEUL  = MO_TE | MO_UL,
>  MO_TEUQ  = MO_TE | MO_UQ,
> +MO_TEUO  = MO_TE | MO_UO,
>  MO_TESW  = MO_TE | MO_SW,
>  MO_TESL  = MO_TE | MO_SL,
> +MO_TESQ  = MO_TE | MO_SQ,
>  #endif
>
>  MO_SSIZE = MO_SIZE | MO_SIGN,
> --
> 2.33.1
>
>



Re: [PATCH 2/3] virtio-net: Only enable userland vq if using tap backend

2021-11-21 Thread Eugenio Perez Martin
On Mon, Nov 22, 2021 at 3:39 AM Jason Wang  wrote:
>
> On Fri, Nov 19, 2021 at 3:50 PM Eugenio Perez Martin
>  wrote:
> >
> > On Fri, Nov 19, 2021 at 3:44 AM Jason Wang  wrote:
> > >
> > > On Thu, Nov 18, 2021 at 3:57 PM Eugenio Perez Martin
> > >  wrote:
> > > >
> > > > On Thu, Nov 18, 2021 at 6:06 AM Jason Wang  wrote:
> > > > >
> > > > > On Thu, Nov 18, 2021 at 3:29 AM Eugenio Pérez  
> > > > > wrote:
> > > > > >
> > > > > > Qemu falls back on userland handlers even if vhost-user and 
> > > > > > vhost-vdpa
> > > > > > cases. These assumes a tap device can handle the packets.
> > > > > >
> > > > > > If a vdpa device fail to start, it can trigger a sigsegv because of
> > > > > > that. Do not resort on them unless actually possible.
> > > > >
> > > > > It would be better to show the calltrace here then we can see the 
> > > > > root cause.
> > > > >
> > > >
> > > > Sure, I'll paste here and I'll resend to the next version:
> > > > #1  0x55955f696e92 in nc_sendv_compat (flags=,
> > > > iovcnt=2, iov=0x7ffe73abe300, nc=0x7fcf22d6d010) at ../net/net.c:756
> > > > #2  qemu_deliver_packet_iov (sender=,
> > > > opaque=0x7fcf22d6d010, iovcnt=2, iov=0x7ffe73abe300, flags= > > > out>) at ../net/net.c:784
> > > > #3  qemu_deliver_packet_iov (sender=, flags= > > > out>, iov=0x7ffe73abe300, iovcnt=2, opaque=0x7fcf22d6d010) at
> > > > ../net/net.c:763
> > > > #4  0x55955f69a078 in qemu_net_queue_deliver_iov (iovcnt=2,
> > > > iov=0x7ffe73abe300, flags=0, sender=0x5595631f5ac0,
> > > > queue=0x559561c7baa0) at ../net/queue.c:179
> > > > #5  qemu_net_queue_send_iov (queue=0x559561c7baa0,
> > > > sender=0x5595631f5ac0, flags=flags@entry=0,
> > > > iov=iov@entry=0x7ffe73abe300,
> > > > iovcnt=iovcnt@entry=2, sent_cb=sent_cb@entry=0x55955f82ae60
> > > > ) at ../net/queue.c:246
> > > > #6  0x55955f697d43 in qemu_sendv_packet_async
> > > > (sent_cb=0x55955f82ae60 , iovcnt=2,
> > > > iov=0x7ffe73abe300,
> > > > sender=) at ../net/net.c:825
> > > > #7  qemu_sendv_packet_async (sender=,
> > > > iov=iov@entry=0x7ffe73abe300, iovcnt=iovcnt@entry=1662966768,
> > > > sent_cb=sent_cb@entry=0x55955f82ae60 ) at
> > > > ../net/net.c:794
> > > > #8  0x55955f82aba9 in virtio_net_flush_tx (q=0x0,
> > > > q@entry=0x5595631edbf0) at ../hw/net/virtio-net.c:2577
> > > > #9  0x55955f82ade8 in virtio_net_tx_bh (opaque=0x5595631edbf0) at
> > > > ../hw/net/virtio-net.c:2694
> > > > #10 0x55955f9e847d in aio_bh_call (bh=0x559561c7e590) at 
> > > > ../util/async.c:169
> > > > #11 aio_bh_poll (ctx=ctx@entry=0x559561c81650) at ../util/async.c:169
> > > > #12 0x55955f9d6912 in aio_dispatch (ctx=0x559561c81650) at
> > > > ../util/aio-posix.c:381
> > > > #13 0x55955f9e8322 in aio_ctx_dispatch (source=,
> > > > callback=, user_data=)
> > > > at ../util/async.c:311
> > > > #14 0x7fcf20a5495d in g_main_context_dispatch () from
> > > > /lib64/libglib-2.0.so.0
> > > > #15 0x55955f9f2fc0 in glib_pollfds_poll () at 
> > > > ../util/main-loop.c:232
> > > > #16 os_host_main_loop_wait (timeout=) at 
> > > > ../util/main-loop.c:255
> > > > #17 main_loop_wait (nonblocking=nonblocking@entry=0) at 
> > > > ../util/main-loop.c:531
> > > > #18 0x55955f7eee49 in qemu_main_loop () at ../softmmu/runstate.c:726
> > > > #19 0x55955f6235c2 in main (argc=, argv= > > > out>, envp=) at ../softmmu/main.c:50
> > > >
> > > > In nc_sendv_compat, nc->info is net_vhost_vdpa_info, so
> > > > nc->info->receive is NULL.
> > > >
> > > > > >
> > > > > > Signed-off-by: Eugenio Pérez 
> > > > > > ---
> > > > > >  include/hw/virtio/virtio.h |  2 ++
> > > > > >  hw/net/virtio-net.c|  4 
> > > > > >  hw/virtio/virtio.c | 21 +
> > > > > >  3 files changed, 19 insertions(+), 8 deletions(-)
> > > > > >
> > > > > > diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> > > > > > index 8bab9cfb75..1712ba0b4c 100644
> > > > > > --- a/include/hw/virtio/virtio.h
> > > > > > +++ b/include/hw/virtio/virtio.h
> > > > > > @@ -105,6 +105,8 @@ struct VirtIODevice
> > > > > >  VMChangeStateEntry *vmstate;
> > > > > >  char *bus_name;
> > > > > >  uint8_t device_endian;
> > > > > > +/* backend does not support userspace handler */
> > > > > > +bool disable_ioeventfd_handler;
> > > > > >  bool use_guest_notifier_mask;
> > > > > >  AddressSpace *dma_as;
> > > > > >  QLIST_HEAD(, VirtQueue) *vector_queues;
> > > > > > diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> > > > > > index 004acf858f..8c5c4e5a9d 100644
> > > > > > --- a/hw/net/virtio-net.c
> > > > > > +++ b/hw/net/virtio-net.c
> > > > > > @@ -3501,6 +3501,10 @@ static void 
> > > > > > virtio_net_device_realize(DeviceState *dev, Error **errp)
> > > > > >  nc = qemu_get_queue(n->nic);
> > > > > >  nc->rxfilter_notify_enabled = 1;
> > > > > >
> > > > > > +if (!nc->peer || nc->peer->info->type != 
> > > > > > NET_CLIENT_DRIVER_TAP) {
> > > > > > +/* Only tap can use userspace

Re: [PATCH 2/3] virtio-net: Only enable userland vq if using tap backend

2021-11-21 Thread Jason Wang
On Mon, Nov 22, 2021 at 2:24 PM Eugenio Perez Martin
 wrote:
>
> On Mon, Nov 22, 2021 at 3:39 AM Jason Wang  wrote:
> >
> > On Fri, Nov 19, 2021 at 3:50 PM Eugenio Perez Martin
> >  wrote:
> > >
> > > On Fri, Nov 19, 2021 at 3:44 AM Jason Wang  wrote:
> > > >
> > > > On Thu, Nov 18, 2021 at 3:57 PM Eugenio Perez Martin
> > > >  wrote:
> > > > >
> > > > > On Thu, Nov 18, 2021 at 6:06 AM Jason Wang  
> > > > > wrote:
> > > > > >
> > > > > > On Thu, Nov 18, 2021 at 3:29 AM Eugenio Pérez  
> > > > > > wrote:
> > > > > > >
> > > > > > > Qemu falls back on userland handlers even if vhost-user and 
> > > > > > > vhost-vdpa
> > > > > > > cases. These assumes a tap device can handle the packets.
> > > > > > >
> > > > > > > If a vdpa device fail to start, it can trigger a sigsegv because 
> > > > > > > of
> > > > > > > that. Do not resort on them unless actually possible.
> > > > > >
> > > > > > It would be better to show the calltrace here then we can see the 
> > > > > > root cause.
> > > > > >
> > > > >
> > > > > Sure, I'll paste here and I'll resend to the next version:
> > > > > #1  0x55955f696e92 in nc_sendv_compat (flags=,
> > > > > iovcnt=2, iov=0x7ffe73abe300, nc=0x7fcf22d6d010) at ../net/net.c:756
> > > > > #2  qemu_deliver_packet_iov (sender=,
> > > > > opaque=0x7fcf22d6d010, iovcnt=2, iov=0x7ffe73abe300, flags= > > > > out>) at ../net/net.c:784
> > > > > #3  qemu_deliver_packet_iov (sender=, flags= > > > > out>, iov=0x7ffe73abe300, iovcnt=2, opaque=0x7fcf22d6d010) at
> > > > > ../net/net.c:763
> > > > > #4  0x55955f69a078 in qemu_net_queue_deliver_iov (iovcnt=2,
> > > > > iov=0x7ffe73abe300, flags=0, sender=0x5595631f5ac0,
> > > > > queue=0x559561c7baa0) at ../net/queue.c:179
> > > > > #5  qemu_net_queue_send_iov (queue=0x559561c7baa0,
> > > > > sender=0x5595631f5ac0, flags=flags@entry=0,
> > > > > iov=iov@entry=0x7ffe73abe300,
> > > > > iovcnt=iovcnt@entry=2, sent_cb=sent_cb@entry=0x55955f82ae60
> > > > > ) at ../net/queue.c:246
> > > > > #6  0x55955f697d43 in qemu_sendv_packet_async
> > > > > (sent_cb=0x55955f82ae60 , iovcnt=2,
> > > > > iov=0x7ffe73abe300,
> > > > > sender=) at ../net/net.c:825
> > > > > #7  qemu_sendv_packet_async (sender=,
> > > > > iov=iov@entry=0x7ffe73abe300, iovcnt=iovcnt@entry=1662966768,
> > > > > sent_cb=sent_cb@entry=0x55955f82ae60 ) at
> > > > > ../net/net.c:794
> > > > > #8  0x55955f82aba9 in virtio_net_flush_tx (q=0x0,
> > > > > q@entry=0x5595631edbf0) at ../hw/net/virtio-net.c:2577
> > > > > #9  0x55955f82ade8 in virtio_net_tx_bh (opaque=0x5595631edbf0) at
> > > > > ../hw/net/virtio-net.c:2694
> > > > > #10 0x55955f9e847d in aio_bh_call (bh=0x559561c7e590) at 
> > > > > ../util/async.c:169
> > > > > #11 aio_bh_poll (ctx=ctx@entry=0x559561c81650) at ../util/async.c:169
> > > > > #12 0x55955f9d6912 in aio_dispatch (ctx=0x559561c81650) at
> > > > > ../util/aio-posix.c:381
> > > > > #13 0x55955f9e8322 in aio_ctx_dispatch (source=,
> > > > > callback=, user_data=)
> > > > > at ../util/async.c:311
> > > > > #14 0x7fcf20a5495d in g_main_context_dispatch () from
> > > > > /lib64/libglib-2.0.so.0
> > > > > #15 0x55955f9f2fc0 in glib_pollfds_poll () at 
> > > > > ../util/main-loop.c:232
> > > > > #16 os_host_main_loop_wait (timeout=) at 
> > > > > ../util/main-loop.c:255
> > > > > #17 main_loop_wait (nonblocking=nonblocking@entry=0) at 
> > > > > ../util/main-loop.c:531
> > > > > #18 0x55955f7eee49 in qemu_main_loop () at 
> > > > > ../softmmu/runstate.c:726
> > > > > #19 0x55955f6235c2 in main (argc=, argv= > > > > out>, envp=) at ../softmmu/main.c:50
> > > > >
> > > > > In nc_sendv_compat, nc->info is net_vhost_vdpa_info, so
> > > > > nc->info->receive is NULL.
> > > > >
> > > > > > >
> > > > > > > Signed-off-by: Eugenio Pérez 
> > > > > > > ---
> > > > > > >  include/hw/virtio/virtio.h |  2 ++
> > > > > > >  hw/net/virtio-net.c|  4 
> > > > > > >  hw/virtio/virtio.c | 21 +
> > > > > > >  3 files changed, 19 insertions(+), 8 deletions(-)
> > > > > > >
> > > > > > > diff --git a/include/hw/virtio/virtio.h 
> > > > > > > b/include/hw/virtio/virtio.h
> > > > > > > index 8bab9cfb75..1712ba0b4c 100644
> > > > > > > --- a/include/hw/virtio/virtio.h
> > > > > > > +++ b/include/hw/virtio/virtio.h
> > > > > > > @@ -105,6 +105,8 @@ struct VirtIODevice
> > > > > > >  VMChangeStateEntry *vmstate;
> > > > > > >  char *bus_name;
> > > > > > >  uint8_t device_endian;
> > > > > > > +/* backend does not support userspace handler */
> > > > > > > +bool disable_ioeventfd_handler;
> > > > > > >  bool use_guest_notifier_mask;
> > > > > > >  AddressSpace *dma_as;
> > > > > > >  QLIST_HEAD(, VirtQueue) *vector_queues;
> > > > > > > diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> > > > > > > index 004acf858f..8c5c4e5a9d 100644
> > > > > > > --- a/hw/net/virtio-net.c
> > > > > > > +++ b/hw/net/virtio-net.c
> > > > > > > @@ -3501,6 +3501,10 @@ static void 
>

Re: [PATCH 2/3] vdpa: Add dummy receive callbacks

2021-11-21 Thread Eugenio Perez Martin
On Mon, Nov 22, 2021 at 4:55 AM Jason Wang  wrote:
>
> On Fri, Nov 19, 2021 at 6:20 PM Eugenio Pérez  wrote:
> >
> > Qemu falls back on userland handlers even if vhost-user and vhost-vdpa
> > cases. These assumes a tap device can handle the packets.
> >
> > If a vdpa device fail to start, it can trigger a sigsegv because of
> > that. Add dummy receivers that return no progress so it can keep
> > running.
> >
> > Fixes: 1e0a84ea49 ("vhost-vdpa: introduce vhost-vdpa net client")
> > Signed-off-by: Eugenio Pérez 
> > ---
> >  net/vhost-vdpa.c | 16 
> >  1 file changed, 16 insertions(+)
> >
> > diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
> > index 2e3c22a8c7..4c75b78304 100644
> > --- a/net/vhost-vdpa.c
> > +++ b/net/vhost-vdpa.c
> > @@ -170,9 +170,25 @@ static bool vhost_vdpa_check_peer_type(NetClientState 
> > *nc, ObjectClass *oc,
> >  return true;
> >  }
> >
> > +/** Dummy receive in case qemu falls back to userland tap networking */
> > +static ssize_t vhost_vdpa_receive_iov(NetClientState *nc,
> > +  const struct iovec *iov, int iovcnt)
> > +{
> > +return 0;
> > +}
> > +
> > +/** Dummy receive in case qemu falls back to userland tap networking */
> > +static ssize_t vhost_vdpa_receive_raw(NetClientState *nc, const uint8_t 
> > *buf,
> > +  size_t size)
> > +{
> > +return 0;
> > +}
>
> It looks to me the .receive_raw is not need, in nc_sendv_compat() we had:
>
> =>  if (flags & QEMU_NET_PACKET_FLAG_RAW && nc->info->receive_raw) {
> ret = nc->info->receive_raw(nc, buffer, offset);
> } else {
> ret = nc->info->receive(nc, buffer, offset);
> }
>

Right, I will delete the _raw part.

Thanks!

> Thanks
>
> > +
> >  static NetClientInfo net_vhost_vdpa_info = {
> >  .type = NET_CLIENT_DRIVER_VHOST_VDPA,
> >  .size = sizeof(VhostVDPAState),
> > +.receive_iov = vhost_vdpa_receive_iov,
> > +.receive_raw = vhost_vdpa_receive_raw,
> >  .cleanup = vhost_vdpa_cleanup,
> >  .has_vnet_hdr = vhost_vdpa_has_vnet_hdr,
> >  .has_ufo = vhost_vdpa_has_ufo,
> > --
> > 2.27.0
> >
>




[PULL 0/2] riscv-to-apply queue

2021-11-21 Thread Alistair Francis
From: Alistair Francis 

The following changes since commit c5fbdd60cf1fb52f01bdfe342b6fa65d5343e1b1:

  Merge tag 'qemu-sparc-20211121' of git://github.com/mcayland/qemu into 
staging (2021-11-21 14:12:25 +0100)

are available in the Git repository at:

  g...@github.com:alistair23/qemu.git tags/pull-riscv-to-apply-20211122

for you to fetch changes up to 526e7443027c71fe7b04c29df529e1f9f425f9e3:

  hw/misc/sifive_u_otp: Do not reset OTP content on hardware reset (2021-11-22 
10:46:22 +1000)


Seventh RISC-V PR for QEMU 6.2

 - Deprecate IF_NONE for SiFive OTP
 - Don't reset SiFive OTP content


Philippe Mathieu-Daudé (1):
  hw/misc/sifive_u_otp: Do not reset OTP content on hardware reset

Thomas Huth (1):
  hw/misc/sifive_u_otp: Use IF_PFLASH for the OTP device instead of IF_NONE

 docs/about/deprecated.rst |  6 ++
 hw/misc/sifive_u_otp.c| 22 +-
 2 files changed, 19 insertions(+), 9 deletions(-)



[PULL 1/2] hw/misc/sifive_u_otp: Use IF_PFLASH for the OTP device instead of IF_NONE

2021-11-21 Thread Alistair Francis
From: Thomas Huth 

Configuring a drive with "if=none" is meant for creation of a backend
only, it should not get automatically assigned to a device frontend.
Use "if=pflash" for the One-Time-Programmable device instead (like
it is e.g. also done for the efuse device in hw/arm/xlnx-zcu102.c).

Since the old way of configuring the device has already been published
with the previous QEMU versions, we cannot remove this immediately, but
have to deprecate it and support it for at least two more releases.

Signed-off-by: Thomas Huth 
Acked-by: Philippe Mathieu-Daudé 
Reviewed-by: Markus Armbruster 
Reviewed-by: Alistair Francis 
Message-id: 2029102549.217755-1-th...@redhat.com
Signed-off-by: Alistair Francis 
---
 docs/about/deprecated.rst | 6 ++
 hw/misc/sifive_u_otp.c| 9 -
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst
index c03fcf951f..ff7488cb63 100644
--- a/docs/about/deprecated.rst
+++ b/docs/about/deprecated.rst
@@ -192,6 +192,12 @@ as short-form boolean values, and passed to plugins as 
``arg_name=on``.
 However, short-form booleans are deprecated and full explicit ``arg_name=on``
 form is preferred.
 
+``-drive if=none`` for the sifive_u OTP device (since 6.2)
+''
+
+Using ``-drive if=none`` to configure the OTP device of the sifive_u
+RISC-V machine is deprecated. Use ``-drive if=pflash`` instead.
+
 
 QEMU Machine Protocol (QMP) commands
 
diff --git a/hw/misc/sifive_u_otp.c b/hw/misc/sifive_u_otp.c
index 18aa0bd55d..cf6098ff2c 100644
--- a/hw/misc/sifive_u_otp.c
+++ b/hw/misc/sifive_u_otp.c
@@ -209,7 +209,14 @@ static void sifive_u_otp_realize(DeviceState *dev, Error 
**errp)
   TYPE_SIFIVE_U_OTP, SIFIVE_U_OTP_REG_SIZE);
 sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mmio);
 
-dinfo = drive_get_next(IF_NONE);
+dinfo = drive_get_next(IF_PFLASH);
+if (!dinfo) {
+dinfo = drive_get_next(IF_NONE);
+if (dinfo) {
+warn_report("using \"-drive if=none\" for the OTP is deprecated, "
+"use \"-drive if=pflash\" instead.");
+}
+}
 if (dinfo) {
 int ret;
 uint64_t perm;
-- 
2.31.1




[PULL 2/2] hw/misc/sifive_u_otp: Do not reset OTP content on hardware reset

2021-11-21 Thread Alistair Francis
From: Philippe Mathieu-Daudé 

Once a "One Time Programmable" is programmed, it shouldn't be reset.

Do not re-initialize the OTP content in the DeviceReset handler,
initialize it once in the DeviceRealize one.

Fixes: 9fb45c62ae8 ("riscv: sifive: Implement a model for SiFive FU540 OTP")
Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Alistair Francis 
Message-Id: <2029104757.331579-1-f4...@amsat.org>
Signed-off-by: Alistair Francis 
---
 hw/misc/sifive_u_otp.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/hw/misc/sifive_u_otp.c b/hw/misc/sifive_u_otp.c
index cf6098ff2c..52fdb750c0 100644
--- a/hw/misc/sifive_u_otp.c
+++ b/hw/misc/sifive_u_otp.c
@@ -242,14 +242,10 @@ static void sifive_u_otp_realize(DeviceState *dev, Error 
**errp)
 
 if (blk_pread(s->blk, 0, s->fuse, filesize) != filesize) {
 error_setg(errp, "failed to read the initial flash content");
+return;
 }
 }
 }
-}
-
-static void sifive_u_otp_reset(DeviceState *dev)
-{
-SiFiveUOTPState *s = SIFIVE_U_OTP(dev);
 
 /* Initialize all fuses' initial value to 0xFFs */
 memset(s->fuse, 0xff, sizeof(s->fuse));
@@ -266,13 +262,15 @@ static void sifive_u_otp_reset(DeviceState *dev)
 serial_data = s->serial;
 if (blk_pwrite(s->blk, index * SIFIVE_U_OTP_FUSE_WORD,
&serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) {
-error_report("write error index<%d>", index);
+error_setg(errp, "failed to write index<%d>", index);
+return;
 }
 
 serial_data = ~(s->serial);
 if (blk_pwrite(s->blk, (index + 1) * SIFIVE_U_OTP_FUSE_WORD,
&serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) {
-error_report("write error index<%d>", index + 1);
+error_setg(errp, "failed to write index<%d>", index + 1);
+return;
 }
 }
 
@@ -286,7 +284,6 @@ static void sifive_u_otp_class_init(ObjectClass *klass, 
void *data)
 
 device_class_set_props(dc, sifive_u_otp_properties);
 dc->realize = sifive_u_otp_realize;
-dc->reset = sifive_u_otp_reset;
 }
 
 static const TypeInfo sifive_u_otp_info = {
-- 
2.31.1




Re: [PATCH v3 3/3] cpus-common: implement dirty limit on vCPU

2021-11-21 Thread Markus Armbruster
huang...@chinatelecom.cn writes:

> From: Hyman Huang(黄勇) 
>
> implement dirtyrate calculation periodically basing on
> dirty-ring and throttle vCPU until it reachs the quota
> dirtyrate given by user.
>
> introduce qmp commands set-dirty-limit/cancel-dirty-limit to
> set/cancel dirty limit on vCPU.

Please start sentences with a capital letter.

>
> Signed-off-by: Hyman Huang(黄勇) 

[...]

> diff --git a/qapi/misc.json b/qapi/misc.json
> index 358548a..98e6001 100644
> --- a/qapi/misc.json
> +++ b/qapi/misc.json
> @@ -527,3 +527,42 @@
>   'data': { '*option': 'str' },
>   'returns': ['CommandLineOptionInfo'],
>   'allow-preconfig': true }
> +
> +##
> +# @set-dirty-limit:
> +#
> +# This command could be used to cap the vCPU memory load, which is also
> +# refered as dirtyrate. One should use "calc-dirty-rate" with "dirty-ring"
> +# and to calculate vCPU dirtyrate and query it with "query-dirty-rate".
> +# Once getting the vCPU current dirtyrate, "set-dirty-limit" can be used
> +# to set the upper limit of dirtyrate for the interested vCPU.

"dirtyrate" is not a word.  Let's spell it "dirty page rate", for
consistency with the documentation in migration.json.

Regarding "One should use ...": sounds like you have to run
calc-dirty-rate with argument @mode set to @dirty-ring before this
command.  Correct?  What happens when you don't?  set-dirty-limit fails?

Do you also have to run query-dirty-rate before this command?

Speaking of migration.json: should these commands be defined there, next
to calc-dirty-rate and query-dirty-rate?

> +#
> +# @idx: vCPU index to set dirtylimit.
> +#
> +# @dirtyrate: upper limit of drityrate the specified vCPU could reach (MB/s)

Typo "drityrate".

Suggest "upper limit for the specified vCPU's dirty page rate (MB/s)".

> +#
> +# Since: 6.3
> +#
> +# Example:
> +#   {"execute": "set-dirty-limit"}
> +#"arguments": { "idx": 0,
> +#   "dirtyrate": 200 } }
> +#
> +##
> +{ 'command': 'set-dirty-limit',
> +  'data': { 'idx': 'int', 'dirtyrate': 'uint64' } }
> +
> +##
> +# @cancel-dirty-limit:
> +#
> +# @idx: vCPU index to canceled the dirtylimit
> +#
> +# Since: 6.3
> +#
> +# Example:
> +#   {"execute": "cancel-dirty-limit"}
> +#"arguments": { "idx": 0 } }
> +#
> +##
> +{ 'command': 'cancel-dirty-limit',
> +  'data': { 'idx': 'int' } }
> diff --git a/softmmu/vl.c b/softmmu/vl.c
> index 1159a64..170ee23 100644
> --- a/softmmu/vl.c
> +++ b/softmmu/vl.c
> @@ -3776,5 +3776,6 @@ void qemu_init(int argc, char **argv, char **envp)
>  qemu_init_displays();
>  accel_setup_post(current_machine);
>  os_setup_post();
> +dirtylimit_setup(current_machine->smp.max_cpus);
>  resume_mux_open();
>  }




Re: [PATCH 2/2] docs: Use double quotes instead of single quotes for COLO

2021-11-21 Thread Markus Armbruster
Looks like this is based on your "[PATCH] docs/COLO-FT.txt: Drop
deprecated 'props' from object-add in COLO docs".  To make things easier
for reviewers and maintainers, please resend all three patches together
in a single series.  I'd squash "[PATCH] docs/COLO-FT.txt: Drop
deprecated 'props' from object-add in COLO docs" and "[PATCH 1/2] docs:
Drop deprecated 'props' from object-add" together.

Thanks!




[PATCH v2 1/2] docs: Drop deprecated 'props' from object-add

2021-11-21 Thread Rao, Lei
From: "Rao, Lei" 

In commit 5024340745 "qapi/qom: Drop deprecated 'props' from
object-add" (v6.0.0), we also should update documents.

Signed-off-by: Lei Rao 
---
 docs/COLO-FT.txt| 16 
 docs/system/authz.rst   | 26 ++
 docs/throttle.txt   |  8 +++-
 docs/tools/qemu-nbd.rst |  2 +-
 4 files changed, 22 insertions(+), 30 deletions(-)

diff --git a/docs/COLO-FT.txt b/docs/COLO-FT.txt
index 8d6d53a..fd5ffcc 100644
--- a/docs/COLO-FT.txt
+++ b/docs/COLO-FT.txt
@@ -289,11 +289,11 @@ Wait until disk is synced, then:
 {'execute': 'human-monitor-command', 'arguments':{ 'command-line': 'drive_add 
-n buddy 
driver=replication,mode=primary,file.driver=nbd,file.host=127.0.0.2,file.port=,file.export=parent0,node-name=replication0'}}
 {'execute': 'x-blockdev-change', 'arguments':{ 'parent': 'colo-disk0', 'node': 
'replication0' } }
 
-{'execute': 'object-add', 'arguments':{ 'qom-type': 'filter-mirror', 'id': 
'm0', 'props': { 'netdev': 'hn0', 'queue': 'tx', 'outdev': 'mirror0' } } }
-{'execute': 'object-add', 'arguments':{ 'qom-type': 'filter-redirector', 'id': 
'redire0', 'props': { 'netdev': 'hn0', 'queue': 'rx', 'indev': 'compare_out' } 
} }
-{'execute': 'object-add', 'arguments':{ 'qom-type': 'filter-redirector', 'id': 
'redire1', 'props': { 'netdev': 'hn0', 'queue': 'rx', 'outdev': 'compare0' } } }
+{'execute': 'object-add', 'arguments':{ 'qom-type': 'filter-mirror', 'id': 
'm0', 'netdev': 'hn0', 'queue': 'tx', 'outdev': 'mirror0' } }
+{'execute': 'object-add', 'arguments':{ 'qom-type': 'filter-redirector', 'id': 
'redire0', 'netdev': 'hn0', 'queue': 'rx', 'indev': 'compare_out' } }
+{'execute': 'object-add', 'arguments':{ 'qom-type': 'filter-redirector', 'id': 
'redire1', 'netdev': 'hn0', 'queue': 'rx', 'outdev': 'compare0' } }
 {'execute': 'object-add', 'arguments':{ 'qom-type': 'iothread', 'id': 
'iothread1' } }
-{'execute': 'object-add', 'arguments':{ 'qom-type': 'colo-compare', 'id': 
'comp0', 'props': { 'primary_in': 'compare0-0', 'secondary_in': 'compare1', 
'outdev': 'compare_out0', 'iothread': 'iothread1' } } }
+{'execute': 'object-add', 'arguments':{ 'qom-type': 'colo-compare', 'id': 
'comp0', 'primary_in': 'compare0-0', 'secondary_in': 'compare1', 'outdev': 
'compare_out0', 'iothread': 'iothread1' } }
 
 {'execute': 'migrate-set-capabilities', 'arguments':{ 'capabilities': [ 
{'capability': 'x-colo', 'state': true } ] } }
 {'execute': 'migrate', 'arguments':{ 'uri': 'tcp:127.0.0.2:9998' } }
@@ -318,11 +318,11 @@ Wait until disk is synced, then:
 {'execute': 'human-monitor-command', 'arguments':{ 'command-line': 'drive_add 
-n buddy 
driver=replication,mode=primary,file.driver=nbd,file.host=127.0.0.1,file.port=,file.export=parent0,node-name=replication0'}}
 {'execute': 'x-blockdev-change', 'arguments':{ 'parent': 'colo-disk0', 'node': 
'replication0' } }
 
-{'execute': 'object-add', 'arguments':{ 'qom-type': 'filter-mirror', 'id': 
'm0', 'props': { 'insert': 'before', 'position': 'id=rew0', 'netdev': 'hn0', 
'queue': 'tx', 'outdev': 'mirror0' } } }
-{'execute': 'object-add', 'arguments':{ 'qom-type': 'filter-redirector', 'id': 
'redire0', 'props': { 'insert': 'before', 'position': 'id=rew0', 'netdev': 
'hn0', 'queue': 'rx', 'indev': 'compare_out' } } }
-{'execute': 'object-add', 'arguments':{ 'qom-type': 'filter-redirector', 'id': 
'redire1', 'props': { 'insert': 'before', 'position': 'id=rew0', 'netdev': 
'hn0', 'queue': 'rx', 'outdev': 'compare0' } } }
+{'execute': 'object-add', 'arguments':{ 'qom-type': 'filter-mirror', 'id': 
'm0', 'insert': 'before', 'position': 'id=rew0', 'netdev': 'hn0', 'queue': 
'tx', 'outdev': 'mirror0' } }
+{'execute': 'object-add', 'arguments':{ 'qom-type': 'filter-redirector', 'id': 
'redire0', 'insert': 'before', 'position': 'id=rew0', 'netdev': 'hn0', 'queue': 
'rx', 'indev': 'compare_out' } }
+{'execute': 'object-add', 'arguments':{ 'qom-type': 'filter-redirector', 'id': 
'redire1', 'insert': 'before', 'position': 'id=rew0', 'netdev': 'hn0', 'queue': 
'rx', 'outdev': 'compare0' } }
 {'execute': 'object-add', 'arguments':{ 'qom-type': 'iothread', 'id': 
'iothread1' } }
-{'execute': 'object-add', 'arguments':{ 'qom-type': 'colo-compare', 'id': 
'comp0', 'props': { 'primary_in': 'compare0-0', 'secondary_in': 'compare1', 
'outdev': 'compare_out0', 'iothread': 'iothread1' } } }
+{'execute': 'object-add', 'arguments':{ 'qom-type': 'colo-compare', 'id': 
'comp0', 'primary_in': 'compare0-0', 'secondary_in': 'compare1', 'outdev': 
'compare_out0', 'iothread': 'iothread1' } }
 
 {'execute': 'migrate-set-capabilities', 'arguments':{ 'capabilities': [ 
{'capability': 'x-colo', 'state': true } ] } }
 {'execute': 'migrate', 'arguments':{ 'uri': 'tcp:127.0.0.1:9998' } }
diff --git a/docs/system/authz.rst b/docs/system/authz.rst
index 942af39..55b7315 100644
--- a/docs/system/authz.rst
+++ b/docs/system/authz.rst
@@ -77,9 +77,7 @@ To create an instance of this driver via QMP:
  "arguments": {
"qom-type": "authz-s

[PATCH v2 2/2] docs: Use double quotes instead of single quotes for COLO

2021-11-21 Thread Rao, Lei
From: "Rao, Lei" 

Signed-off-by: Lei Rao 
---
 docs/COLO-FT.txt   | 106 ++---
 docs/block-replication.txt |  52 +++---
 2 files changed, 79 insertions(+), 79 deletions(-)

diff --git a/docs/COLO-FT.txt b/docs/COLO-FT.txt
index fd5ffcc..8ec653f 100644
--- a/docs/COLO-FT.txt
+++ b/docs/COLO-FT.txt
@@ -209,9 +209,9 @@ children.0=childs0 \
 
 
 3. On Secondary VM's QEMU monitor, issue command
-{'execute':'qmp_capabilities'}
-{'execute': 'nbd-server-start', 'arguments': {'addr': {'type': 'inet', 'data': 
{'host': '0.0.0.0', 'port': ''} } } }
-{'execute': 'nbd-server-add', 'arguments': {'device': 'parent0', 'writable': 
true } }
+{"execute":"qmp_capabilities"}
+{"execute": "nbd-server-start", "arguments": {"addr": {"type": "inet", "data": 
{"host": "0.0.0.0", "port": ""} } } }
+{"execute": "nbd-server-add", "arguments": {"device": "parent0", "writable": 
true } }
 
 Note:
   a. The qmp command nbd-server-start and nbd-server-add must be run
@@ -222,11 +222,11 @@ Note:
  will be merged into the parent disk on failover.
 
 4. On Primary VM's QEMU monitor, issue command:
-{'execute':'qmp_capabilities'}
-{'execute': 'human-monitor-command', 'arguments': {'command-line': 'drive_add 
-n buddy 
driver=replication,mode=primary,file.driver=nbd,file.host=127.0.0.2,file.port=,file.export=parent0,node-name=replication0'}}
-{'execute': 'x-blockdev-change', 'arguments':{'parent': 'colo-disk0', 'node': 
'replication0' } }
-{'execute': 'migrate-set-capabilities', 'arguments': {'capabilities': [ 
{'capability': 'x-colo', 'state': true } ] } }
-{'execute': 'migrate', 'arguments': {'uri': 'tcp:127.0.0.2:9998' } }
+{"execute":"qmp_capabilities"}
+{"execute": "human-monitor-command", "arguments": {"command-line": "drive_add 
-n buddy 
driver=replication,mode=primary,file.driver=nbd,file.host=127.0.0.2,file.port=,file.export=parent0,node-name=replication0"}}
+{"execute": "x-blockdev-change", "arguments":{"parent": "colo-disk0", "node": 
"replication0" } }
+{"execute": "migrate-set-capabilities", "arguments": {"capabilities": [ 
{"capability": "x-colo", "state": true } ] } }
+{"execute": "migrate", "arguments": {"uri": "tcp:127.0.0.2:9998" } }
 
   Note:
   a. There should be only one NBD Client for each primary disk.
@@ -249,59 +249,59 @@ if you want to resume the replication, follow "Secondary 
resume replication"
 == Primary Failover ==
 The Secondary died, resume on the Primary
 
-{'execute': 'x-blockdev-change', 'arguments':{ 'parent': 'colo-disk0', 
'child': 'children.1'} }
-{'execute': 'human-monitor-command', 'arguments':{ 'command-line': 'drive_del 
replication0' } }
-{'execute': 'object-del', 'arguments':{ 'id': 'comp0' } }
-{'execute': 'object-del', 'arguments':{ 'id': 'iothread1' } }
-{'execute': 'object-del', 'arguments':{ 'id': 'm0' } }
-{'execute': 'object-del', 'arguments':{ 'id': 'redire0' } }
-{'execute': 'object-del', 'arguments':{ 'id': 'redire1' } }
-{'execute': 'x-colo-lost-heartbeat' }
+{"execute": "x-blockdev-change", "arguments":{ "parent": "colo-disk0", 
"child": "children.1"} }
+{"execute": "human-monitor-command", "arguments":{ "command-line": "drive_del 
replication0" } }
+{"execute": "object-del", "arguments":{ "id": "comp0" } }
+{"execute": "object-del", "arguments":{ "id": "iothread1" } }
+{"execute": "object-del", "arguments":{ "id": "m0" } }
+{"execute": "object-del", "arguments":{ "id": "redire0" } }
+{"execute": "object-del", "arguments":{ "id": "redire1" } }
+{"execute": "x-colo-lost-heartbeat" }
 
 == Secondary Failover ==
 The Primary died, resume on the Secondary and prepare to become the new Primary
 
-{'execute': 'nbd-server-stop'}
-{'execute': 'x-colo-lost-heartbeat'}
+{"execute": "nbd-server-stop"}
+{"execute": "x-colo-lost-heartbeat"}
 
-{'execute': 'object-del', 'arguments':{ 'id': 'f2' } }
-{'execute': 'object-del', 'arguments':{ 'id': 'f1' } }
-{'execute': 'chardev-remove', 'arguments':{ 'id': 'red1' } }
-{'execute': 'chardev-remove', 'arguments':{ 'id': 'red0' } }
+{"execute": "object-del", "arguments":{ "id": "f2" } }
+{"execute": "object-del", "arguments":{ "id": "f1" } }
+{"execute": "chardev-remove", "arguments":{ "id": "red1" } }
+{"execute": "chardev-remove", "arguments":{ "id": "red0" } }
 
-{'execute': 'chardev-add', 'arguments':{ 'id': 'mirror0', 'backend': {'type': 
'socket', 'data': {'addr': { 'type': 'inet', 'data': { 'host': '0.0.0.0', 
'port': '9003' } }, 'server': true } } } }
-{'execute': 'chardev-add', 'arguments':{ 'id': 'compare1', 'backend': {'type': 
'socket', 'data': {'addr': { 'type': 'inet', 'data': { 'host': '0.0.0.0', 
'port': '9004' } }, 'server': true } } } }
-{'execute': 'chardev-add', 'arguments':{ 'id': 'compare0', 'backend': {'type': 
'socket', 'data': {'addr': { 'type': 'inet', 'data': { 'host': '127.0.0.1', 
'port': '9001' } }, 'server': true } } } }
-{'execute': 'chardev-add', 'arguments':{ 'id': 'compare0-0', 'backend': 
{'type': 'socket', 'data': {'addr': { 'type': '