Re: [PULL 04/12] hmp: Simplify qom-set

2020-06-01 Thread Markus Armbruster
"Dr. David Alan Gilbert (git)"  writes:

> From: "Dr. David Alan Gilbert" 
>
> Simplify qom_set by making it use qmp_qom_set and the JSON parser.
>
> (qemu) qom-get /machine smm
> "auto"
> (qemu) qom-set /machine smm "auto"
>
> Signed-off-by: Dr. David Alan Gilbert 
> Message-Id: <20200520151108.160598-3-dgilb...@redhat.com>
> Reviewed-by: Philippe Mathieu-Daudé 
> Reviewed-by: Markus Armbruster 
> Signed-off-by: Dr. David Alan Gilbert 
>   With 's'->'S' type change suggested by Paolo and Markus

This is actually more than just simplification, it's disarming a bear
trap: the string visitor is restricted to a subset of the QAPI types,
and when you qom-set a property with a type it can't handle, QEMU
aborts.  I mentioned this in the discussion of possible ways out of the
qom-get impasse, but missed reraising it in patch review.

A suitably amended commit would be nice, but respinning the PR just for
that may not be worthwhile.




RE: [PATCH 2/3] migration/colo: Update checkpoint time lately

2020-06-01 Thread Zhanghailiang
Reviewed-by: zhanghailiang 

Hmm, How much time it spends on preparing before COLO process ?

> -Original Message-
> From: Zhang Chen [mailto:chen.zh...@intel.com]
> Sent: Friday, May 15, 2020 12:28 PM
> To: Dr . David Alan Gilbert ; Juan Quintela
> ; Zhanghailiang ;
> qemu-dev 
> Cc: Zhang Chen ; Jason Wang
> ; Zhang Chen 
> Subject: [PATCH 2/3] migration/colo: Update checkpoint time lately
> 
> From: Zhang Chen 
> 
> Previous operation(like vm_start and replication_start_all) will consume
> extra time for first forced synchronization, so reduce it in this patch.
> 
> Signed-off-by: Zhang Chen 
> ---
>  migration/colo.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/migration/colo.c b/migration/colo.c index
> 5ef69b885d..d5bced22cb 100644
> --- a/migration/colo.c
> +++ b/migration/colo.c
> @@ -531,7 +531,6 @@ static void colo_process_checkpoint(MigrationState
> *s)  {
>  QIOChannelBuffer *bioc;
>  QEMUFile *fb = NULL;
> -int64_t current_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);
>  Error *local_err = NULL;
>  int ret;
> 
> @@ -580,8 +579,8 @@ static void colo_process_checkpoint(MigrationState
> *s)
>  qemu_mutex_unlock_iothread();
>  trace_colo_vm_state_change("stop", "run");
> 
> -timer_mod(s->colo_delay_timer,
> -current_time + s->parameters.x_checkpoint_delay);
> +timer_mod(s->colo_delay_timer,
> qemu_clock_get_ms(QEMU_CLOCK_HOST) +
> +  s->parameters.x_checkpoint_delay);
> 
>  while (s->state == MIGRATION_STATUS_COLO) {
>  if (failover_get_state() != FAILOVER_STATUS_NONE) {
> --
> 2.17.1




Re: [PATCH v3 0/3] account for NVDIMM nodes during SRAT generation

2020-06-01 Thread Michael S. Tsirkin
On Thu, May 28, 2020 at 04:03:51PM -0700, no-re...@patchew.org wrote:
> Patchew URL: 
> https://patchew.org/QEMU/20200528162011.16258-1-vishal.l.ve...@intel.com/
> 
> 
> 
> Hi,
> 
> This series seems to have some coding style problems. See output below for
> more information:
> 
> Message-id: 20200528162011.16258-1-vishal.l.ve...@intel.com
> Subject: [PATCH v3 0/3] account for NVDIMM nodes during SRAT generation
> Type: series
> 
> === 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 ===
> 
> Switched to a new branch 'test'
> 7e9fa62 tests/acpi: update expected SRAT files
> e8c3427 hw/acpi-build: account for NVDIMM numa nodes in SRAT
> 7598dc9 diffs-allowed: add the SRAT AML to diffs-allowed
> 
> === OUTPUT BEGIN ===
> 1/3 Checking commit 7598dc9bc984 (diffs-allowed: add the SRAT AML to 
> diffs-allowed)
> 2/3 Checking commit e8c342740610 (hw/acpi-build: account for NVDIMM numa 
> nodes in SRAT)
> 3/3 Checking commit 7e9fa62e9d26 (tests/acpi: update expected SRAT files)
> ERROR: Do not add expected files together with tests, follow instructions in 
> tests/qtest/bios-tables-test.c: both tests/data/acpi/q35/SRAT.dimmpxm and 
> tests/qtest/bios-tables-test-allowed-diff.h found
> 
> ERROR: Do not add expected files together with tests, follow instructions in 
> tests/qtest/bios-tables-test.c: both tests/data/acpi/q35/SRAT.dimmpxm and 
> tests/qtest/bios-tables-test-allowed-diff.h found
> 
> total: 2 errors, 0 warnings, 1 lines checked
> 
> Patch 3/3 has style problems, please review.  If any of these errors
> are false positives report them to the maintainer, see
> CHECKPATCH in MAINTAINERS.

This is a bug I introduced in checkpatch, pls ignore.


> === OUTPUT END ===
> 
> Test command exited with code: 1
> 
> 
> The full log is available at
> http://patchew.org/logs/20200528162011.16258-1-vishal.l.ve...@intel.com/testing.checkpatch/?type=message.
> ---
> Email generated automatically by Patchew [https://patchew.org/].
> Please send your feedback to patchew-de...@redhat.com




[PATCH] checkpatch: reversed logic with acpi test checks

2020-06-01 Thread Michael S. Tsirkin
Logic reversed: allowed list should just be ignored. Instead we
only take that into account :(

Fixes: e11b06a880ca ("checkpatch: ignore allowed diff list")
Signed-off-by: Michael S. Tsirkin 
---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 0ba213e9f2..55aa45dc16 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1267,7 +1267,7 @@ sub checkfilename {
 # files and when changing tests.
if ($name =~ m#^tests/data/acpi/# and not $name =~ m#^\.sh$#) {
$$acpi_testexpected = $name;
-   } elsif ($name =~ m#^tests/qtest/bios-tables-test-allowed-diff.h$#) {
+   } elsif (not $name =~ m#^tests/qtest/bios-tables-test-allowed-diff.h$#) 
{
$$acpi_nontestexpected = $name;
}
if (defined $$acpi_testexpected and defined $$acpi_nontestexpected) {
-- 
MST




Re: [PATCH v3 0/4] microvm: memory config tweaks

2020-06-01 Thread Michael S. Tsirkin
On Fri, May 29, 2020 at 09:39:53AM +0200, Gerd Hoffmann wrote:
> With more microvm memory config tweaks split this into its owns series,
> the microvm acpi patch series is already big enough ...

Okay.

We might want to add pci to microvm and maybe we'll need more space
then, but let's leave this for another day.

Reviewed-by: Michael S. Tsirkin 


> v2:
>  - use 3G split.
>  - add patch to move virtio-mmio region.
>  - pick up acks & reviews.
> v3:
>  - fix xen build.
>  - pick up acks & reviews.
> 
> take care,
>   Gerd
> 
> Gerd Hoffmann (4):
>   microvm: use 3G split unconditionally
>   microvm: drop max-ram-below-4g support
>   x86: move max-ram-below-4g to pc
>   microvm: move virtio base to 0xfeb0
> 
>  include/hw/i386/microvm.h |  2 +-
>  include/hw/i386/pc.h  |  2 ++
>  include/hw/i386/x86.h |  4 
>  hw/i386/microvm.c | 35 +
>  hw/i386/pc.c  | 46 +++
>  hw/i386/pc_piix.c | 10 -
>  hw/i386/pc_q35.c  | 10 -
>  hw/i386/x86.c | 46 ---
>  hw/i386/xen/xen-hvm.c |  2 +-
>  9 files changed, 61 insertions(+), 96 deletions(-)
> 
> -- 
> 2.18.4




Re: [RFC v2 16/18] guest memory protection: Add Error ** to GuestMemoryProtection::kvm_init

2020-06-01 Thread Richard Henderson
On 5/20/20 8:43 PM, David Gibson wrote:
> This allows failures to be reported richly and idiomatically.
> 
> Signed-off-by: David Gibson 
> ---
>  accel/kvm/kvm-all.c|  4 +++-
>  include/exec/guest-memory-protection.h |  2 +-
>  target/i386/sev.c  | 31 +-
>  3 files changed, 19 insertions(+), 18 deletions(-)

Reviewed-by: Richard Henderson 

r~




Re: [RFC v2 15/18] guest memory protection: Decouple kvm_memcrypt_*() helpers from KVM

2020-06-01 Thread Richard Henderson
On 5/20/20 8:43 PM, David Gibson wrote:
> The kvm_memcrypt_enabled() and kvm_memcrypt_encrypt_data() helper functions
> don't conceptually have any connection to KVM (although it's not possible
> in practice to use them without it).

Yet?

I would expect TCG implementations of these interfaces eventually, for
simulation of such hardware.  Or are we expecting *this* interface to be used
only with kvm/any-other-hw-accel, as the nested guest inside of the outermost
tcg qemu that's simulating hardware that supports...

Anyway, the actual code looks ok.

Reviewed-by: Richard Henderson 

r~



Re: [PATCH] hw/pci/pcie: Move hot plug capability check to pre_plug callback

2020-06-01 Thread Michael S. Tsirkin
On Mon, Jun 01, 2020 at 06:29:34PM +0200, Julia Suvorova wrote:
> Check for hot plug capability earlier to avoid removing devices attached
> during the initialization process.
> 
> Run qemu with an unattached drive:
>   -drive file=$FILE,if=none,id=drive0 \
>   -device pcie-root-port,id=rp0,slot=3,bus=pcie.0,hotplug=off
> Hotplug a block device:
>   device_add virtio-blk-pci,id=blk0,drive=drive0,bus=rp0
> If hotplug fails on plug_cb, drive0 will be deleted.
> 
> Signed-off-by: Julia Suvorova 


Fixes: 0501e1aa1d32a6 ("hw/pci/pcie: Forbid hot-plug if it's disabled on the 
slot")

correct?


> ---
> Hard to say if it's a bug or generally acceptable behaviour, but seems like
> hotplug_handler_plug should never fail.
> 
>  hw/pci/pcie.c | 19 +++
>  1 file changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c
> index f50e10b8fb..5b9c022d91 100644
> --- a/hw/pci/pcie.c
> +++ b/hw/pci/pcie.c
> @@ -407,6 +407,17 @@ static void pcie_cap_slot_plug_common(PCIDevice 
> *hotplug_dev, DeviceState *dev,
>  void pcie_cap_slot_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev,
> Error **errp)
>  {
> +PCIDevice *hotplug_pdev = PCI_DEVICE(hotplug_dev);
> +uint8_t *exp_cap = hotplug_pdev->config + hotplug_pdev->exp.exp_cap;
> +uint32_t sltcap = pci_get_word(exp_cap + PCI_EXP_SLTCAP);
> +
> +/* Check if hot-plug is disabled on the slot */
> +if (dev->hotplugged && (sltcap & PCI_EXP_SLTCAP_HPC) == 0) {
> +error_setg(errp, "Hot-plug failed: unsupported by the port device 
> '%s'",
> + DEVICE(hotplug_pdev)->id);
> +return;
> +}
> +
>  pcie_cap_slot_plug_common(PCI_DEVICE(hotplug_dev), dev, errp);
>  }
>  
> @@ -415,7 +426,6 @@ void pcie_cap_slot_plug_cb(HotplugHandler *hotplug_dev, 
> DeviceState *dev,
>  {
>  PCIDevice *hotplug_pdev = PCI_DEVICE(hotplug_dev);
>  uint8_t *exp_cap = hotplug_pdev->config + hotplug_pdev->exp.exp_cap;
> -uint32_t sltcap = pci_get_word(exp_cap + PCI_EXP_SLTCAP);
>  PCIDevice *pci_dev = PCI_DEVICE(dev);
>  
>  /* Don't send event when device is enabled during qemu machine creation:
> @@ -431,13 +441,6 @@ void pcie_cap_slot_plug_cb(HotplugHandler *hotplug_dev, 
> DeviceState *dev,
>  return;
>  }
>  
> -/* Check if hot-plug is disabled on the slot */
> -if ((sltcap & PCI_EXP_SLTCAP_HPC) == 0) {
> -error_setg(errp, "Hot-plug failed: unsupported by the port device 
> '%s'",
> - DEVICE(hotplug_pdev)->id);
> -return;
> -}
> -
>  /* To enable multifunction hot-plug, we just ensure the function
>   * 0 added last. When function 0 is added, we set the sltsta and
>   * inform OS via event notification.
> -- 
> 2.25.4




Re: [RFC v2 14/18] guest memory protection: Rework the "memory-encryption" property

2020-06-01 Thread Richard Henderson
On 5/20/20 8:43 PM, David Gibson wrote:
> +++ b/include/hw/boards.h
> @@ -12,6 +12,8 @@
>  #include "qom/object.h"
>  #include "hw/core/cpu.h"
>  
> +typedef struct GuestMemoryProtection GuestMemoryProtection;
> +

I think this needs to be in include/qemu/typedefs.h,
and the other typedef in patch 10 needs to be moved there.

IIRC, clang warns about duplicate typedefs.


r~



Re: [PATCH v2 0/8] hw: Fix some incomplete memory region size

2020-06-01 Thread Michael S. Tsirkin
On Mon, Jun 01, 2020 at 04:29:22PM +0200, Philippe Mathieu-Daudé wrote:
> Series fully reviewed.
> 
> Since v1:
> - Add parenthesis on the Xen patch (Paul Durrant)
> - Add Peter's R-b tags


PCI things:

Reviewed-by: Michael S. Tsirkin 

I'll queue pci patches in my tree.

> memory_region_set_size() handle the 16 Exabytes limit by
> special-casing the UINT64_MAX value.
> This is not a problem for the 32-bit maximum, 4 GiB, but
> in some places we incorrectly use UINT32_MAX instead of
> 4 GiB, and end up missing 1 byte in the memory region.
> 
> This series fixes the cases I encountered.
> Also included few patches while reviewing, I replaced some
> magic values by the IEC binary prefix equivalent.
> 
> Regards,
> 
> Phil.
> 
> Philippe Mathieu-Daudé (8):
>   hw/arm/aspeed: Correct DRAM container region size
>   hw/pci-host/prep: Correct RAVEN bus bridge memory region size
>   hw/pci/pci_bridge: Correct pci_bridge_io memory region size
>   hw/pci/pci_bridge: Use the IEC binary prefix definitions
>   hw/pci-host: Use the IEC binary prefix definitions
>   hw/hppa/dino: Use the IEC binary prefix definitions
>   hw/i386/xen/xen-hvm: Use the IEC binary prefix definitions
>   target/i386/cpu: Use the IEC binary prefix definitions
> 
>  hw/arm/aspeed.c | 2 +-
>  hw/hppa/dino.c  | 4 ++--
>  hw/i386/xen/xen-hvm.c   | 3 ++-
>  hw/pci-host/i440fx.c| 3 ++-
>  hw/pci-host/prep.c  | 2 +-
>  hw/pci-host/q35.c   | 2 +-
>  hw/pci-host/versatile.c | 5 +++--
>  hw/pci/pci_bridge.c | 7 ---
>  target/i386/cpu.c   | 2 +-
>  9 files changed, 17 insertions(+), 13 deletions(-)
> 
> -- 
> 2.21.3




Re: [RFC v2 12/18] guest memory protection: Perform KVM init via interface

2020-06-01 Thread Richard Henderson
On 6/1/20 8:39 PM, Richard Henderson wrote:
> On 5/20/20 8:42 PM, David Gibson wrote:
>> +if (object_dynamic_cast(obj, TYPE_GUEST_MEMORY_PROTECTION)) {
>> +GuestMemoryProtection *gmpo = GUEST_MEMORY_PROTECTION(obj);
> 
> This duplicates the interface check.  You should use
> 
>   gmpo = (GuestMemoryProtection *)
> object_dynamic_cast(obj, TYPE_GUEST_MEMORY_PROTECTION);
>   if (gmpo) {
> 
> AFICT.

Or ignore this nit, since you clean it up in patch 14.

Reviewed-by: Richard Henderson 

r~




Re: [RFC v2 13/18] guest memory protection: Move side effect out of machine_set_memory_encryption()

2020-06-01 Thread Richard Henderson
On 5/20/20 8:42 PM, David Gibson wrote:
> When the "memory-encryption" property is set, we also disable KSM
> merging for the guest, since it won't accomplish anything.
> 
> We want that, but doing it in the property set function itself is
> thereoretically incorrect, in the unlikely event of some configuration
> environment that set the property then cleared it again before
> constructing the guest.
> 
> But more important, it makes some other cleanups we want more
> difficult.  So, instead move this logic to machine_run_board_init()
> conditional on the final value of the property.
> 
> Signed-off-by: David Gibson 
> ---
>  hw/core/machine.c | 17 +
>  1 file changed, 9 insertions(+), 8 deletions(-)

Reviewed-by: Richard Henderson 

r~




Re: [RFC v2 12/18] guest memory protection: Perform KVM init via interface

2020-06-01 Thread Richard Henderson
On 5/20/20 8:42 PM, David Gibson wrote:
> +if (object_dynamic_cast(obj, TYPE_GUEST_MEMORY_PROTECTION)) {
> +GuestMemoryProtection *gmpo = GUEST_MEMORY_PROTECTION(obj);

This duplicates the interface check.  You should use

  gmpo = (GuestMemoryProtection *)
object_dynamic_cast(obj, TYPE_GUEST_MEMORY_PROTECTION);
  if (gmpo) {

AFICT.


r~



RE: [PATCH 1/3] migration/colo: Optimize COLO boot code path

2020-06-01 Thread Zhanghailiang
Reviewed-by: zhanghailiang 

> -Original Message-
> From: Zhang Chen [mailto:chen.zh...@intel.com]
> Sent: Friday, May 15, 2020 12:28 PM
> To: Dr . David Alan Gilbert ; Juan Quintela
> ; Zhanghailiang ;
> qemu-dev 
> Cc: Zhang Chen ; Jason Wang
> ; Zhang Chen 
> Subject: [PATCH 1/3] migration/colo: Optimize COLO boot code path
> 
> From: Zhang Chen 
> 
> No need to reuse MIGRATION_STATUS_ACTIVE boot COLO.
> 
> Signed-off-by: Zhang Chen 
> ---
>  migration/colo.c  |  2 --
>  migration/migration.c | 17 ++---
>  2 files changed, 10 insertions(+), 9 deletions(-)
> 
> diff --git a/migration/colo.c b/migration/colo.c index
> d015d4f84e..5ef69b885d 100644
> --- a/migration/colo.c
> +++ b/migration/colo.c
> @@ -669,8 +669,6 @@ void migrate_start_colo_process(MigrationState *s)
>  colo_checkpoint_notify, s);
> 
>  qemu_sem_init(&s->colo_exit_sem, 0);
> -migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE,
> -  MIGRATION_STATUS_COLO);
>  colo_process_checkpoint(s);
>  qemu_mutex_lock_iothread();
>  }
> diff --git a/migration/migration.c b/migration/migration.c index
> 0bb042a0f7..c889ef6eb7 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -2972,7 +2972,10 @@ static void
> migration_completion(MigrationState *s)
>  goto fail_invalidate;
>  }
> 
> -if (!migrate_colo_enabled()) {
> +if (migrate_colo_enabled()) {
> +migrate_set_state(&s->state, current_active_state,
> +  MIGRATION_STATUS_COLO);
> +} else {
>  migrate_set_state(&s->state, current_active_state,
>MIGRATION_STATUS_COMPLETED);
>  }
> @@ -3304,12 +3307,7 @@ static void
> migration_iteration_finish(MigrationState *s)
>  migration_calculate_complete(s);
>  runstate_set(RUN_STATE_POSTMIGRATE);
>  break;
> -
> -case MIGRATION_STATUS_ACTIVE:
> -/*
> - * We should really assert here, but since it's during
> - * migration, let's try to reduce the usage of assertions.
> - */
> +case MIGRATION_STATUS_COLO:
>  if (!migrate_colo_enabled()) {
>  error_report("%s: critical error: calling COLO code without "
>   "COLO enabled", __func__); @@ -3319,6
> +3317,11 @@ static void migration_iteration_finish(MigrationState *s)
>   * Fixme: we will run VM in COLO no matter its old running state.
>   * After exited COLO, we will keep running.
>   */
> +case MIGRATION_STATUS_ACTIVE:
> +/*
> + * We should really assert here, but since it's during
> + * migration, let's try to reduce the usage of assertions.
> + */
>  s->vm_was_running = true;
>  /* Fallthrough */
>  case MIGRATION_STATUS_FAILED:
> --
> 2.17.1




Re: [RFC v2 11/18] guest memory protection: Handle memory encrption via interface

2020-06-01 Thread Richard Henderson
On 5/20/20 8:42 PM, David Gibson wrote:
> At the moment AMD SEV sets a special function pointer, plus an opaque
> handle in KVMState to let things know how to encrypt guest memory.
> 
> Now that we have a QOM interface for handling things related to guest
> memory protection, use a QOM method on that interface, rather than a bare
> function pointer for this.
> 
> Signed-off-by: David Gibson 
> ---
>  accel/kvm/kvm-all.c| 23 +++
>  accel/kvm/sev-stub.c   |  5 --
>  include/exec/guest-memory-protection.h |  2 +
>  include/sysemu/sev.h   |  6 +-
>  target/i386/sev.c  | 84 ++
>  5 files changed, 63 insertions(+), 57 deletions(-)

Reviewed-by: Richard Henderson 

r~




Re: [RFC v2 09/18] target/i386: sev: Unify SEVState and SevGuestState

2020-06-01 Thread Richard Henderson
On 5/20/20 8:42 PM, David Gibson wrote:
> SEVState is contained with SevGuestState.  We've now fixed redundancies
> and name conflicts, so there's no real point to the nested structure.  Just
> move all the fields of SEVState into SevGuestState.
> 
> This eliminates the SEVState structure, which as a bonus removes the
> confusion with the SevState enum.
> 
> Signed-off-by: David Gibson 
> ---
>  target/i386/sev.c | 79 ---
>  1 file changed, 34 insertions(+), 45 deletions(-)

Yay!

Reviewed-by: Richard Henderson 

r~




Re: [PATCH v4 2/2] vhost-user-blk: delay vhost_user_blk_disconnect

2020-06-01 Thread Li Feng
Hi Raphael,
I'm sorry. I just end my journey today.

Yes, pls sign off me here.
this patch is nearly the same as my previous patch.

Thanks,
Feng Li

Raphael Norwitz  于2020年5月31日周日 上午8:55写道:
>
> On Thu, May 28, 2020 at 5:13 AM Dima Stepanov  wrote:
> >
> > A socket write during vhost-user communication may trigger a disconnect
> > event, calling vhost_user_blk_disconnect() and clearing all the
> > vhost_dev structures holding data that vhost-user functions expect to
> > remain valid to roll back initialization correctly. Delay the cleanup to
> > keep vhost_dev structure valid.
> > There are two possible states to handle:
> > 1. RUN_STATE_PRELAUNCH: skip bh oneshot call and perform disconnect in
> > the caller routine.
> > 2. RUN_STATE_RUNNING: delay by using bh
> >
> > BH changes are based on the similar changes for the vhost-user-net
> > device:
> >   commit e7c83a885f865128ae3cf1946f8cb538b63cbfba
> >   "vhost-user: delay vhost_user_stop"
> >
> > Signed-off-by: Dima Stepanov 
>
> Reviewed-by: Raphael Norwitz 
>
> Li Feng - would you also like to sign off here?
>
> > ---
> >  hw/block/vhost-user-blk.c | 38 +-
> >  1 file changed, 37 insertions(+), 1 deletion(-)
> >
> > diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c
> > index 9d8c0b3..76838e7 100644
> > --- a/hw/block/vhost-user-blk.c
> > +++ b/hw/block/vhost-user-blk.c
> > @@ -349,6 +349,19 @@ static void vhost_user_blk_disconnect(DeviceState *dev)
> >  vhost_dev_cleanup(&s->dev);
> >  }
> >
> > +static void vhost_user_blk_event(void *opaque, QEMUChrEvent event);
> > +
> > +static void vhost_user_blk_chr_closed_bh(void *opaque)
> > +{
> > +DeviceState *dev = opaque;
> > +VirtIODevice *vdev = VIRTIO_DEVICE(dev);
> > +VHostUserBlk *s = VHOST_USER_BLK(vdev);
> > +
> > +vhost_user_blk_disconnect(dev);
> > +qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, vhost_user_blk_event,
> > +NULL, opaque, NULL, true);
> > +}
> > +
> >  static void vhost_user_blk_event(void *opaque, QEMUChrEvent event)
> >  {
> >  DeviceState *dev = opaque;
> > @@ -363,7 +376,30 @@ static void vhost_user_blk_event(void *opaque, 
> > QEMUChrEvent event)
> >  }
> >  break;
> >  case CHR_EVENT_CLOSED:
> > -vhost_user_blk_disconnect(dev);
> > +/*
> > + * A close event may happen during a read/write, but vhost
> > + * code assumes the vhost_dev remains setup, so delay the
> > + * stop & clear. There are two possible paths to hit this
> > + * disconnect event:
> > + * 1. When VM is in the RUN_STATE_PRELAUNCH state. The
> > + * vhost_user_blk_device_realize() is a caller.
> > + * 2. In tha main loop phase after VM start.
> > + *
> > + * For p2 the disconnect event will be delayed. We can't
> > + * do the same for p1, because we are not running the loop
> > + * at this moment. So just skip this step and perform
> > + * disconnect in the caller function.
> > + *
> > + * TODO: maybe it is a good idea to make the same fix
> > + * for other vhost-user devices.
> > + */
> > +if (runstate_is_running()) {
> > +AioContext *ctx = qemu_get_current_aio_context();
> > +
> > +qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, NULL, NULL,
> > +NULL, NULL, false);
> > +aio_bh_schedule_oneshot(ctx, vhost_user_blk_chr_closed_bh, 
> > opaque);
> > +}
> >  break;
> >  case CHR_EVENT_BREAK:
> >  case CHR_EVENT_MUX_IN:
> > --
> > 2.7.4
> >
> >



Re: [RFC v2 08/18] target/i386: sev: Remove redundant handle field

2020-06-01 Thread Richard Henderson
On 5/20/20 8:42 PM, David Gibson wrote:
> The user can explicitly specify a handle via the "handle" property wired
> to SevGuestState::handle.  That gets passed to the KVM_SEV_LAUNCH_START
> ioctl() which may update it, the final value being copied back to both
> SevGuestState::handle and SEVState::handle.
> 
> AFAICT, nothing will be looking SEVState::handle before it and
> SevGuestState::handle have been updated from the ioctl().  So, remove the
> field and just use SevGuestState::handle directly.
> 
> Signed-off-by: David Gibson 
> ---
>  target/i386/sev.c | 12 
>  1 file changed, 4 insertions(+), 8 deletions(-)

Reviewed-by: Richard Henderson 

r~




Re: [RFC v2 07/18] target/i386: sev: Remove redundant policy field

2020-06-01 Thread Richard Henderson
On 5/20/20 8:42 PM, David Gibson wrote:
> SEVState::policy is set from the final value of the policy field in the
> parameter structure for the KVM_SEV_LAUNCH_START ioctl().  But, AFAICT
> that ioctl() won't ever change it from the original supplied value which
> comes from SevGuestState::policy.
> 
> So, remove this field and just use SevGuestState::policy directly.
> 
> Signed-off-by: David Gibson 
> ---
>  target/i386/sev.c | 7 ++-
>  1 file changed, 2 insertions(+), 5 deletions(-)

Reviewed-by: Richard Henderson 

r~




Re: [RFC v2 06/18] target/i386: sev: Remove redundant cbitpos and reduced_phys_bits fields

2020-06-01 Thread Richard Henderson
On 5/20/20 8:42 PM, David Gibson wrote:
> The SEVState structure has cbitpos and reduced_phys_bits fields which are
> simply copied from the SevGuestState structure and never changed.  Now that
> SEVState is embedded in SevGuestState we can just access the original copy
> directly.
> 
> Signed-off-by: David Gibson 
> ---
>  target/i386/sev.c | 19 +++
>  1 file changed, 7 insertions(+), 12 deletions(-)

Reviewed-by: Richard Henderson 

r~




Re: [RFC v2 05/18] target/i386: sev: Partial cleanup to sev_state global

2020-06-01 Thread Richard Henderson
On 5/20/20 8:42 PM, David Gibson wrote:
> The SEV code uses a pretty ugly global to access its internal state.  Now
> that SEVState is embedded in SevGuestState, we can avoid accessing it via
> the global in some cases.  In the remaining cases use a new global
> referencing the containing SevGuestState which will simplify some future
> transformations.
> 
> Signed-off-by: David Gibson 
> ---
>  target/i386/sev.c | 92 ---
>  1 file changed, 48 insertions(+), 44 deletions(-)

Reviewed-by: Richard Henderson 

r~




Re: [RFC v2 04/18] target/i386: sev: Embed SEVState in SevGuestState

2020-06-01 Thread Richard Henderson
On 5/20/20 8:42 PM, David Gibson wrote:
> Currently SevGuestState contains only configuration information.  For
> runtime state another non-QOM struct SEVState is allocated separately.
> 
> Simplify things by instead embedding the SEVState structure in
> SevGuestState.
> 
> Signed-off-by: David Gibson 
> ---
>  target/i386/sev.c | 54 +--
>  1 file changed, 29 insertions(+), 25 deletions(-)

Reviewed-by: Richard Henderson 

r~




Re: [RFC v2 03/18] target/i386: sev: Rename QSevGuestInfo

2020-06-01 Thread Richard Henderson
On 5/20/20 8:42 PM, David Gibson wrote:
> At the moment this is a purely passive object which is just a container for
> information used elsewhere, hence the name.  I'm going to change that
> though, so as a preliminary rename it to SevGuestState.
> 
> That name risks confusion with both SEVState and SevState, but I'll be
> working on that in following patches.
> 
> Signed-off-by: David Gibson 
> ---
>  target/i386/sev.c | 87 ---
>  1 file changed, 44 insertions(+), 43 deletions(-)

Reviewed-by: Richard Henderson 

r~




Re: [RFC v2 02/18] target/i386: sev: Move local structure definitions into .c file

2020-06-01 Thread Richard Henderson
On 5/20/20 8:42 PM, David Gibson wrote:
> Neither QSevGuestInfo nor SEVState (not to be confused with SevState) is
> used anywhere outside target/i386/sev.c, so they might as well live in
> there rather than in a (somewhat) exposed header.
> 
> Signed-off-by: David Gibson 
> ---
>  target/i386/sev.c  | 44 ++
>  target/i386/sev_i386.h | 44 --
>  2 files changed, 44 insertions(+), 44 deletions(-)

Reviewed-by: Richard Henderson 

r~




Re: [RFC v2 01/18] target/i386: sev: Remove unused QSevGuestInfoClass

2020-06-01 Thread Richard Henderson
On 5/20/20 8:42 PM, David Gibson wrote:
> This structure is nothing but an empty wrapper around the parent class,
> which by QOM conventions means we don't need it at all.
> 
> Signed-off-by: David Gibson 
> ---
>  target/i386/sev.c  | 1 -
>  target/i386/sev_i386.h | 5 -
>  2 files changed, 6 deletions(-)

Reviewed-by: Richard Henderson 

r~



[PATCH for-5.1 V4 4/4] MAINTAINERS: Add myself as Loongson-3 maintainer

2020-06-01 Thread Huacai Chen
Signed-off-by: Huacai Chen 
Co-developed-by: Jiaxun Yang 
---
 MAINTAINERS | 5 +
 1 file changed, 5 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 0944d9c..c42a218 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1092,6 +1092,11 @@ F: hw/isa/vt82c686.c
 F: hw/pci-host/bonito.c
 F: include/hw/isa/vt82c686.h
 
+Loongson-3
+M: Huacai Chen 
+S: Maintained
+F: hw/mips/mips_loongson3.c
+
 Boston
 M: Paul Burton 
 R: Aleksandar Rikalo 
-- 
2.7.0




[PATCH for-5.1 V4 3/4] hw/mips: Add Loongson-3 machine support (with KVM)

2020-06-01 Thread Huacai Chen
Add Loongson-3 based machine support, it use i8259 as the interrupt
controler and use GPEX as the pci controller. Currently it can only
work with KVM, but we will add TCG support in future.

We already have a full functional Linux kernel (based on Linux-5.4.x LTS
but not upstream yet) here:

https://github.com/chenhuacai/linux

How to use QEMU/Loongson-3?
1, Download kernel source from the above URL;
2, Build a kernel with arch/mips/configs/loongson3_{def,hpc}config;
3, Boot the a Loongson-3A4000 host with this kernel;
4, Build QEMU-5.0.0 with this patchset;
5, modprobe kvm;
6, Use QEMU with TCG (available in future):
   qemu-system-mips64el -M loongson3,accel=tcg -cpu Loongson-3A1000 -kernel 
 -append ...
   Use QEMU with KVM (available at present):
   qemu-system-mips64el -M loongson3,accel=kvm -cpu Loongson-3A4000 -kernel 
 -append ...

   The "-cpu" parameter can be omitted here and QEMU will use the correct type 
for TCG/KVM automatically.

Signed-off-by: Huacai Chen 
Co-developed-by: Jiaxun Yang 
---
 default-configs/mips64el-softmmu.mak |   1 +
 hw/mips/Kconfig  |  10 +
 hw/mips/Makefile.objs|   1 +
 hw/mips/loongson3.c  | 901 +++
 4 files changed, 913 insertions(+)
 create mode 100644 hw/mips/loongson3.c

diff --git a/default-configs/mips64el-softmmu.mak 
b/default-configs/mips64el-softmmu.mak
index 9f8a3ef..2a2a3fb 100644
--- a/default-configs/mips64el-softmmu.mak
+++ b/default-configs/mips64el-softmmu.mak
@@ -3,6 +3,7 @@
 include mips-softmmu-common.mak
 CONFIG_IDE_VIA=y
 CONFIG_FULOONG=y
+CONFIG_LOONGSON3=y
 CONFIG_ATI_VGA=y
 CONFIG_RTL8139_PCI=y
 CONFIG_JAZZ=y
diff --git a/hw/mips/Kconfig b/hw/mips/Kconfig
index 67d39c5..42931fd 100644
--- a/hw/mips/Kconfig
+++ b/hw/mips/Kconfig
@@ -45,6 +45,16 @@ config FULOONG
 bool
 select PCI_BONITO
 
+config LOONGSON3
+bool
+select PCKBD
+select SERIAL
+select ISA_BUS
+select PCI_EXPRESS_GENERIC_BRIDGE
+select VIRTIO_VGA
+select QXL if SPICE
+select MSI_NONBROKEN
+
 config MIPS_CPS
 bool
 select PTIMER
diff --git a/hw/mips/Makefile.objs b/hw/mips/Makefile.objs
index 3b3e6ea..31dedcb 100644
--- a/hw/mips/Makefile.objs
+++ b/hw/mips/Makefile.objs
@@ -4,5 +4,6 @@ obj-$(CONFIG_MALTA) += gt64xxx_pci.o malta.o
 obj-$(CONFIG_MIPSSIM) += mipssim.o
 obj-$(CONFIG_JAZZ) += jazz.o
 obj-$(CONFIG_FULOONG) += fuloong2e.o
+obj-$(CONFIG_LOONGSON3) += loongson3.o
 obj-$(CONFIG_MIPS_CPS) += cps.o
 obj-$(CONFIG_MIPS_BOSTON) += boston.o
diff --git a/hw/mips/loongson3.c b/hw/mips/loongson3.c
new file mode 100644
index 000..e4b9538
--- /dev/null
+++ b/hw/mips/loongson3.c
@@ -0,0 +1,901 @@
+/*
+ * Generic Loongson-3 Platform support
+ *
+ * Copyright (c) 2016-2020 Huacai Chen (che...@lemote.com)
+ * This code is licensed under the GNU GPL v2.
+ *
+ * Contributions are licensed under the terms of the GNU GPL,
+ * version 2 or (at your option) any later version.
+ */
+
+/*
+ * Generic PC Platform based on Loongson-3 CPU (MIPS64R2 with extensions,
+ * 800~2000MHz)
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "qemu/units.h"
+#include "qapi/error.h"
+#include "cpu.h"
+#include "elf.h"
+#include "hw/boards.h"
+#include "hw/char/serial.h"
+#include "hw/mips/mips.h"
+#include "hw/mips/cpudevs.h"
+#include "hw/intc/i8259.h"
+#include "hw/loader.h"
+#include "hw/ide.h"
+#include "hw/isa/superio.h"
+#include "hw/pci/msi.h"
+#include "hw/pci/pci.h"
+#include "hw/pci/pci_host.h"
+#include "hw/pci-host/gpex.h"
+#include "hw/rtc/mc146818rtc.h"
+#include "net/net.h"
+#include "exec/address-spaces.h"
+#include "sysemu/kvm.h"
+#include "sysemu/qtest.h"
+#include "sysemu/reset.h"
+#include "sysemu/runstate.h"
+#include "qemu/log.h"
+#include "qemu/error-report.h"
+
+#define INITRD_OFFSET 0x0400
+#define BOOTPARAM_ADDR0x8ff0
+#define BOOTPARAM_PHYADDR 0x0ff0
+#define CFG_ADDR  0x0f10
+#define FW_CONF_ADDR  0x0fff
+#define PM_MMIO_ADDR  0x1008
+#define PM_MMIO_SIZE  0x100
+#define PM_CNTL_MODE  0x10
+
+#define PHYS_TO_VIRT(x) ((x) | ~(target_ulong)0x7fff)
+
+/* Loongson-3 has a 2MB flash rom */
+#define BIOS_SIZE   (2 * MiB)
+#define LOONGSON_MAX_VCPUS  16
+
+#define LOONGSON3_BIOSNAME "bios_loongson3.bin"
+
+#define PCIE_IRQ_BASE   3
+
+#define VIRT_PCI_IO_BASE0x1800ul
+#define VIRT_PCI_IO_SIZE0x000cul
+#define VIRT_PCI_MEM_BASE   0x4000ul
+#define VIRT_PCI_MEM_SIZE   0x4000ul
+#define VIRT_PCI_ECAM_BASE  0x1a00ul
+#define VIRT_PCI_ECAM_SIZE  0x0200ul
+
+#define align(x) (((x) + 63) & ~63)
+
+/* LEFI (a UEFI-like interface for BIOS-Kernel boot parameters) data structrues
+ * defined at arch/mips/include/asm/mach-loongson64/boot_param.h in Linux 
kernel
+ */
+struct efi_memory_map_loongson {
+uint16_t vers;   /* version of efi_memory_map */
+uint32_t nr_map; /* nu

[PATCH for-5.1 V4 2/4] target/mips: Add Loongson-3 CPU definition

2020-06-01 Thread Huacai Chen
Loongson-3 CPU family include Loongson-3A R1/R2/R3/R4 and Loongson-3B
R1/R2. Loongson-3A R1 is the oldest and its ISA is the smallest, while
Loongson-3A R4 is the newest and its ISA is almost the superset of all
others. To reduce complexity, we just define two CPU types:
1, "Loongson-3A1000" CPU which is corresponding to Loongson-3A R1. It is
   suitable for TCG because Loongson-3A R1 has fewest ASE.
2, "Loongson-3A4000" CPU which is corresponding to Loongson-3A R4. It is
   suitable for KVM because Loongson-3A R4 has the VZ ASE.

Loongson-3A has CONFIG6 and CONFIG7, so add their bit-fields as well.

Signed-off-by: Huacai Chen 
Co-developed-by: Jiaxun Yang 
---
 target/mips/cpu.h| 28 +
 target/mips/internal.h   |  2 +
 target/mips/mips-defs.h  |  7 +++-
 target/mips/translate.c  |  2 +
 target/mips/translate_init.inc.c | 86 
 5 files changed, 123 insertions(+), 2 deletions(-)

diff --git a/target/mips/cpu.h b/target/mips/cpu.h
index 94d01ea..0b3c987 100644
--- a/target/mips/cpu.h
+++ b/target/mips/cpu.h
@@ -940,7 +940,35 @@ struct CPUMIPSState {
 #define CP0C5_UFR  2
 #define CP0C5_NFExists 0
 int32_t CP0_Config6;
+int32_t CP0_Config6_rw_bitmask;
+#define CP0C6_BPPASS  31
+#define CP0C6_KPOS24
+#define CP0C6_KE  23
+#define CP0C6_VTLBONLY22
+#define CP0C6_LASX21
+#define CP0C6_SSEN20
+#define CP0C6_DISDRTIME   19
+#define CP0C6_PIXNUEN 18
+#define CP0C6_SCRAND  17
+#define CP0C6_LLEXCEN 16
+#define CP0C6_DISVC   15
+#define CP0C6_VCLRU   14
+#define CP0C6_DCLRU   13
+#define CP0C6_PIXUEN  12
+#define CP0C6_DISBLKLYEN  11
+#define CP0C6_UMEMUALEN   10
+#define CP0C6_SFBEN   8
+#define CP0C6_FLTINT  7
+#define CP0C6_VLTINT  6
+#define CP0C6_DISBTB  5
+#define CP0C6_STPREFCTL   2
+#define CP0C6_INSTPREF1
+#define CP0C6_DATAPREF0
 int32_t CP0_Config7;
+int64_t CP0_Config7_rw_bitmask;
+#define CP0C7_NAPCGEN   2
+#define CP0C7_UNIMUEN   1
+#define CP0C7_VFPUCGEN  0
 uint64_t CP0_LLAddr;
 uint64_t CP0_MAAR[MIPS_MAAR_MAX];
 int32_t CP0_MAARI;
diff --git a/target/mips/internal.h b/target/mips/internal.h
index 1bf274b..7853cb1 100644
--- a/target/mips/internal.h
+++ b/target/mips/internal.h
@@ -36,7 +36,9 @@ struct mips_def_t {
 int32_t CP0_Config5;
 int32_t CP0_Config5_rw_bitmask;
 int32_t CP0_Config6;
+int32_t CP0_Config6_rw_bitmask;
 int32_t CP0_Config7;
+int32_t CP0_Config7_rw_bitmask;
 target_ulong CP0_LLAddr_rw_bitmask;
 int CP0_LLAddr_shift;
 int32_t SYNCI_Step;
diff --git a/target/mips/mips-defs.h b/target/mips/mips-defs.h
index a831bb4..c2c96db 100644
--- a/target/mips/mips-defs.h
+++ b/target/mips/mips-defs.h
@@ -51,8 +51,9 @@
  */
 #define INSN_LOONGSON2E   0x0001ULL
 #define INSN_LOONGSON2F   0x0002ULL
-#define INSN_VR54XX   0x0004ULL
-#define INSN_R59000x0008ULL
+#define INSN_LOONGSON3A   0x0004ULL
+#define INSN_VR54XX   0x0008ULL
+#define INSN_R59000x0010ULL
 /*
  *   bits 56-63: vendor-specific ASEs
  */
@@ -94,6 +95,8 @@
 /* Wave Computing: "nanoMIPS" */
 #define CPU_NANOMIPS32  (CPU_MIPS32R6 | ISA_NANOMIPS32)
 
+#define CPU_LOONGSON3A  (CPU_MIPS64R2 | INSN_LOONGSON3A)
+
 /*
  * Strictly follow the architecture standard:
  * - Disallow "special" instruction handling for PMON/SPIM.
diff --git a/target/mips/translate.c b/target/mips/translate.c
index 25b595a..2caf4cb 100644
--- a/target/mips/translate.c
+++ b/target/mips/translate.c
@@ -31206,7 +31206,9 @@ void cpu_state_reset(CPUMIPSState *env)
 env->CP0_Config5 = env->cpu_model->CP0_Config5;
 env->CP0_Config5_rw_bitmask = env->cpu_model->CP0_Config5_rw_bitmask;
 env->CP0_Config6 = env->cpu_model->CP0_Config6;
+env->CP0_Config6_rw_bitmask = env->cpu_model->CP0_Config6_rw_bitmask;
 env->CP0_Config7 = env->cpu_model->CP0_Config7;
+env->CP0_Config7_rw_bitmask = env->cpu_model->CP0_Config7_rw_bitmask;
 env->CP0_LLAddr_rw_bitmask = env->cpu_model->CP0_LLAddr_rw_bitmask
  << env->cpu_model->CP0_LLAddr_shift;
 env->CP0_LLAddr_shift = env->cpu_model->CP0_LLAddr_shift;
diff --git a/target/mips/translate_init.inc.c b/target/mips/translate_init.inc.c
index 6d145a9..a31f229 100644
--- a/target/mips/translate_init.inc.c
+++ b/target/mips/translate_init.inc.c
@@ -802,6 +802,92 @@ const mips_def_t mips_defs[] =
 .mmu_type = MMU_TYPE_R4000,
 },
 {
+.name = "Loongson-3A1000",
+.CP0_PRid = 0x6305,
+/* 64KB I-cache and d-cache. 4 way with 32 bit cache line size.  */
+.CP0_Config0 = MIPS_CONFIG0 | (0x1 << CP0C0_AR) | (0x2 << CP0C0_AT) |
+   (MMU_TYPE_R4000 << CP0C0_MT),
+   

[PATCH for-5.1 V4 1/4] hw/mips: Implement the kvm_type() hook in MachineClass

2020-06-01 Thread Huacai Chen
MIPS has two types of KVM: TE & VZ, and TE is the default type. Now we
can't create a VZ guest in QEMU because it lacks the kvm_type() hook in
MachineClass. Besides, libvirt uses a null-machine to detect the kvm
capability, so by default it will return "KVM not supported" on a VZ
platform. Thus, null-machine also need the kvm_type() hook.

Reviewed-by: Aleksandar Markovic 
Signed-off-by: Huacai Chen 
Co-developed-by: Jiaxun Yang 
---
 hw/core/Makefile.objs  |  2 +-
 hw/core/null-machine.c |  4 
 hw/mips/Makefile.objs  |  2 +-
 hw/mips/common.c   | 42 ++
 include/hw/mips/mips.h |  3 +++
 5 files changed, 51 insertions(+), 2 deletions(-)
 create mode 100644 hw/mips/common.c

diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
index 1d540ed..b5672f4 100644
--- a/hw/core/Makefile.objs
+++ b/hw/core/Makefile.objs
@@ -17,11 +17,11 @@ common-obj-$(CONFIG_SOFTMMU) += vm-change-state-handler.o
 common-obj-$(CONFIG_SOFTMMU) += qdev-properties-system.o
 common-obj-$(CONFIG_SOFTMMU) += sysbus.o
 common-obj-$(CONFIG_SOFTMMU) += machine.o
-common-obj-$(CONFIG_SOFTMMU) += null-machine.o
 common-obj-$(CONFIG_SOFTMMU) += loader.o
 common-obj-$(CONFIG_SOFTMMU) += machine-hmp-cmds.o
 common-obj-$(CONFIG_SOFTMMU) += numa.o
 common-obj-$(CONFIG_SOFTMMU) += clock-vmstate.o
+obj-$(CONFIG_SOFTMMU) += null-machine.o
 obj-$(CONFIG_SOFTMMU) += machine-qmp-cmds.o
 
 common-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
diff --git a/hw/core/null-machine.c b/hw/core/null-machine.c
index cb47d9d..94a36f9 100644
--- a/hw/core/null-machine.c
+++ b/hw/core/null-machine.c
@@ -17,6 +17,7 @@
 #include "sysemu/sysemu.h"
 #include "exec/address-spaces.h"
 #include "hw/core/cpu.h"
+#include "hw/mips/mips.h"
 
 static void machine_none_init(MachineState *mch)
 {
@@ -50,6 +51,9 @@ static void machine_none_machine_init(MachineClass *mc)
 mc->max_cpus = 1;
 mc->default_ram_size = 0;
 mc->default_ram_id = "ram";
+#ifdef TARGET_MIPS
+mc->kvm_type = mips_kvm_type;
+#endif
 }
 
 DEFINE_MACHINE("none", machine_none_machine_init)
diff --git a/hw/mips/Makefile.objs b/hw/mips/Makefile.objs
index 739e2b7..3b3e6ea 100644
--- a/hw/mips/Makefile.objs
+++ b/hw/mips/Makefile.objs
@@ -1,4 +1,4 @@
-obj-y += addr.o mips_int.o
+obj-y += addr.o common.o mips_int.o
 obj-$(CONFIG_R4K) += r4k.o
 obj-$(CONFIG_MALTA) += gt64xxx_pci.o malta.o
 obj-$(CONFIG_MIPSSIM) += mipssim.o
diff --git a/hw/mips/common.c b/hw/mips/common.c
new file mode 100644
index 000..4d8e141
--- /dev/null
+++ b/hw/mips/common.c
@@ -0,0 +1,42 @@
+/*
+ * Common MIPS routines
+ *
+ * Copyright (c) 2020 Huacai Chen (che...@lemote.com)
+ * This code is licensed under the GNU GPL v2.
+ */
+
+#include 
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "hw/boards.h"
+#include "hw/mips/mips.h"
+#include "sysemu/kvm_int.h"
+
+#ifndef CONFIG_KVM
+
+int mips_kvm_type(MachineState *machine, const char *vm_type)
+{
+return 0;
+}
+
+#else
+
+int mips_kvm_type(MachineState *machine, const char *vm_type)
+{
+int r;
+KVMState *s = KVM_STATE(machine->accelerator);
+
+r = kvm_check_extension(s, KVM_CAP_MIPS_VZ);
+if (r > 0) {
+return KVM_VM_MIPS_VZ;
+}
+
+r = kvm_check_extension(s, KVM_CAP_MIPS_TE);
+if (r > 0) {
+return KVM_VM_MIPS_TE;
+}
+
+return -1;
+}
+
+#endif
diff --git a/include/hw/mips/mips.h b/include/hw/mips/mips.h
index 0af4c3d..2ac0580 100644
--- a/include/hw/mips/mips.h
+++ b/include/hw/mips/mips.h
@@ -20,4 +20,7 @@ void rc4030_dma_write(void *dma, uint8_t *buf, int len);
 
 DeviceState *rc4030_init(rc4030_dma **dmas, IOMMUMemoryRegion **dma_mr);
 
+/* common.c */
+int mips_kvm_type(MachineState *machine, const char *vm_type);
+
 #endif
-- 
2.7.0




[PATCH for-5.1 V4 0/7] mips: Add Loongson-3 machine support (with KVM)

2020-06-01 Thread Huacai Chen
Loongson-3 CPU family include Loongson-3A R1/R2/R3/R4 and Loongson-3B
R1/R2. Loongson-3A R1 is the oldest and its ISA is the smallest, while
Loongson-3A R4 is the newest and its ISA is almost the superset of all
others. To reduce complexity, in QEMU we just define two CPU types:

1, "Loongson-3A1000" CPU which is corresponding to Loongson-3A R1. It is
   suitable for TCG because Loongson-3A R1 has fewest ASE.
2, "Loongson-3A4000" CPU which is corresponding to Loongson-3A R4. It is
   suitable for KVM because Loongson-3A R4 has the VZ ASE.

Loongson-3 lacks English documents. I've tried to translated them with
translate.google.com, and the machine translated documents (together
with their original Chinese versions) are available here.

Loongson-3A R1 (Loongson-3A1000)
User Manual Part 1:
http://ftp.godson.ac.cn/lemote/3A1000_p1.pdf
http://ftp.godson.ac.cn/lemote/Loongson3A1000_processor_user_manual_P1.pdf 
(Chinese Version)
User Manual Part 2:
http://ftp.godson.ac.cn/lemote/3A1000_p2.pdf
http://ftp.godson.ac.cn/lemote/Loongson3A1000_processor_user_manual_P2.pdf 
(Chinese Version)

Loongson-3A R2 (Loongson-3A2000)
User Manual Part 1:
http://ftp.godson.ac.cn/lemote/3A2000_p1.pdf
http://ftp.godson.ac.cn/lemote/Loongson3A2000_user1.pdf (Chinese Version)
User Manual Part 2:
http://ftp.godson.ac.cn/lemote/3A2000_p2.pdf
http://ftp.godson.ac.cn/lemote/Loongson3A2000_user2.pdf (Chinese Version)

Loongson-3A R3 (Loongson-3A3000)
User Manual Part 1:
http://ftp.godson.ac.cn/lemote/3A3000_p1.pdf
http://ftp.godson.ac.cn/lemote/Loongson3A3000_3B3000usermanual1.pdf (Chinese 
Version)
User Manual Part 2:
http://ftp.godson.ac.cn/lemote/3A3000_p2.pdf
http://ftp.godson.ac.cn/lemote/Loongson3A3000_3B3000usermanual2.pdf (Chinese 
Version)

Loongson-3A R4 (Loongson-3A4000)
User Manual Part 1:
http://ftp.godson.ac.cn/lemote/3A4000_p1.pdf
http://ftp.godson.ac.cn/lemote/3A4000user.pdf (Chinese Version)
User Manual Part 2:
I'm sorry that it is unavailable now.

We are preparing to add QEMU's Loongson-3 support. MIPS VZ extension is
fully supported in Loongson-3A R4+, so we at first add QEMU/KVM support
in this series. And the next series will add QEMU/TCG support (it will
emulate Loongson-3A R1).

We already have a full functional Linux kernel (based on Linux-5.4.x LTS
but not upstream yet) here:

https://github.com/chenhuacai/linux

How to use QEMU/Loongson-3?
1, Download kernel source from the above URL;
2, Build a kernel with arch/mips/configs/loongson3_{def,hpc}config;
3, Boot a Loongson-3A4000 host with this kernel;
4, Build QEMU-5.0.0 with this patchset;
5, modprobe kvm;
6, Use QEMU with TCG (available in future):
   qemu-system-mips64el -M loongson3,accel=tcg -cpu Loongson-3A1000 -kernel 
 -append ... 
   Use QEMU with KVM (available at present): 
   qemu-system-mips64el -M loongson3,accel=kvm -cpu Loongson-3A4000 -kernel 
 -append ... 

   The "-cpu" parameter can be omitted here and QEMU will use the correct type 
for TCG/KVM automatically.

V1 -> V2:
1, Add a cover letter;
2, Improve CPU definitions;
3, Remove LS7A-related things (Use GPEX instead);
4, Add a description of how to run QEMU/Loongson-3.

V2 -> V3:
1, Fix all possible checkpatch.pl errors and warnings.

V3 -> V4:
1, Sync code with upstream;
2, Remove merged patches;
3, Fix build failure without CONFIG_KVM;
4, Add Reviewed-by: Aleksandar Markovic .

Huacai Chen(4):
 hw/mips: Implement the kvm_type() hook in MachineClass
 target/mips: Add Loongson-3 CPU definition
 hw/mips: Add Loongson-3 machine support (with KVM)
 MAINTAINERS: Add myself as Loongson-3 maintainer

Signed-off-by: Huacai Chen 
---
 MAINTAINERS  |   5 +
 default-configs/mips64el-softmmu.mak |   1 +
 hw/core/Makefile.objs|   2 +-
 hw/core/null-machine.c   |   4 +
 hw/mips/Kconfig  |  10 +
 hw/mips/Makefile.objs|   3 +-
 hw/mips/common.c |  42 ++
 hw/mips/loongson3.c  | 901 +++
 include/hw/mips/mips.h   |   3 +
 target/mips/cpu.h|  28 ++
 target/mips/internal.h   |   2 +
 target/mips/mips-defs.h  |   7 +-
 target/mips/translate.c  |   2 +
 target/mips/translate_init.inc.c |  86 
 14 files changed, 1092 insertions(+), 4 deletions(-)
 create mode 100644 hw/mips/common.c
 create mode 100644 hw/mips/loongson3.c
--
2.7.0



Re: [PATCH 1/1] e1000e: Added ICR clearing by corresponding IMS bit.

2020-06-01 Thread Jason Wang



On 2020/6/2 上午12:47, Andrew Melnichenko wrote:
As I understand it, the e1000e.c was implemented by 82574L 
spec(https://www.intel.com/content/dam/doc/datasheet/82574l-gbe-controller-datasheet.pdf).
In the same spec there is 10.2.4 paragraph which provides more details 
when ICR should be cleared.


• Case 1 - Interrupt Mask register equals 0x (mask all): ICR
content is cleared.
• Case 2 - Interrupt was asserted (ICR.INT_ASSERT=1) and auto mask
is active: ICR
content is cleared, and the IAM register is written to the IMC
register.
• Case 3 - Interrupt was not asserted (ICR.INT_ASSERT=0): Read has
no side affect.



Thanks for the pointer, so it looks to me the current implementation is 
fine ?


static uint32_t
e1000e_mac_icr_read(E1000ECore *core, int index)
{
    uint32_t ret = core->mac[ICR];
    trace_e1000e_irq_icr_read_entry(ret);

    if (core->mac[IMS] == 0) {
    trace_e1000e_irq_icr_clear_zero_ims();
    core->mac[ICR] = 0;
    }


// This is the case 1)


    if ((core->mac[ICR] & E1000_ICR_ASSERTED) &&
    (core->mac[CTRL_EXT] & E1000_CTRL_EXT_IAME)) {
    trace_e1000e_irq_icr_clear_iame();
    core->mac[ICR] = 0;
    trace_e1000e_irq_icr_process_iame();
    e1000e_clear_ims_bits(core, core->mac[IAM]);
    }


// This is the case 2) and case 3)

    trace_e1000e_irq_icr_read_exit(core->mac[ICR]);
    e1000e_update_interrupt_state(core);
    return ret;
}


Thanks




On Fri, May 29, 2020 at 10:35 AM Jason Wang > wrote:



On 2020/5/29 下午3:18, Jason Wang wrote:
>
> On 2020/5/13 下午7:31, and...@daynix.com
 wrote:
>> From: Andrew Melnychenko mailto:and...@daynix.com>>
>>
>> Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1707441
>> Added ICR clearing if there is IMS bit - according to the note by
>> section 13.3.27 of the 8257X developers manual.
>>
>> Signed-off-by: Andrew Melnychenko mailto:and...@daynix.com>>
>> ---
>>   hw/net/e1000e_core.c | 10 ++
>>   hw/net/trace-events  |  1 +
>>   2 files changed, 11 insertions(+)
>>
>> diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c
>> index d5676871fa..10212d7932 100644
>> --- a/hw/net/e1000e_core.c
>> +++ b/hw/net/e1000e_core.c
>> @@ -2624,6 +2624,16 @@ e1000e_mac_icr_read(E1000ECore *core,
int index)
>>   e1000e_clear_ims_bits(core, core->mac[IAM]);
>>   }
>>   +    /*
>> + * PCIe* GbE Controllers Open Source Software Developer's
Manual
>> + * 13.3.27 Interrupt Cause Read Register
>> + */
>> +    if ((core->mac[ICR] & E1000_ICR_ASSERTED) &&
>> +    (core->mac[ICR] & core->mac[IMS])) {
>> + trace_e1000e_irq_icr_clear_icr_bit_ims(core->mac[ICR],
>> core->mac[IMS]);
>> +    core->mac[ICR] = 0;
>> +    }
>> +
>
>
> Hi Andrew:
>
> So my comments still. I think we need to implement 82574l
behavior (if
> you go through e1000e.c all chapters it mentioned is for 82574l
> datasheet not the one you pointed to me).
>
> And actually the 82574l behavior is much more simpler.


To be more specific.

See chapter 7.4.5 which describes the ICR clearing.

It has three methods for clearing: auto-clear, clear-on-write and
clear-on-read.

And in the part of "Read to clear" it said:

"""
All bits in the ICR register are cleared on a read to ICR.

"""

So there's no need to IMS and other stuffs here.

Thanks


>
> Thanks






Re: [RFC v2 10/18] guest memory protection: Add guest memory protection interface

2020-06-01 Thread Richard Henderson
On 5/20/20 8:42 PM, David Gibson wrote:
> @@ -0,0 +1,29 @@
> +#/*

Two extraneous # at the beginning of the new files.


r~



RE: [PATCH 1/5] block/quorum.c: stable children names

2020-06-01 Thread Zhang, Chen



> -Original Message-
> From: Lukas Straub 
> Sent: Monday, May 11, 2020 8:27 PM
> To: qemu-devel 
> Cc: Alberto Garcia ; Dr. David Alan Gilbert
> ; Zhang, Chen 
> Subject: [PATCH 1/5] block/quorum.c: stable children names
> 
> If we remove the child with the highest index from the quorum, decrement
> s->next_child_index. This way we get stable children names as long as we
> only remove the last child.
> 

Looks good for me, and it can solve this bug:
colo: Can not recover colo after svm failover twice
https://bugs.launchpad.net/bugs/1881231

Reviewed-by: Zhang Chen 

> Signed-off-by: Lukas Straub 
> ---
>  block/quorum.c | 20 ++--
>  1 file changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/block/quorum.c b/block/quorum.c index 6d7a56bd93..acfa09c2cc
> 100644
> --- a/block/quorum.c
> +++ b/block/quorum.c
> @@ -29,6 +29,8 @@
> 
>  #define HASH_LENGTH 32
> 
> +#define INDEXSTR_LEN 32
> +
>  #define QUORUM_OPT_VOTE_THRESHOLD "vote-threshold"
>  #define QUORUM_OPT_BLKVERIFY  "blkverify"
>  #define QUORUM_OPT_REWRITE"rewrite-corrupted"
> @@ -972,9 +974,9 @@ static int quorum_open(BlockDriverState *bs, QDict
> *options, int flags,
>  opened = g_new0(bool, s->num_children);
> 
>  for (i = 0; i < s->num_children; i++) {
> -char indexstr[32];
> -ret = snprintf(indexstr, 32, "children.%d", i);
> -assert(ret < 32);
> +char indexstr[INDEXSTR_LEN];
> +ret = snprintf(indexstr, INDEXSTR_LEN, "children.%d", i);
> +assert(ret < INDEXSTR_LEN);
> 
>  s->children[i] = bdrv_open_child(NULL, options, indexstr, bs,
>   &child_format, false, &local_err); 
> @@ -1026,7 +1028,7
> @@ static void quorum_add_child(BlockDriverState *bs, BlockDriverState
> *child_bs,  {
>  BDRVQuorumState *s = bs->opaque;
>  BdrvChild *child;
> -char indexstr[32];
> +char indexstr[INDEXSTR_LEN];
>  int ret;
> 
>  if (s->is_blkverify) {
> @@ -1041,8 +1043,8 @@ static void quorum_add_child(BlockDriverState *bs,
> BlockDriverState *child_bs,
>  return;
>  }
> 
> -ret = snprintf(indexstr, 32, "children.%u", s->next_child_index);
> -if (ret < 0 || ret >= 32) {
> +ret = snprintf(indexstr, INDEXSTR_LEN, "children.%u", s-
> >next_child_index);
> +if (ret < 0 || ret >= INDEXSTR_LEN) {
>  error_setg(errp, "cannot generate child name");
>  return;
>  }
> @@ -1069,6 +1071,7 @@ static void quorum_del_child(BlockDriverState *bs,
> BdrvChild *child,
>   Error **errp)  {
>  BDRVQuorumState *s = bs->opaque;
> +char indexstr[INDEXSTR_LEN];
>  int i;
> 
>  for (i = 0; i < s->num_children; i++) { @@ -1090,6 +1093,11 @@ static 
> void
> quorum_del_child(BlockDriverState *bs, BdrvChild *child,
>  /* We know now that num_children > threshold, so blkverify must be
> false */
>  assert(!s->is_blkverify);
> 
> +snprintf(indexstr, INDEXSTR_LEN, "children.%u", s->next_child_index - 1);
> +if (!strncmp(child->name, indexstr, INDEXSTR_LEN)) {
> +s->next_child_index--;
> +}
> +
>  bdrv_drained_begin(bs);
> 
>  /* We can safely remove this child now */
> --
> 2.20.1




RE: [PATCH] block/quorum.c: Decrease child index when del_child

2020-06-01 Thread Zhang, Chen
Oh, I missed the patch detail. I just reviewed overall view on your series.
Looks your patch is good for me.

Thanks
Zhang Chen

> -Original Message-
> From: Lukas Straub 
> Sent: Tuesday, June 2, 2020 2:12 AM
> To: Alberto Garcia 
> Cc: Zhang, Chen ; Kevin Wolf ;
> Max Reitz ; qemu-dev ;
> Jason Wang ; Zhanghailiang
> ; Dr . David Alan Gilbert
> ; Zhang Chen 
> Subject: Re: [PATCH] block/quorum.c: Decrease child index when del_child
> 
> On Mon, 01 Jun 2020 12:38:32 +0200
> Alberto Garcia  wrote:
> > As I explained a few weeks ago this patch is not correct.
> > quorum_del_child() allows you to remove any child from the Quorum
> > device, so nothing guarantees that next_child_index-1 is free.
> >
> > https://lists.gnu.org/archive/html/qemu-block/2020-05/msg00634.html
> >
> > Berto
> >
> 
> Hi,
> Did you have a look at my series? There it's fixed properly:
> https://lore.kernel.org/qemu-
> devel/9df6b3723ec30cb749ceaa555d82a29a6d79496d.1589199922.git.lukasstr
> a...@web.de/
> 
> Regards,
> Lukas Straub



Re: [PATCH v1 3/3] tests/tcg: add simple commpage test case

2020-06-01 Thread Richard Henderson
On 5/27/20 3:05 AM, Alex Bennée wrote:
> The COMMPAGE are a number of kernel provided user-space routines for
> 32 bit ARM systems. Add a basic series of smoke tests to ensure it is
> working as it should.
> 
> Signed-off-by: Alex Bennée 
> ---
>  tests/tcg/arm/commpage.c  | 61 +++
>  tests/tcg/arm/Makefile.target |  2 ++
>  2 files changed, 63 insertions(+)
>  create mode 100644 tests/tcg/arm/commpage.c

Reviewed-by: Richard Henderson 


r~



Re: [PATCH v1 1/3] linux-user: provide fallback pgd_find_hole for bare chroots

2020-06-01 Thread Richard Henderson
On 5/27/20 3:05 AM, Alex Bennée wrote:
> +static uintptr_t pgd_find_hole_fallback(uintptr_t guest_size, uintptr_t brk, 
> long align)
> +{
> +uintptr_t base;
> +
> +/* Start at the bottom and work our way up */
> +base = mmap_min_addr;
> +
> +while (true) {
> +uintptr_t align_start, end;
> +align_start = ROUND_UP(base, align);
> +end = align_start + guest_size;
> +
> +/* if brk is anywhere in the range give ourselves some room to grow. 
> */
> +if (align_start <= brk && brk < end) {
> +base += 16 * MiB;

You should skip the entire brk region with base = brk + 16 * MiB.

> +base += qemu_host_page_size;

If align < qemu_host_page_size, then we'll try the same page multiple times.
Better as base = align_start + qemu_host_page_size.

Or even base = ROUND_UP(base, align) right at the beginning.


r~



Re: [PATCH v1 2/3] linux-user: deal with address wrap for ARM_COMMPAGE on 32 bit

2020-06-01 Thread Richard Henderson
On 5/27/20 3:05 AM, Alex Bennée wrote:
> @@ -2145,7 +2145,7 @@ static uintptr_t pgd_find_hole_fallback(uintptr_t 
> guest_size, uintptr_t brk, lon
>  
>  /* Return value for guest_base, or -1 if no hole found. */
>  static uintptr_t pgb_find_hole(uintptr_t guest_loaddr, uintptr_t guest_size,
> -   long align)
> +   long align, uintptr_t offset)
>  {
>  GSList *maps, *iter;
>  uintptr_t this_start, this_end, next_start, brk;
> @@ -2171,7 +2171,7 @@ static uintptr_t pgb_find_hole(uintptr_t guest_loaddr, 
> uintptr_t guest_size,
>  
>  this_end = ((MapInfo *)iter->data)->start;
>  next_start = ((MapInfo *)iter->data)->end;
> -align_start = ROUND_UP(this_start, align);
> +align_start = ROUND_UP(this_start + offset, align);
>  
>  /* Skip holes that are too small. */

I suppose offset is supposed to mean we start from -offset?  You didn't update
pgb_find_hole_fallback.

> -loaddr = ARM_COMMPAGE & -align;
> +offset = (128 * KiB);

Why 128K?  Surely this should be an expression against ARM_COMMPAGE.


r~



Re: [PATCH v2 3/3] exec/cpu-common: Move MUSB specific typedefs to 'hw/usb/hcd-musb.h'

2020-06-01 Thread Richard Henderson
On 6/1/20 7:15 AM, Philippe Mathieu-Daudé wrote:
> The CPUReadMemoryFunc/CPUWriteMemoryFunc typedefs are legacy
> remnant from before the conversion to MemoryRegions.
> Since they are now only used in tusb6010.c and hcd-musb.c,
> move them to "hw/usb/musb.h" and rename them appropriately.
> 
> Suggested-by: Peter Maydell 
> Reviewed-by: Peter Maydell 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  include/exec/cpu-common.h | 3 ---
>  include/hw/usb/hcd-musb.h | 9 +
>  hw/usb/hcd-musb.c | 4 ++--
>  3 files changed, 7 insertions(+), 9 deletions(-)

Reviewed-by: Richard Henderson 


r~





Re: [PATCH v2 2/3] hw/usb: Move device-specific declarations to new 'hcd-musb.h' header

2020-06-01 Thread Richard Henderson
On 6/1/20 7:15 AM, Philippe Mathieu-Daudé wrote:
> Move the declarations for the MUSB-HDRC USB2.0 OTG compliant core
> into a separate header.
> 
> Reviewed-by: Peter Maydell 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  include/hw/usb.h  | 30 -
>  include/hw/usb/hcd-musb.h | 46 +++
>  hw/usb/hcd-musb.c |  1 +
>  hw/usb/tusb6010.c |  1 +
>  4 files changed, 48 insertions(+), 30 deletions(-)
>  create mode 100644 include/hw/usb/hcd-musb.h

Reviewed-by: Richard Henderson 


r~





Re: [PATCH v2 1/3] exec/memory: Remove unused MemoryRegionMmio type

2020-06-01 Thread Richard Henderson
On 6/1/20 7:15 AM, Philippe Mathieu-Daudé wrote:
> Since commit 62a0db942dec ('memory: Remove old_mmio accessors')
> this structure is unused. Remove it.
> 
> Suggested-by: Peter Maydell 
> Reviewed-by: Peter Maydell 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  include/exec/memory.h | 6 --
>  1 file changed, 6 deletions(-)

Reviewed-by: Richard Henderson 


r~





Re: [PATCH 5/6] exec: Restrict 32-bit CPUs to 32-bit address space

2020-06-01 Thread Richard Henderson
On 6/1/20 1:09 AM, Philippe Mathieu-Daudé wrote:
> On 5/31/20 9:09 PM, Peter Maydell wrote:
>> On Sun, 31 May 2020 at 18:54, Philippe Mathieu-Daudé  wrote:
>>>
>>> It is pointless to have 32-bit CPUs see a 64-bit address
>>> space, when they can only address the 32 lower bits.
>>>
>>> Only create CPU address space with a size it can address.
>>> This makes HMP 'info mtree' command easier to understand
>>> (on 32-bit CPUs).
>>
>>> diff --git a/exec.c b/exec.c
>>> index 5162f0d12f..d6809a9447 100644
>>> --- a/exec.c
>>> +++ b/exec.c
>>> @@ -2962,9 +2962,17 @@ static void tcg_commit(MemoryListener *listener)
>>>
>>>  static void memory_map_init(void)
>>>  {
>>> +uint64_t system_memory_size;
>>> +
>>> +#if TARGET_LONG_BITS >= 64
>>> +system_memory_size = UINT64_MAX;
>>> +#else
>>> +system_memory_size = 1ULL << TARGET_LONG_BITS;
>>> +#endif
>>
>> TARGET_LONG_BITS is a description of the CPU's virtual
>> address size; but the size of the system_memory memory
>> region is related to the CPU's physical address size[*].
> 
> OK I misunderstood it was the physical size, not virtual.

It is the physical size.

In the armv7 case, the lpae page table entry maps a 32-bit virtual address to a
40-bit physical address.  The i686 page table extensions do something similar.

See TARGET_PHYS_ADDR_SPACE_BITS.


r~



Re: [PATCH v2 8/8] target/i386/cpu: Use the IEC binary prefix definitions

2020-06-01 Thread Richard Henderson
On 6/1/20 7:29 AM, Philippe Mathieu-Daudé wrote:
> IEC binary prefixes ease code review: the unit is explicit.
> 
> Reviewed-by: Peter Maydell 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  target/i386/cpu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Richard Henderson 


r~




Re: [PATCH v2 7/8] hw/i386/xen/xen-hvm: Use the IEC binary prefix definitions

2020-06-01 Thread Richard Henderson
On 6/1/20 7:29 AM, Philippe Mathieu-Daudé wrote:
> IEC binary prefixes ease code review: the unit is explicit.
> 
> Reviewed-by: Peter Maydell 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/i386/xen/xen-hvm.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Reviewed-by: Richard Henderson 


r~




Re: [PATCH v2 6/8] hw/hppa/dino: Use the IEC binary prefix definitions

2020-06-01 Thread Richard Henderson
On 6/1/20 7:29 AM, Philippe Mathieu-Daudé wrote:
> IEC binary prefixes ease code review: the unit is explicit.
> 
> Reviewed-by: Peter Maydell 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/hppa/dino.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson 


r~




Re: [PATCH v2 5/8] hw/pci-host: Use the IEC binary prefix definitions

2020-06-01 Thread Richard Henderson
On 6/1/20 7:29 AM, Philippe Mathieu-Daudé wrote:
> IEC binary prefixes ease code review: the unit is explicit.
> 
> Reviewed-by: Peter Maydell 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/pci-host/i440fx.c| 3 ++-
>  hw/pci-host/q35.c   | 2 +-
>  hw/pci-host/versatile.c | 5 +++--
>  3 files changed, 6 insertions(+), 4 deletions(-)

Reviewed-by: Richard Henderson 


r~




Re: [PATCH v2 4/8] hw/pci/pci_bridge: Use the IEC binary prefix definitions

2020-06-01 Thread Richard Henderson
On 6/1/20 7:29 AM, Philippe Mathieu-Daudé wrote:
> IEC binary prefixes ease code review: the unit is explicit.
> 
> Reviewed-by: Peter Maydell 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/pci/pci_bridge.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson 


r~




Re: [PATCH v2 3/8] hw/pci/pci_bridge: Correct pci_bridge_io memory region size

2020-06-01 Thread Richard Henderson
On 6/1/20 7:29 AM, Philippe Mathieu-Daudé wrote:
> memory_region_set_size() handle the 16 Exabytes limit by
> special-casing the UINT64_MAX value. This is not a problem
> for the 32-bit maximum, 4 GiB.
> By using the UINT32_MAX value, the pci_bridge_io MemoryRegion
> ends up missing 1 byte:
> 
>   (qemu) info mtree
>   memory-region: pci_bridge_io
> -fffe (prio 0, i/o): pci_bridge_io
>   0060-0060 (prio 0, i/o): i8042-data
>   0064-0064 (prio 0, i/o): i8042-cmd
>   01ce-01d1 (prio 0, i/o): vbe
>   0378-037f (prio 0, i/o): parallel
>   03b4-03b5 (prio 0, i/o): vga
>   ...
> 
> Fix by using the correct value. We now have:
> 
>   memory-region: pci_bridge_io
> - (prio 0, i/o): pci_bridge_io
>   0060-0060 (prio 0, i/o): i8042-data
>   0064-0064 (prio 0, i/o): i8042-cmd
>   ...
> 
> Reviewed-by: Peter Maydell 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/pci/pci_bridge.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Reviewed-by: Richard Henderson 


r~




Re: [PATCH v2 2/8] hw/pci-host/prep: Correct RAVEN bus bridge memory region size

2020-06-01 Thread Richard Henderson
On 6/1/20 7:29 AM, Philippe Mathieu-Daudé wrote:
> memory_region_set_size() handle the 16 Exabytes limit by
> special-casing the UINT64_MAX value. This is not a problem
> for the 32-bit maximum, 4 GiB.
> By using the UINT32_MAX value, the bm-raven MemoryRegion
> ends up missing 1 byte:
> 
>   $ qemu-system-ppc -M prep -S -monitor stdio -usb
>   memory-region: bm-raven
> -fffe (prio 0, i/o): bm-raven
>   -3eff (prio 0, i/o): alias bm-pci-memory 
> @pci-memory -3eff
>   8000- (prio 0, i/o): alias bm-system 
> @system -7fff
> 
> Fix by using the correct value. We now have:
> 
>   memory-region: bm-raven
> - (prio 0, i/o): bm-raven
>   -3eff (prio 0, i/o): alias bm-pci-memory 
> @pci-memory -3eff
>   8000- (prio 0, i/o): alias bm-system 
> @system -7fff
> 
> Reviewed-by: Peter Maydell 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/pci-host/prep.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Richard Henderson 


r~




Re: [PATCH v2 1/8] hw/arm/aspeed: Correct DRAM container region size

2020-06-01 Thread Richard Henderson
On 6/1/20 7:29 AM, Philippe Mathieu-Daudé wrote:
> memory_region_set_size() handle the 16 Exabytes limit by
> special-casing the UINT64_MAX value. This is not a problem
> for the 32-bit maximum, 4 GiB.
> By using the UINT32_MAX value, the aspeed-ram-container
> MemoryRegion ends up missing 1 byte:
> 
>  $ qemu-system-arm -M ast2600-evb -S -monitor stdio
>  (qemu) info mtree
> 
>   address-space: aspeed.fmc-ast2600-dma-dram
> 8000-00017ffe (prio 0, i/o): aspeed-ram-container
>   8000-bfff (prio 0, ram): ram
>   c000- (prio 0, i/o): max_ram
> 
> Fix by using the correct value. We now have:
> 
>   address-space: aspeed.fmc-ast2600-dma-dram
> 8000-00017fff (prio 0, i/o): aspeed-ram-container
>   8000-bfff (prio 0, ram): ram
>   c000- (prio 0, i/o): max_ram
> 
> Reviewed-by: Peter Maydell 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/arm/aspeed.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Richard Henderson 


r~




Re: [PATCH v2 9/9] target/arm: Convert Neon one-register-and-immediate insns to decodetree

2020-06-01 Thread Richard Henderson
On 5/22/20 7:55 AM, Peter Maydell wrote:
> Convert the insns in the one-register-and-immediate group to decodetree.
> 
> In the new decode, our asimd_imm_const() function returns a 64-bit value
> rather than a 32-bit one, which means we don't need to treat cmode=14 op=1
> as a special case in the decoder (it is the only encoding where the two
> halves of the 64-bit value are different).
> 
> Signed-off-by: Peter Maydell 
> ---
>  target/arm/neon-dp.decode   |  22 ++
>  target/arm/translate-neon.inc.c | 118 
>  target/arm/translate.c  | 101 +--
>  3 files changed, 142 insertions(+), 99 deletions(-)


Reviewed-by: Richard Henderson 

because this is a faithful transliteration of the existing code, but...

> +switch (cmode) {
> +case 0: case 1:
> +/* no-op */
> +break;
> +case 2: case 3:
> +imm <<= 8;
> +break;
> +case 4: case 5:
> +imm <<= 16;
> +break;
> +case 6: case 7:
> +imm <<= 24;
> +break;
> +case 8: case 9:
> +imm |= imm << 16;
> +break;
> +case 10: case 11:
> +imm = (imm << 8) | (imm << 24);
> +break;

It might be clearer to use dup_const for each case, which would more closely
match the pseudocode.  E.g. here,

return dup_const(MO_16, imm << 8);

> +imm |= (imm << 8) | (imm << 16) | (imm << 24);

return dup_const(MO_8, imm);

Something to remember for a follow-up.

r~



Re: [PATCH v2 5/9] target/arm: Convert Neon narrowing shifts with op==8 to decodetree

2020-06-01 Thread Richard Henderson
On 5/22/20 7:55 AM, Peter Maydell wrote:
> Convert the Neon narrowing shifts where op==8 to decodetree:
>  * VSHRN
>  * VRSHRN
>  * VQSHRUN
>  * VQRSHRUN
> 
> Signed-off-by: Peter Maydell 
> ---
>  target/arm/neon-dp.decode   |  27 +
>  target/arm/translate-neon.inc.c | 168 
>  target/arm/translate.c  |   1 +
>  3 files changed, 196 insertions(+)

Reviewed-by: Richard Henderson 


r~




Re: [PATCH v2 4/9] target/arm: Convert VQSHLU, VQSHL 2-reg-shift insns to decodetree

2020-06-01 Thread Richard Henderson
On 5/22/20 7:55 AM, Peter Maydell wrote:
> Convert the VQSHLU and QVSHL 2-reg-shift insns to decodetree.
> These are the last of the simple shift-by-immediate insns.
> 
> Signed-off-by: Peter Maydell 
> ---
>  target/arm/neon-dp.decode   |  15 +
>  target/arm/translate-neon.inc.c | 108 +++
>  target/arm/translate.c  | 110 +---
>  3 files changed, 126 insertions(+), 107 deletions(-)

Reviewed-by: Richard Henderson 


r~




Re: [PATCH v2 1/9] target/arm: Convert Neon VSHL and VSLI 2-reg-shift insn to decodetree

2020-06-01 Thread Richard Henderson
On 5/22/20 7:55 AM, Peter Maydell wrote:
> Convert the VSHL and VSLI insns from the Neon 2-registers-and-a-shift
> group to decodetree.
> 
> Signed-off-by: Peter Maydell 
> ---
>  target/arm/neon-dp.decode   | 25 ++
>  target/arm/translate-neon.inc.c | 38 +
>  target/arm/translate.c  | 18 +++-
>  3 files changed, 71 insertions(+), 10 deletions(-)

Reviewed-by: Richard Henderson 


r~




Re: [PATCH v4 13/13] stubs: Restrict ui/win32-kbd-hook to system-mode

2020-06-01 Thread Richard Henderson
On 5/22/20 10:25 AM, Philippe Mathieu-Daudé wrote:
> In Makefile.objs, the ui/ directory is restricted to system-mode:
> 
>  43 ifeq ($(CONFIG_SOFTMMU),y)
>  ...
>  65 common-obj-y += ui/
>  66 common-obj-m += ui/
>  ...
>  82 endif # CONFIG_SOFTMMU
> 
> Restrict the ui/ stub added in commit 2df9f5718df to only build
> it for system-mode emulation.
> 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---

Reviewed-by: Richard Henderson 


r~




Re: [PATCH v2 1/1] target/rx: Check for page crossings in use_goto_tb()

2020-06-01 Thread Richard Henderson
On 5/31/20 6:45 AM, Ahmed Karaman wrote:
> Add the page crossings check in use_goto_tb(). If this check is not
> applied, a number of bugs may occasionally occur during target rx
> system mode emulation.
> Also, this check is needed in user mode related to emulation of system
> call mmap(). rx target does not currently support user mode, but it is
> better to prepare use_goto_tb() in that sense in advance.
> 
> Rename parameter dc of type DisasContext* to the more common name ctx,
> to keep consistency with other targets.
> 
> Add detailed comments.
> 
> Buglink: https://bugs.launchpad.net/qemu/+bug/1880763
> Signed-off-by: Ahmed Karaman 
> ---
>  target/rx/translate.c | 9 ++---
>  1 file changed, 6 insertions(+), 3 deletions(-)

Reviewed-by: Richard Henderson 

Although I note that this failure is not currently visible because RX does not
have an MMU.  So there are no page permissions to change or fail.


r~




Re: [PATCH] target/m68k: implement opcode fetoxm1

2020-06-01 Thread Richard Henderson
On 5/31/20 6:19 AM, Laurent Vivier wrote:
> Example provided in the launchpad bug fails with:
> 
>qemu: uncaught target signal 4 (Illegal instruction) - core dumped
>Illegal instruction (core dumped)
> 
> It appears fetoxm1 is not implemented:
> 
>IN: expm1f
>0x85cc: fetoxm1x %fp2,%fp0
>Disassembler disagrees with translator over instruction decoding
>Please report this to qemu-devel@nongnu.org
> 
>(gdb) x/2hx 0x85cc
>0x85cc: 0xf200 0x0808
> 
> This patch adds the instruction.
> 
> Bug: https://bugs.launchpad.net/qemu/+bug/1881450
> Signed-off-by: Laurent Vivier 
> ---
>  target/m68k/helper.h | 1 +
>  target/m68k/fpu_helper.c | 5 +
>  target/m68k/translate.c  | 3 +++
>  3 files changed, 9 insertions(+)

Reviewed-by: Richard Henderson 


r~



Re: [PATCH] target/m68k: implement fmove.l #,FPCR

2020-06-01 Thread Richard Henderson
On 5/31/20 4:02 AM, Laurent Vivier wrote:
> The immediate value mode was ignored and instruction execution
> ends to an invalid access mode.
> 
> This was found running 'R' that set FPSR to 0 at startup with
> a 'fmove.l #0,FPSR' in qemu-system-m68k emulation and triggers a
> kernel crash:
> 
> [   56.64] *** ADDRESS ERROR ***   FORMAT=2
> [   56.64] Current process id is 728
> [   56.64] BAD KERNEL TRAP: 
> [   56.64] Modules linked in: sg evdev mac_hid ip_tables x_tables 
> sha1_generic hmac ipv6 nf_defrag_ipv6 autofs4 ext4 crc16 mbcache jbd2 
> crc32c_generic sd_mod t10_pi crc_t10dif crct10dif_generic crct10dif_common 
> sr_mod cdrom mac_esp macsonic esp_scsi
> [   56.64] PC: [<00016a2c>] X_UNSUPP+0x2c/0x3c
> [   56.64] SR: 2004  SP: 3eb5e68c  a2: c02e239a
> [   56.64] d0: 0040d1: 0002d2: 8002adecd3: 8002ad50
> [   56.64] d4: 8002c768d5: 000da0: ffc2a1: ffc1
> [   56.64] Process R (pid: 728, task=a3dfda5d)
> [   56.64] Frame format=2 instr addr=
> [   56.65] Stack from 3a4d9f30:
> [   56.65] 4100 0002 0002 ffc2 ffc1 1fff 
> 8000 
> [   56.65] 3fbf 8000   2000  
> 7fff 
> [   56.65]   00050008  867c c02c2000 
> efffee20 02d8
> [   56.65] 2a28 3a4d9f98 0002 0014 fffe 8002c768 
> 0002 0041
> [   56.65] 0002 c041fc58 c0743758   0008c075 
> 2b24 0012
> [   56.65] 07d0 0024 0002 c05bef04 c05bef04 005e 
> 0077 c28aca70
> [   56.65] Call Trace: [<00050008>] copy_overflow+0x10/0x28
> [   56.65]  [<2a28>] buserr+0x20/0x28
> [   56.65]  [<0008c075>] bpf_check+0x57f/0x1cfa
> [   56.65]  [<2b24>] syscall+0x8/0xc
> [   56.65]  [] dn_sched_init+0x75/0x88
> [   56.65] Code: 1017 0200 00f0 0c00 0040 66ff  05ac  8800  
>  f23c 9000   222e ff84 082e 0005 ff1c 6600 000a 0281
> [   56.65] Disabling lock debugging due to kernel taint
> ...
> 
> Reported-by: John Paul Adrian Glaubitz 
> Signed-off-by: Laurent Vivier 
> ---
>  target/m68k/translate.c | 14 ++
>  1 file changed, 14 insertions(+)

Reviewed-by: Richard Henderson 

r~



Re: [PATCH v3 0/6] iotests: Dump QCOW2 dirty bitmaps metadata

2020-06-01 Thread Eric Blake

On 6/1/20 8:48 AM, Andrey Shinkevich wrote:

Add dirty bitmap information to QCOW2 metadata dump in qcow2.py script.

v3:
   01: JSON format output possibility added.


Also, you split it into a series.  Thanks; this makes it easier to 
review each step :)




v2:
   01: Refactoring of the Python code in the script qcow2.py.
   New methods were added. The bitmap dictionary was instantiated.
   The all of bitmaps information is read completely before
   printing the dictionary.
   02: The outputs of the tests 031, 036 and 061 were modified.

Andrey Shinkevich (6):
   iotests: Add extension names to qcow2.py dump
   iotests: move check for printable data to QcowHeaderExtension class
   iotests: dump bitmap extension data with qcow2.py
   iotests: Dump bitmap directory info with qcow2.py
   iotests: Dump bitmap table entries serialized in QCOW2 image
   iotests: Dump QCOW2 image metadata in JSON format with qcow2.py

  tests/qemu-iotests/031.out  |  22 +--
  tests/qemu-iotests/036.out  |   4 +-
  tests/qemu-iotests/061.out  |  18 +--
  tests/qemu-iotests/qcow2.py | 338 ++--
  4 files changed, 346 insertions(+), 36 deletions(-)



--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH] MAINTAINERS: Volunteer for maintaining the Renesas hardware

2020-06-01 Thread Aurelien Jarno
On 2020-06-01 11:20, Philippe Mathieu-Daudé wrote:
> I don't have much clue about the Renesas hardware, but at least
> I know now the source files a little bit, so I volunteer to pick
> up patches and send pull-requests for them during my scarce
> hobbyist time, until someone else with more knowledge steps up
> to do this job instead.
> 
> Suggested-by: Alex Bennée 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  MAINTAINERS | 15 +--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 0944d9c731..cbba3ac757 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -298,9 +298,7 @@ SH4 TCG CPUs
>  M: Aurelien Jarno 
>  S: Odd Fixes
>  F: target/sh4/
> -F: hw/sh4/
>  F: disas/sh4.c
> -F: include/hw/sh4/
>  
>  SPARC TCG CPUs
>  M: Mark Cave-Ayland 
> @@ -1238,6 +1236,18 @@ F: pc-bios/canyonlands.dt[sb]
>  F: pc-bios/u-boot-sam460ex-20100605.bin
>  F: roms/u-boot-sam460ex
>  
> +Renesas Hardware
> +
> +SH4 Hardware
> +M: Aurelien Jarno 
> +M: Philippe Mathieu-Daudé 

That's fine for me, and just to be clear I don't mind being demoted to a
reviewer or even removed from there. I do not really have time to work
on that.

> +S: Odd Fixes
> +F: hw/sh4/
> +F: hw/char/sh_serial.c
> +F: hw/intc/sh_intc.c
> +F: hw/timer/sh_timer.c
> +F: include/hw/sh4/
> +
>  SH4 Machines
>  
>  R2D
> @@ -1246,6 +1256,7 @@ S: Maintained
>  F: hw/sh4/r2d.c
>  F: hw/intc/sh_intc.c
>  F: hw/timer/sh_timer.c
> +F: include/hw/sh4/sh_intc.h
>  
>  Shix
>  M: Magnus Damm 

Acked-by: Aurelien Jarno 

-- 
Aurelien Jarno  GPG: 4096R/1DDD8C9B
aurel...@aurel32.net http://www.aurel32.net



Re: [PATCH] block/quorum.c: Decrease child index when del_child

2020-06-01 Thread Alberto Garcia
On Mon 01 Jun 2020 08:12:00 PM CEST, Lukas Straub wrote:
>> As I explained a few weeks ago this patch is not correct.
>> quorum_del_child() allows you to remove any child from the Quorum
>> device, so nothing guarantees that next_child_index-1 is free.
>> 
>> https://lists.gnu.org/archive/html/qemu-block/2020-05/msg00634.html
>> 
> Hi,
> Did you have a look at my series? There it's fixed properly:
> https://lore.kernel.org/qemu-devel/9df6b3723ec30cb749ceaa555d82a29a6d79496d.1589199922.git.lukasstra...@web.de/

Oh, I somehow overlooked that, thanks for the reminder!

Berto



Re: [PATCH v5 07/11] hw/char: Initial commit of Ibex UART

2020-06-01 Thread Alistair Francis
On Thu, May 28, 2020 at 3:23 PM Alistair Francis
 wrote:
>
> This is the initial commit of the Ibex UART device. Serial TX is
> working, while RX has been implemeneted but untested.
>
> This is based on the documentation from:
> https://docs.opentitan.org/hw/ip/uart/doc/
>
> Signed-off-by: Alistair Francis 

Ping! This is the last patch not reviewed.

Alistair

> ---
>  include/hw/char/ibex_uart.h | 110 
>  hw/char/ibex_uart.c | 492 
>  MAINTAINERS |   2 +
>  hw/char/Makefile.objs   |   1 +
>  hw/riscv/Kconfig|   4 +
>  5 files changed, 609 insertions(+)
>  create mode 100644 include/hw/char/ibex_uart.h
>  create mode 100644 hw/char/ibex_uart.c
>
> diff --git a/include/hw/char/ibex_uart.h b/include/hw/char/ibex_uart.h
> new file mode 100644
> index 00..2bec772615
> --- /dev/null
> +++ b/include/hw/char/ibex_uart.h
> @@ -0,0 +1,110 @@
> +/*
> + * QEMU lowRISC Ibex UART device
> + *
> + * Copyright (c) 2020 Western Digital
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a 
> copy
> + * of this software and associated documentation files (the "Software"), to 
> deal
> + * in the Software without restriction, including without limitation the 
> rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
> FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + */
> +
> +#ifndef HW_IBEX_UART_H
> +#define HW_IBEX_UART_H
> +
> +#include "hw/sysbus.h"
> +#include "chardev/char-fe.h"
> +#include "qemu/timer.h"
> +
> +#define IBEX_UART_INTR_STATE   0x00
> +#define INTR_STATE_TX_WATERMARK (1 << 0)
> +#define INTR_STATE_RX_WATERMARK (1 << 1)
> +#define INTR_STATE_TX_EMPTY (1 << 2)
> +#define INTR_STATE_RX_OVERFLOW  (1 << 3)
> +#define IBEX_UART_INTR_ENABLE  0x04
> +#define IBEX_UART_INTR_TEST0x08
> +
> +#define IBEX_UART_CTRL 0x0c
> +#define UART_CTRL_TX_ENABLE (1 << 0)
> +#define UART_CTRL_RX_ENABLE (1 << 1)
> +#define UART_CTRL_NF(1 << 2)
> +#define UART_CTRL_SLPBK (1 << 4)
> +#define UART_CTRL_LLPBK (1 << 5)
> +#define UART_CTRL_PARITY_EN (1 << 6)
> +#define UART_CTRL_PARITY_ODD(1 << 7)
> +#define UART_CTRL_RXBLVL(3 << 8)
> +#define UART_CTRL_NCO   (0x << 16)
> +
> +#define IBEX_UART_STATUS   0x10
> +#define UART_STATUS_TXFULL  (1 << 0)
> +#define UART_STATUS_RXFULL  (1 << 1)
> +#define UART_STATUS_TXEMPTY (1 << 2)
> +#define UART_STATUS_RXIDLE  (1 << 4)
> +#define UART_STATUS_RXEMPTY (1 << 5)
> +
> +#define IBEX_UART_RDATA0x14
> +#define IBEX_UART_WDATA0x18
> +
> +#define IBEX_UART_FIFO_CTRL0x1c
> +#define FIFO_CTRL_RXRST  (1 << 0)
> +#define FIFO_CTRL_TXRST  (1 << 1)
> +#define FIFO_CTRL_RXILVL (7 << 2)
> +#define FIFO_CTRL_RXILVL_SHIFT   (2)
> +#define FIFO_CTRL_TXILVL (3 << 5)
> +#define FIFO_CTRL_TXILVL_SHIFT   (5)
> +
> +#define IBEX_UART_FIFO_STATUS  0x20
> +#define IBEX_UART_OVRD 0x24
> +#define IBEX_UART_VAL  0x28
> +#define IBEX_UART_TIMEOUT_CTRL 0x2c
> +
> +#define IBEX_UART_TX_FIFO_SIZE 16
> +
> +#define TYPE_IBEX_UART "ibex-uart"
> +#define IBEX_UART(obj) \
> +OBJECT_CHECK(IbexUartState, (obj), TYPE_IBEX_UART)
> +
> +typedef struct {
> +/*  */
> +SysBusDevice parent_obj;
> +
> +/*  */
> +MemoryRegion mmio;
> +
> +uint8_t tx_fifo[IBEX_UART_TX_FIFO_SIZE];
> +uint32_t tx_level;
> +
> +QEMUTimer *fifo_trigger_handle;
> +uint64_t char_tx_time;
> +
> +uint32_t uart_intr_state;
> +uint32_t uart_intr_enable;
> +uint32_t uart_ctrl;
> +uint32_t uart_status;
> +uint32_t uart_rdata;
> +uint32_t uart_fifo_ctrl;
> +uint32_t uart_fifo_status;
> +uint32_t uart_ovrd;
> +uint32_t uart_val;
> +uint32_t uart_timeout_ctrl;
> +
> +CharBackend chr;
> +qemu_irq tx_watermark;
> +qemu_irq rx_watermark;
> +qemu_irq tx_empty;
> +qemu_irq rx_overflow;
> +} IbexUartState;
> +#endif /* HW_IBEX_UART_H */
> diff --git a/hw/char/ibex_uart.c b/hw/char/ibex_uart.c
> new file mode 100644
> index 00..c416325d73
> ---

Re: [PATCH v4 2/4] target/riscv: Remove the deprecated CPUs

2020-06-01 Thread Alistair Francis
On Sun, May 31, 2020 at 9:51 PM Bin Meng  wrote:
>
> On Fri, May 29, 2020 at 6:24 AM Alistair Francis
>  wrote:
> >
> > Signed-off-by: Alistair Francis 
> > Reviewed-by: Bin Meng 
> > ---
> >  docs/system/deprecated.rst  | 33 ++---
> >  target/riscv/cpu.h  |  7 ---
> >  target/riscv/cpu.c  | 28 
> >  tests/qtest/machine-none-test.c |  4 ++--
> >  4 files changed, 20 insertions(+), 52 deletions(-)
> >
> > diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
> > index 50927bad74..a6664bfca9 100644
> > --- a/docs/system/deprecated.rst
> > +++ b/docs/system/deprecated.rst
> > @@ -314,21 +314,6 @@ should be used instead of the 1.09.1 version.
> >  System emulator CPUS
> >  
> >
> > -RISC-V ISA CPUs (since 4.1)
> > -'''
> > -
> > -The RISC-V cpus with the ISA version in the CPU name have been depcreated. 
> > The
> > -four CPUs are: ``rv32gcsu-v1.9.1``, ``rv32gcsu-v1.10.0``, 
> > ``rv64gcsu-v1.9.1`` and
> > -``rv64gcsu-v1.10.0``. Instead the version can be specified via the CPU 
> > ``priv_spec``
> > -option when using the ``rv32`` or ``rv64`` CPUs.
> > -
> > -RISC-V ISA CPUs (since 4.1)
>
> Not sure if this is a typo. Should we say: RISC-V no MMU CPUs ? If
> not, since the subsection titles are the same, should we merge the
> following description to above?

Good point.

To be more clear I have changed this to:

RISC-V ISA Specific CPUs (removed in 5.1)
...
RISC-V no MMU CPUs (removed in 5.1)


>
> > -'''
> > -
> > -The RISC-V no MMU cpus have been depcreated. The two CPUs: 
> > ``rv32imacu-nommu`` and
> > -``rv64imacu-nommu`` should no longer be used. Instead the MMU status can 
> > be specified
> > -via the CPU ``mmu`` option when using the ``rv32`` or ``rv64`` CPUs.
> > -
> >  ``compat`` property of server class POWER CPUs (since 5.0)
> >  ''
> >
> > @@ -486,6 +471,24 @@ The ``hub_id`` parameter of ``hostfwd_add`` / 
> > ``hostfwd_remove`` (removed in 5.0
> >  The ``[hub_id name]`` parameter tuple of the 'hostfwd_add' and
> >  'hostfwd_remove' HMP commands has been replaced by ``netdev_id``.
> >
> > +System emulator CPUS
> > +
> > +
> > +RISC-V ISA CPUs (removed in 5.1)
> > +
> > +
> > +The RISC-V cpus with the ISA version in the CPU name have been removed. The
> > +four CPUs are: ``rv32gcsu-v1.9.1``, ``rv32gcsu-v1.10.0``, 
> > ``rv64gcsu-v1.9.1`` and
> > +``rv64gcsu-v1.10.0``. Instead the version can be specified via the CPU 
> > ``priv_spec``
> > +option when using the ``rv32`` or ``rv64`` CPUs.
> > +
> > +RISC-V ISA CPUs (removed in 5.1)
> > +
> > +
> > +The RISC-V no MMU cpus have been removed. The two CPUs: 
> > ``rv32imacu-nommu`` and
> > +``rv64imacu-nommu`` can no longer be used. Instead the MMU status can be 
> > specified
> > +via the CPU ``mmu`` option when using the ``rv32`` or ``rv64`` CPUs.
> > +
> >  System emulator machines
> >  
> >
> > diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> > index d0e7f5b9c5..76b98d7a33 100644
> > --- a/target/riscv/cpu.h
> > +++ b/target/riscv/cpu.h
> > @@ -40,13 +40,6 @@
> >  #define TYPE_RISCV_CPU_SIFIVE_E51   RISCV_CPU_TYPE_NAME("sifive-e51")
> >  #define TYPE_RISCV_CPU_SIFIVE_U34   RISCV_CPU_TYPE_NAME("sifive-u34")
> >  #define TYPE_RISCV_CPU_SIFIVE_U54   RISCV_CPU_TYPE_NAME("sifive-u54")
> > -/* Deprecated */
> > -#define TYPE_RISCV_CPU_RV32IMACU_NOMMU  
> > RISCV_CPU_TYPE_NAME("rv32imacu-nommu")
> > -#define TYPE_RISCV_CPU_RV32GCSU_V1_09_1 
> > RISCV_CPU_TYPE_NAME("rv32gcsu-v1.9.1")
> > -#define TYPE_RISCV_CPU_RV32GCSU_V1_10_0 
> > RISCV_CPU_TYPE_NAME("rv32gcsu-v1.10.0")
> > -#define TYPE_RISCV_CPU_RV64IMACU_NOMMU  
> > RISCV_CPU_TYPE_NAME("rv64imacu-nommu")
> > -#define TYPE_RISCV_CPU_RV64GCSU_V1_09_1 
> > RISCV_CPU_TYPE_NAME("rv64gcsu-v1.9.1")
> > -#define TYPE_RISCV_CPU_RV64GCSU_V1_10_0 
> > RISCV_CPU_TYPE_NAME("rv64gcsu-v1.10.0")
> >
> >  #define RV32 ((target_ulong)1 << (TARGET_LONG_BITS - 2))
> >  #define RV64 ((target_ulong)2 << (TARGET_LONG_BITS - 2))
> > diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> > index 059d71f2c7..112f2e3a2f 100644
> > --- a/target/riscv/cpu.c
> > +++ b/target/riscv/cpu.c
> > @@ -135,16 +135,6 @@ static void riscv_base32_cpu_init(Object *obj)
> >  set_misa(env, 0);
> >  }
> >
> > -static void rv32gcsu_priv1_09_1_cpu_init(Object *obj)
> > -{
> > -CPURISCVState *env = &RISCV_CPU(obj)->env;
> > -set_misa(env, RV32 | RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU);
> > -set_priv_version(env, PRIV_VERSION_1_09_1);
> > -set_resetvec(env, DEFAULT_RSTVEC);
> > -set_feature(env, RISCV_FEATURE_MMU);
> > -set_feature(env, RISCV_FEATURE_PMP);
> > -}
> > -
> >  static void rv32gcsu_priv1_10_0_cpu_init(Object *obj)
> >  {
> >  CPURISCVState *env = &RISC

[PATCH v9 9/9] tests/vm: Add workaround to consume console

2020-06-01 Thread Robert Foley
This adds support to basevm.py so that we always
drain the console chars.  This makes use of
support added in an earlier commit that allows
QEMUMachine to use the ConsoleSocket.

This is a workaround we found was needed since
there is a known issue where QEMU will hang waiting
for console characters to be consumed.

We also added the option of logging the console to a file.
LOG_CONSOLE=1 will now log the output to a file.

Signed-off-by: Robert Foley 
Reviewed-by: Peter Puhov 
Acked-by: Alex Bennée 
---
 tests/vm/Makefile.include |  4 
 tests/vm/basevm.py| 21 +++--
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/tests/vm/Makefile.include b/tests/vm/Makefile.include
index 39f918a430..f21948c46a 100644
--- a/tests/vm/Makefile.include
+++ b/tests/vm/Makefile.include
@@ -49,6 +49,7 @@ endif
@echo 'EXTRA_CONFIGURE_OPTS="..."'
@echo "J=[0..9]* - Override the -jN parameter 
for make commands"
@echo "DEBUG=1   - Enable verbose output on 
host and interactive debugging"
+   @echo "LOG_CONSOLE=1 - Log console to file in: 
~/.cache/qemu-vm "
@echo "V=1   - Enable verbose ouput on host 
and guest commands"
@echo "QEMU_LOCAL=1 - Use QEMU binary local to this 
build."
@echo "QEMU=/path/to/qemu- Change path to QEMU binary"
@@ -75,6 +76,7 @@ $(IMAGES_DIR)/%.img:  $(SRC_PATH)/tests/vm/% \
$(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \
$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
$(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
+   $(if $(LOG_CONSOLE),--log-console) \
--image "$@" \
--force \
--build-image $@, \
@@ -91,6 +93,7 @@ vm-build-%: $(IMAGES_DIR)/%.img
$(if $(V),--verbose) \
$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
$(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
+   $(if $(LOG_CONSOLE),--log-console) \
--image "$<" \
$(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \
--snapshot \
@@ -114,6 +117,7 @@ vm-boot-ssh-%: $(IMAGES_DIR)/%.img
$(if $(V)$(DEBUG), --debug) \
$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
$(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
+   $(if $(LOG_CONSOLE),--log-console) \
--image "$<" \
--interactive \
false, \
diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
index f716798b40..04d083409a 100644
--- a/tests/vm/basevm.py
+++ b/tests/vm/basevm.py
@@ -117,6 +117,11 @@ class BaseVM(object):
  "w").write(self._config['ssh_pub_key'])
 
 self.debug = args.debug
+self._console_log_path = None
+if args.log_console:
+self._console_log_path = \
+ os.path.join(os.path.expanduser("~/.cache/qemu-vm"),
+  "{}.install.log".format(self.name))
 self._stderr = sys.stderr
 self._devnull = open(os.devnull, "w")
 if self.debug:
@@ -271,7 +276,13 @@ class BaseVM(object):
 args += self._data_args + extra_args + self._config['extra_args']
 logging.debug("QEMU args: %s", " ".join(args))
 qemu_path = get_qemu_path(self.arch, self._build_path)
-guest = QEMUMachine(binary=qemu_path, args=args)
+
+# Since console_log_path is only set when the user provides the
+# log_console option, we will set drain_console=True so the
+# console is always drained.
+guest = QEMUMachine(binary=qemu_path, args=args,
+console_log=self._console_log_path,
+drain_console=True)
 guest.set_machine(self._config['machine'])
 guest.set_console()
 try:
@@ -285,6 +296,8 @@ class BaseVM(object):
 raise
 atexit.register(self.shutdown)
 self._guest = guest
+# Init console so we can start consuming the chars.
+self.console_init()
 usernet_info = guest.qmp("human-monitor-command",
  command_line="info usernet")
 self.ssh_port = None
@@ -296,7 +309,9 @@ class BaseVM(object):
 raise Exception("Cannot find ssh port from 'info usernet':\n%s" % \
 usernet_info)
 
-def console_init(self, timeout = 120):
+def console_init(self, timeout = None):
+if timeout == None:
+timeout = self.socket_timeout
 vm = self._guest
 vm.console_socket.settimeout(timeout)
 self.console_raw_path = os.path.join(vm._temp_dir,
@@ -578,6 +593,8 @@ def parse_args(vmcls):
 parser.add_option("--efi-aarch64",
   default="/usr/share

Re: [PATCH v2 4/5] target/tricore: Implement tricore_cpu_get_phys_page_debug

2020-06-01 Thread Richard Henderson
On 5/29/20 12:21 AM, Bastian Koppelmann wrote:
> this also removes tricore_cpu_get_phys_page_attrs_debug() as it was a
> temporary fix from b190f477e29c7cd03a8fee49c96d27f160e3f5b0.
> 
> Signed-off-by: Bastian Koppelmann 
> ---
>  target/tricore/cpu.c| 10 +-
>  target/tricore/helper.c | 13 +
>  2 files changed, 14 insertions(+), 9 deletions(-)

Reviewed-by: Richard Henderson 


r~



[PATCH v9 6/9] tests/vm: Added a new script for centos.aarch64.

2020-06-01 Thread Robert Foley
centos.aarch64 creates a CentOS 8 image.
Also added a new kickstart script used to build the centos.aarch64 image.

Signed-off-by: Robert Foley 
Reviewed-by: Peter Puhov 
Reviewed-by: Alex Bennée 
---
 tests/vm/Makefile.include|   3 +-
 tests/vm/centos-8-aarch64.ks |  51 
 tests/vm/centos.aarch64  | 227 +++
 3 files changed, 280 insertions(+), 1 deletion(-)
 create mode 100644 tests/vm/centos-8-aarch64.ks
 create mode 100755 tests/vm/centos.aarch64

diff --git a/tests/vm/Makefile.include b/tests/vm/Makefile.include
index 4fa292765d..39f918a430 100644
--- a/tests/vm/Makefile.include
+++ b/tests/vm/Makefile.include
@@ -6,7 +6,7 @@ IMAGES := freebsd netbsd openbsd centos fedora
 ifneq ($(GENISOIMAGE),)
 IMAGES += ubuntu.i386 centos
 ifneq ($(EFI_AARCH64),)
-IMAGES += ubuntu.aarch64
+IMAGES += ubuntu.aarch64 centos.aarch64
 endif
 endif
 
@@ -28,6 +28,7 @@ ifneq ($(GENISOIMAGE),)
@echo "  vm-build-ubuntu.i386- Build QEMU in ubuntu i386 VM"
 ifneq ($(EFI_AARCH64),)
@echo "  vm-build-ubuntu.aarch64 - Build QEMU in ubuntu aarch64 
VM"
+   @echo "  vm-build-centos.aarch64 - Build QEMU in CentOS aarch64 
VM"
 else
@echo "  (to build centos/ubuntu aarch64 images use configure 
--efi-aarch64)"
 endif
diff --git a/tests/vm/centos-8-aarch64.ks b/tests/vm/centos-8-aarch64.ks
new file mode 100644
index 00..fd6ebe4d49
--- /dev/null
+++ b/tests/vm/centos-8-aarch64.ks
@@ -0,0 +1,51 @@
+# CentOS aarch64 image kickstart file.
+# This file is used by the CentOS installer to
+# script the generation of the image.
+#
+# Copyright 2020 Linaro
+#
+ignoredisk --only-use=vda
+# System bootloader configuration
+bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=vda
+autopart --type=plain
+# Partition clearing information
+clearpart --linux --initlabel --drives=vda
+# Use text mode install
+text
+repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream
+# Use CDROM installation media
+cdrom
+# Keyboard layouts
+keyboard --vckeymap=us --xlayouts=''
+# System language
+lang en_US.UTF-8
+
+# Network information
+network  --bootproto=dhcp --device=enp0s1 --onboot=off --ipv6=auto 
--no-activate
+network  --hostname=localhost.localdomain
+# Run the Setup Agent on first boot
+firstboot --enable
+# Do not configure the X Window System
+skipx
+# System services
+services --enabled="chronyd"
+# System timezone
+timezone America/New_York --isUtc
+
+# Shutdown after installation is complete.
+shutdown
+
+%packages
+@^server-product-environment
+kexec-tools
+
+%end
+
+%addon com_redhat_kdump --enable --reserve-mb='auto'
+
+%end
+%anaconda
+pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
+pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
+pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
+%end
diff --git a/tests/vm/centos.aarch64 b/tests/vm/centos.aarch64
new file mode 100755
index 00..d5232ecdb8
--- /dev/null
+++ b/tests/vm/centos.aarch64
@@ -0,0 +1,227 @@
+#!/usr/bin/env python3
+#
+# Centos aarch64 image
+#
+# Copyright 2020 Linaro
+#
+# Authors:
+#  Robert Foley 
+#  Originally based on ubuntu.aarch64
+#
+# This code is licensed under the GPL version 2 or later.  See
+# the COPYING file in the top-level directory.
+#
+
+import os
+import sys
+import subprocess
+import basevm
+import time
+import traceback
+import aarch64vm
+
+DEFAULT_CONFIG = {
+'cpu'  : "max",
+'machine'  : "virt,gic-version=max",
+'install_cmds' : "yum install -y make git python3 gcc gcc-c++ flex bison, 
"\
+"yum install -y glib2-devel pixman-devel zlib-devel, "\
+"yum install -y perl-Test-Harness, "\
+"alternatives --set python /usr/bin/python3, "\
+"sudo dnf config-manager "\
+"--add-repo=https://download.docker.com/linux/centos/docker-ce.repo,"\
+"sudo dnf install --nobest -y docker-ce.aarch64,"\
+"systemctl enable docker",
+# We increase beyond the default time since during boot
+# it can take some time (many seconds) to log into the VM.
+'ssh_timeout'  : 60,
+}
+
+class CentosAarch64VM(basevm.BaseVM):
+name = "centos.aarch64"
+arch = "aarch64"
+login_prompt = "localhost login:"
+prompt = '[root@localhost ~]#'
+image_name = "CentOS-8-aarch64-1905-dvd1.iso"
+image_link = 
"http://mirrors.usc.edu/pub/linux/distributions/centos/8.0.1905/isos/aarch64/";
+image_link += image_name
+BUILD_SCRIPT = """
+set -e;
+cd $(mktemp -d);
+sudo chmod a+r /dev/vdb;
+tar --checkpoint=.10 -xf /dev/vdb;
+./configure {configure_opts};
+make --output-sync {target} -j{jobs} {verbose};
+"""
+def set_key_perm(self):
+"""Set permissions properly on certain files to allow
+   ssh access."""
+self.console_wait_send(self.prompt,
+   "/usr/sbin/restorecon

[PATCH v9 8/9] python/qemu: Add ConsoleSocket for optional use in QEMUMachine

2020-06-01 Thread Robert Foley
We add the ConsoleSocket object, which has a socket interface
and which will consume all arriving characters on the
socket, placing them into an in memory buffer.
This will also provide those chars via recv() as
would a regular socket.
ConsoleSocket also has the option of dumping
the console bytes to a log file.

We also give QEMUMachine the option of using ConsoleSocket
to drain and to use for logging console to a file.
By default QEMUMachine does not use ConsoleSocket.

This is added in preparation for use by basevm.py in a later commit.
This is a workaround we found was needed for basevm.py since
there is a known issue where QEMU will hang waiting
for console characters to be consumed.

Cc: Eduardo Habkost 
Cc: Cleber Rosa 
Signed-off-by: Robert Foley 
Reviewed-by: Peter Puhov 
Acked-by: Alex Bennée 
Tested-by: Philippe Mathieu-Daudé 
---
 python/qemu/console_socket.py | 110 ++
 python/qemu/machine.py|  23 +--
 2 files changed, 129 insertions(+), 4 deletions(-)
 create mode 100644 python/qemu/console_socket.py

diff --git a/python/qemu/console_socket.py b/python/qemu/console_socket.py
new file mode 100644
index 00..830cb7c628
--- /dev/null
+++ b/python/qemu/console_socket.py
@@ -0,0 +1,110 @@
+#!/usr/bin/env python3
+#
+# This python module implements a ConsoleSocket object which is
+# designed always drain the socket itself, and place
+# the bytes into a in memory buffer for later processing.
+#
+# Optionally a file path can be passed in and we will also
+# dump the characters to this file for debug.
+#
+# Copyright 2020 Linaro
+#
+# Authors:
+#  Robert Foley 
+#
+# This code is licensed under the GPL version 2 or later.  See
+# the COPYING file in the top-level directory.
+#
+import asyncore
+import socket
+import threading
+import io
+import os
+import sys
+from collections import deque
+import time
+import traceback
+
+class ConsoleSocket(asyncore.dispatcher):
+
+def __init__(self, address, file=None):
+self._recv_timeout_sec = 300
+self._buffer = deque()
+self._asyncore_thread = None
+self._sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+self._sock.connect(address)
+self._logfile = None
+if file:
+self._logfile = open(file, "w")
+asyncore.dispatcher.__init__(self, sock=self._sock)
+self._open = True
+self._thread_start()
+
+def _thread_start(self):
+"""Kick off a thread to wait on the asyncore.loop"""
+if self._asyncore_thread is not None:
+return
+self._asyncore_thread = threading.Thread(target=asyncore.loop,
+ kwargs={'timeout':1})
+self._asyncore_thread.daemon = True
+self._asyncore_thread.start()
+
+def handle_close(self):
+"""redirect close to base class"""
+# Call the base class close, but not self.close() since
+# handle_close() occurs in the context of the thread which
+# self.close() attempts to join.
+asyncore.dispatcher.close(self)
+
+def close(self):
+"""Close the base object and wait for the thread to terminate"""
+if self._open:
+self._open = False
+asyncore.dispatcher.close(self)
+if self._asyncore_thread is not None:
+thread, self._asyncore_thread = self._asyncore_thread, None
+thread.join()
+if self._logfile:
+self._logfile.close()
+self._logfile = None
+
+def handle_read(self):
+"""process arriving characters into in memory _buffer"""
+try:
+data = asyncore.dispatcher.recv(self, 1)
+# latin1 is needed since there are some chars
+# we are receiving that cannot be encoded to utf-8
+# such as 0xe2, 0x80, 0xA6.
+string = data.decode("latin1")
+except:
+print("Exception seen.")
+traceback.print_exc()
+return
+if self._logfile:
+self._logfile.write("{}".format(string))
+self._logfile.flush()
+for c in string:
+self._buffer.extend(c)
+
+def recv(self, n=1, sleep_delay_s=0.1):
+"""Return chars from in memory buffer"""
+start_time = time.time()
+while len(self._buffer) < n:
+time.sleep(sleep_delay_s)
+elapsed_sec = time.time() - start_time
+if elapsed_sec > self._recv_timeout_sec:
+raise socket.timeout
+chars = ''.join([self._buffer.popleft() for i in range(n)])
+# We choose to use latin1 to remain consistent with
+# handle_read() and give back the same data as the user would
+# receive if they were reading directly from the
+# socket w/o our intervention.
+return chars.encode("latin1")
+
+def set_blocking(self):
+"""Maintain compatibility with socke

[PATCH v9 3/9] tests/vm: Added configuration file support

2020-06-01 Thread Robert Foley
Changes to tests/vm/basevm.py to allow accepting a configuration file
as a parameter. Allows for specifying VM options such as
cpu, machine, memory, and arbitrary qemu arguments for specifying options
such as NUMA configuration.
Also added an example conf_example_aarch64.yml and conf_example_x86.yml.

Signed-off-by: Robert Foley 
Reviewed-by: Peter Puhov 
Reviewed-by: Alex Bennée 
---
 configure |  9 ++
 tests/vm/Makefile.include |  6 
 tests/vm/basevm.py| 40 +++-
 tests/vm/conf_example_aarch64.yml | 51 +++
 tests/vm/conf_example_x86.yml | 50 ++
 5 files changed, 155 insertions(+), 1 deletion(-)
 create mode 100644 tests/vm/conf_example_aarch64.yml
 create mode 100644 tests/vm/conf_example_x86.yml

diff --git a/configure b/configure
index f087d2bcd1..b645470a63 100755
--- a/configure
+++ b/configure
@@ -950,6 +950,13 @@ do
 fi
 done
 
+# Check for existence of python3 yaml, needed to
+# import yaml config files into vm-build.
+python_yaml="no"
+if $(python3 -c "import yaml" 2> /dev/null); then
+python_yaml="yes"
+fi
+
 : ${smbd=${SMBD-/usr/sbin/smbd}}
 
 # Default objcc to clang if available, otherwise use CC
@@ -6597,6 +6604,7 @@ if test "$docs" != "no"; then
 echo "sphinx-build  $sphinx_build"
 fi
 echo "genisoimage   $genisoimage"
+echo "python_yaml   $python_yaml"
 echo "slirp support $slirp $(echo_version $slirp $slirp_version)"
 if test "$slirp" != "no" ; then
 echo "smbd  $smbd"
@@ -7659,6 +7667,7 @@ echo "PYTHON=$python" >> $config_host_mak
 echo "SPHINX_BUILD=$sphinx_build" >> $config_host_mak
 echo "SPHINX_WERROR=$sphinx_werror" >> $config_host_mak
 echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
+echo "PYTHON_YAML=$python_yaml" >> $config_host_mak
 echo "CC=$cc" >> $config_host_mak
 if $iasl -h > /dev/null 2>&1; then
   echo "IASL=$iasl" >> $config_host_mak
diff --git a/tests/vm/Makefile.include b/tests/vm/Makefile.include
index a253aba457..f6c3892bb2 100644
--- a/tests/vm/Makefile.include
+++ b/tests/vm/Makefile.include
@@ -44,6 +44,12 @@ endif
@echo "QEMU_LOCAL=1 - Use QEMU binary local to this 
build."
@echo "QEMU=/path/to/qemu- Change path to QEMU binary"
@echo "QEMU_IMG=/path/to/qemu-img- Change path to qemu-img tool"
+ifeq ($(PYTHON_YAML),yes)
+   @echo "QEMU_CONFIG=/path/conf.yml   - Change path to VM 
configuration .yml file."
+else
+   @echo "(install python3-yaml to enable support for yaml file to 
configure a VM.)"
+endif
+   @echo "   See conf_example_*.yml for 
file format details."
 
 vm-build-all: $(addprefix vm-build-, $(IMAGES))
 
diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
index cfe20c58f7..fa56fbbb4b 100644
--- a/tests/vm/basevm.py
+++ b/tests/vm/basevm.py
@@ -481,7 +481,6 @@ class BaseVM(object):
   cwd=cidir,
   stdin=self._devnull, stdout=self._stdout,
   stderr=self._stdout)
-
 return os.path.join(cidir, "cloud-init.iso")
 
 def get_qemu_path(arch, build_path=None):
@@ -497,6 +496,41 @@ def get_qemu_path(arch, build_path=None):
 qemu_path = "qemu-system-" + arch
 return qemu_path
 
+def parse_config(config, args):
+""" Parse yaml config and populate our config structure.
+The yaml config allows the user to override the
+defaults for VM parameters.  In many cases these
+defaults can be overridden without rebuilding the VM."""
+if args.config:
+config_file = args.config
+elif 'QEMU_CONFIG' in os.environ:
+config_file = os.environ['QEMU_CONFIG']
+else:
+return config
+if not os.path.exists(config_file):
+raise Exception("config file {} does not exist".format(config_file))
+# We gracefully handle importing the yaml module
+# since it might not be installed.
+# If we are here it means the user supplied a .yml file,
+# so if the yaml module is not installed we will exit with error.
+try:
+import yaml
+except ImportError:
+print("The python3-yaml package is needed "\
+  "to support config.yaml files")
+# Instead of raising an exception we exit to avoid
+# a raft of messy (expected) errors to stdout.
+exit(1)
+with open(config_file) as f:
+yaml_dict = yaml.safe_load(f)
+
+if 'qemu-conf' in yaml_dict:
+config.update(yaml_dict['qemu-conf'])
+else:
+raise Exception("config file {} is not valid"\
+" missing qemu-conf".format(config_file))
+return config
+
 def parse_args(vmcls):
 
 def get_default_jobs():
@@ -536,6 +570,9 @@ def parse_args(vmcls):
   help="run tests with a snapshot")
 parser.add_option("--genisoimage", default="genisoim

[PATCH v9 7/9] tests/vm: change scripts to use self._config

2020-06-01 Thread Robert Foley
This change converts existing scripts to using for example self.ROOT_PASS,
to self._config['root_pass'].
We made similar changes for GUEST_USER, and GUEST_PASS.
This allows us also to remove the change in basevm.py,
which adds __getattr__ for backwards compatibility.

Signed-off-by: Robert Foley 
Reviewed-by: Peter Puhov 
---
 tests/vm/basevm.py | 11 ++-
 tests/vm/fedora| 17 +
 tests/vm/freebsd   | 16 
 tests/vm/netbsd| 19 ++-
 tests/vm/openbsd   | 17 +
 5 files changed, 38 insertions(+), 42 deletions(-)

diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
index 5fd66f6b26..f716798b40 100644
--- a/tests/vm/basevm.py
+++ b/tests/vm/basevm.py
@@ -183,13 +183,6 @@ class BaseVM(object):
 self.console_init(timeout=timeout)
 self.console_wait(wait_string)
 
-def __getattr__(self, name):
-# Support direct access to config by key.
-# for example, access self._config['cpu'] by self.cpu
-if name.lower() in self._config.keys():
-return self._config[name.lower()]
-return object.__getattribute__(self, name)
-
 def _download_with_cache(self, url, sha256sum=None, sha512sum=None):
 def check_sha256sum(fname):
 if not sha256sum:
@@ -239,13 +232,13 @@ class BaseVM(object):
 return r
 
 def ssh(self, *cmd):
-return self._ssh_do(self.GUEST_USER, cmd, False)
+return self._ssh_do(self._config["guest_user"], cmd, False)
 
 def ssh_root(self, *cmd):
 return self._ssh_do("root", cmd, False)
 
 def ssh_check(self, *cmd):
-self._ssh_do(self.GUEST_USER, cmd, True)
+self._ssh_do(self._config["guest_user"], cmd, True)
 
 def ssh_root_check(self, *cmd):
 self._ssh_do("root", cmd, True)
diff --git a/tests/vm/fedora b/tests/vm/fedora
index bd9c6cf295..f536a92678 100755
--- a/tests/vm/fedora
+++ b/tests/vm/fedora
@@ -109,20 +109,20 @@ class FedoraVM(basevm.BaseVM):
 
 self.console_wait_send("7) [!] Root password", "7\n")
 self.console_wait("Password:")
-self.console_send("%s\n" % self.ROOT_PASS)
+self.console_send("%s\n" % self._config["root_pass"])
 self.console_wait("Password (confirm):")
-self.console_send("%s\n" % self.ROOT_PASS)
+self.console_send("%s\n" % self._config["root_pass"])
 
 self.console_wait_send("8) [ ] User creation", "8\n")
 self.console_wait_send("1) [ ] Create user",   "1\n")
 self.console_wait_send("3) User name", "3\n")
-self.console_wait_send("ENTER:", "%s\n" % self.GUEST_USER)
+self.console_wait_send("ENTER:", "%s\n" % self._config["guest_user"])
 self.console_wait_send("4) [ ] Use password",  "4\n")
 self.console_wait_send("5) Password",  "5\n")
 self.console_wait("Password:")
-self.console_send("%s\n" % self.GUEST_PASS)
+self.console_send("%s\n" % self._config["guest_pass"])
 self.console_wait("Password (confirm):")
-self.console_send("%s\n" % self.GUEST_PASS)
+self.console_send("%s\n" % self._config["guest_pass"])
 self.console_wait_send("7) Groups","c\n")
 
 while True:
@@ -140,7 +140,7 @@ class FedoraVM(basevm.BaseVM):
 if good:
 break
 time.sleep(10)
-self.console_send("r\n" % self.GUEST_PASS)
+self.console_send("r\n" % self._config["guest_pass"])
 
 self.console_wait_send("'b' to begin install", "b\n")
 
@@ -151,12 +151,13 @@ class FedoraVM(basevm.BaseVM):
 
 # setup qemu user
 prompt = " ~]$"
-self.console_ssh_init(prompt, self.GUEST_USER, self.GUEST_PASS)
+self.console_ssh_init(prompt, self._config["guest_user"],
+  self._config["guest_pass"])
 self.console_wait_send(prompt, "exit\n")
 
 # setup root user
 prompt = " ~]#"
-self.console_ssh_init(prompt, "root", self.ROOT_PASS)
+self.console_ssh_init(prompt, "root", self._config["root_pass"])
 self.console_sshd_config(prompt)
 
 # setup virtio-blk #1 (tarfile)
diff --git a/tests/vm/freebsd b/tests/vm/freebsd
index 298967fe9c..898393b58d 100755
--- a/tests/vm/freebsd
+++ b/tests/vm/freebsd
@@ -114,9 +114,9 @@ class FreeBSDVM(basevm.BaseVM):
 
 # post-install configuration
 self.console_wait("New Password:")
-self.console_send("%s\n" % self.ROOT_PASS)
+self.console_send("%s\n" % self._config["root_pass"])
 self.console_wait("Retype New Password:")
-self.console_send("%s\n" % self.ROOT_PASS)
+self.console_send("%s\n" % self._config["root_pass"])
 
 self.console_wait_send("Network Configuration", "\n")
 self.console_wait_send("IPv4",  "y")
@@ -135,9 +135,9 @@ class FreeBSDVM(basevm.BaseVM):
 # qemu user
   

[PATCH v9 4/9] tests/vm: Add common Ubuntu python module

2020-06-01 Thread Robert Foley
Add a common Ubuntu python module and make use of
it with the ubuntu.i386 script.
This is preparation for adding an Ubuntu script
ubuntu.aarch64.  Splitting out the common
logic such as build_image() will reduce duplication.

Signed-off-by: Robert Foley 
Tested-by: Philippe Mathieu-Daudé 
---
 tests/vm/ubuntu.i386 | 46 +
 tests/vm/ubuntuvm.py | 60 
 2 files changed, 72 insertions(+), 34 deletions(-)
 create mode 100644 tests/vm/ubuntuvm.py

diff --git a/tests/vm/ubuntu.i386 b/tests/vm/ubuntu.i386
index 1570775335..c699eaf8d7 100755
--- a/tests/vm/ubuntu.i386
+++ b/tests/vm/ubuntu.i386
@@ -11,15 +11,22 @@
 # the COPYING file in the top-level directory.
 #
 
-import os
 import sys
-import subprocess
 import basevm
-import time
+import ubuntuvm
 
-class UbuntuX86VM(basevm.BaseVM):
+DEFAULT_CONFIG = {
+'install_cmds' : "apt-get update,"\
+ "apt-get build-dep -y qemu,"\
+ "apt-get install -y libfdt-dev flex bison 
language-pack-en",
+}
+
+class UbuntuX86VM(ubuntuvm.UbuntuVM):
 name = "ubuntu.i386"
 arch = "i386"
+image_link="https://cloud-images.ubuntu.com/releases/bionic/"\
+   "release-20191114/ubuntu-18.04-server-cloudimg-i386.img"
+
image_sha256="28969840626d1ea80bb249c08eef1a4533e8904aa51a327b40f37ac4b4ff04ef"
 BUILD_SCRIPT = """
 set -e;
 cd $(mktemp -d);
@@ -29,34 +36,5 @@ class UbuntuX86VM(basevm.BaseVM):
 make --output-sync {target} -j{jobs} {verbose};
 """
 
-def build_image(self, img):
-cimg = self._download_with_cache(
-
"https://cloud-images.ubuntu.com/releases/bionic/release-20191114/ubuntu-18.04-server-cloudimg-i386.img";,
-
sha256sum="28969840626d1ea80bb249c08eef1a4533e8904aa51a327b40f37ac4b4ff04ef")
-img_tmp = img + ".tmp"
-subprocess.check_call(["cp", "-f", cimg, img_tmp])
-self.exec_qemu_img("resize", img_tmp, "50G")
-self.boot(img_tmp, extra_args = [
-"-device", "VGA",
-"-cdrom", self.gen_cloud_init_iso()
-])
-self.wait_ssh()
-self.ssh_root_check("touch /etc/cloud/cloud-init.disabled")
-self.ssh_root_check("apt-get update")
-self.ssh_root_check("apt-get install -y cloud-initramfs-growroot")
-# Don't check the status in case the guest hang up too quickly
-self.ssh_root("sync && reboot")
-time.sleep(5)
-self.wait_ssh()
-# The previous update sometimes doesn't survive a reboot, so do it 
again
-self.ssh_root_check("sed -ie s/^#\ deb-src/deb-src/g 
/etc/apt/sources.list")
-self.ssh_root_check("apt-get update")
-self.ssh_root_check("apt-get build-dep -y qemu")
-self.ssh_root_check("apt-get install -y libfdt-dev flex bison 
language-pack-en")
-self.ssh_root("poweroff")
-self.wait()
-os.rename(img_tmp, img)
-return 0
-
 if __name__ == "__main__":
-sys.exit(basevm.main(UbuntuX86VM))
+sys.exit(basevm.main(UbuntuX86VM, DEFAULT_CONFIG))
diff --git a/tests/vm/ubuntuvm.py b/tests/vm/ubuntuvm.py
new file mode 100644
index 00..6689ad87aa
--- /dev/null
+++ b/tests/vm/ubuntuvm.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python3
+#
+# Ubuntu VM testing library
+#
+# Copyright 2017 Red Hat Inc.
+# Copyright 2020 Linaro
+#
+# Authors:
+#  Robert Foley 
+#  Originally based on ubuntu.i386 Fam Zheng 
+#
+# This code is licensed under the GPL version 2 or later.  See
+# the COPYING file in the top-level directory.
+
+import os
+import subprocess
+import basevm
+
+class UbuntuVM(basevm.BaseVM):
+
+def __init__(self, args, config=None):
+self.login_prompt = "ubuntu-{}-guest login:".format(self.arch)
+basevm.BaseVM.__init__(self, args, config)
+
+def build_image(self, img):
+"""Build an Ubuntu VM image.  The child class will
+   define the install_cmds to init the VM."""
+os_img = self._download_with_cache(self.image_link,
+   sha256sum=self.image_sha256)
+img_tmp = img + ".tmp"
+subprocess.check_call(["cp", "-f", os_img, img_tmp])
+self.exec_qemu_img("resize", img_tmp, "+50G")
+ci_img = self.gen_cloud_init_iso()
+
+self.boot(img_tmp, extra_args = [ "-device", "VGA", "-cdrom", ci_img, 
])
+
+# First command we issue is fix for slow ssh login.
+self.wait_ssh(wait_root=True,
+  cmd="chmod -x /etc/update-motd.d/*")
+# Wait for cloud init to finish
+self.wait_ssh(wait_root=True,
+  cmd="ls /var/lib/cloud/instance/boot-finished")
+self.ssh_root("touch /etc/cloud/cloud-init.disabled")
+# Disable auto upgrades.
+# We want to keep the VM system state stable.
+self.ssh_root('sed -ie \'s/"1"/"0"/g\' '\
+  '/etc/apt/apt.conf.d/20auto-upgrades')
+self.ssh_ro

[PATCH v9 5/9] tests/vm: Added a new script for ubuntu.aarch64.

2020-06-01 Thread Robert Foley
ubuntu.aarch64 provides a script to create an Ubuntu 18.04 VM.
Another new file is also added aarch64vm.py, which is a module with
common methods used by aarch64 VMs, such as how to create the
flash images.

Signed-off-by: Robert Foley 
Reviewed-by: Peter Puhov 
---
 configure |  20 +++
 tests/vm/Makefile.include |  11 
 tests/vm/aarch64vm.py | 106 ++
 tests/vm/basevm.py|  12 +
 tests/vm/ubuntu.aarch64   |  68 
 5 files changed, 217 insertions(+)
 create mode 100644 tests/vm/aarch64vm.py
 create mode 100755 tests/vm/ubuntu.aarch64

diff --git a/configure b/configure
index b645470a63..0f2c1472db 100755
--- a/configure
+++ b/configure
@@ -411,6 +411,7 @@ prefix="/usr/local"
 mandir="\${prefix}/share/man"
 datadir="\${prefix}/share"
 firmwarepath="\${prefix}/share/qemu-firmware"
+efi_aarch64=""
 qemu_docdir="\${prefix}/share/doc/qemu"
 bindir="\${prefix}/bin"
 libdir="\${prefix}/lib"
@@ -1099,6 +1100,8 @@ for opt do
   ;;
   --firmwarepath=*) firmwarepath="$optarg"
   ;;
+  --efi-aarch64=*) efi_aarch64="$optarg"
+  ;;
   --host=*|--build=*|\
   --disable-dependency-tracking|\
   --sbindir=*|--sharedstatedir=*|\
@@ -1753,6 +1756,7 @@ Advanced options (experts only):
   --sysconfdir=PATHinstall config in PATH$confsuffix
   --localstatedir=PATH install local state in PATH (set at runtime on 
win32)
   --firmwarepath=PATH  search PATH for firmware files
+  --efi-aarch64=PATH   PATH of efi file to use for aarch64 VMs.
   --with-confsuffix=SUFFIX suffix for QEMU data inside 
datadir/libdir/sysconfdir [$confsuffix]
   --with-pkgversion=VERS   use specified string as sub-version of the package
   --enable-debug   enable common debug build options
@@ -3548,6 +3552,20 @@ EOF
   fi
 fi
 
+
+# efi-aarch64 probe
+# Check for efi files needed by aarch64 VMs.
+# By default we will use the efi included with QEMU.
+# Allow user to override the path for efi also.
+if ! test -f "$efi_aarch64"; then
+  if test -f $source_path/pc-bios/edk2-aarch64-code.fd.bz2; then
+# valid after build
+efi_aarch64=$PWD/pc-bios/edk2-aarch64-code.fd
+  else
+efi_aarch64=""
+  fi
+fi
+
 ##
 # libcap-ng library probe
 if test "$cap_ng" != "no" ; then
@@ -6604,6 +6622,7 @@ if test "$docs" != "no"; then
 echo "sphinx-build  $sphinx_build"
 fi
 echo "genisoimage   $genisoimage"
+echo "efi_aarch64   $efi_aarch64"
 echo "python_yaml   $python_yaml"
 echo "slirp support $slirp $(echo_version $slirp $slirp_version)"
 if test "$slirp" != "no" ; then
@@ -7667,6 +7686,7 @@ echo "PYTHON=$python" >> $config_host_mak
 echo "SPHINX_BUILD=$sphinx_build" >> $config_host_mak
 echo "SPHINX_WERROR=$sphinx_werror" >> $config_host_mak
 echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
+echo "EFI_AARCH64=$efi_aarch64" >> $config_host_mak
 echo "PYTHON_YAML=$python_yaml" >> $config_host_mak
 echo "CC=$cc" >> $config_host_mak
 if $iasl -h > /dev/null 2>&1; then
diff --git a/tests/vm/Makefile.include b/tests/vm/Makefile.include
index f6c3892bb2..4fa292765d 100644
--- a/tests/vm/Makefile.include
+++ b/tests/vm/Makefile.include
@@ -5,6 +5,9 @@
 IMAGES := freebsd netbsd openbsd centos fedora
 ifneq ($(GENISOIMAGE),)
 IMAGES += ubuntu.i386 centos
+ifneq ($(EFI_AARCH64),)
+IMAGES += ubuntu.aarch64
+endif
 endif
 
 IMAGES_DIR := $(HOME)/.cache/qemu-vm/images
@@ -23,6 +26,11 @@ vm-help vm-test:
 ifneq ($(GENISOIMAGE),)
@echo "  vm-build-centos - Build QEMU in CentOS VM, 
with Docker"
@echo "  vm-build-ubuntu.i386- Build QEMU in ubuntu i386 VM"
+ifneq ($(EFI_AARCH64),)
+   @echo "  vm-build-ubuntu.aarch64 - Build QEMU in ubuntu aarch64 
VM"
+else
+   @echo "  (to build centos/ubuntu aarch64 images use configure 
--efi-aarch64)"
+endif
 else
@echo "  (install genisoimage to build centos/ubuntu images)"
 endif
@@ -65,6 +73,7 @@ $(IMAGES_DIR)/%.img:  $(SRC_PATH)/tests/vm/% \
$(if $(V)$(DEBUG), --debug) \
$(if $(GENISOIMAGE),--genisoimage $(GENISOIMAGE)) \
$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
+   $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
--image "$@" \
--force \
--build-image $@, \
@@ -80,6 +89,7 @@ vm-build-%: $(IMAGES_DIR)/%.img
$(if $(J),--jobs $(J)) \
$(if $(V),--verbose) \
$(if $(QEMU_LOCAL),--build-path $(BUILD_DIR)) \
+   $(if $(EFI_AARCH64),--efi-aarch64 $(EFI_AARCH64)) \
--image "$<" \
$(if $(BUILD_TARGET),--build-target $(BUILD_TARGET)) \
--snapshot \
@@ -102,6 +112,7 @@ vm-boot-ssh-%: $(IMAGES_DIR)/%.img
$(if $(J),--jobs $(J)) \
$(if $(V)$(DEBUG), --debug) \
$(if $(QEMU_LOCAL),--buil

[PATCH v9 2/9] tests/vm: Add configuration to basevm.py

2020-06-01 Thread Robert Foley
Added use of a configuration to tests/vm/basevm.py.
The configuration provides parameters used to configure a VM.
This allows for providing alternate configurations to the VM being
created/launched. cpu, machine, memory, and NUMA configuration are all
examples of configuration which we might want to vary on the VM being created
or launched.
This will for example allow for creating an aarch64 vm.

Signed-off-by: Robert Foley 
Reviewed-by: Peter Puhov 
Reviewed-by: Alex Bennée 
---
 tests/vm/basevm.py | 172 +++--
 1 file changed, 133 insertions(+), 39 deletions(-)

diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
index 5a58e6c393..cfe20c58f7 100644
--- a/tests/vm/basevm.py
+++ b/tests/vm/basevm.py
@@ -29,16 +29,41 @@ import tempfile
 import shutil
 import multiprocessing
 import traceback
-
-SSH_KEY = open(os.path.join(os.path.dirname(__file__),
-   "..", "keys", "id_rsa")).read()
-SSH_PUB_KEY = open(os.path.join(os.path.dirname(__file__),
-   "..", "keys", "id_rsa.pub")).read()
-
+import shlex
+
+SSH_KEY_FILE = os.path.join(os.path.dirname(__file__),
+   "..", "keys", "id_rsa")
+SSH_PUB_KEY_FILE = os.path.join(os.path.dirname(__file__),
+   "..", "keys", "id_rsa.pub")
+
+# This is the standard configuration.
+# Any or all of these can be overridden by
+# passing in a config argument to the VM constructor.
+DEFAULT_CONFIG = {
+'cpu' : "max",
+'machine' : 'pc',
+'guest_user'  : "qemu",
+'guest_pass'  : "qemupass",
+'root_pass'   : "qemupass",
+'ssh_key_file': SSH_KEY_FILE,
+'ssh_pub_key_file': SSH_PUB_KEY_FILE,
+'memory'  : "4G",
+'extra_args'  : [],
+'qemu_args'   : "",
+'dns' : "",
+'ssh_port': 0,
+'install_cmds': "",
+'boot_dev_type'   : "block",
+'ssh_timeout' : 1,
+}
+BOOT_DEVICE = {
+'block' :  "-drive file={},if=none,id=drive0,cache=writeback "\
+   "-device virtio-blk,drive=drive0,bootindex=0",
+'scsi'  :  "-device virtio-scsi-device,id=scsi "\
+   "-drive file={},format=raw,if=none,id=hd0 "\
+   "-device scsi-hd,drive=hd0,bootindex=0",
+}
 class BaseVM(object):
-GUEST_USER = "qemu"
-GUEST_PASS = "qemupass"
-ROOT_PASS = "qemupass"
 
 envvars = [
 "https_proxy",
@@ -57,25 +82,38 @@ class BaseVM(object):
 poweroff = "poweroff"
 # enable IPv6 networking
 ipv6 = True
+# This is the timeout on the wait for console bytes.
+socket_timeout = 120
 # Scale up some timeouts under TCG.
 # 4 is arbitrary, but greater than 2,
 # since we found we need to wait more than twice as long.
 tcg_ssh_timeout_multiplier = 4
-def __init__(self, args):
+def __init__(self, args, config=None):
 self._guest = None
 self._genisoimage = args.genisoimage
 self._build_path = args.build_path
+# Allow input config to override defaults.
+self._config = DEFAULT_CONFIG.copy()
+if config != None:
+self._config.update(config)
+self.validate_ssh_keys()
 self._tmpdir = os.path.realpath(tempfile.mkdtemp(prefix="vm-test-",
  suffix=".tmp",
  dir="."))
 atexit.register(shutil.rmtree, self._tmpdir)
-
-self._ssh_key_file = os.path.join(self._tmpdir, "id_rsa")
-open(self._ssh_key_file, "w").write(SSH_KEY)
-subprocess.check_call(["chmod", "600", self._ssh_key_file])
-
-self._ssh_pub_key_file = os.path.join(self._tmpdir, "id_rsa.pub")
-open(self._ssh_pub_key_file, "w").write(SSH_PUB_KEY)
+# Copy the key files to a temporary directory.
+# Also chmod the key file to agree with ssh requirements.
+self._config['ssh_key'] = \
+open(self._config['ssh_key_file']).read().rstrip()
+self._config['ssh_pub_key'] = \
+open(self._config['ssh_pub_key_file']).read().rstrip()
+self._ssh_tmp_key_file = os.path.join(self._tmpdir, "id_rsa")
+open(self._ssh_tmp_key_file, "w").write(self._config['ssh_key'])
+subprocess.check_call(["chmod", "600", self._ssh_tmp_key_file])
+
+self._ssh_tmp_pub_key_file = os.path.join(self._tmpdir, "id_rsa.pub")
+open(self._ssh_tmp_pub_key_file,
+ "w").write(self._config['ssh_pub_key'])
 
 self.debug = args.debug
 self._stderr = sys.stderr
@@ -84,11 +122,14 @@ class BaseVM(object):
 self._stdout = sys.stdout
 else:
 self._stdout = self._devnull
+netdev = "user,id=vnet,hostfwd=:127.0.0.1:{}-:22"
 self._args = [ \
-"-nodefaults", "-m", "4G",
-"-cpu", "max",
-"-netdev", "user,id=vnet,hostfwd=:127.0.0.1:0-:22" +
-   (",ipv6=no" if not self.ipv6

[PATCH v9 1/9] tests/vm: pass args through to BaseVM's __init__

2020-06-01 Thread Robert Foley
Adding the args parameter to BaseVM's __init__.
We will shortly need to pass more parameters to the class
so let's just pass args rather than growing the parameter list.

Signed-off-by: Robert Foley 
Reviewed-by: Alex Bennée 
Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 
---
 tests/vm/basevm.py | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
index a80b616a08..5a58e6c393 100644
--- a/tests/vm/basevm.py
+++ b/tests/vm/basevm.py
@@ -61,11 +61,10 @@ class BaseVM(object):
 # 4 is arbitrary, but greater than 2,
 # since we found we need to wait more than twice as long.
 tcg_ssh_timeout_multiplier = 4
-def __init__(self, debug=False, vcpus=None, genisoimage=None,
- build_path=None):
+def __init__(self, args):
 self._guest = None
-self._genisoimage = genisoimage
-self._build_path = build_path
+self._genisoimage = args.genisoimage
+self._build_path = args.build_path
 self._tmpdir = os.path.realpath(tempfile.mkdtemp(prefix="vm-test-",
  suffix=".tmp",
  dir="."))
@@ -78,7 +77,7 @@ class BaseVM(object):
 self._ssh_pub_key_file = os.path.join(self._tmpdir, "id_rsa.pub")
 open(self._ssh_pub_key_file, "w").write(SSH_PUB_KEY)
 
-self.debug = debug
+self.debug = args.debug
 self._stderr = sys.stderr
 self._devnull = open(os.devnull, "w")
 if self.debug:
@@ -92,8 +91,8 @@ class BaseVM(object):
(",ipv6=no" if not self.ipv6 else ""),
 "-device", "virtio-net-pci,netdev=vnet",
 "-vnc", "127.0.0.1:0,to=20"]
-if vcpus and vcpus > 1:
-self._args += ["-smp", "%d" % vcpus]
+if args.jobs and args.jobs > 1:
+self._args += ["-smp", "%d" % args.jobs]
 if kvm_available(self.arch):
 self._args += ["-enable-kvm"]
 else:
@@ -456,8 +455,7 @@ def main(vmcls):
 return 1
 logging.basicConfig(level=(logging.DEBUG if args.debug
else logging.WARN))
-vm = vmcls(debug=args.debug, vcpus=args.jobs,
-   genisoimage=args.genisoimage, build_path=args.build_path)
+vm = vmcls(args)
 if args.build_image:
 if os.path.exists(args.image) and not args.force:
 sys.stderr.writelines(["Image file exists: %s\n" % args.image,
-- 
2.17.1




[PATCH v9 0/9] tests/vm: Add support for aarch64 VMs

2020-06-01 Thread Robert Foley
This is version 9 of the patch series to
add support for aarch64 VMs in the vm-build infrastructure.
 - Ubuntu 18.04 aarch64 VM
 - CentOS 8 aarch64 VM

v8: https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg08458.html

Changes in v9:
- Fixed one bug/typo in configure for efi-aarch64.
- Fixed indentation of efi-aarch64 code in configure.
- Updated file header for ubuntuvm.py
- Few minor changes in ConsoleSocket
- Updated some comments in basevm.py around the call to 
  QEMUMachine regarding drain_console=True.

Robert Foley (9):
  tests/vm: pass args through to BaseVM's __init__
  tests/vm: Add configuration to basevm.py
  tests/vm: Added configuration file support
  tests/vm: Add common Ubuntu python module
  tests/vm: Added a new script for ubuntu.aarch64.
  tests/vm: Added a new script for centos.aarch64.
  tests/vm: change scripts to use self._config
  python/qemu: Add ConsoleSocket for optional use in QEMUMachine
  tests/vm: Add workaround to consume console

 configure |  29 
 python/qemu/console_socket.py | 110 +
 python/qemu/machine.py|  23 ++-
 tests/vm/Makefile.include |  22 +++
 tests/vm/aarch64vm.py | 106 +
 tests/vm/basevm.py| 256 --
 tests/vm/centos-8-aarch64.ks  |  51 ++
 tests/vm/centos.aarch64   | 227 ++
 tests/vm/conf_example_aarch64.yml |  51 ++
 tests/vm/conf_example_x86.yml |  50 ++
 tests/vm/fedora   |  17 +-
 tests/vm/freebsd  |  16 +-
 tests/vm/netbsd   |  19 +--
 tests/vm/openbsd  |  17 +-
 tests/vm/ubuntu.aarch64   |  68 
 tests/vm/ubuntu.i386  |  46 ++
 tests/vm/ubuntuvm.py  |  60 +++
 17 files changed, 1045 insertions(+), 123 deletions(-)
 create mode 100644 python/qemu/console_socket.py
 create mode 100644 tests/vm/aarch64vm.py
 create mode 100644 tests/vm/centos-8-aarch64.ks
 create mode 100755 tests/vm/centos.aarch64
 create mode 100644 tests/vm/conf_example_aarch64.yml
 create mode 100644 tests/vm/conf_example_x86.yml
 create mode 100755 tests/vm/ubuntu.aarch64
 create mode 100644 tests/vm/ubuntuvm.py

-- 
2.17.1




Re: [PATCH v2 3/5] target/tricore: Raise EXCP_DEBUG in gen_goto_tb() for singlestep

2020-06-01 Thread Richard Henderson
On 5/29/20 12:21 AM, Bastian Koppelmann wrote:
>  if (ctx->base.singlestep_enabled) {
> -/* raise exception debug */
> +generate_qemu_excp(ctx, EXCP_DEBUG);
>  }
>  tcg_gen_exit_tb(NULL, 0);

For preference, put an else here:

  if (singlestep) {
generate_qemu_excp();
  } else {
tcg_gen_exit_tb();
  }

else you emit dead code after the exception.

r~



Re: [PULL 0/5] tricore queue

2020-06-01 Thread Peter Maydell
On Mon, 1 Jun 2020 at 16:11, Bastian Koppelmann
 wrote:
>
> The following changes since commit 7ea32024c6b3ad9c88d6200e73dbf76c8e160024:
>
>   Merge remote-tracking branch 
> 'remotes/amarkovic/tags/mips-queue-june-01-2020' into staging (2020-06-01 
> 13:43:59 +0100)
>
> are available in the Git repository at:
>
>   https://github.com/bkoppelmann/qemu.git tags/pull-tricore-20200601
>
> for you to fetch changes up to d127de3baa64d1cabc8e1994e658688abb577ba9:
>
>   target/tricore: Implement gdbstub (2020-06-01 16:55:13 +0200)
>
> 
> Remove ctx->env ptr, add TriCore gdb stub
>
> 
> Bastian Koppelmann (5):
>   target/tricore: Don't save pc in generate_qemu_excp
>   target/tricore: Move translate feature check to ctx
>   target/tricore: Raise EXCP_DEBUG in gen_goto_tb() for singlestep
>   target/tricore: Implement tricore_cpu_get_phys_page_debug
>   target/tricore: Implement gdbstub
>


Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/5.1
for any user-visible changes.

-- PMM



[PATCH] sparc: implement addr function

2020-06-01 Thread Jason A. Donenfeld
The sparc firmware provides an addr function, which is used by operating
systems like OpenBSD to query and work with framebuffer information,
addressing the cells directly. Without it, QEMU cannot start OpenBSD at
all, while with it, QEMU boots out of the box.

Suggested-by: Mark Cave-Ayland 
Signed-off-by: Jason A. Donenfeld 
---
After this lands, somebody will need to update the submodule and
prebuilt inside of qemu.

 forth/device/extra.fs | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/forth/device/extra.fs b/forth/device/extra.fs
index 9ca6b78..f778f7a 100644
--- a/forth/device/extra.fs
+++ b/forth/device/extra.fs
@@ -19,6 +19,12 @@
rot encode-int 2swap property
 ;
 
+: addr
+  parse-word $find if
+cell +
+  then
+;
+
 \ -
 \ property utils
 \ -
-- 
2.26.2




Re: [Libguestfs] Provide NBD via Browser over Websockets

2020-06-01 Thread Eric Wheeler
On Sat, 30 May 2020, Richard W.M. Jones wrote:
> On Fri, May 29, 2020 at 09:08:29PM +, Eric Wheeler wrote:
> > On Fri, 29 May 2020, Richard W.M. Jones wrote:
> > > On Fri, May 29, 2020 at 08:58:06AM -0500, Eric Blake wrote:
> > > > On 5/29/20 8:50 AM, Daniel P. Berrang�© wrote:
> > > > 
> > > > >>>(2) You need to persuade qemu's NBD client to read from a WebSocket.
> > > > >>>I didn't really know anything about WebSockets until today but it
> > > > >>>seems as if they are a full-duplex protocol layered on top of HTTP 
> > > > >>>[a].
> > > > >>>Is there a WebSocket proxy that turns WS into plain TCP (a bit like
> > > > >>>stunnel)?  Google suggests [b].
> > > > >>>
> > > > >>>[a] https://en.wikipedia.org/wiki/WebSocket#Protocol_handshake
> > > > >>>[b] https://github.com/novnc/websockify
> > > > >>
> > > > >>qemu already knows how to connect as a client to websockets; Dan 
> > > > >>Berrange
> > > > >>knows more about that setup.  I suspect it would not be too difficult 
> > > > >>to
> > > > >>teach the qemu NBD client code to use a WebSocket instead of a Unix 
> > > > >>or TCP
> > > > >>socket as its data source.
> > > > >
> > > > >Actually the inverse. The QIOChannelWebsocket impl is only the server
> > > > >side of the problem, as used by QEMU's VNC server. We've never 
> > > > >implemented
> > > > >the client side. There is nothing especially stopping us doing that - 
> > > > >just
> > > > >needs someone motivated with time to work on it.
> > > > 
> > > > In the meantime, you may still be able to set up something like:
> > > > 
> > > > local machine:
> > > > iso -> NBD server -> Unix socket -> websockify -> WebSocket
> > > 
> > > I guess the idea is to have a zero-install solution for the browser.
> > > As I said in the email earlier this is very common for IPMI-type
> > > remote access to blade servers and in my experience is implemented
> > > using a Java applet and a proprietary protocol terminated at the BMC
> > > (which then emulates a virtual CDROM to the server).  There are some
> > > HP blade servers on Red Hat's internal Beaker instance where you can
> > > play with this.  For qemu we wouldn't need to invent a new protocol
> > > when NBD is available and already implemented (albeit not yet on top
> > > of WebSockets).
> > > 
> > > The NBD server must run inside the browser and therefore be either
> > > written from scratch in Javascript, or an existing server
> > > cross-compiled to WASM (if that is possible - I don't really know).
> > 
> > Interesting idea about WASM.  I'll see if I can build one of the simple 
> > nbd servers that are around.  Not sure how to link it to the JS file IO, 
> > however.
> 
> After reading a bit about compiling to WebSockets it sounds like you
> can cross-compile a C program, but there's no library support at all.
> IOW to port an existing server you'd have to implement enough of POSIX
> to make it work.  nbdkit has a liberal license deliberately to make it
> possible to chop it up and incorporate it into completely forked
> codebases (nbdkit is a plot to make NBD more popular).
> 
> But since NBD is pretty simple, a fresh Javascript server might be
> easier, especially if you stick to only implementing reads.

Good point, I'll wait on trying WASM.  

If anyone plans to implement NBD in JS let me know, otherwise I'll 
probably implement a stripped down verion to integrate as an nbdkit plugin 
to avoid re-writing all the handshake and version bits.

--
Eric Wheeler

> Rich.
> 
> -- 
> Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
> Read my programming and virtualization blog: http://rwmj.wordpress.com
> virt-top is 'top' for virtual machines.  Tiny program with many
> powerful monitoring features, net stats, disk stats, logging, etc.
> http://people.redhat.com/~rjones/virt-top
> 
> 

Re: [PATCH v2 2/5] target/tricore: Move translate feature check to ctx

2020-06-01 Thread Richard Henderson
On 5/29/20 12:21 AM, Bastian Koppelmann wrote:
> this allows us to remove the references to env from ctx. This also fixes
> a segfault that was due to the unititalized ctx->env ptr.
> 
> Reported-by: Andreas Konopik 
> Signed-off-by: Bastian Koppelmann 
> ---
>  target/tricore/translate.c | 60 +-
>  1 file changed, 33 insertions(+), 27 deletions(-)

Reviewed-by: Richard Henderson 


r~



Re: [PATCH v2 1/5] target/tricore: Don't save pc in generate_qemu_excp

2020-06-01 Thread Richard Henderson
On 5/29/20 12:21 AM, Bastian Koppelmann wrote:
> EXCP_DEBUG is the only user. If we encounter a jump in tricore-gdb it's
> target was overwritten by generate_qemu_excp() and we would never leave.
> 
> Signed-off-by: Bastian Koppelmann 
> ---
>  target/tricore/translate.c | 1 -
>  1 file changed, 1 deletion(-)

Reviewed-by: Richard Henderson 


r~



Re: [PATCH v2 00/20] backup performance: block_status + async

2020-06-01 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20200601181118.579-1-vsement...@virtuozzo.com/



Hi,

This series failed the asan build test. Please find the testing commands and
their output below. If you have Docker installed, you can probably reproduce it
locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
export ARCH=x86_64
make docker-image-fedora V=1 NETWORK=1
time make docker-test-debug@fedora TARGET_LIST=x86_64-softmmu J=14 NETWORK=1
=== TEST SCRIPT END ===

PASS 1 fdc-test /x86_64/fdc/cmos
PASS 2 fdc-test /x86_64/fdc/no_media_on_start
PASS 3 fdc-test /x86_64/fdc/read_without_media
==8167==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 4 fdc-test /x86_64/fdc/media_change
PASS 5 fdc-test /x86_64/fdc/sense_interrupt
PASS 6 fdc-test /x86_64/fdc/relative_seek
---
PASS 32 test-opts-visitor /visitor/opts/range/beyond
PASS 33 test-opts-visitor /visitor/opts/dict/unvisited
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-coroutine -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="test-coroutine" 
==8242==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 test-coroutine /basic/no-dangling-access
PASS 2 test-coroutine /basic/lifecycle
PASS 3 test-coroutine /basic/yield
==8242==WARNING: ASan is ignoring requested __asan_handle_no_return: stack top: 
0x7ffc47dee000; bottom 0x7f11b97d2000; size: 0x00ea8e61c000 (100748080)
False positive error reports may follow
For details see https://github.com/google/sanitizers/issues/189
PASS 4 test-coroutine /basic/nesting
---
PASS 12 test-aio /aio/event/flush
PASS 13 test-aio /aio/event/wait/no-flush-cb
PASS 14 test-aio /aio/timer/schedule
==8257==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 15 test-aio /aio/coroutine/queue-chaining
PASS 16 test-aio /aio-gsource/flush
PASS 17 test-aio /aio-gsource/bh/schedule
---
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
QTEST_QEMU_BINARY=x86_64-softmmu/qemu-system-x86_64 QTEST_QEMU_IMG=qemu-img 
tests/qtest/ide-test -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="ide-test" 
PASS 28 test-aio /aio-gsource/timer/schedule
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-aio-multithread -m=quick -k --tap < /dev/null | 
./scripts/tap-driver.pl --test-name="test-aio-multithread" 
==8268==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 test-aio-multithread /aio/multi/lifecycle
==8265==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 ide-test /x86_64/ide/identify
PASS 2 test-aio-multithread /aio/multi/schedule
==8285==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 2 ide-test /x86_64/ide/flush
PASS 3 test-aio-multithread /aio/multi/mutex/contended
==8296==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 3 ide-test /x86_64/ide/bmdma/simple_rw
==8307==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 4 ide-test /x86_64/ide/bmdma/trim
==8313==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 4 test-aio-multithread /aio/multi/mutex/handoff
PASS 5 test-aio-multithread /aio/multi/mutex/mcs
PASS 6 test-aio-multithread /aio/multi/mutex/pthread
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-throttle -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="test-throttle" 
==8330==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 test-throttle /throttle/leak_bucket
PASS 2 test-throttle /throttle/compute_wait
PASS 3 test-throttle /throttle/init
---
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-thread-pool -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="test-thread-pool" 
PASS 1 test-thread-pool /thread-pool/submit
PASS 2 test-thread-pool /thread-pool/submit-aio
==8334==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 3 test-thread-pool /thread-pool/submit-co
PASS 4 test-thread-pool /thread-pool/submit-many
PASS 5 test-thread-pool /thread-pool/cancel
==8401==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 6 test-thread-pool /thread-pool/cancel-async
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-hbitmap -m=quick -k --tap < /dev/null | .

[Bug 1881648] [NEW] `qemu-img info` reports an incorrect actual-size when the underlying posix filesystem has transparent compression

2020-06-01 Thread Graham Christensen
Public bug reported:

qemu-img info reports the same thing as `du`*1024:

$ qemu-img info --output json ./my.qcow2  | jq '."actual-size"'
558619648

$ du ./my.qcow2
545527  ./my.qcow2

$ echo $((558619648 / 545527))
1024

and this is correct in terms of bytes on disk, but due to transparent
compression implemented by the filesystem, it is not the actual byte
count:

$ du -h --apparent-size ./my.qcow2
1346568192  my.qcow2

** Affects: qemu
 Importance: Undecided
 Status: New

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

Title:
  `qemu-img info` reports an incorrect actual-size when the underlying
  posix filesystem has transparent compression

Status in QEMU:
  New

Bug description:
  qemu-img info reports the same thing as `du`*1024:

  $ qemu-img info --output json ./my.qcow2  | jq '."actual-size"'
  558619648

  $ du ./my.qcow2
  545527./my.qcow2

  $ echo $((558619648 / 545527))
  1024

  and this is correct in terms of bytes on disk, but due to transparent
  compression implemented by the filesystem, it is not the actual byte
  count:

  $ du -h --apparent-size ./my.qcow2
  1346568192my.qcow2

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



[Bug 1881645] [NEW] qemu-system-x86_64 --help (or --version) gives no output

2020-06-01 Thread Adriano Pinaffo
Public bug reported:

I have Arch Linux with qemu 5.0.0-6 (seen with pacman). Running VMs work just 
fine, but when I run qemu-system-x86_64 --version or qemu-system-x86_64 --help, 
there is no feedback on the screen. This behavior messes up other applications 
(GNS3 in my case that cannot recognize qemu as correctly installed because 
there is no feedback.
My kernel is 5.6.11.

** Affects: qemu
 Importance: Undecided
 Status: New

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

Title:
  qemu-system-x86_64 --help (or --version) gives no output

Status in QEMU:
  New

Bug description:
  I have Arch Linux with qemu 5.0.0-6 (seen with pacman). Running VMs work just 
fine, but when I run qemu-system-x86_64 --version or qemu-system-x86_64 --help, 
there is no feedback on the screen. This behavior messes up other applications 
(GNS3 in my case that cannot recognize qemu as correctly installed because 
there is no feedback.
  My kernel is 5.6.11.

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



Re: [PATCH v2 00/20] backup performance: block_status + async

2020-06-01 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20200601181118.579-1-vsement...@virtuozzo.com/



Hi,

This series failed the docker-quick@centos7 build test. Please find the testing 
commands and
their output below. If you have Docker installed, you can probably reproduce it
locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-centos7 V=1 NETWORK=1
time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1
=== TEST SCRIPT END ===

  TESTcheck-unit: tests/test-logging
  TESTcheck-unit: tests/test-replication
**
ERROR:/tmp/qemu-test/src/tests/test-replication.c:428:test_secondary_start: 
assertion failed: (!local_err)
ERROR - Bail out! 
ERROR:/tmp/qemu-test/src/tests/test-replication.c:428:test_secondary_start: 
assertion failed: (!local_err)
make: *** [check-unit] Error 1
make: *** Waiting for unfinished jobs
  TESTcheck-qtest-x86_64: tests/qtest/boot-order-test
  TESTcheck-qtest-x86_64: tests/qtest/bios-tables-test
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', 
'--label', 'com.qemu.instance.uuid=73ef29198bda41a1bce9aa3697266e4c', '-u', 
'1001', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', 
'-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 
'SHOW_ENV=1', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', 
'/home/patchew/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', 
'/var/tmp/patchew-tester-tmp-j0ydkht8/src/docker-src.2020-06-01-14.44.54.8388:/var/tmp/qemu:z,ro',
 'qemu:centos7', '/var/tmp/qemu/run', 'test-quick']' returned non-zero exit 
status 2.
filter=--filter=label=com.qemu.instance.uuid=73ef29198bda41a1bce9aa3697266e4c
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-j0ydkht8/src'
make: *** [docker-run-test-quick@centos7] Error 2

real14m11.116s
user0m9.306s


The full log is available at
http://patchew.org/logs/20200601181118.579-1-vsement...@virtuozzo.com/testing.docker-quick@centos7/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

Re: [PATCH] msix: add valid.accepts methods to check address

2020-06-01 Thread P J P
+-- On Mon, 1 Jun 2020, Philippe Mathieu-Daudé wrote --+
| Fixes: CVE-2020-x

'CVE-2020-13754' assigned to this issue by Mitre.
  -> https://bugzilla.redhat.com/show_bug.cgi?id=1842363

Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
8685 545E B54C 486B C6EB 271E E285 8B5A F050 DE8D

Re: [PATCH 0/2] Add support for SEV Launch Secret Injection

2020-06-01 Thread Dr. David Alan Gilbert
cc'ing in Brijesh for SEV stuff, and also Paolo.

* Tobin Feldman-Fitzthum (to...@linux.vnet.ibm.com) wrote:
> This patchset contains two patches. The first enables QEMU
> to facilitate the injection of a secret blob into the guest
> memory.
> 
> The second enables QEMU to parse the guest ROM to determine
> the address at which the secret should be injected.
> 
> Tobin Feldman-Fitzthum (2):
>   sev: add sev-inject-launch-secret
>   sev: scan guest ROM for launch secret address
> 
>  include/sysemu/sev.h   |   2 +
>  qapi/misc-target.json  |  20 +++
>  target/i386/monitor.c  |   8 +++
>  target/i386/sev-stub.c |   5 ++
>  target/i386/sev.c  | 113 +
>  target/i386/sev_i386.h |  16 ++
>  target/i386/trace-events   |   1 +
>  tests/qtest/qmp-cmd-test.c |   6 +-
>  8 files changed, 168 insertions(+), 3 deletions(-)
> 
> -- 
> 2.20.1 (Apple Git-117)
> 
> 
--
Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK




[PULL 12/12] migration/migration.c: Fix hang in ram_save_host_page

2020-06-01 Thread Dr. David Alan Gilbert (git)
From: Lukas Straub 

migration_rate_limit will erroneously ratelimit a shutdown socket,
which causes the migration thread to hang in ram_save_host_page
if the socket is shutdown.

Fix this by explicitly testing if the socket has errors or was
shutdown in migration_rate_limit.

Signed-off-by: Lukas Straub 
Message-Id: 

Reviewed-by: Dr. David Alan Gilbert 
Signed-off-by: Dr. David Alan Gilbert 
---
 migration/migration.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/migration/migration.c b/migration/migration.c
index 0bb042a0f7..b63ad91d34 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -3361,6 +3361,10 @@ bool migration_rate_limit(void)
 bool urgent = false;
 migration_update_counters(s, now);
 if (qemu_file_rate_limit(s->to_dst_file)) {
+
+if (qemu_file_get_error(s->to_dst_file)) {
+return false;
+}
 /*
  * Wait for a delay to do rate limiting OR
  * something urgent to post the semaphore.
-- 
2.26.2




[PULL 10/12] migration/colo.c: Relaunch failover even if there was an error

2020-06-01 Thread Dr. David Alan Gilbert (git)
From: Lukas Straub 

If vmstate_loading is true, secondary_vm_do_failover will set failover
status to FAILOVER_STATUS_RELAUNCH and return success without initiating
failover. However, if there is an error during the vmstate_loading
section, failover isn't relaunched. Instead we then wait for
failover on colo_incoming_sem.

Fix this by relaunching failover even if there was an error. Also,
to make this work properly, set vmstate_loading to false when
returning during the vmstate_loading section.

Signed-off-by: Lukas Straub 
Message-Id: 

Reviewed-by: zhanghailiang 
Signed-off-by: Dr. David Alan Gilbert 
---
 migration/colo.c | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/migration/colo.c b/migration/colo.c
index 4105999634..59639f519f 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -752,6 +752,7 @@ static void 
colo_incoming_process_checkpoint(MigrationIncomingState *mis,
 ret = qemu_load_device_state(fb);
 if (ret < 0) {
 error_setg(errp, "COLO: load device state failed");
+vmstate_loading = false;
 qemu_mutex_unlock_iothread();
 return;
 }
@@ -760,6 +761,7 @@ static void 
colo_incoming_process_checkpoint(MigrationIncomingState *mis,
 replication_get_error_all(&local_err);
 if (local_err) {
 error_propagate(errp, local_err);
+vmstate_loading = false;
 qemu_mutex_unlock_iothread();
 return;
 }
@@ -768,6 +770,7 @@ static void 
colo_incoming_process_checkpoint(MigrationIncomingState *mis,
 replication_do_checkpoint_all(&local_err);
 if (local_err) {
 error_propagate(errp, local_err);
+vmstate_loading = false;
 qemu_mutex_unlock_iothread();
 return;
 }
@@ -779,6 +782,7 @@ static void 
colo_incoming_process_checkpoint(MigrationIncomingState *mis,
 
 if (local_err) {
 error_propagate(errp, local_err);
+vmstate_loading = false;
 qemu_mutex_unlock_iothread();
 return;
 }
@@ -789,9 +793,6 @@ static void 
colo_incoming_process_checkpoint(MigrationIncomingState *mis,
 qemu_mutex_unlock_iothread();
 
 if (failover_get_state() == FAILOVER_STATUS_RELAUNCH) {
-failover_set_state(FAILOVER_STATUS_RELAUNCH,
-FAILOVER_STATUS_NONE);
-failover_request_active(NULL);
 return;
 }
 
@@ -890,6 +891,14 @@ void *colo_process_incoming_thread(void *opaque)
 error_report_err(local_err);
 break;
 }
+
+if (failover_get_state() == FAILOVER_STATUS_RELAUNCH) {
+failover_set_state(FAILOVER_STATUS_RELAUNCH,
+FAILOVER_STATUS_NONE);
+failover_request_active(NULL);
+break;
+}
+
 if (failover_get_state() != FAILOVER_STATUS_NONE) {
 error_report("failover request");
 break;
@@ -897,8 +906,6 @@ void *colo_process_incoming_thread(void *opaque)
 }
 
 out:
-vmstate_loading = false;
-
 /*
  * There are only two reasons we can get here, some error happened
  * or the user triggered failover.
-- 
2.26.2




[PULL 07/12] migration/colo.c: Use event instead of semaphore

2020-06-01 Thread Dr. David Alan Gilbert (git)
From: Lukas Straub 

If multiple packets miscompare in a short timeframe, the semaphore
value will be increased multiple times. This causes multiple
checkpoints even if one would be sufficient.

Fix this by using a event instead of a semaphore for triggering
checkpoints. Now, checkpoint requests will be ignored until the
checkpoint event is sent to colo-compare (which releases the
miscompared packets).

Benchmark results (iperf3):
Client-to-server tcp:
without patch: ~66 Mbit/s
with patch: ~61 Mbit/s
Server-to-client tcp:
without patch: ~702 Kbit/s
with patch: ~16 Mbit/s

Signed-off-by: Lukas Straub 
Message-Id: 

Reviewed-by: zhanghailiang 
Signed-off-by: Dr. David Alan Gilbert 
---
 migration/colo.c  | 9 +
 migration/migration.h | 4 ++--
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/migration/colo.c b/migration/colo.c
index d015d4f84e..fe0d6e93e5 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -436,6 +436,7 @@ static int colo_do_checkpoint_transaction(MigrationState *s,
 goto out;
 }
 
+qemu_event_reset(&s->colo_checkpoint_event);
 colo_notify_compares_event(NULL, COLO_EVENT_CHECKPOINT, &local_err);
 if (local_err) {
 goto out;
@@ -589,7 +590,7 @@ static void colo_process_checkpoint(MigrationState *s)
 goto out;
 }
 
-qemu_sem_wait(&s->colo_checkpoint_sem);
+qemu_event_wait(&s->colo_checkpoint_event);
 
 if (s->state != MIGRATION_STATUS_COLO) {
 goto out;
@@ -637,7 +638,7 @@ out:
 colo_compare_unregister_notifier(&packets_compare_notifier);
 timer_del(s->colo_delay_timer);
 timer_free(s->colo_delay_timer);
-qemu_sem_destroy(&s->colo_checkpoint_sem);
+qemu_event_destroy(&s->colo_checkpoint_event);
 
 /*
  * Must be called after failover BH is completed,
@@ -654,7 +655,7 @@ void colo_checkpoint_notify(void *opaque)
 MigrationState *s = opaque;
 int64_t next_notify_time;
 
-qemu_sem_post(&s->colo_checkpoint_sem);
+qemu_event_set(&s->colo_checkpoint_event);
 s->colo_checkpoint_time = qemu_clock_get_ms(QEMU_CLOCK_HOST);
 next_notify_time = s->colo_checkpoint_time +
 s->parameters.x_checkpoint_delay;
@@ -664,7 +665,7 @@ void colo_checkpoint_notify(void *opaque)
 void migrate_start_colo_process(MigrationState *s)
 {
 qemu_mutex_unlock_iothread();
-qemu_sem_init(&s->colo_checkpoint_sem, 0);
+qemu_event_init(&s->colo_checkpoint_event, false);
 s->colo_delay_timer =  timer_new_ms(QEMU_CLOCK_HOST,
 colo_checkpoint_notify, s);
 
diff --git a/migration/migration.h b/migration/migration.h
index 507284e563..f617960522 100644
--- a/migration/migration.h
+++ b/migration/migration.h
@@ -215,8 +215,8 @@ struct MigrationState
 /* The semaphore is used to notify COLO thread that failover is finished */
 QemuSemaphore colo_exit_sem;
 
-/* The semaphore is used to notify COLO thread to do checkpoint */
-QemuSemaphore colo_checkpoint_sem;
+/* The event is used to notify COLO thread to do checkpoint */
+QemuEvent colo_checkpoint_event;
 int64_t colo_checkpoint_time;
 QEMUTimer *colo_delay_timer;
 
-- 
2.26.2




[PULL 03/12] hmp: Implement qom-get HMP command

2020-06-01 Thread Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" 

This started off as Andreas Färber's implementation from
March 2015, but after feedback from Paolo and Markus it morphed into
using the json output which handles structs reasonably.

Use with qom-list to find the members of an object.

(qemu) qom-get /backend/console[0]/device/vga.rom[0] size
65536
(qemu) qom-get /machine smm
"auto"
(qemu) qom-get /machine rtc-time
{
"tm_year": 120,
"tm_sec": 51,
"tm_hour": 9,
"tm_min": 50,
"tm_mon": 4,
"tm_mday": 20
}
(qemu) qom-get /machine frob
Error: Property '.frob' not found

Signed-off-by: Dr. David Alan Gilbert 
Message-Id: <20200520151108.160598-2-dgilb...@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Markus Armbruster 
Signed-off-by: Dr. David Alan Gilbert 
---
 hmp-commands.hx| 14 ++
 include/monitor/hmp.h  |  1 +
 qom/qom-hmp-cmds.c | 18 ++
 tests/qtest/test-hmp.c |  1 +
 4 files changed, 34 insertions(+)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 7f0f3974ad..250ddae54d 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1790,6 +1790,20 @@ SRST
   Print QOM properties of object at location *path*
 ERST
 
+{
+.name   = "qom-get",
+.args_type  = "path:s,property:s",
+.params = "path property",
+.help   = "print QOM property",
+.cmd= hmp_qom_get,
+.flags  = "p",
+},
+
+SRST
+``qom-get`` *path* *property*
+  Print QOM property *property* of object at location *path*
+ERST
+
 {
 .name   = "qom-set",
 .args_type  = "path:s,property:s,value:s",
diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h
index e33ca5a911..c986cfd28b 100644
--- a/include/monitor/hmp.h
+++ b/include/monitor/hmp.h
@@ -96,6 +96,7 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict);
 void hmp_info_numa(Monitor *mon, const QDict *qdict);
 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict);
 void hmp_qom_list(Monitor *mon, const QDict *qdict);
+void hmp_qom_get(Monitor *mon, const QDict *qdict);
 void hmp_qom_set(Monitor *mon, const QDict *qdict);
 void hmp_info_qom_tree(Monitor *mon, const QDict *dict);
 void object_add_completion(ReadLineState *rs, int nb_args, const char *str);
diff --git a/qom/qom-hmp-cmds.c b/qom/qom-hmp-cmds.c
index cd08233a4c..a8b0a080c7 100644
--- a/qom/qom-hmp-cmds.c
+++ b/qom/qom-hmp-cmds.c
@@ -12,6 +12,8 @@
 #include "qapi/error.h"
 #include "qapi/qapi-commands-qom.h"
 #include "qapi/qmp/qdict.h"
+#include "qapi/qmp/qjson.h"
+#include "qapi/qmp/qstring.h"
 #include "qom/object.h"
 
 void hmp_qom_list(Monitor *mon, const QDict *qdict)
@@ -62,6 +64,22 @@ void hmp_qom_set(Monitor *mon, const QDict *qdict)
 hmp_handle_error(mon, err);
 }
 
+void hmp_qom_get(Monitor *mon, const QDict *qdict)
+{
+const char *path = qdict_get_str(qdict, "path");
+const char *property = qdict_get_str(qdict, "property");
+Error *err = NULL;
+QObject *obj = qmp_qom_get(path, property, &err);
+
+if (err == NULL) {
+QString *str = qobject_to_json_pretty(obj);
+monitor_printf(mon, "%s\n", qstring_get_str(str));
+qobject_unref(str);
+}
+
+hmp_handle_error(mon, err);
+}
+
 typedef struct QOMCompositionState {
 Monitor *mon;
 int indent;
diff --git a/tests/qtest/test-hmp.c b/tests/qtest/test-hmp.c
index f8aa5f92c5..b8b1271b9e 100644
--- a/tests/qtest/test-hmp.c
+++ b/tests/qtest/test-hmp.c
@@ -61,6 +61,7 @@ static const char *hmp_cmds[] = {
 "p $pc + 8",
 "qom-list /",
 "qom-set /machine initrd test",
+"qom-get /machine initrd",
 "screendump /dev/null",
 "sendkey x",
 "singlestep on",
-- 
2.26.2




[PULL 11/12] migration/colo.c: Move colo_notify_compares_event to the right place

2020-06-01 Thread Dr. David Alan Gilbert (git)
From: Lukas Straub 

If the secondary has to failover during checkpointing, it still is
in the old state (i.e. different state than primary). Thus we can't
expose the primary state until after the checkpoint is sent.

This fixes sporadic connection reset of client connections during
failover.

Signed-off-by: Lukas Straub 
Message-Id: 

Reviewed-by: zhanghailiang 
Signed-off-by: Dr. David Alan Gilbert 
---
 migration/colo.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/migration/colo.c b/migration/colo.c
index 59639f519f..ea7d1e9d4e 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -436,12 +436,6 @@ static int colo_do_checkpoint_transaction(MigrationState 
*s,
 goto out;
 }
 
-qemu_event_reset(&s->colo_checkpoint_event);
-colo_notify_compares_event(NULL, COLO_EVENT_CHECKPOINT, &local_err);
-if (local_err) {
-goto out;
-}
-
 /* Disable block migration */
 migrate_set_block_enabled(false, &local_err);
 if (local_err) {
@@ -503,6 +497,12 @@ static int colo_do_checkpoint_transaction(MigrationState 
*s,
 goto out;
 }
 
+qemu_event_reset(&s->colo_checkpoint_event);
+colo_notify_compares_event(NULL, COLO_EVENT_CHECKPOINT, &local_err);
+if (local_err) {
+goto out;
+}
+
 colo_receive_check_message(s->rp_state.from_dst_file,
COLO_MESSAGE_VMSTATE_LOADED, &local_err);
 if (local_err) {
-- 
2.26.2




[PULL 05/12] virtiofsd: remove symlink fallbacks

2020-06-01 Thread Dr. David Alan Gilbert (git)
From: Miklos Szeredi 

Path lookup in the kernel has special rules for looking up magic symlinks
under /proc.  If a filesystem operation is instructed to follow symlinks
(e.g. via AT_SYMLINK_FOLLOW or lack of AT_SYMLINK_NOFOLLOW), and the final
component is such a proc symlink, then the target of the magic symlink is
used for the operation, even if the target itself is a symlink.  I.e. path
lookup is always terminated after following a final magic symlink.

I was erronously assuming that in the above case the target symlink would
also be followed, and so workarounds were added for a couple of operations
to handle the symlink case.  Since the symlink can be handled simply by
following the proc symlink, these workardouds are not needed.

Also remove the "norace" option, which disabled the workarounds.

Commit bdfd66788349 ("virtiofsd: Fix xattr operations") already dealt with
the same issue for xattr operations.

Signed-off-by: Miklos Szeredi 
Message-Id: <20200514140736.20561-1-mszer...@redhat.com>
Acked-by: Vivek Goyal 
Signed-off-by: Dr. David Alan Gilbert 
---
 tools/virtiofsd/passthrough_ll.c | 175 ++-
 1 file changed, 6 insertions(+), 169 deletions(-)

diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 3ba1d90984..2ce7c96085 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -140,7 +140,6 @@ enum {
 struct lo_data {
 pthread_mutex_t mutex;
 int debug;
-int norace;
 int writeback;
 int flock;
 int posix_lock;
@@ -176,7 +175,6 @@ static const struct fuse_opt lo_opts[] = {
 { "cache=none", offsetof(struct lo_data, cache), CACHE_NONE },
 { "cache=auto", offsetof(struct lo_data, cache), CACHE_AUTO },
 { "cache=always", offsetof(struct lo_data, cache), CACHE_ALWAYS },
-{ "norace", offsetof(struct lo_data, norace), 1 },
 { "readdirplus", offsetof(struct lo_data, readdirplus_set), 1 },
 { "no_readdirplus", offsetof(struct lo_data, readdirplus_clear), 1 },
 FUSE_OPT_END
@@ -592,136 +590,6 @@ static void lo_getattr(fuse_req_t req, fuse_ino_t ino,
 fuse_reply_attr(req, &buf, lo->timeout);
 }
 
-/*
- * Increments parent->nlookup and caller must release refcount using
- * lo_inode_put(&parent).
- */
-static int lo_parent_and_name(struct lo_data *lo, struct lo_inode *inode,
-  char path[PATH_MAX], struct lo_inode **parent)
-{
-char procname[64];
-char *last;
-struct stat stat;
-struct lo_inode *p;
-int retries = 2;
-int res;
-
-retry:
-sprintf(procname, "%i", inode->fd);
-
-res = readlinkat(lo->proc_self_fd, procname, path, PATH_MAX);
-if (res < 0) {
-fuse_log(FUSE_LOG_WARNING, "%s: readlink failed: %m\n", __func__);
-goto fail_noretry;
-}
-
-if (res >= PATH_MAX) {
-fuse_log(FUSE_LOG_WARNING, "%s: readlink overflowed\n", __func__);
-goto fail_noretry;
-}
-path[res] = '\0';
-
-last = strrchr(path, '/');
-if (last == NULL) {
-/* Shouldn't happen */
-fuse_log(
-FUSE_LOG_WARNING,
-"%s: INTERNAL ERROR: bad path read from proc\n", __func__);
-goto fail_noretry;
-}
-if (last == path) {
-p = &lo->root;
-pthread_mutex_lock(&lo->mutex);
-p->nlookup++;
-g_atomic_int_inc(&p->refcount);
-pthread_mutex_unlock(&lo->mutex);
-} else {
-*last = '\0';
-res = fstatat(AT_FDCWD, last == path ? "/" : path, &stat, 0);
-if (res == -1) {
-if (!retries) {
-fuse_log(FUSE_LOG_WARNING,
- "%s: failed to stat parent: %m\n", __func__);
-}
-goto fail;
-}
-p = lo_find(lo, &stat);
-if (p == NULL) {
-if (!retries) {
-fuse_log(FUSE_LOG_WARNING,
- "%s: failed to find parent\n", __func__);
-}
-goto fail;
-}
-}
-last++;
-res = fstatat(p->fd, last, &stat, AT_SYMLINK_NOFOLLOW);
-if (res == -1) {
-if (!retries) {
-fuse_log(FUSE_LOG_WARNING,
- "%s: failed to stat last\n", __func__);
-}
-goto fail_unref;
-}
-if (stat.st_dev != inode->key.dev || stat.st_ino != inode->key.ino) {
-if (!retries) {
-fuse_log(FUSE_LOG_WARNING,
- "%s: failed to match last\n", __func__);
-}
-goto fail_unref;
-}
-*parent = p;
-memmove(path, last, strlen(last) + 1);
-
-return 0;
-
-fail_unref:
-unref_inode_lolocked(lo, p, 1);
-lo_inode_put(lo, &p);
-fail:
-if (retries) {
-retries--;
-goto retry;
-}
-fail_noretry:
-errno = EIO;
-return -1;
-}
-
-static int utimensat_empty(struct lo_data *lo, struct lo_inode *inode,
-   const struct timespec *tv)
-{
-int res;
-struct lo_inode *parent;
-char p

[PULL 09/12] migration/colo.c: Flush ram cache only after receiving device state

2020-06-01 Thread Dr. David Alan Gilbert (git)
From: Lukas Straub 

If we suceed in receiving ram state, but fail receiving the device
state, there will be a mismatch between the two.

Fix this by flushing the ram cache only after the vmstate has been
received.

Signed-off-by: Lukas Straub 
Message-Id: 
<3289d007d494cb0e2f05b1cf4ae6a78d300fede3.1589193382.git.lukasstra...@web.de>
Reviewed-by: zhanghailiang 
Signed-off-by: Dr. David Alan Gilbert 
---
 migration/colo.c | 1 +
 migration/ram.c  | 5 +
 migration/ram.h  | 1 +
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/migration/colo.c b/migration/colo.c
index d00b3b9d6b..4105999634 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -748,6 +748,7 @@ static void 
colo_incoming_process_checkpoint(MigrationIncomingState *mis,
 
 qemu_mutex_lock_iothread();
 vmstate_loading = true;
+colo_flush_ram_cache();
 ret = qemu_load_device_state(fb);
 if (ret < 0) {
 error_setg(errp, "COLO: load device state failed");
diff --git a/migration/ram.c b/migration/ram.c
index 859f835f1a..41cc530d9d 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -3360,7 +3360,7 @@ static bool postcopy_is_running(void)
  * Flush content of RAM cache into SVM's memory.
  * Only flush the pages that be dirtied by PVM or SVM or both.
  */
-static void colo_flush_ram_cache(void)
+void colo_flush_ram_cache(void)
 {
 RAMBlock *block = NULL;
 void *dst_host;
@@ -3632,9 +3632,6 @@ static int ram_load(QEMUFile *f, void *opaque, int 
version_id)
 }
 trace_ram_load_complete(ret, seq_iter);
 
-if (!ret  && migration_incoming_in_colo_state()) {
-colo_flush_ram_cache();
-}
 return ret;
 }
 
diff --git a/migration/ram.h b/migration/ram.h
index 5ceaff7cb4..2eeaacfa13 100644
--- a/migration/ram.h
+++ b/migration/ram.h
@@ -65,6 +65,7 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *rb);
 
 /* ram cache */
 int colo_init_ram_cache(void);
+void colo_flush_ram_cache(void);
 void colo_release_ram_cache(void);
 void colo_incoming_start_dirty_log(void);
 
-- 
2.26.2




[PULL 01/12] migration/rdma: fix potential nullptr access in rdma_start_incoming_migration

2020-06-01 Thread Dr. David Alan Gilbert (git)
From: Pan Nengyuan 

'rdma' is NULL when taking the first error branch in 
rdma_start_incoming_migration.
And it will cause a null pointer access in label 'err'. Fix that.

Fixes: 59c59c67ee6b0327ae932deb303caa47919aeb1e
Signed-off-by: Pan Nengyuan 
Message-Id: <20200508100755.7875-2-pannengy...@huawei.com>
Reviewed-by: Juan Quintela 
Signed-off-by: Dr. David Alan Gilbert 
  Note this is CID 1428762
---
 migration/rdma.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/migration/rdma.c b/migration/rdma.c
index 967fda5b0c..72e8b1c95b 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -4056,7 +4056,9 @@ void rdma_start_incoming_migration(const char *host_port, 
Error **errp)
 return;
 err:
 error_propagate(errp, local_err);
-g_free(rdma->host);
+if (rdma) {
+g_free(rdma->host);
+}
 g_free(rdma);
 g_free(rdma_return_path);
 }
-- 
2.26.2




[PULL 00/12] migration/virtiofs/hmp queue

2020-06-01 Thread Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" 

The following changes since commit 7ea32024c6b3ad9c88d6200e73dbf76c8e160024:

  Merge remote-tracking branch 'remotes/amarkovic/tags/mips-queue-june-01-2020' 
into staging (2020-06-01 13:43:59 +0100)

are available in the Git repository at:

  git://github.com/dagrh/qemu.git tags/pull-migration-20200601a

for you to fetch changes up to 773861274ad75a62c7ecf70ecc8e4ba31ed62190:

  migration/migration.c: Fix hang in ram_save_host_page (2020-06-01 18:44:27 
+0100)


Migration/virtiofs/hmp pull 2020-06-01

A mixed pull with:
  - RDMA migration fix (CID 1428762)
  - HMP qom-get addition and qom-set cleanup
  - a virtiofsd fix
  - COLO fixes

Signed-off-by: Dr. David Alan Gilbert 


Dr. David Alan Gilbert (2):
  hmp: Implement qom-get HMP command
  hmp: Simplify qom-set

Lukas Straub (6):
  migration/colo.c: Use event instead of semaphore
  migration/colo.c: Use cpu_synchronize_all_states()
  migration/colo.c: Flush ram cache only after receiving device state
  migration/colo.c: Relaunch failover even if there was an error
  migration/colo.c: Move colo_notify_compares_event to the right place
  migration/migration.c: Fix hang in ram_save_host_page

Miklos Szeredi (1):
  virtiofsd: remove symlink fallbacks

Pan Nengyuan (2):
  migration/rdma: fix potential nullptr access in 
rdma_start_incoming_migration
  migration/rdma: cleanup rdma context before g_free to avoid memleaks

Philippe Mathieu-Daudé (1):
  migration/vmstate: Remove unnecessary MemoryRegion forward declaration

 hmp-commands.hx  |  16 +++-
 include/migration/vmstate.h  |   1 -
 include/monitor/hmp.h|   1 +
 migration/colo.c |  39 +
 migration/migration.c|   4 +
 migration/migration.h|   4 +-
 migration/ram.c  |   5 +-
 migration/ram.h  |   1 +
 migration/rdma.c |  12 ++-
 qom/qom-hmp-cmds.c   |  34 +---
 tests/qtest/test-hmp.c   |   1 +
 tools/virtiofsd/passthrough_ll.c | 175 ++-
 12 files changed, 86 insertions(+), 207 deletions(-)




[PULL 06/12] migration/vmstate: Remove unnecessary MemoryRegion forward declaration

2020-06-01 Thread Dr. David Alan Gilbert (git)
From: Philippe Mathieu-Daudé 

"migration/vmstate.h" only uses pointer to MemoryRegion, which
is already forward declared in "qemu/typedefs.h".

Signed-off-by: Philippe Mathieu-Daudé 
Message-Id: <20200530165512.15225-1-f4...@amsat.org>
Reviewed-by: Dr. David Alan Gilbert 
Signed-off-by: Dr. David Alan Gilbert 
---
 include/migration/vmstate.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 30667631bc..eafa39f560 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -1199,7 +1199,6 @@ static inline int vmstate_register(VMStateIf *obj, int 
instance_id,
 void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd,
 void *opaque);
 
-struct MemoryRegion;
 void vmstate_register_ram(struct MemoryRegion *memory, DeviceState *dev);
 void vmstate_unregister_ram(struct MemoryRegion *memory, DeviceState *dev);
 void vmstate_register_ram_global(struct MemoryRegion *memory);
-- 
2.26.2




[PULL 08/12] migration/colo.c: Use cpu_synchronize_all_states()

2020-06-01 Thread Dr. David Alan Gilbert (git)
From: Lukas Straub 

cpu_synchronize_all_pre_loadvm() marks all vcpus as dirty, so the
registers are loaded from CPUState before we continue running
the vm. However if we failover during checkpoint, CPUState is not
initialized and the registers are loaded with garbage. This causes
guest hangs and crashes.

Fix this by using cpu_synchronize_all_states(), which initializes
CPUState from the current cpu registers additionally to marking
the vcpus as dirty.

Signed-off-by: Lukas Straub 
Message-Id: 
<9675031ce557b73ebd10e7bd20ebbf57f30b177c.1589193382.git.lukasstra...@web.de>
Reviewed-by: Dr. David Alan Gilbert 

Signed-off-by: Dr. David Alan Gilbert 
---
 migration/colo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/migration/colo.c b/migration/colo.c
index fe0d6e93e5..d00b3b9d6b 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -705,7 +705,7 @@ static void 
colo_incoming_process_checkpoint(MigrationIncomingState *mis,
 }
 
 qemu_mutex_lock_iothread();
-cpu_synchronize_all_pre_loadvm();
+cpu_synchronize_all_states();
 ret = qemu_loadvm_state_main(mis->from_src_file, mis);
 qemu_mutex_unlock_iothread();
 
-- 
2.26.2




[PULL 04/12] hmp: Simplify qom-set

2020-06-01 Thread Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" 

Simplify qom_set by making it use qmp_qom_set and the JSON parser.

(qemu) qom-get /machine smm
"auto"
(qemu) qom-set /machine smm "auto"

Signed-off-by: Dr. David Alan Gilbert 
Message-Id: <20200520151108.160598-3-dgilb...@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Markus Armbruster 
Signed-off-by: Dr. David Alan Gilbert 
  With 's'->'S' type change suggested by Paolo and Markus
---
 hmp-commands.hx|  2 +-
 qom/qom-hmp-cmds.c | 16 +---
 2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 250ddae54d..28256209b5 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1806,7 +1806,7 @@ ERST
 
 {
 .name   = "qom-set",
-.args_type  = "path:s,property:s,value:s",
+.args_type  = "path:s,property:s,value:S",
 .params = "path property value",
 .help   = "set QOM property",
 .cmd= hmp_qom_set,
diff --git a/qom/qom-hmp-cmds.c b/qom/qom-hmp-cmds.c
index a8b0a080c7..f704b6949a 100644
--- a/qom/qom-hmp-cmds.c
+++ b/qom/qom-hmp-cmds.c
@@ -48,19 +48,13 @@ void hmp_qom_set(Monitor *mon, const QDict *qdict)
 const char *property = qdict_get_str(qdict, "property");
 const char *value = qdict_get_str(qdict, "value");
 Error *err = NULL;
-bool ambiguous = false;
-Object *obj;
+QObject *obj;
 
-obj = object_resolve_path(path, &ambiguous);
-if (obj == NULL) {
-error_set(&err, ERROR_CLASS_DEVICE_NOT_FOUND,
-  "Device '%s' not found", path);
-} else {
-if (ambiguous) {
-monitor_printf(mon, "Warning: Path '%s' is ambiguous\n", path);
-}
-object_property_parse(obj, value, property, &err);
+obj = qobject_from_json(value, &err);
+if (err == NULL) {
+qmp_qom_set(path, property, obj, &err);
 }
+
 hmp_handle_error(mon, err);
 }
 
-- 
2.26.2




[PULL 02/12] migration/rdma: cleanup rdma context before g_free to avoid memleaks

2020-06-01 Thread Dr. David Alan Gilbert (git)
From: Pan Nengyuan 

When error happen in initializing 'rdma_return_path', we should cleanup rdma 
context
before g_free(rdma) to avoid some memleaks. This patch fix that.

Reported-by: Euler Robot 
Signed-off-by: Pan Nengyuan 
Message-Id: <20200508100755.7875-3-pannengy...@huawei.com>
Reviewed-by: Juan Quintela 
Signed-off-by: Dr. David Alan Gilbert 
---
 migration/rdma.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/migration/rdma.c b/migration/rdma.c
index 72e8b1c95b..ec45d33ba3 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -4094,20 +4094,20 @@ void rdma_start_outgoing_migration(void *opaque,
 rdma_return_path = qemu_rdma_data_init(host_port, errp);
 
 if (rdma_return_path == NULL) {
-goto err;
+goto return_path_err;
 }
 
 ret = qemu_rdma_source_init(rdma_return_path,
 s->enabled_capabilities[MIGRATION_CAPABILITY_RDMA_PIN_ALL], errp);
 
 if (ret) {
-goto err;
+goto return_path_err;
 }
 
 ret = qemu_rdma_connect(rdma_return_path, errp);
 
 if (ret) {
-goto err;
+goto return_path_err;
 }
 
 rdma->return_path = rdma_return_path;
@@ -4120,6 +4120,8 @@ void rdma_start_outgoing_migration(void *opaque,
 s->to_dst_file = qemu_fopen_rdma(rdma, "wb");
 migrate_fd_connect(s, NULL);
 return;
+return_path_err:
+qemu_rdma_cleanup(rdma);
 err:
 g_free(rdma);
 g_free(rdma_return_path);
-- 
2.26.2




[Bug 1880332] Re: Possible regression in QEMU 5.0.0 after CVE-2020-10702 (segmentation fault)

2020-06-01 Thread Richard Henderson
This is a compiler bug affecting (at least) libcrypto.so.1.1:

  179d90:   d503233fpaciasp
  179d94:   a9bb7bfdstp x29, x30, [sp, #-80]!
...
  17a400:   d50323bfautiasp
  17a404:   f84507fdldr x29, [sp], #80
  17a408:   d65f03c0ret

The PAC happens with the initial sp:

  X30=005501de55fc  SP=0055018477a0

while the AUTH happens with the decremented sp:

  X30=0011005501de55fc  SP=005501847750

Since the salt (sp) is different for the two operations, the
authorization should and does fail:

  X30=0020005501de55fc

Note bit 53 is now set in x30, which is the error indication.

The compiler must move the authiasp down below the ldr pop.


** Changed in: qemu
   Status: New => Invalid

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

Title:
  Possible regression in QEMU 5.0.0 after CVE-2020-10702 (segmentation
  fault)

Status in QEMU:
  Invalid

Bug description:
  I've come across a very specific situation, but I'm sure it could be
  replicated in other cases.

  In QEMU 5.0.0 when I use user emulation with a cURL binary for aarch64
  and connect to a server using TLS 1.2 and ECDHE-ECDSA-
  CHACHA20-POLY1305 cypher a segmentation fault occurs.

  I attach a Dockerfile that reproduces this crash and the strace output
  with and without the de0b1bae6461f67243282555475f88b2384a1eb9 commit
  reverted.

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



Re: [PATCH v2 00/20] backup performance: block_status + async

2020-06-01 Thread Vladimir Sementsov-Ogievskiy

01.06.2020 21:10, Vladimir Sementsov-Ogievskiy wrote:

Hi all!

This a last part of original
"[RFC 00/24] backup performance: block_status + async", prepartions are
already merged.

The series turn backup into series of block_copy_async calls, covering
the whole disk, so we get block-status based paralallel async requests
out of the box, which gives performance gain:

-    -  --  
--    ---
mirror(upstream)  backup(new)backup(new, no-copy-range) 
 backup(new, copy-range-1w)  backup(upstream)  backup(upstream, no-copy-range)
hdd-ext4:hdd-ext4  18.86 +- 0.11 45.50 +- 2.35  19.22 +- 0.09   
19.51 +- 0.09   22.85 +- 5.98 19.72 +- 0.35
hdd-ext4:ssd-ext4  8.99 +- 0.02  9.30 +- 0.01   8.97 +- 0.02
9.02 +- 0.029.68 +- 0.26  9.84 +- 0.12
ssd-ext4:hdd-ext4  9.09 +- 0.11  9.34 +- 0.10   9.34 +- 0.10
8.99 +- 0.0111.37 +- 0.37 11.47 +- 0.30
ssd-ext4:ssd-ext4  4.07 +- 0.02  5.41 +- 0.05   4.05 +- 0.01
8.35 +- 0.589.83 +- 0.64  8.62 +- 0.35
hdd-xfs:hdd-xfs18.90 +- 0.19 43.26 +- 2.47  19.62 +- 0.14   
19.38 +- 0.16   19.55 +- 0.26 19.62 +- 0.12
hdd-xfs:ssd-xfs8.93 +- 0.12  9.35 +- 0.03   8.93 +- 0.08
8.93 +- 0.059.79 +- 0.30  9.55 +- 0.15
ssd-xfs:hdd-xfs9.15 +- 0.07  9.74 +- 0.28   9.29 +- 0.03
9.08 +- 0.0510.85 +- 0.31 10.91 +- 0.30
ssd-xfs:ssd-xfs4.06 +- 0.01  4.93 +- 0.02   4.04 +- 0.01
8.17 +- 0.429.52 +- 0.49  8.85 +- 0.46
ssd-ext4:nbd   9.96 +- 0.11  11.45 +- 0.15  11.45 +- 0.02   
17.22 +- 0.06   34.45 +- 1.35 35.16 +- 0.37
nbd:ssd-ext4   9.84 +- 0.02  9.84 +- 0.04   9.80 +- 0.06
18.96 +- 0.06   30.89 +- 0.73 31.46 +- 0.21
-    -  --  
--    ---


I should add, that nbd results may be damaged by the fact that node with nbd 
server is my desktop, which was used for another tasks in parallel. Still I 
don't think it really hurt.




The table shows, that copy_range is in bad relation with parallel async
requests. copy_range brings real performance gain only on supporting fs,
like btrfs. But even on such fs, I'm not sure that this is a good
default behavior: if we do offload copy, so, that no real copy but just
link block in backup the same blocks as in original, this means that
further write from guest will lead to fragmentation of guest disk, when
the aim of backup is to operate transparently for the guest.

So, in addition to these series I also suggest to disable copy_range by
default.

===

How to test:

prepare images:
In a directories, where you want to place source and target images,
prepare images by:

for img in test-source test-target; do
  ./qemu-img create -f raw $img 1000M;
  ./qemu-img bench -c 1000 -d 1 -f raw -s 1M -w --pattern=0xff $img
done

prepare similar image for nbd server, and start it somewhere by

  qemu-nbd --persistent --nocache -f raw IMAGE

Then, run benchmark, like this:
./bench-backup.py --qemu new:../../x86_64-softmmu/qemu-system-x86_64 
upstream:/work/src/qemu/up-backup-block-copy-master/x86_64-softmmu/qemu-system-x86_64
 --dir hdd-ext4:/test-a hdd-xfs:/test-b ssd-ext4:/ssd ssd-xfs:/ssd-b --test 
$(for fs in ext4 xfs; do echo hdd-$fs:hdd-$fs hdd-$fs:ssd-$fs ssd-$fs:hdd-$fs 
ssd-$fs:ssd-$fs; done) --nbd 192.168.100.2 --test ssd-ext4:nbd nbd:ssd-ext4

(you may simply reduce number of directories/test-cases, use --help for
  help)

===

Note, that I included here
"[PATCH] block/block-copy: block_copy_dirty_clusters: fix failure check"
which was previously sent in separate, but still untouched in mailing
list. It still may be applied separately.

Vladimir Sementsov-Ogievskiy (20):
   block/block-copy: block_copy_dirty_clusters: fix failure check
   iotests: 129 don't check backup "busy"
   qapi: backup: add x-use-copy-range parameter
   block/block-copy: More explicit call_state
   block/block-copy: implement block_copy_async
   block/block-copy: add max_chunk and max_workers parameters
   block/block-copy: add ratelimit to block-copy
   block/block-copy: add block_copy_cancel
   blockjob: add set_speed to BlockJobDriver
   job: call job_enter from job_user_pause
   qapi: backup: add x-max-chunk and x-max-workers parameters
   iotests: 56: prepare for backup over block-copy
   iotests: 129: prepare for backup over block-copy
   iotests: 185: prepare for backup over block-copy
   iotests: 219: prepare for backup over block-copy
   iotests: 257: prepare for backup over block-copy
   backup: move to block-copy

  1   2   3   >