[PATCH v3 5/5] s390x/pci: Honor DMA limits set by vfio

2020-09-15 Thread Matthew Rosato
When an s390 guest is using lazy unmapping, it can result in a very
large number of oustanding DMA requests, far beyond the default
limit configured for vfio.  Let's track DMA usage similar to vfio
in the host, and trigger the guest to flush their DMA mappings
before vfio runs out.

Signed-off-by: Matthew Rosato 
---
 hw/s390x/s390-pci-bus.c  | 56 +++-
 hw/s390x/s390-pci-bus.h  |  9 
 hw/s390x/s390-pci-inst.c | 34 +++--
 hw/s390x/s390-pci-inst.h |  3 +++
 4 files changed, 91 insertions(+), 11 deletions(-)

diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index 92146a2..8e8398d 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -17,6 +17,7 @@
 #include "cpu.h"
 #include "s390-pci-bus.h"
 #include "s390-pci-inst.h"
+#include "s390-pci-vfio.h"
 #include "hw/pci/pci_bus.h"
 #include "hw/qdev-properties.h"
 #include "hw/pci/pci_bridge.h"
@@ -24,6 +25,8 @@
 #include "qemu/error-report.h"
 #include "qemu/module.h"
 
+#include "hw/vfio/pci.h"
+
 #ifndef DEBUG_S390PCI_BUS
 #define DEBUG_S390PCI_BUS  0
 #endif
@@ -737,6 +740,41 @@ static void s390_pci_iommu_free(S390pciState *s, PCIBus 
*bus, int32_t devfn)
 object_unref(OBJECT(iommu));
 }
 
+static S390PCIDMACount *s390_start_dma_count(S390pciState *s, VFIODevice *vdev)
+{
+int id = vdev->group->container->fd;
+S390PCIDMACount *cnt;
+uint32_t avail;
+
+if (!s390_pci_update_dma_avail(id, )) {
+return NULL;
+}
+
+QTAILQ_FOREACH(cnt, >zpci_dma_limit, link) {
+if (cnt->id  == id) {
+cnt->users++;
+return cnt;
+}
+}
+
+cnt = g_new0(S390PCIDMACount, 1);
+cnt->id = id;
+cnt->users = 1;
+cnt->avail = avail;
+QTAILQ_INSERT_TAIL(>zpci_dma_limit, cnt, link);
+return cnt;
+}
+
+static void s390_end_dma_count(S390pciState *s, S390PCIDMACount *cnt)
+{
+assert(cnt);
+
+cnt->users--;
+if (cnt->users == 0) {
+QTAILQ_REMOVE(>zpci_dma_limit, cnt, link);
+}
+}
+
 static void s390_pcihost_realize(DeviceState *dev, Error **errp)
 {
 PCIBus *b;
@@ -764,6 +802,7 @@ static void s390_pcihost_realize(DeviceState *dev, Error 
**errp)
 s->bus_no = 0;
 QTAILQ_INIT(>pending_sei);
 QTAILQ_INIT(>zpci_devs);
+QTAILQ_INIT(>zpci_dma_limit);
 
 css_register_io_adapters(CSS_IO_ADAPTER_PCI, true, false,
  S390_ADAPTER_SUPPRESSIBLE, errp);
@@ -902,6 +941,7 @@ static void s390_pcihost_plug(HotplugHandler *hotplug_dev, 
DeviceState *dev,
 {
 S390pciState *s = S390_PCI_HOST_BRIDGE(hotplug_dev);
 PCIDevice *pdev = NULL;
+VFIOPCIDevice *vpdev = NULL;
 S390PCIBusDevice *pbdev = NULL;
 
 if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_BRIDGE)) {
@@ -941,17 +981,20 @@ static void s390_pcihost_plug(HotplugHandler 
*hotplug_dev, DeviceState *dev,
 }
 }
 
+pbdev->pdev = pdev;
+pbdev->iommu = s390_pci_get_iommu(s, pci_get_bus(pdev), pdev->devfn);
+pbdev->iommu->pbdev = pbdev;
+pbdev->state = ZPCI_FS_DISABLED;
+
 if (object_dynamic_cast(OBJECT(dev), "vfio-pci")) {
 pbdev->fh |= FH_SHM_VFIO;
+vpdev = container_of(pbdev->pdev, VFIOPCIDevice, pdev);
+pbdev->iommu->dma_limit = s390_start_dma_count(s,
+   >vbasedev);
 } else {
 pbdev->fh |= FH_SHM_EMUL;
 }
 
-pbdev->pdev = pdev;
-pbdev->iommu = s390_pci_get_iommu(s, pci_get_bus(pdev), pdev->devfn);
-pbdev->iommu->pbdev = pbdev;
-pbdev->state = ZPCI_FS_DISABLED;
-
 if (s390_pci_msix_init(pbdev)) {
 error_setg(errp, "MSI-X support is mandatory "
"in the S390 architecture");
@@ -1004,6 +1047,9 @@ static void s390_pcihost_unplug(HotplugHandler 
*hotplug_dev, DeviceState *dev,
 pbdev->fid = 0;
 QTAILQ_REMOVE(>zpci_devs, pbdev, link);
 g_hash_table_remove(s->zpci_table, >idx);
+if (pbdev->iommu->dma_limit) {
+s390_end_dma_count(s, pbdev->iommu->dma_limit);
+}
 qdev_unrealize(dev);
 }
 }
diff --git a/hw/s390x/s390-pci-bus.h b/hw/s390x/s390-pci-bus.h
index 0458059..f166fd9 100644
--- a/hw/s390x/s390-pci-bus.h
+++ b/hw/s390x/s390-pci-bus.h
@@ -270,6 +270,13 @@ typedef struct S390IOTLBEntry {
 uint64_t perm;
 } S390IOTLBEntry;
 
+typedef struct S390PCIDMACount {
+int id;
+int users;
+uint32_t avail;
+QTAILQ_ENTRY(S390PCIDMACount) link;
+} S390PCIDMACount;
+
 struct S390PCIIOMMU {
 Object parent_obj;
 S390PCIBusDevice *pbdev;
@@ -281,6 +288,7 @@ struct S390PCIIOMMU {
 uint64_t pba;
 uint64_t pal;
 GHashTable *iotlb;
+S390PCIDMACount *dma_limit;
 };
 
 typedef struct S390PCIIOMMUTable {
@@ -356,6 +364,7 @@ struct S390pciState {
 GHashTable *zpci_table;
 QTAILQ_HEAD(, SeiContainer) pending_sei;
 QTAILQ_HEAD(, 

Re: [PATCH v3 14/15] hw/block/nvme: Use zone metadata file for persistence

2020-09-15 Thread Klaus Jensen
On Sep 14 07:14, Dmitry Fomichev wrote:
> A ZNS drive that is emulated by this module is currently initialized
> with all zones Empty upon startup. However, actual ZNS SSDs save the
> state and condition of all zones in their internal NVRAM in the event
> of power loss. When such a drive is powered up again, it closes or
> finishes all zones that were open at the moment of shutdown. Besides
> that, the write pointer position as well as the state and condition
> of all zones is preserved across power-downs.
> 
> This commit adds the capability to have a persistent zone metadata
> to the device. The new optional module property, "zone_file",
> is introduced. If added to the command line, this property specifies
> the name of the file that stores the zone metadata. If "zone_file" is
> omitted, the device will be initialized with all zones empty, the same
> as before.
> 
> If zone metadata is configured to be persistent, then zone descriptor
> extensions also persist across controller shutdowns.
> 
> Signed-off-by: Dmitry Fomichev 

This doesn't build on mingw.

> ---
>  hw/block/nvme.c | 370 +---
>  hw/block/nvme.h |  37 +
>  2 files changed, 386 insertions(+), 21 deletions(-)
> 
> diff --git a/hw/block/nvme.c b/hw/block/nvme.c
> index b49ae83dd5..41f4c0dacd 100644
> --- a/hw/block/nvme.c
> +++ b/hw/block/nvme.c
> @@ -3429,7 +3557,188 @@ static int nvme_init_zone_meta(NvmeCtrl *n, 
> NvmeNamespace *ns,
>  return 0;
>  }
>  
> -static void nvme_zoned_init_ctrl(NvmeCtrl *n, Error **errp)
> +static int nvme_open_zone_file(NvmeCtrl *n, bool *init_meta)
> +{
> +struct stat statbuf;
> +size_t fsize;
> +int ret;
> +
> +ret = stat(n->params.zone_file, );
> +if (ret && errno == ENOENT) {
> +*init_meta = true;
> +} else if (!S_ISREG(statbuf.st_mode)) {
> +fprintf(stderr, "%s is not a regular file\n", strerror(errno));
> +return -1;
> +}
> +
> +n->zone_file_fd = open(n->params.zone_file,
> +   O_RDWR | O_LARGEFILE | O_BINARY | O_CREAT, 644);

mode is wrong - I think you meant for it to be octal.


signature.asc
Description: PGP signature


Re: [PATCH 1/5] qom: Allow objects to be allocated with increased alignment

2020-09-15 Thread Richard Henderson
On 9/15/20 11:07 AM, Eduardo Habkost wrote:
> On Tue, Sep 15, 2020 at 10:46:31AM -0700, Richard Henderson wrote:
>> It turns out that some hosts have a default malloc alignment less
>> than that required for vectors.
>>
>> We assume that, with compiler annotation on CPUArchState, that we
>> can properly align the vector portion of the guest state.  Fix the
>> alignment of the allocation by using qemu_memalloc when required.
>>
>> Signed-off-by: Richard Henderson 
>> ---
>> Cc: Paolo Bonzini 
>> Cc: "Daniel P. Berrangé" 
>> Cc: Eduardo Habkost 
>> ---
>>  include/qom/object.h |  4 
>>  qom/object.c | 16 +---
>>  2 files changed, 17 insertions(+), 3 deletions(-)
>>
>> diff --git a/include/qom/object.h b/include/qom/object.h
>> index 056f67ab3b..d52d0781a3 100644
>> --- a/include/qom/object.h
>> +++ b/include/qom/object.h
>> @@ -770,6 +770,9 @@ struct Object
>>   * @instance_size: The size of the object (derivative of #Object).  If
>>   *   @instance_size is 0, then the size of the object will be the size of 
>> the
>>   *   parent object.
>> + * @instance_align: The required alignment of the object.  If 
>> @instance_align
>> + *   is 0, then normal malloc alignment is sufficient; if non-zero, then we
>> + *   must use qemu_memalign for allocation.
>>   * @instance_init: This function is called to initialize an object.  The 
>> parent
>>   *   class will have already been initialized so the type is only 
>> responsible
>>   *   for initializing its own members.
>> @@ -807,6 +810,7 @@ struct TypeInfo
>>  const char *parent;
>>  
>>  size_t instance_size;
>> +size_t instance_align;
>>  void (*instance_init)(Object *obj);
>>  void (*instance_post_init)(Object *obj);
>>  void (*instance_finalize)(Object *obj);
>> diff --git a/qom/object.c b/qom/object.c
>> index 387efb25eb..2e53cb44a6 100644
>> --- a/qom/object.c
>> +++ b/qom/object.c
>> @@ -50,6 +50,7 @@ struct TypeImpl
>>  size_t class_size;
>>  
>>  size_t instance_size;
>> +size_t instance_align;
>>  
>>  void (*class_init)(ObjectClass *klass, void *data);
>>  void (*class_base_init)(ObjectClass *klass, void *data);
>> @@ -114,6 +115,7 @@ static TypeImpl *type_new(const TypeInfo *info)
>>  
>>  ti->class_size = info->class_size;
>>  ti->instance_size = info->instance_size;
>> +ti->instance_align = info->instance_align;
>>  
>>  ti->class_init = info->class_init;
>>  ti->class_base_init = info->class_base_init;
>> @@ -691,13 +693,21 @@ static void object_finalize(void *data)
>>  static Object *object_new_with_type(Type type)
>>  {
>>  Object *obj;
>> +size_t size, align;
>>  
>>  g_assert(type != NULL);
>>  type_initialize(type);
>>  
>> -obj = g_malloc(type->instance_size);
>> -object_initialize_with_type(obj, type->instance_size, type);
>> -obj->free = g_free;
>> +size = type->instance_size;
>> +align = type->instance_align;
>> +if (align) {
> 
> If we check for (align > G_MEM_ALIGN) instead, we will be able to
> set instance_align automatically at OBJECT_DEFINE_TYPE*.

I agree a value check would be good here, as well as setting this by default.

As for the value check itself...

I see that G_MEM_ALIGN isn't actually defined in an interesting or even correct
way.  E.g. it doesn't take the long double type into account.

The usual mechanism is

struct s {
  char pad;
  union {
long l;
void *p;
double d;
long double ld;
  } u;
};

offsetof(s, u)

since all of these types are required to be taken into account by the system
malloc.

E.g it doesn't take other host guarantees into account, e.g. i386-linux
guarantees 16-byte alignment.  This possibly dubious ABI change was made 20+
years ago with the introduction of SSE and is now set in stone.

Glibc has a "malloc-alignment.h" internal header that defaults to

  MIN(2 * sizeof(size_t), __alignof__(long double))

and is overridden for i386.  Sadly, it doesn't export MALLOC_ALIGNMENT.

Musl has two different malloc implementations.  One has UNIT = 16; the other
has SIZE_ALIGN = 4*sizeof(size_t).  Both have a minimum value of 16, and this
is not target-specific.

Any further comments on the subject, or should I put together something that
computes the MAX of the above?


r~



Re: PATCH: Increase System Firmware Max Size

2020-09-15 Thread McMillan, Erich
Apologies, ignore previous patch. The relevant patch is below:

>From 473daf6129debf8d158a9ae1aff788c5bdbbc799 Mon Sep 17 00:00:00 2001
From: Erich McMillan 
Date: Tue, 15 Sep 2020 13:23:25 -0500
Subject: [PATCH 2/2] Add max firmware size as optional parameter

Signed-off-by: Erich McMillan 
---
 hw/i386/pc_sysfw.c  | 13 ++---
 include/hw/loader.h |  9 +
 qemu-options.hx |  8 
 softmmu/vl.c| 40 
 4 files changed, 59 insertions(+), 11 deletions(-)

diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c
index b6c0822..ba6c99d 100644
--- a/hw/i386/pc_sysfw.c
+++ b/hw/i386/pc_sysfw.c
@@ -39,15 +39,6 @@
 #include "hw/block/flash.h"
 #include "sysemu/kvm.h"

-/*
- * We don't have a theoretically justifiable exact lower bound on the base
- * address of any flash mapping. In practice, the IO-APIC MMIO range is
- * [0xFEE0..0xFEE01000] -- see IO_APIC_DEFAULT_ADDRESS --, leaving free
- * only 18MB-4KB below 4G. For now, restrict the cumulative mapping to 8MB in
- * size.
- */
-#define FLASH_SIZE_LIMIT (8 * MiB)
-
 #define FLASH_SECTOR_SIZE 4096

 static void pc_isa_bios_init(MemoryRegion *rom_memory,
@@ -182,10 +173,10 @@ static void pc_system_flash_map(PCMachineState *pcms,
 }
 if ((hwaddr)size != size
 || total_size > HWADDR_MAX - size
-|| total_size + size > FLASH_SIZE_LIMIT) {
+|| total_size + size > MaxCombinedFirmwareSize) {
 error_report("combined size of system firmware exceeds "
  "%" PRIu64 " bytes",
- FLASH_SIZE_LIMIT);
+ MaxCombinedFirmwareSize);
 exit(1);
 }

diff --git a/include/hw/loader.h b/include/hw/loader.h
index a9eeea3..7898b63 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -318,4 +318,13 @@ int rom_add_option(const char *file, int32_t bootindex);
  * overflow on real hardware too. */
 #define UBOOT_MAX_GUNZIP_BYTES (64 << 20)

+/*
+ * We don't have a theoretically justifiable exact lower bound on the base
+ * address of any flash mapping. In practice, the IO-APIC MMIO range is
+ * [0xFEE0..0xFEE01000] -- see IO_APIC_DEFAULT_ADDRESS --, leaving free
+ * only 18MB-4KB below 4G. For now, restrict the cumulative mapping to 8MB in
+ * size, but allow user to specify larger size via command line.
+ */
+extern uint64_t MaxCombinedFirmwareSize;
+
 #endif
diff --git a/qemu-options.hx b/qemu-options.hx
index b0f0205..32eed3a 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1377,6 +1377,14 @@ SRST
 |qemu_system_x86| -hda a -hdb b
 ERST

+DEF("maxfirmwaresize", HAS_ARG, QEMU_OPTION_maxfirmwaresize,
+"-maxfirmwaresize [size=]megs  specify maximum combined firmware size, 
default is 8MiB. Known issues if value exceeds 16MiB.\n",
+QEMU_ARCH_ALL)
+SRST
+``-maxfirmwaresize [size=]megs``
+Specify maximum combined firmware size, default is 8MiB. Known issues if 
value exceeds 16MiB.
+ERST
+
 DEF("mtdblock", HAS_ARG, QEMU_OPTION_mtdblock,
 "-mtdblock file  use 'file' as on-board Flash memory image\n",
 QEMU_ARCH_ALL)
diff --git a/softmmu/vl.c b/softmmu/vl.c
index 0cc86b0..fcf41d2 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -116,6 +116,8 @@

 #define MAX_VIRTIO_CONSOLES 1

+uint64_t MaxCombinedFirmwareSize = 8 * MiB;
+
 static const char *data_dir[16];
 static int data_dir_idx;
 const char *bios_name = NULL;
@@ -448,6 +450,20 @@ static QemuOptsList qemu_mem_opts = {
 },
 };

+static QemuOptsList qemu_max_fw_size_opts = {
+.name = "maxfirmwaresize",
+.implied_opt_name = "size",
+.head = QTAILQ_HEAD_INITIALIZER(qemu_max_fw_size_opts.head),
+.merge_lists = true,
+.desc = {
+{
+.name = "size",
+.type = QEMU_OPT_SIZE,
+},
+{ /* end of list */ }
+},
+};
+
 static QemuOptsList qemu_icount_opts = {
 .name = "icount",
 .implied_opt_name = "shift",
@@ -2576,6 +2592,23 @@ static bool object_create_delayed(const char *type, 
QemuOpts *opts)
 return !object_create_initial(type, opts);
 }

+static void set_max_firmware_size(uint64_t *maxfwsize)
+{
+const char *max_fw_size_str;
+QemuOpts *opts = qemu_find_opts_singleton("maxfirmwaresize");
+
+max_fw_size_str = qemu_opt_get(opts, "size");
+
+if (max_fw_size_str) {
+if (!*max_fw_size_str) {
+error_report("missing 'size' option value");
+exit(EXIT_FAILURE);
+}
+
+*maxfwsize = qemu_opt_get_size(opts, "size", 8 * MiB);
+}
+}
+

 static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
MachineClass *mc)
@@ -2904,6 +2937,7 @@ void qemu_init(int argc, char **argv, char **envp)
 qemu_add_opts(_machine_opts);
 qemu_add_opts(_accel_opts);
 qemu_add_opts(_mem_opts);
+qemu_add_opts(_max_fw_size_opts);
 qemu_add_opts(_smp_opts);
 qemu_add_opts(_boot_opts);
 

Re: PATCH: Increase System Firmware Max Size

2020-09-15 Thread McMillan, Erich
Hi all,

I've rewritten the FLASH_SIZE_LIMIT as a command line parameter as requested, 
but I'd like some feedback. My current concerns are:

  1.  I'm not too happy using an global variable in this manner, but I'm not 
sure the appropriate way to share this information between vl.c and pc_sysfw.c. 
Is there a way for other .c modules to query the QemuOpts, or is this not 
preferred.
  2.  Would appreciate feedback on the help strings, I think the formatting is 
correct based on -m (memory size) flag.
  3.  If global variable is acceptable then is it appropriate for it to be 
shared via loader.h, this seemed the most appropriate place to put it without 
adding new includes to either vl.c or pc_sysfw.c.

Thank you,
Erich

diff --git a/softmmu/vl.c b/softmmu/vl.c
index 
05d1a4cb6bf863b6ac1df8f94694c073fa4f8d90..a34995819fa14ef728d82ab179ef3a2e468e2365
 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -442,6 +442,20 @@ static QemuOptsList qemu_mem_opts = {
 },
 };

+static QemuOptsList qemu_max_fw_size_opts = {
+.name = "maxfirmwaresize",
+.implied_opt_name = "fwsize",
+.head = QTAILQ_HEAD_INITIALIZER(qemu_max_fw_size_opts.head),
+.merge_lists = true,
+.desc = {
+{
+.name = "size",
+.type = QEMU_OPT_SIZE,
+},
+{ /* end of list */ }
+},
+};
+
 static QemuOptsList qemu_icount_opts = {
 .name = "icount",
 .implied_opt_name = "shift",
@@ -2559,6 +2573,23 @@ static bool object_create_delayed(const char *type, 
QemuOpts *opts)
 return !object_create_initial(type, opts);
 }

+static void set_max_firmware_size(uint64_t *maxfwsize)
+{
+const char *max_fw_size_str;
+QemuOpts *opts = qemu_find_opts_singleton("maxfirmwaresize");
+
+max_fw_size_str = qemu_opt_get(opts, "size");
+
+if (max_fw_size_str) {
+if (!*max_fw_size_str) {
+error_report("missing 'size' option value");
+exit(EXIT_FAILURE);
+}
+
+*maxfwsize = qemu_opt_get_size(opts, "size", 8 * MiB);
+}
+}
+

 static bool set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
MachineClass *mc)
@@ -2887,6 +2918,7 @@ void qemu_init(int argc, char **argv, char **envp)
 qemu_add_opts(_machine_opts);
 qemu_add_opts(_accel_opts);
 qemu_add_opts(_mem_opts);
+qemu_add_opts(_max_fw_size_opts);
 qemu_add_opts(_smp_opts);
 qemu_add_opts(_boot_opts);
 qemu_add_opts(_add_fd_opts);
@@ -3143,6 +3175,10 @@ void qemu_init(int argc, char **argv, char **envp)
 exit(EXIT_FAILURE);
 }
 break;
+case QEMU_OPTION_maxfirmwaresize:
+opts = 
qemu_opts_parse_noisily(qemu_find_opts("maxfirmwaresize"),
+   optarg, true);
+break;
 #ifdef CONFIG_TPM
 case QEMU_OPTION_tpmdev:
 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) {
@@ -3831,6 +3867,8 @@ void qemu_init(int argc, char **argv, char **envp)
 have_custom_ram_size = set_memory_options(_slots, _size,
   machine_class);

+set_max_firmware_size();
+
 os_daemonize();

 /*
diff --git a/include/hw/loader.h b/include/hw/loader.h
index 
a9eeea39521d2d5b5e9b73e0fcbd4d4ce9292046..9e982cd60f8f2173a3160f563167e48b7ca88aa9
 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -318,4 +318,13 @@ int rom_add_option(const char *file, int32_t bootindex);
  * overflow on real hardware too. */
 #define UBOOT_MAX_GUNZIP_BYTES (64 << 20)

+/*
+ * We don't have a theoretically justifiable exact lower bound on the base
+ * address of any flash mapping. In practice, the IO-APIC MMIO range is
+ * [0xFEE0..0xFEE01000] -- see IO_APIC_DEFAULT_ADDRESS --, leaving free
+ * only 18MB-4KB below 4G. For now, restrict the cumulative mapping to 8MB in
+ * size, but allow user to specify larger size via command line.
+ */
+uint64_t MaxCombinedFirmwareSize = (8 * MiB);
+
 #endif
diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c
index 
b8d8ef59eb17c6ace8194fc69c3d27809becfbc0..012c28a3b4de1c1618404faefd63a99267636935
 100644
--- a/hw/i386/pc_sysfw.c
+++ b/hw/i386/pc_sysfw.c
@@ -39,14 +39,8 @@
 #include "hw/block/flash.h"
 #include "sysemu/kvm.h"

-/*
- * We don't have a theoretically justifiable exact lower bound on the base
- * address of any flash mapping. In practice, the IO-APIC MMIO range is
- * [0xFEE0..0xFEE01000] -- see IO_APIC_DEFAULT_ADDRESS --, leaving free
- * only 18MB-4KB below 4G. For now, restrict the cumulative mapping to 8MB in
- * size.
- */
-#define FLASH_SIZE_LIMIT (8 * MiB)
+
+extern MaxCombinedFirmwareSize;

 #define FLASH_SECTOR_SIZE 4096

@@ -177,10 +171,10 @@ static void pc_system_flash_map(PCMachineState *pcms,
 }
 if ((hwaddr)size != size
 || total_size > HWADDR_MAX - size
-|| total_size + size > FLASH_SIZE_LIMIT) {
+|| 

Re: [PATCH] hw/scsi/vmw_pvscsi.c: Fix wrong usage of gboolean types in PVSCSIState

2020-09-15 Thread Dr. David Alan Gilbert
* Philippe Mathieu-Daudé (phi...@redhat.com) wrote:
> Hi Amey,
> 
> On 9/14/20 1:44 AM, Amey Narkhede wrote:
> > rings_info_valid, msg_ring_info_valid and use_msg fields of struct
> > PVSCSIState are using gboolean TRUE/FALSE values with the type uint8_t.
> > Change their type to bool along with the usage of initialization macro
> > VMSTATE_BOOL during initialization of vmstate_pvscsi and
> > pvscsi_properties.
> > 
> > Signed-off-by: Amey Narkhede 
> > ---
> >  hw/scsi/vmw_pvscsi.c | 22 +++---
> >  1 file changed, 11 insertions(+), 11 deletions(-)
> > 
> > diff --git a/hw/scsi/vmw_pvscsi.c b/hw/scsi/vmw_pvscsi.c
> > index c071e0c7aa..86f00e3d7e 100644
> > --- a/hw/scsi/vmw_pvscsi.c
> > +++ b/hw/scsi/vmw_pvscsi.c
> > @@ -123,9 +123,9 @@ typedef struct {
> >  /* Collector for current command data */
> >  uint32_t curr_cmd_data[PVSCSI_MAX_CMD_DATA_WORDS];
> > 
> > -uint8_t rings_info_valid;/* Whether data rings initialized 
> >   */
> > -uint8_t msg_ring_info_valid; /* Whether message ring 
> > initialized */
> > -uint8_t use_msg; /* Whether to use message ring
> >   */
> > +bool rings_info_valid;/* Whether data rings initialized   
> > */
> > +bool msg_ring_info_valid; /* Whether message ring initialized 
> > */
> > +bool use_msg; /* Whether to use message ring  
> > */
> > 
> >  uint8_t msi_used;/* For migration compatibility
> >   */
> >  PVSCSIRingInfo rings;/* Data transfer rings manager
> >   */
> > @@ -349,8 +349,8 @@ pvscsi_reset_state(PVSCSIState *s)
> >  s->reg_command_status = PVSCSI_COMMAND_PROCESSING_SUCCEEDED;
> >  s->reg_interrupt_status = 0;
> >  pvscsi_ring_cleanup(>rings);
> > -s->rings_info_valid = FALSE;
> > -s->msg_ring_info_valid = FALSE;
> > +s->rings_info_valid = false;
> > +s->msg_ring_info_valid = false;
> >  QTAILQ_INIT(>pending_queue);
> >  QTAILQ_INIT(>completion_queue);
> >  }
> > @@ -792,7 +792,7 @@ pvscsi_on_cmd_setup_rings(PVSCSIState *s)
> >  pvscsi_dbg_dump_tx_rings_config(rc);
> >  pvscsi_ring_init_data(>rings, rc);
> > 
> > -s->rings_info_valid = TRUE;
> > +s->rings_info_valid = true;
> >  return PVSCSI_COMMAND_PROCESSING_SUCCEEDED;
> >  }
> > 
> > @@ -874,7 +874,7 @@ pvscsi_on_cmd_setup_msg_ring(PVSCSIState *s)
> >  if (pvscsi_ring_init_msg(>rings, rc) < 0) {
> >  return PVSCSI_COMMAND_PROCESSING_FAILED;
> >  }
> > -s->msg_ring_info_valid = TRUE;
> > +s->msg_ring_info_valid = true;
> >  }
> >  return sizeof(PVSCSICmdDescSetupMsgRing) / sizeof(uint32_t);
> >  }
> > @@ -1232,9 +1232,9 @@ static const VMStateDescription vmstate_pvscsi = {
> >  VMSTATE_UINT32(curr_cmd_data_cntr, PVSCSIState),
> >  VMSTATE_UINT32_ARRAY(curr_cmd_data, PVSCSIState,
> >   ARRAY_SIZE(((PVSCSIState 
> > *)NULL)->curr_cmd_data)),
> > -VMSTATE_UINT8(rings_info_valid, PVSCSIState),
> > -VMSTATE_UINT8(msg_ring_info_valid, PVSCSIState),
> > -VMSTATE_UINT8(use_msg, PVSCSIState),
> > +VMSTATE_BOOL(rings_info_valid, PVSCSIState),
> > +VMSTATE_BOOL(msg_ring_info_valid, PVSCSIState),
> > +VMSTATE_BOOL(use_msg, PVSCSIState),
> 
> I believe this change the migration data structure. This
> area is described in "Changing migration data structures"
> in docs/devel/migration.rst.
> 
> If this structure were not affected, your change would be
> a good cleanup. However changing migration can become a
> nightmare, so ... cleaning this is hard.
> 
> Cc'ing Dave (a migration maintainer) as I'm not sure there
> already is a document describing easily this problem.

Well; the migration structures are...very unstructured.
It turns out that VMSTATE_BOOL already reads/writes a raw
byte to the file - so it's the same size as the VMSTATE_UINT8 at least.
Disappointingly get_bool and put_bool in vmstate-types.c don't do any
sanitation either; so you get whatever the raw value is.

glib's FALSE/TRUE is:

#define FALSE   (0)
#define TRUE(!FALSE)

so that's probably fine;  as long as no one does anything silly like
compare the value with TRUE or true.

Dave

> > 
> >  VMSTATE_UINT64(rings.rs_pa, PVSCSIState),
> >  VMSTATE_UINT32(rings.txr_len_mask, PVSCSIState),
> > @@ -1255,7 +1255,7 @@ static const VMStateDescription vmstate_pvscsi = {
> >  };
> > 
> >  static Property pvscsi_properties[] = {
> > -DEFINE_PROP_UINT8("use_msg", PVSCSIState, use_msg, 1),
> > +DEFINE_PROP_BOOL("use_msg", PVSCSIState, use_msg, true),
> >  DEFINE_PROP_BIT("x-old-pci-configuration", PVSCSIState, compat_flags,
> >  PVSCSI_COMPAT_OLD_PCI_CONFIGURATION_BIT, false),
> >  DEFINE_PROP_BIT("x-disable-pcie", PVSCSIState, compat_flags,
> > --
> > 2.28.0
> > 
> > This is my first qemu patch. Let know if there are any 

Re: riscv32 wait() problem, qemu or glibc?

2020-09-15 Thread Andreas K . Hüttel
Not sure if this helps in any way, but I tried if the problem is specific to 
the return value 42. Leading to more confusing results... though this looks 
more like an emulator problem than a libc problem to me now.

Happy to debug further, but with limited ideas on how to proceed.

(riscv-ilp32 chroot) farino /tmp # ./wait-test 
child wants to return 34 (0x22), parent received 32 (0x20), difference -2
child wants to return 35 (0x23), parent received 33 (0x21), difference -2
child wants to return 36 (0x24), parent received 34 (0x22), difference -2
child wants to return 37 (0x25), parent received 35 (0x23), difference -2
child wants to return 38 (0x26), parent received 36 (0x24), difference -2
child wants to return 39 (0x27), parent received 37 (0x25), difference -2
child wants to return 40 (0x28), parent received 38 (0x26), difference -2
child wants to return 41 (0x29), parent received 39 (0x27), difference -2
child wants to return 42 (0x2A), parent received 40 (0x28), difference -2
child wants to return 43 (0x2B), parent received 41 (0x29), difference -2
child wants to return 44 (0x2C), parent received 42 (0x2A), difference -2
child wants to return 45 (0x2D), parent received 43 (0x2B), difference -2
child wants to return 46 (0x2E), parent received 44 (0x2C), difference -2
child wants to return 47 (0x2F), parent received 45 (0x2D), difference -2
child wants to return 48 (0x30), parent received 46 (0x2E), difference -2
child wants to return 49 (0x31), parent received 47 (0x2F), difference -2
child wants to return 50 (0x32), parent received 48 (0x30), difference -2
child wants to return 51 (0x33), parent received 49 (0x31), difference -2
child wants to return 52 (0x34), parent received 50 (0x32), difference -2
child wants to return 53 (0x35), parent received 51 (0x33), difference -2
child wants to return 54 (0x36), parent received 52 (0x34), difference -2
child wants to return 55 (0x37), parent received 53 (0x35), difference -2
child wants to return 56 (0x38), parent received 54 (0x36), difference -2
child wants to return 57 (0x39), parent received 55 (0x37), difference -2
child wants to return 58 (0x3A), parent received 56 (0x38), difference -2
child wants to return 59 (0x3B), parent received 57 (0x39), difference -2
child wants to return 60 (0x3C), parent received 58 (0x3A), difference -2
child wants to return 61 (0x3D), parent received 59 (0x3B), difference -2
child wants to return 62 (0x3E), parent received 60 (0x3C), difference -2
child wants to return 63 (0x3F), parent received 61 (0x3D), difference -2
child wants to return 64 (0x40), parent received 62 (0x3E), difference -2
child wants to return 162 (0xA2), parent received 160 (0xA0), difference -2
child wants to return 163 (0xA3), parent received 161 (0xA1), difference -2
child wants to return 164 (0xA4), parent received 162 (0xA2), difference -2
child wants to return 165 (0xA5), parent received 163 (0xA3), difference -2
child wants to return 166 (0xA6), parent received 164 (0xA4), difference -2
child wants to return 167 (0xA7), parent received 165 (0xA5), difference -2
child wants to return 168 (0xA8), parent received 166 (0xA6), difference -2
child wants to return 169 (0xA9), parent received 167 (0xA7), difference -2
child wants to return 170 (0xAA), parent received 168 (0xA8), difference -2
child wants to return 171 (0xAB), parent received 169 (0xA9), difference -2
child wants to return 172 (0xAC), parent received 170 (0xAA), difference -2
child wants to return 173 (0xAD), parent received 171 (0xAB), difference -2
child wants to return 174 (0xAE), parent received 172 (0xAC), difference -2
child wants to return 175 (0xAF), parent received 173 (0xAD), difference -2
child wants to return 176 (0xB0), parent received 174 (0xAE), difference -2
child wants to return 177 (0xB1), parent received 175 (0xAF), difference -2
child wants to return 178 (0xB2), parent received 176 (0xB0), difference -2
child wants to return 179 (0xB3), parent received 177 (0xB1), difference -2
child wants to return 180 (0xB4), parent received 178 (0xB2), difference -2
child wants to return 181 (0xB5), parent received 179 (0xB3), difference -2
child wants to return 182 (0xB6), parent received 180 (0xB4), difference -2
child wants to return 183 (0xB7), parent received 181 (0xB5), difference -2
child wants to return 184 (0xB8), parent received 182 (0xB6), difference -2
child wants to return 185 (0xB9), parent received 183 (0xB7), difference -2
child wants to return 186 (0xBA), parent received 184 (0xB8), difference -2
child wants to return 187 (0xBB), parent received 185 (0xB9), difference -2
child wants to return 188 (0xBC), parent received 186 (0xBA), difference -2
child wants to return 189 (0xBD), parent received 187 (0xBB), difference -2
child wants to return 190 (0xBE), parent received 188 (0xBC), difference -2
child wants to return 191 (0xBF), parent received 189 (0xBD), difference -2
child wants to return 192 (0xC0), parent received 190 (0xBE), difference -2
(riscv-ilp32 

RE: [PATCH v3 02/15] hw/block/nvme: Report actual LBA data shift in LBAF

2020-09-15 Thread Dmitry Fomichev
> -Original Message-
> From: Klaus Jensen 
> Sent: Tuesday, September 15, 2020 3:34 AM
> To: Dmitry Fomichev 
> Cc: Keith Busch ; Klaus Jensen
> ; Kevin Wolf ; Philippe
> Mathieu-Daudé ; Maxim Levitsky
> ; Fam Zheng ; Niklas Cassel
> ; Damien Le Moal ;
> qemu-bl...@nongnu.org; qemu-devel@nongnu.org; Alistair Francis
> ; Matias Bjorling 
> Subject: Re: [PATCH v3 02/15] hw/block/nvme: Report actual LBA data shift in
> LBAF
> 
> On Sep 14 07:14, Dmitry Fomichev wrote:
> > Calculate the data shift value to report based on the set value of
> > logical_block_size device property.
> >
> > In the process, use a local variable to calculate the LBA format
> > index instead of the hardcoded value 0. This makes the code more
> > readable and it will make it easier to add support for multiple LBA
> > formats in the future.
> >
> > Signed-off-by: Dmitry Fomichev 
> > ---
> >  hw/block/nvme.c |  4 +++-
> >  hw/block/nvme.h | 11 +++
> >  2 files changed, 14 insertions(+), 1 deletion(-)
> >
> > diff --git a/hw/block/nvme.c b/hw/block/nvme.c
> > index 3a90d80694..1cfc136042 100644
> > --- a/hw/block/nvme.c
> > +++ b/hw/block/nvme.c
> > @@ -2203,6 +2203,7 @@ static void nvme_init_namespace(NvmeCtrl *n,
> NvmeNamespace *ns, Error **errp)
> >  {
> >  int64_t bs_size;
> >  NvmeIdNs *id_ns = >id_ns;
> > +int lba_index;
> >
> >  bs_size = blk_getlength(n->conf.blk);
> >  if (bs_size < 0) {
> > @@ -2212,7 +2213,8 @@ static void nvme_init_namespace(NvmeCtrl *n,
> NvmeNamespace *ns, Error **errp)
> >
> >  n->ns_size = bs_size;
> >
> > -id_ns->lbaf[0].ds = BDRV_SECTOR_BITS;
> > +lba_index = NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas);
> > +id_ns->lbaf[lba_index].ds = nvme_ilog2(n->conf.logical_block_size);
> 
> Instead of defining a new function, we can directly use clz32().
> 
>   31 - clz32(n->conf.logical_block_size)

Ok nice! I looked up what QEMU uses for binary log, but couldn't find it quickly
so I decided to define a function for that :) Will switch to clzXX in the patch 
set -
I believe there are three occurrences where ilog2 is used in the added code.



RE: [PATCH v3 01/15] hw/block/nvme: Define 64 bit cqe.result

2020-09-15 Thread Dmitry Fomichev
> -Original Message-
> From: Klaus Jensen 
> Sent: Tuesday, September 15, 2020 3:37 AM
> To: Dmitry Fomichev 
> Cc: Keith Busch ; Klaus Jensen
> ; Kevin Wolf ; Philippe
> Mathieu-Daudé ; Maxim Levitsky
> ; Fam Zheng ; Niklas Cassel
> ; Damien Le Moal ;
> qemu-bl...@nongnu.org; qemu-devel@nongnu.org; Alistair Francis
> ; Matias Bjorling 
> Subject: Re: [PATCH v3 01/15] hw/block/nvme: Define 64 bit cqe.result
> 
> On Sep 14 07:14, Dmitry Fomichev wrote:
> > From: Ajay Joshi 
> >
> > A new write command, Zone Append, is added as a part of Zoned
> > Namespace Command Set. Upon successful completion of this command,
> > the controller returns the start LBA of the performed write operation
> > in cqe.result field. Therefore, the maximum size of this variable
> > needs to be changed from 32 to 64 bit, consuming the reserved 32 bit
> > field that follows the result in CQE struct. Since the existing
> > commands are expected to return a 32 bit LE value, two separate
> > variables, result32 and result64, are now kept in a union.
> >
> > Signed-off-by: Ajay Joshi 
> > Signed-off-by: Dmitry Fomichev 
> > Reviewed-by: Klaus Jensen 
> 
> I know that I R-b'ed this, but can this be moved to the namespace types
> patch, since that is the TP that changes this.

You probably meant the ZNS patch since result64 is first used there to return
ZA starting data LBA. Sure, I can move this stuff to that patch.

> 
> Also, I don't think we should touch the tracing in the block driver
> since it is not aware of namespace types.

Ok


RE: [PATCH v2 00/15] hw/block/nvme: Support Namespace Types and Zoned Namespace Command Set

2020-09-15 Thread Dmitry Fomichev
> -Original Message-
> From: Klaus Jensen 
> Sent: Tuesday, September 15, 2020 3:44 AM
> To: Dmitry Fomichev 
> Cc: Keith Busch ; Klaus Jensen
> ; Kevin Wolf ; Philippe
> Mathieu-Daudé ; Maxim Levitsky
> ; Fam Zheng ; Niklas Cassel
> ; Damien Le Moal ;
> qemu-bl...@nongnu.org; qemu-devel@nongnu.org; Alistair Francis
> ; Matias Bjorling 
> Subject: Re: [PATCH v2 00/15] hw/block/nvme: Support Namespace Types
> and Zoned Namespace Command Set
> 
> On Sep 13 07:54, Dmitry Fomichev wrote:
> > v1 -> v2:
> >
> >  - Incorporated feedback from Klaus and Alistair.
> 
> Since it's been a while since I reviewed this, it would have been nice
> if you had listed what feedback you incorporated ;)

I'll try to make the list and include it with v4...


Re: [PATCH V1 32/32] vfio-pci: improved tracing

2020-09-15 Thread Dr. David Alan Gilbert
* Steve Sistare (steven.sist...@oracle.com) wrote:
> Print more info for existing trace points:
>   trace_kvm_irqchip_add_msi_route.
>   trace_pci_update_mappings_del
>   trace_pci_update_mappings_add
> 
> Add new trace points:
>   trace_kvm_irqchip_assign_irqfd
>   trace_msix_table_mmio_write
>   trace_vfio_dma_unmap
>   trace_vfio_dma_map
>   trace_vfio_region
>   trace_vfio_descriptors
>   trace_ram_block_add
> 
> Signed-off-by: Steve Sistare 

Why don't you split this out into a separate patch by itself; if they're
general extra useful tracing they can just go in.

Note that you've also added a new warning in  vfio_dma_unmap

Dave

> ---
>  accel/kvm/kvm-all.c|  8 ++--
>  accel/kvm/trace-events |  3 ++-
>  exec.c |  3 +++
>  hw/pci/msix.c  |  1 +
>  hw/pci/pci.c   | 10 ++
>  hw/pci/trace-events|  5 +++--
>  hw/vfio/common.c   | 16 +++-
>  hw/vfio/pci.c  |  1 +
>  hw/vfio/trace-events   |  9 ++---
>  trace-events   |  2 ++
>  10 files changed, 45 insertions(+), 13 deletions(-)
> 
> diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
> index 63ef6af..5511ea7 100644
> --- a/accel/kvm/kvm-all.c
> +++ b/accel/kvm/kvm-all.c
> @@ -46,6 +46,7 @@
>  #include "sysemu/reset.h"
>  
>  #include "hw/boards.h"
> +#include "trace-root.h"
>  
>  /* This check must be after config-host.h is included */
>  #ifdef CONFIG_EVENTFD
> @@ -1670,7 +1671,7 @@ int kvm_irqchip_add_msi_route(KVMState *s, int vector, 
> PCIDevice *dev)
>  }
>  
>  trace_kvm_irqchip_add_msi_route(dev ? dev->name : (char *)"N/A",
> -vector, virq);
> +vector, virq, msg.address, msg.data);
>  
>  kvm_add_routing_entry(s, );
>  kvm_arch_add_msi_route_post(, vector, dev);
> @@ -1717,6 +1718,7 @@ static int kvm_irqchip_assign_irqfd(KVMState *s, 
> EventNotifier *event,
>  {
>  int fd = event_notifier_get_fd(event);
>  int rfd = resample ? event_notifier_get_fd(resample) : -1;
> +int ret;
>  
>  struct kvm_irqfd irqfd = {
>  .fd = fd,
> @@ -1758,7 +1760,9 @@ static int kvm_irqchip_assign_irqfd(KVMState *s, 
> EventNotifier *event,
>  return -ENOSYS;
>  }
>  
> -return kvm_vm_ioctl(s, KVM_IRQFD, );
> +ret = kvm_vm_ioctl(s, KVM_IRQFD, );
> +trace_kvm_irqchip_assign_irqfd(fd, virq, rfd, ret);
> +return ret;
>  }
>  
>  int kvm_irqchip_add_adapter_route(KVMState *s, AdapterInfo *adapter)
> diff --git a/accel/kvm/trace-events b/accel/kvm/trace-events
> index a68eb66..67a01e6 100644
> --- a/accel/kvm/trace-events
> +++ b/accel/kvm/trace-events
> @@ -9,7 +9,8 @@ kvm_device_ioctl(int fd, int type, void *arg) "dev fd %d, 
> type 0x%x, arg %p"
>  kvm_failed_reg_get(uint64_t id, const char *msg) "Warning: Unable to 
> retrieve ONEREG %" PRIu64 " from KVM: %s"
>  kvm_failed_reg_set(uint64_t id, const char *msg) "Warning: Unable to set 
> ONEREG %" PRIu64 " to KVM: %s"
>  kvm_irqchip_commit_routes(void) ""
> -kvm_irqchip_add_msi_route(char *name, int vector, int virq) "dev %s vector 
> %d virq %d"
> +kvm_irqchip_add_msi_route(char *name, int vector, int virq, uint64_t addr, 
> uint32_t data) "%s, vector %d, virq %d, msg {addr 0x%"PRIx64", data 0x%x}"
> +kvm_irqchip_assign_irqfd(int fd, int virq, int rfd, int status) "(fd=%d, 
> virq=%d, rfd=%d) KVM_IRQFD returns %d"
>  kvm_irqchip_update_msi_route(int virq) "Updating MSI route virq=%d"
>  kvm_irqchip_release_virq(int virq) "virq %d"
>  kvm_set_ioeventfd_mmio(int fd, uint64_t addr, uint32_t val, bool assign, 
> uint32_t size, bool datamatch) "fd: %d @0x%" PRIx64 " val=0x%x assign: %d 
> size: %d match: %d"
> diff --git a/exec.c b/exec.c
> index 5473c09..dd99ee0 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -2319,6 +2319,9 @@ static void ram_block_add(RAMBlock *new_block, Error 
> **errp, bool shared)
>  }
>  ram_block_notify_add(new_block->host, new_block->max_length);
>  }
> +trace_ram_block_add(new_block->host, new_block->max_length,
> +memory_region_name(new_block->mr),
> +new_block->mr->readonly ? "ro" : "rw");
>  }
>  
>  #ifdef CONFIG_POSIX
> diff --git a/hw/pci/msix.c b/hw/pci/msix.c
> index 67e34f3..65a2882 100644
> --- a/hw/pci/msix.c
> +++ b/hw/pci/msix.c
> @@ -189,6 +189,7 @@ static void msix_table_mmio_write(void *opaque, hwaddr 
> addr,
>  int vector = addr / PCI_MSIX_ENTRY_SIZE;
>  bool was_masked;
>  
> +trace_msix_table_mmio_write(dev->name, addr, val, size);
>  was_masked = msix_is_masked(dev, vector);
>  pci_set_long(dev->msix_table + addr, val);
>  msix_handle_mask_update(dev, vector, was_masked);
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index c2e1509..6142411 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -1324,9 +1324,11 @@ void pci_update_mappings(PCIDevice *d)
>  PCIIORegion *r;
>  int i;
>  pcibus_t new_addr;
> +const char *name;
>  
>  for(i = 0; i 

[Bug 1892604] Re: qemu-system-arm: ../hw/usb/hcd-dwc2.c:666: dwc2_glbreg_read: Assertion `addr <= GINTSTS2' failed.

2020-09-15 Thread Petunia
ah, well then its the same error:
qemu-system-arm: /build/qemu/src/qemu-5.1.0/hw/usb/hcd-dwc2.c:666: 
dwc2_glbreg_read: Assertion `addr <= GINTSTS2' failed.

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

Title:
  qemu-system-arm: ../hw/usb/hcd-dwc2.c:666: dwc2_glbreg_read: Assertion
  `addr <= GINTSTS2' failed.

Status in QEMU:
  New

Bug description:
  When trying to run the 2016-05-27 Raspbian image on the emulated
  raspi2 platform, the system boots but shortly after the login prompt
  QEMU (master; commit ID ca489cd037e4d50dc6c40570a167504ad7e5a521) dies
  with:

  qemu-system-arm: ../hw/usb/hcd-dwc2.c:666: dwc2_glbreg_read: Assertion
  `addr <= GINTSTS2' failed.

  Steps to reproduce:

  1. Get the image: wget
  
http://downloads.raspberrypi.org/raspbian/images/raspbian-2016-05-31/2016-05-27
  -raspbian-jessie.zip

  2. Extract the kernel image and DTB:

  sudo losetup -f --show -P 2016-05-27-raspbian-jessie.img
  sudo mkdir /mnt/rpi
  sudo mount /dev/loop11p1 /mnt/rpi/
  cp /mnt/rpi/kernel7.img . 



  cp /mnt/rpi/bcm2709-rpi-2-b.dtb . 



  sudo umount /mnt/rpi 
  sudo losetup -d /dev/loop11 

  3. Run QEMU:
  qemu-system-arm -M raspi2 -m 1G -dtb bcm2709-rpi-2-b.dtb -kernel kernel7.img 
-append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 
root=/dev/mmcblk0p2" -sd 2016-05-27-raspbian-jessie.img -smp 4 -serial stdio 
-display none

  A few seconds after the login prompt is displayed, QEMU will exit with
  the assertion failure.

  I also tried changing all of the asserts to if statements that (for
  MMIO reads) returned 0 and (for writes) just returned, but this
  resulted in a non-responsive system.

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



[Bug 1895053] Re: Cannot nspawn raspbian 10 [FAILED] Failed to start Journal Service.

2020-09-15 Thread Petunia
I take back everything and claim the opposite... same error as bug
reporter

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

Title:
  Cannot nspawn raspbian 10 [FAILED] Failed to start Journal Service.

Status in QEMU:
  New

Bug description:
  Hi, I'm using nspawn and asked the question @systemd-devel. They redirected 
me to you, guessing that nspawn calls a syscall or ioctl qemu isnt aware of and 
can't implement properly?
  They were like: "Sorry, that's not my department." ^^

  Maybe you can reproduce the issue or help me investigating whats wrong
  or put the ball right back into their court? :D

  Testscript:
  wget https://downloads.raspberrypi.org/raspios_lite_armhf_latest -o r.zip
  unzip r.zip
  LOOP=$(losetup --show -Pf *raspios-buster-armhf-lite.img)
  mount ${LOOP}p2 /mnt
  mount ${LOOP}p1 /mnt/boot
  systemd-nspawn --bind /usr/bin/qemu-arm-static --boot --directory=/mnt -- 
systemd.log_level=debug

  Output:
  see attachment

  System:
  uname -a
  Linux MArch 5.8.7-arch1-1 #1 SMP PREEMPT Sat, 05 Sep 2020 12:31:32 +
  x86_64 GNU/Linux

  qemu-arm-static --version
  qemu-arm version 5.1.0

  systemd-nspawn --version
  systemd 246 (246.4-1-arch)
  +PAM +AUDIT -SELINUX -IMA -APPARMOR +SMACK -SYSVINIT +UTMP +LIBCRYPTSETUP
  +GCRYPT +GNUTLS +ACL +XZ +LZ4 +ZSTD +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN
  +PCRE2 default-hierarchy=hybrid

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



[PATCH v2 2/2] hw: usb: hcd-ohci: check for processed TD before retire

2020-09-15 Thread P J P
From: Prasad J Pandit 

While servicing OHCI transfer descriptors(TD), ohci_service_iso_td
retires a TD if it has passed its time frame. It does not check if
the TD was already processed once and holds an error code in TD_CC.
It may happen if the TD list has a loop. Add check to avoid an
infinite loop condition.

Signed-off-by: Prasad J Pandit 
---
 hw/usb/hcd-ohci.c | 4 
 1 file changed, 4 insertions(+)

Update v2: one patch for loop issue
  -> https://lists.nongnu.org/archive/html/qemu-devel/2020-09/msg05145.html

diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c
index 9dc59101f9..8b912e95d3 100644
--- a/hw/usb/hcd-ohci.c
+++ b/hw/usb/hcd-ohci.c
@@ -691,6 +691,10 @@ static int ohci_service_iso_td(OHCIState *ohci, struct 
ohci_ed *ed,
the next ISO TD of the same ED */
 trace_usb_ohci_iso_td_relative_frame_number_big(relative_frame_number,
 frame_count);
+if (OHCI_CC_DATAOVERRUN == OHCI_BM(iso_td.flags, TD_CC)) {
+/* avoid infinite loop */
+return 1;
+}
 OHCI_SET_BM(iso_td.flags, TD_CC, OHCI_CC_DATAOVERRUN);
 ed->head &= ~OHCI_DPTR_MASK;
 ed->head |= (iso_td.next & OHCI_DPTR_MASK);
-- 
2.26.2




[PATCH v2 1/2] hw: usb: hcd-ohci: check len and frame_number variables

2020-09-15 Thread P J P
From: Prasad J Pandit 

While servicing the OHCI transfer descriptors(TD), OHCI host
controller derives variables 'start_addr', 'end_addr', 'len'
etc. from values supplied by the host controller driver.
Host controller driver may supply values such that using
above variables leads to out-of-bounds access issues.
Add checks to avoid them.

AddressSanitizer: stack-buffer-overflow on address 0x7ffd53af76a0
  READ of size 2 at 0x7ffd53af76a0 thread T0
  #0 ohci_service_iso_td ../hw/usb/hcd-ohci.c:734
  #1 ohci_service_ed_list ../hw/usb/hcd-ohci.c:1180
  #2 ohci_process_lists ../hw/usb/hcd-ohci.c:1214
  #3 ohci_frame_boundary ../hw/usb/hcd-ohci.c:1257
  #4 timerlist_run_timers ../util/qemu-timer.c:572
  #5 qemu_clock_run_timers ../util/qemu-timer.c:586
  #6 qemu_clock_run_all_timers ../util/qemu-timer.c:672
  #7 main_loop_wait ../util/main-loop.c:527
  #8 qemu_main_loop ../softmmu/vl.c:1676
  #9 main ../softmmu/main.c:50

Reported-by: Gaoning Pan 
Reported-by: Yongkang Jia 
Reported-by: Yi Ren 
Signed-off-by: Prasad J Pandit 
---
 hw/usb/hcd-ohci.c | 24 ++--
 1 file changed, 22 insertions(+), 2 deletions(-)

Update v2: one patch to fix oob access
  -> https://lists.nongnu.org/archive/html/qemu-devel/2020-09/msg05145.html

diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c
index 1e6e85e86a..9dc59101f9 100644
--- a/hw/usb/hcd-ohci.c
+++ b/hw/usb/hcd-ohci.c
@@ -731,7 +731,11 @@ static int ohci_service_iso_td(OHCIState *ohci, struct 
ohci_ed *ed,
 }
 
 start_offset = iso_td.offset[relative_frame_number];
-next_offset = iso_td.offset[relative_frame_number + 1];
+if (relative_frame_number < frame_count) {
+next_offset = iso_td.offset[relative_frame_number + 1];
+} else {
+next_offset = iso_td.be;
+}
 
 if (!(OHCI_BM(start_offset, TD_PSW_CC) & 0xe) || 
 ((relative_frame_number < frame_count) && 
@@ -764,7 +768,12 @@ static int ohci_service_iso_td(OHCIState *ohci, struct 
ohci_ed *ed,
 }
 } else {
 /* Last packet in the ISO TD */
-end_addr = iso_td.be;
+end_addr = next_offset;
+}
+
+if (start_addr > end_addr) {
+trace_usb_ohci_iso_td_bad_cc_overrun(start_addr, end_addr);
+return 1;
 }
 
 if ((start_addr & OHCI_PAGE_MASK) != (end_addr & OHCI_PAGE_MASK)) {
@@ -773,6 +782,9 @@ static int ohci_service_iso_td(OHCIState *ohci, struct 
ohci_ed *ed,
 } else {
 len = end_addr - start_addr + 1;
 }
+if (len > sizeof(ohci->usb_buf)) {
+len = sizeof(ohci->usb_buf);
+}
 
 if (len && dir != OHCI_TD_DIR_IN) {
 if (ohci_copy_iso_td(ohci, start_addr, end_addr, ohci->usb_buf, len,
@@ -975,8 +987,16 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed 
*ed)
 if ((td.cbp & 0xf000) != (td.be & 0xf000)) {
 len = (td.be & 0xfff) + 0x1001 - (td.cbp & 0xfff);
 } else {
+if (td.cbp > td.be) {
+trace_usb_ohci_iso_td_bad_cc_overrun(td.cbp, td.be);
+ohci_die(ohci);
+return 1;
+}
 len = (td.be - td.cbp) + 1;
 }
+if (len > sizeof(ohci->usb_buf)) {
+len = sizeof(ohci->usb_buf);
+}
 
 pktlen = len;
 if (len && dir != OHCI_TD_DIR_IN) {
-- 
2.26.2




[PATCH v2 0/2] hw: usb: hcd-ohci: fix oob access and loop issues

2020-09-15 Thread P J P
From: Prasad J Pandit 

Hello,

* While servicing transfer descriptors(TD) in ohci_service[_iso]_td
  routines, it may lead to out-of-bounds access and/or infinite loop
  issues, as the OHCI controller driver may supply malicious values
  to derive frame_number, start_addr, end_addr etc. variables.

* This series breaks earlier single patch into two.
  One for an out-of-bounds access issue and another to fix infinite
  loop case.
  -> https://lists.nongnu.org/archive/html/qemu-devel/2020-09/msg05145.html

Thank you.
--
Prasad J Pandit (2):
  hw: usb: hcd-ohci: check len and frame_number variables
  hw: usb: hcd-ohci: check for processed TD before retire

 hw/usb/hcd-ohci.c | 28 ++--
 1 file changed, 26 insertions(+), 2 deletions(-)

--
2.26.2




Re: [PATCH v10 15/26] cirrus: Building freebsd in a single short

2020-09-15 Thread Yonggang Luo
On Wed, Sep 16, 2020 at 1:48 AM Philippe Mathieu-Daudé 
wrote:
>
> Typo "single shot" in subject?

Yeap, single shot, hope the maintainer fix it
>
>
> On 9/15/20 7:12 PM, Yonggang Luo wrote:
> > This reverts commit 45f7b7b9f38f5c4d1529a37c93dedfc26a231bba
> > ("cirrus.yml: Split FreeBSD job into two parts").
> >
> > freebsd 1 hour limit not hit anymore
> >
> > I think we going to a wrong direction, I think there is some tests a
stall the test runner,
> > please look at
> > https://cirrus-ci.com/task/5110577531977728
> > When its running properly, the consumed time are little, but when tests
running too long,
> > look at the cpu usage, the cpu usage are nearly zero. doesn't consuming
time.
> >
> > And look at
> > https://cirrus-ci.com/task/6119341601062912
> >
> > If the tests running properly, the time consuming are little
> > We should not hide the error by split them
> >
> > Signed-off-by: Yonggang Luo 
> > Reviewed-by: Daniel P. Berrangé 
> > Reviewed-by: Ed Maste 
> > ---
> >  .cirrus.yml | 35 ---
> >  1 file changed, 8 insertions(+), 27 deletions(-)
> >
> > diff --git a/.cirrus.yml b/.cirrus.yml
> > index 3dd9fcff7f..25fb4add9b 100644
> > --- a/.cirrus.yml
> > +++ b/.cirrus.yml
> > @@ -1,38 +1,19 @@
> >  env:
> >CIRRUS_CLONE_DEPTH: 1
> >
> > -freebsd_1st_task:
> > +freebsd_12_task:
> >freebsd_instance:
> >  image_family: freebsd-12-1
> > -cpu: 4
> > -memory: 4G
> > -  install_script: ASSUME_ALWAYS_YES=yes pkg bootstrap -f ; pkg install
-y
> > -bash curl cyrus-sasl git glib gmake gnutls gsed
> > -nettle perl5 pixman pkgconf png usbredir
> > +cpu: 8
> > +memory: 8G
> > +  install_script:
> > +- ASSUME_ALWAYS_YES=yes pkg bootstrap -f ;
> > +- pkg install -y bash curl cyrus-sasl git glib gmake gnutls gsed
> > +  nettle perl5 pixman pkgconf png usbredir
> >script:
> >  - mkdir build
> >  - cd build
> > -- ../configure --disable-user --target-list-exclude='alpha-softmmu
> > -ppc64-softmmu ppc-softmmu riscv32-softmmu riscv64-softmmu
s390x-softmmu
> > -sparc64-softmmu sparc-softmmu x86_64-softmmu i386-softmmu'
> > ---enable-werror || { cat config.log; exit 1; }
> > -- gmake -j$(sysctl -n hw.ncpu)
> > -- gmake -j$(sysctl -n hw.ncpu) check
> > -
> > -freebsd_2nd_task:
> > -  freebsd_instance:
> > -image_family: freebsd-12-1
> > -cpu: 4
> > -memory: 4G
> > -  install_script: ASSUME_ALWAYS_YES=yes pkg bootstrap -f ; pkg install
-y
> > -bash curl cyrus-sasl git glib gmake gnutls gtk3 gsed libepoxy
mesa-libs
> > -nettle perl5 pixman pkgconf png SDL2 usbredir
> > -  script:
> > -- ./configure --enable-werror --target-list='alpha-softmmu
ppc64-softmmu
> > -ppc-softmmu riscv32-softmmu riscv64-softmmu s390x-softmmu
> > -sparc64-softmmu sparc-softmmu x86_64-softmmu i386-softmmu
> > -sparc-bsd-user sparc64-bsd-user x86_64-bsd-user i386-bsd-user'
> > -|| { cat config.log; exit 1; }
> > +- ../configure --enable-werror || { cat config.log; exit 1; }
> >  - gmake -j$(sysctl -n hw.ncpu)
> >  - gmake -j$(sysctl -n hw.ncpu) check
> >
> >
>


--
 此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo


Re: [PATCH 1/5] qom: Allow objects to be allocated with increased alignment

2020-09-15 Thread Eduardo Habkost
On Tue, Sep 15, 2020 at 10:46:31AM -0700, Richard Henderson wrote:
> It turns out that some hosts have a default malloc alignment less
> than that required for vectors.
> 
> We assume that, with compiler annotation on CPUArchState, that we
> can properly align the vector portion of the guest state.  Fix the
> alignment of the allocation by using qemu_memalloc when required.
> 
> Signed-off-by: Richard Henderson 
> ---
> Cc: Paolo Bonzini 
> Cc: "Daniel P. Berrangé" 
> Cc: Eduardo Habkost 
> ---
>  include/qom/object.h |  4 
>  qom/object.c | 16 +---
>  2 files changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/include/qom/object.h b/include/qom/object.h
> index 056f67ab3b..d52d0781a3 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -770,6 +770,9 @@ struct Object
>   * @instance_size: The size of the object (derivative of #Object).  If
>   *   @instance_size is 0, then the size of the object will be the size of the
>   *   parent object.
> + * @instance_align: The required alignment of the object.  If @instance_align
> + *   is 0, then normal malloc alignment is sufficient; if non-zero, then we
> + *   must use qemu_memalign for allocation.
>   * @instance_init: This function is called to initialize an object.  The 
> parent
>   *   class will have already been initialized so the type is only responsible
>   *   for initializing its own members.
> @@ -807,6 +810,7 @@ struct TypeInfo
>  const char *parent;
>  
>  size_t instance_size;
> +size_t instance_align;
>  void (*instance_init)(Object *obj);
>  void (*instance_post_init)(Object *obj);
>  void (*instance_finalize)(Object *obj);
> diff --git a/qom/object.c b/qom/object.c
> index 387efb25eb..2e53cb44a6 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -50,6 +50,7 @@ struct TypeImpl
>  size_t class_size;
>  
>  size_t instance_size;
> +size_t instance_align;
>  
>  void (*class_init)(ObjectClass *klass, void *data);
>  void (*class_base_init)(ObjectClass *klass, void *data);
> @@ -114,6 +115,7 @@ static TypeImpl *type_new(const TypeInfo *info)
>  
>  ti->class_size = info->class_size;
>  ti->instance_size = info->instance_size;
> +ti->instance_align = info->instance_align;
>  
>  ti->class_init = info->class_init;
>  ti->class_base_init = info->class_base_init;
> @@ -691,13 +693,21 @@ static void object_finalize(void *data)
>  static Object *object_new_with_type(Type type)
>  {
>  Object *obj;
> +size_t size, align;
>  
>  g_assert(type != NULL);
>  type_initialize(type);
>  
> -obj = g_malloc(type->instance_size);
> -object_initialize_with_type(obj, type->instance_size, type);
> -obj->free = g_free;
> +size = type->instance_size;
> +align = type->instance_align;
> +if (align) {

If we check for (align > G_MEM_ALIGN) instead, we will be able to
set instance_align automatically at OBJECT_DEFINE_TYPE*.

> +obj = qemu_memalign(align, size);
> +} else {
> +obj = g_malloc(size);
> +}
> +
> +object_initialize_with_type(obj, size, type);
> +obj->free = (align ? qemu_vfree : g_free);
>  
>  return obj;
>  }
> -- 
> 2.25.1
> 

-- 
Eduardo




[PATCH 4/5] target/riscv: Set instance_align on RISCVCPU TypeInfo

2020-09-15 Thread Richard Henderson
Fix alignment of CPURISCVState.vreg.

Signed-off-by: Richard Henderson 
---
Cc: Alistair Francis 
Cc: qemu-ri...@nongnu.org
---
 target/riscv/cpu.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 57c006df5d..0bbfd7f457 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -628,6 +628,7 @@ static const TypeInfo riscv_cpu_type_infos[] = {
 .name = TYPE_RISCV_CPU,
 .parent = TYPE_CPU,
 .instance_size = sizeof(RISCVCPU),
+.instance_align = __alignof__(RISCVCPU),
 .instance_init = riscv_cpu_init,
 .abstract = true,
 .class_size = sizeof(RISCVCPUClass),
-- 
2.25.1




[Bug 1892604] Re: qemu-system-arm: ../hw/usb/hcd-dwc2.c:666: dwc2_glbreg_read: Assertion `addr <= GINTSTS2' failed.

2020-09-15 Thread Brendan Dolan-Gavitt
That part is easily fixed by running

qemu-img resize 2016-05-27-raspbian-jessie.img 4G

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

Title:
  qemu-system-arm: ../hw/usb/hcd-dwc2.c:666: dwc2_glbreg_read: Assertion
  `addr <= GINTSTS2' failed.

Status in QEMU:
  New

Bug description:
  When trying to run the 2016-05-27 Raspbian image on the emulated
  raspi2 platform, the system boots but shortly after the login prompt
  QEMU (master; commit ID ca489cd037e4d50dc6c40570a167504ad7e5a521) dies
  with:

  qemu-system-arm: ../hw/usb/hcd-dwc2.c:666: dwc2_glbreg_read: Assertion
  `addr <= GINTSTS2' failed.

  Steps to reproduce:

  1. Get the image: wget
  
http://downloads.raspberrypi.org/raspbian/images/raspbian-2016-05-31/2016-05-27
  -raspbian-jessie.zip

  2. Extract the kernel image and DTB:

  sudo losetup -f --show -P 2016-05-27-raspbian-jessie.img
  sudo mkdir /mnt/rpi
  sudo mount /dev/loop11p1 /mnt/rpi/
  cp /mnt/rpi/kernel7.img . 



  cp /mnt/rpi/bcm2709-rpi-2-b.dtb . 



  sudo umount /mnt/rpi 
  sudo losetup -d /dev/loop11 

  3. Run QEMU:
  qemu-system-arm -M raspi2 -m 1G -dtb bcm2709-rpi-2-b.dtb -kernel kernel7.img 
-append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 
root=/dev/mmcblk0p2" -sd 2016-05-27-raspbian-jessie.img -smp 4 -serial stdio 
-display none

  A few seconds after the login prompt is displayed, QEMU will exit with
  the assertion failure.

  I also tried changing all of the asserts to if statements that (for
  MMIO reads) returned 0 and (for writes) just returned, but this
  resulted in a non-responsive system.

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



[PATCH 1/5] qom: Allow objects to be allocated with increased alignment

2020-09-15 Thread Richard Henderson
It turns out that some hosts have a default malloc alignment less
than that required for vectors.

We assume that, with compiler annotation on CPUArchState, that we
can properly align the vector portion of the guest state.  Fix the
alignment of the allocation by using qemu_memalloc when required.

Signed-off-by: Richard Henderson 
---
Cc: Paolo Bonzini 
Cc: "Daniel P. Berrangé" 
Cc: Eduardo Habkost 
---
 include/qom/object.h |  4 
 qom/object.c | 16 +---
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/include/qom/object.h b/include/qom/object.h
index 056f67ab3b..d52d0781a3 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -770,6 +770,9 @@ struct Object
  * @instance_size: The size of the object (derivative of #Object).  If
  *   @instance_size is 0, then the size of the object will be the size of the
  *   parent object.
+ * @instance_align: The required alignment of the object.  If @instance_align
+ *   is 0, then normal malloc alignment is sufficient; if non-zero, then we
+ *   must use qemu_memalign for allocation.
  * @instance_init: This function is called to initialize an object.  The parent
  *   class will have already been initialized so the type is only responsible
  *   for initializing its own members.
@@ -807,6 +810,7 @@ struct TypeInfo
 const char *parent;
 
 size_t instance_size;
+size_t instance_align;
 void (*instance_init)(Object *obj);
 void (*instance_post_init)(Object *obj);
 void (*instance_finalize)(Object *obj);
diff --git a/qom/object.c b/qom/object.c
index 387efb25eb..2e53cb44a6 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -50,6 +50,7 @@ struct TypeImpl
 size_t class_size;
 
 size_t instance_size;
+size_t instance_align;
 
 void (*class_init)(ObjectClass *klass, void *data);
 void (*class_base_init)(ObjectClass *klass, void *data);
@@ -114,6 +115,7 @@ static TypeImpl *type_new(const TypeInfo *info)
 
 ti->class_size = info->class_size;
 ti->instance_size = info->instance_size;
+ti->instance_align = info->instance_align;
 
 ti->class_init = info->class_init;
 ti->class_base_init = info->class_base_init;
@@ -691,13 +693,21 @@ static void object_finalize(void *data)
 static Object *object_new_with_type(Type type)
 {
 Object *obj;
+size_t size, align;
 
 g_assert(type != NULL);
 type_initialize(type);
 
-obj = g_malloc(type->instance_size);
-object_initialize_with_type(obj, type->instance_size, type);
-obj->free = g_free;
+size = type->instance_size;
+align = type->instance_align;
+if (align) {
+obj = qemu_memalign(align, size);
+} else {
+obj = g_malloc(size);
+}
+
+object_initialize_with_type(obj, size, type);
+obj->free = (align ? qemu_vfree : g_free);
 
 return obj;
 }
-- 
2.25.1




Re: [PATCH] guest agent: Fixes for windows guest agent building on msys2/mingw

2020-09-15 Thread Philippe Mathieu-Daudé
On 9/15/20 7:41 PM, 罗勇刚(Yonggang Luo) wrote:
> On Wed, Sep 16, 2020 at 12:41 AM Philippe Mathieu-Daudé
> mailto:phi...@redhat.com>> wrote:
>>
>> On 9/15/20 6:33 PM, Yonggang Luo wrote:
>> > error message:
>> > "cc" "-Iqga/qemu-ga.exe.p" "-Iqga" "-I../qga" "-I." "-Iqapi"
> "-Itrace" "-Iui" "-Iui/shader" "-IC:/CI-Tools/msys64/mingw64/include"
> "-IC:/CI-Tools/msys64/mingw64/include/glib-2.0"
> "-IC:/CI-Tools/msys64/mingw64/lib/glib-2.0/include"
> "-fdiagnostics-color=auto" "-pipe" "-Wall" "-Winvalid-pch" "-Werror"
> "-std=gnu99" "-g" "-m64" "-mcx16" "-D_GNU_SOURCE"
> "-D_FILE_OFFSET_BITS=64" "-D_LARGEFILE_SOURCE" "-Wstrict-prototypes"
> "-Wredundant-decls" "-Wundef" "-Wwrite-strings" "-Wmissing-prototypes"
> "-fno-strict-aliasing" "-fno-common" "-fwrapv" "-Wold-style-declaration"
> "-Wold-style-definition" "-Wtype-limits" "-Wformat-security"
> "-Wformat-y2k" "-Winit-self" "-Wignored-qualifiers" "-Wempty-body"
> "-Wnested-externs" "-Wendif-labels" "-Wexpansion-to-defined"
> "-Wno-missing-include-dirs" "-Wno-shift-negative-value" "-Wno-psabi"
> "-fstack-protector-strong" "-iquote" "/c/work/xemu/qemu/tcg/i386"
> "-iquote" "." "-iquote" "/c/work/xemu/qemu" "-iquote"
> "/c/work/xemu/qemu/accel/tcg" "-iquote" "/c/work/xemu/qemu/include"
> "-iquote" "/c/work/xemu/qemu/disas/libvixl" "-pthread" "-mms-bitfields"
> -MD -MQ qga/qemu-ga.exe.p/commands-win32.c.obj -MF
> "qga/qemu-ga.exe.p/commands-win32.c.obj.d" -o
> qga/qemu-ga.exe.p/commands-win32.c.obj "-c" ../qga/commands-win32.c -MP
>> > ../qga/commands-win32.c:62:24: error: redundant redeclaration of
> 'CM_Get_DevNode_PropertyW' [-Werror=redundant-decls]
>> >    62 | CMAPI CONFIGRET WINAPI CM_Get_DevNode_PropertyW(
>> >       |                        ^~~~
>> > In file included from ../qga/commands-win32.c:26:
>> >
> C:/CI-Tools/msys64/mingw64/x86_64-w64-mingw32/include/cfgmgr32.h:840:26:
> note: previous declaration of 'CM_Get_DevNode_PropertyW' was here
>> >   840 |   CMAPI CONFIGRET WINAPI CM_Get_DevNode_PropertyW(DEVINST
> dnDevInst, const DEVPROPKEY *PropertyKey, DEVPROPTYPE *PropertyType,
> PBYTE PropertyBuffer, PULONG PropertyBufferSize, ULONG ulFlags);
>> >       |                          ^~~~
>> > cc1.exe: all warnings being treated as errors
>> > make: [Makefile.ninja:5143:qga/qemu-ga.exe.p/commands-win32.c.obj]
> 错误 1 (已忽略)
>> >
>> > This error comes from qemu configure didn't add predefined macro
> -DUNICODE -D_UNICODE in QEMU_CFLAGS,
>> > and these too macro are standard config for win32 if using windows
> wide api.
>> >
>> > in cfgmgr32.h
>> >   CMAPI CONFIGRET WINAPI CM_Get_DevNode_PropertyW(DEVINST dnDevInst,
> const DEVPROPKEY *PropertyKey, DEVPROPTYPE *PropertyType, PBYTE
> PropertyBuffer, PULONG PropertyBufferSize, ULONG ulFlags);
>> > #ifdef UNICODE
>> > #define CM_Get_DevNode_Property CM_Get_DevNode_PropertyW
>> > #endif
>> >
>> > macro CM_Get_DevNode_Property defined only when UNICODE are defined.
>> > and in win32, UNICODE and _UNICODE should be defined at the same time
>> >
>> > #endif
>> >
>> > Signed-off-by: Yonggang Luo  >
>> > ---
>> >  configure | 1 +
>> >  1 file changed, 1 insertion(+)
>> >
>> > diff --git a/configure b/configure
>> > index 9f141891ea..f5d661af4a 100755
>> > --- a/configure
>> > +++ b/configure
>> > @@ -812,6 +812,7 @@ MINGW32*)
>> >    mingw32="yes"
>> >    hax="yes"
>> >    whpx=""
>> > +  QEMU_CFLAGS="-DUNICODE -D_UNICODE $QEMU_CFLAGS"
>>
>> What about declaring them in include/qemu/osdep.h
>> instead?
> That's a good idea.
> But more compiling error warns me that the windows version of qemu are
> not in a good situation.

:)

> On Win32, all API should call the wide version so that support for
> Unicode properly.
> But obviously the currently qemu didn't do that
> 
> ```
[...]
> ../util/qemu-sockets.c: In function 'socket_sockaddr_to_address_inet':
> C:/work/xemu/qemu/include/qapi/error.h:319:25: error: format '%s'
> expects argument of type 'char *', but argument 6 has type 'WCHAR *'
> {aka 'short unsigned int *'} [-Werror=format=]
>   319 |                         (fmt), ## __VA_ARGS__)
>       |                         ^
> ../util/qemu-sockets.c:1235:9: note: in expansion of macro 'error_setg'
>  1235 |         error_setg(errp, "Cannot format numeric socket address: %s",
>       |         ^~
> In file included from ../io/dns-resolver.c:26:
> ../io/dns-resolver.c: In function 'qio_dns_resolver_lookup_sync_inet':
> C:/work/xemu/qemu/include/qapi/error.h:319:25: error: format '%s'
> expects argument of type 'char *', but argument 8 has type 'WCHAR *'
> {aka 'short unsigned int *'} [-Werror=format=]
>   319 |                         (fmt), ## __VA_ARGS__)
>       |                         ^
> ../io/dns-resolver.c:93:9: note: in expansion of macro 'error_setg'
>    93 |         error_setg(errp, "address resolution failed for %s:%s: %s",
>       |         ^~
> cc1.exe: all warnings being treated as errors
> make: 

[Bug 1892604] Re: qemu-system-arm: ../hw/usb/hcd-dwc2.c:666: dwc2_glbreg_read: Assertion `addr <= GINTSTS2' failed.

2020-09-15 Thread Petunia
for me the output is:
% qemu-system-arm -M raspi2 -m 1G -dtb bcm2709-rpi-2-b.dtb -kernel kernel7.img 
-append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 
root=/dev/mmcblk0p2" -sd 2016-05-27-raspbian-jessie.img -smp 4 -serial stdio 
-display none

WARNING: Image format was not specified for '2016-05-27-raspbian-jessie.img' 
and probing guessed raw.
 Automatically detecting the format is dangerous for raw images, write 
operations on block 0 will be restricted.
 Specify the 'raw' format explicitly to remove the restrictions.
qemu-system-arm: Invalid SD card size: 3.74 GiB
SD card size has to be a power of 2, e.g. 4 GiB.
You can resize disk images with 'qemu-img resize  '
(note that this will lose data if you make the image smaller than it currently 
is).

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

Title:
  qemu-system-arm: ../hw/usb/hcd-dwc2.c:666: dwc2_glbreg_read: Assertion
  `addr <= GINTSTS2' failed.

Status in QEMU:
  New

Bug description:
  When trying to run the 2016-05-27 Raspbian image on the emulated
  raspi2 platform, the system boots but shortly after the login prompt
  QEMU (master; commit ID ca489cd037e4d50dc6c40570a167504ad7e5a521) dies
  with:

  qemu-system-arm: ../hw/usb/hcd-dwc2.c:666: dwc2_glbreg_read: Assertion
  `addr <= GINTSTS2' failed.

  Steps to reproduce:

  1. Get the image: wget
  
http://downloads.raspberrypi.org/raspbian/images/raspbian-2016-05-31/2016-05-27
  -raspbian-jessie.zip

  2. Extract the kernel image and DTB:

  sudo losetup -f --show -P 2016-05-27-raspbian-jessie.img
  sudo mkdir /mnt/rpi
  sudo mount /dev/loop11p1 /mnt/rpi/
  cp /mnt/rpi/kernel7.img . 



  cp /mnt/rpi/bcm2709-rpi-2-b.dtb . 



  sudo umount /mnt/rpi 
  sudo losetup -d /dev/loop11 

  3. Run QEMU:
  qemu-system-arm -M raspi2 -m 1G -dtb bcm2709-rpi-2-b.dtb -kernel kernel7.img 
-append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 
root=/dev/mmcblk0p2" -sd 2016-05-27-raspbian-jessie.img -smp 4 -serial stdio 
-display none

  A few seconds after the login prompt is displayed, QEMU will exit with
  the assertion failure.

  I also tried changing all of the asserts to if statements that (for
  MMIO reads) returned 0 and (for writes) just returned, but this
  resulted in a non-responsive system.

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



Re: [PATCH V1 22/32] char: qio_channel_socket_accept reuse fd

2020-09-15 Thread Daniel P . Berrangé
On Tue, Sep 15, 2020 at 06:33:34PM +0100, Dr. David Alan Gilbert wrote:
> * Steve Sistare (steven.sist...@oracle.com) wrote:
> > From: Mark Kanda 
> > 
> > Add an fd argument to qio_channel_socket_accept.  If not -1, the channel
> > uses that fd instead of accepting a new socket connection.  All callers
> > pass -1 in this patch, so no functional change.
> 
> Doesn't some of this just come from the fact you're insisting on reusing
> the command line?   We should be able to open a chardev on an fd
> shouldn't we?

Even ignoring that question, this patch looks pointless to me. The callers
have to be modified to pass in the FD to use instead of accepting a new
connection. Given that, you migt as well just modify the callers to use
the FD immediately if valid and never call qio_channel_socket_accept at all.

ie

   if (reuse_fd)
  fd = reuse_fd;
   else
  fd = qio_channel_socket_accept(ioc...)

> 
> Dave
> 
> > Signed-off-by: Mark Kanda 
> > Signed-off-by: Steve Sistare 
> > ---
> >  include/io/channel-socket.h|  3 ++-
> >  io/channel-socket.c| 12 +---
> >  io/net-listener.c  |  4 ++--
> >  scsi/qemu-pr-helper.c  |  2 +-
> >  tests/qtest/tpm-emu.c  |  2 +-
> >  tests/test-char.c  |  2 +-
> >  tests/test-io-channel-socket.c |  4 ++--
> >  7 files changed, 18 insertions(+), 11 deletions(-)
> > 
> > diff --git a/include/io/channel-socket.h b/include/io/channel-socket.h
> > index 777ff59..0ffc560 100644
> > --- a/include/io/channel-socket.h
> > +++ b/include/io/channel-socket.h
> > @@ -248,6 +248,7 @@ qio_channel_socket_get_remote_address(QIOChannelSocket 
> > *ioc,
> >  /**
> >   * qio_channel_socket_accept:
> >   * @ioc: the socket channel object
> > + * @reuse_fd: fd to reuse; -1 otherwise
> >   * @errp: pointer to a NULL-initialized error object
> >   *
> >   * If the socket represents a server, then this accepts
> > @@ -258,7 +259,7 @@ qio_channel_socket_get_remote_address(QIOChannelSocket 
> > *ioc,
> >   */
> >  QIOChannelSocket *
> >  qio_channel_socket_accept(QIOChannelSocket *ioc,
> > -  Error **errp);
> > +  int reuse_fd, Error **errp);
> >  
> >  
> >  #endif /* QIO_CHANNEL_SOCKET_H */
> > diff --git a/io/channel-socket.c b/io/channel-socket.c
> > index e1b4667..dde12bf 100644
> > --- a/io/channel-socket.c
> > +++ b/io/channel-socket.c
> > @@ -352,7 +352,7 @@ void qio_channel_socket_dgram_async(QIOChannelSocket 
> > *ioc,
> >  
> >  QIOChannelSocket *
> >  qio_channel_socket_accept(QIOChannelSocket *ioc,
> > -  Error **errp)
> > +  int reuse_fd, Error **errp)
> >  {
> >  QIOChannelSocket *cioc;
> >  
> > @@ -362,8 +362,14 @@ qio_channel_socket_accept(QIOChannelSocket *ioc,
> >  
> >   retry:
> >  trace_qio_channel_socket_accept(ioc);
> > -cioc->fd = qemu_accept(ioc->fd, (struct sockaddr *)>remoteAddr,
> > -   >remoteAddrLen);
> > +
> > +if (reuse_fd != -1) {
> > +cioc->fd = reuse_fd;
> > +} else {
> > +cioc->fd = qemu_accept(ioc->fd, (struct sockaddr 
> > *)>remoteAddr,
> > +   >remoteAddrLen);
> > +}
> > +
> >  if (cioc->fd < 0) {
> >  if (errno == EINTR) {
> >  goto retry;
> > diff --git a/io/net-listener.c b/io/net-listener.c
> > index 5d8a226..bbdea1e 100644
> > --- a/io/net-listener.c
> > +++ b/io/net-listener.c
> > @@ -45,7 +45,7 @@ static gboolean qio_net_listener_channel_func(QIOChannel 
> > *ioc,
> >  QIOChannelSocket *sioc;
> >  
> >  sioc = qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc),
> > - NULL);
> > + -1, NULL);
> >  if (!sioc) {
> >  return TRUE;
> >  }
> > @@ -194,7 +194,7 @@ static gboolean 
> > qio_net_listener_wait_client_func(QIOChannel *ioc,
> >  QIOChannelSocket *sioc;
> >  
> >  sioc = qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc),
> > - NULL);
> > + -1, NULL);
> >  if (!sioc) {
> >  return TRUE;
> >  }
> > diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c
> > index 57ad830..0e6d683 100644
> > --- a/scsi/qemu-pr-helper.c
> > +++ b/scsi/qemu-pr-helper.c
> > @@ -800,7 +800,7 @@ static gboolean accept_client(QIOChannel *ioc, 
> > GIOCondition cond, gpointer opaqu
> >  PRHelperClient *prh;
> >  
> >  cioc = qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc),
> > - NULL);
> > + -1, NULL);
> >  if (!cioc) {
> >  return TRUE;
> >  }
> > diff --git a/tests/qtest/tpm-emu.c b/tests/qtest/tpm-emu.c
> > index 2e8eb7b..19e5dab 100644
> > --- a/tests/qtest/tpm-emu.c
> > +++ b/tests/qtest/tpm-emu.c
> > @@ -83,7 +83,7 @@ void *tpm_emu_ctrl_thread(void *data)
> >  g_cond_signal(>data_cond);
> >  
> >  

Re: [PATCH v10 15/26] cirrus: Building freebsd in a single short

2020-09-15 Thread Philippe Mathieu-Daudé
Typo "single shot" in subject?

On 9/15/20 7:12 PM, Yonggang Luo wrote:
> This reverts commit 45f7b7b9f38f5c4d1529a37c93dedfc26a231bba
> ("cirrus.yml: Split FreeBSD job into two parts").
> 
> freebsd 1 hour limit not hit anymore
> 
> I think we going to a wrong direction, I think there is some tests a stall 
> the test runner,
> please look at
> https://cirrus-ci.com/task/5110577531977728
> When its running properly, the consumed time are little, but when tests 
> running too long,
> look at the cpu usage, the cpu usage are nearly zero. doesn't consuming time.
> 
> And look at
> https://cirrus-ci.com/task/6119341601062912
> 
> If the tests running properly, the time consuming are little
> We should not hide the error by split them
> 
> Signed-off-by: Yonggang Luo 
> Reviewed-by: Daniel P. Berrangé 
> Reviewed-by: Ed Maste 
> ---
>  .cirrus.yml | 35 ---
>  1 file changed, 8 insertions(+), 27 deletions(-)
> 
> diff --git a/.cirrus.yml b/.cirrus.yml
> index 3dd9fcff7f..25fb4add9b 100644
> --- a/.cirrus.yml
> +++ b/.cirrus.yml
> @@ -1,38 +1,19 @@
>  env:
>CIRRUS_CLONE_DEPTH: 1
>  
> -freebsd_1st_task:
> +freebsd_12_task:
>freebsd_instance:
>  image_family: freebsd-12-1
> -cpu: 4
> -memory: 4G
> -  install_script: ASSUME_ALWAYS_YES=yes pkg bootstrap -f ; pkg install -y
> -bash curl cyrus-sasl git glib gmake gnutls gsed
> -nettle perl5 pixman pkgconf png usbredir
> +cpu: 8
> +memory: 8G
> +  install_script:
> +- ASSUME_ALWAYS_YES=yes pkg bootstrap -f ;
> +- pkg install -y bash curl cyrus-sasl git glib gmake gnutls gsed
> +  nettle perl5 pixman pkgconf png usbredir
>script:
>  - mkdir build
>  - cd build
> -- ../configure --disable-user --target-list-exclude='alpha-softmmu
> -ppc64-softmmu ppc-softmmu riscv32-softmmu riscv64-softmmu 
> s390x-softmmu
> -sparc64-softmmu sparc-softmmu x86_64-softmmu i386-softmmu'
> ---enable-werror || { cat config.log; exit 1; }
> -- gmake -j$(sysctl -n hw.ncpu)
> -- gmake -j$(sysctl -n hw.ncpu) check
> -
> -freebsd_2nd_task:
> -  freebsd_instance:
> -image_family: freebsd-12-1
> -cpu: 4
> -memory: 4G
> -  install_script: ASSUME_ALWAYS_YES=yes pkg bootstrap -f ; pkg install -y
> -bash curl cyrus-sasl git glib gmake gnutls gtk3 gsed libepoxy mesa-libs
> -nettle perl5 pixman pkgconf png SDL2 usbredir
> -  script:
> -- ./configure --enable-werror --target-list='alpha-softmmu ppc64-softmmu
> -ppc-softmmu riscv32-softmmu riscv64-softmmu s390x-softmmu
> -sparc64-softmmu sparc-softmmu x86_64-softmmu i386-softmmu
> -sparc-bsd-user sparc64-bsd-user x86_64-bsd-user i386-bsd-user'
> -|| { cat config.log; exit 1; }
> +- ../configure --enable-werror || { cat config.log; exit 1; }
>  - gmake -j$(sysctl -n hw.ncpu)
>  - gmake -j$(sysctl -n hw.ncpu) check
>  
> 




[PATCH 2/5] target/arm: Set instance_align on CPUARM TypeInfo

2020-09-15 Thread Richard Henderson
Fix alignment of CPUARMState.vfp.zregs.

Signed-off-by: Richard Henderson 
---
Cc: Peter Maydell 
Cc: qemu-...@nongnu.org
---
 target/arm/cpu.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 7b5ea65fab..a7643deab4 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -2290,6 +2290,7 @@ void arm_cpu_register(const ARMCPUInfo *info)
 TypeInfo type_info = {
 .parent = TYPE_ARM_CPU,
 .instance_size = sizeof(ARMCPU),
+.instance_align = __alignof__(ARMCPU),
 .instance_init = arm_cpu_instance_init,
 .class_size = sizeof(ARMCPUClass),
 .class_init = info->class_init ?: cpu_register_class_init,
@@ -2305,6 +2306,7 @@ static const TypeInfo arm_cpu_type_info = {
 .name = TYPE_ARM_CPU,
 .parent = TYPE_CPU,
 .instance_size = sizeof(ARMCPU),
+.instance_align = __alignof__(ARMCPU),
 .instance_init = arm_cpu_initfn,
 .instance_finalize = arm_cpu_finalizefn,
 .abstract = true,
-- 
2.25.1




Re: [PATCH v2 6/8] configure: include tilegx-linux-user in the deprecation logic

2020-09-15 Thread Richard Henderson
On 9/15/20 6:43 AM, Alex Bennée wrote:
> The target is already marked as deprecated in the documentation.
> 
> Signed-off-by: Alex Bennée 
> ---
>  configure | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Richard Henderson 

r~




Re: [PATCH v2 6/8] configure: include tilegx-linux-user in the deprecation logic

2020-09-15 Thread Philippe Mathieu-Daudé
On 9/15/20 3:43 PM, Alex Bennée wrote:
> The target is already marked as deprecated in the documentation.
> 
> Signed-off-by: Alex Bennée 
> ---
>  configure | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/configure b/configure
> index 58be974065c8..dfd7f18dcb24 100755
> --- a/configure
> +++ b/configure
> @@ -280,7 +280,7 @@ supported_whpx_target() {
>  return 1
>  }
>  
> -deprecated_targets_list=ppc64abi32-linux-user
> +deprecated_targets_list=ppc64abi32-linux-user,tilegx-linux-user
>  deprecated_features=""
>  
>  supported_target() {
> 

Reviewed-by: Philippe Mathieu-Daudé 




[PATCH 0/5] qom: Allow object to be aligned

2020-09-15 Thread Richard Henderson
I've seen some failures on arm and s390x hosts after
enabling host vector support.  It turns out that the
malloc for these hosts does not provide 16-byte alignment.

We already have a function that can alloc with alignment,
but we need to pass this down from the structure.  We also
don't want to use this function unconditionally, because
the windows version does page allocation, which would be
overkill for the vast majority of the objects allocated.


r~


Cc: Paolo Bonzini 
Cc: "Daniel P. Berrangé" 
Cc: Eduardo Habkost 
Cc: Peter Maydell 
Cc: David Gibson 
Cc: Alistair Francis 
Cc: David Hildenbrand 
Cc: Cornelia Huck 
Cc: qemu-...@nongnu.org
Cc: qemu-...@nongnu.org
Cc: qemu-ri...@nongnu.org
Cc: qemu-s3...@nongnu.org


Richard Henderson (5):
  qom: Allow objects to be allocated with increased alignment
  target/arm: Set instance_align on CPUARM TypeInfo
  target/ppc: Set instance_align on PowerPCCPU TypeInfo
  target/riscv: Set instance_align on RISCVCPU TypeInfo
  target/s390x: Set instance_align on S390CPU TypeInfo

 include/qom/object.h|  4 
 qom/object.c| 16 +---
 target/arm/cpu.c|  2 ++
 target/riscv/cpu.c  |  1 +
 target/s390x/cpu.c  |  1 +
 target/ppc/translate_init.c.inc |  1 +
 6 files changed, 22 insertions(+), 3 deletions(-)

-- 
2.25.1




[PATCH 5/5] target/s390x: Set instance_align on S390CPU TypeInfo

2020-09-15 Thread Richard Henderson
Fix alignment of CPUS390XState.vregs.

Signed-off-by: Richard Henderson 
---
Cc: David Hildenbrand 
Cc: Cornelia Huck 
Cc: qemu-s3...@nongnu.org
---
 target/s390x/cpu.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c
index 749cd548f0..e350edc9f5 100644
--- a/target/s390x/cpu.c
+++ b/target/s390x/cpu.c
@@ -517,6 +517,7 @@ static const TypeInfo s390_cpu_type_info = {
 .name = TYPE_S390_CPU,
 .parent = TYPE_CPU,
 .instance_size = sizeof(S390CPU),
+.instance_align = __alignof__(S390CPU),
 .instance_init = s390_cpu_initfn,
 .instance_finalize = s390_cpu_finalize,
 .abstract = true,
-- 
2.25.1




[PATCH v2] hw/block/nand: Decommission the NAND museum

2020-09-15 Thread Philippe Mathieu-Daudé
This is the QEMU equivalent of this Linux commit (but 7 years later):
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f7025a43a9da2

The MTD subsystem has its own small museum of ancient NANDs
in a form of the CONFIG_MTD_NAND_MUSEUM_IDS configuration option.
The museum contains stone age NANDs with 256 bytes pages, as well
as iron age NANDs with 512 bytes per page and up to 8MiB page size.

It is with great sorrow that I inform you that the museum is being
decommissioned. The MTD subsystem is out of budget for Kconfig
options and already has too many of them, and there is a general
kernel trend to simplify the configuration menu.

We remove the stone age exhibits along with closing the museum,
but some of the iron age ones are transferred to the regular NAND
depot. Namely, only those which have unique device IDs are
transferred, and the ones which have conflicting device IDs are
removed.

The machine using this device are:
- axis-dev88
- tosa (via tc6393xb_init)
- spitz based (akita, borzoi, terrier)

Reviewed-by: Richard Henderson 
Signed-off-by: Philippe Mathieu-Daudé 
---
Peter, as 4 of the 5 machines are ARM-based, can this go via your tree?
---
 hw/block/nand.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/hw/block/nand.c b/hw/block/nand.c
index 5c8112ed5a4..5f01ba2bc44 100644
--- a/hw/block/nand.c
+++ b/hw/block/nand.c
@@ -138,7 +138,7 @@ static void mem_and(uint8_t *dest, const uint8_t *src, 
size_t n)
 # define ADDR_SHIFT16
 # include "nand.c"
 
-/* Information based on Linux drivers/mtd/nand/nand_ids.c */
+/* Information based on Linux drivers/mtd/nand/raw/nand_ids.c */
 static const struct {
 int size;
 int width;
@@ -154,15 +154,14 @@ static const struct {
 [0xe8] = { 1,  8,  8, 4, 0 },
 [0xec] = { 1,  8,  8, 4, 0 },
 [0xea] = { 2,  8,  8, 4, 0 },
-[0xd5] = { 4,  8,  9, 4, 0 },
 [0xe3] = { 4,  8,  9, 4, 0 },
 [0xe5] = { 4,  8,  9, 4, 0 },
-[0xd6] = { 8,  8,  9, 4, 0 },
 
-[0x39] = { 8,  8,  9, 4, 0 },
-[0xe6] = { 8,  8,  9, 4, 0 },
-[0x49] = { 8,  16, 9, 4, NAND_BUSWIDTH_16 },
-[0x59] = { 8,  16, 9, 4, NAND_BUSWIDTH_16 },
+[0x6b] = { 4,8,9, 4, 0 },
+[0xe3] = { 4,8,9, 4, 0 },
+[0xe5] = { 4,8,9, 4, 0 },
+[0xd6] = { 8,8,9, 4, 0 },
+[0xe6] = { 8,8,9, 4, 0 },
 
 [0x33] = { 16, 8,  9, 5, 0 },
 [0x73] = { 16, 8,  9, 5, 0 },
-- 
2.26.2




[PATCH] hw/scsi/lsi53c895a: Sanitize some trace events format

2020-09-15 Thread Philippe Mathieu-Daudé
Make some lsi53c895a trace events more understandable.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/scsi/trace-events | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/scsi/trace-events b/hw/scsi/trace-events
index 9a4a60ca635..ac4209f361e 100644
--- a/hw/scsi/trace-events
+++ b/hw/scsi/trace-events
@@ -234,9 +234,9 @@ spapr_vscsi_do_crq(unsigned c0, unsigned c1) "crq: %02x 
%02x ..."
 
 # lsi53c895a.c
 lsi_reset(void) "Reset"
-lsi_update_irq(int level, uint8_t dstat, uint8_t sist1, uint8_t sist0) "Update 
IRQ level %d dstat 0x%02x sist 0x%02x0x%02x"
+lsi_update_irq(int level, uint8_t dstat, uint8_t sist1, uint8_t sist0) "Update 
IRQ level %d dstat 0x%02x sist 1:0x%02x 0:0x%02x"
 lsi_update_irq_disconnected(void) "Handled IRQs & disconnected, looking for 
pending processes"
-lsi_script_scsi_interrupt(uint8_t stat1, uint8_t stat0, uint8_t sist1, uint8_t 
sist0) "SCSI Interrupt 0x%02x0x%02x prev 0x%02x0x%02x"
+lsi_script_scsi_interrupt(uint8_t stat1, uint8_t stat0, uint8_t sist1, uint8_t 
sist0) "SCSI Interrupt stat 1:0x%02x 0:0x%02x sist 1:0x%02x 0:0x%02x"
 lsi_script_dma_interrupt(uint8_t stat, uint8_t dstat) "DMA Interrupt 0x%x prev 
0x%x"
 lsi_bad_phase_jump(uint32_t dsp) "Data phase mismatch jump to 0x%"PRIX32
 lsi_bad_phase_interrupt(void) "Phase mismatch interrupt"
-- 
2.26.2




[PATCH 3/5] target/ppc: Set instance_align on PowerPCCPU TypeInfo

2020-09-15 Thread Richard Henderson
Fix alignment of CPUPPCState.vsr.

Signed-off-by: Richard Henderson 
---
Cc: David Gibson 
Cc: qemu-...@nongnu.org
---
 target/ppc/translate_init.c.inc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/target/ppc/translate_init.c.inc b/target/ppc/translate_init.c.inc
index 230a062d29..accb4f2fae 100644
--- a/target/ppc/translate_init.c.inc
+++ b/target/ppc/translate_init.c.inc
@@ -10960,6 +10960,7 @@ static const TypeInfo ppc_cpu_type_info = {
 .name = TYPE_POWERPC_CPU,
 .parent = TYPE_CPU,
 .instance_size = sizeof(PowerPCCPU),
+.instance_align = __alignof__(PowerPCCPU),
 .instance_init = ppc_cpu_instance_init,
 .instance_finalize = ppc_cpu_instance_finalize,
 .abstract = true,
-- 
2.25.1




[Bug 1895053] Re: Cannot nspawn raspbian 10 [FAILED] Failed to start Journal Service.

2020-09-15 Thread Petunia
tldr: i dont have the same issue as described in your bug
see my post there:
https://bugs.launchpad.net/qemu/+bug/1892604/comments/6

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

Title:
  Cannot nspawn raspbian 10 [FAILED] Failed to start Journal Service.

Status in QEMU:
  New

Bug description:
  Hi, I'm using nspawn and asked the question @systemd-devel. They redirected 
me to you, guessing that nspawn calls a syscall or ioctl qemu isnt aware of and 
can't implement properly?
  They were like: "Sorry, that's not my department." ^^

  Maybe you can reproduce the issue or help me investigating whats wrong
  or put the ball right back into their court? :D

  Testscript:
  wget https://downloads.raspberrypi.org/raspios_lite_armhf_latest -o r.zip
  unzip r.zip
  LOOP=$(losetup --show -Pf *raspios-buster-armhf-lite.img)
  mount ${LOOP}p2 /mnt
  mount ${LOOP}p1 /mnt/boot
  systemd-nspawn --bind /usr/bin/qemu-arm-static --boot --directory=/mnt -- 
systemd.log_level=debug

  Output:
  see attachment

  System:
  uname -a
  Linux MArch 5.8.7-arch1-1 #1 SMP PREEMPT Sat, 05 Sep 2020 12:31:32 +
  x86_64 GNU/Linux

  qemu-arm-static --version
  qemu-arm version 5.1.0

  systemd-nspawn --version
  systemd 246 (246.4-1-arch)
  +PAM +AUDIT -SELINUX -IMA -APPARMOR +SMACK -SYSVINIT +UTMP +LIBCRYPTSETUP
  +GCRYPT +GNUTLS +ACL +XZ +LZ4 +ZSTD +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN
  +PCRE2 default-hierarchy=hybrid

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



Re: [PATCH V1 22/32] char: qio_channel_socket_accept reuse fd

2020-09-15 Thread Dr. David Alan Gilbert
* Steve Sistare (steven.sist...@oracle.com) wrote:
> From: Mark Kanda 
> 
> Add an fd argument to qio_channel_socket_accept.  If not -1, the channel
> uses that fd instead of accepting a new socket connection.  All callers
> pass -1 in this patch, so no functional change.

Doesn't some of this just come from the fact you're insisting on reusing
the command line?   We should be able to open a chardev on an fd
shouldn't we?

Dave

> Signed-off-by: Mark Kanda 
> Signed-off-by: Steve Sistare 
> ---
>  include/io/channel-socket.h|  3 ++-
>  io/channel-socket.c| 12 +---
>  io/net-listener.c  |  4 ++--
>  scsi/qemu-pr-helper.c  |  2 +-
>  tests/qtest/tpm-emu.c  |  2 +-
>  tests/test-char.c  |  2 +-
>  tests/test-io-channel-socket.c |  4 ++--
>  7 files changed, 18 insertions(+), 11 deletions(-)
> 
> diff --git a/include/io/channel-socket.h b/include/io/channel-socket.h
> index 777ff59..0ffc560 100644
> --- a/include/io/channel-socket.h
> +++ b/include/io/channel-socket.h
> @@ -248,6 +248,7 @@ qio_channel_socket_get_remote_address(QIOChannelSocket 
> *ioc,
>  /**
>   * qio_channel_socket_accept:
>   * @ioc: the socket channel object
> + * @reuse_fd: fd to reuse; -1 otherwise
>   * @errp: pointer to a NULL-initialized error object
>   *
>   * If the socket represents a server, then this accepts
> @@ -258,7 +259,7 @@ qio_channel_socket_get_remote_address(QIOChannelSocket 
> *ioc,
>   */
>  QIOChannelSocket *
>  qio_channel_socket_accept(QIOChannelSocket *ioc,
> -  Error **errp);
> +  int reuse_fd, Error **errp);
>  
>  
>  #endif /* QIO_CHANNEL_SOCKET_H */
> diff --git a/io/channel-socket.c b/io/channel-socket.c
> index e1b4667..dde12bf 100644
> --- a/io/channel-socket.c
> +++ b/io/channel-socket.c
> @@ -352,7 +352,7 @@ void qio_channel_socket_dgram_async(QIOChannelSocket *ioc,
>  
>  QIOChannelSocket *
>  qio_channel_socket_accept(QIOChannelSocket *ioc,
> -  Error **errp)
> +  int reuse_fd, Error **errp)
>  {
>  QIOChannelSocket *cioc;
>  
> @@ -362,8 +362,14 @@ qio_channel_socket_accept(QIOChannelSocket *ioc,
>  
>   retry:
>  trace_qio_channel_socket_accept(ioc);
> -cioc->fd = qemu_accept(ioc->fd, (struct sockaddr *)>remoteAddr,
> -   >remoteAddrLen);
> +
> +if (reuse_fd != -1) {
> +cioc->fd = reuse_fd;
> +} else {
> +cioc->fd = qemu_accept(ioc->fd, (struct sockaddr *)>remoteAddr,
> +   >remoteAddrLen);
> +}
> +
>  if (cioc->fd < 0) {
>  if (errno == EINTR) {
>  goto retry;
> diff --git a/io/net-listener.c b/io/net-listener.c
> index 5d8a226..bbdea1e 100644
> --- a/io/net-listener.c
> +++ b/io/net-listener.c
> @@ -45,7 +45,7 @@ static gboolean qio_net_listener_channel_func(QIOChannel 
> *ioc,
>  QIOChannelSocket *sioc;
>  
>  sioc = qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc),
> - NULL);
> + -1, NULL);
>  if (!sioc) {
>  return TRUE;
>  }
> @@ -194,7 +194,7 @@ static gboolean 
> qio_net_listener_wait_client_func(QIOChannel *ioc,
>  QIOChannelSocket *sioc;
>  
>  sioc = qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc),
> - NULL);
> + -1, NULL);
>  if (!sioc) {
>  return TRUE;
>  }
> diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c
> index 57ad830..0e6d683 100644
> --- a/scsi/qemu-pr-helper.c
> +++ b/scsi/qemu-pr-helper.c
> @@ -800,7 +800,7 @@ static gboolean accept_client(QIOChannel *ioc, 
> GIOCondition cond, gpointer opaqu
>  PRHelperClient *prh;
>  
>  cioc = qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc),
> - NULL);
> + -1, NULL);
>  if (!cioc) {
>  return TRUE;
>  }
> diff --git a/tests/qtest/tpm-emu.c b/tests/qtest/tpm-emu.c
> index 2e8eb7b..19e5dab 100644
> --- a/tests/qtest/tpm-emu.c
> +++ b/tests/qtest/tpm-emu.c
> @@ -83,7 +83,7 @@ void *tpm_emu_ctrl_thread(void *data)
>  g_cond_signal(>data_cond);
>  
>  qio_channel_wait(QIO_CHANNEL(lioc), G_IO_IN);
> -ioc = QIO_CHANNEL(qio_channel_socket_accept(lioc, _abort));
> +ioc = QIO_CHANNEL(qio_channel_socket_accept(lioc, -1, _abort));
>  g_assert(ioc);
>  
>  {
> diff --git a/tests/test-char.c b/tests/test-char.c
> index 614bdac..1bb6ae0 100644
> --- a/tests/test-char.c
> +++ b/tests/test-char.c
> @@ -884,7 +884,7 @@ char_socket_client_server_thread(gpointer data)
>  QIOChannelSocket *cioc;
>  
>  retry:
> -cioc = qio_channel_socket_accept(ioc, _abort);
> +cioc = qio_channel_socket_accept(ioc, -1, _abort);
>  g_assert_nonnull(cioc);
>  
>  if (char_socket_ping_pong(QIO_CHANNEL(cioc), NULL) != 0) {
> diff --git a/tests/test-io-channel-socket.c 

[PATCH v10 25/26] block: Fixes nfs compiling error on msys2/mingw

2020-09-15 Thread Yonggang Luo
These compiling errors are fixed:
../block/nfs.c:27:10: fatal error: poll.h: No such file or directory
   27 | #include 
  |  ^~~~
compilation terminated.

../block/nfs.c:63:5: error: unknown type name 'blkcnt_t'
   63 | blkcnt_t st_blocks;
  | ^~~~
../block/nfs.c: In function 'nfs_client_open':
../block/nfs.c:550:27: error: 'struct _stat64' has no member named 'st_blocks'
  550 | client->st_blocks = st.st_blocks;
  |   ^
../block/nfs.c: In function 'nfs_get_allocated_file_size':
../block/nfs.c:751:41: error: 'struct _stat64' has no member named 'st_blocks'
  751 | return (task.ret < 0 ? task.ret : st.st_blocks * 512);
  | ^
../block/nfs.c: In function 'nfs_reopen_prepare':
../block/nfs.c:805:31: error: 'struct _stat64' has no member named 'st_blocks'
  805 | client->st_blocks = st.st_blocks;
  |   ^
../block/nfs.c: In function 'nfs_get_allocated_file_size':
../block/nfs.c:752:1: error: control reaches end of non-void function 
[-Werror=return-type]
  752 | }
  | ^

On msys2/mingw, there is no st_blocks in struct _stat64 yet, we disable the 
usage of it
on msys2/mingw, and create a typedef long long blkcnt_t; for further 
implementation

Signed-off-by: Yonggang Luo 
---
 block/nfs.c | 37 ++---
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/block/nfs.c b/block/nfs.c
index 61a249a9fc..5f83dbe407 100644
--- a/block/nfs.c
+++ b/block/nfs.c
@@ -24,7 +24,9 @@
 
 #include "qemu/osdep.h"
 
+#if !defined(_WIN32)
 #include 
+#endif
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
@@ -51,6 +53,13 @@
 #define QEMU_NFS_MAX_PAGECACHE_SIZE (8388608 / NFS_BLKSIZE)
 #define QEMU_NFS_MAX_DEBUG_LEVEL 2
 
+#if defined(_WIN32)
+#define nfs_stat __stat64
+typedef long long blkcnt_t;
+#else
+#define nfs_stat stat
+#endif
+
 typedef struct NFSClient {
 struct nfs_context *context;
 struct nfsfh *fh;
@@ -70,7 +79,7 @@ typedef struct NFSRPC {
 int ret;
 int complete;
 QEMUIOVector *iov;
-struct stat *st;
+struct nfs_stat *st;
 Coroutine *co;
 NFSClient *client;
 } NFSRPC;
@@ -415,11 +424,21 @@ static void nfs_file_close(BlockDriverState *bs)
 nfs_client_close(client);
 }
 
+static blkcnt_t nfs_get_st_blocks(const struct nfs_stat *st)
+{
+#if defined(_WIN32)
+/* TODO: Not be possible implement on win32 yet */
+return 0;
+#else
+return st->st_blocks;
+#endif
+}
+
 static int64_t nfs_client_open(NFSClient *client, BlockdevOptionsNfs *opts,
int flags, int open_flags, Error **errp)
 {
 int64_t ret = -EINVAL;
-struct stat st;
+struct nfs_stat st;
 char *file = NULL, *strp = NULL;
 
 qemu_mutex_init(>mutex);
@@ -545,7 +564,7 @@ static int64_t nfs_client_open(NFSClient *client, 
BlockdevOptionsNfs *opts,
 }
 
 ret = DIV_ROUND_UP(st.st_size, BDRV_SECTOR_SIZE);
-client->st_blocks = st.st_blocks;
+client->st_blocks = nfs_get_st_blocks();
 client->has_zero_init = S_ISREG(st.st_mode);
 *strp = '/';
 goto out;
@@ -706,6 +725,7 @@ static int nfs_has_zero_init(BlockDriverState *bs)
 return client->has_zero_init;
 }
 
+#if !defined(_WIN32)
 /* Called (via nfs_service) with QemuMutex held.  */
 static void
 nfs_get_allocated_file_size_cb(int ret, struct nfs_context *nfs, void *data,
@@ -729,7 +749,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState 
*bs)
 {
 NFSClient *client = bs->opaque;
 NFSRPC task = {0};
-struct stat st;
+struct nfs_stat st;
 
 if (bdrv_is_read_only(bs) &&
 !(bs->open_flags & BDRV_O_NOCACHE)) {
@@ -746,8 +766,9 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState 
*bs)
 nfs_set_events(client);
 BDRV_POLL_WHILE(bs, !task.complete);
 
-return (task.ret < 0 ? task.ret : st.st_blocks * 512);
+return (task.ret < 0 ? task.ret : nfs_get_st_blocks() * 512);
 }
+#endif
 
 static int coroutine_fn
 nfs_file_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
@@ -778,7 +799,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state,
   BlockReopenQueue *queue, Error **errp)
 {
 NFSClient *client = state->bs->opaque;
-struct stat st;
+struct nfs_stat st;
 int ret = 0;
 
 if (state->flags & BDRV_O_RDWR && bdrv_is_read_only(state->bs)) {
@@ -800,7 +821,7 @@ static int nfs_reopen_prepare(BDRVReopenState *state,
nfs_get_error(client->context));
 return ret;
 }
-client->st_blocks = st.st_blocks;
+client->st_blocks = nfs_get_st_blocks();
 }
 
 return 0;
@@ -869,7 +890,9 @@ static BlockDriver bdrv_nfs = {
 .create_opts= _create_opts,
 
 .bdrv_has_zero_init = nfs_has_zero_init,
+#if !defined(_WIN32)
 .bdrv_get_allocated_file_size   = 

[PATCH v10 23/26] meson: upgrade meson for execute custom ninjatool under msys2 properly

2020-09-15 Thread Yonggang Luo
* Bump versions to 0.55.2 for release

* Tag Info:
object 008d13038f95e7c7d8ad553f14e408da5b94c360
type commit
tag 0.55.2
tagger Jussi Pakkanen  2020/9/11 1:24:47

Signed-off-by: Yonggang Luo 
---
 meson | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/meson b/meson
index 68ed748f84..008d13038f 16
--- a/meson
+++ b/meson
@@ -1 +1 @@
-Subproject commit 68ed748f84f14c2d4e62dcbd123816e5898eb04c
+Subproject commit 008d13038f95e7c7d8ad553f14e408da5b94c360
-- 
2.28.0.windows.1




Re: [PATCH 00/13] dma: Let the DMA API take MemTxAttrs argument and propagate MemTxResult

2020-09-15 Thread Philippe Mathieu-Daudé
This series is fully review.

Paolo, does it belong to your tree?

On 9/4/20 5:44 PM, Philippe Mathieu-Daudé wrote:
> Salvaging cleanups patches from the RFC series "Forbid DMA write
> accesses to MMIO regions" [*], propagating MemTxResult and
> adding documentation.
> 
> [*] https://www.mail-archive.com/qemu-block@nongnu.org/msg72924.html
> 
> Klaus Jensen (1):
>   pci: pass along the return value of dma_memory_rw
> 
> Philippe Mathieu-Daudé (12):
>   docs/devel/loads-stores: Add regexp for DMA functions
>   dma: Document address_space_map/address_space_unmap() prototypes
>   dma: Let dma_memory_set() propagate MemTxResult
>   dma: Let dma_memory_rw() propagate MemTxResult
>   dma: Let dma_memory_read() propagate MemTxResult
>   dma: Let dma_memory_write() propagate MemTxResult
>   dma: Let dma_memory_valid() take MemTxAttrs argument
>   dma: Let dma_memory_set() take MemTxAttrs argument
>   dma: Let dma_memory_rw_relaxed() take MemTxAttrs argument
>   dma: Let dma_memory_rw() take MemTxAttrs argument
>   dma: Let dma_memory_read/write() take MemTxAttrs argument
>   dma: Let dma_memory_map() take MemTxAttrs argument
> 
>  docs/devel/loads-stores.rst   |   2 +
>  include/hw/pci/pci.h  |   7 +-
>  include/hw/ppc/spapr_vio.h|  11 ++-
>  include/sysemu/dma.h  | 156 +++---
>  dma-helpers.c |  16 ++--
>  hw/arm/musicpal.c |  13 +--
>  hw/arm/smmu-common.c  |   3 +-
>  hw/arm/smmuv3.c   |  14 +--
>  hw/core/generic-loader.c  |   3 +-
>  hw/display/virtio-gpu.c   |   8 +-
>  hw/dma/pl330.c|  12 ++-
>  hw/dma/sparc32_dma.c  |  16 ++--
>  hw/dma/xlnx-zynq-devcfg.c |   6 +-
>  hw/dma/xlnx_dpdma.c   |  10 ++-
>  hw/hyperv/vmbus.c |   8 +-
>  hw/i386/amd_iommu.c   |  16 ++--
>  hw/i386/intel_iommu.c |  28 +++---
>  hw/ide/ahci.c |   9 +-
>  hw/ide/macio.c|   2 +-
>  hw/intc/spapr_xive.c  |   3 +-
>  hw/intc/xive.c|   7 +-
>  hw/misc/bcm2835_property.c|   3 +-
>  hw/misc/macio/mac_dbdma.c |  10 ++-
>  hw/net/allwinner-sun8i-emac.c |  21 +++--
>  hw/net/ftgmac100.c|  25 --
>  hw/net/imx_fec.c  |  32 ---
>  hw/nvram/fw_cfg.c |  12 ++-
>  hw/pci-host/pnv_phb3.c|   5 +-
>  hw/pci-host/pnv_phb3_msi.c|   9 +-
>  hw/pci-host/pnv_phb4.c|   7 +-
>  hw/sd/allwinner-sdhost.c  |  14 +--
>  hw/sd/sdhci.c |  35 +---
>  hw/usb/hcd-dwc2.c |   8 +-
>  hw/usb/hcd-ehci.c |   6 +-
>  hw/usb/hcd-ohci.c |  28 +++---
>  hw/usb/libhw.c|   3 +-
>  hw/virtio/virtio.c|   6 +-
>  37 files changed, 385 insertions(+), 189 deletions(-)
> 




Re: [PATCH 0/3] pci: Let PCI DMA API functions propagate a MemTxResult

2020-09-15 Thread Philippe Mathieu-Daudé
On 9/4/20 6:26 PM, Philippe Mathieu-Daudé wrote:
> The DMA API propagates MemTxResult:
> - MEMTX_OK,
> - MEMTX_device_ERROR,
> - MEMTX_DECODE_ERROR.
> 
> Let the PCI DMA API propagate them, as they are
> clearer than an undocumented 'int'.
> 
> Based-on: <20200904154439.643272-1-phi...@redhat.com>
> https://lists.gnu.org/archive/html/qemu-devel/2020-09/msg02048.html
> 
> Philippe Mathieu-Daudé (3):
>   pci: Let pci_dma_rw() propagate MemTxResult
>   pci: Let pci_dma_read() propagate MemTxResult
>   pci: Let pci_dma_write() propagate MemTxResult
> 
>  include/hw/pci/pci.h | 50 ++--
>  1 file changed, 44 insertions(+), 6 deletions(-)
> 

This series is fully review.

Paolo, if you take the DMA series on which this one
is based, could you take this too?

Thanks :)




Re: [PATCH] hw/input/tsc2xxx: Reduce MouseTransformInfo structure exposure

2020-09-15 Thread Philippe Mathieu-Daudé
ping?

On 9/7/20 3:01 AM, Philippe Mathieu-Daudé wrote:
> Commit a5d7eb6534a ("Add TSC2301 touchscreen & keypad controller")
> added the MouseTransformInfo declaration in "ui/console.h",
> however it is only used in "hw/input/tsc2xxx.h".
> Reduce the structure exposure by moving it to the single include
> where it is used.
> 
> This should fix a build failure on OpenBSD:
> 
>   In file included from hw/arm/nseries.c:30:
>   In file included from include/hw/arm/omap.h:24:
>   In file included from include/hw/input/tsc2xxx.h:14:
>   include/ui/console.h:11:11: fatal error: 'epoxy/gl.h' file not found
>   # include 
> ^~~~
>   1 error generated.
>   gmake: *** [Makefile.ninja:1735:
>   libqemu-aarch64-softmmu.fa.p/hw_arm_nseries.c.o] Error 1
> 
> Reported-by: Peter Maydell 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  include/hw/input/tsc2xxx.h | 8 +++-
>  include/ui/console.h   | 8 
>  2 files changed, 7 insertions(+), 9 deletions(-)
> 
> diff --git a/include/hw/input/tsc2xxx.h b/include/hw/input/tsc2xxx.h
> index 3cd8f1bf55b..5b76ebc1776 100644
> --- a/include/hw/input/tsc2xxx.h
> +++ b/include/hw/input/tsc2xxx.h
> @@ -11,7 +11,13 @@
>  #ifndef HW_INPUT_TSC2XXX_H
>  #define HW_INPUT_TSC2XXX_H
>  
> -#include "ui/console.h"
> +typedef struct MouseTransformInfo {
> +/* Touchscreen resolution */
> +int x;
> +int y;
> +/* Calibration values as used/generated by tslib */
> +int a[7];
> +} MouseTransformInfo;
>  
>  typedef struct uWireSlave {
>  uint16_t (*receive)(void *opaque);
> diff --git a/include/ui/console.h b/include/ui/console.h
> index f35b4fc082b..30eed00dfcd 100644
> --- a/include/ui/console.h
> +++ b/include/ui/console.h
> @@ -65,14 +65,6 @@ void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
>  
>  void kbd_put_ledstate(int ledstate);
>  
> -typedef struct MouseTransformInfo {
> -/* Touchscreen resolution */
> -int x;
> -int y;
> -/* Calibration values as used/generated by tslib */
> -int a[7];
> -} MouseTransformInfo;
> -
>  void hmp_mouse_set(Monitor *mon, const QDict *qdict);
>  
>  /* keysym is a unicode code except for special keys (see QEMU_KEY_xxx
> 



Re: [PATCH] hw/arm/aspeed: Map the UART5 device unconditionally

2020-09-15 Thread Philippe Mathieu-Daudé
ping?

On 9/5/20 11:24 PM, Philippe Mathieu-Daudé wrote:
> The UART5 is present on the machine regardless there is a
> character device connected to it. Map it unconditionally.
> 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/arm/aspeed_ast2600.c | 8 +++-
>  hw/arm/aspeed_soc.c | 8 +++-
>  2 files changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/hw/arm/aspeed_ast2600.c b/hw/arm/aspeed_ast2600.c
> index 9d95e421435..1450bde7cf2 100644
> --- a/hw/arm/aspeed_ast2600.c
> +++ b/hw/arm/aspeed_ast2600.c
> @@ -325,11 +325,9 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, 
> Error **errp)
>  }
>  
>  /* UART - attach an 8250 to the IO space as our UART5 */
> -if (serial_hd(0)) {
> -qemu_irq uart5 = aspeed_soc_get_irq(s, ASPEED_DEV_UART5);
> -serial_mm_init(get_system_memory(), sc->memmap[ASPEED_DEV_UART5], 2,
> -   uart5, 38400, serial_hd(0), DEVICE_LITTLE_ENDIAN);
> -}
> +serial_mm_init(get_system_memory(), sc->memmap[ASPEED_DEV_UART5], 2,
> +   aspeed_soc_get_irq(s, ASPEED_DEV_UART5),
> +   38400, serial_hd(0), DEVICE_LITTLE_ENDIAN);
>  
>  /* I2C */
>  object_property_set_link(OBJECT(>i2c), "dram", OBJECT(s->dram_mr),
> diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c
> index 35be126db6f..7eefd54ac07 100644
> --- a/hw/arm/aspeed_soc.c
> +++ b/hw/arm/aspeed_soc.c
> @@ -283,11 +283,9 @@ static void aspeed_soc_realize(DeviceState *dev, Error 
> **errp)
>  }
>  
>  /* UART - attach an 8250 to the IO space as our UART5 */
> -if (serial_hd(0)) {
> -qemu_irq uart5 = aspeed_soc_get_irq(s, ASPEED_DEV_UART5);
> -serial_mm_init(get_system_memory(), sc->memmap[ASPEED_DEV_UART5], 2,
> -   uart5, 38400, serial_hd(0), DEVICE_LITTLE_ENDIAN);
> -}
> +serial_mm_init(get_system_memory(), sc->memmap[ASPEED_DEV_UART5], 2,
> +   aspeed_soc_get_irq(s, ASPEED_DEV_UART5), 38400,
> +   serial_hd(0), DEVICE_LITTLE_ENDIAN);
>  
>  /* I2C */
>  object_property_set_link(OBJECT(>i2c), "dram", OBJECT(s->dram_mr),
> 



Re: [PATCH] hw/mips/malta: Fix FPGA I/O region size

2020-09-15 Thread Philippe Mathieu-Daudé
ping?

On 9/5/20 11:30 PM, Philippe Mathieu-Daudé wrote:
> The FPGA present on the CoreCard has an I/O region 1MiB wide.
> 
> Refs:
> - Atlas User’s Manual (Document Number: MD5)
> - Malta User’s Manual (Document Number: MD00048)
> 
> Fixes: ea85df72b60 ("mips_malta: convert to memory API")
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/mips/malta.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/mips/malta.c b/hw/mips/malta.c
> index a59e20c81c5..6a19be0a5dc 100644
> --- a/hw/mips/malta.c
> +++ b/hw/mips/malta.c
> @@ -574,7 +574,7 @@ static MaltaFPGAState *malta_fpga_init(MemoryRegion 
> *address_space,
>  memory_region_init_alias(>iomem_lo, NULL, "malta-fpga",
>   >iomem, 0, 0x900);
>  memory_region_init_alias(>iomem_hi, NULL, "malta-fpga",
> - >iomem, 0xa00, 0x1 - 0xa00);
> + >iomem, 0xa00, 0x10 - 0xa00);
>  
>  memory_region_add_subregion(address_space, base, >iomem_lo);
>  memory_region_add_subregion(address_space, base + 0xa00, >iomem_hi);
> 



Re: [PATCH v2 5/8] configure: clean-up the target-list-exclude logic

2020-09-15 Thread Richard Henderson
On 9/15/20 6:43 AM, Alex Bennée wrote:
> Rather than sed and loop just do a grep.
> 
> Signed-off-by: Alex Bennée 
> ---
>  configure | 10 +-
>  1 file changed, 1 insertion(+), 9 deletions(-)

Reviewed-by: Richard Henderson 

r~




[PATCH v10 26/26] block: enable libnfs on msys2/mingw in cirrus.yml

2020-09-15 Thread Yonggang Luo
At the begging libnfs are not enabled because of compiling error,
now it's fixed so enable it

Signed-off-by: Yonggang Luo 
---
 .cirrus.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.cirrus.yml b/.cirrus.yml
index 90ed891865..ca4d7db64f 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -93,6 +93,7 @@ windows_msys2_task:
 mingw-w64-x86_64-libusb
 mingw-w64-x86_64-usbredir
 mingw-w64-x86_64-libtasn1
+mingw-w64-x86_64-libnfs
 mingw-w64-x86_64-nettle
 mingw-w64-x86_64-cyrus-sasl
 mingw-w64-x86_64-curl
-- 
2.28.0.windows.1




Re: [PATCH v2 01/10] capstone: Convert Makefile bits to meson bits

2020-09-15 Thread Yonggang Luo
On Wed, Sep 16, 2020 at 1:14 AM Paolo Bonzini  wrote:
>
> On 15/09/20 19:07, 罗勇刚(Yonggang Luo) wrote:
> >
> > Linux distributions generally do not want to have bundled
libraries, so
> >
> > Yes, bundled libraries is a bad idea, but static linked library is
> > another case, that won't affect
> > the Linux distributions.
>
> As far as Linux distributions are concerned, static linking is a case of
> bundling.  Bundling means that, for example, any security issue will
> require rebuilding the package that does the bundling (this applies
> especially to slirp among the three that QEMU we bundles).

Oh, see that, so capstone and  libfdt doesn't have the security concern?
>
>
> Paolo
>


--
 此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo


Re: [PATCH v2 01/10] capstone: Convert Makefile bits to meson bits

2020-09-15 Thread Yonggang Luo
On Wed, Sep 16, 2020 at 1:00 AM Paolo Bonzini  wrote:

> On 15/09/20 18:12, 罗勇刚(Yonggang Luo) wrote:
> >
> > I suggest remove the capstone=system option cause the system library
> > may not satisfy the requirements of qemu and create in-consistence
> > expereince when bug or error happens about capstone. We either have
> > git submodule capstone or nothing at all
>
> Linux distributions generally do not want to have bundled libraries, so
>
Yes, bundled libraries is a bad idea, but static linked library is another
case, that won't affect
the Linux distributions.

> the fallback to the system library is the default.  We single out
> capstone, libfdt and slirp because they are slightly less common
>
Ineed, I would like suggest these three libraries always to be static
linked or not use it at all.

> dependencies and are missing on some distros; however, in general we
> strive to _only_ use system libraries and not package any of QEMU's
> dependencies.
>
> Paolo
>
>

-- 
 此致
礼
罗勇刚
Yours
sincerely,
Yonggang Luo


Re: [PATCH v2 8/8] configure: add [lm32|unicore32]-softmmu to deprecation logic

2020-09-15 Thread Richard Henderson
On 9/15/20 6:43 AM, Alex Bennée wrote:
> While we are at it move the few places where they are into the
> deprecation build bucket.
> 
> Signed-off-by: Alex Bennée 
> ---
>  configure  | 2 +-
>  .gitlab-ci.yml | 9 +
>  .shippable.yml | 2 +-
>  3 files changed, 7 insertions(+), 6 deletions(-)

Reviewed-by: Richard Henderson 

r~




Re: [PATCH v2 2/8] iotests: Drop readlink -f

2020-09-15 Thread Richard Henderson
On 9/15/20 6:43 AM, Alex Bennée wrote:
> From: Max Reitz 
> 
> On macOS, (out of the box) readlink does not have -f.  We do not really
> need readlink here, though, it was just a replacement for realpath
> (which is not available on our BSD test systems), which we needed to
> make the $(dirname) into an absolute path.
> 
> Instead of using either, just use "cd; pwd" like is done for
> $source_iotests.
> 
>("iotests: Allow running from different directory")
> 
> Fixes: b1cbc33a3971b6bb005d5ac3569feae35a71de0f
> Reported-by: Claudio Fontana 
> Reported-by: Thomas Huth 
> Suggested-by: Peter Maydell 
> Signed-off-by: Max Reitz 
> Message-Id: <20200914145606.94620-1-mre...@redhat.com>
> Signed-off-by: Alex Bennée 
> ---
>  tests/qemu-iotests/check | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Richard Henderson 

r~




Re: [PATCH v2 4/8] configure: also skip deprecated targets with target-list-exclude

2020-09-15 Thread Richard Henderson
On 9/15/20 6:43 AM, Alex Bennée wrote:
> Now the user has to make an even more deliberate decision to
> enable a deprecated target rather than getting it as a side effect of
> using --target-exclude-list.
> 
> Signed-off-by: Alex Bennée 
> ---
>  configure | 11 ---
>  1 file changed, 8 insertions(+), 3 deletions(-)

Reviewed-by: Richard Henderson 

r~




[PATCH v10 22/26] rcu: fixes test-logging.c by call drain_call_rcu before rmdir_full

2020-09-15 Thread Yonggang Luo
drain_call_rcu is necessary on win32, because under win32, if you
don't close the file before remove it, the remove would be fail.

Signed-off-by: Yonggang Luo 
---
 tests/test-logging.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/test-logging.c b/tests/test-logging.c
index cec18b31b4..a7e36dbfe8 100644
--- a/tests/test-logging.c
+++ b/tests/test-logging.c
@@ -211,6 +211,8 @@ int main(int argc, char **argv)
  tmp_path, test_logfile_lock);
 
 rc = g_test_run();
+qemu_log_close();
+drain_call_rcu();
 
 rmdir_full(tmp_path);
 return rc;
-- 
2.28.0.windows.1




[PATCH v10 21/26] tests: Fixes test-qdev-global-props.c

2020-09-15 Thread Yonggang Luo
On win32 the line ending are \r\n, so we skip the \n in function 
test_dynamic_globalprop

Signed-off-by: Yonggang Luo 
Reviewed-by: Daniel P. Berrangé 
---
 tests/test-qdev-global-props.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tests/test-qdev-global-props.c b/tests/test-qdev-global-props.c
index 8a3c14d92c..c8862cac5f 100644
--- a/tests/test-qdev-global-props.c
+++ b/tests/test-qdev-global-props.c
@@ -251,10 +251,13 @@ static void test_dynamic_globalprop(void)
 g_test_trap_assert_passed();
 g_test_trap_assert_stderr_unmatched("*prop1*");
 g_test_trap_assert_stderr_unmatched("*prop2*");
-g_test_trap_assert_stderr("*warning: global dynamic-prop-type-bad.prop3 
has invalid class name\n*");
+g_test_trap_assert_stderr(
+"*warning: global dynamic-prop-type-bad.prop3 has invalid class 
name*");
 g_test_trap_assert_stderr_unmatched("*prop4*");
-g_test_trap_assert_stderr("*warning: global nohotplug-type.prop5=105 not 
used\n*");
-g_test_trap_assert_stderr("*warning: global nondevice-type.prop6 has 
invalid class name\n*");
+g_test_trap_assert_stderr(
+"*warning: global nohotplug-type.prop5=105 not used*");
+g_test_trap_assert_stderr(
+"*warning: global nondevice-type.prop6 has invalid class name*");
 g_test_trap_assert_stdout("");
 }
 
-- 
2.28.0.windows.1




[PATCH v10 24/26] ci: Enable msys2 ci in cirrus

2020-09-15 Thread Yonggang Luo
Install msys2 in a proper way refer to 
https://github.com/cirruslabs/cirrus-ci-docs/issues/699
The https://wiki.qemu.org/Hosts/W32#Native_builds_with_MSYS2 need to be updated.
There is no need of --cross-prefix, open mingw64.exe instead of msys2.exe then 
we don't
need the --cross-prefix, besides we using environment variable settings:
MSYS: winsymlinks:nativestrict
MSYSTEM: MINGW64
CHERE_INVOKING: 1
to opening mingw64 native shell.
Now all enabled msys2/tests are passed

Signed-off-by: Yonggang Luo 
Reviewed-by: Daniel P. Berrangé 
---
 .cirrus.yml | 61 +
 1 file changed, 61 insertions(+)

diff --git a/.cirrus.yml b/.cirrus.yml
index 25fb4add9b..90ed891865 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -44,3 +44,64 @@ macos_xcode_task:
--enable-werror --cc=clang || { cat config.log; exit 1; }
 - gmake -j$(sysctl -n hw.ncpu)
 - gmake check
+
+windows_msys2_task:
+  windows_container:
+image: cirrusci/windowsservercore:cmake
+os_version: 2019
+cpu: 8
+memory: 8G
+  env:
+MSYS: winsymlinks:nativestrict
+MSYSTEM: MINGW64
+CHERE_INVOKING: 1
+  printenv_script:
+- C:\tools\msys64\usr\bin\bash.exe -lc 'printenv'
+  install_script:
+- C:\tools\msys64\usr\bin\bash.exe -lc "cd /c/tools &&
+curl -O 
http://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz;
+- C:\tools\msys64\usr\bin\bash.exe -lc "cd /c/tools &&
+curl -O 
http://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz.sig;
+- C:\tools\msys64\usr\bin\bash.exe -lc "cd /c/tools &&
+pacman -U --noconfirm msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz"
+- C:\tools\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -Sy"
+- C:\tools\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -S --needed
+bash pacman pacman-mirrors msys2-runtime"
+- taskkill /F /IM gpg-agent.exe
+- C:\tools\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -Su"
+- C:\tools\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -S --needed
+base-devel
+git
+mingw-w64-x86_64-python
+mingw-w64-x86_64-python-setuptools
+mingw-w64-x86_64-toolchain
+mingw-w64-x86_64-SDL2
+mingw-w64-x86_64-SDL2_image
+mingw-w64-x86_64-gtk3
+mingw-w64-x86_64-glib2
+mingw-w64-x86_64-ninja
+mingw-w64-x86_64-make
+mingw-w64-x86_64-lzo2
+mingw-w64-x86_64-zstd
+mingw-w64-x86_64-libjpeg-turbo
+mingw-w64-x86_64-pixman
+mingw-w64-x86_64-libgcrypt
+mingw-w64-x86_64-libpng
+mingw-w64-x86_64-libssh
+mingw-w64-x86_64-libxml2
+mingw-w64-x86_64-snappy
+mingw-w64-x86_64-libusb
+mingw-w64-x86_64-usbredir
+mingw-w64-x86_64-libtasn1
+mingw-w64-x86_64-nettle
+mingw-w64-x86_64-cyrus-sasl
+mingw-w64-x86_64-curl
+mingw-w64-x86_64-gnutls
+mingw-w64-x86_64-zstd"
+  script:
+- C:\tools\msys64\usr\bin\bash.exe -lc "mkdir build"
+- C:\tools\msys64\usr\bin\bash.exe -lc "cd build && ../configure 
--python=python3"
+- C:\tools\msys64\usr\bin\bash.exe -lc "cd build && make 
-j$NUMBER_OF_PROCESSORS"
+  test_script:
+- C:\tools\msys64\usr\bin\bash.exe -lc "cd build && make V=1 check"
+
-- 
2.28.0.windows.1




[PATCH v10 19/26] tests: Fixes test-io-channel-file by mask only owner file state mask bits

2020-09-15 Thread Yonggang Luo
This is the error on msys2/mingw
Running test test-io-channel-file
**
ERROR:../tests/test-io-channel-file.c:59:test_io_channel_file_helper: assertion 
failed (TEST_MASK & ~mask == st.st_mode & 0777): (384 == 438)
ERROR test-io-channel-file - Bail out! 
ERROR:../tests/test-io-channel-file.c:59:test_io_channel_file_helper: assertion 
failed (TEST_MASK & ~mask == st.st_mode & 0777): (384 == 438)

Signed-off-by: Yonggang Luo 
Reviewed-by: Daniel P. Berrangé 
---
 tests/test-io-channel-file.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/tests/test-io-channel-file.c b/tests/test-io-channel-file.c
index bac2b07562..0aa0477541 100644
--- a/tests/test-io-channel-file.c
+++ b/tests/test-io-channel-file.c
@@ -28,6 +28,16 @@
 #define TEST_FILE "tests/test-io-channel-file.txt"
 #define TEST_MASK 0600
 
+/*
+ * On Windows the stat() function in the C library checks only
+ * the FAT-style READONLY attribute and does not look at the ACL at all.
+ */
+#ifdef _WIN32
+#define TEST_MASK_EXPECT 0700
+#else
+#define TEST_MASK_EXPECT 0777
+#endif
+
 static void test_io_channel_file_helper(int flags)
 {
 QIOChannel *src, *dst;
@@ -56,7 +66,7 @@ static void test_io_channel_file_helper(int flags)
 umask(mask);
 ret = stat(TEST_FILE, );
 g_assert_cmpint(ret, >, -1);
-g_assert_cmpuint(TEST_MASK & ~mask, ==, st.st_mode & 0777);
+g_assert_cmpuint(TEST_MASK & ~mask, ==, st.st_mode & TEST_MASK_EXPECT);
 
 unlink(TEST_FILE);
 object_unref(OBJECT(src));
-- 
2.28.0.windows.1




[PATCH v10 00/26] W32, W64 msys2/mingw patches

2020-09-15 Thread Yonggang Luo
V9-V10
* gcrypt: test_tls_psk_init should write binary file instead text file.
  Split #include  out, that line not belong this patch

* tests: Enable crypto tests under msys2/mingw
  move qemu_socketpair into oslib-win32.c and rename to socketpair
  move qemu_link into osdep.c
  Fixes code style warning

* tests: Fixes test-io-channel-file by mask only owner file state mask bits
  Update comment place

* ci: Enable msys2 ci in cirrus
  Fixes misleading error message

Fixes all checkpatch error messages

V8-V9

* ci: Enable msys2 ci in cirrus
  do not install libnfs, libcapstone and jemalloc
  ident lines properly
  Do not install libnfs when the add the msys2 ci,

* Revert "configure: add --ninja option"
  Skip this revision

* block: Fixes nfs compiling error on msys2/mingw
  Use typedef long long blkcnt_t; for libnfs on msys2/mingw
  for futher implemenation, still disable nfs_get_allocated_file_size
  on win32 as it not working yet, but preserve the possibility implemenation
  it in futher

* gcrypt: test_tls_psk_init should write binary file instead text file.
  only fixes the file open mode parameter

* osdep: file locking functions are not available on Win32:
  Reword with "Do not declare the following locking functions on Win32:"

* meson: Use -b to ignore CR vs. CR-LF issues on Windows
  Reword of commit message

* tests: Enable crypto tests under msys2/mingw
  Reimplement qemu_socketpair in a simpler way. without thirdparty code

* block: enable libnfs on msys2/mingw in cirrus.yml
  New commit

* tests: disable /char/stdio/* tests in test-char.c on win32
  Needs review

* tests: fixes aio-win32 about aio_remove_fd_handler, get it consistence with=
 aio-posix.c
  Needs review

* rcu: fixes test-logging.c by call drain_call_rcu before rmdir_full
  Needs review

It first introduce msys2 CI on cirrus by fixes nfs, capstone, curses and
disable partial test-char tests.
And then fixes all unit tests failure on msys2/mingw
This fixes the reviews suggested in the mailling list
All cirrus CI are passed

Maxim Levitsky (1):
  rcu: Implement drain_call_rcu

Yonggang Luo (25):
  ci: fixes msys2 build by upgrading capstone to 4.0.2
  configure: Fixes ncursesw detection under msys2/mingw and enable
curses
  win32: Simplify gmtime_r detection direct base on
_POSIX_THREAD_SAFE_FUNCTIONS.
  curses: Fixes curses compiling errors.
  tests: disable /char/stdio/* tests in test-char.c on win32
  tests: Fixes test-replication.c on msys2/mingw.
  tests: test-replication disable /replication/secondary/* on
msys2/mingw.
  osdep: file locking functions are not available on Win32
  meson: Use -b to ignore CR vs. CR-LF issues on Windows
  gcrypt: test_tls_psk_init should write binary file instead text file.
  tests: Enable crypto tests under msys2/mingw
  meson: remove empty else and duplicated gio deps
  vmstate: Fixes test-vmstate.c on msys2/mingw
  cirrus: Building freebsd in a single short
  tests: Convert g_free to g_autofree macro in test-logging.c
  tests: Fixes test-io-channel-socket.c tests under msys2/mingw
  tests: fixes aio-win32 about aio_remove_fd_handler, get it consistence
with aio-posix.c
  tests: Fixes test-io-channel-file by mask only owner file state mask
bits
  tests: fix test-util-sockets.c
  tests: Fixes test-qdev-global-props.c
  rcu: fixes test-logging.c by call drain_call_rcu before rmdir_full
  meson: upgrade meson for execute custom ninjatool under msys2 properly
  ci: Enable msys2 ci in cirrus
  block: Fixes nfs compiling error on msys2/mingw
  block: enable libnfs on msys2/mingw in cirrus.yml

 .cirrus.yml  | 97 +++-
 block/nfs.c  | 37 +---
 capstone |  2 +-
 configure| 61 ++--
 include/qemu/osdep.h |  3 +-
 include/qemu/rcu.h   |  1 +
 include/sysemu/os-win32.h|  9 ++-
 meson|  2 +-
 meson.build  |  6 --
 tests/crypto-tls-psk-helpers.c   |  6 +-
 tests/crypto-tls-x509-helpers.c  |  6 +-
 tests/crypto-tls-x509-helpers.h  |  5 +-
 tests/qapi-schema/meson.build|  2 +-
 tests/test-char.c| 27 +
 tests/test-crypto-tlscredsx509.c | 47 
 tests/test-crypto-tlssession.c   | 64 -
 tests/test-io-channel-file.c | 12 +++-
 tests/test-io-channel-socket.c   |  2 +
 tests/test-io-channel-tls.c  | 49 +---
 tests/test-logging.c |  6 +-
 tests/test-qdev-global-props.c   |  9 ++-
 tests/test-replication.c | 22 ++--
 tests/test-util-sockets.c|  6 +-
 tests/test-vmstate.c |  3 +-
 ui/curses.c  | 14 ++---
 util/aio-win32.c | 12 +++-
 util/osdep.c | 16 ++
 util/oslib-win32.c   | 78 -
 util/rcu.c   | 55 ++
 29 files changed, 459 

[PATCH v10 04/26] win32: Simplify gmtime_r detection direct base on _POSIX_THREAD_SAFE_FUNCTIONS.

2020-09-15 Thread Yonggang Luo
First, this reduce the size of configure, configure are tending to removal in 
future,
and this didn't introduce any new feature or remove any exist feature.
Second, the current localtime_r detection are conflict with ncursesw detection 
in
mingw, when ncursesw detected, it will provide the following compile flags
pkg-config --cflags ncursesw
-D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L 
-IC:/CI-Tools/msys64/mingw64/include/ncursesw
And the compile flag _POSIX_C_SOURCE will always cause 
_POSIX_THREAD_SAFE_FUNCTIONS to
be defined, in new version of mingw, that's will cause localtime_r to be 
defined.
But the configure script didn't provide _POSIX_C_SOURCE macro, and that's will 
result
localtime_r not detected because localtime_r are defined in forceinline manner.

And finally cause conflict between QEMU defined localtime_r
struct tm *localtime_r(const time_t *timep, struct tm *result);
with mingw defined localtime_r

```
#if defined(_POSIX_C_SOURCE) && !defined(_POSIX_THREAD_SAFE_FUNCTIONS)
#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L
#endif

#ifdef _POSIX_THREAD_SAFE_FUNCTIONS
__forceinline struct tm *__CRTDECL localtime_r(const time_t *_Time, struct tm 
*_Tm) {
  return localtime_s(_Tm, _Time) ? NULL : _Tm;
}
__forceinline struct tm *__CRTDECL gmtime_r(const time_t *_Time, struct tm 
*_Tm) {
  return gmtime_s(_Tm, _Time) ? NULL : _Tm;
}
__forceinline char *__CRTDECL ctime_r(const time_t *_Time, char *_Str) {
  return ctime_s(_Str, 0x7fff, _Time) ? NULL : _Str;
}
__forceinline char *__CRTDECL asctime_r(const struct tm *_Tm, char * _Str) {
  return asctime_s(_Str, 0x7fff, _Tm) ? NULL : _Str;
}
#endif
```

So I suggest remove this configure script, and restrict msys2/mingw version to 
easy to maintain.
And use _POSIX_THREAD_SAFE_FUNCTIONS to guard the localtime_r and counterpart 
functions

Signed-off-by: Yonggang Luo 
---
 configure | 34 --
 include/sysemu/os-win32.h |  4 ++--
 util/oslib-win32.c|  2 +-
 3 files changed, 3 insertions(+), 37 deletions(-)

diff --git a/configure b/configure
index dc4b7a2e55..bac48b5b49 100755
--- a/configure
+++ b/configure
@@ -2496,37 +2496,6 @@ if test "$vhost_net" = ""; then
   test "$vhost_kernel" = "yes" && vhost_net=yes
 fi
 
-##
-# MinGW / Mingw-w64 localtime_r/gmtime_r check
-
-if test "$mingw32" = "yes"; then
-# Some versions of MinGW / Mingw-w64 lack localtime_r
-# and gmtime_r entirely.
-#
-# Some versions of Mingw-w64 define a macro for
-# localtime_r/gmtime_r.
-#
-# Some versions of Mingw-w64 will define functions
-# for localtime_r/gmtime_r, but only if you have
-# _POSIX_THREAD_SAFE_FUNCTIONS defined. For fun
-# though, unistd.h and pthread.h both define
-# that for you.
-#
-# So this #undef localtime_r and #include 
-# are not in fact redundant.
-cat > $TMPC << EOF
-#include 
-#include 
-#undef localtime_r
-int main(void) { localtime_r(NULL, NULL); return 0; }
-EOF
-if compile_prog "" "" ; then
-localtime_r="yes"
-else
-localtime_r="no"
-fi
-fi
-
 ##
 # pkg-config probe
 
@@ -7088,9 +7057,6 @@ if [ "$bsd" = "yes" ] ; then
   echo "CONFIG_BSD=y" >> $config_host_mak
 fi
 
-if test "$localtime_r" = "yes" ; then
-  echo "CONFIG_LOCALTIME_R=y" >> $config_host_mak
-fi
 if test "$qom_cast_debug" = "yes" ; then
   echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak
 fi
diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
index d8978e28c0..3ac8a53bac 100644
--- a/include/sysemu/os-win32.h
+++ b/include/sysemu/os-win32.h
@@ -48,12 +48,12 @@
 #define siglongjmp(env, val) longjmp(env, val)
 
 /* Missing POSIX functions. Don't use MinGW-w64 macros. */
-#ifndef CONFIG_LOCALTIME_R
+#ifndef _POSIX_THREAD_SAFE_FUNCTIONS
 #undef gmtime_r
 struct tm *gmtime_r(const time_t *timep, struct tm *result);
 #undef localtime_r
 struct tm *localtime_r(const time_t *timep, struct tm *result);
-#endif /* CONFIG_LOCALTIME_R */
+#endif
 
 static inline void os_setup_signal_handling(void) {}
 static inline void os_daemonize(void) {}
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index c654dafd93..f2fa9a3549 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -106,7 +106,7 @@ void qemu_anon_ram_free(void *ptr, size_t size)
 }
 }
 
-#ifndef CONFIG_LOCALTIME_R
+#ifndef _POSIX_THREAD_SAFE_FUNCTIONS
 /* FIXME: add proper locking */
 struct tm *gmtime_r(const time_t *timep, struct tm *result)
 {
-- 
2.28.0.windows.1




Re: [PATCH v2 01/10] capstone: Convert Makefile bits to meson bits

2020-09-15 Thread Paolo Bonzini
On 15/09/20 19:07, 罗勇刚(Yonggang Luo) wrote:
> 
> Linux distributions generally do not want to have bundled libraries, so
> 
> Yes, bundled libraries is a bad idea, but static linked library is
> another case, that won't affect
> the Linux distributions. 

As far as Linux distributions are concerned, static linking is a case of
bundling.  Bundling means that, for example, any security issue will
require rebuilding the package that does the bundling (this applies
especially to slirp among the three that QEMU we bundles).

Paolo




[PATCH v10 20/26] tests: fix test-util-sockets.c

2020-09-15 Thread Yonggang Luo
Fixes following errors:
Running test test-util-sockets
ERROR test-util-sockets - missing test plan

# Start of name tests
**
ERROR:../tests/test-util-sockets.c:93:test_socket_fd_pass_name_good: assertion 
failed (fd != -1): (-1 != -1)
Bail out! ERROR:../tests/test-util-sockets.c:93:test_socket_fd_pass_name_good: 
assertion failed (fd != -1): (-1 != -1)

First should call to qemu_init_main_loop before socket_init,
then on win32 doesn't support for SOCKET_ADDRESS_TYPE_FD socket type

Signed-off-by: Yonggang Luo 
Reviewed-by: Daniel P. Berrangé 
---
 tests/test-util-sockets.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tests/test-util-sockets.c b/tests/test-util-sockets.c
index af9f5c0c70..1bbb16d9b1 100644
--- a/tests/test-util-sockets.c
+++ b/tests/test-util-sockets.c
@@ -75,7 +75,7 @@ int monitor_vprintf(Monitor *mon, const char *fmt, va_list 
ap) { abort(); }
 void monitor_init_qmp(Chardev *chr, bool pretty, Error **errp) {}
 void monitor_init_hmp(Chardev *chr, bool use_readline, Error **errp) {}
 
-
+#ifndef _WIN32
 static void test_socket_fd_pass_name_good(void)
 {
 SocketAddress addr;
@@ -227,6 +227,7 @@ static void test_socket_fd_pass_num_nocli(void)
 
 g_free(addr.u.fd.str);
 }
+#endif
 
 #ifdef __linux__
 static gchar *abstract_sock_name;
@@ -321,6 +322,7 @@ int main(int argc, char **argv)
 {
 bool has_ipv4, has_ipv6;
 
+qemu_init_main_loop(_abort);
 socket_init();
 
 g_test_init(, , NULL);
@@ -340,6 +342,7 @@ int main(int argc, char **argv)
 test_fd_is_socket_bad);
 g_test_add_func("/util/socket/is-socket/good",
 test_fd_is_socket_good);
+#ifndef _WIN32
 g_test_add_func("/socket/fd-pass/name/good",
 test_socket_fd_pass_name_good);
 g_test_add_func("/socket/fd-pass/name/bad",
@@ -352,6 +355,7 @@ int main(int argc, char **argv)
 test_socket_fd_pass_num_bad);
 g_test_add_func("/socket/fd-pass/num/nocli",
 test_socket_fd_pass_num_nocli);
+#endif
 }
 
 #ifdef __linux__
-- 
2.28.0.windows.1




[PATCH v10 18/26] tests: fixes aio-win32 about aio_remove_fd_handler, get it consistence with aio-posix.c

2020-09-15 Thread Yonggang Luo
This is a fixes for
(C:\work\xemu\qemu\build\tests\test-aio-multithread.exe:19100): GLib-CRITICAL 
**: 23:03:24.965: g_source_remove_poll: assertion '!SOURCE_DESTROYED (source)' 
failed
ERROR test-aio-multithread - Bail out! GLib-FATAL-CRITICAL: 
g_source_remove_poll: assertion '!SOURCE_DESTROYED (source)' failed

(C:\work\xemu\qemu\build\tests\test-bdrv-drain.exe:21036): GLib-CRITICAL **: 
23:03:29.861: g_source_remove_poll: assertion '!SOURCE_DESTROYED (source)' 
failed
ERROR test-bdrv-drain - Bail out! GLib-FATAL-CRITICAL: g_source_remove_poll: 
assertion '!SOURCE_DESTROYED (source)' failed

And the idea comes from https://patchwork.kernel.org/patch/9975239/

Signed-off-by: Yonggang Luo 
---
 util/aio-win32.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/util/aio-win32.c b/util/aio-win32.c
index 953c56ab48..49bd90e62e 100644
--- a/util/aio-win32.c
+++ b/util/aio-win32.c
@@ -37,6 +37,16 @@ struct AioHandler {
 
 static void aio_remove_fd_handler(AioContext *ctx, AioHandler *node)
 {
+/*
+ * If the GSource is in the process of being destroyed then
+ * g_source_remove_poll() causes an assertion failure.  Skip
+ * removal in that case, because glib cleans up its state during
+ * destruction anyway.
+ */
+if (!g_source_is_destroyed(>source)) {
+g_source_remove_poll(>source, >pfd);
+}
+
 /* If aio_poll is in progress, just mark the node as deleted */
 if (qemu_lockcnt_count(>list_lock)) {
 node->deleted = 1;
@@ -139,8 +149,6 @@ void aio_set_event_notifier(AioContext *ctx,
 /* Are we deleting the fd handler? */
 if (!io_notify) {
 if (node) {
-g_source_remove_poll(>source, >pfd);
-
 aio_remove_fd_handler(ctx, node);
 }
 } else {
-- 
2.28.0.windows.1




[PATCH v10 16/26] tests: Convert g_free to g_autofree macro in test-logging.c

2020-09-15 Thread Yonggang Luo
g_autofree are prefer than g_free when possible.

Signed-off-by: Yonggang Luo 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Daniel P. Berrangé 
---
 tests/test-logging.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/test-logging.c b/tests/test-logging.c
index 8a1161de1d..cec18b31b4 100644
--- a/tests/test-logging.c
+++ b/tests/test-logging.c
@@ -196,7 +196,8 @@ static void rmdir_full(gchar const *root)
 
 int main(int argc, char **argv)
 {
-gchar *tmp_path = g_dir_make_tmp("qemu-test-logging.XX", NULL);
+g_autofree gchar *tmp_path = g_dir_make_tmp(
+"qemu-test-logging.XX", NULL);
 int rc;
 
 g_test_init(, , NULL);
@@ -212,6 +213,5 @@ int main(int argc, char **argv)
 rc = g_test_run();
 
 rmdir_full(tmp_path);
-g_free(tmp_path);
 return rc;
 }
-- 
2.28.0.windows.1




[Bug 1895703] [NEW] performance degradation in tcg since Meson switch

2020-09-15 Thread Philippe Mathieu-Daudé
Public bug reported:

The buildsys conversion to Meson (1d806cef0e3..7fd51e68c34)
introduced a degradation in performance in some TCG targets:


Test Program: matmult_double

Target  Instructions PreviousLatest
 1d806cef   7fd51e68
--    --  --
alpha  3 233 957 639   - +7.472%
m68k   3 919 110 506   -+18.433%


Original report from Ahmed Karaman with further testing done
by Aleksandar Markovic:
https://www.mail-archive.com/qemu-devel@nongnu.org/msg740279.html

** Affects: qemu
 Importance: Undecided
 Status: New


** Tags: buildsys tcg

** Tags added: buildsys tcg

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

Title:
  performance degradation in tcg since Meson switch

Status in QEMU:
  New

Bug description:
  The buildsys conversion to Meson (1d806cef0e3..7fd51e68c34)
  introduced a degradation in performance in some TCG targets:

  
  Test Program: matmult_double
  
  Target  Instructions PreviousLatest
   1d806cef   7fd51e68
  --    --  --
  alpha  3 233 957 639   - +7.472%
  m68k   3 919 110 506   -+18.433%
  

  Original report from Ahmed Karaman with further testing done
  by Aleksandar Markovic:
  https://www.mail-archive.com/qemu-devel@nongnu.org/msg740279.html

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



[PATCH v10 01/26] rcu: Implement drain_call_rcu

2020-09-15 Thread Yonggang Luo
From: Maxim Levitsky 

This will allow is to preserve the semantics of hmp_device_del,
that the device is deleted immediatly which was changed by previos
patch that delayed this to RCU callback

Signed-off-by: Maxim Levitsky 
Suggested-by: Stefan Hajnoczi 
Reviewed-by: Stefan Hajnoczi 
---
 include/qemu/rcu.h |  1 +
 util/rcu.c | 55 ++
 2 files changed, 56 insertions(+)

diff --git a/include/qemu/rcu.h b/include/qemu/rcu.h
index 570aa603eb..0e375ebe13 100644
--- a/include/qemu/rcu.h
+++ b/include/qemu/rcu.h
@@ -133,6 +133,7 @@ struct rcu_head {
 };
 
 extern void call_rcu1(struct rcu_head *head, RCUCBFunc *func);
+extern void drain_call_rcu(void);
 
 /* The operands of the minus operator must have the same type,
  * which must be the one that we specify in the cast.
diff --git a/util/rcu.c b/util/rcu.c
index 60a37f72c3..c4fefa9333 100644
--- a/util/rcu.c
+++ b/util/rcu.c
@@ -293,6 +293,61 @@ void call_rcu1(struct rcu_head *node, void (*func)(struct 
rcu_head *node))
 qemu_event_set(_call_ready_event);
 }
 
+
+struct rcu_drain {
+struct rcu_head rcu;
+QemuEvent drain_complete_event;
+};
+
+static void drain_rcu_callback(struct rcu_head *node)
+{
+struct rcu_drain *event = (struct rcu_drain *)node;
+qemu_event_set(>drain_complete_event);
+}
+
+/*
+ * This function ensures that all pending RCU callbacks
+ * on the current thread are done executing
+
+ * drops big qemu lock during the wait to allow RCU thread
+ * to process the callbacks
+ *
+ */
+
+void drain_call_rcu(void)
+{
+struct rcu_drain rcu_drain;
+bool locked = qemu_mutex_iothread_locked();
+
+memset(_drain, 0, sizeof(struct rcu_drain));
+qemu_event_init(_drain.drain_complete_event, false);
+
+if (locked) {
+qemu_mutex_unlock_iothread();
+}
+
+
+/*
+ * RCU callbacks are invoked in the same order as in which they
+ * are registered, thus we can be sure that when 'drain_rcu_callback'
+ * is called, all RCU callbacks that were registered on this thread
+ * prior to calling this function are completed.
+ *
+ * Note that since we have only one global queue of the RCU callbacks,
+ * we also end up waiting for most of RCU callbacks that were registered
+ * on the other threads, but this is a side effect that shoudn't be
+ * assumed.
+ */
+
+call_rcu1(_drain.rcu, drain_rcu_callback);
+qemu_event_wait(_drain.drain_complete_event);
+
+if (locked) {
+qemu_mutex_lock_iothread();
+}
+
+}
+
 void rcu_register_thread(void)
 {
 assert(rcu_reader.ctr == 0);
-- 
2.28.0.windows.1




[PATCH v10 03/26] configure: Fixes ncursesw detection under msys2/mingw and enable curses

2020-09-15 Thread Yonggang Luo
The mingw pkg-config are showing following absolute path and contains : as the 
separator,
so we must not use : as path separator. and we know the command line parameter 
are not likely
contains newline, we could use newline as path command line parameter separator

-D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L 
-IC:/CI-Tools/msys64/mingw64/include/ncursesw:-I/usr/include/ncursesw:
-DNCURSES_WIDECHAR -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC -pipe 
-lncursesw -lgnurx -ltre -lintl -liconv
-DNCURSES_WIDECHAR -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC -lncursesw
-DNCURSES_WIDECHAR -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC -lcursesw
-DNCURSES_WIDECHAR /CI-Tools/msys64/mingw64/include/ncursesw -pipe -lncursesw 
-lgnurx -ltre -lintl -liconv
-DNCURSES_WIDECHAR /CI-Tools/msys64/mingw64/include/ncursesw -lncursesw
-DNCURSES_WIDECHAR /CI-Tools/msys64/mingw64/include/ncursesw -lcursesw
-DNCURSES_WIDECHAR -I/usr/include/ncursesw -pipe -lncursesw -lgnurx -ltre 
-lintl -liconv
-DNCURSES_WIDECHAR -I/usr/include/ncursesw -lncursesw
-DNCURSES_WIDECHAR -I/usr/include/ncursesw -lcursesw

Refer to https://unix.stackexchange.com/a/103011/218958

If your file names are guaranteed not to contain newlines, you can use newlines 
as the separator. W
hen you expand the variable, first turn off globbing with set -f and set the 
list of field splitting characters
IFS to contain only a newline.

msys2/mingw lacks the POSIX-required langinfo.h.

gcc test.c -DNCURSES_WIDECHAR -I/mingw64/include/ncursesw -pipe -lncursesw 
-lgnurx -ltre -lintl -liconv
test.c:4:10: fatal error: langinfo.h: No such file or directory
4 | #include 
  |  ^~~~
compilation terminated.

So we using g_get_codeset instead of nl_langinfo(CODESET)

Signed-off-by: Yonggang Luo 
Reviewed-by: Gerd Hoffmann 
---
 configure   | 25 +++--
 ui/curses.c | 10 +-
 2 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/configure b/configure
index f59080703e..dc4b7a2e55 100755
--- a/configure
+++ b/configure
@@ -3654,35 +3654,40 @@ if test "$iconv" = "no" ; then
 fi
 if test "$curses" != "no" ; then
   if test "$mingw32" = "yes" ; then
-curses_inc_list="$($pkg_config --cflags ncurses 2>/dev/null):"
-curses_lib_list="$($pkg_config --libs ncurses 2>/dev/null):-lpdcurses"
+curses_inc_list="$($pkg_config --cflags ncurses 2>/dev/null)
+  $($pkg_config --cflags ncursesw 2>/dev/null)"
+curses_lib_list="$($pkg_config --libs ncurses 2>/dev/null)
+  $($pkg_config --libs ncursesw 2>/dev/null)
+  -lpdcurses"
   else
-curses_inc_list="$($pkg_config --cflags ncursesw 
2>/dev/null):-I/usr/include/ncursesw:"
-curses_lib_list="$($pkg_config --libs ncursesw 
2>/dev/null):-lncursesw:-lcursesw"
+curses_inc_list="$($pkg_config --cflags ncursesw 2>/dev/null)
+  -I/usr/include/ncursesw:"
+curses_lib_list="$($pkg_config --libs ncursesw 2>/dev/null)
+  -lncursesw
+  -lcursesw"
   fi
   curses_found=no
   cat > $TMPC << EOF
 #include 
 #include 
 #include 
-#include 
 int main(void) {
-  const char *codeset;
   wchar_t wch = L'w';
   setlocale(LC_ALL, "");
   resize_term(0, 0);
   addwstr(L"wide chars\n");
   addnwstr(, 1);
   add_wch(WACS_DEGREE);
-  codeset = nl_langinfo(CODESET);
-  return codeset != 0;
+  return 0;
 }
 EOF
-  IFS=:
+  IFS='
+'   # turn off variable value expansion except for 
splitting at newlines
   for curses_inc in $curses_inc_list; do
 # Make sure we get the wide character prototypes
 curses_inc="-DNCURSES_WIDECHAR $curses_inc"
-IFS=:
+IFS='
+'   # turn off variable value expansion except for 
splitting at newlines
 for curses_lib in $curses_lib_list; do
   unset IFS
   if compile_prog "$curses_inc" "$curses_lib" ; then
diff --git a/ui/curses.c b/ui/curses.c
index a59b23a9cf..12bc682cf9 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -30,7 +30,6 @@
 #endif
 #include 
 #include 
-#include 
 #include 
 
 #include "qapi/error.h"
@@ -526,6 +525,7 @@ static void font_setup(void)
 iconv_t nativecharset_to_ucs2;
 iconv_t font_conv;
 int i;
+g_autofree gchar *local_codeset = g_get_codeset();
 
 /*
  * Control characters are normally non-printable, but VGA does have
@@ -566,14 +566,14 @@ static void font_setup(void)
   0x25bc
 };
 
-ucs2_to_nativecharset = iconv_open(nl_langinfo(CODESET), "UCS-2");
+ucs2_to_nativecharset = iconv_open(local_codeset, "UCS-2");
 if (ucs2_to_nativecharset == (iconv_t) -1) {
 fprintf(stderr, "Could not convert font glyphs from UCS-2: '%s'\n",
 strerror(errno));
 exit(1);
 }
 
-nativecharset_to_ucs2 = iconv_open("UCS-2", nl_langinfo(CODESET));
+nativecharset_to_ucs2 = iconv_open("UCS-2", local_codeset);
 if (nativecharset_to_ucs2 == (iconv_t) -1) {
 iconv_close(ucs2_to_nativecharset);
 fprintf(stderr, "Could not convert font glyphs to 

[PATCH v10 17/26] tests: Fixes test-io-channel-socket.c tests under msys2/mingw

2020-09-15 Thread Yonggang Luo
Currently test-io-channel-socket doesn't init with
qemu_init_main_loop
and that's cause the qemu_aio_context not inited,
and the following is the stack when null pointer accessed:

qemu_fd_register (c:\work\xemu\qemu\util\main-loop.c:336)
qemu_try_set_nonblock (c:\work\xemu\qemu\util\oslib-win32.c:224)
qemu_set_nonblock (c:\work\xemu\qemu\util\oslib-win32.c:230)
socket_can_bind_connect (c:\work\xemu\qemu\tests\socket-helpers.c:93)
socket_check_protocol_support (c:\work\xemu\qemu\tests\socket-helpers.c:141)
main (c:\work\xemu\qemu\tests\test-io-channel-socket.c:568)
__tmainCRTStartup (@__tmainCRTStartup:142)
mainCRTStartup (@1400014f6..140001539:3)
BaseThreadInitThunk (@BaseThreadInitThunk:9)
RtlUserThreadStart (@RtlUserThreadStart:12)

Signed-off-by: Yonggang Luo 
Reviewed-by: Daniel P. Berrangé 
---
 tests/test-io-channel-socket.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/test-io-channel-socket.c b/tests/test-io-channel-socket.c
index d43083a766..743577d744 100644
--- a/tests/test-io-channel-socket.c
+++ b/tests/test-io-channel-socket.c
@@ -25,6 +25,7 @@
 #include "socket-helpers.h"
 #include "qapi/error.h"
 #include "qemu/module.h"
+#include "qemu/main-loop.h"
 
 
 static void test_io_channel_set_socket_bufs(QIOChannel *src,
@@ -556,6 +557,7 @@ int main(int argc, char **argv)
 bool has_ipv4, has_ipv6;
 
 module_call_init(MODULE_INIT_QOM);
+qemu_init_main_loop(_abort);
 socket_init();
 
 g_test_init(, , NULL);
-- 
2.28.0.windows.1




[PATCH v10 02/26] ci: fixes msys2 build by upgrading capstone to 4.0.2

2020-09-15 Thread Yonggang Luo
The currently random version capstone have the following compiling issue:
  CC  /c/work/xemu/qemu/build/slirp/src/arp_table.o
make[1]: *** No rule to make target 
“/c/work/xemu/qemu/build/capstone/capstone.lib”。 Stop.

Subproject commit 1d230532840a37ac032c6ab80128238fc930c6c1 are the tagged 
version 4.0.2
when upgrading to this version, the folder structure of include are changed to
qemu\capstone\include
│  platform.h
│
├─capstone
│  arm.h
│  arm64.h
│  capstone.h
│  evm.h
│  m680x.h
│  m68k.h
│  mips.h
│  platform.h
│  ppc.h
│  sparc.h
│  systemz.h
│  tms320c64x.h
│  x86.h
│  xcore.h
│
└─windowsce
intrin.h
stdint.h

in capstone. so we need add extra include path 
-I${source_path}/capstone/include/capstone
for directly #include , and the exist include path should preserve, 
because
in capstone code there something like #include "capstone/capstone.h"

If only using
capstone_cflags="-I${source_path}/capstone/include/capstone"
Then will cause the following compiling error:

  CC  cs.o
cs.c:17:10: fatal error: 'capstone/capstone.h' file not found
#include 
 ^
1 error generated.

Signed-off-by: Yonggang Luo 
---
 capstone  | 2 +-
 configure | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/capstone b/capstone
index 22ead3e0bf..1d23053284 16
--- a/capstone
+++ b/capstone
@@ -1 +1 @@
-Subproject commit 22ead3e0bfdb87516656453336160e0a37b066bf
+Subproject commit 1d230532840a37ac032c6ab80128238fc930c6c1
diff --git a/configure b/configure
index ce27eafb0a..f59080703e 100755
--- a/configure
+++ b/configure
@@ -5157,7 +5157,7 @@ case "$capstone" in
   LIBCAPSTONE=libcapstone.a
 fi
 capstone_libs="-Lcapstone -lcapstone"
-capstone_cflags="-I${source_path}/capstone/include"
+capstone_cflags="-I${source_path}/capstone/include 
-I${source_path}/capstone/include/capstone"
 ;;
 
   system)
-- 
2.28.0.windows.1




[PATCH v10 05/26] curses: Fixes curses compiling errors.

2020-09-15 Thread Yonggang Luo
This is the compiling error:
../ui/curses.c: In function 'curses_refresh':
../ui/curses.c:256:5: error: 'next_maybe_keycode' may be used uninitialized in 
this function [-Werror=maybe-uninitialized]
  256 | curses2foo(_curses2keycode, _curseskey2keycode, chr, maybe_keycode)
  | ^~
../ui/curses.c:302:32: note: 'next_maybe_keycode' was declared here
  302 | enum maybe_keycode next_maybe_keycode;
  |^~
../ui/curses.c:256:5: error: 'maybe_keycode' may be used uninitialized in this 
function [-Werror=maybe-uninitialized]
  256 | curses2foo(_curses2keycode, _curseskey2keycode, chr, maybe_keycode)
  | ^~
../ui/curses.c:265:24: note: 'maybe_keycode' was declared here
  265 | enum maybe_keycode maybe_keycode;
  |^
cc1.exe: all warnings being treated as errors

gcc version 10.2.0 (Rev1, Built by MSYS2 project)

Signed-off-by: Yonggang Luo 
Reviewed-by: Gerd Hoffmann 
Reviewed-by: Daniel P. Berrangé 
---
 ui/curses.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ui/curses.c b/ui/curses.c
index 12bc682cf9..e4f9588c3e 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -262,7 +262,7 @@ static int curses2foo(const int _curses2foo[], const int 
_curseskey2foo[],
 static void curses_refresh(DisplayChangeListener *dcl)
 {
 int chr, keysym, keycode, keycode_alt;
-enum maybe_keycode maybe_keycode;
+enum maybe_keycode maybe_keycode = CURSES_KEYCODE;
 
 curses_winch_check();
 
@@ -299,7 +299,7 @@ static void curses_refresh(DisplayChangeListener *dcl)
 
 /* alt or esc key */
 if (keycode == 1) {
-enum maybe_keycode next_maybe_keycode;
+enum maybe_keycode next_maybe_keycode = CURSES_KEYCODE;
 int nextchr = console_getch(_maybe_keycode);
 
 if (nextchr != -1) {
-- 
2.28.0.windows.1




[PATCH v10 07/26] tests: Fixes test-replication.c on msys2/mingw.

2020-09-15 Thread Yonggang Luo
On Windows there is no path like /tmp/s_local_disk.XX
Use g_get_tmp_dir instead of /tmp.

Signed-off-by: Yonggang Luo 
Reviewed-by: Daniel P. Berrangé 
---
 tests/test-replication.c | 18 ++
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/tests/test-replication.c b/tests/test-replication.c
index 9ab3666a90..e7cbd6b144 100644
--- a/tests/test-replication.c
+++ b/tests/test-replication.c
@@ -23,14 +23,14 @@
 
 /* primary */
 #define P_ID "primary-id"
-static char p_local_disk[] = "/tmp/p_local_disk.XX";
+static char *p_local_disk;
 
 /* secondary */
 #define S_ID "secondary-id"
 #define S_LOCAL_DISK_ID "secondary-local-disk-id"
-static char s_local_disk[] = "/tmp/s_local_disk.XX";
-static char s_active_disk[] = "/tmp/s_active_disk.XX";
-static char s_hidden_disk[] = "/tmp/s_hidden_disk.XX";
+static char *s_local_disk;
+static char *s_active_disk;
+static char *s_hidden_disk;
 
 /* FIXME: steal from blockdev.c */
 QemuOptsList qemu_drive_opts = {
@@ -571,6 +571,11 @@ static void setup_sigabrt_handler(void)
 int main(int argc, char **argv)
 {
 int ret;
+const char *tmpdir = g_get_tmp_dir();
+p_local_disk = g_strdup_printf("%s/p_local_disk.XX", tmpdir);
+s_local_disk = g_strdup_printf("%s/s_local_disk.XX", tmpdir);
+s_active_disk = g_strdup_printf("%s/s_active_disk.XX", tmpdir);
+s_hidden_disk = g_strdup_printf("%s/s_hidden_disk.XX", tmpdir);
 qemu_init_main_loop(_fatal);
 bdrv_init();
 
@@ -605,5 +610,10 @@ int main(int argc, char **argv)
 
 cleanup_imgs();
 
+g_free(p_local_disk);
+g_free(s_local_disk);
+g_free(s_active_disk);
+g_free(s_hidden_disk);
+
 return ret;
 }
-- 
2.28.0.windows.1




[PATCH v10 08/26] tests: test-replication disable /replication/secondary/* on msys2/mingw.

2020-09-15 Thread Yonggang Luo
They caused failure on msys2/mingw, that's because file-win32.c not implement
.bdrv_reopen_prepare/commit/abort yet.

This is the error message:
> $ ./tests/test-replication.exe
> # random seed: R02S3f4d1c01af2b0a046990e0235c481faf
> 1..13
> # Start of replication tests
> # Start of primary tests
> ok 1 /replication/primary/read
> ok 2 /replication/primary/write
> ok 3 /replication/primary/start
> ok 4 /replication/primary/stop
> ok 5 /replication/primary/do_checkpoint
> ok 6 /replication/primary/get_error_all
> # End of primary tests
> # Start of secondary tests
> ok 7 /replication/secondary/read
> ok 8 /replication/secondary/write
> Unexpected error in bdrv_reopen_prepare() at ../block.c:4191:
> Block format 'file' used by node '#block4287' does not support reopening
> files

Signed-off-by: Yonggang Luo 
Reviewed-by: Daniel P. Berrangé 
---
 tests/test-replication.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/tests/test-replication.c b/tests/test-replication.c
index e7cbd6b144..b067240add 100644
--- a/tests/test-replication.c
+++ b/tests/test-replication.c
@@ -392,6 +392,7 @@ static void test_secondary_write(void)
 teardown_secondary();
 }
 
+#ifndef _WIN32
 static void test_secondary_start(void)
 {
 BlockBackend *top_blk, *local_blk;
@@ -546,6 +547,7 @@ static void test_secondary_get_error_all(void)
 
 teardown_secondary();
 }
+#endif
 
 static void sigabrt_handler(int signo)
 {
@@ -597,6 +599,7 @@ int main(int argc, char **argv)
 /* Secondary */
 g_test_add_func("/replication/secondary/read",  test_secondary_read);
 g_test_add_func("/replication/secondary/write", test_secondary_write);
+#ifndef _WIN32
 g_test_add_func("/replication/secondary/start", test_secondary_start);
 g_test_add_func("/replication/secondary/stop",  test_secondary_stop);
 g_test_add_func("/replication/secondary/continuous_replication",
@@ -605,6 +608,7 @@ int main(int argc, char **argv)
 test_secondary_do_checkpoint);
 g_test_add_func("/replication/secondary/get_error_all",
 test_secondary_get_error_all);
+#endif
 
 ret = g_test_run();
 
-- 
2.28.0.windows.1




Re: [PATCH v2 01/10] capstone: Convert Makefile bits to meson bits

2020-09-15 Thread Paolo Bonzini
On 15/09/20 18:12, 罗勇刚(Yonggang Luo) wrote:
> 
> I suggest remove the capstone=system option cause the system library
> may not satisfy the requirements of qemu and create in-consistence
> expereince when bug or error happens about capstone. We either have
> git submodule capstone or nothing at all

Linux distributions generally do not want to have bundled libraries, so
the fallback to the system library is the default.  We single out
capstone, libfdt and slirp because they are slightly less common
dependencies and are missing on some distros; however, in general we
strive to _only_ use system libraries and not package any of QEMU's
dependencies.

Paolo




Re: [PATCH v2 1/8] linux-user: test, don't assert addr != test in pgb_reserved_va

2020-09-15 Thread Richard Henderson
On 9/15/20 6:43 AM, Alex Bennée wrote:
> On older kernels which don't implement MAP_FIXED_NOREPLACE the kernel
> may still fail to give us the address we asked for despite having
> already probed the map for a valid hole. Asserting isn't particularly
> useful to the user so let us move the check up and expand the
> error_report a little to give them a fighting chance of working around
> the problem.
> 
> Ameliorates: ee94743034
> Cc: Bug 1895080 <1895...@bugs.launchpad.net>
> Signed-off-by: Alex Bennée 
> ---
>  linux-user/elfload.c | 9 -
>  1 file changed, 4 insertions(+), 5 deletions(-)

Reviewed-by: Richard Henderson 

r~



[PATCH v10 11/26] gcrypt: test_tls_psk_init should write binary file instead text file.

2020-09-15 Thread Yonggang Luo
On windows, if open file with "w", it's will automatically convert
"\n" to "\r\n" when writing to file.

Signed-off-by: Yonggang Luo 
---
 tests/crypto-tls-psk-helpers.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/crypto-tls-psk-helpers.c b/tests/crypto-tls-psk-helpers.c
index a8395477c3..11ae26368c 100644
--- a/tests/crypto-tls-psk-helpers.c
+++ b/tests/crypto-tls-psk-helpers.c
@@ -32,7 +32,7 @@ void test_tls_psk_init(const char *pskfile)
 {
 FILE *fp;
 
-fp = fopen(pskfile, "w");
+fp = fopen(pskfile, "wb");
 if (fp == NULL) {
 g_critical("Failed to create pskfile %s", pskfile);
 abort();
-- 
2.28.0.windows.1




[PATCH v10 06/26] tests: disable /char/stdio/* tests in test-char.c on win32

2020-09-15 Thread Yonggang Luo
These tests are blocking test-char to be finished.
Disable them by using variable is_win32, so we doesn't
need macro to open it. and easy recover those function
latter.

Signed-off-by: Yonggang Luo 
---
 tests/test-char.c | 27 +--
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/tests/test-char.c b/tests/test-char.c
index d35cc839bc..09e4069306 100644
--- a/tests/test-char.c
+++ b/tests/test-char.c
@@ -77,7 +77,6 @@ static void fe_event(void *opaque, QEMUChrEvent event)
 }
 }
 
-#ifdef _WIN32
 static void char_console_test_subprocess(void)
 {
 QemuOpts *opts;
@@ -102,7 +101,7 @@ static void char_console_test(void)
 g_test_trap_assert_passed();
 g_test_trap_assert_stdout("CONSOLE");
 }
-#endif
+
 static void char_stdio_test_subprocess(void)
 {
 Chardev *chr;
@@ -1448,7 +1447,11 @@ static SocketAddress unixaddr = {
 
 int main(int argc, char **argv)
 {
-bool has_ipv4, has_ipv6;
+bool has_ipv4, has_ipv6, is_win32 = false;
+
+#ifdef _WIN32
+is_win32 = true;
+#endif
 
 qemu_init_main_loop(_abort);
 socket_init();
@@ -1467,12 +1470,16 @@ int main(int argc, char **argv)
 g_test_add_func("/char/invalid", char_invalid_test);
 g_test_add_func("/char/ringbuf", char_ringbuf_test);
 g_test_add_func("/char/mux", char_mux_test);
-#ifdef _WIN32
-g_test_add_func("/char/console/subprocess", char_console_test_subprocess);
-g_test_add_func("/char/console", char_console_test);
-#endif
-g_test_add_func("/char/stdio/subprocess", char_stdio_test_subprocess);
-g_test_add_func("/char/stdio", char_stdio_test);
+if (0) {
+g_test_add_func("/char/console/subprocess",
+char_console_test_subprocess);
+g_test_add_func("/char/console", char_console_test);
+}
+
+if (!is_win32) {
+g_test_add_func("/char/stdio/subprocess", char_stdio_test_subprocess);
+g_test_add_func("/char/stdio", char_stdio_test);
+}
 #ifndef _WIN32
 g_test_add_func("/char/pipe", char_pipe_test);
 #endif
@@ -1534,7 +1541,7 @@ int main(int argc, char **argv)
 g_test_add_data_func("/char/socket/client/dupid-reconnect/" # name, \
   ##name, char_socket_client_dupid_test)
 
-if (has_ipv4) {
+if (has_ipv4 && !is_win32) {
 SOCKET_SERVER_TEST(tcp, );
 SOCKET_CLIENT_TEST(tcp, );
 g_test_add_data_func("/char/socket/server/two-clients/tcp", ,
-- 
2.28.0.windows.1




[PATCH v10 10/26] meson: Use -b to ignore CR vs. CR-LF issues on Windows

2020-09-15 Thread Yonggang Luo
Ideally we would use the '--strip-trailing-cr' option, but not
being POSIX is a portability problem (i.e. BSDs and Solaris
based OSes). Instead use the '-b' option which, although doing
slightly more, produce the expected result on Windows."

Signed-off-by: Yonggang Luo 
Reviewed-by: Eric Blake 
Reviewed-by: Daniel P. Berrangé 
---
 tests/qapi-schema/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build
index c87d141417..f1449298b0 100644
--- a/tests/qapi-schema/meson.build
+++ b/tests/qapi-schema/meson.build
@@ -220,6 +220,6 @@ qapi_doc = custom_target('QAPI doc',
 
 # "full_path()" needed here to work around
 # https://github.com/mesonbuild/meson/issues/7585
-test('QAPI doc', diff, args: ['-u', files('doc-good.texi'), 
qapi_doc[0].full_path()],
+test('QAPI doc', diff, args: ['-b', '-u', files('doc-good.texi'), 
qapi_doc[0].full_path()],
  depends: qapi_doc,
  suite: ['qapi-schema', 'qapi-doc'])
-- 
2.28.0.windows.1




[PATCH v10 14/26] vmstate: Fixes test-vmstate.c on msys2/mingw

2020-09-15 Thread Yonggang Luo
The vmstate are valid on win32, just need generate tmp path properly

Signed-off-by: Yonggang Luo 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Thomas Huth 
Reviewed-by: Daniel P. Berrangé 
---
 tests/test-vmstate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index 1c763015d0..ac38bfcfe8 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -34,7 +34,6 @@
 #include "qemu/module.h"
 #include "io/channel-file.h"
 
-static char temp_file[] = "/tmp/vmst.test.XX";
 static int temp_fd;
 
 
@@ -1484,6 +1483,8 @@ static void test_tmp_struct(void)
 
 int main(int argc, char **argv)
 {
+g_autofree char *temp_file = g_strdup_printf(
+"%s/vmst.test.XX", g_get_tmp_dir());
 temp_fd = mkstemp(temp_file);
 
 module_call_init(MODULE_INIT_QOM);
-- 
2.28.0.windows.1




[PATCH v10 15/26] cirrus: Building freebsd in a single short

2020-09-15 Thread Yonggang Luo
This reverts commit 45f7b7b9f38f5c4d1529a37c93dedfc26a231bba
("cirrus.yml: Split FreeBSD job into two parts").

freebsd 1 hour limit not hit anymore

I think we going to a wrong direction, I think there is some tests a stall the 
test runner,
please look at
https://cirrus-ci.com/task/5110577531977728
When its running properly, the consumed time are little, but when tests running 
too long,
look at the cpu usage, the cpu usage are nearly zero. doesn't consuming time.

And look at
https://cirrus-ci.com/task/6119341601062912

If the tests running properly, the time consuming are little
We should not hide the error by split them

Signed-off-by: Yonggang Luo 
Reviewed-by: Daniel P. Berrangé 
Reviewed-by: Ed Maste 
---
 .cirrus.yml | 35 ---
 1 file changed, 8 insertions(+), 27 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index 3dd9fcff7f..25fb4add9b 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -1,38 +1,19 @@
 env:
   CIRRUS_CLONE_DEPTH: 1
 
-freebsd_1st_task:
+freebsd_12_task:
   freebsd_instance:
 image_family: freebsd-12-1
-cpu: 4
-memory: 4G
-  install_script: ASSUME_ALWAYS_YES=yes pkg bootstrap -f ; pkg install -y
-bash curl cyrus-sasl git glib gmake gnutls gsed
-nettle perl5 pixman pkgconf png usbredir
+cpu: 8
+memory: 8G
+  install_script:
+- ASSUME_ALWAYS_YES=yes pkg bootstrap -f ;
+- pkg install -y bash curl cyrus-sasl git glib gmake gnutls gsed
+  nettle perl5 pixman pkgconf png usbredir
   script:
 - mkdir build
 - cd build
-- ../configure --disable-user --target-list-exclude='alpha-softmmu
-ppc64-softmmu ppc-softmmu riscv32-softmmu riscv64-softmmu s390x-softmmu
-sparc64-softmmu sparc-softmmu x86_64-softmmu i386-softmmu'
---enable-werror || { cat config.log; exit 1; }
-- gmake -j$(sysctl -n hw.ncpu)
-- gmake -j$(sysctl -n hw.ncpu) check
-
-freebsd_2nd_task:
-  freebsd_instance:
-image_family: freebsd-12-1
-cpu: 4
-memory: 4G
-  install_script: ASSUME_ALWAYS_YES=yes pkg bootstrap -f ; pkg install -y
-bash curl cyrus-sasl git glib gmake gnutls gtk3 gsed libepoxy mesa-libs
-nettle perl5 pixman pkgconf png SDL2 usbredir
-  script:
-- ./configure --enable-werror --target-list='alpha-softmmu ppc64-softmmu
-ppc-softmmu riscv32-softmmu riscv64-softmmu s390x-softmmu
-sparc64-softmmu sparc-softmmu x86_64-softmmu i386-softmmu
-sparc-bsd-user sparc64-bsd-user x86_64-bsd-user i386-bsd-user'
-|| { cat config.log; exit 1; }
+- ../configure --enable-werror || { cat config.log; exit 1; }
 - gmake -j$(sysctl -n hw.ncpu)
 - gmake -j$(sysctl -n hw.ncpu) check
 
-- 
2.28.0.windows.1




[PATCH v10 13/26] meson: remove empty else and duplicated gio deps

2020-09-15 Thread Yonggang Luo
Signed-off-by: Yonggang Luo 
Reviewed-by: Daniel P. Berrangé 
---
 meson.build | 6 --
 1 file changed, 6 deletions(-)

diff --git a/meson.build b/meson.build
index 690723b470..23cb1b8742 100644
--- a/meson.build
+++ b/meson.build
@@ -317,7 +317,6 @@ opengl = not_found
 if 'CONFIG_OPENGL' in config_host
   opengl = declare_dependency(compile_args: 
config_host['OPENGL_CFLAGS'].split(),
   link_args: config_host['OPENGL_LIBS'].split())
-else
 endif
 gtk = not_found
 if 'CONFIG_GTK' in config_host
@@ -344,11 +343,6 @@ if 'CONFIG_ICONV' in config_host
   iconv = declare_dependency(compile_args: config_host['ICONV_CFLAGS'].split(),
  link_args: config_host['ICONV_LIBS'].split())
 endif
-gio = not_found
-if 'CONFIG_GIO' in config_host
-  gio = declare_dependency(compile_args: config_host['GIO_CFLAGS'].split(),
-   link_args: config_host['GIO_LIBS'].split())
-endif
 vnc = not_found
 png = not_found
 jpeg = not_found
-- 
2.28.0.windows.1




[PATCH v10 12/26] tests: Enable crypto tests under msys2/mingw

2020-09-15 Thread Yonggang Luo
Fixes following tests on msys2/mingw
'test-crypto-tlscredsx509'
test-crypto-tlssession'
'test-io-channel-tls'

These tests are failure with:
ERROR test-crypto-tlscredsx509 - missing test plan
ERROR test-crypto-tlssession - missing test plan
ERROR test-io-channel-tls - missing test plan

Because on win32 those test case are all disabled in the header

Add qemu_socket_pair for cross platform support
Convert file system handling functions to glib
Add qemu_link function instead posix only link function.
Use send ad recv from qemu that convert Windows Socks error to errno properly.
Use g_remove instead unlink
Use g_mkdir instead mkdir

Signed-off-by: Yonggang Luo 
---
 include/qemu/osdep.h |  1 +
 include/sysemu/os-win32.h|  5 +++
 tests/crypto-tls-psk-helpers.c   |  4 +-
 tests/crypto-tls-x509-helpers.c  |  6 ++-
 tests/crypto-tls-x509-helpers.h  |  5 ++-
 tests/test-crypto-tlscredsx509.c | 47 +++-
 tests/test-crypto-tlssession.c   | 64 +++
 tests/test-io-channel-tls.c  | 49 +++-
 util/osdep.c | 16 +++
 util/oslib-win32.c   | 76 
 10 files changed, 197 insertions(+), 76 deletions(-)

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index e80fddd1e8..dd4c63e4b6 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -499,6 +499,7 @@ int qemu_mprotect_none(void *addr, size_t size);
 
 int qemu_open(const char *name, int flags, ...);
 int qemu_close(int fd);
+int qemu_link(const char *exist_path1, const char *new_path2);
 int qemu_unlink(const char *name);
 #ifndef _WIN32
 int qemu_dup(int fd);
diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
index 3ac8a53bac..8863833f67 100644
--- a/include/sysemu/os-win32.h
+++ b/include/sysemu/os-win32.h
@@ -194,4 +194,9 @@ ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, 
int flags);
 ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
struct sockaddr *addr, socklen_t *addrlen);
 
+#undef socketpair
+#define socketpair qemu_socketpair
+int qemu_socketpair(int family, int type, int protocol, int channel[2]);
+
+
 #endif
diff --git a/tests/crypto-tls-psk-helpers.c b/tests/crypto-tls-psk-helpers.c
index 11ae26368c..6f82bfceb2 100644
--- a/tests/crypto-tls-psk-helpers.c
+++ b/tests/crypto-tls-psk-helpers.c
@@ -26,6 +26,8 @@
 #include "crypto-tls-psk-helpers.h"
 #include "qemu/sockets.h"
 
+#include 
+
 #ifdef QCRYPTO_HAVE_TLS_TEST_SUPPORT
 
 void test_tls_psk_init(const char *pskfile)
@@ -44,7 +46,7 @@ void test_tls_psk_init(const char *pskfile)
 
 void test_tls_psk_cleanup(const char *pskfile)
 {
-unlink(pskfile);
+qemu_unlink(pskfile);
 }
 
 #endif /* QCRYPTO_HAVE_TLS_TEST_SUPPORT */
diff --git a/tests/crypto-tls-x509-helpers.c b/tests/crypto-tls-x509-helpers.c
index 01b3daf358..051f045657 100644
--- a/tests/crypto-tls-x509-helpers.c
+++ b/tests/crypto-tls-x509-helpers.c
@@ -23,6 +23,8 @@
 #include "crypto-tls-x509-helpers.h"
 #include "crypto/init.h"
 #include "qemu/sockets.h"
+#include 
+#include 
 
 #ifdef QCRYPTO_HAVE_TLS_TEST_SUPPORT
 
@@ -133,7 +135,7 @@ void test_tls_init(const char *keyfile)
 void test_tls_cleanup(const char *keyfile)
 {
 asn1_delete_structure(_asn1);
-unlink(keyfile);
+qemu_unlink(keyfile);
 }
 
 /*
@@ -501,7 +503,7 @@ void test_tls_discard_cert(QCryptoTLSTestCertReq *req)
 req->crt = NULL;
 
 if (getenv("QEMU_TEST_DEBUG_CERTS") == NULL) {
-unlink(req->filename);
+qemu_unlink(req->filename);
 }
 }
 
diff --git a/tests/crypto-tls-x509-helpers.h b/tests/crypto-tls-x509-helpers.h
index 08efba4e19..0856934a70 100644
--- a/tests/crypto-tls-x509-helpers.h
+++ b/tests/crypto-tls-x509-helpers.h
@@ -24,8 +24,9 @@
 #include 
 #include 
 
-#if !(defined WIN32) && \
-defined(CONFIG_TASN1)
+#include "qemu/osdep.h"
+
+#if defined(CONFIG_TASN1)
 # define QCRYPTO_HAVE_TLS_TEST_SUPPORT
 #endif
 
diff --git a/tests/test-crypto-tlscredsx509.c b/tests/test-crypto-tlscredsx509.c
index f487349c32..62d5d2defd 100644
--- a/tests/test-crypto-tlscredsx509.c
+++ b/tests/test-crypto-tlscredsx509.c
@@ -25,6 +25,9 @@
 #include "qapi/error.h"
 #include "qemu/module.h"
 
+#include 
+#include 
+
 #ifdef QCRYPTO_HAVE_TLS_TEST_SUPPORT
 
 #define WORKDIR "tests/test-crypto-tlscredsx509-work/"
@@ -77,34 +80,34 @@ static void test_tls_creds(const void *opaque)
 QCryptoTLSCreds *creds;
 
 #define CERT_DIR "tests/test-crypto-tlscredsx509-certs/"
-mkdir(CERT_DIR, 0700);
+g_mkdir_with_parents(CERT_DIR, 0700);
 
-unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT);
+qemu_unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_CA_CERT);
 if (data->isServer) {
-unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT);
-unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_KEY);
+qemu_unlink(CERT_DIR QCRYPTO_TLS_CREDS_X509_SERVER_CERT);
+qemu_unlink(CERT_DIR 

[PATCH v10 09/26] osdep: file locking functions are not available on Win32

2020-09-15 Thread Yonggang Luo
Do not declare the following locking functions on Win32:
int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive);
int qemu_unlock_fd(int fd, int64_t start, int64_t len);
int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive);
bool qemu_has_ofd_lock(void);

Signed-off-by: Yonggang Luo 
Reviewed-by: Daniel P. Berrangé 
---
 include/qemu/osdep.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 412962d91a..e80fddd1e8 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -502,11 +502,11 @@ int qemu_close(int fd);
 int qemu_unlink(const char *name);
 #ifndef _WIN32
 int qemu_dup(int fd);
-#endif
 int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive);
 int qemu_unlock_fd(int fd, int64_t start, int64_t len);
 int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive);
 bool qemu_has_ofd_lock(void);
+#endif
 
 #if defined(__HAIKU__) && defined(__i386__)
 #define FMT_pid "%ld"
-- 
2.28.0.windows.1




Re: [PATCH v2 01/10] capstone: Convert Makefile bits to meson bits

2020-09-15 Thread Paolo Bonzini
On 15/09/20 16:27, Richard Henderson wrote:
> On 9/14/20 11:27 PM, Paolo Bonzini wrote:
>> Looks good. Can you just add a "# Submodules" heading above the test?
>>
>> I would also like to remove the "yes" value (that is, the default fails if 
>> the
>> internal copy is not there) but it can be done later for all submodules.
> 
> Unless you simply plan to rename {no, yes} to {disabled, enabled}, as for the
> Feature objects, why?
> 
> That seems to be the only sensible value for --enable-foo, without the =system
> or =git specifiers.  We *should* fail if no system library nor internal copy 
> is
> present.

Yes, that was a bit concise.  I would like "auto" to take the meaning
that "yes" currently as.  Right now we have

no -> Easy :)
system -> System capstone if found, fail otherwise
internal/git -> Compile capstone if found, fail otherwise
auto -> System capstone, then internal, then disable
yes -> System capstone, then internal, then fail

I'm not sure of the usefulness of disabling a dependency because we
don't have it checked out, since we have the machinery to do the
checkout automatically.  So that would become:

no -> Easy :)
system -> System capstone if found, fail otherwise
internal/git -> Compile capstone if found, fail otherwise
auto -> System capstone, then internal, then fail

The disadvantage is that it would be different from other "auto"
symbols, which never fail.  But then those other "auto" symbols do not
have a built-in fallback, so the question is whether the combination of

1) building from a fresh git checkout
2) --disable-git-update
3) not having a system capstone/libfdt/slirp
4) not having --disable-{capstone,libfdt,slirp} on the command line

is more likely to be intentional or operator error.

Paolo




Re: couple meson issues

2020-09-15 Thread Paolo Bonzini
On 15/09/20 15:44, Andrew Jones wrote:
> Hi Paolo,
> 
> I noticed that 'make check-qtest-aarch64' no longer runs the
> arm-cpu-feature test. I simply did
> 
> diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
> index 874b5be62be2..db169a53b530 100644
> --- a/tests/qtest/meson.build
> +++ b/tests/qtest/meson.build
> @@ -146,7 +146,8 @@ qtests_aarch64 = \
>(cpu != 'arm' ? ['bios-tables-test'] : []) +   
>\
>(config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? 
> ['tpm-tis-device-test'] : []) +\
>(config_all_devices.has_key('CONFIG_TPM_TIS_SYSBUS') ? 
> ['tpm-tis-device-swtpm-test'] : []) +  \
> -  ['numa-test',
> +  ['arm-cpu-features',
> +   'numa-test',
> 'boot-serial-test',
> 'migration-test']

Yes, either that or "qtests_aarch64 = qtests_arm + ".

> to get it to run, but don't know if it should be done that way. Were you
> planning to inherit tests for aarch64 from arm or something instead?
> 
> Also, I was surprised to not see something like "KVM supported" when I did
> configure on an AArch64 machine with KVM.

That's a "TODO":

# TODO: add back KVM/HAX/HVF/WHPX/TCG
#summary_info += {'KVM support':   have_kvm}
#summary_info += {'HAX support':   have_hax}
#summary_info += {'HVF support':   have_hvf}
#summary_info += {'WHPX support':  have_whpx}
#summary_info += {'TCG support':   have_tcg}

which I had honestly completely forgotten about.

Accelerator support is per-target so it must be computed in the "foreach
target : target_dirs" loop around line 550 of meson.build.  But I might
even have the patch already, since it was meant to be temporary and
fixed as soon as that loop was added to meson in the very first series.

Paolo




[PATCH v8 6/7] block: drop bdrv_prwv

2020-09-15 Thread Vladimir Sementsov-Ogievskiy
Now that we are not maintaining boilerplate code for coroutine
wrappers, there is no more sense in keeping the extra indirection layer
of bdrv_prwv().  Let's drop it and instead generate pure bdrv_preadv()
and bdrv_pwritev().

Currently, bdrv_pwritev() and bdrv_preadv() are returning bytes on
success, auto generated functions will instead return zero, as their
_co_ prototype. Still, it's simple to make the conversion safe: the
only external user of bdrv_pwritev() is test-bdrv-drain, and it is
comfortable enough with bdrv_co_pwritev() instead. So prototypes are
moved to local block/coroutines.h. Next, the only internal use is
bdrv_pread() and bdrv_pwrite(), which are modified to return bytes on
success.

Of course, it would be great to convert bdrv_pread() and bdrv_pwrite()
to return 0 on success. But this requires audit (and probably
conversion) of all their users, let's leave it for another day
refactoring.

Signed-off-by: Vladimir Sementsov-Ogievskiy 
Reviewed-by: Eric Blake 
---
 block/coroutines.h  | 10 -
 include/block/block.h   |  2 --
 block/io.c  | 49 -
 tests/test-bdrv-drain.c |  2 +-
 4 files changed, 15 insertions(+), 48 deletions(-)

diff --git a/block/coroutines.h b/block/coroutines.h
index c62b3a2697..6c63a819c9 100644
--- a/block/coroutines.h
+++ b/block/coroutines.h
@@ -31,12 +31,12 @@ int coroutine_fn bdrv_co_check(BlockDriverState *bs,
BdrvCheckResult *res, BdrvCheckMode fix);
 int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp);
 
-int coroutine_fn
-bdrv_co_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov,
- bool is_write, BdrvRequestFlags flags);
 int generated_co_wrapper
-bdrv_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov,
-  bool is_write, BdrvRequestFlags flags);
+bdrv_preadv(BdrvChild *child, int64_t offset, unsigned int bytes,
+QEMUIOVector *qiov, BdrvRequestFlags flags);
+int generated_co_wrapper
+bdrv_pwritev(BdrvChild *child, int64_t offset, unsigned int bytes,
+ QEMUIOVector *qiov, BdrvRequestFlags flags);
 
 int coroutine_fn
 bdrv_co_common_block_status_above(BlockDriverState *bs,
diff --git a/include/block/block.h b/include/block/block.h
index d8fb02fa2a..b8b4c177de 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -383,9 +383,7 @@ int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset,
int bytes, BdrvRequestFlags flags);
 int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags);
 int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int bytes);
-int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov);
 int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, int bytes);
-int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov);
 int bdrv_pwrite_sync(BdrvChild *child, int64_t offset,
  const void *buf, int count);
 /*
diff --git a/block/io.c b/block/io.c
index 5270d68d72..68d7d9cf80 100644
--- a/block/io.c
+++ b/block/io.c
@@ -890,23 +890,11 @@ static int bdrv_check_byte_request(BlockDriverState *bs, 
int64_t offset,
 return 0;
 }
 
-int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset,
-  QEMUIOVector *qiov, bool is_write,
-  BdrvRequestFlags flags)
-{
-if (is_write) {
-return bdrv_co_pwritev(child, offset, qiov->size, qiov, flags);
-} else {
-return bdrv_co_preadv(child, offset, qiov->size, qiov, flags);
-}
-}
-
 int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset,
int bytes, BdrvRequestFlags flags)
 {
-QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, NULL, bytes);
-
-return bdrv_prwv(child, offset, , true, BDRV_REQ_ZERO_WRITE | flags);
+return bdrv_pwritev(child, offset, bytes, NULL,
+BDRV_REQ_ZERO_WRITE | flags);
 }
 
 /*
@@ -950,41 +938,19 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags 
flags)
 }
 }
 
-/* return < 0 if error. See bdrv_pwrite() for the return codes */
-int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov)
-{
-int ret;
-
-ret = bdrv_prwv(child, offset, qiov, false, 0);
-if (ret < 0) {
-return ret;
-}
-
-return qiov->size;
-}
-
 /* See bdrv_pwrite() for the return codes */
 int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int bytes)
 {
+int ret;
 QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
 
 if (bytes < 0) {
 return -EINVAL;
 }
 
-return bdrv_preadv(child, offset, );
-}
-
-int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov)
-{
-int ret;
+ret = bdrv_preadv(child, offset, bytes, ,  0);
 
-ret = bdrv_prwv(child, offset, qiov, true, 0);
-if (ret < 0) {
-return ret;
-}
-
-return qiov->size;
+return ret < 0 ? ret : bytes;
 }
 
 /* Return no. of bytes 

[PATCH v8 0/7] coroutines: generate wrapper code

2020-09-15 Thread Vladimir Sementsov-Ogievskiy
Hi all!

The aim of the series is to reduce code-duplication and writing
parameters structure-packing by hand around coroutine function wrappers.

Benefits:
 - no code duplication
 - less indirection

v8:
04: - rebase on meson build
- script interface is changed to satisfy meson custom_target
- rename script s/coroutine-wrapper.py/block-coroutine-wrapper.py/
- add docs/devel/block-coroutine-wrapper.rst

Vladimir Sementsov-Ogievskiy (7):
  block: return error-code from bdrv_invalidate_cache
  block/io: refactor coroutine wrappers
  block: declare some coroutine functions in block/coroutines.h
  scripts: add block-coroutine-wrapper.py
  block: generate coroutine-wrapper code
  block: drop bdrv_prwv
  block/io: refactor save/load vmstate

 docs/devel/block-coroutine-wrapper.rst |  54 
 block/block-gen.h  |  49 
 block/coroutines.h |  65 +
 include/block/block.h  |  34 ++-
 block.c|  97 ++-
 block/io.c | 336 -
 tests/test-bdrv-drain.c|   2 +-
 block/meson.build  |   8 +
 scripts/block-coroutine-wrapper.py | 187 ++
 9 files changed, 451 insertions(+), 381 deletions(-)
 create mode 100644 docs/devel/block-coroutine-wrapper.rst
 create mode 100644 block/block-gen.h
 create mode 100644 block/coroutines.h
 create mode 100755 scripts/block-coroutine-wrapper.py

-- 
2.21.3




[PATCH v8 7/7] block/io: refactor save/load vmstate

2020-09-15 Thread Vladimir Sementsov-Ogievskiy
Like for read/write in a previous commit, drop extra indirection layer,
generate directly bdrv_readv_vmstate() and bdrv_writev_vmstate().

Signed-off-by: Vladimir Sementsov-Ogievskiy 
Reviewed-by: Eric Blake 
---
 block/coroutines.h| 10 +++
 include/block/block.h |  6 ++--
 block/io.c| 67 ++-
 3 files changed, 42 insertions(+), 41 deletions(-)

diff --git a/block/coroutines.h b/block/coroutines.h
index 6c63a819c9..f69179f5ef 100644
--- a/block/coroutines.h
+++ b/block/coroutines.h
@@ -57,11 +57,9 @@ bdrv_common_block_status_above(BlockDriverState *bs,
int64_t *map,
BlockDriverState **file);
 
-int coroutine_fn
-bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos,
-   bool is_read);
-int generated_co_wrapper
-bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos,
-bool is_read);
+int coroutine_fn bdrv_co_readv_vmstate(BlockDriverState *bs,
+   QEMUIOVector *qiov, int64_t pos);
+int coroutine_fn bdrv_co_writev_vmstate(BlockDriverState *bs,
+QEMUIOVector *qiov, int64_t pos);
 
 #endif /* BLOCK_COROUTINES_INT_H */
diff --git a/include/block/block.h b/include/block/block.h
index b8b4c177de..6cd789724b 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -572,8 +572,10 @@ int path_has_protocol(const char *path);
 int path_is_absolute(const char *path);
 char *path_combine(const char *base_path, const char *filename);
 
-int bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos);
-int bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos);
+int generated_co_wrapper
+bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos);
+int generated_co_wrapper
+bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos);
 int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,
   int64_t pos, int size);
 
diff --git a/block/io.c b/block/io.c
index 68d7d9cf80..84f82bc069 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2491,66 +2491,67 @@ int bdrv_is_allocated_above(BlockDriverState *top,
 }
 
 int coroutine_fn
-bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos,
-   bool is_read)
+bdrv_co_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos)
 {
 BlockDriver *drv = bs->drv;
 int ret = -ENOTSUP;
 
+if (!drv) {
+return -ENOMEDIUM;
+}
+
 bdrv_inc_in_flight(bs);
 
-if (!drv) {
-ret = -ENOMEDIUM;
-} else if (drv->bdrv_load_vmstate) {
-if (is_read) {
-ret = drv->bdrv_load_vmstate(bs, qiov, pos);
-} else {
-ret = drv->bdrv_save_vmstate(bs, qiov, pos);
-}
+if (drv->bdrv_load_vmstate) {
+ret = drv->bdrv_load_vmstate(bs, qiov, pos);
 } else if (bs->file) {
-ret = bdrv_co_rw_vmstate(bs->file->bs, qiov, pos, is_read);
+ret = bdrv_co_readv_vmstate(bs->file->bs, qiov, pos);
 }
 
 bdrv_dec_in_flight(bs);
+
 return ret;
 }
 
-int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,
-  int64_t pos, int size)
+int coroutine_fn
+bdrv_co_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos)
 {
-QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, size);
-int ret;
+BlockDriver *drv = bs->drv;
+int ret = -ENOTSUP;
 
-ret = bdrv_writev_vmstate(bs, , pos);
-if (ret < 0) {
-return ret;
+if (!drv) {
+return -ENOMEDIUM;
 }
 
-return size;
-}
+bdrv_inc_in_flight(bs);
 
-int bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos)
-{
-return bdrv_rw_vmstate(bs, qiov, pos, false);
+if (drv->bdrv_load_vmstate) {
+ret = drv->bdrv_save_vmstate(bs, qiov, pos);
+} else if (bs->file) {
+ret = bdrv_co_writev_vmstate(bs->file->bs, qiov, pos);
+}
+
+bdrv_dec_in_flight(bs);
+
+return ret;
 }
 
-int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf,
+int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,
   int64_t pos, int size)
 {
 QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, size);
-int ret;
-
-ret = bdrv_readv_vmstate(bs, , pos);
-if (ret < 0) {
-return ret;
-}
+int ret = bdrv_writev_vmstate(bs, , pos);
 
-return size;
+return ret < 0 ? ret : size;
 }
 
-int bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos)
+int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf,
+  int64_t pos, int size)
 {
-return bdrv_rw_vmstate(bs, qiov, pos, true);
+QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, size);
+int ret = bdrv_readv_vmstate(bs, , pos);
+
+return ret < 0 ? ret : size;
 }
 
 

[PATCH v8 4/7] scripts: add block-coroutine-wrapper.py

2020-09-15 Thread Vladimir Sementsov-Ogievskiy
We have a very frequent pattern of creating coroutine from function
with several arguments:

  - create structure to pack parameters
  - create _entry function to call original function taking parameters
from struct
  - do different magic to handle completion: set ret to NOT_DONE or
EINPROGRESS or use separate bool field
  - fill the struct and create coroutine from _entry function and this
struct as a parameter
  - do coroutine enter and BDRV_POLL_WHILE loop

Let's reduce code duplication by generating coroutine wrappers.

This patch adds scripts/block-coroutine-wrapper.py together with some
friends, which will generate functions with declared prototypes marked
by 'generated_co_wrapper' specifier.

The usage of new code generation is as follows:

1. define somewhere

int coroutine_fn bdrv_co_NAME(...) {...}

   function

2. declare in some header file

int generated_co_wrapper bdrv_NAME(...);

   function with same list of parameters. (you'll need to include
   "block/generated-co-wrapper.h" to get the specifier)

3. both declarations should be available through block/coroutines.h
   header.

4. add header with generated_co_wrapper declaration into
   COROUTINE_HEADERS list in Makefile

Still, no function is now marked, this work is for the following
commit.

Signed-off-by: Vladimir Sementsov-Ogievskiy 
---
 docs/devel/block-coroutine-wrapper.rst |  54 +++
 block/block-gen.h  |  49 +++
 include/block/block.h  |  10 ++
 block/meson.build  |   8 ++
 scripts/block-coroutine-wrapper.py | 187 +
 5 files changed, 308 insertions(+)
 create mode 100644 docs/devel/block-coroutine-wrapper.rst
 create mode 100644 block/block-gen.h
 create mode 100755 scripts/block-coroutine-wrapper.py

diff --git a/docs/devel/block-coroutine-wrapper.rst 
b/docs/devel/block-coroutine-wrapper.rst
new file mode 100644
index 00..f7050bbc8f
--- /dev/null
+++ b/docs/devel/block-coroutine-wrapper.rst
@@ -0,0 +1,54 @@
+===
+block-coroutine-wrapper
+===
+
+A lot of functions in QEMJ block layer (see ``block/*``) can by called
+only in coroutine context. Such functions are normally marked by
+coroutine_fn specifier. Still, sometimes we need to call them from
+non-coroutine context, for this we need to start a coroutine, run the
+needed function from it and wait for coroutine finish in
+BDRV_POLL_WHILE() loop. To run a coroutine we need a function with one
+void* argument. So for each coroutine_fn function, which needs
+non-coroutine interface, we should define a structure to pack the
+parameters, define a separate function to unpack the parameters and
+call the original function and finally define a new interface function
+with same list of arguments as original one, which will pack the
+parameters into a struct, create a coroutine, run it and wait in
+BDRV_POLL_WHILE() loop. It's boring to create such wrappers by hand, so
+we have a script to generate them.
+
+Usage
+=
+
+Assume we have defined ``coroutine_fn`` function
+``bdrv_co_foo()`` and need a non-coroutine interface for it,
+called ``bdrv_foo()``. In this case the script can help. To
+trigger the generation:
+
+1. You need ``bdrv_foo`` declaration somewhere (for example in
+   ``block/coroutines.h`` with ``generated_co_wrapper`` mark,
+   like this:
+
+.. code-block:: c
+
+int generated_co_wrapper bdrv_foor();
+
+2. You need to feed this declaration to block-coroutine-wrapper script.
+   For this, add .h (or .c) file with the declaration to
+   ``input: files(...)`` list of ``block_gen_c`` target declaration in
+   ``block/meson.build``
+
+You are done. On build, coroutine wrappers will be generated in
+``/block/block-gen.c``.
+
+Links
+=
+
+1. The script location is ``scripts/block-coroutine-wrapper.py``.
+
+2. Generic place for private ``generated_co_wrapper`` declarations is
+   ``block/coroutines.h``, for public declarations:
+   ``include/block/block.h``
+
+3. The core API of generated coroutine wrappers is placed in
+   (not generated) ``block/block-gen.h``
diff --git a/block/block-gen.h b/block/block-gen.h
new file mode 100644
index 00..f80cf4897d
--- /dev/null
+++ b/block/block-gen.h
@@ -0,0 +1,49 @@
+/*
+ * Block coroutine wrapping core, used by auto-generated block/block-gen.c
+ *
+ * Copyright (c) 2003 Fabrice Bellard
+ * Copyright (c) 2020 Virtuozzo International GmbH
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright 

[PATCH v8 2/7] block/io: refactor coroutine wrappers

2020-09-15 Thread Vladimir Sementsov-Ogievskiy
Most of our coroutine wrappers already follow this convention:

We have 'coroutine_fn bdrv_co_()' as
the core function, and a wrapper 'bdrv_()' which does parameters packing and call bdrv_run_co().

The only outsiders are the bdrv_prwv_co and
bdrv_common_block_status_above wrappers. Let's refactor them to behave
as the others, it simplifies further conversion of coroutine wrappers.

This patch adds indirection layer, but it will be compensated by
further commit, which will drop bdrv_co_prwv together with is_write
logic, to keep read and write path separate.

Signed-off-by: Vladimir Sementsov-Ogievskiy 
Reviewed-by: Eric Blake 
---
 block/io.c | 60 +-
 1 file changed, 32 insertions(+), 28 deletions(-)

diff --git a/block/io.c b/block/io.c
index ad3a51ed53..2e2c89ce31 100644
--- a/block/io.c
+++ b/block/io.c
@@ -933,27 +933,31 @@ typedef struct RwCo {
 BdrvRequestFlags flags;
 } RwCo;
 
+static int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset,
+ QEMUIOVector *qiov, bool is_write,
+ BdrvRequestFlags flags)
+{
+if (is_write) {
+return bdrv_co_pwritev(child, offset, qiov->size, qiov, flags);
+} else {
+return bdrv_co_preadv(child, offset, qiov->size, qiov, flags);
+}
+}
+
 static int coroutine_fn bdrv_rw_co_entry(void *opaque)
 {
 RwCo *rwco = opaque;
 
-if (!rwco->is_write) {
-return bdrv_co_preadv(rwco->child, rwco->offset,
-  rwco->qiov->size, rwco->qiov,
-  rwco->flags);
-} else {
-return bdrv_co_pwritev(rwco->child, rwco->offset,
-   rwco->qiov->size, rwco->qiov,
-   rwco->flags);
-}
+return bdrv_co_prwv(rwco->child, rwco->offset, rwco->qiov,
+rwco->is_write, rwco->flags);
 }
 
 /*
  * Process a vectored synchronous request using coroutines
  */
-static int bdrv_prwv_co(BdrvChild *child, int64_t offset,
-QEMUIOVector *qiov, bool is_write,
-BdrvRequestFlags flags)
+static int bdrv_prwv(BdrvChild *child, int64_t offset,
+ QEMUIOVector *qiov, bool is_write,
+ BdrvRequestFlags flags)
 {
 RwCo rwco = {
 .child = child,
@@ -971,8 +975,7 @@ int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset,
 {
 QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, NULL, bytes);
 
-return bdrv_prwv_co(child, offset, , true,
-BDRV_REQ_ZERO_WRITE | flags);
+return bdrv_prwv(child, offset, , true, BDRV_REQ_ZERO_WRITE | flags);
 }
 
 /*
@@ -1021,7 +1024,7 @@ int bdrv_preadv(BdrvChild *child, int64_t offset, 
QEMUIOVector *qiov)
 {
 int ret;
 
-ret = bdrv_prwv_co(child, offset, qiov, false, 0);
+ret = bdrv_prwv(child, offset, qiov, false, 0);
 if (ret < 0) {
 return ret;
 }
@@ -1045,7 +1048,7 @@ int bdrv_pwritev(BdrvChild *child, int64_t offset, 
QEMUIOVector *qiov)
 {
 int ret;
 
-ret = bdrv_prwv_co(child, offset, qiov, true, 0);
+ret = bdrv_prwv(child, offset, qiov, true, 0);
 if (ret < 0) {
 return ret;
 }
@@ -2465,14 +2468,15 @@ early_out:
 return ret;
 }
 
-static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs,
-   BlockDriverState *base,
-   bool want_zero,
-   int64_t offset,
-   int64_t bytes,
-   int64_t *pnum,
-   int64_t *map,
-   BlockDriverState **file)
+static int coroutine_fn
+bdrv_co_common_block_status_above(BlockDriverState *bs,
+  BlockDriverState *base,
+  bool want_zero,
+  int64_t offset,
+  int64_t bytes,
+  int64_t *pnum,
+  int64_t *map,
+  BlockDriverState **file)
 {
 BlockDriverState *p;
 int ret = 0;
@@ -2510,10 +2514,10 @@ static int coroutine_fn 
bdrv_block_status_above_co_entry(void *opaque)
 {
 BdrvCoBlockStatusData *data = opaque;
 
-return bdrv_co_block_status_above(data->bs, data->base,
-  data->want_zero,
-  data->offset, data->bytes,
-  data->pnum, data->map, data->file);
+return bdrv_co_common_block_status_above(data->bs, data->base,
+ data->want_zero,
+ data->offset, data->bytes,
+

[PATCH v8 5/7] block: generate coroutine-wrapper code

2020-09-15 Thread Vladimir Sementsov-Ogievskiy
Use code generation implemented in previous commit to generated
coroutine wrappers in block.c and block/io.c

Signed-off-by: Vladimir Sementsov-Ogievskiy 
Reviewed-by: Eric Blake 
---
 block/coroutines.h|   6 +-
 include/block/block.h |  16 ++--
 block.c   |  73 ---
 block/io.c| 212 --
 4 files changed, 13 insertions(+), 294 deletions(-)

diff --git a/block/coroutines.h b/block/coroutines.h
index 9ce1730a09..c62b3a2697 100644
--- a/block/coroutines.h
+++ b/block/coroutines.h
@@ -34,7 +34,7 @@ int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState 
*bs, Error **errp);
 int coroutine_fn
 bdrv_co_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov,
  bool is_write, BdrvRequestFlags flags);
-int
+int generated_co_wrapper
 bdrv_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov,
   bool is_write, BdrvRequestFlags flags);
 
@@ -47,7 +47,7 @@ bdrv_co_common_block_status_above(BlockDriverState *bs,
   int64_t *pnum,
   int64_t *map,
   BlockDriverState **file);
-int
+int generated_co_wrapper
 bdrv_common_block_status_above(BlockDriverState *bs,
BlockDriverState *base,
bool want_zero,
@@ -60,7 +60,7 @@ bdrv_common_block_status_above(BlockDriverState *bs,
 int coroutine_fn
 bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos,
bool is_read);
-int
+int generated_co_wrapper
 bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos,
 bool is_read);
 
diff --git a/include/block/block.h b/include/block/block.h
index a0655b84d6..d8fb02fa2a 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -403,8 +403,9 @@ void bdrv_refresh_filename(BlockDriverState *bs);
 int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
   PreallocMode prealloc, BdrvRequestFlags 
flags,
   Error **errp);
-int bdrv_truncate(BdrvChild *child, int64_t offset, bool exact,
-  PreallocMode prealloc, BdrvRequestFlags flags, Error **errp);
+int generated_co_wrapper
+bdrv_truncate(BdrvChild *child, int64_t offset, bool exact,
+  PreallocMode prealloc, BdrvRequestFlags flags, Error **errp);
 
 int64_t bdrv_nb_sectors(BlockDriverState *bs);
 int64_t bdrv_getlength(BlockDriverState *bs);
@@ -446,7 +447,8 @@ typedef enum {
 BDRV_FIX_ERRORS   = 2,
 } BdrvCheckMode;
 
-int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix);
+int generated_co_wrapper bdrv_check(BlockDriverState *bs, BdrvCheckResult *res,
+BdrvCheckMode fix);
 
 /* The units of offset and total_work_size may be chosen arbitrarily by the
  * block driver; total_work_size may change during the course of the amendment
@@ -470,12 +472,13 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb);
 int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf);
 
 /* Invalidate any cached metadata used by image formats */
-int bdrv_invalidate_cache(BlockDriverState *bs, Error **errp);
+int generated_co_wrapper bdrv_invalidate_cache(BlockDriverState *bs,
+   Error **errp);
 void bdrv_invalidate_cache_all(Error **errp);
 int bdrv_inactivate_all(void);
 
 /* Ensure contents are flushed to disk.  */
-int bdrv_flush(BlockDriverState *bs);
+int generated_co_wrapper bdrv_flush(BlockDriverState *bs);
 int coroutine_fn bdrv_co_flush(BlockDriverState *bs);
 int bdrv_flush_all(void);
 void bdrv_close_all(void);
@@ -490,7 +493,8 @@ void bdrv_drain_all(void);
 AIO_WAIT_WHILE(bdrv_get_aio_context(bs_),  \
cond); })
 
-int bdrv_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes);
+int generated_co_wrapper bdrv_pdiscard(BdrvChild *child, int64_t offset,
+   int64_t bytes);
 int bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes);
 int bdrv_has_zero_init_1(BlockDriverState *bs);
 int bdrv_has_zero_init(BlockDriverState *bs);
diff --git a/block.c b/block.c
index ec5a8cbd7b..d49d591917 100644
--- a/block.c
+++ b/block.c
@@ -4655,43 +4655,6 @@ int coroutine_fn bdrv_co_check(BlockDriverState *bs,
 return bs->drv->bdrv_co_check(bs, res, fix);
 }
 
-typedef struct CheckCo {
-BlockDriverState *bs;
-BdrvCheckResult *res;
-BdrvCheckMode fix;
-int ret;
-} CheckCo;
-
-static void coroutine_fn bdrv_check_co_entry(void *opaque)
-{
-CheckCo *cco = opaque;
-cco->ret = bdrv_co_check(cco->bs, cco->res, cco->fix);
-aio_wait_kick();
-}
-
-int bdrv_check(BlockDriverState *bs,
-   BdrvCheckResult *res, BdrvCheckMode fix)
-{
-Coroutine *co;
-CheckCo cco = {
-.bs = bs,
-.res = res,
-.ret = -EINPROGRESS,
-.fix 

[PATCH v8 1/7] block: return error-code from bdrv_invalidate_cache

2020-09-15 Thread Vladimir Sementsov-Ogievskiy
This is the only coroutine wrapper from block.c and block/io.c which
doesn't return a value, so let's convert it to the common behavior, to
simplify moving to generated coroutine wrappers in a further commit.

Also, bdrv_invalidate_cache is a void function, returning error only
through **errp parameter, which is considered to be bad practice, as
it forces callers to define and propagate local_err variable, so
conversion is good anyway.

This patch leaves the conversion of .bdrv_co_invalidate_cache() driver
callbacks and bdrv_invalidate_cache_all() for another day.

Signed-off-by: Vladimir Sementsov-Ogievskiy 
Reviewed-by: Eric Blake 
---
 include/block/block.h |  2 +-
 block.c   | 32 ++--
 2 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/include/block/block.h b/include/block/block.h
index 6e36154061..8aef849a75 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -460,7 +460,7 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb);
 int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf);
 
 /* Invalidate any cached metadata used by image formats */
-void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp);
+int bdrv_invalidate_cache(BlockDriverState *bs, Error **errp);
 void bdrv_invalidate_cache_all(Error **errp);
 int bdrv_inactivate_all(void);
 
diff --git a/block.c b/block.c
index 2ba76b2c36..ccfe1d851b 100644
--- a/block.c
+++ b/block.c
@@ -5649,8 +5649,8 @@ void bdrv_init_with_whitelist(void)
 bdrv_init();
 }
 
-static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,
-  Error **errp)
+static int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,
+ Error **errp)
 {
 BdrvChild *child, *parent;
 uint64_t perm, shared_perm;
@@ -5659,14 +5659,14 @@ static void coroutine_fn 
bdrv_co_invalidate_cache(BlockDriverState *bs,
 BdrvDirtyBitmap *bm;
 
 if (!bs->drv)  {
-return;
+return -ENOMEDIUM;
 }
 
 QLIST_FOREACH(child, >children, next) {
 bdrv_co_invalidate_cache(child->bs, _err);
 if (local_err) {
 error_propagate(errp, local_err);
-return;
+return -EINVAL;
 }
 }
 
@@ -5689,7 +5689,7 @@ static void coroutine_fn 
bdrv_co_invalidate_cache(BlockDriverState *bs,
 ret = bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, NULL, errp);
 if (ret < 0) {
 bs->open_flags |= BDRV_O_INACTIVE;
-return;
+return ret;
 }
 bdrv_set_perm(bs, perm, shared_perm);
 
@@ -5698,7 +5698,7 @@ static void coroutine_fn 
bdrv_co_invalidate_cache(BlockDriverState *bs,
 if (local_err) {
 bs->open_flags |= BDRV_O_INACTIVE;
 error_propagate(errp, local_err);
-return;
+return -EINVAL;
 }
 }
 
@@ -5710,7 +5710,7 @@ static void coroutine_fn 
bdrv_co_invalidate_cache(BlockDriverState *bs,
 if (ret < 0) {
 bs->open_flags |= BDRV_O_INACTIVE;
 error_setg_errno(errp, -ret, "Could not refresh total sector 
count");
-return;
+return ret;
 }
 }
 
@@ -5720,27 +5720,30 @@ static void coroutine_fn 
bdrv_co_invalidate_cache(BlockDriverState *bs,
 if (local_err) {
 bs->open_flags |= BDRV_O_INACTIVE;
 error_propagate(errp, local_err);
-return;
+return -EINVAL;
 }
 }
 }
+
+return 0;
 }
 
 typedef struct InvalidateCacheCo {
 BlockDriverState *bs;
 Error **errp;
 bool done;
+int ret;
 } InvalidateCacheCo;
 
 static void coroutine_fn bdrv_invalidate_cache_co_entry(void *opaque)
 {
 InvalidateCacheCo *ico = opaque;
-bdrv_co_invalidate_cache(ico->bs, ico->errp);
+ico->ret = bdrv_co_invalidate_cache(ico->bs, ico->errp);
 ico->done = true;
 aio_wait_kick();
 }
 
-void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
+int bdrv_invalidate_cache(BlockDriverState *bs, Error **errp)
 {
 Coroutine *co;
 InvalidateCacheCo ico = {
@@ -5757,22 +5760,23 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error 
**errp)
 bdrv_coroutine_enter(bs, co);
 BDRV_POLL_WHILE(bs, !ico.done);
 }
+
+return ico.ret;
 }
 
 void bdrv_invalidate_cache_all(Error **errp)
 {
 BlockDriverState *bs;
-Error *local_err = NULL;
 BdrvNextIterator it;
 
 for (bs = bdrv_first(); bs; bs = bdrv_next()) {
 AioContext *aio_context = bdrv_get_aio_context(bs);
+int ret;
 
 aio_context_acquire(aio_context);
-bdrv_invalidate_cache(bs, _err);
+ret = bdrv_invalidate_cache(bs, errp);
 aio_context_release(aio_context);
-if (local_err) {
-error_propagate(errp, local_err);
+if (ret < 0) {
 bdrv_next_cleanup();
   

[PATCH v8 3/7] block: declare some coroutine functions in block/coroutines.h

2020-09-15 Thread Vladimir Sementsov-Ogievskiy
We are going to keep coroutine-wrappers code (structure-packing
parameters, BDRV_POLL wrapper functions) in separate auto-generated
files. So, we'll need a header with declaration of original _co_
functions, for those which are static now. As well, we'll need
declarations for wrapper functions. Do these declarations now, as a
preparation step.

Signed-off-by: Vladimir Sementsov-Ogievskiy 
Reviewed-by: Eric Blake 
---
 block/coroutines.h | 67 ++
 block.c|  8 +++---
 block/io.c | 34 +++
 3 files changed, 88 insertions(+), 21 deletions(-)
 create mode 100644 block/coroutines.h

diff --git a/block/coroutines.h b/block/coroutines.h
new file mode 100644
index 00..9ce1730a09
--- /dev/null
+++ b/block/coroutines.h
@@ -0,0 +1,67 @@
+/*
+ * Block layer I/O functions
+ *
+ * Copyright (c) 2003 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef BLOCK_COROUTINES_INT_H
+#define BLOCK_COROUTINES_INT_H
+
+#include "block/block_int.h"
+
+int coroutine_fn bdrv_co_check(BlockDriverState *bs,
+   BdrvCheckResult *res, BdrvCheckMode fix);
+int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp);
+
+int coroutine_fn
+bdrv_co_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov,
+ bool is_write, BdrvRequestFlags flags);
+int
+bdrv_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov,
+  bool is_write, BdrvRequestFlags flags);
+
+int coroutine_fn
+bdrv_co_common_block_status_above(BlockDriverState *bs,
+  BlockDriverState *base,
+  bool want_zero,
+  int64_t offset,
+  int64_t bytes,
+  int64_t *pnum,
+  int64_t *map,
+  BlockDriverState **file);
+int
+bdrv_common_block_status_above(BlockDriverState *bs,
+   BlockDriverState *base,
+   bool want_zero,
+   int64_t offset,
+   int64_t bytes,
+   int64_t *pnum,
+   int64_t *map,
+   BlockDriverState **file);
+
+int coroutine_fn
+bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos,
+   bool is_read);
+int
+bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos,
+bool is_read);
+
+#endif /* BLOCK_COROUTINES_INT_H */
diff --git a/block.c b/block.c
index ccfe1d851b..ec5a8cbd7b 100644
--- a/block.c
+++ b/block.c
@@ -48,6 +48,7 @@
 #include "qemu/timer.h"
 #include "qemu/cutils.h"
 #include "qemu/id.h"
+#include "block/coroutines.h"
 
 #ifdef CONFIG_BSD
 #include 
@@ -4640,8 +4641,8 @@ static void bdrv_delete(BlockDriverState *bs)
  * free of errors) or -errno when an internal error occurred. The results of 
the
  * check are stored in res.
  */
-static int coroutine_fn bdrv_co_check(BlockDriverState *bs,
-  BdrvCheckResult *res, BdrvCheckMode fix)
+int coroutine_fn bdrv_co_check(BlockDriverState *bs,
+   BdrvCheckResult *res, BdrvCheckMode fix)
 {
 if (bs->drv == NULL) {
 return -ENOMEDIUM;
@@ -5649,8 +5650,7 @@ void bdrv_init_with_whitelist(void)
 bdrv_init();
 }
 
-static int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs,
- Error **errp)
+int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp)
 {
 BdrvChild *child, *parent;
 uint64_t perm, shared_perm;
diff --git a/block/io.c b/block/io.c
index 2e2c89ce31..676c932caf 100644
--- a/block/io.c
+++ b/block/io.c
@@ -29,6 +29,7 @@
 #include "block/blockjob.h"
 #include 

Re: [PATCH 7/9] tests/performance: Add nightly tests

2020-09-15 Thread Aleksandar Markovic
On Wednesday, September 2, 2020, Alex Bennée  wrote:

>
> Ahmed Karaman  writes:
>
> > A nightly performance testing system to monitor any change in QEMU
> > performance across seventeen different targets.
> >
> > The system includes eight different benchmarks to provide a variety
> > of testing workloads.
> >
> > dijkstra_double:
> > Find the shortest path between the source node and all other nodes
> > using Dijkstra’s algorithm. The graph contains n nodes where all nxn
> > distances are double values. The value of n can be specified using
> > the -n flag. The default value is 2000.
> >
> > dijkstra_int32:
> > Find the shortest path between the source node and all other nodes
> > using Dijkstra’s algorithm. The graph contains n nodes where all nxn
> > distances are int32 values. The value of n can be specified using
> > the -n flag. The default value is 2000.
> >
> > matmult_double:
> > Standard matrix multiplication of an n*n matrix of randomly generated
> > double numbers from 0 to 100. The value of n is passed as an argument
> > with the -n flag. The default value is 200.
> >
> > matmult_int32:
> > Standard matrix multiplication of an n*n matrix of randomly generated
> > integer numbers from 0 to 100. The value of n is passed as an
> > argument with the -n flag. The default value is 200.
> >
> > qsort_double:
> > Quick sort of an array of n randomly generated double numbers from 0
> > to 1000. The value of n is passed as an argument with the -n flag.
> > The default value is 30.
> >
> > qsort_int32:
> > Quick sort of an array of n randomly generated integer numbers from 0
> > to 5000. The value of n is passed as an argument with the -n
> > flag.The default value is 30.
> >
> > qsort_string:
> > Quick sort of an array of 1 randomly generated strings of size 8
> > (including null terminating character). The sort process is repeated
> > n number of times. The value of n is passed as an argument with the
> > -n flag. The default value is 20.
> >
> > search_string:
> > Search for the occurrence of a small string in a much larger random
> > string (“needle in a hay”). The search process is repeated n number
> > of times and each time, a different large random string (“hay”) is
> > generated. The value of n can be specified using the -n flag. The
> > default value is 20.
> >
> > Syntax:
> > nightly_tests_core.py [-h] [-r REF]
> > Optional arguments:
> > -h, --helpShow this help message and exit
> > -r REF, --reference REF
> > Reference QEMU version - Default is v5.1.0
> > Example of usage:
> > nightly_tests_core.py -r v5.1.0 2>log.txt
> >
> > The following report includes detailed setup and execution details
> > of the system:
> > https://ahmedkrmn.github.io/TCG-Continuous-Benchmarking/
> QEMU-Nightly-Performance-Tests/
> >
> > Signed-off-by: Ahmed Karaman 
> > ---
> >  tests/performance/nightly-tests/README.md | 243 +
> >  .../source/dijkstra_double/dijkstra_double.c  | 194 
> >  .../source/dijkstra_int32/dijkstra_int32.c| 192 
> >  .../source/matmult_double/matmult_double.c| 123 +++
> >  .../source/matmult_int32/matmult_int32.c  | 121 +++
> >  .../source/qsort_double/qsort_double.c| 104 ++
> >  .../source/qsort_int32/qsort_int32.c  | 103 ++
> >  .../source/qsort_string/qsort_string.c| 122 +++
> >  .../source/search_string/search_string.c  | 110 +++
> >  .../scripts/nightly_tests_core.py | 920 ++
> >  .../scripts/run_nightly_tests.py  | 135 +++
> >  .../nightly-tests/scripts/send_email.py   |  56 ++
> >  12 files changed, 2423 insertions(+)
> >  create mode 100644 tests/performance/nightly-tests/README.md
> >  create mode 100644 tests/performance/nightly-tests/benchmarks/source/
> dijkstra_double/dijkstra_double.c
> >  create mode 100644 tests/performance/nightly-tests/benchmarks/source/
> dijkstra_int32/dijkstra_int32.c
> >  create mode 100644 tests/performance/nightly-tests/benchmarks/source/
> matmult_double/matmult_double.c
> >  create mode 100644 tests/performance/nightly-tests/benchmarks/source/
> matmult_int32/matmult_int32.c
> >  create mode 100644 tests/performance/nightly-
> tests/benchmarks/source/qsort_double/qsort_double.c
> >  create mode 100644 tests/performance/nightly-
> tests/benchmarks/source/qsort_int32/qsort_int32.c
> >  create mode 100644 tests/performance/nightly-
> tests/benchmarks/source/qsort_string/qsort_string.c
> >  create mode 100644
> > tests/performance/nightly-tests/benchmarks/source/
> search_string/search_string.c
>
> Perhaps we could compress these paths down to:
>
>   tests/tcg/benchmarks/foo.c
>   tests/tcg/benchmarks/bar.c
>
> and then we can also ensure they are built using the existing TCG tests
> cross compile framework.
>
>
Hi,

May I just bring some alternative views on this topic of
benchmarks/multiple cross-compiling/nightly tests?

Having a known source code of any benchmark 

Re: [PATCH] guest agent: Fixes for windows guest agent building on msys2/mingw

2020-09-15 Thread Philippe Mathieu-Daudé
On 9/15/20 6:33 PM, Yonggang Luo wrote:
> error message:
> "cc" "-Iqga/qemu-ga.exe.p" "-Iqga" "-I../qga" "-I." "-Iqapi" "-Itrace" "-Iui" 
> "-Iui/shader" "-IC:/CI-Tools/msys64/mingw64/include" 
> "-IC:/CI-Tools/msys64/mingw64/include/glib-2.0" 
> "-IC:/CI-Tools/msys64/mingw64/lib/glib-2.0/include" 
> "-fdiagnostics-color=auto" "-pipe" "-Wall" "-Winvalid-pch" "-Werror" 
> "-std=gnu99" "-g" "-m64" "-mcx16" "-D_GNU_SOURCE" "-D_FILE_OFFSET_BITS=64" 
> "-D_LARGEFILE_SOURCE" "-Wstrict-prototypes" "-Wredundant-decls" "-Wundef" 
> "-Wwrite-strings" "-Wmissing-prototypes" "-fno-strict-aliasing" "-fno-common" 
> "-fwrapv" "-Wold-style-declaration" "-Wold-style-definition" "-Wtype-limits" 
> "-Wformat-security" "-Wformat-y2k" "-Winit-self" "-Wignored-qualifiers" 
> "-Wempty-body" "-Wnested-externs" "-Wendif-labels" "-Wexpansion-to-defined" 
> "-Wno-missing-include-dirs" "-Wno-shift-negative-value" "-Wno-psabi" 
> "-fstack-protector-strong" "-iquote" "/c/work/xemu/qemu/tcg/i386" "-iquote" 
> "." "-iquote" "/c/work/xemu/qemu" "-iquote" "/c/work/xemu/qemu/accel/tcg" 
> "-iquote" "/c/work/xemu/qemu/include" "-iquote" 
> "/c/work/xemu/qemu/disas/libvixl" "-pthread" "-mms-bitfields" -MD -MQ 
> qga/qemu-ga.exe.p/commands-win32.c.obj -MF 
> "qga/qemu-ga.exe.p/commands-win32.c.obj.d" -o 
> qga/qemu-ga.exe.p/commands-win32.c.obj "-c" ../qga/commands-win32.c -MP
> ../qga/commands-win32.c:62:24: error: redundant redeclaration of 
> 'CM_Get_DevNode_PropertyW' [-Werror=redundant-decls]
>62 | CMAPI CONFIGRET WINAPI CM_Get_DevNode_PropertyW(
>   |^~~~
> In file included from ../qga/commands-win32.c:26:
> C:/CI-Tools/msys64/mingw64/x86_64-w64-mingw32/include/cfgmgr32.h:840:26: 
> note: previous declaration of 'CM_Get_DevNode_PropertyW' was here
>   840 |   CMAPI CONFIGRET WINAPI CM_Get_DevNode_PropertyW(DEVINST dnDevInst, 
> const DEVPROPKEY *PropertyKey, DEVPROPTYPE *PropertyType, PBYTE 
> PropertyBuffer, PULONG PropertyBufferSize, ULONG ulFlags);
>   |  ^~~~
> cc1.exe: all warnings being treated as errors
> make: [Makefile.ninja:5143:qga/qemu-ga.exe.p/commands-win32.c.obj] 错误 1 (已忽略)
> 
> This error comes from qemu configure didn't add predefined macro -DUNICODE 
> -D_UNICODE in QEMU_CFLAGS,
> and these too macro are standard config for win32 if using windows wide api.
> 
> in cfgmgr32.h
>   CMAPI CONFIGRET WINAPI CM_Get_DevNode_PropertyW(DEVINST dnDevInst, const 
> DEVPROPKEY *PropertyKey, DEVPROPTYPE *PropertyType, PBYTE PropertyBuffer, 
> PULONG PropertyBufferSize, ULONG ulFlags);
> #ifdef UNICODE
> #define CM_Get_DevNode_Property CM_Get_DevNode_PropertyW
> #endif
> 
> macro CM_Get_DevNode_Property defined only when UNICODE are defined.
> and in win32, UNICODE and _UNICODE should be defined at the same time
> 
> #endif
> 
> Signed-off-by: Yonggang Luo 
> ---
>  configure | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/configure b/configure
> index 9f141891ea..f5d661af4a 100755
> --- a/configure
> +++ b/configure
> @@ -812,6 +812,7 @@ MINGW32*)
>mingw32="yes"
>hax="yes"
>whpx=""
> +  QEMU_CFLAGS="-DUNICODE -D_UNICODE $QEMU_CFLAGS"

What about declaring them in include/qemu/osdep.h
instead?

-- >8 --
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 412962d91a2..cd5cedc0b21 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -74,6 +74,12 @@ extern int daemon(int, int);
 /* enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later) */
 #ifdef __MINGW32__
 #define __USE_MINGW_ANSI_STDIO 1
+#ifndef UNICODE
+#define UNICODE
+#endif
+#ifndef _UNICODE
+#define _UNICODE
+#endif
 #endif

 #include 
---

>vhost_user="no"
>audio_possible_drivers="dsound sdl"
>if check_include dsound.h; then
> 



Re: [PATCH v9 10/12] migration/dirtyrate: Implement calculate_dirtyrate() function

2020-09-15 Thread Li Qiang
Chuan Zheng  于2020年9月15日周二 上午10:34写道:
>
> Implement calculate_dirtyrate() function.
>
> Signed-off-by: Chuan Zheng 
> Signed-off-by: YanYing Zhuang 
> Reviewed-by: Dr. David Alan Gilbert 

Reviewed-by: Li Qiang 

> ---
>  migration/dirtyrate.c | 45 +++--
>  1 file changed, 43 insertions(+), 2 deletions(-)
>
> diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
> index bcff10e..af02647 100644
> --- a/migration/dirtyrate.c
> +++ b/migration/dirtyrate.c
> @@ -162,6 +162,21 @@ static void get_ramblock_dirty_info(RAMBlock *block,
>  strcpy(info->idstr, qemu_ram_get_idstr(block));
>  }
>
> +static void free_ramblock_dirty_info(struct RamblockDirtyInfo *infos, int 
> count)
> +{
> +int i;
> +
> +if (!infos) {
> +return;
> +}
> +
> +for (i = 0; i < count; i++) {
> +g_free(infos[i].sample_page_vfn);
> +g_free(infos[i].hash_result);
> +}
> +g_free(infos);
> +}
> +
>  static bool skip_sample_ramblock(RAMBlock *block)
>  {
>  /*
> @@ -287,8 +302,34 @@ static bool compare_page_hash_info(struct 
> RamblockDirtyInfo *info,
>
>  static void calculate_dirtyrate(struct DirtyRateConfig config)
>  {
> -/* todo */
> -return;
> +struct RamblockDirtyInfo *block_dinfo = NULL;
> +int block_count = 0;
> +int64_t msec = 0;
> +int64_t initial_time;
> +
> +rcu_register_thread();
> +reset_dirtyrate_stat();
> +rcu_read_lock();
> +initial_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
> +if (!record_ramblock_hash_info(_dinfo, config, _count)) {
> +goto out;
> +}
> +rcu_read_unlock();
> +
> +msec = config.sample_period_seconds * 1000;
> +msec = set_sample_page_period(msec, initial_time);
> +
> +rcu_read_lock();
> +if (!compare_page_hash_info(block_dinfo, block_count)) {
> +goto out;
> +}
> +
> +update_dirtyrate(msec);
> +
> +out:
> +rcu_read_unlock();
> +free_ramblock_dirty_info(block_dinfo, block_count);
> +rcu_unregister_thread();
>  }
>
>  void *get_dirtyrate_thread(void *arg)
> --
> 1.8.3.1
>



Re: [PATCH v9 09/12] migration/dirtyrate: Implement set_sample_page_period() and is_sample_period_valid()

2020-09-15 Thread Li Qiang
Chuan Zheng  于2020年9月15日周二 上午10:34写道:
>
> Implement is_sample_period_valid() to check if the sample period is vaild and
> do set_sample_page_period() to sleep specific time between sample actions.
>
> Signed-off-by: Chuan Zheng 
> Reviewed-by: Dr. David Alan Gilbert 
> Reviewed-by: David Edmondson 

Reviewed-by: Li Qiang 

> ---
>  migration/dirtyrate.c | 24 
>  migration/dirtyrate.h |  6 ++
>  2 files changed, 30 insertions(+)
>
> diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
> index 903f728..bcff10e 100644
> --- a/migration/dirtyrate.c
> +++ b/migration/dirtyrate.c
> @@ -27,6 +27,30 @@
>  static int CalculatingState = DIRTY_RATE_STATUS_UNSTARTED;
>  static struct DirtyRateStat DirtyStat;
>
> +static int64_t set_sample_page_period(int64_t msec, int64_t initial_time)
> +{
> +int64_t current_time;
> +
> +current_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
> +if ((current_time - initial_time) >= msec) {
> +msec = current_time - initial_time;
> +} else {
> +g_usleep((msec + initial_time - current_time) * 1000);
> +}
> +
> +return msec;
> +}
> +
> +static bool is_sample_period_valid(int64_t sec)
> +{
> +if (sec < MIN_FETCH_DIRTYRATE_TIME_SEC ||
> +sec > MAX_FETCH_DIRTYRATE_TIME_SEC) {
> +return false;
> +}
> +
> +return true;
> +}
> +
>  static int dirtyrate_set_state(int *state, int old_state, int new_state)
>  {
>  assert(new_state < DIRTY_RATE_STATUS__MAX);
> diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h
> index faaf9da..8f9bc80 100644
> --- a/migration/dirtyrate.h
> +++ b/migration/dirtyrate.h
> @@ -29,6 +29,12 @@
>   */
>  #define MIN_RAMBLOCK_SIZE 128
>
> +/*
> + * Take 1s as minimum time for calculation duration
> + */
> +#define MIN_FETCH_DIRTYRATE_TIME_SEC  1
> +#define MAX_FETCH_DIRTYRATE_TIME_SEC  60
> +
>  struct DirtyRateConfig {
>  uint64_t sample_pages_per_gigabytes; /* sample pages per GB */
>  int64_t sample_period_seconds; /* time duration between two sampling */
> --
> 1.8.3.1
>



Re: [PATCH v2 03/10] disas: Move host asm annotations to tb_gen_code

2020-09-15 Thread Thomas Huth
On 15/09/2020 01.02, Richard Henderson wrote:
> Instead of creating GStrings and passing them into log_disas,
> just print the annotations directly in tb_gen_code.
> 
> Fix the annotations for the slow paths of the TB, after the
> part implementing the final guest instruction.
> 
> Signed-off-by: Richard Henderson 
> ---
>  include/disas/disas.h |  2 +-
>  include/exec/log.h|  4 ++--
>  accel/tcg/translate-all.c | 24 +++-
>  disas.c   | 29 +
>  tcg/tcg.c |  4 ++--
>  5 files changed, 29 insertions(+), 34 deletions(-)

Reviewed-by: Thomas Huth 




Re: [PATCH v9 07/12] migration/dirtyrate: Compare page hash results for recorded sampled page

2020-09-15 Thread Li Qiang
Chuan Zheng  于2020年9月15日周二 上午10:34写道:
>
> Compare page hash results for recorded sampled page.
>
> Signed-off-by: Chuan Zheng 
> Signed-off-by: YanYing Zhuang 
> Reviewed-by: Dr. David Alan Gilbert 
> ---
>  migration/dirtyrate.c | 63 
> +++
>  1 file changed, 63 insertions(+)
>
> diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
> index 5e6eedf..2d48eb8 100644
> --- a/migration/dirtyrate.c
> +++ b/migration/dirtyrate.c
> @@ -177,6 +177,69 @@ out:
>  return ret;
>  }
>
> +static void calc_page_dirty_rate(struct RamblockDirtyInfo *info)
> +{
> +uint32_t crc;
> +int i;
> +
> +for (i = 0; i < info->sample_pages_count; i++) {
> +crc = get_ramblock_vfn_hash(info, info->sample_page_vfn[i]);
> +if (crc != info->hash_result[i]) {
> +info->sample_dirty_count++;
> +}
> +}
> +}
> +
> +static struct RamblockDirtyInfo *
> +find_page_matched(RAMBlock *block, int count,
> +  struct RamblockDirtyInfo *infos)
> +{
> +int i;
> +struct RamblockDirtyInfo *matched;
> +
> +for (i = 0; i <= count; i++) {

'i < count'?

> +if (!strcmp(infos[i].idstr, qemu_ram_get_idstr(block))) {
> +break;
> +}
> +}
> +
> +if (i == count) {
> +return NULL;
> +}
> +
> +if (infos[i].ramblock_addr != qemu_ram_get_host_addr(block) ||
> +infos[i].ramblock_pages !=
> +(qemu_ram_get_used_length(block) >> TARGET_PAGE_BITS)) {
> +return NULL;
> +}
> +
> +matched = [i];
> +
> +return matched;
> +}
> +
> +static bool compare_page_hash_info(struct RamblockDirtyInfo *info,
> +  int block_count)
> +{
> +struct RamblockDirtyInfo *block_dinfo = NULL;
> +RAMBlock *block = NULL;
> +
> +RAMBLOCK_FOREACH_MIGRATABLE(block) {
> +block_dinfo = find_page_matched(block, block_count, info);
> +if (block_dinfo == NULL) {
> +continue;
> +}
> +calc_page_dirty_rate(block_dinfo);
> +update_dirtyrate_stat(block_dinfo);
> +}
> +
> +if (DirtyStat.total_sample_count == 0) {
> +return false;
> +}
> +
> +return true;
> +}
> +
>  static void calculate_dirtyrate(struct DirtyRateConfig config)
>  {
>  /* todo */
> --
> 1.8.3.1
>



[PATCH] guest agent: Fixes for windows guest agent building on msys2/mingw

2020-09-15 Thread Yonggang Luo
error message:
"cc" "-Iqga/qemu-ga.exe.p" "-Iqga" "-I../qga" "-I." "-Iqapi" "-Itrace" "-Iui" 
"-Iui/shader" "-IC:/CI-Tools/msys64/mingw64/include" 
"-IC:/CI-Tools/msys64/mingw64/include/glib-2.0" 
"-IC:/CI-Tools/msys64/mingw64/lib/glib-2.0/include" "-fdiagnostics-color=auto" 
"-pipe" "-Wall" "-Winvalid-pch" "-Werror" "-std=gnu99" "-g" "-m64" "-mcx16" 
"-D_GNU_SOURCE" "-D_FILE_OFFSET_BITS=64" "-D_LARGEFILE_SOURCE" 
"-Wstrict-prototypes" "-Wredundant-decls" "-Wundef" "-Wwrite-strings" 
"-Wmissing-prototypes" "-fno-strict-aliasing" "-fno-common" "-fwrapv" 
"-Wold-style-declaration" "-Wold-style-definition" "-Wtype-limits" 
"-Wformat-security" "-Wformat-y2k" "-Winit-self" "-Wignored-qualifiers" 
"-Wempty-body" "-Wnested-externs" "-Wendif-labels" "-Wexpansion-to-defined" 
"-Wno-missing-include-dirs" "-Wno-shift-negative-value" "-Wno-psabi" 
"-fstack-protector-strong" "-iquote" "/c/work/xemu/qemu/tcg/i386" "-iquote" "." 
"-iquote" "/c/work/xemu/qemu" "-iquote" "/c/work/xemu/qemu/accel/tcg" "-iquote" 
"/c/work/xemu/qemu/include" "-iquote" "/c/work/xemu/qemu/disas/libvixl" 
"-pthread" "-mms-bitfields" -MD -MQ qga/qemu-ga.exe.p/commands-win32.c.obj -MF 
"qga/qemu-ga.exe.p/commands-win32.c.obj.d" -o 
qga/qemu-ga.exe.p/commands-win32.c.obj "-c" ../qga/commands-win32.c -MP
../qga/commands-win32.c:62:24: error: redundant redeclaration of 
'CM_Get_DevNode_PropertyW' [-Werror=redundant-decls]
   62 | CMAPI CONFIGRET WINAPI CM_Get_DevNode_PropertyW(
  |^~~~
In file included from ../qga/commands-win32.c:26:
C:/CI-Tools/msys64/mingw64/x86_64-w64-mingw32/include/cfgmgr32.h:840:26: note: 
previous declaration of 'CM_Get_DevNode_PropertyW' was here
  840 |   CMAPI CONFIGRET WINAPI CM_Get_DevNode_PropertyW(DEVINST dnDevInst, 
const DEVPROPKEY *PropertyKey, DEVPROPTYPE *PropertyType, PBYTE PropertyBuffer, 
PULONG PropertyBufferSize, ULONG ulFlags);
  |  ^~~~
cc1.exe: all warnings being treated as errors
make: [Makefile.ninja:5143:qga/qemu-ga.exe.p/commands-win32.c.obj] 错误 1 (已忽略)

This error comes from qemu configure didn't add predefined macro -DUNICODE 
-D_UNICODE in QEMU_CFLAGS,
and these too macro are standard config for win32 if using windows wide api.

in cfgmgr32.h
  CMAPI CONFIGRET WINAPI CM_Get_DevNode_PropertyW(DEVINST dnDevInst, const 
DEVPROPKEY *PropertyKey, DEVPROPTYPE *PropertyType, PBYTE PropertyBuffer, 
PULONG PropertyBufferSize, ULONG ulFlags);
#ifdef UNICODE
#define CM_Get_DevNode_Property CM_Get_DevNode_PropertyW
#endif

macro CM_Get_DevNode_Property defined only when UNICODE are defined.
and in win32, UNICODE and _UNICODE should be defined at the same time

#endif

Signed-off-by: Yonggang Luo 
---
 configure | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configure b/configure
index 9f141891ea..f5d661af4a 100755
--- a/configure
+++ b/configure
@@ -812,6 +812,7 @@ MINGW32*)
   mingw32="yes"
   hax="yes"
   whpx=""
+  QEMU_CFLAGS="-DUNICODE -D_UNICODE $QEMU_CFLAGS"
   vhost_user="no"
   audio_possible_drivers="dsound sdl"
   if check_include dsound.h; then
-- 
2.28.0.windows.1




Re: [PATCH v9 08/12] migration/dirtyrate: skip sampling ramblock with size below MIN_RAMBLOCK_SIZE

2020-09-15 Thread Li Qiang
Chuan Zheng  于2020年9月15日周二 上午10:34写道:
>
> In order to sample real RAM, skip ramblock with size below MIN_RAMBLOCK_SIZE
> which is set as 128M.
>
> Signed-off-by: Chuan Zheng 
> Reviewed-by: David Edmondson 
> Reviewed-by: Dr. David Alan Gilbert 

Reviewed-by: Li Qiang 
> ---
>  migration/dirtyrate.c | 21 +
>  migration/dirtyrate.h |  5 +
>  2 files changed, 26 insertions(+)
>
> diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
> index 2d48eb8..903f728 100644
> --- a/migration/dirtyrate.c
> +++ b/migration/dirtyrate.c
> @@ -138,6 +138,18 @@ static void get_ramblock_dirty_info(RAMBlock *block,
>  strcpy(info->idstr, qemu_ram_get_idstr(block));
>  }
>
> +static bool skip_sample_ramblock(RAMBlock *block)
> +{
> +/*
> + * Sample only blocks larger than MIN_RAMBLOCK_SIZE.
> + */
> +if (qemu_ram_get_used_length(block) < (MIN_RAMBLOCK_SIZE << 10)) {
> +return true;
> +}
> +
> +return false;
> +}
> +
>  static bool record_ramblock_hash_info(struct RamblockDirtyInfo **block_dinfo,
>struct DirtyRateConfig config,
>int *block_count)
> @@ -150,6 +162,9 @@ static bool record_ramblock_hash_info(struct 
> RamblockDirtyInfo **block_dinfo,
>  bool ret = false;
>
>  RAMBLOCK_FOREACH_MIGRATABLE(block) {
> +if (skip_sample_ramblock(block)) {
> +continue;
> +}
>  total_count++;
>  }
>
> @@ -159,6 +174,9 @@ static bool record_ramblock_hash_info(struct 
> RamblockDirtyInfo **block_dinfo,
>  }
>
>  RAMBLOCK_FOREACH_MIGRATABLE(block) {
> +if (skip_sample_ramblock(block)) {
> +continue;
> +}
>  if (index >= total_count) {
>  break;
>  }
> @@ -225,6 +243,9 @@ static bool compare_page_hash_info(struct 
> RamblockDirtyInfo *info,
>  RAMBlock *block = NULL;
>
>  RAMBLOCK_FOREACH_MIGRATABLE(block) {
> +if (skip_sample_ramblock(block)) {
> +continue;
> +}
>  block_dinfo = find_page_matched(block, block_count, info);
>  if (block_dinfo == NULL) {
>  continue;
> diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h
> index a3ee305..faaf9da 100644
> --- a/migration/dirtyrate.h
> +++ b/migration/dirtyrate.h
> @@ -24,6 +24,11 @@
>   */
>  #define RAMBLOCK_INFO_MAX_LEN 256
>
> +/*
> + * Minimum RAMBlock size to sample, in megabytes.
> + */
> +#define MIN_RAMBLOCK_SIZE 128
> +
>  struct DirtyRateConfig {
>  uint64_t sample_pages_per_gigabytes; /* sample pages per GB */
>  int64_t sample_period_seconds; /* time duration between two sampling */
> --
> 1.8.3.1
>



Re: [PATCH] pci: check bus pointer before dereference

2020-09-15 Thread Philippe Mathieu-Daudé
+Igor

On 9/15/20 3:51 PM, Li Qiang wrote:
> P J P  于2020年8月27日周四 下午7:52写道:
>>
>> From: Prasad J Pandit 
>>
>> While mapping IRQ level in pci_change_irq_level() routine,
>> it does not check if pci_get_bus() returned a valid pointer.
>> It may lead to a NULL pointer dereference issue. Add check to
>> avoid it.
>>
>>  -> https://ruhr-uni-bochum.sciebo.de/s/NNWP2GfwzYKeKwE?path=%2Flsi_nullptr1
>> ==1183858==Hint: address points to the zero page.
>> #0 pci_change_irq_level hw/pci/pci.c:259
>> #1 pci_irq_handler hw/pci/pci.c:1445
>> #2 pci_set_irq hw/pci/pci.c:1463
>> #3 lsi_set_irq hw/scsi/lsi53c895a.c:488
>> #4 lsi_update_irq hw/scsi/lsi53c895a.c:523
>> #5 lsi_script_scsi_interrupt hw/scsi/lsi53c895a.c:554
>> #6 lsi_execute_script hw/scsi/lsi53c895a.c:1149
>> #7 lsi_reg_writeb hw/scsi/lsi53c895a.c:1984
>> #8 lsi_io_write hw/scsi/lsi53c895a.c:2146
>> ...
>>
>> Reported-by: Ruhr-University 
>> Signed-off-by: Prasad J Pandit 
>> ---
>>  hw/pci/pci.c | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
>> index de0fae10ab..df5a2c3294 100644
>> --- a/hw/pci/pci.c
>> +++ b/hw/pci/pci.c
>> @@ -253,6 +253,9 @@ static void pci_change_irq_level(PCIDevice *pci_dev, int 
>> irq_num, int change)
>>  PCIBus *bus;
>>  for (;;) {
>>  bus = pci_get_bus(pci_dev);
>> +if (!bus) {
> 
> Hi Prasad,
> 
> I think in normal this 'bus' will be not NULL.
> I have look at the link in the commit msg.
> I find it is another DMA to MMIO issue which we have discussed a lot
> but didn't come up with an
> satisfying solution.
> 
> Maybe we can try to the DMA to MMIO issue direction.
> CC: Peter, Jason and Alex
> 
> Thanks,
> Li Qiang
> 
> 
>> +return;

Nack, this should be an abort().

As usual, question is how we got here.

As Li said, it is another DMA to MMIO bug class.

lsi_execute_script
 -> address_space_write
-> acpi_pcihp_eject_slot
   -> bus_remove_child

So at this point the PCI device is still MMIO-mapped
but eject from the bus... ???
Then IRQ is triggered, which the device wants to
propagate via its PCI bus but it doesn't have any more
and b00m.

If a device is hotpluggable, who is responsible to
unmap its regions?

>> +}
>>  irq_num = bus->map_irq(pci_dev, irq_num);
>>  if (bus->set_irq)
>>  break;
>> --
>> 2.26.2
>>
>>
> 




Re: [PATCH v9 06/12] migration/dirtyrate: Record hash results for each sampled page

2020-09-15 Thread Li Qiang
Chuan Zheng  于2020年9月15日周二 上午10:34写道:
>
> Record hash results for each sampled page, crc32 is taken to calculate
> hash results for each sampled length in TARGET_PAGE_SIZE.
>
> Signed-off-by: Chuan Zheng 
> Signed-off-by: YanYing Zhuang 
> Reviewed-by: David Edmondson 

Reviewed-by: Li Qiang 

> ---
>  migration/dirtyrate.c | 109 
> ++
>  1 file changed, 109 insertions(+)
>
> diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
> index 7366bf3..5e6eedf 100644
> --- a/migration/dirtyrate.c
> +++ b/migration/dirtyrate.c
> @@ -10,6 +10,7 @@
>   * See the COPYING file in the top-level directory.
>   */
>
> +#include 
>  #include "qemu/osdep.h"
>  #include "qapi/error.h"
>  #include "cpu.h"
> @@ -68,6 +69,114 @@ static void update_dirtyrate(uint64_t msec)
>  DirtyStat.dirty_rate = dirtyrate;
>  }
>
> +/*
> + * get hash result for the sampled memory with length of TARGET_PAGE_SIZE
> + * in ramblock, which starts from ramblock base address.
> + */
> +static uint32_t get_ramblock_vfn_hash(struct RamblockDirtyInfo *info,
> +  uint64_t vfn)
> +{
> +uint32_t crc;
> +
> +crc = crc32(0, (info->ramblock_addr +
> +vfn * TARGET_PAGE_SIZE), TARGET_PAGE_SIZE);
> +
> +return crc;
> +}
> +
> +static bool save_ramblock_hash(struct RamblockDirtyInfo *info)
> +{
> +unsigned int sample_pages_count;
> +int i;
> +GRand *rand;
> +
> +sample_pages_count = info->sample_pages_count;
> +
> +/* ramblock size less than one page, return success to skip this 
> ramblock */
> +if (unlikely(info->ramblock_pages == 0 || sample_pages_count == 0)) {
> +return true;
> +}
> +
> +info->hash_result = g_try_malloc0_n(sample_pages_count,
> +sizeof(uint32_t));
> +if (!info->hash_result) {
> +return false;
> +}
> +
> +info->sample_page_vfn = g_try_malloc0_n(sample_pages_count,
> +sizeof(uint64_t));
> +if (!info->sample_page_vfn) {
> +g_free(info->hash_result);
> +return false;
> +}
> +
> +rand  = g_rand_new();
> +for (i = 0; i < sample_pages_count; i++) {
> +info->sample_page_vfn[i] = g_rand_int_range(rand, 0,
> +info->ramblock_pages - 
> 1);
> +info->hash_result[i] = get_ramblock_vfn_hash(info,
> + 
> info->sample_page_vfn[i]);
> +}
> +g_rand_free(rand);
> +
> +return true;
> +}
> +
> +static void get_ramblock_dirty_info(RAMBlock *block,
> +struct RamblockDirtyInfo *info,
> +struct DirtyRateConfig *config)
> +{
> +uint64_t sample_pages_per_gigabytes = config->sample_pages_per_gigabytes;
> +
> +/* Right shift 30 bits to calc ramblock size in GB */
> +info->sample_pages_count = (qemu_ram_get_used_length(block) *
> +sample_pages_per_gigabytes) >> 30;
> +/* Right shift TARGET_PAGE_BITS to calc page count */
> +info->ramblock_pages = qemu_ram_get_used_length(block) >>
> +   TARGET_PAGE_BITS;
> +info->ramblock_addr = qemu_ram_get_host_addr(block);
> +strcpy(info->idstr, qemu_ram_get_idstr(block));
> +}
> +
> +static bool record_ramblock_hash_info(struct RamblockDirtyInfo **block_dinfo,
> +  struct DirtyRateConfig config,
> +  int *block_count)
> +{
> +struct RamblockDirtyInfo *info = NULL;
> +struct RamblockDirtyInfo *dinfo = NULL;
> +RAMBlock *block = NULL;
> +int total_count = 0;
> +int index = 0;
> +bool ret = false;
> +
> +RAMBLOCK_FOREACH_MIGRATABLE(block) {
> +total_count++;
> +}
> +
> +dinfo = g_try_malloc0_n(total_count, sizeof(struct RamblockDirtyInfo));
> +if (dinfo == NULL) {
> +goto out;
> +}
> +
> +RAMBLOCK_FOREACH_MIGRATABLE(block) {
> +if (index >= total_count) {
> +break;
> +}
> +info = [index];
> +get_ramblock_dirty_info(block, info, );
> +if (!save_ramblock_hash(info)) {
> +goto out;
> +}
> +index++;
> +}
> +ret = true;
> +
> +out:
> +*block_count = index;
> +*block_dinfo = dinfo;
> +return ret;
> +}
> +
>  static void calculate_dirtyrate(struct DirtyRateConfig config)
>  {
>  /* todo */
> --
> 1.8.3.1
>



Re: [PATCH v9 04/12] migration/dirtyrate: Add dirtyrate statistics series functions

2020-09-15 Thread Li Qiang
Chuan Zheng  于2020年9月15日周二 上午10:34写道:
>
> Add dirtyrate statistics functions to record/update dirtyrate info.
>
> Signed-off-by: Chuan Zheng 
> Reviewed-by: Dr. David Alan Gilbert 

Reviewed-by: Li Qiang 

> ---
>  migration/dirtyrate.c | 32 
>  migration/dirtyrate.h | 12 
>  2 files changed, 44 insertions(+)
>
> diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
> index 7bea8ff..ab372ba 100644
> --- a/migration/dirtyrate.c
> +++ b/migration/dirtyrate.c
> @@ -23,6 +23,7 @@
>  #include "dirtyrate.h"
>
>  static int CalculatingState = DIRTY_RATE_STATUS_UNSTARTED;
> +static struct DirtyRateStat DirtyStat;
>
>  static int dirtyrate_set_state(int *state, int old_state, int new_state)
>  {
> @@ -34,6 +35,37 @@ static int dirtyrate_set_state(int *state, int old_state, 
> int new_state)
>  }
>  }
>
> +static void reset_dirtyrate_stat(void)
> +{
> +DirtyStat.total_dirty_samples = 0;
> +DirtyStat.total_sample_count = 0;
> +DirtyStat.total_block_mem_MB = 0;
> +DirtyStat.dirty_rate = -1;
> +DirtyStat.start_time = 0;
> +DirtyStat.calc_time = 0;
> +}
> +
> +static void update_dirtyrate_stat(struct RamblockDirtyInfo *info)
> +{
> +DirtyStat.total_dirty_samples += info->sample_dirty_count;
> +DirtyStat.total_sample_count += info->sample_pages_count;
> +/* size of total pages in MB */
> +DirtyStat.total_block_mem_MB += (info->ramblock_pages *
> + TARGET_PAGE_SIZE) >> 20;
> +}
> +
> +static void update_dirtyrate(uint64_t msec)
> +{
> +uint64_t dirtyrate;
> +uint64_t total_dirty_samples = DirtyStat.total_dirty_samples;
> +uint64_t total_sample_count = DirtyStat.total_sample_count;
> +uint64_t total_block_mem_MB = DirtyStat.total_block_mem_MB;
> +
> +dirtyrate = total_dirty_samples * total_block_mem_MB *
> +1000 / (total_sample_count * msec);
> +
> +DirtyStat.dirty_rate = dirtyrate;
> +}
>
>  static void calculate_dirtyrate(struct DirtyRateConfig config)
>  {
> diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h
> index 479e222..a3ee305 100644
> --- a/migration/dirtyrate.h
> +++ b/migration/dirtyrate.h
> @@ -42,6 +42,18 @@ struct RamblockDirtyInfo {
>  uint32_t *hash_result; /* array of hash result for sampled pages */
>  };
>
> +/*
> + * Store calculation statistics for each measure.
> + */
> +struct DirtyRateStat {
> +uint64_t total_dirty_samples; /* total dirty sampled page */
> +uint64_t total_sample_count; /* total sampled pages */
> +uint64_t total_block_mem_MB; /* size of total sampled pages in MB */
> +int64_t dirty_rate; /* dirty rate in MB/s */
> +int64_t start_time; /* calculation start time in units of second */
> +int64_t calc_time; /* time duration of two sampling in units of second */
> +};
> +
>  void *get_dirtyrate_thread(void *arg);
>  #endif
>
> --
> 1.8.3.1
>



Re: [PATCH v9 05/12] migration/dirtyrate: move RAMBLOCK_FOREACH_MIGRATABLE into ram.h

2020-09-15 Thread Li Qiang
Chuan Zheng  于2020年9月15日周二 上午10:34写道:
>
> RAMBLOCK_FOREACH_MIGRATABLE is need in dirtyrate measure,
> move the existing definition up into migration/ram.h
>
> Signed-off-by: Chuan Zheng 
> Reviewed-by: Dr. David Alan Gilbert 
> Reviewed-by: David Edmondson 

Reviewed-by: Li Qiang 

> ---
>  migration/dirtyrate.c |  1 +
>  migration/ram.c   | 11 +--
>  migration/ram.h   | 10 ++
>  3 files changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
> index ab372ba..7366bf3 100644
> --- a/migration/dirtyrate.c
> +++ b/migration/dirtyrate.c
> @@ -20,6 +20,7 @@
>  #include "qemu/rcu_queue.h"
>  #include "qapi/qapi-commands-migration.h"
>  #include "migration.h"
> +#include "ram.h"
>  #include "dirtyrate.h"
>
>  static int CalculatingState = DIRTY_RATE_STATUS_UNSTARTED;
> diff --git a/migration/ram.c b/migration/ram.c
> index 76d4fee..37ef0da 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -158,21 +158,12 @@ out:
>  return ret;
>  }
>
> -static bool ramblock_is_ignored(RAMBlock *block)
> +bool ramblock_is_ignored(RAMBlock *block)
>  {
>  return !qemu_ram_is_migratable(block) ||
> (migrate_ignore_shared() && qemu_ram_is_shared(block));
>  }
>
> -/* Should be holding either ram_list.mutex, or the RCU lock. */
> -#define RAMBLOCK_FOREACH_NOT_IGNORED(block)\
> -INTERNAL_RAMBLOCK_FOREACH(block)   \
> -if (ramblock_is_ignored(block)) {} else
> -
> -#define RAMBLOCK_FOREACH_MIGRATABLE(block) \
> -INTERNAL_RAMBLOCK_FOREACH(block)   \
> -if (!qemu_ram_is_migratable(block)) {} else
> -
>  #undef RAMBLOCK_FOREACH
>
>  int foreach_not_ignored_block(RAMBlockIterFunc func, void *opaque)
> diff --git a/migration/ram.h b/migration/ram.h
> index 2eeaacf..011e854 100644
> --- a/migration/ram.h
> +++ b/migration/ram.h
> @@ -37,6 +37,16 @@ extern MigrationStats ram_counters;
>  extern XBZRLECacheStats xbzrle_counters;
>  extern CompressionStats compression_counters;
>
> +bool ramblock_is_ignored(RAMBlock *block);
> +/* Should be holding either ram_list.mutex, or the RCU lock. */
> +#define RAMBLOCK_FOREACH_NOT_IGNORED(block)\
> +INTERNAL_RAMBLOCK_FOREACH(block)   \
> +if (ramblock_is_ignored(block)) {} else
> +
> +#define RAMBLOCK_FOREACH_MIGRATABLE(block) \
> +INTERNAL_RAMBLOCK_FOREACH(block)   \
> +if (!qemu_ram_is_migratable(block)) {} else
> +
>  int xbzrle_cache_resize(int64_t new_size, Error **errp);
>  uint64_t ram_bytes_remaining(void);
>  uint64_t ram_bytes_total(void);
> --
> 1.8.3.1
>



Re: [PATCH v9 03/12] migration/dirtyrate: Add RamblockDirtyInfo to store sampled page info

2020-09-15 Thread Li Qiang
Chuan Zheng  于2020年9月15日周二 上午10:34写道:
>
> Add RamblockDirtyInfo to store sampled page info of each ramblock.
>
> Signed-off-by: Chuan Zheng 
> Reviewed-by: Dr. David Alan Gilbert 
> Reviewed-by: David Edmondson 

Reviewed-by: Li Qiang 

> ---
>  migration/dirtyrate.h | 18 ++
>  1 file changed, 18 insertions(+)
>
> diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h
> index 5be9714..479e222 100644
> --- a/migration/dirtyrate.h
> +++ b/migration/dirtyrate.h
> @@ -19,11 +19,29 @@
>   */
>  #define DIRTYRATE_DEFAULT_SAMPLE_PAGES512
>
> +/*
> + * Record ramblock idstr
> + */
> +#define RAMBLOCK_INFO_MAX_LEN 256
> +
>  struct DirtyRateConfig {
>  uint64_t sample_pages_per_gigabytes; /* sample pages per GB */
>  int64_t sample_period_seconds; /* time duration between two sampling */
>  };
>
> +/*
> + * Store dirtypage info for each ramblock.
> + */
> +struct RamblockDirtyInfo {
> +char idstr[RAMBLOCK_INFO_MAX_LEN]; /* idstr for each ramblock */
> +uint8_t *ramblock_addr; /* base address of ramblock we measure */
> +uint64_t ramblock_pages; /* ramblock size in TARGET_PAGE_SIZE */
> +uint64_t *sample_page_vfn; /* relative offset address for sampled page */
> +uint64_t sample_pages_count; /* count of sampled pages */
> +uint64_t sample_dirty_count; /* count of dirty pages we measure */
> +uint32_t *hash_result; /* array of hash result for sampled pages */
> +};
> +
>  void *get_dirtyrate_thread(void *arg);
>  #endif
>
> --
> 1.8.3.1
>



<    1   2   3   4   5   >