Re: [PATCH for-7.1 09/11] pc-bios: Add NPCM8xx Bootrom

2022-04-21 Thread Peter Maydell
On Tue, 5 Apr 2022 at 23:38, Hao Wu  wrote:
>
> The bootrom is a minimal bootrom that can be used to bring up
> an NPCM845 Linux kernel. Its source code can be found at
> github.com/google/vbootrom/tree/master/npcm8xx
>
> Signed-off-by: Hao Wu 
> Reviwed-by: Titus Rwantare 
> ---
>  pc-bios/npcm8xx_bootrom.bin | Bin 0 -> 608 bytes
>  1 file changed, 0 insertions(+), 0 deletions(-)
>  create mode 100644 pc-bios/npcm8xx_bootrom.bin
>
> diff --git a/pc-bios/npcm8xx_bootrom.bin b/pc-bios/npcm8xx_bootrom.bin
> new file mode 100644
> index 
> ..6370d6475635c4d445d2b927311edcd591949c82
> GIT binary patch
> literal 608
> zcmdUrKTE?<6vfX=0{*3B5ET?nwWA^;qEk()n=Xb9-4dxoSBrz#p|QJQL~zokn{Eyc
> z?PBXUkU+aB?k?IbNQftG5ej|*FC2c{bKkr7zLy3jhNxj`gc_y5h&V=Ru)PgZC)Y`f
> zTqA9Am28qLHlr*^&hT#;re-)dpxT0U42|O+cWOcx=B;{6xXH04vx?cjm
> z+%U{oFx!aPpV3>ZKz0i$XA-yq{f} zl3%RlR5(6+1;xg_<~xR#bPItDN1*Hp^{JyNs7o*BMq0Q9q1#>x4;|pb zTac^w;l#@9zGd|z-rs*H@V-o%PEV)D-)8n2%DyH5@w_^Y8
> LH5R3RMV#gjxYTW}

You can't just dump a sourceless binary into pc-bios/.
Check out the commit that added the npcm7xx bootrom blob
for what else you need: that's commit d1cb5eda67a0a6.

In particular you need to document it in the README file, and have
runes in the Makefile to rebuild the blob from source (and running
the Makefile should be how the blob in the commit was created!).
You'll probably also want a preceding commit to bump the vbootrom
submodule commit and provide a fresh npcm7xx_bootrom blob from
whatever commit you choose to bump the submodule to.

thanks
-- PMM



[PULL 18/31] hw/arm/exynos4210: Delete unused macro definitions

2022-04-21 Thread Peter Maydell
Delete a couple of #defines which are never used.

Signed-off-by: Peter Maydell 
Reviewed-by: Richard Henderson 
Message-id: 20220404154658.565020-12-peter.mayd...@linaro.org
---
 include/hw/arm/exynos4210.h | 4 
 1 file changed, 4 deletions(-)

diff --git a/include/hw/arm/exynos4210.h b/include/hw/arm/exynos4210.h
index b564e3582bb..f0769a4045b 100644
--- a/include/hw/arm/exynos4210.h
+++ b/include/hw/arm/exynos4210.h
@@ -67,10 +67,6 @@
 #define EXYNOS4210_MAX_EXT_COMBINER_IN_IRQ   \
 (EXYNOS4210_MAX_EXT_COMBINER_OUT_IRQ * 8)
 
-/* IRQs number for external and internal GIC */
-#define EXYNOS4210_EXT_GIC_NIRQ (160-32)
-#define EXYNOS4210_INT_GIC_NIRQ 64
-
 #define EXYNOS4210_I2C_NUMBER   9
 
 #define EXYNOS4210_NUM_DMA  3
-- 
2.25.1




[PULL 25/31] hw/arm/exynos4210: Drop Exynos4210Irq struct

2022-04-21 Thread Peter Maydell
The only time we use the int_combiner_irq[] and ext_combiner_irq[]
arrays in the Exynos4210Irq struct is during realize of the SoC -- we
initialize them with the input IRQs of the combiner devices, and then
connect those to outputs of other devices in
exynos4210_init_board_irqs().  Now that the combiner objects are
easily accessible as s->int_combiner and s->ext_combiner we can make
the connections directly from one device to the other without going
via these arrays.

Since these are the only two remaining elements of Exynos4210Irq,
we can remove that struct entirely.

Signed-off-by: Peter Maydell 
Reviewed-by: Richard Henderson 
Message-id: 20220404154658.565020-19-peter.mayd...@linaro.org
---
 include/hw/arm/exynos4210.h |  6 --
 hw/arm/exynos4210.c | 34 --
 2 files changed, 8 insertions(+), 32 deletions(-)

diff --git a/include/hw/arm/exynos4210.h b/include/hw/arm/exynos4210.h
index d38be8767b3..97353f1c02f 100644
--- a/include/hw/arm/exynos4210.h
+++ b/include/hw/arm/exynos4210.h
@@ -82,17 +82,11 @@
  */
 #define EXYNOS4210_NUM_SPLITTERS (EXYNOS4210_MAX_EXT_COMBINER_IN_IRQ + 38)
 
-typedef struct Exynos4210Irq {
-qemu_irq int_combiner_irq[EXYNOS4210_MAX_INT_COMBINER_IN_IRQ];
-qemu_irq ext_combiner_irq[EXYNOS4210_MAX_EXT_COMBINER_IN_IRQ];
-} Exynos4210Irq;
-
 struct Exynos4210State {
 /*< private >*/
 SysBusDevice parent_obj;
 /*< public >*/
 ARMCPU *cpu[EXYNOS4210_NCPUS];
-Exynos4210Irq irqs;
 qemu_irq irq_table[EXYNOS4210_MAX_INT_COMBINER_IN_IRQ];
 
 MemoryRegion chipid_mem;
diff --git a/hw/arm/exynos4210.c b/hw/arm/exynos4210.c
index 27c6ab27123..8dafa2215b6 100644
--- a/hw/arm/exynos4210.c
+++ b/hw/arm/exynos4210.c
@@ -331,8 +331,9 @@ static int mapline_size(const int *mapline)
 static void exynos4210_init_board_irqs(Exynos4210State *s)
 {
 uint32_t grp, bit, irq_id, n;
-Exynos4210Irq *is = &s->irqs;
 DeviceState *extgicdev = DEVICE(&s->ext_gic);
+DeviceState *intcdev = DEVICE(&s->int_combiner);
+DeviceState *extcdev = DEVICE(&s->ext_combiner);
 int splitcount = 0;
 DeviceState *splitter;
 const int *mapline;
@@ -375,8 +376,10 @@ static void exynos4210_init_board_irqs(Exynos4210State *s)
 splitin = 0;
 for (;;) {
 s->irq_table[in] = qdev_get_gpio_in(splitter, 0);
-qdev_connect_gpio_out(splitter, splitin, is->int_combiner_irq[in]);
-qdev_connect_gpio_out(splitter, splitin + 1, 
is->ext_combiner_irq[in]);
+qdev_connect_gpio_out(splitter, splitin,
+  qdev_get_gpio_in(intcdev, in));
+qdev_connect_gpio_out(splitter, splitin + 1,
+  qdev_get_gpio_in(extcdev, in));
 splitin += 2;
 if (!mapline) {
 break;
@@ -414,11 +417,11 @@ static void exynos4210_init_board_irqs(Exynos4210State *s)
 qdev_realize(splitter, NULL, &error_abort);
 splitcount++;
 s->irq_table[n] = qdev_get_gpio_in(splitter, 0);
-qdev_connect_gpio_out(splitter, 0, is->int_combiner_irq[n]);
+qdev_connect_gpio_out(splitter, 0, qdev_get_gpio_in(intcdev, n));
 qdev_connect_gpio_out(splitter, 1,
   qdev_get_gpio_in(extgicdev, irq_id - 32));
 } else {
-s->irq_table[n] = is->int_combiner_irq[n];
+s->irq_table[n] = qdev_get_gpio_in(intcdev, n);
 }
 }
 /*
@@ -440,25 +443,6 @@ uint32_t exynos4210_get_irq(uint32_t grp, uint32_t bit)
 return EXYNOS4210_COMBINER_GET_IRQ_NUM(grp, bit);
 }
 
-/*
- * Get Combiner input GPIO into irqs structure
- */
-static void exynos4210_combiner_get_gpioin(Exynos4210Irq *irqs,
-   DeviceState *dev, int ext)
-{
-int n;
-int max;
-qemu_irq *irq;
-
-max = ext ? EXYNOS4210_MAX_EXT_COMBINER_IN_IRQ :
-EXYNOS4210_MAX_INT_COMBINER_IN_IRQ;
-irq = ext ? irqs->ext_combiner_irq : irqs->int_combiner_irq;
-
-for (n = 0; n < max; n++) {
-irq[n] = qdev_get_gpio_in(dev, n);
-}
-}
-
 static uint8_t chipid_and_omr[] = { 0x11, 0x02, 0x21, 0x43,
 0x09, 0x00, 0x00, 0x00 };
 
@@ -630,7 +614,6 @@ static void exynos4210_realize(DeviceState *socdev, Error 
**errp)
 sysbus_connect_irq(busdev, n,
qdev_get_gpio_in(DEVICE(&s->a9mpcore), n));
 }
-exynos4210_combiner_get_gpioin(&s->irqs, DEVICE(&s->int_combiner), 0);
 sysbus_mmio_map(busdev, 0, EXYNOS4210_INT_COMBINER_BASE_ADDR);
 
 /* External Interrupt Combiner */
@@ -640,7 +623,6 @@ static void exynos4210_realize(DeviceState *socdev, Error 
**errp)
 for (n = 0; n < EXYNOS4210_MAX_INT_COMBINER_OUT_IRQ; n++) {
 sysbus_connect_irq(busdev, n, qdev_get_gpio_in(DEVICE(&s->ext_gic), 
n));
 }
-exynos4210_combiner_get_gpioin(&s->irqs, DEVICE(&s->ext_combiner), 1);
 sysbus_mmio_ma

[PULL 29/31] hw/arm/virt: impact of gic-version on max CPUs

2022-04-21 Thread Peter Maydell
From: Heinrich Schuchardt 

Describe that the gic-version influences the maximum number of CPUs.

Signed-off-by: Heinrich Schuchardt 
Message-id: 20220413231456.35811-1-heinrich.schucha...@canonical.com
[PMM: minor punctuation tweaks]
Reviewed-by: Peter Maydell 
Signed-off-by: Peter Maydell 
---
 docs/system/arm/virt.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/docs/system/arm/virt.rst b/docs/system/arm/virt.rst
index 1544632b674..1297dff5228 100644
--- a/docs/system/arm/virt.rst
+++ b/docs/system/arm/virt.rst
@@ -96,9 +96,9 @@ gic-version
   Valid values are:
 
   ``2``
-GICv2
+GICv2. Note that this limits the number of CPUs to 8.
   ``3``
-GICv3
+GICv3. This allows up to 512 CPUs.
   ``host``
 Use the same GIC version the host provides, when using KVM
   ``max``
-- 
2.25.1




Re: [PATCH v6 2/4] hw/arm/virt: Consider SMP configuration in CPU topology

2022-04-21 Thread Gavin Shan

Hi Igor,

On 4/20/22 10:50 PM, Igor Mammedov wrote:

On Wed, 20 Apr 2022 22:24:46 +0800
Gavin Shan  wrote:

On 4/20/22 7:50 PM, Igor Mammedov wrote:

On Wed, 20 Apr 2022 18:31:02 +0800
Gavin Shan  wrote:

On 4/20/22 4:32 PM, Igor Mammedov wrote:

On Mon, 18 Apr 2022 10:09:18 +0800
Gavin Shan  wrote:
  

Currently, the SMP configuration isn't considered when the CPU
topology is populated. In this case, it's impossible to provide
the default CPU-to-NUMA mapping or association based on the socket
ID of the given CPU.

This takes account of SMP configuration when the CPU topology
is populated. The die ID for the given CPU isn't assigned since
it's not supported on arm/virt machine. Besides, the used SMP
configuration in qtest/numa-test/aarch64_numa_cpu() is corrcted
to avoid testing failure

Signed-off-by: Gavin Shan 
Reviewed-by: Yanan Wang 
---
hw/arm/virt.c   | 15 ++-
tests/qtest/numa-test.c |  3 ++-
2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index d2e5ecd234..5443ecae92 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -2505,6 +2505,7 @@ static const CPUArchIdList 
*virt_possible_cpu_arch_ids(MachineState *ms)
int n;
unsigned int max_cpus = ms->smp.max_cpus;
VirtMachineState *vms = VIRT_MACHINE(ms);
+MachineClass *mc = MACHINE_GET_CLASS(vms);

if (ms->possible_cpus) {

assert(ms->possible_cpus->len == max_cpus);
@@ -2518,8 +2519,20 @@ static const CPUArchIdList 
*virt_possible_cpu_arch_ids(MachineState *ms)
ms->possible_cpus->cpus[n].type = ms->cpu_type;
ms->possible_cpus->cpus[n].arch_id =
virt_cpu_mp_affinity(vms, n);
+
+assert(!mc->smp_props.dies_supported);
+ms->possible_cpus->cpus[n].props.has_socket_id = true;
+ms->possible_cpus->cpus[n].props.socket_id =
+(n / (ms->smp.clusters * ms->smp.cores * ms->smp.threads));
+ms->possible_cpus->cpus[n].props.has_cluster_id = true;
+ms->possible_cpus->cpus[n].props.cluster_id =
+(n / (ms->smp.cores * ms->smp.threads)) % ms->smp.clusters;
+ms->possible_cpus->cpus[n].props.has_core_id = true;
+ms->possible_cpus->cpus[n].props.core_id =
+(n / ms->smp.threads) % ms->smp.cores;
ms->possible_cpus->cpus[n].props.has_thread_id = true;
-ms->possible_cpus->cpus[n].props.thread_id = n;
+ms->possible_cpus->cpus[n].props.thread_id =
+n % ms->smp.threads;
}
return ms->possible_cpus;
}
diff --git a/tests/qtest/numa-test.c b/tests/qtest/numa-test.c
index 90bf68a5b3..aeda8c774c 100644
--- a/tests/qtest/numa-test.c
+++ b/tests/qtest/numa-test.c
@@ -223,7 +223,8 @@ static void aarch64_numa_cpu(const void *data)
QTestState *qts;
g_autofree char *cli = NULL;

-cli = make_cli(data, "-machine smp.cpus=2 "

+cli = make_cli(data, "-machine "
+"smp.cpus=2,smp.sockets=1,smp.clusters=1,smp.cores=1,smp.threads=2 "


Is cluster-less config possible?
(looks like it used to work before and it doesn't after this series)
  


Nope, it's impossible. This specific test case uses arm/virt machine
where cluster is always supported.mc->smp_props.clusters_supported
has been set to true in hw/arm/virt.c::virt_machine_class_init().

Exactly, the changes to virt_possible_cpu_arch_ids() included in this patch 
breaks
the test. It's why the fix to qtest/numa-test has been squashed to this patch, 
to
make it 'bit bisect' friendly as Yanan suggested.


so what was error that broke the test?
(probably should be mentioned in commit message)

(also is it possible to split out the test patch into
a separate one and put it before this one)
   


With amend to the command lines, the following one is used and below error
is raised from the test. The error is mentioned in the commit log in
PATCH[v7 2/4].

  -machine smp.cpus=2   \
  -numa node,nodeid=0,memdev=ram -numa node,nodeid=1\
  -numa cpu,node-id=1,thread-id=0   \
  -numa cpu,node-id=0,thread-id=1

  qemu-system-aarch64: -numa cpu,node-id=0,thread-id=1: no match found
  (reported from hw/core/machine.c::machine_set_cpu_numa_node())

After the changes to virt_possible_cpu_arch_ids() is applied, "thread-id=1"
isn't valid any more. The CPU topology becomes like below. Note that
mc->smp_props.prefer_sockets is true on arm/virt machine.

  indexsocket   clustercorethread
  
000 00
110 00

With the amended command lines, the topology changes again so
that "thread-id=1" is valid:

  indexsocket   clustercorethread
  
000 00
100 01

It shou

[PULL 24/31] hw/arm/exynos4210: Put combiners into state struct

2022-04-21 Thread Peter Maydell
Switch the creation of the combiner devices to the new-style
"embedded in state struct" approach, so we can easily refer
to the object elsewhere during realize.

Signed-off-by: Peter Maydell 
Reviewed-by: Richard Henderson 
Message-id: 20220404154658.565020-18-peter.mayd...@linaro.org
---
 include/hw/arm/exynos4210.h   |  3 ++
 include/hw/intc/exynos4210_combiner.h | 57 +++
 hw/arm/exynos4210.c   | 20 +-
 hw/intc/exynos4210_combiner.c | 31 +--
 4 files changed, 72 insertions(+), 39 deletions(-)
 create mode 100644 include/hw/intc/exynos4210_combiner.h

diff --git a/include/hw/arm/exynos4210.h b/include/hw/arm/exynos4210.h
index f24617f681d..d38be8767b3 100644
--- a/include/hw/arm/exynos4210.h
+++ b/include/hw/arm/exynos4210.h
@@ -28,6 +28,7 @@
 #include "hw/sysbus.h"
 #include "hw/cpu/a9mpcore.h"
 #include "hw/intc/exynos4210_gic.h"
+#include "hw/intc/exynos4210_combiner.h"
 #include "hw/core/split-irq.h"
 #include "target/arm/cpu-qom.h"
 #include "qom/object.h"
@@ -105,6 +106,8 @@ struct Exynos4210State {
 qemu_or_irq cpu_irq_orgate[EXYNOS4210_NCPUS];
 A9MPPrivState a9mpcore;
 Exynos4210GicState ext_gic;
+Exynos4210CombinerState int_combiner;
+Exynos4210CombinerState ext_combiner;
 SplitIRQ splitter[EXYNOS4210_NUM_SPLITTERS];
 };
 
diff --git a/include/hw/intc/exynos4210_combiner.h 
b/include/hw/intc/exynos4210_combiner.h
new file mode 100644
index 000..429844fed41
--- /dev/null
+++ b/include/hw/intc/exynos4210_combiner.h
@@ -0,0 +1,57 @@
+/*
+ * Samsung exynos4210 Interrupt Combiner
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
+ * All rights reserved.
+ *
+ * Evgeny Voevodin 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#ifndef HW_INTC_EXYNOS4210_COMBINER
+#define HW_INTC_EXYNOS4210_COMBINER
+
+#include "hw/sysbus.h"
+
+/*
+ * State for each output signal of internal combiner
+ */
+typedef struct CombinerGroupState {
+uint8_t src_mask;/* 1 - source enabled, 0 - disabled */
+uint8_t src_pending;/* Pending source interrupts before masking */
+} CombinerGroupState;
+
+#define TYPE_EXYNOS4210_COMBINER "exynos4210.combiner"
+OBJECT_DECLARE_SIMPLE_TYPE(Exynos4210CombinerState, EXYNOS4210_COMBINER)
+
+/* Number of groups and total number of interrupts for the internal combiner */
+#define IIC_NGRP 64
+#define IIC_NIRQ (IIC_NGRP * 8)
+#define IIC_REGSET_SIZE 0x41
+
+struct Exynos4210CombinerState {
+SysBusDevice parent_obj;
+
+MemoryRegion iomem;
+
+struct CombinerGroupState group[IIC_NGRP];
+uint32_t reg_set[IIC_REGSET_SIZE];
+uint32_t icipsr[2];
+uint32_t external;  /* 1 means that this combiner is external */
+
+qemu_irq output_irq[IIC_NGRP];
+};
+
+#endif
diff --git a/hw/arm/exynos4210.c b/hw/arm/exynos4210.c
index 05b28cf5905..27c6ab27123 100644
--- a/hw/arm/exynos4210.c
+++ b/hw/arm/exynos4210.c
@@ -624,25 +624,23 @@ static void exynos4210_realize(DeviceState *socdev, Error 
**errp)
 }
 
 /* Internal Interrupt Combiner */
-dev = qdev_new("exynos4210.combiner");
-busdev = SYS_BUS_DEVICE(dev);
-sysbus_realize_and_unref(busdev, &error_fatal);
+busdev = SYS_BUS_DEVICE(&s->int_combiner);
+sysbus_realize(busdev, &error_fatal);
 for (n = 0; n < EXYNOS4210_MAX_INT_COMBINER_OUT_IRQ; n++) {
 sysbus_connect_irq(busdev, n,
qdev_get_gpio_in(DEVICE(&s->a9mpcore), n));
 }
-exynos4210_combiner_get_gpioin(&s->irqs, dev, 0);
+exynos4210_combiner_get_gpioin(&s->irqs, DEVICE(&s->int_combiner), 0);
 sysbus_mmio_map(busdev, 0, EXYNOS4210_INT_COMBINER_BASE_ADDR);
 
 /* External Interrupt Combiner */
-dev = qdev_new("exynos4210.combiner");
-qdev_prop_set_uint32(dev, "external", 1);
-busdev = SYS_BUS_DEVICE(dev);
-sysbus_realize_and_unref(busdev, &error_fatal);
+qdev_prop_set_uint32(DEVICE(&s->ext_combiner), "external", 1);
+busdev = SYS_BUS_DEVICE(&s->ext_combiner);
+sysbus_realize(busdev, &error_fatal);
 for (n = 0; n < EXYNOS4210_MAX_INT_COMBINER_OUT_IRQ; n++) {
 sysbus_connect_irq(busdev, n, qdev_get_gpio_in(DEVICE(&s->ext_gic), 
n));
 }
-exynos4210_combiner_get_gpioin(&s->irqs, dev, 1);
+exynos4210_combiner_get_gpioin(&s->irqs, DEVICE(&s->ext_combiner), 1);
 sysbus_mmio_map(busdev, 0, E

[PULL 28/31] hw/core/irq: remove unused 'qemu_irq_split' function

2022-04-21 Thread Peter Maydell
From: Zongyuan Li 

Signed-off-by: Zongyuan Li 
Reviewed-by: Peter Maydell 
Message-id: 20220324181557.203805-5-zongyuan...@smartx.com
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/811
Signed-off-by: Peter Maydell 
---
 include/hw/irq.h |  5 -
 hw/core/irq.c| 15 ---
 2 files changed, 20 deletions(-)

diff --git a/include/hw/irq.h b/include/hw/irq.h
index dc7abf199e3..645b73d2512 100644
--- a/include/hw/irq.h
+++ b/include/hw/irq.h
@@ -46,11 +46,6 @@ void qemu_free_irq(qemu_irq irq);
 /* Returns a new IRQ with opposite polarity.  */
 qemu_irq qemu_irq_invert(qemu_irq irq);
 
-/* Returns a new IRQ which feeds into both the passed IRQs.
- * It's probably better to use the TYPE_SPLIT_IRQ device instead.
- */
-qemu_irq qemu_irq_split(qemu_irq irq1, qemu_irq irq2);
-
 /* For internal use in qtest.  Similar to qemu_irq_split, but operating
on an existing vector of qemu_irq.  */
 void qemu_irq_intercept_in(qemu_irq *gpio_in, qemu_irq_handler handler, int n);
diff --git a/hw/core/irq.c b/hw/core/irq.c
index 741219277b1..3623f711fe6 100644
--- a/hw/core/irq.c
+++ b/hw/core/irq.c
@@ -106,21 +106,6 @@ qemu_irq qemu_irq_invert(qemu_irq irq)
 return qemu_allocate_irq(qemu_notirq, irq, 0);
 }
 
-static void qemu_splitirq(void *opaque, int line, int level)
-{
-struct IRQState **irq = opaque;
-irq[0]->handler(irq[0]->opaque, irq[0]->n, level);
-irq[1]->handler(irq[1]->opaque, irq[1]->n, level);
-}
-
-qemu_irq qemu_irq_split(qemu_irq irq1, qemu_irq irq2)
-{
-qemu_irq *s = g_new0(qemu_irq, 2);
-s[0] = irq1;
-s[1] = irq2;
-return qemu_allocate_irq(qemu_splitirq, s, 0);
-}
-
 void qemu_irq_intercept_in(qemu_irq *gpio_in, qemu_irq_handler handler, int n)
 {
 int i;
-- 
2.25.1




Re: [PATCH v2 00/18] tests: introduce testing coverage for TLS with migration

2022-04-21 Thread Dr. David Alan Gilbert
* Daniel P. Berrangé (berra...@redhat.com) wrote:
> This significantly expands the migration test suite to cover testing
> with TLS over TCP and UNIX sockets, with both PSK (pre shared keys)
> and x509 credentials, and for both single and multifd scenarios.
> 
> It identified one bug in handling PSK credentials with UNIX sockets,
> but other than that everything was operating as expected.
> 
> To minimize the impact on code duplication alopt of refactoring is
> done of the migration tests to introduce a common helper for running
> the migration process. The various tests mostly just have to provide
> a callback to set a few parameters/capabilities before migration
> starts, and sometimes a callback to cleanup or validate after
> completion/failure.
> 
> There is one functional bugfix in patch 6, I would like to see
> in 7.0. The rest is all test suite additions, and I don't mind
> if they are in 7.0 or 7.1

I've queued:
tests: expand the migration precopy helper to support failures
tests: switch migration FD passing test to use common precopy helper
tests: introduce ability to provide hooks for migration precopy test
tests: merge code for UNIX and TCP migration pre-copy tests
tests: switch MigrateStart struct to be stack allocated
migration: fix use of TLS PSK credentials with a UNIX socket
tests: print newline after QMP response in qtest logs
tests: support QTEST_TRACE env variable
tests: improve error message when saving TLS PSK file fails

> Changed in v2:
> 
>   - Use structs to pass around most parameters
>   - Hide expected errors from stderr
> 
> Daniel P. Berrangé (18):
>   tests: fix encoding of IP addresses in x509 certs
>   tests: improve error message when saving TLS PSK file fails
>   tests: support QTEST_TRACE env variable
>   tests: print newline after QMP response in qtest logs
>   tests: add more helper macros for creating TLS x509 certs
>   migration: fix use of TLS PSK credentials with a UNIX socket
>   tests: switch MigrateStart struct to be stack allocated
>   tests: merge code for UNIX and TCP migration pre-copy tests
>   tests: introduce ability to provide hooks for migration precopy test
>   tests: switch migration FD passing test to use common precopy helper
>   tests: expand the migration precopy helper to support failures
>   tests: add migration tests of TLS with PSK credentials
>   tests: add migration tests of TLS with x509 credentials
>   tests: convert XBZRLE migration test to use common helper
>   tests: convert multifd migration tests to use common helper
>   tests: add multifd migration tests of TLS with PSK credentials
>   tests: add multifd migration tests of TLS with x509 credentials
>   tests: ensure migration status isn't reported as failed
> 
>  meson.build  |1 +
>  migration/tls.c  |4 -
>  tests/qtest/libqtest.c   |   13 +-
>  tests/qtest/meson.build  |   12 +-
>  tests/qtest/migration-helpers.c  |   13 +
>  tests/qtest/migration-helpers.h  |1 +
>  tests/qtest/migration-test.c | 1208 +-
>  tests/unit/crypto-tls-psk-helpers.c  |   20 +-
>  tests/unit/crypto-tls-psk-helpers.h  |1 +
>  tests/unit/crypto-tls-x509-helpers.c |   16 +-
>  tests/unit/crypto-tls-x509-helpers.h |   53 ++
>  tests/unit/test-crypto-tlssession.c  |   11 +-
>  12 files changed, 1096 insertions(+), 257 deletions(-)
> 
> -- 
> 2.34.1
> 
> 
> 
-- 
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK




Re: [PATCH 29/34] build: move vhost-vsock configuration to Kconfig

2022-04-21 Thread Marc-André Lureau
On Wed, Apr 20, 2022 at 8:19 PM Paolo Bonzini  wrote:

> vhost-vsock and vhost-user-vsock are two devices of their own; it should
> be possible to enable/disable them with --without-default-devices, not
> --without-default-features.  Compute their default value in Kconfig to
> obtain the more intuitive behavior.
>
> Signed-off-by: Paolo Bonzini 
>

We also lose the configure options, but it is overdue

Reviewed-by: Marc-André Lureau 


> ---
>  configure | 16 
>  hw/virtio/Kconfig | 10 ++
>  meson.build   |  1 -
>  3 files changed, 10 insertions(+), 17 deletions(-)
>
> diff --git a/configure b/configure
> index 2aa4dc3ce1..a3b57877e5 100755
> --- a/configure
> +++ b/configure
> @@ -286,7 +286,6 @@ vhost_kernel="$default_feature"
>  vhost_net="$default_feature"
>  vhost_crypto="$default_feature"
>  vhost_scsi="$default_feature"
> -vhost_vsock="$default_feature"
>  vhost_user="no"
>  vhost_user_fs="$default_feature"
>  vhost_vdpa="$default_feature"
> @@ -878,10 +877,6 @@ for opt do
>;;
>--enable-vhost-scsi) vhost_scsi="yes"
>;;
> -  --disable-vhost-vsock) vhost_vsock="no"
> -  ;;
> -  --enable-vhost-vsock) vhost_vsock="yes"
> -  ;;
>--disable-vhost-user-fs) vhost_user_fs="no"
>;;
>--enable-vhost-user-fs) vhost_user_fs="yes"
> @@ -1108,7 +1103,6 @@ cat << EOF
>safe-stack  SafeStack Stack Smash Protection. Depends on
>clang/llvm >= 3.7 and requires coroutine backend
> ucontext.
>vhost-net   vhost-net kernel acceleration support
> -  vhost-vsock virtio sockets device support
>vhost-scsi  vhost-scsi kernel target support
>vhost-cryptovhost-user-crypto backend support
>vhost-kernelvhost kernel backend support
> @@ -1548,10 +1542,6 @@ test "$vhost_scsi" = "" && vhost_scsi=$vhost_kernel
>  if test "$vhost_scsi" = "yes" && test "$vhost_kernel" != "yes"; then
>error_exit "--enable-vhost-scsi requires --enable-vhost-kernel"
>  fi
> -test "$vhost_vsock" = "" && vhost_vsock=$vhost_kernel
> -if test "$vhost_vsock" = "yes" && test "$vhost_kernel" != "yes"; then
> -  error_exit "--enable-vhost-vsock requires --enable-vhost-kernel"
> -fi
>
>  # vhost-user backends
>  test "$vhost_crypto" = "" && vhost_crypto=$vhost_user
> @@ -2104,12 +2094,6 @@ fi
>  if test "$vhost_crypto" = "yes" ; then
>echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak
>  fi
> -if test "$vhost_vsock" = "yes" ; then
> -  echo "CONFIG_VHOST_VSOCK=y" >> $config_host_mak
> -  if test "$vhost_user" = "yes" ; then
> -echo "CONFIG_VHOST_USER_VSOCK=y" >> $config_host_mak
> -  fi
> -fi
>  if test "$vhost_kernel" = "yes" ; then
>echo "CONFIG_VHOST_KERNEL=y" >> $config_host_mak
>  fi
> diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig
> index c144d42f9b..b642ae1081 100644
> --- a/hw/virtio/Kconfig
> +++ b/hw/virtio/Kconfig
> @@ -59,6 +59,16 @@ config VIRTIO_MEM
>  depends on VIRTIO_MEM_SUPPORTED
>  select MEM_DEVICE
>
> +config VHOST_VSOCK
> +bool
> +default y
> +depends on VIRTIO && VHOST_KERNEL
> +
> +config VHOST_USER_VSOCK
> +bool
> +default y
> +depends on VIRTIO && VHOST_USER
> +
>  config VHOST_USER_I2C
>  bool
>  default y
> diff --git a/meson.build b/meson.build
> index ff5c076805..033d0c9aa1 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -3678,7 +3678,6 @@ summary_info += {'vhost-kernel support':
> config_host.has_key('CONFIG_VHOST_KERNE
>  summary_info += {'vhost-net support':
> config_host.has_key('CONFIG_VHOST_NET')}
>  summary_info += {'vhost-crypto support':
> config_host.has_key('CONFIG_VHOST_CRYPTO')}
>  summary_info += {'vhost-scsi support':
> config_host.has_key('CONFIG_VHOST_SCSI')}
> -summary_info += {'vhost-vsock support':
> config_host.has_key('CONFIG_VHOST_VSOCK')}
>  summary_info += {'vhost-user support':
> config_host.has_key('CONFIG_VHOST_USER')}
>  summary_info += {'vhost-user-blk server support':
> have_vhost_user_blk_server}
>  summary_info += {'vhost-user-fs support':
> config_host.has_key('CONFIG_VHOST_USER_FS')}
> --
> 2.35.1
>
>
>
>

-- 
Marc-André Lureau


[PULL 30/31] hw/misc: Add PWRON STRAP bit fields in GCR module

2022-04-21 Thread Peter Maydell
From: Hao Wu 

Similar to the Aspeed code in include/misc/aspeed_scu.h, we define
the PWRON STRAP fields in their corresponding module for NPCM7XX.

Signed-off-by: Hao Wu 
Reviewed-by: Patrick Venture 
Message-id: 20220411165842.3912945-2-wuhao...@google.com
Reviewed-by: Peter Maydell 
Signed-off-by: Peter Maydell 
---
 include/hw/misc/npcm7xx_gcr.h | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/include/hw/misc/npcm7xx_gcr.h b/include/hw/misc/npcm7xx_gcr.h
index 13109d9d324..9419e0a7d2a 100644
--- a/include/hw/misc/npcm7xx_gcr.h
+++ b/include/hw/misc/npcm7xx_gcr.h
@@ -19,6 +19,36 @@
 #include "exec/memory.h"
 #include "hw/sysbus.h"
 
+/*
+ * NPCM7XX PWRON STRAP bit fields
+ * 12: SPI0 powered by VSBV3 at 1.8V
+ * 11: System flash attached to BMC
+ * 10: BSP alternative pins.
+ * 9:8: Flash UART command route enabled.
+ * 7: Security enabled.
+ * 6: HI-Z state control.
+ * 5: ECC disabled.
+ * 4: Reserved
+ * 3: JTAG2 enabled.
+ * 2:0: CPU and DRAM clock frequency.
+ */
+#define NPCM7XX_PWRON_STRAP_SPI0F18 BIT(12)
+#define NPCM7XX_PWRON_STRAP_SFABBIT(11)
+#define NPCM7XX_PWRON_STRAP_BSPABIT(10)
+#define NPCM7XX_PWRON_STRAP_FUP(x)  ((x) << 8)
+#define FUP_NORM_UART2  3
+#define FUP_PROG_UART3  2
+#define FUP_PROG_UART2  1
+#define FUP_NORM_UART3  0
+#define NPCM7XX_PWRON_STRAP_SECEN   BIT(7)
+#define NPCM7XX_PWRON_STRAP_HIZ BIT(6)
+#define NPCM7XX_PWRON_STRAP_ECC BIT(5)
+#define NPCM7XX_PWRON_STRAP_RESERVE1BIT(4)
+#define NPCM7XX_PWRON_STRAP_J2ENBIT(3)
+#define NPCM7XX_PWRON_STRAP_CKFRQ(x)(x)
+#define CKFRQ_SKIPINIT  0x000
+#define CKFRQ_DEFAULT   0x111
+
 /*
  * Number of registers in our device state structure. Don't change this without
  * incrementing the version_id in the vmstate.
-- 
2.25.1




[PULL 26/31] hw/arm/realview: replace 'qemu_split_irq' with 'TYPE_SPLIT_IRQ'

2022-04-21 Thread Peter Maydell
From: Zongyuan Li 

Signed-off-by: Zongyuan Li 
Reviewed-by: Peter Maydell 
Message-id: 20220324181557.203805-2-zongyuan...@smartx.com
Signed-off-by: Peter Maydell 
---
 hw/arm/realview.c | 33 -
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/hw/arm/realview.c b/hw/arm/realview.c
index 7b424e94a5f..d2dc8a89525 100644
--- a/hw/arm/realview.c
+++ b/hw/arm/realview.c
@@ -13,9 +13,11 @@
 #include "hw/sysbus.h"
 #include "hw/arm/boot.h"
 #include "hw/arm/primecell.h"
+#include "hw/core/split-irq.h"
 #include "hw/net/lan9118.h"
 #include "hw/net/smc91c111.h"
 #include "hw/pci/pci.h"
+#include "hw/qdev-core.h"
 #include "net/net.h"
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
@@ -53,6 +55,20 @@ static const int realview_board_id[] = {
 0x76d
 };
 
+static void split_irq_from_named(DeviceState *src, const char* outname,
+ qemu_irq out1, qemu_irq out2) {
+DeviceState *splitter = qdev_new(TYPE_SPLIT_IRQ);
+
+qdev_prop_set_uint32(splitter, "num-lines", 2);
+
+qdev_realize_and_unref(splitter, NULL, &error_fatal);
+
+qdev_connect_gpio_out(splitter, 0, out1);
+qdev_connect_gpio_out(splitter, 1, out2);
+qdev_connect_gpio_out_named(src, outname, 0,
+qdev_get_gpio_in(splitter, 0));
+}
+
 static void realview_init(MachineState *machine,
   enum realview_board_type board_type)
 {
@@ -66,7 +82,6 @@ static void realview_init(MachineState *machine,
 DeviceState *dev, *sysctl, *gpio2, *pl041;
 SysBusDevice *busdev;
 qemu_irq pic[64];
-qemu_irq mmc_irq[2];
 PCIBus *pci_bus = NULL;
 NICInfo *nd;
 DriveInfo *dinfo;
@@ -229,14 +244,14 @@ static void realview_init(MachineState *machine,
  * and the PL061 has them the other way about. Also the card
  * detect line is inverted.
  */
-mmc_irq[0] = qemu_irq_split(
-qdev_get_gpio_in(sysctl, ARM_SYSCTL_GPIO_MMC_WPROT),
-qdev_get_gpio_in(gpio2, 1));
-mmc_irq[1] = qemu_irq_split(
-qdev_get_gpio_in(sysctl, ARM_SYSCTL_GPIO_MMC_CARDIN),
-qemu_irq_invert(qdev_get_gpio_in(gpio2, 0)));
-qdev_connect_gpio_out_named(dev, "card-read-only", 0, mmc_irq[0]);
-qdev_connect_gpio_out_named(dev, "card-inserted", 0, mmc_irq[1]);
+split_irq_from_named(dev, "card-read-only",
+   qdev_get_gpio_in(sysctl, ARM_SYSCTL_GPIO_MMC_WPROT),
+   qdev_get_gpio_in(gpio2, 1));
+
+split_irq_from_named(dev, "card-inserted",
+   qdev_get_gpio_in(sysctl, ARM_SYSCTL_GPIO_MMC_CARDIN),
+   qemu_irq_invert(qdev_get_gpio_in(gpio2, 0)));
+
 dinfo = drive_get(IF_SD, 0, 0);
 if (dinfo) {
 DeviceState *card;
-- 
2.25.1




Re: [PATCH 30/34] build: move vhost-scsi configuration to Kconfig

2022-04-21 Thread Marc-André Lureau
On Wed, Apr 20, 2022 at 8:23 PM Paolo Bonzini  wrote:

> vhost-scsi and vhost-user-scsi are two devices of their own; it should
> be possible to enable/disable them with --without-default-devices, not
> --without-default-features.  Compute their default value in Kconfig to
> obtain the more intuitive behavior.
>
> Signed-off-by: Paolo Bonzini 
>

Reviewed-by: Marc-André Lureau 



> ---
>  configure   | 15 ---
>  hw/scsi/Kconfig |  5 +
>  include/hw/virtio/virtio-scsi.h |  2 --
>  meson.build |  1 -
>  4 files changed, 5 insertions(+), 18 deletions(-)
>
> diff --git a/configure b/configure
> index a3b57877e5..65ae2c0c1f 100755
> --- a/configure
> +++ b/configure
> @@ -285,7 +285,6 @@ EXTRA_LDFLAGS=""
>  vhost_kernel="$default_feature"
>  vhost_net="$default_feature"
>  vhost_crypto="$default_feature"
> -vhost_scsi="$default_feature"
>  vhost_user="no"
>  vhost_user_fs="$default_feature"
>  vhost_vdpa="$default_feature"
> @@ -873,10 +872,6 @@ for opt do
>;;
>--enable-vhost-crypto) vhost_crypto="yes"
>;;
> -  --disable-vhost-scsi) vhost_scsi="no"
> -  ;;
> -  --enable-vhost-scsi) vhost_scsi="yes"
> -  ;;
>--disable-vhost-user-fs) vhost_user_fs="no"
>;;
>--enable-vhost-user-fs) vhost_user_fs="yes"
> @@ -1103,7 +1098,6 @@ cat << EOF
>safe-stack  SafeStack Stack Smash Protection. Depends on
>clang/llvm >= 3.7 and requires coroutine backend
> ucontext.
>vhost-net   vhost-net kernel acceleration support
> -  vhost-scsi  vhost-scsi kernel target support
>vhost-cryptovhost-user-crypto backend support
>vhost-kernelvhost kernel backend support
>vhost-user  vhost-user backend support
> @@ -1537,12 +1531,6 @@ if test "$vhost_kernel" = "yes" && test "$linux" !=
> "yes"; then
>error_exit "vhost-kernel is only available on Linux"
>  fi
>
> -# vhost-kernel devices
> -test "$vhost_scsi" = "" && vhost_scsi=$vhost_kernel
> -if test "$vhost_scsi" = "yes" && test "$vhost_kernel" != "yes"; then
> -  error_exit "--enable-vhost-scsi requires --enable-vhost-kernel"
> -fi
> -
>  # vhost-user backends
>  test "$vhost_crypto" = "" && vhost_crypto=$vhost_user
>  if test "$vhost_crypto" = "yes" && test "$vhost_user" = "no"; then
> @@ -2079,9 +2067,6 @@ if test "$modules" = "yes"; then
>echo "CONFIG_MODULES=y" >> $config_host_mak
>  fi
>
> -if test "$vhost_scsi" = "yes" ; then
> -  echo "CONFIG_VHOST_SCSI=y" >> $config_host_mak
> -fi
>  if test "$vhost_net" = "yes" ; then
>echo "CONFIG_VHOST_NET=y" >> $config_host_mak
>  fi
> diff --git a/hw/scsi/Kconfig b/hw/scsi/Kconfig
> index 77d397c949..e7b34dc8e2 100644
> --- a/hw/scsi/Kconfig
> +++ b/hw/scsi/Kconfig
> @@ -48,6 +48,11 @@ config VIRTIO_SCSI
>  depends on VIRTIO
>  select SCSI
>
> +config VHOST_SCSI
> +bool
> +default y
> +depends on VIRTIO && VHOST_KERNEL
> +
>  config VHOST_USER_SCSI
>  bool
>  # Only PCI devices are provided for now
> diff --git a/include/hw/virtio/virtio-scsi.h
> b/include/hw/virtio/virtio-scsi.h
> index 543681bc18..0997313f0a 100644
> --- a/include/hw/virtio/virtio-scsi.h
> +++ b/include/hw/virtio/virtio-scsi.h
> @@ -55,10 +55,8 @@ struct VirtIOSCSIConf {
>  bool seg_max_adjust;
>  uint32_t max_sectors;
>  uint32_t cmd_per_lun;
> -#ifdef CONFIG_VHOST_SCSI
>  char *vhostfd;
>  char *wwpn;
> -#endif
>  CharBackend chardev;
>  uint32_t boot_tpgt;
>  IOThread *iothread;
> diff --git a/meson.build b/meson.build
> index 033d0c9aa1..b18731ee84 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -3677,7 +3677,6 @@ summary_info += {'QOM debugging':
>  get_option('qom_cast_debug')}
>  summary_info += {'vhost-kernel support':
> config_host.has_key('CONFIG_VHOST_KERNEL')}
>  summary_info += {'vhost-net support':
> config_host.has_key('CONFIG_VHOST_NET')}
>  summary_info += {'vhost-crypto support':
> config_host.has_key('CONFIG_VHOST_CRYPTO')}
> -summary_info += {'vhost-scsi support':
> config_host.has_key('CONFIG_VHOST_SCSI')}
>  summary_info += {'vhost-user support':
> config_host.has_key('CONFIG_VHOST_USER')}
>  summary_info += {'vhost-user-blk server support':
> have_vhost_user_blk_server}
>  summary_info += {'vhost-user-fs support':
> config_host.has_key('CONFIG_VHOST_USER_FS')}
> --
> 2.35.1
>
>
>
>

-- 
Marc-André Lureau


[PULL 31/31] hw/arm: Use bit fields for NPCM7XX PWRON STRAPs

2022-04-21 Thread Peter Maydell
From: Hao Wu 

This patch uses the defined fields to describe PWRON STRAPs for
better readability.

Signed-off-by: Hao Wu 
Reviewed-by: Patrick Venture 
Message-id: 20220411165842.3912945-3-wuhao...@google.com
Reviewed-by: Peter Maydell 
Signed-off-by: Peter Maydell 
---
 hw/arm/npcm7xx_boards.c | 24 +++-
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c
index 0678a56156f..6bc6f5d2fe2 100644
--- a/hw/arm/npcm7xx_boards.c
+++ b/hw/arm/npcm7xx_boards.c
@@ -30,11 +30,25 @@
 #include "sysemu/sysemu.h"
 #include "sysemu/block-backend.h"
 
-#define NPCM750_EVB_POWER_ON_STRAPS 0x1ff7
-#define QUANTA_GSJ_POWER_ON_STRAPS 0x1fff
-#define QUANTA_GBS_POWER_ON_STRAPS 0x17ff
-#define KUDO_BMC_POWER_ON_STRAPS 0x1fff
-#define MORI_BMC_POWER_ON_STRAPS 0x1fff
+#define NPCM7XX_POWER_ON_STRAPS_DEFAULT (   \
+NPCM7XX_PWRON_STRAP_SPI0F18 |   \
+NPCM7XX_PWRON_STRAP_SFAB |  \
+NPCM7XX_PWRON_STRAP_BSPA |  \
+NPCM7XX_PWRON_STRAP_FUP(FUP_NORM_UART2) |   \
+NPCM7XX_PWRON_STRAP_SECEN | \
+NPCM7XX_PWRON_STRAP_HIZ |   \
+NPCM7XX_PWRON_STRAP_ECC |   \
+NPCM7XX_PWRON_STRAP_RESERVE1 |  \
+NPCM7XX_PWRON_STRAP_J2EN |  \
+NPCM7XX_PWRON_STRAP_CKFRQ(CKFRQ_DEFAULT))
+
+#define NPCM750_EVB_POWER_ON_STRAPS ( \
+NPCM7XX_POWER_ON_STRAPS_DEFAULT & ~NPCM7XX_PWRON_STRAP_J2EN)
+#define QUANTA_GSJ_POWER_ON_STRAPS NPCM7XX_POWER_ON_STRAPS_DEFAULT
+#define QUANTA_GBS_POWER_ON_STRAPS ( \
+NPCM7XX_POWER_ON_STRAPS_DEFAULT & ~NPCM7XX_PWRON_STRAP_SFAB)
+#define KUDO_BMC_POWER_ON_STRAPS NPCM7XX_POWER_ON_STRAPS_DEFAULT
+#define MORI_BMC_POWER_ON_STRAPS NPCM7XX_POWER_ON_STRAPS_DEFAULT
 
 static const char npcm7xx_default_bootrom[] = "npcm7xx_bootrom.bin";
 
-- 
2.25.1




Re: [PATCH v6 2/4] hw/arm/virt: Consider SMP configuration in CPU topology

2022-04-21 Thread Gavin Shan

Hi Drew,

On 4/21/22 5:02 PM, Andrew Jones wrote:

On Wed, Apr 20, 2022 at 10:24:46PM +0800, Gavin Shan wrote:
...

With amend to the command lines, the following one is used and below error
is raised from the test. The error is mentioned in the commit log in
PATCH[v7 2/4].

 -machine smp.cpus=2   \
 -numa node,nodeid=0,memdev=ram -numa node,nodeid=1\
 -numa cpu,node-id=1,thread-id=0   \
 -numa cpu,node-id=0,thread-id=1

 qemu-system-aarch64: -numa cpu,node-id=0,thread-id=1: no match found
 (reported from hw/core/machine.c::machine_set_cpu_numa_node())

After the changes to virt_possible_cpu_arch_ids() is applied, "thread-id=1"
isn't valid any more. The CPU topology becomes like below. Note that
mc->smp_props.prefer_sockets is true on arm/virt machine.


prefer_sockets is only true for mach-virt 6.1 and older. It's false for
6.2 and later.



Yeah, @perfer_socket is false in last mach-virt-7.0 , which is used in
this test case. So we prefer CPU core over sockets, as explained in
hw/core/machine.c::machine_parse_smp_config(). The CPU topology
becomes like below instead, but 'thread-id=1' is still invalid.

  indexsocket   clustercorethread
  
000 00
100 10



 indexsocket   clustercorethread
 
   000 00
   110 00

With the amended command lines, the topology changes again so
that "thread-id=1" is valid:

 indexsocket   clustercorethread
 
   000 00
   100 01

It should be ok to split the test/qtest/aarch64_numa_cpu() changes into
a separate patch and put it before this one. In that case, the specified
smp.{socket, cluster, core, threads} isn't used by arm/virt machine yet,
and 'thread-id=2' should be still valid. Lets do this if I need post v8.
Otherwise, I guess it's also fine to squash the test/qtest/aarch64_numa_cpu()
changes into PATCH[2/4], as we're doing.







"-numa node,nodeid=0,memdev=ram -numa node,nodeid=1 "
"-numa cpu,node-id=1,thread-id=0 "
"-numa cpu,node-id=0,thread-id=1");


Thanks,
Gavin




Re: [PATCH v7 4/4] hw/acpi/aml-build: Use existing CPU topology to build PPTT table

2022-04-21 Thread wangyanan (Y)

Hi Gavin,

On 2022/4/20 18:49, Gavin Shan wrote:

When the PPTT table is built, the CPU topology is re-calculated, but
it's unecessary because the CPU topology has been populated in
virt_possible_cpu_arch_ids() on arm/virt machine.

This reworks build_pptt() to avoid by reusing the existing IDs in
ms->possible_cpus. Currently, the only user of build_pptt() is
arm/virt machine.

Signed-off-by: Gavin Shan 
---
  hw/acpi/aml-build.c | 109 +++-
  1 file changed, 47 insertions(+), 62 deletions(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 4086879ebf..73f4e69c29 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -2002,86 +2002,71 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, 
MachineState *ms,
  const char *oem_id, const char *oem_table_id)
  {
  MachineClass *mc = MACHINE_GET_CLASS(ms);
-GQueue *list = g_queue_new();
-guint pptt_start = table_data->len;
-guint parent_offset;
-guint length, i;
-int uid = 0;
-int socket;
+CPUArchIdList *cpus = ms->possible_cpus;
+int64_t socket_id = -1, cluster_id = -1, core_id = -1;
+uint32_t socket_offset = 0, cluster_offset = 0, core_offset = 0;
+uint32_t pptt_start = table_data->len;
+int n;
  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);
-}
+/*
+ * This works with the assumption that cpus[n].props.*_id has been
+ * sorted from top to down levels in mc->possible_cpu_arch_ids().
+ * Otherwise, the unexpected and duplicate containers will be
+ * created.
+ */

s/duplicate/duplicated

+for (n = 0; n < cpus->len; n++) {
+if (cpus->cpus[n].props.socket_id != socket_id) {
+assert(cpus->cpus[n].props.socket_id > socket_id);
+socket_id = cpus->cpus[n].props.socket_id;
+cluster_id = -1;
+core_id = -1;
+socket_offset = table_data->len - pptt_start;
+build_processor_hierarchy_node(table_data,
+(1 << 0), /* Physical package */
+0, socket_id, NULL, 0);
+}
  
-if (mc->smp_props.clusters_supported) {

-length = g_queue_get_length(list);
-for (i = 0; i < length; i++) {
-int cluster;
-
-parent_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 */
-parent_offset, cluster, NULL, 0);
+if (mc->smp_props.clusters_supported) {
+if (cpus->cpus[n].props.cluster_id != cluster_id) {
+assert(cpus->cpus[n].props.cluster_id > cluster_id);
+cluster_id = cpus->cpus[n].props.cluster_id;
+core_id = -1;
+cluster_offset = table_data->len - pptt_start;
+build_processor_hierarchy_node(table_data,
+(0 << 0), /* Not a physical package */
+socket_offset, cluster_id, NULL, 0);
  }
+} else {
+cluster_offset = socket_offset;
  }
-}
  
-length = g_queue_get_length(list);

-for (i = 0; i < length; i++) {
-int core;
-
-parent_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,
+if (ms->smp.threads == 1) {
+build_processor_hierarchy_node(table_data,
+(1 << 1) | /* ACPI Processor ID valid */
+(1 << 3),  /* Node is a Leaf */
+cluster_offset, n, NULL, 0);
+} else {
+if (cpus->cpus[n].props.core_id != core_id) {
+assert(cpus->cpus[n].props.core_id > core_id);
+core_id = cpus->cpus[n].props.core_id;
+core_offset = table_data->len - pptt_start;
+build_processor_hierarchy_node(table_data,
  (0 << 0), /* not a physical package */

nit: For consistency, maybe "Not a physical p

Re: [PATCH for-7.1 11/11] hw/arm: Add NPCM845 Evaluation board

2022-04-21 Thread Peter Maydell
On Tue, 5 Apr 2022 at 23:38, Hao Wu  wrote:
>
> Signed-off-by: Hao Wu 
> Reviwed-by: Patrick Venture 
> ---
>  hw/arm/meson.build   |   2 +-
>  hw/arm/npcm8xx_boards.c  | 257 +++
>  include/hw/arm/npcm8xx.h |  20 +++
>  3 files changed, 278 insertions(+), 1 deletion(-)
>  create mode 100644 hw/arm/npcm8xx_boards.c

> --- /dev/null
> +++ b/hw/arm/npcm8xx_boards.c
> @@ -0,0 +1,257 @@
> +/*
> + * Machine definitions for boards featuring an NPCM8xx SoC.
> + *
> + * Copyright 2022 Google LLC
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License as published by the
> + * Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful, but 
> WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
> + * for more details.
> + */
> +
> +#include "qemu/osdep.h"
> +
> +#include "chardev/char.h"
> +#include "hw/arm/npcm8xx.h"
> +#include "hw/core/cpu.h"
> +#include "hw/loader.h"
> +#include "hw/qdev-core.h"
> +#include "hw/qdev-properties.h"
> +#include "qapi/error.h"
> +#include "qemu-common.h"

Don't include qemu-common.h unless you really need it (if you rebase
on current head-of-git you almost certainly don't, as it now contains
only a very few things, most of its previous contents having been split
into more specific header files). There are some patches in flight which
rename/delete it entirely, so if you don't #include it you'll avoid
a conflict when they land.

thanks
-- PMM



Re: [PATCH v7 4/4] hw/acpi/aml-build: Use existing CPU topology to build PPTT table

2022-04-21 Thread Gavin Shan

Hi Igor,

On 4/20/22 10:56 PM, Igor Mammedov wrote:

On Wed, 20 Apr 2022 18:49:09 +0800
Gavin Shan  wrote:


When the PPTT table is built, the CPU topology is re-calculated, but
it's unecessary because the CPU topology has been populated in
virt_possible_cpu_arch_ids() on arm/virt machine.

This reworks build_pptt() to avoid by reusing the existing IDs in
ms->possible_cpus. Currently, the only user of build_pptt() is
arm/virt machine.

Signed-off-by: Gavin Shan 


Looks fine to me, so

Acked-by: Igor Mammedov 


Also do we have a bios-tables tests that watches over/tests PPTT table?
if not please add one as a patch on top.



Thanks a lot for your continuous reviews. We won't have PPTT table included
in bios-table tests. I will add one after this series is merged because
our downstream release needs this series :)


---
  hw/acpi/aml-build.c | 109 +++-
  1 file changed, 47 insertions(+), 62 deletions(-)

diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
index 4086879ebf..73f4e69c29 100644
--- a/hw/acpi/aml-build.c
+++ b/hw/acpi/aml-build.c
@@ -2002,86 +2002,71 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, 
MachineState *ms,
  const char *oem_id, const char *oem_table_id)
  {
  MachineClass *mc = MACHINE_GET_CLASS(ms);
-GQueue *list = g_queue_new();
-guint pptt_start = table_data->len;
-guint parent_offset;
-guint length, i;
-int uid = 0;
-int socket;
+CPUArchIdList *cpus = ms->possible_cpus;
+int64_t socket_id = -1, cluster_id = -1, core_id = -1;
+uint32_t socket_offset = 0, cluster_offset = 0, core_offset = 0;
+uint32_t pptt_start = table_data->len;
+int n;
  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);
-}
+/*
+ * This works with the assumption that cpus[n].props.*_id has been
+ * sorted from top to down levels in mc->possible_cpu_arch_ids().
+ * Otherwise, the unexpected and duplicate containers will be
+ * created.
+ */
+for (n = 0; n < cpus->len; n++) {
+if (cpus->cpus[n].props.socket_id != socket_id) {
+assert(cpus->cpus[n].props.socket_id > socket_id);
+socket_id = cpus->cpus[n].props.socket_id;
+cluster_id = -1;
+core_id = -1;
+socket_offset = table_data->len - pptt_start;
+build_processor_hierarchy_node(table_data,
+(1 << 0), /* Physical package */
+0, socket_id, NULL, 0);
+}
  
-if (mc->smp_props.clusters_supported) {

-length = g_queue_get_length(list);
-for (i = 0; i < length; i++) {
-int cluster;
-
-parent_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 */
-parent_offset, cluster, NULL, 0);
+if (mc->smp_props.clusters_supported) {
+if (cpus->cpus[n].props.cluster_id != cluster_id) {
+assert(cpus->cpus[n].props.cluster_id > cluster_id);
+cluster_id = cpus->cpus[n].props.cluster_id;
+core_id = -1;
+cluster_offset = table_data->len - pptt_start;
+build_processor_hierarchy_node(table_data,
+(0 << 0), /* Not a physical package */
+socket_offset, cluster_id, NULL, 0);
  }
+} else {
+cluster_offset = socket_offset;
  }
-}
  
-length = g_queue_get_length(list);

-for (i = 0; i < length; i++) {
-int core;
-
-parent_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,
+if (ms->smp.threads == 1) {
+build_processor_hierarchy_node(table_data,
+(1 << 1) | /* ACPI Processor ID valid */
+(1 << 3),  /* Node is a Leaf */
+cluster_offset, n, NULL, 0);
+} else {
+   

Re: [PATCH 00/19] block: fix coroutine_fn annotations

2022-04-21 Thread Stefan Hajnoczi
On Fri, Apr 15, 2022 at 03:18:34PM +0200, Paolo Bonzini wrote:
> This is the initial result of reviving Marc-André's series at
> https://patchew.org/QEMU/20170704220346.29244-1-marcandre.lur...@redhat.com/.
> A lot of the patches are similar to the ones that Marc-André wrote,
> but due to the changes in the code it was easier to redo them.
> 
> For nbd, the patch is on top of "nbd: mark more coroutine_fns" that
> I sent a few days ago and that (AIUI) Eric has already queued; only
> one function was missing, much to my surprise.
> 
> Apart from this, I also identified the following functions that
> can be called both in coroutine context and outside:
> 
> - qmp_dispatch
> - schedule_next_request
> - nvme_get_free_req
> - bdrv_create
> - bdrv_remove_persistent_dirty_bitmap
> - bdrv_can_store_new_dirty_bitmap
> - bdrv_do_drained_begin
> - bdrv_do_drained_end
> - bdrv_drain_all_begin
> - qcow2_open
> - qcow2_has_zero_init
> - bdrv_qed_open
> - qio_channel_readv_full_all_eof
> - qio_channel_writev_full_all
> 
> besides, of course, everything that is generated by
> scripts/block-coroutine-wrapper.py.

This looks useful, thanks for bringing it back!

As Eric mentioned, the commits need justifications. The following cases
come to mind:

1. Add coroutine_fn because the function calls a function that is marked
   with coroutine_fn. This must be fixed because it can lead to crashes.

2. Remove coroutine_fn because the function does not call any functions
   marked with coroutine_fn. This is optional because it does not lead
   to crashes and maybe the author intended to be explicit that this
   function runs only in coroutine context even though it doesn't yield.

3. Variants of these cases but related to runtime qemu_in_coroutine()
   checks. Functions should not have coroutine_fn if they legitimately
   are called in both contexts. Any calls to coroutine_fn child
   functions must be conditional on qemu_in_coroutine() or something
   else that indicates whether we are running in coroutine context.

Stefan


signature.asc
Description: PGP signature


Re: [PATCH 2/3] iotests: 314 test on duplicated clusters (parallels format)

2022-04-21 Thread Stefan Hajnoczi
On Mon, Apr 18, 2022 at 02:04:29PM +0300, Natalia Kuzmina wrote:
> Reading from duplicated offset and from original offset returns
> the same data. After repairing changing either of these
> blocks of data does not affect another one.
> 
> Signed-off-by: Natalia Kuzmina 
> ---
>  tests/qemu-iotests/314|  88 ++
>  tests/qemu-iotests/314.out|  36 +++
>  .../parallels-2-duplicated-cluster.bz2| Bin 0 -> 148 bytes
>  3 files changed, 124 insertions(+)
>  create mode 100755 tests/qemu-iotests/314
>  create mode 100644 tests/qemu-iotests/314.out
>  create mode 100644 
> tests/qemu-iotests/sample_images/parallels-2-duplicated-cluster.bz2

Reviewed-by: Stefan Hajnoczi 


signature.asc
Description: PGP signature


Re: [PATCH 4/5] 9pfs: fix wrong errno being sent to Linux client on macOS host

2022-04-21 Thread Greg Kurz
On Thu, 21 Apr 2022 13:13:08 +0200
Christian Schoenebeck  wrote:

> On Donnerstag, 21. April 2022 12:48:35 CEST Greg Kurz wrote:
> > On Tue, 19 Apr 2022 13:41:59 +0200
> > 
> > Christian Schoenebeck  wrote:
> > > Linux and macOS only share some errno definitions with equal macro
> > > name and value. In fact most mappings for errno are completely
> > > different on the two systems.
> > > 
> > > This patch converts some important errno values from macOS host to
> > > corresponding Linux errno values before eventually sending such error
> > > codes along with Tlerror replies (if 9p2000.L is used that is), which
> > > fixes a bunch of misbehaviours when running a Linux client on macOS
> > > host.
> > 
> > This even fixes an actual protocol violation :
> > 
> > lerror -- return error code
> > 
> > size[4] Rlerror tag[2] ecode[4]
> > 
> > lerror replaces the reply message used in a successful call. ecode is a
> > numerical Linux errno.
> > ^
> > 
> > Taken from
> > https://github.com/chaos/diod/wiki/protocol#lerrorreturn-error-code
> 
> Again, something to add to the commit log?
> 

IMHO a protocol violation is important enough to be mentioned but
I'll leave it to you.

> > > For instance this patch fixes:
> > >   mount -t 9p -o posixacl ...
> > > 
> > > on Linux guest if security_mode=mapped was used for 9p server, which
> > > refused to mount successfully, because macOS returned ENOATTR==93
> > > when client tried to retrieve POSIX ACL xattrs, because errno 93
> > > is defined as EPROTONOSUPPORT==93 on Linux, so Linux client believed
> > > that xattrs were not supported by filesystem on host in general.
> > > 
> > > Signed-off-by: Christian Schoenebeck 
> > > ---
> > > 
> > >  hw/9pfs/9p.c | 27 +++
> > >  1 file changed, 27 insertions(+)
> > > 
> > > diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> > > index d953035e1c..becc41cbfd 100644
> > > --- a/hw/9pfs/9p.c
> > > +++ b/hw/9pfs/9p.c
> > > @@ -57,6 +57,31 @@ enum {
> > > 
> > >  P9ARRAY_DEFINE_TYPE(V9fsPath, v9fs_path_free);
> > > 
> > > +/* Translates errno from host -> Linux if needed */
> > > +static int errno_to_dotl(int err) {
> > > +#if defined(CONFIG_LINUX)
> > > +/* nothing to translate (Linux -> Linux) */
> > > +#elif defined(CONFIG_DARWIN)
> > > +/* translation mandatory for macOS hosts */
> > > +if (err == ENAMETOOLONG) {
> > > +err = 36; /* ==ENAMETOOLONG on Linux */
> > > +} else if (err == ENOTEMPTY) {
> > > +err = 39; /* ==ENOTEMPTY on Linux */
> > > +} else if (err == ELOOP) {
> > > +err = 40; /* ==ELOOP on Linux */
> > > +} else if (err == ENOATTR) {
> > > +err = 61; /* ==ENODATA on Linux */
> > > +} else if (err == ENOTSUP) {
> > > +err = 95; /* ==EOPNOTSUPP on Linux */
> > > +} else if (err == EOPNOTSUPP) {
> > > +err = 95; /* ==EOPNOTSUPP on Linux */
> > > +}
> > 
> > I'm assuming you have audited all errnos, right ? Just to be sure
> > that this won't bite anymore.
> 
> Depends on what you mean with "all". Like I wrote in the commit log, for now 
> I 
> translated in this patch those errnos that I identified as important, and 
> those are audited by me of course (checked the man pages for what errors are 
> expected as result from calls on Linux vs. macOS side and looked up numeric 
> values from header files on both sides, tests).
> 

I was pretty sure you'd have done that at least :-)

> However if you rather mean really all errnos that were ever defined on Linux 
> and macOS, then the answer is no. That would probably quite some work, and 
> I'm 
> not sure if you could just try to translate them dry, i.e. by just looking at 
> the headers or something.
> 

But yes I was rather meaning the full errno set.

> So yes, your concern is justified. The question is, should this all be 
> translated right now already, or would it be OK to address this minimum set 
> of 
> errno translation for now (especially for qemu-stable) and then later address 
> the rest?
> 

My concern is about the maintenance burden of investigating future
implementations of this issue, so I'd say it is mostly up to you
as the principal maintainer. Maybe leave a FIXME comment in the code
that the list of translated errnos isn't exhaustive at least ?

> On the long term you would probably import the Linux errno header file into 
> the code base, then prefix the individual macros with something like 
> DOTL_ENODATA, etc. and then use those macros for translating the errnos 
> instead of using literal numerics, maybe using GCC's designated array 
> initializers then.
> 

This would make sense indeed since 9p2000.L explicitly mentions the
numerical linux errnos.

> > > +#else
> > > +#error Missing errno translation to Linux for this host system
> > > +#endif
> > > +return err;
> > > +}
> > > +
> > 
> > As with the other patch, I'd rather move this magic to 9p-util.h .
> 
> Makes sense. There is indeed already too much utility code piled up in

Re: [PATCH v7 2/4] hw/arm/virt: Consider SMP configuration in CPU topology

2022-04-21 Thread wangyanan (Y)

Hi Gavin,
Sorry I missed the v6.
On 2022/4/20 18:49, Gavin Shan wrote:

Currently, the SMP configuration isn't considered when the CPU
topology is populated. In this case, it's impossible to provide
the default CPU-to-NUMA mapping or association based on the socket
ID of the given CPU.

This takes account of SMP configuration when the CPU topology
is populated. The die ID for the given CPU isn't assigned since
it's not supported on arm/virt machine. Besides, the used SMP
configuration in qtest/numa-test/aarch64_numa_cpu() is corrcted
to avoid testing failure

Signed-off-by: Gavin Shan 
Reviewed-by: Yanan Wang 
---
  hw/arm/virt.c   | 15 ++-
  tests/qtest/numa-test.c |  3 ++-
  2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index d2e5ecd234..5443ecae92 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -2505,6 +2505,7 @@ static const CPUArchIdList 
*virt_possible_cpu_arch_ids(MachineState *ms)
  int n;
  unsigned int max_cpus = ms->smp.max_cpus;
  VirtMachineState *vms = VIRT_MACHINE(ms);
+MachineClass *mc = MACHINE_GET_CLASS(vms);
  
  if (ms->possible_cpus) {

  assert(ms->possible_cpus->len == max_cpus);
@@ -2518,8 +2519,20 @@ static const CPUArchIdList 
*virt_possible_cpu_arch_ids(MachineState *ms)
  ms->possible_cpus->cpus[n].type = ms->cpu_type;
  ms->possible_cpus->cpus[n].arch_id =
  virt_cpu_mp_affinity(vms, n);
+
+assert(!mc->smp_props.dies_supported);
+ms->possible_cpus->cpus[n].props.has_socket_id = true;
+ms->possible_cpus->cpus[n].props.socket_id =
+(n / (ms->smp.clusters * ms->smp.cores * ms->smp.threads));

nit: so the outermost "()" is unnecessary too.

+ms->possible_cpus->cpus[n].props.has_cluster_id = true;
+ms->possible_cpus->cpus[n].props.cluster_id =
+(n / (ms->smp.cores * ms->smp.threads)) % ms->smp.clusters;
+ms->possible_cpus->cpus[n].props.has_core_id = true;
+ms->possible_cpus->cpus[n].props.core_id =
+(n / ms->smp.threads) % ms->smp.cores;
  ms->possible_cpus->cpus[n].props.has_thread_id = true;
-ms->possible_cpus->cpus[n].props.thread_id = n;
+ms->possible_cpus->cpus[n].props.thread_id =
+n % ms->smp.threads;
  }
  return ms->possible_cpus;
  }
diff --git a/tests/qtest/numa-test.c b/tests/qtest/numa-test.c
index 90bf68a5b3..aeda8c774c 100644
--- a/tests/qtest/numa-test.c
+++ b/tests/qtest/numa-test.c
@@ -223,7 +223,8 @@ static void aarch64_numa_cpu(const void *data)
  QTestState *qts;
  g_autofree char *cli = NULL;
  
-cli = make_cli(data, "-machine smp.cpus=2 "

+cli = make_cli(data, "-machine "
+"smp.cpus=2,smp.sockets=1,smp.clusters=1,smp.cores=1,smp.threads=2 "
  "-numa node,nodeid=0,memdev=ram -numa node,nodeid=1 "
  "-numa cpu,node-id=1,thread-id=0 "
  "-numa cpu,node-id=0,thread-id=1");

Thanks,
Yanan



Re: [PATCH 32/34] meson: create have_vhost_* variables

2022-04-21 Thread Marc-André Lureau
On Wed, Apr 20, 2022 at 8:16 PM Paolo Bonzini  wrote:

> When using Meson options rather than config-host.h, the "when" clauses
> have to be changed to if statements (which is not necessarily great,
> though at least it highlights which parts of the build are per-target
> and which are not).
>
> Do that before moving vhost logic to meson.build, though for now
> the variables are just based on config-host.mak data.
>
> Signed-off-by: Paolo Bonzini 
>

Reviewed-by: Marc-André Lureau 

---
>  meson.build   | 31 ---
>  tests/meson.build |  2 +-
>  tools/meson.build |  2 +-
>  3 files changed, 22 insertions(+), 13 deletions(-)
>
> diff --git a/meson.build b/meson.build
> index 870dd8dee0..5b5eb442c4 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -312,6 +312,15 @@ have_tpm = get_option('tpm') \
>.require(targetos != 'windows', error_message: 'TPM emulation only
> available on POSIX systems') \
>.allowed()
>
> +# vhost
> +have_vhost_user = 'CONFIG_VHOST_USER' in config_host
> +have_vhost_vdpa = 'CONFIG_VHOST_VDPA' in config_host
> +have_vhost_kernel = 'CONFIG_VHOST_KERNEL' in config_host
> +have_vhost_net_user = 'CONFIG_VHOST_NET_USER' in config_host
> +have_vhost_net_vdpa = 'CONFIG_VHOST_NET_VDPA' in config_host
> +have_vhost_net = 'CONFIG_VHOST_NET' in config_host
> +have_vhost_user_crypto = 'CONFIG_VHOST_CRYPTO' in config_host
> +
>  # Target-specific libraries and flags
>  libm = cc.find_library('m', required: false)
>  threads = dependency('threads')
> @@ -1440,7 +1449,7 @@ has_statx_mnt_id = cc.links(statx_mnt_id_test)
>  have_vhost_user_blk_server = get_option('vhost_user_blk_server') \
>.require(targetos == 'linux',
> error_message: 'vhost_user_blk_server requires linux') \
> -  .require('CONFIG_VHOST_USER' in config_host,
> +  .require(have_vhost_user,
> error_message: 'vhost_user_blk_server requires vhost-user
> support') \
>.disable_auto_if(not have_system) \
>.allowed()
> @@ -2283,9 +2292,9 @@ host_kconfig = \
>(have_ivshmem ? ['CONFIG_IVSHMEM=y'] : []) + \
>(opengl.found() ? ['CONFIG_OPENGL=y'] : []) + \
>(x11.found() ? ['CONFIG_X11=y'] : []) + \
> -  ('CONFIG_VHOST_USER' in config_host ? ['CONFIG_VHOST_USER=y'] : []) + \
> -  ('CONFIG_VHOST_VDPA' in config_host ? ['CONFIG_VHOST_VDPA=y'] : []) + \
> -  ('CONFIG_VHOST_KERNEL' in config_host ? ['CONFIG_VHOST_KERNEL=y'] : [])
> + \
> +  (have_vhost_user ? ['CONFIG_VHOST_USER=y'] : []) + \
> +  (have_vhost_vdpa ? ['CONFIG_VHOST_VDPA=y'] : []) + \
> +  (have_vhost_kernel ? ['CONFIG_VHOST_KERNEL=y'] : []) + \
>(have_virtfs ? ['CONFIG_VIRTFS=y'] : []) + \
>('CONFIG_LINUX' in config_host ? ['CONFIG_LINUX=y'] : []) + \
>(have_pvrdma ? ['CONFIG_PVRDMA=y'] : []) + \
> @@ -2967,7 +2976,7 @@ if have_system or have_user
>  endif
>
>  vhost_user = not_found
> -if targetos == 'linux' and 'CONFIG_VHOST_USER' in config_host
> +if targetos == 'linux' and have_vhost_user
>libvhost_user = subproject('libvhost-user')
>vhost_user = libvhost_user.get_variable('vhost_user_dep')
>  endif
> @@ -3548,7 +3557,7 @@ if have_tools
>   dependencies: qemuutil,
>   install: true)
>
> -  if 'CONFIG_VHOST_USER' in config_host
> +  if have_vhost_user
>  subdir('contrib/vhost-user-blk')
>  subdir('contrib/vhost-user-gpu')
>  subdir('contrib/vhost-user-input')
> @@ -3674,12 +3683,12 @@ if 'simple' in get_option('trace_backends')
>  endif
>  summary_info += {'D-Bus display': dbus_display}
>  summary_info += {'QOM debugging': get_option('qom_cast_debug')}
> -summary_info += {'vhost-kernel support':
> config_host.has_key('CONFIG_VHOST_KERNEL')}
> -summary_info += {'vhost-net support':
> config_host.has_key('CONFIG_VHOST_NET')}
> -summary_info += {'vhost-crypto support':
> config_host.has_key('CONFIG_VHOST_CRYPTO')}
> -summary_info += {'vhost-user support':
> config_host.has_key('CONFIG_VHOST_USER')}
> +summary_info += {'vhost-kernel support': have_vhost_kernel}
> +summary_info += {'vhost-net support': have_vhost_net}
> +summary_info += {'vhost-user support': have_vhost_user}
> +summary_info += {'vhost-user-crypto support': have_vhost_user_crypto}
>  summary_info += {'vhost-user-blk server support':
> have_vhost_user_blk_server}
> -summary_info += {'vhost-vdpa support':
> config_host.has_key('CONFIG_VHOST_VDPA')}
> +summary_info += {'vhost-vdpa support': have_vhost_vdpa}
>  summary_info += {'build guest agent': have_ga}
>  summary(summary_info, bool_yn: true, section: 'Configurable features')
>
> diff --git a/tests/meson.build b/tests/meson.build
> index 4f691e8465..8e318ec513 100644
> --- a/tests/meson.build
> +++ b/tests/meson.build
> @@ -68,7 +68,7 @@ test_deps = {
>'test-qht-par': qht_bench,
>  }
>
> -if have_tools and 'CONFIG_VHOST_USER' in config_host and 'CONFIG_LINUX'
> in config_host
> +if have_tools and have_vhost_user and 'CONFIG_LINUX' in config_host
>executable('vhost-user-bridge',
>   sources: files('vhost

Re: [PATCH v7 1/4] qapi/machine.json: Add cluster-id

2022-04-21 Thread wangyanan (Y)

Hi Gavin,

On 2022/4/20 18:49, Gavin Shan wrote:

This adds cluster-id in CPU instance properties, which will be used
by arm/virt machine. Besides, the cluster-id is also verified or
dumped in various spots:

   * hw/core/machine.c::machine_set_cpu_numa_node() to associate
 CPU with its NUMA node.

   * hw/core/machine.c::machine_numa_finish_cpu_init() to associate
 CPU with NUMA node when no default association isn't provided.
nit: It doesn't really matter too much. But maybe clearer to read a 
sentence like
"machine_numa_finish_cpu_init() to record CPU slots with no NUMA mapping 
set."


Thanks,
Yanan


   * hw/core/machine-hmp-cmds.c::hmp_hotpluggable_cpus() to dump
 cluster-id.

Signed-off-by: Gavin Shan 
Reviewed-by: Yanan Wang 
---
  hw/core/machine-hmp-cmds.c |  4 
  hw/core/machine.c  | 16 
  qapi/machine.json  |  6 --
  3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/hw/core/machine-hmp-cmds.c b/hw/core/machine-hmp-cmds.c
index 4e2f319aeb..5cb5eecbfc 100644
--- a/hw/core/machine-hmp-cmds.c
+++ b/hw/core/machine-hmp-cmds.c
@@ -77,6 +77,10 @@ void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
  if (c->has_die_id) {
  monitor_printf(mon, "die-id: \"%" PRIu64 "\"\n", c->die_id);
  }
+if (c->has_cluster_id) {
+monitor_printf(mon, "cluster-id: \"%" PRIu64 "\"\n",
+   c->cluster_id);
+}
  if (c->has_core_id) {
  monitor_printf(mon, "core-id: \"%" PRIu64 "\"\n", c->core_id);
  }
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 1e23fdc14b..ac91dfd834 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -679,6 +679,11 @@ void machine_set_cpu_numa_node(MachineState *machine,
  return;
  }
  
+if (props->has_cluster_id && !slot->props.has_cluster_id) {

+error_setg(errp, "cluster-id is not supported");
+return;
+}
+
  if (props->has_socket_id && !slot->props.has_socket_id) {
  error_setg(errp, "socket-id is not supported");
  return;
@@ -698,6 +703,11 @@ void machine_set_cpu_numa_node(MachineState *machine,
  continue;
  }
  
+if (props->has_cluster_id &&

+props->cluster_id != slot->props.cluster_id) {
+continue;
+}
+
  if (props->has_die_id && props->die_id != slot->props.die_id) {
  continue;
  }
@@ -992,6 +1002,12 @@ static char *cpu_slot_to_string(const CPUArchId *cpu)
  }
  g_string_append_printf(s, "die-id: %"PRId64, cpu->props.die_id);
  }
+if (cpu->props.has_cluster_id) {
+if (s->len) {
+g_string_append_printf(s, ", ");
+}
+g_string_append_printf(s, "cluster-id: %"PRId64, 
cpu->props.cluster_id);
+}
  if (cpu->props.has_core_id) {
  if (s->len) {
  g_string_append_printf(s, ", ");
diff --git a/qapi/machine.json b/qapi/machine.json
index d25a481ce4..4c417e32a5 100644
--- a/qapi/machine.json
+++ b/qapi/machine.json
@@ -868,10 +868,11 @@
  # @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 socket the CPU belongs to (since 4.1)
-# @core-id: core number within die the CPU belongs to
+# @cluster-id: cluster number within die the CPU belongs to (since 7.1)
+# @core-id: core number within cluster the CPU belongs to
  # @thread-id: thread number within core the CPU belongs to
  #
-# Note: currently there are 5 properties that could be present
+# Note: currently there are 6 properties that could be present
  #   but management should be prepared to pass through other
  #   properties with device_add command to allow for future
  #   interface extension. This also requires the filed names to be kept in
@@ -883,6 +884,7 @@
'data': { '*node-id': 'int',
  '*socket-id': 'int',
  '*die-id': 'int',
+'*cluster-id': 'int',
  '*core-id': 'int',
  '*thread-id': 'int'
}





Re: [PATCH 33/34] meson: use have_vhost_* variables to pick sources

2022-04-21 Thread Marc-André Lureau
On Wed, Apr 20, 2022 at 8:28 PM Paolo Bonzini  wrote:

> Signed-off-by: Paolo Bonzini 
>

Reviewed-by: Marc-André Lureau 


> ---
>  Kconfig.host|  3 ---
>  backends/meson.build|  8 ++--
>  hw/net/meson.build  |  8 ++--
>  hw/virtio/Kconfig   |  3 ---
>  hw/virtio/meson.build   | 25 -
>  meson.build |  1 +
>  net/meson.build | 12 +++-
>  tests/qtest/meson.build |  4 +++-
>  8 files changed, 39 insertions(+), 25 deletions(-)
>
> diff --git a/Kconfig.host b/Kconfig.host
> index 60b9c07b5e..1165c4eacd 100644
> --- a/Kconfig.host
> +++ b/Kconfig.host
> @@ -22,15 +22,12 @@ config TPM
>
>  config VHOST_USER
>  bool
> -select VHOST
>
>  config VHOST_VDPA
>  bool
> -select VHOST
>
>  config VHOST_KERNEL
>  bool
> -select VHOST
>
>  config VIRTFS
>  bool
> diff --git a/backends/meson.build b/backends/meson.build
> index 535c3ca7dd..b1884a88ec 100644
> --- a/backends/meson.build
> +++ b/backends/meson.build
> @@ -12,9 +12,13 @@ softmmu_ss.add([files(
>  softmmu_ss.add(when: 'CONFIG_POSIX', if_true: files('rng-random.c'))
>  softmmu_ss.add(when: 'CONFIG_POSIX', if_true: files('hostmem-file.c'))
>  softmmu_ss.add(when: 'CONFIG_LINUX', if_true: files('hostmem-memfd.c'))
> -softmmu_ss.add(when: ['CONFIG_VHOST_USER', 'CONFIG_VIRTIO'], if_true:
> files('vhost-user.c'))
> +if have_vhost_user
> +  softmmu_ss.add(when: 'CONFIG_VIRTIO', if_true: files('vhost-user.c'))
> +endif
>  softmmu_ss.add(when: 'CONFIG_VIRTIO_CRYPTO', if_true:
> files('cryptodev-vhost.c'))
> -softmmu_ss.add(when: ['CONFIG_VIRTIO_CRYPTO', 'CONFIG_VHOST_CRYPTO'],
> if_true: files('cryptodev-vhost-user.c'))
> +if have_vhost_user_crypto
> +  softmmu_ss.add(when: 'CONFIG_VIRTIO_CRYPTO', if_true:
> files('cryptodev-vhost-user.c'))
> +endif
>  softmmu_ss.add(when: gio, if_true: files('dbus-vmstate.c'))
>  softmmu_ss.add(when: 'CONFIG_SGX', if_true: files('hostmem-epc.c'))
>
> diff --git a/hw/net/meson.build b/hw/net/meson.build
> index 685b75badb..ebac261542 100644
> --- a/hw/net/meson.build
> +++ b/hw/net/meson.build
> @@ -46,8 +46,12 @@ specific_ss.add(when: 'CONFIG_XILINX_ETHLITE', if_true:
> files('xilinx_ethlite.c'
>  softmmu_ss.add(when: 'CONFIG_VIRTIO_NET', if_true: files('net_rx_pkt.c'))
>  specific_ss.add(when: 'CONFIG_VIRTIO_NET', if_true: files('virtio-net.c'))
>
> -softmmu_ss.add(when: ['CONFIG_VIRTIO_NET', 'CONFIG_VHOST_NET'], if_true:
> files('vhost_net.c'), if_false: files('vhost_net-stub.c'))
> -softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost_net-stub.c'))
> +if have_vhost_net
> +  softmmu_ss.add(when: 'CONFIG_VIRTIO_NET', if_true:
> files('vhost_net.c'), if_false: files('vhost_net-stub.c'))
> +  softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost_net-stub.c'))
> +else
> +  softmmu_ss.add(files('vhost_net-stub.c'))
> +endif
>
>  softmmu_ss.add(when: 'CONFIG_ETSEC', if_true: files(
>'fsl_etsec/etsec.c',
> diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig
> index f8e235f814..e9ecae1f50 100644
> --- a/hw/virtio/Kconfig
> +++ b/hw/virtio/Kconfig
> @@ -1,6 +1,3 @@
> -config VHOST
> -bool
> -
>  config VIRTIO
>  bool
>
> diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build
> index f371404b04..7e8877fd64 100644
> --- a/hw/virtio/meson.build
> +++ b/hw/virtio/meson.build
> @@ -2,18 +2,22 @@ softmmu_virtio_ss = ss.source_set()
>  softmmu_virtio_ss.add(files('virtio-bus.c'))
>  softmmu_virtio_ss.add(when: 'CONFIG_VIRTIO_PCI', if_true:
> files('virtio-pci.c'))
>  softmmu_virtio_ss.add(when: 'CONFIG_VIRTIO_MMIO', if_true:
> files('virtio-mmio.c'))
> -softmmu_virtio_ss.add(when: 'CONFIG_VHOST', if_false:
> files('vhost-stub.c'))
> -
> -softmmu_ss.add_all(when: 'CONFIG_VIRTIO', if_true: softmmu_virtio_ss)
> -softmmu_ss.add(when: 'CONFIG_VIRTIO', if_false: files('vhost-stub.c'))
> -
> -softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost-stub.c'))
>
>  virtio_ss = ss.source_set()
>  virtio_ss.add(files('virtio.c'))
> -virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c',
> 'vhost-backend.c', 'vhost-iova-tree.c'))
> -virtio_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user.c'))
> -virtio_ss.add(when: 'CONFIG_VHOST_VDPA', if_true:
> files('vhost-shadow-virtqueue.c', 'vhost-vdpa.c'))
> +
> +if have_vhost
> +  virtio_ss.add(files('vhost.c', 'vhost-backend.c', 'vhost-iova-tree.c'))
> +  if have_vhost_user
> +virtio_ss.add(files('vhost-user.c'))
> +  endif
> +  if have_vhost_vdpa
> +virtio_ss.add(files('vhost-vdpa.c', 'vhost-shadow-virtqueue.c'))
> +  endif
> +else
> +  softmmu_virtio_ss.add(files('vhost-stub.c'))
> +endif
> +
>  virtio_ss.add(when: 'CONFIG_VIRTIO_BALLOON', if_true:
> files('virtio-balloon.c'))
>  virtio_ss.add(when: 'CONFIG_VIRTIO_CRYPTO', if_true:
> files('virtio-crypto.c'))
>  virtio_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true:
> files('vhost-user-fs.c'))
> @@ -54,3 +58,6 @@ virtio_pci_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true:
> files('virtio-mem-pci.c'))
>  virtio_ss.ad

Re: [PATCH 04/26] coroutine: remove incorrect coroutine_fn annotations

2022-04-21 Thread Stefan Hajnoczi
On Fri, Apr 15, 2022 at 03:18:38PM +0200, Paolo Bonzini wrote:
> Signed-off-by: Paolo Bonzini 
> ---
>  include/qemu/coroutine.h | 2 +-
>  util/qemu-coroutine.c| 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)

This one is easy to audit because the implementation of
qemu_coroutine_get_aio_context() definitely does not require running in
coroutine context. :)

Reviewed-by: Stefan Hajnoczi 


signature.asc
Description: PGP signature


Re: [PATCH 31/34] build: move vhost-user-fs configuration to Kconfig

2022-04-21 Thread Marc-André Lureau
On Wed, Apr 20, 2022 at 8:24 PM Paolo Bonzini  wrote:

> vhost-user-fs is a device and it should be possible to enable/disable
> it with --without-default-devices, not --without-default-features.
> Compute its default value in Kconfig to obtain the more intuitive
> behavior.
>
> In this case the configure options were undocumented, too.
>
> Signed-off-by: Paolo Bonzini 
>

Reviewed-by: Marc-André Lureau 

---
>  configure | 12 
>  hw/virtio/Kconfig |  5 +
>  meson.build   |  1 -
>  3 files changed, 5 insertions(+), 13 deletions(-)
>
> diff --git a/configure b/configure
> index 65ae2c0c1f..3b38ff3c63 100755
> --- a/configure
> +++ b/configure
> @@ -286,7 +286,6 @@ vhost_kernel="$default_feature"
>  vhost_net="$default_feature"
>  vhost_crypto="$default_feature"
>  vhost_user="no"
> -vhost_user_fs="$default_feature"
>  vhost_vdpa="$default_feature"
>  debug_tcg="no"
>  sanitizers="no"
> @@ -872,10 +871,6 @@ for opt do
>;;
>--enable-vhost-crypto) vhost_crypto="yes"
>;;
> -  --disable-vhost-user-fs) vhost_user_fs="no"
> -  ;;
> -  --enable-vhost-user-fs) vhost_user_fs="yes"
> -  ;;
>--disable-zlib-test)
>;;
>--disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
> @@ -1536,10 +1531,6 @@ test "$vhost_crypto" = "" &&
> vhost_crypto=$vhost_user
>  if test "$vhost_crypto" = "yes" && test "$vhost_user" = "no"; then
>error_exit "--enable-vhost-crypto requires --enable-vhost-user"
>  fi
> -test "$vhost_user_fs" = "" && vhost_user_fs=$vhost_user
> -if test "$vhost_user_fs" = "yes" && test "$vhost_user" = "no"; then
> -  error_exit "--enable-vhost-user-fs requires --enable-vhost-user"
> -fi
>
>  # OR the vhost-kernel, vhost-vdpa and vhost-user values for simplicity
>  if test "$vhost_net" = ""; then
> @@ -2088,9 +2079,6 @@ fi
>  if test "$vhost_vdpa" = "yes" ; then
>echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak
>  fi
> -if test "$vhost_user_fs" = "yes" ; then
> -  echo "CONFIG_VHOST_USER_FS=y" >> $config_host_mak
> -fi
>
>  # XXX: suppress that
>  if [ "$bsd" = "yes" ] ; then
> diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig
> index b642ae1081..f8e235f814 100644
> --- a/hw/virtio/Kconfig
> +++ b/hw/virtio/Kconfig
> @@ -78,3 +78,8 @@ config VHOST_USER_RNG
>  bool
>  default y
>  depends on VIRTIO && VHOST_USER
> +
> +config VHOST_USER_FS
> +bool
> +default y
> +depends on VIRTIO && VHOST_USER
> diff --git a/meson.build b/meson.build
> index b18731ee84..870dd8dee0 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -3679,7 +3679,6 @@ summary_info += {'vhost-net support':
> config_host.has_key('CONFIG_VHOST_NET')}
>  summary_info += {'vhost-crypto support':
> config_host.has_key('CONFIG_VHOST_CRYPTO')}
>  summary_info += {'vhost-user support':
> config_host.has_key('CONFIG_VHOST_USER')}
>  summary_info += {'vhost-user-blk server support':
> have_vhost_user_blk_server}
> -summary_info += {'vhost-user-fs support':
> config_host.has_key('CONFIG_VHOST_USER_FS')}
>  summary_info += {'vhost-vdpa support':
> config_host.has_key('CONFIG_VHOST_VDPA')}
>  summary_info += {'build guest agent': have_ga}
>  summary(summary_info, bool_yn: true, section: 'Configurable features')
> --
> 2.35.1
>
>
>
>

-- 
Marc-André Lureau


Re: [PATCH 4/5] 9pfs: fix wrong errno being sent to Linux client on macOS host

2022-04-21 Thread Christian Schoenebeck
On Donnerstag, 21. April 2022 13:46:26 CEST Greg Kurz wrote:
> On Thu, 21 Apr 2022 13:13:08 +0200
> 
> Christian Schoenebeck  wrote:
> > On Donnerstag, 21. April 2022 12:48:35 CEST Greg Kurz wrote:
> > > On Tue, 19 Apr 2022 13:41:59 +0200
> > > 
> > > Christian Schoenebeck  wrote:
> > > > Linux and macOS only share some errno definitions with equal macro
> > > > name and value. In fact most mappings for errno are completely
> > > > different on the two systems.
> > > > 
> > > > This patch converts some important errno values from macOS host to
> > > > corresponding Linux errno values before eventually sending such error
> > > > codes along with Tlerror replies (if 9p2000.L is used that is), which
> > > > fixes a bunch of misbehaviours when running a Linux client on macOS
> > > > host.
> > > 
> > > This even fixes an actual protocol violation :
> > > 
> > > lerror -- return error code
> > > 
> > > size[4] Rlerror tag[2] ecode[4]
> > > 
> > > lerror replaces the reply message used in a successful call. ecode is a
> > > numerical Linux errno.
> > > ^
> > > 
> > > Taken from
> > > https://github.com/chaos/diod/wiki/protocol#lerrorreturn-error-code
> > 
> > Again, something to add to the commit log?
> 
> IMHO a protocol violation is important enough to be mentioned but
> I'll leave it to you.

Ok, will do.

> > > > For instance this patch fixes:
> > > >   mount -t 9p -o posixacl ...
> > > > 
> > > > on Linux guest if security_mode=mapped was used for 9p server, which
> > > > refused to mount successfully, because macOS returned ENOATTR==93
> > > > when client tried to retrieve POSIX ACL xattrs, because errno 93
> > > > is defined as EPROTONOSUPPORT==93 on Linux, so Linux client believed
> > > > that xattrs were not supported by filesystem on host in general.
> > > > 
> > > > Signed-off-by: Christian Schoenebeck 
> > > > ---
> > > > 
> > > >  hw/9pfs/9p.c | 27 +++
> > > >  1 file changed, 27 insertions(+)
> > > > 
> > > > diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> > > > index d953035e1c..becc41cbfd 100644
> > > > --- a/hw/9pfs/9p.c
> > > > +++ b/hw/9pfs/9p.c
> > > > @@ -57,6 +57,31 @@ enum {
> > > > 
> > > >  P9ARRAY_DEFINE_TYPE(V9fsPath, v9fs_path_free);
> > > > 
> > > > +/* Translates errno from host -> Linux if needed */
> > > > +static int errno_to_dotl(int err) {
> > > > +#if defined(CONFIG_LINUX)
> > > > +/* nothing to translate (Linux -> Linux) */
> > > > +#elif defined(CONFIG_DARWIN)
> > > > +/* translation mandatory for macOS hosts */
> > > > +if (err == ENAMETOOLONG) {
> > > > +err = 36; /* ==ENAMETOOLONG on Linux */
> > > > +} else if (err == ENOTEMPTY) {
> > > > +err = 39; /* ==ENOTEMPTY on Linux */
> > > > +} else if (err == ELOOP) {
> > > > +err = 40; /* ==ELOOP on Linux */
> > > > +} else if (err == ENOATTR) {
> > > > +err = 61; /* ==ENODATA on Linux */
> > > > +} else if (err == ENOTSUP) {
> > > > +err = 95; /* ==EOPNOTSUPP on Linux */
> > > > +} else if (err == EOPNOTSUPP) {
> > > > +err = 95; /* ==EOPNOTSUPP on Linux */
> > > > +}
> > > 
> > > I'm assuming you have audited all errnos, right ? Just to be sure
> > > that this won't bite anymore.
> > 
> > Depends on what you mean with "all". Like I wrote in the commit log, for
> > now I translated in this patch those errnos that I identified as
> > important, and those are audited by me of course (checked the man pages
> > for what errors are expected as result from calls on Linux vs. macOS side
> > and looked up numeric values from header files on both sides, tests).
> 
> I was pretty sure you'd have done that at least :-)
> 
> > However if you rather mean really all errnos that were ever defined on
> > Linux and macOS, then the answer is no. That would probably quite some
> > work, and I'm not sure if you could just try to translate them dry, i.e.
> > by just looking at the headers or something.
> 
> But yes I was rather meaning the full errno set.
> 
> > So yes, your concern is justified. The question is, should this all be
> > translated right now already, or would it be OK to address this minimum
> > set of errno translation for now (especially for qemu-stable) and then
> > later address the rest?
> 
> My concern is about the maintenance burden of investigating future
> implementations of this issue, so I'd say it is mostly up to you
> as the principal maintainer. Maybe leave a FIXME comment in the code
> that the list of translated errnos isn't exhaustive at least ?

I stick to this minimal approach with FIXME comment then for now. I have 
tested this patch thoroughly on macOS and did not encounter similar issues. So 
I think it is good enough as first-aid patch at least.

The aforementioned case-insensitive filesystem issues are a higher priority 
from my PoV, because they trigger various misbehaviour in my tests.

Best regards,
Christian Schoenebeck

> > On the long term you would probably import the Linux err

Re: Future of libslirp in QEMU

2022-04-21 Thread Paolo Bonzini

On 4/20/22 21:08, Anders Pitman wrote:
I noticed in the 7.0 changelog that libslirp might be removed as a 
submodule in the future. Since user networking is very important for my 
project, I'm wondering if this is simply an implementation detail, or if 
there are plans to eventually remove slirp support entirely from QEMU 
(which would be bad for me)?


No, libslirp is now a standalone project and we'll rely on distros to 
provide the package for the library (and a -devel package that 
meson/pkg-config can use to find whether the library exist).


Paolo

Is there somewhere I can read the discussion about this? I searched the 
mailing list archives but didn't see anything obvious.





Re: [PATCH v8 10/12] target/hexagon: import parser for idef-parser

2022-04-21 Thread Anton Johansson via

Here's an updated version of `gen_set_usr_field_If`

https://gitlab.com/AntonJohansson/qemu/-/blob/feature/idef-parser/target/hexagon/genptr.c#L673

If this looks alright and we have your "reviewed-by" on this patch, I'll 
go ahead and submit the new

patchset! :)

--
Anton Johansson,
rev.ng Labs Srl.




From: Anton Johansson 
Sent: Tuesday, April 12, 2022 10:11 AM
To: Taylor Simpson ; qemu-devel@nongnu.org
Cc: a...@rev.ng; Brian Cain ; Michael Lambert 
; bab...@rev.ng; ni...@rev.ng; richard.hender...@linaro.org
Subject: Re: [PATCH v8 10/12] target/hexagon: import parser for idef-parser

Very nice catch, this is the bug that plagued us a few weeks ago when rebasing,
it has since been fixed. Actually the `gen_set_overflow` fucntion has been 
removed
completely as it was only called when we handled `asl/asr_r_r_sat`.
Current way we handle overflow:

Overflow is now only set by saturates, this assumption holds for the 
instructions
we parse in phase 1. In the parser, all saturates call `gen_rvalue_sat` which 
emits
a call to `gen_set_usr_field_if` in `genptr.c` to set USR_OVF only if the value 
is
non-zero. It does this via OR'ing with the previous value.

See 
https://gitlab.com/AntonJohansson/qemu/-/blob/feature/idef-parser/target/hexagon/idef-parser/parser-helpers.c#L2109
 for `gen_rvalue_sat`
and 
https://gitlab.com/AntonJohansson/qemu/-/blob/feature/idef-parser/target/hexagon/genptr.c#L669
 for `gen_set_usr_field_if`

Your implementation of gen_set_usr_field_if is not correct.  Don't extract the bits from the value 
based on the reg_field_info.  The easiest thing to do is compare val with zero and jump over a call 
to gen_set_usr_field.  If you are determined to do an "or", you have to assert that 
ref_field_info[field].width == 1.  Then, you can extract 1 bit from val starting at offset zero and 
shift the result left by ref_field_info[field].offset and then "or" with USR.

Thanks,
Taylor





Re: [PATCH 24/34] configure: switch directory options to automatic parsing

2022-04-21 Thread Paolo Bonzini

On 4/21/22 11:48, Marc-André Lureau wrote:

While prefix, bindir and qemu_suffix needs special treatment due to
differences between Windows and POSIX systems, everything else
needs no extra code in configure.


Afaik, it's not common to install binaries under $prefix on Windows. I 
don't know any open-source project doing that. msys2 explicitly change 
it to bin again: 
https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-qemu/PKGBUILD#L94 



It's not, but it's been done like this forever in QEMU for the sake of 
installing
in "C:\Program Files".

I didn't want to introduce visible changes with this patch, but we could
remove this special casing, and apply it instead when building the NSIS
installers.

Paolo



Re: [PATCH 34/34] configure, meson: move vhost options to Meson

2022-04-21 Thread Marc-André Lureau
On Wed, Apr 20, 2022 at 8:05 PM Paolo Bonzini  wrote:

> Finish the conversion by moving all the definitions and the constraint
> checks to meson_options.txt and meson.build respectively.
>
> Signed-off-by: Paolo Bonzini 
>

lgtm
Reviewed-by: Marc-André Lureau 


> ---
>  configure | 82 ---
>  meson.build   | 33 +++---
>  meson_options.txt | 10 +
>  scripts/meson-buildoptions.sh | 15 +++
>  4 files changed, 51 insertions(+), 89 deletions(-)
>
> diff --git a/configure b/configure
> index 3b38ff3c63..0cedfcf5a9 100755
> --- a/configure
> +++ b/configure
> @@ -282,11 +282,6 @@ EXTRA_CXXFLAGS=""
>  EXTRA_OBJCFLAGS=""
>  EXTRA_LDFLAGS=""
>
> -vhost_kernel="$default_feature"
> -vhost_net="$default_feature"
> -vhost_crypto="$default_feature"
> -vhost_user="no"
> -vhost_vdpa="$default_feature"
>  debug_tcg="no"
>  sanitizers="no"
>  tsan="no"
> @@ -526,7 +521,6 @@ haiku)
>  ;;
>  linux)
>linux="yes"
> -  vhost_user=${default_feature:-yes}
>  ;;
>  esac
>
> @@ -863,14 +857,6 @@ for opt do
>;;
>--with-coroutine=*) coroutine="$optarg"
>;;
> -  --disable-vhost-net) vhost_net="no"
> -  ;;
> -  --enable-vhost-net) vhost_net="yes"
> -  ;;
> -  --disable-vhost-crypto) vhost_crypto="no"
> -  ;;
> -  --enable-vhost-crypto) vhost_crypto="yes"
> -  ;;
>--disable-zlib-test)
>;;
>--disable-virtio-blk-data-plane|--enable-virtio-blk-data-plane)
> @@ -882,18 +868,6 @@ for opt do
>--enable-uuid|--disable-uuid)
>echo "$0: $opt is obsolete, UUID support is always built" >&2
>;;
> -  --disable-vhost-user) vhost_user="no"
> -  ;;
> -  --enable-vhost-user) vhost_user="yes"
> -  ;;
> -  --disable-vhost-vdpa) vhost_vdpa="no"
> -  ;;
> -  --enable-vhost-vdpa) vhost_vdpa="yes"
> -  ;;
> -  --disable-vhost-kernel) vhost_kernel="no"
> -  ;;
> -  --enable-vhost-kernel) vhost_kernel="yes"
> -  ;;
>--disable-capstone) capstone="disabled"
>;;
>--enable-capstone) capstone="enabled"
> @@ -1092,11 +1066,6 @@ cat << EOF
>debug-info  debugging information
>safe-stack  SafeStack Stack Smash Protection. Depends on
>clang/llvm >= 3.7 and requires coroutine backend
> ucontext.
> -  vhost-net   vhost-net kernel acceleration support
> -  vhost-cryptovhost-user-crypto backend support
> -  vhost-kernelvhost kernel backend support
> -  vhost-user  vhost-user backend support
> -  vhost-vdpa  vhost-vdpa kernel backend support
>
>  NOTE: The object files are built at the place where configure is launched
>  EOF
> @@ -1510,35 +1479,6 @@ else
>  exit 1
>  fi
>
> -#
> -# vhost interdependencies and host support
> -
> -# vhost backends
> -if test "$vhost_user" = "yes" && test "$mingw32" = "yes"; then
> -  error_exit "vhost-user is not available on Windows"
> -fi
> -test "$vhost_vdpa" = "" && vhost_vdpa=$linux
> -if test "$vhost_vdpa" = "yes" && test "$linux" != "yes"; then
> -  error_exit "vhost-vdpa is only available on Linux"
> -fi
> -test "$vhost_kernel" = "" && vhost_kernel=$linux
> -if test "$vhost_kernel" = "yes" && test "$linux" != "yes"; then
> -  error_exit "vhost-kernel is only available on Linux"
> -fi
> -
> -# vhost-user backends
> -test "$vhost_crypto" = "" && vhost_crypto=$vhost_user
> -if test "$vhost_crypto" = "yes" && test "$vhost_user" = "no"; then
> -  error_exit "--enable-vhost-crypto requires --enable-vhost-user"
> -fi
> -
> -# OR the vhost-kernel, vhost-vdpa and vhost-user values for simplicity
> -if test "$vhost_net" = ""; then
> -  test "$vhost_user" = "yes" && vhost_net=yes
> -  test "$vhost_vdpa" = "yes" && vhost_net=yes
> -  test "$vhost_kernel" = "yes" && vhost_net=yes
> -fi
> -
>  ##
>  # pkg-config probe
>
> @@ -2058,28 +1998,6 @@ if test "$modules" = "yes"; then
>echo "CONFIG_MODULES=y" >> $config_host_mak
>  fi
>
> -if test "$vhost_net" = "yes" ; then
> -  echo "CONFIG_VHOST_NET=y" >> $config_host_mak
> -fi
> -if test "$vhost_user" = "yes" ; then
> -  echo "CONFIG_VHOST_NET_USER=y" >> $config_host_mak
> -fi
> -if test "$vhost_vdpa" = "yes" ; then
> -  echo "CONFIG_VHOST_NET_VDPA=y" >> $config_host_mak
> -fi
> -if test "$vhost_crypto" = "yes" ; then
> -  echo "CONFIG_VHOST_CRYPTO=y" >> $config_host_mak
> -fi
> -if test "$vhost_kernel" = "yes" ; then
> -  echo "CONFIG_VHOST_KERNEL=y" >> $config_host_mak
> -fi
> -if test "$vhost_user" = "yes" ; then
> -  echo "CONFIG_VHOST_USER=y" >> $config_host_mak
> -fi
> -if test "$vhost_vdpa" = "yes" ; then
> -  echo "CONFIG_VHOST_VDPA=y" >> $config_host_mak
> -fi
> -
>  # XXX: suppress that
>  if [ "$bsd" = "yes" ] ; then
>echo "CONFIG_BSD=y" >> $config_host_mak
> diff --git a/meson.build b/meson.build
> index e8446cf148..499082bf55 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -313,14 +313,26 @@ have_tpm = get_option('tpm') \
>.allowed()
>
>  # vhost
> -have_vhost_user = 'CONFIG_VHOST_USER' in 

Re: [PATCH 5/5] 9pfs: fix removing non-existent POSIX ACL xattr on macOS host

2022-04-21 Thread Greg Kurz
On Thu, 21 Apr 2022 12:55:24 +0200
Christian Schoenebeck  wrote:

> On Donnerstag, 21. April 2022 10:26:11 CEST Greg Kurz wrote:
> > On Tue, 19 Apr 2022 13:43:30 +0200
> > 
> > Christian Schoenebeck  wrote:
> > > When mapped POSIX ACL is used, we are ignoring errors when trying
> > > to remove a POSIX ACL xattr that does not exist. On Linux hosts we
> > > would get ENODATA in such cases, on macOS hosts however we get
> > > ENOATTR instead, so ignore ENOATTR errors as well.
> > > 
> > > This patch fixes e.g. a command on Linux guest like:
> > >   cp --preserve=mode old new
> > > 
> > > Signed-off-by: Christian Schoenebeck 
> > > ---
> > > 
> > >  hw/9pfs/9p-posix-acl.c | 8 +++-
> > >  1 file changed, 7 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/hw/9pfs/9p-posix-acl.c b/hw/9pfs/9p-posix-acl.c
> > > index eadae270dd..2bf155f941 100644
> > > --- a/hw/9pfs/9p-posix-acl.c
> > > +++ b/hw/9pfs/9p-posix-acl.c
> > > @@ -65,7 +65,13 @@ static int mp_pacl_removexattr(FsContext *ctx,
> > > 
> > >  int ret;
> > >  
> > >  ret = local_removexattr_nofollow(ctx, path, MAP_ACL_ACCESS);
> > > 
> > > -if (ret == -1 && errno == ENODATA) {
> > > +if (ret == -1 &&
> > > +  (errno == ENODATA
> > > +#ifdef ENOATTR
> > > +  || errno == ENOATTR
> > > +#endif
> > > +  )
> > 
> > We already have this in  which is included by
> > 9p-posix-acl.c :
> > 
> > /*
> >  * Modern distributions (e.g. Fedora 15), have no libattr.so, place attr.h
> >  * in /usr/include/sys, and don't have ENOATTR.
> >  */
> > 
> > 
> > #ifdef CONFIG_LIBATTR
> > #  include 
> > #else
> > #  if !defined(ENOATTR)
> > #define ENOATTR ENODATA
> > #  endif
> > #  include 
> > #endif
> > 
> > I guess this patch could just s/ENODATA/ENOATTR/ to avoid the
> > extra ifdefery.
> 
> Not viable, because macOS does have both ENODATA==96 and ENOATTR==93. On 
> Linux 
> the two macros were historically defined to the same numeric values, that's 
> why it worked there.
> 

I was meaning your current fix could simply do:

-if (ret == -1 && errno == ENODATA) {
+if (ret == -1 && errno == ENOATTR) {

since ENOATTR works in all cases, but this is rather a hack.

Another solution would be to ensure that local_removexattr_nofollow() only
reports linux errnos. This could be handled cleanly in the
fremovexattrat_nofollow() implementation in 9p-util-darwin.c.

Since the 9p code base mostly assumes the host is linux, this should
probably be generalized to other places where we check errno.

> Maybe I should define a separate macro like:
> 
> #if ...
> # define P9_ENOATTR ENOATTR
> #else
> # define P9_ENOATTR ENODATA
> #end
> 
> ?
> 
> Actually good that you pointed me at this, because I just realized there is a 
> 2nd place in 9p-posix-acl.c which would require this as well. For some reason 
> the 2nd place just did not trigger while I was testing it on macOS.
> 
> Best regards,
> Christian Schoenebeck
> 
> 




Re: [PATCH] hw/crypto: add Allwinner sun4i-ss crypto device

2022-04-21 Thread Peter Maydell
On Sun, 10 Apr 2022 at 20:12, Corentin Labbe  wrote:
>
> From: Corentin LABBE 
>
> The Allwinner A10 has a cryptographic offloader device which
> could be easily emulated.
> The emulated device is tested with Linux only as any of BSD does not
> support it.
>
> Signed-off-by: Corentin LABBE 

Hi; thanks for this patch, and sorry it's taken me a while to get
to reviewing it.

(Daniel, I cc'd you since this device model is making use of crypto
related APIs.)

Firstly, a note on patch structure. This is quite a large patch,
and I think it would be useful to split it at least into two parts:
 (1) add the new device model
 (2) change the allwinner SoC to create that new device

> diff --git a/docs/system/arm/cubieboard.rst b/docs/system/arm/cubieboard.rst
> index 344ff8cef9..7836643ba4 100644
> --- a/docs/system/arm/cubieboard.rst
> +++ b/docs/system/arm/cubieboard.rst
> @@ -14,3 +14,4 @@ Emulated devices:
>  - SDHCI
>  - USB controller
>  - SATA controller
> +- crypto
> diff --git a/docs/system/devices/allwinner-sun4i-ss.rst 
> b/docs/system/devices/allwinner-sun4i-ss.rst
> new file mode 100644
> index 00..6e7d2142b5
> --- /dev/null
> +++ b/docs/system/devices/allwinner-sun4i-ss.rst
> @@ -0,0 +1,31 @@
> +Allwinner sun4i-ss
> +==

If you create a new rst file in docs, you need to put it into the
manual by adding it to some table of contents. Otherwise sphinx
will complain when you build the documentation, and users won't be
able to find it. (If you pass 'configure' the --enable-docs option
that will check that you have everything installed to be able to
build the docs.)

There are two options here: you can have this document, and
add it to the toctree in docs/system/device-emulation.rst, and
make the "crypto" bullet point in cubieboard.rst be a hyperlink to
the device-emulation.rst file. Or you can compress the information
down and put it into orangepi.rst.

> +The ``sun4i-ss`` emulates the Allwinner cryptographic offloader
> +present on early Allwinner SoCs (A10, A10s, A13, A20, A33)
> +In qemu only A10 via the cubieboard machine is supported.
> +
> +The emulated hardware is capable of handling the following algorithms:
> +- SHA1 and MD5 hash algorithms
> +- AES/DES/DES3 in CBC/ECB
> +- PRNG
> +
> +The emulated hardware does not handle yet:
> +- CTS for AES
> +- CTR for AES/DES/DES3
> +- IRQ and DMA mode
> +Anyway the Linux driver also does not handle them yet.
> +
> +The emulation needs a real crypto backend, for the moment only gnutls/nettle 
> is supported.
> +So the device emulation needs qemu to be compiled with optionnal gnutls.

> diff --git a/hw/Kconfig b/hw/Kconfig
> index ad20cce0a9..43bd7fc14d 100644
> --- a/hw/Kconfig
> +++ b/hw/Kconfig
> @@ -6,6 +6,7 @@ source audio/Kconfig
>  source block/Kconfig
>  source char/Kconfig
>  source core/Kconfig
> +source crypto/Kconfig
>  source display/Kconfig
>  source dma/Kconfig
>  source gpio/Kconfig

I don't think we really need a new subdirectory of hw/
for a single device. If you can find two other devices that
already exist in QEMU that would also belong in hw/crypto/
then we can create it. Otherwise just put this device in
hw/misc.

> diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
> index 97f3b38019..fd8232b1d4 100644
> --- a/hw/arm/Kconfig
> +++ b/hw/arm/Kconfig
> @@ -317,6 +317,7 @@ config ALLWINNER_A10
>  select AHCI
>  select ALLWINNER_A10_PIT
>  select ALLWINNER_A10_PIC
> +select ALLWINNER_CRYPTO_SUN4I_SS
>  select ALLWINNER_EMAC
>  select SERIAL
>  select UNIMP
> diff --git a/hw/arm/allwinner-a10.c b/hw/arm/allwinner-a10.c
> index 05e84728cb..e9104ee028 100644
> --- a/hw/arm/allwinner-a10.c
> +++ b/hw/arm/allwinner-a10.c
> @@ -23,6 +23,7 @@
>  #include "hw/misc/unimp.h"
>  #include "sysemu/sysemu.h"
>  #include "hw/boards.h"
> +#include "hw/crypto/allwinner-sun4i-ss.h"
>  #include "hw/usb/hcd-ohci.h"
>
>  #define AW_A10_MMC0_BASE0x01c0f000
> @@ -32,6 +33,7 @@
>  #define AW_A10_EMAC_BASE0x01c0b000
>  #define AW_A10_EHCI_BASE0x01c14000
>  #define AW_A10_OHCI_BASE0x01c14400
> +#define AW_A10_CRYPTO_BASE  0x01c15000
>  #define AW_A10_SATA_BASE0x01c18000
>  #define AW_A10_RTC_BASE 0x01c20d00
>
> @@ -48,6 +50,10 @@ static void aw_a10_init(Object *obj)
>
>  object_initialize_child(obj, "emac", &s->emac, TYPE_AW_EMAC);
>
> +#if defined CONFIG_NETTLE
> +object_initialize_child(obj, "crypto", &s->crypto, TYPE_AW_SUN4I_SS);
> +#endif

Don't put this kind of ifdef into device/SoC code, please.
The device emulation needs to work regardless of what
the specific crypto backends that got compiled into QEMU are.

> +#include 
> +#include 
> +#include 
> +#include 
> +#include 

Similarly, don't directly include nettle headers. The device needs
to use the backend-agnostic headers from include/crypto. To the
extent that they aren't sufficient to implement this device we
can look at enhancing them.

> +static const VMStateDescription vmstate_allwinner_sun4i_ss = 

Re: [RFC PATCH] tests/qtest: pass stdout/stderr down to subtests

2022-04-21 Thread Stefan Hajnoczi
On Thu, Apr 14, 2022 at 07:25:54PM +0200, Eric Auger wrote:
> Hi Alex,
> 
> On 4/7/22 5:00 PM, Alex Bennée wrote:
> > When trying to work out what the virtio-net-tests where doing it was
> > hard because the g_test_trap_subprocess redirects all output to
> > /dev/null. Lift this restriction by using the appropriate flags so you
> > can see something similar to what the vhost-user-blk tests show when
> > running.
> > 
> > While we are at it remove the g_test_verbose() check so we always show
> > how the QEMU is run.
> > 
> > Signed-off-by: Alex Bennée 
> > ---
> >  tests/qtest/qos-test.c | 7 +++
> >  1 file changed, 3 insertions(+), 4 deletions(-)
> > 
> > diff --git a/tests/qtest/qos-test.c b/tests/qtest/qos-test.c
> > index f97d0a08fd..c6c196cc95 100644
> > --- a/tests/qtest/qos-test.c
> > +++ b/tests/qtest/qos-test.c
> > @@ -89,9 +89,7 @@ static void qos_set_machines_devices_available(void)
> >  
> >  static void restart_qemu_or_continue(char *path)
> >  {
> > -if (g_test_verbose()) {
> > -qos_printf("Run QEMU with: '%s'\n", path);
> > -}
> > +qos_printf("Run QEMU with: '%s'\n", path);
> >  /* compares the current command line with the
> >   * one previously executed: if they are the same,
> >   * don't restart QEMU, if they differ, stop previous
> > @@ -185,7 +183,8 @@ static void run_one_test(const void *arg)
> >  static void subprocess_run_one_test(const void *arg)
> >  {
> >  const gchar *path = arg;
> > -g_test_trap_subprocess(path, 0, 0);
> > +g_test_trap_subprocess(path, 0,
> > +   G_TEST_SUBPROCESS_INHERIT_STDOUT | 
> > G_TEST_SUBPROCESS_INHERIT_STDERR);
> While workling on libqos/pci tests on aarch64 I also did that but I
> noticed there were a bunch of errors such as:
> 
> /aarch64/virt/generic-pcihost/pci-bus-generic/pci-bus/virtio-net-pci/virtio-net/virtio-net-tests/vhost-user/multiqueue:
> qemu-system-aarch64: Failed to set msg fds.
> qemu-system-aarch64: vhost VQ 0 ring restore failed: -22: Invalid
> argument (22)
> qemu-system-aarch64: Failed to set msg fds.
> qemu-system-aarch64: vhost VQ 1 ring restore failed: -22: Invalid
> argument (22)
> qemu-system-aarch64: Failed to set msg fds.
> qemu-system-aarch64: vhost VQ 2 ring restore failed: -22: Invalid
> argument (22)
> qemu-system-aarch64: Failed to set msg fds.
> qemu-system-aarch64: vhost VQ 3 ring restore failed: -22: Invalid
> argument (22)
> 
> I see those also when running with x86_64-softmmu/qemu-system-x86_64
> (this is no aarch64 specific).
> 
> I don't know if it is an issue to get those additional errors?

I see the same errors on
/x86_64/pc/i440FX-pcihost/pci-bus-pc/pci-bus/virtio-net-pci/virtio-net/virtio-net-tests/vhost-user/.

On the other hand, "make check" is happy (and silent) when run on the
command-line.

If the CI enables more verbose output then these messages might be
diffed and interpreted as failures, but I didn't check the CI scripts.

As long as GitLab CI is happy I think it's okay to merge this patch, but
it would be interesting to investigate the reason for these messages.

Stefan


signature.asc
Description: PGP signature


[PULL 00/13] Dump patches

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

The following changes since commit 9c125d17e9402c232c46610802e5931b3639d77b:

  Merge tag 'pull-tcg-20220420' of https://gitlab.com/rth7680/qemu into staging 
(2022-04-20 16:43:11 -0700)

are available in the Git repository at:

  g...@gitlab.com:marcandre.lureau/qemu.git tags/dump-pull-request

for you to fetch changes up to 6df5f4c69ac5143e5f468123e6336c46da164bce:

  dump/win_dump: add 32-bit guest Windows support (2022-04-21 16:43:06 +0400)


dump queue

Hi

The "dump" queue, with:
- [PATCH v3/v4 0/9] dump: Cleanup and consolidation
- [PATCH v4 0/4] dump: add 32-bit guest Windows support



Janosch Frank (9):
  dump: Use ERRP_GUARD()
  dump: Remove the sh_info variable
  dump: Introduce shdr_num to decrease complexity
  dump: Remove the section if when calculating the memory offset
  dump: Add more offset variables
  dump: Introduce dump_is_64bit() helper function
  dump: Consolidate phdr note writes
  dump: Cleanup dump_begin write functions
  dump: Consolidate elf note function

Viktor Prutyanov (4):
  include/qemu: rename Windows context definitions to expose bitness
  dump/win_dump: add helper macros for Windows dump header access
  include/qemu: add 32-bit Windows dump structures
  dump/win_dump: add 32-bit guest Windows support

 include/qemu/win_dump_defs.h | 115 ++-
 include/sysemu/dump.h|   9 +-
 contrib/elf2dmp/main.c   |   6 +-
 dump/dump.c  | 372 ---
 dump/win_dump.c  | 299 ++--
 hmp-commands.hx  |   2 +-
 6 files changed, 478 insertions(+), 325 deletions(-)

-- 
2.35.1.693.g805e0a68082a




[PULL 11/13] dump/win_dump: add helper macros for Windows dump header access

2022-04-21 Thread marcandre . lureau
From: Viktor Prutyanov 

Perform read access to Windows dump header fields via helper macros.
This is preparation for the next 32-bit guest Windows dump support.

Signed-off-by: Viktor Prutyanov 
Reviewed-by: Marc-André Lureau 
Message-Id: <20220406171558.199263-3-viktor.prutya...@redhat.com>
---
 dump/win_dump.c | 100 +++-
 1 file changed, 65 insertions(+), 35 deletions(-)

diff --git a/dump/win_dump.c b/dump/win_dump.c
index e9215e4fd5e5..d733918038b2 100644
--- a/dump/win_dump.c
+++ b/dump/win_dump.c
@@ -23,11 +23,25 @@
 #include "hw/misc/vmcoreinfo.h"
 #include "win_dump.h"
 
-static size_t write_run(WinDumpPhyMemRun64 *run, int fd, Error **errp)
+#define WIN_DUMP_PTR_SIZE sizeof(uint64_t)
+
+#define _WIN_DUMP_FIELD(f) (h->f)
+#define WIN_DUMP_FIELD(field) _WIN_DUMP_FIELD(field)
+
+#define _WIN_DUMP_FIELD_PTR(f) ((void *)&h->f)
+#define WIN_DUMP_FIELD_PTR(field) _WIN_DUMP_FIELD_PTR(field)
+
+#define _WIN_DUMP_FIELD_SIZE(f) sizeof(h->f)
+#define WIN_DUMP_FIELD_SIZE(field) _WIN_DUMP_FIELD_SIZE(field)
+
+#define WIN_DUMP_CTX_SIZE sizeof(WinContext64)
+
+static size_t write_run(uint64_t base_page, uint64_t page_count,
+int fd, Error **errp)
 {
 void *buf;
-uint64_t addr = run->BasePage << TARGET_PAGE_BITS;
-uint64_t size = run->PageCount << TARGET_PAGE_BITS;
+uint64_t addr = base_page << TARGET_PAGE_BITS;
+uint64_t size = page_count << TARGET_PAGE_BITS;
 uint64_t len, l;
 size_t total = 0;
 
@@ -58,13 +72,14 @@ static size_t write_run(WinDumpPhyMemRun64 *run, int fd, 
Error **errp)
 
 static void write_runs(DumpState *s, WinDumpHeader64 *h, Error **errp)
 {
-WinDumpPhyMemDesc64 *desc = &h->PhysicalMemoryBlock;
-WinDumpPhyMemRun64 *run = desc->Run;
+uint64_t BasePage, PageCount;
 Error *local_err = NULL;
 int i;
 
-for (i = 0; i < desc->NumberOfRuns; i++) {
-s->written_size += write_run(run + i, s->fd, &local_err);
+for (i = 0; i < WIN_DUMP_FIELD(PhysicalMemoryBlock.NumberOfRuns); i++) {
+BasePage = WIN_DUMP_FIELD(PhysicalMemoryBlock.Run[i].BasePage);
+PageCount = WIN_DUMP_FIELD(PhysicalMemoryBlock.Run[i].PageCount);
+s->written_size += write_run(BasePage, PageCount, s->fd, &local_err);
 if (local_err) {
 error_propagate(errp, local_err);
 return;
@@ -72,11 +87,24 @@ static void write_runs(DumpState *s, WinDumpHeader64 *h, 
Error **errp)
 }
 }
 
+static int cpu_read_ptr(CPUState *cpu, uint64_t addr, uint64_t *ptr)
+{
+int ret;
+uint64_t ptr64;
+
+ret = cpu_memory_rw_debug(cpu, addr, &ptr64, WIN_DUMP_PTR_SIZE, 0);
+
+*ptr = ptr64;
+
+return ret;
+}
+
 static void patch_mm_pfn_database(WinDumpHeader64 *h, Error **errp)
 {
 if (cpu_memory_rw_debug(first_cpu,
-h->KdDebuggerDataBlock + KDBG_MM_PFN_DATABASE_OFFSET64,
-(uint8_t *)&h->PfnDatabase, sizeof(h->PfnDatabase), 0)) {
+WIN_DUMP_FIELD(KdDebuggerDataBlock) + 
KDBG_MM_PFN_DATABASE_OFFSET64,
+WIN_DUMP_FIELD_PTR(PfnDatabase),
+WIN_DUMP_FIELD_SIZE(PfnDatabase), 0)) {
 error_setg(errp, "win-dump: failed to read MmPfnDatabase");
 return;
 }
@@ -86,16 +114,17 @@ static void patch_bugcheck_data(WinDumpHeader64 *h, Error 
**errp)
 {
 uint64_t KiBugcheckData;
 
-if (cpu_memory_rw_debug(first_cpu,
-h->KdDebuggerDataBlock + KDBG_KI_BUGCHECK_DATA_OFFSET64,
-(uint8_t *)&KiBugcheckData, sizeof(KiBugcheckData), 0)) {
+if (cpu_read_ptr(first_cpu,
+WIN_DUMP_FIELD(KdDebuggerDataBlock) +
+KDBG_KI_BUGCHECK_DATA_OFFSET64,
+&KiBugcheckData)) {
 error_setg(errp, "win-dump: failed to read KiBugcheckData");
 return;
 }
 
-if (cpu_memory_rw_debug(first_cpu,
-KiBugcheckData,
-h->BugcheckData, sizeof(h->BugcheckData), 0)) {
+if (cpu_memory_rw_debug(first_cpu, KiBugcheckData,
+WIN_DUMP_FIELD(BugcheckData),
+WIN_DUMP_FIELD_SIZE(BugcheckData), 0)) {
 error_setg(errp, "win-dump: failed to read bugcheck data");
 return;
 }
@@ -104,8 +133,8 @@ static void patch_bugcheck_data(WinDumpHeader64 *h, Error 
**errp)
  * If BugcheckCode wasn't saved, we consider guest OS as alive.
  */
 
-if (!h->BugcheckCode) {
-h->BugcheckCode = LIVE_SYSTEM_DUMP;
+if (!WIN_DUMP_FIELD(BugcheckCode)) {
+*(uint32_t *)WIN_DUMP_FIELD_PTR(BugcheckCode) = LIVE_SYSTEM_DUMP;
 }
 }
 
@@ -154,7 +183,7 @@ static void check_kdbg(WinDumpHeader64 *h, Error **errp)
 {
 const char OwnerTag[] = "KDBG";
 char read_OwnerTag[4];
-uint64_t KdDebuggerDataBlock = h->KdDebuggerDataBlock;
+uint64_t KdDebuggerDataBlock = WIN_DUMP_FIELD(KdDebuggerDataBlock);
 bool try_fallback = true;
 
 try_again:
@@ -173,7 +202,7 @@ try_again:
  * we try to use KDBG obtained by guest driver.
  */
 
-KdDebuggerDataBlock = h-

[PULL 01/13] dump: Use ERRP_GUARD()

2022-04-21 Thread marcandre . lureau
From: Janosch Frank 

Let's move to the new way of handling errors before changing the dump
code. This patch has mostly been generated by the coccinelle script
scripts/coccinelle/errp-guard.cocci.

Signed-off-by: Janosch Frank 
Reviewed-by: Richard Henderson 
Reviewed-by: Marc-André Lureau 
Message-Id: <20220330123603.107120-2-fran...@linux.ibm.com>
---
 dump/dump.c | 144 ++--
 1 file changed, 61 insertions(+), 83 deletions(-)

diff --git a/dump/dump.c b/dump/dump.c
index e766ce1d7d91..b91e9d8c123e 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -389,23 +389,21 @@ static void write_data(DumpState *s, void *buf, int 
length, Error **errp)
 static void write_memory(DumpState *s, GuestPhysBlock *block, ram_addr_t start,
  int64_t size, Error **errp)
 {
+ERRP_GUARD();
 int64_t i;
-Error *local_err = NULL;
 
 for (i = 0; i < size / s->dump_info.page_size; i++) {
 write_data(s, block->host_addr + start + i * s->dump_info.page_size,
-   s->dump_info.page_size, &local_err);
-if (local_err) {
-error_propagate(errp, local_err);
+   s->dump_info.page_size, errp);
+if (*errp) {
 return;
 }
 }
 
 if ((size % s->dump_info.page_size) != 0) {
 write_data(s, block->host_addr + start + i * s->dump_info.page_size,
-   size % s->dump_info.page_size, &local_err);
-if (local_err) {
-error_propagate(errp, local_err);
+   size % s->dump_info.page_size, errp);
+if (*errp) {
 return;
 }
 }
@@ -475,11 +473,11 @@ static void get_offset_range(hwaddr phys_addr,
 
 static void write_elf_loads(DumpState *s, Error **errp)
 {
+ERRP_GUARD();
 hwaddr offset, filesz;
 MemoryMapping *memory_mapping;
 uint32_t phdr_index = 1;
 uint32_t max_index;
-Error *local_err = NULL;
 
 if (s->have_section) {
 max_index = s->sh_info;
@@ -493,14 +491,13 @@ static void write_elf_loads(DumpState *s, Error **errp)
  s, &offset, &filesz);
 if (s->dump_info.d_class == ELFCLASS64) {
 write_elf64_load(s, memory_mapping, phdr_index++, offset,
- filesz, &local_err);
+ filesz, errp);
 } else {
 write_elf32_load(s, memory_mapping, phdr_index++, offset,
- filesz, &local_err);
+ filesz, errp);
 }
 
-if (local_err) {
-error_propagate(errp, local_err);
+if (*errp) {
 return;
 }
 
@@ -513,7 +510,7 @@ static void write_elf_loads(DumpState *s, Error **errp)
 /* write elf header, PT_NOTE and elf note to vmcore. */
 static void dump_begin(DumpState *s, Error **errp)
 {
-Error *local_err = NULL;
+ERRP_GUARD();
 
 /*
  * the vmcore's format is:
@@ -541,73 +538,64 @@ static void dump_begin(DumpState *s, Error **errp)
 
 /* write elf header to vmcore */
 if (s->dump_info.d_class == ELFCLASS64) {
-write_elf64_header(s, &local_err);
+write_elf64_header(s, errp);
 } else {
-write_elf32_header(s, &local_err);
+write_elf32_header(s, errp);
 }
-if (local_err) {
-error_propagate(errp, local_err);
+if (*errp) {
 return;
 }
 
 if (s->dump_info.d_class == ELFCLASS64) {
 /* write PT_NOTE to vmcore */
-write_elf64_note(s, &local_err);
-if (local_err) {
-error_propagate(errp, local_err);
+write_elf64_note(s, errp);
+if (*errp) {
 return;
 }
 
 /* write all PT_LOAD to vmcore */
-write_elf_loads(s, &local_err);
-if (local_err) {
-error_propagate(errp, local_err);
+write_elf_loads(s, errp);
+if (*errp) {
 return;
 }
 
 /* write section to vmcore */
 if (s->have_section) {
-write_elf_section(s, 1, &local_err);
-if (local_err) {
-error_propagate(errp, local_err);
+write_elf_section(s, 1, errp);
+if (*errp) {
 return;
 }
 }
 
 /* write notes to vmcore */
-write_elf64_notes(fd_write_vmcore, s, &local_err);
-if (local_err) {
-error_propagate(errp, local_err);
+write_elf64_notes(fd_write_vmcore, s, errp);
+if (*errp) {
 return;
 }
 } else {
 /* write PT_NOTE to vmcore */
-write_elf32_note(s, &local_err);
-if (local_err) {
-error_propagate(errp, local_err);
+write_elf32_note(s, errp);
+if (*errp) {
 return;
 }
 
 /* write all PT_LOAD to vmcore */
-write_elf_loads(s, &local_err);
-if (local_err) {
-error_propagate(errp, local_err);
+wr

[PULL 07/13] dump: Consolidate phdr note writes

2022-04-21 Thread marcandre . lureau
From: Janosch Frank 

There's no need to have two write functions. Let's rather have two
functions that set the data for elf 32/64 and then write it in a
common function.

Signed-off-by: Janosch Frank 
Reviewed-by: Richard Henderson 
Reviewed-by: Marc-André Lureau 
Message-Id: <20220330123603.107120-8-fran...@linux.ibm.com>
---
 dump/dump.c | 94 +++--
 1 file changed, 48 insertions(+), 46 deletions(-)

diff --git a/dump/dump.c b/dump/dump.c
index b063db134021..0d95fc5b7a3c 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -245,24 +245,15 @@ static void write_elf32_load(DumpState *s, MemoryMapping 
*memory_mapping,
 }
 }
 
-static void write_elf64_note(DumpState *s, Error **errp)
+static void write_elf64_phdr_note(DumpState *s, Elf64_Phdr *phdr)
 {
-Elf64_Phdr phdr;
-int ret;
-
-memset(&phdr, 0, sizeof(Elf64_Phdr));
-phdr.p_type = cpu_to_dump32(s, PT_NOTE);
-phdr.p_offset = cpu_to_dump64(s, s->note_offset);
-phdr.p_paddr = 0;
-phdr.p_filesz = cpu_to_dump64(s, s->note_size);
-phdr.p_memsz = cpu_to_dump64(s, s->note_size);
-phdr.p_vaddr = 0;
-
-ret = fd_write_vmcore(&phdr, sizeof(Elf64_Phdr), s);
-if (ret < 0) {
-error_setg_errno(errp, -ret,
- "dump: failed to write program header table");
-}
+memset(phdr, 0, sizeof(*phdr));
+phdr->p_type = cpu_to_dump32(s, PT_NOTE);
+phdr->p_offset = cpu_to_dump64(s, s->note_offset);
+phdr->p_paddr = 0;
+phdr->p_filesz = cpu_to_dump64(s, s->note_size);
+phdr->p_memsz = cpu_to_dump64(s, s->note_size);
+phdr->p_vaddr = 0;
 }
 
 static inline int cpu_index(CPUState *cpu)
@@ -310,24 +301,15 @@ static void write_elf64_notes(WriteCoreDumpFunction f, 
DumpState *s,
 write_guest_note(f, s, errp);
 }
 
-static void write_elf32_note(DumpState *s, Error **errp)
+static void write_elf32_phdr_note(DumpState *s, Elf32_Phdr *phdr)
 {
-Elf32_Phdr phdr;
-int ret;
-
-memset(&phdr, 0, sizeof(Elf32_Phdr));
-phdr.p_type = cpu_to_dump32(s, PT_NOTE);
-phdr.p_offset = cpu_to_dump32(s, s->note_offset);
-phdr.p_paddr = 0;
-phdr.p_filesz = cpu_to_dump32(s, s->note_size);
-phdr.p_memsz = cpu_to_dump32(s, s->note_size);
-phdr.p_vaddr = 0;
-
-ret = fd_write_vmcore(&phdr, sizeof(Elf32_Phdr), s);
-if (ret < 0) {
-error_setg_errno(errp, -ret,
- "dump: failed to write program header table");
-}
+memset(phdr, 0, sizeof(*phdr));
+phdr->p_type = cpu_to_dump32(s, PT_NOTE);
+phdr->p_offset = cpu_to_dump32(s, s->note_offset);
+phdr->p_paddr = 0;
+phdr->p_filesz = cpu_to_dump32(s, s->note_size);
+phdr->p_memsz = cpu_to_dump32(s, s->note_size);
+phdr->p_vaddr = 0;
 }
 
 static void write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,
@@ -357,6 +339,32 @@ static void write_elf32_notes(WriteCoreDumpFunction f, 
DumpState *s,
 write_guest_note(f, s, errp);
 }
 
+static void write_elf_phdr_note(DumpState *s, Error **errp)
+{
+ERRP_GUARD();
+Elf32_Phdr phdr32;
+Elf64_Phdr phdr64;
+void *phdr;
+size_t size;
+int ret;
+
+if (dump_is_64bit(s)) {
+write_elf64_phdr_note(s, &phdr64);
+size = sizeof(phdr64);
+phdr = &phdr64;
+} else {
+write_elf32_phdr_note(s, &phdr32);
+size = sizeof(phdr32);
+phdr = &phdr32;
+}
+
+ret = fd_write_vmcore(phdr, size, s);
+if (ret < 0) {
+error_setg_errno(errp, -ret,
+ "dump: failed to write program header table");
+}
+}
+
 static void write_elf_section(DumpState *s, int type, Error **errp)
 {
 Elf32_Shdr shdr32;
@@ -550,13 +558,13 @@ static void dump_begin(DumpState *s, Error **errp)
 return;
 }
 
-if (dump_is_64bit(s)) {
-/* write PT_NOTE to vmcore */
-write_elf64_note(s, errp);
-if (*errp) {
-return;
-}
+/* write PT_NOTE to vmcore */
+write_elf_phdr_note(s, errp);
+if (*errp) {
+return;
+}
 
+if (dump_is_64bit(s)) {
 /* write all PT_LOAD to vmcore */
 write_elf_loads(s, errp);
 if (*errp) {
@@ -577,12 +585,6 @@ static void dump_begin(DumpState *s, Error **errp)
 return;
 }
 } else {
-/* write PT_NOTE to vmcore */
-write_elf32_note(s, errp);
-if (*errp) {
-return;
-}
-
 /* write all PT_LOAD to vmcore */
 write_elf_loads(s, errp);
 if (*errp) {
-- 
2.35.1.693.g805e0a68082a




[PULL 03/13] dump: Introduce shdr_num to decrease complexity

2022-04-21 Thread marcandre . lureau
From: Janosch Frank 

Let's move from a boolean to a int variable which will later enable us
to store the number of sections that are in the dump file.

Signed-off-by: Janosch Frank 
Reviewed-by: Richard Henderson 
Reviewed-by: Marc-André Lureau 
Message-Id: <20220330123603.107120-4-fran...@linux.ibm.com>
---
 include/sysemu/dump.h |  2 +-
 dump/dump.c   | 24 
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
index b463fc9c0226..19458bffbd1d 100644
--- a/include/sysemu/dump.h
+++ b/include/sysemu/dump.h
@@ -155,7 +155,7 @@ typedef struct DumpState {
 ArchDumpInfo dump_info;
 MemoryMappingList list;
 uint32_t phdr_num;
-bool have_section;
+uint32_t shdr_num;
 bool resume;
 bool detached;
 ssize_t note_size;
diff --git a/dump/dump.c b/dump/dump.c
index 010b272da038..285ed4475b0d 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -144,12 +144,12 @@ static void write_elf64_header(DumpState *s, Error **errp)
 elf_header.e_phoff = cpu_to_dump64(s, sizeof(Elf64_Ehdr));
 elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf64_Phdr));
 elf_header.e_phnum = cpu_to_dump16(s, phnum);
-if (s->have_section) {
+if (s->shdr_num) {
 uint64_t shoff = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->phdr_num;
 
 elf_header.e_shoff = cpu_to_dump64(s, shoff);
 elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf64_Shdr));
-elf_header.e_shnum = cpu_to_dump16(s, 1);
+elf_header.e_shnum = cpu_to_dump16(s, s->shdr_num);
 }
 
 ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
@@ -181,12 +181,12 @@ static void write_elf32_header(DumpState *s, Error **errp)
 elf_header.e_phoff = cpu_to_dump32(s, sizeof(Elf32_Ehdr));
 elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf32_Phdr));
 elf_header.e_phnum = cpu_to_dump16(s, phnum);
-if (s->have_section) {
+if (s->shdr_num) {
 uint32_t shoff = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->phdr_num;
 
 elf_header.e_shoff = cpu_to_dump32(s, shoff);
 elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf32_Shdr));
-elf_header.e_shnum = cpu_to_dump16(s, 1);
+elf_header.e_shnum = cpu_to_dump16(s, s->shdr_num);
 }
 
 ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
@@ -565,7 +565,7 @@ static void dump_begin(DumpState *s, Error **errp)
 }
 
 /* write section to vmcore */
-if (s->have_section) {
+if (s->shdr_num) {
 write_elf_section(s, 1, errp);
 if (*errp) {
 return;
@@ -591,7 +591,7 @@ static void dump_begin(DumpState *s, Error **errp)
 }
 
 /* write section to vmcore */
-if (s->have_section) {
+if (s->shdr_num) {
 write_elf_section(s, 0, errp);
 if (*errp) {
 return;
@@ -1802,11 +1802,11 @@ static void dump_init(DumpState *s, int fd, bool 
has_format,
  */
 s->phdr_num = 1; /* PT_NOTE */
 if (s->list.num < UINT16_MAX - 2) {
+s->shdr_num = 0;
 s->phdr_num += s->list.num;
-s->have_section = false;
 } else {
 /* sh_info of section 0 holds the real number of phdrs */
-s->have_section = true;
+s->shdr_num = 1;
 
 /* the type of shdr->sh_info is uint32_t, so we should avoid overflow 
*/
 if (s->list.num <= UINT32_MAX - 1) {
@@ -1817,19 +1817,19 @@ static void dump_init(DumpState *s, int fd, bool 
has_format,
 }
 
 if (s->dump_info.d_class == ELFCLASS64) {
-if (s->have_section) {
+if (s->shdr_num) {
 s->memory_offset = sizeof(Elf64_Ehdr) +
sizeof(Elf64_Phdr) * s->phdr_num +
-   sizeof(Elf64_Shdr) + s->note_size;
+   sizeof(Elf64_Shdr) * s->shdr_num + s->note_size;
 } else {
 s->memory_offset = sizeof(Elf64_Ehdr) +
sizeof(Elf64_Phdr) * s->phdr_num + s->note_size;
 }
 } else {
-if (s->have_section) {
+if (s->shdr_num) {
 s->memory_offset = sizeof(Elf32_Ehdr) +
sizeof(Elf32_Phdr) * s->phdr_num +
-   sizeof(Elf32_Shdr) + s->note_size;
+   sizeof(Elf32_Shdr) * s->shdr_num + s->note_size;
 } else {
 s->memory_offset = sizeof(Elf32_Ehdr) +
sizeof(Elf32_Phdr) * s->phdr_num + s->note_size;
-- 
2.35.1.693.g805e0a68082a




[PULL 09/13] dump: Consolidate elf note function

2022-04-21 Thread marcandre . lureau
From: Janosch Frank 

Just like with the other write functions let's move the 32/64 bit elf
handling to a function to improve readability.

Signed-off-by: Janosch Frank 
Reviewed-by: Marc-André Lureau 
Message-Id: <20220330123603.107120-10-fran...@linux.ibm.com>
---
 dump/dump.c | 18 +++---
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/dump/dump.c b/dump/dump.c
index 929ef953515c..4d9658ffa24f 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -519,6 +519,15 @@ static void write_elf_loads(DumpState *s, Error **errp)
 }
 }
 
+static void write_elf_notes(DumpState *s, Error **errp)
+{
+if (dump_is_64bit(s)) {
+write_elf64_notes(fd_write_vmcore, s, errp);
+} else {
+write_elf32_notes(fd_write_vmcore, s, errp);
+}
+}
+
 /* write elf header, PT_NOTE and elf note to vmcore. */
 static void dump_begin(DumpState *s, Error **errp)
 {
@@ -578,13 +587,8 @@ static void dump_begin(DumpState *s, Error **errp)
 }
 }
 
-if (dump_is_64bit(s)) {
-/* write notes to vmcore */
-write_elf64_notes(fd_write_vmcore, s, errp);
-} else {
-/* write notes to vmcore */
-write_elf32_notes(fd_write_vmcore, s, errp);
-}
+/* write notes to vmcore */
+write_elf_notes(s, errp);
 }
 
 static int get_next_block(DumpState *s, GuestPhysBlock *block)
-- 
2.35.1.693.g805e0a68082a




[PULL 02/13] dump: Remove the sh_info variable

2022-04-21 Thread marcandre . lureau
From: Janosch Frank 

There's no need to have phdr_num and sh_info at the same time. We can
make phdr_num 32 bit and set PN_XNUM when we write the header if
phdr_num >= PN_XNUM.

Signed-off-by: Janosch Frank 
Reviewed-by: Richard Henderson 
Reviewed-by: Marc-André Lureau 
Message-Id: <20220407094824.5074-1-fran...@linux.ibm.com>
---
 include/sysemu/dump.h |  3 +--
 dump/dump.c   | 44 +++
 2 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
index 250143cb5a71..b463fc9c0226 100644
--- a/include/sysemu/dump.h
+++ b/include/sysemu/dump.h
@@ -154,8 +154,7 @@ typedef struct DumpState {
 GuestPhysBlockList guest_phys_blocks;
 ArchDumpInfo dump_info;
 MemoryMappingList list;
-uint16_t phdr_num;
-uint32_t sh_info;
+uint32_t phdr_num;
 bool have_section;
 bool resume;
 bool detached;
diff --git a/dump/dump.c b/dump/dump.c
index b91e9d8c123e..010b272da038 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -123,6 +123,12 @@ static int fd_write_vmcore(const void *buf, size_t size, 
void *opaque)
 
 static void write_elf64_header(DumpState *s, Error **errp)
 {
+/*
+ * phnum in the elf header is 16 bit, if we have more segments we
+ * set phnum to PN_XNUM and write the real number of segments to a
+ * special section.
+ */
+uint16_t phnum = MIN(s->phdr_num, PN_XNUM);
 Elf64_Ehdr elf_header;
 int ret;
 
@@ -137,9 +143,9 @@ static void write_elf64_header(DumpState *s, Error **errp)
 elf_header.e_ehsize = cpu_to_dump16(s, sizeof(elf_header));
 elf_header.e_phoff = cpu_to_dump64(s, sizeof(Elf64_Ehdr));
 elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf64_Phdr));
-elf_header.e_phnum = cpu_to_dump16(s, s->phdr_num);
+elf_header.e_phnum = cpu_to_dump16(s, phnum);
 if (s->have_section) {
-uint64_t shoff = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->sh_info;
+uint64_t shoff = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->phdr_num;
 
 elf_header.e_shoff = cpu_to_dump64(s, shoff);
 elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf64_Shdr));
@@ -154,6 +160,12 @@ static void write_elf64_header(DumpState *s, Error **errp)
 
 static void write_elf32_header(DumpState *s, Error **errp)
 {
+/*
+ * phnum in the elf header is 16 bit, if we have more segments we
+ * set phnum to PN_XNUM and write the real number of segments to a
+ * special section.
+ */
+uint16_t phnum = MIN(s->phdr_num, PN_XNUM);
 Elf32_Ehdr elf_header;
 int ret;
 
@@ -168,9 +180,9 @@ static void write_elf32_header(DumpState *s, Error **errp)
 elf_header.e_ehsize = cpu_to_dump16(s, sizeof(elf_header));
 elf_header.e_phoff = cpu_to_dump32(s, sizeof(Elf32_Ehdr));
 elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf32_Phdr));
-elf_header.e_phnum = cpu_to_dump16(s, s->phdr_num);
+elf_header.e_phnum = cpu_to_dump16(s, phnum);
 if (s->have_section) {
-uint32_t shoff = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->sh_info;
+uint32_t shoff = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->phdr_num;
 
 elf_header.e_shoff = cpu_to_dump32(s, shoff);
 elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf32_Shdr));
@@ -357,12 +369,12 @@ static void write_elf_section(DumpState *s, int type, 
Error **errp)
 if (type == 0) {
 shdr_size = sizeof(Elf32_Shdr);
 memset(&shdr32, 0, shdr_size);
-shdr32.sh_info = cpu_to_dump32(s, s->sh_info);
+shdr32.sh_info = cpu_to_dump32(s, s->phdr_num);
 shdr = &shdr32;
 } else {
 shdr_size = sizeof(Elf64_Shdr);
 memset(&shdr64, 0, shdr_size);
-shdr64.sh_info = cpu_to_dump32(s, s->sh_info);
+shdr64.sh_info = cpu_to_dump32(s, s->phdr_num);
 shdr = &shdr64;
 }
 
@@ -477,13 +489,6 @@ static void write_elf_loads(DumpState *s, Error **errp)
 hwaddr offset, filesz;
 MemoryMapping *memory_mapping;
 uint32_t phdr_index = 1;
-uint32_t max_index;
-
-if (s->have_section) {
-max_index = s->sh_info;
-} else {
-max_index = s->phdr_num;
-}
 
 QTAILQ_FOREACH(memory_mapping, &s->list.head, next) {
 get_offset_range(memory_mapping->phys_addr,
@@ -501,7 +506,7 @@ static void write_elf_loads(DumpState *s, Error **errp)
 return;
 }
 
-if (phdr_index >= max_index) {
+if (phdr_index >= s->phdr_num) {
 break;
 }
 }
@@ -1800,22 +1805,21 @@ static void dump_init(DumpState *s, int fd, bool 
has_format,
 s->phdr_num += s->list.num;
 s->have_section = false;
 } else {
+/* sh_info of section 0 holds the real number of phdrs */
 s->have_section = true;
-s->phdr_num = PN_XNUM;
-s->sh_info = 1; /* PT_NOTE */
 
 /* the type of shdr->sh_info is uint32_t, so we should avoid overflow 
*/
 if (s->list.num <= UINT32

[PULL 12/13] include/qemu: add 32-bit Windows dump structures

2022-04-21 Thread marcandre . lureau
From: Viktor Prutyanov 

These structures are required to produce 32-bit guest Windows Complete
Memory Dump. Add 32-bit Windows dump header, CPU context and physical
memory descriptor structures along with corresponding definitions.

Signed-off-by: Viktor Prutyanov 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Marc-André Lureau 
Message-Id: <20220406171558.199263-4-viktor.prutya...@redhat.com>
---
 include/qemu/win_dump_defs.h | 107 +++
 1 file changed, 107 insertions(+)

diff --git a/include/qemu/win_dump_defs.h b/include/qemu/win_dump_defs.h
index 5a5e5a5e0989..73a44e2408c2 100644
--- a/include/qemu/win_dump_defs.h
+++ b/include/qemu/win_dump_defs.h
@@ -11,11 +11,22 @@
 #ifndef QEMU_WIN_DUMP_DEFS_H
 #define QEMU_WIN_DUMP_DEFS_H
 
+typedef struct WinDumpPhyMemRun32 {
+uint32_t BasePage;
+uint32_t PageCount;
+} QEMU_PACKED WinDumpPhyMemRun32;
+
 typedef struct WinDumpPhyMemRun64 {
 uint64_t BasePage;
 uint64_t PageCount;
 } QEMU_PACKED WinDumpPhyMemRun64;
 
+typedef struct WinDumpPhyMemDesc32 {
+uint32_t NumberOfRuns;
+uint32_t NumberOfPages;
+WinDumpPhyMemRun32 Run[86];
+} QEMU_PACKED WinDumpPhyMemDesc32;
+
 typedef struct WinDumpPhyMemDesc64 {
 uint32_t NumberOfRuns;
 uint32_t unused;
@@ -33,6 +44,39 @@ typedef struct WinDumpExceptionRecord {
 uint64_t ExceptionInformation[15];
 } QEMU_PACKED WinDumpExceptionRecord;
 
+typedef struct WinDumpHeader32 {
+char Signature[4];
+char ValidDump[4];
+uint32_t MajorVersion;
+uint32_t MinorVersion;
+uint32_t DirectoryTableBase;
+uint32_t PfnDatabase;
+uint32_t PsLoadedModuleList;
+uint32_t PsActiveProcessHead;
+uint32_t MachineImageType;
+uint32_t NumberProcessors;
+union {
+struct {
+uint32_t BugcheckCode;
+uint32_t BugcheckParameter1;
+uint32_t BugcheckParameter2;
+uint32_t BugcheckParameter3;
+uint32_t BugcheckParameter4;
+};
+uint8_t BugcheckData[20];
+};
+uint8_t VersionUser[32];
+uint32_t reserved0;
+uint32_t KdDebuggerDataBlock;
+union {
+WinDumpPhyMemDesc32 PhysicalMemoryBlock;
+uint8_t PhysicalMemoryBlockBuffer[700];
+};
+uint8_t reserved1[3200];
+uint32_t RequiredDumpSpace;
+uint8_t reserved2[92];
+} QEMU_PACKED WinDumpHeader32;
+
 typedef struct WinDumpHeader64 {
 char Signature[4];
 char ValidDump[4];
@@ -81,25 +125,49 @@ typedef struct WinDumpHeader64 {
 uint8_t reserved[4018];
 } QEMU_PACKED WinDumpHeader64;
 
+typedef union WinDumpHeader {
+struct {
+char Signature[4];
+char ValidDump[4];
+};
+WinDumpHeader32 x32;
+WinDumpHeader64 x64;
+} WinDumpHeader;
+
 #define KDBG_OWNER_TAG_OFFSET64 0x10
 #define KDBG_MM_PFN_DATABASE_OFFSET64   0xC0
 #define KDBG_KI_BUGCHECK_DATA_OFFSET64  0x88
 #define KDBG_KI_PROCESSOR_BLOCK_OFFSET640x218
 #define KDBG_OFFSET_PRCB_CONTEXT_OFFSET64   0x338
 
+#define KDBG_OWNER_TAG_OFFSET   KDBG_OWNER_TAG_OFFSET64
+#define KDBG_MM_PFN_DATABASE_OFFSET KDBG_MM_PFN_DATABASE_OFFSET64
+#define KDBG_KI_BUGCHECK_DATA_OFFSETKDBG_KI_BUGCHECK_DATA_OFFSET64
+#define KDBG_KI_PROCESSOR_BLOCK_OFFSET  KDBG_KI_PROCESSOR_BLOCK_OFFSET64
+#define KDBG_OFFSET_PRCB_CONTEXT_OFFSET KDBG_OFFSET_PRCB_CONTEXT_OFFSET64
+
 #define VMCOREINFO_ELF_NOTE_HDR_SIZE24
+#define VMCOREINFO_WIN_DUMP_NOTE_SIZE64 (sizeof(WinDumpHeader64) + \
+ VMCOREINFO_ELF_NOTE_HDR_SIZE)
+#define VMCOREINFO_WIN_DUMP_NOTE_SIZE32 (sizeof(WinDumpHeader32) + \
+ VMCOREINFO_ELF_NOTE_HDR_SIZE)
 
 #define WIN_CTX_X64 0x0010L
+#define WIN_CTX_X86 0x0001L
 
 #define WIN_CTX_CTL 0x0001L
 #define WIN_CTX_INT 0x0002L
 #define WIN_CTX_SEG 0x0004L
 #define WIN_CTX_FP  0x0008L
 #define WIN_CTX_DBG 0x0010L
+#define WIN_CTX_EXT 0x0020L
 
 #define WIN_CTX64_FULL  (WIN_CTX_X64 | WIN_CTX_CTL | WIN_CTX_INT | WIN_CTX_FP)
 #define WIN_CTX64_ALL   (WIN_CTX64_FULL | WIN_CTX_SEG | WIN_CTX_DBG)
 
+#define WIN_CTX32_FULL (WIN_CTX_X86 | WIN_CTX_CTL | WIN_CTX_INT | WIN_CTX_SEG)
+#define WIN_CTX32_ALL (WIN_CTX32_FULL | WIN_CTX_FP | WIN_CTX_DBG | WIN_CTX_EXT)
+
 #define LIVE_SYSTEM_DUMP0x0161
 
 typedef struct WinM128A {
@@ -107,6 +175,40 @@ typedef struct WinM128A {
 int64_t high;
 } QEMU_ALIGNED(16) WinM128A;
 
+typedef struct WinContext32 {
+uint32_t ContextFlags;
+
+uint32_t Dr0;
+uint32_t Dr1;
+uint32_t Dr2;
+uint32_t Dr3;
+uint32_t Dr6;
+uint32_t Dr7;
+
+uint8_t  FloatSave[112];
+
+uint32_t SegGs;
+uint32_t SegFs;
+uint32_t SegEs;
+uint32_t SegDs;
+
+uint32_t Edi;
+uint32_t Esi;
+uint32_t Ebx;
+uint32_t Edx;
+uint32_t Ecx;
+uint32_t Eax;
+
+uint32_t Ebp;
+uint32_t Eip;
+uint32_t SegCs;
+uint32_t EFlags;
+uint32_t Esp;
+uint32_t SegSs;
+
+uint8_t Ext

[PULL 10/13] include/qemu: rename Windows context definitions to expose bitness

2022-04-21 Thread marcandre . lureau
From: Viktor Prutyanov 

Context structure in 64-bit Windows differs from 32-bit one and it
should be reflected in its name.

Signed-off-by: Viktor Prutyanov 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Marc-André Lureau 
Message-Id: <20220406171558.199263-2-viktor.prutya...@redhat.com>
---
 include/qemu/win_dump_defs.h |  8 
 contrib/elf2dmp/main.c   |  6 +++---
 dump/win_dump.c  | 14 +++---
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/include/qemu/win_dump_defs.h b/include/qemu/win_dump_defs.h
index 145096e8ee79..5a5e5a5e0989 100644
--- a/include/qemu/win_dump_defs.h
+++ b/include/qemu/win_dump_defs.h
@@ -97,8 +97,8 @@ typedef struct WinDumpHeader64 {
 #define WIN_CTX_FP  0x0008L
 #define WIN_CTX_DBG 0x0010L
 
-#define WIN_CTX_FULL(WIN_CTX_X64 | WIN_CTX_CTL | WIN_CTX_INT | WIN_CTX_FP)
-#define WIN_CTX_ALL (WIN_CTX_FULL | WIN_CTX_SEG | WIN_CTX_DBG)
+#define WIN_CTX64_FULL  (WIN_CTX_X64 | WIN_CTX_CTL | WIN_CTX_INT | WIN_CTX_FP)
+#define WIN_CTX64_ALL   (WIN_CTX64_FULL | WIN_CTX_SEG | WIN_CTX_DBG)
 
 #define LIVE_SYSTEM_DUMP0x0161
 
@@ -107,7 +107,7 @@ typedef struct WinM128A {
 int64_t high;
 } QEMU_ALIGNED(16) WinM128A;
 
-typedef struct WinContext {
+typedef struct WinContext64 {
 uint64_t PHome[6];
 
 uint32_t ContextFlags;
@@ -174,6 +174,6 @@ typedef struct WinContext {
 uint64_t LastBranchFromRip;
 uint64_t LastExceptionToRip;
 uint64_t LastExceptionFromRip;
-} QEMU_ALIGNED(16) WinContext;
+} QEMU_ALIGNED(16) WinContext64;
 
 #endif /* QEMU_WIN_DUMP_DEFS_H */
diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c
index 20b477d582a4..b9fc6d230ca0 100644
--- a/contrib/elf2dmp/main.c
+++ b/contrib/elf2dmp/main.c
@@ -141,10 +141,10 @@ static KDDEBUGGER_DATA64 *get_kdbg(uint64_t KernBase, 
struct pdb_reader *pdb,
 return kdbg;
 }
 
-static void win_context_init_from_qemu_cpu_state(WinContext *ctx,
+static void win_context_init_from_qemu_cpu_state(WinContext64 *ctx,
 QEMUCPUState *s)
 {
-WinContext win_ctx = (WinContext){
+WinContext64 win_ctx = (WinContext64){
 .ContextFlags = WIN_CTX_X64 | WIN_CTX_INT | WIN_CTX_SEG | WIN_CTX_CTL,
 .MxCsr = INITIAL_MXCSR,
 
@@ -302,7 +302,7 @@ static int fill_context(KDDEBUGGER_DATA64 *kdbg,
 for (i = 0; i < qe->state_nr; i++) {
 uint64_t Prcb;
 uint64_t Context;
-WinContext ctx;
+WinContext64 ctx;
 QEMUCPUState *s = qe->state[i];
 
 if (va_space_rw(vs, kdbg->KiProcessorBlock + sizeof(Prcb) * i,
diff --git a/dump/win_dump.c b/dump/win_dump.c
index fbdbb7bd93a6..e9215e4fd5e5 100644
--- a/dump/win_dump.c
+++ b/dump/win_dump.c
@@ -188,7 +188,7 @@ try_again:
 }
 
 struct saved_context {
-WinContext ctx;
+WinContext64 ctx;
 uint64_t addr;
 };
 
@@ -220,7 +220,7 @@ static void patch_and_save_context(WinDumpHeader64 *h,
 CPUX86State *env = &x86_cpu->env;
 uint64_t Prcb;
 uint64_t Context;
-WinContext ctx;
+WinContext64 ctx;
 
 if (cpu_memory_rw_debug(first_cpu,
 KiProcessorBlock + i * sizeof(uint64_t),
@@ -240,8 +240,8 @@ static void patch_and_save_context(WinDumpHeader64 *h,
 
 saved_ctx[i].addr = Context;
 
-ctx = (WinContext){
-.ContextFlags = WIN_CTX_ALL,
+ctx = (WinContext64){
+.ContextFlags = WIN_CTX64_ALL,
 .MxCsr = env->mxcsr,
 
 .SegEs = env->segs[0].selector,
@@ -283,13 +283,13 @@ static void patch_and_save_context(WinDumpHeader64 *h,
 };
 
 if (cpu_memory_rw_debug(first_cpu, Context,
-(uint8_t *)&saved_ctx[i].ctx, sizeof(WinContext), 0)) {
+(uint8_t *)&saved_ctx[i].ctx, sizeof(WinContext64), 0)) {
 error_setg(errp, "win-dump: failed to save CPU #%d context", i);
 return;
 }
 
 if (cpu_memory_rw_debug(first_cpu, Context,
-(uint8_t *)&ctx, sizeof(WinContext), 1)) {
+(uint8_t *)&ctx, sizeof(WinContext64), 1)) {
 error_setg(errp, "win-dump: failed to write CPU #%d context", i);
 return;
 }
@@ -305,7 +305,7 @@ static void restore_context(WinDumpHeader64 *h,
 
 for (i = 0; i < h->NumberProcessors; i++) {
 if (cpu_memory_rw_debug(first_cpu, saved_ctx[i].addr,
-(uint8_t *)&saved_ctx[i].ctx, sizeof(WinContext), 1)) {
+(uint8_t *)&saved_ctx[i].ctx, sizeof(WinContext64), 1)) {
 warn_report("win-dump: failed to restore CPU #%d context", i);
 }
 }
-- 
2.35.1.693.g805e0a68082a




[PULL 04/13] dump: Remove the section if when calculating the memory offset

2022-04-21 Thread marcandre . lureau
From: Janosch Frank 

When s->shdr_num is 0 we'll add 0 bytes of section headers which is
equivalent to not adding section headers but with the multiplication
we can remove a if/else.

Signed-off-by: Janosch Frank 
Reviewed-by: Richard Henderson 
Reviewed-by: Marc-André Lureau 
Message-Id: <20220330123603.107120-5-fran...@linux.ibm.com>
---
 dump/dump.c | 24 
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/dump/dump.c b/dump/dump.c
index 285ed4475b0d..9c80680eb2a4 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -1817,23 +1817,15 @@ static void dump_init(DumpState *s, int fd, bool 
has_format,
 }
 
 if (s->dump_info.d_class == ELFCLASS64) {
-if (s->shdr_num) {
-s->memory_offset = sizeof(Elf64_Ehdr) +
-   sizeof(Elf64_Phdr) * s->phdr_num +
-   sizeof(Elf64_Shdr) * s->shdr_num + s->note_size;
-} else {
-s->memory_offset = sizeof(Elf64_Ehdr) +
-   sizeof(Elf64_Phdr) * s->phdr_num + s->note_size;
-}
+s->memory_offset = sizeof(Elf64_Ehdr) +
+   sizeof(Elf64_Phdr) * s->phdr_num +
+   sizeof(Elf64_Shdr) * s->shdr_num +
+   s->note_size;
 } else {
-if (s->shdr_num) {
-s->memory_offset = sizeof(Elf32_Ehdr) +
-   sizeof(Elf32_Phdr) * s->phdr_num +
-   sizeof(Elf32_Shdr) * s->shdr_num + s->note_size;
-} else {
-s->memory_offset = sizeof(Elf32_Ehdr) +
-   sizeof(Elf32_Phdr) * s->phdr_num + s->note_size;
-}
+s->memory_offset = sizeof(Elf32_Ehdr) +
+   sizeof(Elf32_Phdr) * s->phdr_num +
+   sizeof(Elf32_Shdr) * s->shdr_num +
+   s->note_size;
 }
 
 return;
-- 
2.35.1.693.g805e0a68082a




[PULL 05/13] dump: Add more offset variables

2022-04-21 Thread marcandre . lureau
From: Janosch Frank 

Offset calculations are easy enough to get wrong. Let's add a few
variables to make moving around elf headers and data sections easier.

Signed-off-by: Janosch Frank 
Reviewed-by: Marc-André Lureau 
Reviewed-by: Richard Henderson 
Message-Id: <20220330123603.107120-6-fran...@linux.ibm.com>
---
 include/sysemu/dump.h |  4 
 dump/dump.c   | 35 +++
 2 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
index 19458bffbd1d..ffc2ea1072f3 100644
--- a/include/sysemu/dump.h
+++ b/include/sysemu/dump.h
@@ -159,6 +159,10 @@ typedef struct DumpState {
 bool resume;
 bool detached;
 ssize_t note_size;
+hwaddr shdr_offset;
+hwaddr phdr_offset;
+hwaddr section_offset;
+hwaddr note_offset;
 hwaddr memory_offset;
 int fd;
 
diff --git a/dump/dump.c b/dump/dump.c
index 9c80680eb2a4..7f226257eec3 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -141,13 +141,11 @@ static void write_elf64_header(DumpState *s, Error **errp)
 elf_header.e_machine = cpu_to_dump16(s, s->dump_info.d_machine);
 elf_header.e_version = cpu_to_dump32(s, EV_CURRENT);
 elf_header.e_ehsize = cpu_to_dump16(s, sizeof(elf_header));
-elf_header.e_phoff = cpu_to_dump64(s, sizeof(Elf64_Ehdr));
+elf_header.e_phoff = cpu_to_dump64(s, s->phdr_offset);
 elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf64_Phdr));
 elf_header.e_phnum = cpu_to_dump16(s, phnum);
 if (s->shdr_num) {
-uint64_t shoff = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->phdr_num;
-
-elf_header.e_shoff = cpu_to_dump64(s, shoff);
+elf_header.e_shoff = cpu_to_dump64(s, s->shdr_offset);
 elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf64_Shdr));
 elf_header.e_shnum = cpu_to_dump16(s, s->shdr_num);
 }
@@ -178,13 +176,11 @@ static void write_elf32_header(DumpState *s, Error **errp)
 elf_header.e_machine = cpu_to_dump16(s, s->dump_info.d_machine);
 elf_header.e_version = cpu_to_dump32(s, EV_CURRENT);
 elf_header.e_ehsize = cpu_to_dump16(s, sizeof(elf_header));
-elf_header.e_phoff = cpu_to_dump32(s, sizeof(Elf32_Ehdr));
+elf_header.e_phoff = cpu_to_dump32(s, s->phdr_offset);
 elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf32_Phdr));
 elf_header.e_phnum = cpu_to_dump16(s, phnum);
 if (s->shdr_num) {
-uint32_t shoff = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->phdr_num;
-
-elf_header.e_shoff = cpu_to_dump32(s, shoff);
+elf_header.e_shoff = cpu_to_dump32(s, s->shdr_offset);
 elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf32_Shdr));
 elf_header.e_shnum = cpu_to_dump16(s, s->shdr_num);
 }
@@ -247,12 +243,11 @@ static void write_elf32_load(DumpState *s, MemoryMapping 
*memory_mapping,
 static void write_elf64_note(DumpState *s, Error **errp)
 {
 Elf64_Phdr phdr;
-hwaddr begin = s->memory_offset - s->note_size;
 int ret;
 
 memset(&phdr, 0, sizeof(Elf64_Phdr));
 phdr.p_type = cpu_to_dump32(s, PT_NOTE);
-phdr.p_offset = cpu_to_dump64(s, begin);
+phdr.p_offset = cpu_to_dump64(s, s->note_offset);
 phdr.p_paddr = 0;
 phdr.p_filesz = cpu_to_dump64(s, s->note_size);
 phdr.p_memsz = cpu_to_dump64(s, s->note_size);
@@ -312,13 +307,12 @@ static void write_elf64_notes(WriteCoreDumpFunction f, 
DumpState *s,
 
 static void write_elf32_note(DumpState *s, Error **errp)
 {
-hwaddr begin = s->memory_offset - s->note_size;
 Elf32_Phdr phdr;
 int ret;
 
 memset(&phdr, 0, sizeof(Elf32_Phdr));
 phdr.p_type = cpu_to_dump32(s, PT_NOTE);
-phdr.p_offset = cpu_to_dump32(s, begin);
+phdr.p_offset = cpu_to_dump32(s, s->note_offset);
 phdr.p_paddr = 0;
 phdr.p_filesz = cpu_to_dump32(s, s->note_size);
 phdr.p_memsz = cpu_to_dump32(s, s->note_size);
@@ -1817,15 +1811,16 @@ static void dump_init(DumpState *s, int fd, bool 
has_format,
 }
 
 if (s->dump_info.d_class == ELFCLASS64) {
-s->memory_offset = sizeof(Elf64_Ehdr) +
-   sizeof(Elf64_Phdr) * s->phdr_num +
-   sizeof(Elf64_Shdr) * s->shdr_num +
-   s->note_size;
+s->phdr_offset = sizeof(Elf64_Ehdr);
+s->shdr_offset = s->phdr_offset + sizeof(Elf64_Phdr) * s->phdr_num;
+s->note_offset = s->shdr_offset + sizeof(Elf64_Shdr) * s->shdr_num;
+s->memory_offset = s->note_offset + s->note_size;
 } else {
-s->memory_offset = sizeof(Elf32_Ehdr) +
-   sizeof(Elf32_Phdr) * s->phdr_num +
-   sizeof(Elf32_Shdr) * s->shdr_num +
-   s->note_size;
+
+s->phdr_offset = sizeof(Elf32_Ehdr);
+s->shdr_offset = s->phdr_offset + sizeof(Elf32_Phdr) * s->phdr_num;
+s->note_offset = s->shdr_offset + sizeof(Elf32_Shdr) * s->shdr_num;
+s->memory_offset = s->note_offset + s->note_size;

Re: Future of libslirp in QEMU

2022-04-21 Thread Cornelia Huck
On Wed, Apr 20 2022, "Anders Pitman"  wrote:

> Awesome, thanks.
>
> Apparently I'm not properly performing a date-sorted search on the list 
> archives. I started here:
>
> https://lists.gnu.org/archive/html/qemu-devel/
>
> Then entered "slirp" and searched with chronological order, but the latest 
> entry is from 2020. What am I doing wrong?

FWIW, I'd recommend searching the qemu-devel mailing via public inbox on
lore:

https://lore.kernel.org/qemu-devel/

[I got the same outdated results on the page you listed, no idea what is
wrong there.]




[PULL 06/13] dump: Introduce dump_is_64bit() helper function

2022-04-21 Thread marcandre . lureau
From: Janosch Frank 

Checking d_class in dump_info leads to lengthy conditionals so let's
shorten things a bit by introducing a helper function.

Signed-off-by: Janosch Frank 
Reviewed-by: Richard Henderson 
Reviewed-by: Marc-André Lureau 
Message-Id: <20220330123603.107120-7-fran...@linux.ibm.com>
---
 dump/dump.c | 25 +++--
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/dump/dump.c b/dump/dump.c
index 7f226257eec3..b063db134021 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -54,6 +54,11 @@ static Error *dump_migration_blocker;
   DIV_ROUND_UP((name_size), 4) +\
   DIV_ROUND_UP((desc_size), 4)) * 4)
 
+static inline bool dump_is_64bit(DumpState *s)
+{
+return s->dump_info.d_class == ELFCLASS64;
+}
+
 uint16_t cpu_to_dump16(DumpState *s, uint16_t val)
 {
 if (s->dump_info.d_endian == ELFDATA2LSB) {
@@ -488,7 +493,7 @@ static void write_elf_loads(DumpState *s, Error **errp)
 get_offset_range(memory_mapping->phys_addr,
  memory_mapping->length,
  s, &offset, &filesz);
-if (s->dump_info.d_class == ELFCLASS64) {
+if (dump_is_64bit(s)) {
 write_elf64_load(s, memory_mapping, phdr_index++, offset,
  filesz, errp);
 } else {
@@ -536,7 +541,7 @@ static void dump_begin(DumpState *s, Error **errp)
  */
 
 /* write elf header to vmcore */
-if (s->dump_info.d_class == ELFCLASS64) {
+if (dump_is_64bit(s)) {
 write_elf64_header(s, errp);
 } else {
 write_elf32_header(s, errp);
@@ -545,7 +550,7 @@ static void dump_begin(DumpState *s, Error **errp)
 return;
 }
 
-if (s->dump_info.d_class == ELFCLASS64) {
+if (dump_is_64bit(s)) {
 /* write PT_NOTE to vmcore */
 write_elf64_note(s, errp);
 if (*errp) {
@@ -756,7 +761,7 @@ static void get_note_sizes(DumpState *s, const void *note,
 uint64_t name_sz;
 uint64_t desc_sz;
 
-if (s->dump_info.d_class == ELFCLASS64) {
+if (dump_is_64bit(s)) {
 const Elf64_Nhdr *hdr = note;
 note_head_sz = sizeof(Elf64_Nhdr);
 name_sz = tswap64(hdr->n_namesz);
@@ -1016,10 +1021,10 @@ out:
 
 static void write_dump_header(DumpState *s, Error **errp)
 {
-if (s->dump_info.d_class == ELFCLASS32) {
-create_header32(s, errp);
-} else {
+if (dump_is_64bit(s)) {
 create_header64(s, errp);
+} else {
+create_header32(s, errp);
 }
 }
 
@@ -1706,8 +1711,8 @@ static void dump_init(DumpState *s, int fd, bool 
has_format,
 uint32_t size;
 uint16_t format;
 
-note_head_size = s->dump_info.d_class == ELFCLASS32 ?
-sizeof(Elf32_Nhdr) : sizeof(Elf64_Nhdr);
+note_head_size = dump_is_64bit(s) ?
+sizeof(Elf64_Nhdr) : sizeof(Elf32_Nhdr);
 
 format = le16_to_cpu(vmci->vmcoreinfo.guest_format);
 size = le32_to_cpu(vmci->vmcoreinfo.size);
@@ -1810,7 +1815,7 @@ static void dump_init(DumpState *s, int fd, bool 
has_format,
 }
 }
 
-if (s->dump_info.d_class == ELFCLASS64) {
+if (dump_is_64bit(s)) {
 s->phdr_offset = sizeof(Elf64_Ehdr);
 s->shdr_offset = s->phdr_offset + sizeof(Elf64_Phdr) * s->phdr_num;
 s->note_offset = s->shdr_offset + sizeof(Elf64_Shdr) * s->shdr_num;
-- 
2.35.1.693.g805e0a68082a




[PULL 08/13] dump: Cleanup dump_begin write functions

2022-04-21 Thread marcandre . lureau
From: Janosch Frank 

There's no need to have a gigantic if in there let's move the elf
32/64 bit logic into the section, segment or note code.

Signed-off-by: Janosch Frank 
Reviewed-by: Richard Henderson 
Reviewed-by: Marc-André Lureau 
Message-Id: <20220330123603.107120-9-fran...@linux.ibm.com>
---
 dump/dump.c | 42 +++---
 1 file changed, 11 insertions(+), 31 deletions(-)

diff --git a/dump/dump.c b/dump/dump.c
index 0d95fc5b7a3c..929ef953515c 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -564,46 +564,26 @@ static void dump_begin(DumpState *s, Error **errp)
 return;
 }
 
-if (dump_is_64bit(s)) {
-/* write all PT_LOAD to vmcore */
-write_elf_loads(s, errp);
+/* write all PT_LOAD to vmcore */
+write_elf_loads(s, errp);
+if (*errp) {
+return;
+}
+
+/* write section to vmcore */
+if (s->shdr_num) {
+write_elf_section(s, 1, errp);
 if (*errp) {
 return;
 }
+}
 
-/* write section to vmcore */
-if (s->shdr_num) {
-write_elf_section(s, 1, errp);
-if (*errp) {
-return;
-}
-}
-
+if (dump_is_64bit(s)) {
 /* write notes to vmcore */
 write_elf64_notes(fd_write_vmcore, s, errp);
-if (*errp) {
-return;
-}
 } else {
-/* write all PT_LOAD to vmcore */
-write_elf_loads(s, errp);
-if (*errp) {
-return;
-}
-
-/* write section to vmcore */
-if (s->shdr_num) {
-write_elf_section(s, 0, errp);
-if (*errp) {
-return;
-}
-}
-
 /* write notes to vmcore */
 write_elf32_notes(fd_write_vmcore, s, errp);
-if (*errp) {
-return;
-}
 }
 }
 
-- 
2.35.1.693.g805e0a68082a




Re: [PATCH 29/41] tests: run-time skip test-qga if TSAN is enabled

2022-04-21 Thread Marc-André Lureau
Hi

On Wed, Apr 20, 2022 at 8:24 PM Daniel P. Berrangé 
wrote:

> On Wed, Apr 20, 2022 at 05:26:12PM +0400, marcandre.lur...@redhat.com
> wrote:
> > From: Marc-André Lureau 
> >
> > This allows to make sure the test is still built, and gives more
> > accurate report details.
> >
> > Signed-off-by: Marc-André Lureau 
> > ---
> >  tests/unit/test-qga.c  | 7 +++
> >  tests/unit/meson.build | 2 +-
> >  2 files changed, 8 insertions(+), 1 deletion(-)
>
> Reviewed-by: Daniel P. Berrangé 
>

Can you review "[PATCH 26/41] compiler.h: add
QEMU_SANITIZE_{ADDRESS,THREAD}", it depends on it.

thanks


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

-- 
Marc-André Lureau


[PULL 13/13] dump/win_dump: add 32-bit guest Windows support

2022-04-21 Thread marcandre . lureau
From: Viktor Prutyanov 

Before this patch, 'dump-guest-memory -w' was accepting only 64-bit
dump header provided by guest through vmcoreinfo and thus was unable
to produce 32-bit guest Windows dump. So, add 32-bit guest Windows
dumping support.

Signed-off-by: Viktor Prutyanov 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Marc-André Lureau 
Message-Id: <20220406171558.199263-5-viktor.prutya...@redhat.com>
---
 dump/win_dump.c | 245 +---
 hmp-commands.hx |   2 +-
 2 files changed, 150 insertions(+), 97 deletions(-)

diff --git a/dump/win_dump.c b/dump/win_dump.c
index d733918038b2..ba508790bcea 100644
--- a/dump/win_dump.c
+++ b/dump/win_dump.c
@@ -23,18 +23,24 @@
 #include "hw/misc/vmcoreinfo.h"
 #include "win_dump.h"
 
-#define WIN_DUMP_PTR_SIZE sizeof(uint64_t)
+static size_t win_dump_ptr_size(bool x64)
+{
+return x64 ? sizeof(uint64_t) : sizeof(uint32_t);
+}
 
-#define _WIN_DUMP_FIELD(f) (h->f)
+#define _WIN_DUMP_FIELD(f) (x64 ? h->x64.f : h->x32.f)
 #define WIN_DUMP_FIELD(field) _WIN_DUMP_FIELD(field)
 
-#define _WIN_DUMP_FIELD_PTR(f) ((void *)&h->f)
+#define _WIN_DUMP_FIELD_PTR(f) (x64 ? (void *)&h->x64.f : (void *)&h->x32.f)
 #define WIN_DUMP_FIELD_PTR(field) _WIN_DUMP_FIELD_PTR(field)
 
-#define _WIN_DUMP_FIELD_SIZE(f) sizeof(h->f)
+#define _WIN_DUMP_FIELD_SIZE(f) (x64 ? sizeof(h->x64.f) : sizeof(h->x32.f))
 #define WIN_DUMP_FIELD_SIZE(field) _WIN_DUMP_FIELD_SIZE(field)
 
-#define WIN_DUMP_CTX_SIZE sizeof(WinContext64)
+static size_t win_dump_ctx_size(bool x64)
+{
+return x64 ? sizeof(WinContext64) : sizeof(WinContext32);
+}
 
 static size_t write_run(uint64_t base_page, uint64_t page_count,
 int fd, Error **errp)
@@ -70,7 +76,7 @@ static size_t write_run(uint64_t base_page, uint64_t 
page_count,
 return total;
 }
 
-static void write_runs(DumpState *s, WinDumpHeader64 *h, Error **errp)
+static void write_runs(DumpState *s, WinDumpHeader *h, bool x64, Error **errp)
 {
 uint64_t BasePage, PageCount;
 Error *local_err = NULL;
@@ -87,22 +93,24 @@ static void write_runs(DumpState *s, WinDumpHeader64 *h, 
Error **errp)
 }
 }
 
-static int cpu_read_ptr(CPUState *cpu, uint64_t addr, uint64_t *ptr)
+static int cpu_read_ptr(bool x64, CPUState *cpu, uint64_t addr, uint64_t *ptr)
 {
 int ret;
+uint32_t ptr32;
 uint64_t ptr64;
 
-ret = cpu_memory_rw_debug(cpu, addr, &ptr64, WIN_DUMP_PTR_SIZE, 0);
+ret = cpu_memory_rw_debug(cpu, addr, x64 ? (void *)&ptr64 : (void *)&ptr32,
+win_dump_ptr_size(x64), 0);
 
-*ptr = ptr64;
+*ptr = x64 ? ptr64 : ptr32;
 
 return ret;
 }
 
-static void patch_mm_pfn_database(WinDumpHeader64 *h, Error **errp)
+static void patch_mm_pfn_database(WinDumpHeader *h, bool x64, Error **errp)
 {
 if (cpu_memory_rw_debug(first_cpu,
-WIN_DUMP_FIELD(KdDebuggerDataBlock) + 
KDBG_MM_PFN_DATABASE_OFFSET64,
+WIN_DUMP_FIELD(KdDebuggerDataBlock) + KDBG_MM_PFN_DATABASE_OFFSET,
 WIN_DUMP_FIELD_PTR(PfnDatabase),
 WIN_DUMP_FIELD_SIZE(PfnDatabase), 0)) {
 error_setg(errp, "win-dump: failed to read MmPfnDatabase");
@@ -110,13 +118,12 @@ static void patch_mm_pfn_database(WinDumpHeader64 *h, 
Error **errp)
 }
 }
 
-static void patch_bugcheck_data(WinDumpHeader64 *h, Error **errp)
+static void patch_bugcheck_data(WinDumpHeader *h, bool x64, Error **errp)
 {
 uint64_t KiBugcheckData;
 
-if (cpu_read_ptr(first_cpu,
-WIN_DUMP_FIELD(KdDebuggerDataBlock) +
-KDBG_KI_BUGCHECK_DATA_OFFSET64,
+if (cpu_read_ptr(x64, first_cpu,
+WIN_DUMP_FIELD(KdDebuggerDataBlock) + KDBG_KI_BUGCHECK_DATA_OFFSET,
 &KiBugcheckData)) {
 error_setg(errp, "win-dump: failed to read KiBugcheckData");
 return;
@@ -141,30 +148,34 @@ static void patch_bugcheck_data(WinDumpHeader64 *h, Error 
**errp)
 /*
  * This routine tries to correct mistakes in crashdump header.
  */
-static void patch_header(WinDumpHeader64 *h)
+static void patch_header(WinDumpHeader *h, bool x64)
 {
 Error *local_err = NULL;
 
-h->RequiredDumpSpace = sizeof(WinDumpHeader64) +
-(h->PhysicalMemoryBlock.NumberOfPages << TARGET_PAGE_BITS);
-h->PhysicalMemoryBlock.unused = 0;
-h->unused1 = 0;
+if (x64) {
+h->x64.RequiredDumpSpace = sizeof(WinDumpHeader64) +
+(h->x64.PhysicalMemoryBlock.NumberOfPages << TARGET_PAGE_BITS);
+h->x64.PhysicalMemoryBlock.unused = 0;
+h->x64.unused1 = 0;
+} else {
+h->x32.RequiredDumpSpace = sizeof(WinDumpHeader32) +
+(h->x32.PhysicalMemoryBlock.NumberOfPages << TARGET_PAGE_BITS);
+}
 
-patch_mm_pfn_database(h, &local_err);
+patch_mm_pfn_database(h, x64, &local_err);
 if (local_err) {
 warn_report_err(local_err);
 local_err = NULL;
 }
-patch_bugcheck_data(h, &local_err);
+patch_bugcheck_data(h, x64, &local_err);
 if (local_err) {
 warn_report_err

Re: [PATCH 32/41] qtest: simplify socket_send()

2022-04-21 Thread Marc-André Lureau
Hi

On Wed, Apr 20, 2022 at 8:20 PM Daniel P. Berrangé 
wrote:

> On Wed, Apr 20, 2022 at 05:26:15PM +0400, marcandre.lur...@redhat.com
> wrote:
> > From: Marc-André Lureau 
> >
> > Reuse qemu_write_full().
> >
> > Signed-off-by: Marc-André Lureau 
> > ---
> >  tests/qtest/libqtest.c | 16 ++--
> >  1 file changed, 2 insertions(+), 14 deletions(-)
> >
> > diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> > index 7b5890dcc487..2b9bdb947d6f 100644
> > --- a/tests/qtest/libqtest.c
> > +++ b/tests/qtest/libqtest.c
> > @@ -414,21 +414,9 @@ void qtest_quit(QTestState *s)
> >
> >  static void socket_send(int fd, const char *buf, size_t size)
> >  {
> > -size_t offset;
> > -
> > -offset = 0;
> > -while (offset < size) {
> > -ssize_t len;
> > +size_t res = qemu_write_full(fd, buf, size);
> >
> > -len = write(fd, buf + offset, size - offset);
> > -if (len == -1 && errno == EINTR) {
> > -continue;
> > -}
> > -
> > -g_assert_cmpint(len, >, 0);
> > -
> > -offset += len;
> > -}
> > +assert(res == size);
> >  }
>
> IMHO socket_send should jsut be deleted, with the few callers
> directly using qemu_write_full
>

It's not a big deal, it's an internal helper. There is an additional
assert() there, and the socket_send_fds() pair. I'll leave it for now.

thanks

-- 
Marc-André Lureau


Re: [PATCH 5/5] 9pfs: fix removing non-existent POSIX ACL xattr on macOS host

2022-04-21 Thread Christian Schoenebeck
On Donnerstag, 21. April 2022 14:26:37 CEST Greg Kurz wrote:
> On Thu, 21 Apr 2022 12:55:24 +0200
> 
> Christian Schoenebeck  wrote:
> > On Donnerstag, 21. April 2022 10:26:11 CEST Greg Kurz wrote:
> > > On Tue, 19 Apr 2022 13:43:30 +0200
> > > 
> > > Christian Schoenebeck  wrote:
> > > > When mapped POSIX ACL is used, we are ignoring errors when trying
> > > > to remove a POSIX ACL xattr that does not exist. On Linux hosts we
> > > > would get ENODATA in such cases, on macOS hosts however we get
> > > > ENOATTR instead, so ignore ENOATTR errors as well.
> > > > 
> > > > This patch fixes e.g. a command on Linux guest like:
> > > >   cp --preserve=mode old new
> > > > 
> > > > Signed-off-by: Christian Schoenebeck 
> > > > ---
> > > > 
> > > >  hw/9pfs/9p-posix-acl.c | 8 +++-
> > > >  1 file changed, 7 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/hw/9pfs/9p-posix-acl.c b/hw/9pfs/9p-posix-acl.c
> > > > index eadae270dd..2bf155f941 100644
> > > > --- a/hw/9pfs/9p-posix-acl.c
> > > > +++ b/hw/9pfs/9p-posix-acl.c
> > > > @@ -65,7 +65,13 @@ static int mp_pacl_removexattr(FsContext *ctx,
> > > > 
> > > >  int ret;
> > > >  
> > > >  ret = local_removexattr_nofollow(ctx, path, MAP_ACL_ACCESS);
> > > > 
> > > > -if (ret == -1 && errno == ENODATA) {
> > > > +if (ret == -1 &&
> > > > +  (errno == ENODATA
> > > > +#ifdef ENOATTR
> > > > +  || errno == ENOATTR
> > > > +#endif
> > > > +  )
> > > 
> > > We already have this in  which is included by
> > > 9p-posix-acl.c :
> > > 
> > > /*
> > > 
> > >  * Modern distributions (e.g. Fedora 15), have no libattr.so, place
> > >  attr.h
> > >  * in /usr/include/sys, and don't have ENOATTR.
> > >  */
> > > 
> > > #ifdef CONFIG_LIBATTR
> > > #  include 
> > > #else
> > > #  if !defined(ENOATTR)
> > > #define ENOATTR ENODATA
> > > #  endif
> > > #  include 
> > > #endif
> > > 
> > > I guess this patch could just s/ENODATA/ENOATTR/ to avoid the
> > > extra ifdefery.
> > 
> > Not viable, because macOS does have both ENODATA==96 and ENOATTR==93. On
> > Linux the two macros were historically defined to the same numeric
> > values, that's why it worked there.
> 
> I was meaning your current fix could simply do:
> 
> -if (ret == -1 && errno == ENODATA) {
> +if (ret == -1 && errno == ENOATTR) {
> 
> since ENOATTR works in all cases, but this is rather a hack.
> 
> Another solution would be to ensure that local_removexattr_nofollow() only
> reports linux errnos. This could be handled cleanly in the
> fremovexattrat_nofollow() implementation in 9p-util-darwin.c.
> 
> Since the 9p code base mostly assumes the host is linux, this should
> probably be generalized to other places where we check errno.

Got it. I tend to go with the former (checking errno == ENOATTR and defining 
ENOATTR if non existent). I find that a bit cleaner than the latter which 
would have the potential to mask another error (ENODATA).

> > Maybe I should define a separate macro like:
> > 
> > #if ...
> > # define P9_ENOATTR ENOATTR
> > #else
> > # define P9_ENOATTR ENODATA
> > #end
> > 
> > ?
> > 
> > Actually good that you pointed me at this, because I just realized there
> > is a 2nd place in 9p-posix-acl.c which would require this as well. For
> > some reason the 2nd place just did not trigger while I was testing it on
> > macOS.
> > 
> > Best regards,
> > Christian Schoenebeck





Q: TX (THR) throttling for serial interface?

2022-04-21 Thread REITHER Robert
Hello,

ich have (realtime) problems in a QEMU client, spending too  much time with the 
serial IRQ (INT 4) while sending massive data over the serial interface (sttyS0)
I've found out that IRQ loops as long as there is send data available (LSR_THRE 
always 1, IIR_THRI always 1), which can lead to up to 1s IRQ time in my case.
QEMU always drains the TX FIFO at once and will only set the UART register bits 
afterwards.

My Linux console is using serial interface(because we use the same image on 
real hardware as also for the qemu client).

In very old QEMU code I found the method to throttle the TX int 
(THROTTLE_TX_INTERVAL) to probably avoid this behavior.
https://code.grnet.gr/projects/qemu/repository/revisions/6936bfe514bbac7af4b24fad9ed9688b78b5be69/entry/hw/serial.c

Is there a way to do something similar in actual QEMU code (setting TX delay 
timer)?
Or should I just try to switch to virtio_console?

Thank you
Robert


Re: [PATCH] hw/crypto: add Allwinner sun4i-ss crypto device

2022-04-21 Thread Daniel P . Berrangé
On Thu, Apr 21, 2022 at 01:38:00PM +0100, Peter Maydell wrote:
> On Sun, 10 Apr 2022 at 20:12, Corentin Labbe  wrote:
> >
> > From: Corentin LABBE 
> >
> > The Allwinner A10 has a cryptographic offloader device which
> > could be easily emulated.
> > The emulated device is tested with Linux only as any of BSD does not
> > support it.
> >
> > Signed-off-by: Corentin LABBE 
> 

> > +The ``sun4i-ss`` emulates the Allwinner cryptographic offloader
> > +present on early Allwinner SoCs (A10, A10s, A13, A20, A33)
> > +In qemu only A10 via the cubieboard machine is supported.
> > +
> > +The emulated hardware is capable of handling the following algorithms:
> > +- SHA1 and MD5 hash algorithms
> > +- AES/DES/DES3 in CBC/ECB
> > +- PRNG
> > +
> > +The emulated hardware does not handle yet:
> > +- CTS for AES
> > +- CTR for AES/DES/DES3



> > @@ -48,6 +50,10 @@ static void aw_a10_init(Object *obj)
> >
> >  object_initialize_child(obj, "emac", &s->emac, TYPE_AW_EMAC);
> >
> > +#if defined CONFIG_NETTLE
> > +object_initialize_child(obj, "crypto", &s->crypto, TYPE_AW_SUN4I_SS);
> > +#endif
> 
> Don't put this kind of ifdef into device/SoC code, please.
> The device emulation needs to work regardless of what
> the specific crypto backends that got compiled into QEMU are.
> 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> 
> Similarly, don't directly include nettle headers. The device needs
> to use the backend-agnostic headers from include/crypto. To the
> extent that they aren't sufficient to implement this device we
> can look at enhancing them.

The include/crypto/{cipher,hash}.h files should provide APIs that
cover these uses cases from what I see in this patch.

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




Re: [PATCH 3/6] scsi-disk: add MODE_PAGE_APPLE quirk for Macintosh

2022-04-21 Thread Fam Zheng
On 2022-04-21 07:51, Mark Cave-Ayland wrote:
> One of the mechanisms MacOS uses to identify drives compatible with MacOS is 
> to
> send a custom MODE SELECT command for page 0x30 to the drive. The response to
> this is a hard-coded manufacturer string which must match in order for the
> drive to be usable within MacOS.
> 
> Add an implementation of the MODE SELECT page 0x30 response guarded by a newly
> defined SCSI_DISK_QUIRK_MODE_PAGE_APPLE quirk bit so that drives attached
> to non-Apple machines function exactly as before.
> 
> Signed-off-by: Mark Cave-Ayland 
> ---
>  hw/scsi/scsi-disk.c  | 19 +++
>  include/hw/scsi/scsi.h   |  3 +++
>  include/scsi/constants.h |  1 +
>  3 files changed, 23 insertions(+)
> 
> diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
> index d89cdd4e4a..37013756d5 100644
> --- a/hw/scsi/scsi-disk.c
> +++ b/hw/scsi/scsi-disk.c
> @@ -1085,6 +1085,7 @@ static int mode_sense_page(SCSIDiskState *s, int page, 
> uint8_t **p_outbuf,
>  [MODE_PAGE_R_W_ERROR]  = (1 << TYPE_DISK) | (1 << 
> TYPE_ROM),
>  [MODE_PAGE_AUDIO_CTL]  = (1 << TYPE_ROM),
>  [MODE_PAGE_CAPABILITIES]   = (1 << TYPE_ROM),
> +[MODE_PAGE_APPLE]  = (1 << TYPE_ROM),
>  };
>  
>  uint8_t *p = *p_outbuf + 2;
> @@ -1229,6 +1230,22 @@ static int mode_sense_page(SCSIDiskState *s, int page, 
> uint8_t **p_outbuf,
>  p[19] = (16 * 176) & 0xff;
>  break;
>  
> + case MODE_PAGE_APPLE:
> +if (s->qdev.type == TYPE_DISK &&
> +(s->quirks & SCSI_DISK_QUIRK_MODE_PAGE_APPLE)) {

This is always false. SCSI_DISK_QUIRK_MODE_PAGE_APPLE is defined 0.

You need (1 << SCSI_DISK_QUIRK_MODE_PAGE_APPLE) instead.

> +
> +length = 0x24;
> +if (page_control == 1) { /* Changeable Values */
> +break;
> +}
> +
> +memset(p, 0, length);
> +strcpy((char *)p + 8, "APPLE COMPUTER, INC   ");
> +break;
> +} else {
> +return -1;
> +}
> +
>  default:
>  return -1;
>  }
> @@ -3042,6 +3059,8 @@ static Property scsi_hd_properties[] = {
>  DEFINE_PROP_UINT16("rotation_rate", SCSIDiskState, rotation_rate, 0),
>  DEFINE_PROP_INT32("scsi_version", SCSIDiskState, 
> qdev.default_scsi_version,
>5),
> +DEFINE_PROP_BIT("quirk_mode_page_apple", SCSIDiskState, quirks,
> +SCSI_DISK_QUIRK_MODE_PAGE_APPLE, 0),
>  DEFINE_BLOCK_CHS_PROPERTIES(SCSIDiskState, qdev.conf),
>  DEFINE_PROP_END_OF_LIST(),
>  };
> diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h
> index 1ffb367f94..f629706250 100644
> --- a/include/hw/scsi/scsi.h
> +++ b/include/hw/scsi/scsi.h
> @@ -226,4 +226,7 @@ SCSIDevice *scsi_device_get(SCSIBus *bus, int channel, 
> int target, int lun);
>  /* scsi-generic.c. */
>  extern const SCSIReqOps scsi_generic_req_ops;
>  
> +/* scsi-disk.c */
> +#define SCSI_DISK_QUIRK_MODE_PAGE_APPLE 0
> +
>  #endif
> diff --git a/include/scsi/constants.h b/include/scsi/constants.h
> index 2a32c08b5e..21ca7b50cd 100644
> --- a/include/scsi/constants.h
> +++ b/include/scsi/constants.h
> @@ -234,6 +234,7 @@
>  #define MODE_PAGE_FAULT_FAIL  0x1c
>  #define MODE_PAGE_TO_PROTECT  0x1d
>  #define MODE_PAGE_CAPABILITIES0x2a
> +#define MODE_PAGE_APPLE   0x30
>  #define MODE_PAGE_ALLS0x3f
>  /* Not in Mt. Fuji, but in ATAPI 2.6 -- deprecated now in favor
>   * of MODE_PAGE_SENSE_POWER */
> -- 
> 2.20.1
> 
> 

Fam



Re: [PATCH 26/41] compiler.h: add QEMU_SANITIZE_{ADDRESS,THREAD}

2022-04-21 Thread Daniel P . Berrangé
On Wed, Apr 20, 2022 at 05:26:09PM +0400, marcandre.lur...@redhat.com wrote:
> From: Marc-André Lureau 
> 
> Simplify a bit pre-compiler conditions.
> 
> For TSAN, QEMU already has CONFIG_TSAN, but it is only set when the
> fiber API is present. (I wonder whether supporting TSAN without the
> fiber API is really relevant)
> 
> Signed-off-by: Marc-André Lureau 
> ---
>  include/qemu/compiler.h | 8 
>  1 file changed, 8 insertions(+)

Reviewed-by: Daniel P. Berrangé 


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




[PATCH] qga: use fixed-length and GDateTime for log timestamp

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

The old code is kind of wrong. Say it's 1649309843.01 seconds past
the epoch. Prints "1649309843.1". 9us later, it prints "1649309843.10".
Should really use %06lu for the microseconds part.

Use GDateTime instead, as suggested by Daniel.

Suggested-by: Markus Armbruster 
Suggested-by: Daniel P. Berrangé 
Signed-off-by: Marc-André Lureau 
---
 qga/main.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/qga/main.c b/qga/main.c
index 3c20bf1fbfe0..3b9546c18584 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -328,11 +328,9 @@ static void ga_log(const gchar *domain, GLogLevelFlags 
level,
 #else
 if (level & s->log_level) {
 #endif
-gint64 t = g_get_real_time();
-fprintf(s->log_file,
-"%" G_GINT64_FORMAT ".%" G_GINT64_FORMAT
-": %s: %s\n", t / G_USEC_PER_SEC, t % G_USEC_PER_SEC,
-level_str, msg);
+g_autoptr(GDateTime) now = g_date_time_new_now_utc();
+g_autofree char *nowstr = g_date_time_format(now, "%s.%f");
+fprintf(s->log_file, "%s: %s: %s\n", nowstr, level_str, msg);
 fflush(s->log_file);
 }
 }
-- 
2.35.1.693.g805e0a68082a




Re: [PATCH v3] Use io_uring_register_ring_fd() to skip fd operations

2022-04-21 Thread Fam Zheng
On 2022-04-19 07:33, Sam Li wrote:
> Linux recently added a new io_uring(7) optimization API that QEMU
> doesn't take advantage of yet. The liburing library that QEMU uses
> has added a corresponding new API calling io_uring_register_ring_fd().
> When this API is called after creating the ring, the io_uring_submit()
> library function passes a flag to the io_uring_enter(2) syscall
> allowing it to skip the ring file descriptor fdget()/fdput()
> operations. This saves some CPU cycles.
> 
> Signed-off-by: Sam Li 
> ---
>  block/io_uring.c | 10 +-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/block/io_uring.c b/block/io_uring.c
> index 782afdb433..51f4834b69 100644
> --- a/block/io_uring.c
> +++ b/block/io_uring.c
> @@ -435,8 +435,16 @@ LuringState *luring_init(Error **errp)
>  }
>  
>  ioq_init(&s->io_q);
> -return s;
> +if (io_uring_register_ring_fd(&s->ring) < 0) {
> +/*
> + * Only warn about this error: we will fallback to the non-optimized
> + * io_uring operations.
> + */
> +error_setg_errno(errp, errno,
> + "failed to register linux io_uring ring file 
> descriptor");
> +}
>  
> +return s;

As a general convention, I don't think the errp is going to get proper handling
by the callers, if non-NULL is returned like here. IOW a matching error_free is
never called and this is memory leak?

I guess error_report is better?

Fam

>  }
>  
>  void luring_cleanup(LuringState *s)
> -- 
> 2.35.1
> 
> 



Re: [PATCH 27/41] Use QEMU_SANITIZE_THREAD

2022-04-21 Thread Daniel P . Berrangé
On Wed, Apr 20, 2022 at 05:26:10PM +0400, marcandre.lur...@redhat.com wrote:
> From: Marc-André Lureau 
> 
> Signed-off-by: Marc-André Lureau 
> ---
>  include/qemu/atomic.h| 8 +---
>  subprojects/libvhost-user/include/compiler.h | 1 +
>  2 files changed, 6 insertions(+), 3 deletions(-)
>  create mode 12 subprojects/libvhost-user/include/compiler.h

Reviewed-by: Daniel P. Berrangé 


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




Re: [PATCH] qga: use fixed-length and GDateTime for log timestamp

2022-04-21 Thread Daniel P . Berrangé
On Thu, Apr 21, 2022 at 05:35:49PM +0400, marcandre.lur...@redhat.com wrote:
> From: Marc-André Lureau 
> 
> The old code is kind of wrong. Say it's 1649309843.01 seconds past
> the epoch. Prints "1649309843.1". 9us later, it prints "1649309843.10".
> Should really use %06lu for the microseconds part.
> 
> Use GDateTime instead, as suggested by Daniel.
> 
> Suggested-by: Markus Armbruster 
> Suggested-by: Daniel P. Berrangé 
> Signed-off-by: Marc-André Lureau 
> ---
>  qga/main.c | 8 +++-
>  1 file changed, 3 insertions(+), 5 deletions(-)

Reviewed-by: Daniel P. Berrangé 


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




[PULL 00/30] Misc patches

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

The following changes since commit 9c125d17e9402c232c46610802e5931b3639d77b:

  Merge tag 'pull-tcg-20220420' of https://gitlab.com/rth7680/qemu into staging 
(2022-04-20 16:43:11 -0700)

are available in the Git repository at:

  g...@gitlab.com:marcandre.lureau/qemu.git tags/misc-pull-request

for you to fetch changes up to 55fa0170721e827c1701db3a66a54d44b5660d53:

  qga: use fixed-length and GDateTime for log timestamp (2022-04-21 17:37:16 
+0400)


Misc cleanups



Marc-André Lureau (30):
  glib-compat: isolate g_date_time_format_iso8601 version-bypass
  scripts/analyze-inclusions: drop qemu-common.h from analysis
  Simplify softmmu/main.c
  hw/hyperv: remove needless qemu-common.h include
  include: rename qemu-common.h qemu/help-texts.h
  qga: replace usleep() with g_usleep()
  docs: trace-events-all is installed without renaming
  arm/digic: replace snprintf() with g_strdup_printf()
  arm/allwinner-a10: replace snprintf() with g_strdup_printf()
  intc/exynos4210_gic: replace snprintf() with g_strdup_printf()
  doc/style: CLang -> Clang
  osdep.h: move qemu_build_not_reached()
  compiler.h: replace QEMU_NORETURN with G_NORETURN
  include: move qemu_msync() to osdep
  include: move qemu_fdatasync() to osdep
  include: add qemu/keyval.h
  include: move qdict_{crumple,flatten} declarations
  tests: remove block/qdict checks from check-qobject.c
  compiler.h: add QEMU_SANITIZE_{ADDRESS,THREAD}
  tests: run-time skip test-qga if TSAN is enabled
  Move error_printf_unless_qmp() with monitor unit
  qga: move qga_get_host_name()
  qtest: simplify socket_send()
  util: simplify write in signal handler
  util: use qemu_write_full() in qemu_write_pidfile()
  util: use qemu_create() in qemu_write_pidfile()
  util: replace qemu_get_local_state_pathname()
  qga: remove need for QEMU atomic.h
  tests/fuzz: fix warning
  qga: use fixed-length and GDateTime for log timestamp

 docs/devel/style.rst |  2 +-
 docs/devel/tracing.rst   |  2 +-
 accel/tcg/internal.h |  3 +-
 include/block/qdict.h|  3 +
 include/exec/exec-all.h  | 20 +++---
 include/exec/helper-head.h   |  2 +-
 include/glib-compat.h| 12 +---
 include/hw/core/cpu.h|  2 +-
 include/hw/core/tcg-cpu-ops.h|  6 +-
 include/hw/hw.h  |  2 +-
 include/monitor/monitor.h|  3 +
 include/qapi/qmp/qdict.h |  3 -
 include/qemu-main.h  | 10 +++
 include/qemu/compiler.h  | 26 +++-
 include/qemu/cutils.h|  2 -
 include/qemu/error-report.h  |  2 -
 include/{qemu-common.h => qemu/help-texts.h} |  5 --
 include/qemu/keyval.h| 14 +
 include/qemu/option.h|  6 --
 include/qemu/osdep.h | 43 +
 include/qemu/thread.h|  2 +-
 include/tcg/tcg-ldst.h   |  4 +-
 include/tcg/tcg.h|  2 +-
 linux-user/user-internals.h  |  2 +-
 qga/commands-common.h| 11 
 scripts/cocci-macro-file.h   |  2 +-
 target/alpha/cpu.h   | 10 +--
 target/arm/internals.h   | 12 ++--
 target/hppa/cpu.h|  2 +-
 target/i386/tcg/helper-tcg.h | 24 
 target/microblaze/cpu.h  |  6 +-
 target/mips/tcg/tcg-internal.h   | 17 ++---
 target/nios2/cpu.h   |  6 +-
 target/openrisc/exception.h  |  2 +-
 target/ppc/cpu.h | 14 ++---
 target/ppc/internal.h|  6 +-
 target/riscv/cpu.h   | 10 +--
 target/s390x/s390x-internal.h|  6 +-
 target/s390x/tcg/tcg_s390x.h | 12 ++--
 target/sh4/cpu.h |  6 +-
 target/sparc/cpu.h   | 10 +--
 target/xtensa/cpu.h  |  6 +-
 accel/stubs/tcg-stub.c   |  4 +-
 bsd-user/main.c  |  2 +-
 bsd-user/signal.c|  3 +-
 hw/arm/allwinner-a10.c   |  4 +-
 hw/arm/digic.c   |  5 +-
 hw/hyperv/syndbg.c   |  1 -
 hw/intc/exynos4210_gic.c |  9 +--
 hw/misc/mips_itu.c   |  3 +-
 linux-user/main.c|  2 +-
 linux-user/signal.c  |  3 +-
 monitor/hmp.c|  4 +-
 monitor/monitor.c   

[PULL 01/30] glib-compat: isolate g_date_time_format_iso8601 version-bypass

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

The solution was discussed with Markus Armbruster during the review:
https://patchew.org/QEMU/20220323155743.1585078-1-marcandre.lur...@redhat.com/20220323155743.1585078-14-marcandre.lur...@redhat.com/

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-3-marcandre.lur...@redhat.com>
---
 include/glib-compat.h | 10 --
 util/error-report.c   |  6 +-
 2 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/include/glib-compat.h b/include/glib-compat.h
index dc14d3ec0d1e..3113a7d2af84 100644
--- a/include/glib-compat.h
+++ b/include/glib-compat.h
@@ -145,16 +145,6 @@ qemu_g_test_slow(void)
 #define g_test_thorough() qemu_g_test_slow()
 #define g_test_quick() (!qemu_g_test_slow())
 
-#if GLIB_CHECK_VERSION(2,62,0)
-static inline gchar *
-g_date_time_format_iso8601_compat(GDateTime *datetime)
-{
-return g_date_time_format_iso8601(datetime);
-}
-
-#define g_date_time_format_iso8601 g_date_time_format_iso8601_compat
-#endif
-
 #pragma GCC diagnostic pop
 
 #endif
diff --git a/util/error-report.c b/util/error-report.c
index d9d3ac30cfab..4ec7b30bcbcc 100644
--- a/util/error-report.c
+++ b/util/error-report.c
@@ -183,9 +183,13 @@ static void print_loc(void)
 static char *
 real_time_iso8601(void)
 {
-#if GLIB_CHECK_VERSION(2, 62, 0)
+#if GLIB_CHECK_VERSION(2,62,0)
 g_autoptr(GDateTime) dt = g_date_time_new_from_unix_utc(g_get_real_time());
+/* ignore deprecation warning, since GLIB_VERSION_MAX_ALLOWED is 2.56 */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 return g_date_time_format_iso8601(dt);
+#pragma GCC diagnostic pop
 #else
 GTimeVal tv;
 g_get_current_time(&tv);
-- 
2.36.0




[PULL 02/30] scripts/analyze-inclusions: drop qemu-common.h from analysis

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

The header is no longer commonly included.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-4-marcandre.lur...@redhat.com>
---
 scripts/analyze-inclusions | 4 
 1 file changed, 4 deletions(-)

diff --git a/scripts/analyze-inclusions b/scripts/analyze-inclusions
index 14806e18c6e1..45c821de32b3 100644
--- a/scripts/analyze-inclusions
+++ b/scripts/analyze-inclusions
@@ -46,7 +46,6 @@ grep_include() {
 }
 
 echo Found $(find . -name "*.d" | wc -l) object files
-echo $(grep_include -F 'include/qemu-common.h') files include qemu-common.h
 echo $(grep_include -F 'hw/hw.h') files include hw/hw.h
 echo $(grep_include 'target/[a-z0-9]*/cpu\.h') files include cpu.h
 echo $(grep_include -F 'qapi-types.h') files include qapi-types.h
@@ -86,9 +85,6 @@ analyze() {
 echo osdep.h:
 analyze ../include/qemu/osdep.h
 
-echo qemu-common.h:
-analyze  -include ../include/qemu/osdep.h ../include/qemu-common.h
-
 echo hw/hw.h:
 analyze -include ../include/qemu/osdep.h ../include/hw/hw.h
 
-- 
2.36.0




[PULL 09/30] arm/allwinner-a10: replace snprintf() with g_strdup_printf()

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

Also fixes a GCC 12.0.1 false-positive:
../hw/arm/allwinner-a10.c: In function ‘aw_a10_realize’:
../hw/arm/allwinner-a10.c:135:35: error: ‘%d’ directive writing between 1 and 
11 bytes into a region of size 8 [-Werror=format-overflow=]
  135 | sprintf(bus, "usb-bus.%d", i);
  |   ^~

Signed-off-by: Marc-André Lureau 
Reviewed-by: Peter Maydell 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-15-marcandre.lur...@redhat.com>
---
 hw/arm/allwinner-a10.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/hw/arm/allwinner-a10.c b/hw/arm/allwinner-a10.c
index 05e84728cb34..79082289ea5b 100644
--- a/hw/arm/allwinner-a10.c
+++ b/hw/arm/allwinner-a10.c
@@ -130,9 +130,7 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
 int i;
 
 for (i = 0; i < AW_A10_NUM_USB; i++) {
-char bus[16];
-
-sprintf(bus, "usb-bus.%d", i);
+g_autofree char *bus = g_strdup_printf("usb-bus.%d", i);
 
 object_property_set_bool(OBJECT(&s->ehci[i]), "companion-enable",
  true, &error_fatal);
-- 
2.36.0




[PULL 05/30] include: rename qemu-common.h qemu/help-texts.h

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

Suggested-by: Peter Maydell 
Signed-off-by: Marc-André Lureau 
Reviewed-by: Warner Losh 
Message-Id: <20220420132624.2439741-7-marcandre.lur...@redhat.com>
---
 include/{qemu-common.h => qemu/help-texts.h} | 0
 bsd-user/main.c  | 2 +-
 linux-user/main.c| 2 +-
 qemu-img.c   | 2 +-
 qemu-io.c| 2 +-
 qemu-nbd.c   | 2 +-
 qga/main.c   | 2 +-
 scsi/qemu-pr-helper.c| 2 +-
 softmmu/vl.c | 2 +-
 storage-daemon/qemu-storage-daemon.c | 2 +-
 tools/virtiofsd/passthrough_ll.c | 2 +-
 ui/cocoa.m   | 2 +-
 12 files changed, 11 insertions(+), 11 deletions(-)
 rename include/{qemu-common.h => qemu/help-texts.h} (100%)

diff --git a/include/qemu-common.h b/include/qemu/help-texts.h
similarity index 100%
rename from include/qemu-common.h
rename to include/qemu/help-texts.h
diff --git a/bsd-user/main.c b/bsd-user/main.c
index 74f2d35a5497..6f09180d6541 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -24,7 +24,7 @@
 #include 
 
 #include "qemu/osdep.h"
-#include "qemu-common.h"
+#include "qemu/help-texts.h"
 #include "qemu/units.h"
 #include "qemu/accel.h"
 #include "qemu-version.h"
diff --git a/linux-user/main.c b/linux-user/main.c
index 5fb6ecac3f86..7ca48664e447 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -18,7 +18,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "qemu-common.h"
+#include "qemu/help-texts.h"
 #include "qemu/units.h"
 #include "qemu/accel.h"
 #include "qemu-version.h"
diff --git a/qemu-img.c b/qemu-img.c
index ef3224a9d4a8..6337a63b3b80 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -25,7 +25,7 @@
 #include "qemu/osdep.h"
 #include 
 
-#include "qemu-common.h"
+#include "qemu/help-texts.h"
 #include "qemu/qemu-progress.h"
 #include "qemu-version.h"
 #include "qapi/error.h"
diff --git a/qemu-io.c b/qemu-io.c
index 38321a27a301..d70d3dd4fde5 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -15,7 +15,7 @@
 #include 
 #endif
 
-#include "qemu-common.h"
+#include "qemu/help-texts.h"
 #include "qapi/error.h"
 #include "qemu-io.h"
 #include "qemu/error-report.h"
diff --git a/qemu-nbd.c b/qemu-nbd.c
index bf9c5fedceba..397ffa64d768 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -21,7 +21,7 @@
 #include 
 #include 
 
-#include "qemu-common.h"
+#include "qemu/help-texts.h"
 #include "qapi/error.h"
 #include "qemu/cutils.h"
 #include "sysemu/block-backend.h"
diff --git a/qga/main.c b/qga/main.c
index 1deb0ee2fbfe..e4b22df01dcd 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -18,7 +18,7 @@
 #include 
 #include 
 #endif
-#include "qemu-common.h"
+#include "qemu/help-texts.h"
 #include "qapi/qmp/json-parser.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qjson.h"
diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c
index 1f2a84c53454..df493e2a503e 100644
--- a/scsi/qemu-pr-helper.c
+++ b/scsi/qemu-pr-helper.c
@@ -36,7 +36,7 @@
 #include 
 #endif
 
-#include "qemu-common.h"
+#include "qemu/help-texts.h"
 #include "qapi/error.h"
 #include "qemu/cutils.h"
 #include "qemu/main-loop.h"
diff --git a/softmmu/vl.c b/softmmu/vl.c
index f679d48d7415..2a38ebe5fbb4 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -23,7 +23,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "qemu-common.h"
+#include "qemu/help-texts.h"
 #include "qemu/datadir.h"
 #include "qemu/units.h"
 #include "exec/cpu-common.h"
diff --git a/storage-daemon/qemu-storage-daemon.c 
b/storage-daemon/qemu-storage-daemon.c
index 1398f0443d76..9b8b17f52e48 100644
--- a/storage-daemon/qemu-storage-daemon.c
+++ b/storage-daemon/qemu-storage-daemon.c
@@ -42,7 +42,7 @@
 #include "qapi/qmp/qstring.h"
 #include "qapi/qobject-input-visitor.h"
 
-#include "qemu-common.h"
+#include "qemu/help-texts.h"
 #include "qemu-version.h"
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 028dacdd8f5a..b15c631ca512 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -38,7 +38,7 @@
 #include "qemu/osdep.h"
 #include "qemu/timer.h"
 #include "qemu-version.h"
-#include "qemu-common.h"
+#include "qemu/help-texts.h"
 #include "fuse_virtio.h"
 #include "fuse_log.h"
 #include "fuse_lowlevel.h"
diff --git a/ui/cocoa.m b/ui/cocoa.m
index 839ae4f58a69..68bff4ff3796 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -27,7 +27,7 @@
 #import 
 #include 
 
-#include "qemu-common.h"
+#include "qemu/help-texts.h"
 #include "qemu-main.h"
 #include "ui/clipboard.h"
 #include "ui/console.h"
-- 
2.36.0




[PULL 07/30] docs: trace-events-all is installed without renaming

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-13-marcandre.lur...@redhat.com>
---
 docs/devel/tracing.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/docs/devel/tracing.rst b/docs/devel/tracing.rst
index ec9a687cfdc9..d288480db11f 100644
--- a/docs/devel/tracing.rst
+++ b/docs/devel/tracing.rst
@@ -48,7 +48,7 @@ file. During build, the "trace-events" file in each listed 
subdirectory will be
 processed by the "tracetool" script to generate code for the trace events.
 
 The individual "trace-events" files are merged into a "trace-events-all" file,
-which is also installed into "/usr/share/qemu" with the name "trace-events".
+which is also installed into "/usr/share/qemu".
 This merged file is to be used by the "simpletrace.py" script to later analyse
 traces in the simpletrace data format.
 
-- 
2.36.0




[PULL 03/30] Simplify softmmu/main.c

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

Move qemu_main() declaration to a new header.

Simplify main.c since both cocoa & sdl cannot be enabled together.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Akihiko Odaki 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-5-marcandre.lur...@redhat.com>
---
 include/qemu-common.h |  5 -
 include/qemu-main.h   | 10 ++
 softmmu/main.c| 25 +
 ui/cocoa.m|  1 +
 4 files changed, 20 insertions(+), 21 deletions(-)
 create mode 100644 include/qemu-main.h

diff --git a/include/qemu-common.h b/include/qemu-common.h
index a923ed28d5bf..ba32cc8b1f39 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -10,9 +10,4 @@
 "See  for how to report bugs.\n" 
\
 "More information on the QEMU project at ."
 
-/* main function, renamed */
-#if defined(CONFIG_COCOA)
-int qemu_main(int argc, char **argv, char **envp);
-#endif
-
 #endif
diff --git a/include/qemu-main.h b/include/qemu-main.h
new file mode 100644
index ..6a3e90d0ad59
--- /dev/null
+++ b/include/qemu-main.h
@@ -0,0 +1,10 @@
+/*
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#ifndef QEMU_MAIN_H
+#define QEMU_MAIN_H
+
+int qemu_main(int argc, char **argv, char **envp);
+
+#endif /* QEMU_MAIN_H */
diff --git a/softmmu/main.c b/softmmu/main.c
index 639c67ff4893..c00432ff098e 100644
--- a/softmmu/main.c
+++ b/softmmu/main.c
@@ -23,28 +23,14 @@
  */
 
 #include "qemu/osdep.h"
-#include "qemu-common.h"
+#include "qemu-main.h"
 #include "sysemu/sysemu.h"
 
 #ifdef CONFIG_SDL
-#if defined(__APPLE__) || defined(main)
 #include 
-static int qemu_main(int argc, char **argv, char **envp);
-int main(int argc, char **argv)
-{
-return qemu_main(argc, argv, NULL);
-}
-#undef main
-#define main qemu_main
 #endif
-#endif /* CONFIG_SDL */
-
-#ifdef CONFIG_COCOA
-#undef main
-#define main qemu_main
-#endif /* CONFIG_COCOA */
 
-int main(int argc, char **argv, char **envp)
+int qemu_main(int argc, char **argv, char **envp)
 {
 qemu_init(argc, argv, envp);
 qemu_main_loop();
@@ -52,3 +38,10 @@ int main(int argc, char **argv, char **envp)
 
 return 0;
 }
+
+#ifndef CONFIG_COCOA
+int main(int argc, char **argv)
+{
+return qemu_main(argc, argv, NULL);
+}
+#endif
diff --git a/ui/cocoa.m b/ui/cocoa.m
index c4e5468f9e64..839ae4f58a69 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -28,6 +28,7 @@
 #include 
 
 #include "qemu-common.h"
+#include "qemu-main.h"
 #include "ui/clipboard.h"
 #include "ui/console.h"
 #include "ui/input.h"
-- 
2.36.0




[PULL 15/30] include: move qemu_fdatasync() to osdep

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

Move QEMU-specific code to util/osdep.c, so cutils can become a common
subproject.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-22-marcandre.lur...@redhat.com>
---
 include/qemu/cutils.h |  1 -
 include/qemu/osdep.h  |  2 ++
 util/cutils.c | 16 
 util/osdep.c  | 16 
 4 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index fb47ec931876..5c6572d44422 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -129,7 +129,6 @@ static inline const char *qemu_strchrnul(const char *s, int 
c)
 const char *qemu_strchrnul(const char *s, int c);
 #endif
 time_t mktimegm(struct tm *tm);
-int qemu_fdatasync(int fd);
 int qemu_parse_fd(const char *param);
 int qemu_strtoi(const char *nptr, const char **endptr, int base,
 int *result);
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index bf4f75dcde8f..a87f1b7f32e6 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -641,6 +641,8 @@ static inline void qemu_reset_optind(void)
 #endif
 }
 
+int qemu_fdatasync(int fd);
+
 /**
  * Sync changes made to the memory mapped file back to the backing
  * storage. For POSIX compliant systems this will fallback
diff --git a/util/cutils.c b/util/cutils.c
index c0775bb53c29..b2777210e7da 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -144,22 +144,6 @@ time_t mktimegm(struct tm *tm)
 return t;
 }
 
-/*
- * Make sure data goes on disk, but if possible do not bother to
- * write out the inode just for timestamp updates.
- *
- * Unfortunately even in 2009 many operating systems do not support
- * fdatasync and have to fall back to fsync.
- */
-int qemu_fdatasync(int fd)
-{
-#ifdef CONFIG_FDATASYNC
-return fdatasync(fd);
-#else
-return fsync(fd);
-#endif
-}
-
 static int64_t suffix_mul(char suffix, int64_t unit)
 {
 switch (qemu_toupper(suffix)) {
diff --git a/util/osdep.c b/util/osdep.c
index 1ea2398686ee..c7aec36f22c7 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -607,3 +607,19 @@ writev(int fd, const struct iovec *iov, int iov_cnt)
 return readv_writev(fd, iov, iov_cnt, true);
 }
 #endif
+
+/*
+ * Make sure data goes on disk, but if possible do not bother to
+ * write out the inode just for timestamp updates.
+ *
+ * Unfortunately even in 2009 many operating systems do not support
+ * fdatasync and have to fall back to fsync.
+ */
+int qemu_fdatasync(int fd)
+{
+#ifdef CONFIG_FDATASYNC
+return fdatasync(fd);
+#else
+return fsync(fd);
+#endif
+}
-- 
2.36.0




[PULL 04/30] hw/hyperv: remove needless qemu-common.h include

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-6-marcandre.lur...@redhat.com>
---
 hw/hyperv/syndbg.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/hw/hyperv/syndbg.c b/hw/hyperv/syndbg.c
index 89ae19b9aab6..ebb8a29f7838 100644
--- a/hw/hyperv/syndbg.c
+++ b/hw/hyperv/syndbg.c
@@ -10,7 +10,6 @@
 #include "qemu/error-report.h"
 #include "qemu/main-loop.h"
 #include "qemu/sockets.h"
-#include "qemu-common.h"
 #include "qapi/error.h"
 #include "migration/vmstate.h"
 #include "hw/qdev-properties.h"
-- 
2.36.0




[PULL 10/30] intc/exynos4210_gic: replace snprintf() with g_strdup_printf()

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

While at it, replace '%x' with '%u' as suggested by Philippe Mathieu-Daudé.

Also fixes a GCC 12.0.1 -Wformat-overflow false-positive.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Peter Maydell 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-16-marcandre.lur...@redhat.com>
---
 hw/intc/exynos4210_gic.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/hw/intc/exynos4210_gic.c b/hw/intc/exynos4210_gic.c
index bc73d1f11524..f8dd719caa1e 100644
--- a/hw/intc/exynos4210_gic.c
+++ b/hw/intc/exynos4210_gic.c
@@ -289,10 +289,6 @@ static void exynos4210_gic_realize(DeviceState *dev, Error 
**errp)
 Object *obj = OBJECT(dev);
 Exynos4210GicState *s = EXYNOS4210_GIC(obj);
 SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
-const char cpu_prefix[] = "exynos4210-gic-alias_cpu";
-const char dist_prefix[] = "exynos4210-gic-alias_dist";
-char cpu_alias_name[sizeof(cpu_prefix) + 3];
-char dist_alias_name[sizeof(cpu_prefix) + 3];
 SysBusDevice *gicbusdev;
 uint32_t n = s->num_cpu;
 uint32_t i;
@@ -322,8 +318,10 @@ static void exynos4210_gic_realize(DeviceState *dev, Error 
**errp)
  */
 assert(n <= EXYNOS4210_NCPUS);
 for (i = 0; i < n; i++) {
+g_autofree char *cpu_alias_name = 
g_strdup_printf("exynos4210-gic-alias_cpu%u", i);
+g_autofree char *dist_alias_name = 
g_strdup_printf("exynos4210-gic-alias_dist%u", i);
+
 /* Map CPU interface per SMP Core */
-sprintf(cpu_alias_name, "%s%x", cpu_prefix, i);
 memory_region_init_alias(&s->cpu_alias[i], obj,
  cpu_alias_name,
  sysbus_mmio_get_region(gicbusdev, 1),
@@ -333,7 +331,6 @@ static void exynos4210_gic_realize(DeviceState *dev, Error 
**errp)
 EXYNOS4210_EXT_GIC_CPU_GET_OFFSET(i), &s->cpu_alias[i]);
 
 /* Map Distributor per SMP Core */
-sprintf(dist_alias_name, "%s%x", dist_prefix, i);
 memory_region_init_alias(&s->dist_alias[i], obj,
  dist_alias_name,
  sysbus_mmio_get_region(gicbusdev, 0),
-- 
2.36.0




[PULL 12/30] osdep.h: move qemu_build_not_reached()

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

Move the macro and declaration so it can use glib in the following
patch (it already depends on glib anyway for !optimize)

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-19-marcandre.lur...@redhat.com>
---
 include/qemu/compiler.h | 16 
 include/qemu/osdep.h| 16 
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index d9359859d435..c13bc8b58652 100644
--- a/include/qemu/compiler.h
+++ b/include/qemu/compiler.h
@@ -156,22 +156,6 @@
 #define QEMU_ALWAYS_INLINE
 #endif
 
-/**
- * qemu_build_not_reached()
- *
- * The compiler, during optimization, is expected to prove that a call
- * to this function cannot be reached and remove it.  If the compiler
- * supports QEMU_ERROR, this will be reported at compile time; otherwise
- * this will be reported at link time due to the missing symbol.
- */
-extern void QEMU_NORETURN QEMU_ERROR("code path is reachable")
-qemu_build_not_reached_always(void);
-#if defined(__OPTIMIZE__) && !defined(__NO_INLINE__)
-#define qemu_build_not_reached()  qemu_build_not_reached_always()
-#else
-#define qemu_build_not_reached()  g_assert_not_reached()
-#endif
-
 /**
  * In most cases, normal "fallthrough" comments are good enough for
  * switch-case statements, but sometimes the compiler has problems
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index a7332947107a..848916f5165c 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -169,6 +169,22 @@ extern "C" {
 #define assert(x)  g_assert(x)
 #endif
 
+/**
+ * qemu_build_not_reached()
+ *
+ * The compiler, during optimization, is expected to prove that a call
+ * to this function cannot be reached and remove it.  If the compiler
+ * supports QEMU_ERROR, this will be reported at compile time; otherwise
+ * this will be reported at link time due to the missing symbol.
+ */
+extern void QEMU_NORETURN QEMU_ERROR("code path is reachable")
+qemu_build_not_reached_always(void);
+#if defined(__OPTIMIZE__) && !defined(__NO_INLINE__)
+#define qemu_build_not_reached()  qemu_build_not_reached_always()
+#else
+#define qemu_build_not_reached()  g_assert_not_reached()
+#endif
+
 /*
  * According to waitpid man page:
  * WCOREDUMP
-- 
2.36.0




[PULL 21/30] Move error_printf_unless_qmp() with monitor unit

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

Since it depends on monitor code, and error_vprintf_unless_qmp() is
already there.

This will help to move error-report in a common subproject.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-31-marcandre.lur...@redhat.com>
---
 include/monitor/monitor.h   |  3 +++
 include/qemu/error-report.h |  2 --
 monitor/monitor.c   | 10 ++
 stubs/error-printf.c|  1 +
 ui/vnc.c|  1 +
 util/error-report.c | 11 ---
 6 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index cc4cc6c6adcf..a4b40e8391db 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -56,4 +56,7 @@ void monitor_register_hmp(const char *name, bool info,
 void monitor_register_hmp_info_hrt(const char *name,
HumanReadableText *(*handler)(Error 
**errp));
 
+int error_vprintf_unless_qmp(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0);
+int error_printf_unless_qmp(const char *fmt, ...) G_GNUC_PRINTF(1, 2);
+
 #endif /* MONITOR_H */
diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index b6f45e69d79a..3ae2357fda54 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -32,8 +32,6 @@ void loc_set_file(const char *fname, int lno);
 
 int error_vprintf(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0);
 int error_printf(const char *fmt, ...) G_GNUC_PRINTF(1, 2);
-int error_vprintf_unless_qmp(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0);
-int error_printf_unless_qmp(const char *fmt, ...) G_GNUC_PRINTF(1, 2);
 
 void error_vreport(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0);
 void warn_vreport(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0);
diff --git a/monitor/monitor.c b/monitor/monitor.c
index 21c7a68758f5..86949024f643 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -286,6 +286,16 @@ int error_vprintf_unless_qmp(const char *fmt, va_list ap)
 return -1;
 }
 
+int error_printf_unless_qmp(const char *fmt, ...)
+{
+va_list ap;
+int ret;
+
+va_start(ap, fmt);
+ret = error_vprintf_unless_qmp(fmt, ap);
+va_end(ap);
+return ret;
+}
 
 static MonitorQAPIEventConf monitor_qapi_event_conf[QAPI_EVENT__MAX] = {
 /* Limit guest-triggerable events to 1 per second */
diff --git a/stubs/error-printf.c b/stubs/error-printf.c
index a2f61521a16f..0e326d801059 100644
--- a/stubs/error-printf.c
+++ b/stubs/error-printf.c
@@ -1,5 +1,6 @@
 #include "qemu/osdep.h"
 #include "qemu/error-report.h"
+#include "monitor/monitor.h"
 
 int error_vprintf(const char *fmt, va_list ap)
 {
diff --git a/ui/vnc.c b/ui/vnc.c
index 6261d922953b..badf1d7664fe 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -54,6 +54,7 @@
 #include "qemu/cutils.h"
 #include "qemu/help_option.h"
 #include "io/dns-resolver.h"
+#include "monitor/monitor.h"
 
 #define VNC_REFRESH_INTERVAL_BASE GUI_REFRESH_INTERVAL_DEFAULT
 #define VNC_REFRESH_INTERVAL_INC  50
diff --git a/util/error-report.c b/util/error-report.c
index 4ec7b30bcbcc..dbadaf206d27 100644
--- a/util/error-report.c
+++ b/util/error-report.c
@@ -40,17 +40,6 @@ int error_printf(const char *fmt, ...)
 return ret;
 }
 
-int error_printf_unless_qmp(const char *fmt, ...)
-{
-va_list ap;
-int ret;
-
-va_start(ap, fmt);
-ret = error_vprintf_unless_qmp(fmt, ap);
-va_end(ap);
-return ret;
-}
-
 static Location std_loc = {
 .kind = LOC_NONE
 };
-- 
2.36.0




[PULL 06/30] qga: replace usleep() with g_usleep()

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

The latter simply requires glib.h, while the former is not in the
Windows API (but provided by mingw header & CRT)

Also simplify the expression for 1/10s.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-12-marcandre.lur...@redhat.com>
---
 qga/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qga/main.c b/qga/main.c
index e4b22df01dcd..aa00ad8fabdf 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -610,7 +610,7 @@ static gboolean channel_event_cb(GIOCondition condition, 
gpointer data)
  * host-side chardev. sleep a bit to mitigate this
  */
 if (s->virtio) {
-usleep(100 * 1000);
+g_usleep(G_USEC_PER_SEC / 10);
 }
 return true;
 default:
-- 
2.36.0




[PULL 14/30] include: move qemu_msync() to osdep

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

The implementation depends on the OS. (and longer-term goal is to move
cutils to a common subproject)

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-21-marcandre.lur...@redhat.com>
---
 include/qemu/cutils.h |  1 -
 include/qemu/osdep.h  | 13 +
 util/cutils.c | 38 --
 util/oslib-posix.c| 18 ++
 util/oslib-win32.c| 10 ++
 5 files changed, 41 insertions(+), 39 deletions(-)

diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index e873bad36674..fb47ec931876 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -130,7 +130,6 @@ const char *qemu_strchrnul(const char *s, int c);
 #endif
 time_t mktimegm(struct tm *tm);
 int qemu_fdatasync(int fd);
-int qemu_msync(void *addr, size_t length, int fd);
 int qemu_parse_fd(const char *param);
 int qemu_strtoi(const char *nptr, const char **endptr, int base,
 int *result);
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 14b6b65a5fa9..bf4f75dcde8f 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -641,6 +641,19 @@ static inline void qemu_reset_optind(void)
 #endif
 }
 
+/**
+ * Sync changes made to the memory mapped file back to the backing
+ * storage. For POSIX compliant systems this will fallback
+ * to regular msync call. Otherwise it will trigger whole file sync
+ * (including the metadata case there is no support to skip that otherwise)
+ *
+ * @addr   - start of the memory area to be synced
+ * @length - length of the are to be synced
+ * @fd - file descriptor for the file to be synced
+ *   (mandatory only for POSIX non-compliant systems)
+ */
+int qemu_msync(void *addr, size_t length, int fd);
+
 /**
  * qemu_get_host_name:
  * @errp: Error object
diff --git a/util/cutils.c b/util/cutils.c
index a01a3a754049..c0775bb53c29 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -160,44 +160,6 @@ int qemu_fdatasync(int fd)
 #endif
 }
 
-/**
- * Sync changes made to the memory mapped file back to the backing
- * storage. For POSIX compliant systems this will fallback
- * to regular msync call. Otherwise it will trigger whole file sync
- * (including the metadata case there is no support to skip that otherwise)
- *
- * @addr   - start of the memory area to be synced
- * @length - length of the are to be synced
- * @fd - file descriptor for the file to be synced
- *   (mandatory only for POSIX non-compliant systems)
- */
-int qemu_msync(void *addr, size_t length, int fd)
-{
-#ifdef CONFIG_POSIX
-size_t align_mask = ~(qemu_real_host_page_size() - 1);
-
-/**
- * There are no strict reqs as per the length of mapping
- * to be synced. Still the length needs to follow the address
- * alignment changes. Additionally - round the size to the multiple
- * of PAGE_SIZE
- */
-length += ((uintptr_t)addr & (qemu_real_host_page_size() - 1));
-length = (length + ~align_mask) & align_mask;
-
-addr = (void *)((uintptr_t)addr & align_mask);
-
-return msync(addr, length, MS_SYNC);
-#else /* CONFIG_POSIX */
-/**
- * Perform the sync based on the file descriptor
- * The sync range will most probably be wider than the one
- * requested - but it will still get the job done
- */
-return qemu_fdatasync(fd);
-#endif /* CONFIG_POSIX */
-}
-
 static int64_t suffix_mul(char suffix, int64_t unit)
 {
 switch (qemu_toupper(suffix)) {
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index c471c5bc9f8d..161f1123259f 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -950,3 +950,21 @@ int fcntl_setfl(int fd, int flag)
 }
 return 0;
 }
+
+int qemu_msync(void *addr, size_t length, int fd)
+{
+size_t align_mask = ~(qemu_real_host_page_size() - 1);
+
+/**
+ * There are no strict reqs as per the length of mapping
+ * to be synced. Still the length needs to follow the address
+ * alignment changes. Additionally - round the size to the multiple
+ * of PAGE_SIZE
+ */
+length += ((uintptr_t)addr & (qemu_real_host_page_size() - 1));
+length = (length + ~align_mask) & align_mask;
+
+addr = (void *)((uintptr_t)addr & align_mask);
+
+return msync(addr, length, MS_SYNC);
+}
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index f38b06914e12..1e05c316b311 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -596,3 +596,13 @@ size_t qemu_get_host_physmem(void)
 }
 return 0;
 }
+
+int qemu_msync(void *addr, size_t length, int fd)
+{
+/**
+ * Perform the sync based on the file descriptor
+ * The sync range will most probably be wider than the one
+ * requested - but it will still get the job done
+ */
+return qemu_fdatasync(fd);
+}
-- 
2.36.0




[PULL 22/30] qga: move qga_get_host_name()

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

The function is specific to qemu-ga, no need to share it in QEMU.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Reviewed-by: Konstantin Kostiuk 
Message-Id: <20220420132624.2439741-32-marcandre.lur...@redhat.com>
---
 include/qemu/osdep.h  | 10 --
 qga/commands-common.h | 11 +++
 qga/commands-posix.c  | 35 +++
 qga/commands-win32.c  | 13 +
 qga/commands.c|  2 +-
 util/oslib-posix.c| 35 ---
 util/oslib-win32.c| 13 -
 7 files changed, 60 insertions(+), 59 deletions(-)

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index a87f1b7f32e6..4bf2883a60b3 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -656,16 +656,6 @@ int qemu_fdatasync(int fd);
  */
 int qemu_msync(void *addr, size_t length, int fd);
 
-/**
- * qemu_get_host_name:
- * @errp: Error object
- *
- * Operating system agnostic way of querying host name.
- *
- * Returns allocated hostname (caller should free), NULL on failure.
- */
-char *qemu_get_host_name(Error **errp);
-
 /**
  * qemu_get_host_physmem:
  *
diff --git a/qga/commands-common.h b/qga/commands-common.h
index 90785ed4bb7b..d0e4a9696f37 100644
--- a/qga/commands-common.h
+++ b/qga/commands-common.h
@@ -18,4 +18,15 @@ GuestFileHandle *guest_file_handle_find(int64_t id, Error 
**errp);
 GuestFileRead *guest_file_read_unsafe(GuestFileHandle *gfh,
   int64_t count, Error **errp);
 
+/**
+ * qga_get_host_name:
+ * @errp: Error object
+ *
+ * Operating system agnostic way of querying host name.
+ * Compared to g_get_host_name(), it doesn't cache the result.
+ *
+ * Returns allocated hostname (caller should free), NULL on failure.
+ */
+char *qga_get_host_name(Error **errp);
+
 #endif
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 390c1560e1b5..77f4672ca2c9 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -3278,3 +3278,38 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp)
 
 return NULL;
 }
+
+#ifndef HOST_NAME_MAX
+# ifdef _POSIX_HOST_NAME_MAX
+#  define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
+# else
+#  define HOST_NAME_MAX 255
+# endif
+#endif
+
+char *qga_get_host_name(Error **errp)
+{
+long len = -1;
+g_autofree char *hostname = NULL;
+
+#ifdef _SC_HOST_NAME_MAX
+len = sysconf(_SC_HOST_NAME_MAX);
+#endif /* _SC_HOST_NAME_MAX */
+
+if (len < 0) {
+len = HOST_NAME_MAX;
+}
+
+/* Unfortunately, gethostname() below does not guarantee a
+ * NULL terminated string. Therefore, allocate one byte more
+ * to be sure. */
+hostname = g_new0(char, len + 1);
+
+if (gethostname(hostname, len) < 0) {
+error_setg_errno(errp, errno,
+ "cannot get hostname");
+return NULL;
+}
+
+return g_steal_pointer(&hostname);
+}
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 406e4072a012..d56b5fd2a71c 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -2519,3 +2519,16 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp)
 }
 return head;
 }
+
+char *qga_get_host_name(Error **errp)
+{
+wchar_t tmp[MAX_COMPUTERNAME_LENGTH + 1];
+DWORD size = G_N_ELEMENTS(tmp);
+
+if (GetComputerNameW(tmp, &size) == 0) {
+error_setg_win32(errp, GetLastError(), "failed close handle");
+return NULL;
+}
+
+return g_utf16_to_utf8(tmp, size, NULL, NULL, NULL);
+}
diff --git a/qga/commands.c b/qga/commands.c
index 4e9ce25b2e73..690da0073d6e 100644
--- a/qga/commands.c
+++ b/qga/commands.c
@@ -511,7 +511,7 @@ int ga_parse_whence(GuestFileWhence *whence, Error **errp)
 GuestHostName *qmp_guest_get_host_name(Error **errp)
 {
 GuestHostName *result = NULL;
-g_autofree char *hostname = qemu_get_host_name(errp);
+g_autofree char *hostname = qga_get_host_name(errp);
 
 /*
  * We want to avoid using g_get_host_name() because that
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 161f1123259f..fd2bdc9ac7b3 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -886,41 +886,6 @@ void sigaction_invoke(struct sigaction *action,
 action->sa_sigaction(info->ssi_signo, &si, NULL);
 }
 
-#ifndef HOST_NAME_MAX
-# ifdef _POSIX_HOST_NAME_MAX
-#  define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
-# else
-#  define HOST_NAME_MAX 255
-# endif
-#endif
-
-char *qemu_get_host_name(Error **errp)
-{
-long len = -1;
-g_autofree char *hostname = NULL;
-
-#ifdef _SC_HOST_NAME_MAX
-len = sysconf(_SC_HOST_NAME_MAX);
-#endif /* _SC_HOST_NAME_MAX */
-
-if (len < 0) {
-len = HOST_NAME_MAX;
-}
-
-/* Unfortunately, gethostname() below does not guarantee a
- * NULL terminated string. Therefore, allocate one byte more
- * to be sure. */
-hostname = g_new0(char, len + 1);
-
-if (gethostname(hostname, len) < 0) {
-error_setg_errno(errp, errno,
-

[PULL 13/30] compiler.h: replace QEMU_NORETURN with G_NORETURN

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

G_NORETURN was introduced in glib 2.68, fallback to G_GNUC_NORETURN in
glib-compat.

Note that this attribute must be placed before the function declaration
(bringing a bit of consistency in qemu codebase usage).

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Reviewed-by: Warner Losh 
Message-Id: <20220420132624.2439741-20-marcandre.lur...@redhat.com>
---
 accel/tcg/internal.h |  3 +--
 include/exec/exec-all.h  | 20 +-
 include/exec/helper-head.h   |  2 +-
 include/glib-compat.h|  4 
 include/hw/core/cpu.h|  2 +-
 include/hw/core/tcg-cpu-ops.h|  6 +++---
 include/hw/hw.h  |  2 +-
 include/qemu/compiler.h  |  2 --
 include/qemu/osdep.h |  3 ++-
 include/qemu/thread.h|  2 +-
 include/tcg/tcg-ldst.h   |  4 ++--
 include/tcg/tcg.h|  2 +-
 linux-user/user-internals.h  |  2 +-
 scripts/cocci-macro-file.h   |  2 +-
 target/alpha/cpu.h   | 10 -
 target/arm/internals.h   | 12 +--
 target/hppa/cpu.h|  2 +-
 target/i386/tcg/helper-tcg.h | 24 ++---
 target/microblaze/cpu.h  |  6 +++---
 target/mips/tcg/tcg-internal.h   | 17 ---
 target/nios2/cpu.h   |  6 +++---
 target/openrisc/exception.h  |  2 +-
 target/ppc/cpu.h | 14 ++---
 target/ppc/internal.h|  6 +++---
 target/riscv/cpu.h   | 10 -
 target/s390x/s390x-internal.h|  6 +++---
 target/s390x/tcg/tcg_s390x.h | 12 +--
 target/sh4/cpu.h |  6 +++---
 target/sparc/cpu.h   | 10 -
 target/xtensa/cpu.h  |  6 +++---
 accel/stubs/tcg-stub.c   |  4 ++--
 bsd-user/signal.c|  3 ++-
 hw/misc/mips_itu.c   |  3 ++-
 linux-user/signal.c  |  3 ++-
 monitor/hmp.c|  4 ++--
 qemu-img.c   | 12 +++
 target/alpha/helper.c| 10 -
 target/arm/pauth_helper.c|  4 ++--
 target/arm/tlb_helper.c  |  7 ---
 target/hexagon/op_helper.c   |  9 
 target/hppa/cpu.c|  8 +++
 target/hppa/op_helper.c  |  4 ++--
 target/i386/tcg/bpt_helper.c |  2 +-
 target/i386/tcg/excp_helper.c| 31 ++--
 target/i386/tcg/misc_helper.c|  6 +++---
 target/i386/tcg/sysemu/misc_helper.c |  7 ---
 target/openrisc/exception.c  |  2 +-
 target/openrisc/exception_helper.c   |  3 ++-
 target/riscv/op_helper.c |  4 ++--
 target/rx/op_helper.c| 22 +++-
 target/s390x/tcg/excp_helper.c   | 22 +++-
 target/sh4/op_helper.c   |  5 +++--
 target/sparc/mmu_helper.c|  8 +++
 target/tricore/op_helper.c   |  6 +++---
 tcg/tcg.c|  3 ++-
 tests/fp/fp-bench.c  |  3 ++-
 tests/fp/fp-test.c   |  3 ++-
 scripts/checkpatch.pl|  2 +-
 58 files changed, 214 insertions(+), 191 deletions(-)

diff --git a/accel/tcg/internal.h b/accel/tcg/internal.h
index 881bc1ede0b1..3092bfa96430 100644
--- a/accel/tcg/internal.h
+++ b/accel/tcg/internal.h
@@ -14,8 +14,7 @@
 TranslationBlock *tb_gen_code(CPUState *cpu, target_ulong pc,
   target_ulong cs_base, uint32_t flags,
   int cflags);
-
-void QEMU_NORETURN cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);
+G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);
 void page_init(void);
 void tb_htable_init(void);
 
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index d2cb0981f405..311e5fb422a3 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -58,10 +58,10 @@ void restore_state_to_opc(CPUArchState *env, 
TranslationBlock *tb,
  */
 bool cpu_restore_state(CPUState *cpu, uintptr_t searched_pc, bool will_exit);
 
-void QEMU_NORETURN cpu_loop_exit_noexc(CPUState *cpu);
-void QEMU_NORETURN cpu_loop_exit(CPUState *cpu);
-void QEMU_NORETURN cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc);
-void QEMU_NORETURN cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc);
+G_NORETURN void cpu_loop_exit_noexc(CPUState *cpu);
+G_NORETURN void cpu_loop_exit(CPUState *cpu);
+G_NORETURN void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc);
+G_NORETURN void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc);
 
 /**
  * cpu_loop_exit_requested:
@@ -669,9 +669,9 @@ bool handle_sigsegv_accerr_write(CPUState *cpu, sigset_t 
*old_set,
  * Use the TCGCPUOps hook to record cpu state, do guest operating system
  * specific things to raise SIGSEGV, and ju

[PULL 08/30] arm/digic: replace snprintf() with g_strdup_printf()

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

Also fixes a GCC 12.0.1 false-positive:
../hw/arm/digic.c: In function ‘digic_init’:
../hw/arm/digic.c:45:54: error: ‘%d’ directive output may be truncated writing 
between 1 and 11 bytes into a region of size 5 [-Werror=format-truncation=]
   45 | snprintf(name, DIGIC_TIMER_NAME_MLEN, "timer[%d]", i);
  |  ^~

Signed-off-by: Marc-André Lureau 
Reviewed-by: Peter Maydell 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-14-marcandre.lur...@redhat.com>
---
 hw/arm/digic.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/hw/arm/digic.c b/hw/arm/digic.c
index 614232165cdc..6df554797734 100644
--- a/hw/arm/digic.c
+++ b/hw/arm/digic.c
@@ -39,10 +39,7 @@ static void digic_init(Object *obj)
 object_initialize_child(obj, "cpu", &s->cpu, ARM_CPU_TYPE_NAME("arm946"));
 
 for (i = 0; i < DIGIC4_NB_TIMERS; i++) {
-#define DIGIC_TIMER_NAME_MLEN11
-char name[DIGIC_TIMER_NAME_MLEN];
-
-snprintf(name, DIGIC_TIMER_NAME_MLEN, "timer[%d]", i);
+g_autofree char *name = g_strdup_printf("timer[%d]", i);
 object_initialize_child(obj, name, &s->timer[i], TYPE_DIGIC_TIMER);
 }
 
-- 
2.36.0




[PULL 16/30] include: add qemu/keyval.h

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

Do not require the whole option machinery to handle keyval, as it is
used by QAPI alone, without the option API. And match the associated
unit name.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-24-marcandre.lur...@redhat.com>
---
 include/qemu/keyval.h | 14 ++
 include/qemu/option.h |  6 --
 qapi/qobject-input-visitor.c  |  2 +-
 qom/object_interfaces.c   |  1 +
 softmmu/vl.c  |  1 +
 tests/unit/check-qom-proplist.c   |  1 +
 tests/unit/test-forward-visitor.c |  2 +-
 tests/unit/test-keyval.c  |  2 +-
 util/keyval.c |  2 +-
 9 files changed, 21 insertions(+), 10 deletions(-)
 create mode 100644 include/qemu/keyval.h

diff --git a/include/qemu/keyval.h b/include/qemu/keyval.h
new file mode 100644
index ..2d263286d7c5
--- /dev/null
+++ b/include/qemu/keyval.h
@@ -0,0 +1,14 @@
+/*
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#ifndef KEYVAL_H_
+#define KEYVAL_H_
+
+QDict *keyval_parse_into(QDict *qdict, const char *params, const char 
*implied_key,
+ bool *p_help, Error **errp);
+QDict *keyval_parse(const char *params, const char *implied_key,
+bool *help, Error **errp);
+void keyval_merge(QDict *old, const QDict *new, Error **errp);
+
+#endif /* KEYVAL_H_ */
diff --git a/include/qemu/option.h b/include/qemu/option.h
index bbd86e1c4eab..b34982878238 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -144,12 +144,6 @@ void qemu_opts_print_help(QemuOptsList *list, bool 
print_caption);
 void qemu_opts_free(QemuOptsList *list);
 QemuOptsList *qemu_opts_append(QemuOptsList *dst, QemuOptsList *list);
 
-QDict *keyval_parse_into(QDict *qdict, const char *params, const char 
*implied_key,
- bool *p_help, Error **errp);
-QDict *keyval_parse(const char *params, const char *implied_key,
-bool *help, Error **errp);
-void keyval_merge(QDict *old, const QDict *new, Error **errp);
-
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuOpts, qemu_opts_del)
 
 #endif
diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c
index f0b4c7ca9d39..3e8aca6b1594 100644
--- a/qapi/qobject-input-visitor.c
+++ b/qapi/qobject-input-visitor.c
@@ -28,7 +28,7 @@
 #include "qapi/qmp/qnum.h"
 #include "qapi/qmp/qstring.h"
 #include "qemu/cutils.h"
-#include "qemu/option.h"
+#include "qemu/keyval.h"
 
 typedef struct StackObject {
 const char *name;/* Name of @obj in its parent, if any */
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index 3b61c195c53d..f94b6c319312 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -17,6 +17,7 @@
 #include "qemu/qemu-print.h"
 #include "qapi/opts-visitor.h"
 #include "qemu/config-file.h"
+#include "qemu/keyval.h"
 
 bool user_creatable_complete(UserCreatable *uc, Error **errp)
 {
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 2a38ebe5fbb4..5312bd25649f 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -128,6 +128,7 @@
 #include "qapi/qmp/qerror.h"
 #include "sysemu/iothread.h"
 #include "qemu/guest-random.h"
+#include "qemu/keyval.h"
 
 #include "config-host.h"
 
diff --git a/tests/unit/check-qom-proplist.c b/tests/unit/check-qom-proplist.c
index ed341088d35f..79d4a8b89d38 100644
--- a/tests/unit/check-qom-proplist.c
+++ b/tests/unit/check-qom-proplist.c
@@ -27,6 +27,7 @@
 #include "qom/object.h"
 #include "qemu/module.h"
 #include "qemu/option.h"
+#include "qemu/keyval.h"
 #include "qemu/config-file.h"
 #include "qom/object_interfaces.h"
 
diff --git a/tests/unit/test-forward-visitor.c 
b/tests/unit/test-forward-visitor.c
index 01de15522711..eea8ffc0720e 100644
--- a/tests/unit/test-forward-visitor.c
+++ b/tests/unit/test-forward-visitor.c
@@ -15,7 +15,7 @@
 #include "qapi/qmp/qobject.h"
 #include "qapi/qmp/qdict.h"
 #include "test-qapi-visit.h"
-#include "qemu/option.h"
+#include "qemu/keyval.h"
 
 typedef bool GenericVisitor (Visitor *, const char *, void **, Error **);
 #define CAST_VISIT_TYPE(fn) ((GenericVisitor *)(fn))
diff --git a/tests/unit/test-keyval.c b/tests/unit/test-keyval.c
index af0581ae6c5b..4dc52c7a1a8b 100644
--- a/tests/unit/test-keyval.c
+++ b/tests/unit/test-keyval.c
@@ -19,7 +19,7 @@
 #include "qapi/qobject-input-visitor.h"
 #include "test-qapi-visit.h"
 #include "qemu/cutils.h"
-#include "qemu/option.h"
+#include "qemu/keyval.h"
 
 static void test_keyval_parse(void)
 {
diff --git a/util/keyval.c b/util/keyval.c
index 0cf2e84dc8d8..66a5b4740f12 100644
--- a/util/keyval.c
+++ b/util/keyval.c
@@ -95,8 +95,8 @@
 #include "qapi/qmp/qlist.h"
 #include "qapi/qmp/qstring.h"
 #include "qemu/cutils.h"
+#include "qemu/keyval.h"
 #include "qemu/help_option.h"
-#include "qemu/option.h"
 
 /*
  * Convert @key to a list index.
-- 
2.36.0




[PULL 24/30] util: simplify write in signal handler

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

Use qemu_write_full() instead of open-coding a write loop.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-36-marcandre.lur...@redhat.com>
---
 util/compatfd.c | 18 ++
 1 file changed, 2 insertions(+), 16 deletions(-)

diff --git a/util/compatfd.c b/util/compatfd.c
index ab810c42a927..55b6e0b7fb27 100644
--- a/util/compatfd.c
+++ b/util/compatfd.c
@@ -42,25 +42,11 @@ static void *sigwait_compat(void *opaque)
 }
 } else {
 struct qemu_signalfd_siginfo buffer;
-size_t offset = 0;
-
 memset(&buffer, 0, sizeof(buffer));
 buffer.ssi_signo = sig;
 
-while (offset < sizeof(buffer)) {
-ssize_t len;
-
-len = write(info->fd, (char *)&buffer + offset,
-sizeof(buffer) - offset);
-if (len == -1 && errno == EINTR) {
-continue;
-}
-
-if (len <= 0) {
-return NULL;
-}
-
-offset += len;
+if (qemu_write_full(info->fd, &buffer, sizeof(buffer)) != 
sizeof(buffer)) {
+return NULL;
 }
 }
 }
-- 
2.36.0




[PULL 17/30] include: move qdict_{crumple,flatten} declarations

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

Move them where they belong, since the functions are implemented in 
block-qdict.c.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-25-marcandre.lur...@redhat.com>
---
 include/block/qdict.h  | 3 +++
 include/qapi/qmp/qdict.h   | 3 ---
 softmmu/vl.c   | 1 +
 tests/unit/check-qobject.c | 1 +
 4 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/include/block/qdict.h b/include/block/qdict.h
index ced2acfb92a0..b4c28d96a9e5 100644
--- a/include/block/qdict.h
+++ b/include/block/qdict.h
@@ -12,6 +12,9 @@
 
 #include "qapi/qmp/qdict.h"
 
+QObject *qdict_crumple(const QDict *src, Error **errp);
+void qdict_flatten(QDict *qdict);
+
 void qdict_copy_default(QDict *dst, QDict *src, const char *key);
 void qdict_set_default_str(QDict *dst, const char *key, const char *val);
 
diff --git a/include/qapi/qmp/qdict.h b/include/qapi/qmp/qdict.h
index 882d950bde89..82e90fc07229 100644
--- a/include/qapi/qmp/qdict.h
+++ b/include/qapi/qmp/qdict.h
@@ -68,7 +68,4 @@ const char *qdict_get_try_str(const QDict *qdict, const char 
*key);
 
 QDict *qdict_clone_shallow(const QDict *src);
 
-QObject *qdict_crumple(const QDict *src, Error **errp);
-void qdict_flatten(QDict *qdict);
-
 #endif /* QDICT_H */
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 5312bd25649f..06a0e342fe9e 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -125,6 +125,7 @@
 #include "qapi/qapi-visit-qom.h"
 #include "qapi/qapi-commands-ui.h"
 #include "qapi/qmp/qdict.h"
+#include "block/qdict.h"
 #include "qapi/qmp/qerror.h"
 #include "sysemu/iothread.h"
 #include "qemu/guest-random.h"
diff --git a/tests/unit/check-qobject.c b/tests/unit/check-qobject.c
index 0ed094e55f3a..c5e850a10cb5 100644
--- a/tests/unit/check-qobject.c
+++ b/tests/unit/check-qobject.c
@@ -15,6 +15,7 @@
 #include "qapi/qmp/qnull.h"
 #include "qapi/qmp/qnum.h"
 #include "qapi/qmp/qstring.h"
+#include "block/qdict.h"
 
 #include 
 
-- 
2.36.0




[PULL 11/30] doc/style: CLang -> Clang

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

It's not the way it is usually written (see https://clang.llvm.org/).

Signed-off-by: Marc-André Lureau 
Reviewed-by: Damien Hedde 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-17-marcandre.lur...@redhat.com>
---
 docs/devel/style.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/docs/devel/style.rst b/docs/devel/style.rst
index 9e66d133e15b..7ddd42b6c2c8 100644
--- a/docs/devel/style.rst
+++ b/docs/devel/style.rst
@@ -522,7 +522,7 @@ documented in the GNU Compiler Collection manual starting 
at version 4.0.
 Automatic memory deallocation
 =
 
-QEMU has a mandatory dependency either the GCC or CLang compiler. As
+QEMU has a mandatory dependency on either the GCC or the Clang compiler. As
 such it has the freedom to make use of a C language extension for
 automatically running a cleanup function when a stack variable goes
 out of scope. This can be used to simplify function cleanup paths,
-- 
2.36.0




[PULL 18/30] tests: remove block/qdict checks from check-qobject.c

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

The functions are already covered in check-block-qdict.c.
This will help moving QAPI-related tests in a common subproject.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-26-marcandre.lur...@redhat.com>
---
 tests/unit/check-qobject.c | 8 
 1 file changed, 8 deletions(-)

diff --git a/tests/unit/check-qobject.c b/tests/unit/check-qobject.c
index c5e850a10cb5..022b7c74fe57 100644
--- a/tests/unit/check-qobject.c
+++ b/tests/unit/check-qobject.c
@@ -15,7 +15,6 @@
 #include "qapi/qmp/qnull.h"
 #include "qapi/qmp/qnum.h"
 #include "qapi/qmp/qstring.h"
-#include "block/qdict.h"
 
 #include 
 
@@ -179,7 +178,6 @@ static void qobject_is_equal_list_test(void)
 static void qobject_is_equal_dict_test(void)
 {
 g_autoptr(QDict) dict_cloned = NULL;
-g_autoptr(QDict) dict_crumpled = NULL;
 g_autoptr(QDict) dict_0 = qdict_new();
 g_autoptr(QDict) dict_1 = qdict_new();
 g_autoptr(QDict) dict_different_key = qdict_new();
@@ -237,12 +235,6 @@ static void qobject_is_equal_dict_test(void)
   dict_different_null_key, dict_longer, dict_shorter,
   dict_nested);
 
-dict_crumpled = qobject_to(QDict, qdict_crumple(dict_1, &error_abort));
-check_equal(dict_crumpled, dict_nested);
-
-qdict_flatten(dict_nested);
-check_equal(dict_0, dict_nested);
-
 /* Containing an NaN value will make this dict compare unequal to
  * itself */
 qdict_put(dict_0, "NaN", qnum_from_double(NAN));
-- 
2.36.0




[PULL 29/30] tests/fuzz: fix warning

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

../tests/qtest/fuzz/generic_fuzz.c:746:17: warning: variable 'name' set but not 
used [-Wunused-but-set-variable]

Signed-off-by: Marc-André Lureau 
Reviewed-by: Thomas Huth 
Message-Id: <20220420132624.2439741-42-marcandre.lur...@redhat.com>
---
 tests/qtest/fuzz/generic_fuzz.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/tests/qtest/fuzz/generic_fuzz.c b/tests/qtest/fuzz/generic_fuzz.c
index dd7e25851cb6..bce83604825e 100644
--- a/tests/qtest/fuzz/generic_fuzz.c
+++ b/tests/qtest/fuzz/generic_fuzz.c
@@ -743,14 +743,12 @@ static void usage(void)
 
 static int locate_fuzz_memory_regions(Object *child, void *opaque)
 {
-const char *name;
 MemoryRegion *mr;
 if (object_dynamic_cast(child, TYPE_MEMORY_REGION)) {
 mr = MEMORY_REGION(child);
 if ((memory_region_is_ram(mr) ||
 memory_region_is_ram_device(mr) ||
 memory_region_is_rom(mr)) == false) {
-name = object_get_canonical_path_component(child);
 /*
  * We don't want duplicate pointers to the same MemoryRegion, so
  * try to remove copies of the pointer, before adding it.
-- 
2.36.0




[PULL 19/30] compiler.h: add QEMU_SANITIZE_{ADDRESS,THREAD}

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

Simplify a bit pre-compiler conditions.

For TSAN, QEMU already has CONFIG_TSAN, but it is only set when the
fiber API is present. (I wonder whether supporting TSAN without the
fiber API is really relevant)

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-27-marcandre.lur...@redhat.com>
---
 include/qemu/compiler.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index f12c0fb581ec..f20a76e4a286 100644
--- a/include/qemu/compiler.h
+++ b/include/qemu/compiler.h
@@ -106,6 +106,14 @@
 #define __has_attribute(x) 0 /* compatibility with older GCC */
 #endif
 
+#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)
+# define QEMU_SANITIZE_ADDRESS 1
+#endif
+
+#if defined(__SANITIZE_THREAD__) || __has_feature(thread_sanitizer)
+# define QEMU_SANITIZE_THREAD 1
+#endif
+
 /*
  * GCC doesn't provide __has_attribute() until GCC 5, but we know all the GCC
  * versions we support have the "flatten" attribute. Clang may not have the
-- 
2.36.0




[PULL 20/30] tests: run-time skip test-qga if TSAN is enabled

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

This allows to make sure the test is still built, and gives more
accurate report details.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-30-marcandre.lur...@redhat.com>
---
 tests/unit/test-qga.c  | 7 +++
 tests/unit/meson.build | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c
index 5cb140d1b53d..e17a288034bc 100644
--- a/tests/unit/test-qga.c
+++ b/tests/unit/test-qga.c
@@ -969,6 +969,13 @@ int main(int argc, char **argv)
 TestFixture fix;
 int ret;
 
+#ifdef QEMU_SANITIZE_THREAD
+{
+g_test_skip("tsan enabled, 
https://github.com/google/sanitizers/issues/1116";);
+return 0;
+}
+#endif
+
 setlocale (LC_ALL, "");
 g_test_init(&argc, &argv, NULL);
 fixture_setup(&fix, NULL, NULL);
diff --git a/tests/unit/meson.build b/tests/unit/meson.build
index 026e39f52025..ab01e00f12cf 100644
--- a/tests/unit/meson.build
+++ b/tests/unit/meson.build
@@ -153,7 +153,7 @@ if have_system
   endif
 endif
 
-if have_ga and targetos == 'linux' and 'CONFIG_TSAN' not in config_host
+if have_ga and targetos == 'linux'
   tests += {'test-qga': ['../qtest/libqtest.c']}
   test_deps += {'test-qga': qga}
 endif
-- 
2.36.0




Re: [PULL 00/23] ppc queue

2022-04-21 Thread Richard Henderson

On 4/20/22 15:13, Daniel Henrique Barboza wrote:

The following changes since commit 2d20a57453f6a206938cbbf77bed0b378c806c1f:

   Merge tag 'pull-fixes-for-7.1-200422-1' of https://github.com/stsquad/qemu 
into staging (2022-04-20 11:13:08 -0700)

are available in the Git repository at:

   https://gitlab.com/danielhb/qemu.git tags/pull-ppc-20220420-2

for you to fetch changes up to 2d94af4b16c40758eee3a8591307ae173090d4ad:

   hw/ppc: change indentation to spaces from TABs (2022-04-20 18:00:30 -0300)


ppc patch queue for 2022-04-20

First batch of ppc patches for QEMU 7.1:

- skiboot firmware version bump
- pseries: add 2M DDW pagesize
- pseries: make virtual hypervisor code TCG only
- powernv: introduce GPIO lines for PSIHB device
- powernv: remove PCIE root bridge LSI
- target/ppc: alternative softfloat 128 bit integer support
- assorted fixes


Applied, thanks.  Please update the wiki changelog for 7.1 as appropriate.


r~




Alexey Kardashevskiy (2):
   ppc/spapr/ddw: Add 2M pagesize
   ppc/vof: Fix uninitialized string tracing

Bernhard Beschow (1):
   hw/ppc/ppc405_boards: Initialize g_autofree pointer

Cédric Le Goater (5):
   ppc/pnv: Fix PSI IRQ definition
   ppc/pnv: Remove PnvLpcController::psi link
   ppc/pnv: Remove PnvOCC::psi link
   ppc/pnv: Remove PnvPsiClas::irq_set
   ppc/pnv: Remove useless checks in set_irq handlers

Fabiano Rosas (3):
   spapr: Move hypercall_register_softmmu
   spapr: Move nested KVM hypercalls under a TCG only config.
   target/ppc: Improve KVM hypercall trace

Frederic Barrat (3):
   pcie: Don't try triggering a LSI when not defined
   ppc/pnv: Remove LSI on the PCIE host bridge
   target/ppc: Add two missing register callbacks on POWER10

Guo Zhi (1):
   hw/ppc: change indentation to spaces from TABs

Joel Stanley (1):
   ppc/pnv: Update skiboot to v7.0

Matheus Ferst (7):
   qemu/int128: add int128_urshift
   softfloat: add uint128_to_float128
   softfloat: add int128_to_float128
   softfloat: add float128_to_uint128
   softfloat: add float128_to_int128
   target/ppc: implement xscv[su]qqp
   target/ppc: implement xscvqp[su]qz

  fpu/softfloat.c | 183 
  hw/pci-host/pnv_phb3.c  |   1 +
  hw/pci-host/pnv_phb4.c  |   1 +
  hw/pci/pcie.c   |   5 +-
  hw/pci/pcie_aer.c   |   2 +-
  hw/ppc/pnv.c|  30 +++---
  hw/ppc/pnv_lpc.c|  19 +---
  hw/ppc/pnv_occ.c|  16 +---
  hw/ppc/pnv_psi.c|  36 +++
  hw/ppc/ppc405_boards.c  |   4 +-
  hw/ppc/ppc440_bamboo.c  |   6 +-
  hw/ppc/spapr_hcall.c|  74 +--
  hw/ppc/spapr_rtas.c |  18 ++--
  hw/ppc/spapr_rtas_ddw.c |   1 +
  hw/ppc/vof.c|   2 +-
  include/fpu/softfloat.h |   7 ++
  include/hw/ppc/pnv_lpc.h|   8 +-
  include/hw/ppc/pnv_occ.h|   7 +-
  include/hw/ppc/pnv_psi.h|   7 +-
  include/hw/ppc/ppc.h|  10 +-
  include/hw/ppc/spapr.h  |   1 +
  include/qemu/int128.h   |  21 +
  pc-bios/skiboot.lid | Bin 2528128 -> 2527240 bytes
  roms/skiboot|   2 +-
  target/ppc/cpu_init.c   |   2 +
  target/ppc/fpu_helper.c |  33 +++
  target/ppc/helper.h |   4 +
  target/ppc/insn32.decode|   7 ++
  target/ppc/kvm.c|   2 +-
  target/ppc/trace-events |   2 +-
  target/ppc/translate/vsx-impl.c.inc |  22 +
  tests/unit/test-int128.c|  50 ++
  32 files changed, 446 insertions(+), 137 deletions(-)





[PULL 28/30] qga: remove need for QEMU atomic.h

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

Since the introduction of guest-exec in/out/err redirections in commit
a1853dca74 ("qga: guest-exec simple stdin/stdout/stderr redirection"),
some execution state variables are handled with atomic ops. However,
there are no threads involved in this code (and glib sources are
dispatched in the same thread), and no other obvious reason to use them.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-40-marcandre.lur...@redhat.com>
---
 qga/commands.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/qga/commands.c b/qga/commands.c
index 690da0073d6e..7ff551d092a1 100644
--- a/qga/commands.c
+++ b/qga/commands.c
@@ -18,7 +18,6 @@
 #include "qapi/qmp/qerror.h"
 #include "qemu/base64.h"
 #include "qemu/cutils.h"
-#include "qemu/atomic.h"
 #include "commands-common.h"
 
 /* Maximum captured guest-exec out_data/err_data - 16MB */
@@ -162,13 +161,12 @@ GuestExecStatus *qmp_guest_exec_status(int64_t pid, Error 
**errp)
 
 ges = g_new0(GuestExecStatus, 1);
 
-bool finished = qatomic_mb_read(&gei->finished);
+bool finished = gei->finished;
 
 /* need to wait till output channels are closed
  * to be sure we captured all output at this point */
 if (gei->has_output) {
-finished = finished && qatomic_mb_read(&gei->out.closed);
-finished = finished && qatomic_mb_read(&gei->err.closed);
+finished &= gei->out.closed && gei->err.closed;
 }
 
 ges->exited = finished;
@@ -270,7 +268,7 @@ static void guest_exec_child_watch(GPid pid, gint status, 
gpointer data)
 (int32_t)gpid_to_int64(pid), (uint32_t)status);
 
 gei->status = status;
-qatomic_mb_set(&gei->finished, true);
+gei->finished = true;
 
 g_spawn_close_pid(pid);
 }
@@ -326,7 +324,7 @@ static gboolean guest_exec_input_watch(GIOChannel *ch,
 done:
 g_io_channel_shutdown(ch, true, NULL);
 g_io_channel_unref(ch);
-qatomic_mb_set(&p->closed, true);
+p->closed = true;
 g_free(p->data);
 
 return false;
@@ -380,7 +378,7 @@ static gboolean guest_exec_output_watch(GIOChannel *ch,
 close:
 g_io_channel_shutdown(ch, true, NULL);
 g_io_channel_unref(ch);
-qatomic_mb_set(&p->closed, true);
+p->closed = true;
 return false;
 }
 
-- 
2.36.0




[PULL 25/30] util: use qemu_write_full() in qemu_write_pidfile()

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

Mostly for correctness.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-37-marcandre.lur...@redhat.com>
---
 util/oslib-posix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index fd2bdc9ac7b3..9751bc6be9d7 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -184,7 +184,7 @@ bool qemu_write_pidfile(const char *path, Error **errp)
 }
 
 snprintf(pidstr, sizeof(pidstr), FMT_pid "\n", getpid());
-if (write(fd, pidstr, strlen(pidstr)) != strlen(pidstr)) {
+if (qemu_write_full(fd, pidstr, strlen(pidstr)) != strlen(pidstr)) {
 error_setg(errp, "Failed to write pid file");
 goto fail_unlink;
 }
-- 
2.36.0




[PULL 23/30] qtest: simplify socket_send()

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

Reuse qemu_write_full().

Signed-off-by: Marc-André Lureau 
Reviewed-by: Thomas Huth 
Message-Id: <20220420132624.2439741-33-marcandre.lur...@redhat.com>
---
 tests/qtest/libqtest.c | 16 ++--
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 7b5890dcc487..2b9bdb947d6f 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -414,21 +414,9 @@ void qtest_quit(QTestState *s)
 
 static void socket_send(int fd, const char *buf, size_t size)
 {
-size_t offset;
-
-offset = 0;
-while (offset < size) {
-ssize_t len;
+size_t res = qemu_write_full(fd, buf, size);
 
-len = write(fd, buf + offset, size - offset);
-if (len == -1 && errno == EINTR) {
-continue;
-}
-
-g_assert_cmpint(len, >, 0);
-
-offset += len;
-}
+assert(res == size);
 }
 
 static void qtest_client_socket_send(QTestState *s, const char *buf)
-- 
2.36.0




Re: [PATCH v4 00/19] migration: Postcopy Preemption

2022-04-21 Thread Dr. David Alan Gilbert
* Peter Xu (pet...@redhat.com) wrote:
> This is v4 of postcopy preempt series.  It can also be found here:
> 
>   https://github.com/xzpeter/qemu/tree/postcopy-preempt
> 
> RFC: 
> https://lore.kernel.org/qemu-devel/20220119080929.39485-1-pet...@redhat.com
> V1:  
> https://lore.kernel.org/qemu-devel/20220216062809.57179-1-pet...@redhat.com
> V2:  
> https://lore.kernel.org/qemu-devel/20220301083925.33483-1-pet...@redhat.com
> V3:  
> https://lore.kernel.org/qemu-devel/20220330213908.26608-1-pet...@redhat.com

I've queued:
migration: Allow migrate-recover to run multiple times
migration: Move channel setup out of postcopy_try_recover()
migration: Export ram_load_postcopy()
migration: Move migrate_allow_multifd and helpers into migration.c
migration: Add pss.postcopy_requested status
migration: Drop multifd tls_hostname cache
migration: Postpone releasing MigrationState.hostname

> v4:
> - Fix a double-free on params.tls-creds when quitting qemu
> - Reorder patches to satisfy per-commit builds
> 
> v3:
> - Rebased to master since many patches landed
> - Fixed one bug on postcopy recovery when preempt enabled, this is only
>   found when I test with TLS+recovery, because TLS changed the timing.
> - Dropped patch:
>   "migration: Fail postcopy preempt with TLS for now"
> - Added patches for TLS:
>   - "migration: Postpone releasing MigrationState.hostname"
>   - "migration: Drop multifd tls_hostname cache"
>   - "migration: Enable TLS for preempt channel"
>   - "migration: Export tls-[creds|hostname|authz] params to cmdline too"
>   - "tests: Add postcopy tls migration test"
>   - "tests: Add postcopy tls recovery migration test"
> - Added two more tests to the preempt test patch (tls, tls+recovery)
> 
> Abstract
> 
> 
> This series added a new migration capability called "postcopy-preempt".  It 
> can
> be enabled when postcopy is enabled, and it'll simply (but greatly) speed up
> postcopy page requests handling process.
> 
> Below are some initial postcopy page request latency measurements after the
> new series applied.
> 
> For each page size, I measured page request latency for three cases:
> 
>   (a) Vanilla:the old postcopy
>   (b) Preempt no-break-huge:  preempt enabled, 
> x-postcopy-preempt-break-huge=off
>   (c) Preempt full:   preempt enabled, 
> x-postcopy-preempt-break-huge=on
>   (this is the default option when preempt 
> enabled)
> 
> Here x-postcopy-preempt-break-huge parameter is just added in v2 so as to
> conditionally disable the behavior to break sending a precopy huge page for
> debugging purpose.  So when it's off, postcopy will not preempt precopy
> sending a huge page, but still postcopy will use its own channel.
> 
> I tested it separately to give a rough idea on which part of the change
> helped how much of it.  The overall benefit should be the comparison
> between case (a) and (c).
> 
>   |---+-+---+--|
>   | Page size | Vanilla | Preempt no-break-huge | Preempt full |
>   |---+-+---+--|
>   | 4K|   10.68 |   N/A [*] | 0.57 |
>   | 2M|   10.58 |  5.49 | 5.02 |
>   | 1G| 2046.65 |   933.185 |  649.445 |
>   |---+-+---+--|
>   [*]: This case is N/A because 4K page does not contain huge page at all
> 
> [1] 
> https://github.com/xzpeter/small-stuffs/blob/master/tools/huge_vm/uffd-latency.bpf
> 
> TODO List
> =
> 
> Avoid precopy write() blocks postcopy
> -
> 
> I didn't prove this, but I always think the write() syscalls being blocked
> for precopy pages can affect postcopy services.  If we can solve this
> problem then my wild guess is we can further reduce the average page
> latency.
> 
> Two solutions at least in mind: (1) we could have made the write side of
> the migration channel NON_BLOCK too, or (2) multi-threads on send side,
> just like multifd, but we may use lock to protect which page to send too
> (e.g., the core idea is we should _never_ rely anything on the main thread,
> multifd has that dependency on queuing pages only on main thread).
> 
> That can definitely be done and thought about later.
> 
> Multi-channel for preemption threads
> 
> 
> Currently the postcopy preempt feature use only one extra channel and one
> extra thread on dest (no new thread on src QEMU).  It should be mostly good
> enough for major use cases, but when the postcopy queue is long enough
> (e.g. hundreds of vCPUs faulted on different pages) logically we could
> still observe more delays in average.  Whether growing threads/channels can
> solve it is debatable, but sounds worthwhile a try.  That's yet another
> thing we can think about after this patchset lands.
> 
> Logically the design provides space for that - the receiving pos

[PULL 26/30] util: use qemu_create() in qemu_write_pidfile()

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

qemu_open_old(O_CREATE) should be replaced with qemu_create() which
handles Error reporting.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-38-marcandre.lur...@redhat.com>
---
 util/oslib-posix.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 9751bc6be9d7..bcb35c3c8246 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -138,9 +138,8 @@ bool qemu_write_pidfile(const char *path, Error **errp)
 .l_len = 0,
 };
 
-fd = qemu_open_old(path, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
+fd = qemu_create(path, O_WRONLY, S_IRUSR | S_IWUSR, errp);
 if (fd == -1) {
-error_setg_errno(errp, errno, "Cannot open pid file");
 return false;
 }
 
-- 
2.36.0




Re: [RFC PATCH] tests/qtest: pass stdout/stderr down to subtests

2022-04-21 Thread Alex Bennée


Stefan Hajnoczi  writes:

> [[PGP Signed Part:Undecided]]
> On Thu, Apr 14, 2022 at 07:25:54PM +0200, Eric Auger wrote:
>> Hi Alex,
>> 
>> On 4/7/22 5:00 PM, Alex Bennée wrote:
>> > When trying to work out what the virtio-net-tests where doing it was
>> > hard because the g_test_trap_subprocess redirects all output to
>> > /dev/null. Lift this restriction by using the appropriate flags so you
>> > can see something similar to what the vhost-user-blk tests show when
>> > running.
>> > 
>> > While we are at it remove the g_test_verbose() check so we always show
>> > how the QEMU is run.
>> > 
>> > Signed-off-by: Alex Bennée 
>> > ---
>> >  tests/qtest/qos-test.c | 7 +++
>> >  1 file changed, 3 insertions(+), 4 deletions(-)
>> > 
>> > diff --git a/tests/qtest/qos-test.c b/tests/qtest/qos-test.c
>> > index f97d0a08fd..c6c196cc95 100644
>> > --- a/tests/qtest/qos-test.c
>> > +++ b/tests/qtest/qos-test.c
>> > @@ -89,9 +89,7 @@ static void qos_set_machines_devices_available(void)
>> >  
>> >  static void restart_qemu_or_continue(char *path)
>> >  {
>> > -if (g_test_verbose()) {
>> > -qos_printf("Run QEMU with: '%s'\n", path);
>> > -}
>> > +qos_printf("Run QEMU with: '%s'\n", path);
>> >  /* compares the current command line with the
>> >   * one previously executed: if they are the same,
>> >   * don't restart QEMU, if they differ, stop previous
>> > @@ -185,7 +183,8 @@ static void run_one_test(const void *arg)
>> >  static void subprocess_run_one_test(const void *arg)
>> >  {
>> >  const gchar *path = arg;
>> > -g_test_trap_subprocess(path, 0, 0);
>> > +g_test_trap_subprocess(path, 0,
>> > +   G_TEST_SUBPROCESS_INHERIT_STDOUT | 
>> > G_TEST_SUBPROCESS_INHERIT_STDERR);
>> While workling on libqos/pci tests on aarch64 I also did that but I
>> noticed there were a bunch of errors such as:
>> 
>> /aarch64/virt/generic-pcihost/pci-bus-generic/pci-bus/virtio-net-pci/virtio-net/virtio-net-tests/vhost-user/multiqueue:
>> qemu-system-aarch64: Failed to set msg fds.
>> qemu-system-aarch64: vhost VQ 0 ring restore failed: -22: Invalid
>> argument (22)
>> qemu-system-aarch64: Failed to set msg fds.
>> qemu-system-aarch64: vhost VQ 1 ring restore failed: -22: Invalid
>> argument (22)
>> qemu-system-aarch64: Failed to set msg fds.
>> qemu-system-aarch64: vhost VQ 2 ring restore failed: -22: Invalid
>> argument (22)
>> qemu-system-aarch64: Failed to set msg fds.
>> qemu-system-aarch64: vhost VQ 3 ring restore failed: -22: Invalid
>> argument (22)
>> 
>> I see those also when running with x86_64-softmmu/qemu-system-x86_64
>> (this is no aarch64 specific).

I think it's a case of things not being cleanly taken down leaving
dangling sockets. I suspect the qemu instance should shutdown before the
fake vhost-user daemon.

>> 
>> I don't know if it is an issue to get those additional errors?
>
> I see the same errors on
> /x86_64/pc/i440FX-pcihost/pci-bus-pc/pci-bus/virtio-net-pci/virtio-net/virtio-net-tests/vhost-user/.
>
> On the other hand, "make check" is happy (and silent) when run on the
> command-line.
>
> If the CI enables more verbose output then these messages might be
> diffed and interpreted as failures, but I didn't check the CI scripts.
>
> As long as GitLab CI is happy I think it's okay to merge this patch, but
> it would be interesting to investigate the reason for these messages.

Well this is all part of trying to get a working test case for the gpio
vhost-user device. So far I'm adding verbose output to try and divine
all the secret moving parts that go to make the test work.

>
> Stefan
>
> [[End of PGP Signed Part]]


-- 
Alex Bennée



[PULL 27/30] util: replace qemu_get_local_state_pathname()

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

Simplify the function to only return the directory path. Callers are
adjusted to use the GLib function to build paths, g_build_filename().

Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
Message-Id: <20220420132624.2439741-39-marcandre.lur...@redhat.com>
---
 include/qemu/osdep.h  | 9 +++--
 qga/main.c| 8 
 scsi/qemu-pr-helper.c | 6 --
 tools/virtiofsd/fuse_virtio.c | 4 +++-
 util/oslib-posix.c| 7 ++-
 util/oslib-win32.c| 5 ++---
 6 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 4bf2883a60b3..baaa23c1568d 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -556,16 +556,13 @@ void qemu_set_cloexec(int fd);
 void fips_set_state(bool requested);
 bool fips_get_state(void);
 
-/* Return a dynamically allocated pathname denoting a file or directory that is
- * appropriate for storing local state.
- *
- * @relative_pathname need not start with a directory separator; one will be
- * added automatically.
+/* Return a dynamically allocated directory path that is appropriate for 
storing
+ * local state.
  *
  * The caller is responsible for releasing the value returned with g_free()
  * after use.
  */
-char *qemu_get_local_state_pathname(const char *relative_pathname);
+char *qemu_get_local_state_dir(void);
 
 /* Find program directory, and save it for later usage with
  * qemu_get_exec_dir().
diff --git a/qga/main.c b/qga/main.c
index aa00ad8fabdf..3c20bf1fbfe0 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -129,12 +129,12 @@ static void stop_agent(GAState *s, bool requested);
 static void
 init_dfl_pathnames(void)
 {
+g_autofree char *state = qemu_get_local_state_dir();
+
 g_assert(dfl_pathnames.state_dir == NULL);
 g_assert(dfl_pathnames.pidfile == NULL);
-dfl_pathnames.state_dir = qemu_get_local_state_pathname(
-  QGA_STATE_RELATIVE_DIR);
-dfl_pathnames.pidfile   = qemu_get_local_state_pathname(
-  QGA_STATE_RELATIVE_DIR G_DIR_SEPARATOR_S "qemu-ga.pid");
+dfl_pathnames.state_dir = g_build_filename(state, QGA_STATE_RELATIVE_DIR, 
NULL);
+dfl_pathnames.pidfile = g_build_filename(state, QGA_STATE_RELATIVE_DIR, 
"qemu-ga.pid", NULL);
 }
 
 static void quit_handler(int sig)
diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c
index df493e2a503e..196b78c00df5 100644
--- a/scsi/qemu-pr-helper.c
+++ b/scsi/qemu-pr-helper.c
@@ -77,8 +77,10 @@ static int gid = -1;
 
 static void compute_default_paths(void)
 {
-socket_path = qemu_get_local_state_pathname("run/qemu-pr-helper.sock");
-pidfile = qemu_get_local_state_pathname("run/qemu-pr-helper.pid");
+g_autofree char *state = qemu_get_local_state_dir();
+
+socket_path = g_build_filename(state, "run", "qemu-pr-helper.sock", NULL);
+pidfile = g_build_filename(state, "run", "qemu-pr-helper.pid", NULL);
 }
 
 static void usage(const char *name)
diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
index 60b96470c51a..a52eacf82e1e 100644
--- a/tools/virtiofsd/fuse_virtio.c
+++ b/tools/virtiofsd/fuse_virtio.c
@@ -901,10 +901,12 @@ static bool fv_socket_lock(struct fuse_session *se)
 {
 g_autofree gchar *sk_name = NULL;
 g_autofree gchar *pidfile = NULL;
+g_autofree gchar *state = NULL;
 g_autofree gchar *dir = NULL;
 Error *local_err = NULL;
 
-dir = qemu_get_local_state_pathname("run/virtiofsd");
+state = qemu_get_local_state_dir();
+dir = g_build_filename(state, "run", "virtiofsd", NULL);
 
 if (g_mkdir_with_parents(dir, S_IRWXU) < 0) {
 fuse_log(FUSE_LOG_ERR, "%s: Failed to create directory %s: %s\n",
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index bcb35c3c8246..b8bf7d4070ce 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -297,12 +297,9 @@ int qemu_pipe(int pipefd[2])
 }
 
 char *
-qemu_get_local_state_pathname(const char *relative_pathname)
+qemu_get_local_state_dir(void)
 {
-g_autofree char *dir = g_strdup_printf("%s/%s",
-   CONFIG_QEMU_LOCALSTATEDIR,
-   relative_pathname);
-return get_relocated_path(dir);
+return get_relocated_path(CONFIG_QEMU_LOCALSTATEDIR);
 }
 
 void qemu_set_tty_echo(int fd, bool echo)
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index b897d759365f..9c1e8121fd6d 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -235,7 +235,7 @@ int qemu_get_thread_id(void)
 }
 
 char *
-qemu_get_local_state_pathname(const char *relative_pathname)
+qemu_get_local_state_dir(void)
 {
 HRESULT result;
 char base_path[MAX_PATH+1] = "";
@@ -247,8 +247,7 @@ qemu_get_local_state_pathname(const char *relative_pathname)
 g_critical("CSIDL_COMMON_APPDATA unavailable: %ld", (long)result);
 abort();
 }
-return g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", base_path,
-   rel

Re: [PATCH v5 2/2] Added parameter to take screenshot with screendump as PNG

2022-04-21 Thread Markus Armbruster
Kshitij Suri  writes:

> Currently screendump only supports PPM format, which is un-compressed. Added
> a "format" parameter to QMP and HMP screendump command to support PNG image
> capture using libpng.
>
> QMP example usage:
> { "execute": "screendump", "arguments": { "filename": "/tmp/image",
> "format":"png" } }
>
> HMP example usage:
> screendump /tmp/image -f png
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/718
>
> Signed-off-by: Kshitij Suri 
>
> Reviewed-by: Daniel P. Berrangé 

QAPI schema
Acked-by: Markus Armbruster 




[PULL 30/30] qga: use fixed-length and GDateTime for log timestamp

2022-04-21 Thread marcandre . lureau
From: Marc-André Lureau 

The old code is kind of wrong. Say it's 1649309843.01 seconds past
the epoch. Prints "1649309843.1". 9us later, it prints "1649309843.10".
Should really use %06lu for the microseconds part.

Use GDateTime instead, as suggested by Daniel.

Suggested-by: Markus Armbruster 
Suggested-by: Daniel P. Berrangé 
Signed-off-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
---
 qga/main.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/qga/main.c b/qga/main.c
index 3c20bf1fbfe0..3b9546c18584 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -328,11 +328,9 @@ static void ga_log(const gchar *domain, GLogLevelFlags 
level,
 #else
 if (level & s->log_level) {
 #endif
-gint64 t = g_get_real_time();
-fprintf(s->log_file,
-"%" G_GINT64_FORMAT ".%" G_GINT64_FORMAT
-": %s: %s\n", t / G_USEC_PER_SEC, t % G_USEC_PER_SEC,
-level_str, msg);
+g_autoptr(GDateTime) now = g_date_time_new_now_utc();
+g_autofree char *nowstr = g_date_time_format(now, "%s.%f");
+fprintf(s->log_file, "%s: %s: %s\n", nowstr, level_str, msg);
 fflush(s->log_file);
 }
 }
-- 
2.36.0




Re: [PATCH] migration: Fix operator type

2022-04-21 Thread Dr. David Alan Gilbert
* Peter Xu (pet...@redhat.com) wrote:
> On Wed, Apr 06, 2022 at 11:25:15AM +0100, Dr. David Alan Gilbert (git) wrote:
> > From: "Dr. David Alan Gilbert" 
> > 
> > Clang spotted an & that should have been an &&; fix it.
> > 
> > Reported by: David Binderman / https://gitlab.com/dcb
> > Fixes: 65dacaa04fa ("migration: introduce save_normal_page()")
> > Resolves: https://gitlab.com/qemu-project/qemu/-/issues/963
> > Signed-off-by: Dr. David Alan Gilbert 
> 
> Reviewed-by: Peter Xu 

Queued

> -- 
> Peter Xu
> 
> 
-- 
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK




Re: [PULL 13/13] dump/win_dump: add 32-bit guest Windows support

2022-04-21 Thread Marc-André Lureau
On Thu, Apr 21, 2022 at 5:08 PM  wrote:

> From: Viktor Prutyanov 
>
> Before this patch, 'dump-guest-memory -w' was accepting only 64-bit
> dump header provided by guest through vmcoreinfo and thus was unable
> to produce 32-bit guest Windows dump. So, add 32-bit guest Windows
> dumping support.
>
> Signed-off-by: Viktor Prutyanov 
> Reviewed-by: Philippe Mathieu-Daudé 
> Reviewed-by: Marc-André Lureau 
> Message-Id: <20220406171558.199263-5-viktor.prutya...@redhat.com>
> ---
>  dump/win_dump.c | 245 +---
>  hmp-commands.hx |   2 +-
>  2 files changed, 150 insertions(+), 97 deletions(-)
>
> diff --git a/dump/win_dump.c b/dump/win_dump.c
> index d733918038b2..ba508790bcea 100644
> --- a/dump/win_dump.c
> +++ b/dump/win_dump.c
> @@ -23,18 +23,24 @@
>  #include "hw/misc/vmcoreinfo.h"
>  #include "win_dump.h"
>
> -#define WIN_DUMP_PTR_SIZE sizeof(uint64_t)
> +static size_t win_dump_ptr_size(bool x64)
> +{
> +return x64 ? sizeof(uint64_t) : sizeof(uint32_t);
> +}
>
> -#define _WIN_DUMP_FIELD(f) (h->f)
> +#define _WIN_DUMP_FIELD(f) (x64 ? h->x64.f : h->x32.f)
>  #define WIN_DUMP_FIELD(field) _WIN_DUMP_FIELD(field)
>
> -#define _WIN_DUMP_FIELD_PTR(f) ((void *)&h->f)
> +#define _WIN_DUMP_FIELD_PTR(f) (x64 ? (void *)&h->x64.f : (void
> *)&h->x32.f)
>  #define WIN_DUMP_FIELD_PTR(field) _WIN_DUMP_FIELD_PTR(field)
>
> -#define _WIN_DUMP_FIELD_SIZE(f) sizeof(h->f)
> +#define _WIN_DUMP_FIELD_SIZE(f) (x64 ? sizeof(h->x64.f) :
> sizeof(h->x32.f))
>  #define WIN_DUMP_FIELD_SIZE(field) _WIN_DUMP_FIELD_SIZE(field)
>
> -#define WIN_DUMP_CTX_SIZE sizeof(WinContext64)
> +static size_t win_dump_ctx_size(bool x64)
> +{
> +return x64 ? sizeof(WinContext64) : sizeof(WinContext32);
> +}
>
>  static size_t write_run(uint64_t base_page, uint64_t page_count,
>  int fd, Error **errp)
> @@ -70,7 +76,7 @@ static size_t write_run(uint64_t base_page, uint64_t
> page_count,
>  return total;
>  }
>
> -static void write_runs(DumpState *s, WinDumpHeader64 *h, Error **errp)
> +static void write_runs(DumpState *s, WinDumpHeader *h, bool x64, Error
> **errp)
>  {
>  uint64_t BasePage, PageCount;
>  Error *local_err = NULL;
> @@ -87,22 +93,24 @@ static void write_runs(DumpState *s, WinDumpHeader64
> *h, Error **errp)
>  }
>  }
>
> -static int cpu_read_ptr(CPUState *cpu, uint64_t addr, uint64_t *ptr)
> +static int cpu_read_ptr(bool x64, CPUState *cpu, uint64_t addr, uint64_t
> *ptr)
>  {
>  int ret;
> +uint32_t ptr32;
>  uint64_t ptr64;
>
> -ret = cpu_memory_rw_debug(cpu, addr, &ptr64, WIN_DUMP_PTR_SIZE, 0);
> +ret = cpu_memory_rw_debug(cpu, addr, x64 ? (void *)&ptr64 : (void
> *)&ptr32,
> +win_dump_ptr_size(x64), 0);
>
> -*ptr = ptr64;
> +*ptr = x64 ? ptr64 : ptr32;
>
>  return ret;
>  }
>
> -static void patch_mm_pfn_database(WinDumpHeader64 *h, Error **errp)
> +static void patch_mm_pfn_database(WinDumpHeader *h, bool x64, Error
> **errp)
>  {
>  if (cpu_memory_rw_debug(first_cpu,
> -WIN_DUMP_FIELD(KdDebuggerDataBlock) +
> KDBG_MM_PFN_DATABASE_OFFSET64,
> +WIN_DUMP_FIELD(KdDebuggerDataBlock) +
> KDBG_MM_PFN_DATABASE_OFFSET,
>  WIN_DUMP_FIELD_PTR(PfnDatabase),
>  WIN_DUMP_FIELD_SIZE(PfnDatabase), 0)) {
>  error_setg(errp, "win-dump: failed to read MmPfnDatabase");
> @@ -110,13 +118,12 @@ static void patch_mm_pfn_database(WinDumpHeader64
> *h, Error **errp)
>  }
>  }
>
> -static void patch_bugcheck_data(WinDumpHeader64 *h, Error **errp)
> +static void patch_bugcheck_data(WinDumpHeader *h, bool x64, Error **errp)
>  {
>  uint64_t KiBugcheckData;
>
> -if (cpu_read_ptr(first_cpu,
> -WIN_DUMP_FIELD(KdDebuggerDataBlock) +
> -KDBG_KI_BUGCHECK_DATA_OFFSET64,
> +if (cpu_read_ptr(x64, first_cpu,
> +WIN_DUMP_FIELD(KdDebuggerDataBlock) +
> KDBG_KI_BUGCHECK_DATA_OFFSET,
>  &KiBugcheckData)) {
>  error_setg(errp, "win-dump: failed to read KiBugcheckData");
>  return;
> @@ -141,30 +148,34 @@ static void patch_bugcheck_data(WinDumpHeader64 *h,
> Error **errp)
>  /*
>   * This routine tries to correct mistakes in crashdump header.
>   */
> -static void patch_header(WinDumpHeader64 *h)
> +static void patch_header(WinDumpHeader *h, bool x64)
>  {
>  Error *local_err = NULL;
>
> -h->RequiredDumpSpace = sizeof(WinDumpHeader64) +
> -(h->PhysicalMemoryBlock.NumberOfPages << TARGET_PAGE_BITS);
> -h->PhysicalMemoryBlock.unused = 0;
> -h->unused1 = 0;
> +if (x64) {
> +h->x64.RequiredDumpSpace = sizeof(WinDumpHeader64) +
> +(h->x64.PhysicalMemoryBlock.NumberOfPages <<
> TARGET_PAGE_BITS);
> +h->x64.PhysicalMemoryBlock.unused = 0;
> +h->x64.unused1 = 0;
> +} else {
> +h->x32.RequiredDumpSpace = sizeof(WinDumpHeader32) +
> +(h->x32.PhysicalMemoryBlock.NumberOfPages <<
> TARGET_PAGE_BITS);
> +}
>
> -patch_mm_pfn_database

Re: [PATCH v5 0/2] Option to take screenshot with screendump as PNG

2022-04-21 Thread Markus Armbruster
Kshitij Suri  writes:

> Hi,
>
> Hope this mail finds everyone well! I have updated the code as
> required and would be grateful if I could get your reviews for any
> changes that are needed to be implemented in the patch. In case no
> change is required, please do let me know the next steps for the same.

Unless something still comes up in review, the next step is merging.

Gerd, would you like to take it?




Re: [PULL 00/23] ppc queue

2022-04-21 Thread Peter Maydell
On Thu, 21 Apr 2022 at 14:53, Richard Henderson
 wrote:
>
> On 4/20/22 15:13, Daniel Henrique Barboza wrote:
> > The following changes since commit 2d20a57453f6a206938cbbf77bed0b378c806c1f:
> >
> >Merge tag 'pull-fixes-for-7.1-200422-1' of 
> > https://github.com/stsquad/qemu into staging (2022-04-20 11:13:08 -0700)
> >
> > are available in the Git repository at:
> >
> >https://gitlab.com/danielhb/qemu.git tags/pull-ppc-20220420-2
> >
> > for you to fetch changes up to 2d94af4b16c40758eee3a8591307ae173090d4ad:
> >
> >hw/ppc: change indentation to spaces from TABs (2022-04-20 18:00:30 
> > -0300)
> >
> > 
> > ppc patch queue for 2022-04-20
> >
> > First batch of ppc patches for QEMU 7.1:
> >
> > - skiboot firmware version bump
> > - pseries: add 2M DDW pagesize
> > - pseries: make virtual hypervisor code TCG only
> > - powernv: introduce GPIO lines for PSIHB device
> > - powernv: remove PCIE root bridge LSI
> > - target/ppc: alternative softfloat 128 bit integer support
> > - assorted fixes
>
> Applied, thanks.  Please update the wiki changelog for 7.1 as appropriate.

I created the wiki page last week, incidentally, so you can directly
quote the URL in these applied-thanks notes:
https://wiki.qemu.org/ChangeLog/7.1

-- PMM



Re: [PATCH] migration: Read state once

2022-04-21 Thread Dr. David Alan Gilbert
* Dr. David Alan Gilbert (git) (dgilb...@redhat.com) wrote:
> From: "Dr. David Alan Gilbert" 
> 
> The 'status' field for the migration is updated normally using
> an atomic operation from the migration thread.
> Most readers of it aren't that careful, and in most cases it doesn't
> matter.
> 
> In query_migrate->fill_source_migration_info the 'state'
> is read twice; the first time to decide which state fields to fill in,
> and then secondly to copy the state to the status field; that can end up
> with a status that's inconsistent; e.g. setting up the fields
> for 'setup' and then having an 'active' status.  In that case
> libvirt gets upset by the lack of ram info.
> The symptom is:
>libvirt.libvirtError: internal error: migration was active, but no RAM 
> info was set
> 
> Read the state exactly once in fill_source_migration_info.
> 
> This is a possible fix for:
> https://bugzilla.redhat.com/show_bug.cgi?id=2074205
> 
> Signed-off-by: Dr. David Alan Gilbert 

Queued

> ---
>  migration/migration.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/migration/migration.c b/migration/migration.c
> index 695f0f2900..811c584619 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -1073,6 +1073,7 @@ static void populate_disk_info(MigrationInfo *info)
>  static void fill_source_migration_info(MigrationInfo *info)
>  {
>  MigrationState *s = migrate_get_current();
> +int state = qatomic_read(&s->state);
>  GSList *cur_blocker = migration_blockers;
>  
>  info->blocked_reasons = NULL;
> @@ -1092,7 +1093,7 @@ static void fill_source_migration_info(MigrationInfo 
> *info)
>  }
>  info->has_blocked_reasons = info->blocked_reasons != NULL;
>  
> -switch (s->state) {
> +switch (state) {
>  case MIGRATION_STATUS_NONE:
>  /* no migration has happened ever */
>  /* do not overwrite destination migration status */
> @@ -1137,7 +1138,7 @@ static void fill_source_migration_info(MigrationInfo 
> *info)
>  info->has_status = true;
>  break;
>  }
> -info->status = s->state;
> +info->status = state;
>  }
>  
>  typedef enum WriteTrackingSupport {
> -- 
> 2.35.1
> 
> 
-- 
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK




<    1   2   3   4   5   6   >