Re: [PATCH v4 1/4] virtio:add support in configure interrupt

2021-03-25 Thread Cindy Lu
On Wed, Mar 24, 2021 at 2:30 PM Jason Wang  wrote:
>
>
> 在 2021/3/23 上午9:56, Cindy Lu 写道:
> > Add configure notifier support in virtio and related driver
> > When peer is vhost vdpa, setup the configure interrupt function
> > vhost_net_start and release the resource when vhost_net_stop
>
>
> So this patch doesn't complie, please fix.
>
>
> >
> > Signed-off-by: Cindy Lu 
> > ---
> >   hw/display/vhost-user-gpu.c| 14 +++
> >   hw/net/vhost_net.c | 16 +++--
> >   hw/net/virtio-net.c| 24 +++
> >   hw/s390x/virtio-ccw.c  |  6 ++---
> >   hw/virtio/vhost-user-fs.c  | 12 ++
> >   hw/virtio/vhost-vsock-common.c | 12 ++
> >   hw/virtio/vhost.c  | 44 --
> >   hw/virtio/virtio-crypto.c  | 13 ++
> >   hw/virtio/virtio.c | 28 ++
> >   include/hw/virtio/vhost.h  |  4 
> >   include/hw/virtio/virtio.h | 23 --
> >   include/net/vhost_net.h|  3 +++
> >   12 files changed, 169 insertions(+), 30 deletions(-)
> >
> > diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c
> > index 51f1747c4a..959ad115b6 100644
> > --- a/hw/display/vhost-user-gpu.c
> > +++ b/hw/display/vhost-user-gpu.c
> > @@ -487,18 +487,24 @@ vhost_user_gpu_set_status(VirtIODevice *vdev, uint8_t 
> > val)
> >   }
> >
> >   static bool
> > -vhost_user_gpu_guest_notifier_pending(VirtIODevice *vdev, int idx)
> > +vhost_user_gpu_guest_notifier_pending(VirtIODevice *vdev, int idx,
> > +int type)
> >   {
> >   VhostUserGPU *g = VHOST_USER_GPU(vdev);
> > -
> > +if (type != VIRTIO_VQ_VECTOR) {
> > +return false;
> > +}
> >   return vhost_virtqueue_pending(&g->vhost->dev, idx);
> >   }
> >
> >   static void
> > -vhost_user_gpu_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask)
> > +vhost_user_gpu_guest_notifier_mask(VirtIODevice *vdev, int idx, bool mask,
> > +int type)
> >   {
> >   VhostUserGPU *g = VHOST_USER_GPU(vdev);
> > -
> > +if (type != VIRTIO_VQ_VECTOR) {
> > +return;
> > +}
> >   vhost_virtqueue_mask(&g->vhost->dev, vdev, idx, mask);
> >   }
> >
> > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> > index 24d555e764..2ef8cc608e 100644
> > --- a/hw/net/vhost_net.c
> > +++ b/hw/net/vhost_net.c
> > @@ -339,7 +339,9 @@ int vhost_net_start(VirtIODevice *dev, NetClientState 
> > *ncs,
> >   dev->use_guest_notifier_mask = false;
> >   }
> >}
> > -
> > +if (ncs->peer && ncs->peer->info->type == 
> > NET_CLIENT_DRIVER_VHOST_VDPA) {
> > +dev->use_config_notifier = VIRTIO_CONFIG_SUPPORT;
> > +}
> >   r = k->set_guest_notifiers(qbus->parent, total_queues * 2, true);
> >   if (r < 0) {
> >   error_report("Error binding guest notifier: %d", -r);
> > @@ -391,7 +393,6 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState 
> > *ncs,
> >   for (i = 0; i < total_queues; i++) {
> >   vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev);
> >   }
> > -
> >   r = k->set_guest_notifiers(qbus->parent, total_queues * 2, false);
> >   if (r < 0) {
> >   fprintf(stderr, "vhost guest notifier cleanup failed: %d\n", r);
> > @@ -426,6 +427,17 @@ void vhost_net_virtqueue_mask(VHostNetState *net, 
> > VirtIODevice *dev,
> >   vhost_virtqueue_mask(&net->dev, dev, idx, mask);
> >   }
> >
> > +bool vhost_net_config_pending(VHostNetState *net, int idx)
> > +{
> > +return vhost_config_pending(&net->dev, idx);
> > +}
> > +
> > +void vhost_net_config_mask(VHostNetState *net, VirtIODevice *dev,
> > +  bool mask)
> > +{
> > +vhost_config_mask(&net->dev, dev,  mask);
> > +}
> > +
> >   VHostNetState *get_vhost_net(NetClientState *nc)
> >   {
> >   VHostNetState *vhost_net = 0;
> > diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> > index 9179013ac4..b84427fe99 100644
> > --- a/hw/net/virtio-net.c
> > +++ b/hw/net/virtio-net.c
> > @@ -3055,22 +3055,36 @@ static NetClientInfo net_virtio_info = {
> >   .announce = virtio_net_announce,
> >   };
> >
> > -static bool virtio_net_guest_notifier_pending(VirtIODevice *vdev, int idx)
> > +
> > +static bool virtio_net_guest_notifier_pending(VirtIODevice *vdev, int idx,
> > +int type)
> >   {
> >   VirtIONet *n = VIRTIO_NET(vdev);
> >   NetClientState *nc = qemu_get_subqueue(n->nic, vq2q(idx));
> >   assert(n->vhost_started);
> > -return vhost_net_virtqueue_pending(get_vhost_net(nc->peer), idx);
> > +
> > +if (type == VIRTIO_VQ_VECTOR) {
> > +return vhost_net_virtqueue_pending(get_vhost_net(nc->peer), idx);
> > +}
> > +if (type == VIRTIO_CONFIG_VECTOR) {
> > +return vhost_net_config_pending(get_vhost_net(nc->peer), idx);
> > +}
> > +return false;
> >   }
> >
> >   

Re: [PATCH v4 2/4] vhost-vdpa: add callback function for configure interrupt

2021-03-25 Thread Cindy Lu
On Wed, Mar 24, 2021 at 2:35 PM Jason Wang  wrote:
>
>
> 在 2021/3/23 上午9:56, Cindy Lu 写道:
> > Add call back function for configure interrupt.
> > Set the notifier's fd to the kernel driver when vdpa start.
> > also set -1 while vdpa stop. then the kernel will release
> > the related resource
> >
> > Signed-off-by: Cindy Lu 
> > ---
> >   hw/virtio/trace-events|  2 ++
> >   hw/virtio/vhost-vdpa.c| 40 +--
> >   include/hw/virtio/vhost-backend.h |  4 
> >   3 files changed, 44 insertions(+), 2 deletions(-)
> >
> > diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events
> > index 2060a144a2..6710835b46 100644
> > --- a/hw/virtio/trace-events
> > +++ b/hw/virtio/trace-events
> > @@ -52,6 +52,8 @@ vhost_vdpa_set_vring_call(void *dev, unsigned int index, 
> > int fd) "dev: %p index:
> >   vhost_vdpa_get_features(void *dev, uint64_t features) "dev: %p features: 
> > 0x%"PRIx64
> >   vhost_vdpa_set_owner(void *dev) "dev: %p"
> >   vhost_vdpa_vq_get_addr(void *dev, void *vq, uint64_t desc_user_addr, 
> > uint64_t avail_user_addr, uint64_t used_user_addr) "dev: %p vq: %p 
> > desc_user_addr: 0x%"PRIx64" avail_user_addr: 0x%"PRIx64" used_user_addr: 
> > 0x%"PRIx64
> > +vhost_vdpa_set_config_call(void *dev, int *fd)"dev: %p fd: %p"
> > +
> >
> >   # virtio.c
> >   virtqueue_alloc_element(void *elem, size_t sz, unsigned in_num, unsigned 
> > out_num) "elem %p size %zd in_num %u out_num %u"
> > diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
> > index 01d2101d09..bde32eefe7 100644
> > --- a/hw/virtio/vhost-vdpa.c
> > +++ b/hw/virtio/vhost-vdpa.c
> > @@ -467,20 +467,47 @@ static int vhost_vdpa_get_config(struct vhost_dev 
> > *dev, uint8_t *config,
> >   }
> >   return ret;
> >}
> > -
> > +static void vhost_vdpa_config_notify_start(struct vhost_dev *dev,
> > +struct VirtIODevice *vdev, bool start)
> > +{
> > +int fd = 0;
> > +int r = 0;
> > +if (!(dev->features & (0x1ULL << VIRTIO_NET_F_STATUS))) {
> > +return;
> > +}
> > +if (start) {
> > +fd = event_notifier_get_fd(&vdev->config_notifier);
> > +r = dev->vhost_ops->vhost_set_config_call(dev, &fd);
> > + /*set the fd call back to vdpa driver*/
> > +if (!r) {
> > +vdev->use_config_notifier = VIRTIO_CONFIG_WORK;
> > +event_notifier_set(&vdev->config_notifier);
>
>
> Is this a workaround for the vdpa device without config interrupt? I
> wonder how much we could gain from this.
>
this is a bit identify if the config notifier working now, this bit to check in
virtio bus  for different behavior , I will change this bit 's name to
make it more clearly

>
> > +info_report("vhost_vdpa_config_notify start!");
>
>
> This is a debug code I guess.
>
sure I will remove this
>
> > +  }
> > +} else {
> > +fd = -1;
> > +vdev->use_config_notifier = VIRTIO_CONFIG_STOP;
>
>
> Looks like a duplicated state with vhost_dev->started?
>
>
> > +r = dev->vhost_ops->vhost_set_config_call(dev, &fd);
> > +}
> > +return;
> > +}
> >   static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
> >   {
> >   struct vhost_vdpa *v = dev->opaque;
> >   trace_vhost_vdpa_dev_start(dev, started);
> > +VirtIODevice *vdev = dev->vdev;
> > +
> >   if (started) {
> >   uint8_t status = 0;
> >   memory_listener_register(&v->listener, &address_space_memory);
> >   vhost_vdpa_set_vring_ready(dev);
> >   vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
> >   vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status);
> > -
> > +/*set the configure interrupt call back*/
> > +vhost_vdpa_config_notify_start(dev, vdev, true);
> >   return !(status & VIRTIO_CONFIG_S_DRIVER_OK);
> >   } else {
> > +vhost_vdpa_config_notify_start(dev, vdev, false);
> >   vhost_vdpa_reset_device(dev);
> >   vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE |
> >  VIRTIO_CONFIG_S_DRIVER);
> > @@ -546,6 +573,14 @@ static int vhost_vdpa_set_vring_call(struct vhost_dev 
> > *dev,
> >   return vhost_vdpa_call(dev, VHOST_SET_VRING_CALL, file);
> >   }
> >
> > +static int vhost_vdpa_set_config_call(struct vhost_dev *dev,
> > +   int *fd)
> > +{
> > +trace_vhost_vdpa_set_config_call(dev, fd);
> > +
> > +return vhost_vdpa_call(dev, VHOST_VDPA_SET_CONFIG_CALL, fd);
> > +}
> > +
> >   static int vhost_vdpa_get_features(struct vhost_dev *dev,
> >uint64_t *features)
> >   {
> > @@ -611,4 +646,5 @@ const VhostOps vdpa_ops = {
> >   .vhost_get_device_id = vhost_vdpa_get_device_id,
> >   .vhost_vq_get_addr = vhost_vdpa_vq_get_addr,
> >   .vhost_force_iommu = vhost_vdpa_force_iommu,
> > +.vhost_set_config_call = vhost_vdpa_set_config_call,
>

[PATCH RFC RESEND v2 3/6] hw/pci: Add pci_root_bus_max_bus

2021-03-25 Thread Wang Xingang
From: Xingang Wang 

This helps to find max bus number of a root bus.

Signed-off-by: Xingang Wang 
Signed-off-by: Jiahui Cen 
---
 hw/pci/pci.c | 34 ++
 include/hw/pci/pci.h |  1 +
 2 files changed, 35 insertions(+)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index e17aa9075f..c7957cbf7c 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -538,6 +538,40 @@ int pci_bus_num(PCIBus *s)
 return PCI_BUS_GET_CLASS(s)->bus_num(s);
 }
 
+int pci_root_bus_max_bus(PCIBus *bus)
+{
+PCIHostState *host;
+PCIDevice *dev;
+int max_bus = 0;
+int type, devfn;
+uint8_t subordinate;
+
+if (!pci_bus_is_root(bus)) {
+return 0;
+}
+
+host = PCI_HOST_BRIDGE(BUS(bus)->parent);
+max_bus = pci_bus_num(host->bus);
+
+for (devfn = 0; devfn < ARRAY_SIZE(host->bus->devices); devfn++) {
+dev = host->bus->devices[devfn];
+
+if (!dev) {
+continue;
+}
+
+type = dev->config[PCI_HEADER_TYPE] & ~PCI_HEADER_TYPE_MULTI_FUNCTION;
+if (type == PCI_HEADER_TYPE_BRIDGE) {
+subordinate = dev->config[PCI_SUBORDINATE_BUS];
+if (subordinate > max_bus) {
+max_bus = subordinate;
+}
+}
+}
+
+return max_bus;
+}
+
 int pci_bus_numa_node(PCIBus *bus)
 {
 return PCI_BUS_GET_CLASS(bus)->numa_node(bus);
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 718b5a454a..e0c69534f4 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -450,6 +450,7 @@ static inline PCIBus *pci_get_bus(const PCIDevice *dev)
 return PCI_BUS(qdev_get_parent_bus(DEVICE(dev)));
 }
 int pci_bus_num(PCIBus *s);
+int pci_root_bus_max_bus(PCIBus *bus);
 static inline int pci_dev_bus_num(const PCIDevice *dev)
 {
 return pci_bus_num(pci_get_bus(dev));
-- 
2.19.1




[PATCH RFC RESEND v2 2/6] hw/pci: Add iommu option for pci root bus

2021-03-25 Thread Wang Xingang
From: Xingang Wang 

This add iommu option for pci root bus, including primary bus
and pxb root bus. The option is valid only if there is a virtual
iommu device.

Signed-off-by: Xingang Wang 
Signed-off-by: Jiahui Cen 
---
 hw/arm/virt.c   | 25 +
 hw/i386/pc.c| 19 +++
 hw/pci-bridge/pci_expander_bridge.c |  3 +++
 hw/pci-host/q35.c   |  1 +
 include/hw/arm/virt.h   |  1 +
 include/hw/i386/pc.h|  1 +
 6 files changed, 50 insertions(+)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index aa2bbd14e0..446b3b867f 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -1366,6 +1366,7 @@ static void create_pcie(VirtMachineState *vms)
 }
 
 pci = PCI_HOST_BRIDGE(dev);
+pci->iommu = vms->primary_bus_iommu;
 vms->bus = pci->bus;
 if (vms->bus) {
 for (i = 0; i < nb_nics; i++) {
@@ -2319,6 +2320,20 @@ static void virt_set_iommu(Object *obj, const char 
*value, Error **errp)
 }
 }
 
+static bool virt_get_primary_bus_iommu(Object *obj, Error **errp)
+{
+VirtMachineState *vms = VIRT_MACHINE(obj);
+
+return vms->primary_bus_iommu;
+}
+
+static void virt_set_primary_bus_iommu(Object *obj, bool value, Error **errp)
+{
+VirtMachineState *vms = VIRT_MACHINE(obj);
+
+vms->primary_bus_iommu = value;
+}
+
 static CpuInstanceProperties
 virt_cpu_index_to_props(MachineState *ms, unsigned cpu_index)
 {
@@ -2652,6 +2667,13 @@ static void virt_machine_class_init(ObjectClass *oc, 
void *data)
   "Set the IOMMU type. "
   "Valid values are none and smmuv3");
 
+object_class_property_add_bool(oc, "primary_bus_iommu",
+  virt_get_primary_bus_iommu,
+  virt_set_primary_bus_iommu);
+object_class_property_set_description(oc, "primary_bus_iommu",
+  "Set on/off to enable/disable "
+  "iommu for primary bus");
+
 object_class_property_add_bool(oc, "ras", virt_get_ras,
virt_set_ras);
 object_class_property_set_description(oc, "ras",
@@ -2719,6 +2741,9 @@ static void virt_instance_init(Object *obj)
 /* Default disallows iommu instantiation */
 vms->iommu = VIRT_IOMMU_NONE;
 
+/* The primary bus is attached to iommu by default */
+vms->primary_bus_iommu = true;
+
 /* Default disallows RAS instantiation */
 vms->ras = false;
 
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 8a84b25a03..b64e4bb7f2 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1529,6 +1529,21 @@ static void pc_machine_set_hpet(Object *obj, bool value, 
Error **errp)
 pcms->hpet_enabled = value;
 }
 
+static bool pc_machine_get_primary_bus_iommu(Object *obj, Error **errp)
+{
+PCMachineState *pcms = PC_MACHINE(obj);
+
+return pcms->primary_bus_iommu;
+}
+
+static void pc_machine_set_primary_bus_iommu(Object *obj, bool value,
+ Error **errp)
+{
+PCMachineState *pcms = PC_MACHINE(obj);
+
+pcms->primary_bus_iommu = value;
+}
+
 static void pc_machine_get_max_ram_below_4g(Object *obj, Visitor *v,
 const char *name, void *opaque,
 Error **errp)
@@ -1628,6 +1643,7 @@ static void pc_machine_initfn(Object *obj)
 #ifdef CONFIG_HPET
 pcms->hpet_enabled = true;
 #endif
+pcms->primary_bus_iommu = true;
 
 pc_system_flash_create(pcms);
 pcms->pcspk = isa_new(TYPE_PC_SPEAKER);
@@ -1752,6 +1768,9 @@ static void pc_machine_class_init(ObjectClass *oc, void 
*data)
 object_class_property_add_bool(oc, "hpet",
 pc_machine_get_hpet, pc_machine_set_hpet);
 
+object_class_property_add_bool(oc, "primary_bus_iommu",
+pc_machine_get_primary_bus_iommu, pc_machine_set_primary_bus_iommu);
+
 object_class_property_add(oc, PC_MACHINE_MAX_FW_SIZE, "size",
 pc_machine_get_max_fw_size, pc_machine_set_max_fw_size,
 NULL, NULL);
diff --git a/hw/pci-bridge/pci_expander_bridge.c 
b/hw/pci-bridge/pci_expander_bridge.c
index aedded1064..f1a0eadc03 100644
--- a/hw/pci-bridge/pci_expander_bridge.c
+++ b/hw/pci-bridge/pci_expander_bridge.c
@@ -57,6 +57,7 @@ struct PXBDev {
 
 uint8_t bus_nr;
 uint16_t numa_node;
+bool iommu;
 };
 
 static PXBDev *convert_to_pxb(PCIDevice *dev)
@@ -255,6 +256,7 @@ static void pxb_dev_realize_common(PCIDevice *dev, bool 
pcie, Error **errp)
 bus->map_irq = pxb_map_irq_fn;
 
 PCI_HOST_BRIDGE(ds)->bus = bus;
+PCI_HOST_BRIDGE(ds)->iommu = pxb->iommu;
 
 pxb_register_bus(dev, bus, &local_err);
 if (local_err) {
@@ -301,6 +303,7 @@ static Property pxb_dev_properties[] = {
 /* Note: 0 is not a legal PXB bus number. */
 DEFINE_PROP_UINT8("bus_nr", PXBDev, bus_nr, 0),
 DEFINE_PROP_UINT16("

[PATCH RFC RESEND v2 1/6] hw/pci/pci_host: Add iommu property for pci host

2021-03-25 Thread Wang Xingang
From: Xingang Wang 

The pci host iommu property is useful to check whether
the iommu is enabled on the pci root bus.

Signed-off-by: Xingang Wang 
Signed-off-by: Jiahui Cen 
---
 hw/pci/pci.c  | 18 +-
 hw/pci/pci_host.c |  2 ++
 include/hw/pci/pci.h  |  1 +
 include/hw/pci/pci_host.h |  1 +
 4 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index ac9a24889c..e17aa9075f 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -417,6 +417,22 @@ const char *pci_root_bus_path(PCIDevice *dev)
 return rootbus->qbus.name;
 }
 
+bool pci_root_bus_has_iommu(PCIBus *bus)
+{
+PCIBus *rootbus = bus;
+PCIHostState *host_bridge;
+
+if (!pci_bus_is_root(bus)) {
+rootbus = pci_device_root_bus(bus->parent_dev);
+}
+
+host_bridge = PCI_HOST_BRIDGE(rootbus->qbus.parent);
+
+assert(host_bridge->bus == rootbus);
+
+return host_bridge->iommu;
+}
+
 static void pci_root_bus_init(PCIBus *bus, DeviceState *parent,
   MemoryRegion *address_space_mem,
   MemoryRegion *address_space_io,
@@ -2716,7 +2732,7 @@ AddressSpace *pci_device_iommu_address_space(PCIDevice 
*dev)
 
 iommu_bus = parent_bus;
 }
-if (iommu_bus && iommu_bus->iommu_fn) {
+if (pci_root_bus_has_iommu(bus) && iommu_bus && iommu_bus->iommu_fn) {
 return iommu_bus->iommu_fn(bus, iommu_bus->iommu_opaque, devfn);
 }
 return &address_space_memory;
diff --git a/hw/pci/pci_host.c b/hw/pci/pci_host.c
index 8ca5fadcbd..92ce213b18 100644
--- a/hw/pci/pci_host.c
+++ b/hw/pci/pci_host.c
@@ -222,6 +222,8 @@ const VMStateDescription vmstate_pcihost = {
 static Property pci_host_properties_common[] = {
 DEFINE_PROP_BOOL("x-config-reg-migration-enabled", PCIHostState,
  mig_enabled, true),
+DEFINE_PROP_BOOL("pci-host-iommu-enabled", PCIHostState,
+ iommu, true),
 DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 6be4e0c460..718b5a454a 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -480,6 +480,7 @@ void pci_for_each_bus(PCIBus *bus,
 
 PCIBus *pci_device_root_bus(const PCIDevice *d);
 const char *pci_root_bus_path(PCIDevice *dev);
+bool pci_root_bus_has_iommu(PCIBus *bus);
 PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn);
 int pci_qdev_find_device(const char *id, PCIDevice **pdev);
 void pci_bus_get_w64_range(PCIBus *bus, Range *range);
diff --git a/include/hw/pci/pci_host.h b/include/hw/pci/pci_host.h
index 52e038c019..64128e3a19 100644
--- a/include/hw/pci/pci_host.h
+++ b/include/hw/pci/pci_host.h
@@ -43,6 +43,7 @@ struct PCIHostState {
 uint32_t config_reg;
 bool mig_enabled;
 PCIBus *bus;
+bool iommu;
 
 QLIST_ENTRY(PCIHostState) next;
 };
-- 
2.19.1




[PATCH RFC RESEND v2 0/6] Introduce IOMMU Option For PCI Root Bus

2021-03-25 Thread Wang Xingang
From: Xingang Wang 

These patches add support for configure iommu on/off for pci root bus,
including primary bus and pxb root bus. At present, All root bus
will go through iommu when iommu is configured, which is not flexible.

So this add option to enable/disable iommu for primary bus and pxb
root bus.  When iommu is enabled for the root bus, devices attached to it
will go through iommu. When iommu is disabled for the root bus, devices
will not go through iommu accordingly.

The option example for iommu configuration is like the following:

primary root bus option:
arm: -machine virt iommu=smmuv3,primary_bus_iommu=false(or true)
x86: -machine q35,primary_bus_iommu=false(or true)

pxb root bus:
 -device pxb-pcie,bus_nr=0x10,id=pci.10,bus=pcie.0,addr=0x3.0x1,iommu=false 

History:

v1 -> v2:
- rebase on top of v6.0.0-rc0
- Fix some issues
- Took into account Eric's comments, and remove the PCI_BUS_IOMMU flag,
  replace it with a property in PCIHostState.
- Add support for x86 iommu option

Xingang Wang (6):
  hw/pci/pci_host: Add iommu property for pci host
  hw/pci: Add iommu option for pci root bus
  hw/pci: Add pci_root_bus_max_bus
  hw/arm/virt-acpi-build: Add explicit idmap info in IORT table
  hw/i386/acpi-build: Add explicit scope in DMAR table
  hw/i386/acpi-build: Add iommu filter in IVRS table

 hw/arm/virt-acpi-build.c| 103 ++--
 hw/arm/virt.c   |  25 +++
 hw/i386/acpi-build.c|  70 ++-
 hw/i386/pc.c|  19 +
 hw/pci-bridge/pci_expander_bridge.c |   3 +
 hw/pci-host/q35.c   |   1 +
 hw/pci/pci.c|  52 +-
 hw/pci/pci_host.c   |   2 +
 include/hw/arm/virt.h   |   1 +
 include/hw/i386/pc.h|   1 +
 include/hw/pci/pci.h|   2 +
 include/hw/pci/pci_host.h   |   1 +
 12 files changed, 254 insertions(+), 26 deletions(-)

-- 
2.19.1




[PATCH RFC RESEND v2 4/6] hw/arm/virt-acpi-build: Add explicit idmap info in IORT table

2021-03-25 Thread Wang Xingang
From: Xingang Wang 

The idmap of smmuv3 and root complex covers the whole RID space for now,
this patch add explicit idmap info according to root bus number range.
This add smmuv3 idmap for certain bus which has enabled the iommu property.

Signed-off-by: Xingang Wang 
Signed-off-by: Jiahui Cen 
---
 hw/arm/virt-acpi-build.c | 103 ++-
 1 file changed, 81 insertions(+), 22 deletions(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index f5a2b2d4cb..5491036c86 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -44,6 +44,7 @@
 #include "hw/acpi/tpm.h"
 #include "hw/pci/pcie_host.h"
 #include "hw/pci/pci.h"
+#include "hw/pci/pci_bus.h"
 #include "hw/pci-host/gpex.h"
 #include "hw/arm/virt.h"
 #include "hw/mem/nvdimm.h"
@@ -237,6 +238,41 @@ static void acpi_dsdt_add_tpm(Aml *scope, VirtMachineState 
*vms)
 aml_append(scope, dev);
 }
 
+typedef
+struct AcpiIortMapping {
+AcpiIortIdMapping idmap;
+bool iommu;
+} AcpiIortMapping;
+
+/* For all PCI host bridges, walk and insert DMAR scope */
+static int
+iort_host_bridges(Object *obj, void *opaque)
+{
+GArray *map_blob = opaque;
+AcpiIortMapping map;
+AcpiIortIdMapping *idmap = &map.idmap;
+int bus_num, max_bus;
+
+if (object_dynamic_cast(obj, TYPE_PCI_HOST_BRIDGE)) {
+PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus;
+
+if (bus) {
+bus_num = pci_bus_num(bus);
+max_bus = pci_root_bus_max_bus(bus);
+
+idmap->input_base = cpu_to_le32(bus_num << 8);
+idmap->id_count = cpu_to_le32((max_bus - bus_num + 1) << 8);
+idmap->output_base = cpu_to_le32(bus_num << 8);
+idmap->flags = cpu_to_le32(0);
+
+map.iommu = pci_root_bus_has_iommu(bus);
+g_array_append_val(map_blob, map);
+}
+}
+
+return 0;
+}
+
 static void
 build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
 {
@@ -247,6 +283,21 @@ build_iort(GArray *table_data, BIOSLinker *linker, 
VirtMachineState *vms)
 AcpiIortSmmu3 *smmu;
 size_t node_size, iort_node_offset, iort_length, smmu_offset = 0;
 AcpiIortRC *rc;
+int smmu_mapping_count;
+GArray *map_blob = g_array_new(false, true, sizeof(AcpiIortMapping));
+AcpiIortMapping *map;
+
+/* pci_for_each_bus(vms->bus, insert_map, map_blob); */
+object_child_foreach_recursive(object_get_root(),
+   iort_host_bridges, map_blob);
+
+smmu_mapping_count = 0;
+for (int i = 0; i < map_blob->len; i++) {
+map = &g_array_index(map_blob, AcpiIortMapping, i);
+if (map->iommu) {
+smmu_mapping_count++;
+}
+}
 
 iort = acpi_data_push(table_data, sizeof(*iort));
 
@@ -280,13 +331,13 @@ build_iort(GArray *table_data, BIOSLinker *linker, 
VirtMachineState *vms)
 
 /* SMMUv3 node */
 smmu_offset = iort_node_offset + node_size;
-node_size = sizeof(*smmu) + sizeof(*idmap);
+node_size = sizeof(*smmu) + sizeof(*idmap) * smmu_mapping_count;
 iort_length += node_size;
 smmu = acpi_data_push(table_data, node_size);
 
 smmu->type = ACPI_IORT_NODE_SMMU_V3;
 smmu->length = cpu_to_le16(node_size);
-smmu->mapping_count = cpu_to_le32(1);
+smmu->mapping_count = cpu_to_le32(smmu_mapping_count);
 smmu->mapping_offset = cpu_to_le32(sizeof(*smmu));
 smmu->base_address = cpu_to_le64(vms->memmap[VIRT_SMMU].base);
 smmu->flags = cpu_to_le32(ACPI_IORT_SMMU_V3_COHACC_OVERRIDE);
@@ -295,23 +346,28 @@ build_iort(GArray *table_data, BIOSLinker *linker, 
VirtMachineState *vms)
 smmu->gerr_gsiv = cpu_to_le32(irq + 2);
 smmu->sync_gsiv = cpu_to_le32(irq + 3);
 
-/* Identity RID mapping covering the whole input RID range */
-idmap = &smmu->id_mapping_array[0];
-idmap->input_base = 0;
-idmap->id_count = cpu_to_le32(0x);
-idmap->output_base = 0;
-/* output IORT node is the ITS group node (the first node) */
-idmap->output_reference = cpu_to_le32(iort_node_offset);
+for (int i = 0, j = 0; i < map_blob->len; i++) {
+map = &g_array_index(map_blob, AcpiIortMapping, i);
+
+if (!map->iommu) {
+continue;
+}
+
+idmap = &smmu->id_mapping_array[j++];
+*idmap = map->idmap;
+/* output IORT node is the ITS group node (the first node) */
+idmap->output_reference = cpu_to_le32(iort_node_offset);
+}
 }
 
 /* Root Complex Node */
-node_size = sizeof(*rc) + sizeof(*idmap);
+node_size = sizeof(*rc) + sizeof(*idmap) * map_blob->len;
 iort_length += node_size;
 rc = acpi_data_push(table_data, node_size);
 
 rc->type = ACPI_IORT_NODE_PCI_ROOT_COMPLEX;
 rc->length = cpu_to_le16(node_size);
-rc->mapping_count = cpu_to_le32(1);
+rc->mapping_count = cpu_to_le32(map_

[PATCH RFC RESEND v2 6/6] hw/i386/acpi-build: Add iommu filter in IVRS table

2021-03-25 Thread Wang Xingang
From: Xingang Wang 

When building amd IVRS table, only devices attached to root bus with
IOMMU flag should be scanned.

Signed-off-by: Xingang Wang 
Signed-off-by: Jiahui Cen 
---
 hw/i386/acpi-build.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 6936889cad..e0f38305da 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -2229,7 +2229,7 @@ ivrs_host_bridges(Object *obj, void *opaque)
 if (object_dynamic_cast(obj, TYPE_PCI_HOST_BRIDGE)) {
 PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus;
 
-if (bus) {
+if (bus && pci_root_bus_has_iommu(bus)) {
 pci_for_each_device(bus, pci_bus_num(bus), insert_ivhd, ivhd_blob);
 }
 }
-- 
2.19.1




[PATCH RFC RESEND v2 5/6] hw/i386/acpi-build: Add explicit scope in DMAR table

2021-03-25 Thread Wang Xingang
From: Xingang Wang 

In DMAR table, the drhd is set to cover all pci devices when intel_iommu
is on. This patch add explicit scope data, including only the pci devices
that go through iommu.

Signed-off-by: Xingang Wang 
Signed-off-by: Jiahui Cen 
---
 hw/i386/acpi-build.c | 68 ++--
 1 file changed, 66 insertions(+), 2 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index de98750aef..6936889cad 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -1988,6 +1988,56 @@ build_srat(GArray *table_data, BIOSLinker *linker, 
MachineState *machine)
  x86ms->oem_table_id);
 }
 
+/*
+ * Insert DMAR scope for PCI bridges and endpoint devcie
+ */
+static void
+insert_scope(PCIBus *bus, PCIDevice *dev, void *opaque)
+{
+GArray *scope_blob = opaque;
+AcpiDmarDeviceScope *scope = NULL;
+
+if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_BRIDGE)) {
+/* Dmar Scope Type: 0x02 for PCI Bridge */
+build_append_int_noprefix(scope_blob, 0x02, 1);
+} else {
+/* Dmar Scope Type: 0x01 for PCI Endpoint Device */
+build_append_int_noprefix(scope_blob, 0x01, 1);
+}
+
+/* length */
+build_append_int_noprefix(scope_blob,
+  sizeof(*scope) + sizeof(scope->path[0]), 1);
+/* reserved */
+build_append_int_noprefix(scope_blob, 0, 2);
+/* enumeration_id */
+build_append_int_noprefix(scope_blob, 0, 1);
+/* bus */
+build_append_int_noprefix(scope_blob, pci_bus_num(bus), 1);
+/* device */
+build_append_int_noprefix(scope_blob, PCI_SLOT(dev->devfn), 1);
+/* function */
+build_append_int_noprefix(scope_blob, PCI_FUNC(dev->devfn), 1);
+}
+
+/* For all PCI host bridges, walk and insert DMAR scope */
+static int
+dmar_host_bridges(Object *obj, void *opaque)
+{
+GArray *scope_blob = opaque;
+
+if (object_dynamic_cast(obj, TYPE_PCI_HOST_BRIDGE)) {
+PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus;
+
+if (bus && pci_root_bus_has_iommu(bus)) {
+pci_for_each_device(bus, pci_bus_num(bus), insert_scope,
+scope_blob);
+}
+}
+
+return 0;
+}
+
 /*
  * VT-d spec 8.1 DMA Remapping Reporting Structure
  * (version Oct. 2014 or later)
@@ -2007,6 +2057,15 @@ build_dmar_q35(GArray *table_data, BIOSLinker *linker, 
const char *oem_id,
 /* Root complex IOAPIC use one path[0] only */
 size_t ioapic_scope_size = sizeof(*scope) + sizeof(scope->path[0]);
 IntelIOMMUState *intel_iommu = INTEL_IOMMU_DEVICE(iommu);
+GArray *scope_blob = g_array_new(false, true, 1);
+
+/*
+ * A PCI bus walk, for each PCI host bridge.
+ * Insert scope for each PCI bridge and endpoint device which
+ * is attached to a bus with iommu enabled.
+ */
+object_child_foreach_recursive(object_get_root(),
+   dmar_host_bridges, scope_blob);
 
 assert(iommu);
 if (x86_iommu_ir_supported(iommu)) {
@@ -2020,8 +2079,9 @@ build_dmar_q35(GArray *table_data, BIOSLinker *linker, 
const char *oem_id,
 /* DMAR Remapping Hardware Unit Definition structure */
 drhd = acpi_data_push(table_data, sizeof(*drhd) + ioapic_scope_size);
 drhd->type = cpu_to_le16(ACPI_DMAR_TYPE_HARDWARE_UNIT);
-drhd->length = cpu_to_le16(sizeof(*drhd) + ioapic_scope_size);
-drhd->flags = ACPI_DMAR_INCLUDE_PCI_ALL;
+drhd->length =
+cpu_to_le16(sizeof(*drhd) + ioapic_scope_size + scope_blob->len);
+drhd->flags = 0;/* Don't include all pci device */
 drhd->pci_segment = cpu_to_le16(0);
 drhd->address = cpu_to_le64(Q35_HOST_BRIDGE_IOMMU_ADDR);
 
@@ -2035,6 +2095,10 @@ build_dmar_q35(GArray *table_data, BIOSLinker *linker, 
const char *oem_id,
 scope->path[0].device = PCI_SLOT(Q35_PSEUDO_DEVFN_IOAPIC);
 scope->path[0].function = PCI_FUNC(Q35_PSEUDO_DEVFN_IOAPIC);
 
+/* Add scope found above */
+g_array_append_vals(table_data, scope_blob->data, scope_blob->len);
+g_array_free(scope_blob, true);
+
 if (iommu->dt_supported) {
 atsr = acpi_data_push(table_data, sizeof(*atsr));
 atsr->type = cpu_to_le16(ACPI_DMAR_TYPE_ATSR);
-- 
2.19.1




Re: [PATCH v4 00/11] 64bit block-layer: part II

2021-03-25 Thread Vladimir Sementsov-Ogievskiy

25.03.2021 00:13, no-re...@patchew.org wrote:

Patchew URL: 
https://patchew.org/QEMU/20210324205132.464899-1-vsement...@virtuozzo.com/



Hi,

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

Type: series
Message-id: 20210324205132.464899-1-vsement...@virtuozzo.com
Subject: [PATCH v4 00/11] 64bit block-layer: part II

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

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
 From https://github.com/patchew-project/qemu
  - [tag update]  patchew/20210323221539.3532660-1-cr...@redhat.com -> 
patchew/20210323221539.3532660-1-cr...@redhat.com
  * [new tag] patchew/20210324205132.464899-1-vsement...@virtuozzo.com 
-> patchew/20210324205132.464899-1-vsement...@virtuozzo.com
Switched to a new branch 'test'
bed608a block/io: allow 64bit discard requests
9b3b5c7 block: use int64_t instead of int in driver discard handlers
9d5776f block: make BlockLimits::max_pdiscard 64bit
1dc4bab block/io: allow 64bit write-zeroes requests
05ca540 block: use int64_t instead of int in driver write_zeroes handlers
5864b0d block: make BlockLimits::max_pwrite_zeroes 64bit
9698c13 block: use int64_t instead of uint64_t in copy_range driver handlers
4e60566 block: use int64_t instead of uint64_t in driver write handlers
8aa3af1 block: use int64_t instead of uint64_t in driver read handlers
fc695f9 qcow2: check request on vmstate save/load path
a13a9ef block/io: bring request check to bdrv_co_{read, write}v_vmstate

=== OUTPUT BEGIN ===
1/11 Checking commit a13a9efd128c (block/io: bring request check to 
bdrv_co_{read, write}v_vmstate)
ERROR: Author email address is mangled by the mailing list
#2:
Author: Vladimir Sementsov-Ogievskiy via 


That's a strange false-positive.

Look at 1/11: it's not mangled in any way. Looking at the source I see clean 
"From:" header:

  From: Vladimir Sementsov-Ogievskiy 

And there is no any "Author" in the message source at all. "qemu-devel" is 
noted only in Cc: list.



--
Best regards,
Vladimir



Re: [PATCH 2/3] aspeed: Add Scater-Gather support for HACE Hash

2021-03-25 Thread Cédric Le Goater
On 3/24/21 11:38 PM, Klaus Heinrich Kiwi wrote:
> Complement the Aspeed HACE support with Scatter-Gather hash support for
> sha256 and sha512. Scatter-Gather is only supported on AST2600-series.
> 
> Signed-off-by: Klaus Heinrich Kiwi 

this looks good. A few extra comments,

> ---
>  hw/misc/aspeed_hace.c | 127 --
>  include/hw/misc/aspeed_hace.h |   6 ++
>  2 files changed, 127 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/misc/aspeed_hace.c b/hw/misc/aspeed_hace.c
> index 93313d2b80..8a37b1d961 100644
> --- a/hw/misc/aspeed_hace.c
> +++ b/hw/misc/aspeed_hace.c
> @@ -57,6 +57,10 @@
>  /* Other cmd bits */
>  #define  HASH_IRQ_ENBIT(9)
>  #define  HASH_SG_EN BIT(18)
> +/* Scatter-gather data list */
> +#define  SG_LIST_LAST   BIT(31)
> +#define  SG_LIST_LEN_MASK   0x7fff
> +#define  SG_LIST_ADDR_MASK  0x7ff8  /* 8-byte aligned */
>  
>  static const struct {
>  uint32_t mask;
> @@ -129,6 +133,117 @@ static int do_hash_operation(AspeedHACEState *s, int 
> algo)
>  return 0;
>  }
>  
> +static int do_hash_sg_operation(AspeedHACEState *s, int algo)

Do we really care about the return value ? 

> +{
> +uint32_t src, dest, reqSize;
> +hwaddr len;
> +const size_t reqLen = sizeof(struct aspeed_sg_list);
> +struct iovec iov[ASPEED_HACE_MAX_SG];
> +unsigned int i = 0;
> +unsigned int isLast = 0;
> +uint8_t *digestBuf = NULL;
> +size_t digestLen = 0, size = 0;
> +struct aspeed_sg_list *sgList;
> +int rc;
> +
> +reqSize = s->regs[R_HASH_SRC_LEN];
> +dest = s->regs[R_HASH_DEST];
> +
> +while (!isLast && i < ASPEED_HACE_MAX_SG) {
> +src = s->regs[R_HASH_SRC] + (i * reqLen);
> +len = reqLen;
> +sgList = (struct aspeed_sg_list *) address_space_map(&s->dram_as,
> + src,
> + (hwaddr *) &len,
> +   false,
> + MEMTXATTRS_UNSPECIFIED);

This should be doing LE loads.

> +if (!sgList) {
> +qemu_log_mask(LOG_GUEST_ERROR,
> + "%s: failed to map dram for SG Array entry '%u' for address 
> '0x%0x'\n",
> + __func__, i, src);
> +rc = -EACCES;
> +goto cleanup;
> +}
> +if (len != reqLen)
> +qemu_log_mask(LOG_GUEST_ERROR,
> + "%s:  Warning: dram map for SG array entry '%u' requested size 
> '%lu' != mapped size '%lu'\n",
> + __func__, i, reqLen, len);
> +
> +isLast = sgList->len & SG_LIST_LAST;
> +
> +iov[i].iov_len = (hwaddr) (sgList->len & SG_LIST_LEN_MASK);
> +iov[i].iov_base = address_space_map(&s->dram_as,
> +sgList->phy_addr & SG_LIST_ADDR_MASK,
> +&iov[i].iov_len, false,
> +MEMTXATTRS_UNSPECIFIED);
> +if (!iov[i].iov_base) {
> +qemu_log_mask(LOG_GUEST_ERROR,
> + "%s: failed to map dram for SG array entry '%u' for region 
> '0x%x', len '%u'\n",
> + __func__, i, sgList->phy_addr & SG_LIST_ADDR_MASK,
> + sgList->len & SG_LIST_LEN_MASK);
> +rc = -EACCES;
> +goto cleanup;
> +}
> +if (iov[i].iov_len != (sgList->len & SG_LIST_LEN_MASK))
> +qemu_log_mask(LOG_GUEST_ERROR,
> + "%s:  Warning: dram map for SG region entry %u requested size 
> %u != mapped size %lu\n",
> + __func__, i, (sgList->len & SG_LIST_LEN_MASK), iov[i].iov_len);
> +
> +
> +address_space_unmap(&s->dram_as, (void *) sgList, len, false,
> +len);
> +size += iov[i].iov_len;
> +i++;
> +}
> +
> +if (!isLast) {
> +qemu_log_mask(LOG_GUEST_ERROR,
> + "%s: Error: Exhausted maximum of '%u' SG array 
> entries\n",
> + __func__, ASPEED_HACE_MAX_SG);
> +rc = -ENOTSUP;
> +goto cleanup;
> +}
> +
> +if (size != reqSize)
> +qemu_log_mask(LOG_GUEST_ERROR,
> + "%s: Warning: requested SG total size %u != actual size %lu\n",
> + __func__, reqSize, size);
> +
> +rc = qcrypto_hash_bytesv(algo, iov, i, &digestBuf, &digestLen,
> +&error_fatal);
> +if (rc < 0) {
> +qemu_log_mask(LOG_GUEST_ERROR, "%s: qcrypto failed\n",
> +  __func__);
> +goto cleanup;
> +}
> +
> +rc = address_space_write(&s->dram_as, dest, MEMTXATTRS_UNSPECIFIED,
> + digestBuf, digestLen);
> +if (rc)
> +qemu_log_mask(LOG_GUEST_ERROR,
> +  "%s: address space write failed\n", __func__);
> +g_free(digestBuf);
> +
> +cleanup:
> +
> +for

Re: [PATCH v4 00/11] 64bit block-layer: part II

2021-03-25 Thread Vladimir Sementsov-Ogievskiy

25.03.2021 10:42, Vladimir Sementsov-Ogievskiy wrote:

25.03.2021 00:13, no-re...@patchew.org wrote:

Patchew URL: 
https://patchew.org/QEMU/20210324205132.464899-1-vsement...@virtuozzo.com/



Hi,

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

Type: series
Message-id: 20210324205132.464899-1-vsement...@virtuozzo.com
Subject: [PATCH v4 00/11] 64bit block-layer: part II

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

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
 From https://github.com/patchew-project/qemu
  - [tag update]  patchew/20210323221539.3532660-1-cr...@redhat.com -> 
patchew/20210323221539.3532660-1-cr...@redhat.com
  * [new tag] patchew/20210324205132.464899-1-vsement...@virtuozzo.com 
-> patchew/20210324205132.464899-1-vsement...@virtuozzo.com
Switched to a new branch 'test'
bed608a block/io: allow 64bit discard requests
9b3b5c7 block: use int64_t instead of int in driver discard handlers
9d5776f block: make BlockLimits::max_pdiscard 64bit
1dc4bab block/io: allow 64bit write-zeroes requests
05ca540 block: use int64_t instead of int in driver write_zeroes handlers
5864b0d block: make BlockLimits::max_pwrite_zeroes 64bit
9698c13 block: use int64_t instead of uint64_t in copy_range driver handlers
4e60566 block: use int64_t instead of uint64_t in driver write handlers
8aa3af1 block: use int64_t instead of uint64_t in driver read handlers
fc695f9 qcow2: check request on vmstate save/load path
a13a9ef block/io: bring request check to bdrv_co_{read, write}v_vmstate

=== OUTPUT BEGIN ===
1/11 Checking commit a13a9efd128c (block/io: bring request check to 
bdrv_co_{read, write}v_vmstate)
ERROR: Author email address is mangled by the mailing list
#2:
Author: Vladimir Sementsov-Ogievskiy via 


That's a strange false-positive.

Look at 1/11: it's not mangled in any way. Looking at the source I see clean 
"From:" header:

   From: Vladimir Sementsov-Ogievskiy 

And there is no any "Author" in the message source at all. "qemu-devel" is 
noted only in Cc: list.



Hmm, but if look at mail on patchew, 
https://patchew.org/QEMU/20210324205132.464899-1-vsement...@virtuozzo.com/20210324205132.464899-2-vsement...@virtuozzo.com/
yes it is mangled..

I hope everyone who is in CC (as me) gets this email not-mangled.

--
Best regards,
Vladimir



Re: [PATCH 1/2] spapr: number of SMP sockets must be equal to NUMA nodes

2021-03-25 Thread Cédric Le Goater
On 3/25/21 3:10 AM, David Gibson wrote:
> On Tue, Mar 23, 2021 at 02:21:33PM -0300, Daniel Henrique Barboza wrote:
>>
>>
>> On 3/22/21 10:03 PM, David Gibson wrote:
>>> On Fri, Mar 19, 2021 at 03:34:52PM -0300, Daniel Henrique Barboza wrote:
 Kernel commit 4bce545903fa ("powerpc/topology: Update
 topology_core_cpumask") cause a regression in the pseries machine when
 defining certain SMP topologies [1]. The reasoning behind the change is
 explained in kernel commit 4ca234a9cbd7 ("powerpc/smp: Stop updating
 cpu_core_mask"). In short, cpu_core_mask logic was causing troubles with
 large VMs with lots of CPUs and was changed by cpu_cpu_mask because, as
 far as the kernel understanding of SMP topologies goes, both masks are
 equivalent.

 Further discussions in the kernel mailing list [2] shown that the
 powerpc kernel always considered that the number of sockets were equal
 to the number of NUMA nodes. The claim is that it doesn't make sense,
 for Power hardware at least, 2+ sockets being in the same NUMA node. The
 immediate conclusion is that all SMP topologies the pseries machine were
 supplying to the kernel, with more than one socket in the same NUMA node
 as in [1], happened to be correctly represented in the kernel by
 accident during all these years.

 There's a case to be made for virtual topologies being detached from
 hardware constraints, allowing maximum flexibility to users. At the same
 time, this freedom can't result in unrealistic hardware representations
 being emulated. If the real hardware and the pseries kernel don't
 support multiple chips/sockets in the same NUMA node, neither should we.

 Starting in 6.0.0, all sockets must match an unique NUMA node in the
 pseries machine. qtest changes were made to adapt to this new
 condition.
>>>
>>> Oof.  I really don't like this idea.  It means a bunch of fiddly work
>>> for users to match these up, for no real gain.  I'm also concerned
>>> that this will require follow on changes in libvirt to not make this a
>>> really cryptic and irritating point of failure.
>>
>> Haven't though about required Libvirt changes, although I can say that there
>> will be some amount to be mande and it will probably annoy existing users
>> (everyone that has a multiple socket per NUMA node topology).
>>
>> There is not much we can do from the QEMU layer aside from what I've proposed
>> here. The other alternative is to keep interacting with the kernel folks to
>> see if there is a way to keep our use case untouched.
> 
> Right.  Well.. not necessarily untouched, but I'm hoping for more
> replies from Cédric to my objections and mpe's.  Even with sockets
> being a kinda meaningless concept in PAPR, I don't think tying it to
> NUMA nodes makes sense.

I did a couple of replies in different email threads but maybe not 
to all. I felt it was going nowhere :/ Couple of thoughts,

Shouldn't we get rid of the socket concept, die also, under pseries 
since they don't exist under PAPR ? We only have numa nodes, cores, 
threads AFAICT.

Should we diverged from PAPR and add extra DT properties "qemu,..." ?
There are a couple of places where Linux checks for the underlying 
hypervisor already.

>> This also means that
>> 'ibm,chip-id' will probably remain in use since it's the only place where
>> we inform cores per socket information to the kernel.
> 
> Well.. unless we can find some other sensible way to convey that
> information.  I haven't given up hope for that yet.

Well, we could start by fixing the value in QEMU. It is broken today.


This is all coming from some work we did last year to evaluate our HW 
(mostly for XIVE) on 2s, 4s, 16s systems on baremetal, KVM and PowerVM. 
We saw some real problems because Linux did not have a clear view of the 
topology. See the figures here : 

http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20210303174857.1760393-9-...@kaod.org/

The node id is a key parameter for system resource management, memory 
allocation, interrupt affinity, etc. Linux scales much better if used
correctly. 

C.



Re: [RFC PATCH v2 0/3] virtio-net: graceful drop of vhost for TAP

2021-03-25 Thread Yuri Benditovich
Hi Jason,

This was discussed earlier on the previous series of patches.
https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg01829.html
There were strong objections from both Daniel and Michael and I feel
that the series was rejected.
There was Michael's claim:
"We did what this patch is trying to change for years now, in
particular KVM also seems to happily disable CPU features not supported
by kernel so I wonder why we can't keep doing it, with tweaks for some
corner cases."
https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg03187.html
And it was Michael's question:
"Can we limit the change to when a VM is migrated in?"
https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg03163.html
So I'm trying to suggest another approach:
- In case of conflicting features (for example RSS and vhost) we in
qemu we do not have enough information to prefer one or another.
- If we drop to userspace in the first set_features we say: "vhost is
less important than other requested features"
- This series keeps backward compatibility, i.e. if you start with
vhost and some features are not available - they are silently cleared.
- But in case the features are available on source machine - they are used
- In case of migration this series says: "We prefer successful
migration even if for that we need to drop to userspace"
- On the migration back to the 1st system we again work with all the
features and with vhost as all the features are available.

Thanks,
Yuri



On Thu, Mar 25, 2021 at 8:59 AM Jason Wang  wrote:
>
>
> 在 2021/3/22 下午8:24, Yuri Benditovich 写道:
> > Allow fallback to userspace only upon migration, only for specific features
> > and only if 'vhostforce' is not requested.
> >
> > Changes from v1:
> > Patch 1 dropeed (will be submitted in another series)
> > Added device callback in case the migration should fail due to missing 
> > features
>
>
> Hi Yuri:
>
> Have a quick glance at the series. A questions is why we need to do the
> fallback only during load?
>
> I think we should do it in the device initializating. E.g when the vhost
> features can not satisfy, we should disable vhost since there.
>
> Thanks
>
>
> >
> > Yuri Benditovich (3):
> >net: add ability to hide (disable) vhost_net
> >virtio: introduce 'missing_features_migrated' device callback
> >virtio-net: implement missing_features_migrated callback
> >
> >   hw/net/vhost_net.c |  4 ++-
> >   hw/net/virtio-net.c| 51 ++
> >   hw/virtio/virtio.c |  8 ++
> >   include/hw/virtio/virtio.h |  8 ++
> >   include/net/net.h  |  1 +
> >   5 files changed, 71 insertions(+), 1 deletion(-)
> >
>



Re: gitlab-ci: Only build /staging branch?

2021-03-25 Thread Philippe Mathieu-Daudé
On 3/25/21 6:43 AM, Thomas Huth wrote:
> On 24/03/2021 22.58, Philippe Mathieu-Daudé wrote:
>> On 3/24/21 7:33 PM, Philippe Mathieu-Daudé wrote:
>>> On 3/24/21 7:01 PM, Philippe Mathieu-Daudé wrote:
 Hi,

 Peter's current workflow is push to /staging and if his
 testing succeeds, he pushes the same commit as /master.

 IMO there is no point in building /master branch, as it
 has already been built earlier as /staging.
>>
>> Similarly with tags. Although we don't tag often.
> 
> Tags are used for pull-requests. So I think we should run the whole CI
> for tags, to make it clear that a pull-request always includes code that
> builds fine.

Sorry the context was not clear :/

This is only relevant for the qemu-project/qemu gitlab namespace.

v6.0 is at the door and I was wondering what is missing to have the
CI used as a gate.

- Stefan/Paolo moved the main repository location.

- Alex made yet another effort to get the CI pipeline green again.

- IIRC Peter said waiting 2h after pushing /staging is too long.
Currently worst case it takes ~2h25 between one /staging and the
next one, simply because /master is rebuilt in the middle. If we
remove /master we have ~1h15 per /staging pipeline.

- I don't remember what is missing from Cleber script, maybe we can
use it as it without waiting for a respin?

We have never been that close, but we are not there yet...

Regards,

Phil.



Re: [PATCH V2] target/riscv: Align the data type of reset vector address

2021-03-25 Thread Dylan Jhong
Hi All,

Please ignore this patch.
There is a compile error while building 32bit qemu.

The error occurs in ./target/riscv/cpu.c:557  
"DEFINE_PROP_UINT64("resetvec", RISCVCPU, cfg.resetvec, DEFAULT_RSTVEC)"

It should be written differently according to 32bit or 64bit machine.

I'll send patch v3 to fix this issue.
Sorry for my mistake.

Regards,
Dylan

On Thu, Mar 25, 2021 at 01:52:13PM +0800, Dylan Dai-Rong Jhong(鍾岱融) wrote:
> Signed-off-by: Dylan Jhong 
> Signed-off-by: Ruinland ChuanTzu Tsai 
> ---
>  target/riscv/cpu.c | 2 +-
>  target/riscv/cpu.h | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> index 7d6ed80f6b..4ac901245a 100644
> --- a/target/riscv/cpu.c
> +++ b/target/riscv/cpu.c
> @@ -137,7 +137,7 @@ static void set_feature(CPURISCVState *env, int feature)
>  env->features |= (1ULL << feature);
>  }
>  
> -static void set_resetvec(CPURISCVState *env, int resetvec)
> +static void set_resetvec(CPURISCVState *env, target_ulong resetvec)
>  {
>  #ifndef CONFIG_USER_ONLY
>  env->resetvec = resetvec;
> diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> index 0a33d387ba..d9d7891666 100644
> --- a/target/riscv/cpu.h
> +++ b/target/riscv/cpu.h
> @@ -303,7 +303,7 @@ struct RISCVCPU {
>  uint16_t elen;
>  bool mmu;
>  bool pmp;
> -uint64_t resetvec;
> +target_ulong resetvec;
>  } cfg;
>  };
>  
> -- 
> 2.17.1
> 



Re: [PATCH 05/15] Hexagon (target/hexagon) change variables from int to bool when appropriate

2021-03-25 Thread Philippe Mathieu-Daudé
Hi Taylor,

On 3/25/21 3:50 AM, Taylor Simpson wrote:
> Address feedback from Richard Henderson 

If you look at the git history, we use the following tags:
- Reported-by: Richard Henderson 
- Suggested-by: Richard Henderson 
and tools know how to use them:
https://repo.or.cz/git-dm.git/blob/5ccc4dac6837:/gitdm#l292
(same comment applies to other patches in your series).

That said,
Reviewed-by: Philippe Mathieu-Daudé 

> 
> Signed-off-by: Taylor Simpson 
> ---
>  target/hexagon/cpu_bits.h  |  2 +-
>  target/hexagon/decode.c| 80 
> +++---
>  target/hexagon/insn.h  | 21 ++--
>  target/hexagon/op_helper.c |  8 ++---
>  target/hexagon/translate.c |  6 ++--
>  target/hexagon/translate.h |  2 +-
>  6 files changed, 60 insertions(+), 59 deletions(-)



Re: [PATCH v4 09/14] util/mmap-alloc: Pass flags instead of separate bools to qemu_ram_mmap()

2021-03-25 Thread David Hildenbrand

On 23.03.21 21:49, Peter Xu wrote:

On Fri, Mar 19, 2021 at 11:12:25AM +0100, David Hildenbrand wrote:

Let's pass flags instead of bools to prepare for passing other flags and
update the documentation of qemu_ram_mmap(). Introduce new QEMU_MAP_
flags that abstract the mmap() PROT_ and MAP_ flag handling and simplify
it.

We expose only flags that are currently supported by qemu_ram_mmap().
Maybe, we'll see qemu_mmap() in the future as well that can implement these
flags.

Note: We don't use MAP_ flags as some flags (e.g., MAP_SYNC) are only
defined for some systems and we want to always be able to identify
these flags reliably inside qemu_ram_mmap() -- for example, to properly
warn when some future flags are not available or effective on a system.
Also, this way we can simplify PROT_ handling as well.

Signed-off-by: David Hildenbrand 
---
  include/qemu/mmap-alloc.h | 16 +---
  include/qemu/osdep.h  | 18 ++
  softmmu/physmem.c |  8 +---
  util/mmap-alloc.c | 15 ---
  util/oslib-posix.c|  3 ++-
  5 files changed, 42 insertions(+), 18 deletions(-)

diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h
index 456ff87df1..a60a2085b3 100644
--- a/include/qemu/mmap-alloc.h
+++ b/include/qemu/mmap-alloc.h
@@ -7,18 +7,22 @@ size_t qemu_fd_getpagesize(int fd);
  size_t qemu_mempath_getpagesize(const char *mem_path);
  
  /**

- * qemu_ram_mmap: mmap the specified file or device.
+ * qemu_ram_mmap: mmap anonymous memory, the specified file or device.
+ *
+ * mmap() abstraction to map guest RAM, simplifying flag handling, taking
+ * care of alignment requirements and installing guard pages.
   *
   * Parameters:
   *  @fd: the file or the device to mmap
   *  @size: the number of bytes to be mmaped
   *  @align: if not zero, specify the alignment of the starting mapping 
address;
   *  otherwise, the alignment in use will be determined by QEMU.
- *  @readonly: true for a read-only mapping, false for read/write.
- *  @shared: map has RAM_SHARED flag.
- *  @is_pmem: map has RAM_PMEM flag.
+ *  @qemu_map_flags: QEMU_MAP_* flags
   *  @map_offset: map starts at offset of map_offset from the start of fd
   *
+ * Internally, MAP PRIVATE, MAP_ANONYMOUS and MAP_SHARED_VALIDATE are set

  ^
  |
  + underscore



Nice catch, thanks :)


--
Thanks,

David / dhildenb




[PATCH V3] target/riscv: Align the data type of reset vector address

2021-03-25 Thread Dylan Jhong
Signed-off-by: Dylan Jhong 
Signed-off-by: Ruinland ChuanTzu Tsai 
---
 target/riscv/cpu.c | 6 +-
 target/riscv/cpu.h | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 7d6ed80f6b..8a5f18bcb0 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -137,7 +137,7 @@ static void set_feature(CPURISCVState *env, int feature)
 env->features |= (1ULL << feature);
 }
 
-static void set_resetvec(CPURISCVState *env, int resetvec)
+static void set_resetvec(CPURISCVState *env, target_ulong resetvec)
 {
 #ifndef CONFIG_USER_ONLY
 env->resetvec = resetvec;
@@ -554,7 +554,11 @@ static Property riscv_cpu_properties[] = {
 DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64),
 DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true),
 DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
+#if defined(TARGET_RISCV32)
+DEFINE_PROP_UINT32("resetvec", RISCVCPU, cfg.resetvec, DEFAULT_RSTVEC),
+#elif defined(TARGET_RISCV64)
 DEFINE_PROP_UINT64("resetvec", RISCVCPU, cfg.resetvec, DEFAULT_RSTVEC),
+#endif
 DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index 0a33d387ba..d9d7891666 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -303,7 +303,7 @@ struct RISCVCPU {
 uint16_t elen;
 bool mmu;
 bool pmp;
-uint64_t resetvec;
+target_ulong resetvec;
 } cfg;
 };
 
-- 
2.17.1




Re: gitlab-ci: Only build /staging branch?

2021-03-25 Thread Philippe Mathieu-Daudé
On 3/25/21 10:29 AM, Philippe Mathieu-Daudé wrote:
> On 3/25/21 6:43 AM, Thomas Huth wrote:
>> On 24/03/2021 22.58, Philippe Mathieu-Daudé wrote:
>>> On 3/24/21 7:33 PM, Philippe Mathieu-Daudé wrote:
 On 3/24/21 7:01 PM, Philippe Mathieu-Daudé wrote:
> Hi,
>
> Peter's current workflow is push to /staging and if his
> testing succeeds, he pushes the same commit as /master.
>
> IMO there is no point in building /master branch, as it
> has already been built earlier as /staging.
>>>
>>> Similarly with tags. Although we don't tag often.
>>
>> Tags are used for pull-requests. So I think we should run the whole CI
>> for tags, to make it clear that a pull-request always includes code that
>> builds fine.
> 
> Sorry the context was not clear :/
> 
> This is only relevant for the qemu-project/qemu gitlab namespace.
> 
> v6.0 is at the door and I was wondering what is missing to have the
> CI used as a gate.
> 
> - Stefan/Paolo moved the main repository location.
> 
> - Alex made yet another effort to get the CI pipeline green again.
> 
> - IIRC Peter said waiting 2h after pushing /staging is too long.
> Currently worst case it takes ~2h25 between one /staging and the
> next one, simply because /master is rebuilt in the middle. If we
> remove /master we have ~1h15 per /staging pipeline.
> 
> - I don't remember what is missing from Cleber script, maybe we can
> use it as it without waiting for a respin?

As someone else is caring about this, please disregard this thread
and its questions/suggestions.

Regards,

Phil.



Re: [PULL 0/2] Block patches

2021-03-25 Thread Stefan Hajnoczi
On Wed, Mar 24, 2021 at 08:42:27PM +, Peter Maydell wrote:
> On Wed, 24 Mar 2021 at 20:18, Vladimir Sementsov-Ogievskiy
>  wrote:
> >
> > 24.03.2021 21:05, Peter Maydell wrote:
> > > On Wed, 24 Mar 2021 at 14:52, Stefan Hajnoczi  wrote:
> > >>
> > >> Vladimir Sementsov-Ogievskiy (2):
> > >>migration/block-dirty-bitmap: make incoming disabled bitmaps busy
> > >>migrate-bitmaps-postcopy-test: check that we can't remove in-flight
> > >>  bitmaps
> > >
> > > This failed the 'qsd-jobs' iotest on s390x:
> 
> > I can't believe it related. My commit modifies bitmap status during bitmaps 
> > migration on target vm. There is no kind of migration in qsd-jobs test.
> 
> It's possible it's an intermittent, but it's not one I've seen
> before. We still have lots of time this release cycle to figure
> out the issue and get this fix in.

Vladimir: I'll get hold of an s390 machine and try to reproduce the
failure. I should have some news by Monday.

Let's put the pull request on hold for now.

Stefan


signature.asc
Description: PGP signature


[PATCH 0/1] avocado-qemu: New SMMUv3 tests

2021-03-25 Thread Eric Auger
This patch adds a first set of SMMU functional tests using
a Fedora cloud-init image. Given the kernel in use,
range invalidation is not tested yet. However different
guest kernel configurations are tested: standard, strict=0
and passthrough mode.

The patch applies on top of Cleber's series:
PATCH v2 00/10] Acceptance Test: introduce base class for
Linux based tests.

Special thanks to Cleber for his support on this first
trial.

Best Regards

Eric

Eric Auger (1):
  avocado_qemu: Add SMMUv3 tests

 tests/acceptance/smmu.py | 104 +++
 1 file changed, 104 insertions(+)
 create mode 100644 tests/acceptance/smmu.py

-- 
2.26.2




[PATCH 1/1] avocado_qemu: Add SMMUv3 tests

2021-03-25 Thread Eric Auger
Add new tests checking the good behavior of the SMMUv3 protecting
2 virtio pci devices (block and net). We check the guest boots and
we are able to install a package. Different guest configs are tested:
standard, passthrough an strict=0. Given the version of the guest
kernel in use (5.3.7 at this moment), range invalidation is not yet
tested. This will be handled separately.

Signed-off-by: Eric Auger 
---
 tests/acceptance/smmu.py | 104 +++
 1 file changed, 104 insertions(+)
 create mode 100644 tests/acceptance/smmu.py

diff --git a/tests/acceptance/smmu.py b/tests/acceptance/smmu.py
new file mode 100644
index 00..65ecac8f1a
--- /dev/null
+++ b/tests/acceptance/smmu.py
@@ -0,0 +1,104 @@
+# SMMUv3 Functional tests
+#
+# Copyright (c) 2021 Red Hat, Inc.
+#
+# Author:
+#  Eric Auger 
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or
+# later.  See the COPYING file in the top-level directory.
+
+import os
+
+from avocado_qemu import LinuxTest, BUILD_DIR
+from avocado.utils import ssh
+
+class SMMU(LinuxTest):
+
+KERNEL_COMMON_PARAMS = ("root=UUID=b6950a44-9f3c-4076-a9c2-355e8475b0a7 ro 
"
+"earlyprintk=pl011,0x900 ignore_loglevel "
+"no_timer_check printk.time=1 rd_NO_PLYMOUTH "
+"console=ttyAMA0 ")
+IOMMU_ADDON = ',iommu_platform=on,disable-modern=off,disable-legacy=on'
+IMAGE = ("https://archives.fedoraproject.org/pub/archive/fedora/";
+ "linux/releases/31/Everything/aarch64/os/images/pxeboot/")
+kernel_path = None
+initrd_path = None
+kernel_params = None
+
+def set_up_boot(self):
+path = self.download_boot()
+self.vm.add_args('-device', 'virtio-blk-pci,bus=pcie.0,scsi=off,' +
+ 'drive=drv0,id=virtio-disk0,bootindex=1,'
+ 'werror=stop,rerror=stop' + self.IOMMU_ADDON)
+self.vm.add_args('-drive',
+ 'file=%s,if=none,cache=writethrough,id=drv0' % path)
+
+def setUp(self):
+super(SMMU, self).setUp(None, 'virtio-net-pci' + self.IOMMU_ADDON)
+
+def add_common_args(self):
+self.vm.add_args("-machine", "virt")
+self.vm.add_args('-bios', os.path.join(BUILD_DIR, 'pc-bios',
+  'edk2-aarch64-code.fd'))
+self.vm.add_args('-device', 'virtio-rng-pci,rng=rng0')
+self.vm.add_args('-object',
+ 'rng-random,id=rng0,filename=/dev/urandom')
+
+def common_vm_setup(self, custom_kernel=None):
+self.require_accelerator("kvm")
+self.add_common_args()
+self.vm.add_args("-accel", "kvm")
+self.vm.add_args("-cpu", "host")
+self.vm.add_args("-machine", "iommu=smmuv3")
+
+if custom_kernel is None:
+return
+
+kernel_url = self.IMAGE + 'vmlinuz'
+initrd_url = self.IMAGE + 'initrd.img'
+self.kernel_path = self.fetch_asset(kernel_url)
+self.initrd_path = self.fetch_asset(initrd_url)
+
+def run_and_check(self):
+if self.kernel_path:
+self.vm.add_args('-kernel', self.kernel_path,
+ '-append', self.kernel_params,
+ '-initrd', self.initrd_path)
+self.launch_and_wait()
+self.ssh_command('cat /proc/cmdline')
+self.ssh_command('dnf -y install numactl-devel')
+
+def test_smmu(self):
+"""
+:avocado: tags=accel:kvm
+:avocado: tags=cpu:host
+:avocado: tags=smmu
+"""
+
+self.common_vm_setup()
+self.run_and_check()
+
+def test_smmu_passthrough(self):
+"""
+:avocado: tags=accel:kvm
+:avocado: tags=cpu:host
+:avocado: tags=smmu
+"""
+self.common_vm_setup(True)
+
+self.kernel_params = self.KERNEL_COMMON_PARAMS + 'iommu.passthrough=on'
+
+self.run_and_check()
+
+def test_smmu_nostrict(self):
+"""
+:avocado: tags=accel:kvm
+:avocado: tags=cpu:host
+:avocado: tags=smmu
+"""
+self.common_vm_setup(True)
+
+self.kernel_params = self.KERNEL_COMMON_PARAMS + 'iommu.strict=0'
+
+self.run_and_check()
-- 
2.26.2




Re: [PATCH v1 0/3] migration: Fixes to the 'background-snapshot' code

2021-03-25 Thread Andrey Gruzdev

On 24.03.2021 18:41, Peter Xu wrote:

On Wed, Mar 24, 2021 at 11:09:27AM +0300, Andrey Gruzdev wrote:

I'm also looking into introducing UFFD_FEATURE_WP_UNALLOCATED so as to
wr-protect page holes too for a uffd-wp region when the feature bit is set.
With that feature we should be able to avoid pre-fault as what we do in the
last patch of this series.  However even if that can work out, we'll still need
this for old kernel anyways.

I'm curious this new feature is based on adding wr-protection at the level of 
VMAs,
so we won't miss write faults for missing pages?

I think we can do it with multiple ways.

The most efficient one would be wr-protect the range during uffd-wp
registration, so as you said it'll be per-vma attribute.  However that'll
change the general semantics of uffd-wp as normally we need registration and
explicit wr-protect.  Then it'll still be pte-based for faulted in pages (the
ones we wr-protected during registration will still be), however for the rest
it'll become vma-based.  It's indeed a bit confusing.

The other way is we can fault in zero page during UFFDIO_WRITEPROTECT.  However
that's less efficient, since it's close to pre-fault on read but it's just
slightly more cleaner than doing it in userspace.  When I rethink about this it
may not worth it to do in kernel if userspace can achieve things similar.

So let's stick with current solution; that idea may need more thoughts..

Thanks,

Agree, let's stick with current solution. For the future I think having 
a registration

flag like WP_MISSING to induce per-vma wr-protection is not a bad choice.

The reason is that usage of UFFDIO_WRITEPROTECT ioctl is often 
asymmetrical; we usually

write-protect the whole registration range but un-protect by small chunks.

So if we stay with current current symmetric protect/un-protect API but 
add the registration

flag to handle protection for unpopulated pages - that may be worth to do.

--
Andrey Gruzdev, Principal Engineer
Virtuozzo GmbH  +7-903-247-6397
virtuzzo.com




Re: [PATCH] qapi: introduce 'query-cpu-model-cpuid' action

2021-03-25 Thread Vladimir Sementsov-Ogievskiy

24.03.2021 16:39, Valeriy Vdovin wrote:

Introducing new qapi method 'query-cpu-model-cpuid'. This method can be used to
get virtualized cpu model info generated by QEMU during VM initialization in
the form of cpuid representation.

Diving into more details about virtual cpu generation: QEMU first parses '-cpu'
command line option. From there it takes the name of the model as the basis for
feature set of the new virtual cpu. After that it uses trailing '-cpu' options,
that state if additional cpu features should be present on the virtual cpu or
excluded from it (tokens '+'/'-' or '=on'/'=off').
After that QEMU checks if the host's cpu can actually support the derived
feature set and applies host limitations to it.
After this initialization procedure, virtual cpu has it's model and
vendor names, and a working feature set and is ready for identification
instructions such as CPUID.

Currently full output for this method is only supported for x86 cpus.

To learn exactly how virtual cpu is presented to the guest machine via CPUID
instruction, new qapi method can be used. By calling 'query-cpu-model-cpuid'
method, one can get a full listing of all CPUID leafs with subleafs which are
supported by the initialized virtual cpu.

Other than debug, the method is useful in cases when we would like to
utilize QEMU's virtual cpu initialization routines and put the retrieved
values into kernel CPUID overriding mechanics for more precise control
over how various processes perceive its underlying hardware with
container processes as a good example.

Output format:
The core part of the returned JSON object can be described as a list of lists
with top level list contains leaf-level elements and the bottom level
containing subleafs, where 'leaf' is CPUID argument passed in EAX register and
'subleaf' is a value passed to CPUID in ECX register for some specific
leafs, that support that. Each most basic CPUID result is passed in a
maximum of 4 registers EAX, EBX, ECX and EDX, with most leafs not utilizing
all 4 registers at once.
Also note that 'subleaf' is a kind of extension, used by only a couple of
leafs, while most of the leafs don't have this. Nevertheless, the output
data structure presents ALL leafs as having at least a single 'subleaf'.
This is done for data structure uniformity, so that it could be
processed in a more straightforward manner, in this case no one suffers
from such simplification.

Use example:
virsh qemu-monitor-command VM --pretty '{ "execute": "query-cpu-model-cpuid" }'
{
   "return": {
 "cpuid": {
   "leafs": [
 {
   "leaf": 0,
   "subleafs": [
 {
   "eax": 13,
   "edx": 1231384169,
   "ecx": 1818588270,
   "ebx": 1970169159,
   "subleaf": 0
 }
   ]
 },
 {
   "leaf": 1,
   "subleafs": [
 {
   "eax": 329443,
   "edx": 529267711,
   "ecx": 4160369187,
   "ebx": 133120,
   "subleaf": 0
 }
   ]
 },
 {
   "leaf": 2,
   "subleafs": [
 {
   "eax": 1,
   "edx": 2895997,
   "ecx": 0,
   "ebx": 0,
   "subleaf": 0
 }
   ]
 },
   ]
 },
 "vendor": "GenuineIntel",
 "class-name": "Skylake-Client-IBRS-x86_64-cpu",
 "model-id": "Intel Core Processor (Skylake, IBRS)"
   },
   "id": "libvirt-40"
}
Signed-off-by: Valeriy Vdovin 
---
  qapi/machine-target.json | 122 
  target/i386/cpu.c| 292 +--
  2 files changed, 405 insertions(+), 9 deletions(-)

diff --git a/qapi/machine-target.json b/qapi/machine-target.json
index e7811654b7..c5b137aa5c 100644
--- a/qapi/machine-target.json
+++ b/qapi/machine-target.json
@@ -329,3 +329,125 @@
  ##
  { 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'],
'if': 'defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_I386) 
|| defined(TARGET_S390X) || defined(TARGET_MIPS)' }
+##
+
+
+# @CpuidSubleaf:
+#
+# CPUID leaf extension information, based on ECX value.
+#
+# CPUID x86 instruction has 'leaf' argument passed in EAX register. Leaf
+# argument identifies the type of information, the caller wants to retrieve in
+# single call to CPUID.
+# Some but not all leaves depend on the value passed in ECX register as an
+# additional argument to CPUID. This argument is present in cpuid documentation
+# as 'subleaf'.
+# If CPUID ignores the value in ECX, normally this means that leaf does not
+# have subleaves. Another way to see it is that each leaf has at least one
+# subleaf (one type of output).
+#
+# @subleaf: value passed to CPUID in ECX register. If CPUID leaf has only a
+#   single leaf, the value of ECX is ignored by CPU and should as well
+#   be ignored in this field.
+# @eax: value in eax af

Re: [PATCH 1/2] spapr: number of SMP sockets must be equal to NUMA nodes

2021-03-25 Thread Daniel Henrique Barboza




On 3/25/21 5:56 AM, Cédric Le Goater wrote:

On 3/25/21 3:10 AM, David Gibson wrote:

On Tue, Mar 23, 2021 at 02:21:33PM -0300, Daniel Henrique Barboza wrote:



On 3/22/21 10:03 PM, David Gibson wrote:

On Fri, Mar 19, 2021 at 03:34:52PM -0300, Daniel Henrique Barboza wrote:

Kernel commit 4bce545903fa ("powerpc/topology: Update
topology_core_cpumask") cause a regression in the pseries machine when
defining certain SMP topologies [1]. The reasoning behind the change is
explained in kernel commit 4ca234a9cbd7 ("powerpc/smp: Stop updating
cpu_core_mask"). In short, cpu_core_mask logic was causing troubles with
large VMs with lots of CPUs and was changed by cpu_cpu_mask because, as
far as the kernel understanding of SMP topologies goes, both masks are
equivalent.

Further discussions in the kernel mailing list [2] shown that the
powerpc kernel always considered that the number of sockets were equal
to the number of NUMA nodes. The claim is that it doesn't make sense,
for Power hardware at least, 2+ sockets being in the same NUMA node. The
immediate conclusion is that all SMP topologies the pseries machine were
supplying to the kernel, with more than one socket in the same NUMA node
as in [1], happened to be correctly represented in the kernel by
accident during all these years.

There's a case to be made for virtual topologies being detached from
hardware constraints, allowing maximum flexibility to users. At the same
time, this freedom can't result in unrealistic hardware representations
being emulated. If the real hardware and the pseries kernel don't
support multiple chips/sockets in the same NUMA node, neither should we.

Starting in 6.0.0, all sockets must match an unique NUMA node in the
pseries machine. qtest changes were made to adapt to this new
condition.


Oof.  I really don't like this idea.  It means a bunch of fiddly work
for users to match these up, for no real gain.  I'm also concerned
that this will require follow on changes in libvirt to not make this a
really cryptic and irritating point of failure.


Haven't though about required Libvirt changes, although I can say that there
will be some amount to be mande and it will probably annoy existing users
(everyone that has a multiple socket per NUMA node topology).

There is not much we can do from the QEMU layer aside from what I've proposed
here. The other alternative is to keep interacting with the kernel folks to
see if there is a way to keep our use case untouched.


Right.  Well.. not necessarily untouched, but I'm hoping for more
replies from Cédric to my objections and mpe's.  Even with sockets
being a kinda meaningless concept in PAPR, I don't think tying it to
NUMA nodes makes sense.


I did a couple of replies in different email threads but maybe not
to all. I felt it was going nowhere :/ Couple of thoughts,

Shouldn't we get rid of the socket concept, die also, under pseries
since they don't exist under PAPR ? We only have numa nodes, cores,
threads AFAICT.


I don't think we work with 'die'.

Getting rid of the 'socket' representation is sensible regarding PAPR,
but the effect for pseries will be similar to what this patch is already
doing: users could have multiple sockets in the same NUMA node, and then
they won't. Either because we got rid of the 'socket' representation or
because socket == NUMA node.



Should we diverged from PAPR and add extra DT properties "qemu,..." ?
There are a couple of places where Linux checks for the underlying
hypervisor already.


This also means that
'ibm,chip-id' will probably remain in use since it's the only place where
we inform cores per socket information to the kernel.


Well.. unless we can find some other sensible way to convey that
information.  I haven't given up hope for that yet.


Well, we could start by fixing the value in QEMU. It is broken today.



I'll look into it. It makes more sense to talk about keeping it when
it's working properly.



DHB





This is all coming from some work we did last year to evaluate our HW
(mostly for XIVE) on 2s, 4s, 16s systems on baremetal, KVM and PowerVM.
We saw some real problems because Linux did not have a clear view of the
topology. See the figures here :

http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20210303174857.1760393-9-...@kaod.org/

The node id is a key parameter for system resource management, memory
allocation, interrupt affinity, etc. Linux scales much better if used
correctly.

C.





Re: [PULL 0/2] Block patches

2021-03-25 Thread Vladimir Sementsov-Ogievskiy

25.03.2021 12:56, Stefan Hajnoczi wrote:

On Wed, Mar 24, 2021 at 08:42:27PM +, Peter Maydell wrote:

On Wed, 24 Mar 2021 at 20:18, Vladimir Sementsov-Ogievskiy
 wrote:


24.03.2021 21:05, Peter Maydell wrote:

On Wed, 24 Mar 2021 at 14:52, Stefan Hajnoczi  wrote:


Vladimir Sementsov-Ogievskiy (2):
migration/block-dirty-bitmap: make incoming disabled bitmaps busy
migrate-bitmaps-postcopy-test: check that we can't remove in-flight
  bitmaps


This failed the 'qsd-jobs' iotest on s390x:



I can't believe it related. My commit modifies bitmap status during bitmaps 
migration on target vm. There is no kind of migration in qsd-jobs test.


It's possible it's an intermittent, but it's not one I've seen
before. We still have lots of time this release cycle to figure
out the issue and get this fix in.


Vladimir: I'll get hold of an s390 machine and try to reproduce the
failure. I should have some news by Monday.


Thanks! My path modifies migration/block-dirty-bitmap.c. qsd-jobs runs 
block-commit and block-stream jobs and don't start any kind of migration or 
snapshot or savevm, so it seems impossible that qsd-jobs runs the code touched 
by my patch..



Let's put the pull request on hold for now.

Stefan




--
Best regards,
Vladimir



Re: [PATCH V3] target/riscv: Align the data type of reset vector address

2021-03-25 Thread Bin Meng
On Thu, Mar 25, 2021 at 5:42 PM Dylan Jhong  wrote:
>
> Signed-off-by: Dylan Jhong 
> Signed-off-by: Ruinland ChuanTzu Tsai 
> ---
>  target/riscv/cpu.c | 6 +-
>  target/riscv/cpu.h | 2 +-
>  2 files changed, 6 insertions(+), 2 deletions(-)
>

Reviewed-by: Bin Meng 



Re: Crashes with qemu-system-ppc64

2021-03-25 Thread Greg Kurz
On Wed, 24 Mar 2021 10:17:55 +0100
Paolo Bonzini  wrote:

> On 24/03/21 00:35, Philippe Mathieu-Daudé wrote:
> > Hmmm does this assert() matches your comment?
> > 
> > -- >8 --
> > diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> > index cefc5eaa0a9..41cbee77d14 100644
> > --- a/hw/core/qdev.c
> > +++ b/hw/core/qdev.c
> > @@ -1130,6 +1130,8 @@ Object *qdev_get_machine(void)
> >   {
> >   static Object *dev;
> > 
> > +assert(phase_check(PHASE_MACHINE_CREATED));
> > +
> 
> Very nice use of phase_check!  Kudos.
> 

It seems promising at first sight but qdev_get_machine() gets
called under qemu_create_machine() long before phase is advanced
to PHASE_MACHINE_CREATED.

qemu-system-ppc64: ../../hw/core/qdev.c:1133: qdev_get_machine: Assertion 
`phase_check(PHASE_MACHINE_CREATED)' failed.

(gdb) bt
#0  0x764a3708 in raise () at /lib64/power9/libc.so.6
#1  0x76483bcc in abort () at /lib64/power9/libc.so.6
#2  0x76497210 in __assert_fail_base () at /lib64/power9/libc.so.6
#3  0x764972b4 in __assert_fail () at /lib64/power9/libc.so.6
#4  0x0001009e7820 in qdev_get_machine () at ../../hw/core/qdev.c:1133
#5  0x0001009e7820 in qdev_get_machine () at ../../hw/core/qdev.c:1129
#6  0x000100747894 in memory_region_do_init (mr=0x101261200, owner=0x0, 
name=, size=) at ../../softmmu/memory.c:1177
#7  0x0001007fccc4 in memory_map_init () at ../../softmmu/physmem.c:2630
#8  0x0001007fccc4 in cpu_exec_init_all () at ../../softmmu/physmem.c:3034
#9  0x0001007e9c9c in qemu_create_machine 
(machine_class=machine_class@entry=0x1014b96d0) at ../../softmmu/vl.c:2086
#10 0x0001007eb8c0 in qemu_init (argc=, argv=, envp=) at ../../softmmu/vl.c:1640
#11 0x0001002f53c8 in main (argc=, argv=, 
envp=) at ../../softmmu/main.c:49


static void memory_region_do_init(MemoryRegion *mr,
  Object *owner,
  const char *name,
  uint64_t size)
{
[...]
if (!owner) {
owner = container_get(qdev_get_machine(), "/unattached");
}

The true condition for qdev_get_machine() to be functional is
actually that the following happened already:

object_property_add_child(object_get_root(), "machine",
  OBJECT(current_machine));

This is the case with the call stack ^^ and I don't see any valid
reason to forbid use of qdev_get_machine() here.

So I'm wondering if we shouldn't rather check the existence of the
"/machine" path in the QOM tree instead of checking the phase.

> Paolo
> 




Re: gitlab-ci: Only build /staging branch?

2021-03-25 Thread Peter Maydell
On Thu, 25 Mar 2021 at 09:33, Philippe Mathieu-Daudé  wrote:
> v6.0 is at the door and I was wondering what is missing to have the
> CI used as a gate.

It needs to be faster. Mostly I do check the gitlab CI pipeline
status, but in the run-up to getting rc0 out I stopped waiting
for the gitlab CI job to finish, because I was continually finding
that I kicked off a run, my local build-tests would complete within
an hour or so, and the gitlab CI jobs were still pending, barely
started, etc. Turnaround on testing a merge must be 90 minutes or
less, especially during release periods, because there are always
a huge number of merges that arrive for me to test in the last
couple of days before freeze.

thanks
-- PMM



Re: [PATCH v3] linux-user/s390x: Use the guest pointer for the sigreturn stub

2021-03-25 Thread Laurent Vivier
Le 24/03/2021 à 19:51, Andreas Krebbel a écrit :
> When setting up the pointer for the sigreturn stub in the return
> address register (r14) we currently use the host frame address instead
> of the guest frame address.
> 
> Note: This only caused problems if Qemu has been built with
> --disable-pie (as it is in distros nowadays). Otherwise guest_base
> defaults to 0 hiding the actual problem.
> 
> Signed-off-by: Andreas Krebbel 
> ---
>  linux-user/s390x/signal.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/linux-user/s390x/signal.c b/linux-user/s390x/signal.c
> index ecfa2a14a9..7107c5fb53 100644
> --- a/linux-user/s390x/signal.c
> +++ b/linux-user/s390x/signal.c
> @@ -211,9 +211,10 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
>  /* Set up to return from userspace.  If provided, use a stub
> already in userspace.  */
>  if (ka->sa_flags & TARGET_SA_RESTORER) {
> -env->regs[14] = (unsigned long) ka->sa_restorer | PSW_ADDR_AMODE;
> +env->regs[14] = ka->sa_restorer | PSW_ADDR_AMODE;
>  } else {
> -env->regs[14] = (unsigned long) frame->retcode | PSW_ADDR_AMODE;
> +env->regs[14] = (frame_addr + offsetof(typeof(*frame), retcode))
> +| PSW_ADDR_AMODE;
>  __put_user(S390_SYSCALL_OPCODE | TARGET_NR_rt_sigreturn,
> (uint16_t *)(frame->retcode));
>  }
> 

Reviewed-by: Laurent Vivier 



Re: [PATCH] qapi: introduce 'query-cpu-model-cpuid' action

2021-03-25 Thread Vladimir Sementsov-Ogievskiy

25.03.2021 13:11, Vladimir Sementsov-Ogievskiy wrote:

24.03.2021 16:39, Valeriy Vdovin wrote:

Introducing new qapi method 'query-cpu-model-cpuid'. This method can be used to
get virtualized cpu model info generated by QEMU during VM initialization in
the form of cpuid representation.

Diving into more details about virtual cpu generation: QEMU first parses '-cpu'
command line option. From there it takes the name of the model as the basis for
feature set of the new virtual cpu. After that it uses trailing '-cpu' options,
that state if additional cpu features should be present on the virtual cpu or
excluded from it (tokens '+'/'-' or '=on'/'=off').
After that QEMU checks if the host's cpu can actually support the derived
feature set and applies host limitations to it.
After this initialization procedure, virtual cpu has it's model and
vendor names, and a working feature set and is ready for identification
instructions such as CPUID.

Currently full output for this method is only supported for x86 cpus.

To learn exactly how virtual cpu is presented to the guest machine via CPUID
instruction, new qapi method can be used. By calling 'query-cpu-model-cpuid'
method, one can get a full listing of all CPUID leafs with subleafs which are
supported by the initialized virtual cpu.

Other than debug, the method is useful in cases when we would like to
utilize QEMU's virtual cpu initialization routines and put the retrieved
values into kernel CPUID overriding mechanics for more precise control
over how various processes perceive its underlying hardware with
container processes as a good example.

Output format:
The core part of the returned JSON object can be described as a list of lists
with top level list contains leaf-level elements and the bottom level
containing subleafs, where 'leaf' is CPUID argument passed in EAX register and
'subleaf' is a value passed to CPUID in ECX register for some specific
leafs, that support that. Each most basic CPUID result is passed in a
maximum of 4 registers EAX, EBX, ECX and EDX, with most leafs not utilizing
all 4 registers at once.
Also note that 'subleaf' is a kind of extension, used by only a couple of
leafs, while most of the leafs don't have this. Nevertheless, the output
data structure presents ALL leafs as having at least a single 'subleaf'.
This is done for data structure uniformity, so that it could be
processed in a more straightforward manner, in this case no one suffers
from such simplification.

Use example:
virsh qemu-monitor-command VM --pretty '{ "execute": "query-cpu-model-cpuid" }'
{
   "return": {
 "cpuid": {
   "leafs": [
 {
   "leaf": 0,
   "subleafs": [
 {
   "eax": 13,
   "edx": 1231384169,
   "ecx": 1818588270,
   "ebx": 1970169159,
   "subleaf": 0
 }
   ]
 },
 {
   "leaf": 1,
   "subleafs": [
 {
   "eax": 329443,
   "edx": 529267711,
   "ecx": 4160369187,
   "ebx": 133120,
   "subleaf": 0
 }
   ]
 },
 {
   "leaf": 2,
   "subleafs": [
 {
   "eax": 1,
   "edx": 2895997,
   "ecx": 0,
   "ebx": 0,
   "subleaf": 0
 }
   ]
 },
   ]
 },
 "vendor": "GenuineIntel",
 "class-name": "Skylake-Client-IBRS-x86_64-cpu",
 "model-id": "Intel Core Processor (Skylake, IBRS)"
   },
   "id": "libvirt-40"
}
Signed-off-by: Valeriy Vdovin 
---
  qapi/machine-target.json | 122 
  target/i386/cpu.c    | 292 +--
  2 files changed, 405 insertions(+), 9 deletions(-)

diff --git a/qapi/machine-target.json b/qapi/machine-target.json
index e7811654b7..c5b137aa5c 100644
--- a/qapi/machine-target.json
+++ b/qapi/machine-target.json
@@ -329,3 +329,125 @@
  ##
  { 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'],
    'if': 'defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_I386) 
|| defined(TARGET_S390X) || defined(TARGET_MIPS)' }
+##
+
+
+# @CpuidSubleaf:
+#
+# CPUID leaf extension information, based on ECX value.
+#
+# CPUID x86 instruction has 'leaf' argument passed in EAX register. Leaf
+# argument identifies the type of information, the caller wants to retrieve in
+# single call to CPUID.
+# Some but not all leaves depend on the value passed in ECX register as an
+# additional argument to CPUID. This argument is present in cpuid documentation
+# as 'subleaf'.
+# If CPUID ignores the value in ECX, normally this means that leaf does not
+# have subleaves. Another way to see it is that each leaf has at least one
+# subleaf (one type of output).
+#
+# @subleaf: value passed to CPUID in ECX register. If CPUID leaf has only a
+#   single leaf, the value of ECX is ignored by CPU and should as well
+#  

Re: gitlab-ci: Only build /staging branch?

2021-03-25 Thread Paolo Bonzini

On 25/03/21 11:34, Peter Maydell wrote:

It needs to be faster. Mostly I do check the gitlab CI pipeline
status, but in the run-up to getting rc0 out I stopped waiting
for the gitlab CI job to finish, because I was continually finding
that I kicked off a run, my local build-tests would complete within
an hour or so, and the gitlab CI jobs were still pending, barely
started, etc. Turnaround on testing a merge must be 90 minutes or
less, especially during release periods, because there are always
a huge number of merges that arrive for me to test in the last
couple of days before freeze.


Perhaps we could script it so that if the pipeline passes the merge to 
master is done automatically.


Paolo




Re: gitlab-ci: Only build /staging branch?

2021-03-25 Thread Peter Maydell
On Thu, 25 Mar 2021 at 11:05, Paolo Bonzini  wrote:
>
> On 25/03/21 11:34, Peter Maydell wrote:
> > It needs to be faster. Mostly I do check the gitlab CI pipeline
> > status, but in the run-up to getting rc0 out I stopped waiting
> > for the gitlab CI job to finish, because I was continually finding
> > that I kicked off a run, my local build-tests would complete within
> > an hour or so, and the gitlab CI jobs were still pending, barely
> > started, etc. Turnaround on testing a merge must be 90 minutes or
> > less, especially during release periods, because there are always
> > a huge number of merges that arrive for me to test in the last
> > couple of days before freeze.
>
> Perhaps we could script it so that if the pipeline passes the merge to
> master is done automatically.

That would be nice eventually, but we can't do it until the gitlab
CI is the *only* gating criterion.

thanks
-- PMM



Re: [PATCH v2] piix: fix regression during unplug in Xen HVM domUs

2021-03-25 Thread Olaf Hering
Am Mon, 22 Mar 2021 18:09:17 -0400
schrieb John Snow :

> My understanding is that XEN has some extra disks that it unplugs when 
> it later figures out it doesn't need them. How exactly this works is 
> something I've not looked into too closely.

It has no extra disks, why would it?

I assume each virtualization variant has some sort of unplug if it has to 
support guests that lack PV/virtio/enlightened/whatever drivers.

In case of HVM, the configured block or network devices can be either accessed 
via emulated PCI or via the PV drivers. Since the BIOS, the bootloader and 
potentially the operating system kernel typically lack PV drivers, they will 
find the devices only via the PCI bus. In case they happen to have PV drivers 
in addition to PCI drivers, both drivers will find and offer the same resource 
via different paths. In case of a block device, ata_piix.ko will show it via 
"/dev/sda" and xen-blkfront.ko will show it via "/dev/xvda". This is obviously 
bad, at least in the read-write case.

The pvops kernel triggers the unplug of the emulated PCI hardware early, prior 
any other PCI initialization. As a result the PCI drivers will not find their 
hardware anymore. In case of ata_piix, only the non-CDROM storage will be 
removed in qmeu, because there is no PV-CDROM driver.

The PV support in old xenlinux based kernels is only available as modules. As a 
result the unplug will happen after PCI was initialized, but it must happen 
before any PCI device drivers are loaded.


> So if these IDE devices have been "unplugged" already, we avoid 
> resetting them here. What about this reset causes the bug you describe 
> in the commit message?
> 
> Does this reset now happen earlier/later as compared to what it did 
> prior to ee358e91 ?

Prior this commit, piix_ide_reset was only called when the entire emulated 
machine was reset. Like: never.
With this commit, piix_ide_reset will be called from pci_piix3_xen_ide_unplug. 
For some reason it confuses the emulated USB hardware. Why it does confused it, 
no idea.

I wonder what the purpose of the qdev_reset_all() call really is. It is 10 
years old. It might be stale.


Olaf


pgpAJb2zZreCU.pgp
Description: Digitale Signatur von OpenPGP


Re: gitlab-ci: Only build /staging branch?

2021-03-25 Thread Daniel P . Berrangé
On Thu, Mar 25, 2021 at 12:05:32PM +0100, Paolo Bonzini wrote:
> On 25/03/21 11:34, Peter Maydell wrote:
> > It needs to be faster. Mostly I do check the gitlab CI pipeline
> > status, but in the run-up to getting rc0 out I stopped waiting
> > for the gitlab CI job to finish, because I was continually finding
> > that I kicked off a run, my local build-tests would complete within
> > an hour or so, and the gitlab CI jobs were still pending, barely
> > started, etc. Turnaround on testing a merge must be 90 minutes or
> > less, especially during release periods, because there are always
> > a huge number of merges that arrive for me to test in the last
> > couple of days before freeze.
> 
> Perhaps we could script it so that if the pipeline passes the merge to
> master is done automatically.

No need to script it, that functionality already exists in GitLab.

Push to the staging branch, and open a merge request for applying
staging -> master, and enable "merge when pipeline succeeds".

You can actually do this all in one command

https://docs.gitlab.com/ee/user/project/push_options.html

  git push \
 -o merge_request.create \
 -o merge_request.target=master \
 -o merge_request.merge_when_pipeline_succeeds \
 origin staging


The gitlab-ci.yml file could then be configured so that pipeline
jobs are associated with a merge request, rather than push event.
This will avoid the pipeline being re-run on master after the
merge.

If you enable "merge trains" option in the repo, then you can
even push to multiple branches concurrently, and gitlab will
serialize the CI pipelines from each merge request in turn,
(assuming no conflicts between then).

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




[PATCH v6 0/6] coroutine rwlock downgrade fix, minor VDI changes

2021-03-25 Thread Paolo Bonzini
This is a resubmit of David Edmondson's series at
https://patchew.org/QEMU/20210309144015.557477-1-david.edmond...@oracle.com/.
After closer analysis on IRC, the CoRwlock's attempt to ensure
fairness turned out to be flawed.  Therefore, this series
reimplements CoRwlock without using a CoQueue.  Tracking whether
each queued coroutine is a reader/writer makes it possible to
never wake a writer when only readers should be allowed and
vice versa.

v2->v3: new CoRwlock implementation

v3->v4: fix upgrade and add a test for that, too

v4->v5: typo

v5->v6: improve documentation, do not read lock->owners where
neither wrlock nor lock->mutex exclude concurrent writes

David Edmondson (4):
  block/vdi: When writing new bmap entry fails, don't leak the buffer
  block/vdi: Don't assume that blocks are larger than VdiHeader
  coroutine-lock: Store the coroutine in the CoWaitRecord only once
  test-coroutine: Add rwlock downgrade test

Paolo Bonzini (2):
  coroutine-lock: Reimplement CoRwlock to fix downgrade bug
  test-coroutine: Add rwlock upgrade test

 block/vdi.c |  11 ++-
 include/qemu/coroutine.h|  17 ++--
 tests/unit/test-coroutine.c | 161 
 util/qemu-coroutine-lock.c  | 149 +
 4 files changed, 274 insertions(+), 64 deletions(-)

-- 
2.29.2




[PATCH v6 1/6] block/vdi: When writing new bmap entry fails, don't leak the buffer

2021-03-25 Thread Paolo Bonzini
From: David Edmondson 

If a new bitmap entry is allocated, requiring the entire block to be
written, avoiding leaking the buffer allocated for the block should
the write fail.

Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: David Edmondson 
Message-Id: <20210309144015.557477-2-david.edmond...@oracle.com>
Acked-by: Max Reitz 
Signed-off-by: Paolo Bonzini 
---
 block/vdi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/block/vdi.c b/block/vdi.c
index 5627e7d764..2a6dc26124 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -690,6 +690,7 @@ nonallocating_write:
 
 logout("finished data write\n");
 if (ret < 0) {
+g_free(block);
 return ret;
 }
 
-- 
2.29.2





[PATCH v6 6/6] test-coroutine: Add rwlock downgrade test

2021-03-25 Thread Paolo Bonzini
From: David Edmondson 

Test that downgrading an rwlock does not result in a failure to
schedule coroutines queued on the rwlock.

The diagram associated with test_co_rwlock_downgrade() describes the
intended behaviour, but what was observed previously corresponds to:

| c1 | c2 | c3 | c4   |
|+++--|
| rdlock |||  |
| yield  |||  |
|| wrlock ||  |
||||  |
||| rdlock |  |
||||  |
|||| wrlock   |
||||  |
| unlock |||  |
| yield  |||  |
||  ||  |
|| downgrade  ||  |
|| ...||  |
|| unlock ||  |
|||  |  |
||||  |

This results in a failure...

ERROR:../tests/test-coroutine.c:369:test_co_rwlock_downgrade: assertion failed: 
(c3_done)
Bail out! ERROR:../tests/test-coroutine.c:369:test_co_rwlock_downgrade: 
assertion failed: (c3_done)

...as a result of the c3 coroutine failing to run to completion.

Signed-off-by: David Edmondson 
Message-Id: <20210309144015.557477-5-david.edmond...@oracle.com>
Signed-off-by: Paolo Bonzini 
---
 tests/unit/test-coroutine.c | 99 +
 1 file changed, 99 insertions(+)

diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c
index 6e6f51d480..aa77a3bcb3 100644
--- a/tests/unit/test-coroutine.c
+++ b/tests/unit/test-coroutine.c
@@ -325,6 +325,104 @@ static void test_co_rwlock_upgrade(void)
 g_assert(c2_done);
 }
 
+static void coroutine_fn rwlock_rdlock_yield(void *opaque)
+{
+qemu_co_rwlock_rdlock(&rwlock);
+qemu_coroutine_yield();
+
+qemu_co_rwlock_unlock(&rwlock);
+qemu_coroutine_yield();
+
+*(bool *)opaque = true;
+}
+
+static void coroutine_fn rwlock_wrlock_downgrade(void *opaque)
+{
+qemu_co_rwlock_wrlock(&rwlock);
+
+qemu_co_rwlock_downgrade(&rwlock);
+qemu_co_rwlock_unlock(&rwlock);
+*(bool *)opaque = true;
+}
+
+static void coroutine_fn rwlock_rdlock(void *opaque)
+{
+qemu_co_rwlock_rdlock(&rwlock);
+
+qemu_co_rwlock_unlock(&rwlock);
+*(bool *)opaque = true;
+}
+
+static void coroutine_fn rwlock_wrlock(void *opaque)
+{
+qemu_co_rwlock_wrlock(&rwlock);
+
+qemu_co_rwlock_unlock(&rwlock);
+*(bool *)opaque = true;
+}
+
+/*
+ * Check that downgrading a reader-writer lock does not cause a hang.
+ *
+ * Four coroutines are used to produce a situation where there are
+ * both reader and writer hopefuls waiting to acquire an rwlock that
+ * is held by a reader.
+ *
+ * The correct sequence of operations we aim to provoke can be
+ * represented as:
+ *
+ * | c1 | c2 | c3 | c4 |
+ * |+++|
+ * | rdlock ||||
+ * | yield  ||||
+ * || wrlock |||
+ * |||||
+ * ||| rdlock ||
+ * |||||
+ * |||| wrlock |
+ * |||||
+ * | unlock ||||
+ * | yield  ||||
+ * ||  |||
+ * || downgrade  |||
+ * |||  ||
+ * ||| unlock ||
+ * || ...|||
+ * || unlock |||
+ * ||||  |
+ * |||| unlock |
+ */
+static void test_co_rwlock_downgrade(void)
+{
+bool c1_done = false;
+bool c2_done = false;
+bool c3_done = false;
+bool c4_done = false;
+Coroutine *c1, *c2, *c3, *c4;
+
+qemu_co_rwlock_init(&rwlock);
+
+c1 = qemu_coroutine_create(rwlock_rdlock_yield, &c1_done);
+c2 = qemu_coroutine_create(rwlock_wrlock_downgrade, &c2_done);
+c3 = qemu_coroutine_create(rwlock_rdlock, &c3_done);
+c4 = qemu_coroutine_create(rwlock_wrlock, &c4_done);
+
+qemu_coroutine_enter(c1);
+qemu_coroutine_enter(c2);
+qemu_coroutine_enter(c3);
+qemu_coroutine_enter(c4);
+
+qemu_coroutine_enter(c1);
+
+g_assert(c2_done);
+g_assert(c3_done);
+g_assert(c4_done);
+
+qemu_coroutine_enter(c1);
+
+g_assert(c1_done);
+}
+
 /*
  * Check that creation, enter, and return work
  */
@@ -563,6 +661,7 @@ int main(int argc, char **argv)
 g_test_add_func("/locking/co-mutex", test_co_mutex);
 g_test_add_func("/locking/c

[PATCH v6 4/6] coroutine-lock: Reimplement CoRwlock to fix downgrade bug

2021-03-25 Thread Paolo Bonzini
An invariant of the current rwlock is that if multiple coroutines hold a
reader lock, all must be runnable. The unlock implementation relies on
this, choosing to wake a single coroutine when the final read lock
holder exits the critical section, assuming that it will wake a
coroutine attempting to acquire a write lock.

The downgrade implementation violates this assumption by creating a
read lock owning coroutine that is exclusively runnable - any other
coroutines that are waiting to acquire a read lock are *not* made
runnable when the write lock holder converts its ownership to read
only.

More in general, the old implementation had lots of other fairness bugs.
The root cause of the bugs was that CoQueue would wake up readers even
if there were pending writers, and would wake up writers even if there
were readers.  In that case, the coroutine would go back to sleep *at
the end* of the CoQueue, losing its place at the head of the line.

To fix this, keep the queue of waiters explicitly in the CoRwlock
instead of using CoQueue, and store for each whether it is a
potential reader or a writer.  This way, downgrade can look at the
first queued coroutines and wake it only if it is a reader, causing
all other readers in line to be released in turn.

Reported-by: David Edmondson 
Reviewed-by: David Edmondson 
Signed-off-by: Paolo Bonzini 
---
v3->v4: clean up the code and fix upgrade logic.  Fix upgrade comment too.

 include/qemu/coroutine.h   |  17 +++--
 util/qemu-coroutine-lock.c | 148 -
 2 files changed, 106 insertions(+), 59 deletions(-)

diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
index 84eab6e3bf..7919d3bb62 100644
--- a/include/qemu/coroutine.h
+++ b/include/qemu/coroutine.h
@@ -237,11 +237,15 @@ bool qemu_co_enter_next_impl(CoQueue *queue, QemuLockable 
*lock);
 bool qemu_co_queue_empty(CoQueue *queue);
 
 
+typedef struct CoRwTicket CoRwTicket;
 typedef struct CoRwlock {
-int pending_writer;
-int reader;
 CoMutex mutex;
-CoQueue queue;
+
+/* Number of readers, or -1 if owned for writing.  */
+int owners;
+
+/* Waiting coroutines.  */
+QSIMPLEQ_HEAD(, CoRwTicket) tickets;
 } CoRwlock;
 
 /**
@@ -260,10 +264,9 @@ void qemu_co_rwlock_rdlock(CoRwlock *lock);
 /**
  * Write Locks the CoRwlock from a reader.  This is a bit more efficient than
  * @qemu_co_rwlock_unlock followed by a separate @qemu_co_rwlock_wrlock.
- * However, if the lock cannot be upgraded immediately, control is transferred
- * to the caller of the current coroutine.  Also, @qemu_co_rwlock_upgrade
- * only overrides CoRwlock fairness if there are no concurrent readers, so
- * another writer might run while @qemu_co_rwlock_upgrade blocks.
+ * Note that if the lock cannot be upgraded immediately, control is transferred
+ * to the caller of the current coroutine; another writer might run while
+ * @qemu_co_rwlock_upgrade blocks.
  */
 void qemu_co_rwlock_upgrade(CoRwlock *lock);
 
diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c
index eb73cf11dc..2669403839 100644
--- a/util/qemu-coroutine-lock.c
+++ b/util/qemu-coroutine-lock.c
@@ -327,11 +327,51 @@ void coroutine_fn qemu_co_mutex_unlock(CoMutex *mutex)
 trace_qemu_co_mutex_unlock_return(mutex, self);
 }
 
+struct CoRwTicket {
+bool read;
+Coroutine *co;
+QSIMPLEQ_ENTRY(CoRwTicket) next;
+};
+
 void qemu_co_rwlock_init(CoRwlock *lock)
 {
-memset(lock, 0, sizeof(*lock));
-qemu_co_queue_init(&lock->queue);
 qemu_co_mutex_init(&lock->mutex);
+lock->owners = 0;
+QSIMPLEQ_INIT(&lock->tickets);
+}
+
+/* Releases the internal CoMutex.  */
+static void qemu_co_rwlock_maybe_wake_one(CoRwlock *lock)
+{
+CoRwTicket *tkt = QSIMPLEQ_FIRST(&lock->tickets);
+Coroutine *co = NULL;
+
+/*
+ * Setting lock->owners here prevents rdlock and wrlock from
+ * sneaking in between unlock and wake.
+ */
+
+if (tkt) {
+if (tkt->read) {
+if (lock->owners >= 0) {
+lock->owners++;
+co = tkt->co;
+}
+} else {
+if (lock->owners == 0) {
+lock->owners = -1;
+co = tkt->co;
+}
+}
+}
+
+if (co) {
+QSIMPLEQ_REMOVE_HEAD(&lock->tickets, next);
+qemu_co_mutex_unlock(&lock->mutex);
+aio_co_wake(co);
+} else {
+qemu_co_mutex_unlock(&lock->mutex);
+}
 }
 
 void qemu_co_rwlock_rdlock(CoRwlock *lock)
@@ -340,13 +380,22 @@ void qemu_co_rwlock_rdlock(CoRwlock *lock)
 
 qemu_co_mutex_lock(&lock->mutex);
 /* For fairness, wait if a writer is in line.  */
-while (lock->pending_writer) {
-qemu_co_queue_wait(&lock->queue, &lock->mutex);
+if (lock->owners == 0 || (lock->owners > 0 && 
QSIMPLEQ_EMPTY(&lock->tickets))) {
+lock->owners++;
+qemu_co_mutex_unlock(&lock->mutex);
+} else {
+CoRwTicket my_ticket = { true, self };
+
+QSIMPLEQ_IN

[PATCH v6 2/6] block/vdi: Don't assume that blocks are larger than VdiHeader

2021-03-25 Thread Paolo Bonzini
From: David Edmondson 

Given that the block size is read from the header of the VDI file, a
wide variety of sizes might be seen. Rather than re-using a block
sized memory region when writing the VDI header, allocate an
appropriately sized buffer.

Signed-off-by: David Edmondson 
Message-Id: <20210309144015.557477-3-david.edmond...@oracle.com>
Acked-by: Max Reitz 
Signed-off-by: Paolo Bonzini 
---
 block/vdi.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/block/vdi.c b/block/vdi.c
index 2a6dc26124..548f8a057b 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -696,18 +696,20 @@ nonallocating_write:
 
 if (block) {
 /* One or more new blocks were allocated. */
-VdiHeader *header = (VdiHeader *) block;
+VdiHeader *header;
 uint8_t *base;
 uint64_t offset;
 uint32_t n_sectors;
 
+g_free(block);
+header = g_malloc(sizeof(*header));
+
 logout("now writing modified header\n");
 assert(VDI_IS_ALLOCATED(bmap_first));
 *header = s->header;
 vdi_header_to_le(header);
-ret = bdrv_pwrite(bs->file, 0, block, sizeof(VdiHeader));
-g_free(block);
-block = NULL;
+ret = bdrv_pwrite(bs->file, 0, header, sizeof(*header));
+g_free(header);
 
 if (ret < 0) {
 return ret;
-- 
2.29.2





[PATCH v6 3/6] coroutine-lock: Store the coroutine in the CoWaitRecord only once

2021-03-25 Thread Paolo Bonzini
From: David Edmondson 

When taking the slow path for mutex acquisition, set the coroutine
value in the CoWaitRecord in push_waiter(), rather than both there and
in the caller.

Reviewed-by: Paolo Bonzini 
Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: David Edmondson 
Message-Id: <20210309144015.557477-4-david.edmond...@oracle.com>
Signed-off-by: Paolo Bonzini 
---
 util/qemu-coroutine-lock.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c
index 5816bf8900..eb73cf11dc 100644
--- a/util/qemu-coroutine-lock.c
+++ b/util/qemu-coroutine-lock.c
@@ -204,7 +204,6 @@ static void coroutine_fn 
qemu_co_mutex_lock_slowpath(AioContext *ctx,
 unsigned old_handoff;
 
 trace_qemu_co_mutex_lock_entry(mutex, self);
-w.co = self;
 push_waiter(mutex, &w);
 
 /* This is the "Responsibility Hand-Off" protocol; a lock() picks from
-- 
2.29.2





[PATCH v6 5/6] test-coroutine: Add rwlock upgrade test

2021-03-25 Thread Paolo Bonzini
Test that rwlock upgrade is fair, and that readers go back to sleep if
a writer is in line.

Signed-off-by: Paolo Bonzini 
---
 tests/unit/test-coroutine.c | 62 +
 1 file changed, 62 insertions(+)

diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c
index e946d93a65..6e6f51d480 100644
--- a/tests/unit/test-coroutine.c
+++ b/tests/unit/test-coroutine.c
@@ -264,6 +264,67 @@ static void test_co_mutex_lockable(void)
 g_assert(QEMU_MAKE_LOCKABLE(null_pointer) == NULL);
 }
 
+static CoRwlock rwlock;
+
+/* Test that readers are properly sent back to the queue when upgrading,
+ * even if they are the sole readers.  The test scenario is as follows:
+ *
+ *
+ * | c1   | c2 |
+ * |--++
+ * | rdlock   ||
+ * | yield||
+ * |  | wrlock |
+ * |  ||
+ * | upgrade  ||
+ * |  |  |
+ * |  | unlock |
+ * |||
+ * | unlock   ||
+ */
+
+static void coroutine_fn rwlock_yield_upgrade(void *opaque)
+{
+qemu_co_rwlock_rdlock(&rwlock);
+qemu_coroutine_yield();
+
+qemu_co_rwlock_upgrade(&rwlock);
+qemu_co_rwlock_unlock(&rwlock);
+
+*(bool *)opaque = true;
+}
+
+static void coroutine_fn rwlock_wrlock_yield(void *opaque)
+{
+qemu_co_rwlock_wrlock(&rwlock);
+qemu_coroutine_yield();
+
+qemu_co_rwlock_unlock(&rwlock);
+*(bool *)opaque = true;
+}
+
+static void test_co_rwlock_upgrade(void)
+{
+bool c1_done = false;
+bool c2_done = false;
+Coroutine *c1, *c2;
+
+qemu_co_rwlock_init(&rwlock);
+c1 = qemu_coroutine_create(rwlock_yield_upgrade, &c1_done);
+c2 = qemu_coroutine_create(rwlock_wrlock_yield, &c2_done);
+
+qemu_coroutine_enter(c1);
+qemu_coroutine_enter(c2);
+
+/* c1 now should go to sleep.  */
+qemu_coroutine_enter(c1);
+g_assert(!c1_done);
+
+qemu_coroutine_enter(c2);
+g_assert(c1_done);
+g_assert(c2_done);
+}
+
 /*
  * Check that creation, enter, and return work
  */
@@ -501,6 +562,7 @@ int main(int argc, char **argv)
 g_test_add_func("/basic/order", test_order);
 g_test_add_func("/locking/co-mutex", test_co_mutex);
 g_test_add_func("/locking/co-mutex/lockable", test_co_mutex_lockable);
+g_test_add_func("/locking/co-rwlock/upgrade", test_co_rwlock_upgrade);
 if (g_test_perf()) {
 g_test_add_func("/perf/lifecycle", perf_lifecycle);
 g_test_add_func("/perf/nesting", perf_nesting);
-- 
2.29.2





Re: [RFC v11 28/55] target/arm: refactor exception and cpu code

2021-03-25 Thread Claudio Fontana
On 3/24/21 11:29 PM, Richard Henderson wrote:
> On 3/23/21 9:46 AM, Claudio Fontana wrote:
>> move exception code out of tcg/
>> as we need part of it for KVM too.
>>
>> put the exception code into separate cpu modules as appropriate,
>> including:
>>
>> cpu-sysemu.c
>> tcg/tcg-cpu.c
>> tcg/sysemu/tcg-cpu.c
>>
>> to avoid naming confusion with the existing cpu_tcg.c,
>> containg cpu models definitions for 32bit TCG-only cpus,
>> rename this file as tcg/tcg-cpu-models.c
> 
> Obviously all of this should not be done in one step.


Ok will work on it.


> 
> Isn't tcg/tcg-* redundant?


I considered that, and at some point I had "cpu.c" for x86 too. After working 
on it for a while, I noticed how
it got really confusing in practice to have files called just "cpu.c" when 
working on them, just too many files are called "cpu.c". It was confusing.

I also like the extra emphasis on the accel for this:

kvm/kvm.c
kvm/kvm-cpu.c
kvm/kvm-stub.c

tcg/tcg-cpu.c
tcg/tcg-stub.c


Thanks,

Claudio



[Bug 1915925] Re: ARM semihosting HEAPINFO results wrote to wrong address

2021-03-25 Thread Alex Bennée
This is now merged and while be available in the 6.0 release.

** Changed in: qemu
   Status: In Progress => Fix Committed

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

Title:
  ARM semihosting HEAPINFO results wrote to wrong address

Status in QEMU:
  Fix Committed

Bug description:
  This affects latest development branch of QEMU.

  According to the ARM spec of the HEAPINFO semihosting call:

  https://developer.arm.com/documentation/100863/0300/Semihosting-
  operations/SYS-HEAPINFO--0x16-?lang=en

  > the PARAMETER REGISTER contains the address of a pointer to a four-
  field data block.

  However, QEMU treated the PARAMETER REGISTER as pointing to a four-
  field data block directly.

  Here is a simple program that can demonstrate this problem:
  https://github.com/iNvEr7/qemu-learn/tree/newlib-bug/semihosting-
  newlib

  This code links with newlib with semihosting mode, which will call the
  HEAPINFO SVC during crt0 routine. When running in QEMU (make run), it
  may crash the program either because of invalid write or memory
  curruption, depending on the compiled program structure.

  Also refer to my discussion with newlib folks:
  https://sourceware.org/pipermail/newlib/2021/018260.html

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



[Bug 1918302] Re: qemu-system-arm segfaults while servicing SYS_HEAPINFO

2021-03-25 Thread Alex Bennée
I think this is fixed now - it would be useful if the OP could confirm
with the current state of master.

** Changed in: qemu
   Status: In Progress => Fix Committed

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

Title:
  qemu-system-arm segfaults while servicing SYS_HEAPINFO

Status in QEMU:
  Fix Committed

Bug description:
  I compiled QEMU version 5.2.0 from source on Ubuntu 18.04, and tried
  to use it to run the attached bare-metal Arm hello-world image, using
  the command line

  qemu-system-arm -M microbit -semihosting -nographic -device
  loader,file=hello.hex

  The result was that qemu-system-arm itself died of a segfault.
  Compiling it for debugging, the location of the segfault was in
  target/arm/arm-semi.c, in the case handler for the semihosting call
  TARGET_SYS_HEAPINFO, on line 1020 which assigns to 'rambase':

  const struct arm_boot_info *info = env->boot_info;
  target_ulong rambase = info->loader_start;

  and the problem seems to be that 'info', aka env->boot_info, is NULL
  in this context.

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



Re: [PATCH-for-6.1] hw/isa/piix4: Use qdev_get_gpio_in_named() to get ISA IRQ

2021-03-25 Thread Richard Henderson

On 3/24/21 12:29 PM, Philippe Mathieu-Daudé wrote:

Since commit 078778c5a55 ("piix4: Add an i8259 Interrupt Controller")
the TYPE_PIIX4_PCI_DEVICE exposes the ISA input IRQs as "isa" alias.

Use this alias to get IRQ for the power management PCI function.

Signed-off-by: Philippe Mathieu-Daudé
---
  hw/isa/piix4.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)


Reviewed-by: Richard Henderson 

r~



Re: [PATCH 1/6] hw/isa/vt82c686: Name output IRQ as 'intr'

2021-03-25 Thread Richard Henderson

On 3/24/21 11:54 AM, Philippe Mathieu-Daudé wrote:

Named IRQs are easier to understand in the monitor.
Name the single output interrupt as 'intr'.

Signed-off-by: Philippe Mathieu-Daudé
---
  hw/isa/vt82c686.c   | 2 +-
  hw/mips/fuloong2e.c | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)


Reviewed-by: Richard Henderson 

r~




[PATCH-for-6.1 0/2] hw/block/pflash_cfi02: Do not create aliases when not necessary

2021-03-25 Thread Philippe Mathieu-Daudé
Simplify memory layout when no pflash_cfi02 mapping requested.
For example using the r2d machine:

  (qemu) info mtree
  address-space: memory
- (prio 0, i/o): system
  -00ff (prio 0, i/o): pflash
-00ff (prio 0, romd): alias pflash-alias =
@r2d.flash -00ff
  0400-043f (prio 0, i/o): r2d-fpga
  0c00-0fff (prio 0, ram): r2d.sdram

  (qemu) info mtree
  address-space: memory
- (prio 0, i/o): system
  -00ff (prio 0, romd): r2d.flash
  0400-043f (prio 0, i/o): r2d-fpga
  0c00-0fff (prio 0, ram): r2d.sdram

Philippe Mathieu-Daud=C3=A9 (2):
  hw/block/pflash_cfi02: Set romd mode in pflash_cfi02_realize()
  hw/block/pflash_cfi02: Do not create aliases when not necessary

 hw/block/pflash_cfi02.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

--=20
2.26.2




[PATCH-for-6.1 1/2] hw/block/pflash_cfi02: Set romd mode in pflash_cfi02_realize()

2021-03-25 Thread Philippe Mathieu-Daudé
The ROMD mode isn't related to mapping setup.
Ideally we'd set this mode when the state machine resets,
but for now simply move it to pflash_cfi02_realize() to
not introduce logical change.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/block/pflash_cfi02.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index 25c053693ce..35e30bb812c 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -173,7 +173,6 @@ static void pflash_setup_mappings(PFlashCFI02 *pfl)
  "pflash-alias", &pfl->orig_mem, 0, size);
 memory_region_add_subregion(&pfl->mem, i * size, 
&pfl->mem_mappings[i]);
 }
-pfl->rom_mode = true;
 }
 
 static void pflash_reset_state_machine(PFlashCFI02 *pfl)
@@ -917,6 +916,7 @@ static void pflash_cfi02_realize(DeviceState *dev, Error 
**errp)
 /* Allocate memory for a bitmap for sectors being erased. */
 pfl->sector_erase_map = bitmap_new(pfl->total_sectors);
 
+pfl->rom_mode = true;
 pflash_setup_mappings(pfl);
 sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem);
 
-- 
2.26.2




[PATCH-for-6.1 2/2] hw/block/pflash_cfi02: Do not create aliases when not necessary

2021-03-25 Thread Philippe Mathieu-Daudé
When no mapping is requested, it is pointless to create
alias regions.
Only create them when multiple mappings are requested to
simplify the memory layout. The flatview is not changed.

For example using 'qemu-system-sh4 -M r2d -S -monitor stdio',

* before:

  (qemu) info mtree
  address-space: memory
- (prio 0, i/o): system
  -00ff (prio 0, i/o): pflash
-00ff (prio 0, romd): alias pflash-alias 
@r2d.flash -00ff
  0400-043f (prio 0, i/o): r2d-fpga
  0c00-0fff (prio 0, ram): r2d.sdram
  (qemu) info mtree -f
  FlatView #0
   AS "memory", root: system
   AS "cpu-memory-0", root: system
   Root memory region: system
-00ff (prio 0, romd): r2d.flash
0400-043f (prio 0, i/o): r2d-fpga
0c00-0fff (prio 0, ram): r2d.sdram

* after:

  (qemu) info mtree
  address-space: memory
- (prio 0, i/o): system
  -00ff (prio 0, romd): r2d.flash
  0400-043f (prio 0, i/o): r2d-fpga
  0c00-0fff (prio 0, ram): r2d.sdram
  (qemu) info mtree -f
  FlatView #0
   AS "memory", root: system
   AS "cpu-memory-0", root: system
   Root memory region: system
-00ff (prio 0, romd): r2d.flash
0400-043f (prio 0, i/o): r2d-fpga
0c00-0fff (prio 0, ram): r2d.sdram

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/block/pflash_cfi02.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index 35e30bb812c..02c514fb6e0 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -917,8 +917,12 @@ static void pflash_cfi02_realize(DeviceState *dev, Error 
**errp)
 pfl->sector_erase_map = bitmap_new(pfl->total_sectors);
 
 pfl->rom_mode = true;
-pflash_setup_mappings(pfl);
-sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem);
+if (pfl->mappings > 1) {
+pflash_setup_mappings(pfl);
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem);
+} else {
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->orig_mem);
+}
 
 timer_init_ns(&pfl->timer, QEMU_CLOCK_VIRTUAL, pflash_timer, pfl);
 pfl->status = 0;
-- 
2.26.2




Re: [PATCH] migration: Move populate_vfio_info() into a separate file

2021-03-25 Thread Juan Quintela
"Dr. David Alan Gilbert"  wrote:
> * Thomas Huth (th...@redhat.com) wrote:
>> On 15/03/2021 22.05, Philippe Mathieu-Daudé wrote:
>> > Hi Thomas,
>> > 
>> > +Alex
>> > 
>> > On 3/15/21 8:07 PM, Thomas Huth wrote:
>> > > The CONFIG_VFIO switch only works in target specific code. Since
>> > > migration/migration.c is common code, the #ifdef does not have
>> > > the intended behavior here. Move the related code to a separate
>> > > file now which gets compiled via specific_ss instead.
>> > > 
>> > > Fixes: 3710586caa ("qapi: Add VFIO devices migration stats in
>> > > Migration stats")
>> > > Signed-off-by: Thomas Huth 
>> > > ---
>> > >   migration/meson.build |  3 ++-
>> > >   migration/migration.c | 15 ---
>> > >   migration/migration.h |  2 ++
>> > >   migration/special.c   | 25 +
>> > >   4 files changed, 29 insertions(+), 16 deletions(-)
>> > >   create mode 100644 migration/special.c
>> > > 
>> > > diff --git a/migration/meson.build b/migration/meson.build
>> > > index 9645f44005..e1f72f6ba0 100644
>> > > --- a/migration/meson.build
>> > > +++ b/migration/meson.build
>> > > @@ -30,4 +30,5 @@ softmmu_ss.add(when: ['CONFIG_RDMA', rdma],
>> > > if_true: files('rdma.c'))
>> > >   softmmu_ss.add(when: 'CONFIG_LIVE_BLOCK_MIGRATION', if_true:
>> > > files('block.c'))
>> > >   softmmu_ss.add(when: zstd, if_true: files('multifd-zstd.c'))
>> > > -specific_ss.add(when: 'CONFIG_SOFTMMU', if_true:
>> > > files('dirtyrate.c', 'ram.c'))
>> > > +specific_ss.add(when: 'CONFIG_SOFTMMU',
>> > > +if_true: files('dirtyrate.c', 'ram.c', 'special.c'))
>> > 
>> > Why not simply name this migration/vfio.c? That way we do not start
>> > mixed bag of everything target specific.
>> 
>> I don't mind ... well, if we have other small functions there in the future
>> that depend on CONFIG switches, a mixed bag file might not be such a bad
>> idea instead of having lots and lots of small other files ... OTOH, if there
>> is more vfio migration code in the works that might fit here, a name like
>> vfio.c would be better, of course. What do the maintainers think?
>
> Could this be done with stubs instead of an ifdef; i.e. a stub of
> 'vfio_mig_active' and 'vfio_mig_bytes_transferred'?

My understanding is that they can't (at least easily).
Because they are really target specific :-(

> As for naming 'special' is too generic.
> 'vfio' is too specific (especially since most vfio code ends up under
> hw/vfio)
>
> how about migration/target.c  as something which is explicit about why
> it's done that way.

I agree with the target name.

But I can't think of a really much easier way that what is in this
patch.

To make stubs you need to ifdef half of hw/vfio/vfio-common.h, or just
put the #ifdef in migration/target.c

Even althought I hate #ifdefs, I am not sure that the stubs options is
much clearly here.

Later, Juan.




Re: [RFC PATCH v2 3/5] Add APIs to get/set MTE tags

2021-03-25 Thread Juan Quintela
Haibo Xu  wrote:
> MTE spec provide instructions to retrieve the memory tags:
> (1) LDG, at 16 bytes granularity, and available in both user
> and kernel space;
> (2) LDGM, at 256 bytes granularity in maximum, and only
> available in kernel space
>
> To improve the performance, KVM has exposed the LDGM capability
> to user space by providing a new APIs. This patch is just a
> wrapper for the KVM APIs.
>
> Signed-off-by: Haibo Xu 
> ---
>  target/arm/kvm64.c   | 24 
>  target/arm/kvm_arm.h |  2 ++
>  2 files changed, 26 insertions(+)
>
> diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c
> index 73a191f8e1..3157025316 100644
> --- a/target/arm/kvm64.c
> +++ b/target/arm/kvm64.c
> @@ -1606,3 +1606,27 @@ bool kvm_arm_verify_ext_dabt_pending(CPUState *cs)
>  }
>  return false;
>  }
> +
> +int kvm_arm_mte_get_tags(uint64_t ipa, uint64_t len, uint8_t *buf)
> +{
> +struct kvm_arm_copy_mte_tags args = {
> +.guest_ipa = ipa,
> +.length = len,
> +.addr = buf,
> +.flags = KVM_ARM_TAGS_FROM_GUEST,
> +};
> +
> +return kvm_vm_ioctl(kvm_state, KVM_ARM_MTE_COPY_TAGS, &args);

Just a question, how fast/slow are this calls?

My understanding is that we are making a kvm call for each page that we
want to migrate, right?

Each time that we want to send it.

Later, Juan.


> +}
> +
> +int kvm_arm_mte_set_tags(uint64_t ipa, uint64_t len, uint8_t *buf)
> +{
> +struct kvm_arm_copy_mte_tags args = {
> +.guest_ipa = ipa,
> +.length = len,
> +.addr = buf,
> +.flags = KVM_ARM_TAGS_TO_GUEST,
> +};
> +
> +return kvm_vm_ioctl(kvm_state, KVM_ARM_MTE_COPY_TAGS, &args);
> +}
> diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h
> index 34f8daa377..bbb833d6c6 100644
> --- a/target/arm/kvm_arm.h
> +++ b/target/arm/kvm_arm.h
> @@ -360,6 +360,8 @@ int kvm_arm_vgic_probe(void);
>  
>  void kvm_arm_pmu_set_irq(CPUState *cs, int irq);
>  void kvm_arm_pmu_init(CPUState *cs);
> +int kvm_arm_mte_get_tags(uint64_t ipa, uint64_t len, uint8_t *buf);
> +int kvm_arm_mte_set_tags(uint64_t ipa, uint64_t len, uint8_t *buf);
>  
>  /**
>   * kvm_arm_pvtime_init:




Re: [PATCH 2/6] hw/isa/vt82c686: Simplify removing unuseful qemu_allocate_irqs() call

2021-03-25 Thread Richard Henderson

On 3/24/21 11:54 AM, Philippe Mathieu-Daudé wrote:

Instead of creating an input IRQ with qemu_allocate_irqs()
to pass it as output IRQ of the PIC, with its handler simply
dispatching into the "intr" output IRQ, simplify by directly
connecting the PIC to the "intr" named output.

Fixes: 3dc31cb8490 ("vt82c686: Move creation of ISA devices to the ISA bridge")
Signed-off-by: Philippe Mathieu-Daudé
---
  hw/isa/vt82c686.c | 10 +-
  1 file changed, 1 insertion(+), 9 deletions(-)


Reviewed-by: Richard Henderson 

r~




Re: [PATCH 4/6] hw/ide/via: Replace magic 2 value by ARRAY_SIZE / MAX_IDE_DEVS

2021-03-25 Thread Richard Henderson

On 3/24/21 11:54 AM, Philippe Mathieu-Daudé wrote:

Signed-off-by: Philippe Mathieu-Daudé
---
  hw/ide/via.c | 12 ++--
  1 file changed, 6 insertions(+), 6 deletions(-)


Reviewed-by: Richard Henderson 

r~




Re: [PATCH 3/5] tools/vhost-user-i2c: Add backend driver

2021-03-25 Thread Alex Bennée


Viresh Kumar  writes:

> On 25-03-21, 13:09, Jie Deng wrote:
>> 
>> On 2021/3/24 15:33, Viresh Kumar wrote:
>> > +
>> > +/* Definitions from virtio-i2c specifications */
>> > +#define VHOST_USER_I2C_MAX_QUEUES   1
>> > +
>> > +/* Status */
>> > +#define VIRTIO_I2C_MSG_OK   0
>> > +#define VIRTIO_I2C_MSG_ERR  1
>> > +
>> > +/* The bit 0 of the @virtio_i2c_out_hdr.@flags, used to group the 
>> > requests */
>> > +#define VIRTIO_I2C_FLAGS_FAIL_NEXT  0x0001
>> > +
>> > +/**
>> > + * struct virtio_i2c_out_hdr - the virtio I2C message OUT header
>> > + * @addr: the controlled device's address
>> > + * @padding: used to pad to full dword
>> > + * @flags: used for feature extensibility
>> > + */
>> > +struct virtio_i2c_out_hdr {
>> > +uint16_t addr;
>> > +uint16_t padding;
>> > +uint32_t flags;
>> > +} __attribute__((packed));
>> 
>> 
>> __le16,  __le32 ?
>
> Maybe, but I didn't do them because of this:
>
> docs/devel/style.rst:
>
> "Don't use Linux kernel internal types like u32, __u32 or __le32."
>  
>> > +
>> > +/**
>> > + * struct virtio_i2c_in_hdr - the virtio I2C message IN header
>> > + * @status: the processing result from the backend
>> > + */
>> > +struct virtio_i2c_in_hdr {
>> > +uint8_t status;
>> > +} __attribute__((packed));
>> > +
>> 
>> I understand these definitions can be removed once the frontend driver is
>> merged by the Linux ?
>
> Yes, we would be required to somehow include the uapi header that
> kernel is adding and then this won't be required.

What I often do is include a temporary patch in my series that includes
the updated uapi headers from my Linux branch and mark it as not for
merge until the uapi headers make it into a released tree.

>  
>> > +/* vhost-user-i2c definitions */
>> > +
>> > +#ifndef container_of
>> > +#define container_of(ptr, type, member) ({  \
>> > +const typeof(((type *) 0)->member) *__mptr = (ptr); \
>> > +(type *) ((char *) __mptr - offsetof(type, member));})
>> > +#endif
>> 
>> 
>> This seems to be a general interface.  I see there is a definition in
>> qemu/compiler.h.
>> 
>> Can we reuse it ?
>
> Damn. My bad (maybe not). I picked this part from the RPMB patchset
> that Alex sent and didn't bother looking for it.
>
> Though on the other hand, we are looking to make this file independent
> of qemu so it can be used by other hypervisors without any (or much)
> modifications, and maybe so it was done so.
>
> Alex ?


-- 
Alex Bennée



Re: [PATCH 3/6] hw/isa/vt82c686: Let ISA function expose ISA IRQs

2021-03-25 Thread Richard Henderson

On 3/24/21 11:54 AM, Philippe Mathieu-Daudé wrote:

The 2 cascaded 8259 PIC are managed by the PCI function #0
(ISA bridge). Expose the 16 IRQs on this function, so other
functions from the same chipset can access them.

Signed-off-by: Philippe Mathieu-Daudé
---
  hw/isa/vt82c686.c | 13 -
  1 file changed, 12 insertions(+), 1 deletion(-)


Reviewed-by: Richard Henderson 

r~




Re: [PATCH 5/6] hw/ide/via: Connect IDE function output IRQs to the ISA function input

2021-03-25 Thread Richard Henderson

On 3/24/21 11:54 AM, Philippe Mathieu-Daudé wrote:

To avoid abusing isa_get_irq(NULL) using a hidden ISA bridge
under the hood, let the IDE function expose 2 output IRQs,
and connect them to the ISA function inputs when creating
the south bridge chipset model in vt82c686b_southbridge_init.

Signed-off-by: Philippe Mathieu-Daudé 
---
  hw/ide/via.c| 19 +--
  hw/mips/fuloong2e.c |  9 -
  2 files changed, 25 insertions(+), 3 deletions(-)





@@ -112,7 +124,7 @@ static void via_ide_set_irq(void *opaque, int n, int level)
  d->config[0x70 + n * 8] &= ~0x80;
  }
  
-qemu_set_irq(isa_get_irq(NULL, 14 + n), level);

+qemu_set_irq(s->irq[n], level);
  }
  
  static void via_ide_reset(DeviceState *dev)

...

diff --git a/hw/mips/fuloong2e.c b/hw/mips/fuloong2e.c
index 931385c760f..f1c5db13b78 100644
--- a/hw/mips/fuloong2e.c
+++ b/hw/mips/fuloong2e.c
@@ -203,12 +203,19 @@ static void vt82c686b_southbridge_init(PCIBus *pci_bus, 
int slot, qemu_irq intc,
 I2CBus **i2c_bus)
  {
  PCIDevice *dev;
+DeviceState *isa;
  
  dev = pci_create_simple_multifunction(pci_bus, PCI_DEVFN(slot, 0), true,

TYPE_VT82C686B_ISA);
-qdev_connect_gpio_out_named(DEVICE(dev), "intr", 0, intc);
+isa = DEVICE(dev);
+qdev_connect_gpio_out_named(isa, "intr", 0, intc);
  
  dev = pci_create_simple(pci_bus, PCI_DEVFN(slot, 1), "via-ide");

+for (unsigned i = 0; i < 2; i++) {
+qdev_connect_gpio_out_named(DEVICE(dev), "ide-irq", i,


   ^^^ isa?


+qdev_get_gpio_in_named(isa,
+   "isa-irq", 14 + i));
+}


It all looks a little funny, but I think I follow it, and see that it can't be 
split further, because of the movement of the +14.


Reviewed-by: Richard Henderson 

r~




Memory address of ivshmem device

2021-03-25 Thread Luca Belluardo
Hi,
I'm using KVM from command line to run a VM and I have to create a ivshmem
between host and guest. The options that I pass are:
-device ivshmem-plain, memdev=id -object
memory-backend-file,size=1M,share,mem-path=/dev/shm/ivshmem,id=id
Now, from host side I can read and write the shmem. From guest not because
the OS in VM doesn't have a device PCI manager. I want to know if the
device has a fixed address on KVM VM so to force read and write to that
address in the application on VM.

Best regards

Luca Belluardo


Re: [PATCH v3] i386/cpu_dump: support AVX512 ZMM regs dump

2021-03-25 Thread Richard Henderson

On 3/24/21 9:15 PM, Robert Hoo wrote:

+} else if (env->xcr0 & XFEATURE_AVX) {


This is normally a 2-bit test.


I beg your pardon. What 2 bits?


I forget the names, but isn't the usual test xcr0 & 6 == 6?


BTW, checkpatch didn't warn me on this. It escaped.:)


Heh.


r~



Re: [RFC PATCH v2 5/5] Enable the MTE support for KVM guest

2021-03-25 Thread Juan Quintela
Haibo Xu  wrote:
> Signed-off-by: Haibo Xu 
> ---
>  hw/arm/virt.c | 22 +++---
>  1 file changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index 76658b93a3..36cfdb29e9 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -79,6 +79,7 @@
>  #include "hw/virtio/virtio-iommu.h"
>  #include "hw/char/pl011.h"
>  #include "qemu/guest-random.h"
> +#include "migration/misc.h"
>  
>  #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \
>  static void virt_##major##_##minor##_class_init(ObjectClass *oc, \
> @@ -828,6 +829,21 @@ static void virt_powerdown_req(Notifier *n, void *opaque)
>  }
>  }
>  
> +static int virt_precopy_notify(NotifierWithReturn *n, void *data)
> +{
> +PrecopyNotifyData *pnd = data;
> +
> +switch (pnd->reason) {
> +case PRECOPY_NOTIFY_SETUP:
> +precopy_enable_metadata_migration();
> +break;
> +default:
> +break;
> +}
> +
> +return 0;
> +}
> +
>  static void create_gpio_keys(char *fdt, DeviceState *pl061_dev,
>   uint32_t phandle)
>  {
> @@ -1912,9 +1928,9 @@ static void machvirt_init(MachineState *machine)
>  }
>  
>  if (vms->mte && kvm_enabled()) {
> -error_report("mach-virt: KVM does not support providing "
> - "MTE to the guest CPU");
> -exit(1);
> +/* connect migration precopy request */
> +vms->precopy_notifier.notify = virt_precopy_notify;
> +precopy_add_notifier(&vms->precopy_notifier);
>  }
>  
>  create_fdt(vms);

Why are you using a notifier here?
It is not enough for you just esetup at this point a variable somewhere
   "foo->mte_enabled = true"

And create a function that just does:

bool is_mte_enabled(vode)
{
return foo->mte_enabled;
}

And just check that everywhere?

Later, Juan.




Re: [PATCH v3] linux-user/s390x: Use the guest pointer for the sigreturn stub

2021-03-25 Thread Richard Henderson

On 3/24/21 12:51 PM, Andreas Krebbel wrote:

When setting up the pointer for the sigreturn stub in the return
address register (r14) we currently use the host frame address instead
of the guest frame address.

Note: This only caused problems if Qemu has been built with
--disable-pie (as it is in distros nowadays). Otherwise guest_base
defaults to 0 hiding the actual problem.

Signed-off-by: Andreas Krebbel
---
  linux-user/s390x/signal.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)


Reviewed-by: Richard Henderson 

r~




Re: [PATCH-for-6.1 1/2] hw/block/pflash_cfi02: Set romd mode in pflash_cfi02_realize()

2021-03-25 Thread Richard Henderson

On 3/25/21 6:09 AM, Philippe Mathieu-Daudé wrote:

The ROMD mode isn't related to mapping setup.
Ideally we'd set this mode when the state machine resets,
but for now simply move it to pflash_cfi02_realize() to
not introduce logical change.

Signed-off-by: Philippe Mathieu-Daudé
---
  hw/block/pflash_cfi02.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)


Reviewed-by: Richard Henderson 

r~




Re: [PATCH-for-6.1 2/2] hw/block/pflash_cfi02: Do not create aliases when not necessary

2021-03-25 Thread Richard Henderson

On 3/25/21 6:09 AM, Philippe Mathieu-Daudé wrote:

When no mapping is requested, it is pointless to create
alias regions.
Only create them when multiple mappings are requested to
simplify the memory layout. The flatview is not changed.

For example using 'qemu-system-sh4 -M r2d -S -monitor stdio',

* before:

   (qemu) info mtree
   address-space: memory
 - (prio 0, i/o): system
   -00ff (prio 0, i/o): pflash
 -00ff (prio 0, romd): alias pflash-alias 
@r2d.flash -00ff
   0400-043f (prio 0, i/o): r2d-fpga
   0c00-0fff (prio 0, ram): r2d.sdram
   (qemu) info mtree -f
   FlatView #0
AS "memory", root: system
AS "cpu-memory-0", root: system
Root memory region: system
 -00ff (prio 0, romd): r2d.flash
 0400-043f (prio 0, i/o): r2d-fpga
 0c00-0fff (prio 0, ram): r2d.sdram

* after:

   (qemu) info mtree
   address-space: memory
 - (prio 0, i/o): system
   -00ff (prio 0, romd): r2d.flash
   0400-043f (prio 0, i/o): r2d-fpga
   0c00-0fff (prio 0, ram): r2d.sdram
   (qemu) info mtree -f
   FlatView #0
AS "memory", root: system
AS "cpu-memory-0", root: system
Root memory region: system
 -00ff (prio 0, romd): r2d.flash
 0400-043f (prio 0, i/o): r2d-fpga
 0c00-0fff (prio 0, ram): r2d.sdram

Signed-off-by: Philippe Mathieu-Daudé 
---
  hw/block/pflash_cfi02.c | 8 ++--
  1 file changed, 6 insertions(+), 2 deletions(-)



Reviewed-by: Richard Henderson 

r~



diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index 35e30bb812c..02c514fb6e0 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -917,8 +917,12 @@ static void pflash_cfi02_realize(DeviceState *dev, Error 
**errp)
  pfl->sector_erase_map = bitmap_new(pfl->total_sectors);
  
  pfl->rom_mode = true;

-pflash_setup_mappings(pfl);
-sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem);
+if (pfl->mappings > 1) {
+pflash_setup_mappings(pfl);
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem);
+} else {
+sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->orig_mem);
+}
  
  timer_init_ns(&pfl->timer, QEMU_CLOCK_VIRTUAL, pflash_timer, pfl);

  pfl->status = 0;






Re: [PATCH v2 04/10] Acceptance Tests: move useful ssh methods to base class

2021-03-25 Thread Auger Eric
Hi Cleber,

On 3/24/21 11:23 PM, Cleber Rosa wrote:
> On Wed, Mar 24, 2021 at 10:07:31AM +0100, Auger Eric wrote:
>> Hi Cleber,
>>
>> On 3/23/21 11:15 PM, Cleber Rosa wrote:
>>> Both the virtiofs submounts and the linux ssh mips malta tests
>>> contains useful methods related to ssh that deserve to be made
>>> available to other tests.  Let's move them to the base LinuxTest
>> nit: strictly speaking they are moved to another class which is
>> inherited by LinuxTest, right?
>>> class.
>>>
>>> The method that helps with setting up an ssh connection will now
>>> support both key and password based authentication, defaulting to key
>>> based.
>>>
>>> Signed-off-by: Cleber Rosa 
>>> Reviewed-by: Wainer dos Santos Moschetta 
>>> Reviewed-by: Willian Rampazzo 
>>> ---
>>>  tests/acceptance/avocado_qemu/__init__.py | 48 ++-
>>>  tests/acceptance/linux_ssh_mips_malta.py  | 38 ++
>>>  tests/acceptance/virtiofs_submounts.py| 37 -
>>>  3 files changed, 50 insertions(+), 73 deletions(-)
>>>
>>> diff --git a/tests/acceptance/avocado_qemu/__init__.py 
>>> b/tests/acceptance/avocado_qemu/__init__.py
>>> index 83b1741ec8..67f75f66e5 100644
>>> --- a/tests/acceptance/avocado_qemu/__init__.py
>>> +++ b/tests/acceptance/avocado_qemu/__init__.py
>>> @@ -20,6 +20,7 @@
>>>  from avocado.utils import cloudinit
>>>  from avocado.utils import datadrainer
>>>  from avocado.utils import network
>>> +from avocado.utils import ssh
>>>  from avocado.utils import vmimage
>>>  from avocado.utils.path import find_command
>>>  
>>> @@ -43,6 +44,8 @@
>>>  from qemu.accel import kvm_available
>>>  from qemu.accel import tcg_available
>>>  from qemu.machine import QEMUMachine
>>> +from qemu.utils import get_info_usernet_hostfwd_port
>>> +
>>>  
>>>  def is_readable_executable_file(path):
>>>  return os.path.isfile(path) and os.access(path, os.R_OK | os.X_OK)
>>> @@ -253,7 +256,50 @@ def fetch_asset(self, name,
>>>  cancel_on_missing=cancel_on_missing)
>>>  
>>>  
>>> -class LinuxTest(Test):
>>> +class LinuxSSHMixIn:
>>> +"""Contains utility methods for interacting with a guest via SSH."""
>>> +
>>> +def ssh_connect(self, username, credential, credential_is_key=True):
>>> +self.ssh_logger = logging.getLogger('ssh')
>>> +res = self.vm.command('human-monitor-command',
>>> +  command_line='info usernet')
>>> +port = get_info_usernet_hostfwd_port(res)
>>> +self.assertIsNotNone(port)
>>> +self.assertGreater(port, 0)
>>> +self.log.debug('sshd listening on port: %d', port)
>>> +if credential_is_key:
>>> +self.ssh_session = ssh.Session('127.0.0.1', port=port,
>>> +   user=username, key=credential)
>>> +else:
>>> +self.ssh_session = ssh.Session('127.0.0.1', port=port,
>>> +   user=username, 
>>> password=credential)
>>> +for i in range(10):
>>> +try:
>>> +self.ssh_session.connect()
>>> +return
>>> +except:
>>> +time.sleep(4)
>>> +pass
>>> +self.fail('ssh connection timeout')
>>> +
>>> +def ssh_command(self, command):
>>> +self.ssh_logger.info(command)
>>> +result = self.ssh_session.cmd(command)
>>> +stdout_lines = [line.rstrip() for line
>>> +in result.stdout_text.splitlines()]
>>> +for line in stdout_lines:
>>> +self.ssh_logger.info(line)
>>> +stderr_lines = [line.rstrip() for line
>>> +in result.stderr_text.splitlines()]
>>> +for line in stderr_lines:
>>> +self.ssh_logger.warning(line)
>>> +
>>> +self.assertEqual(result.exit_status, 0,
>>> + f'Guest command failed: {command}')
>>> +return stdout_lines, stderr_lines
>>> +
>>> +
>>> +class LinuxTest(Test, LinuxSSHMixIn):
>>>  """Facilitates having a cloud-image Linux based available.
>>>  
>>>  For tests that indend to interact with guests, this is a better choice
>>> diff --git a/tests/acceptance/linux_ssh_mips_malta.py 
>>> b/tests/acceptance/linux_ssh_mips_malta.py
>>> index 052008f02d..3f590a081f 100644
>>> --- a/tests/acceptance/linux_ssh_mips_malta.py
>>> +++ b/tests/acceptance/linux_ssh_mips_malta.py
>>> @@ -12,7 +12,7 @@
>>>  import time
>>>  
>>>  from avocado import skipUnless
>>> -from avocado_qemu import Test
>>> +from avocado_qemu import Test, LinuxSSHMixIn
>>>  from avocado_qemu import wait_for_console_pattern
>>>  from avocado.utils import process
>>>  from avocado.utils import archive
>>> @@ -21,7 +21,7 @@
>>>  from qemu.utils import get_info_usernet_hostfwd_port
>> Can't you remove this now?
>>>  
>>>  
> 
> Yes, good catch!
> 
>>> -class LinuxSSH(Test):
>>> +class LinuxSSH(Test, LinuxSSHMixIn):
>> out of curiosity why can't it be mi

Re: [PATCH 01/15] Hexagon (target/hexagon) TCG generation cleanup

2021-03-25 Thread Richard Henderson

On 3/24/21 8:49 PM, Taylor Simpson wrote:

Simplify TCG generation of hex_reg_written

Address feedback from Richard Henderson 

Signed-off-by: Taylor Simpson 
---
  target/hexagon/genptr.c | 12 +---
  1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/target/hexagon/genptr.c b/target/hexagon/genptr.c
index 7481f4c..349b949 100644
--- a/target/hexagon/genptr.c
+++ b/target/hexagon/genptr.c
@@ -43,9 +43,15 @@ static inline void gen_log_predicated_reg_write(int rnum, 
TCGv val, int slot)
  tcg_gen_movcond_tl(TCG_COND_EQ, hex_new_value[rnum], slot_mask, zero,
 val, hex_new_value[rnum]);
  #if HEX_DEBUG
-/* Do this so HELPER(debug_commit_end) will know */
-tcg_gen_movcond_tl(TCG_COND_EQ, hex_reg_written[rnum], slot_mask, zero,
-   one, hex_reg_written[rnum]);
+/*
+ * Do this so HELPER(debug_commit_end) will know
+ *
+ * Note that slot_mask indicates the value is not written
+ * (i.e., slot was cancelled), so we create a true/false value before
+ * or'ing with hex_reg_written[rnum].
+ */
+tcg_gen_setcond_tl(TCG_COND_EQ, slot_mask, slot_mask, zero);
+tcg_gen_or_tl(hex_reg_written[rnum], hex_reg_written[rnum], slot_mask);
  #endif
  
  tcg_temp_free(one);


The one variable is no longer used.

r~



Re: Crashes with qemu-system-ppc64

2021-03-25 Thread Mark Cave-Ayland

On 23/03/2021 22:57, Peter Maydell wrote:


On Tue, 23 Mar 2021 at 21:21, Mark Cave-Ayland
 wrote:

I'm not sure what the right solution is here. In my mind there hasn't really 
been any
difference between TYPE_DEVICE and TYPE_SYS_BUS_DEVICE other than the APIs that
expose the memory regions and IRQs are different, but clearly platform bus
expects/defines a different behaviour here.

Probably the quickest solution for now would be to change the DBDMA device so 
that it
is derived from TYPE_DEVICE rather than TYPE_SYS_BUS_DEVICE and make the 
relevant
changes if everyone agrees?


You want to be at least cautious about doing that. TYPE_DEVICE objects
don't get reset usually, because they are not part of the qbus hierarchy
(all TYPE_SYS_BUS_DEVICE devices live on the sysbus and get reset when
the sysbus is reset). So you would need the (currently nonexistent)
reset function of the containing macio device to manually reset any
TYPE_DEVICE children it has. (This is one of the areas where reset is
a mess, incidentally: logically speaking if you have a PCI device then
you want its children to all get reset when the PCI device itself is
reset; as it stands that doesn't happen, because its sysbus children
are on the sysbus, and a pci-bus-reset won't touch them.)

I forget how the platform bus stuff is supposed to work, but something
should be arranging that it only happens for a pretty restrictive subset
of devices -- in general it should certainly not be firing for random
sysbus devices that are part of something else.

It's a pretty old commit (from 2018, one of Igor's), but I wonder if
this was broken by commit a3fc8396352e945f9. The original design of
the platform bus was that the "grab unassigned IRQs and MMIO regions"
hook got run as a machine-init-done hook. That meant that by definition
the board code had finished setting up all its sysbus devices, and
anything still unconnected must be (assuming not a bug) something the
user requested via -device to be put on the platform bus. But in
commit a3fc8396352e945f9 we changed this to use the hotplug-handler
callbacks, which happen when the device is realized. So it stopped
being true that we would only find loose MMIOs and IRQs on the user's
sysbus devices and now we're also incorrectly grabbing parts of
devices that are supposed to be being wired up by QEMU code before
that code has a chance to do that wiring.

There must still be something causing this not to happen literally for
every sysbus device, or we'd have noticed a lot earlier. I'm not sure
what's specifically different here, but I think it is that:
  (1) we only create the platform bus itself as pretty much the
  last thing we do in machine init. This (accidentally?)
  means it doesn't get to see most of the sysbus devices in
  the board itself
  (2) macio-oldworld is a pluggable PCI device which happens to
  use a sysbus device as part of its implementation, which
  is probably not very common

I think the long term fix is that we either need to undo
a3fc8396352e945f9 so that we only run after all other device
creation code has run and the unassigned IRQs and MMIOs really
are just the loose ends, or alternatively we need to make the
hooks much more restrictive about identifying what devices are
supposed to go into the platform bus.


Thanks for the analysis: I can certainly see how the above commit would have changed 
the behaviour. Looking at hw/ppc/e590plat.c in e500plat_machine_class_init() I see 
that line 101 reads "machine_class_allow_dynamic_sysbus_dev(mc, TYPE_ETSEC_COMMON);" 
which looks like it is intended to add a class restriction to this functionality.


In machine_initfn() a callback for machine_init_notify() is added to perform the 
check but the macio-oldworld device is realized first, because qmp_x_exit_preconfig() 
calls qemu_create_cli_devices() to realize the devices just before 
qemu_machine_creation_done() where the notifier is invoked.



Second note: does it actually make sense for a user to create
a macio-oldworld device and plug it into anything? It's a PCI
device, but is it really a generally usable device rather than
a specific built-into-the-board part of the g3beige machine ?
If it isn't actually useful for a user to create it on the command
line with -device, we could sidestep the whole thing for 6.0 by
marking it dc->user_creatable = false ...


I'd prefer not to do that if possible since the macio device is a good example to 
have as something that passes device-introspect-test whilst containing several 
different child devices.


Given that the DBDMA device hasn't changed for some time and the above commit dates 
back to 2018 then I'd be inclined to leave it for now unless it is causing gitlab CI 
to fail.



ATB,

Mark.



Re: [PATCH 02/15] Hexagon (target/hexagon) remove unnecessary inline directives

2021-03-25 Thread Richard Henderson

On 3/24/21 8:49 PM, Taylor Simpson wrote:

Address feedback from Richard Henderson 

Signed-off-by: Taylor Simpson 
---
  linux-user/hexagon/cpu_loop.c |  2 +-
  target/hexagon/cpu.c  |  9 -
  target/hexagon/cpu.h  |  6 ++
  target/hexagon/decode.c   |  6 +++---
  target/hexagon/fma_emu.c  | 39 ---
  target/hexagon/op_helper.c| 39 +++
  target/hexagon/translate.c|  2 +-
  7 files changed, 50 insertions(+), 53 deletions(-)

diff --git a/linux-user/hexagon/cpu_loop.c b/linux-user/hexagon/cpu_loop.c
index 9a68ca0..a752a0a 100644
--- a/linux-user/hexagon/cpu_loop.c
+++ b/linux-user/hexagon/cpu_loop.c
@@ -25,7 +25,7 @@
  
  void cpu_loop(CPUHexagonState *env)

  {
-CPUState *cs = CPU(hexagon_env_get_cpu(env));
+CPUState *cs = CPUSTATE_FROM_ENV(env);


This is not removing inlines from functions in c files, so this patch should be 
split.



-static inline HexagonCPU *hexagon_env_get_cpu(CPUHexagonState *env)
-{
-return container_of(env, HexagonCPU, env);
-}
+#define HEXAGONCPU_FROM_ENV(env)container_of((env), HexagonCPU, env)
+#define CPUSTATE_FROM_ENV(env)  CPU(HEXAGONCPU_FROM_ENV(env))


Since a578cdfbdd8f, these should be replaced by env_archcpu and env_cpu 
respectively.



r~



Re: Crashes with qemu-system-ppc64

2021-03-25 Thread Peter Maydell
On Thu, 25 Mar 2021 at 12:57, Mark Cave-Ayland
 wrote:
> Thanks for the analysis: I can certainly see how the above commit would have 
> changed
> the behaviour. Looking at hw/ppc/e590plat.c in e500plat_machine_class_init() 
> I see
> that line 101 reads "machine_class_allow_dynamic_sysbus_dev(mc, 
> TYPE_ETSEC_COMMON);"
> which looks like it is intended to add a class restriction to this 
> functionality.

Aha. I thought there was a restriction somewhere but hadn't found that
function. I think the device plug callback functions should check that
list rather than saying "any TYPE_SYS_BUS_DEVICE is fine".

> In machine_initfn() a callback for machine_init_notify() is added to perform 
> the
> check but the macio-oldworld device is realized first

Also, this check is only for "did the user dynamically create a sysbus
device that isn't an allowed one", which is a necessary check, but
not quite the same thing as "is this device we're looking at one we want to
assume belongs to the platform bus".

I'll put together a patch...

thanks
-- PMM



[Bug 1918302] Re: qemu-system-arm segfaults while servicing SYS_HEAPINFO

2021-03-25 Thread Peter Maydell
I think there's still work to do here -- we don't properly tell
semihosting where the memory is on M-profile or in all A-profile cases.
I don't think that "look at the stack pointer" is a very good heuristic.

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

Title:
  qemu-system-arm segfaults while servicing SYS_HEAPINFO

Status in QEMU:
  Fix Committed

Bug description:
  I compiled QEMU version 5.2.0 from source on Ubuntu 18.04, and tried
  to use it to run the attached bare-metal Arm hello-world image, using
  the command line

  qemu-system-arm -M microbit -semihosting -nographic -device
  loader,file=hello.hex

  The result was that qemu-system-arm itself died of a segfault.
  Compiling it for debugging, the location of the segfault was in
  target/arm/arm-semi.c, in the case handler for the semihosting call
  TARGET_SYS_HEAPINFO, on line 1020 which assigns to 'rambase':

  const struct arm_boot_info *info = env->boot_info;
  target_ulong rambase = info->loader_start;

  and the problem seems to be that 'info', aka env->boot_info, is NULL
  in this context.

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



Re: [PATCH v3 15/16] qapi/expr.py: move related checks inside check_xxx functions

2021-03-25 Thread Markus Armbruster
John Snow  writes:

> On 2/25/21 10:28 AM, Markus Armbruster wrote:
>> John Snow  writes:
>> 
>>> There's not a big obvious difference between the types of checks that
>>> happen in the main function versus the kind that happen in the
>>> functions. Now they're in one place for each of the main types.
>>>
>>> As part of the move, spell out the required and optional keywords so
>>> they're obvious at a glance. Use tuples instead of lists for immutable
>>> data, too.
>>>
>>> Signed-off-by: John Snow 
>>> Reviewed-by: Cleber Rosa 
>> 
>> No objection to changing read-only lists to tuples (applies to previous
>> patch, too).
>> 
>> No objection to turning positional into keyword arguments where that
>> improves clarity.
>> 
>> I have doubts on the code motion.  Yes, the checks for each type are now
>> together.  On the other hand, the check_keys() are now separate.  I can
>> no longer see all the keys at a glance.
>> 
>
> I guess it depends on where you wanted to see them; I thought it was 
> strange that in check_foobar I couldn't see what foobar's valid keys 
> were without scrolling back to the bottom of the file.
>
> Needing to see all the keys for the disparate forms together was not a 
> case I ran into, but you can always drop this patch for now if you'd 
> like.

Let's shelve it for now.

>   I had some more adventurous patches that keeps pushing in this 
> direction, but I don't know if it's really important.

When I work on a something, I tend to accumulate semi-related cleanups.
Including them is rarely a problem for reviewers when the result is two
dozen patches or so.  When this isn't the case, I can:

* Pick them into a separate cleanup series to go before the real work.
  Risks delaying the real work.

* Funnel them onto a cleanup branch to flushed later.  Risks lonely
  death in a rotting branch.

* Force myself to abstain from improving things that could really use
  improvement.  I call this "sitting on my hands".

This patch is in part three of at least six.  Almost 90 patches up to
part three, with many more to come.  I'm *desperate* to limit scope to
not get overwhelmed.  Please consider the remedies above.  This is a cry
for help, not a demand.

>   My appetite in 
> this area has waned since November.

I understand.




[Bug 1909247] Re: QEMU: use after free vulnerability in esp_do_dma() in hw/scsi/esp.c

2021-03-25 Thread Mark Cave-Ayland
If Alex is interested in having a fuzz-proof device as a starting point
for fuzzing QEMU's SCSI layer then I don't mind doing the basic work as
I've spent a few months deep in the internals of the ESP controller, and
it makes sense to look at this whilst it is all still fresh. I'd say
there's at least one more set of ESP changes already waiting for after
the 6.0 release.

PJP:
Your change to esp-pci.c looks like a genuine issue, although there is an 
inconsistency within ESP as to what determines whether a request is in progress 
or not. My v2 patchset above uses the request member being non-NULL to indicate 
a valid request, but this should be made consistent throughout the driver.

Can you provide a qtest reproducer so that it can be incorporated into
the test included in the v2 patchset and also allow me to check that
this issue has been fixed?

Alex:
If you can try PJP's patch to esp-pci.c and if you still see some issues then 
please update this bug with a test case or two, and I will look at them when I 
get a moment.

Mauro:
Thanks for the test case - again I shall look at this when I have some 
available time.

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

Title:
  QEMU: use after free vulnerability in esp_do_dma() in hw/scsi/esp.c

Status in QEMU:
  New

Bug description:
  A use-after-free vulnerability was found in the am53c974 SCSI host bus
  adapter emulation of QEMU. It could occur in the esp_do_dma() function
  in hw/scsi/esp.c while handling the 'Information Transfer' command
  (CMD_TI). A privileged guest user may abuse this flaw to crash the
  QEMU process on the host, resulting in a denial of service or
  potential code execution with the privileges of the QEMU process.

  This issue was reported by Cheolwoo Myung (Seoul National University).

  Original report:
  Using hypervisor fuzzer, hyfuzz, I found a use-after-free issue in
  am53c974 emulator of QEMU enabled ASan.

  It occurs while transferring information, as it does not check the
  buffer to be transferred.

  A malicious guest user/process could use this flaw to crash the QEMU
  process resulting in DoS scenario.

  To reproduce this issue, please run the QEMU with the following command
  line.

  # To enable ASan option, please set configuration with the following
  $ ./configure --target-list=i386-softmmu --disable-werror --enable-sanitizers
  $ make

  # To reproduce this issue, please run the QEMU process with the following 
command line
  $ ./qemu-system-i386 -m 512 -drive 
file=./hyfuzz.img,index=0,media=disk,format=raw \
  -device am53c974,id=scsi -device scsi-hd,drive=SysDisk \
  -drive id=SysDisk,if=none,file=./disk.img

  Please find attached the disk images to reproduce this issue.

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



[PATCH] MAINTAINERS: add/replace backups for some s390 areas

2021-03-25 Thread Matthew Rosato
S390 PCI currently has no backup, add one.  Add an additional backup
for vfio-ccw and refresh the backup for vfio-ap.

Signed-off-by: Matthew Rosato 
---
 MAINTAINERS | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 554be84..5620fc8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1516,6 +1516,7 @@ L: qemu-s3...@nongnu.org
 
 S390 PCI
 M: Matthew Rosato 
+M: Eric Farman 
 S: Supported
 F: hw/s390x/s390-pci*
 F: include/hw/s390x/s390-pci*
@@ -1830,6 +1831,7 @@ F: docs/igd-assign.txt
 vfio-ccw
 M: Cornelia Huck 
 M: Eric Farman 
+M: Matthew Rosato 
 S: Supported
 F: hw/vfio/ccw.c
 F: hw/s390x/s390-ccw.c
@@ -1839,10 +1841,9 @@ T: git https://gitlab.com/cohuck/qemu.git s390-next
 L: qemu-s3...@nongnu.org
 
 vfio-ap
-M: Christian Borntraeger 
 M: Tony Krowiak 
 M: Halil Pasic 
-M: Pierre Morel 
+M: Jason Herne 
 S: Supported
 F: hw/s390x/ap-device.c
 F: hw/s390x/ap-bridge.c
-- 
1.8.3.1




Re: [PATCH] MAINTAINERS: add/replace backups for some s390 areas

2021-03-25 Thread Pierre Morel




On 3/25/21 2:55 PM, Matthew Rosato wrote:

S390 PCI currently has no backup, add one.  Add an additional backup
for vfio-ccw and refresh the backup for vfio-ap.

Signed-off-by: Matthew Rosato 
---
  MAINTAINERS | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 554be84..5620fc8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1516,6 +1516,7 @@ L: qemu-s3...@nongnu.org
  
  S390 PCI

  M: Matthew Rosato 
+M: Eric Farman 
  S: Supported
  F: hw/s390x/s390-pci*
  F: include/hw/s390x/s390-pci*
@@ -1830,6 +1831,7 @@ F: docs/igd-assign.txt
  vfio-ccw
  M: Cornelia Huck 
  M: Eric Farman 
+M: Matthew Rosato 
  S: Supported
  F: hw/vfio/ccw.c
  F: hw/s390x/s390-ccw.c
@@ -1839,10 +1841,9 @@ T: git https://gitlab.com/cohuck/qemu.git s390-next
  L: qemu-s3...@nongnu.org
  
  vfio-ap

-M: Christian Borntraeger 
  M: Tony Krowiak 
  M: Halil Pasic 
-M: Pierre Morel 
+M: Jason Herne 
  S: Supported
  F: hw/s390x/ap-device.c
  F: hw/s390x/ap-bridge.c



Acked-by: Pierre Morel 


--
Pierre Morel
IBM Lab Boeblingen



Re: [PATCH] MAINTAINERS: add/replace backups for some s390 areas

2021-03-25 Thread Eric Farman




On 3/25/21 9:55 AM, Matthew Rosato wrote:

S390 PCI currently has no backup, add one.  Add an additional backup
for vfio-ccw and refresh the backup for vfio-ap.

Signed-off-by: Matthew Rosato 


Acked-by: Eric Farman 


---
  MAINTAINERS | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 554be84..5620fc8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1516,6 +1516,7 @@ L: qemu-s3...@nongnu.org
  
  S390 PCI

  M: Matthew Rosato 
+M: Eric Farman 
  S: Supported
  F: hw/s390x/s390-pci*
  F: include/hw/s390x/s390-pci*
@@ -1830,6 +1831,7 @@ F: docs/igd-assign.txt
  vfio-ccw
  M: Cornelia Huck 
  M: Eric Farman 
+M: Matthew Rosato 
  S: Supported
  F: hw/vfio/ccw.c
  F: hw/s390x/s390-ccw.c
@@ -1839,10 +1841,9 @@ T: git https://gitlab.com/cohuck/qemu.git s390-next
  L: qemu-s3...@nongnu.org
  
  vfio-ap

-M: Christian Borntraeger 
  M: Tony Krowiak 
  M: Halil Pasic 
-M: Pierre Morel 
+M: Jason Herne 
  S: Supported
  F: hw/s390x/ap-device.c
  F: hw/s390x/ap-bridge.c





[PATCH v11 2/7] vt82c686: Add VT8231_SUPERIO based on VIA_SUPERIO

2021-03-25 Thread BALATON Zoltan
The VT8231 south bridge is very similar to VT82C686B but there are
some differences in register addresses and functionality, e.g. the
VT8231 only has one serial port. This commit adds VT8231_SUPERIO
subclass based on the abstract VIA_SUPERIO class to emulate the
superio part of VT8231.

Signed-off-by: BALATON Zoltan 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/isa/vt82c686.c | 102 ++
 1 file changed, 102 insertions(+)

diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c
index 6fb81c4ac6..b3048fd37e 100644
--- a/hw/isa/vt82c686.c
+++ b/hw/isa/vt82c686.c
@@ -417,6 +417,107 @@ static const TypeInfo vt82c686b_superio_info = {
 };
 
 
+#define TYPE_VT8231_SUPERIO "vt8231-superio"
+
+static void vt8231_superio_cfg_write(void *opaque, hwaddr addr,
+ uint64_t data, unsigned size)
+{
+ViaSuperIOState *sc = opaque;
+uint8_t idx = sc->regs[0];
+
+if (addr == 0) { /* config index register */
+sc->regs[0] = data;
+return;
+}
+
+/* config data register */
+trace_via_superio_write(idx, data);
+switch (idx) {
+case 0x00 ... 0xdf:
+case 0xe7 ... 0xef:
+case 0xf0 ... 0xf1:
+case 0xf5:
+case 0xf8:
+case 0xfd:
+/* ignore write to read only registers */
+return;
+default:
+qemu_log_mask(LOG_UNIMP,
+  "via_superio_cfg: unimplemented register 0x%x\n", idx);
+break;
+}
+sc->regs[idx] = data;
+}
+
+static const MemoryRegionOps vt8231_superio_cfg_ops = {
+.read = via_superio_cfg_read,
+.write = vt8231_superio_cfg_write,
+.endianness = DEVICE_NATIVE_ENDIAN,
+.impl = {
+.min_access_size = 1,
+.max_access_size = 1,
+},
+};
+
+static void vt8231_superio_reset(DeviceState *dev)
+{
+ViaSuperIOState *s = VIA_SUPERIO(dev);
+
+memset(s->regs, 0, sizeof(s->regs));
+/* Device ID */
+s->regs[0xf0] = 0x3c;
+/* Device revision */
+s->regs[0xf1] = 0x01;
+/* Function select - all disabled */
+vt8231_superio_cfg_write(s, 0, 0xf2, 1);
+vt8231_superio_cfg_write(s, 1, 0x03, 1);
+/* Serial port base addr */
+vt8231_superio_cfg_write(s, 0, 0xf4, 1);
+vt8231_superio_cfg_write(s, 1, 0xfe, 1);
+/* Parallel port base addr */
+vt8231_superio_cfg_write(s, 0, 0xf6, 1);
+vt8231_superio_cfg_write(s, 1, 0xde, 1);
+/* Floppy ctrl base addr */
+vt8231_superio_cfg_write(s, 0, 0xf7, 1);
+vt8231_superio_cfg_write(s, 1, 0xfc, 1);
+
+vt8231_superio_cfg_write(s, 0, 0, 1);
+}
+
+static void vt8231_superio_init(Object *obj)
+{
+VIA_SUPERIO(obj)->io_ops = &vt8231_superio_cfg_ops;
+}
+
+static uint16_t vt8231_superio_serial_iobase(ISASuperIODevice *sio,
+ uint8_t index)
+{
+return 0x2f8; /* FIXME: This should be settable via registers f2-f4 */
+}
+
+static void vt8231_superio_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+ISASuperIOClass *sc = ISA_SUPERIO_CLASS(klass);
+
+dc->reset = vt8231_superio_reset;
+sc->serial.count = 1;
+sc->serial.get_iobase = vt8231_superio_serial_iobase;
+sc->parallel.count = 1;
+sc->ide.count = 0; /* emulated by via-ide */
+sc->floppy.count = 1;
+}
+
+static const TypeInfo vt8231_superio_info = {
+.name  = TYPE_VT8231_SUPERIO,
+.parent= TYPE_VIA_SUPERIO,
+.instance_size = sizeof(ViaSuperIOState),
+.instance_init = vt8231_superio_init,
+.class_size= sizeof(ISASuperIOClass),
+.class_init= vt8231_superio_class_init,
+};
+
+
 OBJECT_DECLARE_SIMPLE_TYPE(VT82C686BISAState, VT82C686B_ISA)
 
 struct VT82C686BISAState {
@@ -540,6 +641,7 @@ static void vt82c686b_register_types(void)
 type_register_static(&vt8231_pm_info);
 type_register_static(&via_superio_info);
 type_register_static(&vt82c686b_superio_info);
+type_register_static(&vt8231_superio_info);
 type_register_static(&via_info);
 }
 
-- 
2.21.4




[PATCH v11 7/7] hw/ppc: Add emulation of Genesi/bPlan Pegasos II

2021-03-25 Thread BALATON Zoltan
Add new machine called pegasos2 emulating the Genesi/bPlan Pegasos II,
a PowerPC board based on the Marvell MV64361 system controller and the
VIA VT8231 integrated south bridge/superio chips. It can run Linux,
AmigaOS and a wide range of MorphOS versions. Currently a firmware ROM
image is needed to boot and only MorphOS has a video driver to produce
graphics output. Linux could work too but distros that supported this
machine don't include usual video drivers so those only run with
serial console for now.

Signed-off-by: BALATON Zoltan 
Reviewed-by: Philippe Mathieu-Daudé 
---
 MAINTAINERS |  10 ++
 default-configs/devices/ppc-softmmu.mak |   2 +
 hw/ppc/Kconfig  |   9 ++
 hw/ppc/meson.build  |   2 +
 hw/ppc/pegasos2.c   | 144 
 5 files changed, 167 insertions(+)
 create mode 100644 hw/ppc/pegasos2.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 554be84b32..0343d04da9 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1368,6 +1368,16 @@ F: pc-bios/canyonlands.dt[sb]
 F: pc-bios/u-boot-sam460ex-20100605.bin
 F: roms/u-boot-sam460ex
 
+pegasos2
+M: BALATON Zoltan 
+R: David Gibson 
+L: qemu-...@nongnu.org
+S: Maintained
+F: hw/ppc/pegasos2.c
+F: hw/pci-host/mv64361.c
+F: hw/pci-host/mv643xx.h
+F: include/hw/pci-host/mv64361.h
+
 RISC-V Machines
 ---
 OpenTitan
diff --git a/default-configs/devices/ppc-softmmu.mak 
b/default-configs/devices/ppc-softmmu.mak
index 61b78b844d..4535993d8d 100644
--- a/default-configs/devices/ppc-softmmu.mak
+++ b/default-configs/devices/ppc-softmmu.mak
@@ -14,5 +14,7 @@ CONFIG_SAM460EX=y
 CONFIG_MAC_OLDWORLD=y
 CONFIG_MAC_NEWWORLD=y
 
+CONFIG_PEGASOS2=n
+
 # For PReP
 CONFIG_PREP=y
diff --git a/hw/ppc/Kconfig b/hw/ppc/Kconfig
index d11dc30509..e51e0e5e5a 100644
--- a/hw/ppc/Kconfig
+++ b/hw/ppc/Kconfig
@@ -68,6 +68,15 @@ config SAM460EX
 select USB_OHCI
 select FDT_PPC
 
+config PEGASOS2
+bool
+select MV64361
+select VT82C686
+select IDE_VIA
+select SMBUS_EEPROM
+# This should come with VT82C686
+select ACPI_X86
+
 config PREP
 bool
 imply PCI_DEVICES
diff --git a/hw/ppc/meson.build b/hw/ppc/meson.build
index 218631c883..86d6f379d1 100644
--- a/hw/ppc/meson.build
+++ b/hw/ppc/meson.build
@@ -78,5 +78,7 @@ ppc_ss.add(when: 'CONFIG_E500', if_true: files(
 ))
 # PowerPC 440 Xilinx ML507 reference board.
 ppc_ss.add(when: 'CONFIG_VIRTEX', if_true: files('virtex_ml507.c'))
+# Pegasos2
+ppc_ss.add(when: 'CONFIG_PEGASOS2', if_true: files('pegasos2.c'))
 
 hw_arch += {'ppc': ppc_ss}
diff --git a/hw/ppc/pegasos2.c b/hw/ppc/pegasos2.c
new file mode 100644
index 00..0bfd0928aa
--- /dev/null
+++ b/hw/ppc/pegasos2.c
@@ -0,0 +1,144 @@
+/*
+ * QEMU PowerPC CHRP (Genesi/bPlan Pegasos II) hardware System Emulator
+ *
+ * Copyright (c) 2018-2020 BALATON Zoltan
+ *
+ * This work is licensed under the GNU GPL license version 2 or later.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "qemu/units.h"
+#include "qapi/error.h"
+#include "hw/hw.h"
+#include "hw/ppc/ppc.h"
+#include "hw/sysbus.h"
+#include "hw/pci/pci_host.h"
+#include "hw/irq.h"
+#include "hw/pci-host/mv64361.h"
+#include "hw/isa/vt82c686.h"
+#include "hw/ide/pci.h"
+#include "hw/i2c/smbus_eeprom.h"
+#include "hw/qdev-properties.h"
+#include "sysemu/reset.h"
+#include "hw/boards.h"
+#include "hw/loader.h"
+#include "hw/fw-path-provider.h"
+#include "elf.h"
+#include "qemu/log.h"
+#include "qemu/error-report.h"
+#include "sysemu/kvm.h"
+#include "kvm_ppc.h"
+#include "exec/address-spaces.h"
+#include "trace.h"
+#include "qemu/datadir.h"
+#include "sysemu/device_tree.h"
+
+#define PROM_FILENAME "pegasos2.rom"
+#define PROM_ADDR 0xfff0
+#define PROM_SIZE 0x8
+
+#define BUS_FREQ_HZ 1
+
+static void pegasos2_cpu_reset(void *opaque)
+{
+PowerPCCPU *cpu = opaque;
+
+cpu_reset(CPU(cpu));
+cpu->env.spr[SPR_HID1] = 7ULL << 28;
+}
+
+static void pegasos2_init(MachineState *machine)
+{
+PowerPCCPU *cpu = NULL;
+MemoryRegion *rom = g_new(MemoryRegion, 1);
+DeviceState *mv;
+PCIBus *pci_bus;
+PCIDevice *dev;
+I2CBus *i2c_bus;
+const char *fwname = machine->firmware ?: PROM_FILENAME;
+char *filename;
+int sz;
+uint8_t *spd_data;
+
+/* init CPU */
+cpu = POWERPC_CPU(cpu_create(machine->cpu_type));
+if (PPC_INPUT(&cpu->env) != PPC_FLAGS_INPUT_6xx) {
+error_report("Incompatible CPU, only 6xx bus supported");
+exit(1);
+}
+
+/* Set time-base frequency */
+cpu_ppc_tb_init(&cpu->env, BUS_FREQ_HZ / 4);
+qemu_register_reset(pegasos2_cpu_reset, cpu);
+
+/* RAM */
+memory_region_add_subregion(get_system_memory(), 0, machine->ram);
+
+/* allocate and load firmware */
+filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, fwname);
+if (!filename) {
+error_report("Could not find firmware '%s'", fwname);
+exit(1);
+}
+me

[PATCH v11 6/7] hw/pci-host: Add emulation of Marvell MV64361 PPC system controller

2021-03-25 Thread BALATON Zoltan
The Marvell Discovery II aka. MV64361 is a PowerPC system controller
chip that is used on the pegasos2 PPC board. This adds emulation of it
that models the device enough to boot guests on this board. The
mv643xx.h header with register definitions is taken from Linux 4.15.10
only fixing white space errors, removing not needed parts and changing
formatting for QEMU coding style.

Signed-off-by: BALATON Zoltan 
---
 hw/pci-host/Kconfig   |   4 +
 hw/pci-host/meson.build   |   2 +
 hw/pci-host/mv64361.c | 951 ++
 hw/pci-host/mv643xx.h | 918 
 hw/pci-host/trace-events  |   6 +
 include/hw/pci-host/mv64361.h |   8 +
 include/hw/pci/pci_ids.h  |   1 +
 7 files changed, 1890 insertions(+)
 create mode 100644 hw/pci-host/mv64361.c
 create mode 100644 hw/pci-host/mv643xx.h
 create mode 100644 include/hw/pci-host/mv64361.h

diff --git a/hw/pci-host/Kconfig b/hw/pci-host/Kconfig
index 2ccc96f02c..79c20bf28b 100644
--- a/hw/pci-host/Kconfig
+++ b/hw/pci-host/Kconfig
@@ -72,3 +72,7 @@ config REMOTE_PCIHOST
 config SH_PCI
 bool
 select PCI
+
+config MV64361
+bool
+select PCI
diff --git a/hw/pci-host/meson.build b/hw/pci-host/meson.build
index 87a896973e..34b3538beb 100644
--- a/hw/pci-host/meson.build
+++ b/hw/pci-host/meson.build
@@ -19,6 +19,8 @@ pci_ss.add(when: 'CONFIG_GRACKLE_PCI', if_true: 
files('grackle.c'))
 pci_ss.add(when: 'CONFIG_UNIN_PCI', if_true: files('uninorth.c'))
 # PowerPC E500 boards
 pci_ss.add(when: 'CONFIG_PPCE500_PCI', if_true: files('ppce500.c'))
+# Pegasos2
+pci_ss.add(when: 'CONFIG_MV64361', if_true: files('mv64361.c'))
 
 # ARM devices
 pci_ss.add(when: 'CONFIG_VERSATILE_PCI', if_true: files('versatile.c'))
diff --git a/hw/pci-host/mv64361.c b/hw/pci-host/mv64361.c
new file mode 100644
index 00..20510d8680
--- /dev/null
+++ b/hw/pci-host/mv64361.c
@@ -0,0 +1,951 @@
+/*
+ * Marvell Discovery II MV64361 System Controller for
+ * QEMU PowerPC CHRP (Genesi/bPlan Pegasos II) hardware System Emulator
+ *
+ * Copyright (c) 2018-2020 BALATON Zoltan
+ *
+ * This work is licensed under the GNU GPL license version 2 or later.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "qemu/units.h"
+#include "qapi/error.h"
+#include "hw/hw.h"
+#include "hw/sysbus.h"
+#include "hw/pci/pci.h"
+#include "hw/pci/pci_host.h"
+#include "hw/irq.h"
+#include "hw/intc/i8259.h"
+#include "hw/qdev-properties.h"
+#include "exec/address-spaces.h"
+#include "qemu/log.h"
+#include "qemu/error-report.h"
+#include "trace.h"
+#include "hw/pci-host/mv64361.h"
+#include "mv643xx.h"
+
+#define TYPE_MV64361_PCI_BRIDGE "mv64361-pcibridge"
+
+static void mv64361_pcibridge_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+k->vendor_id = PCI_VENDOR_ID_MARVELL;
+k->device_id = PCI_DEVICE_ID_MARVELL_MV6436X;
+k->class_id = PCI_CLASS_BRIDGE_HOST;
+/*
+ * PCI-facing part of the host bridge,
+ * not usable without the host-facing part
+ */
+dc->user_creatable = false;
+}
+
+static const TypeInfo mv64361_pcibridge_info = {
+.name  = TYPE_MV64361_PCI_BRIDGE,
+.parent= TYPE_PCI_DEVICE,
+.instance_size = sizeof(PCIDevice),
+.class_init= mv64361_pcibridge_class_init,
+.interfaces = (InterfaceInfo[]) {
+{ INTERFACE_CONVENTIONAL_PCI_DEVICE },
+{ },
+},
+};
+
+
+#define TYPE_MV64361_PCI "mv64361-pcihost"
+OBJECT_DECLARE_SIMPLE_TYPE(MV64361PCIState, MV64361_PCI)
+
+struct MV64361PCIState {
+PCIHostState parent_obj;
+
+uint8_t index;
+MemoryRegion io;
+MemoryRegion mem;
+qemu_irq irq[PCI_NUM_PINS];
+
+uint32_t io_base;
+uint32_t io_size;
+uint32_t mem_base[4];
+uint32_t mem_size[4];
+uint64_t remap[5];
+};
+
+static int mv64361_pcihost_map_irq(PCIDevice *pci_dev, int n)
+{
+return (n + PCI_SLOT(pci_dev->devfn)) % PCI_NUM_PINS;
+}
+
+static void mv64361_pcihost_set_irq(void *opaque, int n, int level)
+{
+MV64361PCIState *s = opaque;
+qemu_set_irq(s->irq[n], level);
+}
+
+static void mv64361_pcihost_realize(DeviceState *dev, Error **errp)
+{
+MV64361PCIState *s = MV64361_PCI(dev);
+PCIHostState *h = PCI_HOST_BRIDGE(dev);
+char *name;
+
+name = g_strdup_printf("pci%d-io", s->index);
+memory_region_init(&s->io, OBJECT(dev), name, 0x1);
+g_free(name);
+name = g_strdup_printf("pci%d-mem", s->index);
+memory_region_init(&s->mem, OBJECT(dev), name, 1ULL << 32);
+g_free(name);
+name = g_strdup_printf("pci.%d", s->index);
+h->bus = pci_register_root_bus(dev, name, mv64361_pcihost_set_irq,
+   mv64361_pcihost_map_irq, dev,
+   &s->mem, &s->io, 0, 4, TYPE_PCI_BUS);
+g_free(name);
+pci_create_simple(h->bus, 0, TYPE_MV64361_PCI_BRIDGE);
+}
+
+static Property mv64361_pcihos

[PATCH v11 4/7] vt82c686: Add emulation of VT8231 south bridge

2021-03-25 Thread BALATON Zoltan
Add emulation of VT8231 south bridge ISA part based on the similar
VT82C686B but implemented in a separate subclass that holds the
differences while reusing parts that can be shared.

Signed-off-by: BALATON Zoltan 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/isa/vt82c686.c | 84 +++
 include/hw/isa/vt82c686.h |  1 +
 include/hw/pci/pci_ids.h  |  1 +
 3 files changed, 86 insertions(+)

diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c
index 69f073ec9e..60a84d984b 100644
--- a/hw/isa/vt82c686.c
+++ b/hw/isa/vt82c686.c
@@ -8,6 +8,9 @@
  *
  * Contributions after 2012-01-13 are licensed under the terms of the
  * GNU GPL, version 2 or (at your option) any later version.
+ *
+ * VT8231 south bridge support and general clean up to allow it
+ * Copyright (c) 2018-2020 BALATON Zoltan
  */
 
 #include "qemu/osdep.h"
@@ -640,6 +643,86 @@ static const TypeInfo vt82c686b_isa_info = {
 .class_init= vt82c686b_class_init,
 };
 
+/* TYPE_VT8231_ISA */
+
+static void vt8231_write_config(PCIDevice *d, uint32_t addr,
+uint32_t val, int len)
+{
+ViaISAState *s = VIA_ISA(d);
+
+trace_via_isa_write(addr, val, len);
+pci_default_write_config(d, addr, val, len);
+if (addr == 0x50) {
+/* BIT(2): enable or disable superio config io ports */
+via_superio_io_enable(s->via_sio, val & BIT(2));
+}
+}
+
+static void vt8231_isa_reset(DeviceState *dev)
+{
+ViaISAState *s = VIA_ISA(dev);
+uint8_t *pci_conf = s->dev.config;
+
+pci_set_long(pci_conf + PCI_CAPABILITY_LIST, 0x00c0);
+pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
+ PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL);
+pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM);
+
+pci_conf[0x58] = 0x40; /* Miscellaneous Control 0 */
+pci_conf[0x67] = 0x08; /* Fast IR Config */
+pci_conf[0x6b] = 0x01; /* Fast IR I/O Base */
+}
+
+static void vt8231_realize(PCIDevice *d, Error **errp)
+{
+ViaISAState *s = VIA_ISA(d);
+DeviceState *dev = DEVICE(d);
+ISABus *isa_bus;
+qemu_irq *isa_irq;
+int i;
+
+qdev_init_gpio_out(dev, &s->cpu_intr, 1);
+isa_irq = qemu_allocate_irqs(via_isa_request_i8259_irq, s, 1);
+isa_bus = isa_bus_new(dev, get_system_memory(), pci_address_space_io(d),
+  &error_fatal);
+isa_bus_irqs(isa_bus, i8259_init(isa_bus, *isa_irq));
+i8254_pit_init(isa_bus, 0x40, 0, NULL);
+i8257_dma_init(isa_bus, 0);
+s->via_sio = VIA_SUPERIO(isa_create_simple(isa_bus, TYPE_VT8231_SUPERIO));
+mc146818_rtc_init(isa_bus, 2000, NULL);
+
+for (i = 0; i < PCI_CONFIG_HEADER_SIZE; i++) {
+if (i < PCI_COMMAND || i >= PCI_REVISION_ID) {
+d->wmask[i] = 0;
+}
+}
+}
+
+static void vt8231_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+k->realize = vt8231_realize;
+k->config_write = vt8231_write_config;
+k->vendor_id = PCI_VENDOR_ID_VIA;
+k->device_id = PCI_DEVICE_ID_VIA_8231_ISA;
+k->class_id = PCI_CLASS_BRIDGE_ISA;
+k->revision = 0x10;
+dc->reset = vt8231_isa_reset;
+dc->desc = "ISA bridge";
+dc->vmsd = &vmstate_via;
+/* Reason: part of VIA VT8231 southbridge, needs to be wired up */
+dc->user_creatable = false;
+}
+
+static const TypeInfo vt8231_isa_info = {
+.name  = TYPE_VT8231_ISA,
+.parent= TYPE_VIA_ISA,
+.instance_size = sizeof(ViaISAState),
+.class_init= vt8231_class_init,
+};
+
 
 static void vt82c686b_register_types(void)
 {
@@ -651,6 +734,7 @@ static void vt82c686b_register_types(void)
 type_register_static(&vt8231_superio_info);
 type_register_static(&via_isa_info);
 type_register_static(&vt82c686b_isa_info);
+type_register_static(&vt8231_isa_info);
 }
 
 type_init(vt82c686b_register_types)
diff --git a/include/hw/isa/vt82c686.h b/include/hw/isa/vt82c686.h
index 0692b9a527..0f01aaa471 100644
--- a/include/hw/isa/vt82c686.h
+++ b/include/hw/isa/vt82c686.h
@@ -3,6 +3,7 @@
 
 #define TYPE_VT82C686B_ISA "vt82c686b-isa"
 #define TYPE_VT82C686B_PM "vt82c686b-pm"
+#define TYPE_VT8231_ISA "vt8231-isa"
 #define TYPE_VT8231_PM "vt8231-pm"
 #define TYPE_VIA_AC97 "via-ac97"
 #define TYPE_VIA_MC97 "via-mc97"
diff --git a/include/hw/pci/pci_ids.h b/include/hw/pci/pci_ids.h
index aa3f67eaa4..ac0c23ebc7 100644
--- a/include/hw/pci/pci_ids.h
+++ b/include/hw/pci/pci_ids.h
@@ -210,6 +210,7 @@
 #define PCI_DEVICE_ID_VIA_82C686B_PM 0x3057
 #define PCI_DEVICE_ID_VIA_AC97   0x3058
 #define PCI_DEVICE_ID_VIA_MC97   0x3068
+#define PCI_DEVICE_ID_VIA_8231_ISA   0x8231
 #define PCI_DEVICE_ID_VIA_8231_PM0x8235
 
 #define PCI_VENDOR_ID_MARVELL0x11ab
-- 
2.21.4




[PATCH v11 0/7] Pegasos2 emulation

2021-03-25 Thread BALATON Zoltan
Hello,

This is adding a new PPC board called pegasos2. More info on it can be
found at:

https://osdn.net/projects/qmiga/wiki/SubprojectPegasos2

Currently it needs a firmware ROM image that I cannot include due to
original copyright holder (bPlan) did not release it under a free
licence but I have plans to write a replacement in the future. With
the original board firmware it can boot MorphOS now as:

qemu-system-ppc -M pegasos2 -cdrom morphos.iso -device ati-vga,romfile="" 
-serial stdio

then enter "boot cd boot.img" at the firmware "ok" prompt as described
in the MorphOS.readme. To boot Linux use same command line with e.g.
-cdrom debian-8.11.0-powerpc-netinst.iso then enter
"boot cd install/pegasos"

The last patch adds the actual board code after previous patches
adding VT8231 and MV64361 system controller chip emulation.

Regards,
BALATON Zoltan

v11: Changes to last two patches David asked for during review

v10: Updated comments and added R-b from Mark

v9: Rebased to master

v8: Do not emulate setting of serial port address via register, just
hard code a default address instead

v7: Fix errp usage in patch 2

v6: Rebased on master, updated commit message about migration change

v5: Changes for review comments from David and Philippe

V4: Rename pegasos2_reset to pegasos2_cpu_reset
Add new files to MAINTAINERS

BALATON Zoltan (6):
  vt82c686: QOM-ify superio related functionality
  vt82c686: Add VT8231_SUPERIO based on VIA_SUPERIO
  vt82c686: Introduce abstract TYPE_VIA_ISA and base vt82c686b_isa on it
  vt82c686: Add emulation of VT8231 south bridge
  hw/pci-host: Add emulation of Marvell MV64361 PPC system controller
  hw/ppc: Add emulation of Genesi/bPlan Pegasos II

Philippe Mathieu-Daudé (1):
  hw/isa/Kconfig: Add missing dependency VIA VT82C686 -> APM

 MAINTAINERS |  10 +
 default-configs/devices/ppc-softmmu.mak |   2 +
 hw/isa/Kconfig  |   1 +
 hw/isa/vt82c686.c   | 422 +--
 hw/pci-host/Kconfig |   4 +
 hw/pci-host/meson.build |   2 +
 hw/pci-host/mv64361.c   | 951 
 hw/pci-host/mv643xx.h   | 918 +++
 hw/pci-host/trace-events|   6 +
 hw/ppc/Kconfig  |   9 +
 hw/ppc/meson.build  |   2 +
 hw/ppc/pegasos2.c   | 144 
 include/hw/isa/vt82c686.h   |   2 +-
 include/hw/pci-host/mv64361.h   |   8 +
 include/hw/pci/pci_ids.h|   4 +-
 15 files changed, 2403 insertions(+), 82 deletions(-)
 create mode 100644 hw/pci-host/mv64361.c
 create mode 100644 hw/pci-host/mv643xx.h
 create mode 100644 hw/ppc/pegasos2.c
 create mode 100644 include/hw/pci-host/mv64361.h

-- 
2.21.4




[PATCH v11 3/7] vt82c686: Introduce abstract TYPE_VIA_ISA and base vt82c686b_isa on it

2021-03-25 Thread BALATON Zoltan
To allow reusing ISA bridge emulation for vt8231_isa move the device
state of vt82c686b_isa emulation in an abstract via_isa class. This
change breaks migration back compatibility but this is not an issue
for Fuloong2E machine which is not versioned or migration supported.

Signed-off-by: BALATON Zoltan 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/isa/vt82c686.c| 70 ++--
 include/hw/pci/pci_ids.h |  2 +-
 2 files changed, 40 insertions(+), 32 deletions(-)

diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c
index b3048fd37e..69f073ec9e 100644
--- a/hw/isa/vt82c686.c
+++ b/hw/isa/vt82c686.c
@@ -518,24 +518,48 @@ static const TypeInfo vt8231_superio_info = {
 };
 
 
-OBJECT_DECLARE_SIMPLE_TYPE(VT82C686BISAState, VT82C686B_ISA)
+#define TYPE_VIA_ISA "via-isa"
+OBJECT_DECLARE_SIMPLE_TYPE(ViaISAState, VIA_ISA)
 
-struct VT82C686BISAState {
+struct ViaISAState {
 PCIDevice dev;
 qemu_irq cpu_intr;
 ViaSuperIOState *via_sio;
 };
 
+static const VMStateDescription vmstate_via = {
+.name = "via-isa",
+.version_id = 1,
+.minimum_version_id = 1,
+.fields = (VMStateField[]) {
+VMSTATE_PCI_DEVICE(dev, ViaISAState),
+VMSTATE_END_OF_LIST()
+}
+};
+
+static const TypeInfo via_isa_info = {
+.name  = TYPE_VIA_ISA,
+.parent= TYPE_PCI_DEVICE,
+.instance_size = sizeof(ViaISAState),
+.abstract  = true,
+.interfaces= (InterfaceInfo[]) {
+{ INTERFACE_CONVENTIONAL_PCI_DEVICE },
+{ },
+},
+};
+
 static void via_isa_request_i8259_irq(void *opaque, int irq, int level)
 {
-VT82C686BISAState *s = opaque;
+ViaISAState *s = opaque;
 qemu_set_irq(s->cpu_intr, level);
 }
 
+/* TYPE_VT82C686B_ISA */
+
 static void vt82c686b_write_config(PCIDevice *d, uint32_t addr,
uint32_t val, int len)
 {
-VT82C686BISAState *s = VT82C686B_ISA(d);
+ViaISAState *s = VIA_ISA(d);
 
 trace_via_isa_write(addr, val, len);
 pci_default_write_config(d, addr, val, len);
@@ -545,19 +569,9 @@ static void vt82c686b_write_config(PCIDevice *d, uint32_t 
addr,
 }
 }
 
-static const VMStateDescription vmstate_via = {
-.name = "vt82c686b",
-.version_id = 1,
-.minimum_version_id = 1,
-.fields = (VMStateField[]) {
-VMSTATE_PCI_DEVICE(dev, VT82C686BISAState),
-VMSTATE_END_OF_LIST()
-}
-};
-
 static void vt82c686b_isa_reset(DeviceState *dev)
 {
-VT82C686BISAState *s = VT82C686B_ISA(dev);
+ViaISAState *s = VIA_ISA(dev);
 uint8_t *pci_conf = s->dev.config;
 
 pci_set_long(pci_conf + PCI_CAPABILITY_LIST, 0x00c0);
@@ -577,7 +591,7 @@ static void vt82c686b_isa_reset(DeviceState *dev)
 
 static void vt82c686b_realize(PCIDevice *d, Error **errp)
 {
-VT82C686BISAState *s = VT82C686B_ISA(d);
+ViaISAState *s = VIA_ISA(d);
 DeviceState *dev = DEVICE(d);
 ISABus *isa_bus;
 qemu_irq *isa_irq;
@@ -601,7 +615,7 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
 }
 }
 
-static void via_class_init(ObjectClass *klass, void *data)
+static void vt82c686b_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
@@ -609,28 +623,21 @@ static void via_class_init(ObjectClass *klass, void *data)
 k->realize = vt82c686b_realize;
 k->config_write = vt82c686b_write_config;
 k->vendor_id = PCI_VENDOR_ID_VIA;
-k->device_id = PCI_DEVICE_ID_VIA_ISA_BRIDGE;
+k->device_id = PCI_DEVICE_ID_VIA_82C686B_ISA;
 k->class_id = PCI_CLASS_BRIDGE_ISA;
 k->revision = 0x40;
 dc->reset = vt82c686b_isa_reset;
 dc->desc = "ISA bridge";
 dc->vmsd = &vmstate_via;
-/*
- * Reason: part of VIA VT82C686 southbridge, needs to be wired up,
- * e.g. by mips_fuloong2e_init()
- */
+/* Reason: part of VIA VT82C686 southbridge, needs to be wired up */
 dc->user_creatable = false;
 }
 
-static const TypeInfo via_info = {
+static const TypeInfo vt82c686b_isa_info = {
 .name  = TYPE_VT82C686B_ISA,
-.parent= TYPE_PCI_DEVICE,
-.instance_size = sizeof(VT82C686BISAState),
-.class_init= via_class_init,
-.interfaces = (InterfaceInfo[]) {
-{ INTERFACE_CONVENTIONAL_PCI_DEVICE },
-{ },
-},
+.parent= TYPE_VIA_ISA,
+.instance_size = sizeof(ViaISAState),
+.class_init= vt82c686b_class_init,
 };
 
 
@@ -642,7 +649,8 @@ static void vt82c686b_register_types(void)
 type_register_static(&via_superio_info);
 type_register_static(&vt82c686b_superio_info);
 type_register_static(&vt8231_superio_info);
-type_register_static(&via_info);
+type_register_static(&via_isa_info);
+type_register_static(&vt82c686b_isa_info);
 }
 
 type_init(vt82c686b_register_types)
diff --git a/include/hw/pci/pci_ids.h b/include/hw/pci/pci_ids.h
index ea28dcc850..aa3f67eaa4 100644
--- a/include/hw/pci/pci_ids.h
+++ b/include/hw/pc

[PATCH v11 1/7] vt82c686: QOM-ify superio related functionality

2021-03-25 Thread BALATON Zoltan
Collect superio functionality and its controlling config registers
handling in an abstract VIA_SUPERIO class that is a subclass of
ISA_SUPERIO and put vt82c686b specific parts in a subclass of this
abstract class.

Signed-off-by: BALATON Zoltan 
Reviewed-by: Mark Cave-Ayland 
---
 hw/isa/vt82c686.c | 196 +-
 include/hw/isa/vt82c686.h |   1 -
 2 files changed, 132 insertions(+), 65 deletions(-)

diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c
index 05d084f698..6fb81c4ac6 100644
--- a/hw/isa/vt82c686.c
+++ b/hw/isa/vt82c686.c
@@ -249,15 +249,80 @@ static const TypeInfo vt8231_pm_info = {
 };
 
 
-typedef struct SuperIOConfig {
+#define TYPE_VIA_SUPERIO "via-superio"
+OBJECT_DECLARE_SIMPLE_TYPE(ViaSuperIOState, VIA_SUPERIO)
+
+struct ViaSuperIOState {
+ISASuperIODevice superio;
 uint8_t regs[0x100];
+const MemoryRegionOps *io_ops;
 MemoryRegion io;
-} SuperIOConfig;
+};
+
+static inline void via_superio_io_enable(ViaSuperIOState *s, bool enable)
+{
+memory_region_set_enabled(&s->io, enable);
+}
+
+static void via_superio_realize(DeviceState *d, Error **errp)
+{
+ViaSuperIOState *s = VIA_SUPERIO(d);
+ISASuperIOClass *ic = ISA_SUPERIO_GET_CLASS(s);
+Error *local_err = NULL;
+
+assert(s->io_ops);
+ic->parent_realize(d, &local_err);
+if (local_err) {
+error_propagate(errp, local_err);
+return;
+}
+memory_region_init_io(&s->io, OBJECT(d), s->io_ops, s, "via-superio", 2);
+memory_region_set_enabled(&s->io, false);
+/* The floppy also uses 0x3f0 and 0x3f1 but this seems to work anyway */
+memory_region_add_subregion(isa_address_space_io(ISA_DEVICE(s)), 0x3f0,
+&s->io);
+}
+
+static uint64_t via_superio_cfg_read(void *opaque, hwaddr addr, unsigned size)
+{
+ViaSuperIOState *sc = opaque;
+uint8_t idx = sc->regs[0];
+uint8_t val = sc->regs[idx];
+
+if (addr == 0) {
+return idx;
+}
+if (addr == 1 && idx == 0) {
+val = 0; /* reading reg 0 where we store index value */
+}
+trace_via_superio_read(idx, val);
+return val;
+}
+
+static void via_superio_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+ISASuperIOClass *sc = ISA_SUPERIO_CLASS(klass);
+
+sc->parent_realize = dc->realize;
+dc->realize = via_superio_realize;
+}
+
+static const TypeInfo via_superio_info = {
+.name  = TYPE_VIA_SUPERIO,
+.parent= TYPE_ISA_SUPERIO,
+.instance_size = sizeof(ViaSuperIOState),
+.class_size= sizeof(ISASuperIOClass),
+.class_init= via_superio_class_init,
+.abstract  = true,
+};
+
+#define TYPE_VT82C686B_SUPERIO "vt82c686b-superio"
 
-static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
-  unsigned size)
+static void vt82c686b_superio_cfg_write(void *opaque, hwaddr addr,
+uint64_t data, unsigned size)
 {
-SuperIOConfig *sc = opaque;
+ViaSuperIOState *sc = opaque;
 uint8_t idx = sc->regs[0];
 
 if (addr == 0) { /* config index register */
@@ -288,25 +353,9 @@ static void superio_cfg_write(void *opaque, hwaddr addr, 
uint64_t data,
 sc->regs[idx] = data;
 }
 
-static uint64_t superio_cfg_read(void *opaque, hwaddr addr, unsigned size)
-{
-SuperIOConfig *sc = opaque;
-uint8_t idx = sc->regs[0];
-uint8_t val = sc->regs[idx];
-
-if (addr == 0) {
-return idx;
-}
-if (addr == 1 && idx == 0) {
-val = 0; /* reading reg 0 where we store index value */
-}
-trace_via_superio_read(idx, val);
-return val;
-}
-
-static const MemoryRegionOps superio_cfg_ops = {
-.read = superio_cfg_read,
-.write = superio_cfg_write,
+static const MemoryRegionOps vt82c686b_superio_cfg_ops = {
+.read = via_superio_cfg_read,
+.write = vt82c686b_superio_cfg_write,
 .endianness = DEVICE_NATIVE_ENDIAN,
 .impl = {
 .min_access_size = 1,
@@ -314,13 +363,66 @@ static const MemoryRegionOps superio_cfg_ops = {
 },
 };
 
+static void vt82c686b_superio_reset(DeviceState *dev)
+{
+ViaSuperIOState *s = VIA_SUPERIO(dev);
+
+memset(s->regs, 0, sizeof(s->regs));
+/* Device ID */
+vt82c686b_superio_cfg_write(s, 0, 0xe0, 1);
+vt82c686b_superio_cfg_write(s, 1, 0x3c, 1);
+/* Function select - all disabled */
+vt82c686b_superio_cfg_write(s, 0, 0xe2, 1);
+vt82c686b_superio_cfg_write(s, 1, 0x03, 1);
+/* Floppy ctrl base addr 0x3f0-7 */
+vt82c686b_superio_cfg_write(s, 0, 0xe3, 1);
+vt82c686b_superio_cfg_write(s, 1, 0xfc, 1);
+/* Parallel port base addr 0x378-f */
+vt82c686b_superio_cfg_write(s, 0, 0xe6, 1);
+vt82c686b_superio_cfg_write(s, 1, 0xde, 1);
+/* Serial port 1 base addr 0x3f8-f */
+vt82c686b_superio_cfg_write(s, 0, 0xe7, 1);
+vt82c686b_superio_cfg_write(s, 1, 0xfe, 1);
+/* Serial port 2 base addr 0x2f8-f */
+vt82c6

Re: [PATCH v10 0/7] Pegasos2 emulation

2021-03-25 Thread BALATON Zoltan

On Thu, 25 Mar 2021, David Gibson wrote:

On Tue, Mar 23, 2021 at 01:57:25PM +0100, BALATON Zoltan wrote:

On Tue, 23 Mar 2021, David Gibson wrote:

On Wed, Mar 17, 2021 at 02:17:51AM +0100, BALATON Zoltan wrote:

Hello,

This is adding a new PPC board called pegasos2. More info on it can be
found at:

https://osdn.net/projects/qmiga/wiki/SubprojectPegasos2

Currently it needs a firmware ROM image that I cannot include due to
original copyright holder (bPlan) did not release it under a free
licence but I have plans to write a replacement in the future. With
the original board firmware it can boot MorphOS now as:

qemu-system-ppc -M pegasos2 -cdrom morphos.iso -device ati-vga,romfile="" 
-serial stdio

then enter "boot cd boot.img" at the firmware "ok" prompt as described
in the MorphOS.readme. To boot Linux use same command line with e.g.
-cdrom debian-8.11.0-powerpc-netinst.iso then enter
"boot cd install/pegasos"

The last patch adds the actual board code after previous patches
adding VT8231 and MV64361 system controller chip emulation.


I've applied 1..5 to a new ppc-for-6.1 branch.  Sorry it didn't make
it for 6.0, I just didn't have time to look this over until too late.


Thanks but maybe you should wait if the dropped original first patch can be
reviewed now and brought back. It would be easier for me to resubmit whole
series rebased than port the dropped patch on top of a partly applied
series. Also first patches without the last two is not much useful as the
vt8231 model these add would not be used by anything else.


Ok, I've dropped your patches from ppc-for-6.1 again, and I'll wait
for the next posting.


Should've waited for the outcome of the review of the patch in question as 
it turns out it was voted against so the ones you dropped will stay. Sorry 
for the churn, I've posted v11 with all patches again changing last two 
patches according to your review. Let me know if anything else is needed.


Thank you,
BALATON Zoltan



[PATCH v11 5/7] hw/isa/Kconfig: Add missing dependency VIA VT82C686 -> APM

2021-03-25 Thread BALATON Zoltan
From: Philippe Mathieu-Daudé 

TYPE_VIA_PM calls apm_init() in via_pm_realize(), so
requires APM to be selected.

Reported-by: BALATON Zoltan 
Signed-off-by: Philippe Mathieu-Daudé 
Signed-off-by: BALATON Zoltan 
---
 hw/isa/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/isa/Kconfig b/hw/isa/Kconfig
index 2691eae2f0..55e0003ce4 100644
--- a/hw/isa/Kconfig
+++ b/hw/isa/Kconfig
@@ -48,6 +48,7 @@ config VT82C686
 select SERIAL_ISA
 select FDC
 select USB_UHCI
+select APM
 
 config SMC37C669
 bool
-- 
2.21.4




Re: [PATCH v4 05/19] qapi/expr.py: constrain incoming expression types

2021-03-25 Thread Markus Armbruster
John Snow  writes:

> mypy does not know the types of values stored in Dicts that masquerade
> as objects. Help the type checker out by constraining the type.
>
> Signed-off-by: John Snow 
> ---
>  scripts/qapi/expr.py | 26 +++---
>  1 file changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py
> index b4bbcd54c0..b75c85c160 100644
> --- a/scripts/qapi/expr.py
> +++ b/scripts/qapi/expr.py
> @@ -15,9 +15,18 @@
>  # See the COPYING file in the top-level directory.
>  
>  import re
> +from typing import Dict, Optional
>  
>  from .common import c_name
>  from .error import QAPISemError
> +from .parser import QAPIDoc
> +from .source import QAPISourceInfo
> +
> +
> +# Deserialized JSON objects as returned by the parser;
> +# The values of this mapping are not necessary to exhaustively type

Not necessary and also not practical with current mypy.  Correct?

> +# here, because the purpose of this module is to interrogate that type.
> +_JSONObject = Dict[str, object]
>  
>  
>  # Names consist of letters, digits, -, and _, starting with a letter.
> @@ -315,9 +324,20 @@ def check_event(expr, info):
>  
>  def check_exprs(exprs):
>  for expr_elem in exprs:
> -expr = expr_elem['expr']
> -info = expr_elem['info']
> -doc = expr_elem.get('doc')
> +# Expression
> +assert isinstance(expr_elem['expr'], dict)

I dislike relaxing OrderedDict to dict here.  I'm going to accept it
anyway, because the difference between the two is going away in 3.7, and
because so far order actually matters only in certain sub-expressions,
not top-level expressions.

> +for key in expr_elem['expr'].keys():
> +assert isinstance(key, str)
> +expr: _JSONObject = expr_elem['expr']
> +
> +# QAPISourceInfo
> +assert isinstance(expr_elem['info'], QAPISourceInfo)
> +info: QAPISourceInfo = expr_elem['info']
> +
> +# Optional[QAPIDoc]
> +tmp = expr_elem.get('doc')
> +assert tmp is None or isinstance(tmp, QAPIDoc)
> +doc: Optional[QAPIDoc] = tmp
>  
>  if 'include' in expr:
>  continue

I see you didn't bite on the idea to do less checking here.  Okay.




Re: [PATCH v3 6/7] hw/arm/smmuv3: Fix SMMU_CMD_CFGI_STE_RANGE handling

2021-03-25 Thread Zenghui Yu

On 2021/3/9 18:27, Eric Auger wrote:

If the whole SID range (32b) is invalidated (SMMU_CMD_CFGI_ALL),
@end overflows and we fail to handle the command properly.

Once this gets fixed, the current code really is awkward in the
sense it loops over the whole range instead of removing the
currently cached configs through a hash table lookup.

Fix both the overflow and the lookup.

Signed-off-by: Eric Auger 
Reviewed-by: Peter Maydell 


Not much to do with this patch, but maybe we can take the fix a little
further. We now take StreamID as the start of the invalidation range,
regardless of whatever the Range is, whilst the spec clearly states that
"the StreamID parameter (of *CMD_CFGI_ALL* command) is IGNORED". If
there are some random bits in the StreamID field (who knows), we'll fail
to perform the full invalidation but get a strange range (e.g.,
SMMUSIDRange={.start=1, .end=0}) instead.

And having looked at the spec again, 4.3.2 CMD_CFGI_STE_RANGE:

 - "Invalidation is performed for an *aligned* range of 2^(Range+1)
StreamIDs."

 - "The bottom Range+1 bits of the StreamID parameter are IGNORED,
aligning the range to its size."

which seems to be some bits that we had never taken into account. And
what I'm saying is roughly something like below (compile tested), any
thoughts?


diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
index 3b87324ce2..8705612535 100644
--- a/hw/arm/smmuv3.c
+++ b/hw/arm/smmuv3.c
@@ -980,16 +980,20 @@ static int smmuv3_cmdq_consume(SMMUv3State *s)
 }
 case SMMU_CMD_CFGI_STE_RANGE: /* same as SMMU_CMD_CFGI_ALL */
 {
-uint32_t start = CMD_SID(&cmd);
+uint32_t sid = CMD_SID(&cmd), mask;
 uint8_t range = CMD_STE_RANGE(&cmd);
-uint64_t end = start + (1ULL << (range + 1)) - 1;
-SMMUSIDRange sid_range = {start, end};
+SMMUSIDRange sid_range;

 if (CMD_SSEC(&cmd)) {
 cmd_error = SMMU_CERROR_ILL;
 break;
 }
-trace_smmuv3_cmdq_cfgi_ste_range(start, end);
+
+mask = (1ULL << (range + 1)) - 1;
+sid_range.start = sid & ~mask;
+sid_range.end = sid_range.start + mask;
+
+trace_smmuv3_cmdq_cfgi_ste_range(sid_range.start, 
sid_range.end);
 g_hash_table_foreach_remove(bs->configs, 
smmuv3_invalidate_ste,

 &sid_range);
 break;



Re: [PATCH v4 08/19] qapi: add tests for invalid 'data' field type

2021-03-25 Thread Markus Armbruster
John Snow  writes:

> It needs to be an object (dict), not anything else.
>
> Signed-off-by: John Snow 
>
> ---
>
> Note: this actually doesn't ... work, but on-list, we discussed wanting
> tests first, then the fix. That can't happen here, because QAPI crashes
> at runtime. So uh, just squash this into the following patch, I guess?

Yes.

> I tried.

Thanks!

> Signed-off-by: John Snow 
> ---
>  tests/qapi-schema/alternate-invalid-data-type.err  |  0
>  tests/qapi-schema/alternate-invalid-data-type.json |  4 
>  tests/qapi-schema/alternate-invalid-data-type.out  |  0
>  tests/qapi-schema/meson.build  |  2 ++
>  tests/qapi-schema/union-invalid-data-type.err  |  0
>  tests/qapi-schema/union-invalid-data-type.json | 13 +
>  tests/qapi-schema/union-invalid-data-type.out  |  0
>  7 files changed, 19 insertions(+)
>  create mode 100644 tests/qapi-schema/alternate-invalid-data-type.err
>  create mode 100644 tests/qapi-schema/alternate-invalid-data-type.json
>  create mode 100644 tests/qapi-schema/alternate-invalid-data-type.out
>  create mode 100644 tests/qapi-schema/union-invalid-data-type.err
>  create mode 100644 tests/qapi-schema/union-invalid-data-type.json
>  create mode 100644 tests/qapi-schema/union-invalid-data-type.out
>
> diff --git a/tests/qapi-schema/alternate-invalid-data-type.err 
> b/tests/qapi-schema/alternate-invalid-data-type.err
> new file mode 100644
> index 00..e69de29bb2
> diff --git a/tests/qapi-schema/alternate-invalid-data-type.json 
> b/tests/qapi-schema/alternate-invalid-data-type.json
> new file mode 100644
> index 00..7d5d905581
> --- /dev/null
> +++ b/tests/qapi-schema/alternate-invalid-data-type.json
> @@ -0,0 +1,4 @@
> +# Alternate type requires an object for 'data'
> +{ 'alternate': 'Alt',
> +  'data': ['rubbish', 'nonsense']
> +}

Let's name it alternate-data-invalid.json, for consistency with
struct-data-invalid.json

> diff --git a/tests/qapi-schema/alternate-invalid-data-type.out 
> b/tests/qapi-schema/alternate-invalid-data-type.out
> new file mode 100644
> index 00..e69de29bb2
> diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build
> index 8ba6917132..cc5b136cfb 100644
> --- a/tests/qapi-schema/meson.build
> +++ b/tests/qapi-schema/meson.build
> @@ -15,6 +15,7 @@ schemas = [
>'alternate-conflict-bool-string.json',
>'alternate-conflict-num-string.json',
>'alternate-empty.json',
> +  'alternate-invalid-data-type.json',
>'alternate-invalid-dict.json',
>'alternate-nested.json',
>'alternate-unknown.json',
> @@ -192,6 +193,7 @@ schemas = [
>'union-clash-branches.json',
>'union-empty.json',
>'union-invalid-base.json',
> +  'union-invalid-data-type.json',
>'union-optional-branch.json',
>'union-unknown.json',
>'unknown-escape.json',
> diff --git a/tests/qapi-schema/union-invalid-data-type.err 
> b/tests/qapi-schema/union-invalid-data-type.err
> new file mode 100644
> index 00..e69de29bb2
> diff --git a/tests/qapi-schema/union-invalid-data-type.json 
> b/tests/qapi-schema/union-invalid-data-type.json
> new file mode 100644
> index 00..5a32d267bf
> --- /dev/null
> +++ b/tests/qapi-schema/union-invalid-data-type.json
> @@ -0,0 +1,13 @@
> +# the union data type must be an object.
> +
> +{ 'struct': 'TestTypeA',
> +  'data': { 'string': 'str' } }
> +
> +{ 'struct': 'TestTypeB',
> +  'data': { 'integer': 'int' } }

These two seem superfluous.

> +
> +{ 'union': 'TestUnion',
> +  'base': 'int',
> +  'discriminator': 'int',
> +  'data': ['TestTypeA', 'TestTypeB']
> +}

Name it union-invalid-data.json.

> diff --git a/tests/qapi-schema/union-invalid-data-type.out 
> b/tests/qapi-schema/union-invalid-data-type.out
> new file mode 100644
> index 00..e69de29bb2




Re: [PATCH] MAINTAINERS: add/replace backups for some s390 areas

2021-03-25 Thread Halil Pasic
On Thu, 25 Mar 2021 09:55:09 -0400
Matthew Rosato  wrote:

> S390 PCI currently has no backup, add one.  Add an additional backup
> for vfio-ccw and refresh the backup for vfio-ap.
> 
> Signed-off-by: Matthew Rosato 

Acked-by: Halil Pasic 



Re: [PATCH v4 09/19] qapi/expr.py: Check type of 'data' member

2021-03-25 Thread Markus Armbruster
Suggest

qapi/expr.py: Check type of union and alternate 'data' member

John Snow  writes:

> We don't actually check, so the user can get some unpleasant stacktraces.

Let's point to the new tests here.

> Formalize it.

Huh?

> Signed-off-by: John Snow 
> ---
>  scripts/qapi/expr.py  | 7 +++
>  tests/qapi-schema/alternate-invalid-data-type.err | 2 ++
>  tests/qapi-schema/union-invalid-data-type.err | 2 ++
>  3 files changed, 11 insertions(+)
>
> diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py
> index 73e7d8cb0d..ca5ab7bfda 100644
> --- a/scripts/qapi/expr.py
> +++ b/scripts/qapi/expr.py
> @@ -281,6 +281,9 @@ def check_union(expr, info):
>  raise QAPISemError(info, "'discriminator' requires 'base'")
>  check_name_is_str(discriminator, info, "'discriminator'")
>  
> +if not isinstance(members, dict):
> +raise QAPISemError(info, "'data' must be an object")
> +
>  for (key, value) in members.items():
>  source = "'data' member '%s'" % key
>  if discriminator is None:
> @@ -296,6 +299,10 @@ def check_alternate(expr, info):
>  
>  if not members:
>  raise QAPISemError(info, "'data' must not be empty")
> +
> +if not isinstance(members, dict):
> +raise QAPISemError(info, "'data' must be an object")
> +
>  for (key, value) in members.items():
>  source = "'data' member '%s'" % key
>  check_name_lower(key, info, source)
> diff --git a/tests/qapi-schema/alternate-invalid-data-type.err 
> b/tests/qapi-schema/alternate-invalid-data-type.err
> index e69de29bb2..c7301ccb00 100644
> --- a/tests/qapi-schema/alternate-invalid-data-type.err
> +++ b/tests/qapi-schema/alternate-invalid-data-type.err
> @@ -0,0 +1,2 @@
> +alternate-invalid-data-type.json: In alternate 'Alt':
> +alternate-invalid-data-type.json:2: 'data' must be an object
> diff --git a/tests/qapi-schema/union-invalid-data-type.err 
> b/tests/qapi-schema/union-invalid-data-type.err
> index e69de29bb2..b71c3400c5 100644
> --- a/tests/qapi-schema/union-invalid-data-type.err
> +++ b/tests/qapi-schema/union-invalid-data-type.err
> @@ -0,0 +1,2 @@
> +union-invalid-data-type.json: In union 'TestUnion':
> +union-invalid-data-type.json:9: 'data' must be an object




Re: [RFC v11 23/55] target/arm: move arm_sctlr away from tcg helpers

2021-03-25 Thread Claudio Fontana
On 3/24/21 11:07 PM, Richard Henderson wrote:
> On 3/23/21 9:46 AM, Claudio Fontana wrote:
>> this function is used for kvm too, add it to the
>> cpu-common module.
>>
>> Signed-off-by: Claudio Fontana 
> 
> Reviewed-by: Richard Henderson 
> 
>>   /* #endif TARGET_AARCH64 , see matching comment above */
>> +
>> +uint64_t arm_sctlr(CPUARMState *env, int el)
>> +{
>> +/* Only EL0 needs to be adjusted for EL1&0 or EL2&0. */
>> +if (el == 0) {
>> +ARMMMUIdx mmu_idx = arm_mmu_idx_el(env, 0);
>> +el = (mmu_idx == ARMMMUIdx_E20_0 || mmu_idx == ARMMMUIdx_SE20_0)
>> +? 2 : 1;
> 
> I only thought of it because of the comment, but *E20_0 is aarch64 only; 
> aarch32 always uses el = 1 here.  ;-)
> 
> 
> r~

In this case, maybe we should do:


uint64_t arm_sctlr(CPUARMState *env, int el)
{
/* Only EL0 needs to be adjusted for EL1&0 or EL2&0. */
if (el == 0) {
#ifdef TARGET_AARCH64
ARMMMUIdx mmu_idx = arm_mmu_idx_el(env, 0);
el = (mmu_idx == ARMMMUIdx_E20_0 || mmu_idx == ARMMMUIdx_SE20_0)
? 2 : 1;
#else
el = 1;
#endif
}
return env->cp15.sctlr_el[el];
}

?

Thanks,

Claudio




[PATCH] hw/arm/smmuv3: Drop unused CDM_VALID() and is_cd_valid()

2021-03-25 Thread Zenghui Yu
They were introduced in commit 9bde7f0674fe ("hw/arm/smmuv3: Implement
translate callback") but never actually used. Drop them.

Signed-off-by: Zenghui Yu 
---
 hw/arm/smmuv3-internal.h | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/hw/arm/smmuv3-internal.h b/hw/arm/smmuv3-internal.h
index b6f7e53b7c..3dac5766ca 100644
--- a/hw/arm/smmuv3-internal.h
+++ b/hw/arm/smmuv3-internal.h
@@ -595,13 +595,6 @@ static inline int pa_range(STE *ste)
 #define CD_A(x)  extract32((x)->word[1], 14, 1)
 #define CD_AARCH64(x)extract32((x)->word[1], 9 , 1)
 
-#define CDM_VALID(x)((x)->word[0] & 0x1)
-
-static inline int is_cd_valid(SMMUv3State *s, STE *ste, CD *cd)
-{
-return CD_VALID(cd);
-}
-
 /**
  * tg2granule - Decodes the CD translation granule size field according
  * to the ttbr in use
-- 
2.19.1




Re: [PATCH 5/6] hw/ide/via: Connect IDE function output IRQs to the ISA function input

2021-03-25 Thread Philippe Mathieu-Daudé
On 3/25/21 1:29 PM, Richard Henderson wrote:
> On 3/24/21 11:54 AM, Philippe Mathieu-Daudé wrote:
>> To avoid abusing isa_get_irq(NULL) using a hidden ISA bridge
>> under the hood, let the IDE function expose 2 output IRQs,
>> and connect them to the ISA function inputs when creating
>> the south bridge chipset model in vt82c686b_southbridge_init.
>>
>> Signed-off-by: Philippe Mathieu-Daudé 
>> ---
>>   hw/ide/via.c    | 19 +--
>>   hw/mips/fuloong2e.c |  9 -
>>   2 files changed, 25 insertions(+), 3 deletions(-)

>> diff --git a/hw/mips/fuloong2e.c b/hw/mips/fuloong2e.c
>> index 931385c760f..f1c5db13b78 100644
>> --- a/hw/mips/fuloong2e.c
>> +++ b/hw/mips/fuloong2e.c
>> @@ -203,12 +203,19 @@ static void vt82c686b_southbridge_init(PCIBus
>> *pci_bus, int slot, qemu_irq intc,
>>  I2CBus **i2c_bus)
>>   {
>>   PCIDevice *dev;
>> +    DeviceState *isa;
>>     dev = pci_create_simple_multifunction(pci_bus, PCI_DEVFN(slot,
>> 0), true,
>>     TYPE_VT82C686B_ISA);
>> -    qdev_connect_gpio_out_named(DEVICE(dev), "intr", 0, intc);
>> +    isa = DEVICE(dev);
>> +    qdev_connect_gpio_out_named(isa, "intr", 0, intc);
>>     dev = pci_create_simple(pci_bus, PCI_DEVFN(slot, 1), "via-ide");
>> +    for (unsigned i = 0; i < 2; i++) {
>> +    qdev_connect_gpio_out_named(DEVICE(dev), "ide-irq", i,
> 
>    ^^^ isa?

OK.

>> +    qdev_get_gpio_in_named(isa,
>> +   "isa-irq",
>> 14 + i));
>> +    }
> 
> It all looks a little funny, but I think I follow it, and see that it
> can't be split further, because of the movement of the +14.

I can break the indent to shift left. Anyway this disappear in the next
commit.

> Reviewed-by: Richard Henderson 
> 

Thanks!

Phil.



Re: [RFC v11 26/55] target/arm: split a15 cpu model and 32bit class functions to cpu32.c

2021-03-25 Thread Claudio Fontana
On 3/24/21 11:17 PM, Richard Henderson wrote:
> On 3/23/21 9:46 AM, Claudio Fontana wrote:
>> -static void arm_cpu_dump_state(CPUState *cs, FILE *f, int flags)
>> -{
>> -ARMCPU *cpu = ARM_CPU(cs);
>> -CPUARMState *env = &cpu->env;
>> -int i;
>> -
>> -if (is_a64(env)) {
>> -aarch64_cpu_dump_state(cs, f, flags);
>> -return;
>> -}
> 
> You've lost this bit.
> 
> Somewhere there needs to be a check of the current cpu state, and one of the 
> two functions must be called.


Thanks for the nice catch, I got confused there.

> 
> 
>> @@ -823,6 +951,7 @@ static void aarch64_cpu_class_init(ObjectClass *oc, void 
>> *data)
>>  cc->gdb_num_core_regs = 34;
>>  cc->gdb_core_xml_file = "aarch64-core.xml";
>>  cc->gdb_arch_name = aarch64_gdb_arch_name;
>> +cc->dump_state = aarch64_cpu_dump_state;
> 
> I suggest this continue to set arm_cpu_dump_state, like so,
> 
> static void arm_cpu_dump_state(CPUState *cs, FILE *f, int flags)
> {
>  if (is_a64(env)) {
>  aarch64_cpu_dump_state(cs, f, flags);
>  } else {
>  aarch32_cpu_dump_state(cs, f, flags);
>  }
> }
> 
> 
> r~
> 




Re: [PATCH v2 07/10] Acceptance Tests: set up SSH connection by default after boot for LinuxTest

2021-03-25 Thread Wainer dos Santos Moschetta

Hi,

On 3/23/21 7:15 PM, Cleber Rosa wrote:

The LinuxTest specifically targets users that need to interact with Linux
guests.  So, it makes sense to give a connection by default, and avoid
requiring it as boiler-plate code.

Signed-off-by: Cleber Rosa 
---
  tests/acceptance/avocado_qemu/__init__.py | 5 -
  tests/acceptance/virtiofs_submounts.py| 1 -
  2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/tests/acceptance/avocado_qemu/__init__.py 
b/tests/acceptance/avocado_qemu/__init__.py
index 535f63a48d..4960142bcc 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -390,7 +390,7 @@ def set_up_cloudinit(self, ssh_pubkey=None):
  cloudinit_iso = self.prepare_cloudinit(ssh_pubkey)
  self.vm.add_args('-drive', 'file=%s,format=raw' % cloudinit_iso)
  
-def launch_and_wait(self):

+def launch_and_wait(self, set_up_ssh_connection=True):
  self.vm.set_console()
  self.vm.launch()
  console_drainer = 
datadrainer.LineLogger(self.vm.console_socket.fileno(),
@@ -398,3 +398,6 @@ def launch_and_wait(self):
  console_drainer.start()
  self.log.info('VM launched, waiting for boot confirmation from guest')
  cloudinit.wait_for_phone_home(('0.0.0.0', self.phone_home_port), 
self.name)
+if set_up_ssh_connection:
+self.log.info('Setting up the SSH connection')
+self.ssh_connect(self.username, self.ssh_key)


Where is self.username set?

- Wainer


diff --git a/tests/acceptance/virtiofs_submounts.py 
b/tests/acceptance/virtiofs_submounts.py
index e10a935ac4..e019d3b896 100644
--- a/tests/acceptance/virtiofs_submounts.py
+++ b/tests/acceptance/virtiofs_submounts.py
@@ -136,7 +136,6 @@ def set_up_virtiofs(self):
  
  def launch_vm(self):

  self.launch_and_wait()
-self.ssh_connect('root', self.ssh_key)
  
  def set_up_nested_mounts(self):

  scratch_dir = os.path.join(self.shared_dir, 'scratch')





Re: [PATCH v4 10/19] qapi/expr.py: Add casts in a few select cases

2021-03-25 Thread Markus Armbruster
John Snow  writes:

> Casts are instructions to the type checker only, they aren't "safe" and
> should probably be avoided in general. In this case, when we perform
> type checking on a nested structure, the type of each field does not
> "stick".
>
> (See PEP 647 for an example of "type narrowing" that does "stick".
>  It is available in Python 3.10, so we can't use it yet.)
>
> We don't need to assert that something is a str if we've already checked
> or asserted that it is -- use a cast instead for these cases.
>
> Signed-off-by: John Snow 
> ---
>  scripts/qapi/expr.py | 10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py
> index ca5ab7bfda..505e67bd21 100644
> --- a/scripts/qapi/expr.py
> +++ b/scripts/qapi/expr.py
> @@ -15,7 +15,7 @@
>  # See the COPYING file in the top-level directory.
>  
>  import re
> -from typing import Dict, Optional
> +from typing import Dict, Optional, cast
>  
>  from .common import c_name
>  from .error import QAPISemError
> @@ -259,7 +259,7 @@ def check_enum(expr, info):
>  
>  
>  def check_struct(expr, info):
> -name = expr['struct']
> +name = cast(str, expr['struct'])  # Asserted in check_exprs

"Asserted" suggests an an assert statement.  It's actually the
check_name_is_str() visible in the last hunk.  What about "Checked in
check_exprs()" or "Ensured by check_exprs()"?

>  members = expr['data']
>  
>  check_type(members, info, "'data'", allow_dict=name)
> @@ -267,7 +267,7 @@ def check_struct(expr, info):
>  
>  
>  def check_union(expr, info):
> -name = expr['union']
> +name = cast(str, expr['union'])  # Asserted in check_exprs
>  base = expr.get('base')
>  discriminator = expr.get('discriminator')
>  members = expr['data']
> @@ -366,8 +366,8 @@ def check_exprs(exprs):
>  else:
>  raise QAPISemError(info, "expression is missing metatype")
>  
> -name = expr[meta]
> -check_name_is_str(name, info, "'%s'" % meta)
> +check_name_is_str(expr[meta], info, "'%s'" % meta)
> +name = cast(str, expr[meta])
>  info.set_defn(meta, name)
>  check_defn_name_str(name, info, meta)




Re: [PATCH 1/1] avocado_qemu: Add SMMUv3 tests

2021-03-25 Thread Cleber Rosa
On Thu, Mar 25, 2021 at 10:57:12AM +0100, Eric Auger wrote:
> Add new tests checking the good behavior of the SMMUv3 protecting
> 2 virtio pci devices (block and net). We check the guest boots and
> we are able to install a package. Different guest configs are tested:
> standard, passthrough an strict=0. Given the version of the guest
> kernel in use (5.3.7 at this moment), range invalidation is not yet
> tested. This will be handled separately.
> 
> Signed-off-by: Eric Auger 
> ---
>  tests/acceptance/smmu.py | 104 +++
>  1 file changed, 104 insertions(+)
>  create mode 100644 tests/acceptance/smmu.py
> 
> diff --git a/tests/acceptance/smmu.py b/tests/acceptance/smmu.py
> new file mode 100644
> index 00..65ecac8f1a
> --- /dev/null
> +++ b/tests/acceptance/smmu.py
> @@ -0,0 +1,104 @@
> +# SMMUv3 Functional tests
> +#
> +# Copyright (c) 2021 Red Hat, Inc.
> +#
> +# Author:
> +#  Eric Auger 
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2 or
> +# later.  See the COPYING file in the top-level directory.
> +
> +import os
> +
> +from avocado_qemu import LinuxTest, BUILD_DIR
> +from avocado.utils import ssh

This import is not needed, given that the you're not using them directly,
but only using the LinuxTest methods that wrap them.

> +
> +class SMMU(LinuxTest):
> +
> +KERNEL_COMMON_PARAMS = ("root=UUID=b6950a44-9f3c-4076-a9c2-355e8475b0a7 
> ro "
> +"earlyprintk=pl011,0x900 ignore_loglevel "
> +"no_timer_check printk.time=1 rd_NO_PLYMOUTH "
> +"console=ttyAMA0 ")
> +IOMMU_ADDON = ',iommu_platform=on,disable-modern=off,disable-legacy=on'
> +IMAGE = ("https://archives.fedoraproject.org/pub/archive/fedora/";
> + "linux/releases/31/Everything/aarch64/os/images/pxeboot/")
> +kernel_path = None
> +initrd_path = None
> +kernel_params = None
> +
> +def set_up_boot(self):
> +path = self.download_boot()
> +self.vm.add_args('-device', 'virtio-blk-pci,bus=pcie.0,scsi=off,' +
> + 'drive=drv0,id=virtio-disk0,bootindex=1,'
> + 'werror=stop,rerror=stop' + self.IOMMU_ADDON)
> +self.vm.add_args('-drive',
> + 'file=%s,if=none,cache=writethrough,id=drv0' % path)
> +
> +def setUp(self):
> +super(SMMU, self).setUp(None, 'virtio-net-pci' + self.IOMMU_ADDON)
> +
> +def add_common_args(self):
> +self.vm.add_args("-machine", "virt")
> +self.vm.add_args('-bios', os.path.join(BUILD_DIR, 'pc-bios',
> +  'edk2-aarch64-code.fd'))
> +self.vm.add_args('-device', 'virtio-rng-pci,rng=rng0')
> +self.vm.add_args('-object',
> + 'rng-random,id=rng0,filename=/dev/urandom')
> +
> +def common_vm_setup(self, custom_kernel=None):
> +self.require_accelerator("kvm")
> +self.add_common_args()

I know you're following the previous test pattern/template, but maybe
combine add_command_args() and common_vm_setup()?  They seem to be
doing the same thing.

> +self.vm.add_args("-accel", "kvm")
> +self.vm.add_args("-cpu", "host")
> +self.vm.add_args("-machine", "iommu=smmuv3")
> +
> +if custom_kernel is None:
> +return
> +
> +kernel_url = self.IMAGE + 'vmlinuz'
> +initrd_url = self.IMAGE + 'initrd.img'
> +self.kernel_path = self.fetch_asset(kernel_url)
> +self.initrd_path = self.fetch_asset(initrd_url)
> +
> +def run_and_check(self):
> +if self.kernel_path:
> +self.vm.add_args('-kernel', self.kernel_path,
> + '-append', self.kernel_params,
> + '-initrd', self.initrd_path)
> +self.launch_and_wait()
> +self.ssh_command('cat /proc/cmdline')
> +self.ssh_command('dnf -y install numactl-devel')

Would you expect the package installation to cover significant more
than, say, a package removal?  Not relying on the distro's package
repos (and external networking) would be an improvement to the test's
stability, but I wonder how much functional coverage would be lost.

FIY, I've tried it with 'dnf -y remove yum' instead, and test times
are also considerably lower.

> +
> +def test_smmu(self):
> +"""
> +:avocado: tags=accel:kvm
> +:avocado: tags=cpu:host
> +:avocado: tags=smmu
> +"""

These tags are common across all tests, so you can move them to the class'
docstring.  Also, you need to add ":avocado: tags=arch:aarch64" or else
these will be attempted to be executed with other targets.

> +
> +self.common_vm_setup()
> +self.run_and_check()
> +
> +def test_smmu_passthrough(self):
> +"""
> +:avocado: tags=accel:kvm
> +:avocado: tags=cpu:host
> +:avocado: tags=smmu
> +"""
> +se

Re: [PATCH 03/15] Hexagon (target/hexagon) properly generate TB end for DISAS_NORETURN

2021-03-25 Thread Richard Henderson

On 3/24/21 8:49 PM, Taylor Simpson wrote:

When exiting a TB, generate all the code before returning from
hexagon_tr_translate_packet so that nothing needs to be done in
hexagon_tr_tb_stop.

Address feedback from Richard Henderson 

Signed-off-by: Taylor Simpson 
---
  target/hexagon/translate.c | 62 +-
  target/hexagon/translate.h |  3 ---
  2 files changed, 34 insertions(+), 31 deletions(-)

diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c
index 5d92ab0..19b9bc7 100644
--- a/target/hexagon/translate.c
+++ b/target/hexagon/translate.c
@@ -54,16 +54,41 @@ static const char * const hexagon_prednames[] = {
"p0", "p1", "p2", "p3"
  };
  
-void gen_exception(int excp)

+static void gen_exception(int excp)


I would call this something like gen_exception_raw or gen_exception_nopc, or 
something because,



+static void gen_exception_end_tb(DisasContext *ctx, int excp)


... *all* exceptions end the tb.


+{
+gen_exec_counters(ctx);
+tcg_gen_mov_tl(hex_gpr[HEX_REG_PC], hex_next_PC);
+gen_exception(excp);


The helper_raise_exception call longjmped away, so


+tcg_gen_exit_tb(NULL, 0);


... this exit_tb is dead code.


@@ -537,8 +551,7 @@ static bool hexagon_tr_breakpoint_check(DisasContextBase 
*dcbase, CPUState *cpu,
  DisasContext *ctx = container_of(dcbase, DisasContext, base);
  
  tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], ctx->base.pc_next);

-ctx->base.is_jmp = DISAS_NORETURN;
-gen_exception_debug();
+gen_exception_end_tb(ctx, EXCP_DEBUG);


The set of the pc is also redundant?


r~



Re: [PATCH 04/15] Hexagon (target/hexagon) decide if pred has been written at TCG gen time

2021-03-25 Thread Richard Henderson

On 3/24/21 8:49 PM, Taylor Simpson wrote:

Multiple writes to the same preg are and'ed together.  Rather than
generating a runtime check, we can determine at TCG generation time
if the predicate has previously been written in the packet.

Test added to tests/tcg/hexagon/misc.c

Address feedback from Richard Henderson

Signed-off-by: Taylor Simpson
---
  target/hexagon/gen_tcg_funcs.py |  2 +-
  target/hexagon/genptr.c | 22 +++---
  target/hexagon/translate.c  |  9 +++--
  target/hexagon/translate.h  |  2 ++
  tests/tcg/hexagon/misc.c| 19 +++
  5 files changed, 44 insertions(+), 10 deletions(-)


Reviewed-by: Richard Henderson 

r~



Re: [PATCH 05/15] Hexagon (target/hexagon) change variables from int to bool when appropriate

2021-03-25 Thread Richard Henderson

On 3/24/21 8:50 PM, Taylor Simpson wrote:

Address feedback from Richard Henderson

Signed-off-by: Taylor Simpson
---
  target/hexagon/cpu_bits.h  |  2 +-
  target/hexagon/decode.c| 80 +++---
  target/hexagon/insn.h  | 21 ++--
  target/hexagon/op_helper.c |  8 ++---
  target/hexagon/translate.c |  6 ++--
  target/hexagon/translate.h |  2 +-
  6 files changed, 60 insertions(+), 59 deletions(-)


Reviewed-by: Richard Henderson 

r~




Re: [PATCH 06/15] Hexagon (target/hexagon) utility function changes

2021-03-25 Thread Richard Henderson

On 3/24/21 8:50 PM, Taylor Simpson wrote:

Remove unused carry_from_add64 function
Change type of softfloat_roundingmodes

Address feedback from Richard Henderson

Signed-off-by: Taylor Simpson
---
  target/hexagon/arch.c   | 15 +--
  target/hexagon/arch.h   |  1 -
  target/hexagon/macros.h |  2 --
  3 files changed, 1 insertion(+), 17 deletions(-)


These are two separate changes.

Split them, and you can have

Reviewed-by: Richard Henderson 

for each.


r~



  1   2   3   >