[PATCH V6 4/4] MAINTAINERS: Add Loongson-3 maintainer and reviewer

2020-06-24 Thread Huacai Chen
Add myself as a maintainer of Loongson-3 virtual platform, and also add
Jiaxun Yang as a reviewer.

Signed-off-by: Huacai Chen 
Co-developed-by: Jiaxun Yang 
---
 MAINTAINERS | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 51a4570..0226a74 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1095,6 +1095,13 @@ F: hw/isa/vt82c686.c
 F: hw/pci-host/bonito.c
 F: include/hw/isa/vt82c686.h
 
+Loongson-3 Virtual Platform
+M: Huacai Chen 
+R: Jiaxun Yang 
+S: Maintained
+F: hw/mips/loongson3_virt.c
+F: hw/intc/loongson_liointc.c
+
 Boston
 M: Paul Burton 
 R: Aleksandar Rikalo 
-- 
2.7.0




[PULL 24/31] target/i386: Add notes for versioned CPU models

2020-06-24 Thread Paolo Bonzini
From: Tao Xu 

Add which features are added or removed in this version.

Signed-off-by: Tao Xu 
Message-Id: <20200324051034.30541-1-tao3...@intel.com>
Signed-off-by: Paolo Bonzini 
---
 target/i386/cpu.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index b1b311baa2..06dc013d88 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -3135,6 +3135,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
 .versions = (X86CPUVersionDefinition[]) {
 { .version = 1 },
 { .version = 2,
+  .note = "ARCH_CAPABILITIES",
   .props = (PropValue[]) {
   { "arch-capabilities", "on" },
   { "rdctl-no", "on" },
@@ -3146,6 +3147,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
 },
 { .version = 3,
   .alias = "Cascadelake-Server-noTSX",
+  .note = "ARCH_CAPABILITIES, no TSX",
   .props = (PropValue[]) {
   { "hle", "off" },
   { "rtm", "off" },
@@ -3367,6 +3369,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
 { .version = 1 },
 {
 .version = 2,
+.note = "no TSX",
 .alias = "Icelake-Client-noTSX",
 .props = (PropValue[]) {
 { "hle", "off" },
@@ -3484,6 +3487,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
 { .version = 1 },
 {
 .version = 2,
+.note = "no TSX",
 .alias = "Icelake-Server-noTSX",
 .props = (PropValue[]) {
 { "hle", "off" },
@@ -3604,6 +3608,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
 { .version = 1 },
 {
 .version = 2,
+.note = "no MPX, no MONITOR",
 .props = (PropValue[]) {
 { "monitor", "off" },
 { "mpx", "off" },
-- 
2.26.2





[PULL 19/31] softfloat: return low bits of quotient from floatx80_modrem

2020-06-24 Thread Paolo Bonzini
From: Joseph Myers 

Both x87 and m68k need the low parts of the quotient for their
remainder operations.  Arrange for floatx80_modrem to track those bits
and return them via a pointer.

The architectures using float32_rem and float64_rem do not appear to
need this information, so the *_rem interface is left unchanged and
the information returned only from floatx80_modrem.  The logic used to
determine the low 7 bits of the quotient for m68k
(target/m68k/fpu_helper.c:make_quotient) appears completely bogus (it
looks at the result of converting the remainder to integer, the
quotient having been discarded by that point); this patch does not
change that, but the m68k maintainers may wish to do so.

Signed-off-by: Joseph Myers 
Reviewed-by: Richard Henderson 
Message-Id: 
Signed-off-by: Paolo Bonzini 
---
 fpu/softfloat.c | 23 ++-
 include/fpu/softfloat.h |  3 ++-
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index 1ee3342715..79be4f5840 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -5699,10 +5699,11 @@ floatx80 floatx80_div(floatx80 a, floatx80 b, 
float_status *status)
 | `a' with respect to the corresponding value `b'.  The operation is performed
 | according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic,
 | if 'mod' is false; if 'mod' is true, return the remainder based on truncating
-| the quotient toward zero instead.
+| the quotient toward zero instead.  '*quotient' is set to the low 64 bits of
+| the absolute value of the integer quotient.
 **/
 
-floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod,
+floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod, uint64_t *quotient,
  float_status *status)
 {
 bool aSign, zSign;
@@ -5710,6 +5711,7 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod,
 uint64_t aSig0, aSig1, bSig;
 uint64_t q, term0, term1, alternateASig0, alternateASig1;
 
+*quotient = 0;
 if (floatx80_invalid_encoding(a) || floatx80_invalid_encoding(b)) {
 float_raise(float_flag_invalid, status);
 return floatx80_default_nan(status);
@@ -5768,7 +5770,7 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod,
 shift128Right( aSig0, 0, 1, ,  );
 expDiff = 0;
 }
-q = ( bSig <= aSig0 );
+*quotient = q = ( bSig <= aSig0 );
 if ( q ) aSig0 -= bSig;
 expDiff -= 64;
 while ( 0 < expDiff ) {
@@ -5778,6 +5780,8 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod,
 sub128( aSig0, aSig1, term0, term1, ,  );
 shortShift128Left( aSig0, aSig1, 62, ,  );
 expDiff -= 62;
+*quotient <<= 62;
+*quotient += q;
 }
 expDiff += 64;
 if ( 0 < expDiff ) {
@@ -5791,6 +5795,12 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool 
mod,
 ++q;
 sub128( aSig0, aSig1, term0, term1, ,  );
 }
+if (expDiff < 64) {
+*quotient <<= expDiff;
+} else {
+*quotient = 0;
+}
+*quotient += q;
 }
 else {
 term1 = 0;
@@ -5805,6 +5815,7 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod,
 aSig0 = alternateASig0;
 aSig1 = alternateASig1;
 zSign = ! zSign;
+++*quotient;
 }
 }
 return
@@ -5821,7 +5832,8 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod,
 
 floatx80 floatx80_rem(floatx80 a, floatx80 b, float_status *status)
 {
-return floatx80_modrem(a, b, false, status);
+uint64_t quotient;
+return floatx80_modrem(a, b, false, , status);
 }
 
 /*
@@ -5832,7 +5844,8 @@ floatx80 floatx80_rem(floatx80 a, floatx80 b, 
float_status *status)
 
 floatx80 floatx80_mod(floatx80 a, floatx80 b, float_status *status)
 {
-return floatx80_modrem(a, b, true, status);
+uint64_t quotient;
+return floatx80_modrem(a, b, true, , status);
 }
 
 /*
diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h
index bff6934d09..ff4e2605b1 100644
--- a/include/fpu/softfloat.h
+++ b/include/fpu/softfloat.h
@@ -687,7 +687,8 @@ floatx80 floatx80_add(floatx80, floatx80, float_status 
*status);
 floatx80 floatx80_sub(floatx80, floatx80, float_status *status);
 floatx80 floatx80_mul(floatx80, floatx80, float_status *status);
 floatx80 floatx80_div(floatx80, floatx80, float_status *status);
-floatx80 floatx80_modrem(floatx80, floatx80, bool, float_status *status);
+floatx80 floatx80_modrem(floatx80, floatx80, bool, uint64_t *,
+ float_status *status);
 floatx80 floatx80_mod(floatx80, floatx80, float_status *status);
 floatx80 floatx80_rem(floatx80, floatx80, float_status *status);
 floatx80 floatx80_sqrt(floatx80, float_status 

Re: [PATCH v5 00/12] pc-bios: s390x: Cleanup part 1

2020-06-24 Thread Janosch Frank
On 6/24/20 12:46 PM, Thomas Huth wrote:
> On 24/06/2020 12.44, Cornelia Huck wrote:
>> On Wed, 24 Jun 2020 03:52:14 -0400
>> Janosch Frank  wrote:
>>
>>> The bios is in dire need for a cleanup as there are still a lot of
>>> magic constants being used throughout as well as duplicated code.
>>>
>>> In the first part of this series we consolidate constants and
>>> functions, as well as doing some minor cleanups and fixes.
>>>
>>> The patches are available here:
>>> https://github.com/frankjaa/qemu/pull/new/cleanup_bios
>>>
>>> v5:
>>> * Fixed whitespace damage
>>> * Removed reset PSW mask changes in dasd-ipl.c
>>> * Added jump2ipl.c cleanup patches
>>>
>>> v4:
>>> * Renamed time.h to s390-time.h
>>> * Fixed function names in sleep()
>>> * Changed order of sense_id_ccw initialization
>>> * Added missing include before sleep()
>>>
>>> v3:
>>> * Dropped 0x00 to 0x0/0 patch
>>> * Moved some timing functions into helper.h instead of time.h
>>> * Fixed IPL psw manipulation in dasd-ipl.c
>>> * Minor cosmetic fixes found by review
>>>
>>> v2:
>>> * Included cio fixup to get rid of compile errors...
>>> * Minor cosmetic fixes found by review
>>>
>>>
>>> Janosch Frank (12):
>>>pc-bios: s390x: cio.c cleanup and compile fix
>>>pc-bios: s390x: Consolidate timing functions into time.h
>>>pc-bios: s390x: Move sleep and yield to helper.h
>>>pc-bios: s390x: Get rid of magic offsets into the lowcore
>>>pc-bios: s390x: Remove unneeded dasd-ipl.c reset psw mask changes
>>>pc-bios: s390x: Rename PSW_MASK_ZMODE to PSW_MASK_64
>>>pc-bios: s390x: Use PSW masks where possible and introduce
>>>  PSW_MASK_SHORT_ADDR
>>>pc-bios: s390x: Move panic() into header and add infinite loop
>>>pc-bios: s390x: Use ebcdic2ascii table
>>>pc-bios: s390x: Make u32 ptr check explicit
>>>pc-bios: s390x: Fix bootmap.c passing PSWs as addresses
>>>pc-bios: s390x: Cleanup jump to ipl code
>>>
>>>   pc-bios/s390-ccw/bootmap.c |  9 
>>>   pc-bios/s390-ccw/bootmap.h |  2 +-
>>>   pc-bios/s390-ccw/cio.c | 40 +++---
>>>   pc-bios/s390-ccw/cio.h | 17 ++-
>>>   pc-bios/s390-ccw/dasd-ipl.c|  3 ---
>>>   pc-bios/s390-ccw/helper.h  | 19 +++-
>>>   pc-bios/s390-ccw/jump2ipl.c| 35 -
>>>   pc-bios/s390-ccw/main.c| 15 +++--
>>>   pc-bios/s390-ccw/menu.c|  1 +
>>>   pc-bios/s390-ccw/netmain.c | 23 +++
>>>   pc-bios/s390-ccw/s390-arch.h   |  4 +++-
>>>   pc-bios/s390-ccw/s390-ccw.h| 27 ++-
>>>   pc-bios/s390-ccw/s390-time.h   | 23 +++
>>>   pc-bios/s390-ccw/start.S   |  5 +++--
>>>   pc-bios/s390-ccw/virtio-net.c  |  2 ++
>>>   pc-bios/s390-ccw/virtio-scsi.c |  2 ++
>>>   pc-bios/s390-ccw/virtio.c  | 18 +++
>>>   17 files changed, 120 insertions(+), 125 deletions(-)
>>>   create mode 100644 pc-bios/s390-ccw/s390-time.h
>>>
>>
>> Hm... what's the general status of this? Most of the patches have at
>> least one R-b/A-b already, I see.
>>
>> Do the s390-ccw boot maintainers want to pick this (once the rest has
>> been looked at) and then send me a pull req, or should I pick it when
>> it is good to go? Softfreeze is less than two weeks away :)
> 
> I'd like to review the missing parts and run my tests with the patches 
> applied ... I'm just a little bit swamped right now, so please give me 
> some more time...
> 
>   Thomas

I'd suggest we hold off on the RFC patch since it makes testing all of
the boot methods necessary and I was only able to test direct, dasd
passthrough and virtio-ccw up to now. Time to build a testing environment...

I can move that patch into the next series for further discussion. It
was mostly added to prove the 64 bit PSW mask removal in patch #5.



signature.asc
Description: OpenPGP digital signature


[PATCH] hw/core/null-machine: Do not initialize unused chardev backends

2020-06-24 Thread Philippe Mathieu-Daudé
The MachineClass uses an inverted logic (inherited from the
PC machines [*]) to create the chardev backends for the default
devices (see commits 998bbd74b9d..aa40fc9c964 and ac33f8fad14).

As the none-machine doesn't have any hardware device, it is
pointless to initialize chardev backends. Fix by setting the
'no_defaults' bits in its MachineClass.

Suggested-by: Thomas Huth 
Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/core/null-machine.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/hw/core/null-machine.c b/hw/core/null-machine.c
index cb47d9d4f8..7e693523d7 100644
--- a/hw/core/null-machine.c
+++ b/hw/core/null-machine.c
@@ -50,6 +50,11 @@ static void machine_none_machine_init(MachineClass *mc)
 mc->max_cpus = 1;
 mc->default_ram_size = 0;
 mc->default_ram_id = "ram";
+mc->no_serial = 1;
+mc->no_parallel = 1;
+mc->no_floppy = 1;
+mc->no_cdrom = 1;
+mc->no_sdcard = 1;
 }
 
 DEFINE_MACHINE("none", machine_none_machine_init)
-- 
2.21.3




[PULL 26/31] numa: forbid '-numa node, mem' for 5.1 and newer machine types

2020-06-24 Thread Paolo Bonzini
From: Igor Mammedov 

Deprecation period is run out and it's a time to flip the switch
introduced by cd5ff8333a.  Disable legacy option for new machine
types (since 5.1) and amend documentation.

'-numa node,memdev' shall be used instead of disabled option
with new machine types.

Signed-off-by: Igor Mammedov 
Reviewed-by: Michal Privoznik 
Reviewed-by: Michael S. Tsirkin 
Reviewed-by: Greg Kurz 
Message-Id: <20200609135635.761587-1-imamm...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 docs/system/deprecated.rst | 37 -
 hw/arm/virt.c  |  2 +-
 hw/core/numa.c |  7 +++
 hw/i386/pc.c   |  1 -
 hw/i386/pc_piix.c  |  1 +
 hw/i386/pc_q35.c   |  1 +
 hw/ppc/spapr.c |  2 +-
 qemu-options.hx|  9 +
 8 files changed, 36 insertions(+), 24 deletions(-)

diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
index 3a255591c3..2fd6047481 100644
--- a/docs/system/deprecated.rst
+++ b/docs/system/deprecated.rst
@@ -95,23 +95,6 @@ error in the future.
 The ``-realtime mlock=on|off`` argument has been replaced by the
 ``-overcommit mem-lock=on|off`` argument.
 
-``-numa node,mem=``\ *size* (since 4.1)
-'''
-
-The parameter ``mem`` of ``-numa node`` is used to assign a part of
-guest RAM to a NUMA node. But when using it, it's impossible to manage 
specified
-RAM chunk on the host side (like bind it to a host node, setting bind policy, 
...),
-so guest end-ups with the fake NUMA configuration with suboptiomal performance.
-However since 2014 there is an alternative way to assign RAM to a NUMA node
-using parameter ``memdev``, which does the same as ``mem`` and adds
-means to actualy manage node RAM on the host side. Use parameter ``memdev``
-with *memory-backend-ram* backend as an replacement for parameter ``mem``
-to achieve the same fake NUMA effect or a properly configured
-*memory-backend-file* backend to actually benefit from NUMA configuration.
-In future new machine versions will not accept the option but it will still
-work with old machine types. User can check QAPI schema to see if the legacy
-option is supported by looking at MachineInfo::numa-mem-supported property.
-
 ``-numa`` node (without memory specified) (since 4.1)
 '
 
@@ -519,3 +502,23 @@ long starting at 1MiB, the old command::
 can be rewritten as::
 
   qemu-nbd -t --image-opts 
driver=raw,offset=1M,size=100M,file.driver=qcow2,file.file.driver=file,file.file.filename=file.qcow2
+
+Command line options
+
+
+``-numa node,mem=``\ *size* (removed in 5.1)
+
+
+The parameter ``mem`` of ``-numa node`` was used to assign a part of
+guest RAM to a NUMA node. But when using it, it's impossible to manage a 
specified
+RAM chunk on the host side (like bind it to a host node, setting bind policy, 
...),
+so the guest ends up with the fake NUMA configuration with suboptiomal 
performance.
+However since 2014 there is an alternative way to assign RAM to a NUMA node
+using parameter ``memdev``, which does the same as ``mem`` and adds
+means to actually manage node RAM on the host side. Use parameter ``memdev``
+with *memory-backend-ram* backend as replacement for parameter ``mem``
+to achieve the same fake NUMA effect or a properly configured
+*memory-backend-file* backend to actually benefit from NUMA configuration.
+New machine versions (since 5.1) will not accept the option but it will still
+work with old machine types. User can check the QAPI schema to see if the 
legacy
+option is supported by looking at MachineInfo::numa-mem-supported property.
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index caceb1e4a0..05c321f1ed 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -2262,7 +2262,6 @@ static void virt_machine_class_init(ObjectClass *oc, void 
*data)
 hc->pre_plug = virt_machine_device_pre_plug_cb;
 hc->plug = virt_machine_device_plug_cb;
 hc->unplug_request = virt_machine_device_unplug_request_cb;
-mc->numa_mem_supported = true;
 mc->nvdimm_supported = true;
 mc->auto_enable_numa_with_memhp = true;
 mc->default_ram_id = "mach-virt.ram";
@@ -2375,6 +2374,7 @@ DEFINE_VIRT_MACHINE_AS_LATEST(5, 1)
 static void virt_machine_5_0_options(MachineClass *mc)
 {
 virt_machine_5_1_options(mc);
+mc->numa_mem_supported = true;
 }
 DEFINE_VIRT_MACHINE(5, 0)
 
diff --git a/hw/core/numa.c b/hw/core/numa.c
index 5f81900f88..2725886d06 100644
--- a/hw/core/numa.c
+++ b/hw/core/numa.c
@@ -117,6 +117,13 @@ static void parse_numa_node(MachineState *ms, 
NumaNodeOptions *node,
 }
 
 if (node->has_mem) {
+if (!mc->numa_mem_supported) {
+error_setg(errp, "Parameter -numa node,mem is not supported by 
this"
+  " machine type");
+error_append_hint(errp, "Use -numa node,memdev instead\n");
+

[PATCH v4 01/20] stubs: add isa_create_simple

2020-06-24 Thread Gerd Hoffmann
Needed for -soundhw cleanup.

Signed-off-by: Gerd Hoffmann 
Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 
---
 stubs/isa-bus.c | 7 +++
 stubs/Makefile.objs | 1 +
 2 files changed, 8 insertions(+)
 create mode 100644 stubs/isa-bus.c

diff --git a/stubs/isa-bus.c b/stubs/isa-bus.c
new file mode 100644
index ..522f448997d4
--- /dev/null
+++ b/stubs/isa-bus.c
@@ -0,0 +1,7 @@
+#include "qemu/osdep.h"
+#include "hw/isa/isa.h"
+
+ISADevice *isa_create_simple(ISABus *bus, const char *name)
+{
+g_assert_not_reached();
+}
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 28e48171d1f3..869204668231 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -7,6 +7,7 @@ stub-obj-y += fdset.o
 stub-obj-y += gdbstub.o
 stub-obj-y += iothread-lock.o
 stub-obj-y += is-daemonized.o
+stub-obj-y += isa-bus.o
 stub-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 stub-obj-$(CONFIG_LINUX_IO_URING) += io_uring.o
 stub-obj-y += monitor-core.o
-- 
2.18.4




[PATCH v4 08/20] audio: deprecate -soundhw gus

2020-06-24 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().
Remove the now obsolete init function.

Signed-off-by: Gerd Hoffmann 
---
 hw/audio/gus.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/hw/audio/gus.c b/hw/audio/gus.c
index c8df2bde6b32..7e4a8cadad6f 100644
--- a/hw/audio/gus.c
+++ b/hw/audio/gus.c
@@ -286,12 +286,6 @@ static void gus_realizefn (DeviceState *dev, Error **errp)
 AUD_set_active_out (s->voice, 1);
 }
 
-static int GUS_init (ISABus *bus)
-{
-isa_create_simple (bus, TYPE_GUS);
-return 0;
-}
-
 static Property gus_properties[] = {
 DEFINE_AUDIO_PROPERTIES(GUSState, card),
 DEFINE_PROP_UINT32 ("freq",GUSState, freq,44100),
@@ -322,7 +316,7 @@ static const TypeInfo gus_info = {
 static void gus_register_types (void)
 {
 type_register_static (_info);
-isa_register_soundhw("gus", "Gravis Ultrasound GF1", GUS_init);
+deprecated_register_soundhw("gus", "Gravis Ultrasound GF1", 1, TYPE_GUS);
 }
 
 type_init (gus_register_types)
-- 
2.18.4




[PATCH v4 05/20] audio: deprecate -soundhw es1370

2020-06-24 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().  Remove the now obsolete init
function.  Add an alias so both es1370 and ES1370 are working with
-device.

Signed-off-by: Gerd Hoffmann 
---
 hw/audio/es1370.c | 9 ++---
 qdev-monitor.c| 1 +
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/hw/audio/es1370.c b/hw/audio/es1370.c
index 5f8a83ff5624..4255463a49ff 100644
--- a/hw/audio/es1370.c
+++ b/hw/audio/es1370.c
@@ -884,12 +884,6 @@ static void es1370_exit(PCIDevice *dev)
 AUD_remove_card(>card);
 }
 
-static int es1370_init (PCIBus *bus)
-{
-pci_create_simple (bus, -1, TYPE_ES1370);
-return 0;
-}
-
 static Property es1370_properties[] = {
 DEFINE_AUDIO_PROPERTIES(ES1370State, card),
 DEFINE_PROP_END_OF_LIST(),
@@ -928,7 +922,8 @@ static const TypeInfo es1370_info = {
 static void es1370_register_types (void)
 {
 type_register_static (_info);
-pci_register_soundhw("es1370", "ENSONIQ AudioPCI ES1370", es1370_init);
+deprecated_register_soundhw("es1370", "ENSONIQ AudioPCI ES1370",
+0, TYPE_ES1370);
 }
 
 type_init (es1370_register_types)
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 105d9792ecdf..e3083fae394b 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -55,6 +55,7 @@ typedef struct QDevAlias
 static const QDevAlias qdev_alias_table[] = {
 { "AC97", "ac97" }, /* -soundhw name */
 { "e1000", "e1000-82540em" },
+{ "ES1370", "es1370" }, /* -soundhw name */
 { "ich9-ahci", "ahci" },
 { "lsi53c895a", "lsi" },
 { "virtio-9p-ccw", "virtio-9p", QEMU_ARCH_S390X },
-- 
2.18.4




Re: [PATCH] xen: Fix xen-legacy-backend qdev types

2020-06-24 Thread Jason Andryuk
On Wed, Jun 24, 2020 at 8:30 AM Paul Durrant  wrote:
>
> > -Original Message-
> > From: Jason Andryuk 
> > Sent: 24 June 2020 13:20
> > To: Stefano Stabellini ; Anthony Perard 
> > ; Paul
> > Durrant ; xen-de...@lists.xenproject.org
> > Cc: Jason Andryuk ; qemu-devel@nongnu.org
> > Subject: [PATCH] xen: Fix xen-legacy-backend qdev types
> >
> > xen-sysdev is a TYPE_SYS_BUS_DEVICE.  bus_type should not be changed so
> > that it can plug into the System bus.  Otherwise this assert triggers:
> > qemu-system-i386: hw/core/qdev.c:102: qdev_set_parent_bus: Assertion
> > `dc->bus_type && object_dynamic_cast(OBJECT(bus), dc->bus_type)'
> > failed.
> >
> > TYPE_XENBACKEND attaches to TYPE_XENSYSBUS, so its class_init needs to
> > be set accordingly to attach the qdev.  Otherwise the following assert
> > triggers:
> > qemu-system-i386: hw/core/qdev.c:102: qdev_set_parent_bus: Assertion
> > `dc->bus_type && object_dynamic_cast(OBJECT(bus), dc->bus_type)'
> > failed.
> >
> > TYPE_XENBACKEND is not a subclass of XEN_XENSYSDEV, so it's parent
> > is just TYPE_DEVICE.  Change that.
> >
> > Signed-off-by: Jason Andryuk 
>
> Clearly we raced. This patch and my patch #1 are identical so I'm happy to 
> give my ack to this.

Yeah, looks like you beat me by a hair :)

Either way it gets fixed is fine by me.

Thanks,
Jason



[PATCH v5 01/10] module: qom module support

2020-06-24 Thread Gerd Hoffmann
Add support for qom types provided by modules.  For starters use a
manually maintained list which maps qom type to module and prefix.

Two load functions are added:  One to load the module for a specific
type, and one to load all modules (needed for object/device lists as
printed by -- for example -- qemu -device help).

Signed-off-by: Gerd Hoffmann 
---
 include/qemu/module.h |  2 ++
 util/module.c | 55 +++
 2 files changed, 57 insertions(+)

diff --git a/include/qemu/module.h b/include/qemu/module.h
index 011ae1ae7605..9121a475c1b6 100644
--- a/include/qemu/module.h
+++ b/include/qemu/module.h
@@ -70,5 +70,7 @@ void register_dso_module_init(void (*fn)(void), 
module_init_type type);
 
 void module_call_init(module_init_type type);
 bool module_load_one(const char *prefix, const char *lib_name);
+void module_load_qom_one(const char *type);
+void module_load_qom_all(void);
 
 #endif
diff --git a/util/module.c b/util/module.c
index e48d9aacc05a..ee560a4b4269 100644
--- a/util/module.c
+++ b/util/module.c
@@ -245,3 +245,58 @@ bool module_load_one(const char *prefix, const char 
*lib_name)
 #endif
 return success;
 }
+
+/*
+ * Building devices and other qom objects modular is mostly useful in
+ * case they have dependencies to external shared libraries, so we can
+ * cut down the core qemu library dependencies.  Which is the case for
+ * only a very few devices & objects.
+ *
+ * So with the expectation that this will be rather the exception than
+ * to rule and the list will not gain that many entries go with a
+ * simple manually maintained list for now.
+ */
+static struct {
+const char *type;
+const char *prefix;
+const char *module;
+} const qom_modules[] = {
+};
+
+static bool module_loaded_qom_all;
+
+void module_load_qom_one(const char *type)
+{
+int i;
+
+if (module_loaded_qom_all) {
+return;
+}
+for (i = 0; i < ARRAY_SIZE(qom_modules); i++) {
+if (strcmp(qom_modules[i].type, type) == 0) {
+module_load_one(qom_modules[i].prefix,
+qom_modules[i].module);
+return;
+}
+}
+}
+
+void module_load_qom_all(void)
+{
+int i;
+
+if (module_loaded_qom_all) {
+return;
+}
+for (i = 0; i < ARRAY_SIZE(qom_modules); i++) {
+if (i > 0 && (strcmp(qom_modules[i - 1].module,
+ qom_modules[i].module) == 0 &&
+  strcmp(qom_modules[i - 1].prefix,
+ qom_modules[i].prefix) == 0)) {
+/* one module implementing multiple types -> load only once */
+continue;
+}
+module_load_one(qom_modules[i].prefix, qom_modules[i].module);
+}
+module_loaded_qom_all = true;
+}
-- 
2.18.4




[PATCH v5 00/10] build some devices as modules.

2020-06-24 Thread Gerd Hoffmann
Specifically devices which depend on shared libraries,
to reduce the runtime dependencies of core qemu.

v2:
 - better commit messages.
 - add some more devices.
 - general tidy up.

v3:
 - rebase, solve stubs conflict.
 - fix -vga $name
 - fix -device $name,help

v4:
 - rebase to latest master
 - adapt to armbru's device init changes

v5:
 - move from qdev (aka device) to qom (aka object) level.
 - add braille chardev.

Gerd Hoffmann (10):
  module: qom module support
  object: qom module support
  qdev: device module support
  build: fix device module builds
  ccid: build smartcard as module
  usb: build usb-redir as module
  vga: build qxl as module
  vga: build virtio-gpu only once
  vga: build virtio-gpu as module
  chardev: enable modules, use for braille

 Makefile.objs|  2 ++
 Makefile.target  |  7 +
 include/qemu/module.h|  2 ++
 include/qom/object.h | 12 +++
 chardev/char.c   |  2 +-
 hw/core/qdev.c   |  6 ++--
 qdev-monitor.c   |  5 +--
 qom/object.c | 14 +
 qom/qom-qmp-cmds.c   |  3 +-
 softmmu/vl.c |  4 +--
 util/module.c| 67 
 chardev/Makefile.objs|  5 ++-
 hw/Makefile.objs |  2 ++
 hw/display/Makefile.objs | 28 ++---
 hw/usb/Makefile.objs | 13 +---
 15 files changed, 148 insertions(+), 24 deletions(-)

-- 
2.18.4




Re: [PULL 25/31] osdep: Make MIN/MAX evaluate arguments only once

2020-06-24 Thread Philippe Mathieu-Daudé
On 6/24/20 2:13 PM, Eric Blake wrote:
> On 6/24/20 5:50 AM, Paolo Bonzini wrote:
>> From: Eric Blake 
>>
>> I'm not aware of any immediate bugs in qemu where a second runtime
>> evalution of the arguments to MIN() or MAX() causes a problem, but
> 
> evaluation
> 
>> Update the MIN/MAX macros to only evaluate their argument once at
>> runtime;
> 
>> Use of MIN when MIN_CONST is needed:
>>
>> In file included from /home/eblake/qemu/qemu-img.c:25:
>> /home/eblake/qemu/include/qemu/osdep.h:249:5: error: braced-group
>> within expression allowed only inside a function
>>    249 | ({  \
>>    | ^
>> /home/eblake/qemu/qemu-img.c:92:12: note: in expansion of macro ‘MIN’
> 
> UTF-8 mojibake in the commit message ;(

Oh, this is not a git-publish bug:
https://github.com/bonzini/qemu/commit/6f9ff58baae

> 
> 
>> Signed-off-by: Eric Blake 
>>
>> Message-Id: <20200604215236.2798244-1-ebl...@redhat.com>
>> Signed-off-by: Paolo Bonzini 
>> ---
> 
>> +#define MIN_CONST(a, b) \
>> +    __builtin_choose_expr(  \
>> +    __builtin_constant_p(a) && __builtin_constant_p(b), \
>> +    (a) < (b) ? (a) : (b),  \
>> +    ((void)0))
> 
> This one is correct...
> 
>> +#undef MAX
>> +#define MAX(a, b)   \
>> +    ({  \
>> +    typeof(1 ? (a) : (b)) _a = (a), _b = (b);   \
>> +    _a > _b ? _a : _b;  \
>> +    })
>> +#define MAX_CONST(a, b) \
>> +    __builtin_choose_expr(  \
>> +    __builtin_constant_p(a) && __builtin_constant_p(b), \
>> +    (a) > (b) ? (a) : (b),  \
>> +    __builtin_unreachable())
> 
> ...but this one should also use ((void)0), to match the commit message.
> 
>> +
>> +/* Minimum function that returns zero only if both values are zero.
>>    * Intended for use with unsigned values only. */
> 
> And checkpatch complains about the formatting here.
> 
> Ah well.  I had all these things fixed in my tree, but failed to post a
> v5.  Not worth holding up this pull request in isolation, but if there
> are any other build issues, I'll post a v5 of this patch, otherwise a
> followup.
> 




[PATCH v5 0/5] VIRTIO-IOMMU probe request support and MSI bypass on ARM

2020-06-24 Thread Eric Auger
By default the virtio-iommu translates MSI transactions. This
behavior is inherited from ARM SMMU. However the virt machine
code knows where the MSI doorbells are, so we can easily
declare those regions as VIRTIO_IOMMU_RESV_MEM_T_MSI. With that
setting the guest iommu subsystem will not need to map MSIs.
This setup will simplify the VFIO integration.

In this series, the ITS or GICV2M doorbells are declared as
HW MSI regions to be bypassed by the VIRTIO-IOMMU.

This also paves the way to the x86 integration where the MSI
region, [0xFEE0,0xFEEF], will be exposed by the q35
machine.  However this will be handled in a separate series
when not-DT support gets resolved.

Best Regards

Eric

This series can be found at:
https://github.com/eauger/qemu/tree/v5.0.0-virtio-iommu-msi-bypass-v5

History:

v4 -> v5:
- Take into account some additional comments from Markus:
  - reserved region type becomes an unsigned + some comment/desc
rewording
  - assert if the type is not RESERVED or MSI

v3 -> v4:
- collected Jean and markus's R-bs
- tool into account all Markus' comments in [1/5] (except removal of
  goto)
- use ':' as delimitor instead of commas
- add example in 4/5 commit message as suggested by Markus

v2 -> v3:
- Introduce VIRT_MSI_CTRL_NONE in VirtMSIControllerType
- do not fill the remainder of the probe buffer

v1 -> v2:
- check which MSI controller is in use and advertise the
  corresponding MSI doorbell
- managed for both ITS and GICv2M
- various fixes spotted by Peter and Jean-Philippe, see
  individual logs

v1: Most of those patches were respinned from
  [PATCH for-5.0 v11 00/20] VIRTIO-IOMMU device
  except the last one which is new


Eric Auger (5):
  qdev: Introduce DEFINE_PROP_RESERVED_REGION
  virtio-iommu: Implement RESV_MEM probe request
  virtio-iommu: Handle reserved regions in the translation process
  virtio-iommu-pci: Add array of Interval properties
  hw/arm/virt: Let the virtio-iommu bypass MSIs

 include/exec/memory.h|   6 ++
 include/hw/arm/virt.h|   7 ++
 include/hw/qdev-properties.h |   3 +
 include/hw/virtio/virtio-iommu.h |   2 +
 include/qemu/typedefs.h  |   1 +
 hw/arm/virt.c|  18 +
 hw/core/qdev-properties.c|  89 
 hw/virtio/virtio-iommu-pci.c |   3 +
 hw/virtio/virtio-iommu.c | 112 +--
 hw/virtio/trace-events   |   1 +
 10 files changed, 238 insertions(+), 4 deletions(-)

-- 
2.20.1




[PATCH v5 3/5] virtio-iommu: Handle reserved regions in the translation process

2020-06-24 Thread Eric Auger
When translating an address we need to check if it belongs to
a reserved virtual address range. If it does, there are 2 cases:

- it belongs to a RESERVED region: the guest should neither use
  this address in a MAP not instruct the end-point to DMA on
  them. We report an error

- It belongs to an MSI region: we bypass the translation.

Signed-off-by: Eric Auger 
Reviewed-by: Peter Xu 
Reviewed-by: Jean-Philippe Brucker 

---

v1 -> v2:
- use addr when testing addr belongs to the reserved region
  and use a block local variable
---
 hw/virtio/virtio-iommu.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index aabc3e36b1..d0541ec4ad 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -605,6 +605,7 @@ static IOMMUTLBEntry 
virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr,
 uint32_t sid, flags;
 bool bypass_allowed;
 bool found;
+int i;
 
 interval.low = addr;
 interval.high = addr + 1;
@@ -638,6 +639,25 @@ static IOMMUTLBEntry 
virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr,
 goto unlock;
 }
 
+for (i = 0; i < s->nb_reserved_regions; i++) {
+ReservedRegion *reg = >reserved_regions[i];
+
+if (addr >= reg->low && addr <= reg->high) {
+switch (reg->type) {
+case VIRTIO_IOMMU_RESV_MEM_T_MSI:
+entry.perm = flag;
+break;
+case VIRTIO_IOMMU_RESV_MEM_T_RESERVED:
+default:
+virtio_iommu_report_fault(s, VIRTIO_IOMMU_FAULT_R_MAPPING,
+  VIRTIO_IOMMU_FAULT_F_ADDRESS,
+  sid, addr);
+break;
+}
+goto unlock;
+}
+}
+
 if (!ep->domain) {
 if (!bypass_allowed) {
 error_report_once("%s %02x:%02x.%01x not attached to any domain",
-- 
2.20.1




Migration vmdesc and xen-save-devices-state

2020-06-24 Thread Jason Andryuk
Hi,

At some point, QEMU changed to add a json VM description (vmdesc)
after the migration data.  The vmdesc is not needed to restore the
migration data, but qemu_loadvm_state() will read and discard the
vmdesc to clear the stream when should_send_vmdesc() is true.

xen-save-devices-state generates its migration data without a vmdesc.
xen-load-devices-state in turn calls qemu_loadvm_state() which tries
to load vmdesc since should_send_vmdesc is true for xen.  When
restoring from a file, this is fine since it'll return EOF, print
"Expected vmdescription section, but got 0" and end the restore
successfully.

Linux stubdoms load their migration data over a console, so they don't
hit the EOF and end up waiting.  There does seem to be a timeout
though and restore continues after a delay, but we'd like to eliminate
the delay.

Two options to address this are to either:
1) set suppress_vmdesc for the Xen machines to bypass the
should_send_vmdesc() check.
or
2) just send the vmdesc data.

Since vmdesc is just discarded, maybe #1 should be followed.

If going with #2, qemu_save_device_state() needs to generate the
vmdesc data.  Looking at qemu_save_device_state() and
qemu_savevm_state_complete_precopy_non_iterable(), they are both very
similar and could seemingly be merged.  qmp_xen_save_devices_state()
could even leverage the bdrv_inactivate_all() call in
qemu_savevm_state_complete_precopy_non_iterable().

The would make qemu_save_device_state a little more heavywight, which
could impact COLO.  I'm not sure how performance sensitive the COLO
code is, and I haven't measured anything.

Does anyone have thoughts or opinions on the subject?

Thanks,
Jason



[PATCH v2 01/25] iotests: Fix 051 output after qdev_init_nofail() removal

2020-06-24 Thread Alex Bennée
From: Philippe Mathieu-Daudé 

Commit 96927c744 replaced qdev_init_nofail() call by
isa_realize_and_unref() which has a different error
message. Update the test output accordingly.

Gitlab CI error after merging b77b5b3dc7:
https://gitlab.com/qemu-project/qemu/-/jobs/597414772#L4375

Reported-by: Thomas Huth 
Signed-off-by: Philippe Mathieu-Daudé 
Signed-off-by: Alex Bennée 
Reviewed-by: John Snow 
Reviewed-by: Thomas Huth 
Message-Id: <20200616154949.6586-1-phi...@redhat.com>
---
 tests/qemu-iotests/051.pc.out | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/qemu-iotests/051.pc.out b/tests/qemu-iotests/051.pc.out
index 0ea80d35f0e..da8ad871876 100644
--- a/tests/qemu-iotests/051.pc.out
+++ b/tests/qemu-iotests/051.pc.out
@@ -142,7 +142,7 @@ QEMU X.Y.Z monitor - type 'help' for more information
 
 Testing: -drive if=ide
 QEMU X.Y.Z monitor - type 'help' for more information
-(qemu) QEMU_PROG: Initialization of device ide-hd failed: Device needs media, 
but drive is empty
+(qemu) QEMU_PROG: Device needs media, but drive is empty
 
 Testing: -drive if=virtio
 QEMU X.Y.Z monitor - type 'help' for more information
@@ -214,7 +214,7 @@ QEMU X.Y.Z monitor - type 'help' for more information
 
 Testing: -drive file=TEST_DIR/t.qcow2,if=ide,readonly=on
 QEMU X.Y.Z monitor - type 'help' for more information
-(qemu) QEMU_PROG: Initialization of device ide-hd failed: Block node is 
read-only
+(qemu) QEMU_PROG: Block node is read-only
 
 Testing: -drive file=TEST_DIR/t.qcow2,if=virtio,readonly=on
 QEMU X.Y.Z monitor - type 'help' for more information
-- 
2.20.1




[PATCH v2 02/25] crypto/linux_keyring: fix 'secret_keyring' configure test

2020-06-24 Thread Alex Bennée
From: David Edmondson 

The configure test for 'secret_keyring' incorrectly checked the
'have_keyring' variable.

Fixes: 54e7aac0562452e4fcab65ca5001d030eef2de15
Signed-off-by: David Edmondson 
Signed-off-by: Alex Bennée 
Message-Id: <20200618092636.71832-1-david.edmond...@oracle.com>
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index ba88fd18244..69ffd750dbc 100755
--- a/configure
+++ b/configure
@@ -6369,7 +6369,7 @@ EOF
 fi
 if test "$secret_keyring" != "no"
 then
-if test "$have_keyring" == "yes"
+if test "$have_keyring" = "yes"
 then
secret_keyring=yes
 else
-- 
2.20.1




[PATCH v2 04/25] tests/vm: Add configuration to basevm.py

2020-06-24 Thread Alex Bennée
From: 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 
Signed-off-by: Alex Bennée 
Message-Id: <20200601211421.1277-3-robert.fo...@linaro.org>
---
 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 5a58e6c3930..cfe20c58f7e 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",
-  

[PATCH v2 00/25] testing/next (vm, gitlab, docker)

2020-06-24 Thread Alex Bennée
Hi,

This is the current state of my testing/next queue. The main changes
from the last post:

  https://patchew.org/QEMU/20200622143204.12921-1-alex.ben...@linaro.org/

are the inclusion of Danial's excellent work to generate containers
which are stored in the gitlab registry and used as a basis for
the builds in gitlab (saving the manual apt/yum steps we used to do).

On top of those changes I've tried to tweak the tooling so a local
build can pull cached images from a REGISTRY. So far it doesn't seem
to be working although it does attempt to do it. I've included the
patches for review and in the hopes someone else can help debug what
else we need to do.

The following need review:

 - gitlab: split build-disabled into two phases
 - gitlab: enable check-tcg for linux-user tests
 - gitlab: add acceptance testing to system builds
 - tests/docker: add --registry support to tooling
 - gitlab: build containers with buildkit and metadata
 - .gitignore: un-ignore .gitlab-ci.d
 - tests/docker: change tag naming scheme of our images

Alex Bennée (11):
  tests/vm: switch from optsparse to argparse
  tests/vm: allow us to take advantage of MTTCG
  tests/docker: check for an parameters not empty string
  tests/docker: change tag naming scheme of our images
  .gitignore: un-ignore .gitlab-ci.d
  gitlab: build containers with buildkit and metadata
  tests/docker: add --registry support to tooling
  gitlab: add acceptance testing to system builds
  gitlab: enable check-tcg for linux-user tests
  gitlab: add avocado asset caching
  gitlab: split build-disabled into two phases

Daniel P. Berrangé (3):
  gitlab: introduce explicit "container" and "build" stages
  gitlab: build all container images during CI
  gitlab: convert jobs to use custom built containers

David Edmondson (1):
  crypto/linux_keyring: fix 'secret_keyring' configure test

Philippe Mathieu-Daudé (1):
  iotests: Fix 051 output after qdev_init_nofail() removal

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 |  31 +-
 .gitignore|   1 +
 .gitlab-ci.d/containers.yml   | 250 +
 .gitlab-ci.d/edk2.yml |   3 +-
 .gitlab-ci.d/opensbi.yml  |   3 +-
 .gitlab-ci.yml| 275 +--
 .travis.yml   |  23 --
 python/qemu/console_socket.py | 110 ++
 python/qemu/machine.py|  23 +-
 tests/docker/Makefile.include |   5 +-
 tests/docker/common.rc|   2 +-
 tests/docker/docker.py|  27 +-
 .../dockerfiles/debian-alpha-cross.docker |   2 +-
 .../dockerfiles/debian-amd64-cross.docker |   2 +-
 tests/docker/dockerfiles/debian-amd64.docker  |   2 +-
 .../dockerfiles/debian-arm64-cross.docker |   2 +-
 .../debian-arm64-test-cross.docker|   2 +-
 .../dockerfiles/debian-armel-cross.docker |   2 +-
 .../dockerfiles/debian-armhf-cross.docker |   2 +-
 .../dockerfiles/debian-hppa-cross.docker  |   2 +-
 .../dockerfiles/debian-m68k-cross.docker  |   2 +-
 .../dockerfiles/debian-mips-cross.docker  |   2 +-
 .../dockerfiles/debian-mips64-cross.docker|   2 +-
 .../dockerfiles/debian-mips64el-cross.docker  |   2 +-
 .../dockerfiles/debian-mipsel-cross.docker|   2 +-
 .../dockerfiles/debian-powerpc-cross.docker   |   2 +-
 .../dockerfiles/debian-ppc64-cross.docker |   2 +-
 .../dockerfiles/debian-ppc64el-cross.docker   |   2 +-
 .../dockerfiles/debian-riscv64-cross.docker   |   2 +-
 .../dockerfiles/debian-s390x-cross.docker |   2 +-
 .../dockerfiles/debian-sh4-cross.docker   |   2 +-
 .../dockerfiles/debian-sparc64-cross.docker   |   2 +-
 .../dockerfiles/debian-tricore-cross.docker   |   2 +-
 .../dockerfiles/debian-win32-cross.docker |   2 +-
 .../dockerfiles/debian-win64-cross.docker |   2 +-
 tests/docker/dockerfiles/debian9-mxe.docker   |   2 +-
 tests/qemu-iotests/051.pc.out |   4 +-
 tests/vm/Makefile.include |  22 ++
 tests/vm/aarch64vm.py | 106 ++
 tests/vm/basevm.py| 332 +-
 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 +-
 

[PATCH v2 05/25] tests/vm: Added configuration file support

2020-06-24 Thread Alex Bennée
From: 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 
Signed-off-by: Alex Bennée 
Message-Id: <20200601211421.1277-4-robert.fo...@linaro.org>
---
 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 69ffd750dbc..c1ec271931f 100755
--- a/configure
+++ b/configure
@@ -958,6 +958,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
@@ -6751,6 +6758,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"
@@ -7830,6 +7838,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 a253aba4579..f6c3892bb28 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 cfe20c58f7e..fa56fbbb4b6 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 

[PATCH v2 07/25] tests/vm: Added a new script for ubuntu.aarch64.

2020-06-24 Thread Alex Bennée
From: 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 
Signed-off-by: Alex Bennée 
Message-Id: <20200601211421.1277-6-robert.fo...@linaro.org>
---
 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 c1ec271931f..980a323ac7f 100755
--- a/configure
+++ b/configure
@@ -417,6 +417,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"
@@ -1107,6 +1108,8 @@ for opt do
   ;;
   --firmwarepath=*) firmwarepath="$optarg"
   ;;
+  --efi-aarch64=*) efi_aarch64="$optarg"
+  ;;
   --host=*|--build=*|\
   --disable-dependency-tracking|\
   --sbindir=*|--sharedstatedir=*|\
@@ -1777,6 +1780,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
@@ -3593,6 +3597,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
@@ -6758,6 +6776,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
@@ -7838,6 +7857,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 f6c3892bb28..4fa292765d5 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
   

Re: [PATCH v2 0/2] Avoid abort on QMP attempt to add an object with duplicate id

2020-06-24 Thread Auger Eric
Hi,

On 6/24/20 3:35 PM, no-re...@patchew.org wrote:
> Patchew URL: 
> https://patchew.org/QEMU/20200624124301.7112-1-eric.au...@redhat.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 ===
> 
>   TESTiotest-qcow2: 114
>   TESTiotest-qcow2: 117
> **
> ERROR:/tmp/qemu-test/src/tests/qtest/qmp-cmd-test.c:225:test_object_add_with_duplicate_id:
>  assertion failed: (qdict_haskey(resp, "return"))
> ERROR - Bail out! 
> ERROR:/tmp/qemu-test/src/tests/qtest/qmp-cmd-test.c:225:test_object_add_with_duplicate_id:
>  assertion failed: (qdict_haskey(resp, "return"))
> make: *** [check-qtest-aarch64] Error 1
> make: *** Waiting for unfinished jobs
>   TESTiotest-qcow2: 120
>   TESTiotest-qcow2: 126
> ---
>   TESTcheck-qtest-x86_64: tests/qtest/qmp-test
>   TESTcheck-qtest-x86_64: tests/qtest/qmp-cmd-test
> **
> ERROR:/tmp/qemu-test/src/tests/qtest/qmp-cmd-test.c:225:test_object_add_with_duplicate_id:
>  assertion failed: (qdict_haskey(resp, "return"))
> ERROR - Bail out! 
> ERROR:/tmp/qemu-test/src/tests/qtest/qmp-cmd-test.c:225:test_object_add_with_duplicate_id:
>  assertion failed: (qdict_haskey(resp, "return"))
> make: *** [check-qtest-x86_64] Error 1
>   TESTiotest-qcow2: 220
>   TESTiotest-qcow2: 226
>   TESTiotest-qcow2: 229
> ---
> raise CalledProcessError(retcode, cmd)
> subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', 
> '--label', 'com.qemu.instance.uuid=d6cb3d069c7a44ecbf5b02c17a39e884', '-u', 
> '1003', '--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/patchew2/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', 
> '/var/tmp/patchew-tester-tmp-litaiimt/src/docker-src.2020-06-24-09.18.47.9149:/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=d6cb3d069c7a44ecbf5b02c17a39e884
> make[1]: *** [docker-run] Error 1
> make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-litaiimt/src'
> make: *** [docker-run-test-quick@centos7] Error 2
> 
> real16m25.200s
> user0m5.519s
> 
> 
> The full log is available at
> http://patchew.org/logs/20200624124301.7112-1-eric.au...@redhat.com/testing.docker-quick@centos7/?type=message.
> ---
> Email generated automatically by Patchew [https://patchew.org/].
> Please send your feedback to patchew-de...@redhat.com
> 
Hum, time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1

passes for me, run on top of 2/2.

I don't get what's wrong here?

Eric





Building plugin failed on Windows with mingw

2020-06-24 Thread casmac
Hi all,
 I want to build QEMU 4.2.0 with the plugin module on Windows 7 with 
Mingw, but the building process faild.

The step I follow is listed below:
1. create "dsp_build" diretory under source file folder


2. change directory to dsp_build , and run ../configure 
--target-list=dsp-softmmu --cross-prefix=x86_64-w64-mingw32- --enable-gtk 
--enable-sdl --enable-debug --enable-plugins
3. build qemu project
4. make -C tests/plugin, yeilds error:
 CC   bb.o
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:17:24:
 error: variable 'qemu_plugin_version' definition is marked dllimport
 17 | QEMU_PLUGIN_EXPORT int qemu_plugin_version = 
QEMU_PLUGIN_VERSION;
   |
^~~
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:17:24:
 warning: 'qemu_plugin_version' redeclared without dllimport attribute: 
previous dllimport ignored [-Wattributes]
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c: In 
function 'vcpu_tb_exec':
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:33:29:
 warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
 33 |  unsigned long n_insns = (unsigned 
long)udata;
   |
  ^
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c: In 
function 'vcpu_tb_trans':
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:51:46:
 warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
 51 | 
   
   (void *)n_insns);


5. Then , I modified the QEMU_flags and the compilation command 
arguments($(CC) ..) in the makefile :


BUILD_DIR := $(CURDIR)/../..


include $(BUILD_DIR)/config-host.mak
include $(SRC_PATH)/rules.mak


$(call set-vpath, $(SRC_PATH)/tests/plugin)


NAMES :=
NAMES += bb
NAMES += empty
NAMES += insn
NAMES += mem
NAMES += hotblocks
NAMES += howvec
NAMES += hotpages


SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES)))


QEMU_CFLAGS += -fPIC -DBUILDING_DLL   
#added -DBUILDING_DLL
QEMU_CFLAGS += -I$(SRC_PATH)/include/qemu


all: $(SONAMES)


lib%.so: %.o
$(CC) -fPIC -shared -o $@ $^ $(LDLIBS) -L 
/c/msys64/mingw64/lib/ -lglib-2.0
# origianl: $(CC) -shared -Wl,-soname,$@ -o $@ $^ 
$(LDLIBS)


clean:
rm -f *.o *.so *.d
rm -Rf .libs


.PHONY: all clean


6. Executing make yeilds:


make: enter 
??/d/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/build_dsp/tests/plugin??
 CC   bb.o
x86_64-w64-mingw32-gcc -fPIC -shared -o libbb.so bb.o -L 
/c/msys64/mingw64/lib/ -lglib-2.0
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 bb.o: in function `plugin_exit':
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:28: 
undefined reference to `qemu_plugin_outs'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:29: 
undefined reference to `__stack_chk_fail'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 bb.o: in function `vcpu_tb_trans':
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:41: 
undefined reference to `qemu_plugin_tb_n_insns'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:44: 
undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:46: 
undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:49: 
undefined reference to `qemu_plugin_register_vcpu_tb_exec_cb'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 bb.o: in function `qemu_plugin_install':
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:63: 
undefined reference to `qemu_plugin_register_vcpu_tb_trans_cb'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:64: 
undefined reference to `qemu_plugin_register_atexit_cb'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 

[RFC v5 12/12] pc-bios: s390x: Cleanup jump to ipl code

2020-06-24 Thread Janosch Frank
jump_to_IPL_code takes a 64 bit address, masks it with the short psw
address mask and later branches to it using a full 64 bit register.

* As the masking is not necessary, let's remove it
* Without the mask we can save the ipl address to a static 64 bit
  function ptr as we later branch to it
* Let's also clean up the variable names and remove the now unneeded
  ResetInfo

Signed-off-by: Janosch Frank 
---
 pc-bios/s390-ccw/jump2ipl.c | 27 +++
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/pc-bios/s390-ccw/jump2ipl.c b/pc-bios/s390-ccw/jump2ipl.c
index 767012bf0c..aef37cea76 100644
--- a/pc-bios/s390-ccw/jump2ipl.c
+++ b/pc-bios/s390-ccw/jump2ipl.c
@@ -13,20 +13,15 @@
 #define KERN_IMAGE_START 0x01UL
 #define RESET_PSW_MASK (PSW_MASK_SHORTPSW | PSW_MASK_64)
 
-typedef struct ResetInfo {
-uint64_t ipl_psw;
-uint32_t ipl_continue;
-} ResetInfo;
-
-static ResetInfo save;
+static void (*ipl_continue)(void);
+static uint64_t psw_save;
 
 static void jump_to_IPL_2(void)
 {
-ResetInfo *current = 0;
+uint64_t *psw_current = 0;
 
-void (*ipl)(void) = (void *) (uint64_t) current->ipl_continue;
-*current = save;
-ipl(); /* should not return */
+*psw_current = psw_save;
+ipl_continue(); /* should not return */
 }
 
 void jump_to_IPL_code(uint64_t address)
@@ -46,15 +41,15 @@ void jump_to_IPL_code(uint64_t address)
  * content of non-BIOS memory after we loaded the guest, so we
  * save the original content and restore it in jump_to_IPL_2.
  */
-ResetInfo *current = 0;
+uint64_t *psw_current = 0;
 
-save = *current;
+psw_save = *psw_current;
 
-current->ipl_psw = (uint64_t) _to_IPL_2;
-current->ipl_psw |= RESET_PSW_MASK;
-current->ipl_continue = address & PSW_MASK_SHORT_ADDR;
+*psw_current = (uint64_t) _to_IPL_2;
+*psw_current |= RESET_PSW_MASK;
+ipl_continue = (void *)address;
 
-debug_print_int("set IPL addr to", current->ipl_continue);
+debug_print_int("set IPL addr to", (uint64_t)ipl_continue);
 
 /* Ensure the guest output starts fresh */
 sclp_print("\n");
-- 
2.25.1




Re: [PATCH v4 1/5] qdev: Introduce DEFINE_PROP_RESERVED_REGION

2020-06-24 Thread Markus Armbruster
Auger Eric  writes:

> Hi Markus,
>
> On 6/23/20 5:13 PM, Markus Armbruster wrote:
>> Eric Auger  writes:
>> 
>>> Introduce a new property defining a reserved region:
>>> ::.
>>>
>>> This will be used to encode reserved IOVA regions.
>>>
>>> For instance, in virtio-iommu use case, reserved IOVA regions
>>> will be passed by the machine code to the virtio-iommu-pci
>>> device (an array of those). The type of the reserved region
>>> will match the virtio_iommu_probe_resv_mem subtype value:
>>> - VIRTIO_IOMMU_RESV_MEM_T_RESERVED (0)
>>> - VIRTIO_IOMMU_RESV_MEM_T_MSI (1)
>>>
>>> on PC/Q35 machine, this will be used to inform the
>>> virtio-iommu-pci device it should bypass the MSI region.
>>> The reserved region will be: 0xfee0:0xfeef:1.
>>>
>>> On ARM, we can declare the ITS MSI doorbell as an MSI
>>> region to prevent MSIs from being mapped on guest side.
>>>
>>> Signed-off-by: Eric Auger 
>>> Reviewed-by: Markus Armbruster 
>>>
>>> ---
>>>
>>> v3 -> v4:
>>> - use ':' instead of commas as separators.
>>> - rearrange error messages
>>> - check snprintf returned value
>>> - dared to keep Markus' R-b despite those changes
>>> ---
>>>  include/exec/memory.h|  6 +++
>>>  include/hw/qdev-properties.h |  3 ++
>>>  include/qemu/typedefs.h  |  1 +
>>>  hw/core/qdev-properties.c| 89 
>>>  4 files changed, 99 insertions(+)
>>>
>>> diff --git a/include/exec/memory.h b/include/exec/memory.h
>>> index 7207025bd4..d7a53b96cc 100644
>>> --- a/include/exec/memory.h
>>> +++ b/include/exec/memory.h
>>> @@ -51,6 +51,12 @@ extern bool global_dirty_log;
>>>  
>>>  typedef struct MemoryRegionOps MemoryRegionOps;
>>>  
>>> +struct ReservedRegion {
>>> +hwaddr low;
>>> +hwaddr high;
>>> +unsigned int type;
>> 
>> Suggest to s/unsigned int/unsigned/.
>> 
>>> +};
>>> +
>>>  typedef struct IOMMUTLBEntry IOMMUTLBEntry;
>>>  
>>>  /* See address_space_translate: bit 0 is read, bit 1 is write.  */
>>> diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
>>> index 5252bb6b1a..95d0e7201d 100644
>>> --- a/include/hw/qdev-properties.h
>>> +++ b/include/hw/qdev-properties.h
>>> @@ -19,6 +19,7 @@ extern const PropertyInfo qdev_prop_string;
>>>  extern const PropertyInfo qdev_prop_chr;
>>>  extern const PropertyInfo qdev_prop_tpm;
>>>  extern const PropertyInfo qdev_prop_macaddr;
>>> +extern const PropertyInfo qdev_prop_reserved_region;
>>>  extern const PropertyInfo qdev_prop_on_off_auto;
>>>  extern const PropertyInfo qdev_prop_multifd_compression;
>>>  extern const PropertyInfo qdev_prop_losttickpolicy;
>>> @@ -184,6 +185,8 @@ extern const PropertyInfo qdev_prop_pcie_link_width;
>>>  DEFINE_PROP(_n, _s, _f, qdev_prop_drive_iothread, BlockBackend *)
>>>  #define DEFINE_PROP_MACADDR(_n, _s, _f) \
>>>  DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
>>> +#define DEFINE_PROP_RESERVED_REGION(_n, _s, _f) \
>>> +DEFINE_PROP(_n, _s, _f, qdev_prop_reserved_region, ReservedRegion)
>>>  #define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \
>>>  DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto)
>>>  #define DEFINE_PROP_MULTIFD_COMPRESSION(_n, _s, _f, _d) \
>>> diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h
>>> index ce4a78b687..15f5047bf1 100644
>>> --- a/include/qemu/typedefs.h
>>> +++ b/include/qemu/typedefs.h
>>> @@ -58,6 +58,7 @@ typedef struct ISABus ISABus;
>>>  typedef struct ISADevice ISADevice;
>>>  typedef struct IsaDma IsaDma;
>>>  typedef struct MACAddr MACAddr;
>>> +typedef struct ReservedRegion ReservedRegion;
>>>  typedef struct MachineClass MachineClass;
>>>  typedef struct MachineState MachineState;
>>>  typedef struct MemoryListener MemoryListener;
>>> diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
>>> index ead35d7ffd..193d0d95f9 100644
>>> --- a/hw/core/qdev-properties.c
>>> +++ b/hw/core/qdev-properties.c
>>> @@ -15,6 +15,7 @@
>>>  #include "chardev/char.h"
>>>  #include "qemu/uuid.h"
>>>  #include "qemu/units.h"
>>> +#include "qemu/cutils.h"
>>>  
>>>  void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
>>>Error **errp)
>>> @@ -578,6 +579,94 @@ const PropertyInfo qdev_prop_macaddr = {
>>>  .set   = set_mac,
>>>  };
>>>  
>>> +/* --- Reserved Region --- */
>>> +
>>> +/*
>>> + * accepted syntax version:
>> 
>> "version" feels redundant.  Suggest to capitalize "Accepted".
>> 
>>> + *   ::
>>> + *   where low/high addresses are uint64_t in hexadecimal
>>> + *   and type is an unsigned integer in decimal
>>> + */
>>> +static void get_reserved_region(Object *obj, Visitor *v, const char *name,
>>> +void *opaque, Error **errp)
>>> +{
>>> +DeviceState *dev = DEVICE(obj);
>>> +Property *prop = opaque;
>>> +ReservedRegion *rr = qdev_get_prop_ptr(dev, prop);
>>> +char buffer[64];
>>> +char *p = buffer;
>>> +int rc;
>>> +
>>> +rc = snprintf(buffer, 

[PATCH] trivial: Remove extra character in configure help

2020-06-24 Thread Christophe de Dinechin
Signed-off-by: Christophe de Dinechin 
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index ba88fd1824..c7a6a5adfe 100755
--- a/configure
+++ b/configure
@@ -1787,7 +1787,7 @@ Advanced options (experts only):
   --block-drv-ro-whitelist=L
set block driver read-only whitelist
(affects only QEMU, not qemu-img)
-  --enable-trace-backends=B Set trace backend
+  --enable-trace-backends= Set trace backend
Available backends: $trace_backend_list
   --with-trace-file=NAME   Full PATH,NAME of file to store traces
Default:trace-
-- 
2.26.2




Re: [PATCH] i386: Mask SVM features if nested SVM is disabled

2020-06-24 Thread Paolo Bonzini
On 24/06/20 01:01, Eduardo Habkost wrote:
> QEMU incorrectly validates FEAT_SVM feature flags against
> GET_SUPPORTED_CPUID even if SVM features are being masked out by
> cpu_x86_cpuid().  This can make QEMU print warnings on most AMD
> CPU models, even when SVM nesting is disabled (which is the
> default).
> 
> This bug was never detected before because of a Linux KVM bug:
> until Linux v5.6, KVM was not filtering out SVM features in
> GET_SUPPORTED_CPUID when nested was disabled.  This KVM bug was
> fixed in Linux v5.7-rc1, on Linux commit a50718cc3f43 ("KVM:
> nSVM: Expose SVM features to L1 iff nested is enabled").
> 
> Fix the problem by adding a CPUID_EXT3_SVM dependency to all
> FEAT_SVM feature flags in the feature_dependencies table.
> 
> Reported-by: Yanan Fu 
> Signed-off-by: Eduardo Habkost 
> ---
>  target/i386/cpu.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index b1b311baa2..a9edcaf531 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -1404,6 +1404,10 @@ static FeatureDep feature_dependencies[] = {
>  .from = { FEAT_VMX_SECONDARY_CTLS,  VMX_SECONDARY_EXEC_ENABLE_VMFUNC 
> },
>  .to = { FEAT_VMX_VMFUNC,~0ull },
>  },
> +{
> +.from = { FEAT_8000_0001_ECX,   CPUID_EXT3_SVM },
> +.to = { FEAT_SVM,   ~0ull },
> +},
>  };
>  
>  typedef struct X86RegisterInfo32 {
> 

Queued with this fixup:

diff --git a/tests/qtest/test-x86-cpuid-compat.c 
b/tests/qtest/test-x86-cpuid-compat.c
index 772287bdb4..8709e7d9ce 100644
--- a/tests/qtest/test-x86-cpuid-compat.c
+++ b/tests/qtest/test-x86-cpuid-compat.c
@@ -256,7 +256,7 @@ int main(int argc, char **argv)
"-cpu 486,+invtsc", "xlevel", 0x8007);
 /* CPUID[8000_000A].EDX: */
 add_cpuid_test("x86/cpuid/auto-xlevel/486/npt",
-   "-cpu 486,+npt", "xlevel", 0x800A);
+   "-cpu 486,+svm,+npt", "xlevel", 0x800A);
 /* CPUID[C000_0001].EDX: */
 add_cpuid_test("x86/cpuid/auto-xlevel2/phenom/xstore",
"-cpu phenom,+xstore", "xlevel2", 0xC001);
@@ -348,7 +348,7 @@ int main(int argc, char **argv)
"-machine pc-i440fx-2.4 -cpu SandyBridge,",
"xlevel", 0x8008);
 add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.4/npt-on",
-   "-machine pc-i440fx-2.4 -cpu SandyBridge,+npt",
+   "-machine pc-i440fx-2.4 -cpu SandyBridge,+svm,+npt",
"xlevel", 0x8008);
 
 /* Test feature parsing */

Paolo




Re: -enablefips

2020-06-24 Thread Markus Armbruster
Gerd Hoffmann  writes:

> On Tue, Jun 23, 2020 at 11:51:09PM -0400, John Snow wrote:
>> I never knew what this option did, but the answer is ... strange!
>> 
>> It's only defined for linux, in os-posix.c. When called, it calls
>> fips_set_state(true), located in osdep.c.
>> 
>> This will read /proc/sys/crypto/fips_enabled and set the static global
>> 'fips_enabled' to true if this setting is on.
>
> IIRC the idea is to have a global switch to enable fips compilance for
> the whole distro.  RH specific.  rhel-7 kernel has it.  rhel-8 kernel
> too, so it probably isn't obsolete.  Not present in mainline kernels.
>
> I'm wondering what the point of the -enablefips switch is.  Shouldn't
> qemu check /proc/sys/crypto/fips_enabled unconditionally instead?

The switch feels rather silly to me.  If you take the trouble to put
your host in FIPS mode, requiring -enable-fips to make QEMU to actually
honor it makes no sense.  If you don't, QEMU's -enable-fips has no
effect.

I may well misremember things (it's been years), but I vaguely recall
-enable-fips being a lame compromise between "this ought to be upstream"
and "FIPS is stupid, and I want nothing of it".

>> (Tangent: what does *this* setting actually control? Should QEMU
>> meaningfully change its behavior when it's set?)
>
> fips is a security policy ...
>
>> This static global is exposed via the getter fips_get_state(). This
>> function is called only by vnc.c, and appears to disable the use of the
>> password option for -vnc.
>
> ... yes, "no passwords" is one of the rules.  There are probably more.
>
>> (If we really do want to keep it, it should probably go under -global
>> somewhere instead to help reduce flag clutter, but we'd need to have a
>> chat about what fips compliance means for literally every other spot in
>> QEMU that is capable of using or receiving a cleartext password.)
>
> Yep.  IIRC for spice this is handled in libspice-server.  We need to
> look at blockdev encryption I guess.  Any other places where qemu uses
> passwords directly?  I think we don't have to worry about indirect usage
> (sasl).

I'd expect the SASL libraries to honor FIPS mode by themselves.  But
best ask someone who actually knows how FIPS mode is supposed to work.




Re: [PATCH] trivial: Remove extra character in configure help

2020-06-24 Thread Christophe de Dinechin
Please ignore. The =B appears intentional, even if it offsets the whole help 
text.

Maybe replace with =L to indicate a list is expected?

> On 24 Jun 2020, at 10:33, Christophe de Dinechin  wrote:
> 
> Signed-off-by: Christophe de Dinechin 
> ---
> configure | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/configure b/configure
> index ba88fd1824..c7a6a5adfe 100755
> --- a/configure
> +++ b/configure
> @@ -1787,7 +1787,7 @@ Advanced options (experts only):
>   --block-drv-ro-whitelist=L
>set block driver read-only whitelist
>(affects only QEMU, not qemu-img)
> -  --enable-trace-backends=B Set trace backend
> +  --enable-trace-backends= Set trace backend
>Available backends: $trace_backend_list
>   --with-trace-file=NAME   Full PATH,NAME of file to store traces
>Default:trace-
> -- 
> 2.26.2
> 
> 




[PATCH v2 11/25] vnc: Plug minor memory leak in vnc_display_open()

2020-06-24 Thread Markus Armbruster
vnc_display_print_local_addr() leaks the Error object when
qio_channel_socket_get_local_address() fails.  Seems unlikely.  Called
when we create a VNC display with vnc_display_open().  Plug the leak
by passing NULL to ignore the error.

Cc: Daniel P. Berrange 
Cc: Gerd Hoffmann 
Signed-off-by: Markus Armbruster 
---
 ui/vnc.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index 0702a76cce..527ad25124 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -3274,13 +3274,12 @@ int vnc_display_pw_expire(const char *id, time_t 
expires)
 static void vnc_display_print_local_addr(VncDisplay *vd)
 {
 SocketAddress *addr;
-Error *err = NULL;
 
 if (!vd->listener || !vd->listener->nsioc) {
 return;
 }
 
-addr = qio_channel_socket_get_local_address(vd->listener->sioc[0], );
+addr = qio_channel_socket_get_local_address(vd->listener->sioc[0], NULL);
 if (!addr) {
 return;
 }
-- 
2.26.2




[PATCH v2 18/25] riscv_hart: Fix riscv_harts_realize() error API violations

2020-06-24 Thread Markus Armbruster
The Error ** argument must be NULL, _abort, _fatal, or a
pointer to a variable containing NULL.  Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call.

riscv_harts_realize() is wrong that way: it passes @errp to
riscv_hart_realize() in a loop.  I can't tell offhand whether this can
fail.

Fix by checking for failure in each iteration.

Cc: Palmer Dabbelt 
Cc: Alistair Francis 
Cc: Sagar Karandikar 
Cc: Bastian Koppelmann 
Cc: Bin Meng 
Cc: qemu-ri...@nongnu.org
Signed-off-by: Markus Armbruster 
Reviewed-by: Alistair Francis 
---
 hw/riscv/riscv_hart.c | 14 +-
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/hw/riscv/riscv_hart.c b/hw/riscv/riscv_hart.c
index e26c382259..f59fe52f0f 100644
--- a/hw/riscv/riscv_hart.c
+++ b/hw/riscv/riscv_hart.c
@@ -40,19 +40,13 @@ static void riscv_harts_cpu_reset(void *opaque)
 cpu_reset(CPU(cpu));
 }
 
-static void riscv_hart_realize(RISCVHartArrayState *s, int idx,
+static bool riscv_hart_realize(RISCVHartArrayState *s, int idx,
char *cpu_type, Error **errp)
 {
-Error *err = NULL;
-
 object_initialize_child(OBJECT(s), "harts[*]", >harts[idx], cpu_type);
 s->harts[idx].env.mhartid = s->hartid_base + idx;
 qemu_register_reset(riscv_harts_cpu_reset, >harts[idx]);
-qdev_realize(DEVICE(>harts[idx]), NULL, );
-if (err) {
-error_propagate(errp, err);
-return;
-}
+return qdev_realize(DEVICE(>harts[idx]), NULL, errp);
 }
 
 static void riscv_harts_realize(DeviceState *dev, Error **errp)
@@ -63,7 +57,9 @@ static void riscv_harts_realize(DeviceState *dev, Error 
**errp)
 s->harts = g_new0(RISCVCPU, s->num_harts);
 
 for (n = 0; n < s->num_harts; n++) {
-riscv_hart_realize(s, n, s->cpu_type, errp);
+if (!riscv_hart_realize(s, n, s->cpu_type, errp)) {
+return;
+}
 }
 }
 
-- 
2.26.2




[PATCH v2 25/25] arm/{bcm2835, fsl-imx25, fsl-imx6}: Fix realize error API violations

2020-06-24 Thread Markus Armbruster
The Error ** argument must be NULL, _abort, _fatal, or a
pointer to a variable containing NULL.  Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call.

bcm2835_peripherals_realize(), fsl_imx25_realize() and
fsl_imx6_realize() are wrong that way: they pass  to
object_property_set_uint() and object_property_set_bool() without
checking it, and then to sysbus_realize().  Harmless, because the
former can't actually fail here.

Fix by passing _abort instead.

Cc: Peter Maydell 
Cc: Andrew Baumann 
Cc: "Philippe Mathieu-Daudé" 
Cc: Jean-Christophe Dubois 
Cc: qemu-...@nongnu.org
Signed-off-by: Markus Armbruster 
---
 hw/arm/bcm2835_peripherals.c | 12 
 hw/arm/fsl-imx25.c   | 12 +---
 hw/arm/fsl-imx6.c| 12 +---
 3 files changed, 14 insertions(+), 22 deletions(-)

diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c
index 1e975d7eec..7ffdf62067 100644
--- a/hw/arm/bcm2835_peripherals.c
+++ b/hw/arm/bcm2835_peripherals.c
@@ -283,16 +283,12 @@ static void bcm2835_peripherals_realize(DeviceState *dev, 
Error **errp)
  * For the exact details please refer to the Arasan documentation:
  *   SD3.0_Host_AHB_eMMC4.4_Usersguide_ver5.9_jan11_10.pdf
  */
-object_property_set_uint(OBJECT(>sdhci), 3, "sd-spec-version", );
+object_property_set_uint(OBJECT(>sdhci), 3, "sd-spec-version",
+ _abort);
 object_property_set_uint(OBJECT(>sdhci), BCM2835_SDHC_CAPAREG, 
"capareg",
- );
+ _abort);
 object_property_set_bool(OBJECT(>sdhci), true, "pending-insert-quirk",
- );
-if (err) {
-error_propagate(errp, err);
-return;
-}
-
+ _abort);
 sysbus_realize(SYS_BUS_DEVICE(>sdhci), );
 if (err) {
 error_propagate(errp, err);
diff --git a/hw/arm/fsl-imx25.c b/hw/arm/fsl-imx25.c
index f32f9bce0f..7ab5c98fbe 100644
--- a/hw/arm/fsl-imx25.c
+++ b/hw/arm/fsl-imx25.c
@@ -260,15 +260,13 @@ static void fsl_imx25_realize(DeviceState *dev, Error 
**errp)
 };
 
 object_property_set_uint(OBJECT(>esdhc[i]), 2, "sd-spec-version",
- );
+ _abort);
 object_property_set_uint(OBJECT(>esdhc[i]), 
IMX25_ESDHC_CAPABILITIES,
- "capareg", );
+ "capareg",
+ _abort);
 object_property_set_uint(OBJECT(>esdhc[i]), SDHCI_VENDOR_IMX,
- "vendor", );
-if (err) {
-error_propagate(errp, err);
-return;
-}
+ "vendor",
+ _abort);
 sysbus_realize(SYS_BUS_DEVICE(>esdhc[i]), );
 if (err) {
 error_propagate(errp, err);
diff --git a/hw/arm/fsl-imx6.c b/hw/arm/fsl-imx6.c
index d4bc4fae93..4ae3c3efc2 100644
--- a/hw/arm/fsl-imx6.c
+++ b/hw/arm/fsl-imx6.c
@@ -336,15 +336,13 @@ static void fsl_imx6_realize(DeviceState *dev, Error 
**errp)
 
 /* UHS-I SDIO3.0 SDR104 1.8V ADMA */
 object_property_set_uint(OBJECT(>esdhc[i]), 3, "sd-spec-version",
- );
+ _abort);
 object_property_set_uint(OBJECT(>esdhc[i]), IMX6_ESDHC_CAPABILITIES,
- "capareg", );
+ "capareg",
+ _abort);
 object_property_set_uint(OBJECT(>esdhc[i]), SDHCI_VENDOR_IMX,
- "vendor", );
-if (err) {
-error_propagate(errp, err);
-return;
-}
+ "vendor",
+ _abort);
 sysbus_realize(SYS_BUS_DEVICE(>esdhc[i]), );
 if (err) {
 error_propagate(errp, err);
-- 
2.26.2




Re: [PATCH] trivial: Remove extra character in configure help

2020-06-24 Thread Daniel P . Berrangé
On Wed, Jun 24, 2020 at 10:33:37AM +0200, Christophe de Dinechin wrote:
> Signed-off-by: Christophe de Dinechin 
> ---
>  configure | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/configure b/configure
> index ba88fd1824..c7a6a5adfe 100755
> --- a/configure
> +++ b/configure
> @@ -1787,7 +1787,7 @@ Advanced options (experts only):
>--block-drv-ro-whitelist=L
> set block driver read-only whitelist
> (affects only QEMU, not qemu-img)
> -  --enable-trace-backends=B Set trace backend
> +  --enable-trace-backends= Set trace backend

This is just following the style of the option above. "B" is a
placeholder for the desired backend(s).

> Available backends: $trace_backend_list
>--with-trace-file=NAME   Full PATH,NAME of file to store traces
> Default:trace-


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




Re: [PATCH] MAINTAINERS: Cover pip requirements.txt

2020-06-24 Thread Philippe Mathieu-Daudé
Cleber are you OK with this?

On 6/5/20 6:37 PM, Philippe Mathieu-Daudé wrote:
> Add an entry in 'Python scripts' to cover the requirements.txt
> file added in commit 213137217a6 (this file contains a list of
> Python packages used by our test suite).
> 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  MAINTAINERS | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 3e7d9cb0a5..fc4148fba3 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -2219,6 +2219,7 @@ S: Odd fixes
>  F: python/qemu/*py
>  F: scripts/*.py
>  F: tests/*.py
> +F: tests/requirements.txt
>  
>  Benchmark util
>  M: Vladimir Sementsov-Ogievskiy 
> 




[PATCH v4 19/20] pcspk: update docs/system/target-i386-desc.rst.inc

2020-06-24 Thread Gerd Hoffmann
Add PC speaker with config hints.

Signed-off-by: Gerd Hoffmann 
---
 docs/system/target-i386-desc.rst.inc | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/docs/system/target-i386-desc.rst.inc 
b/docs/system/target-i386-desc.rst.inc
index 47a169e0ae2a..7d1fffacbea3 100644
--- a/docs/system/target-i386-desc.rst.inc
+++ b/docs/system/target-i386-desc.rst.inc
@@ -31,6 +31,8 @@ The QEMU PC System emulator simulates the following 
peripherals:
 
 -  CS4231A compatible sound card
 
+-  PC speaker
+
 -  PCI UHCI, OHCI, EHCI or XHCI USB controller and a virtual USB-1.1
hub.
 
@@ -49,7 +51,7 @@ must be told to not have parallel ports to have working GUS.
 
 .. parsed-literal::
 
-   |qemu_system_x86| dos.img -soundhw gus -parallel none
+   |qemu_system_x86| dos.img -device gus -parallel none
 
 Alternatively:
 
@@ -60,3 +62,12 @@ Alternatively:
 Or some other unclaimed IRQ.
 
 CS4231A is the chip used in Windows Sound System and GUSMAX products
+
+The PC speaker audio device can be configured using the pcspk-audiodev
+machine property, i.e.
+
+.. parsed-literal::
+
+   |qemu_system_x86| some.img \
+   -audiodev ,id= \
+   -machine pcspk-audiodev=
-- 
2.18.4




[PATCH v4 18/20] audio: add soundhw deprecation notice

2020-06-24 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann 
---
 docs/system/deprecated.rst | 9 +
 1 file changed, 9 insertions(+)

diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
index 3a255591c341..4cbf3bba3944 100644
--- a/docs/system/deprecated.rst
+++ b/docs/system/deprecated.rst
@@ -82,6 +82,15 @@ should specify an ``audiodev=`` property.  Additionally, 
when using
 vnc, you should specify an ``audiodev=`` propery if you plan to
 transmit audio through the VNC protocol.
 
+Creating sound card devices using ``-soundhw`` (since 5.1)
+''
+
+Sound card devices should be created using ``-device`` instead.  The
+names are the same for most devices.  The exceptions are ``hda`` which
+needs two devices (``-device intel-hda --device hda-duplex``) and
+``pcspk`` which can be activated using ``-machine
+pcspk-audiodev=``.
+
 ``-mon ...,control=readline,pretty=on|off`` (since 4.1)
 '''
 
-- 
2.18.4




[PATCH v4 06/20] audio: deprecate -soundhw adlib

2020-06-24 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().
Remove the now obsolete init function.

Signed-off-by: Gerd Hoffmann 
---
 hw/audio/adlib.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/hw/audio/adlib.c b/hw/audio/adlib.c
index 7c3b67dcfb8c..65dff5b6fca4 100644
--- a/hw/audio/adlib.c
+++ b/hw/audio/adlib.c
@@ -319,16 +319,10 @@ static const TypeInfo adlib_info = {
 .class_init= adlib_class_initfn,
 };
 
-static int Adlib_init (ISABus *bus)
-{
-isa_create_simple (bus, TYPE_ADLIB);
-return 0;
-}
-
 static void adlib_register_types (void)
 {
 type_register_static (_info);
-isa_register_soundhw("adlib", ADLIB_DESC, Adlib_init);
+deprecated_register_soundhw("adlib", ADLIB_DESC, 1, TYPE_ADLIB);
 }
 
 type_init (adlib_register_types)
-- 
2.18.4




[PATCH v4 17/20] audio: deprecate -soundhw pcspk

2020-06-24 Thread Gerd Hoffmann
Add deprecation message to the audio init function.

Factor out audio initialization and call that from
both audio init and realize, so setting the audiodev
property is enough to properly initialize pcspk.

Add a property alias to the machine type to set the
audio device, so pcspk can be initialized using:
"-machine pcspk-audiodev="

Using "-global isa-pcspk.audiodev=" works too but
is not recommended.

Signed-off-by: Gerd Hoffmann 
---
 hw/audio/pcspk.c | 24 +---
 hw/i386/pc.c |  2 ++
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index c37a3878612e..4c7e339ac2b5 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -28,6 +28,7 @@
 #include "audio/audio.h"
 #include "qemu/module.h"
 #include "qemu/timer.h"
+#include "qemu/error-report.h"
 #include "hw/timer/i8254.h"
 #include "migration/vmstate.h"
 #include "hw/audio/pcspk.h"
@@ -112,11 +113,15 @@ static void pcspk_callback(void *opaque, int free)
 }
 }
 
-static int pcspk_audio_init(ISABus *bus)
+static int pcspk_audio_init(PCSpkState *s)
 {
-PCSpkState *s = pcspk_state;
 struct audsettings as = {PCSPK_SAMPLE_RATE, 1, AUDIO_FORMAT_U8, 0};
 
+if (s->voice) {
+/* already initialized */
+return 0;
+}
+
 AUD_register_card(s_spk, >card);
 
 s->voice = AUD_open_out(>card, s->voice, s_spk, s, pcspk_callback, );
@@ -185,6 +190,10 @@ static void pcspk_realizefn(DeviceState *dev, Error **errp)
 
 isa_register_ioport(isadev, >ioport, s->iobase);
 
+if (s->card.state) {
+pcspk_audio_init(s);
+}
+
 pcspk_state = s;
 }
 
@@ -236,9 +245,18 @@ static const TypeInfo pcspk_info = {
 .class_init = pcspk_class_initfn,
 };
 
+static int pcspk_audio_init_soundhw(ISABus *bus)
+{
+PCSpkState *s = pcspk_state;
+
+warn_report("'-soundhw pcspk' is deprecated, "
+"please set a backend using '-machine pcspk-audiodev=' 
instead");
+return pcspk_audio_init(s);
+}
+
 static void pcspk_register(void)
 {
 type_register_static(_info);
-isa_register_soundhw("pcspk", "PC speaker", pcspk_audio_init);
+isa_register_soundhw("pcspk", "PC speaker", pcspk_audio_init_soundhw);
 }
 type_init(pcspk_register)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index f7ca8d981afa..bd393f82377f 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1913,6 +1913,8 @@ static void pc_machine_initfn(Object *obj)
 
 pc_system_flash_create(pcms);
 pcms->pcspk = isa_new(TYPE_PC_SPEAKER);
+object_property_add_alias(OBJECT(pcms), "pcspk-audiodev",
+  OBJECT(pcms->pcspk), "audiodev");
 }
 
 static void pc_machine_reset(MachineState *machine)
-- 
2.18.4




[PATCH v4 04/20] audio: deprecate -soundhw ac97

2020-06-24 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().  Remove the now obsolete init
function.  Add an alias so both ac97 and AC97 are working with -device.

Signed-off-by: Gerd Hoffmann 
---
 hw/audio/ac97.c | 9 ++---
 qdev-monitor.c  | 1 +
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/hw/audio/ac97.c b/hw/audio/ac97.c
index 8a9b9924c495..38522cf0ba44 100644
--- a/hw/audio/ac97.c
+++ b/hw/audio/ac97.c
@@ -1393,12 +1393,6 @@ static void ac97_exit(PCIDevice *dev)
 AUD_remove_card(>card);
 }
 
-static int ac97_init (PCIBus *bus)
-{
-pci_create_simple(bus, -1, TYPE_AC97);
-return 0;
-}
-
 static Property ac97_properties[] = {
 DEFINE_AUDIO_PROPERTIES(AC97LinkState, card),
 DEFINE_PROP_END_OF_LIST (),
@@ -1436,7 +1430,8 @@ static const TypeInfo ac97_info = {
 static void ac97_register_types (void)
 {
 type_register_static (_info);
-pci_register_soundhw("ac97", "Intel 82801AA AC97 Audio", ac97_init);
+deprecated_register_soundhw("ac97", "Intel 82801AA AC97 Audio",
+0, TYPE_AC97);
 }
 
 type_init (ac97_register_types)
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 22da107484c5..105d9792ecdf 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -53,6 +53,7 @@ typedef struct QDevAlias
 
 /* Please keep this table sorted by typename. */
 static const QDevAlias qdev_alias_table[] = {
+{ "AC97", "ac97" }, /* -soundhw name */
 { "e1000", "e1000-82540em" },
 { "ich9-ahci", "ahci" },
 { "lsi53c895a", "lsi" },
-- 
2.18.4




[PATCH v4 07/20] audio: deprecate -soundhw cs4231a

2020-06-24 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().
Remove the now obsolete init function.

Signed-off-by: Gerd Hoffmann 
---
 hw/audio/cs4231a.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/hw/audio/cs4231a.c b/hw/audio/cs4231a.c
index ffdbb58d6a11..59705a8d4701 100644
--- a/hw/audio/cs4231a.c
+++ b/hw/audio/cs4231a.c
@@ -683,12 +683,6 @@ static void cs4231a_realizefn (DeviceState *dev, Error 
**errp)
 AUD_register_card ("cs4231a", >card);
 }
 
-static int cs4231a_init (ISABus *bus)
-{
-isa_create_simple (bus, TYPE_CS4231A);
-return 0;
-}
-
 static Property cs4231a_properties[] = {
 DEFINE_AUDIO_PROPERTIES(CSState, card),
 DEFINE_PROP_UINT32 ("iobase",  CSState, port, 0x534),
@@ -720,7 +714,7 @@ static const TypeInfo cs4231a_info = {
 static void cs4231a_register_types (void)
 {
 type_register_static (_info);
-isa_register_soundhw("cs4231a", "CS4231A", cs4231a_init);
+deprecated_register_soundhw("cs4231a", "CS4231A", 1, TYPE_CS4231A);
 }
 
 type_init (cs4231a_register_types)
-- 
2.18.4




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

2020-06-24 Thread Aleksandar Markovic
уто, 2. јун 2020. у 00:19 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 
>

If there is no objection, I plan to select this patch in the upcoming
"TCG Continuous Benchmarking" project queue.

Thanks to Richard and Ahmed!
Aleksandar

> 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: [PULL 25/31] osdep: Make MIN/MAX evaluate arguments only once

2020-06-24 Thread Daniel P . Berrangé
On Wed, Jun 24, 2020 at 07:13:17AM -0500, Eric Blake wrote:
> On 6/24/20 5:50 AM, Paolo Bonzini wrote:
> > From: Eric Blake 
> > 
> > I'm not aware of any immediate bugs in qemu where a second runtime
> > evalution of the arguments to MIN() or MAX() causes a problem, but
> 
> evaluation
> 
> > Update the MIN/MAX macros to only evaluate their argument once at
> > runtime;
> 
> > Use of MIN when MIN_CONST is needed:
> > 
> > In file included from /home/eblake/qemu/qemu-img.c:25:
> > /home/eblake/qemu/include/qemu/osdep.h:249:5: error: braced-group within 
> > expression allowed only inside a function
> >249 | ({  \
> >| ^
> > /home/eblake/qemu/qemu-img.c:92:12: note: in expansion of macro ‘MIN’
> 
> UTF-8 mojibake in the commit message ;(
> 
> 
> > Signed-off-by: Eric Blake 
> > 
> > Message-Id: <20200604215236.2798244-1-ebl...@redhat.com>
> > Signed-off-by: Paolo Bonzini 
> > ---
> 
> > +#define MIN_CONST(a, b) \
> > +__builtin_choose_expr(  \
> > +__builtin_constant_p(a) && __builtin_constant_p(b), \
> > +(a) < (b) ? (a) : (b),  \
> > +((void)0))
> 
> This one is correct...
> 
> > +#undef MAX
> > +#define MAX(a, b)   \
> > +({  \
> > +typeof(1 ? (a) : (b)) _a = (a), _b = (b);   \
> > +_a > _b ? _a : _b;  \
> > +})
> > +#define MAX_CONST(a, b) \
> > +__builtin_choose_expr(  \
> > +__builtin_constant_p(a) && __builtin_constant_p(b), \
> > +(a) > (b) ? (a) : (b),  \
> > +__builtin_unreachable())
> 
> ...but this one should also use ((void)0), to match the commit message.
> 
> > +
> > +/* Minimum function that returns zero only if both values are zero.
> >* Intended for use with unsigned values only. */
> 
> And checkpatch complains about the formatting here.
> 
> Ah well.  I had all these things fixed in my tree, but failed to post a v5.
> Not worth holding up this pull request in isolation, but if there are any
> other build issues, I'll post a v5 of this patch, otherwise a followup.

FWIW, the current QEMU code defining MIN/MAX was a no-op, since they
were already defined by GLib in /usr/include/glib-2.0/glib/gmacros.h
which we get via glib.h

Now, the GLib impl shared the same theoretical flaw as the old QEMU
impl, but you said it wasn't a real problem right now.

So I'm wondering if the better option would be to remove the MIN/MAX
def from QEMU, and then submit a pull request to GLib to improve
their definition ?

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




Re: [PATCH v4 20/20] audio: set default value for pcspk.iobase property

2020-06-24 Thread Eric Blake

On 6/24/20 6:30 AM, Gerd Hoffmann wrote:

Allows to drop the explicit qdev_prop_set_uint32 call in pcspk_init.


"allows to $verb" is not idiomatic, better is "allows ${verb}ing" 
[Allows dropping] or "allows $subject to $verb" [Allows us to drop].




Signed-off-by: Gerd Hoffmann 
---
  include/hw/audio/pcspk.h | 6 +-
  hw/audio/pcspk.c | 2 +-
  2 files changed, 2 insertions(+), 6 deletions(-)



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




[PATCH v2 1/2] qom: Introduce object_property_try_add_child()

2020-06-24 Thread Eric Auger
object_property_add() does not allow object_property_try_add()
to gracefully fail as _abort is passed as an error handle.

However such failure can easily be triggered from the QMP shell when,
for instance, one attempts to create an object with an id that already
exists. This is achived from the following call path:

user_creatable_add_type -> object_property_add_child ->
object_property_add

For instance, call twice:
object-add qom-type=memory-backend-ram id=mem1 props.size=1073741824
and QEMU aborts.

This behavior is undesired as a user/management application mistake
in reusing a property ID shouldn't result in loss of the VM and live
data within.

This patch introduces a new function, object_property_try_add_child()
which takes an error handle and turn object_property_try_add() into
a non-static one.

Now the call path becomes:

user_creatable_add_type -> object_property_try_add_child ->
object_property_try_add

and the error is returned gracefully to the QMP client.

(QEMU) object-add qom-type=memory-backend-ram id=mem2  props.size=4294967296
{"return": {}}
(QEMU) object-add qom-type=memory-backend-ram id=mem2  props.size=4294967296
{"error": {"class": "GenericError", "desc": "attempt to add duplicate property
'mem2' to object (type 'container')"}}

Signed-off-by: Eric Auger 
Fixes: d2623129a7de ("qom: Drop parameter @errp of object_property_add() & 
friends")
---
 include/qom/object.h| 24 ++--
 qom/object.c| 22 +-
 qom/object_interfaces.c |  7 +--
 3 files changed, 44 insertions(+), 9 deletions(-)

diff --git a/include/qom/object.h b/include/qom/object.h
index 94a61ccc3f..91cf058d86 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -1039,7 +1039,7 @@ Object *object_ref(Object *obj);
 void object_unref(Object *obj);
 
 /**
- * object_property_add:
+ * object_property_try_add:
  * @obj: the object to add a property to
  * @name: the name of the property.  This can contain any character except for
  *  a forward slash.  In general, you should use hyphens '-' instead of
@@ -1056,10 +1056,22 @@ void object_unref(Object *obj);
  *   meant to allow a property to free its opaque upon object
  *   destruction.  This may be NULL.
  * @opaque: an opaque pointer to pass to the callbacks for the property
+ * @errp: error handle
  *
  * Returns: The #ObjectProperty; this can be used to set the @resolve
  * callback for child and link properties.
  */
+ObjectProperty *object_property_try_add(Object *obj, const char *name,
+const char *type,
+ObjectPropertyAccessor *get,
+ObjectPropertyAccessor *set,
+ObjectPropertyRelease *release,
+void *opaque, Error **errp);
+
+/**
+ * object_property_add: same as object_property_try_add with
+ * errp hardcoded to _abort
+ */
 ObjectProperty *object_property_add(Object *obj, const char *name,
 const char *type,
 ObjectPropertyAccessor *get,
@@ -1495,10 +1507,11 @@ Object *object_resolve_path_type(const char *path, 
const char *typename,
 Object *object_resolve_path_component(Object *parent, const char *part);
 
 /**
- * object_property_add_child:
+ * object_property_try_add_child:
  * @obj: the object to add a property to
  * @name: the name of the property
  * @child: the child object
+ * @errp: error handle
  *
  * Child properties form the composition tree.  All objects need to be a child
  * of another object.  Objects can only be a child of one object.
@@ -1512,6 +1525,13 @@ Object *object_resolve_path_component(Object *parent, 
const char *part);
  *
  * Returns: The newly added property on success, or %NULL on failure.
  */
+ObjectProperty *object_property_try_add_child(Object *obj, const char *name,
+  Object *child, Error **errp);
+
+/**
+ * object_property_add_child: same as object_property_try_add_child with
+ * errp hardcoded to _abort
+ */
 ObjectProperty *object_property_add_child(Object *obj, const char *name,
   Object *child);
 
diff --git a/qom/object.c b/qom/object.c
index 6ece96bc2b..96e85cdaf7 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1132,7 +1132,7 @@ void object_unref(Object *obj)
 }
 }
 
-static ObjectProperty *
+ObjectProperty *
 object_property_try_add(Object *obj, const char *name, const char *type,
 ObjectPropertyAccessor *get,
 ObjectPropertyAccessor *set,
@@ -1651,8 +1651,8 @@ static void object_finalize_child_property(Object *obj, 
const char *name,
 }
 
 ObjectProperty *
-object_property_add_child(Object *obj, const char *name,
-  Object *child)
+object_property_try_add_child(Object *obj, const char *name,
+  Object 

Re: [PATCH v3 6/8] s390/sclp: add extended-length sccb support for kvm guest

2020-06-24 Thread Cornelia Huck
On Wed, 24 Jun 2020 14:40:58 +0200
Thomas Huth  wrote:

> On 24/06/2020 14.36, Cornelia Huck wrote:
> > On Thu, 18 Jun 2020 18:22:56 -0400
> > Collin Walling  wrote:
> >   
> >> As more features and facilities are added to the Read SCP Info (RSCPI)
> >> response, more space is required to store them. The space used to store
> >> these new features intrudes on the space originally used to store CPU
> >> entries. This means as more features and facilities are added to the
> >> RSCPI response, less space can be used to store CPU entries.
> >>
> >> With the Extended-Length SCCB (ELS) facility, a KVM guest can execute
> >> the RSCPI command and determine if the SCCB is large enough to store a
> >> complete reponse. If it is not large enough, then the required length
> >> will be set in the SCCB header.
> >>
> >> The caller of the SCLP command is responsible for creating a
> >> large-enough SCCB to store a complete response. Proper checking should
> >> be in place, and the caller should execute the command once-more with
> >> the large-enough SCCB.
> >>
> >> This facility also enables an extended SCCB for the Read CPU Info
> >> (RCPUI) command.
> >>
> >> When this facility is enabled, the boundary violation response cannot
> >> be a result from the RSCPI, RSCPI Forced, or RCPUI commands.
> >>
> >> In order to tolerate kernels that do not yet have full support for this
> >> feature, a "fixed" offset to the start of the CPU Entries within the
> >> Read SCP Info struct is set to allow for the original 248 max entries
> >> when this feature is disabled.
> >>
> >> Additionally, this is introduced as a CPU feature to protect the guest
> >> from migrating to a machine that does not support storing an extended
> >> SCCB. This could otherwise hinder the VM from being able to read all
> >> available CPU entries after migration (such as during re-ipl).
> >>
> >> Signed-off-by: Collin Walling 
> >> ---
> >>   hw/s390x/sclp.c | 21 -
> >>   include/hw/s390x/sclp.h |  1 +
> >>   target/s390x/cpu_features_def.inc.h |  1 +
> >>   target/s390x/gen-features.c |  1 +
> >>   target/s390x/kvm.c  |  8 
> >>   5 files changed, 31 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
> >> index 0dfbe6e5ec..f7c49e339e 100644
> >> --- a/hw/s390x/sclp.c
> >> +++ b/hw/s390x/sclp.c
> >> @@ -56,6 +56,18 @@ static bool sccb_has_valid_boundary(uint64_t sccb_addr, 
> >> uint32_t code,
> >>   uint64_t sccb_boundary = (sccb_addr & PAGE_MASK) + PAGE_SIZE;
> >>   
> >>   switch (code & SCLP_CMD_CODE_MASK) {
> >> +case SCLP_CMDW_READ_SCP_INFO:
> >> +case SCLP_CMDW_READ_SCP_INFO_FORCED:
> >> +case SCLP_CMDW_READ_CPU_INFO:
> >> +/*
> >> + * An extended-length SCCB is only allowed for Read SCP/CPU Info 
> >> and
> >> + * is allowed to exceed the 4k boundary. The respective commands 
> >> will
> >> + * set the length field to the required length if an insufficient
> >> + * SCCB length is provided.
> >> + */
> >> +if (s390_has_feat(S390_FEAT_EXTENDED_LENGTH_SCCB)) {
> >> +return true;
> >> +}  
> > 
> > Add a fallthrough annotation?  
> 
> ... otherwise Coverity and friends will complain later.

Nod.

> 
> >>   default:
> >>   if (sccb_max_addr < sccb_boundary) {
> >>   return true;
> >> @@ -72,6 +84,10 @@ static bool sccb_sufficient_len(SCCB *sccb, int 
> >> num_cpus, int data_len)
> >>   
> >>   if (be16_to_cpu(sccb->h.length) < required_len) {
> >>   sccb->h.response_code = 
> >> cpu_to_be16(SCLP_RC_INSUFFICIENT_SCCB_LENGTH);
> >> +if (s390_has_feat(S390_FEAT_EXTENDED_LENGTH_SCCB) &&
> >> +sccb->h.control_mask[2] & SCLP_VARIABLE_LENGTH_RESPONSE) {
> >> +sccb->h.length = required_len;
> >> +}
> >>   return false;
> >>   }
> >>   return true;
> >> @@ -101,7 +117,9 @@ static void prepare_cpu_entries(MachineState *ms, 
> >> CPUEntry *entry, int *count)
> >>*/
> >>   static inline int get_read_scp_info_data_len(void)
> >>   {
> >> -return offsetof(ReadInfo, entries);
> >> +return s390_has_feat(S390_FEAT_EXTENDED_LENGTH_SCCB) ?
> >> +   offsetof(ReadInfo, entries) :
> >> +   SCLP_READ_SCP_INFO_FIXED_CPU_OFFSET;
> >>   }
> >>   
> >>   /* Provide information about the configuration, CPUs and storage */
> >> @@ -116,6 +134,7 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
> >>   CPUEntry *entries_start = (void *)sccb + data_len;
> >>   
> >>   if (!sccb_sufficient_len(sccb, machine->possible_cpus->len, 
> >> data_len)) {
> >> +warn_report("insufficient sccb size to store read scp info 
> >> response");  
> > 
> > Hm, this warning is triggered by a guest action, isn't it? Not sure how
> > helpful it is.  
> 
> I think this should be qemu_log_mask(LOG_GUEST_ERROR, ...) instead?

Yes, that sounds better.




Re: [PATCH v1 04/10] virtio-pci: implement queue_enabled method

2020-06-24 Thread Laurent Vivier
On 22/06/2020 17:37, Cindy Lu wrote:
> From: Jason Wang 
> 
> With version 1, we can detect whether a queue is enabled via
> queue_enabled.
> 
> Signed-off-by: Jason Wang 
> Signed-off-by: Cindy Lu 
> ---
>  hw/virtio/virtio-pci.c | 18 ++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index 4cb784389c..3918aa9f6c 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -1107,6 +1107,23 @@ static AddressSpace *virtio_pci_get_dma_as(DeviceState 
> *d)
>  return pci_get_address_space(dev);
>  }
>  
> +static bool  virtio_queue_check_enabled(VirtIODevice *vdev, int n)
> +{
> +return  virtio_queue_get_desc_addr(vdev, n) != 0;
> +}

This function is already defined under a different name in
hw/virtio/virtio.c:


   3287 bool virtio_queue_enabled(VirtIODevice *vdev, int n)
   3288 {
   3289 return virtio_queue_get_desc_addr(vdev, n) != 0;
   3290 }

As this file includes "hw/virtio/virtio.h" you can use it directly.

Thanks,
Laurent




Re: [PATCH v11 00/61] target/riscv: support vector extension v0.7.1

2020-06-24 Thread Alistair Francis
On Tue, Jun 23, 2020 at 3:00 PM LIU Zhiwei  wrote:
>
> This patchset implements the vector extension for RISC-V on QEMU.
>
> You can also find the patchset and all *test cases* in
> my repo(https://github.com/romanheros/qemu.git branch:vector-upstream-v11).
> All the test cases are in the directory qemu/tests/riscv/vector/. They are
> riscv64 linux user mode programs.
>
> You can test the patchset by the script qemu/tests/riscv/vector/runcase.sh.
>
> Features:
>   * support specification 
> riscv-v-spec-0.7.1.(https://github.com/riscv/riscv-v-spec/releases/tag/0.7.1/)
>   * support basic vector extension.
>   * support Zvlsseg.
>   * support Zvamo.
>   * not support Zvediv as it is changing.
>   * SLEN always equals VLEN.
>   * element width support 8bit, 16bit, 32bit, 64bit.
>
> Changelog:
>
> v11
>   * fix all non-ASCII characters.
>
> v10
>   * rebase to https://github.com/alistair23/qemu/tree/riscv-to-apply.next.
>   * fix compile error in patch 57/61.
>   * fix review tag typo.
>
> v9
>   * always set dynamic rounding mode for vector float insns.
>   * bug fix atomic implementation.
>   * bug fix first-only-fault.
>   * some small tidy up.
>
> v8
>   * support different float rounding modes for vector instructions.
>   * use lastest released TCG GVEC DUP IR.
>   * set RV_VLEN_MAX to 256 bits, as GVEC IR uses simd_desc.
>
> v7
>   * move vl == 0 check to translation time by add a global cpu_vl.
>   * implement vector element inline load and store function by TCG IR.
>   * based on vec_element_load(store), implement some permutation instructions.
>   * implement rsubs GVEC IR.
>   * fixup vsmul, vmfne, vfmerge, vslidedown.
>   * some other small bugs and indentation errors.
>
> v6
>   * use gvec_dup Gvec IR to accellerate move and merge.
>   * a better way to implement fixed point instructions.
>   * a global check when vl == 0.
>   * limit some macros to only one inline function call.
>   * fixup sew error when use Gvec IR.
>   * fixup bugs for corner cases.
>
> v5
>   * fixup a bug in tb flags.
>
> v4
>   * no change
>
> v3
>   * move check code from execution-time to translation-time
>   * use a continous memory block for vector register description.
>   * vector registers as direct fields in RISCVCPUState.
>   * support VLEN configure from qemu command line.
>   * support ELEN configure from qemu command line.
>   * support vector specification version configure from qemu command line.
>   * probe pages before real load or store access.
>   * use probe_page_check for no-fault operations in linux user mode.
>   * generation atomic exit exception when in parallel environment.
>   * fixup a lot of concrete bugs.
>
> V2
>   * use float16_compare{_quiet}
>   * only use GETPC() in outer most helper
>   * add ctx.ext_v Property
>
>
>
> LIU Zhiwei (61):
>   target/riscv: add vector extension field in CPURISCVState
>   target/riscv: implementation-defined constant parameters
>   target/riscv: support vector extension csr
>   target/riscv: add vector configure instruction
>   target/riscv: add an internals.h header
>   target/riscv: add vector stride load and store instructions
>   target/riscv: add vector index load and store instructions
>   target/riscv: add fault-only-first unit stride load
>   target/riscv: add vector amo operations
>   target/riscv: vector single-width integer add and subtract
>   target/riscv: vector widening integer add and subtract
>   target/riscv: vector integer add-with-carry / subtract-with-borrow
> instructions
>   target/riscv: vector bitwise logical instructions
>   target/riscv: vector single-width bit shift instructions
>   target/riscv: vector narrowing integer right shift instructions
>   target/riscv: vector integer comparison instructions
>   target/riscv: vector integer min/max instructions
>   target/riscv: vector single-width integer multiply instructions
>   target/riscv: vector integer divide instructions
>   target/riscv: vector widening integer multiply instructions
>   target/riscv: vector single-width integer multiply-add instructions
>   target/riscv: vector widening integer multiply-add instructions
>   target/riscv: vector integer merge and move instructions
>   target/riscv: vector single-width saturating add and subtract
>   target/riscv: vector single-width averaging add and subtract
>   target/riscv: vector single-width fractional multiply with rounding
> and saturation
>   target/riscv: vector widening saturating scaled multiply-add
>   target/riscv: vector single-width scaling shift instructions
>   target/riscv: vector narrowing fixed-point clip instructions
>   target/riscv: vector single-width floating-point add/subtract
> instructions
>   target/riscv: vector widening floating-point add/subtract instructions
>   target/riscv: vector single-width floating-point multiply/divide
> instructions
>   target/riscv: vector widening floating-point multiply
>   target/riscv: vector single-width floating-point fused multiply-add
> 

Re: [PATCH v5 0/5] VIRTIO-IOMMU probe request support and MSI bypass on ARM

2020-06-24 Thread Michael S. Tsirkin
On Wed, Jun 24, 2020 at 03:26:20PM +0200, Eric Auger wrote:
> By default the virtio-iommu translates MSI transactions. This
> behavior is inherited from ARM SMMU. However the virt machine
> code knows where the MSI doorbells are, so we can easily
> declare those regions as VIRTIO_IOMMU_RESV_MEM_T_MSI. With that
> setting the guest iommu subsystem will not need to map MSIs.
> This setup will simplify the VFIO integration.
> 
> In this series, the ITS or GICV2M doorbells are declared as
> HW MSI regions to be bypassed by the VIRTIO-IOMMU.


> This also paves the way to the x86 integration where the MSI
> region, [0xFEE0,0xFEEF], will be exposed by the q35
> machine.  However this will be handled in a separate series
> when not-DT support gets resolved.

What's going on with that btw?
I think the next step is to put the spec up for virtio tc vote,
then we can merge that, right? acpi parts will need to be
ratified by the acpi sig.

> Best Regards
> 
> Eric
> 
> This series can be found at:
> https://github.com/eauger/qemu/tree/v5.0.0-virtio-iommu-msi-bypass-v5
> 
> History:
> 
> v4 -> v5:
> - Take into account some additional comments from Markus:
>   - reserved region type becomes an unsigned + some comment/desc
> rewording
>   - assert if the type is not RESERVED or MSI
> 
> v3 -> v4:
> - collected Jean and markus's R-bs
> - tool into account all Markus' comments in [1/5] (except removal of
>   goto)
> - use ':' as delimitor instead of commas
> - add example in 4/5 commit message as suggested by Markus
> 
> v2 -> v3:
> - Introduce VIRT_MSI_CTRL_NONE in VirtMSIControllerType
> - do not fill the remainder of the probe buffer
> 
> v1 -> v2:
> - check which MSI controller is in use and advertise the
>   corresponding MSI doorbell
> - managed for both ITS and GICv2M
> - various fixes spotted by Peter and Jean-Philippe, see
>   individual logs
> 
> v1: Most of those patches were respinned from
>   [PATCH for-5.0 v11 00/20] VIRTIO-IOMMU device
>   except the last one which is new
> 
> 
> Eric Auger (5):
>   qdev: Introduce DEFINE_PROP_RESERVED_REGION
>   virtio-iommu: Implement RESV_MEM probe request
>   virtio-iommu: Handle reserved regions in the translation process
>   virtio-iommu-pci: Add array of Interval properties
>   hw/arm/virt: Let the virtio-iommu bypass MSIs
> 
>  include/exec/memory.h|   6 ++
>  include/hw/arm/virt.h|   7 ++
>  include/hw/qdev-properties.h |   3 +
>  include/hw/virtio/virtio-iommu.h |   2 +
>  include/qemu/typedefs.h  |   1 +
>  hw/arm/virt.c|  18 +
>  hw/core/qdev-properties.c|  89 
>  hw/virtio/virtio-iommu-pci.c |   3 +
>  hw/virtio/virtio-iommu.c | 112 +--
>  hw/virtio/trace-events   |   1 +
>  10 files changed, 238 insertions(+), 4 deletions(-)
> 
> -- 
> 2.20.1




[PATCH] usb: fix usb-host build on windows.

2020-06-24 Thread Gerd Hoffmann
Seems the new API is not available on windows.
Update #ifdefs accordingly.

Fixes: 9f815e83e983 ("usb: add hostdevice property to usb-host")
Reported-by: Howard Spoelstra 
Signed-off-by: Gerd Hoffmann 
---
 hw/usb/host-libusb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index ad7ed8fb0c67..c474551d8456 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -907,7 +907,7 @@ static int usb_host_open(USBHostDevice *s, libusb_device 
*dev, int hostfd)
 goto fail;
 }
 } else {
-#if LIBUSB_API_VERSION >= 0x01000107
+#if LIBUSB_API_VERSION >= 0x01000107 && !defined(CONFIG_WIN32)
 trace_usb_host_open_hostfd(hostfd);
 
 rc = libusb_wrap_sys_device(ctx, hostfd, >dh);
@@ -1107,7 +1107,7 @@ static void usb_host_realize(USBDevice *udev, Error 
**errp)
 QTAILQ_INIT(>isorings);
 s->hostfd = -1;
 
-#if LIBUSB_API_VERSION >= 0x01000107
+#if LIBUSB_API_VERSION >= 0x01000107 && !defined(CONFIG_WIN32)
 if (s->hostdevice) {
 int fd;
 s->needs_autoscan = false;
-- 
2.18.4




[PATCH v2 19/25] gitlab: convert jobs to use custom built containers

2020-06-24 Thread Alex Bennée
From: Daniel P. Berrangé 

Now that we're building standard container images from
dockerfiles in tests/docker/dockerfiles, we can convert
the build jobs to use them. The key benefit of this is
that a contributor can now more easily replicate the CI
environment on their local machine. The container images
are cached too, so we are not spending time waiting for
the apt-get/dnf package installs to complete.

Signed-off-by: Daniel P. Berrangé 
Message-Id: <20200622153318.751107-4-berra...@redhat.com>
[AJB: tweak naming convention]
Signed-off-by: Alex Bennée 
---
 .gitlab-ci.yml | 187 +
 1 file changed, 81 insertions(+), 106 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 72d688875fd..a7abc55a5c6 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -9,133 +9,108 @@ include:
   - local: '/.gitlab-ci.d/opensbi.yml'
   - local: '/.gitlab-ci.d/containers.yml'
 
-.update_apt_template: _script_apt
- before_script:
-  - apt-get update -qq
-  - apt-get install -y -qq git gcc libglib2.0-dev libpixman-1-dev make
-genisoimage
-  - JOBS=$(expr $(nproc) + 1)
-
-.update_dnf_template: _script_dnf
- before_script:
-  - dnf update -y
-  - dnf install -y bzip2 diffutils gcc git genisoimage findutils glib2-devel
-make python3 perl-podlators perl-Test-Harness pixman-devel zlib-devel
-  - JOBS=$(expr $(nproc) + 1)
+.native_build_job_template: _build_job_definition
+  stage: build
+  image: $CI_REGISTRY_IMAGE/qemu/$IMAGE:latest
+  before_script:
+- JOBS=$(expr $(nproc) + 1)
+  script:
+- mkdir build
+- cd build
+- if test -n "$TARGETS";
+  then
+../configure --enable-werror $CONFIGURE_ARGS --target-list="$TARGETS" ;
+  else
+../configure --enable-werror $CONFIGURE_ARGS ;
+  fi
+- make -j"$JOBS"
+- make -j"$JOBS" $MAKE_CHECK_ARGS
 
 build-system1:
- stage: build
- image: ubuntu:19.10
- <<: *before_script_apt
- script:
- - apt-get install -y -qq libgtk-3-dev libvte-dev nettle-dev libcacard-dev
-  libusb-dev libvde-dev libspice-protocol-dev libgl1-mesa-dev 
libvdeplug-dev
- - mkdir build
- - cd build
- - ../configure --enable-werror --target-list="aarch64-softmmu alpha-softmmu
-  cris-softmmu hppa-softmmu lm32-softmmu moxie-softmmu microblazeel-softmmu
-  mips64el-softmmu m68k-softmmu ppc-softmmu riscv64-softmmu sparc-softmmu"
- - make -j"$JOBS"
- - make -j"$JOBS" check
+  <<: *native_build_job_definition
+  variables:
+IMAGE: ubuntu2004
+TARGETS: aarch64-softmmu alpha-softmmu cris-softmmu hppa-softmmu 
lm32-softmmu
+  moxie-softmmu microblazeel-softmmu mips64el-softmmu m68k-softmmu 
ppc-softmmu
+  riscv64-softmmu sparc-softmmu
+MAKE_CHECK_ARGS: check
 
 build-system2:
- stage: build
- image: fedora:latest
- <<: *before_script_dnf
- script:
- - yum install -y SDL2-devel libgcrypt-devel brlapi-devel libaio-devel
-   libfdt-devel lzo-devel librdmacm-devel libibverbs-devel libibumad-devel
-   libzstd-devel
- - mkdir build
- - cd build
- - ../configure --enable-werror --target-list="tricore-softmmu 
unicore32-softmmu
-  microblaze-softmmu mips-softmmu riscv32-softmmu s390x-softmmu sh4-softmmu
-  sparc64-softmmu x86_64-softmmu xtensa-softmmu nios2-softmmu or1k-softmmu"
- - make -j"$JOBS"
- - make -j"$JOBS" check
+  <<: *native_build_job_definition
+  variables:
+IMAGE: fedora
+TARGETS: tricore-softmmu unicore32-softmmu microblaze-softmmu mips-softmmu
+  riscv32-softmmu s390x-softmmu sh4-softmmu sparc64-softmmu x86_64-softmmu
+  xtensa-softmmu nios2-softmmu or1k-softmmu
+MAKE_CHECK_ARGS: check
 
 build-disabled:
- stage: build
- image: fedora:latest
- <<: *before_script_dnf
- script:
- - mkdir build
- - cd build
- - ../configure --enable-werror --disable-rdma --disable-slirp --disable-curl
+  <<: *native_build_job_definition
+  variables:
+IMAGE: fedora
+CONFIGURE_ARGS: --disable-rdma --disable-slirp --disable-curl
   --disable-capstone --disable-live-block-migration --disable-glusterfs
   --disable-replication --disable-coroutine-pool --disable-smartcard
   --disable-guest-agent --disable-curses --disable-libxml2 --disable-tpm
   --disable-qom-cast-debug --disable-spice --disable-vhost-vsock
   --disable-vhost-net --disable-vhost-crypto --disable-vhost-user
-  --target-list="i386-softmmu ppc64-softmmu mips64-softmmu i386-linux-user"
- - make -j"$JOBS"
- - make -j"$JOBS" check-qtest SPEED=slow
+TARGETS: i386-softmmu ppc64-softmmu mips64-softmmu i386-linux-user
+MAKE_CHECK_ARGS: check-qtest SPEED=slow
 
 build-tcg-disabled:
- stage: build
- image: centos:8
- <<: *before_script_dnf
- script:
- - dnf install -y clang gtk3-devel libusbx-devel libgcrypt-devel
- - mkdir build
- - cd build
- - ../configure --cc=clang --enable-werror --disable-tcg --audio-drv-list=""
- - make -j"$JOBS"
- - make check-unit
- - make check-qapi-schema
- - cd tests/qemu-iotests/
- - ./check -raw 001 002 003 004 005 008 009 010 011 

[PATCH v2 16/25] .gitignore: un-ignore .gitlab-ci.d

2020-06-24 Thread Alex Bennée
The sooner we deprecate in-tree builds the sooner this mess of regexes
can be thrown away.

Signed-off-by: Alex Bennée 

---
v2
  - just use explicit !/.gitlab-ci.d
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index 90acb4347d4..2992d15931a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -93,6 +93,7 @@
 *.tp
 *.vr
 *.d
+!/.gitlab-ci.d
 !/scripts/qemu-guest-agent/fsfreeze-hook.d
 *.o
 .sdk
-- 
2.20.1




Re: [RFC RESEND v7 0/4] QEMU cpus.c refactoring

2020-06-24 Thread Roman Bolshakov
On Mon, Jun 22, 2020 at 03:45:30PM +0200, Claudio Fontana wrote:
> Motivation and higher level steps:
> 
> https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg04628.html
> 
> MAIN OPEN POINTS:
> 
> * confirmation on hvf state (Roman).
> 

Hi Claudio,

I'm sorry for delay. I'm wrapping up another round of HVF cleanup that
should make it easier to do hvf-specific changes in patch 4. I expect to
send the cleanup series today.

> * missing reviewed-by for patch 4 in the series
> 

I wonder if it would help to split patch 4 out of the series if nobody
objects patches 1-3. At least it will be easier to rebase the last one
alone. Then patch 4 might become a series on its own.

Regards,
Roman



Re: [PATCH v4] arm/virt: Add memory hot remove support

2020-06-24 Thread Igor Mammedov
On Mon, 22 Jun 2020 13:41:57 +0100
Shameer Kolothum  wrote:

> This adds support for memory(pc-dimm) hot remove on arm/virt that
> uses acpi ged device.
> 
> NVDIMM hot removal is not yet supported.
> 
> Signed-off-by: Shameer Kolothum 
> ---
> v2 --> v3
>   -Addressed Eric's comments on v3. 
> v2 --> v3
>   -Addressed Eric's review comment and added check for NVDIMM.
> RFC v1 --> v2
>   -Rebased on top of latest Qemu master.
>   -Dropped "RFC" and tested with kernel 5.7-rc6
> ---
>  hw/acpi/generic_event_device.c | 29 
>  hw/arm/virt.c  | 62 --
>  2 files changed, 89 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/acpi/generic_event_device.c b/hw/acpi/generic_event_device.c
> index 1cb34111e5..b8abdefa1c 100644
> --- a/hw/acpi/generic_event_device.c
> +++ b/hw/acpi/generic_event_device.c
> @@ -193,6 +193,33 @@ static void acpi_ged_device_plug_cb(HotplugHandler 
> *hotplug_dev,
>  }
>  }
>  
> +static void acpi_ged_unplug_request_cb(HotplugHandler *hotplug_dev,
> +   DeviceState *dev, Error **errp)
> +{
> +AcpiGedState *s = ACPI_GED(hotplug_dev);
> +
> +if ((object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) &&
> +   !(object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM {
> +acpi_memory_unplug_request_cb(hotplug_dev, >memhp_state, dev, 
> errp);
> +} else {
> +error_setg(errp, "acpi: device unplug request for unsupported device"
> +   " type: %s", object_get_typename(OBJECT(dev)));
> +}
> +}
> +
> +static void acpi_ged_unplug_cb(HotplugHandler *hotplug_dev,
> +   DeviceState *dev, Error **errp)
> +{
> +AcpiGedState *s = ACPI_GED(hotplug_dev);
> +
> +if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
> +acpi_memory_unplug_cb(>memhp_state, dev, errp);
> +} else {
> +error_setg(errp, "acpi: device unplug for unsupported device"
> +   " type: %s", object_get_typename(OBJECT(dev)));
> +}
> +}
> +
>  static void acpi_ged_send_event(AcpiDeviceIf *adev, AcpiEventStatusBits ev)
>  {
>  AcpiGedState *s = ACPI_GED(adev);
> @@ -318,6 +345,8 @@ static void acpi_ged_class_init(ObjectClass *class, void 
> *data)
>  dc->vmsd = _acpi_ged;
>  
>  hc->plug = acpi_ged_device_plug_cb;
> +hc->unplug_request = acpi_ged_unplug_request_cb;
> +hc->unplug = acpi_ged_unplug_cb;
>  
>  adevc->send_event = acpi_ged_send_event;
>  }
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index caceb1e4a0..80ef2d7b7a 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -2177,11 +2177,68 @@ static void 
> virt_machine_device_plug_cb(HotplugHandler *hotplug_dev,
>  }
>  }
>  
> +static void virt_dimm_unplug_request(HotplugHandler *hotplug_dev,
> + DeviceState *dev, Error **errp)
> +{
> +VirtMachineState *vms = VIRT_MACHINE(hotplug_dev);
> +Error *local_err = NULL;
> +
> +if (!vms->acpi_dev) {
> +error_setg(_err,
> +   "memory hotplug is not enabled: missing acpi-ged device");
> +goto out;
> +}
> +
> +if (object_dynamic_cast(OBJECT(dev), TYPE_NVDIMM)) {
> +error_setg(_err,
> +   "nvdimm device hot unplug is not supported yet.");
> +goto out;
> +}
> +
> +hotplug_handler_unplug_request(HOTPLUG_HANDLER(vms->acpi_dev), dev,
> +   _err);
> +out:
> +error_propagate(errp, local_err);
> +}
> +
> +static void virt_dimm_unplug(HotplugHandler *hotplug_dev,
> + DeviceState *dev, Error **errp)
> +{
> +VirtMachineState *vms = VIRT_MACHINE(hotplug_dev);
> +Error *local_err = NULL;
> +
> +hotplug_handler_unplug(HOTPLUG_HANDLER(vms->acpi_dev), dev, _err);
> +if (local_err) {
> +goto out;
> +}
> +
> +pc_dimm_unplug(PC_DIMM(dev), MACHINE(vms));
> +qdev_unrealize(dev);

doesn't pc_dimm_unplug() do unrealize already?
(/me wonders why it doesn't explode here,
are we leaking a refference somewhere so dimm is still alive?)

> +
> +out:
> +error_propagate(errp, local_err);
> +}
> +
>  static void virt_machine_device_unplug_request_cb(HotplugHandler 
> *hotplug_dev,
>DeviceState *dev, Error **errp)
>  {
> -error_setg(errp, "device unplug request for unsupported device"
> -   " type: %s", object_get_typename(OBJECT(dev)));
> +if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
> +virt_dimm_unplug_request(hotplug_dev, dev, errp);
> +} else {
> +error_setg(errp, "device unplug request for unsupported device"
> +   " type: %s", object_get_typename(OBJECT(dev)));
> +}
> +}
> +
> +static void virt_machine_device_unplug_cb(HotplugHandler *hotplug_dev,
> +  DeviceState *dev, Error **errp)
> +{
> +if (object_dynamic_cast(OBJECT(dev), 

Re: [PATCH v2 20/25] x86: Fix x86_cpu_new() error API violations

2020-06-24 Thread Paolo Bonzini
On 24/06/20 16:17, Igor Mammedov wrote:
>> -cpu = object_new(MACHINE(x86ms)->cpu_type);
>> -
>> -object_property_set_uint(cpu, apic_id, "apic-id", _err);
>> -qdev_realize(DEVICE(cpu), NULL, _err);
>> -
>> -object_unref(cpu);
>> -error_propagate(errp, local_err);
>> +object_property_set_uint(cpu, apic_id, "apic-id", _abort);
> it may fail here if user specified wrong cpu flags, but there is nothing we 
> can do to fix it.
> perhaps error_fatal would suit this case better?

No, we need to add the error_propagate dance instead.

Paolo




[PATCH V6 2/4] hw/intc: Add Loongson liointc support

2020-06-24 Thread Huacai Chen
Loongson-3 has an integrated liointc (Local I/O interrupt controller).
It is similar to goldfish interrupt controller, but more powerful (e.g.,
it can route external interrupt to multi-cores).

Documents about Loongson-3's liointc:
1, https://wiki.godson.ac.cn/ip_block:liointc;
2, The "I/O中断" section of Loongson-3's user mannual, part 1.

Signed-off-by: Huacai Chen 
Signed-off-by: Jiaxun Yang 
---
 hw/intc/Kconfig|   3 +
 hw/intc/Makefile.objs  |   1 +
 hw/intc/loongson_liointc.c | 241 +
 3 files changed, 245 insertions(+)
 create mode 100644 hw/intc/loongson_liointc.c

diff --git a/hw/intc/Kconfig b/hw/intc/Kconfig
index f562342..2ae1e89 100644
--- a/hw/intc/Kconfig
+++ b/hw/intc/Kconfig
@@ -64,3 +64,6 @@ config OMPIC
 
 config RX_ICU
 bool
+
+config LOONGSON_LIOINTC
+bool
diff --git a/hw/intc/Makefile.objs b/hw/intc/Makefile.objs
index a420263..3ac2b40 100644
--- a/hw/intc/Makefile.objs
+++ b/hw/intc/Makefile.objs
@@ -51,3 +51,4 @@ obj-$(CONFIG_MIPS_CPS) += mips_gic.o
 obj-$(CONFIG_NIOS2) += nios2_iic.o
 obj-$(CONFIG_OMPIC) += ompic.o
 obj-$(CONFIG_IBEX) += ibex_plic.o
+obj-$(CONFIG_LOONGSON_LIOINTC) += loongson_liointc.o
diff --git a/hw/intc/loongson_liointc.c b/hw/intc/loongson_liointc.c
new file mode 100644
index 000..e39e39e
--- /dev/null
+++ b/hw/intc/loongson_liointc.c
@@ -0,0 +1,241 @@
+/*
+ * QEMU Loongson Local I/O interrupt controler.
+ *
+ * Copyright (c) 2020 Jiaxun Yang 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "qemu/osdep.h"
+#include "hw/sysbus.h"
+#include "qemu/module.h"
+#include "hw/irq.h"
+#include "hw/qdev-properties.h"
+
+#define D(x)
+
+#define NUM_IRQS32
+
+#define NUM_CORES   4
+#define NUM_IPS 4
+#define NUM_PARENTS (NUM_CORES * NUM_IPS)
+#define PARENT_COREx_IPy(x, y)(NUM_IPS * x + y)
+
+#define R_MAPPER_START0x0
+#define R_MAPPER_END  0x20
+#define R_ISR   R_MAPPER_END
+#define R_IEN   0x24
+#define R_IEN_SET   0x28
+#define R_IEN_CLR   0x2c
+#define R_PERCORE_ISR(x) (0x40 + 0x8 * x)
+#define R_END   0x64
+
+#define TYPE_LOONGSON_LIOINTC "loongson.liointc"
+#define LOONGSON_LIOINTC(obj) \
+OBJECT_CHECK(struct loongson_liointc, (obj), TYPE_LOONGSON_LIOINTC)
+
+struct loongson_liointc {
+SysBusDevice parent_obj;
+
+MemoryRegion mmio;
+qemu_irq parent_irq[NUM_PARENTS];
+
+uint8_t mapper[NUM_IRQS]; /* 0:3 for core, 4:7 for IP */
+uint32_t isr;
+uint32_t ien;
+uint32_t per_core_isr[NUM_CORES];
+
+/* state of the interrupt input pins */
+uint32_t pin_state;
+bool parent_state[NUM_PARENTS];
+};
+
+static void update_irq(struct loongson_liointc *p)
+{
+uint32_t irq, core, ip;
+uint32_t per_ip_isr[NUM_IPS] = {0};
+
+/* level triggered interrupt */
+p->isr = p->pin_state;
+
+/* Clear disabled IRQs */
+p->isr &= p->ien;
+
+/* Clear per_core_isr */
+for (core = 0; core < NUM_CORES; core++) {
+p->per_core_isr[core] = 0;
+}
+
+/* Update per_core_isr and per_ip_isr */
+for (irq = 0; irq < NUM_IRQS; irq++) {
+if (!(p->isr & (1 << irq))) {
+continue;
+}
+
+for (core = 0; core < NUM_CORES; core++) {
+if ((p->mapper[irq] & (1 << core))) {
+p->per_core_isr[core] |= (1 << irq);
+}
+}
+
+for (ip = 0; ip < NUM_IPS; ip++) {
+if ((p->mapper[irq] & (1 << (ip + 4 {
+per_ip_isr[ip] |= (1 << irq);
+}
+}
+}
+
+/* Emit IRQ to parent! */
+for (core = 0; core < NUM_CORES; core++) {
+for (ip = 0; ip < NUM_IPS; ip++) {
+int parent = PARENT_COREx_IPy(core, ip);
+if (p->parent_state[parent] !=
+(!!p->per_core_isr[core] && !!per_ip_isr[ip])) {
+p->parent_state[parent] = !p->parent_state[parent];
+qemu_set_irq(p->parent_irq[parent], p->parent_state[parent]);
+}
+}
+}
+}
+
+static uint64_t
+liointc_read(void *opaque, hwaddr addr, unsigned int size)
+{
+struct loongson_liointc *p = opaque;
+uint32_t r = 0;
+
+/* Mapper is 1 byte */
+if (size == 1 && addr < R_MAPPER_END) {
+r = p->mapper[addr];
+goto out;
+}
+
+/* Rest is 4 byte */
+if (size != 4 || (addr % 4)) {
+

Re: [PATCH v5 00/12] pc-bios: s390x: Cleanup part 1

2020-06-24 Thread Thomas Huth

On 24/06/2020 12.44, Cornelia Huck wrote:

On Wed, 24 Jun 2020 03:52:14 -0400
Janosch Frank  wrote:


The bios is in dire need for a cleanup as there are still a lot of
magic constants being used throughout as well as duplicated code.

In the first part of this series we consolidate constants and
functions, as well as doing some minor cleanups and fixes.

The patches are available here:
https://github.com/frankjaa/qemu/pull/new/cleanup_bios

v5:
* Fixed whitespace damage
* Removed reset PSW mask changes in dasd-ipl.c
* Added jump2ipl.c cleanup patches

v4:
* Renamed time.h to s390-time.h
* Fixed function names in sleep()
* Changed order of sense_id_ccw initialization
* Added missing include before sleep()

v3:
* Dropped 0x00 to 0x0/0 patch
* Moved some timing functions into helper.h instead of time.h
* Fixed IPL psw manipulation in dasd-ipl.c
* Minor cosmetic fixes found by review

v2:
* Included cio fixup to get rid of compile errors...
* Minor cosmetic fixes found by review


Janosch Frank (12):
   pc-bios: s390x: cio.c cleanup and compile fix
   pc-bios: s390x: Consolidate timing functions into time.h
   pc-bios: s390x: Move sleep and yield to helper.h
   pc-bios: s390x: Get rid of magic offsets into the lowcore
   pc-bios: s390x: Remove unneeded dasd-ipl.c reset psw mask changes
   pc-bios: s390x: Rename PSW_MASK_ZMODE to PSW_MASK_64
   pc-bios: s390x: Use PSW masks where possible and introduce
 PSW_MASK_SHORT_ADDR
   pc-bios: s390x: Move panic() into header and add infinite loop
   pc-bios: s390x: Use ebcdic2ascii table
   pc-bios: s390x: Make u32 ptr check explicit
   pc-bios: s390x: Fix bootmap.c passing PSWs as addresses
   pc-bios: s390x: Cleanup jump to ipl code

  pc-bios/s390-ccw/bootmap.c |  9 
  pc-bios/s390-ccw/bootmap.h |  2 +-
  pc-bios/s390-ccw/cio.c | 40 +++---
  pc-bios/s390-ccw/cio.h | 17 ++-
  pc-bios/s390-ccw/dasd-ipl.c|  3 ---
  pc-bios/s390-ccw/helper.h  | 19 +++-
  pc-bios/s390-ccw/jump2ipl.c| 35 -
  pc-bios/s390-ccw/main.c| 15 +++--
  pc-bios/s390-ccw/menu.c|  1 +
  pc-bios/s390-ccw/netmain.c | 23 +++
  pc-bios/s390-ccw/s390-arch.h   |  4 +++-
  pc-bios/s390-ccw/s390-ccw.h| 27 ++-
  pc-bios/s390-ccw/s390-time.h   | 23 +++
  pc-bios/s390-ccw/start.S   |  5 +++--
  pc-bios/s390-ccw/virtio-net.c  |  2 ++
  pc-bios/s390-ccw/virtio-scsi.c |  2 ++
  pc-bios/s390-ccw/virtio.c  | 18 +++
  17 files changed, 120 insertions(+), 125 deletions(-)
  create mode 100644 pc-bios/s390-ccw/s390-time.h



Hm... what's the general status of this? Most of the patches have at
least one R-b/A-b already, I see.

Do the s390-ccw boot maintainers want to pick this (once the rest has
been looked at) and then send me a pull req, or should I pick it when
it is good to go? Softfreeze is less than two weeks away :)


I'd like to review the missing parts and run my tests with the patches 
applied ... I'm just a little bit swamped right now, so please give me 
some more time...


 Thomas




[PULL 08/31] configure: add libdaxctl support

2020-06-24 Thread Paolo Bonzini
From: Jingqi Liu 

Add a pair of configure options --{enable,disable}-libdaxctl to control
whether QEMU is compiled with libdaxctl [1]. Libdaxctl is a utility
library for managing the device dax subsystem.

QEMU uses mmap(2) to maps vNVDIMM backends and aligns the mapping
address to the page size (getpagesize(2)) by default. However, some
types of backends may require an alignment different than the page
size. The 'align' option is provided to memory-backend-file to allow
users to specify the proper alignment.

For device dax (e.g., /dev/dax0.0), the 'align' option needs to match
the alignment requirement of the device dax, which can be fetched
through the APIs of libdaxctl version 57 or up.

[1] Libdaxctl is a part of ndctl project.
The project's repository is: https://github.com/pmem/ndctl

For more information about libdaxctl APIs, you can refer to the
comments in source code of: pmem/ndctl/daxctl/lib/libdaxctl.c.

Reviewed-by: Joao Martins 
Signed-off-by: Jingqi Liu 
Message-Id: <20200429085011.63752-4-jingqi@intel.com>
Signed-off-by: Paolo Bonzini 
---
 configure | 29 +
 1 file changed, 29 insertions(+)

diff --git a/configure b/configure
index ba88fd1824..8d9435a0e0 100755
--- a/configure
+++ b/configure
@@ -517,6 +517,7 @@ plugins="no"
 fuzzing="no"
 rng_none="no"
 secret_keyring=""
+libdaxctl=""
 
 supported_cpu="no"
 supported_os="no"
@@ -1621,6 +1622,10 @@ for opt do
   ;;
   --disable-keyring) secret_keyring="no"
   ;;
+  --enable-libdaxctl) libdaxctl=yes
+  ;;
+  --disable-libdaxctl) libdaxctl=no
+  ;;
   *)
   echo "ERROR: unknown option $opt"
   echo "Try '$0 --help' for more information"
@@ -1920,6 +1925,7 @@ disabled with --disable-FEATURE, default is enabled if 
available:
   libpmem libpmem support
   xkbcommon   xkbcommon support
   rng-nonedummy RNG, avoid using /dev/(u)random and getrandom()
+  libdaxctl   libdaxctl support
 
 NOTE: The object files are built at the place where configure is launched
 EOF
@@ -6292,6 +6298,24 @@ if test "$libpmem" != "no"; then
fi
 fi
 
+##
+# check for libdaxctl
+
+if test "$libdaxctl" != "no"; then
+   if $pkg_config --atleast-version=57 "libdaxctl"; then
+   libdaxctl="yes"
+   libdaxctl_libs=$($pkg_config --libs libdaxctl)
+   libdaxctl_cflags=$($pkg_config --cflags libdaxctl)
+   libs_softmmu="$libs_softmmu $libdaxctl_libs"
+   QEMU_CFLAGS="$QEMU_CFLAGS $libdaxctl_cflags"
+   else
+   if test "$libdaxctl" = "yes" ; then
+   feature_not_found "libdaxctl" "Install libdaxctl"
+   fi
+   libdaxctl="no"
+   fi
+fi
+
 ##
 # check for slirp
 
@@ -6898,6 +6922,7 @@ echo "parallels support $parallels"
 echo "sheepdog support  $sheepdog"
 echo "capstone  $capstone"
 echo "libpmem support   $libpmem"
+echo "libdaxctl support $libdaxctl"
 echo "libudev   $libudev"
 echo "default devices   $default_devices"
 echo "plugin support$plugins"
@@ -7731,6 +7756,10 @@ if test "$libpmem" = "yes" ; then
   echo "CONFIG_LIBPMEM=y" >> $config_host_mak
 fi
 
+if test "$libdaxctl" = "yes" ; then
+  echo "CONFIG_LIBDAXCTL=y" >> $config_host_mak
+fi
+
 if test "$bochs" = "yes" ; then
   echo "CONFIG_BOCHS=y" >> $config_host_mak
 fi
-- 
2.26.2





[PULL 16/31] softfloat: fix floatx80 remainder pseudo-denormal check for zero

2020-06-24 Thread Paolo Bonzini
From: Joseph Myers 

The floatx80 remainder implementation ignores the high bit of the
significand when checking whether an operand (numerator) with zero
exponent is zero.  This means it mishandles a pseudo-denormal
representation of 0x1p-16382L by treating it as zero.  Fix this by
checking the whole significand instead.

Signed-off-by: Joseph Myers 
Reviewed-by: Richard Henderson 
Message-Id: 
Signed-off-by: Paolo Bonzini 
---
 fpu/softfloat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index b7dcf4d6c3..f164b5c0ad 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -5741,7 +5741,7 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod,
 normalizeFloatx80Subnormal( bSig, ,  );
 }
 if ( aExp == 0 ) {
-if ( (uint64_t) ( aSig0<<1 ) == 0 ) return a;
+if ( aSig0 == 0 ) return a;
 normalizeFloatx80Subnormal( aSig0, ,  );
 }
 bSig |= UINT64_C(0x8000);
-- 
2.26.2





[PULL 27/31] kvm: i386: allow TSC to differ by NTP correction bounds without TSC scaling

2020-06-24 Thread Paolo Bonzini
From: Marcelo Tosatti 

The Linux TSC calibration procedure is subject to small variations
(its common to see +-1 kHz difference between reboots on a given CPU, for 
example).

So migrating a guest between two hosts with identical processor can fail, in 
case
of a small variation in calibrated TSC between them.

Allow a conservative 250ppm error between host TSC and VM TSC frequencies,
rather than requiring an exact match. NTP daemon in the guest can
correct this difference.

Also change migration to accept this bound.

KVM_SET_TSC_KHZ depends on a kernel interface change. Without this change,
the behaviour remains the same: in case of a different frequency
between host and VM, KVM_SET_TSC_KHZ will fail and QEMU will exit.

Signed-off-by: Marcelo Tosatti 

Message-Id: <20200616165805.ga324...@fuller.cnet>
Signed-off-by: Paolo Bonzini 
---
 target/i386/kvm.c | 46 +-
 1 file changed, 41 insertions(+), 5 deletions(-)

diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index b3c13cb898..6adbff3d74 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -740,26 +740,62 @@ static bool hyperv_enabled(X86CPU *cpu)
  cpu->hyperv_features || cpu->hyperv_passthrough);
 }
 
+/*
+ * Check whether target_freq is within conservative
+ * ntp correctable bounds (250ppm) of freq
+ */
+static inline bool freq_within_bounds(int freq, int target_freq)
+{
+int max_freq = freq + (freq * 250 / 100);
+int min_freq = freq - (freq * 250 / 100);
+
+if (target_freq >= min_freq && target_freq <= max_freq) {
+return true;
+}
+
+return false;
+}
+
 static int kvm_arch_set_tsc_khz(CPUState *cs)
 {
 X86CPU *cpu = X86_CPU(cs);
 CPUX86State *env = >env;
-int r;
+int r, cur_freq;
+bool set_ioctl = false;
 
 if (!env->tsc_khz) {
 return 0;
 }
 
-r = kvm_check_extension(cs->kvm_state, KVM_CAP_TSC_CONTROL) ?
+cur_freq = kvm_check_extension(cs->kvm_state, KVM_CAP_GET_TSC_KHZ) ?
+   kvm_vcpu_ioctl(cs, KVM_GET_TSC_KHZ) : -ENOTSUP;
+
+/*
+ * If TSC scaling is supported, attempt to set TSC frequency.
+ */
+if (kvm_check_extension(cs->kvm_state, KVM_CAP_TSC_CONTROL)) {
+set_ioctl = true;
+}
+
+/*
+ * If desired TSC frequency is within bounds of NTP correction,
+ * attempt to set TSC frequency.
+ */
+if (cur_freq != -ENOTSUP && freq_within_bounds(cur_freq, env->tsc_khz)) {
+set_ioctl = true;
+}
+
+r = set_ioctl ?
 kvm_vcpu_ioctl(cs, KVM_SET_TSC_KHZ, env->tsc_khz) :
 -ENOTSUP;
+
 if (r < 0) {
 /* When KVM_SET_TSC_KHZ fails, it's an error only if the current
  * TSC frequency doesn't match the one we want.
  */
-int cur_freq = kvm_check_extension(cs->kvm_state, KVM_CAP_GET_TSC_KHZ) 
?
-   kvm_vcpu_ioctl(cs, KVM_GET_TSC_KHZ) :
-   -ENOTSUP;
+cur_freq = kvm_check_extension(cs->kvm_state, KVM_CAP_GET_TSC_KHZ) ?
+   kvm_vcpu_ioctl(cs, KVM_GET_TSC_KHZ) :
+   -ENOTSUP;
 if (cur_freq <= 0 || cur_freq != env->tsc_khz) {
 warn_report("TSC frequency mismatch between "
 "VM (%" PRId64 " kHz) and host (%d kHz), "
-- 
2.26.2





Re: [PATCH] hw/core/null-machine: Do not initialize unused chardev backends

2020-06-24 Thread Thomas Huth

On 24/06/2020 12.56, Philippe Mathieu-Daudé wrote:

The MachineClass uses an inverted logic (inherited from the
PC machines [*]) to create the chardev backends for the default
devices (see commits 998bbd74b9d..aa40fc9c964 and ac33f8fad14).

As the none-machine doesn't have any hardware device, it is
pointless to initialize chardev backends. Fix by setting the
'no_defaults' bits in its MachineClass.

Suggested-by: Thomas Huth 
Signed-off-by: Philippe Mathieu-Daudé 
---
  hw/core/null-machine.c | 5 +
  1 file changed, 5 insertions(+)

diff --git a/hw/core/null-machine.c b/hw/core/null-machine.c
index cb47d9d4f8..7e693523d7 100644
--- a/hw/core/null-machine.c
+++ b/hw/core/null-machine.c
@@ -50,6 +50,11 @@ static void machine_none_machine_init(MachineClass *mc)
  mc->max_cpus = 1;
  mc->default_ram_size = 0;
  mc->default_ram_id = "ram";
+mc->no_serial = 1;
+mc->no_parallel = 1;
+mc->no_floppy = 1;
+mc->no_cdrom = 1;
+mc->no_sdcard = 1;
  }
  
  DEFINE_MACHINE("none", machine_none_machine_init)




Reviewed-by: Thomas Huth 




[PATCH v4 10/20] audio: deprecate -soundhw hda

2020-06-24 Thread Gerd Hoffmann
Add deprecation message to the audio init function.

Signed-off-by: Gerd Hoffmann 
---
 hw/audio/intel-hda.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c
index f673b8317a84..f6cea49686d7 100644
--- a/hw/audio/intel-hda.c
+++ b/hw/audio/intel-hda.c
@@ -25,6 +25,7 @@
 #include "qemu/bitops.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
+#include "qemu/error-report.h"
 #include "hw/audio/soundhw.h"
 #include "intel-hda.h"
 #include "migration/vmstate.h"
@@ -1307,6 +1308,8 @@ static int intel_hda_and_codec_init(PCIBus *bus)
 BusState *hdabus;
 DeviceState *codec;
 
+warn_report("'-soundhw hda' is deprecated, "
+"please use '-device intel-hda -device hda-duplex' instead");
 controller = DEVICE(pci_create_simple(bus, -1, "intel-hda"));
 hdabus = QLIST_FIRST(>child_bus);
 codec = qdev_new("hda-duplex");
-- 
2.18.4




[PATCH v4 20/20] audio: set default value for pcspk.iobase property

2020-06-24 Thread Gerd Hoffmann
Allows to drop the explicit qdev_prop_set_uint32 call in pcspk_init.

Signed-off-by: Gerd Hoffmann 
---
 include/hw/audio/pcspk.h | 6 +-
 hw/audio/pcspk.c | 2 +-
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/include/hw/audio/pcspk.h b/include/hw/audio/pcspk.h
index 8b485602675f..06cba00b8376 100644
--- a/include/hw/audio/pcspk.h
+++ b/include/hw/audio/pcspk.h
@@ -33,11 +33,7 @@
 
 static inline void pcspk_init(ISADevice *isadev, ISABus *bus, ISADevice *pit)
 {
-DeviceState *dev;
-
-dev = DEVICE(isadev);
-qdev_prop_set_uint32(dev, "iobase", 0x61);
-object_property_set_link(OBJECT(dev), OBJECT(pit), "pit", NULL);
+object_property_set_link(OBJECT(isadev), OBJECT(pit), "pit", NULL);
 isa_realize_and_unref(isadev, bus, _fatal);
 }
 
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index 4c7e339ac2b5..ea539e7605a8 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -219,7 +219,7 @@ static const VMStateDescription vmstate_spk = {
 
 static Property pcspk_properties[] = {
 DEFINE_AUDIO_PROPERTIES(PCSpkState, card),
-DEFINE_PROP_UINT32("iobase", PCSpkState, iobase,  -1),
+DEFINE_PROP_UINT32("iobase", PCSpkState, iobase,  0x61),
 DEFINE_PROP_BOOL("migrate", PCSpkState, migrate,  true),
 DEFINE_PROP_END_OF_LIST(),
 };
-- 
2.18.4




[PATCH v4 11/20] pc_basic_device_init: pass PCMachineState

2020-06-24 Thread Gerd Hoffmann
Need access to pcms for pcspk initialization.
Just preparation, no functional change.

Signed-off-by: Gerd Hoffmann 
---
 include/hw/i386/pc.h | 3 ++-
 hw/i386/pc.c | 3 ++-
 hw/i386/pc_piix.c| 2 +-
 hw/i386/pc_q35.c | 2 +-
 4 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index e6135c34d656..9b94926410c0 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -160,7 +160,8 @@ void pc_memory_init(PCMachineState *pcms,
 MemoryRegion **ram_memory);
 uint64_t pc_pci_hole64_start(void);
 DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus);
-void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
+void pc_basic_device_init(struct PCMachineState *pcms,
+  ISABus *isa_bus, qemu_irq *gsi,
   ISADevice **rtc_state,
   bool create_fdctrl,
   bool no_vmport,
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index d103b8c0ab82..9afb003dfc21 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1176,7 +1176,8 @@ static void pc_superio_init(ISABus *isa_bus, bool 
create_fdctrl, bool no_vmport)
 g_free(a20_line);
 }
 
-void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
+void pc_basic_device_init(struct PCMachineState *pcms,
+  ISABus *isa_bus, qemu_irq *gsi,
   ISADevice **rtc_state,
   bool create_fdctrl,
   bool no_vmport,
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 1497d0e4ae94..605252fe7936 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -235,7 +235,7 @@ static void pc_init1(MachineState *machine,
 }
 
 /* init basic PC hardware */
-pc_basic_device_init(isa_bus, x86ms->gsi, _state, true,
+pc_basic_device_init(pcms, isa_bus, x86ms->gsi, _state, true,
  (pcms->vmport != ON_OFF_AUTO_ON), pcms->pit_enabled,
  0x4);
 
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 46cd06524c68..e4b15f27227a 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -275,7 +275,7 @@ static void pc_q35_init(MachineState *machine)
 }
 
 /* init basic PC hardware */
-pc_basic_device_init(isa_bus, x86ms->gsi, _state, !mc->no_floppy,
+pc_basic_device_init(pcms, isa_bus, x86ms->gsi, _state, !mc->no_floppy,
  (pcms->vmport != ON_OFF_AUTO_ON), pcms->pit_enabled,
  0xff0104);
 
-- 
2.18.4




[PATCH v2 5/6] virtio-serial-bus: add terminal resize messages

2020-06-24 Thread Szymon Lukasz
Implement the part of the virtio spec that allows to notify the virtio
driver about terminal resizes. The virtio spec contains two methods to
achieve that:

For legacy drivers, we have only one port and we put the terminal size
in the config space and inject the config changed interrupt.

For multiport devices, we use the control virtqueue to send a packet
containing the terminal size. Note that the Linux kernel expects
the fields indicating the number of rows and columns in a packet to be
in a different order than the one specified in the current version of
the virtio spec. We follow the Linux implementation, so hopefully there
is no implementation of this functionality conforming to the spec.

Signed-off-by: Szymon Lukasz 
---
 hw/char/trace-events  |  1 +
 hw/char/virtio-serial-bus.c   | 42 +--
 hw/core/machine.c |  1 +
 include/hw/virtio/virtio-serial.h |  5 
 4 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/hw/char/trace-events b/hw/char/trace-events
index d20eafd56f..be40df47ea 100644
--- a/hw/char/trace-events
+++ b/hw/char/trace-events
@@ -10,6 +10,7 @@ serial_ioport_write(uint16_t addr, uint8_t value) "write addr 
0x%02x val 0x%02x"
 
 # virtio-serial-bus.c
 virtio_serial_send_control_event(unsigned int port, uint16_t event, uint16_t 
value) "port %u, event %u, value %u"
+virtio_serial_send_console_resize(unsigned int port, uint16_t cols, uint16_t 
rows) "port %u, cols %u, rows %u"
 virtio_serial_throttle_port(unsigned int port, bool throttle) "port %u, 
throttle %d"
 virtio_serial_handle_control_message(uint16_t event, uint16_t value) "event 
%u, value %u"
 virtio_serial_handle_control_message_port(unsigned int port) "port %u"
diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index 262089c0c9..6d9e94a64e 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -261,6 +261,42 @@ static size_t send_control_event(VirtIOSerial *vser, 
uint32_t port_id,
 return send_control_msg(vser, , sizeof(cpkt));
 }
 
+/*
+ * This struct should be added to the Linux kernel uapi headers
+ * and later imported to standard-headers/linux/virtio_console.h
+ */
+struct virtio_console_resize {
+__virtio16 rows;
+__virtio16 cols;
+};
+
+void virtio_serial_send_console_resize(VirtIOSerialPort *port,
+   uint16_t cols, uint16_t rows)
+{
+VirtIOSerial *vser = port->vser;
+VirtIODevice *vdev = VIRTIO_DEVICE(vser);
+
+if (virtio_vdev_has_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT)) {
+struct {
+struct virtio_console_control control;
+struct virtio_console_resize resize;
+} buffer;
+
+virtio_stl_p(vdev, , port->id);
+virtio_stw_p(vdev, , VIRTIO_CONSOLE_RESIZE);
+virtio_stw_p(vdev, , cols);
+virtio_stw_p(vdev, , rows);
+
+trace_virtio_serial_send_console_resize(port->id, cols, rows);
+send_control_msg(vser, , sizeof(buffer));
+
+} else if (virtio_vdev_has_feature(vdev, VIRTIO_CONSOLE_F_SIZE)) {
+vser->port0_cols = cols;
+vser->port0_rows = rows;
+virtio_notify_config(vdev);
+}
+}
+
 /* Functions for use inside qemu to open and read from/write to ports */
 int virtio_serial_open(VirtIOSerialPort *port)
 {
@@ -572,8 +608,8 @@ static void get_config(VirtIODevice *vdev, uint8_t 
*config_data)
 struct virtio_console_config *config =
 (struct virtio_console_config *)config_data;
 
-config->cols = 0;
-config->rows = 0;
+config->cols = virtio_tswap16(vdev, vser->port0_cols);
+config->rows = virtio_tswap16(vdev, vser->port0_rows);
 config->max_nr_ports = virtio_tswap32(vdev,
   vser->serial.max_virtserial_ports);
 }
@@ -1168,6 +1204,8 @@ static Property virtio_serial_properties[] = {
   31),
 DEFINE_PROP_BIT64("emergency-write", VirtIOSerial, host_features,
   VIRTIO_CONSOLE_F_EMERG_WRITE, true),
+DEFINE_PROP_BIT64("console-size", VirtIOSerial, host_features,
+  VIRTIO_CONSOLE_F_SIZE, true),
 DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 1d80ab0e1d..c370c220f0 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -30,6 +30,7 @@
 
 GlobalProperty hw_compat_5_0[] = {
 { "virtio-balloon-device", "page-poison", "false" },
+{ "virtio-serial-device", "console-size", "off" },
 };
 const size_t hw_compat_5_0_len = G_N_ELEMENTS(hw_compat_5_0);
 
diff --git a/include/hw/virtio/virtio-serial.h 
b/include/hw/virtio/virtio-serial.h
index ed3e916b68..1d6436c0b1 100644
--- a/include/hw/virtio/virtio-serial.h
+++ b/include/hw/virtio/virtio-serial.h
@@ -188,6 +188,8 @@ struct VirtIOSerial {
 virtio_serial_conf serial;
 
 uint64_t host_features;
+
+uint16_t port0_cols, port0_rows;
 };
 
 /* Interface to the virtio-serial bus 

[PATCH v4 09/20] audio: deprecate -soundhw sb16

2020-06-24 Thread Gerd Hoffmann
Switch to deprecated_register_soundhw().
Remove the now obsolete init function.

Signed-off-by: Gerd Hoffmann 
---
 hw/audio/sb16.c | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/hw/audio/sb16.c b/hw/audio/sb16.c
index df6f755a37f8..2d9e50f99b5d 100644
--- a/hw/audio/sb16.c
+++ b/hw/audio/sb16.c
@@ -1415,12 +1415,6 @@ static void sb16_realizefn (DeviceState *dev, Error 
**errp)
 AUD_register_card ("sb16", >card);
 }
 
-static int SB16_init (ISABus *bus)
-{
-isa_create_simple (bus, TYPE_SB16);
-return 0;
-}
-
 static Property sb16_properties[] = {
 DEFINE_AUDIO_PROPERTIES(SB16State, card),
 DEFINE_PROP_UINT32 ("version", SB16State, ver,  0x0405), /* 4.5 */
@@ -1453,7 +1447,8 @@ static const TypeInfo sb16_info = {
 static void sb16_register_types (void)
 {
 type_register_static (_info);
-isa_register_soundhw("sb16", "Creative Sound Blaster 16", SB16_init);
+deprecated_register_soundhw("sb16", "Creative Sound Blaster 16",
+1, TYPE_SB16);
 }
 
 type_init (sb16_register_types)
-- 
2.18.4




Re: [PATCH v3 2/8] s390/sclp: check sccb len before filling in data

2020-06-24 Thread Thomas Huth

On 19/06/2020 00.22, Collin Walling wrote:

The SCCB must be checked for a sufficient length before it is filled
with any data. If the length is insufficient, then the SCLP command
is suppressed and the proper response code is set in the SCCB header.

Fixes: 832be0d8a3bb ("s390x: sclp: Report insufficient SCCB length")
Signed-off-by: Collin Walling 
Reviewed-by: Janosch Frank 
---
  hw/s390x/sclp.c | 24 
  1 file changed, 12 insertions(+), 12 deletions(-)


Reviewed-by: Thomas Huth 




Re: sysbus failed assert for xen_sysdev

2020-06-24 Thread Jason Andryuk
On Wed, Jun 24, 2020 at 6:29 AM Paul Durrant  wrote:
>
> > -Original Message-
> > From: Jason Andryuk 
> > Sent: 24 June 2020 04:24
> > To: Paul Durrant 
> > Cc: Markus Armbruster ; Mark Cave-Ayland 
> > ; Anthony
> > PERARD ; xen-devel 
> > ; QEMU  > de...@nongnu.org>
> > Subject: Re: sysbus failed assert for xen_sysdev
> >
> > On Tue, Jun 23, 2020 at 7:46 AM Paul Durrant  wrote:
> > >
> > > > -Original Message-
> > > > From: Markus Armbruster 
> > > > Sent: 23 June 2020 09:41
> > > > To: Jason Andryuk 
> > > > Cc: Mark Cave-Ayland ; Anthony PERARD 
> > > > ;
> > xen-
> > > > devel ; Paul Durrant ; 
> > > > QEMU 
> > > > Subject: Re: sysbus failed assert for xen_sysdev
> > > >
> > > > Jason Andryuk  writes:
> > > > > Then it gets farther... until
> > > > > qemu-system-i386: hw/core/qdev.c:439: qdev_assert_realized_properly:
> > > > > Assertion `dev->realized' failed.
> > > > >
> > > > > dev->id is NULL. The failing device is:
> > > > > (gdb) p *dev.parent_obj.class.type
> > > > > $12 = {name = 0x56207770 "cfi.pflash01",
> > > > >
> > >
> > > Having commented out the call to xen_be_init() entirely (and 
> > > xen_bus_init() for good measure) I also
> > get this assertion failure, so
> > > I don't think is related.
> >
> > Yes, this is something different.  pc_pflash_create() calls
> > qdev_new(TYPE_PFLASH_CFI01), but it is only realized in
> > pc_system_flash_map()...  and pc_system_flash_map() isn't called for
> > Xen.
> >
> > Removing the call to pc_system_flash_create() from pc_machine_initfn()
> > lets QEMU startup and run a Xen HVM again.  xen_enabled() doesn't work
> > there since accelerators have not been initialized yes, I guess?
>
> Looks like it can be worked round by the following:

Yes, thank you.

Tested-by: Jason Andryuk 

> diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
> index 1497d0e4ae..977d40afb8 100644
> --- a/hw/i386/pc_piix.c
> +++ b/hw/i386/pc_piix.c
> @@ -186,9 +186,12 @@ static void pc_init1(MachineState *machine,
>  if (!xen_enabled()) {
>  pc_memory_init(pcms, system_memory,
> rom_memory, _memory);
> -} else if (machine->kernel_filename != NULL) {
> -/* For xen HVM direct kernel boot, load linux here */
> -xen_load_linux(pcms);
> +} else {
> +pc_system_flash_cleanup_unused(pcms);
> +if (machine->kernel_filename != NULL) {
> +/* For xen HVM direct kernel boot, load linux here */
> +xen_load_linux(pcms);
> +}
>  }
>
>  gsi_state = pc_gsi_create(>gsi, pcmc->pci_enabled);
> diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c
> index ec2a3b3e7e..0ff47a4b59 100644
> --- a/hw/i386/pc_sysfw.c
> +++ b/hw/i386/pc_sysfw.c
> @@ -108,7 +108,7 @@ void pc_system_flash_create(PCMachineState *pcms)
>  }
>  }
>
> -static void pc_system_flash_cleanup_unused(PCMachineState *pcms)
> +void pc_system_flash_cleanup_unused(PCMachineState *pcms)
>  {
>  char *prop_name;
>  int i;
> diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
> index e6135c34d6..497f2b7ab7 100644
> --- a/include/hw/i386/pc.h
> +++ b/include/hw/i386/pc.h
> @@ -187,6 +187,7 @@ int cmos_get_fd_drive_type(FloppyDriveType fd0);
>
>  /* pc_sysfw.c */
>  void pc_system_flash_create(PCMachineState *pcms);
> +void pc_system_flash_cleanup_unused(PCMachineState *pcms);
>  void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memory);
>
>  /* acpi-build.c */
>
>
> >
> > Regards,
> > Jason
>



Re: [PATCH v3 6/8] s390/sclp: add extended-length sccb support for kvm guest

2020-06-24 Thread Thomas Huth

On 24/06/2020 14.36, Cornelia Huck wrote:

On Thu, 18 Jun 2020 18:22:56 -0400
Collin Walling  wrote:


As more features and facilities are added to the Read SCP Info (RSCPI)
response, more space is required to store them. The space used to store
these new features intrudes on the space originally used to store CPU
entries. This means as more features and facilities are added to the
RSCPI response, less space can be used to store CPU entries.

With the Extended-Length SCCB (ELS) facility, a KVM guest can execute
the RSCPI command and determine if the SCCB is large enough to store a
complete reponse. If it is not large enough, then the required length
will be set in the SCCB header.

The caller of the SCLP command is responsible for creating a
large-enough SCCB to store a complete response. Proper checking should
be in place, and the caller should execute the command once-more with
the large-enough SCCB.

This facility also enables an extended SCCB for the Read CPU Info
(RCPUI) command.

When this facility is enabled, the boundary violation response cannot
be a result from the RSCPI, RSCPI Forced, or RCPUI commands.

In order to tolerate kernels that do not yet have full support for this
feature, a "fixed" offset to the start of the CPU Entries within the
Read SCP Info struct is set to allow for the original 248 max entries
when this feature is disabled.

Additionally, this is introduced as a CPU feature to protect the guest
from migrating to a machine that does not support storing an extended
SCCB. This could otherwise hinder the VM from being able to read all
available CPU entries after migration (such as during re-ipl).

Signed-off-by: Collin Walling 
---
  hw/s390x/sclp.c | 21 -
  include/hw/s390x/sclp.h |  1 +
  target/s390x/cpu_features_def.inc.h |  1 +
  target/s390x/gen-features.c |  1 +
  target/s390x/kvm.c  |  8 
  5 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
index 0dfbe6e5ec..f7c49e339e 100644
--- a/hw/s390x/sclp.c
+++ b/hw/s390x/sclp.c
@@ -56,6 +56,18 @@ static bool sccb_has_valid_boundary(uint64_t sccb_addr, 
uint32_t code,
  uint64_t sccb_boundary = (sccb_addr & PAGE_MASK) + PAGE_SIZE;
  
  switch (code & SCLP_CMD_CODE_MASK) {

+case SCLP_CMDW_READ_SCP_INFO:
+case SCLP_CMDW_READ_SCP_INFO_FORCED:
+case SCLP_CMDW_READ_CPU_INFO:
+/*
+ * An extended-length SCCB is only allowed for Read SCP/CPU Info and
+ * is allowed to exceed the 4k boundary. The respective commands will
+ * set the length field to the required length if an insufficient
+ * SCCB length is provided.
+ */
+if (s390_has_feat(S390_FEAT_EXTENDED_LENGTH_SCCB)) {
+return true;
+}


Add a fallthrough annotation?


... otherwise Coverity and friends will complain later.


  default:
  if (sccb_max_addr < sccb_boundary) {
  return true;
@@ -72,6 +84,10 @@ static bool sccb_sufficient_len(SCCB *sccb, int num_cpus, 
int data_len)
  
  if (be16_to_cpu(sccb->h.length) < required_len) {

  sccb->h.response_code = cpu_to_be16(SCLP_RC_INSUFFICIENT_SCCB_LENGTH);
+if (s390_has_feat(S390_FEAT_EXTENDED_LENGTH_SCCB) &&
+sccb->h.control_mask[2] & SCLP_VARIABLE_LENGTH_RESPONSE) {
+sccb->h.length = required_len;
+}
  return false;
  }
  return true;
@@ -101,7 +117,9 @@ static void prepare_cpu_entries(MachineState *ms, CPUEntry 
*entry, int *count)
   */
  static inline int get_read_scp_info_data_len(void)
  {
-return offsetof(ReadInfo, entries);
+return s390_has_feat(S390_FEAT_EXTENDED_LENGTH_SCCB) ?
+   offsetof(ReadInfo, entries) :
+   SCLP_READ_SCP_INFO_FIXED_CPU_OFFSET;
  }
  
  /* Provide information about the configuration, CPUs and storage */

@@ -116,6 +134,7 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
  CPUEntry *entries_start = (void *)sccb + data_len;
  
  if (!sccb_sufficient_len(sccb, machine->possible_cpus->len, data_len)) {

+warn_report("insufficient sccb size to store read scp info response");


Hm, this warning is triggered by a guest action, isn't it? Not sure how
helpful it is.


I think this should be qemu_log_mask(LOG_GUEST_ERROR, ...) instead?

 Thomas




Re: [PATCH v3 8/8] s390: guest support for diagnose 0x318

2020-06-24 Thread Cornelia Huck
On Thu, 18 Jun 2020 18:22:58 -0400
Collin Walling  wrote:

> DIAGNOSE 0x318 (diag318) is an s390 instruction that allows the storage
> of diagnostic information that is collected by the firmware in the case
> of hardware/firmware service events.
> 
> QEMU handles the instruction by storing the info in the CPU state. A
> subsequent register sync will communicate the data to the hypervisor.
> 
> QEMU handles the migration via a VM State Description.
> 
> This feature depends on the Extended-Length SCCB (els) feature. If
> els is not present, then a warning will be printed and the SCLP bit
> that allows the Linux kernel to execute the instruction will not be
> set.
> 
> Availability of this instruction is determined by byte 134 (aka fac134)
> bit 0 of the SCLP Read Info block. This coincidentally expands into the
> space used for CPU entries, which means VMs running with the diag318
> capability may not be able to read information regarding all CPUs
> unless the guest kernel supports an extended-length SCCB.

We cannot do anything about that, I guess.

> 
> This feature is not supported in protected virtualization mode.
> 
> Signed-off-by: Collin Walling 
> ---
>  hw/s390x/sclp.c |  5 +
>  include/hw/s390x/sclp.h |  3 +++
>  target/s390x/cpu.h  |  3 ++-
>  target/s390x/cpu_features.h |  1 +
>  target/s390x/cpu_features_def.inc.h |  3 +++
>  target/s390x/cpu_models.c   |  1 +
>  target/s390x/gen-features.c |  1 +
>  target/s390x/kvm.c  | 31 +
>  target/s390x/machine.c  | 17 
>  9 files changed, 64 insertions(+), 1 deletion(-)

LGTM.




[PATCH v5 06/10] usb: build usb-redir as module

2020-06-24 Thread Gerd Hoffmann
Drops libusbredirparser.so dependency from core qemu.

Signed-off-by: Gerd Hoffmann 
---
 util/module.c| 1 +
 hw/usb/Makefile.objs | 9 ++---
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/util/module.c b/util/module.c
index 89da9a3cce05..e3226165e91c 100644
--- a/util/module.c
+++ b/util/module.c
@@ -263,6 +263,7 @@ static struct {
 } const qom_modules[] = {
 { "ccid-card-passthru","hw-", "usb-smartcard" },
 { "ccid-card-emulated","hw-", "usb-smartcard" },
+{ "usb-redir", "hw-", "usb-redirect"  },
 };
 
 static bool module_loaded_qom_all;
diff --git a/hw/usb/Makefile.objs b/hw/usb/Makefile.objs
index 3c5b3d4fadd3..e342ff59fab0 100644
--- a/hw/usb/Makefile.objs
+++ b/hw/usb/Makefile.objs
@@ -43,9 +43,12 @@ endif
 
 # usb redirection
 ifeq ($(CONFIG_USB),y)
-common-obj-$(CONFIG_USB_REDIR) += redirect.o quirks.o
-redirect.o-cflags = $(USB_REDIR_CFLAGS)
-redirect.o-libs = $(USB_REDIR_LIBS)
+ifeq ($(CONFIG_USB_REDIR),y)
+common-obj-m += redirect.mo
+redirect.mo-objs = redirect.o quirks.o
+redirect.mo-cflags = $(USB_REDIR_CFLAGS)
+redirect.mo-libs = $(USB_REDIR_LIBS)
+endif
 endif
 
 # usb pass-through
-- 
2.18.4




[PATCH v5 09/10] vga: build virtio-gpu as module

2020-06-24 Thread Gerd Hoffmann
Drops libvirglrenderer.so dependency from core qemu.

Signed-off-by: Gerd Hoffmann 
---
 util/module.c|  6 ++
 hw/display/Makefile.objs | 23 +--
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/util/module.c b/util/module.c
index 7c76d2a84b94..a74214eac052 100644
--- a/util/module.c
+++ b/util/module.c
@@ -266,6 +266,12 @@ static struct {
 { "usb-redir", "hw-", "usb-redirect"  },
 { "qxl-vga",   "hw-", "display-qxl"   },
 { "qxl",   "hw-", "display-qxl"   },
+{ "virtio-gpu-device", "hw-", "display-virtio-gpu"},
+{ "virtio-gpu-pci","hw-", "display-virtio-gpu"},
+{ "virtio-vga","hw-", "display-virtio-gpu"},
+{ "vhost-user-gpu-device", "hw-", "display-virtio-gpu"},
+{ "vhost-user-gpu-pci","hw-", "display-virtio-gpu"},
+{ "vhost-user-vga","hw-", "display-virtio-gpu"},
 };
 
 static bool module_loaded_qom_all;
diff --git a/hw/display/Makefile.objs b/hw/display/Makefile.objs
index d619594ad4d3..e907f3182b0c 100644
--- a/hw/display/Makefile.objs
+++ b/hw/display/Makefile.objs
@@ -49,16 +49,19 @@ common-obj-m += qxl.mo
 qxl.mo-objs = qxl.o qxl-logger.o qxl-render.o
 endif
 
-common-obj-$(CONFIG_VIRTIO_GPU) += virtio-gpu-base.o virtio-gpu.o 
virtio-gpu-3d.o
-common-obj-$(CONFIG_VHOST_USER_GPU) += vhost-user-gpu.o
-common-obj-$(call land,$(CONFIG_VIRTIO_GPU),$(CONFIG_VIRTIO_PCI)) += 
virtio-gpu-pci.o
-common-obj-$(call land,$(CONFIG_VHOST_USER_GPU),$(CONFIG_VIRTIO_PCI)) += 
vhost-user-gpu-pci.o
-common-obj-$(CONFIG_VIRTIO_VGA) += virtio-vga.o
-common-obj-$(CONFIG_VHOST_USER_VGA) += vhost-user-vga.o
-virtio-gpu.o-cflags := $(VIRGL_CFLAGS)
-virtio-gpu.o-libs += $(VIRGL_LIBS)
-virtio-gpu-3d.o-cflags := $(VIRGL_CFLAGS)
-virtio-gpu-3d.o-libs += $(VIRGL_LIBS)
+ifeq ($(CONFIG_VIRTIO_GPU),y)
+common-obj-m += virtio-gpu.mo
+virtio-gpu-obj-$(CONFIG_VIRTIO_GPU) += virtio-gpu-base.o virtio-gpu.o 
virtio-gpu-3d.o
+virtio-gpu-obj-$(CONFIG_VHOST_USER_GPU) += vhost-user-gpu.o
+virtio-gpu-obj-$(call land,$(CONFIG_VIRTIO_GPU),$(CONFIG_VIRTIO_PCI)) += 
virtio-gpu-pci.o
+virtio-gpu-obj-$(call land,$(CONFIG_VHOST_USER_GPU),$(CONFIG_VIRTIO_PCI)) += 
vhost-user-gpu-pci.o
+virtio-gpu-obj-$(CONFIG_VIRTIO_VGA) += virtio-vga.o
+virtio-gpu-obj-$(CONFIG_VHOST_USER_VGA) += vhost-user-vga.o
+virtio-gpu.mo-objs := $(virtio-gpu-obj-y)
+virtio-gpu.mo-cflags := $(VIRGL_CFLAGS)
+virtio-gpu.mo-libs := $(VIRGL_LIBS)
+endif
+
 common-obj-$(CONFIG_DPCD) += dpcd.o
 common-obj-$(CONFIG_XLNX_ZYNQMP_ARM) += xlnx_dp.o
 
-- 
2.18.4




[PATCH v2 09/25] tests/vm: change scripts to use self._config

2020-06-24 Thread Alex Bennée
From: 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 
Signed-off-by: Alex Bennée 
Message-Id: <20200601211421.1277-8-robert.fo...@linaro.org>
---
 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 5fd66f6b26a..f716798b405 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 a9195670f4b..b2b478fdbca 100755
--- a/tests/vm/fedora
+++ b/tests/vm/fedora
@@ -108,20 +108,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:
@@ -139,7 +139,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")
 
@@ -150,12 +150,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 f87db2b126e..29252fa4a64 100755
--- a/tests/vm/freebsd
+++ b/tests/vm/freebsd
@@ -113,9 +113,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")
 

[PATCH v2 24/25] gitlab: add avocado asset caching

2020-06-24 Thread Alex Bennée
These can be quite big so lets cache them. I couldn't find any nots on
ccache in the gitlab docs so I've just ignored it for now.

Signed-off-by: Alex Bennée 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20200622143204.12921-19-alex.ben...@linaro.org>
---
 .gitlab-ci.yml | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 54da29dd384..683a1d90fe6 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -8,6 +8,12 @@ stages:
   - build
   - test
 
+# We assume GitLab has it's own caching set up for RPM/APT repositories so we
+# just take care of avocado assets here.
+cache:
+  paths:
+- $HOME/avocado/data/cache
+
 include:
   - local: '/.gitlab-ci.d/edk2.yml'
   - local: '/.gitlab-ci.d/opensbi.yml'
-- 
2.20.1




[PATCH v2 23/25] gitlab: enable check-tcg for linux-user tests

2020-06-24 Thread Alex Bennée
We should have the containers available now.

Signed-off-by: Alex Bennée 
---
 .gitlab-ci.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 7fcbdacd9e9..54da29dd384 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -142,7 +142,7 @@ build-user:
 IMAGE: ubuntu2004
 CONFIGURE_ARGS: --disable-system --disable-guest-agent
   --disable-capstone --disable-slirp --disable-fdt
-MAKE_CHECK_ARGS:  run-tcg-tests-i386-linux-user 
run-tcg-tests-x86_64-linux-user
+MAKE_CHECK_ARGS: check-tcg
 
 build-clang:
   <<: *native_build_job_definition
-- 
2.20.1




[PULL 11/31] hw/scsi/megasas: Fix possible out-of-bounds array access in tracepoints

2020-06-24 Thread Paolo Bonzini
From: Thomas Huth 

Some tracepoints in megasas.c use a guest-controlled value as an index
into the mfi_frame_desc[] array. Thus a malicious guest could cause an
out-of-bounds error here. Fortunately, the impact is very low since this
can only happen when the corresponding tracepoints have been enabled
before, but the problem should be fixed anyway with a proper check.

Buglink: https://bugs.launchpad.net/qemu/+bug/1882065
Signed-off-by: Thomas Huth 
Message-Id: <20200615072629.32321-1-th...@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé 
Signed-off-by: Paolo Bonzini 
---
 hw/scsi/megasas.c | 36 +++-
 1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
index 634af0bbb8..5cfd1bf22e 100644
--- a/hw/scsi/megasas.c
+++ b/hw/scsi/megasas.c
@@ -54,10 +54,6 @@
 #define MEGASAS_FLAG_USE_QUEUE64   1
 #define MEGASAS_MASK_USE_QUEUE64   (1 << MEGASAS_FLAG_USE_QUEUE64)
 
-static const char *mfi_frame_desc[] = {
-"MFI init", "LD Read", "LD Write", "LD SCSI", "PD SCSI",
-"MFI Doorbell", "MFI Abort", "MFI SMP", "MFI Stop"};
-
 typedef struct MegasasCmd {
 uint32_t index;
 uint16_t flags;
@@ -183,6 +179,20 @@ static void megasas_frame_set_scsi_status(MegasasState *s,
 stb_pci_dma(pci, frame + offsetof(struct mfi_frame_header, scsi_status), 
v);
 }
 
+static inline const char *mfi_frame_desc(unsigned int cmd)
+{
+static const char *mfi_frame_descs[] = {
+"MFI init", "LD Read", "LD Write", "LD SCSI", "PD SCSI",
+"MFI Doorbell", "MFI Abort", "MFI SMP", "MFI Stop"
+};
+
+if (cmd < ARRAY_SIZE(mfi_frame_descs)) {
+return mfi_frame_descs[cmd];
+}
+
+return "Unknown";
+}
+
 /*
  * Context is considered opaque, but the HBA firmware is running
  * in little endian mode. So convert it to little endian, too.
@@ -1670,25 +1680,25 @@ static int megasas_handle_scsi(MegasasState *s, 
MegasasCmd *cmd,
 if (is_logical) {
 if (target_id >= MFI_MAX_LD || lun_id != 0) {
 trace_megasas_scsi_target_not_present(
-mfi_frame_desc[frame_cmd], is_logical, target_id, lun_id);
+mfi_frame_desc(frame_cmd), is_logical, target_id, lun_id);
 return MFI_STAT_DEVICE_NOT_FOUND;
 }
 }
 sdev = scsi_device_find(>bus, 0, target_id, lun_id);
 
 cmd->iov_size = le32_to_cpu(cmd->frame->header.data_len);
-trace_megasas_handle_scsi(mfi_frame_desc[frame_cmd], is_logical,
+trace_megasas_handle_scsi(mfi_frame_desc(frame_cmd), is_logical,
   target_id, lun_id, sdev, cmd->iov_size);
 
 if (!sdev || (megasas_is_jbod(s) && is_logical)) {
 trace_megasas_scsi_target_not_present(
-mfi_frame_desc[frame_cmd], is_logical, target_id, lun_id);
+mfi_frame_desc(frame_cmd), is_logical, target_id, lun_id);
 return MFI_STAT_DEVICE_NOT_FOUND;
 }
 
 if (cdb_len > 16) {
 trace_megasas_scsi_invalid_cdb_len(
-mfi_frame_desc[frame_cmd], is_logical,
+mfi_frame_desc(frame_cmd), is_logical,
 target_id, lun_id, cdb_len);
 megasas_write_sense(cmd, SENSE_CODE(INVALID_OPCODE));
 cmd->frame->header.scsi_status = CHECK_CONDITION;
@@ -1706,7 +1716,7 @@ static int megasas_handle_scsi(MegasasState *s, 
MegasasCmd *cmd,
 cmd->req = scsi_req_new(sdev, cmd->index, lun_id, cdb, cmd);
 if (!cmd->req) {
 trace_megasas_scsi_req_alloc_failed(
-mfi_frame_desc[frame_cmd], target_id, lun_id);
+mfi_frame_desc(frame_cmd), target_id, lun_id);
 megasas_write_sense(cmd, SENSE_CODE(NO_SENSE));
 cmd->frame->header.scsi_status = BUSY;
 s->event_count++;
@@ -1751,17 +1761,17 @@ static int megasas_handle_io(MegasasState *s, 
MegasasCmd *cmd, int frame_cmd)
 }
 
 trace_megasas_handle_io(cmd->index,
-mfi_frame_desc[frame_cmd], target_id, lun_id,
+mfi_frame_desc(frame_cmd), target_id, lun_id,
 (unsigned long)lba_start, (unsigned 
long)lba_count);
 if (!sdev) {
 trace_megasas_io_target_not_present(cmd->index,
-mfi_frame_desc[frame_cmd], target_id, lun_id);
+mfi_frame_desc(frame_cmd), target_id, lun_id);
 return MFI_STAT_DEVICE_NOT_FOUND;
 }
 
 if (cdb_len > 16) {
 trace_megasas_scsi_invalid_cdb_len(
-mfi_frame_desc[frame_cmd], 1, target_id, lun_id, cdb_len);
+mfi_frame_desc(frame_cmd), 1, target_id, lun_id, cdb_len);
 megasas_write_sense(cmd, SENSE_CODE(INVALID_OPCODE));
 cmd->frame->header.scsi_status = CHECK_CONDITION;
 s->event_count++;
@@ -1781,7 +1791,7 @@ static int megasas_handle_io(MegasasState *s, MegasasCmd 
*cmd, int frame_cmd)
 lun_id, cdb, cmd);
 if (!cmd->req) {
 trace_megasas_scsi_req_alloc_failed(
-

[PULL 25/31] osdep: Make MIN/MAX evaluate arguments only once

2020-06-24 Thread Paolo Bonzini
From: Eric Blake 

I'm not aware of any immediate bugs in qemu where a second runtime
evalution of the arguments to MIN() or MAX() causes a problem, but
proactively preventing such abuse is easier than falling prey to an
unintended case down the road.  At any rate, here's the conversation
that sparked the current patch:
https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg05718.html

Update the MIN/MAX macros to only evaluate their argument once at
runtime; this uses typeof(1 ? (a) : (b)) to ensure that we are
promoting the temporaries to the same type as the final comparison (we
have to trigger type promotion, as typeof(bitfield) won't compile; and
we can't use typeof((a) + (b)) or even typeof((a) + 0), as some of our
uses of MAX are on void* pointers where such addition is undefined).

However, we are unable to work around gcc refusing to compile ({}) in
a constant context (such as the array length of a static variable),
even when only used in the dead branch of a __builtin_choose_expr(),
so we have to provide a second macro pair MIN_CONST and MAX_CONST for
use when both arguments are known to be compile-time constants and
where the result must also be usable as a constant; this second form
evaluates arguments multiple times but that doesn't matter for
constants.  By using a void expression as the expansion if a
non-constant is presented to this second form, we can enlist the
compiler to ensure the double evaluation is not attempted on
non-constants.

Alas, as both macros now rely on compiler intrinsics, they are no
longer usable in preprocessor #if conditions; those will just have to
be open-coded or the logic rewritten into #define or runtime 'if'
conditions (but where the compiler dead-code-elimination will probably
still apply).

I tested that both gcc 10.1.1 and clang 10.0.0 produce errors for all
forms of macro mis-use.  As the errors can sometimes be cryptic, I'm
demonstrating the gcc output:

Use of MIN when MIN_CONST is needed:

In file included from /home/eblake/qemu/qemu-img.c:25:
/home/eblake/qemu/include/qemu/osdep.h:249:5: error: braced-group within 
expression allowed only inside a function
  249 | ({  \
  | ^
/home/eblake/qemu/qemu-img.c:92:12: note: in expansion of macro ‘MIN’
   92 | char array[MIN(1, 2)] = "";
  |^~~

Use of MIN_CONST when MIN is needed:

/home/eblake/qemu/qemu-img.c: In function ‘is_allocated_sectors’:
/home/eblake/qemu/qemu-img.c:1225:15: error: void value not ignored as it ought 
to be
 1225 | i = MIN_CONST(i, n);
  |   ^

Use of MIN in the preprocessor:

In file included from /home/eblake/qemu/accel/tcg/translate-all.c:20:
/home/eblake/qemu/accel/tcg/translate-all.c: In function ‘page_check_range’:
/home/eblake/qemu/include/qemu/osdep.h:249:6: error: token "{" is not valid in 
preprocessor expressions
  249 | ({  \
  |  ^

Fix the resulting callsites that used #if or computed a compile-time
constant min or max to use the new macros.  cpu-defs.h is interesting,
as CPU_TLB_DYN_MAX_BITS is sometimes used as a constant and sometimes
dynamic.

Signed-off-by: Eric Blake 

Message-Id: <20200604215236.2798244-1-ebl...@redhat.com>
Signed-off-by: Paolo Bonzini 
---
 accel/tcg/translate-all.c |  6 ++---
 hw/usb/hcd-xhci.h |  2 +-
 include/block/block.h |  4 +--
 include/exec/cpu-all.h|  8 +++---
 include/exec/cpu-defs.h   |  7 -
 include/qemu/osdep.h  | 55 ---
 migration/qemu-file.c |  2 +-
 7 files changed, 61 insertions(+), 23 deletions(-)

diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index c3d37058a1..2afa46bd2b 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -2582,9 +2582,9 @@ int page_check_range(target_ulong start, target_ulong 
len, int flags)
 /* This function should never be called with addresses outside the
guest address space.  If this assert fires, it probably indicates
a missing call to h2g_valid.  */
-#if TARGET_ABI_BITS > L1_MAP_ADDR_SPACE_BITS
-assert(start < ((target_ulong)1 << L1_MAP_ADDR_SPACE_BITS));
-#endif
+if (TARGET_ABI_BITS > L1_MAP_ADDR_SPACE_BITS) {
+assert(start < ((target_ulong)1 << L1_MAP_ADDR_SPACE_BITS));
+}
 
 if (len == 0) {
 return 0;
diff --git a/hw/usb/hcd-xhci.h b/hw/usb/hcd-xhci.h
index 2fad4df2a7..946af51fc2 100644
--- a/hw/usb/hcd-xhci.h
+++ b/hw/usb/hcd-xhci.h
@@ -214,7 +214,7 @@ struct XHCIState {
 uint32_t dcbaap_high;
 uint32_t config;
 
-USBPort  uports[MAX(MAXPORTS_2, MAXPORTS_3)];
+USBPort  uports[MAX_CONST(MAXPORTS_2, MAXPORTS_3)];
 XHCIPort ports[MAXPORTS];
 XHCISlot slots[MAXSLOTS];
 uint32_t numports;
diff --git a/include/block/block.h b/include/block/block.h
index 25e299605e..e8fc814996 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -133,8 

[PULL 13/31] xen: Actually fix build without passthrough

2020-06-24 Thread Paolo Bonzini
From: Anthony PERARD 

Fix typo.

Fixes: acd0c9416d48 ("xen: fix build without pci passthrough")
Signed-off-by: Anthony PERARD 
Message-Id: <20200619103115.254127-1-anthony.per...@citrix.com>
Signed-off-by: Paolo Bonzini 
---
 hw/xen/Makefile.objs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/xen/Makefile.objs b/hw/xen/Makefile.objs
index 3fc715e595..502b32d877 100644
--- a/hw/xen/Makefile.objs
+++ b/hw/xen/Makefile.objs
@@ -4,4 +4,4 @@ common-obj-y += xen-legacy-backend.o xen_devconfig.o 
xen_pvdev.o xen-bus.o xen-b
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o 
xen_pt_graphics.o xen_pt_msi.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt_load_rom.o
-obj-$(call $(lnot, $(CONFIG_XEN_PCI_PASSTHROUGH))) += xen_pt_stub.o
+obj-$(call lnot,$(CONFIG_XEN_PCI_PASSTHROUGH)) += xen_pt_stub.o
-- 
2.26.2





[PULL 09/31] exec: fetch the alignment of Linux devdax pmem character device nodes

2020-06-24 Thread Paolo Bonzini
From: Jingqi Liu 

If the backend file is devdax pmem character device, the alignment
specified by the option 'align=NUM' in the '-object memory-backend-file'
needs to match the alignment requirement of the devdax pmem character device.

This patch uses the interfaces of libdaxctl to fetch the devdax pmem file
'align', so that we can compare it with the NUM of 'align=NUM'.
The NUM needs to be larger than or equal to the devdax pmem file 'align'.

It also fixes the problem that mmap() returns failure in qemu_ram_mmap()
when the NUM of 'align=NUM' is less than the devdax pmem file 'align'.

Suggested-by: Dan Williams 
Reviewed-by: Joao Martins 
Signed-off-by: Jingqi Liu 
Message-Id: <20200429085011.63752-2-jingqi@intel.com>
Signed-off-by: Paolo Bonzini 
---
 exec.c | 54 +-
 1 file changed, 53 insertions(+), 1 deletion(-)

diff --git a/exec.c b/exec.c
index d6712fba7e..37c921f364 100644
--- a/exec.c
+++ b/exec.c
@@ -77,6 +77,10 @@
 
 #include "monitor/monitor.h"
 
+#ifdef CONFIG_LIBDAXCTL
+#include 
+#endif
+
 //#define DEBUG_SUBPAGE
 
 #if !defined(CONFIG_USER_ONLY)
@@ -1745,6 +1749,46 @@ static int64_t get_file_size(int fd)
 return size;
 }
 
+static int64_t get_file_align(int fd)
+{
+int64_t align = -1;
+#if defined(__linux__) && defined(CONFIG_LIBDAXCTL)
+struct stat st;
+
+if (fstat(fd, ) < 0) {
+return -errno;
+}
+
+/* Special handling for devdax character devices */
+if (S_ISCHR(st.st_mode)) {
+g_autofree char *path = NULL;
+g_autofree char *rpath = NULL;
+struct daxctl_ctx *ctx;
+struct daxctl_region *region;
+int rc = 0;
+
+path = g_strdup_printf("/sys/dev/char/%d:%d",
+major(st.st_rdev), minor(st.st_rdev));
+rpath = realpath(path, NULL);
+
+rc = daxctl_new();
+if (rc) {
+return -1;
+}
+
+daxctl_region_foreach(ctx, region) {
+if (strstr(rpath, daxctl_region_get_path(region))) {
+align = daxctl_region_get_align(region);
+break;
+}
+}
+daxctl_unref(ctx);
+}
+#endif /* defined(__linux__) && defined(CONFIG_LIBDAXCTL) */
+
+return align;
+}
+
 static int file_ram_open(const char *path,
  const char *region_name,
  bool *created,
@@ -2296,7 +2340,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, 
MemoryRegion *mr,
 {
 RAMBlock *new_block;
 Error *local_err = NULL;
-int64_t file_size;
+int64_t file_size, file_align;
 
 /* Just support these ram flags by now. */
 assert((ram_flags & ~(RAM_SHARED | RAM_PMEM)) == 0);
@@ -2332,6 +2376,14 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, 
MemoryRegion *mr,
 return NULL;
 }
 
+file_align = get_file_align(fd);
+if (file_align > 0 && mr && file_align > mr->align) {
+error_setg(errp, "backing store align 0x%" PRIx64
+   " is larger than 'align' option 0x" RAM_ADDR_FMT,
+   file_align, mr->align);
+return NULL;
+}
+
 new_block = g_malloc0(sizeof(*new_block));
 new_block->mr = mr;
 new_block->used_length = size;
-- 
2.26.2





[PULL 17/31] softfloat: do not return pseudo-denormal from floatx80 remainder

2020-06-24 Thread Paolo Bonzini
From: Joseph Myers 

The floatx80 remainder implementation sometimes returns the numerator
unchanged when the denominator is sufficiently larger than the
numerator.  But if the value to be returned unchanged is a
pseudo-denormal, that is incorrect.  Fix it to normalize the numerator
in that case.

Signed-off-by: Joseph Myers 
Reviewed-by: Richard Henderson 
Message-Id: 
Signed-off-by: Paolo Bonzini 
---
 fpu/softfloat.c | 22 +++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/fpu/softfloat.c b/fpu/softfloat.c
index f164b5c0ad..ab50088c35 100644
--- a/fpu/softfloat.c
+++ b/fpu/softfloat.c
@@ -5706,7 +5706,7 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod,
  float_status *status)
 {
 bool aSign, zSign;
-int32_t aExp, bExp, expDiff;
+int32_t aExp, bExp, expDiff, aExpOrig;
 uint64_t aSig0, aSig1, bSig;
 uint64_t q, term0, term1, alternateASig0, alternateASig1;
 
@@ -5715,7 +5715,7 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool mod,
 return floatx80_default_nan(status);
 }
 aSig0 = extractFloatx80Frac( a );
-aExp = extractFloatx80Exp( a );
+aExpOrig = aExp = extractFloatx80Exp( a );
 aSign = extractFloatx80Sign( a );
 bSig = extractFloatx80Frac( b );
 bExp = extractFloatx80Exp( b );
@@ -5730,6 +5730,13 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool 
mod,
 if ((uint64_t)(bSig << 1)) {
 return propagateFloatx80NaN(a, b, status);
 }
+if (aExp == 0 && aSig0 >> 63) {
+/*
+ * Pseudo-denormal argument must be returned in normalized
+ * form.
+ */
+return packFloatx80(aSign, 1, aSig0);
+}
 return a;
 }
 if ( bExp == 0 ) {
@@ -5749,7 +5756,16 @@ floatx80 floatx80_modrem(floatx80 a, floatx80 b, bool 
mod,
 expDiff = aExp - bExp;
 aSig1 = 0;
 if ( expDiff < 0 ) {
-if ( mod || expDiff < -1 ) return a;
+if ( mod || expDiff < -1 ) {
+if (aExp == 1 && aExpOrig == 0) {
+/*
+ * Pseudo-denormal argument must be returned in
+ * normalized form.
+ */
+return packFloatx80(aSign, aExp, aSig0);
+}
+return a;
+}
 shift128Right( aSig0, 0, 1, ,  );
 expDiff = 0;
 }
-- 
2.26.2





[PULL 23/31] target/i386: reimplement fpatan using floatx80 operations

2020-06-24 Thread Paolo Bonzini
From: Joseph Myers 

The x87 fpatan emulation is currently based around conversion to
double.  This is inherently unsuitable for a good emulation of any
floatx80 operation.  Reimplement using the soft-float operations, as
for other such instructions.

Signed-off-by: Joseph Myers 

Message-Id: 
Signed-off-by: Paolo Bonzini 
---
 target/i386/fpu_helper.c  |  487 -
 tests/tcg/i386/test-i386-fpatan.c | 1071 +
 2 files changed, 1554 insertions(+), 4 deletions(-)
 create mode 100644 tests/tcg/i386/test-i386-fpatan.c

diff --git a/target/i386/fpu_helper.c b/target/i386/fpu_helper.c
index 62820bc735..71cec3962f 100644
--- a/target/i386/fpu_helper.c
+++ b/target/i386/fpu_helper.c
@@ -1239,14 +1239,493 @@ void helper_fptan(CPUX86State *env)
 }
 }
 
+/* Values of pi/4, pi/2, 3pi/4 and pi, with 128-bit precision.  */
+#define pi_4_exp 0x3ffe
+#define pi_4_sig_high 0xc90fdaa22168c234ULL
+#define pi_4_sig_low 0xc4c6628b80dc1cd1ULL
+#define pi_2_exp 0x3fff
+#define pi_2_sig_high 0xc90fdaa22168c234ULL
+#define pi_2_sig_low 0xc4c6628b80dc1cd1ULL
+#define pi_34_exp 0x4000
+#define pi_34_sig_high 0x96cbe3f9990e91a7ULL
+#define pi_34_sig_low 0x9394c9e8a0a5159dULL
+#define pi_exp 0x4000
+#define pi_sig_high 0xc90fdaa22168c234ULL
+#define pi_sig_low 0xc4c6628b80dc1cd1ULL
+
+/*
+ * Polynomial coefficients for an approximation to atan(x), with only
+ * odd powers of x used, for x in the interval [-1/16, 1/16].  (Unlike
+ * for some other approximations, no low part is needed for the first
+ * coefficient here to achieve a sufficiently accurate result, because
+ * the coefficient in this minimax approximation is very close to
+ * exactly 1.)
+ */
+#define fpatan_coeff_0 make_floatx80(0x3fff, 0x8000ULL)
+#define fpatan_coeff_1 make_floatx80(0xbffd, 0xaa43ULL)
+#define fpatan_coeff_2 make_floatx80(0x3ffc, 0xccbfe4f8ULL)
+#define fpatan_coeff_3 make_floatx80(0xbffc, 0x92492491fbab2e66ULL)
+#define fpatan_coeff_4 make_floatx80(0x3ffb, 0xe38e372881ea1e0bULL)
+#define fpatan_coeff_5 make_floatx80(0xbffb, 0xba2c0104bbdd0615ULL)
+#define fpatan_coeff_6 make_floatx80(0x3ffb, 0x9baf7ebf898b42efULL)
+
+struct fpatan_data {
+/* High and low parts of atan(x).  */
+floatx80 atan_high, atan_low;
+};
+
+static const struct fpatan_data fpatan_table[9] = {
+{ floatx80_zero,
+  floatx80_zero },
+{ make_floatx80(0x3ffb, 0xfeadd4d5617b6e33ULL),
+  make_floatx80(0xbfb9, 0xdda19d8305ddc420ULL) },
+{ make_floatx80(0x3ffc, 0xfadbafc96406eb15ULL),
+  make_floatx80(0x3fbb, 0xdb8f3debef442fccULL) },
+{ make_floatx80(0x3ffd, 0xb7b0ca0f26f78474ULL),
+  make_floatx80(0xbfbc, 0xeab9bdba460376faULL) },
+{ make_floatx80(0x3ffd, 0xed63382b0dda7b45ULL),
+  make_floatx80(0x3fbc, 0xdfc88bd978751a06ULL) },
+{ make_floatx80(0x3ffe, 0x8f005d5ef7f59f9bULL),
+  make_floatx80(0x3fbd, 0xb906bc2ccb886e90ULL) },
+{ make_floatx80(0x3ffe, 0xa4bc7d1934f70924ULL),
+  make_floatx80(0x3fbb, 0xcd43f9522bed64f8ULL) },
+{ make_floatx80(0x3ffe, 0xb8053e2bc2319e74ULL),
+  make_floatx80(0xbfbc, 0xd3496ab7bd6eef0cULL) },
+{ make_floatx80(0x3ffe, 0xc90fdaa22168c235ULL),
+  make_floatx80(0xbfbc, 0xece675d1fc8f8cbcULL) },
+};
+
 void helper_fpatan(CPUX86State *env)
 {
-double fptemp, fpsrcop;
+uint8_t old_flags = save_exception_flags(env);
+uint64_t arg0_sig = extractFloatx80Frac(ST0);
+int32_t arg0_exp = extractFloatx80Exp(ST0);
+bool arg0_sign = extractFloatx80Sign(ST0);
+uint64_t arg1_sig = extractFloatx80Frac(ST1);
+int32_t arg1_exp = extractFloatx80Exp(ST1);
+bool arg1_sign = extractFloatx80Sign(ST1);
+
+if (floatx80_is_signaling_nan(ST0, >fp_status)) {
+float_raise(float_flag_invalid, >fp_status);
+ST1 = floatx80_silence_nan(ST0, >fp_status);
+} else if (floatx80_is_signaling_nan(ST1, >fp_status)) {
+float_raise(float_flag_invalid, >fp_status);
+ST1 = floatx80_silence_nan(ST1, >fp_status);
+} else if (floatx80_invalid_encoding(ST0) ||
+   floatx80_invalid_encoding(ST1)) {
+float_raise(float_flag_invalid, >fp_status);
+ST1 = floatx80_default_nan(>fp_status);
+} else if (floatx80_is_any_nan(ST0)) {
+ST1 = ST0;
+} else if (floatx80_is_any_nan(ST1)) {
+/* Pass this NaN through.  */
+} else if (floatx80_is_zero(ST1) && !arg0_sign) {
+/* Pass this zero through.  */
+} else if (((floatx80_is_infinity(ST0) && !floatx80_is_infinity(ST1)) ||
+ arg0_exp - arg1_exp >= 80) &&
+   !arg0_sign) {
+/*
+ * Dividing ST1 by ST0 gives the correct result up to
+ * rounding, and avoids spurious underflow exceptions that
+ * might result from passing some small values through the
+ * polynomial approximation, but if a finite nonzero result of
+ * division is exact, the result of fpatan is still inexact
+ * (and underflowing 

[PULL 30/31] ibex_uart: fix XOR-as-pow

2020-06-24 Thread Paolo Bonzini
The xor-as-pow warning in clang actually detected a genuine bug.
Fix it.

Signed-off-by: Paolo Bonzini 
---
 hw/char/ibex_uart.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/char/ibex_uart.c b/hw/char/ibex_uart.c
index 3e0dd9968e..45cd724998 100644
--- a/hw/char/ibex_uart.c
+++ b/hw/char/ibex_uart.c
@@ -331,7 +331,7 @@ static void ibex_uart_write(void *opaque, hwaddr addr,
 if (value & UART_CTRL_NCO) {
 uint64_t baud = ((value & UART_CTRL_NCO) >> 16);
 baud *= 1000;
-baud /= 2 ^ 20;
+baud >>= 20;
 
 s->char_tx_time = (NANOSECONDS_PER_SECOND / baud) * 10;
 }
-- 
2.26.2





Re: [PATCH v5 00/12] pc-bios: s390x: Cleanup part 1

2020-06-24 Thread Cornelia Huck
On Wed, 24 Jun 2020 12:46:49 +0200
Thomas Huth  wrote:

> On 24/06/2020 12.44, Cornelia Huck wrote:
> > On Wed, 24 Jun 2020 03:52:14 -0400
> > Janosch Frank  wrote:
> >   
> >> The bios is in dire need for a cleanup as there are still a lot of
> >> magic constants being used throughout as well as duplicated code.
> >>
> >> In the first part of this series we consolidate constants and
> >> functions, as well as doing some minor cleanups and fixes.
> >>
> >> The patches are available here:
> >> https://github.com/frankjaa/qemu/pull/new/cleanup_bios
> >>
> >> v5:
> >>* Fixed whitespace damage
> >>* Removed reset PSW mask changes in dasd-ipl.c
> >>* Added jump2ipl.c cleanup patches
> >>
> >> v4:
> >>* Renamed time.h to s390-time.h
> >>* Fixed function names in sleep()
> >>* Changed order of sense_id_ccw initialization
> >>* Added missing include before sleep()
> >>
> >> v3:
> >>* Dropped 0x00 to 0x0/0 patch
> >>* Moved some timing functions into helper.h instead of time.h
> >>* Fixed IPL psw manipulation in dasd-ipl.c
> >>* Minor cosmetic fixes found by review
> >>
> >> v2:
> >>* Included cio fixup to get rid of compile errors...
> >>* Minor cosmetic fixes found by review
> >>
> >>
> >> Janosch Frank (12):
> >>pc-bios: s390x: cio.c cleanup and compile fix
> >>pc-bios: s390x: Consolidate timing functions into time.h
> >>pc-bios: s390x: Move sleep and yield to helper.h
> >>pc-bios: s390x: Get rid of magic offsets into the lowcore
> >>pc-bios: s390x: Remove unneeded dasd-ipl.c reset psw mask changes
> >>pc-bios: s390x: Rename PSW_MASK_ZMODE to PSW_MASK_64
> >>pc-bios: s390x: Use PSW masks where possible and introduce
> >>  PSW_MASK_SHORT_ADDR
> >>pc-bios: s390x: Move panic() into header and add infinite loop
> >>pc-bios: s390x: Use ebcdic2ascii table
> >>pc-bios: s390x: Make u32 ptr check explicit
> >>pc-bios: s390x: Fix bootmap.c passing PSWs as addresses
> >>pc-bios: s390x: Cleanup jump to ipl code
> >>
> >>   pc-bios/s390-ccw/bootmap.c |  9 
> >>   pc-bios/s390-ccw/bootmap.h |  2 +-
> >>   pc-bios/s390-ccw/cio.c | 40 +++---
> >>   pc-bios/s390-ccw/cio.h | 17 ++-
> >>   pc-bios/s390-ccw/dasd-ipl.c|  3 ---
> >>   pc-bios/s390-ccw/helper.h  | 19 +++-
> >>   pc-bios/s390-ccw/jump2ipl.c| 35 -
> >>   pc-bios/s390-ccw/main.c| 15 +++--
> >>   pc-bios/s390-ccw/menu.c|  1 +
> >>   pc-bios/s390-ccw/netmain.c | 23 +++
> >>   pc-bios/s390-ccw/s390-arch.h   |  4 +++-
> >>   pc-bios/s390-ccw/s390-ccw.h| 27 ++-
> >>   pc-bios/s390-ccw/s390-time.h   | 23 +++
> >>   pc-bios/s390-ccw/start.S   |  5 +++--
> >>   pc-bios/s390-ccw/virtio-net.c  |  2 ++
> >>   pc-bios/s390-ccw/virtio-scsi.c |  2 ++
> >>   pc-bios/s390-ccw/virtio.c  | 18 +++
> >>   17 files changed, 120 insertions(+), 125 deletions(-)
> >>   create mode 100644 pc-bios/s390-ccw/s390-time.h
> >>  
> > 
> > Hm... what's the general status of this? Most of the patches have at
> > least one R-b/A-b already, I see.
> > 
> > Do the s390-ccw boot maintainers want to pick this (once the rest has
> > been looked at) and then send me a pull req, or should I pick it when
> > it is good to go? Softfreeze is less than two weeks away :)  
> 
> I'd like to review the missing parts and run my tests with the patches 
> applied ... I'm just a little bit swamped right now, so please give me 
> some more time...

Sure, please don't feel hurried :)




[PULL 31/31] i386: Mask SVM features if nested SVM is disabled

2020-06-24 Thread Paolo Bonzini
From: Eduardo Habkost 

QEMU incorrectly validates FEAT_SVM feature flags against
GET_SUPPORTED_CPUID even if SVM features are being masked out by
cpu_x86_cpuid().  This can make QEMU print warnings on most AMD
CPU models, even when SVM nesting is disabled (which is the
default).

This bug was never detected before because of a Linux KVM bug:
until Linux v5.6, KVM was not filtering out SVM features in
GET_SUPPORTED_CPUID when nested was disabled.  This KVM bug was
fixed in Linux v5.7-rc1, on Linux commit a50718cc3f43 ("KVM:
nSVM: Expose SVM features to L1 iff nested is enabled").

Fix the problem by adding a CPUID_EXT3_SVM dependency to all
FEAT_SVM feature flags in the feature_dependencies table.

Reported-by: Yanan Fu 
Signed-off-by: Eduardo Habkost 
Message-Id: <20200623230116.277409-1-ehabk...@redhat.com>
[Fix testcase. - Paolo]
Signed-off-by: Paolo Bonzini 
---
 target/i386/cpu.c   | 4 
 tests/qtest/test-x86-cpuid-compat.c | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 06dc013d88..36cbd3d027 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -1404,6 +1404,10 @@ static FeatureDep feature_dependencies[] = {
 .from = { FEAT_VMX_SECONDARY_CTLS,  VMX_SECONDARY_EXEC_ENABLE_VMFUNC },
 .to = { FEAT_VMX_VMFUNC,~0ull },
 },
+{
+.from = { FEAT_8000_0001_ECX,   CPUID_EXT3_SVM },
+.to = { FEAT_SVM,   ~0ull },
+},
 };
 
 typedef struct X86RegisterInfo32 {
diff --git a/tests/qtest/test-x86-cpuid-compat.c 
b/tests/qtest/test-x86-cpuid-compat.c
index 772287bdb4..7ca1883a29 100644
--- a/tests/qtest/test-x86-cpuid-compat.c
+++ b/tests/qtest/test-x86-cpuid-compat.c
@@ -256,7 +256,7 @@ int main(int argc, char **argv)
"-cpu 486,+invtsc", "xlevel", 0x8007);
 /* CPUID[8000_000A].EDX: */
 add_cpuid_test("x86/cpuid/auto-xlevel/486/npt",
-   "-cpu 486,+npt", "xlevel", 0x800A);
+   "-cpu 486,+svm,+npt", "xlevel", 0x800A);
 /* CPUID[C000_0001].EDX: */
 add_cpuid_test("x86/cpuid/auto-xlevel2/phenom/xstore",
"-cpu phenom,+xstore", "xlevel2", 0xC001);
@@ -348,7 +348,7 @@ int main(int argc, char **argv)
"-machine pc-i440fx-2.4 -cpu SandyBridge,",
"xlevel", 0x8008);
 add_cpuid_test("x86/cpuid/xlevel-compat/pc-i440fx-2.4/npt-on",
-   "-machine pc-i440fx-2.4 -cpu SandyBridge,+npt",
+   "-machine pc-i440fx-2.4 -cpu SandyBridge,+svm,+npt",
"xlevel", 0x8008);
 
 /* Test feature parsing */
-- 
2.26.2




[PATCH v2 6/6] virtio-console: notify the guest about terminal resizes

2020-06-24 Thread Szymon Lukasz
If a virtio serial port is a console port forward terminal resize
messages from the chardev backend to the guest.

Signed-off-by: Szymon Lukasz 
---
 hw/char/virtio-console.c | 64 +---
 1 file changed, 60 insertions(+), 4 deletions(-)

diff --git a/hw/char/virtio-console.c b/hw/char/virtio-console.c
index 97b9240ef5..1ea06aad08 100644
--- a/hw/char/virtio-console.c
+++ b/hw/char/virtio-console.c
@@ -29,6 +29,7 @@ typedef struct VirtConsole {
 
 CharBackend chr;
 guint watch;
+uint16_t cols, rows;
 } VirtConsole;
 
 /*
@@ -104,6 +105,36 @@ static ssize_t flush_buf(VirtIOSerialPort *port,
 return ret;
 }
 
+static void virtconsole_send_resize(VirtIOSerialPort *port)
+{
+uint16_t cols, rows;
+VirtConsole *vcon = VIRTIO_CONSOLE(port);
+
+/*
+ * We probably shouldn't send these messages before
+ * we told the guest it is a console port (which we do
+ * by sending VIRTIO_CONSOLE_CONSOLE_PORT message).
+ * Instead of adding a new field to the device state
+ * lets just use the guest_connected field for that purpose
+ * since the guest should not care about the terminal size
+ * before opening the port.
+ */
+if (!port->guest_connected) {
+return;
+}
+
+if (qemu_chr_fe_get_winsize(>chr, , ) < 0) {
+cols = 0;
+rows = 0;
+}
+
+if (cols != vcon->cols || rows != vcon->rows) {
+vcon->cols = cols;
+vcon->rows = rows;
+virtio_serial_send_console_resize(port, cols, rows);
+}
+}
+
 /* Callback function that's called when the guest opens/closes the port */
 static void set_guest_connected(VirtIOSerialPort *port, int guest_connected)
 {
@@ -111,7 +142,9 @@ static void set_guest_connected(VirtIOSerialPort *port, int 
guest_connected)
 DeviceState *dev = DEVICE(port);
 VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_GET_CLASS(port);
 
-if (!k->is_console) {
+if (k->is_console) {
+virtconsole_send_resize(port);
+} else {
 qemu_chr_fe_set_open(>chr, guest_connected);
 }
 
@@ -171,6 +204,22 @@ static void chr_event(void *opaque, QEMUChrEvent event)
 }
 }
 
+static void chr_event_console(void *opaque, QEMUChrEvent event)
+{
+VirtConsole *vcon = opaque;
+VirtIOSerialPort *port = VIRTIO_SERIAL_PORT(vcon);
+
+switch (event) {
+case CHR_EVENT_OPENED:
+case CHR_EVENT_RESIZE:
+trace_virtio_console_chr_event(port->id, event);
+virtconsole_send_resize(port);
+break;
+default:
+break;
+}
+}
+
 static int chr_be_change(void *opaque)
 {
 VirtConsole *vcon = opaque;
@@ -179,7 +228,9 @@ static int chr_be_change(void *opaque)
 
 if (k->is_console) {
 qemu_chr_fe_set_handlers(>chr, chr_can_read, chr_read,
- NULL, chr_be_change, vcon, NULL, true);
+ chr_event_console, chr_be_change,
+ vcon, NULL, true);
+virtconsole_send_resize(port);
 } else {
 qemu_chr_fe_set_handlers(>chr, chr_can_read, chr_read,
  chr_event, chr_be_change, vcon, NULL, false);
@@ -207,7 +258,7 @@ static void virtconsole_enable_backend(VirtIOSerialPort 
*port, bool enable)
 VirtIOSerialPortClass *k = VIRTIO_SERIAL_PORT_GET_CLASS(port);
 
 qemu_chr_fe_set_handlers(>chr, chr_can_read, chr_read,
- k->is_console ? NULL : chr_event,
+ k->is_console ? chr_event_console : chr_event,
  chr_be_change, vcon, NULL, false);
 } else {
 qemu_chr_fe_set_handlers(>chr, NULL, NULL, NULL,
@@ -227,6 +278,11 @@ static void virtconsole_realize(DeviceState *dev, Error 
**errp)
 return;
 }
 
+if (k->is_console) {
+vcon->cols = (uint16_t) -1;
+vcon->rows = (uint16_t) -1;
+}
+
 if (qemu_chr_fe_backend_connected(>chr)) {
 /*
  * For consoles we don't block guest data transfer just
@@ -239,7 +295,7 @@ static void virtconsole_realize(DeviceState *dev, Error 
**errp)
  */
 if (k->is_console) {
 qemu_chr_fe_set_handlers(>chr, chr_can_read, chr_read,
- NULL, chr_be_change,
+ chr_event_console, chr_be_change,
  vcon, NULL, true);
 virtio_serial_open(port);
 } else {
-- 
2.27.0




[PATCH v4 15/20] audio: rework pcspk_init()

2020-06-24 Thread Gerd Hoffmann
Instead of creating and returning the pc speaker accept it as argument.
That allows to rework the initialization workflow in followup patches.

Signed-off-by: Gerd Hoffmann 
---
 include/hw/audio/pcspk.h | 6 +-
 hw/i386/pc.c | 2 +-
 hw/isa/i82378.c  | 2 +-
 3 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/include/hw/audio/pcspk.h b/include/hw/audio/pcspk.h
index 7e7f5f49dcb0..8b485602675f 100644
--- a/include/hw/audio/pcspk.h
+++ b/include/hw/audio/pcspk.h
@@ -31,18 +31,14 @@
 
 #define TYPE_PC_SPEAKER "isa-pcspk"
 
-static inline ISADevice *pcspk_init(ISABus *bus, ISADevice *pit)
+static inline void pcspk_init(ISADevice *isadev, ISABus *bus, ISADevice *pit)
 {
 DeviceState *dev;
-ISADevice *isadev;
 
-isadev = isa_new(TYPE_PC_SPEAKER);
 dev = DEVICE(isadev);
 qdev_prop_set_uint32(dev, "iobase", 0x61);
 object_property_set_link(OBJECT(dev), OBJECT(pit), "pit", NULL);
 isa_realize_and_unref(isadev, bus, _fatal);
-
-return isadev;
 }
 
 #endif /* HW_PCSPK_H */
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index ba88e1dfb80f..3f1d42b05102 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1240,7 +1240,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,
 /* connect PIT to output control line of the HPET */
 qdev_connect_gpio_out(hpet, 0, qdev_get_gpio_in(DEVICE(pit), 0));
 }
-pcspk_init(isa_bus, pit);
+pcspk_init(isa_new(TYPE_PC_SPEAKER), isa_bus, pit);
 }
 
 i8257_dma_init(isa_bus, 0);
diff --git a/hw/isa/i82378.c b/hw/isa/i82378.c
index d9e6c7fa0096..75a2da288157 100644
--- a/hw/isa/i82378.c
+++ b/hw/isa/i82378.c
@@ -102,7 +102,7 @@ static void i82378_realize(PCIDevice *pci, Error **errp)
 pit = i8254_pit_init(isabus, 0x40, 0, NULL);
 
 /* speaker */
-pcspk_init(isabus, pit);
+pcspk_init(isa_new(TYPE_PC_SPEAKER), isabus, pit);
 
 /* 2 82C37 (dma) */
 isa_create_simple(isabus, "i82374");
-- 
2.18.4




[PATCH v4 00/20] audio: deprecate -soundhw

2020-06-24 Thread Gerd Hoffmann
v2:
 - use g_assert_not_reached() for stubs.
 - add deprecation notice.

v3:
 - rebase to latest master.
 - adapt to armbru's device initialization changes.

v4:
 - reorder patches, drop temporary -global setup,
   go straight to -machine pcspk-audiodev= instead.
 - update error messages and documentation accordingly.

Gerd Hoffmann (20):
  stubs: add isa_create_simple
  stubs: add pci_create_simple
  audio: add deprecated_register_soundhw
  audio: deprecate -soundhw ac97
  audio: deprecate -soundhw es1370
  audio: deprecate -soundhw adlib
  audio: deprecate -soundhw cs4231a
  audio: deprecate -soundhw gus
  audio: deprecate -soundhw sb16
  audio: deprecate -soundhw hda
  pc_basic_device_init: pass PCMachineState
  pc_basic_device_init: drop has_pit arg
  pc_basic_device_init: drop no_vmport arg
  softmmu: initialize spice and audio earlier
  audio: rework pcspk_init()
  audio: create pcspk device early
  audio: deprecate -soundhw pcspk
  audio: add soundhw deprecation notice
  pcspk: update docs/system/target-i386-desc.rst.inc
  audio: set default value for pcspk.iobase property

 include/hw/audio/pcspk.h | 12 ++--
 include/hw/audio/soundhw.h   |  2 ++
 include/hw/i386/pc.h |  6 +++---
 hw/audio/ac97.c  |  9 ++---
 hw/audio/adlib.c |  8 +---
 hw/audio/cs4231a.c   |  8 +---
 hw/audio/es1370.c|  9 ++---
 hw/audio/gus.c   |  8 +---
 hw/audio/intel-hda.c |  3 +++
 hw/audio/pcspk.c | 26 ++
 hw/audio/sb16.c  |  9 ++---
 hw/audio/soundhw.c   | 24 +++-
 hw/i386/pc.c | 14 --
 hw/i386/pc_piix.c|  3 +--
 hw/i386/pc_q35.c |  3 +--
 hw/isa/i82378.c  |  2 +-
 qdev-monitor.c   |  2 ++
 softmmu/vl.c | 12 ++--
 stubs/isa-bus.c  |  7 +++
 stubs/pci-bus.c  |  7 +++
 docs/system/deprecated.rst   |  9 +
 docs/system/target-i386-desc.rst.inc | 13 -
 stubs/Makefile.objs  |  2 ++
 23 files changed, 120 insertions(+), 78 deletions(-)
 create mode 100644 stubs/isa-bus.c
 create mode 100644 stubs/pci-bus.c

-- 
2.18.4




[PATCH v4 03/20] audio: add deprecated_register_soundhw

2020-06-24 Thread Gerd Hoffmann
Add helper function for -soundhw deprecation.  It can replace the
simple init functions which just call {isa,pci}_create_simple()
with a hardcoded type.  It also prints a deprecation message.

Signed-off-by: Gerd Hoffmann 
---
 include/hw/audio/soundhw.h |  2 ++
 hw/audio/soundhw.c | 24 +++-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/include/hw/audio/soundhw.h b/include/hw/audio/soundhw.h
index c8eef8241846..f09a297854af 100644
--- a/include/hw/audio/soundhw.h
+++ b/include/hw/audio/soundhw.h
@@ -6,6 +6,8 @@ void isa_register_soundhw(const char *name, const char *descr,
 
 void pci_register_soundhw(const char *name, const char *descr,
   int (*init_pci)(PCIBus *bus));
+void deprecated_register_soundhw(const char *name, const char *descr,
+ int isa, const char *typename);
 
 void soundhw_init(void);
 void select_soundhw(const char *optarg);
diff --git a/hw/audio/soundhw.c b/hw/audio/soundhw.c
index c750473c8f0c..173b674ff53a 100644
--- a/hw/audio/soundhw.c
+++ b/hw/audio/soundhw.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 #include "qemu/osdep.h"
+#include "qemu/option.h"
 #include "qemu/help_option.h"
 #include "qemu/error-report.h"
 #include "qom/object.h"
@@ -32,6 +33,7 @@
 struct soundhw {
 const char *name;
 const char *descr;
+const char *typename;
 int enabled;
 int isa;
 union {
@@ -65,6 +67,17 @@ void pci_register_soundhw(const char *name, const char 
*descr,
 soundhw_count++;
 }
 
+void deprecated_register_soundhw(const char *name, const char *descr,
+ int isa, const char *typename)
+{
+assert(soundhw_count < ARRAY_SIZE(soundhw) - 1);
+soundhw[soundhw_count].name = name;
+soundhw[soundhw_count].descr = descr;
+soundhw[soundhw_count].isa = isa;
+soundhw[soundhw_count].typename = typename;
+soundhw_count++;
+}
+
 void select_soundhw(const char *optarg)
 {
 struct soundhw *c;
@@ -136,7 +149,16 @@ void soundhw_init(void)
 
 for (c = soundhw; c->name; ++c) {
 if (c->enabled) {
-if (c->isa) {
+if (c->typename) {
+warn_report("'-soundhw %s' is deprecated, "
+"please use '-device %s' instead",
+c->name, c->typename);
+if (c->isa) {
+isa_create_simple(isa_bus, c->typename);
+} else {
+pci_create_simple(pci_bus, -1, c->typename);
+}
+} else if (c->isa) {
 if (!isa_bus) {
 error_report("ISA bus not available for %s", c->name);
 exit(1);
-- 
2.18.4




[PATCH v4 14/20] softmmu: initialize spice and audio earlier

2020-06-24 Thread Gerd Hoffmann
audiodev must be initialized before machine_set_property
so the machine can have audiodev property aliases.

spice must initialize before audiodev because the default
audiodev is spice only in case spice is actually enabled.

Signed-off-by: Gerd Hoffmann 
---
 softmmu/vl.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index f669c06ede4a..3bfb9d29fd60 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -4131,12 +4131,17 @@ void qemu_init(int argc, char **argv, char **envp)
   fsdev_init_func, NULL, _fatal);
 #endif
 
+/* spice needs the timers to be initialized by this point */
+/* spice must initialize before audio as it changes the default auiodev */
+qemu_spice_init();
+
 /*
- * Note: we need to create block backends before
+ * Note: we need to create audio and block backends before
  * machine_set_property(), so machine properties can refer to
  * them.
  */
 configure_blockdev(_queue, machine_class, snapshot);
+audio_init_audiodevs();
 
 machine_opts = qemu_get_machine_opts();
 qemu_opt_foreach(machine_opts, machine_set_property, current_machine,
@@ -4230,9 +4235,6 @@ void qemu_init(int argc, char **argv, char **envp)
 semihosting_arg_fallback(kernel_filename, kernel_cmdline);
 }
 
-/* spice needs the timers to be initialized by this point */
-qemu_spice_init();
-
 cpu_ticks_init();
 
 if (default_net) {
@@ -4342,8 +4344,6 @@ void qemu_init(int argc, char **argv, char **envp)
 create_default_memdev(current_machine, mem_path);
 }
 
-audio_init_audiodevs();
-
 /* from here on runstate is RUN_STATE_PRELAUNCH */
 machine_run_board_init(current_machine);
 
-- 
2.18.4




RE: sysbus failed assert for xen_sysdev

2020-06-24 Thread Paul Durrant
> -Original Message-
> From: Jason Andryuk 
> Sent: 24 June 2020 13:15
> To: Paul Durrant 
> Cc: Markus Armbruster ; Mark Cave-Ayland 
> ; Anthony
> PERARD ; xen-devel 
> ; QEMU  de...@nongnu.org>
> Subject: Re: sysbus failed assert for xen_sysdev
> 
> On Wed, Jun 24, 2020 at 6:29 AM Paul Durrant  wrote:
> >
> > > -Original Message-
> > > From: Jason Andryuk 
> > > Sent: 24 June 2020 04:24
> > > To: Paul Durrant 
> > > Cc: Markus Armbruster ; Mark Cave-Ayland 
> > > ;
> Anthony
> > > PERARD ; xen-devel 
> > > ; QEMU  > > de...@nongnu.org>
> > > Subject: Re: sysbus failed assert for xen_sysdev
> > >
> > > On Tue, Jun 23, 2020 at 7:46 AM Paul Durrant  wrote:
> > > >
> > > > > -Original Message-
> > > > > From: Markus Armbruster 
> > > > > Sent: 23 June 2020 09:41
> > > > > To: Jason Andryuk 
> > > > > Cc: Mark Cave-Ayland ; Anthony PERARD
> ;
> > > xen-
> > > > > devel ; Paul Durrant ; 
> > > > > QEMU  de...@nongnu.org>
> > > > > Subject: Re: sysbus failed assert for xen_sysdev
> > > > >
> > > > > Jason Andryuk  writes:
> > > > > > Then it gets farther... until
> > > > > > qemu-system-i386: hw/core/qdev.c:439: qdev_assert_realized_properly:
> > > > > > Assertion `dev->realized' failed.
> > > > > >
> > > > > > dev->id is NULL. The failing device is:
> > > > > > (gdb) p *dev.parent_obj.class.type
> > > > > > $12 = {name = 0x56207770 "cfi.pflash01",
> > > > > >
> > > >
> > > > Having commented out the call to xen_be_init() entirely (and 
> > > > xen_bus_init() for good measure) I
> also
> > > get this assertion failure, so
> > > > I don't think is related.
> > >
> > > Yes, this is something different.  pc_pflash_create() calls
> > > qdev_new(TYPE_PFLASH_CFI01), but it is only realized in
> > > pc_system_flash_map()...  and pc_system_flash_map() isn't called for
> > > Xen.
> > >
> > > Removing the call to pc_system_flash_create() from pc_machine_initfn()
> > > lets QEMU startup and run a Xen HVM again.  xen_enabled() doesn't work
> > > there since accelerators have not been initialized yes, I guess?
> >
> > Looks like it can be worked round by the following:
> 
> Yes, thank you.
> 
> Tested-by: Jason Andryuk 

Thanks.

  Paul

> 
> > diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
> > index 1497d0e4ae..977d40afb8 100644
> > --- a/hw/i386/pc_piix.c
> > +++ b/hw/i386/pc_piix.c
> > @@ -186,9 +186,12 @@ static void pc_init1(MachineState *machine,
> >  if (!xen_enabled()) {
> >  pc_memory_init(pcms, system_memory,
> > rom_memory, _memory);
> > -} else if (machine->kernel_filename != NULL) {
> > -/* For xen HVM direct kernel boot, load linux here */
> > -xen_load_linux(pcms);
> > +} else {
> > +pc_system_flash_cleanup_unused(pcms);
> > +if (machine->kernel_filename != NULL) {
> > +/* For xen HVM direct kernel boot, load linux here */
> > +xen_load_linux(pcms);
> > +}
> >  }
> >
> >  gsi_state = pc_gsi_create(>gsi, pcmc->pci_enabled);
> > diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c
> > index ec2a3b3e7e..0ff47a4b59 100644
> > --- a/hw/i386/pc_sysfw.c
> > +++ b/hw/i386/pc_sysfw.c
> > @@ -108,7 +108,7 @@ void pc_system_flash_create(PCMachineState *pcms)
> >  }
> >  }
> >
> > -static void pc_system_flash_cleanup_unused(PCMachineState *pcms)
> > +void pc_system_flash_cleanup_unused(PCMachineState *pcms)
> >  {
> >  char *prop_name;
> >  int i;
> > diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
> > index e6135c34d6..497f2b7ab7 100644
> > --- a/include/hw/i386/pc.h
> > +++ b/include/hw/i386/pc.h
> > @@ -187,6 +187,7 @@ int cmos_get_fd_drive_type(FloppyDriveType fd0);
> >
> >  /* pc_sysfw.c */
> >  void pc_system_flash_create(PCMachineState *pcms);
> > +void pc_system_flash_cleanup_unused(PCMachineState *pcms);
> >  void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion 
> > *rom_memory);
> >
> >  /* acpi-build.c */
> >
> >
> > >
> > > Regards,
> > > Jason
> >




RE: [PATCH] xen: Fix xen-legacy-backend qdev types

2020-06-24 Thread Paul Durrant
> -Original Message-
> From: Jason Andryuk 
> Sent: 24 June 2020 13:20
> To: Stefano Stabellini ; Anthony Perard 
> ; Paul
> Durrant ; xen-de...@lists.xenproject.org
> Cc: Jason Andryuk ; qemu-devel@nongnu.org
> Subject: [PATCH] xen: Fix xen-legacy-backend qdev types
> 
> xen-sysdev is a TYPE_SYS_BUS_DEVICE.  bus_type should not be changed so
> that it can plug into the System bus.  Otherwise this assert triggers:
> qemu-system-i386: hw/core/qdev.c:102: qdev_set_parent_bus: Assertion
> `dc->bus_type && object_dynamic_cast(OBJECT(bus), dc->bus_type)'
> failed.
> 
> TYPE_XENBACKEND attaches to TYPE_XENSYSBUS, so its class_init needs to
> be set accordingly to attach the qdev.  Otherwise the following assert
> triggers:
> qemu-system-i386: hw/core/qdev.c:102: qdev_set_parent_bus: Assertion
> `dc->bus_type && object_dynamic_cast(OBJECT(bus), dc->bus_type)'
> failed.
> 
> TYPE_XENBACKEND is not a subclass of XEN_XENSYSDEV, so it's parent
> is just TYPE_DEVICE.  Change that.
> 
> Signed-off-by: Jason Andryuk 

Clearly we raced. This patch and my patch #1 are identical so I'm happy to give 
my ack to this.

  Paul

> ---
>  hw/xen/xen-legacy-backend.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/xen/xen-legacy-backend.c b/hw/xen/xen-legacy-backend.c
> index 2335ee2e65..c5c75c0064 100644
> --- a/hw/xen/xen-legacy-backend.c
> +++ b/hw/xen/xen-legacy-backend.c
> @@ -789,11 +789,12 @@ static void xendev_class_init(ObjectClass *klass, void 
> *data)
>  set_bit(DEVICE_CATEGORY_MISC, dc->categories);
>  /* xen-backend devices can be plugged/unplugged dynamically */
>  dc->user_creatable = true;
> +dc->bus_type = TYPE_XENSYSBUS;
>  }
> 
>  static const TypeInfo xendev_type_info = {
>  .name  = TYPE_XENBACKEND,
> -.parent= TYPE_XENSYSDEV,
> +.parent= TYPE_DEVICE,
>  .class_init= xendev_class_init,
>  .instance_size = sizeof(struct XenLegacyDevice),
>  };
> @@ -824,7 +825,6 @@ static void xen_sysdev_class_init(ObjectClass *klass, 
> void *data)
>  DeviceClass *dc = DEVICE_CLASS(klass);
> 
>  device_class_set_props(dc, xen_sysdev_properties);
> -dc->bus_type = TYPE_XENSYSBUS;
>  }
> 
>  static const TypeInfo xensysdev_info = {
> --
> 2.25.1





Re: [PATCH 1/2] vvfat: Check that updated filenames are valid

2020-06-24 Thread Kevin Wolf
Am 23.06.2020 um 20:21 hat Eric Blake geschrieben:
> On 6/23/20 12:55 PM, Kevin Wolf wrote:
> > FAT allows only a restricted set of characters in file names, and for
> > some of the illegal characters, it's actually important that we catch
> > them: If filenames can contain '/', the guest can construct filenames
> > containing "../" and escape from the assigned vvfat directory. The same
> > problem could arise if ".." was ever accepted as a literal filename.
> > 
> > Fix this by adding a check that all filenames are valid in
> > check_directory_consistency().
> > 
> > Reported-by: Nathan Huckleberry 
> > Signed-off-by: Kevin Wolf 
> > ---
> >   block/vvfat.c | 23 +++
> >   1 file changed, 23 insertions(+)
> > 
> > diff --git a/block/vvfat.c b/block/vvfat.c
> > index c65a98e3ee..2fab371258 100644
> > --- a/block/vvfat.c
> > +++ b/block/vvfat.c
> > @@ -520,6 +520,25 @@ static void set_begin_of_direntry(direntry_t* 
> > direntry, uint32_t begin)
> >   direntry->begin_hi = cpu_to_le16((begin >> 16) & 0x);
> >   }
> > +static bool valid_filename(const unsigned char *name)
> > +{
> > +unsigned char c;
> > +if (!strcmp((const char*)name, ".") || !strcmp((const char*)name, 
> > "..")) {
> > +return false;
> > +}
> > +for (; (c = *name); name++) {
> > +if (!((c >= '0' && c <= '9') ||
> > +  (c >= 'A' && c <= 'Z') ||
> > +  (c >= 'a' && c <= 'z') ||
> > +  c > 127 ||
> > +  strchr("$%'-_@~`!(){}^#&.+,;=[]", c) != 0))
> 
> s/0/NULL/

Ok, though this line is just copied from to_valid_short_char(). Maybe I
can sneak in a (strictly speaking unrelated) change to that function to
keep both consistent.

> Hmm - would it be any more efficient to use a single comparison of strcspn()
> vs. strlen(), where you merely spell out the bytes that are rejected?  Out
> of 256 byte values, NUL is implicitly rejected (since these are C strings),
> the 128 high-bit bytes are all valid, and you have permitted 62 alnum and 23
> other characters; that leaves merely 42 byte values to explicitly list in a
> reject string.  Of course, writing the string literal containing those 42
> invalid bytes is itself a bit of an exercise in reading the ASCII table:
> 
> "\x01\x02\x03\x04\x05\x06\x07"
> "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
> "\x10\x11\x12\x13\x14\x15\x16\x17"
> "\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
> " \"*/:<>?\\|\x7f"

I think this would be really hard to read.

The above condition is a pretty straighforward implementation of what
the spec says (even the order of characters is the same).

Kevin




Re: [PATCH v3 6/8] s390/sclp: add extended-length sccb support for kvm guest

2020-06-24 Thread Cornelia Huck
On Thu, 18 Jun 2020 18:22:56 -0400
Collin Walling  wrote:

> As more features and facilities are added to the Read SCP Info (RSCPI)
> response, more space is required to store them. The space used to store
> these new features intrudes on the space originally used to store CPU
> entries. This means as more features and facilities are added to the
> RSCPI response, less space can be used to store CPU entries.
> 
> With the Extended-Length SCCB (ELS) facility, a KVM guest can execute
> the RSCPI command and determine if the SCCB is large enough to store a
> complete reponse. If it is not large enough, then the required length
> will be set in the SCCB header.
> 
> The caller of the SCLP command is responsible for creating a
> large-enough SCCB to store a complete response. Proper checking should
> be in place, and the caller should execute the command once-more with
> the large-enough SCCB.
> 
> This facility also enables an extended SCCB for the Read CPU Info
> (RCPUI) command.
> 
> When this facility is enabled, the boundary violation response cannot
> be a result from the RSCPI, RSCPI Forced, or RCPUI commands.
> 
> In order to tolerate kernels that do not yet have full support for this
> feature, a "fixed" offset to the start of the CPU Entries within the
> Read SCP Info struct is set to allow for the original 248 max entries
> when this feature is disabled.
> 
> Additionally, this is introduced as a CPU feature to protect the guest
> from migrating to a machine that does not support storing an extended
> SCCB. This could otherwise hinder the VM from being able to read all
> available CPU entries after migration (such as during re-ipl).
> 
> Signed-off-by: Collin Walling 
> ---
>  hw/s390x/sclp.c | 21 -
>  include/hw/s390x/sclp.h |  1 +
>  target/s390x/cpu_features_def.inc.h |  1 +
>  target/s390x/gen-features.c |  1 +
>  target/s390x/kvm.c  |  8 
>  5 files changed, 31 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
> index 0dfbe6e5ec..f7c49e339e 100644
> --- a/hw/s390x/sclp.c
> +++ b/hw/s390x/sclp.c
> @@ -56,6 +56,18 @@ static bool sccb_has_valid_boundary(uint64_t sccb_addr, 
> uint32_t code,
>  uint64_t sccb_boundary = (sccb_addr & PAGE_MASK) + PAGE_SIZE;
>  
>  switch (code & SCLP_CMD_CODE_MASK) {
> +case SCLP_CMDW_READ_SCP_INFO:
> +case SCLP_CMDW_READ_SCP_INFO_FORCED:
> +case SCLP_CMDW_READ_CPU_INFO:
> +/*
> + * An extended-length SCCB is only allowed for Read SCP/CPU Info and
> + * is allowed to exceed the 4k boundary. The respective commands will
> + * set the length field to the required length if an insufficient
> + * SCCB length is provided.
> + */
> +if (s390_has_feat(S390_FEAT_EXTENDED_LENGTH_SCCB)) {
> +return true;
> +}

Add a fallthrough annotation?

>  default:
>  if (sccb_max_addr < sccb_boundary) {
>  return true;
> @@ -72,6 +84,10 @@ static bool sccb_sufficient_len(SCCB *sccb, int num_cpus, 
> int data_len)
>  
>  if (be16_to_cpu(sccb->h.length) < required_len) {
>  sccb->h.response_code = 
> cpu_to_be16(SCLP_RC_INSUFFICIENT_SCCB_LENGTH);
> +if (s390_has_feat(S390_FEAT_EXTENDED_LENGTH_SCCB) &&
> +sccb->h.control_mask[2] & SCLP_VARIABLE_LENGTH_RESPONSE) {
> +sccb->h.length = required_len;
> +}
>  return false;
>  }
>  return true;
> @@ -101,7 +117,9 @@ static void prepare_cpu_entries(MachineState *ms, 
> CPUEntry *entry, int *count)
>   */
>  static inline int get_read_scp_info_data_len(void)
>  {
> -return offsetof(ReadInfo, entries);
> +return s390_has_feat(S390_FEAT_EXTENDED_LENGTH_SCCB) ?
> +   offsetof(ReadInfo, entries) :
> +   SCLP_READ_SCP_INFO_FIXED_CPU_OFFSET;
>  }
>  
>  /* Provide information about the configuration, CPUs and storage */
> @@ -116,6 +134,7 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
>  CPUEntry *entries_start = (void *)sccb + data_len;
>  
>  if (!sccb_sufficient_len(sccb, machine->possible_cpus->len, data_len)) {
> +warn_report("insufficient sccb size to store read scp info 
> response");

Hm, this warning is triggered by a guest action, isn't it? Not sure how
helpful it is.

>  return;
>  }
>  

(...)

Otherwise, looks good to me.




[PATCH v5 10/10] chardev: enable modules, use for braille

2020-06-24 Thread Gerd Hoffmann
Removes brlapi library dependency from core qemu.

Signed-off-by: Gerd Hoffmann 
---
 Makefile.objs | 1 +
 chardev/char.c| 2 +-
 util/module.c | 1 +
 chardev/Makefile.objs | 5 -
 4 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/Makefile.objs b/Makefile.objs
index ca555ede0710..2dfcd19713f8 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -71,6 +71,7 @@ common-obj-$(CONFIG_TPM) += tpm.o
 
 common-obj-y += backends/
 common-obj-y += chardev/
+common-obj-m += chardev/
 
 common-obj-$(CONFIG_SECCOMP) += qemu-seccomp.o
 qemu-seccomp.o-cflags := $(SECCOMP_CFLAGS)
diff --git a/chardev/char.c b/chardev/char.c
index e3051295ac37..df697f3ce9e0 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -527,7 +527,7 @@ static const ChardevClass *char_get_class(const char 
*driver, Error **errp)
 const ChardevClass *cc;
 char *typename = g_strdup_printf("chardev-%s", driver);
 
-oc = object_class_by_name(typename);
+oc = module_object_class_by_name(typename);
 g_free(typename);
 
 if (!object_class_dynamic_cast(oc, TYPE_CHARDEV)) {
diff --git a/util/module.c b/util/module.c
index a74214eac052..32b0547b8266 100644
--- a/util/module.c
+++ b/util/module.c
@@ -272,6 +272,7 @@ static struct {
 { "vhost-user-gpu-device", "hw-", "display-virtio-gpu"},
 { "vhost-user-gpu-pci","hw-", "display-virtio-gpu"},
 { "vhost-user-vga","hw-", "display-virtio-gpu"},
+{ "chardev-braille",   "chardev-", "baum" },
 };
 
 static bool module_loaded_qom_all;
diff --git a/chardev/Makefile.objs b/chardev/Makefile.objs
index d68e1347f9af..3a58c9d329d6 100644
--- a/chardev/Makefile.objs
+++ b/chardev/Makefile.objs
@@ -18,8 +18,11 @@ chardev-obj-$(CONFIG_WIN32) += char-win.o
 chardev-obj-$(CONFIG_WIN32) += char-win-stdio.o
 
 common-obj-y += msmouse.o wctablet.o testdev.o
-common-obj-$(CONFIG_BRLAPI) += baum.o
+
+ifeq ($(CONFIG_BRLAPI),y)
+common-obj-m += baum.o
 baum.o-cflags := $(SDL_CFLAGS)
 baum.o-libs := $(BRLAPI_LIBS)
+endif
 
 common-obj-$(CONFIG_SPICE) += spice.o
-- 
2.18.4




[PATCH v5 07/10] vga: build qxl as module

2020-06-24 Thread Gerd Hoffmann
First step in making spice support modular.

Signed-off-by: Gerd Hoffmann 
---
 util/module.c| 2 ++
 hw/Makefile.objs | 1 +
 hw/display/Makefile.objs | 5 -
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/util/module.c b/util/module.c
index e3226165e91c..7c76d2a84b94 100644
--- a/util/module.c
+++ b/util/module.c
@@ -264,6 +264,8 @@ static struct {
 { "ccid-card-passthru","hw-", "usb-smartcard" },
 { "ccid-card-emulated","hw-", "usb-smartcard" },
 { "usb-redir", "hw-", "usb-redirect"  },
+{ "qxl-vga",   "hw-", "display-qxl"   },
+{ "qxl",   "hw-", "display-qxl"   },
 };
 
 static bool module_loaded_qom_all;
diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index af8fd9a510ed..14b7ea4eb62e 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -43,5 +43,6 @@ devices-dirs-y += smbios/
 endif
 
 common-obj-y += $(devices-dirs-y)
+common-obj-m += display/
 common-obj-m += usb/
 obj-y += $(devices-dirs-y)
diff --git a/hw/display/Makefile.objs b/hw/display/Makefile.objs
index 77a7d622bd2d..76b3571e4902 100644
--- a/hw/display/Makefile.objs
+++ b/hw/display/Makefile.objs
@@ -44,7 +44,10 @@ common-obj-$(CONFIG_ARTIST) += artist.o
 
 obj-$(CONFIG_VGA) += vga.o
 
-common-obj-$(CONFIG_QXL) += qxl.o qxl-logger.o qxl-render.o
+ifeq ($(CONFIG_QXL),y)
+common-obj-m += qxl.mo
+qxl.mo-objs = qxl.o qxl-logger.o qxl-render.o
+endif
 
 obj-$(CONFIG_VIRTIO_GPU) += virtio-gpu-base.o virtio-gpu.o virtio-gpu-3d.o
 obj-$(CONFIG_VHOST_USER_GPU) += vhost-user-gpu.o
-- 
2.18.4




Re: [PATCH v2 0/2] Avoid abort on QMP attempt to add an object with duplicate id

2020-06-24 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20200624124301.7112-1-eric.au...@redhat.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 ===

  TESTiotest-qcow2: 114
  TESTiotest-qcow2: 117
**
ERROR:/tmp/qemu-test/src/tests/qtest/qmp-cmd-test.c:225:test_object_add_with_duplicate_id:
 assertion failed: (qdict_haskey(resp, "return"))
ERROR - Bail out! 
ERROR:/tmp/qemu-test/src/tests/qtest/qmp-cmd-test.c:225:test_object_add_with_duplicate_id:
 assertion failed: (qdict_haskey(resp, "return"))
make: *** [check-qtest-aarch64] Error 1
make: *** Waiting for unfinished jobs
  TESTiotest-qcow2: 120
  TESTiotest-qcow2: 126
---
  TESTcheck-qtest-x86_64: tests/qtest/qmp-test
  TESTcheck-qtest-x86_64: tests/qtest/qmp-cmd-test
**
ERROR:/tmp/qemu-test/src/tests/qtest/qmp-cmd-test.c:225:test_object_add_with_duplicate_id:
 assertion failed: (qdict_haskey(resp, "return"))
ERROR - Bail out! 
ERROR:/tmp/qemu-test/src/tests/qtest/qmp-cmd-test.c:225:test_object_add_with_duplicate_id:
 assertion failed: (qdict_haskey(resp, "return"))
make: *** [check-qtest-x86_64] Error 1
  TESTiotest-qcow2: 220
  TESTiotest-qcow2: 226
  TESTiotest-qcow2: 229
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', 
'--label', 'com.qemu.instance.uuid=d6cb3d069c7a44ecbf5b02c17a39e884', '-u', 
'1003', '--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/patchew2/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', 
'/var/tmp/patchew-tester-tmp-litaiimt/src/docker-src.2020-06-24-09.18.47.9149:/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=d6cb3d069c7a44ecbf5b02c17a39e884
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-litaiimt/src'
make: *** [docker-run-test-quick@centos7] Error 2

real16m25.200s
user0m5.519s


The full log is available at
http://patchew.org/logs/20200624124301.7112-1-eric.au...@redhat.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 v2 0/3] hyperv: vmbus: ACPI various corrections

2020-06-24 Thread Igor Mammedov
On Tue, 23 Jun 2020 17:44:57 +0200
Paolo Bonzini  wrote:

> On 23/06/20 16:57, Igor Mammedov wrote:
> >>>
> >>>  dtc  |  2 +-
> >>>  hw/hyperv/vmbus.c|  3 +--
> >>>  hw/i386/acpi-build.c | 17 +
> >>>  include/hw/hyperv/vmbus-bridge.h |  3 +--
> >>>  4 files changed, 12 insertions(+), 13 deletions(-)
> >>> 
> >> Queued, thanks.
> >>
> >> Paolo
> >>
> >>  
> > Paolo, there is a newer vesion on list
> > and I don't think _ADR patch should be applied at all
> >   
> 
> Can you explain?  The only difference I saw was the bogus dtc update.

for the record, why is explained in
https://www.mail-archive.com/qemu-devel@nongnu.org/msg715460.html
"Re: [PATCH v3 2/3] i386: acpi: vmbus: Add _ADR definition"

change is not visible because vmbus is not enabled by default
and doesn't have bios_tables test-case that would turn oi on and
make it visible.

> 
> Paolo
> 




[PATCH v2 08/25] tests/vm: Added a new script for centos.aarch64.

2020-06-24 Thread Alex Bennée
From: 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 
Signed-off-by: Alex Bennée 
Message-Id: <20200601211421.1277-7-robert.fo...@linaro.org>
---
 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 4fa292765d5..39f918a430a 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 000..fd6ebe4d49e
--- /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 000..d5232ecdb8c
--- /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
+  

[PATCH v2 03/25] tests/vm: pass args through to BaseVM's __init__

2020-06-24 Thread Alex Bennée
From: 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é 
Signed-off-by: Alex Bennée 
Message-Id: <20200601211421.1277-2-robert.fo...@linaro.org>
---
 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 a80b616a08d..5a58e6c3930 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.20.1




[PATCH v2 12/25] tests/vm: switch from optsparse to argparse

2020-06-24 Thread Alex Bennée
optparse has been deprecated since version 3.2 and argparse is the
blessed replacement. Take the opportunity to enhance our help output
showing defaults when called.

Signed-off-by: Alex Bennée 
Reviewed-by: Daniel P. Berrangé 
Reviewed-by: Robert Foley 
---
 tests/vm/basevm.py | 84 +++---
 1 file changed, 42 insertions(+), 42 deletions(-)

diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
index 04d083409a5..93859362606 100644
--- a/tests/vm/basevm.py
+++ b/tests/vm/basevm.py
@@ -23,7 +23,7 @@ from qemu.accel import kvm_available
 from qemu.machine import QEMUMachine
 import subprocess
 import hashlib
-import optparse
+import argparse
 import atexit
 import tempfile
 import shutil
@@ -556,47 +556,47 @@ def parse_args(vmcls):
 else:
 return 1
 
-parser = optparse.OptionParser(
-description="VM test utility.  Exit codes: "
-"0 = success, "
-"1 = command line error, "
-"2 = environment initialization failed, "
-"3 = test command failed")
-parser.add_option("--debug", "-D", action="store_true",
-  help="enable debug output")
-parser.add_option("--image", "-i", default="%s.img" % vmcls.name,
-  help="image file name")
-parser.add_option("--force", "-f", action="store_true",
-  help="force build image even if image exists")
-parser.add_option("--jobs", type=int, default=get_default_jobs(),
-  help="number of virtual CPUs")
-parser.add_option("--verbose", "-V", action="store_true",
-  help="Pass V=1 to builds within the guest")
-parser.add_option("--build-image", "-b", action="store_true",
-  help="build image")
-parser.add_option("--build-qemu",
-  help="build QEMU from source in guest")
-parser.add_option("--build-target",
-  help="QEMU build target", default="check")
-parser.add_option("--build-path", default=None,
-  help="Path of build directory, "\
-   "for using build tree QEMU binary. ")
-parser.add_option("--interactive", "-I", action="store_true",
-  help="Interactively run command")
-parser.add_option("--snapshot", "-s", action="store_true",
-  help="run tests with a snapshot")
-parser.add_option("--genisoimage", default="genisoimage",
-  help="iso imaging tool")
-parser.add_option("--config", "-c", default=None,
-  help="Provide config yaml for configuration. "\
-   "See config_example.yaml for example.")
-parser.add_option("--efi-aarch64",
-  default="/usr/share/qemu-efi-aarch64/QEMU_EFI.fd",
-  help="Path to efi image for aarch64 VMs.")
-parser.add_option("--log-console", action="store_true",
-  help="Log console to file.")
-parser.disable_interspersed_args()
-return parser.parse_args()
+parser = argparse.ArgumentParser(
+formatter_class=argparse.ArgumentDefaultsHelpFormatter,
+description="Utility for provisioning VMs and running builds",
+epilog="""Remaining arguments are passed to the command.
+Exit codes: 0 = success, 1 = command line error,
+2 = environment initialization failed,
+3 = test command failed""")
+parser.add_argument("--debug", "-D", action="store_true",
+help="enable debug output")
+parser.add_argument("--image", "-i", default="%s.img" % vmcls.name,
+help="image file name")
+parser.add_argument("--force", "-f", action="store_true",
+help="force build image even if image exists")
+parser.add_argument("--jobs", type=int, default=get_default_jobs(),
+help="number of virtual CPUs")
+parser.add_argument("--verbose", "-V", action="store_true",
+help="Pass V=1 to builds within the guest")
+parser.add_argument("--build-image", "-b", action="store_true",
+help="build image")
+parser.add_argument("--build-qemu",
+help="build QEMU from source in guest")
+parser.add_argument("--build-target",
+help="QEMU build target", default="check")
+parser.add_argument("--build-path", default=None,
+help="Path of build directory, "\
+"for using build tree QEMU binary. ")
+parser.add_argument("--interactive", "-I", action="store_true",
+help="Interactively run command")
+parser.add_argument("--snapshot", "-s", action="store_true",
+help="run tests with a snapshot")
+parser.add_argument("--genisoimage", default="genisoimage",
+ 

  1   2   3   4   5   6   >