Re: [Qemu-devel] [PATCH for-QEMU-4.1 v5 07/29] hw/arm: Express dependencies of the fsl-imx31 machine with Kconfig

2019-04-18 Thread Chubb, Peter (Data61, Kensington NSW)
> "Thomas" == Thomas Huth  writes:

Thomas> Add Kconfig dependencies for the fsl-imx31 / kzm machine.
Thomas> This patch is slightly based on earlier work by Ákos Kovács
Thomas> (i.e.  his "hw/arm/Kconfig: Add ARM Kconfig" patch).

Thomas> Signed-off-by: Thomas Huth  
Reviewed-by: Peter Chubb 
--
Dr Peter Chubb Tel: +61 2 9490 5852  http://ts.data61.csiro.au/
Trustworthy Systems Group Data61, CSIRO (formerly NICTA)


Re: [Qemu-devel] [PATCH 2/2] tests: fw_cfg: add reboot_timeout test case

2019-04-18 Thread Li Qiang
Philippe Mathieu-Daudé  于2019年4月19日周五 上午5:01写道:

> Hi Li,
>
> On 3/19/19 3:30 AM, Li Qiang wrote:
> > Signed-off-by: Li Qiang 
> > ---
> >  tests/fw_cfg-test.c | 15 ++-
> >  1 file changed, 14 insertions(+), 1 deletion(-)
> >
> > diff --git a/tests/fw_cfg-test.c b/tests/fw_cfg-test.c
> > index 1c5103fe1c..551b51e38f 100644
> > --- a/tests/fw_cfg-test.c
> > +++ b/tests/fw_cfg-test.c
> > @@ -99,6 +99,17 @@ static void test_fw_cfg_boot_menu(void)
> >  g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_MENU), ==,
> boot_menu);
> >  }
> >
> > +static void test_fw_cfg_reboot_timeout(void)
> > +{
> > +uint32_t reboot_timeout = 0;
> > +size_t filesize;
> > +
> > +filesize = qfw_cfg_get_file(fw_cfg, "etc/boot-fail-wait",
> > + _timeout, sizeof(reboot_timeout));
> > +g_assert_cmpint(filesize, ==, sizeof(reboot_timeout));
> > +g_assert_cmpint(reboot_timeout, ==, 15);
> > +}
> > +
> >  int main(int argc, char **argv)
> >  {
> >  QTestState *s;
> > @@ -106,7 +117,8 @@ int main(int argc, char **argv)
> >
> >  g_test_init(, , NULL);
> >
> > -s = qtest_init("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8");
> > +s = qtest_init("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8 "
> > +   "-boot reboot-timeout=15");
>
> This modify all tests. I'd rather add a specific test with this option.
> Doing so, we can easily modify the timeout and add the <0 and >0x
> cases.
>
>
Ok, will do in the next revision.


> Can you think of a 'splash-time' test (for commit 6912bb0b3d3b1)?


Ok.

PS: any comments in the first patch.

Thanks,
Li Qiang


>
> Regards,
>
> Phil.
>
> >
> >  fw_cfg = pc_fw_cfg_init(s);
> >
> > @@ -125,6 +137,7 @@ int main(int argc, char **argv)
> >  qtest_add_func("fw_cfg/max_cpus", test_fw_cfg_max_cpus);
> >  qtest_add_func("fw_cfg/numa", test_fw_cfg_numa);
> >  qtest_add_func("fw_cfg/boot_menu", test_fw_cfg_boot_menu);
> > +qtest_add_func("fw_cfg/reboot_timeout", test_fw_cfg_reboot_timeout);
> >
> >  ret = g_test_run();
> >
> >
>


[Qemu-devel] [Bug 1825452] [NEW] Pulse audio backend doesn't work in v4.0.0-rc4 release

2019-04-18 Thread Ivan Volosyuk
Public bug reported:

Using Gentoo linux, build from source: qemu v4.0.0-rc4 release
(eeba63fc7fface36f438bcbc0d3b02e7dcb59983)

Pulse audio backend doesn't initialize because of the:
audio/paaudio.c:
-if (!popts->has_server) {
-char pidfile[64];
-char *runtime;
-struct stat st;
-
-runtime = getenv("XDG_RUNTIME_DIR");
-if (!runtime) {
-return NULL;
-}
-snprintf(pidfile, sizeof(pidfile), "%s/pulse/pid", runtime);
-if (stat(pidfile, ) != 0) {
-return NULL;
-}
-}
XDG_RUNTIME_DIR is not set for me. There is no /run/user directory exist in my 
system.

Also:
$ less ~/.pulse/client.conf  
default-server = unix:/home/ivan/.pulse_server

** Affects: qemu
 Importance: Undecided
 Status: New

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

Title:
  Pulse audio backend doesn't work in  v4.0.0-rc4 release

Status in QEMU:
  New

Bug description:
  Using Gentoo linux, build from source: qemu v4.0.0-rc4 release
  (eeba63fc7fface36f438bcbc0d3b02e7dcb59983)

  Pulse audio backend doesn't initialize because of the:
  audio/paaudio.c:
  -if (!popts->has_server) {
  -char pidfile[64];
  -char *runtime;
  -struct stat st;
  -
  -runtime = getenv("XDG_RUNTIME_DIR");
  -if (!runtime) {
  -return NULL;
  -}
  -snprintf(pidfile, sizeof(pidfile), "%s/pulse/pid", runtime);
  -if (stat(pidfile, ) != 0) {
  -return NULL;
  -}
  -}
  XDG_RUNTIME_DIR is not set for me. There is no /run/user directory exist in 
my system.

  Also:
  $ less ~/.pulse/client.conf  
  default-server = unix:/home/ivan/.pulse_server

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



Re: [Qemu-devel] [PATCH v2 1/3] numa: move numa global variable nb_numa_nodes into MachineState

2019-04-18 Thread Tao Xu

On 4/18/2019 10:26 PM, Eduardo Habkost wrote:

On Thu, Apr 18, 2019 at 02:46:00PM +0800, Tao Xu wrote:

The aim of this patch is to add struct NumaState in MachineState
and move existing numa global nb_numa_nodes into NumaState.
And add variable numa_support into MachineClass to decide which
submachines support NUMA.

Suggested-by: Igor Mammedov 
Suggested-by: Eduardo Habkost 
Signed-off-by: Tao Xu 

[...]

+int nb_numa_nodes = ms->numa_state ? ms->numa_state->nb_numa_nodes : 0;


I see 17 occurrences of this same pattern in the patch, and I had
to double-check the ones that didn't check if ms->numa_state is
NULL.

I think a
   int machine_num_numa_nodes(MachineState *ms)
helper would be useful.

While at it, I suggest naming the nb_numa_nodes field "num_nodes"
or "nr_nodes", because it's already inside a struct called
NumaState.

Thank you for your review, I will improve these in the next version of 
patch.





[Qemu-devel] [Bug 1818367] Re: Initialization of device cfi.pflash01 failed: Block node is read-only

2019-04-18 Thread Laszlo Ersek (Red Hat)
(more precisely, the nvram element will be auto-generated when you exit
"virsh edit", and the nvram file will be created (copied) from the
varstore template when you launch the domain)

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

Title:
  Initialization of device cfi.pflash01 failed: Block node is read-only

Status in libvirt:
  New
Status in QEMU:
  Invalid

Bug description:
  Hi,

  I have several vms defined in libvirt using ovmf for uefi, since a later
  update of my server I'm unable to start any of the domains defined. This is
  an example of the output given:

  # virsh start os-1
  error: Failed to start domain os-1
  error: internal error: qemu unexpectedly closed the monitor: 
2019-03-02T21:23:51.726446Z qemu-system-x86_64: Initialization of device 
cfi.pflash01 failed: Block node is read-only

  an example of domain is like this:

 


 
os-1   


 
34c41008-ab91-483b-959c-81a7a12ae9be   


 
8388608 


 
8388608   


 
 


 



 



 
4  


 



 
  hvm   


 
  /var/lib/libvirt/qemu/nvram/os-1-ovmf.fd   


 
   


 



 
   


 
  

 

[Qemu-devel] [Bug 1818367] Re: Initialization of device cfi.pflash01 failed: Block node is read-only

2019-04-18 Thread Laszlo Ersek (Red Hat)
Hi José,

your domain XML is bogus with regard to the firmware configuration. You
have:

 /var/lib/libvirt/qemu/nvram/os-1-ovmf.fd

and no  element, and you write that "os-1-ovmf.fd" is a copy of
"OVMF_VARS.fd".

The  element, with @type='pflash', no other attributes, and then
no  sibling element either, happens to be valid, but it is an
extremely niche use case. It is used when you have a unified, writeable,
OVMF.fd file that contains both the firmware executable and the live
variable store.

Most distros don't provide such unified "OVMF.fd" files, and even if
yours does, you are not passing a full such "OVMF.fd" to the guest, but
just a variable store -- there is no firmware binary at all that the
guest could *execute*.

So please do the following:

- power down the domain

- delete "/var/lib/libvirt/qemu/nvram/os-1-ovmf.fd" for starters

- modify the domain XML as follows, with "virsh edit":

/usr/share/edk2-ovmf/OVMF_CODE.fd

When you exit your editor, libvirtd will:

- create the  element, and auto-generate the pathname for the
   element

- create the varstore file, pointed-to by the pathname above, from the
  template at "/usr/share/edk2-ovmf/OVMF_VARS.fd".


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

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

Title:
  Initialization of device cfi.pflash01 failed: Block node is read-only

Status in libvirt:
  New
Status in QEMU:
  Invalid

Bug description:
  Hi,

  I have several vms defined in libvirt using ovmf for uefi, since a later
  update of my server I'm unable to start any of the domains defined. This is
  an example of the output given:

  # virsh start os-1
  error: Failed to start domain os-1
  error: internal error: qemu unexpectedly closed the monitor: 
2019-03-02T21:23:51.726446Z qemu-system-x86_64: Initialization of device 
cfi.pflash01 failed: Block node is read-only

  an example of domain is like this:

 


 
os-1   


 
34c41008-ab91-483b-959c-81a7a12ae9be   


 
8388608 


 
8388608   


 
 


 



 



 
4  


 



 
  hvm   


 
  /var/lib/libvirt/qemu/nvram/os-1-ovmf.fd   

   

[Qemu-devel] [PATCH v4 1/6] q35: acpi: do not create dummy MCFG table

2019-04-18 Thread Wei Yang
From: Igor Mammedov 

Dummy table (with signature "QEMU") creation came from original SeaBIOS
codebase. And QEMU would have to keep it around if there were Q35 machine
that depended on keeping ACPI tables blob constant size. Luckily there
were no versioned Q35 machine types before commit:
  (since 2.3) a1666142db acpi-build: make ROMs RAM blocks resizeable
which obsoleted need to keep ACPI tables blob the same size on 
source/destination.

Considering the 1st versioned machine is pc-q35-2.4, the dummy table
is not really necessary and it's safe to drop it without breaking
cross version migration in both directions unconditionally.

Signed-off-by: Igor Mammedov 
Signed-off-by: Wei Yang 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/i386/acpi-build.c | 18 --
 1 file changed, 4 insertions(+), 14 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index b17d4a711d..d009176072 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -2401,7 +2401,6 @@ static void
 build_mcfg_q35(GArray *table_data, BIOSLinker *linker, AcpiMcfgInfo *info)
 {
 AcpiTableMcfg *mcfg;
-const char *sig;
 int len = sizeof(*mcfg) + 1 * sizeof(mcfg->allocation[0]);
 
 mcfg = acpi_data_push(table_data, len);
@@ -2411,19 +2410,7 @@ build_mcfg_q35(GArray *table_data, BIOSLinker *linker, 
AcpiMcfgInfo *info)
 mcfg->allocation[0].start_bus_number = 0;
 mcfg->allocation[0].end_bus_number = PCIE_MMCFG_BUS(info->mcfg_size - 1);
 
-/* MCFG is used for ECAM which can be enabled or disabled by guest.
- * To avoid table size changes (which create migration issues),
- * always create the table even if there are no allocations,
- * but set the signature to a reserved value in this case.
- * ACPI spec requires OSPMs to ignore such tables.
- */
-if (info->mcfg_base == PCIE_BASE_ADDR_UNMAPPED) {
-/* Reserved signature: ignored by OSPM */
-sig = "QEMU";
-} else {
-sig = "MCFG";
-}
-build_header(linker, table_data, (void *)mcfg, sig, len, 1, NULL, NULL);
+build_header(linker, table_data, (void *)mcfg, "MCFG", len, 1, NULL, NULL);
 }
 
 /*
@@ -2592,6 +2579,9 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)
 }
 mcfg->mcfg_base = qnum_get_uint(qobject_to(QNum, o));
 qobject_unref(o);
+if (mcfg->mcfg_base == PCIE_BASE_ADDR_UNMAPPED) {
+return false;
+}
 
 o = object_property_get_qobject(pci_host, PCIE_HOST_MCFG_SIZE, NULL);
 assert(o);
-- 
2.19.1




[Qemu-devel] [PATCH v4 2/6] hw/arm/virt-acpi-build: remove unnecessary variable mcfg_start

2019-04-18 Thread Wei Yang
mcfg_start points to the start of MCFG table and is used in
build_header. While this information could be derived from mcfg.

This patch removes the unnecessary variable mcfg_start.

Signed-off-by: Wei Yang 
Reviewed-by: Igor Mammedov 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/arm/virt-acpi-build.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index 857989362a..e09e7eff8d 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -552,7 +552,6 @@ build_mcfg(GArray *table_data, BIOSLinker *linker, 
VirtMachineState *vms)
 const MemMapEntry *memmap = vms->memmap;
 int ecam_id = VIRT_ECAM_ID(vms->highmem_ecam);
 int len = sizeof(*mcfg) + sizeof(mcfg->allocation[0]);
-int mcfg_start = table_data->len;
 
 mcfg = acpi_data_push(table_data, len);
 mcfg->allocation[0].address = cpu_to_le64(memmap[ecam_id].base);
@@ -563,8 +562,7 @@ build_mcfg(GArray *table_data, BIOSLinker *linker, 
VirtMachineState *vms)
 mcfg->allocation[0].end_bus_number =
 PCIE_MMCFG_BUS(memmap[ecam_id].size - 1);
 
-build_header(linker, table_data, (void *)(table_data->data + mcfg_start),
- "MCFG", table_data->len - mcfg_start, 1, NULL, NULL);
+build_header(linker, table_data, (void *)mcfg, "MCFG", len, 1, NULL, NULL);
 }
 
 /* GTDT */
-- 
2.19.1




[Qemu-devel] [PATCH v4 3/6] i386, acpi: remove mcfg_ prefix in AcpiMcfgInfo members

2019-04-18 Thread Wei Yang
This is obvious the member in AcpiMcfgInfo describe MCFG's property.

Remove the mcfg_ prefix.

Signed-off-by: Wei Yang 
Suggested-by: Igor Mammedov 
Reviewed-by: Igor Mammedov 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/i386/acpi-build.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index d009176072..f0d27bffd6 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -87,8 +87,8 @@
 #define ACPI_BUILD_IOAPIC_ID 0x0
 
 typedef struct AcpiMcfgInfo {
-uint64_t mcfg_base;
-uint32_t mcfg_size;
+uint64_t base;
+uint32_t size;
 } AcpiMcfgInfo;
 
 typedef struct AcpiPmInfo {
@@ -2404,11 +2404,11 @@ build_mcfg_q35(GArray *table_data, BIOSLinker *linker, 
AcpiMcfgInfo *info)
 int len = sizeof(*mcfg) + 1 * sizeof(mcfg->allocation[0]);
 
 mcfg = acpi_data_push(table_data, len);
-mcfg->allocation[0].address = cpu_to_le64(info->mcfg_base);
+mcfg->allocation[0].address = cpu_to_le64(info->base);
 /* Only a single allocation so no need to play with segments */
 mcfg->allocation[0].pci_segment = cpu_to_le16(0);
 mcfg->allocation[0].start_bus_number = 0;
-mcfg->allocation[0].end_bus_number = PCIE_MMCFG_BUS(info->mcfg_size - 1);
+mcfg->allocation[0].end_bus_number = PCIE_MMCFG_BUS(info->size - 1);
 
 build_header(linker, table_data, (void *)mcfg, "MCFG", len, 1, NULL, NULL);
 }
@@ -2577,15 +2577,15 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)
 if (!o) {
 return false;
 }
-mcfg->mcfg_base = qnum_get_uint(qobject_to(QNum, o));
+mcfg->base = qnum_get_uint(qobject_to(QNum, o));
 qobject_unref(o);
-if (mcfg->mcfg_base == PCIE_BASE_ADDR_UNMAPPED) {
+if (mcfg->base == PCIE_BASE_ADDR_UNMAPPED) {
 return false;
 }
 
 o = object_property_get_qobject(pci_host, PCIE_HOST_MCFG_SIZE, NULL);
 assert(o);
-mcfg->mcfg_size = qnum_get_uint(qobject_to(QNum, o));
+mcfg->size = qnum_get_uint(qobject_to(QNum, o));
 qobject_unref(o);
 return true;
 }
-- 
2.19.1




[Qemu-devel] [PATCH v4 0/6] Extract build_mcfg

2019-04-18 Thread Wei Yang
This patch set tries to generalize MCFG table build process. And it is
based on one un-merged patch from Igor, which is included in this serials.

v3->v4:
* adjust comment to give more information about MCFG table

v2->v3:
* Includes the un-merged patch from Igor
* use build_append_foo() API to construct MCFG

Igor Mammedov (1):
  q35: acpi: do not create dummy MCFG table

Wei Yang (5):
  hw/arm/virt-acpi-build: remove unnecessary variable mcfg_start
  i386, acpi: remove mcfg_ prefix in AcpiMcfgInfo members
  hw/arm/virt-acpi-build: pass AcpiMcfgInfo to build_mcfg()
  hw/acpi: Consolidate build_mcfg to pci.c
  acpi: pci: use build_append_foo() API to construct MCFG

 default-configs/arm-softmmu.mak  |  1 +
 default-configs/i386-softmmu.mak |  1 +
 hw/acpi/Kconfig  |  4 +++
 hw/acpi/Makefile.objs|  1 +
 hw/acpi/pci.c| 55 
 hw/arm/virt-acpi-build.c | 31 +-
 hw/i386/acpi-build.c | 44 -
 include/hw/acpi/acpi-defs.h  | 18 ---
 include/hw/acpi/pci.h| 34 
 9 files changed, 111 insertions(+), 78 deletions(-)
 create mode 100644 hw/acpi/pci.c
 create mode 100644 include/hw/acpi/pci.h

-- 
2.19.1




[Qemu-devel] [PATCH v4 5/6] hw/acpi: Consolidate build_mcfg to pci.c

2019-04-18 Thread Wei Yang
Now we have two identical build_mcfg functions.

Consolidate them in acpi/pci.c.

Signed-off-by: Wei Yang 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Igor Mammedov 

---
v3:
  * adjust changelog based on Igor's suggestion
---
 default-configs/arm-softmmu.mak  |  1 +
 default-configs/i386-softmmu.mak |  1 +
 hw/acpi/Kconfig  |  4 +++
 hw/acpi/Makefile.objs|  1 +
 hw/acpi/pci.c| 46 
 hw/arm/virt-acpi-build.c | 17 
 hw/i386/acpi-build.c | 18 +
 include/hw/acpi/pci.h|  1 +
 8 files changed, 55 insertions(+), 34 deletions(-)
 create mode 100644 hw/acpi/pci.c

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 613d19a06d..8f2796e195 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -144,6 +144,7 @@ CONFIG_XIO3130=y
 CONFIG_IOH3420=y
 CONFIG_I82801B11=y
 CONFIG_ACPI=y
+CONFIG_ACPI_PCI=y
 CONFIG_ARM_VIRT=y
 CONFIG_SMBIOS=y
 CONFIG_ASPEED_SOC=y
diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index ba3fb3ff50..cd5ea391e8 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -25,3 +25,4 @@
 CONFIG_ISAPC=y
 CONFIG_I440FX=y
 CONFIG_Q35=y
+CONFIG_ACPI_PCI=y
diff --git a/hw/acpi/Kconfig b/hw/acpi/Kconfig
index eca3beed75..7265843cc3 100644
--- a/hw/acpi/Kconfig
+++ b/hw/acpi/Kconfig
@@ -23,6 +23,10 @@ config ACPI_NVDIMM
 bool
 depends on ACPI
 
+config ACPI_PCI
+bool
+depends on ACPI
+
 config ACPI_VMGENID
 bool
 default y
diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
index ba93c5b64a..9bb2101e3b 100644
--- a/hw/acpi/Makefile.objs
+++ b/hw/acpi/Makefile.objs
@@ -11,6 +11,7 @@ common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o
 common-obj-y += acpi_interface.o
 common-obj-y += bios-linker-loader.o
 common-obj-y += aml-build.o utils.o
+common-obj-$(CONFIG_ACPI_PCI) += pci.o
 common-obj-$(CONFIG_TPM) += tpm.o
 
 common-obj-$(CONFIG_IPMI) += ipmi.o
diff --git a/hw/acpi/pci.c b/hw/acpi/pci.c
new file mode 100644
index 00..fa0fa30bb9
--- /dev/null
+++ b/hw/acpi/pci.c
@@ -0,0 +1,46 @@
+/*
+ * Support for generating PCI related ACPI tables and passing them to Guests
+ *
+ * Copyright (C) 2006 Fabrice Bellard
+ * Copyright (C) 2008-2010  Kevin O'Connor 
+ * Copyright (C) 2013-2019 Red Hat Inc
+ * Copyright (C) 2019 Intel Corporation
+ *
+ * Author: Wei Yang 
+ * Author: Michael S. Tsirkin 
+ *
+ * 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/acpi/aml-build.h"
+#include "hw/acpi/pci.h"
+#include "hw/pci/pcie_host.h"
+
+void build_mcfg(GArray *table_data, BIOSLinker *linker, AcpiMcfgInfo *info)
+{
+AcpiTableMcfg *mcfg;
+int len = sizeof(*mcfg) + sizeof(mcfg->allocation[0]);
+
+mcfg = acpi_data_push(table_data, len);
+mcfg->allocation[0].address = cpu_to_le64(info->base);
+
+/* Only a single allocation so no need to play with segments */
+mcfg->allocation[0].pci_segment = cpu_to_le16(0);
+mcfg->allocation[0].start_bus_number = 0;
+mcfg->allocation[0].end_bus_number = PCIE_MMCFG_BUS(info->size - 1);
+
+build_header(linker, table_data, (void *)mcfg, "MCFG", len, 1, NULL, NULL);
+}
+
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index ebddcde596..e3353de9e4 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -546,23 +546,6 @@ build_srat(GArray *table_data, BIOSLinker *linker, 
VirtMachineState *vms)
  "SRAT", table_data->len - srat_start, 3, NULL, NULL);
 }
 
-static void
-build_mcfg(GArray *table_data, BIOSLinker *linker, AcpiMcfgInfo *info)
-{
-AcpiTableMcfg *mcfg;
-int len = sizeof(*mcfg) + sizeof(mcfg->allocation[0]);
-
-mcfg = acpi_data_push(table_data, len);
-mcfg->allocation[0].address = cpu_to_le64(info->base);
-
-/* Only a single allocation so no need to play with segments */
-mcfg->allocation[0].pci_segment = cpu_to_le16(0);
-mcfg->allocation[0].start_bus_number = 0;
-mcfg->allocation[0].end_bus_number = PCIE_MMCFG_BUS(info->size - 1);
-
-build_header(linker, table_data, (void *)mcfg, "MCFG", len, 1, NULL, NULL);
-}
-
 /* GTDT */
 static void
 build_gtdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
diff --git 

[Qemu-devel] [PATCH v4 6/6] acpi: pci: use build_append_foo() API to construct MCFG

2019-04-18 Thread Wei Yang
build_append_foo() API doesn't need explicit endianness conversions
which eliminates a source of errors and it makes build_mcfg() look like
declarative definition of MCFG table in ACPI spec, which makes it easy
to review.

Signed-off-by: Wei Yang 
Suggested-by: Igor Mammedov 
Reviewed-by: Igor Mammedov 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/acpi/pci.c   | 33 +
 include/hw/acpi/acpi-defs.h | 18 --
 2 files changed, 21 insertions(+), 30 deletions(-)

diff --git a/hw/acpi/pci.c b/hw/acpi/pci.c
index fa0fa30bb9..341805e786 100644
--- a/hw/acpi/pci.c
+++ b/hw/acpi/pci.c
@@ -30,17 +30,26 @@
 
 void build_mcfg(GArray *table_data, BIOSLinker *linker, AcpiMcfgInfo *info)
 {
-AcpiTableMcfg *mcfg;
-int len = sizeof(*mcfg) + sizeof(mcfg->allocation[0]);
-
-mcfg = acpi_data_push(table_data, len);
-mcfg->allocation[0].address = cpu_to_le64(info->base);
-
-/* Only a single allocation so no need to play with segments */
-mcfg->allocation[0].pci_segment = cpu_to_le16(0);
-mcfg->allocation[0].start_bus_number = 0;
-mcfg->allocation[0].end_bus_number = PCIE_MMCFG_BUS(info->size - 1);
-
-build_header(linker, table_data, (void *)mcfg, "MCFG", len, 1, NULL, NULL);
+int mcfg_start = table_data->len;
+
+acpi_data_push(table_data, sizeof(AcpiTableHeader));
+
+/*
+ * PCI Firmware Specification, Revision 3.0
+ * 4.1.2 MCFG Table Description.
+ */
+/* Base address, processor-relative */
+build_append_int_noprefix(table_data, info->base, 8);
+/* PCI segment group number */
+build_append_int_noprefix(table_data, 0, 2);
+/* Starting PCI Bus number */
+build_append_int_noprefix(table_data, 0, 1);
+/* Final PCI Bus number */
+build_append_int_noprefix(table_data, PCIE_MMCFG_BUS(info->size - 1), 1);
+/* Reserved */
+build_append_int_noprefix(table_data, 0, 4);
+
+build_header(linker, table_data, (void *)(table_data->data + mcfg_start),
+ "MCFG", table_data->len - mcfg_start, 1, NULL, NULL);
 }
 
diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
index f9aa4bd398..57a3f58b0c 100644
--- a/include/hw/acpi/acpi-defs.h
+++ b/include/hw/acpi/acpi-defs.h
@@ -449,24 +449,6 @@ struct AcpiSratProcessorGiccAffinity {
 
 typedef struct AcpiSratProcessorGiccAffinity AcpiSratProcessorGiccAffinity;
 
-/* PCI fw r3.0 MCFG table. */
-/* Subtable */
-struct AcpiMcfgAllocation {
-uint64_t address;/* Base address, processor-relative */
-uint16_t pci_segment;/* PCI segment group number */
-uint8_t start_bus_number;   /* Starting PCI Bus number */
-uint8_t end_bus_number; /* Final PCI Bus number */
-uint32_t reserved;
-} QEMU_PACKED;
-typedef struct AcpiMcfgAllocation AcpiMcfgAllocation;
-
-struct AcpiTableMcfg {
-ACPI_TABLE_HEADER_DEF;
-uint8_t reserved[8];
-AcpiMcfgAllocation allocation[0];
-} QEMU_PACKED;
-typedef struct AcpiTableMcfg AcpiTableMcfg;
-
 /*
  * TCPA Description Table
  *
-- 
2.19.1




[Qemu-devel] [PATCH v4 4/6] hw/arm/virt-acpi-build: pass AcpiMcfgInfo to build_mcfg()

2019-04-18 Thread Wei Yang
To build MCFG, two information is necessary:

* bus number
* base address

Abstract these two information to AcpiMcfgInfo so that build_mcfg and
build_mcfg_q35 will have the same declaration.

Signed-off-by: Wei Yang 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Igor Mammedov 

---
v3:
  * move AcpiMcfgInfo to pci.h
v2:
  * for arm platform, construct a AcpiMcfgInfo directly
---
 hw/arm/virt-acpi-build.c | 18 +++---
 hw/i386/acpi-build.c |  6 +-
 include/hw/acpi/pci.h| 33 +
 3 files changed, 45 insertions(+), 12 deletions(-)
 create mode 100644 include/hw/acpi/pci.h

diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index e09e7eff8d..ebddcde596 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -40,6 +40,7 @@
 #include "hw/hw.h"
 #include "hw/acpi/aml-build.h"
 #include "hw/acpi/utils.h"
+#include "hw/acpi/pci.h"
 #include "hw/pci/pcie_host.h"
 #include "hw/pci/pci.h"
 #include "hw/arm/virt.h"
@@ -546,21 +547,18 @@ build_srat(GArray *table_data, BIOSLinker *linker, 
VirtMachineState *vms)
 }
 
 static void
-build_mcfg(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
+build_mcfg(GArray *table_data, BIOSLinker *linker, AcpiMcfgInfo *info)
 {
 AcpiTableMcfg *mcfg;
-const MemMapEntry *memmap = vms->memmap;
-int ecam_id = VIRT_ECAM_ID(vms->highmem_ecam);
 int len = sizeof(*mcfg) + sizeof(mcfg->allocation[0]);
 
 mcfg = acpi_data_push(table_data, len);
-mcfg->allocation[0].address = cpu_to_le64(memmap[ecam_id].base);
+mcfg->allocation[0].address = cpu_to_le64(info->base);
 
 /* Only a single allocation so no need to play with segments */
 mcfg->allocation[0].pci_segment = cpu_to_le16(0);
 mcfg->allocation[0].start_bus_number = 0;
-mcfg->allocation[0].end_bus_number =
-PCIE_MMCFG_BUS(memmap[ecam_id].size - 1);
+mcfg->allocation[0].end_bus_number = PCIE_MMCFG_BUS(info->size - 1);
 
 build_header(linker, table_data, (void *)mcfg, "MCFG", len, 1, NULL, NULL);
 }
@@ -801,7 +799,13 @@ void virt_acpi_build(VirtMachineState *vms, 
AcpiBuildTables *tables)
 build_gtdt(tables_blob, tables->linker, vms);
 
 acpi_add_table(table_offsets, tables_blob);
-build_mcfg(tables_blob, tables->linker, vms);
+{
+AcpiMcfgInfo mcfg = {
+   .base = vms->memmap[VIRT_ECAM_ID(vms->highmem_ecam)].base,
+   .size = vms->memmap[VIRT_ECAM_ID(vms->highmem_ecam)].size,
+};
+build_mcfg(tables_blob, tables->linker, );
+}
 
 acpi_add_table(table_offsets, tables_blob);
 build_spcr(tables_blob, tables->linker, vms);
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index f0d27bffd6..c2de7f4b01 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -58,6 +58,7 @@
 
 #include "hw/acpi/aml-build.h"
 #include "hw/acpi/utils.h"
+#include "hw/acpi/pci.h"
 
 #include "qom/qom-qobject.h"
 #include "hw/i386/amd_iommu.h"
@@ -86,11 +87,6 @@
 /* Default IOAPIC ID */
 #define ACPI_BUILD_IOAPIC_ID 0x0
 
-typedef struct AcpiMcfgInfo {
-uint64_t base;
-uint32_t size;
-} AcpiMcfgInfo;
-
 typedef struct AcpiPmInfo {
 bool s3_disabled;
 bool s4_disabled;
diff --git a/include/hw/acpi/pci.h b/include/hw/acpi/pci.h
new file mode 100644
index 00..124af7d32a
--- /dev/null
+++ b/include/hw/acpi/pci.h
@@ -0,0 +1,33 @@
+/*
+ * Support for generating PCI related ACPI tables and passing them to Guests
+ *
+ * Copyright (C) 2006 Fabrice Bellard
+ * Copyright (C) 2008-2010  Kevin O'Connor 
+ * Copyright (C) 2013-2019 Red Hat Inc
+ * Copyright (C) 2019 Intel Corporation
+ *
+ * Author: Wei Yang 
+ * Author: Michael S. Tsirkin 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+#ifndef HW_ACPI_PCI_H
+#define HW_ACPI_PCI_H
+
+typedef struct AcpiMcfgInfo {
+uint64_t base;
+uint32_t size;
+} AcpiMcfgInfo;
+
+#endif
-- 
2.19.1




Re: [Qemu-devel] How do we do user input bitmap properties?

2019-04-18 Thread Laszlo Ersek
On 04/18/19 11:28, Andrew Jones wrote:
> Hi all,
> 
> First some background:
> 
> For the userspace side of AArch64 guest SVE support we need to
> expose KVM's allowed vector lengths bitmap to the user and allow
> the user to choose a subset of that bitmap. Since bitmaps are a
> bit awkward to work with then we'll likely want to expose it as
> an array of vector lengths instead. Also, assuming we want to
> expose the lengths as number-of-quadwords (quadword == 128 bits
> for AArch64 and vector lengths must be multiples of quadwords)
> rather than number-of-bits, then an example array (which will
> always be a sequence) might be
> 
>  [ 8, 16, 32 ]
> 
> The user may choose a subsequence, but only through truncation,
> i.e. [ 8, 32 ] is not valid, but [ 8, 16 ] is.
> 
> Furthermore, different hosts may support different sequences
> which have the same maximum. For example, if the above sequence
> is for Host_A, then Host_B could be
> 
>  [ 8, 16, 24, 32 ]
> 
> The host must support all lengths in the sequence, which means
> that while Host_A supports 32, since it doesn't support 24 and
> we can only truncate sequences, we must use either [ 8 ] or
> [ 8, 16 ] for a compatible sequence if we intend to migrate
> between the hosts.
> 
> Now to the $SUBJECT question:
> 
> My feeling is that we should require the sequence to be
> provided on the command line as a cpu property. Something
> like
> 
>   -cpu host,sve-vl-list=8:16
> 
> (I chose ':' for the delimiter because ',' can't work, but
> if there's a better choice, then that's fine by me.)
> 
> Afaict a property list like this will require a new parser,
> which feels a bit funny since it seems we should already
> have support for this type of thing somewhere in QEMU. So,
> the question is: do we?

I think so. OptsVisitor can parse repeated properties from an option and
turn them into a list that you define in QAPI schema. More precisely,
you'd define the schema first, subject to "rules" and "restrictions",
and then OptsVisitor would allow you to grab that schema from command
line options. A list of integers qualifies.

See for example:

[Qemu-devel] [PATCH v2 0/8] OptsVisitor: support / flatten integer range
https://lists.gnu.org/archive/html/qemu-devel/2013-08/msg02686.html

(this is actually a feature on top of what you seem to need, but this is
what I could find right now).

Although I worked on this stuff in 2012-2013 (and so I remember
basically nothing about it), it should still function, because the qtest
suite exercises it with good coverage.

So, suggestions:
- git show -s eb7ee2cb
- check how "-numa" is parsed, and steal it :)

If OptsVisitor is hard to combine with existent options that are already
parsed in a different manner (and I do think it would be difficult),
then a new option could be introduced. For example:

  -sve-vector-lengths allow=8,allow=16

which should give you an ordered list of lengths, and you could distill
that manually into a single bitmap.

Thanks,
Laszlo
PS: I do mean I don't remember anything about OptsVisitor :/

> I see we have array properties, but
> I don't believe that works with the command line. Should we
> only use QMP for this? We already want some QMP in order to
> query the supported vector lengths. Maybe we should use QMP
> to set the selection too? But then what about command line
> support for developers? And if the property is on the command
> line then we don't have to add it to the migration stream.
> 
> Thanks,
> drew
> 




[Qemu-devel] [PATCH] configure: Change capstone's default state to disabled

2019-04-18 Thread John Arbuckle
Capstone is not necessary in order to use QEMU. Disable it by default.
This will save the user the pain of having to figure why QEMU isn't
building when this library is missing.

Signed-off-by: John Arbuckle 
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index 1c563a7027..77d7967f92 100755
--- a/configure
+++ b/configure
@@ -433,7 +433,7 @@ opengl_dmabuf="no"
 cpuid_h="no"
 avx2_opt=""
 zlib="yes"
-capstone=""
+capstone="no"
 lzo=""
 snappy=""
 bzip2=""
-- 
2.14.3 (Apple Git-98)




Re: [Qemu-devel] [PATCH V13 4/5] util/mmap-alloc: support MAP_SYNC in qemu_ram_mmap()

2019-04-18 Thread Eduardo Habkost
On Thu, Apr 18, 2019 at 07:05:16PM -0300, Eduardo Habkost wrote:
> Hi,
> 
> I found out that this series missed QEMU 4.0 and I was going to
> queue for 4.1, but unfortunately this patch conflicts with:
> 
> commit 2044c3e7116eeac0449dcb4a4130cc8f8b9310da
> Author: Murilo Opsfelder Araujo 
> Date:   Wed Jan 30 21:36:04 2019 -0200
> 
> mmap-alloc: unfold qemu_ram_mmap()
[...]
> On Fri, Feb 08, 2019 at 06:11:11PM +0800, Zhang, Yi wrote:
> > From: Zhang Yi 
> > 
> > When a file supporting DAX is used as vNVDIMM backend, mmap it with
> > MAP_SYNC flag in addition which can ensure file system metadata
> > synced in each guest writes to the backend file, without other QEMU
> > actions (e.g., periodic fsync() by QEMU).
> > 
> > Current, We have below different possible use cases:
> > 
> > 1. pmem=on is set, shared=on is set, MAP_SYNC supported:
> >a: backend is a dax supporting file.
> > - MAP_SYNC will active.
> >b: backend is not a dax supporting file.
> > - mmap will trigger a warning. then MAP_SYNC flag will be ignored
> > 
> > 2. The rest of cases:
> >- we will never pass the MAP_SYNC to mmap2
> > 
> > Signed-off-by: Haozhong Zhang 
> > Signed-off-by: Zhang Yi 

Untested patch rebase is below.  Can Intel help test it and
submit v14?

Signed-off-by: Haozhong Zhang 
Signed-off-by: Zhang Yi 
[ehabkost: Rebased patch to latest code on master]
Signed-off-by: Eduardo Habkost 
---
 util/mmap-alloc.c | 41 +++--
 1 file changed, 39 insertions(+), 2 deletions(-)

diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
index 9713f4b960..7063a44c7d 100644
--- a/util/mmap-alloc.c
+++ b/util/mmap-alloc.c
@@ -10,6 +10,13 @@
  * later.  See the COPYING file in the top-level directory.
  */
 
+#ifdef CONFIG_LINUX
+#include 
+#else  /* !CONFIG_LINUX */
+#define MAP_SYNC  0x0
+#define MAP_SHARED_VALIDATE   0x0
+#endif /* CONFIG_LINUX */
+
 #include "qemu/osdep.h"
 #include "qemu/mmap-alloc.h"
 #include "qemu/host-utils.h"
@@ -82,6 +89,7 @@ void *qemu_ram_mmap(int fd,
 bool is_pmem)
 {
 int flags;
+int map_sync_flags = 0;
 int guardfd;
 size_t offset;
 size_t pagesize;
@@ -132,10 +140,39 @@ void *qemu_ram_mmap(int fd,
 flags = MAP_FIXED;
 flags |= fd == -1 ? MAP_ANONYMOUS : 0;
 flags |= shared ? MAP_SHARED : MAP_PRIVATE;
+if (shared && is_pmem) {
+map_sync_flags = MAP_SYNC | MAP_SHARED_VALIDATE;
+}
 offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr;
 
-ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE, flags, fd, 0);
-
+ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE,
+   flags | map_sync_flags, fd, 0);
+
+if (ptr == MAP_FAILED && map_sync_flags) {
+if (errno == ENOTSUP) {
+char *proc_link, *file_name;
+int len;
+proc_link = g_strdup_printf("/proc/self/fd/%d", fd);
+file_name = g_malloc0(PATH_MAX);
+len = readlink(proc_link, file_name, PATH_MAX - 1);
+if (len < 0) {
+len = 0;
+}
+file_name[len] = '\0';
+fprintf(stderr, "Warning: requesting persistence across crashes "
+"for backend file %s failed. Proceeding without "
+"persistence, data might become corrupted in case of host "
+"crash.\n", file_name);
+g_free(proc_link);
+g_free(file_name);
+}
+/*
+ * if map failed with MAP_SHARED_VALIDATE | MAP_SYNC,
+ * we will remove these flags to handle compatibility.
+ */
+ptr = mmap(guardptr + offset, size, PROT_READ | PROT_WRITE,
+   flags, fd, 0);
+}
 if (ptr == MAP_FAILED) {
 munmap(guardptr, total);
 return MAP_FAILED;
-- 
2.18.0.rc1.1.g3f1ff2140




Re: [Qemu-devel] [PATCH V13 4/5] util/mmap-alloc: support MAP_SYNC in qemu_ram_mmap()

2019-04-18 Thread Eduardo Habkost
Hi,

I found out that this series missed QEMU 4.0 and I was going to
queue for 4.1, but unfortunately this patch conflicts with:

commit 2044c3e7116eeac0449dcb4a4130cc8f8b9310da
Author: Murilo Opsfelder Araujo 
Date:   Wed Jan 30 21:36:04 2019 -0200

mmap-alloc: unfold qemu_ram_mmap()

Unfold parts of qemu_ram_mmap() for the sake of understanding, moving
declarations to the top, and keeping architecture-specifics in the
ifdef-else blocks.  No changes in the function behaviour.

Give ptr and ptr1 meaningful names:
  ptr  -> guardptr : pointer to the PROT_NONE guard region
  ptr1 -> ptr  : pointer to the mapped memory returned to caller

Signed-off-by: Murilo Opsfelder Araujo 
Reviewed-by: Greg Kurz 
Signed-off-by: David Gibson 

I'm queueing patches 1-3 into machine-next[1], so only patches 4
and 5 need to be refreshed and resubmitted.

[1] https://github.com/ehabkost/qemu.git machine-next


On Fri, Feb 08, 2019 at 06:11:11PM +0800, Zhang, Yi wrote:
> From: Zhang Yi 
> 
> When a file supporting DAX is used as vNVDIMM backend, mmap it with
> MAP_SYNC flag in addition which can ensure file system metadata
> synced in each guest writes to the backend file, without other QEMU
> actions (e.g., periodic fsync() by QEMU).
> 
> Current, We have below different possible use cases:
> 
> 1. pmem=on is set, shared=on is set, MAP_SYNC supported:
>a: backend is a dax supporting file.
> - MAP_SYNC will active.
>b: backend is not a dax supporting file.
> - mmap will trigger a warning. then MAP_SYNC flag will be ignored
> 
> 2. The rest of cases:
>- we will never pass the MAP_SYNC to mmap2
> 
> Signed-off-by: Haozhong Zhang 
> Signed-off-by: Zhang Yi 
> ---
>  util/mmap-alloc.c | 45 -
>  1 file changed, 44 insertions(+), 1 deletion(-)
> 
> diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
> index 97bbeed..2f21efd 100644
> --- a/util/mmap-alloc.c
> +++ b/util/mmap-alloc.c
> @@ -10,6 +10,13 @@
>   * later.  See the COPYING file in the top-level directory.
>   */
>  
> +#ifdef CONFIG_LINUX
> +#include 
> +#else  /* !CONFIG_LINUX */
> +#define MAP_SYNC  0x0
> +#define MAP_SHARED_VALIDATE   0x0
> +#endif /* CONFIG_LINUX */
> +
>  #include "qemu/osdep.h"
>  #include "qemu/mmap-alloc.h"
>  #include "qemu/host-utils.h"
> @@ -101,6 +108,8 @@ void *qemu_ram_mmap(int fd,
>  #else
>  void *ptr = mmap(0, total, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 
> 0);
>  #endif
> +int mmap_flags;
> +int map_sync_flags = 0;
>  size_t offset;
>  void *ptr1;
>  
> @@ -111,13 +120,47 @@ void *qemu_ram_mmap(int fd,
>  assert(is_power_of_2(align));
>  /* Always align to host page size */
>  assert(align >= getpagesize());
> +mmap_flags = shared ? MAP_SHARED : MAP_PRIVATE;
> +if (shared && is_pmem) {
> +map_sync_flags = MAP_SYNC | MAP_SHARED_VALIDATE;
> +mmap_flags |= map_sync_flags;
> +}
>  
>  offset = QEMU_ALIGN_UP((uintptr_t)ptr, align) - (uintptr_t)ptr;
>  ptr1 = mmap(ptr + offset, size, PROT_READ | PROT_WRITE,
>  MAP_FIXED |
>  (fd == -1 ? MAP_ANONYMOUS : 0) |
> -(shared ? MAP_SHARED : MAP_PRIVATE),
> +mmap_flags,
>  fd, 0);
> +
> +
> +if (ptr1 == MAP_FAILED && map_sync_flags) {
> +if (errno == ENOTSUP) {
> +char *proc_link, *file_name;
> +int len;
> +proc_link = g_strdup_printf("/proc/self/fd/%d", fd);
> +file_name = g_malloc0(PATH_MAX);
> +len = readlink(proc_link, file_name, PATH_MAX - 1);
> +if (len < 0) {
> +len = 0;
> +}
> +file_name[len] = '\0';
> +fprintf(stderr, "Warning: requesting persistence across crashes "
> +"for backend file %s failed. Proceeding without "
> +"persistence, data might become corrupted in case of 
> host "
> +"crash.\n", file_name);
> +g_free(proc_link);
> +g_free(file_name);
> +}
> +/* if map failed with MAP_SHARED_VALIDATE | MAP_SYNC,
> + * we will remove these flags to handle compatibility.
> + */
> +ptr1 = mmap(ptr + offset, size, PROT_READ | PROT_WRITE,
> +MAP_FIXED |
> +(fd == -1 ? MAP_ANONYMOUS : 0) |
> +MAP_SHARED,
> +fd, 0);
> +}
>  if (ptr1 == MAP_FAILED) {
>  munmap(ptr, total);
>  return MAP_FAILED;
> -- 
> 2.7.4
> 
> 

-- 
Eduardo



Re: [Qemu-devel] [PULL for-4.1 00/36] Error reporting & monitor patches for 2019-04-18

2019-04-18 Thread no-reply
Patchew URL: https://patchew.org/QEMU/20190418205135.6686-1-arm...@redhat.com/



Hi,

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

Type: series
Message-id: 20190418205135.6686-1-arm...@redhat.com
Subject: [Qemu-devel] [PULL for-4.1 00/36] Error reporting & monitor patches 
for 2019-04-18

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

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag]   patchew/20190418205135.6686-1-arm...@redhat.com -> 
patchew/20190418205135.6686-1-arm...@redhat.com
Switched to a new branch 'test'
f65f9a57a6 include: Move fprintf_function to disas/
3613cf2952 disas: Rename include/disas/bfd.h back to include/disas/dis-asm.h
8362074a2c monitor: Clean up how monitor_disas() funnels output to monitor
41465772c0 qom/cpu: Simplify how CPUClass:cpu_dump_state() prints
49fd3a8181 qemu-print: New qemu_fprintf(), qemu_vfprintf()
195a57362a qom/cpu: Simplify how CPUClass::dump_statistics() prints
b439ddf49d target/i386: Simplify how x86_cpu_dump_local_apic_state() prints
f02a059161 target: Clean up how the dump_mmu() print
71ad53d2d8 target: Simplify how the TARGET_cpu_list() print
e48c937bbb memory: Clean up how mtree_info() prints
de799bd96a block/qapi: Clean up how we print to monitor or stdout
de39c5a100 qsp: Simplify how qsp_report() prints
e597dab6a6 tcg: Simplify how dump_drift_info() prints
903672bb0a tcg: Simplify how dump_exec_info() prints
b011a591b1 tcg: Simplify how dump_opcount_info() prints
e2066e0297 trace: Simplify how st_print_trace_file_status() prints
ba66678390 include: Include fprintf-fn.h only where needed
6bf830e5fa monitor: Simplify how -device/device_add print help
f9837a2629 char-pty: Print "char device redirected" message to stdout
8ffea401ea char: Make -chardev help print to stdout
7e517c0c83 blockdev: Make -drive format=help print to stdout
4fc29bdae6 qemu-print: New qemu_printf(), qemu_vprintf() etc.
da66543644 monitor error: Make printf()-like functions return a value
bb86c3751c vl: Make -machine $TYPE, help and -accel help print to stdout
f0f1843fa5 s390x/kvm: Report warnings with warn_report(), not error_printf()
30004a79dd vfio: Report warnings with warn_report(), not error_printf()
86648932be hpet: Report warnings with warn_report(), not error_printf()
77849d6ae3 pci: Report fatal errors with error_report(), not error_printf()
5384051d57 mips/boston: Report errors with error_report(), not error_printf()
5542ac28ff loader-fit: Wean off error_printf()
390e511dee block/ssh: Do not report read/write/flush errors to the user
85da455e60 qemu-img: Use error_vreport() in error_exit()
376c0acbff util/error: do not free error on error_abort
d515fdf4f0 error: Fix error_report_err(), warn_report_err() hint printing
d4406797be log: Make glib logging go through QEMU
3c051888c6 qemu-io: Use error_[gs]et_progname()

=== OUTPUT BEGIN ===
1/36 Checking commit 3c051888c617 (qemu-io: Use error_[gs]et_progname())
2/36 Checking commit d4406797beb3 (log: Make glib logging go through QEMU)
3/36 Checking commit d515fdf4f02b (error: Fix error_report_err(), 
warn_report_err() hint printing)
4/36 Checking commit 376c0acbff33 (util/error: do not free error on error_abort)
5/36 Checking commit 85da455e604b (qemu-img: Use error_vreport() in 
error_exit())
6/36 Checking commit 390e511dee92 (block/ssh: Do not report read/write/flush 
errors to the user)
7/36 Checking commit 5542ac28ff9b (loader-fit: Wean off error_printf())
8/36 Checking commit 5384051d5721 (mips/boston: Report errors with 
error_report(), not error_printf())
9/36 Checking commit 77849d6ae3cf (pci: Report fatal errors with 
error_report(), not error_printf())
10/36 Checking commit 86648932bea9 (hpet: Report warnings with warn_report(), 
not error_printf())
11/36 Checking commit 30004a79dd0d (vfio: Report warnings with warn_report(), 
not error_printf())
12/36 Checking commit f0f1843fa518 (s390x/kvm: Report warnings with 
warn_report(), not error_printf())
13/36 Checking commit bb86c3751c7d (vl: Make -machine $TYPE, help and -accel 
help print to stdout)
14/36 Checking commit da6654364435 (monitor error: Make printf()-like functions 
return a value)
15/36 Checking commit 4fc29bdae6ff (qemu-print: New qemu_printf(), 
qemu_vprintf() etc.)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#36: 
new file mode 100644

total: 0 errors, 1 warnings, 94 lines checked

Patch 15/36 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
16/36 Checking commit 7e517c0c8383 (blockdev: Make -drive format=help print to 
stdout)
17/36 Checking commit 8ffea401ea28 (char: Make -chardev help print to stdout)

[Qemu-devel] [PULL for-4.1 29/36] target: Clean up how the dump_mmu() print

2019-04-18 Thread Markus Armbruster
The various dump_mmu() take an fprintf()-like callback and a FILE * to
pass to it, and so do their helper functions.  Passing around callback
and argument is rather tiresome.

Most dump_mmu() are called only by the target's hmp_info_tlb().  These
all pass monitor_printf() cast to fprintf_function and the current
monitor cast to FILE *.

SPARC's dump_mmu() gets also called from target/sparc/ldst_helper.c a
few times #ifdef DEBUG_MMU.  These calls pass fprintf() and stdout.

The type-punning is technically undefined behaviour, but works in
practice.  Clean up: drop the callback, and call qemu_printf()
instead.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
Message-Id: <20190417191805.28198-11-arm...@redhat.com>
---
 target/m68k/cpu.h  |   3 +-
 target/m68k/helper.c   | 115 ++---
 target/m68k/monitor.c  |   2 +-
 target/nios2/cpu.h |   2 +-
 target/nios2/mmu.c |   7 ++-
 target/nios2/monitor.c |   2 +-
 target/ppc/cpu.h   |   2 +-
 target/ppc/mmu-hash64.c|   7 ++-
 target/ppc/mmu-hash64.h|   2 +-
 target/ppc/mmu_helper.c|  70 +++---
 target/ppc/monitor.c   |   2 +-
 target/sparc/cpu.h |   2 +-
 target/sparc/ldst_helper.c |  18 +++---
 target/sparc/mmu_helper.c  |  97 +++
 target/sparc/monitor.c |   2 +-
 target/xtensa/cpu.h|   2 +-
 target/xtensa/mmu_helper.c |  24 
 target/xtensa/monitor.c|   2 +-
 18 files changed, 178 insertions(+), 183 deletions(-)

diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h
index 9c1f0a2458..73952f6ece 100644
--- a/target/m68k/cpu.h
+++ b/target/m68k/cpu.h
@@ -573,5 +573,6 @@ static inline void cpu_get_tb_cpu_state(CPUM68KState *env, 
target_ulong *pc,
 }
 }
 
-void dump_mmu(FILE *f, fprintf_function cpu_fprintf, CPUM68KState *env);
+void dump_mmu(CPUM68KState *env);
+
 #endif
diff --git a/target/m68k/helper.c b/target/m68k/helper.c
index bb64cf15c0..d958a34959 100644
--- a/target/m68k/helper.c
+++ b/target/m68k/helper.c
@@ -369,30 +369,28 @@ int m68k_cpu_handle_mmu_fault(CPUState *cs, vaddr 
address, int size, int rw,
 
 /* MMU: 68040 only */
 
-static void print_address_zone(FILE *f, fprintf_function cpu_fprintf,
-   uint32_t logical, uint32_t physical,
+static void print_address_zone(uint32_t logical, uint32_t physical,
uint32_t size, int attr)
 {
-cpu_fprintf(f, "%08x - %08x -> %08x - %08x %c ",
+qemu_printf("%08x - %08x -> %08x - %08x %c ",
 logical, logical + size - 1,
 physical, physical + size - 1,
 attr & 4 ? 'W' : '-');
 size >>= 10;
 if (size < 1024) {
-cpu_fprintf(f, "(%d KiB)\n", size);
+qemu_printf("(%d KiB)\n", size);
 } else {
 size >>= 10;
 if (size < 1024) {
-cpu_fprintf(f, "(%d MiB)\n", size);
+qemu_printf("(%d MiB)\n", size);
 } else {
 size >>= 10;
-cpu_fprintf(f, "(%d GiB)\n", size);
+qemu_printf("(%d GiB)\n", size);
 }
 }
 }
 
-static void dump_address_map(FILE *f, fprintf_function cpu_fprintf,
- CPUM68KState *env, uint32_t root_pointer)
+static void dump_address_map(CPUM68KState *env, uint32_t root_pointer)
 {
 int i, j, k;
 int tic_size, tic_shift;
@@ -454,7 +452,7 @@ static void dump_address_map(FILE *f, fprintf_function 
cpu_fprintf,
 if (first_logical != 0x) {
 size = last_logical + (1 << tic_shift) -
first_logical;
-print_address_zone(f, cpu_fprintf, first_logical,
+print_address_zone(first_logical,
first_physical, size, last_attr);
 }
 first_logical = logical;
@@ -465,126 +463,125 @@ static void dump_address_map(FILE *f, fprintf_function 
cpu_fprintf,
 }
 if (first_logical != logical || (attr & 4) != (last_attr & 4)) {
 size = logical + (1 << tic_shift) - first_logical;
-print_address_zone(f, cpu_fprintf, first_logical, first_physical, size,
-   last_attr);
+print_address_zone(first_logical, first_physical, size, last_attr);
 }
 }
 
 #define DUMP_CACHEFLAGS(a) \
 switch (a & M68K_DESC_CACHEMODE) { \
 case M68K_DESC_CM_WRTHRU: /* cachable, write-through */ \
-cpu_fprintf(f, "T"); \
+qemu_printf("T"); \
 break; \
 case M68K_DESC_CM_COPYBK: /* cachable, copyback */ \
-cpu_fprintf(f, "C"); \
+qemu_printf("C"); \
 break; \
 case M68K_DESC_CM_SERIAL: /* noncachable, serialized */ \
-cpu_fprintf(f, "S"); \
+qemu_printf("S"); \
 break; \
 case M68K_DESC_CM_NCACHE: /* noncachable */ \
-cpu_fprintf(f, "N"); \
+

[Qemu-devel] [PULL for-4.1 35/36] disas: Rename include/disas/bfd.h back to include/disas/dis-asm.h

2019-04-18 Thread Markus Armbruster
Commit dc99065b5f9 (v0.1.0) added dis-asm.h from binutils.

Commit 43d4145a986 (v0.1.5) inlined bfd.h into dis-asm.h to remove the
dependency on binutils.

Commit 76cad71136b (v1.4.0) moved dis-asm.h to include/disas/bfd.h.
The new name is confusing when you try to match against (pre GPLv3+)
binutils.  Rename it back.  Keep it in the same directory, of course.

Cc: Paolo Bonzini 
Signed-off-by: Markus Armbruster 
Message-Id: <20190417191805.28198-17-arm...@redhat.com>
Reviewed-by: Dr. David Alan Gilbert 
---
 disas.c| 2 +-
 disas/alpha.c  | 2 +-
 disas/arm-a64.cc   | 2 +-
 disas/arm.c| 2 +-
 disas/cris.c   | 2 +-
 disas/hppa.c   | 2 +-
 disas/i386.c   | 2 +-
 disas/lm32.c   | 2 +-
 disas/m68k.c   | 2 +-
 disas/microblaze.c | 2 +-
 disas/mips.c   | 2 +-
 disas/moxie.c  | 2 +-
 disas/nanomips.cpp | 2 +-
 disas/nios2.c  | 2 +-
 disas/ppc.c| 2 +-
 disas/riscv.c  | 2 +-
 disas/s390.c   | 2 +-
 disas/sh4.c| 2 +-
 disas/sparc.c  | 2 +-
 disas/tci.c| 2 +-
 disas/xtensa.c | 2 +-
 include/disas/{bfd.h => dis-asm.h} | 0
 include/qom/cpu.h  | 2 +-
 target/openrisc/disas.c| 2 +-
 target/ppc/translate_init.inc.c| 2 +-
 25 files changed, 24 insertions(+), 24 deletions(-)
 rename include/disas/{bfd.h => dis-asm.h} (100%)

diff --git a/disas.c b/disas.c
index d15cceb863..41ad0102e2 100644
--- a/disas.c
+++ b/disas.c
@@ -1,7 +1,7 @@
 /* General "disassemble this chunk" code.  Used for debugging. */
 #include "qemu/osdep.h"
 #include "qemu-common.h"
-#include "disas/bfd.h"
+#include "disas/dis-asm.h"
 #include "elf.h"
 #include "qemu/qemu-print.h"
 
diff --git a/disas/alpha.c b/disas/alpha.c
index a0c9ecd49d..3db90fa665 100644
--- a/disas/alpha.c
+++ b/disas/alpha.c
@@ -20,7 +20,7 @@ along with this file; see the file COPYING.  If not, see
 . */
 
 #include "qemu/osdep.h"
-#include "disas/bfd.h"
+#include "disas/dis-asm.h"
 
 /* MAX is redefined below, so remove any previous definition. */
 #undef MAX
diff --git a/disas/arm-a64.cc b/disas/arm-a64.cc
index 9280950ce3..9fa779e175 100644
--- a/disas/arm-a64.cc
+++ b/disas/arm-a64.cc
@@ -19,7 +19,7 @@
 
 extern "C" {
 #include "qemu/osdep.h"
-#include "disas/bfd.h"
+#include "disas/dis-asm.h"
 }
 
 #include "vixl/a64/disasm-a64.h"
diff --git a/disas/arm.c b/disas/arm.c
index 17ea120b44..7d940f2396 100644
--- a/disas/arm.c
+++ b/disas/arm.c
@@ -23,7 +23,7 @@
for things we don't care about.  */
 
 #include "qemu/osdep.h"
-#include "disas/bfd.h"
+#include "disas/dis-asm.h"
 
 #define ARM_EXT_V1  0
 #define ARM_EXT_V2  0
diff --git a/disas/cris.c b/disas/cris.c
index 2dd56deea4..bf9eafc415 100644
--- a/disas/cris.c
+++ b/disas/cris.c
@@ -20,7 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
-#include "disas/bfd.h"
+#include "disas/dis-asm.h"
 #include "target/cris/opcode-cris.h"
 
 #define CONST_STRNEQ(STR1,STR2) (strncmp ((STR1), (STR2), sizeof (STR2) - 1) 
== 0)
diff --git a/disas/hppa.c b/disas/hppa.c
index a2d371fdb1..2dbd1fc445 100644
--- a/disas/hppa.c
+++ b/disas/hppa.c
@@ -19,7 +19,7 @@
along with this program; if not, see . */
 
 #include "qemu/osdep.h"
-#include "disas/bfd.h"
+#include "disas/dis-asm.h"
 
 /* HP PA-RISC SOM object file format:  definitions internal to BFD.
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000,
diff --git a/disas/i386.c b/disas/i386.c
index fc03b9f06a..4c1f0f877b 100644
--- a/disas/i386.c
+++ b/disas/i386.c
@@ -32,7 +32,7 @@
the Intel manual for details.  */
 
 #include "qemu/osdep.h"
-#include "disas/bfd.h"
+#include "disas/dis-asm.h"
 #include "qemu/cutils.h"
 
 /* include/opcode/i386.h r1.78 */
diff --git a/disas/lm32.c b/disas/lm32.c
index fcc2cde23d..c0ef8160fe 100644
--- a/disas/lm32.c
+++ b/disas/lm32.c
@@ -19,7 +19,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "disas/bfd.h"
+#include "disas/dis-asm.h"
 
 typedef enum {
 LM32_OP_SRUI = 0, LM32_OP_NORI, LM32_OP_MULI, LM32_OP_SH, LM32_OP_LB,
diff --git a/disas/m68k.c b/disas/m68k.c
index e544c7137f..863409c67c 100644
--- a/disas/m68k.c
+++ b/disas/m68k.c
@@ -4,7 +4,7 @@
 #include "qemu/osdep.h"
 #include 
 
-#include "disas/bfd.h"
+#include "disas/dis-asm.h"
 
 /*  floatformat.h from sourceware.org CVS 2005-08-14.  */
 /* IEEE floating point support declarations, for GDB, the GNU Debugger.
diff --git a/disas/microblaze.c b/disas/microblaze.c
index c23605043a..0b89b9c4fa 100644
--- a/disas/microblaze.c
+++ b/disas/microblaze.c
@@ -577,7 +577,7 @@ static const char pvr_register_prefix[] = "rpvr";
 
 #endif /* 

[Qemu-devel] [PULL for-4.1 31/36] qom/cpu: Simplify how CPUClass::dump_statistics() prints

2019-04-18 Thread Markus Armbruster
CPUClass method dump_statistics() takes an fprintf()-like callback and
a FILE * to pass to it.

Its only caller hmp_info_cpustats() (via cpu_dump_statistics()) passes
monitor_fprintf() and the current monitor cast to FILE *.
monitor_fprintf() casts it right back, and is otherwise identical to
monitor_printf().  The type-punning is ugly.

Drop the callback, and call qemu_printf() instead.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
Message-Id: <20190417191805.28198-13-arm...@redhat.com>
---
 include/qom/cpu.h  | 11 ---
 monitor.c  |  2 +-
 qom/cpu.c  |  5 ++---
 target/ppc/cpu.h   |  3 +--
 target/ppc/translate.c |  9 -
 5 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 1d6099e5d4..31bafee2b1 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -184,8 +184,7 @@ typedef struct CPUClass {
 void (*dump_state)(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
int flags);
 GuestPanicInformation* (*get_crash_info)(CPUState *cpu);
-void (*dump_statistics)(CPUState *cpu, FILE *f,
-fprintf_function cpu_fprintf, int flags);
+void (*dump_statistics)(CPUState *cpu, int flags);
 int64_t (*get_arch_id)(CPUState *cpu);
 bool (*get_paging_enabled)(const CPUState *cpu);
 void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list,
@@ -576,14 +575,12 @@ void cpu_dump_state(CPUState *cpu, FILE *f, 
fprintf_function cpu_fprintf,
 /**
  * cpu_dump_statistics:
  * @cpu: The CPU whose state is to be dumped.
- * @f: File to dump to.
- * @cpu_fprintf: Function to dump with.
  * @flags: Flags what to dump.
  *
- * Dumps CPU statistics.
+ * Dump CPU statistics to the current monitor if we have one, else to
+ * stdout.
  */
-void cpu_dump_statistics(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
- int flags);
+void cpu_dump_statistics(CPUState *cpu, int flags);
 
 #ifndef CONFIG_USER_ONLY
 /**
diff --git a/monitor.c b/monitor.c
index 0819b99ef7..fb5b681099 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1364,7 +1364,7 @@ static void hmp_info_cpustats(Monitor *mon, const QDict 
*qdict)
 monitor_printf(mon, "No CPU available\n");
 return;
 }
-cpu_dump_statistics(cs, (FILE *)mon, _fprintf, 0);
+cpu_dump_statistics(cs, 0);
 }
 
 static void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
diff --git a/qom/cpu.c b/qom/cpu.c
index a8d2958956..029e7fe9b0 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -230,13 +230,12 @@ void cpu_dump_state(CPUState *cpu, FILE *f, 
fprintf_function cpu_fprintf,
 }
 }
 
-void cpu_dump_statistics(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
- int flags)
+void cpu_dump_statistics(CPUState *cpu, int flags)
 {
 CPUClass *cc = CPU_GET_CLASS(cpu);
 
 if (cc->dump_statistics) {
-cc->dump_statistics(cpu, f, cpu_fprintf, flags);
+cc->dump_statistics(cpu, flags);
 }
 }
 
diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
index 8572241364..27a36b9605 100644
--- a/target/ppc/cpu.h
+++ b/target/ppc/cpu.h
@@ -1270,8 +1270,7 @@ void ppc_cpu_do_interrupt(CPUState *cpu);
 bool ppc_cpu_exec_interrupt(CPUState *cpu, int int_req);
 void ppc_cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
 int flags);
-void ppc_cpu_dump_statistics(CPUState *cpu, FILE *f,
- fprintf_function cpu_fprintf, int flags);
+void ppc_cpu_dump_statistics(CPUState *cpu, int flags);
 hwaddr ppc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
 int ppc_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg);
 int ppc_cpu_gdb_read_register_apple(CPUState *cpu, uint8_t *buf, int reg);
diff --git a/target/ppc/translate.c b/target/ppc/translate.c
index badc1ae1a3..f99f27a134 100644
--- a/target/ppc/translate.c
+++ b/target/ppc/translate.c
@@ -7593,8 +7593,7 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, 
fprintf_function cpu_fprintf,
 #undef RFPL
 }
 
-void ppc_cpu_dump_statistics(CPUState *cs, FILE*f,
- fprintf_function cpu_fprintf, int flags)
+void ppc_cpu_dump_statistics(CPUState *cs, int flags)
 {
 #if defined(DO_PPC_STATISTICS)
 PowerPCCPU *cpu = POWERPC_CPU(cs);
@@ -7614,7 +7613,7 @@ void ppc_cpu_dump_statistics(CPUState *cs, FILE*f,
 handler = t3[op3];
 if (handler->count == 0)
 continue;
-cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
+qemu_printf("%02x %02x %02x (%02x %04d) %16s: "
 "%016" PRIx64 " %" PRId64 "\n",
 op1, op2, op3, op1, (op3 << 5) | op2,
 handler->oname,
@@ -7623,7 +7622,7 @@ void ppc_cpu_dump_statistics(CPUState *cs, FILE*f,
 } else {

[Qemu-devel] [PULL for-4.1 06/36] block/ssh: Do not report read/write/flush errors to the user

2019-04-18 Thread Markus Armbruster
Callbacks ssh_co_readv(), ssh_co_writev(), ssh_co_flush() report
errors to the user with error_printf().  They shouldn't, it's their
caller's job.  Replace by a suitable trace point.  While there, drop
the unreachable !s->sftp case.

Perhaps we should convert this part of the block driver interface to
Error, so block drivers can pass more detail to their callers.  Not
today.

Cc: "Richard W.M. Jones" 
Cc: Kevin Wolf 
Cc: Max Reitz 
Cc: qemu-bl...@nongnu.org
Signed-off-by: Markus Armbruster 
Reviewed-by: Eric Blake 
Message-Id: <20190417190641.26814-3-arm...@redhat.com>
---
 block/ssh.c| 38 +-
 block/trace-events |  3 +++
 2 files changed, 16 insertions(+), 25 deletions(-)

diff --git a/block/ssh.c b/block/ssh.c
index 190ef95300..859249113d 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -159,31 +159,19 @@ sftp_error_setg(Error **errp, BDRVSSHState *s, const char 
*fs, ...)
 g_free(msg);
 }
 
-static void GCC_FMT_ATTR(2, 3)
-sftp_error_report(BDRVSSHState *s, const char *fs, ...)
+static void sftp_error_trace(BDRVSSHState *s, const char *op)
 {
-va_list args;
+char *ssh_err;
+int ssh_err_code;
+unsigned long sftp_err_code;
 
-va_start(args, fs);
-error_vprintf(fs, args);
+/* This is not an errno.  See . */
+ssh_err_code = libssh2_session_last_error(s->session,
+  _err, NULL, 0);
+/* See . */
+sftp_err_code = libssh2_sftp_last_error((s)->sftp);
 
-if ((s)->sftp) {
-char *ssh_err;
-int ssh_err_code;
-unsigned long sftp_err_code;
-
-/* This is not an errno.  See . */
-ssh_err_code = libssh2_session_last_error(s->session,
-  _err, NULL, 0);
-/* See . */
-sftp_err_code = libssh2_sftp_last_error((s)->sftp);
-
-error_printf(": %s (libssh2 error code: %d, sftp error code: %lu)",
- ssh_err, ssh_err_code, sftp_err_code);
-}
-
-va_end(args);
-error_printf("\n");
+trace_sftp_error(op, ssh_err, ssh_err_code, sftp_err_code);
 }
 
 static int parse_uri(const char *filename, QDict *options, Error **errp)
@@ -1035,7 +1023,7 @@ static coroutine_fn int ssh_read(BDRVSSHState *s, 
BlockDriverState *bs,
 goto again;
 }
 if (r < 0) {
-sftp_error_report(s, "read failed");
+sftp_error_trace(s, "read");
 s->offset = -1;
 return -EIO;
 }
@@ -1105,7 +1093,7 @@ static int ssh_write(BDRVSSHState *s, BlockDriverState 
*bs,
 goto again;
 }
 if (r < 0) {
-sftp_error_report(s, "write failed");
+sftp_error_trace(s, "write");
 s->offset = -1;
 return -EIO;
 }
@@ -1188,7 +1176,7 @@ static coroutine_fn int ssh_flush(BDRVSSHState *s, 
BlockDriverState *bs)
 return 0;
 }
 if (r < 0) {
-sftp_error_report(s, "fsync failed");
+sftp_error_trace(s, "fsync");
 return -EIO;
 }
 
diff --git a/block/trace-events b/block/trace-events
index 7335a42540..79ccd8d824 100644
--- a/block/trace-events
+++ b/block/trace-events
@@ -208,3 +208,6 @@ sheepdog_co_rw_vector_new(uint64_t oid) "new oid 0x%" PRIx64
 sheepdog_snapshot_create_info(const char *sn_name, const char *id, const char 
*name, int64_t size, int is_snapshot) "sn_info: name %s id_str %s s: name %s 
vm_state_size %" PRId64 " " "is_snapshot %d"
 sheepdog_snapshot_create(const char *sn_name, const char *id) "%s %s"
 sheepdog_snapshot_create_inode(const char *name, uint32_t snap, uint32_t vdi) 
"s->inode: name %s snap_id 0x%" PRIx32 " vdi 0x%" PRIx32
+
+# ssh.c
+sftp_error(const char *op, const char *ssh_err, int ssh_err_code, unsigned 
long sftp_err_code) "%s failed: %s (libssh2 error code: %d, sftp error code: 
%lu)"
-- 
2.17.2




Re: [Qemu-devel] [PATCH 2/2] tests: fw_cfg: add reboot_timeout test case

2019-04-18 Thread Philippe Mathieu-Daudé
Hi Li,

On 3/19/19 3:30 AM, Li Qiang wrote:
> Signed-off-by: Li Qiang 
> ---
>  tests/fw_cfg-test.c | 15 ++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/fw_cfg-test.c b/tests/fw_cfg-test.c
> index 1c5103fe1c..551b51e38f 100644
> --- a/tests/fw_cfg-test.c
> +++ b/tests/fw_cfg-test.c
> @@ -99,6 +99,17 @@ static void test_fw_cfg_boot_menu(void)
>  g_assert_cmpint(qfw_cfg_get_u16(fw_cfg, FW_CFG_BOOT_MENU), ==, 
> boot_menu);
>  }
>  
> +static void test_fw_cfg_reboot_timeout(void)
> +{
> +uint32_t reboot_timeout = 0;
> +size_t filesize;
> +
> +filesize = qfw_cfg_get_file(fw_cfg, "etc/boot-fail-wait",
> + _timeout, sizeof(reboot_timeout));
> +g_assert_cmpint(filesize, ==, sizeof(reboot_timeout));
> +g_assert_cmpint(reboot_timeout, ==, 15);
> +}
> +
>  int main(int argc, char **argv)
>  {
>  QTestState *s;
> @@ -106,7 +117,8 @@ int main(int argc, char **argv)
>  
>  g_test_init(, , NULL);
>  
> -s = qtest_init("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8");
> +s = qtest_init("-uuid 4600cb32-38ec-4b2f-8acb-81c6ea54f2d8 "
> +   "-boot reboot-timeout=15");

This modify all tests. I'd rather add a specific test with this option.
Doing so, we can easily modify the timeout and add the <0 and >0x cases.

Can you think of a 'splash-time' test (for commit 6912bb0b3d3b1)?

Regards,

Phil.

>  
>  fw_cfg = pc_fw_cfg_init(s);
>  
> @@ -125,6 +137,7 @@ int main(int argc, char **argv)
>  qtest_add_func("fw_cfg/max_cpus", test_fw_cfg_max_cpus);
>  qtest_add_func("fw_cfg/numa", test_fw_cfg_numa);
>  qtest_add_func("fw_cfg/boot_menu", test_fw_cfg_boot_menu);
> +qtest_add_func("fw_cfg/reboot_timeout", test_fw_cfg_reboot_timeout);
>  
>  ret = g_test_run();
>  
> 



[Qemu-devel] [PULL for-4.1 16/36] blockdev: Make -drive format=help print to stdout

2019-04-18 Thread Markus Armbruster
Command line help explicitly requested by the user should be printed
to stdout, not stderr.  We do elsewhere.  Adjust -drive to match: use
qemu_printf() instead of error_printf().  Plain printf() would be
wrong because we need to print to the current monitor for "drive_add
... format=help".

Cc: Kevin Wolf 
Cc: Max Reitz 
Cc: qemu-bl...@nongnu.org
Signed-off-by: Markus Armbruster 
Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 
Message-Id: <20190417190641.26814-13-arm...@redhat.com>
---
 blockdev.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 4775a07d93..79fbac8450 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -40,6 +40,7 @@
 #include "monitor/monitor.h"
 #include "qemu/error-report.h"
 #include "qemu/option.h"
+#include "qemu/qemu-print.h"
 #include "qemu/config-file.h"
 #include "qapi/qapi-commands-block.h"
 #include "qapi/qapi-commands-transaction.h"
@@ -301,7 +302,7 @@ DriveInfo *drive_get_next(BlockInterfaceType type)
 
 static void bdrv_format_print(void *opaque, const char *name)
 {
-error_printf(" %s", name);
+qemu_printf(" %s", name);
 }
 
 typedef struct {
@@ -530,11 +531,11 @@ static BlockBackend *blockdev_init(const char *file, 
QDict *bs_opts,
 
 if ((buf = qemu_opt_get(opts, "format")) != NULL) {
 if (is_help_option(buf)) {
-error_printf("Supported formats:");
+qemu_printf("Supported formats:");
 bdrv_iterate_format(bdrv_format_print, NULL, false);
-error_printf("\nSupported formats (read-only):");
+qemu_printf("\nSupported formats (read-only):");
 bdrv_iterate_format(bdrv_format_print, NULL, true);
-error_printf("\n");
+qemu_printf("\n");
 goto early_err;
 }
 
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 17/36] char: Make -chardev help print to stdout

2019-04-18 Thread Markus Armbruster
Command line help explicitly requested by the user should be printed
to stdout, not stderr.  We do elsewhere.  Adjust -chardev to match:
use qemu_printf() instead of error_printf().  Plain printf() would be
wrong because we need to print to the current monitor for "chardev-add
help".

Cc: "Marc-André Lureau" 
Cc: Paolo Bonzini 
Signed-off-by: Markus Armbruster 
Reviewed-by: Marc-André Lureau 
Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 
Message-Id: <20190417190641.26814-14-arm...@redhat.com>
---
 chardev/char.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/chardev/char.c b/chardev/char.c
index 514cd6b0c3..54724a56b1 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -28,6 +28,7 @@
 #include "sysemu/sysemu.h"
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
+#include "qemu/qemu-print.h"
 #include "chardev/char.h"
 #include "qapi/error.h"
 #include "qapi/qapi-commands-char.h"
@@ -651,7 +652,7 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, 
GMainContext *context,
 
 chardev_name_foreach(help_string_append, str);
 
-error_printf("Available chardev backend types: %s\n", str->str);
+qemu_printf("Available chardev backend types: %s\n", str->str);
 g_string_free(str, true);
 return NULL;
 }
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 33/36] qom/cpu: Simplify how CPUClass:cpu_dump_state() prints

2019-04-18 Thread Markus Armbruster
CPUClass method dump_statistics() takes an fprintf()-like callback and
a FILE * to pass to it.  Most callers pass fprintf() and stderr.
log_cpu_state() passes fprintf() and qemu_log_file.
hmp_info_registers() passes monitor_fprintf() and the current monitor
cast to FILE *.  monitor_fprintf() casts it right back, and is
otherwise identical to monitor_printf().

The callback gets passed around a lot, which is tiresome.  The
type-punning around monitor_fprintf() is ugly.

Drop the callback, and call qemu_fprintf() instead.  Also gets rid of
the type-punning, since qemu_fprintf() takes NULL instead of the
current monitor cast to FILE *.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
Message-Id: <20190417191805.28198-15-arm...@redhat.com>
---
 accel/kvm/kvm-all.c  |   4 +-
 bsd-user/main.c  |   2 +-
 cpus.c   |   2 +-
 exec.c   |   2 +-
 include/exec/log.h   |   2 +-
 include/qom/cpu.h|  11 +-
 linux-user/alpha/cpu_loop.c  |   2 +-
 linux-user/cpu_loop-common.h |   2 +-
 linux-user/cris/cpu_loop.c   |   2 +-
 linux-user/microblaze/cpu_loop.c |   4 +-
 linux-user/s390x/cpu_loop.c  |   4 +-
 linux-user/sh4/cpu_loop.c|   2 +-
 linux-user/sparc/cpu_loop.c  |   2 +-
 monitor.c|   4 +-
 qom/cpu.c|   6 +-
 target/alpha/cpu.h   |   3 +-
 target/alpha/helper.c|  24 +--
 target/arm/arm-semi.c|   2 +-
 target/arm/cpu.h |   3 +-
 target/arm/translate-a64.c   |  82 -
 target/arm/translate.c   |  58 +++
 target/arm/translate.h   |   7 +-
 target/cris/cpu.h|   3 +-
 target/cris/helper.c |   2 +-
 target/cris/translate.c  |  36 ++--
 target/hppa/cpu.h|   2 +-
 target/hppa/helper.c |  24 +--
 target/i386/cpu.h|   3 +-
 target/i386/hax-all.c|   4 +-
 target/i386/helper.c | 277 +++
 target/lm32/cpu.h|   3 +-
 target/lm32/translate.c  |  36 ++--
 target/m68k/cpu.h|   3 +-
 target/m68k/translate.c  |  86 +-
 target/microblaze/cpu.h  |   3 +-
 target/microblaze/helper.c   |   2 +-
 target/microblaze/translate.c|  39 ++---
 target/mips/internal.h   |   3 +-
 target/mips/translate.c  |  76 -
 target/moxie/cpu.h   |   3 +-
 target/moxie/helper.c|   2 +-
 target/moxie/translate.c |  22 +--
 target/nios2/cpu.h   |   3 +-
 target/nios2/helper.c|   2 +-
 target/nios2/translate.c |  24 +--
 target/openrisc/cpu.h|   3 +-
 target/openrisc/translate.c  |  11 +-
 target/ppc/cpu.h |   3 +-
 target/ppc/translate.c   | 161 +-
 target/riscv/cpu.c   |  37 ++---
 target/s390x/helper.c|  42 ++---
 target/s390x/internal.h  |   3 +-
 target/sh4/cpu.h |   3 +-
 target/sh4/translate.c   |  27 +--
 target/sparc/cpu.c   |  84 +-
 target/sparc/cpu.h   |   3 +-
 target/tilegx/cpu.c  |  14 +-
 target/tricore/cpu.h |   3 +-
 target/tricore/translate.c   |  26 +--
 target/unicore32/cpu.h   |   3 +-
 target/unicore32/translate.c |  39 +++--
 target/xtensa/cpu.h  |   3 +-
 target/xtensa/translate.c|  40 ++---
 63 files changed, 682 insertions(+), 711 deletions(-)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 241db496c3..524c4ddfbd 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -1798,7 +1798,7 @@ static int kvm_handle_internal_error(CPUState *cpu, 
struct kvm_run *run)
 if (run->internal.suberror == KVM_INTERNAL_ERROR_EMULATION) {
 fprintf(stderr, "emulation failure\n");
 if (!kvm_arch_stop_on_emulation_error(cpu)) {
-cpu_dump_state(cpu, stderr, fprintf, CPU_DUMP_CODE);
+cpu_dump_state(cpu, stderr, CPU_DUMP_CODE);
 return EXCP_INTERRUPT;
 }
 }
@@ -2089,7 +2089,7 @@ int kvm_cpu_exec(CPUState *cpu)
 qemu_mutex_lock_iothread();
 
 if (ret < 0) {
-cpu_dump_state(cpu, stderr, fprintf, CPU_DUMP_CODE);
+cpu_dump_state(cpu, stderr, CPU_DUMP_CODE);
 vm_stop(RUN_STATE_INTERNAL_ERROR);
 }
 
diff --git a/bsd-user/main.c b/bsd-user/main.c
index 7657c6851d..a8c807e8df 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -640,7 +640,7 @@ void cpu_loop(CPUSPARCState *env)
 badtrap:
 #endif
 printf ("Unhandled trap: 0x%x\n", trapnr);
-cpu_dump_state(cs, stderr, fprintf, 0);
+cpu_dump_state(cs, stderr, 0);
 exit (1);
 }
 process_pending_signals (env);
diff --git a/cpus.c b/cpus.c
index b4eecf70f0..e58e7ab0f6 

Re: [Qemu-devel] [PATCH 00/10] block/pflash_cfi02: Implement missing AMD pflash functionality

2019-04-18 Thread Stephen Checkoway



On Apr 9, 2019, at 12:15, Philippe Mathieu-Daudé  wrote:

> Since you did changes in the CFI table, I think we should add a tests
> verifying the table is correctly generated for all you FlashConfig entries.

In v3 of the patch, I added tests for the CFI table values
- device length
- sector length and number of sectors
- erase suspend supported

-- 
Stephen Checkoway








[Qemu-devel] [PULL for-4.1 05/36] qemu-img: Use error_vreport() in error_exit()

2019-04-18 Thread Markus Armbruster
error_exit() uses low-level error_printf() to report errors.
Modernize it to use error_vreport().

Cc: Kevin Wolf 
Cc: Max Reitz 
Cc: qemu-bl...@nongnu.org
Signed-off-by: Markus Armbruster 
Reviewed-by: Eric Blake 
Message-Id: <20190417190641.26814-2-arm...@redhat.com>
---
 qemu-img.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 8c7b2437f0..c376e91ca0 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -85,13 +85,11 @@ static void QEMU_NORETURN GCC_FMT_ATTR(1, 2) 
error_exit(const char *fmt, ...)
 {
 va_list ap;
 
-error_printf("qemu-img: ");
-
 va_start(ap, fmt);
-error_vprintf(fmt, ap);
+error_vreport(fmt, ap);
 va_end(ap);
 
-error_printf("\nTry 'qemu-img --help' for more information\n");
+error_printf("Try 'qemu-img --help' for more information\n");
 exit(EXIT_FAILURE);
 }
 
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 23/36] tcg: Simplify how dump_exec_info() prints

2019-04-18 Thread Markus Armbruster
dump_exec_info() takes an fprintf()-like callback and a FILE * to pass
to it.

Its only caller hmp_info_jit() passes monitor_fprintf() and the
current monitor cast to FILE *.  monitor_fprintf() casts it right
back, and is otherwise identical to monitor_printf().  The
type-punning is ugly.

Drop the callback, and call qemu_printf() instead.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
Message-Id: <20190417191805.28198-5-arm...@redhat.com>
---
 accel/tcg/translate-all.c | 45 ---
 include/exec/cpu-all.h|  2 +-
 monitor.c |  2 +-
 tcg/tcg.c | 41 ++-
 tcg/tcg.h |  2 +-
 5 files changed, 47 insertions(+), 45 deletions(-)

diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index 85e80a1fad..75a6cf49f1 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -50,6 +50,7 @@
 #include "translate-all.h"
 #include "qemu/bitmap.h"
 #include "qemu/error-report.h"
+#include "qemu/qemu-print.h"
 #include "qemu/timer.h"
 #include "qemu/main-loop.h"
 #include "exec/log.h"
@@ -2214,8 +2215,7 @@ void tb_flush_jmp_cache(CPUState *cpu, target_ulong addr)
 tb_jmp_cache_clear_page(cpu, addr);
 }
 
-static void print_qht_statistics(FILE *f, fprintf_function cpu_fprintf,
- struct qht_stats hst)
+static void print_qht_statistics(struct qht_stats hst)
 {
 uint32_t hgram_opts;
 size_t hgram_bins;
@@ -2224,7 +2224,7 @@ static void print_qht_statistics(FILE *f, 
fprintf_function cpu_fprintf,
 if (!hst.head_buckets) {
 return;
 }
-cpu_fprintf(f, "TB hash buckets %zu/%zu (%0.2f%% head buckets used)\n",
+qemu_printf("TB hash buckets %zu/%zu (%0.2f%% head buckets used)\n",
 hst.used_head_buckets, hst.head_buckets,
 (double)hst.used_head_buckets / hst.head_buckets * 100);
 
@@ -2234,7 +2234,7 @@ static void print_qht_statistics(FILE *f, 
fprintf_function cpu_fprintf,
 hgram_opts |= QDIST_PR_NODECIMAL;
 }
 hgram = qdist_pr(, 10, hgram_opts);
-cpu_fprintf(f, "TB hash occupancy   %0.2f%% avg chain occ. Histogram: 
%s\n",
+qemu_printf("TB hash occupancy   %0.2f%% avg chain occ. Histogram: %s\n",
 qdist_avg() * 100, hgram);
 g_free(hgram);
 
@@ -2247,7 +2247,7 @@ static void print_qht_statistics(FILE *f, 
fprintf_function cpu_fprintf,
 hgram_opts |= QDIST_PR_NODECIMAL | QDIST_PR_NOBINRANGE;
 }
 hgram = qdist_pr(, hgram_bins, hgram_opts);
-cpu_fprintf(f, "TB hash avg chain   %0.3f buckets. Histogram: %s\n",
+qemu_printf("TB hash avg chain   %0.3f buckets. Histogram: %s\n",
 qdist_avg(), hgram);
 g_free(hgram);
 }
@@ -2285,7 +2285,7 @@ static gboolean tb_tree_stats_iter(gpointer key, gpointer 
value, gpointer data)
 return false;
 }
 
-void dump_exec_info(FILE *f, fprintf_function cpu_fprintf)
+void dump_exec_info(void)
 {
 struct tb_tree_stats tst = {};
 struct qht_stats hst;
@@ -2294,43 +2294,44 @@ void dump_exec_info(FILE *f, fprintf_function 
cpu_fprintf)
 tcg_tb_foreach(tb_tree_stats_iter, );
 nb_tbs = tst.nb_tbs;
 /* XXX: avoid using doubles ? */
-cpu_fprintf(f, "Translation buffer state:\n");
+qemu_printf("Translation buffer state:\n");
 /*
  * Report total code size including the padding and TB structs;
  * otherwise users might think "-tb-size" is not honoured.
  * For avg host size we use the precise numbers from tb_tree_stats though.
  */
-cpu_fprintf(f, "gen code size   %zu/%zu\n",
+qemu_printf("gen code size   %zu/%zu\n",
 tcg_code_size(), tcg_code_capacity());
-cpu_fprintf(f, "TB count%zu\n", nb_tbs);
-cpu_fprintf(f, "TB avg target size  %zu max=%zu bytes\n",
+qemu_printf("TB count%zu\n", nb_tbs);
+qemu_printf("TB avg target size  %zu max=%zu bytes\n",
 nb_tbs ? tst.target_size / nb_tbs : 0,
 tst.max_target_size);
-cpu_fprintf(f, "TB avg host size%zu bytes (expansion ratio: %0.1f)\n",
+qemu_printf("TB avg host size%zu bytes (expansion ratio: %0.1f)\n",
 nb_tbs ? tst.host_size / nb_tbs : 0,
 tst.target_size ? (double)tst.host_size / tst.target_size : 0);
-cpu_fprintf(f, "cross page TB count %zu (%zu%%)\n", tst.cross_page,
-nb_tbs ? (tst.cross_page * 100) / nb_tbs : 0);
-cpu_fprintf(f, "direct jump count   %zu (%zu%%) (2 jumps=%zu %zu%%)\n",
+qemu_printf("cross page TB count %zu (%zu%%)\n", tst.cross_page,
+nb_tbs ? (tst.cross_page * 100) / nb_tbs : 0);
+qemu_printf("direct jump count   %zu (%zu%%) (2 jumps=%zu %zu%%)\n",
 tst.direct_jmp_count,
 nb_tbs ? (tst.direct_jmp_count * 100) / nb_tbs : 0,
 tst.direct_jmp2_count,
 nb_tbs ? (tst.direct_jmp2_count * 100) / 

[Qemu-devel] [PULL for-4.1 28/36] target: Simplify how the TARGET_cpu_list() print

2019-04-18 Thread Markus Armbruster
The various TARGET_cpu_list() take an fprintf()-like callback and a
FILE * to pass to it.  Their callers (vl.c's main() via list_cpus(),
bsd-user/main.c's main(), linux-user/main.c's main()) all pass
fprintf() and stdout.  Thus, the flexibility provided by the (rather
tiresome) indirection isn't actually used.

Drop the callback, and call qemu_printf() instead.

Calling printf() would also work, but would make the code unsuitable
for monitor context without making it simpler.

Signed-off-by: Markus Armbruster 
Message-Id: <20190417191805.28198-10-arm...@redhat.com>
Reviewed-by: Dr. David Alan Gilbert 
---
 bsd-user/main.c  |  2 +-
 cpus.c   |  4 +--
 include/exec/cpu-common.h| 13 -
 include/sysemu/cpus.h|  3 +-
 linux-user/main.c|  2 +-
 target/alpha/cpu.c   | 15 --
 target/alpha/cpu.h   |  2 +-
 target/arm/cpu.c |  1 -
 target/arm/cpu.h |  2 +-
 target/arm/helper.c  | 15 --
 target/cris/cpu.c| 14 -
 target/cris/cpu.h|  2 +-
 target/hppa/cpu.c| 14 -
 target/hppa/cpu.h|  2 +-
 target/i386/cpu.c| 29 ---
 target/i386/cpu.h|  2 +-
 target/lm32/cpu.c| 14 -
 target/lm32/cpu.h|  2 +-
 target/m68k/cpu.h|  2 +-
 target/m68k/helper.c | 14 +++--
 target/mips/cpu.h|  2 +-
 target/mips/translate.c  |  1 +
 target/mips/translate_init.inc.c |  5 ++--
 target/openrisc/cpu.c| 15 --
 target/openrisc/cpu.h|  2 +-
 target/ppc/cpu.h |  2 +-
 target/ppc/translate_init.inc.c  | 26 +++--
 target/riscv/cpu.c   | 17 +++
 target/riscv/cpu.h   |  2 +-
 target/s390x/cpu.h   |  2 +-
 target/s390x/cpu_models.c| 21 ++
 target/sh4/cpu.c | 17 +++
 target/sh4/cpu.h |  2 +-
 target/sparc/cpu.c   | 49 +++-
 target/sparc/cpu.h   |  2 +-
 target/tricore/cpu.h |  2 +-
 target/tricore/helper.c  | 15 --
 target/xtensa/cpu.h  |  2 +-
 target/xtensa/helper.c   |  7 +++--
 vl.c |  2 +-
 40 files changed, 129 insertions(+), 218 deletions(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index 8fd8ae4127..7657c6851d 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -819,7 +819,7 @@ int main(int argc, char **argv)
 if (is_help_option(cpu_model)) {
 /* XXX: implement xxx_cpu_list for targets that still miss it */
 #if defined(cpu_list)
-cpu_list(stdout, );
+cpu_list();
 #endif
 exit(1);
 }
diff --git a/cpus.c b/cpus.c
index 684aa9679a..b4eecf70f0 100644
--- a/cpus.c
+++ b/cpus.c
@@ -2181,11 +2181,11 @@ int vm_stop_force_state(RunState state)
 }
 }
 
-void list_cpus(FILE *f, fprintf_function cpu_fprintf, const char *optarg)
+void list_cpus(const char *optarg)
 {
 /* XXX: implement xxx_cpu_list for targets that still miss it */
 #if defined(cpu_list)
-cpu_list(f, cpu_fprintf);
+cpu_list();
 #endif
 }
 
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index cef8b88a2a..848a4b94ab 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -9,19 +9,6 @@
 
 #include "qemu/bswap.h"
 #include "qemu/queue.h"
-#include "qemu/fprintf-fn.h"
-
-/**
- * CPUListState:
- * @cpu_fprintf: Print function.
- * @file: File to print to using @cpu_fprint.
- *
- * State commonly used for iterating over CPU models.
- */
-typedef struct CPUListState {
-fprintf_function cpu_fprintf;
-FILE *file;
-} CPUListState;
 
 /* The CPU list lock nests outside page_(un)lock or mmap_(un)lock */
 void qemu_init_cpu_list(void);
diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h
index ef13a120cc..32c05f27e7 100644
--- a/include/sysemu/cpus.h
+++ b/include/sysemu/cpus.h
@@ -1,7 +1,6 @@
 #ifndef QEMU_CPUS_H
 #define QEMU_CPUS_H
 
-#include "qemu/fprintf-fn.h"
 #include "qemu/timer.h"
 
 /* cpus.c */
@@ -39,7 +38,7 @@ extern int smp_cores;
 extern int smp_threads;
 #endif
 
-void list_cpus(FILE *f, fprintf_function cpu_fprintf, const char *optarg);
+void list_cpus(const char *optarg);
 
 void qemu_tcg_configure(QemuOpts *opts, Error **errp);
 
diff --git a/linux-user/main.c b/linux-user/main.c
index f9efe9ff6e..17387166ab 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -317,7 +317,7 @@ static void handle_arg_cpu(const char *arg)
 if (cpu_model == NULL || is_help_option(cpu_model)) {
 /* XXX: implement xxx_cpu_list for targets that still miss it */
 #if defined(cpu_list)
-cpu_list(stdout, );
+cpu_list();
 #endif
 exit(EXIT_FAILURE);
   

[Qemu-devel] [PULL for-4.1 10/36] hpet: Report warnings with warn_report(), not error_printf()

2019-04-18 Thread Markus Armbruster
Cc: "Michael S. Tsirkin" 
Cc: Paolo Bonzini 
Signed-off-by: Markus Armbruster 
Message-Id: <20190417190641.26814-7-arm...@redhat.com>
---
 hw/timer/hpet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
index d97436bc7b..41024f39fb 100644
--- a/hw/timer/hpet.c
+++ b/hw/timer/hpet.c
@@ -744,7 +744,7 @@ static void hpet_realize(DeviceState *dev, Error **errp)
 HPETTimer *timer;
 
 if (!s->intcap) {
-error_printf("Hpet's intcap not initialized.\n");
+warn_report("Hpet's intcap not initialized");
 }
 if (hpet_cfg.count == UINT8_MAX) {
 /* first instance */
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 25/36] qsp: Simplify how qsp_report() prints

2019-04-18 Thread Markus Armbruster
qsp_report() takes an fprintf()-like callback and a FILE * to pass to
it.

Its only caller hmp_sync_profile() passes monitor_fprintf() and the
current monitor cast to FILE *.  monitor_fprintf() casts it right
back, and is otherwise identical to monitor_printf().  The
type-punning is ugly.

Drop the callback, and call qemu_printf() instead.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
Message-Id: <20190417191805.28198-7-arm...@redhat.com>
---
 include/block/qapi.h |  1 +
 include/qemu/qsp.h   |  6 ++
 monitor.c|  2 +-
 util/qsp.c   | 21 +++--
 4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/include/block/qapi.h b/include/block/qapi.h
index 83bdb098bd..a891f43b9c 100644
--- a/include/block/qapi.h
+++ b/include/block/qapi.h
@@ -27,6 +27,7 @@
 
 #include "block/block.h"
 #include "block/snapshot.h"
+#include "qemu/fprintf-fn.h"
 
 BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
 BlockDriverState *bs, Error **errp);
diff --git a/include/qemu/qsp.h b/include/qemu/qsp.h
index a94c464f90..bf36aabfa8 100644
--- a/include/qemu/qsp.h
+++ b/include/qemu/qsp.h
@@ -11,15 +11,13 @@
 #ifndef QEMU_QSP_H
 #define QEMU_QSP_H
 
-#include "qemu/fprintf-fn.h"
-
 enum QSPSortBy {
 QSP_SORT_BY_TOTAL_WAIT_TIME,
 QSP_SORT_BY_AVG_WAIT_TIME,
 };
 
-void qsp_report(FILE *f, fprintf_function cpu_fprintf, size_t max,
-enum QSPSortBy sort_by, bool callsite_coalesce);
+void qsp_report(size_t max, enum QSPSortBy sort_by,
+bool callsite_coalesce);
 
 bool qsp_is_enabled(void);
 void qsp_enable(void);
diff --git a/monitor.c b/monitor.c
index 7573689585..1650ceec3a 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1336,7 +1336,7 @@ static void hmp_info_sync_profile(Monitor *mon, const 
QDict *qdict)
 enum QSPSortBy sort_by;
 
 sort_by = mean ? QSP_SORT_BY_AVG_WAIT_TIME : QSP_SORT_BY_TOTAL_WAIT_TIME;
-qsp_report((FILE *)mon, monitor_fprintf, max, sort_by, coalesce);
+qsp_report(max, sort_by, coalesce);
 }
 
 static void hmp_info_history(Monitor *mon, const QDict *qdict)
diff --git a/util/qsp.c b/util/qsp.c
index 410f1ba004..5264c97342 100644
--- a/util/qsp.c
+++ b/util/qsp.c
@@ -56,7 +56,9 @@
  *   Critical-Section Execution to Improve the Performance of Multithreaded
  *   Applications", USENIX ATC'12.
  */
+
 #include "qemu/osdep.h"
+#include "qemu/qemu-print.h"
 #include "qemu/thread.h"
 #include "qemu/timer.h"
 #include "qemu/qht.h"
@@ -678,8 +680,7 @@ static gboolean qsp_tree_report(gpointer key, gpointer 
value, gpointer udata)
 return FALSE;
 }
 
-static void
-pr_report(const QSPReport *rep, FILE *f, fprintf_function pr)
+static void pr_report(const QSPReport *rep)
 {
 char *dashes;
 size_t max_len = 0;
@@ -702,15 +703,15 @@ pr_report(const QSPReport *rep, FILE *f, fprintf_function 
pr)
 /* white space to leave to the right of "Call site" */
 callsite_rspace = callsite_len - strlen("Call site");
 
-pr(f, "Type   Object  Call site%*s  Wait Time (s)  "
-   "   Count  Average (us)\n", callsite_rspace, "");
+qemu_printf("Type   Object  Call site%*s  Wait Time (s)  "
+"   Count  Average (us)\n", callsite_rspace, "");
 
 /* build a horizontal rule with dashes */
 n_dashes = 79 + callsite_rspace;
 dashes = g_malloc(n_dashes + 1);
 memset(dashes, '-', n_dashes);
 dashes[n_dashes] = '\0';
-pr(f, "%s\n", dashes);
+qemu_printf("%s\n", dashes);
 
 for (i = 0; i < rep->n_entries; i++) {
 const QSPReportEntry *e = >entries[i];
@@ -726,11 +727,11 @@ pr_report(const QSPReport *rep, FILE *f, fprintf_function 
pr)
e->callsite_at,
callsite_len - (int)strlen(e->callsite_at), "",
e->time_s, e->n_acqs, e->ns_avg * 1e-3);
-pr(f, "%s", s->str);
+qemu_printf("%s", s->str);
 g_string_free(s, TRUE);
 }
 
-pr(f, "%s\n", dashes);
+qemu_printf("%s\n", dashes);
 g_free(dashes);
 }
 
@@ -746,8 +747,8 @@ static void report_destroy(QSPReport *rep)
 g_free(rep->entries);
 }
 
-void qsp_report(FILE *f, fprintf_function cpu_fprintf, size_t max,
-enum QSPSortBy sort_by, bool callsite_coalesce)
+void qsp_report(size_t max, enum QSPSortBy sort_by,
+bool callsite_coalesce)
 {
 GTree *tree = g_tree_new_full(qsp_tree_cmp, _by, g_free, NULL);
 QSPReport rep;
@@ -762,7 +763,7 @@ void qsp_report(FILE *f, fprintf_function cpu_fprintf, 
size_t max,
 g_tree_foreach(tree, qsp_tree_report, );
 g_tree_destroy(tree);
 
-pr_report(, f, cpu_fprintf);
+pr_report();
 report_destroy();
 }
 
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 26/36] block/qapi: Clean up how we print to monitor or stdout

2019-04-18 Thread Markus Armbruster
bdrv_snapshot_dump(), bdrv_image_info_specific_dump(),
bdrv_image_info_dump() and their helpers take an fprintf()-like
callback and a FILE * to pass to it.

hmp.c passes monitor_printf() cast to fprintf_function and the current
monitor cast to FILE *.

qemu-img.c and qemu-io-cmds.c pass fprintf and stdout.

The type-punning is technically undefined behaviour, but works in
practice.  Clean up: drop the callback, and call qemu_printf()
instead.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
Message-Id: <20190417191805.28198-8-arm...@redhat.com>
---
 block/qapi.c | 120 ---
 hmp.c|  12 ++---
 include/block/qapi.h |  10 ++--
 qemu-img.c   |   6 +--
 qemu-io-cmds.c   |   2 +-
 5 files changed, 67 insertions(+), 83 deletions(-)

diff --git a/block/qapi.c b/block/qapi.c
index 21edab34fc..e3e74f898f 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -36,6 +36,7 @@
 #include "qapi/qmp/qlist.h"
 #include "qapi/qmp/qnum.h"
 #include "qapi/qmp/qstring.h"
+#include "qemu/qemu-print.h"
 #include "sysemu/block-backend.h"
 #include "qemu/cutils.h"
 
@@ -660,8 +661,7 @@ static char *get_human_readable_size(char *buf, int 
buf_size, int64_t size)
 return buf;
 }
 
-void bdrv_snapshot_dump(fprintf_function func_fprintf, void *f,
-QEMUSnapshotInfo *sn)
+void bdrv_snapshot_dump(QEMUSnapshotInfo *sn)
 {
 char buf1[128], date_buf[128], clock_buf[128];
 struct tm tm;
@@ -669,9 +669,8 @@ void bdrv_snapshot_dump(fprintf_function func_fprintf, void 
*f,
 int64_t secs;
 
 if (!sn) {
-func_fprintf(f,
- "%-10s%-20s%7s%20s%15s",
- "ID", "TAG", "VM SIZE", "DATE", "VM CLOCK");
+qemu_printf("%-10s%-20s%7s%20s%15s",
+"ID", "TAG", "VM SIZE", "DATE", "VM CLOCK");
 } else {
 ti = sn->date_sec;
 localtime_r(, );
@@ -684,50 +683,46 @@ void bdrv_snapshot_dump(fprintf_function func_fprintf, 
void *f,
  (int)((secs / 60) % 60),
  (int)(secs % 60),
  (int)((sn->vm_clock_nsec / 100) % 1000));
-func_fprintf(f,
- "%-10s%-20s%7s%20s%15s",
- sn->id_str, sn->name,
- get_human_readable_size(buf1, sizeof(buf1),
- sn->vm_state_size),
- date_buf,
- clock_buf);
+qemu_printf("%-10s%-20s%7s%20s%15s",
+sn->id_str, sn->name,
+get_human_readable_size(buf1, sizeof(buf1),
+sn->vm_state_size),
+date_buf,
+clock_buf);
 }
 }
 
-static void dump_qdict(fprintf_function func_fprintf, void *f, int indentation,
-   QDict *dict);
-static void dump_qlist(fprintf_function func_fprintf, void *f, int indentation,
-   QList *list);
+static void dump_qdict(int indentation, QDict *dict);
+static void dump_qlist(int indentation, QList *list);
 
-static void dump_qobject(fprintf_function func_fprintf, void *f,
- int comp_indent, QObject *obj)
+static void dump_qobject(int comp_indent, QObject *obj)
 {
 switch (qobject_type(obj)) {
 case QTYPE_QNUM: {
 QNum *value = qobject_to(QNum, obj);
 char *tmp = qnum_to_string(value);
-func_fprintf(f, "%s", tmp);
+qemu_printf("%s", tmp);
 g_free(tmp);
 break;
 }
 case QTYPE_QSTRING: {
 QString *value = qobject_to(QString, obj);
-func_fprintf(f, "%s", qstring_get_str(value));
+qemu_printf("%s", qstring_get_str(value));
 break;
 }
 case QTYPE_QDICT: {
 QDict *value = qobject_to(QDict, obj);
-dump_qdict(func_fprintf, f, comp_indent, value);
+dump_qdict(comp_indent, value);
 break;
 }
 case QTYPE_QLIST: {
 QList *value = qobject_to(QList, obj);
-dump_qlist(func_fprintf, f, comp_indent, value);
+dump_qlist(comp_indent, value);
 break;
 }
 case QTYPE_QBOOL: {
 QBool *value = qobject_to(QBool, obj);
-func_fprintf(f, "%s", qbool_get_bool(value) ? "true" : "false");
+qemu_printf("%s", qbool_get_bool(value) ? "true" : "false");
 break;
 }
 default:
@@ -735,8 +730,7 @@ static void dump_qobject(fprintf_function func_fprintf, 
void *f,
 }
 }
 
-static void dump_qlist(fprintf_function func_fprintf, void *f, int indentation,
-   QList *list)
+static void dump_qlist(int indentation, QList *list)
 {
 const QListEntry *entry;
 int i = 0;
@@ -744,17 +738,16 @@ static void dump_qlist(fprintf_function func_fprintf, 
void *f, int indentation,
 for (entry 

[Qemu-devel] [PULL for-4.1 24/36] tcg: Simplify how dump_drift_info() prints

2019-04-18 Thread Markus Armbruster
dump_drift_info() takes an fprintf()-like callback and a FILE * to pass
to it.

Its only caller hmp_info_jit() passes monitor_fprintf() and a Monitor
* cast to FILE *.  monitor_fprintf() casts it right back, and is
otherwise identical to monitor_printf().  The type-punning is ugly.

Drop the callback, and call qemu_printf() instead.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
Message-Id: <20190417191805.28198-6-arm...@redhat.com>
---
 cpus.c| 15 +--
 include/sysemu/cpus.h |  2 +-
 monitor.c |  2 +-
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/cpus.c b/cpus.c
index e83f72b48b..684aa9679a 100644
--- a/cpus.c
+++ b/cpus.c
@@ -31,6 +31,7 @@
 #include "qapi/qapi-events-run-state.h"
 #include "qapi/qmp/qerror.h"
 #include "qemu/error-report.h"
+#include "qemu/qemu-print.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/block-backend.h"
 #include "exec/gdbstub.h"
@@ -2454,19 +2455,21 @@ void qmp_inject_nmi(Error **errp)
 nmi_monitor_handle(monitor_get_cpu_index(), errp);
 }
 
-void dump_drift_info(FILE *f, fprintf_function cpu_fprintf)
+void dump_drift_info(void)
 {
 if (!use_icount) {
 return;
 }
 
-cpu_fprintf(f, "Host - Guest clock  %"PRIi64" ms\n",
+qemu_printf("Host - Guest clock  %"PRIi64" ms\n",
 (cpu_get_clock() - cpu_get_icount())/SCALE_MS);
 if (icount_align_option) {
-cpu_fprintf(f, "Max guest delay %"PRIi64" ms\n", 
-max_delay/SCALE_MS);
-cpu_fprintf(f, "Max guest advance   %"PRIi64" ms\n", 
max_advance/SCALE_MS);
+qemu_printf("Max guest delay %"PRIi64" ms\n",
+-max_delay / SCALE_MS);
+qemu_printf("Max guest advance   %"PRIi64" ms\n",
+max_advance / SCALE_MS);
 } else {
-cpu_fprintf(f, "Max guest delay NA\n");
-cpu_fprintf(f, "Max guest advance   NA\n");
+qemu_printf("Max guest delay NA\n");
+qemu_printf("Max guest advance   NA\n");
 }
 }
diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h
index eea0010b53..ef13a120cc 100644
--- a/include/sysemu/cpus.h
+++ b/include/sysemu/cpus.h
@@ -19,7 +19,7 @@ extern int icount_align_option;
 /* drift information for info jit command */
 extern int64_t max_delay;
 extern int64_t max_advance;
-void dump_drift_info(FILE *f, fprintf_function cpu_fprintf);
+void dump_drift_info(void);
 
 /* Unblock cpu */
 void qemu_cpu_kick_self(void);
diff --git a/monitor.c b/monitor.c
index 24e4d49d11..7573689585 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1319,7 +1319,7 @@ static void hmp_info_jit(Monitor *mon, const QDict *qdict)
 }
 
 dump_exec_info();
-dump_drift_info((FILE *)mon, monitor_fprintf);
+dump_drift_info();
 }
 
 static void hmp_info_opcount(Monitor *mon, const QDict *qdict)
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 09/36] pci: Report fatal errors with error_report(), not error_printf()

2019-04-18 Thread Markus Armbruster
Cc: "Michael S. Tsirkin" 
Cc: Marcel Apfelbaum 
Signed-off-by: Markus Armbruster 
Reviewed-by: Marcel Apfelbaum 
Message-Id: <20190417190641.26814-6-arm...@redhat.com>
---
 hw/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 6d13ef877b..1808b242dd 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -951,7 +951,7 @@ static uint16_t pci_req_id_cache_extract(PCIReqIDCache 
*cache)
 result = PCI_BUILD_BDF(bus_n, 0);
 break;
 default:
-error_printf("Invalid PCI requester ID cache type: %d\n",
+error_report("Invalid PCI requester ID cache type: %d",
  cache->type);
 exit(1);
 break;
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 34/36] monitor: Clean up how monitor_disas() funnels output to monitor

2019-04-18 Thread Markus Armbruster
INIT_DISASSEMBLE_INFO() takes an fprintf()-like callback and a FILE *
to pass to it.  monitor_disas() passes monitor_fprintf() and the
current monitor cast to FILE *.  monitor_fprintf() casts it right
back, and is otherwise identical to monitor_printf().  The
type-punning is ugly.

Pass qemu_fprintf() and NULL instead.

monitor_fprintf() is now unused; delete it.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
Message-Id: <20190417191805.28198-16-arm...@redhat.com>
[Commit message typo corrected]
---
 disas.c   |  3 ++-
 include/monitor/monitor.h |  1 -
 monitor.c | 11 ---
 3 files changed, 2 insertions(+), 13 deletions(-)

diff --git a/disas.c b/disas.c
index d9aa713a40..d15cceb863 100644
--- a/disas.c
+++ b/disas.c
@@ -3,6 +3,7 @@
 #include "qemu-common.h"
 #include "disas/bfd.h"
 #include "elf.h"
+#include "qemu/qemu-print.h"
 
 #include "cpu.h"
 #include "disas/disas.h"
@@ -609,7 +610,7 @@ void monitor_disas(Monitor *mon, CPUState *cpu,
 int count, i;
 CPUDebug s;
 
-INIT_DISASSEMBLE_INFO(s.info, (FILE *)mon, monitor_fprintf);
+INIT_DISASSEMBLE_INFO(s.info, NULL, qemu_fprintf);
 
 s.cpu = cpu;
 s.info.read_memory_func
diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index 316a168c41..86656297f1 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -31,7 +31,6 @@ int monitor_fd_param(Monitor *mon, const char *fdname, Error 
**errp);
 int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
 GCC_FMT_ATTR(2, 0);
 int monitor_printf(Monitor *mon, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
-int monitor_fprintf(FILE *stream, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
 void monitor_flush(Monitor *mon);
 int monitor_set_cpu(int cpu_index);
 int monitor_get_cpu_index(void);
diff --git a/monitor.c b/monitor.c
index ad6cec54a1..9b5f10b475 100644
--- a/monitor.c
+++ b/monitor.c
@@ -480,17 +480,6 @@ int monitor_printf(Monitor *mon, const char *fmt, ...)
 return ret;
 }
 
-int monitor_fprintf(FILE *stream, const char *fmt, ...)
-{
-int ret;
-
-va_list ap;
-va_start(ap, fmt);
-ret = monitor_vprintf((Monitor *)stream, fmt, ap);
-va_end(ap);
-return ret;
-}
-
 static void qmp_send_response(Monitor *mon, const QDict *rsp)
 {
 const QObject *data = QOBJECT(rsp);
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 27/36] memory: Clean up how mtree_info() prints

2019-04-18 Thread Markus Armbruster
mtree_info() takes an fprintf()-like callback and a FILE * to pass to
it, and so do its helper functions.  Passing around callback and
argument is rather tiresome.

Its only caller hmp_info_mtree() passes monitor_printf() cast to
fprintf_function and the current monitor cast to FILE *.

The type-punning is technically undefined behaviour, but works in
practice.  Clean up: drop the callback, and call qemu_printf()
instead.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
Message-Id: <20190417191805.28198-9-arm...@redhat.com>
---
 exec.c |  40 -
 include/exec/memory-internal.h |   3 +-
 include/exec/memory.h  |   3 +-
 memory.c   | 156 -
 monitor.c  |   3 +-
 5 files changed, 98 insertions(+), 107 deletions(-)

diff --git a/exec.c b/exec.c
index 6ab62f4eee..85d15606f1 100644
--- a/exec.c
+++ b/exec.c
@@ -35,6 +35,7 @@
 #include "qemu/timer.h"
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
+#include "qemu/qemu-print.h"
 #if defined(CONFIG_USER_ONLY)
 #include "qemu.h"
 #else /* !CONFIG_USER_ONLY */
@@ -4117,42 +4118,41 @@ void page_size_init(void)
 
 #if !defined(CONFIG_USER_ONLY)
 
-static void mtree_print_phys_entries(fprintf_function mon, void *f,
- int start, int end, int skip, int ptr)
+static void mtree_print_phys_entries(int start, int end, int skip, int ptr)
 {
 if (start == end - 1) {
-mon(f, "\t%3d  ", start);
+qemu_printf("\t%3d  ", start);
 } else {
-mon(f, "\t%3d..%-3d ", start, end - 1);
+qemu_printf("\t%3d..%-3d ", start, end - 1);
 }
-mon(f, " skip=%d ", skip);
+qemu_printf(" skip=%d ", skip);
 if (ptr == PHYS_MAP_NODE_NIL) {
-mon(f, " ptr=NIL");
+qemu_printf(" ptr=NIL");
 } else if (!skip) {
-mon(f, " ptr=#%d", ptr);
+qemu_printf(" ptr=#%d", ptr);
 } else {
-mon(f, " ptr=[%d]", ptr);
+qemu_printf(" ptr=[%d]", ptr);
 }
-mon(f, "\n");
+qemu_printf("\n");
 }
 
 #define MR_SIZE(size) (int128_nz(size) ? (hwaddr)int128_get64( \
int128_sub((size), int128_one())) : 0)
 
-void mtree_print_dispatch(fprintf_function mon, void *f,
-  AddressSpaceDispatch *d, MemoryRegion *root)
+void mtree_print_dispatch(AddressSpaceDispatch *d, MemoryRegion *root)
 {
 int i;
 
-mon(f, "  Dispatch\n");
-mon(f, "Physical sections\n");
+qemu_printf("  Dispatch\n");
+qemu_printf("Physical sections\n");
 
 for (i = 0; i < d->map.sections_nb; ++i) {
 MemoryRegionSection *s = d->map.sections + i;
 const char *names[] = { " [unassigned]", " [not dirty]",
 " [ROM]", " [watch]" };
 
-mon(f, "  #%d @" TARGET_FMT_plx ".." TARGET_FMT_plx " %s%s%s%s%s",
+qemu_printf("  #%d @" TARGET_FMT_plx ".." TARGET_FMT_plx
+" %s%s%s%s%s",
 i,
 s->offset_within_address_space,
 s->offset_within_address_space + MR_SIZE(s->mr->size),
@@ -4163,20 +4163,20 @@ void mtree_print_dispatch(fprintf_function mon, void *f,
 s->mr->is_iommu ? " [iommu]" : "");
 
 if (s->mr->alias) {
-mon(f, " alias=%s", s->mr->alias->name ?
+qemu_printf(" alias=%s", s->mr->alias->name ?
 s->mr->alias->name : "noname");
 }
-mon(f, "\n");
+qemu_printf("\n");
 }
 
-mon(f, "Nodes (%d bits per level, %d levels) ptr=[%d] skip=%d\n",
+qemu_printf("Nodes (%d bits per level, %d levels) ptr=[%d] skip=%d\n",
P_L2_BITS, P_L2_LEVELS, d->phys_map.ptr, d->phys_map.skip);
 for (i = 0; i < d->map.nodes_nb; ++i) {
 int j, jprev;
 PhysPageEntry prev;
 Node *n = d->map.nodes + i;
 
-mon(f, "  [%d]\n", i);
+qemu_printf("  [%d]\n", i);
 
 for (j = 0, jprev = 0, prev = *n[0]; j < ARRAY_SIZE(*n); ++j) {
 PhysPageEntry *pe = *n + j;
@@ -4185,14 +4185,14 @@ void mtree_print_dispatch(fprintf_function mon, void *f,
 continue;
 }
 
-mtree_print_phys_entries(mon, f, jprev, j, prev.skip, prev.ptr);
+mtree_print_phys_entries(jprev, j, prev.skip, prev.ptr);
 
 jprev = j;
 prev = *pe;
 }
 
 if (jprev != ARRAY_SIZE(*n)) {
-mtree_print_phys_entries(mon, f, jprev, j, prev.skip, prev.ptr);
+mtree_print_phys_entries(jprev, j, prev.skip, prev.ptr);
 }
 }
 }
diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h
index bb08fa4d2f..d1a9dd1ec8 100644
--- a/include/exec/memory-internal.h
+++ b/include/exec/memory-internal.h
@@ -45,8 +45,7 @@ AddressSpaceDispatch *address_space_dispatch_new(FlatView 
*fv);
 void 

[Qemu-devel] [PULL for-4.1 15/36] qemu-print: New qemu_printf(), qemu_vprintf() etc.

2019-04-18 Thread Markus Armbruster
We commonly want to print to the current monitor if we have one, else
to stdout/stderr.  For stderr, have error_printf().  For stdout, all
we have is monitor_vfprintf(), which is rather unwieldy.  We often
print to stderr just because error_printf() is easier.

New qemu_printf() and qemu_vprintf() do exactly what's needed.  The
next commits will put them to use.

Cc: Dr. David Alan Gilbert 
Signed-off-by: Markus Armbruster 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Dr. David Alan Gilbert 
Message-Id: <20190417190641.26814-12-arm...@redhat.com>
---
 MAINTAINERS   |  2 ++
 include/qemu/qemu-print.h | 19 ++
 stubs/monitor.c   |  5 +
 tests/test-util-sockets.c |  1 +
 util/Makefile.objs|  1 +
 util/qemu-print.c | 42 +++
 6 files changed, 70 insertions(+)
 create mode 100644 include/qemu/qemu-print.h
 create mode 100644 util/qemu-print.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 56139ac8ab..1aa19dc4ef 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1895,6 +1895,8 @@ F: hmp.[ch]
 F: hmp-commands*.hx
 F: include/monitor/hmp-target.h
 F: tests/test-hmp.c
+F: include/qemu/qemu-print.h
+F: util/qemu-print.c
 
 Network device backends
 M: Jason Wang 
diff --git a/include/qemu/qemu-print.h b/include/qemu/qemu-print.h
new file mode 100644
index 00..8fed32bf42
--- /dev/null
+++ b/include/qemu/qemu-print.h
@@ -0,0 +1,19 @@
+/*
+ * Print to stream or current monitor
+ *
+ * Copyright (C) 2019 Red Hat Inc.
+ *
+ * Authors:
+ *  Markus Armbruster ,
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_PRINT_H
+#define QEMU_PRINT_H
+
+int qemu_vprintf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
+int qemu_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+
+#endif
diff --git a/stubs/monitor.c b/stubs/monitor.c
index b57fe6c32f..b2ea975e40 100644
--- a/stubs/monitor.c
+++ b/stubs/monitor.c
@@ -6,6 +6,11 @@
 
 __thread Monitor *cur_mon;
 
+int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
+{
+abort();
+}
+
 int monitor_get_fd(Monitor *mon, const char *name, Error **errp)
 {
 error_setg(errp, "only QEMU supports file descriptor passing");
diff --git a/tests/test-util-sockets.c b/tests/test-util-sockets.c
index 6195a3ac36..fd1ced058c 100644
--- a/tests/test-util-sockets.c
+++ b/tests/test-util-sockets.c
@@ -70,6 +70,7 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Error 
**errp)
  * otherwise we get duplicate syms at link time.
  */
 __thread Monitor *cur_mon;
+int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) { abort(); }
 void monitor_init(Chardev *chr, int flags) {}
 
 
diff --git a/util/Makefile.objs b/util/Makefile.objs
index 835fcd69e2..9206878dec 100644
--- a/util/Makefile.objs
+++ b/util/Makefile.objs
@@ -23,6 +23,7 @@ util-obj-y += bitmap.o bitops.o hbitmap.o
 util-obj-y += fifo8.o
 util-obj-y += cacheinfo.o
 util-obj-y += error.o qemu-error.o
+util-obj-y += qemu-print.o
 util-obj-y += id.o
 util-obj-y += iov.o qemu-config.o qemu-sockets.o uri.o notify.o
 util-obj-y += qemu-option.o qemu-progress.o
diff --git a/util/qemu-print.c b/util/qemu-print.c
new file mode 100644
index 00..86f9417af8
--- /dev/null
+++ b/util/qemu-print.c
@@ -0,0 +1,42 @@
+/*
+ * Print to stream or current monitor
+ *
+ * Copyright (C) 2019 Red Hat Inc.
+ *
+ * Authors:
+ *  Markus Armbruster ,
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "monitor/monitor.h"
+#include "qemu/qemu-print.h"
+
+/*
+ * Print like vprintf().
+ * Print to current monitor if we have one, else to stdout.
+ */
+int qemu_vprintf(const char *fmt, va_list ap)
+{
+if (cur_mon) {
+return monitor_vprintf(cur_mon, fmt, ap);
+}
+return vprintf(fmt, ap);
+}
+
+/*
+ * Print like printf().
+ * Print to current monitor if we have one, else to stdout.
+ */
+int qemu_printf(const char *fmt, ...)
+{
+va_list ap;
+int ret;
+
+va_start(ap, fmt);
+ret = qemu_vprintf(fmt, ap);
+va_end(ap);
+return ret;
+}
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 18/36] char-pty: Print "char device redirected" message to stdout

2019-04-18 Thread Markus Armbruster
char_pty_open() prints a "char device redirected to PTY_NAME (label
LABEL)" message to the current monitor or else to stderr.  This is not
an error, so it shouldn't go to stderr.  Print it to stdout instead.

Why is it even printed?  No other ChardevClass::open() prints anything
on success.  It's because you need to know PTY_NAME to actually use
this char device, e.g. like e.g. "socat STDIO,cfmakeraw FILE:PTY_NAME"
to use the monitor's readline interface.  You can get PTY_NAME with
"info chardev" (a.k.a. query-chardev for QMP), but only if you already
have a monitor.

Signed-off-by: Markus Armbruster 
Message-Id: <20190417190641.26814-15-arm...@redhat.com>
Reviewed-by: Eric Blake 
---
 chardev/char-pty.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/chardev/char-pty.c b/chardev/char-pty.c
index b034332edd..04759b0ef9 100644
--- a/chardev/char-pty.c
+++ b/chardev/char-pty.c
@@ -28,6 +28,7 @@
 #include "io/channel-file.h"
 #include "qemu/sockets.h"
 #include "qemu/error-report.h"
+#include "qemu/qemu-print.h"
 
 #include "chardev/char-io.h"
 
@@ -211,8 +212,8 @@ static void char_pty_open(Chardev *chr,
 qemu_set_nonblock(master_fd);
 
 chr->filename = g_strdup_printf("pty:%s", pty_name);
-error_printf("char device redirected to %s (label %s)\n",
- pty_name, chr->label);
+qemu_printf("char device redirected to %s (label %s)\n",
+pty_name, chr->label);
 
 s = PTY_CHARDEV(chr);
 s->ioc = QIO_CHANNEL(qio_channel_file_new_fd(master_fd));
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 30/36] target/i386: Simplify how x86_cpu_dump_local_apic_state() prints

2019-04-18 Thread Markus Armbruster
x86_cpu_dump_local_apic_state() takes an fprintf()-like callback and a
FILE * to pass to it, and so do its helper functions.

Its only caller hmp_info_local_apic() passes monitor_fprintf() and the
current monitor cast to FILE *.  monitor_fprintf() casts it right
back, and is otherwise identical to monitor_printf().  The
type-punning is ugly.

Drop the callback, and call qemu_printf() instead.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
Message-Id: <20190417191805.28198-12-arm...@redhat.com>
---
 target/i386/cpu.h |  3 +-
 target/i386/helper.c  | 79 ---
 target/i386/monitor.c |  3 +-
 3 files changed, 39 insertions(+), 46 deletions(-)

diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index b39327dcb7..139fe30960 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -1924,8 +1924,7 @@ void enable_compat_apic_id_mode(void);
 #define APIC_DEFAULT_ADDRESS 0xfee0
 #define APIC_SPACE_SIZE  0x10
 
-void x86_cpu_dump_local_apic_state(CPUState *cs, FILE *f,
-   fprintf_function cpu_fprintf, int flags);
+void x86_cpu_dump_local_apic_state(CPUState *cs, int flags);
 
 /* cpu.c */
 bool cpu_is_bsp(X86CPU *cpu);
diff --git a/target/i386/helper.c b/target/i386/helper.c
index e695f8ba7a..565391a9f6 100644
--- a/target/i386/helper.c
+++ b/target/i386/helper.c
@@ -20,6 +20,7 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "qemu/qemu-print.h"
 #include "sysemu/kvm.h"
 #include "kvm_i386.h"
 #ifndef CONFIG_USER_ONLY
@@ -231,12 +232,10 @@ static inline const char *dm2str(uint32_t dm)
 return str[dm];
 }
 
-static void dump_apic_lvt(FILE *f, fprintf_function cpu_fprintf,
-  const char *name, uint32_t lvt, bool is_timer)
+static void dump_apic_lvt(const char *name, uint32_t lvt, bool is_timer)
 {
 uint32_t dm = (lvt & APIC_LVT_DELIV_MOD) >> APIC_LVT_DELIV_MOD_SHIFT;
-cpu_fprintf(f,
-"%s\t 0x%08x %s %-5s %-6s %-7s %-12s %-6s",
+qemu_printf("%s\t 0x%08x %s %-5s %-6s %-7s %-12s %-6s",
 name, lvt,
 lvt & APIC_LVT_INT_POLARITY ? "active-lo" : "active-hi",
 lvt & APIC_LVT_LEVEL_TRIGGER ? "level" : "edge",
@@ -248,9 +247,9 @@ static void dump_apic_lvt(FILE *f, fprintf_function 
cpu_fprintf,
 "tsc-deadline" : "one-shot",
 dm2str(dm));
 if (dm != APIC_DM_NMI) {
-cpu_fprintf(f, " (vec %u)\n", lvt & APIC_VECTOR_MASK);
+qemu_printf(" (vec %u)\n", lvt & APIC_VECTOR_MASK);
 } else {
-cpu_fprintf(f, "\n");
+qemu_printf("\n");
 }
 }
 
@@ -282,8 +281,7 @@ static inline void mask2str(char *str, uint32_t val, 
uint8_t size)
 
 #define MAX_LOGICAL_APIC_ID_MASK_SIZE 16
 
-static void dump_apic_icr(FILE *f, fprintf_function cpu_fprintf,
-  APICCommonState *s, CPUX86State *env)
+static void dump_apic_icr(APICCommonState *s, CPUX86State *env)
 {
 uint32_t icr = s->icr[0], icr2 = s->icr[1];
 uint8_t dest_shorthand = \
@@ -293,16 +291,16 @@ static void dump_apic_icr(FILE *f, fprintf_function 
cpu_fprintf,
 uint32_t dest_field;
 bool x2apic;
 
-cpu_fprintf(f, "ICR\t 0x%08x %s %s %s %s\n",
+qemu_printf("ICR\t 0x%08x %s %s %s %s\n",
 icr,
 logical_mod ? "logical" : "physical",
 icr & APIC_ICR_TRIGGER_MOD ? "level" : "edge",
 icr & APIC_ICR_LEVEL ? "assert" : "de-assert",
 shorthand2str(dest_shorthand));
 
-cpu_fprintf(f, "ICR2\t 0x%08x", icr2);
+qemu_printf("ICR2\t 0x%08x", icr2);
 if (dest_shorthand != 0) {
-cpu_fprintf(f, "\n");
+qemu_printf("\n");
 return;
 }
 x2apic = env->features[FEAT_1_ECX] & CPUID_EXT_X2APIC;
@@ -310,9 +308,9 @@ static void dump_apic_icr(FILE *f, fprintf_function 
cpu_fprintf,
 
 if (!logical_mod) {
 if (x2apic) {
-cpu_fprintf(f, " cpu %u (X2APIC ID)\n", dest_field);
+qemu_printf(" cpu %u (X2APIC ID)\n", dest_field);
 } else {
-cpu_fprintf(f, " cpu %u (APIC ID)\n",
+qemu_printf(" cpu %u (APIC ID)\n",
 dest_field & APIC_LOGDEST_XAPIC_ID);
 }
 return;
@@ -320,87 +318,84 @@ static void dump_apic_icr(FILE *f, fprintf_function 
cpu_fprintf,
 
 if (s->dest_mode == 0xf) { /* flat mode */
 mask2str(apic_id_str, icr2 >> APIC_ICR_DEST_SHIFT, 8);
-cpu_fprintf(f, " mask %s (APIC ID)\n", apic_id_str);
+qemu_printf(" mask %s (APIC ID)\n", apic_id_str);
 } else if (s->dest_mode == 0) { /* cluster mode */
 if (x2apic) {
 mask2str(apic_id_str, dest_field & APIC_LOGDEST_X2APIC_ID, 16);
-cpu_fprintf(f, " cluster %u mask %s (X2APIC ID)\n",
+qemu_printf(" cluster %u mask %s (X2APIC ID)\n",
 dest_field >> 

[Qemu-devel] [PULL for-4.1 19/36] monitor: Simplify how -device/device_add print help

2019-04-18 Thread Markus Armbruster
Commit a95db58f210 added monitor_vfprintf() as an error_printf()
generalized from stderr to arbitrary streams, then used it wrapped in
helper out_printf() to print -device/device_add help to stdout.  Use
qemu_printf() instead, and delete monitor_vfprintf() and out_printf().

Cc: Dr. David Alan Gilbert 
Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
Message-Id: <20190417190641.26814-16-arm...@redhat.com>
---
 include/monitor/monitor.h |  3 ---
 monitor.c | 16 
 qdev-monitor.c| 36 ++--
 3 files changed, 18 insertions(+), 37 deletions(-)

diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index e4c3717454..316a168c41 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -48,7 +48,4 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
 void monitor_fdset_dup_fd_remove(int dup_fd);
 int monitor_fdset_dup_fd_find(int dup_fd);
 
-int monitor_vfprintf(FILE *stream,
- const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
-
 #endif /* MONITOR_H */
diff --git a/monitor.c b/monitor.c
index 7b4a78d798..10be8bdb86 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4541,23 +4541,15 @@ static void monitor_readline_flush(void *opaque)
 monitor_flush(opaque);
 }
 
-/*
- * Print to current monitor if we have one, else to stream.
- */
-int monitor_vfprintf(FILE *stream, const char *fmt, va_list ap)
-{
-if (cur_mon && !monitor_cur_is_qmp()) {
-return monitor_vprintf(cur_mon, fmt, ap);
-}
-return vfprintf(stream, fmt, ap);
-}
-
 /*
  * Print to current monitor if we have one, else to stderr.
  */
 int error_vprintf(const char *fmt, va_list ap)
 {
-return monitor_vfprintf(stderr, fmt, ap);
+if (cur_mon && !monitor_cur_is_qmp()) {
+return monitor_vprintf(cur_mon, fmt, ap);
+}
+return vfprintf(stderr, fmt, ap);
 }
 
 int error_vprintf_unless_qmp(const char *fmt, va_list ap)
diff --git a/qdev-monitor.c b/qdev-monitor.c
index d4320986a2..373b9ad445 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -31,6 +31,7 @@
 #include "qemu/error-report.h"
 #include "qemu/help_option.h"
 #include "qemu/option.h"
+#include "qemu/qemu-print.h"
 #include "sysemu/block-backend.h"
 #include "migration/misc.h"
 
@@ -104,31 +105,22 @@ static bool qdev_class_has_alias(DeviceClass *dc)
 return (qdev_class_get_alias(dc) != NULL);
 }
 
-static void out_printf(const char *fmt, ...)
-{
-va_list ap;
-
-va_start(ap, fmt);
-monitor_vfprintf(stdout, fmt, ap);
-va_end(ap);
-}
-
 static void qdev_print_devinfo(DeviceClass *dc)
 {
-out_printf("name \"%s\"", object_class_get_name(OBJECT_CLASS(dc)));
+qemu_printf("name \"%s\"", object_class_get_name(OBJECT_CLASS(dc)));
 if (dc->bus_type) {
-out_printf(", bus %s", dc->bus_type);
+qemu_printf(", bus %s", dc->bus_type);
 }
 if (qdev_class_has_alias(dc)) {
-out_printf(", alias \"%s\"", qdev_class_get_alias(dc));
+qemu_printf(", alias \"%s\"", qdev_class_get_alias(dc));
 }
 if (dc->desc) {
-out_printf(", desc \"%s\"", dc->desc);
+qemu_printf(", desc \"%s\"", dc->desc);
 }
 if (!dc->user_creatable) {
-out_printf(", no-user");
+qemu_printf(", no-user");
 }
-out_printf("\n");
+qemu_printf("\n");
 }
 
 static void qdev_print_devinfos(bool show_no_user)
@@ -164,7 +156,7 @@ static void qdev_print_devinfos(bool show_no_user)
 continue;
 }
 if (!cat_printed) {
-out_printf("%s%s devices:\n", i ? "\n" : "", cat_name[i]);
+qemu_printf("%s%s devices:\n", i ? "\n" : "", cat_name[i]);
 cat_printed = true;
 }
 qdev_print_devinfo(dc);
@@ -286,20 +278,20 @@ int qdev_device_help(QemuOpts *opts)
 }
 
 if (prop_list) {
-out_printf("%s options:\n", driver);
+qemu_printf("%s options:\n", driver);
 } else {
-out_printf("There are no options for %s.\n", driver);
+qemu_printf("There are no options for %s.\n", driver);
 }
 for (prop = prop_list; prop; prop = prop->next) {
 int len;
-out_printf("  %s=<%s>%n", prop->value->name, prop->value->type, );
+qemu_printf("  %s=<%s>%n", prop->value->name, prop->value->type, );
 if (prop->value->has_description) {
 if (len < 24) {
-out_printf("%*s", 24 - len, "");
+qemu_printf("%*s", 24 - len, "");
 }
-out_printf(" - %s\n", prop->value->description);
+qemu_printf(" - %s\n", prop->value->description);
 } else {
-out_printf("\n");
+qemu_printf("\n");
 }
 }
 
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 36/36] include: Move fprintf_function to disas/

2019-04-18 Thread Markus Armbruster
The previous commits have eliminated fprintf_function outside
disassemblers, simplifying code and cleaning up the ugly type-punning
fprintf_function seems to attract.  Move fprintf_function to
include/disas/dis-asm.h to reduce the temptation to abuse it.

I considered renaming it to fprintf_ftype (reverting that part of
commit 6e2d864edf5, v0.14.0) to get us closer to binutils, but I
figure the fork is too distant to make this worthwhile.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
Message-Id: <20190417191805.28198-18-arm...@redhat.com>
---
 include/disas/dis-asm.h   |  5 +++--
 include/qemu/fprintf-fn.h | 14 --
 2 files changed, 3 insertions(+), 16 deletions(-)
 delete mode 100644 include/qemu/fprintf-fn.h

diff --git a/include/disas/dis-asm.h b/include/disas/dis-asm.h
index 41b61c85f9..9240ec32c2 100644
--- a/include/disas/dis-asm.h
+++ b/include/disas/dis-asm.h
@@ -9,8 +9,6 @@
 #ifndef DISAS_BFD_H
 #define DISAS_BFD_H
 
-#include "qemu/fprintf-fn.h"
-
 typedef void *PTR;
 typedef uint64_t bfd_vma;
 typedef int64_t bfd_signed_vma;
@@ -243,6 +241,9 @@ typedef struct symbol_cache_entry
 } udata;
 } asymbol;
 
+typedef int (*fprintf_function)(FILE *f, const char *fmt, ...)
+GCC_FMT_ATTR(2, 3);
+
 enum dis_insn_type {
   dis_noninsn, /* Not a valid instruction */
   dis_nonbranch,   /* Not a branch instruction */
diff --git a/include/qemu/fprintf-fn.h b/include/qemu/fprintf-fn.h
deleted file mode 100644
index 9068a960b3..00
--- a/include/qemu/fprintf-fn.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Typedef for fprintf-alike function pointers.
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- */
-
-#ifndef QEMU_FPRINTF_FN_H
-#define QEMU_FPRINTF_FN_H
-
-typedef int (*fprintf_function)(FILE *f, const char *fmt, ...)
-GCC_FMT_ATTR(2, 3);
-
-#endif
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 20/36] include: Include fprintf-fn.h only where needed

2019-04-18 Thread Markus Armbruster
Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
Message-Id: <20190417191805.28198-2-arm...@redhat.com>
---
 include/qemu-common.h | 2 --
 include/qemu/cutils.h | 2 --
 include/sysemu/cpus.h | 1 +
 3 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/include/qemu-common.h b/include/qemu-common.h
index a102245519..f891e05e7e 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -12,8 +12,6 @@
 #ifndef QEMU_COMMON_H
 #define QEMU_COMMON_H
 
-#include "qemu/fprintf-fn.h"
-
 #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
 
 /* Copyright string for -version arguments, About dialogs, etc */
diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index d2dad3057c..12301340a4 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -1,8 +1,6 @@
 #ifndef QEMU_CUTILS_H
 #define QEMU_CUTILS_H
 
-#include "qemu/fprintf-fn.h"
-
 /**
  * pstrcpy:
  * @buf: buffer to copy string into
diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h
index 731756d948..eea0010b53 100644
--- a/include/sysemu/cpus.h
+++ b/include/sysemu/cpus.h
@@ -1,6 +1,7 @@
 #ifndef QEMU_CPUS_H
 #define QEMU_CPUS_H
 
+#include "qemu/fprintf-fn.h"
 #include "qemu/timer.h"
 
 /* cpus.c */
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 22/36] tcg: Simplify how dump_opcount_info() prints

2019-04-18 Thread Markus Armbruster
dump_opcount_info() takes an fprintf()-like callback and a FILE * to
pass to it.

Its only caller hmp_info_opcount() passes monitor_fprintf() and the
current monitor cast to FILE *.  monitor_fprintf() casts it right
back, and is otherwise identical to monitor_printf().  The
type-punning is ugly.

Drop the callback, and call qemu_printf() instead.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
Message-Id: <20190417191805.28198-4-arm...@redhat.com>
---
 accel/tcg/translate-all.c | 4 ++--
 include/exec/cpu-all.h| 2 +-
 monitor.c | 2 +-
 tcg/tcg.c | 9 +
 tcg/tcg.h | 2 +-
 5 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index 8f593b926f..85e80a1fad 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -2333,9 +2333,9 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fprintf)
 tcg_dump_info(f, cpu_fprintf);
 }
 
-void dump_opcount_info(FILE *f, fprintf_function cpu_fprintf)
+void dump_opcount_info(void)
 {
-tcg_dump_op_count(f, cpu_fprintf);
+tcg_dump_op_count();
 }
 
 #else /* CONFIG_USER_ONLY */
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index b16c9ec513..40f5edf4dc 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -363,7 +363,7 @@ static inline bool tlb_hit(target_ulong tlb_addr, 
target_ulong addr)
 }
 
 void dump_exec_info(FILE *f, fprintf_function cpu_fprintf);
-void dump_opcount_info(FILE *f, fprintf_function cpu_fprintf);
+void dump_opcount_info(void);
 #endif /* !CONFIG_USER_ONLY */
 
 int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
diff --git a/monitor.c b/monitor.c
index a3e66b7159..30a7ffe32b 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1324,7 +1324,7 @@ static void hmp_info_jit(Monitor *mon, const QDict *qdict)
 
 static void hmp_info_opcount(Monitor *mon, const QDict *qdict)
 {
-dump_opcount_info((FILE *)mon, monitor_fprintf);
+dump_opcount_info();
 }
 #endif
 
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 9b2bf7f439..cc5f4e2a03 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -33,6 +33,7 @@
 #include "qemu/error-report.h"
 #include "qemu/cutils.h"
 #include "qemu/host-utils.h"
+#include "qemu/qemu-print.h"
 #include "qemu/timer.h"
 
 /* Note: the long term plan is to reduce the dependencies on the QEMU
@@ -3768,14 +3769,14 @@ static void tcg_profile_snapshot_table(TCGProfile *prof)
 tcg_profile_snapshot(prof, false, true);
 }
 
-void tcg_dump_op_count(FILE *f, fprintf_function cpu_fprintf)
+void tcg_dump_op_count(void)
 {
 TCGProfile prof = {};
 int i;
 
 tcg_profile_snapshot_table();
 for (i = 0; i < NB_OPS; i++) {
-cpu_fprintf(f, "%s %" PRId64 "\n", tcg_op_defs[i].name,
+qemu_printf("%s %" PRId64 "\n", tcg_op_defs[i].name,
 prof.table_op_count[i]);
 }
 }
@@ -3795,9 +3796,9 @@ int64_t tcg_cpu_exec_time(void)
 return ret;
 }
 #else
-void tcg_dump_op_count(FILE *f, fprintf_function cpu_fprintf)
+void tcg_dump_op_count(void)
 {
-cpu_fprintf(f, "[TCG profiler not compiled]\n");
+qemu_printf("[TCG profiler not compiled]\n");
 }
 
 int64_t tcg_cpu_exec_time(void)
diff --git a/tcg/tcg.h b/tcg/tcg.h
index 32b7cf3489..9f2b03f119 100644
--- a/tcg/tcg.h
+++ b/tcg/tcg.h
@@ -1018,7 +1018,7 @@ int tcg_check_temp_count(void);
 
 int64_t tcg_cpu_exec_time(void);
 void tcg_dump_info(FILE *f, fprintf_function cpu_fprintf);
-void tcg_dump_op_count(FILE *f, fprintf_function cpu_fprintf);
+void tcg_dump_op_count(void);
 
 #define TCG_CT_ALIAS  0x80
 #define TCG_CT_IALIAS 0x40
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 11/36] vfio: Report warnings with warn_report(), not error_printf()

2019-04-18 Thread Markus Armbruster
Cc: Alex Williamson 
Signed-off-by: Markus Armbruster 
Message-Id: <20190417190641.26814-8-arm...@redhat.com>
Acked-by: Alex Williamson 
---
 hw/vfio/pci.c | 19 +--
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 504019c458..0142819ea6 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -947,8 +947,10 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
 if (vdev->pdev.romfile || !vdev->pdev.rom_bar) {
 /* Since pci handles romfile, just print a message and return */
 if (vfio_blacklist_opt_rom(vdev) && vdev->pdev.romfile) {
-error_printf("Warning : Device at %s is known to cause system 
instability issues during option rom execution. Proceeding anyway since user 
specified romfile\n",
- vdev->vbasedev.name);
+warn_report("Device at %s is known to cause system instability"
+" issues during option rom execution",
+vdev->vbasedev.name);
+error_printf("Proceeding anyway since user specified romfile\n");
 }
 return;
 }
@@ -973,11 +975,16 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
 
 if (vfio_blacklist_opt_rom(vdev)) {
 if (dev->opts && qemu_opt_get(dev->opts, "rombar")) {
-error_printf("Warning : Device at %s is known to cause system 
instability issues during option rom execution. Proceeding anyway since user 
specified non zero value for rombar\n",
- vdev->vbasedev.name);
+warn_report("Device at %s is known to cause system instability"
+" issues during option rom execution",
+vdev->vbasedev.name);
+error_printf("Proceeding anyway since user specified"
+ " non zero value for rombar\n");
 } else {
-error_printf("Warning : Rom loading for device at %s has been 
disabled due to system instability issues. Specify rombar=1 or romfile to 
force\n",
- vdev->vbasedev.name);
+warn_report("Rom loading for device at %s has been disabled"
+" due to system instability issues",
+vdev->vbasedev.name);
+error_printf("Specify rombar=1 or romfile to force\n");
 return;
 }
 }
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 32/36] qemu-print: New qemu_fprintf(), qemu_vfprintf()

2019-04-18 Thread Markus Armbruster
Code that doesn't want to know about current monitor vs. stdout
vs. stderr takes an fprintf_function callback and a FILE * argument to
pass to it.  Actual arguments are either fprintf() and stdout or
stderr, or monitor_fprintf() and the current monitor cast to FILE *.
monitor_fprintf() casts it right back, and is otherwise identical to
monitor_printf().  The type-punning is ugly.

New qemu_fprintf() and qemu_vprintf() address this need without type
punning: they are like fprintf() and vfprintf(), except they print to
the current monitor when passed a null FILE *.  The next commits will
put them to use.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
Message-Id: <20190417191805.28198-14-arm...@redhat.com>
---
 include/qemu/qemu-print.h |  4 
 util/qemu-print.c | 27 +++
 2 files changed, 31 insertions(+)

diff --git a/include/qemu/qemu-print.h b/include/qemu/qemu-print.h
index 8fed32bf42..40b596262f 100644
--- a/include/qemu/qemu-print.h
+++ b/include/qemu/qemu-print.h
@@ -16,4 +16,8 @@
 int qemu_vprintf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
 int qemu_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 
+int qemu_vfprintf(FILE *stream, const char *fmt, va_list ap)
+GCC_FMT_ATTR(2, 0);
+int qemu_fprintf(FILE *stream, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
+
 #endif
diff --git a/util/qemu-print.c b/util/qemu-print.c
index 86f9417af8..e79d6b8396 100644
--- a/util/qemu-print.c
+++ b/util/qemu-print.c
@@ -40,3 +40,30 @@ int qemu_printf(const char *fmt, ...)
 va_end(ap);
 return ret;
 }
+
+/*
+ * Print like vfprintf()
+ * Print to @stream if non-null, else to current monitor.
+ */
+int qemu_vfprintf(FILE *stream, const char *fmt, va_list ap)
+{
+if (!stream) {
+return monitor_vprintf(cur_mon, fmt, ap);
+}
+return vfprintf(stream, fmt, ap);
+}
+
+/*
+ * Print like fprintf().
+ * Print to @stream if non-null, else to current monitor.
+ */
+int qemu_fprintf(FILE *stream, const char *fmt, ...)
+{
+va_list ap;
+int ret;
+
+va_start(ap, fmt);
+ret = qemu_vfprintf(stream, fmt, ap);
+va_end(ap);
+return ret;
+}
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 07/36] loader-fit: Wean off error_printf()

2019-04-18 Thread Markus Armbruster
load_fit() reports errors with error_printf() instead of
error_report().  Worse, it even reports errors it actually recovers
from, in fit_cfg_compatible() and fit_load_fdt().  Messed up in
initial commit 51b58561c1d.

Convert the helper functions for load_fit() to Error.  Make sure each
failure path sets an error.

Fix fit_cfg_compatible() and fit_load_fdt() not to report errors they
actually recover from.

Convert load_fit() to error_report().

Cc: Paul Burton 
Cc: Aleksandar Rikalo 
Signed-off-by: Markus Armbruster 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20190417190641.26814-4-arm...@redhat.com>
---
 hw/core/loader-fit.c | 62 +---
 1 file changed, 36 insertions(+), 26 deletions(-)

diff --git a/hw/core/loader-fit.c b/hw/core/loader-fit.c
index 447f60857d..f27b6af942 100644
--- a/hw/core/loader-fit.c
+++ b/hw/core/loader-fit.c
@@ -18,6 +18,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qapi/error.h"
 #include "qemu/units.h"
 #include "exec/memory.h"
 #include "hw/loader.h"
@@ -33,7 +34,7 @@
 #define FIT_LOADER_MAX_PATH (128)
 
 static const void *fit_load_image_alloc(const void *itb, const char *name,
-int *poff, size_t *psz)
+int *poff, size_t *psz, Error **errp)
 {
 const void *data;
 const char *comp;
@@ -46,6 +47,7 @@ static const void *fit_load_image_alloc(const void *itb, 
const char *name,
 
 off = fdt_path_offset(itb, path);
 if (off < 0) {
+error_setg(errp, "can't find node %s", path);
 return NULL;
 }
 if (poff) {
@@ -54,6 +56,7 @@ static const void *fit_load_image_alloc(const void *itb, 
const char *name,
 
 data = fdt_getprop(itb, off, "data", );
 if (!data) {
+error_setg(errp, "can't get %s/data", path);
 return NULL;
 }
 
@@ -73,7 +76,7 @@ static const void *fit_load_image_alloc(const void *itb, 
const char *name,
 
 uncomp_len = gunzip(uncomp_data, uncomp_len, (void *) data, sz);
 if (uncomp_len < 0) {
-error_printf("unable to decompress %s image\n", name);
+error_setg(errp, "unable to decompress %s image", name);
 g_free(uncomp_data);
 return NULL;
 }
@@ -85,18 +88,19 @@ static const void *fit_load_image_alloc(const void *itb, 
const char *name,
 return data;
 }
 
-error_printf("unknown compression '%s'\n", comp);
+error_setg(errp, "unknown compression '%s'", comp);
 return NULL;
 }
 
 static int fit_image_addr(const void *itb, int img, const char *name,
-  hwaddr *addr)
+  hwaddr *addr, Error **errp)
 {
 const void *prop;
 int len;
 
 prop = fdt_getprop(itb, img, name, );
 if (!prop) {
+error_setg(errp, "can't find %s address", name);
 return -ENOENT;
 }
 
@@ -108,13 +112,14 @@ static int fit_image_addr(const void *itb, int img, const 
char *name,
 *addr = fdt64_to_cpu(*(fdt64_t *)prop);
 return 0;
 default:
-error_printf("invalid %s address length %d\n", name, len);
+error_setg(errp, "invalid %s address length %d", name, len);
 return -EINVAL;
 }
 }
 
 static int fit_load_kernel(const struct fit_loader *ldr, const void *itb,
-   int cfg, void *opaque, hwaddr *pend)
+   int cfg, void *opaque, hwaddr *pend,
+   Error **errp)
 {
 const char *name;
 const void *data;
@@ -126,26 +131,26 @@ static int fit_load_kernel(const struct fit_loader *ldr, 
const void *itb,
 
 name = fdt_getprop(itb, cfg, "kernel", NULL);
 if (!name) {
-error_printf("no kernel specified by FIT configuration\n");
+error_setg(errp, "no kernel specified by FIT configuration");
 return -EINVAL;
 }
 
-load_data = data = fit_load_image_alloc(itb, name, _off, );
+load_data = data = fit_load_image_alloc(itb, name, _off, , errp);
 if (!data) {
-error_printf("unable to load kernel image from FIT\n");
+error_prepend(errp, "unable to load kernel image from FIT: ");
 return -EINVAL;
 }
 
-err = fit_image_addr(itb, img_off, "load", _addr);
+err = fit_image_addr(itb, img_off, "load", _addr, errp);
 if (err) {
-error_printf("unable to read kernel load address from FIT\n");
+error_prepend(errp, "unable to read kernel load address from FIT: ");
 ret = err;
 goto out;
 }
 
-err = fit_image_addr(itb, img_off, "entry", _addr);
+err = fit_image_addr(itb, img_off, "entry", _addr, errp);
 if (err) {
-error_printf("unable to read kernel entry address from FIT\n");
+error_prepend(errp, "unable to read kernel entry address from FIT: ");
 ret = err;
 goto out;
 }
@@ -172,7 +177,7 @@ out:
 
 static int fit_load_fdt(const struct fit_loader *ldr, const void *itb,

[Qemu-devel] [PULL for-4.1 14/36] monitor error: Make printf()-like functions return a value

2019-04-18 Thread Markus Armbruster
printf() & friends return the number of characters written on success,
negative value on error.

monitor_printf(), monitor_vfprintf(), monitor_vprintf(),
error_printf(), error_printf_unless_qmp(), error_vprintf(), and
error_vprintf_unless_qmp() return void.  Some of them carry a TODO
comment asking for int instead.

Improve them to return int like printf() does.

This makes our use of monitor_printf() as fprintf_function slightly
less dirty: the function cast no longer adds a return value that isn't
there.  It still changes a parameter's pointer type.  That will be
addressed in a future commit.

monitor_vfprintf() always returns zero.  Improve it to return the
proper value.

Cc: Dr. David Alan Gilbert 
Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
Message-Id: <20190417190641.26814-11-arm...@redhat.com>
---
 include/monitor/monitor.h   |  8 ++---
 include/qemu/error-report.h |  8 ++---
 monitor.c   | 61 -
 stubs/error-printf.c| 13 +---
 util/qemu-error.c   | 12 +---
 5 files changed, 57 insertions(+), 45 deletions(-)

diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index c1b40a9cac..e4c3717454 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -28,9 +28,9 @@ void monitor_resume(Monitor *mon);
 int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp);
 int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp);
 
-void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
+int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
 GCC_FMT_ATTR(2, 0);
-void monitor_printf(Monitor *mon, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
+int monitor_printf(Monitor *mon, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
 int monitor_fprintf(FILE *stream, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
 void monitor_flush(Monitor *mon);
 int monitor_set_cpu(int cpu_index);
@@ -48,7 +48,7 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
 void monitor_fdset_dup_fd_remove(int dup_fd);
 int monitor_fdset_dup_fd_find(int dup_fd);
 
-void monitor_vfprintf(FILE *stream,
-  const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
+int monitor_vfprintf(FILE *stream,
+ const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
 
 #endif /* MONITOR_H */
diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index ce43c02314..00d069b20f 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -30,10 +30,10 @@ void loc_set_none(void);
 void loc_set_cmdline(char **argv, int idx, int cnt);
 void loc_set_file(const char *fname, int lno);
 
-void error_vprintf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
-void error_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
-void error_vprintf_unless_qmp(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
-void error_printf_unless_qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+int error_vprintf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
+int error_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+int error_vprintf_unless_qmp(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
+int error_printf_unless_qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 
 void error_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
 void warn_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
diff --git a/monitor.c b/monitor.c
index 4807bbe811..7b4a78d798 100644
--- a/monitor.c
+++ b/monitor.c
@@ -430,15 +430,14 @@ void monitor_flush(Monitor *mon)
 }
 
 /* flush at every end of line */
-static void monitor_puts(Monitor *mon, const char *str)
+static int monitor_puts(Monitor *mon, const char *str)
 {
+int i;
 char c;
 
 qemu_mutex_lock(>mon_lock);
-for(;;) {
-c = *str++;
-if (c == '\0')
-break;
+for (i = 0; str[i]; i++) {
+c = str[i];
 if (c == '\n') {
 qstring_append_chr(mon->outbuf, '\r');
 }
@@ -448,39 +447,48 @@ static void monitor_puts(Monitor *mon, const char *str)
 }
 }
 qemu_mutex_unlock(>mon_lock);
+
+return i;
 }
 
-void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
+int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
 {
 char *buf;
+int n;
 
 if (!mon)
-return;
+return -1;
 
 if (monitor_is_qmp(mon)) {
-return;
+return -1;
 }
 
 buf = g_strdup_vprintf(fmt, ap);
-monitor_puts(mon, buf);
+n = monitor_puts(mon, buf);
 g_free(buf);
+return n;
 }
 
-void monitor_printf(Monitor *mon, const char *fmt, ...)
+int monitor_printf(Monitor *mon, const char *fmt, ...)
 {
+int ret;
+
 va_list ap;
 va_start(ap, fmt);
-monitor_vprintf(mon, fmt, ap);
+ret = monitor_vprintf(mon, fmt, ap);
 va_end(ap);
+return ret;
 }
 
 int monitor_fprintf(FILE *stream, const char *fmt, ...)
 {
+int ret;
+
 va_list ap;
 va_start(ap, fmt);
-

[Qemu-devel] [PULL for-4.1 21/36] trace: Simplify how st_print_trace_file_status() prints

2019-04-18 Thread Markus Armbruster
st_print_trace_file_status() takes an fprintf()-like callback and a
FILE * to pass to it.

Its only caller hmp_trace_file() passes monitor_fprintf() and the
current monitor cast to FILE *.  monitor_fprintf() casts it right
back, and is otherwise identical to monitor_printf().  The
type-punning is ugly.

Drop the callback, and call qemu_printf() instead.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
Message-Id: <20190417191805.28198-3-arm...@redhat.com>
---
 monitor.c  | 2 +-
 trace/simple.c | 7 ---
 trace/simple.h | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/monitor.c b/monitor.c
index 10be8bdb86..a3e66b7159 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1056,7 +1056,7 @@ static void hmp_trace_file(Monitor *mon, const QDict 
*qdict)
 const char *arg = qdict_get_try_str(qdict, "arg");
 
 if (!op) {
-st_print_trace_file_status((FILE *)mon, _fprintf);
+st_print_trace_file_status();
 } else if (!strcmp(op, "on")) {
 st_set_trace_file_enabled(true);
 } else if (!strcmp(op, "off")) {
diff --git a/trace/simple.c b/trace/simple.c
index ac904eca91..fc7106ec49 100644
--- a/trace/simple.c
+++ b/trace/simple.c
@@ -16,6 +16,7 @@
 #include "trace/control.h"
 #include "trace/simple.h"
 #include "qemu/error-report.h"
+#include "qemu/qemu-print.h"
 
 /** Trace file header event ID, picked to avoid conflict with real event IDs */
 #define HEADER_EVENT_ID (~(uint64_t)0)
@@ -363,10 +364,10 @@ void st_set_trace_file(const char *file)
 st_set_trace_file_enabled(true);
 }
 
-void st_print_trace_file_status(FILE *stream, int (*stream_printf)(FILE 
*stream, const char *fmt, ...))
+void st_print_trace_file_status(void)
 {
-stream_printf(stream, "Trace file \"%s\" %s.\n",
-  trace_file_name, trace_fp ? "on" : "off");
+qemu_printf("Trace file \"%s\" %s.\n",
+trace_file_name, trace_fp ? "on" : "off");
 }
 
 void st_flush_trace_buffer(void)
diff --git a/trace/simple.h b/trace/simple.h
index 9931808c05..5771a0634f 100644
--- a/trace/simple.h
+++ b/trace/simple.h
@@ -11,7 +11,7 @@
 #ifndef TRACE_SIMPLE_H
 #define TRACE_SIMPLE_H
 
-void st_print_trace_file_status(FILE *stream, fprintf_function stream_printf);
+void st_print_trace_file_status(void);
 void st_set_trace_file_enabled(bool enable);
 void st_set_trace_file(const char *file);
 bool st_init(void);
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 12/36] s390x/kvm: Report warnings with warn_report(), not error_printf()

2019-04-18 Thread Markus Armbruster
kvm_s390_mem_op() can fail in two ways: when !cap_mem_op, it returns
-ENOSYS, and when kvm_vcpu_ioctl() fails, it returns -errno set by
ioctl().  Its caller s390_cpu_virt_mem_rw() recovers from both
failures.

kvm_s390_mem_op() prints "KVM_S390_MEM_OP failed" with error_printf()
in the latter failure mode.  Since this is obviously a warning, use
warn_report().

Perhaps the reporting should be left to the caller.  It could warn on
failure other than -ENOSYS.

Cc: Thomas Huth 
Cc: qemu-s3...@nongnu.org
Signed-off-by: Markus Armbruster 
Reviewed-by: Thomas Huth 
Reviewed-by: Cornelia Huck 
Message-Id: <20190417190641.26814-9-arm...@redhat.com>
---
 target/s390x/kvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
index 19530fb94e..2c6e35b5aa 100644
--- a/target/s390x/kvm.c
+++ b/target/s390x/kvm.c
@@ -782,7 +782,7 @@ int kvm_s390_mem_op(S390CPU *cpu, vaddr addr, uint8_t ar, 
void *hostbuf,
 
 ret = kvm_vcpu_ioctl(CPU(cpu), KVM_S390_MEM_OP, _op);
 if (ret < 0) {
-error_printf("KVM_S390_MEM_OP failed: %s\n", strerror(-ret));
+warn_report("KVM_S390_MEM_OP failed: %s", strerror(-ret));
 }
 return ret;
 }
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 03/36] error: Fix error_report_err(), warn_report_err() hint printing

2019-04-18 Thread Markus Armbruster
Before the from qerror_report() to error_setg(), hints looked like
this:

qerror_report(QERR_MACRO, ... arguments ...);
error_printf_unless_qmp(... hint ...);

error_printf_unless_qmp() made perfect sense: it printed exactly when
qerror_report() did.

After the conversion to error_setg():

error_setg(errp, QERR_MACRO, ... arguments ...);
error_printf_unless_qmp(... hint ...);

The "unless QMP part" still made some sense; in QMP context, the
caller generally uses the error as QMP response instead of printing
it.

However, everything else is wrong.  If the caller handles the error,
the hint gets printed anyway (unless QMP).  If the caller reports the
error, the hint gets printed *before* the report (unless QMP) or not
at all (if QMP).

Commit 50b7b000c91 fixed this by making hints a member of Error.  It
kept printing hints with error_printf_unless_qmp():

 void error_report_err(Error *err)
 {
 error_report("%s", error_get_pretty(err));
+if (err->hint) {
+error_printf_unless_qmp("%s\n", err->hint->str);
+}
 error_free(err);
 }

This is wrong.  We should (and now can) print the hint exactly when we
print the error.

The mistake has since been copied to warn_report_err() in commit
e43ead1d0b9.

Fix both to use error_printf().

Reported-by: Vladimir Sementsov-Ogievskiy 
Cc: Eric Blake 
Signed-off-by: Markus Armbruster 
Message-Id: <20190416153850.5186-1-arm...@redhat.com>
Reviewed-by: Eric Blake 
Reviewed-by: Vladimir Sementsov-Ogievskiy 
[Commit message tweaked]
---
 util/error.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/util/error.c b/util/error.c
index 934a78e1b1..712b4d4b5d 100644
--- a/util/error.c
+++ b/util/error.c
@@ -223,7 +223,7 @@ void error_report_err(Error *err)
 {
 error_report("%s", error_get_pretty(err));
 if (err->hint) {
-error_printf_unless_qmp("%s", err->hint->str);
+error_printf("%s", err->hint->str);
 }
 error_free(err);
 }
@@ -232,7 +232,7 @@ void warn_report_err(Error *err)
 {
 warn_report("%s", error_get_pretty(err));
 if (err->hint) {
-error_printf_unless_qmp("%s", err->hint->str);
+error_printf("%s", err->hint->str);
 }
 error_free(err);
 }
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 08/36] mips/boston: Report errors with error_report(), not error_printf()

2019-04-18 Thread Markus Armbruster
Cc: Paul Burton 
Cc: Aleksandar Rikalo 
Signed-off-by: Markus Armbruster 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20190417190641.26814-5-arm...@redhat.com>
---
 hw/mips/boston.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/mips/boston.c b/hw/mips/boston.c
index e5bab3cadc..a8b29f62f5 100644
--- a/hw/mips/boston.c
+++ b/hw/mips/boston.c
@@ -528,21 +528,21 @@ static void boston_mach_init(MachineState *machine)
 fw_size = load_image_targphys(machine->firmware,
   0x1fc0, 4 * MiB);
 if (fw_size == -1) {
-error_printf("unable to load firmware image '%s'\n",
+error_report("unable to load firmware image '%s'",
   machine->firmware);
 exit(1);
 }
 } else if (machine->kernel_filename) {
 fit_err = load_fit(_fit_loader, machine->kernel_filename, s);
 if (fit_err) {
-error_printf("unable to load FIT image\n");
+error_report("unable to load FIT image");
 exit(1);
 }
 
 gen_firmware(memory_region_get_ram_ptr(flash) + 0x7c0,
  s->kernel_entry, s->fdt_base, is_64b);
 } else if (!qtest_enabled()) {
-error_printf("Please provide either a -kernel or -bios argument\n");
+error_report("Please provide either a -kernel or -bios argument");
 exit(1);
 }
 }
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 01/36] qemu-io: Use error_[gs]et_progname()

2019-04-18 Thread Markus Armbruster
From: Christophe Fergeau 

qemu-io reimplements itself what
error_get_progname()/error_set_progname() already does.
This commit switches it to use this API from qemu-error.h

Signed-off-by: Christophe Fergeau 
Reviewed-by: Eric Blake 
Reviewed-by: Stefan Hajnoczi 
Message-Id: <20190131164614.19209-2-cferg...@redhat.com>
Reviewed-by: Markus Armbruster 
Signed-off-by: Markus Armbruster 
---
 qemu-io.c | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/qemu-io.c b/qemu-io.c
index 6df7731af4..2c52ac0ade 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -34,8 +34,6 @@
 
 #define CMD_NOFILE_OK   0x01
 
-static char *progname;
-
 static BlockBackend *qemuio_blk;
 static bool quit_qemu_io;
 
@@ -312,7 +310,7 @@ static char *get_prompt(void)
 static char prompt[FILENAME_MAX + 2 /*"> "*/ + 1 /*"\0"*/ ];
 
 if (!prompt[0]) {
-snprintf(prompt, sizeof(prompt), "%s> ", progname);
+snprintf(prompt, sizeof(prompt), "%s> ", error_get_progname());
 }
 
 return prompt;
@@ -525,7 +523,7 @@ int main(int argc, char **argv)
 #endif
 
 module_call_init(MODULE_INIT_TRACE);
-progname = g_path_get_basename(argv[0]);
+error_set_progname(argv[0]);
 qemu_init_exec_dir(argv[0]);
 
 qcrypto_init(_fatal);
@@ -580,10 +578,10 @@ int main(int argc, char **argv)
 break;
 case 'V':
 printf("%s version " QEMU_FULL_VERSION "\n"
-   QEMU_COPYRIGHT "\n", progname);
+   QEMU_COPYRIGHT "\n", error_get_progname());
 exit(0);
 case 'h':
-usage(progname);
+usage(error_get_progname());
 exit(0);
 case 'U':
 force_share = true;
@@ -600,13 +598,13 @@ int main(int argc, char **argv)
 imageOpts = true;
 break;
 default:
-usage(progname);
+usage(error_get_progname());
 exit(1);
 }
 }
 
 if ((argc - optind) > 1) {
-usage(progname);
+usage(error_get_progname());
 exit(1);
 }
 
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 02/36] log: Make glib logging go through QEMU

2019-04-18 Thread Markus Armbruster
From: Christophe Fergeau 

This commit adds a error_init() helper which calls
g_log_set_default_handler() so that glib logs (g_log, g_warning, ...)
are handled similarly to other QEMU logs. This means they will get a
timestamp if timestamps are enabled, and they will go through the
HMP monitor if one is configured.

This commit also adds a call to error_init() to the binaries
installed by QEMU. Since error_init() also calls error_set_progname(),
this means that *-linux-user, *-bsd-user and qemu-pr-helper messages
output with error_report, info_report, ... will slightly change: they
will be prefixed by the binary name.

glib debug messages are enabled through G_MESSAGES_DEBUG similarly to
the glib default log handler.

At the moment, this change will mostly impact SPICE logging if your
spice version is >= 0.14.1. With older spice versions, this is not going
to work as expected, but will not have any ill effect, so this call is
not conditional on the SPICE version.

Signed-off-by: Christophe Fergeau 
Reviewed-by: Stefan Hajnoczi 
Message-Id: <20190131164614.19209-3-cferg...@redhat.com>
Reviewed-by: Markus Armbruster 
Signed-off-by: Markus Armbruster 
---
 bsd-user/main.c |  2 ++
 include/qemu/error-report.h |  3 +-
 linux-user/main.c   |  2 ++
 qemu-img.c  |  2 +-
 qemu-io.c   |  2 +-
 qemu-nbd.c  |  2 +-
 scsi/qemu-pr-helper.c   |  1 +
 util/qemu-error.c   | 55 -
 vl.c|  2 +-
 9 files changed, 65 insertions(+), 6 deletions(-)

diff --git a/bsd-user/main.c b/bsd-user/main.c
index 0d3156974c..8fd8ae4127 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -24,6 +24,7 @@
 #include "qapi/error.h"
 #include "qemu.h"
 #include "qemu/config-file.h"
+#include "qemu/error-report.h"
 #include "qemu/path.h"
 #include "qemu/help_option.h"
 #include "cpu.h"
@@ -743,6 +744,7 @@ int main(int argc, char **argv)
 if (argc <= 1)
 usage();
 
+error_init(argv[0]);
 module_call_init(MODULE_INIT_TRACE);
 qemu_init_cpu_list();
 module_call_init(MODULE_INIT_QOM);
diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index 0a8d9cc9ea..ce43c02314 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -34,7 +34,6 @@ void error_vprintf(const char *fmt, va_list ap) 
GCC_FMT_ATTR(1, 0);
 void error_printf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 void error_vprintf_unless_qmp(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
 void error_printf_unless_qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
-void error_set_progname(const char *argv0);
 
 void error_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
 void warn_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
@@ -49,6 +48,8 @@ bool error_report_once_cond(bool *printed, const char *fmt, 
...)
 bool warn_report_once_cond(bool *printed, const char *fmt, ...)
 GCC_FMT_ATTR(2, 3);
 
+void error_init(const char *argv0);
+
 /*
  * Similar to error_report(), except it prints the message just once.
  * Return true when it prints, false otherwise.
diff --git a/linux-user/main.c b/linux-user/main.c
index a0aba9cb1e..f9efe9ff6e 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -27,6 +27,7 @@
 #include "qemu/path.h"
 #include "qemu/config-file.h"
 #include "qemu/cutils.h"
+#include "qemu/error-report.h"
 #include "qemu/help_option.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
@@ -600,6 +601,7 @@ int main(int argc, char **argv, char **envp)
 int ret;
 int execfd;
 
+error_init(argv[0]);
 module_call_init(MODULE_INIT_TRACE);
 qemu_init_cpu_list();
 module_call_init(MODULE_INIT_QOM);
diff --git a/qemu-img.c b/qemu-img.c
index aa6f81f1ea..8c7b2437f0 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -4923,8 +4923,8 @@ int main(int argc, char **argv)
 signal(SIGPIPE, SIG_IGN);
 #endif
 
+error_init(argv[0]);
 module_call_init(MODULE_INIT_TRACE);
-error_set_progname(argv[0]);
 qemu_init_exec_dir(argv[0]);
 
 if (qemu_init_main_loop(_error)) {
diff --git a/qemu-io.c b/qemu-io.c
index 2c52ac0ade..8d5d5911cb 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -522,8 +522,8 @@ int main(int argc, char **argv)
 signal(SIGPIPE, SIG_IGN);
 #endif
 
+error_init(argv[0]);
 module_call_init(MODULE_INIT_TRACE);
-error_set_progname(argv[0]);
 qemu_init_exec_dir(argv[0]);
 
 qcrypto_init(_fatal);
diff --git a/qemu-nbd.c b/qemu-nbd.c
index 941ba729c2..dca9e72cee 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -690,8 +690,8 @@ int main(int argc, char **argv)
 signal(SIGPIPE, SIG_IGN);
 #endif
 
+error_init(argv[0]);
 module_call_init(MODULE_INIT_TRACE);
-error_set_progname(argv[0]);
 qcrypto_init(_fatal);
 
 module_call_init(MODULE_INIT_QOM);
diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c
index e7af637232..2541fbbd1b 100644
--- a/scsi/qemu-pr-helper.c
+++ b/scsi/qemu-pr-helper.c
@@ -895,6 +895,7 @@ 

[Qemu-devel] [PULL for-4.1 04/36] util/error: do not free error on error_abort

2019-04-18 Thread Markus Armbruster
From: Vladimir Sementsov-Ogievskiy 

It would be nice to have Error object not freed away when debugging a
coredump.

Signed-off-by: Vladimir Sementsov-Ogievskiy 
Message-Id: <20190415142519.73060-1-vsement...@virtuozzo.com>
[error_printf_unless_qmp() replaced by error_printf()]
Reviewed-by: Markus Armbruster 
Signed-off-by: Markus Armbruster 
---
 util/error.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/util/error.c b/util/error.c
index 712b4d4b5d..ea6d1a3d7e 100644
--- a/util/error.c
+++ b/util/error.c
@@ -34,7 +34,10 @@ static void error_handle_fatal(Error **errp, Error *err)
 if (errp == _abort) {
 fprintf(stderr, "Unexpected error in %s() at %s:%d:\n",
 err->func, err->src, err->line);
-error_report_err(err);
+error_report("%s", error_get_pretty(err));
+if (err->hint) {
+error_printf("%s", err->hint->str);
+}
 abort();
 }
 if (errp == _fatal) {
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 13/36] vl: Make -machine $TYPE, help and -accel help print to stdout

2019-04-18 Thread Markus Armbruster
Command line help help explicitly requested by the user should be
printed to stdout, not stderr.  We do elsewhere.  Adjust -machine
$TYPE,help and -accel help to match: use printf() instead of
error_printf().

Cc: Marcel Apfelbaum 
Signed-off-by: Markus Armbruster 
Reviewed-by: Marcel Apfelbaum 
Message-Id: <20190417190641.26814-10-arm...@redhat.com>
---
 vl.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/vl.c b/vl.c
index 9877972d97..190c773176 100644
--- a/vl.c
+++ b/vl.c
@@ -1556,12 +1556,12 @@ static int machine_help_func(QemuOpts *opts, 
MachineState *machine)
 continue;
 }
 
-error_printf("%s.%s=%s", MACHINE_GET_CLASS(machine)->name,
- prop->name, prop->type);
+printf("%s.%s=%s", MACHINE_GET_CLASS(machine)->name,
+   prop->name, prop->type);
 if (prop->description) {
-error_printf(" (%s)\n", prop->description);
+printf(" (%s)\n", prop->description);
 } else {
-error_printf("\n");
+printf("\n");
 }
 }
 
@@ -3643,7 +3643,7 @@ int main(int argc, char **argv, char **envp)
  optarg, true);
 optarg = qemu_opt_get(accel_opts, "accel");
 if (!optarg || is_help_option(optarg)) {
-error_printf("Possible accelerators: kvm, xen, hax, 
tcg\n");
+printf("Possible accelerators: kvm, xen, hax, tcg\n");
 exit(0);
 }
 opts = qemu_opts_create(qemu_find_opts("machine"), NULL,
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 00/36] Error reporting & monitor patches for 2019-04-18

2019-04-18 Thread Markus Armbruster
Early pull request because I'll be on vacation when 4.1 opens.  Hope
that's okay.

The following changes since commit eeba63fc7fface36f438bcbc0d3b02e7dcb59983:

  Update version for v4.0.0-rc4 release (2019-04-16 21:53:00 +0100)

are available in the Git repository at:

  git://repo.or.cz/qemu/armbru.git tags/pull-error-monitor-2019-04-18

for you to fetch changes up to ede9a8a656c992deecce45f8175985dd81cc6be9:

  include: Move fprintf_function to disas/ (2019-04-18 22:18:59 +0200)


Error reporting & monitor patches for 2019-04-18


Christophe Fergeau (2):
  qemu-io: Use error_[gs]et_progname()
  log: Make glib logging go through QEMU

Markus Armbruster (33):
  error: Fix error_report_err(), warn_report_err() hint printing
  qemu-img: Use error_vreport() in error_exit()
  block/ssh: Do not report read/write/flush errors to the user
  loader-fit: Wean off error_printf()
  mips/boston: Report errors with error_report(), not error_printf()
  pci: Report fatal errors with error_report(), not error_printf()
  hpet: Report warnings with warn_report(), not error_printf()
  vfio: Report warnings with warn_report(), not error_printf()
  s390x/kvm: Report warnings with warn_report(), not error_printf()
  vl: Make -machine $TYPE,help and -accel help print to stdout
  monitor error: Make printf()-like functions return a value
  qemu-print: New qemu_printf(), qemu_vprintf() etc.
  blockdev: Make -drive format=help print to stdout
  char: Make -chardev help print to stdout
  char-pty: Print "char device redirected" message to stdout
  monitor: Simplify how -device/device_add print help
  include: Include fprintf-fn.h only where needed
  trace: Simplify how st_print_trace_file_status() prints
  tcg: Simplify how dump_opcount_info() prints
  tcg: Simplify how dump_exec_info() prints
  tcg: Simplify how dump_drift_info() prints
  qsp: Simplify how qsp_report() prints
  block/qapi: Clean up how we print to monitor or stdout
  memory: Clean up how mtree_info() prints
  target: Simplify how the TARGET_cpu_list() print
  target: Clean up how the dump_mmu() print
  target/i386: Simplify how x86_cpu_dump_local_apic_state() prints
  qom/cpu: Simplify how CPUClass::dump_statistics() prints
  qemu-print: New qemu_fprintf(), qemu_vfprintf()
  qom/cpu: Simplify how CPUClass:cpu_dump_state() prints
  monitor: Clean up how monitor_disas() funnels output to monitor
  disas: Rename include/disas/bfd.h back to include/disas/dis-asm.h
  include: Move fprintf_function to disas/

Vladimir Sementsov-Ogievskiy (1):
  util/error: do not free error on error_abort

 MAINTAINERS|   2 +
 accel/kvm/kvm-all.c|   4 +-
 accel/tcg/translate-all.c  |  49 ++---
 block/qapi.c   | 120 ++---
 block/ssh.c|  38 ++--
 block/trace-events |   3 +
 blockdev.c |   9 +-
 bsd-user/main.c|   6 +-
 chardev/char-pty.c |   5 +-
 chardev/char.c |   3 +-
 cpus.c |  21 ++-
 disas.c|   5 +-
 disas/alpha.c  |   2 +-
 disas/arm-a64.cc   |   2 +-
 disas/arm.c|   2 +-
 disas/cris.c   |   2 +-
 disas/hppa.c   |   2 +-
 disas/i386.c   |   2 +-
 disas/lm32.c   |   2 +-
 disas/m68k.c   |   2 +-
 disas/microblaze.c |   2 +-
 disas/mips.c   |   2 +-
 disas/moxie.c  |   2 +-
 disas/nanomips.cpp |   2 +-
 disas/nios2.c  |   2 +-
 disas/ppc.c|   2 +-
 disas/riscv.c  |   2 +-
 disas/s390.c   |   2 +-
 disas/sh4.c|   2 +-
 disas/sparc.c  |   2 +-
 disas/tci.c|   2 +-
 disas/xtensa.c |   2 +-
 exec.c |  42 ++---
 hmp.c  |  12 +-
 hw/core/loader-fit.c   |  62 ---
 hw/mips/boston.c   |   6 +-
 hw/pci/pci.c   |   2 +-
 hw/timer/hpet.c|   2 +-
 hw/vfio/pci.c  |  19 +-
 include/block/qapi.h   |   9 +-
 include/disas/{bfd.h => dis-asm.h} |   5 +-
 include/exec/cpu-all.h |   4 +-
 include/exec/cpu-common.h  |  13 --
 include/exec/log.h |   2 +-
 include/exec/memory-internal.h |   3 +-
 include/exec/memory.h  |   3 +-
 include/monitor/monitor.h  |   8 +-
 

Re: [Qemu-devel] [PATCH v3 01/10] block/pflash_cfi02: Add test for supported commands

2019-04-18 Thread Stephen Checkoway



> On Apr 18, 2019, at 00:47, Thomas Huth  wrote:
> 
> On 18/04/2019 00.01, Stephen Checkoway wrote:
>> Test the AMD command set for parallel flash chips. This test uses an
>> ARM musicpal board with a pflash drive to test the following list of
>> currently-supported commands.
>> - Autoselect
>> - CFI
>> - Sector erase
>> - Chip erase
>> - Program
>> - Unlock bypass
>> - Reset
>> 
>> Signed-off-by: Stephen Checkoway 
>> ---
>> tests/Makefile.include|   2 +
>> tests/pflash-cfi02-test.c | 227 ++
>> 2 files changed, 229 insertions(+)
>> create mode 100644 tests/pflash-cfi02-test.c
> [...]
>> new file mode 100644
>> index 00..b113fca5af
>> --- /dev/null
>> +++ b/tests/pflash-cfi02-test.c
>> @@ -0,0 +1,227 @@
>> +/*
>> + * QTest testcase for parallel flash with AMD command set
>> + *
>> + * Copyright (c) 2018 Stephen Checkoway
> 
> Do you maybe want to update that to 2019?

Done.

> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
>> + * See the COPYING file in the top-level directory.
>> + */
>> +
>> +#include "qemu/osdep.h"
>> +#include 
> 
> We generally don't use err.h in QEMU ... could you please use the
> standard functions from glib instead?

Done.

> +#include 
> 
> unistd.h is already provided by osdep.h, so you don't need to include it
> here again. (and the scripts/clean-includes script will barf at this
> later, so better fix it right from the start)

Done.

> +#include "libqtest.h"
>> +
>> +/*
>> + * To test the pflash_cfi02 device, we run QEMU with the musicpal machine 
>> with
>> + * a pflash drive. This enables us to test some flash configurations, but 
>> not
>> + * all. In particular, we're limited to a 16-bit wide flash device.
>> + */
>> +
>> +#define MP_FLASH_SIZE_MAX (32 * 1024 * 1024)
>> +#define BASE_ADDR (0x1ULL - MP_FLASH_SIZE_MAX)
>> +
>> +#define FLASH_WIDTH 2
>> +#define CFI_ADDR (FLASH_WIDTH * 0x55)
>> +#define UNLOCK0_ADDR (FLASH_WIDTH * 0x)
>> +#define UNLOCK1_ADDR (FLASH_WIDTH * 0x2AAA)
>> +
>> +#define CFI_CMD 0x98
>> +#define UNLOCK0_CMD 0xAA
>> +#define UNLOCK1_CMD 0x55
>> +#define AUTOSELECT_CMD 0x90
>> +#define RESET_CMD 0xF0
>> +#define PROGRAM_CMD 0xA0
>> +#define SECTOR_ERASE_CMD 0x30
>> +#define CHIP_ERASE_CMD 0x10
>> +#define UNLOCK_BYPASS_CMD 0x20
>> +#define UNLOCK_BYPASS_RESET_CMD 0x00
>> +
>> +static char image_path[] = "/tmp/qtest.XX";
>> +
>> +static inline void flash_write(uint64_t byte_addr, uint16_t data)
>> +{
>> +qtest_writew(global_qtest, BASE_ADDR + byte_addr, data);
>> +}
>> +
>> +static inline uint16_t flash_read(uint64_t byte_addr)
>> +{
>> +return qtest_readw(global_qtest, BASE_ADDR + byte_addr);
>> +}
>> +
>> +static void unlock(void)
>> +{
>> +flash_write(UNLOCK0_ADDR, UNLOCK0_CMD);
>> +flash_write(UNLOCK1_ADDR, UNLOCK1_CMD);
>> +}
>> +
>> +static void reset(void)
>> +{
>> +flash_write(0, RESET_CMD);
>> +}
>> +
>> +static void sector_erase(uint64_t byte_addr)
>> +{
>> +unlock();
>> +flash_write(UNLOCK0_ADDR, 0x80);
>> +unlock();
>> +flash_write(byte_addr, SECTOR_ERASE_CMD);
>> +}
>> +
>> +static void wait_for_completion(uint64_t byte_addr)
>> +{
>> +/* If DQ6 is toggling, step the clock and ensure the toggle stops. */
>> +if ((flash_read(byte_addr) & 0x40) ^ (flash_read(byte_addr) & 0x40)) {
>> +/* Wait for erase or program to finish. */
>> +clock_step_next();
>> +/* Ensure that DQ6 has stopped toggling. */
>> +g_assert_cmpint(flash_read(byte_addr), ==, flash_read(byte_addr));
>> +}
>> +}
>> +
>> +static void bypass_program(uint64_t byte_addr, uint16_t data)
>> +{
>> +flash_write(UNLOCK0_ADDR, PROGRAM_CMD);
>> +flash_write(byte_addr, data);
>> +/*
>> + * Data isn't valid until DQ6 stops toggling. We don't model this as
>> + * writes are immediate, but if this changes in the future, we can wait
>> + * until the program is complete.
>> + */
>> +wait_for_completion(byte_addr);
>> +}
>> +
>> +static void program(uint64_t byte_addr, uint16_t data)
>> +{
>> +unlock();
>> +bypass_program(byte_addr, data);
>> +}
>> +
>> +static void chip_erase(void)
>> +{
>> +unlock();
>> +flash_write(UNLOCK0_ADDR, 0x80);
>> +unlock();
>> +flash_write(UNLOCK0_ADDR, SECTOR_ERASE_CMD);
>> +}
>> +
>> +static void test_flash(void)
>> +{
>> +global_qtest = qtest_initf("-M musicpal,accel=qtest "
>> +   "-drive 
>> if=pflash,file=%s,format=raw,copy-on-read",
>> +   image_path);
>> +/* Check the IDs. */
>> +unlock();
>> +flash_write(UNLOCK0_ADDR, AUTOSELECT_CMD);
>> +g_assert_cmpint(flash_read(FLASH_WIDTH * 0x), ==, 0x00BF);
>> +g_assert_cmpint(flash_read(FLASH_WIDTH * 0x0001), ==, 0x236D);
>> +reset();
>> +
>> +/* Check the erase blocks. */
>> +flash_write(CFI_ADDR, CFI_CMD);
>> +g_assert_cmpint(flash_read(FLASH_WIDTH * 0x10), ==, 'Q');
>> +

[Qemu-devel] [PULL for-4.1 7/9] Clean up ill-advised or unusual header guards

2019-04-18 Thread Markus Armbruster
Leading underscores are ill-advised because such identifiers are
reserved.  Trailing underscores are merely ugly.  Strip both.

Our header guards commonly end in _H.  Normalize the exceptions.

Done with scripts/clean-header-guards.pl.

Signed-off-by: Markus Armbruster 
Message-Id: <20190315145123.28030-7-arm...@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé 
[Changes to slirp/ dropped, as we're about to spin it off]
---
 block/crypto.h | 6 +++---
 hw/i386/amd_iommu.h| 4 ++--
 hw/tpm/tpm_ioctl.h | 7 ---
 hw/xtensa/xtensa_memory.h  | 4 ++--
 include/authz/base.h   | 7 +++
 include/authz/list.h   | 7 +++
 include/authz/simple.h | 7 +++
 include/chardev/spice.h| 4 ++--
 include/hw/ppc/pnv.h   | 7 ---
 include/hw/ppc/pnv_core.h  | 7 ---
 include/hw/ppc/pnv_lpc.h   | 7 ---
 include/hw/ppc/pnv_occ.h   | 7 ---
 include/hw/ppc/pnv_psi.h   | 7 ---
 include/hw/ppc/pnv_xscom.h | 7 ---
 include/hw/ppc/spapr_ovec.h| 7 ---
 include/hw/timer/pl031.h   | 4 ++--
 include/hw/virtio/vhost-vsock.h| 6 +++---
 include/hw/virtio/virtio-crypto.h  | 6 +++---
 include/hw/xen/start_info.h| 6 +++---
 include/hw/xtensa/mx_pic.h | 4 ++--
 include/qemu/drm.h | 4 ++--
 include/qemu/jhash.h   | 6 +++---
 include/sysemu/hvf.h   | 5 +++--
 linux-user/xtensa/syscall_nr.h | 6 +++---
 linux-user/xtensa/target_structs.h | 4 ++--
 linux-user/xtensa/termbits.h   | 6 +++---
 qga/vss-win32/vss-handles.h| 4 ++--
 target/i386/hax-i386.h | 4 ++--
 target/i386/hax-interface.h| 4 ++--
 target/i386/hvf/hvf-i386.h | 4 ++--
 target/i386/hvf/vmcs.h | 4 ++--
 target/i386/hvf/x86_emu.h  | 5 +++--
 target/i386/hvf/x86_flags.h| 7 ---
 target/i386/hvf/x86_mmu.h  | 7 ---
 target/riscv/pmp.h | 4 ++--
 target/sparc/asi.h | 6 +++---
 tests/libqos/e1000e.h  | 4 ++--
 tests/libqos/sdhci.h   | 4 ++--
 38 files changed, 109 insertions(+), 100 deletions(-)

diff --git a/block/crypto.h b/block/crypto.h
index dd7d47903c..b935695e79 100644
--- a/block/crypto.h
+++ b/block/crypto.h
@@ -18,8 +18,8 @@
  *
  */
 
-#ifndef BLOCK_CRYPTO_H__
-#define BLOCK_CRYPTO_H__
+#ifndef BLOCK_CRYPTO_H
+#define BLOCK_CRYPTO_H
 
 #define BLOCK_CRYPTO_OPT_DEF_KEY_SECRET(prefix, helpstr)\
 {   \
@@ -94,4 +94,4 @@ block_crypto_create_opts_init(QDict *opts, Error **errp);
 QCryptoBlockOpenOptions *
 block_crypto_open_opts_init(QDict *opts, Error **errp);
 
-#endif /* BLOCK_CRYPTO_H__ */
+#endif /* BLOCK_CRYPTO_H */
diff --git a/hw/i386/amd_iommu.h b/hw/i386/amd_iommu.h
index 0ff9095f32..3a694b186b 100644
--- a/hw/i386/amd_iommu.h
+++ b/hw/i386/amd_iommu.h
@@ -18,8 +18,8 @@
  * with this program; if not, see .
  */
 
-#ifndef AMD_IOMMU_H_
-#define AMD_IOMMU_H_
+#ifndef AMD_IOMMU_H
+#define AMD_IOMMU_H
 
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
diff --git a/hw/tpm/tpm_ioctl.h b/hw/tpm/tpm_ioctl.h
index 59a0b0595d..f5f5c553a9 100644
--- a/hw/tpm/tpm_ioctl.h
+++ b/hw/tpm/tpm_ioctl.h
@@ -5,8 +5,9 @@
  *
  * This file is licensed under the terms of the 3-clause BSD license
  */
-#ifndef _TPM_IOCTL_H_
-#define _TPM_IOCTL_H_
+
+#ifndef TPM_IOCTL_H
+#define TPM_IOCTL_H
 
 #include 
 #include 
@@ -267,4 +268,4 @@ enum {
 CMD_SET_BUFFERSIZE,
 };
 
-#endif /* _TPM_IOCTL_H */
+#endif /* TPM_IOCTL_H */
diff --git a/hw/xtensa/xtensa_memory.h b/hw/xtensa/xtensa_memory.h
index e9aa08749d..89125c4a0d 100644
--- a/hw/xtensa/xtensa_memory.h
+++ b/hw/xtensa/xtensa_memory.h
@@ -25,8 +25,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef _XTENSA_MEMORY_H
-#define _XTENSA_MEMORY_H
+#ifndef XTENSA_MEMORY_H
+#define XTENSA_MEMORY_H
 
 #include "qemu-common.h"
 #include "cpu.h"
diff --git a/include/authz/base.h b/include/authz/base.h
index 55ac9581ad..14a59a0425 100644
--- a/include/authz/base.h
+++ b/include/authz/base.h
@@ -18,8 +18,8 @@
  *
  */
 
-#ifndef QAUTHZ_BASE_H__
-#define QAUTHZ_BASE_H__
+#ifndef QAUTHZ_BASE_H
+#define QAUTHZ_BASE_H
 
 #include "qemu-common.h"
 #include "qapi/error.h"
@@ -108,5 +108,4 @@ bool qauthz_is_allowed_by_id(const char *authzid,
  const char *identity,
  Error **errp);
 
-#endif /* QAUTHZ_BASE_H__ */
-
+#endif /* QAUTHZ_BASE_H */
diff --git a/include/authz/list.h b/include/authz/list.h
index 138ae7047c..a88cdbbcf8 100644
--- a/include/authz/list.h
+++ b/include/authz/list.h
@@ -18,8 +18,8 @@
  *
  */
 
-#ifndef QAUTHZ_LIST_H__
-#define QAUTHZ_LIST_H__
+#ifndef QAUTHZ_LIST_H
+#define QAUTHZ_LIST_H
 
 #include "authz/base.h"
 #include "qapi/qapi-types-authz.h"
@@ 

[Qemu-devel] [PULL for-4.1 9/9] Clean up decorations and whitespace around header guards

2019-04-18 Thread Markus Armbruster
Cleaned up with scripts/clean-header-guards.pl.

Signed-off-by: Markus Armbruster 
Message-Id: <20190315145123.28030-9-arm...@redhat.com>
---
 hw/ide/ahci_internal.h  | 2 +-
 include/block/aio-wait.h| 2 +-
 include/exec/translator.h   | 2 +-
 include/hw/arm/nrf51_soc.h  | 1 -
 include/hw/arm/smmu-common.h| 2 +-
 include/hw/misc/imx2_wdt.h  | 2 +-
 include/hw/misc/nrf51_rng.h | 3 ++-
 include/hw/pci-host/designware.h| 2 +-
 include/hw/riscv/sifive_plic.h  | 1 -
 include/qemu/pmem.h | 2 +-
 target/xtensa/xtensa-isa-internal.h | 2 +-
 tests/acpi-utils.h  | 2 +-
 tests/tpm-emu.h | 2 +-
 13 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/hw/ide/ahci_internal.h b/hw/ide/ahci_internal.h
index 9b7fa8fc7d..95ecddcd3c 100644
--- a/hw/ide/ahci_internal.h
+++ b/hw/ide/ahci_internal.h
@@ -394,4 +394,4 @@ void ahci_reset(AHCIState *s);
 
 #define SYSBUS_AHCI(obj) OBJECT_CHECK(SysbusAHCIState, (obj), TYPE_SYSBUS_AHCI)
 
-#endif /* HW_IDE_AHCI_H */
+#endif /* HW_IDE_AHCI_INTERNAL_H */
diff --git a/include/block/aio-wait.h b/include/block/aio-wait.h
index afd0ff7eb8..afeeb18f95 100644
--- a/include/block/aio-wait.h
+++ b/include/block/aio-wait.h
@@ -124,4 +124,4 @@ void aio_wait_kick(void);
  */
 void aio_wait_bh_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque);
 
-#endif /* QEMU_AIO_WAIT */
+#endif /* QEMU_AIO_WAIT_H */
diff --git a/include/exec/translator.h b/include/exec/translator.h
index 71e7b2c347..f327242576 100644
--- a/include/exec/translator.h
+++ b/include/exec/translator.h
@@ -141,4 +141,4 @@ void translator_loop(const TranslatorOps *ops, 
DisasContextBase *db,
 
 void translator_loop_temp_check(DisasContextBase *db);
 
-#endif  /* EXEC__TRANSLATOR_H */
+#endif /* EXEC__TRANSLATOR_H */
diff --git a/include/hw/arm/nrf51_soc.h b/include/hw/arm/nrf51_soc.h
index fd7fcc71a5..0cb78aafea 100644
--- a/include/hw/arm/nrf51_soc.h
+++ b/include/hw/arm/nrf51_soc.h
@@ -53,4 +53,3 @@ typedef struct NRF51State {
 } NRF51State;
 
 #endif
-
diff --git a/include/hw/arm/smmu-common.h b/include/hw/arm/smmu-common.h
index b07cadd0ef..9a6ac64c97 100644
--- a/include/hw/arm/smmu-common.h
+++ b/include/hw/arm/smmu-common.h
@@ -167,4 +167,4 @@ void smmu_inv_notifiers_all(SMMUState *s);
 /* Unmap the range of all the notifiers registered to @mr */
 void smmu_inv_notifiers_mr(IOMMUMemoryRegion *mr);
 
-#endif  /* HW_ARM_SMMU_COMMON */
+#endif /* HW_ARM_SMMU_COMMON_H */
diff --git a/include/hw/misc/imx2_wdt.h b/include/hw/misc/imx2_wdt.h
index 8afc99a10e..b91b002528 100644
--- a/include/hw/misc/imx2_wdt.h
+++ b/include/hw/misc/imx2_wdt.h
@@ -30,4 +30,4 @@ typedef struct IMX2WdtState {
 MemoryRegion mmio;
 } IMX2WdtState;
 
-#endif /* IMX7_SNVS_H */
+#endif /* IMX2_WDT_H */
diff --git a/include/hw/misc/nrf51_rng.h b/include/hw/misc/nrf51_rng.h
index 3d6bf79997..b0133bf665 100644
--- a/include/hw/misc/nrf51_rng.h
+++ b/include/hw/misc/nrf51_rng.h
@@ -30,6 +30,7 @@
  * the COPYING file in the top-level directory.
  *
  */
+
 #ifndef NRF51_RNG_H
 #define NRF51_RNG_H
 
@@ -80,4 +81,4 @@ typedef struct {
 } NRF51RNGState;
 
 
-#endif /* NRF51_RNG_H_ */
+#endif /* NRF51_RNG_H */
diff --git a/include/hw/pci-host/designware.h b/include/hw/pci-host/designware.h
index a4f2c0695b..186bb36238 100644
--- a/include/hw/pci-host/designware.h
+++ b/include/hw/pci-host/designware.h
@@ -99,4 +99,4 @@ typedef struct DesignwarePCIEHost {
 MemoryRegion mmio;
 } DesignwarePCIEHost;
 
-#endif  /* DESIGNWARE_H */
+#endif /* DESIGNWARE_H */
diff --git a/include/hw/riscv/sifive_plic.h b/include/hw/riscv/sifive_plic.h
index 688cd97f82..ce8907f6aa 100644
--- a/include/hw/riscv/sifive_plic.h
+++ b/include/hw/riscv/sifive_plic.h
@@ -80,4 +80,3 @@ DeviceState *sifive_plic_create(hwaddr addr, char 
*hart_config,
 uint32_t aperture_size);
 
 #endif
-
diff --git a/include/qemu/pmem.h b/include/qemu/pmem.h
index dfb6d0da62..d2d7ad085c 100644
--- a/include/qemu/pmem.h
+++ b/include/qemu/pmem.h
@@ -33,4 +33,4 @@ pmem_persist(const void *addr, size_t len)
 
 #endif /* CONFIG_LIBPMEM */
 
-#endif /* !QEMU_PMEM_H */
+#endif /* QEMU_PMEM_H */
diff --git a/target/xtensa/xtensa-isa-internal.h 
b/target/xtensa/xtensa-isa-internal.h
index c29295ff96..40dd8bac96 100644
--- a/target/xtensa/xtensa-isa-internal.h
+++ b/target/xtensa/xtensa-isa-internal.h
@@ -228,4 +228,4 @@ int xtensa_isa_name_compare(const void *, const void *);
 extern xtensa_isa_status xtisa_errno;
 extern char xtisa_error_msg[];
 
-#endif /* !XTENSA_ISA_INTERNAL_H */
+#endif /* XTENSA_ISA_INTERNAL_H */
diff --git a/tests/acpi-utils.h b/tests/acpi-utils.h
index ef388bbf12..73fe24f044 100644
--- a/tests/acpi-utils.h
+++ b/tests/acpi-utils.h
@@ -52,4 +52,4 @@ void acpi_fetch_table(QTestState *qts, uint8_t **aml, 
uint32_t *aml_len,
   const uint8_t *addr_ptr, const char *sig,
   bool verify_checksum);
 
-#endif  /* 

[Qemu-devel] [PULL for-4.1 1/9] Clean up includes

2019-04-18 Thread Markus Armbruster
Clean up includes so that osdep.h is included first and headers
which it implies are not included manually.

This commit was created with scripts/clean-includes, with the changes
to the following files manually reverted:

contrib/libvhost-user/libvhost-user-glib.h
contrib/libvhost-user/libvhost-user.c
contrib/libvhost-user/libvhost-user.h
linux-user/mips64/cpu_loop.c
linux-user/mips64/signal.c
linux-user/sparc64/cpu_loop.c
linux-user/sparc64/signal.c
linux-user/x86_64/cpu_loop.c
linux-user/x86_64/signal.c
slirp/src/*
target/s390x/gen-features.c
tests/migration/s390x/a-b-bios.c
tests/test-rcu-simpleq.c
tests/test-rcu-tailq.c
tests/uefi-test-tools/UefiTestToolsPkg/BiosTablesTest/BiosTablesTest.c

We're in the process of spinning out slirp/.  tests/uefi-test-tools/
is guest software.  The remaining reverts are the same as in commit
b7d89466dde.

Signed-off-by: Markus Armbruster 
Message-Id: <20190313162812.8885-1-arm...@redhat.com>
Reviewed-by: Eric Blake 
---
 contrib/elf2dmp/main.c   | 3 +--
 contrib/elf2dmp/pdb.c| 3 +--
 hw/display/ati.c | 1 +
 hw/display/ati_2d.c  | 1 +
 hw/display/ati_dbg.c | 1 +
 hw/display/ati_int.h | 1 -
 include/hw/cpu/cluster.h | 1 -
 tests/fp/platform.h  | 1 -
 tests/libqos/qgraph.h| 4 
 tests/qos-test.c | 2 +-
 10 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c
index 1bfeb89ba7..9a2dbc2902 100644
--- a/contrib/elf2dmp/main.c
+++ b/contrib/elf2dmp/main.c
@@ -5,9 +5,8 @@
  *
  */
 
-#include 
-
 #include "qemu/osdep.h"
+
 #include "err.h"
 #include "addrspace.h"
 #include "pe.h"
diff --git a/contrib/elf2dmp/pdb.c b/contrib/elf2dmp/pdb.c
index 64af20f584..a5bd40c99d 100644
--- a/contrib/elf2dmp/pdb.c
+++ b/contrib/elf2dmp/pdb.c
@@ -18,9 +18,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include 
-
 #include "qemu/osdep.h"
+
 #include "pdb.h"
 #include "err.h"
 
diff --git a/hw/display/ati.c b/hw/display/ati.c
index db409be3c9..75716dd944 100644
--- a/hw/display/ati.c
+++ b/hw/display/ati.c
@@ -16,6 +16,7 @@
  * No 3D at all yet (maybe after 2D works, but feel free to improve it)
  */
 
+#include "qemu/osdep.h"
 #include "ati_int.h"
 #include "ati_regs.h"
 #include "vga_regs.h"
diff --git a/hw/display/ati_2d.c b/hw/display/ati_2d.c
index bc98ba6eeb..f31b3c27c7 100644
--- a/hw/display/ati_2d.c
+++ b/hw/display/ati_2d.c
@@ -7,6 +7,7 @@
  * This work is licensed under the GNU GPL license version 2 or later.
  */
 
+#include "qemu/osdep.h"
 #include "ati_int.h"
 #include "ati_regs.h"
 #include "qemu/log.h"
diff --git a/hw/display/ati_dbg.c b/hw/display/ati_dbg.c
index 1e6c32624e..b045f81d06 100644
--- a/hw/display/ati_dbg.c
+++ b/hw/display/ati_dbg.c
@@ -1,3 +1,4 @@
+#include "qemu/osdep.h"
 #include "ati_int.h"
 
 #ifdef DEBUG_ATI
diff --git a/hw/display/ati_int.h b/hw/display/ati_int.h
index a6f3e20e63..2f426064cf 100644
--- a/hw/display/ati_int.h
+++ b/hw/display/ati_int.h
@@ -9,7 +9,6 @@
 #ifndef ATI_INT_H
 #define ATI_INT_H
 
-#include "qemu/osdep.h"
 #include "hw/pci/pci.h"
 #include "vga_int.h"
 
diff --git a/include/hw/cpu/cluster.h b/include/hw/cpu/cluster.h
index 549c2d31d4..01c1e50cd2 100644
--- a/include/hw/cpu/cluster.h
+++ b/include/hw/cpu/cluster.h
@@ -20,7 +20,6 @@
 #ifndef HW_CPU_CLUSTER_H
 #define HW_CPU_CLUSTER_H
 
-#include "qemu/osdep.h"
 #include "hw/qdev.h"
 
 /*
diff --git a/tests/fp/platform.h b/tests/fp/platform.h
index c20ba70baa..f8c423dde3 100644
--- a/tests/fp/platform.h
+++ b/tests/fp/platform.h
@@ -29,7 +29,6 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 
THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-#include "config-host.h"
 
 #ifndef HOST_WORDS_BIGENDIAN
 #define LITTLEENDIAN 1
diff --git a/tests/libqos/qgraph.h b/tests/libqos/qgraph.h
index ef0c73837a..e799095b30 100644
--- a/tests/libqos/qgraph.h
+++ b/tests/libqos/qgraph.h
@@ -19,11 +19,7 @@
 #ifndef QGRAPH_H
 #define QGRAPH_H
 
-#include 
-#include 
-#include 
 #include 
-#include 
 #include "qemu/module.h"
 #include "malloc.h"
 
diff --git a/tests/qos-test.c b/tests/qos-test.c
index 6b1145eccc..ae2fb5de1c 100644
--- a/tests/qos-test.c
+++ b/tests/qos-test.c
@@ -16,8 +16,8 @@
  * License along with this library; if not, see 
  */
 
-#include 
 #include "qemu/osdep.h"
+#include 
 #include "libqtest.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qbool.h"
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 5/9] target/xtensa: Clean up core-isa.h header guards

2019-04-18 Thread Markus Armbruster
scripts/clean-header-guards.pl warns these headers use reserved
identifier _XTENSA_CORE_CONFIGURATION_H as header guard symbol.  It
additionally warns the guard doesn't match the file name.

Reuse of the same guard symbol in multiple headers is okay as long as
they cannot be included together.

Since we can avoid guard symbol reuse easily, do so: use the guard
symbol scripts/clean-header-guards.pl picks, less the TARGET_ prefix.

Signed-off-by: Markus Armbruster 
Message-Id: <20190315145123.28030-5-arm...@redhat.com>
---
 target/xtensa/core-de212/core-isa.h | 8 +++-
 target/xtensa/core-sample_controller/core-isa.h | 8 +++-
 target/xtensa/core-test_kc705_be/core-isa.h | 8 +++-
 target/xtensa/core-test_mmuhifi_c3/core-isa.h   | 8 +++-
 4 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/target/xtensa/core-de212/core-isa.h 
b/target/xtensa/core-de212/core-isa.h
index 78e7f38310..90ac329230 100644
--- a/target/xtensa/core-de212/core-isa.h
+++ b/target/xtensa/core-de212/core-isa.h
@@ -28,9 +28,8 @@
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
 
-#ifndef _XTENSA_CORE_CONFIGURATION_H
-#define _XTENSA_CORE_CONFIGURATION_H
-
+#ifndef XTENSA_CORE_DE212_CORE_ISA_H
+#define XTENSA_CORE_DE212_CORE_ISA_H
 
 /
Parameters Useful for Any Code, USER or PRIVILEGED
@@ -618,5 +617,4 @@
 #endif /* !XTENSA_HAL_NON_PRIVILEGED_ONLY */
 
 
-#endif /* _XTENSA_CORE_CONFIGURATION_H */
-
+#endif /* XTENSA_CORE_DE212_CORE_ISA_H */
diff --git a/target/xtensa/core-sample_controller/core-isa.h 
b/target/xtensa/core-sample_controller/core-isa.h
index e681e43209..d53dca8665 100644
--- a/target/xtensa/core-sample_controller/core-isa.h
+++ b/target/xtensa/core-sample_controller/core-isa.h
@@ -28,9 +28,8 @@
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
 
-#ifndef _XTENSA_CORE_CONFIGURATION_H
-#define _XTENSA_CORE_CONFIGURATION_H
-
+#ifndef XTENSA_CORE_SAMPLE_CONTROLLER_CORE_ISA_H
+#define XTENSA_CORE_SAMPLE_CONTROLLER_CORE_ISA_H
 
 /
Parameters Useful for Any Code, USER or PRIVILEGED
@@ -640,5 +639,4 @@
 #endif /* !XTENSA_HAL_NON_PRIVILEGED_ONLY */
 
 
-#endif /* _XTENSA_CORE_CONFIGURATION_H */
-
+#endif /* XTENSA_CORE_SAMPLE_CONTROLLER_CORE_ISA_H */
diff --git a/target/xtensa/core-test_kc705_be/core-isa.h 
b/target/xtensa/core-test_kc705_be/core-isa.h
index a4ebdf7197..408fed871d 100644
--- a/target/xtensa/core-test_kc705_be/core-isa.h
+++ b/target/xtensa/core-test_kc705_be/core-isa.h
@@ -28,9 +28,8 @@
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
 
-#ifndef _XTENSA_CORE_CONFIGURATION_H
-#define _XTENSA_CORE_CONFIGURATION_H
-
+#ifndef XTENSA_CORE_TEST_KC705_BE_CORE_ISA_H
+#define XTENSA_CORE_TEST_KC705_BE_CORE_ISA_H
 
 /
Parameters Useful for Any Code, USER or PRIVILEGED
@@ -571,5 +570,4 @@
 #endif /* !XTENSA_HAL_NON_PRIVILEGED_ONLY */
 
 
-#endif /* _XTENSA_CORE_CONFIGURATION_H */
-
+#endif /* XTENSA_CORE_TEST_KC705_BE_CORE_ISA_H */
diff --git a/target/xtensa/core-test_mmuhifi_c3/core-isa.h 
b/target/xtensa/core-test_mmuhifi_c3/core-isa.h
index 309caa1a32..704a31f7c8 100644
--- a/target/xtensa/core-test_mmuhifi_c3/core-isa.h
+++ b/target/xtensa/core-test_mmuhifi_c3/core-isa.h
@@ -7,9 +7,8 @@
  * Copyright (c) 1999-2009 Tensilica Inc.
  */
 
-#ifndef _XTENSA_CORE_CONFIGURATION_H
-#define _XTENSA_CORE_CONFIGURATION_H
-
+#ifndef XTENSA_CORE_TEST_MMUHIFI_C3_CORE_ISA_H
+#define XTENSA_CORE_TEST_MMUHIFI_C3_CORE_ISA_H
 
 /
Parameters Useful for Any Code, USER or PRIVILEGED
@@ -380,5 +379,4 @@
 #endif /* !XTENSA_HAL_NON_PRIVILEGED_ONLY */
 
 
-#endif /* _XTENSA_CORE_CONFIGURATION_H */
-
+#endif /* XTENSA_CORE_TEST_MMUHIFI_C3_CORE_ISA_H */
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 8/9] Normalize header guard symbol definition.

2019-04-18 Thread Markus Armbruster
We commonly define the header guard symbol without an explicit value.
Normalize the exceptions.

Done with scripts/clean-header-guards.pl.

Signed-off-by: Markus Armbruster 
Message-Id: <20190315145123.28030-8-arm...@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/timer/m48t59-internal.h| 3 ++-
 include/disas/capstone.h  | 2 +-
 include/hw/scsi/emulation.h   | 2 +-
 include/qemu/stats64.h| 2 +-
 include/qemu/sys_membarrier.h | 2 +-
 include/qemu/systemd.h| 2 +-
 include/scsi/utils.h  | 2 +-
 include/ui/kbd-state.h| 3 ++-
 scsi/pr-helper.h  | 3 ++-
 target/i386/hvf/x86.h | 2 +-
 target/i386/hvf/x86_decode.h  | 2 +-
 target/i386/hvf/x86_descr.h   | 2 +-
 12 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/hw/timer/m48t59-internal.h b/hw/timer/m48t59-internal.h
index d0f0caf3c7..4d4f2a6fed 100644
--- a/hw/timer/m48t59-internal.h
+++ b/hw/timer/m48t59-internal.h
@@ -22,8 +22,9 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+
 #ifndef HW_M48T59_INTERNAL_H
-#define HW_M48T59_INTERNAL_H 1
+#define HW_M48T59_INTERNAL_H
 
 #define M48T59_DEBUG 0
 
diff --git a/include/disas/capstone.h b/include/disas/capstone.h
index 84e214956d..e29068dd97 100644
--- a/include/disas/capstone.h
+++ b/include/disas/capstone.h
@@ -1,5 +1,5 @@
 #ifndef QEMU_CAPSTONE_H
-#define QEMU_CAPSTONE_H 1
+#define QEMU_CAPSTONE_H
 
 #ifdef CONFIG_CAPSTONE
 
diff --git a/include/hw/scsi/emulation.h b/include/hw/scsi/emulation.h
index 09fba1ff39..9521704326 100644
--- a/include/hw/scsi/emulation.h
+++ b/include/hw/scsi/emulation.h
@@ -1,5 +1,5 @@
 #ifndef HW_SCSI_EMULATION_H
-#define HW_SCSI_EMULATION_H 1
+#define HW_SCSI_EMULATION_H
 
 typedef struct SCSIBlockLimits {
 bool wsnz;
diff --git a/include/qemu/stats64.h b/include/qemu/stats64.h
index 4a357b3e9d..19a5ac4c56 100644
--- a/include/qemu/stats64.h
+++ b/include/qemu/stats64.h
@@ -10,7 +10,7 @@
  */
 
 #ifndef QEMU_STATS64_H
-#define QEMU_STATS64_H 1
+#define QEMU_STATS64_H
 
 #include "qemu/atomic.h"
 
diff --git a/include/qemu/sys_membarrier.h b/include/qemu/sys_membarrier.h
index 316e3dc4a2..b5bfa21d52 100644
--- a/include/qemu/sys_membarrier.h
+++ b/include/qemu/sys_membarrier.h
@@ -7,7 +7,7 @@
  */
 
 #ifndef QEMU_SYS_MEMBARRIER_H
-#define QEMU_SYS_MEMBARRIER_H 1
+#define QEMU_SYS_MEMBARRIER_H
 
 #ifdef CONFIG_MEMBARRIER
 /* Only block reordering at the compiler level in the performance-critical
diff --git a/include/qemu/systemd.h b/include/qemu/systemd.h
index e6a877e5c6..f0ea1266d5 100644
--- a/include/qemu/systemd.h
+++ b/include/qemu/systemd.h
@@ -11,7 +11,7 @@
  */
 
 #ifndef QEMU_SYSTEMD_H
-#define QEMU_SYSTEMD_H 1
+#define QEMU_SYSTEMD_H
 
 #define FIRST_SOCKET_ACTIVATION_FD 3 /* defined by systemd ABI */
 
diff --git a/include/scsi/utils.h b/include/scsi/utils.h
index 4b705f5e0f..9351b21ead 100644
--- a/include/scsi/utils.h
+++ b/include/scsi/utils.h
@@ -1,5 +1,5 @@
 #ifndef SCSI_UTILS_H
-#define SCSI_UTILS_H 1
+#define SCSI_UTILS_H
 
 #ifdef CONFIG_LINUX
 #include 
diff --git a/include/ui/kbd-state.h b/include/ui/kbd-state.h
index d87833553a..eb9067dd53 100644
--- a/include/ui/kbd-state.h
+++ b/include/ui/kbd-state.h
@@ -3,8 +3,9 @@
  * (at your option) any later version.  See the COPYING file in the
  * top-level directory.
  */
+
 #ifndef QEMU_UI_KBD_STATE_H
-#define QEMU_UI_KBD_STATE_H 1
+#define QEMU_UI_KBD_STATE_H
 
 #include "qapi/qapi-types-ui.h"
 
diff --git a/scsi/pr-helper.h b/scsi/pr-helper.h
index 096d1f1df6..e26e104ec7 100644
--- a/scsi/pr-helper.h
+++ b/scsi/pr-helper.h
@@ -23,8 +23,9 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  * IN THE SOFTWARE.
  */
+
 #ifndef QEMU_PR_HELPER_H
-#define QEMU_PR_HELPER_H 1
+#define QEMU_PR_HELPER_H
 
 #define PR_HELPER_CDB_SIZE 16
 #define PR_HELPER_SENSE_SIZE   96
diff --git a/target/i386/hvf/x86.h b/target/i386/hvf/x86.h
index 103ec0976c..c95d5b2116 100644
--- a/target/i386/hvf/x86.h
+++ b/target/i386/hvf/x86.h
@@ -17,7 +17,7 @@
  */
 
 #ifndef HVF_X86_H
-#define HVF_X86_H 1
+#define HVF_X86_H
 
 typedef struct x86_register {
 union {
diff --git a/target/i386/hvf/x86_decode.h b/target/i386/hvf/x86_decode.h
index ef4bcab310..bc574a7a44 100644
--- a/target/i386/hvf/x86_decode.h
+++ b/target/i386/hvf/x86_decode.h
@@ -16,7 +16,7 @@
  */
 
 #ifndef HVF_X86_DECODE_H
-#define HVF_X86_DECODE_H 1
+#define HVF_X86_DECODE_H
 
 #include "cpu.h"
 #include "x86.h"
diff --git a/target/i386/hvf/x86_descr.h b/target/i386/hvf/x86_descr.h
index 25a2b1731c..049ef9a417 100644
--- a/target/i386/hvf/x86_descr.h
+++ b/target/i386/hvf/x86_descr.h
@@ -17,7 +17,7 @@
  */
 
 #ifndef HVF_X86_DESCR_H
-#define HVF_X86_DESCR_H 1
+#define HVF_X86_DESCR_H
 
 #include "x86.h"
 
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 4/9] linux-user/nios2 linux-user/riscv: Clean up header guards

2019-04-18 Thread Markus Armbruster
Reuse of the same guard symbol in multiple headers is okay as long as
they cannot be included together.  scripts/clean-header-guards.pl
can't tell, so it warns.

Since we can avoid guard symbol reuse easily, do so: use guard symbol
${target^^}_${fname^^} for linux-user/$target/$fname, just like we did
in commit a9c94277f0..3500385697.

Signed-off-by: Markus Armbruster 
Message-Id: <20190315145123.28030-4-arm...@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé 
---
 linux-user/nios2/target_cpu.h | 4 ++--
 linux-user/nios2/target_signal.h  | 6 +++---
 linux-user/nios2/target_structs.h | 4 ++--
 linux-user/nios2/target_syscall.h | 6 +++---
 linux-user/riscv/target_cpu.h | 4 ++--
 linux-user/riscv/target_signal.h  | 6 +++---
 linux-user/riscv/target_structs.h | 4 ++--
 7 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/linux-user/nios2/target_cpu.h b/linux-user/nios2/target_cpu.h
index 14f63338fa..5596c05c9c 100644
--- a/linux-user/nios2/target_cpu.h
+++ b/linux-user/nios2/target_cpu.h
@@ -17,8 +17,8 @@
  * License along with this library; if not, see .
  */
 
-#ifndef TARGET_CPU_H
-#define TARGET_CPU_H
+#ifndef NIOS2_TARGET_CPU_H
+#define NIOS2_TARGET_CPU_H
 
 static inline void cpu_clone_regs(CPUNios2State *env, target_ulong newsp)
 {
diff --git a/linux-user/nios2/target_signal.h b/linux-user/nios2/target_signal.h
index 7776bcdbfd..fe48721b3d 100644
--- a/linux-user/nios2/target_signal.h
+++ b/linux-user/nios2/target_signal.h
@@ -1,5 +1,5 @@
-#ifndef TARGET_SIGNAL_H
-#define TARGET_SIGNAL_H
+#ifndef NIOS2_TARGET_SIGNAL_H
+#define NIOS2_TARGET_SIGNAL_H
 
 /* this struct defines a stack used during syscall handling */
 
@@ -18,4 +18,4 @@ typedef struct target_sigaltstack {
 
 #include "../generic/signal.h"
 
-#endif /* TARGET_SIGNAL_H */
+#endif /* NIOS2_TARGET_SIGNAL_H */
diff --git a/linux-user/nios2/target_structs.h 
b/linux-user/nios2/target_structs.h
index 8713772089..7145251706 100644
--- a/linux-user/nios2/target_structs.h
+++ b/linux-user/nios2/target_structs.h
@@ -16,8 +16,8 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, see .
  */
-#ifndef TARGET_STRUCTS_H
-#define TARGET_STRUCTS_H
+#ifndef NIOS2_TARGET_STRUCTS_H
+#define NIOS2_TARGET_STRUCTS_H
 
 struct target_ipc_perm {
 abi_int __key;  /* Key.  */
diff --git a/linux-user/nios2/target_syscall.h 
b/linux-user/nios2/target_syscall.h
index ca6b7e69f6..f3b2a500f4 100644
--- a/linux-user/nios2/target_syscall.h
+++ b/linux-user/nios2/target_syscall.h
@@ -1,5 +1,5 @@
-#ifndef TARGET_SYSCALL_H
-#define TARGET_SYSCALL_H
+#ifndef NIOS2_TARGET_SYSCALL_H
+#define NIOS2_TARGET_SYSCALL_H
 
 #define UNAME_MACHINE "nios2"
 #define UNAME_MINIMUM_RELEASE "3.19.0"
@@ -34,4 +34,4 @@ struct target_pt_regs {
 #define TARGET_MLOCKALL_MCL_CURRENT 1
 #define TARGET_MLOCKALL_MCL_FUTURE  2
 
-#endif  /* TARGET_SYSCALL_H */
+#endif /* NIOS2_TARGET_SYSCALL_H */
diff --git a/linux-user/riscv/target_cpu.h b/linux-user/riscv/target_cpu.h
index 7e090f376a..90f9a4171e 100644
--- a/linux-user/riscv/target_cpu.h
+++ b/linux-user/riscv/target_cpu.h
@@ -1,5 +1,5 @@
-#ifndef TARGET_CPU_H
-#define TARGET_CPU_H
+#ifndef RISCV_TARGET_CPU_H
+#define RISCV_TARGET_CPU_H
 
 static inline void cpu_clone_regs(CPURISCVState *env, target_ulong newsp)
 {
diff --git a/linux-user/riscv/target_signal.h b/linux-user/riscv/target_signal.h
index c8b1455800..f113ba9a55 100644
--- a/linux-user/riscv/target_signal.h
+++ b/linux-user/riscv/target_signal.h
@@ -1,5 +1,5 @@
-#ifndef TARGET_SIGNAL_H
-#define TARGET_SIGNAL_H
+#ifndef RISCV_TARGET_SIGNAL_H
+#define RISCV_TARGET_SIGNAL_H
 
 typedef struct target_sigaltstack {
 abi_ulong ss_sp;
@@ -15,4 +15,4 @@ typedef struct target_sigaltstack {
 
 #include "../generic/signal.h"
 
-#endif /* TARGET_SIGNAL_H */
+#endif /* RISCV_TARGET_SIGNAL_H */
diff --git a/linux-user/riscv/target_structs.h 
b/linux-user/riscv/target_structs.h
index 4f0462c497..ea3e5ed17e 100644
--- a/linux-user/riscv/target_structs.h
+++ b/linux-user/riscv/target_structs.h
@@ -4,8 +4,8 @@
  * This is a copy of ../aarch64/target_structs.h atm.
  *
  */
-#ifndef TARGET_STRUCTS_H
-#define TARGET_STRUCTS_H
+#ifndef RISCV_TARGET_STRUCTS_H
+#define RISCV_TARGET_STRUCTS_H
 
 struct target_ipc_perm {
 abi_int __key;  /* Key.  */
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 3/9] authz: Normalize #include "authz/trace.h" to "trace.h"

2019-04-18 Thread Markus Armbruster
Include the generated trace.h the same way as we do everywhere else.

Signed-off-by: Markus Armbruster 
Message-Id: <20190315145123.28030-3-arm...@redhat.com>
Acked-by: Daniel P. Berrangé 
Reviewed-by: Philippe Mathieu-Daudé 
---
 authz/base.c | 2 +-
 authz/list.c | 2 +-
 authz/listfile.c | 2 +-
 authz/pamacct.c  | 2 +-
 authz/simple.c   | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/authz/base.c b/authz/base.c
index 110dfa4195..baf39fff25 100644
--- a/authz/base.c
+++ b/authz/base.c
@@ -20,7 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "authz/base.h"
-#include "authz/trace.h"
+#include "trace.h"
 
 bool qauthz_is_allowed(QAuthZ *authz,
const char *identity,
diff --git a/authz/list.c b/authz/list.c
index dc6b0fec13..831da936fe 100644
--- a/authz/list.c
+++ b/authz/list.c
@@ -20,7 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "authz/list.h"
-#include "authz/trace.h"
+#include "trace.h"
 #include "qom/object_interfaces.h"
 #include "qapi/qapi-visit-authz.h"
 
diff --git a/authz/listfile.c b/authz/listfile.c
index bc2b58ef6d..d74bbd1048 100644
--- a/authz/listfile.c
+++ b/authz/listfile.c
@@ -20,7 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "authz/listfile.h"
-#include "authz/trace.h"
+#include "trace.h"
 #include "qemu/error-report.h"
 #include "qemu/main-loop.h"
 #include "qemu/sockets.h"
diff --git a/authz/pamacct.c b/authz/pamacct.c
index 5038358cdc..7539867923 100644
--- a/authz/pamacct.c
+++ b/authz/pamacct.c
@@ -20,7 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "authz/pamacct.h"
-#include "authz/trace.h"
+#include "trace.h"
 #include "qom/object_interfaces.h"
 
 #include 
diff --git a/authz/simple.c b/authz/simple.c
index 8ab718803e..c409ce7efc 100644
--- a/authz/simple.c
+++ b/authz/simple.c
@@ -20,7 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "authz/simple.h"
-#include "authz/trace.h"
+#include "trace.h"
 #include "qom/object_interfaces.h"
 
 static bool qauthz_simple_is_allowed(QAuthZ *authz,
-- 
2.17.2




[Qemu-devel] [PULL for-4.1 0/9] Miscellaneous patches for 2019-04-18

2019-04-18 Thread Markus Armbruster
Early pull request because I'll be on vacation when 4.1 opens.  Hope
that's okay.

The following changes since commit eeba63fc7fface36f438bcbc0d3b02e7dcb59983:

  Update version for v4.0.0-rc4 release (2019-04-16 21:53:00 +0100)

are available in the Git repository at:

  git://repo.or.cz/qemu/armbru.git tags/pull-misc-2019-04-18

for you to fetch changes up to 15136db27efaf0bdcf1131d41ad57832a2acadcc:

  Clean up decorations and whitespace around header guards (2019-04-17 19:20:46 
+0200)


Miscellaneous patches for 2019-04-18


Markus Armbruster (9):
  Clean up includes
  Use #include "..." for our own headers, <...> for others
  authz: Normalize #include "authz/trace.h" to "trace.h"
  linux-user/nios2 linux-user/riscv: Clean up header guards
  target/xtensa: Clean up core-isa.h header guards
  Clean up header guards that don't match their file name
  Clean up ill-advised or unusual header guards
  Normalize header guard symbol definition.
  Clean up decorations and whitespace around header guards

 authz/base.c|  2 +-
 authz/list.c|  2 +-
 authz/listfile.c|  2 +-
 authz/pamacct.c |  2 +-
 authz/simple.c  |  2 +-
 block/crypto.h  |  6 +++---
 contrib/elf2dmp/main.c  |  3 +--
 contrib/elf2dmp/pdb.c   |  3 +--
 contrib/elf2dmp/qemu_elf.h  |  6 +++---
 contrib/rdmacm-mux/main.c   | 18 +-
 contrib/rdmacm-mux/rdmacm-mux.h |  6 +++---
 disas/nanomips.h|  4 ++--
 fsdev/qemu-fsdev-throttle.h |  7 ---
 hw/arm/smmuv3-internal.h|  4 ++--
 hw/display/ati.c|  1 +
 hw/display/ati_2d.c |  1 +
 hw/display/ati_dbg.c|  1 +
 hw/display/ati_int.h|  1 -
 hw/display/vga_regs.h   |  6 +++---
 hw/i386/amd_iommu.h |  4 ++--
 hw/ide/ahci_internal.h  |  2 +-
 hw/rdma/rdma_utils.h|  1 -
 hw/rdma/vmw/pvrdma_qp_ops.h |  4 ++--
 hw/sd/sdmmc-internal.h  |  5 +++--
 hw/timer/m48t59-internal.h  |  3 ++-
 hw/tpm/tpm_ioctl.h  |  7 ---
 hw/xtensa/xtensa_memory.h   |  4 ++--
 include/authz/base.h|  7 +++
 include/authz/list.h|  7 +++
 include/authz/listfile.h|  8 +++-
 include/authz/pamacct.h |  7 +++
 include/authz/simple.h  |  7 +++
 include/block/aio-wait.h|  2 +-
 include/chardev/spice.h |  4 ++--
 include/disas/capstone.h|  2 +-
 include/exec/translator.h   |  2 +-
 include/hw/arm/nrf51_soc.h  |  1 -
 include/hw/arm/smmu-common.h|  2 +-
 include/hw/audio/soundhw.h  |  4 ++--
 include/hw/cpu/cluster.h|  1 -
 include/hw/i386/x86-iommu.h |  4 ++--
 include/hw/intc/heathrow_pic.h  |  6 +++---
 include/hw/intc/xlnx-pmu-iomod-intc.h   |  6 +++---
 include/hw/misc/armsse-mhu.h|  4 ++--
 include/hw/misc/imx2_wdt.h  |  2 +-
 include/hw/misc/nrf51_rng.h |  3 ++-
 include/hw/pci-host/designware.h|  2 +-
 include/hw/pci-host/sabre.h |  4 ++--
 include/hw/ppc/pnv.h|  7 ---
 include/hw/ppc/pnv_core.h   |  7 ---
 include/hw/ppc/pnv_lpc.h|  7 ---
 include/hw/ppc/pnv_occ.h|  7 ---
 include/hw/ppc/pnv_psi.h|  7 ---
 include/hw/ppc/pnv_xscom.h  |  7 ---
 include/hw/ppc/spapr_ovec.h |  7 ---
 include/hw/riscv/sifive_plic.h  |  1 -
 include/hw/scsi/emulation.h |  2 +-
 include/hw/timer/pl031.h|  4 ++--
 include/hw/virtio/vhost-vsock.h |  6 +++---
 include/hw/virtio/virtio-crypto.h   |  6 +++---
 include/hw/watchdog/wdt_aspeed.h|  7 ---
 include/hw/xen/start_info.h |  6 +++---
 include/hw/xen/xen-legacy-backend.h |  6 +++---
 include/hw/xtensa/mx_pic.h  |  4 ++--
 

[Qemu-devel] [PULL for-4.1 6/9] Clean up header guards that don't match their file name

2019-04-18 Thread Markus Armbruster
Header guard symbols should match their file name to make guard
collisions less likely.

Cleaned up with scripts/clean-header-guards.pl, followed by some
renaming of new guard symbols picked by the script to better ones.

Signed-off-by: Markus Armbruster 
Message-Id: <20190315145123.28030-6-arm...@redhat.com>
---
 contrib/elf2dmp/qemu_elf.h| 6 +++---
 disas/nanomips.h  | 4 ++--
 fsdev/qemu-fsdev-throttle.h   | 7 ---
 hw/arm/smmuv3-internal.h  | 4 ++--
 hw/display/vga_regs.h | 6 +++---
 hw/rdma/vmw/pvrdma_qp_ops.h   | 4 ++--
 hw/sd/sdmmc-internal.h| 5 +++--
 include/authz/listfile.h  | 8 +++-
 include/authz/pamacct.h   | 7 +++
 include/hw/audio/soundhw.h| 4 ++--
 include/hw/i386/x86-iommu.h   | 4 ++--
 include/hw/intc/heathrow_pic.h| 6 +++---
 include/hw/intc/xlnx-pmu-iomod-intc.h | 6 +++---
 include/hw/misc/armsse-mhu.h  | 4 ++--
 include/hw/pci-host/sabre.h   | 4 ++--
 include/hw/watchdog/wdt_aspeed.h  | 7 ---
 include/hw/xen/xen-legacy-backend.h   | 6 +++---
 include/hw/xtensa/xtensa-isa.h| 6 +++---
 include/migration/qemu-file-types.h   | 4 ++--
 include/qemu/filemonitor.h| 6 +++---
 include/scsi/constants.h  | 4 ++--
 net/colo.h| 6 +++---
 target/i386/hax-posix.h   | 6 +++---
 target/i386/hvf/x86_task.h| 6 --
 target/nios2/cpu.h| 7 ---
 target/nios2/mmu.h| 7 ---
 target/ppc/mmu-book3s-v3.h| 6 +++---
 tests/libqos/qgraph_internal.h| 4 ++--
 tests/migration/migration-test.h  | 7 ---
 29 files changed, 83 insertions(+), 78 deletions(-)

diff --git a/contrib/elf2dmp/qemu_elf.h b/contrib/elf2dmp/qemu_elf.h
index 2a7963821a..66ee1f0ed5 100644
--- a/contrib/elf2dmp/qemu_elf.h
+++ b/contrib/elf2dmp/qemu_elf.h
@@ -5,8 +5,8 @@
  *
  */
 
-#ifndef ELF2DMP_ELF_H
-#define ELF2DMP_ELF_H
+#ifndef EMPF2DMP_QEMU_ELF_H
+#define EMPF2DMP_QEMU_ELF_H
 
 #include "elf.h"
 
@@ -47,4 +47,4 @@ void QEMU_Elf_exit(QEMU_Elf *qe);
 Elf64_Phdr *elf64_getphdr(void *map);
 Elf64_Half elf_getphdrnum(void *map);
 
-#endif /* ELF2DMP_ELF_H */
+#endif /* ELF2DMP_QEMU_ELF_H */
diff --git a/disas/nanomips.h b/disas/nanomips.h
index 243c3e38d2..a0a2225301 100644
--- a/disas/nanomips.h
+++ b/disas/nanomips.h
@@ -20,8 +20,8 @@
  *
  */
 
-#ifndef NANOMIPS_DISASSEMBLER_H
-#define NANOMIPS_DISASSEMBLER_H
+#ifndef DISAS_NANOMIPS_H
+#define DISAS_NANOMIPS_H
 
 #include 
 
diff --git a/fsdev/qemu-fsdev-throttle.h b/fsdev/qemu-fsdev-throttle.h
index 4e83bdac25..7d6211d499 100644
--- a/fsdev/qemu-fsdev-throttle.h
+++ b/fsdev/qemu-fsdev-throttle.h
@@ -12,8 +12,8 @@
  *
  */
 
-#ifndef _FSDEV_THROTTLE_H
-#define _FSDEV_THROTTLE_H
+#ifndef QEMU_FSDEV_THROTTLE_H
+#define QEMU_FSDEV_THROTTLE_H
 
 #include "block/aio.h"
 #include "qemu/main-loop.h"
@@ -35,4 +35,5 @@ void coroutine_fn fsdev_co_throttle_request(FsThrottle *, 
bool ,
 struct iovec *, int);
 
 void fsdev_throttle_cleanup(FsThrottle *);
-#endif /* _FSDEV_THROTTLE_H */
+
+#endif /* QEMU_FSDEV_THROTTLE_H */
diff --git a/hw/arm/smmuv3-internal.h b/hw/arm/smmuv3-internal.h
index 19540f8f41..b160289cd1 100644
--- a/hw/arm/smmuv3-internal.h
+++ b/hw/arm/smmuv3-internal.h
@@ -18,8 +18,8 @@
  * with this program; if not, see .
  */
 
-#ifndef HW_ARM_SMMU_V3_INTERNAL_H
-#define HW_ARM_SMMU_V3_INTERNAL_H
+#ifndef HW_ARM_SMMUV3_INTERNAL_H
+#define HW_ARM_SMMUV3_INTERNAL_H
 
 #include "hw/arm/smmu-common.h"
 
diff --git a/hw/display/vga_regs.h b/hw/display/vga_regs.h
index 16886f5eed..30a98b8736 100644
--- a/hw/display/vga_regs.h
+++ b/hw/display/vga_regs.h
@@ -14,8 +14,8 @@
  *
  */
 
-#ifndef LINUX_VIDEO_VGA_H
-#define LINUX_VIDEO_VGA_H
+#ifndef HW_VGA_REGS_H
+#define HW_VGA_REGS_H
 
 /* Some of the code below is taken from SVGAlib.  The original,
unmodified copyright notice for that code is below. */
@@ -156,4 +156,4 @@
 /* VGA graphics controller bit masks */
 #define VGA_GR06_GRAPHICS_MODE  0x01
 
-#endif /* LINUX_VIDEO_VGA_H */
+#endif /* HW_VGA_REGS_H */
diff --git a/hw/rdma/vmw/pvrdma_qp_ops.h b/hw/rdma/vmw/pvrdma_qp_ops.h
index 31cb48ba29..3a76a59c87 100644
--- a/hw/rdma/vmw/pvrdma_qp_ops.h
+++ b/hw/rdma/vmw/pvrdma_qp_ops.h
@@ -13,8 +13,8 @@
  *
  */
 
-#ifndef PVRDMA_QP_H
-#define PVRDMA_QP_H
+#ifndef PVRDMA_QP_OPS_H
+#define PVRDMA_QP_OPS_H
 
 #include "pvrdma.h"
 
diff --git a/hw/sd/sdmmc-internal.h b/hw/sd/sdmmc-internal.h
index 9aa04766fc..d8bf17d204 100644
--- a/hw/sd/sdmmc-internal.h
+++ b/hw/sd/sdmmc-internal.h
@@ -7,8 +7,9 @@
  * See the COPYING file in the top-level directory.
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
-#ifndef SD_INTERNAL_H
-#define SD_INTERNAL_H
+
+#ifndef SDMMC_INTERNAL_H
+#define SDMMC_INTERNAL_H
 
 #define SDMMC_CMD_MAX 64
 
diff --git 

[Qemu-devel] [PULL for-4.1 2/9] Use #include "..." for our own headers, <...> for others

2019-04-18 Thread Markus Armbruster
Also delete a few redundant #include.

Signed-off-by: Markus Armbruster 
Message-Id: <20190315145123.28030-2-arm...@redhat.com>
---
 contrib/rdmacm-mux/main.c   | 18 +-
 contrib/rdmacm-mux/rdmacm-mux.h |  6 +++---
 hw/rdma/rdma_utils.h|  1 -
 target/i386/whp-dispatch.h  |  2 +-
 target/i386/whpx-all.c  |  1 -
 5 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/contrib/rdmacm-mux/main.c b/contrib/rdmacm-mux/main.c
index 21cc804367..30c7052651 100644
--- a/contrib/rdmacm-mux/main.c
+++ b/contrib/rdmacm-mux/main.c
@@ -14,16 +14,16 @@
  */
 
 #include "qemu/osdep.h"
-#include "sys/poll.h"
-#include "sys/ioctl.h"
-#include "pthread.h"
-#include "syslog.h"
+#include 
+#include 
+#include 
+#include 
 
-#include "infiniband/verbs.h"
-#include "infiniband/umad.h"
-#include "infiniband/umad_types.h"
-#include "infiniband/umad_sa.h"
-#include "infiniband/umad_cm.h"
+#include 
+#include 
+#include 
+#include 
+#include 
 
 #include "rdmacm-mux.h"
 
diff --git a/contrib/rdmacm-mux/rdmacm-mux.h b/contrib/rdmacm-mux/rdmacm-mux.h
index 942a802c47..07a4722913 100644
--- a/contrib/rdmacm-mux/rdmacm-mux.h
+++ b/contrib/rdmacm-mux/rdmacm-mux.h
@@ -17,9 +17,9 @@
 #define RDMACM_MUX_H
 
 #include "linux/if.h"
-#include "infiniband/verbs.h"
-#include "infiniband/umad.h"
-#include "rdma/rdma_user_cm.h"
+#include 
+#include 
+#include 
 
 typedef enum RdmaCmMuxMsgType {
 RDMACM_MUX_MSG_TYPE_REQ   = 0,
diff --git a/hw/rdma/rdma_utils.h b/hw/rdma/rdma_utils.h
index 2d42249691..e7babe96cb 100644
--- a/hw/rdma/rdma_utils.h
+++ b/hw/rdma/rdma_utils.h
@@ -20,7 +20,6 @@
 #include "qemu/error-report.h"
 #include "hw/pci/pci.h"
 #include "sysemu/dma.h"
-#include "stdio.h"
 
 #define rdma_error_report(fmt, ...) \
 error_report("%s: " fmt, "rdma", ## __VA_ARGS__)
diff --git a/target/i386/whp-dispatch.h b/target/i386/whp-dispatch.h
index 4ae3cc8fa5..a23fb33a29 100644
--- a/target/i386/whp-dispatch.h
+++ b/target/i386/whp-dispatch.h
@@ -1,4 +1,4 @@
-#include "windows.h"
+#include 
 
 #include 
 #include 
diff --git a/target/i386/whpx-all.c b/target/i386/whpx-all.c
index 57e53e1f1f..31d47320e4 100644
--- a/target/i386/whpx-all.c
+++ b/target/i386/whpx-all.c
@@ -13,7 +13,6 @@
 #include "exec/address-spaces.h"
 #include "exec/ioport.h"
 #include "qemu-common.h"
-#include "strings.h"
 #include "sysemu/accel.h"
 #include "sysemu/whpx.h"
 #include "sysemu/sysemu.h"
-- 
2.17.2




Re: [Qemu-devel] [PATCH v2 3/3] numa: move numa global variable numa_info into MachineState

2019-04-18 Thread Eduardo Habkost
On Thu, Apr 18, 2019 at 02:46:02PM +0800, Tao Xu wrote:
> The aim of this patch is to move existing numa global numa_info
> into NumaState.
> 
> Suggested-by: Igor Mammedov 
> Suggested-by: Eduardo Habkost 
> Signed-off-by: Tao Xu 

`ms->numa_state->numa_info[i]` is not a very descriptive
expression.  Also, we don't need the "numa" prefix anymore, if
the identifier is not in global scope.

I suggest renaming it to NumaState::nodes.  So this:
>  ms->numa_state->numa_info[i].distance[j]
would become:
  ms->numa_state->nodes[i].distance[j]

This wouldn't block me from merging this patch, but it's a
suggestion in case you send v3 to address the comments on patch
1/3.

-- 
Eduardo



Re: [Qemu-devel] [PATCH v3 07/15] vfio: Report warnings with warn_report(), not error_printf()

2019-04-18 Thread Markus Armbruster
Alex Williamson  writes:

> On Thu, 18 Apr 2019 08:18:56 +0200
> Markus Armbruster  wrote:
>
>> Alex Williamson  writes:
>> 
>> > On Wed, 17 Apr 2019 21:06:33 +0200
>> > Markus Armbruster  wrote:
>> >  
>> >> Cc: Alex Williamson 
>> >> Signed-off-by: Markus Armbruster 
>> >> ---
>> >>  hw/vfio/pci.c | 19 +--
>> >>  1 file changed, 13 insertions(+), 6 deletions(-)
>> >> 
>> >> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
>> >> index 504019c458..0142819ea6 100644
>> >> --- a/hw/vfio/pci.c
>> >> +++ b/hw/vfio/pci.c
>> >> @@ -947,8 +947,10 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
>> >>  if (vdev->pdev.romfile || !vdev->pdev.rom_bar) {
>> >>  /* Since pci handles romfile, just print a message and return */
>> >>  if (vfio_blacklist_opt_rom(vdev) && vdev->pdev.romfile) {
>> >> -error_printf("Warning : Device at %s is known to cause 
>> >> system instability issues during option rom execution. Proceeding anyway 
>> >> since user specified romfile\n",
>> >> - vdev->vbasedev.name);
>> >> +warn_report("Device at %s is known to cause system 
>> >> instability"
>> >> +" issues during option rom execution",
>> >> +vdev->vbasedev.name);
>> >> +error_printf("Proceeding anyway since user specified 
>> >> romfile\n");  
>> >
>> > I'm confused, the original warning is "this device is know to have
>> > issues, proceeding because you asked me to".  Are we categorizing the
>> > first half as a warning and the latter as random uncategorized error
>> > spew?  Did an automated script chunk it this way because of the period
>> > and strict application of the "single phrase" specification of
>> > warn_report()?  If this is the recommended semantics, I'm not sure how
>> > I'd know to generate this myself for similar situations.  Should we
>> > instead try to express this in something acceptable as a single
>> > phrase?  Thanks,  
>> 
>> This is an instance of the following error reporting pattern:
>> 
>> concise error / warning message (one line, single phrase)
>> additional information (free format)
>> 
>> We use error_report() / warn_report() for the former (this adds
>> decorations to the message), and error_printf() for the latter.
>> 
>> "git-grep -w error_printf" will lead you to other instances.  Recommend
>> to look with this series applied, because it removes misuses of
>> error_printf().
>> 
>> Particularly relevant instances are error_report_err() and
>> warn_report_err(): these print the error proper with error_report() /
>> warn_report_err(), and the hint, if any, with error_printf().
>> 
>> Clearer now?
>
> I can't guarantee that I'd be able to reproduce these sorts of
> semantics without prompting, but yes, there does seem to be some method
> to the madness ;)  Thanks,

Hopefully, presence of good examples, absence of bad examples, and
review will do the trick often enough.

> Acked-by: Alex Williamson 

Thanks!



Re: [Qemu-devel] [PATCH 0/4] file-posix: Add dynamic-auto-read-only QAPI feature

2019-04-18 Thread Markus Armbruster
Kevin Wolf  writes:

> This series adds optional feature lists to struct definitions in the
> QAPI schema and makes use of them to advertise the new behaviour of
> auto-read-only=on in file-posix.

General approach looks good to me.  It's just a first step, however.
One that is already useful.



Re: [Qemu-devel] [PATCH] cpu: Fix crash with empty -cpu option

2019-04-18 Thread Eduardo Habkost
On Thu, Apr 18, 2019 at 12:45:01AM -0300, Eduardo Habkost wrote:
> Fix the following crash:
> 
>   $ qemu-system-x86_64 -cpu ''
>   qemu-system-x86_64: qom/cpu.c:291: cpu_class_by_name: \
>   Assertion `cpu_model && cc->class_by_name' failed.
> 
> Regression test script included.
> 
> Fixes: commit 99193d8f2ef5 ("cpu: drop unnecessary NULL check and 
> cpu_common_class_by_name()")
> Signed-off-by: Eduardo Habkost 

Queued on machine-next.

-- 
Eduardo



Re: [Qemu-devel] [PATCH 1/4] qapi: Support features for structs

2019-04-18 Thread Markus Armbruster
Kevin Wolf  writes:

> Sometimes, the behaviour of QEMU changes compatibly, but without a
> change in the QMP syntax (usually by allowing values or operations that
> previously resulted in an error). QMP clients may still need to know
> whether the extension is available.
>
> This allows to add a list of features to struct definitions that will be
> made visible to QMP clients through schema introspection.

Only a first step, but that's okay.  I think we want to be able to tack
features to all user-defined types, commands, and events.  Ideally even
to members of enum and object types.

Use case: feature 'deprecated'.  We talked about ways to communicate
deprecation to management applications.  Introspection was proposed.
Feature 'deprecated' delivers it.

> Signed-off-by: Kevin Wolf 
> ---
>  qapi/introspect.json   |  8 -
>  docs/devel/qapi-code-gen.txt   | 38 
>  scripts/qapi/common.py | 49 --
>  scripts/qapi/doc.py|  3 +-
>  scripts/qapi/introspect.py |  6 +++-
>  scripts/qapi/types.py  |  3 +-
>  scripts/qapi/visit.py  |  3 +-
>  tests/qapi-schema/double-type.err  |  2 +-
>  tests/qapi-schema/test-qapi.py |  3 +-
>  tests/qapi-schema/unknown-expr-key.err |  2 +-
>  10 files changed, 99 insertions(+), 18 deletions(-)
>
> diff --git a/qapi/introspect.json b/qapi/introspect.json
> index 3d22166b2b..3cb6c1aca4 100644
> --- a/qapi/introspect.json
> +++ b/qapi/introspect.json
> @@ -174,6 +174,11 @@
>  #and may even differ from the order of the values of the
>  #enum type of the @tag.
>  #
> +# @features: names of features that are supported by this version and build 
> and
> +#aren't othervise visible through schema introspection (e.g. 
> change
> +#of behaviour related to an object type that didn't come with a
> +#syntactic change in the schema of the object type) (since: 4.1)
> +#
>  # Values of this type are JSON object on the wire.
>  #
>  # Since: 2.5
> @@ -181,7 +186,8 @@
>  { 'struct': 'SchemaInfoObject',
>'data': { 'members': [ 'SchemaInfoObjectMember' ],
>  '*tag': 'str',
> -'*variants': [ 'SchemaInfoObjectVariant' ] } }
> +'*variants': [ 'SchemaInfoObjectVariant' ],
> +'*features': [ 'str' ] } }
>  
>  ##
>  # @SchemaInfoObjectMember:
> diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt
> index b517b0cfbf..e8ec8ac1de 100644
> --- a/docs/devel/qapi-code-gen.txt
> +++ b/docs/devel/qapi-code-gen.txt
> @@ -719,6 +719,34 @@ any non-empty complex type (struct, union, or 
> alternate), and a
>  pointer to that QAPI type is passed as a single argument.
>  
>  
> +=== Features ===

This bolts on features similar to how we bolted on conditionals.
Minimally invasive, but the result is suboptimal.  It'll do for now.

> +
> +Sometimes, the behaviour of QEMU changes compatibly, but without a
> +change in the QMP syntax (usually by allowing values or operations that
> +previously resulted in an error). QMP clients may still need to know
> +whether the extension is available.
> +
> +For this purpose, a list of features can be specified for a struct type.
> +This is exposed to the client as a list of string, where each string
> +signals that this build of QEMU shows a certain behaviour.
> +
> +In the schema, features can be specified as simple strings, for example:
> +
> +{ 'struct': 'TestType',
> +  'data': { 'number': 'int' },
> +  'features': [ 'allow-negative-numbers' ] }
> +
> +Another option is to specify features as dictionaries, where the key
> +'name' specifies the feature string to be exposed to clients:
> +
> +{ 'struct': 'TestType',
> +  'data': { 'number': 'int' },
> +  'features': [ { 'name': 'allow-negative-numbers' } ] }
> +
> +This expanded form is necessary if you want to make the feature
> +conditional (see below in "Configuring the schema").

You justify the general form with a forward reference.  I guess that's
the best you can do without reorganizing the document.  Let's worry
about that later.

> +
> +
>  === Downstream extensions ===
>  
>  QAPI schema names that are externally visible, say in the Client JSON
> @@ -771,6 +799,16 @@ Example: a conditional 'bar' enum member.
   Example: a conditional 'bar' enum member.

   { 'enum': 'IfEnum', 'data':
>[ 'foo',
>  { 'name' : 'bar', 'if': 'defined(IFCOND)' } ] }
>  
> +Similarly, features can be specified as a dictionary with a 'name' and
> +an 'if' key.
> +
> +Example: a conditional 'allow-negative-numbers' feature
> +
> +{ 'struct': 'TestType',
> +  'data': { 'number': 'int' },
> +  'features': [ { 'name': 'allow-negative-numbers',
> +  'if' 'defined(IFCOND)' } ] }
> +

Note the structure of enum's 'data' is identical to struct's 'features'.
We'll get back to that below.

>  Please note that you are responsible to ensure that 

Re: [Qemu-devel] [PATCH 4/4] file-posix: Add dynamic-auto-read-only QAPI feature

2019-04-18 Thread Markus Armbruster
Kevin Wolf  writes:

> In commit 23dece19da4 ('file-posix: Make auto-read-only dynamic') ,
> auto-read-only=on changed its behaviour in file-posix for the 4.0
> release. This change cannot be detected through the usual mechanisms
> like schema introspection. Add a new feature flag to the schema to
> allow libvirt to detect the presence of the new behaviour.
>
> Signed-off-by: Kevin Wolf 
> ---
>  qapi/block-core.json | 11 ++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/qapi/block-core.json b/qapi/block-core.json
> index 7ccbfff9d0..4f96d5846b 100644
> --- a/qapi/block-core.json
> +++ b/qapi/block-core.json
> @@ -2843,6 +2843,13 @@
   ##
   # @BlockdevOptionsFile:
   #
   # Driver specific block device options for the file backend.
   #
   # @filename:path to the image file
   # @pr-manager:  the id for the object that will handle persistent 
reservations
   #   for this device (default: none, forward the commands via 
SG_IO;
   #   since 2.11)
   # @aio: AIO backend (default: threads) (since: 2.8)
   # @locking: whether to enable file locking. If set to 'auto', only enable
   #   when Open File Descriptor (OFD) locking API is available
   #   (default: auto, since 2.10)
   # @drop-cache:  invalidate page cache during live migration.  This prevents
   #   stale data on the migration destination with 
cache.direct=off.
   #   Currently only supported on Linux hosts.
   #   (default: on, since: 4.0)
   # @x-check-cache-dropped: whether to check that page cache was dropped on 
live
   # migration.  May cause noticeable delays if the 
image
>  # file is large, do not use in production.
>  # (default: off) (since: 3.0)
>  #
> +# If the feature 'dynamic-auto-read-only' is present, enabled auto-read-only
> +# means that the driver will open the image read-only at first, dynamically
> +# reopen the image file read-write when the first writer is attached to the
> +# node and reopen read-only when the last writer is detached. This allows to
> +# give QEMU write permissions only on demand when an operation actually needs
> +# write access.
> +#
>  # Since: 2.9
>  ##
>  { 'struct': 'BlockdevOptionsFile',
> @@ -2852,7 +2859,9 @@
>  '*aio': 'BlockdevAioOptions',
>   '*drop-cache': {'type': 'bool',
>   'if': 'defined(CONFIG_LINUX)'},
> -'*x-check-cache-dropped': 'bool' } }
> +'*x-check-cache-dropped': 'bool' },
> +  'features': [ { 'name': 'dynamic-auto-read-only',
> +  'if': 'defined(CONFIG_POSIX)' } ] }
>  
>  ##
>  # @BlockdevOptionsNull:

This uses free-form text to document features.  That means the doc
generator can't flag missing documentation, like it could for members
(it doesn't only because we still got doc work to do there).

A more structured approach could look like this:

   ##
   # @BlockdevOptionsFile:
   #
   # Driver specific block device options for the file backend.
   #
   # @filename:path to the image file
   [More members...]
   #
   # Features:
   # @dynamic-read-only: if present, enabled auto-read-only ...
   #
   # Since: 2.9
   ##



[Qemu-devel] [Bug 1818367] Re: Initialization of device cfi.pflash01 failed: Block node is read-only

2019-04-18 Thread José Pekkarinen
seems to be piece of true on Phil's comments, as extracting the command
on the log and executing it manually the result is the following:

2019-04-18T19:37:49.685841Z qemu-system-x86_64: -object
secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-6-os-1
/master-key.aes: Unable to read /var/lib/libvirt/qemu/domain-6-os-1
/master-key.aes: Failed to open file
“/var/lib/libvirt/qemu/domain-6-os-1/master-key.aes”: No such file or
directory

unless those folders with master keys are dinamically genreated and
trashed after execution it would be worthy to involve here libvirt
project as well.

José.

** Also affects: libvirt
   Importance: Undecided
   Status: New

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

Title:
  Initialization of device cfi.pflash01 failed: Block node is read-only

Status in libvirt:
  New
Status in QEMU:
  New

Bug description:
  Hi,

  I have several vms defined in libvirt using ovmf for uefi, since a later
  update of my server I'm unable to start any of the domains defined. This is
  an example of the output given:

  # virsh start os-1
  error: Failed to start domain os-1
  error: internal error: qemu unexpectedly closed the monitor: 
2019-03-02T21:23:51.726446Z qemu-system-x86_64: Initialization of device 
cfi.pflash01 failed: Block node is read-only

  an example of domain is like this:

 


 
os-1   


 
34c41008-ab91-483b-959c-81a7a12ae9be   


 
8388608 


 
8388608   


 
 


 



 



 
4  


 



 
  hvm   


 
  /var/lib/libvirt/qemu/nvram/os-1-ovmf.fd   


 
   


 



 

Re: [Qemu-devel] [PATCH 1/3] qemu-img: Allow rebase with no input base

2019-04-18 Thread Eric Blake
On 7/13/18 6:14 AM, Max Reitz wrote:
> Currently, you cannot add a backing file to an image when it currently
> has none.  It is really simple to allow this, though (effectively by
> setting old_backing_size to 0), so this patch does just that.

Can't you do that with 'rebase -u'? I guess the point of this patch is
to make 'rebase' without -u also able to add a backing file?  A bit more
clarity in the commit message, such as a sample command line (and
possibly even the error it issued pre-patch) would help.

> 
> Signed-off-by: Max Reitz 
> ---
>  qemu-img.c | 61 ++
>  1 file changed, 34 insertions(+), 27 deletions(-)

At any rate, the code looks fine, even if the diff is harder to read
because of added indentation.

Reviewed-by: Eric Blake 

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH 2/3] qemu-img: Use zero writes after source backing EOF

2019-04-18 Thread Eric Blake
On 7/13/18 6:14 AM, Max Reitz wrote:
> Past the end of the source backing file, we memset() buf_old to zero, so
> it is clearly easy to use blk_pwrite_zeroes() instead of blk_pwrite()
> then.
> 
> Signed-off-by: Max Reitz 
> ---
>  qemu-img.c | 11 +--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 

> @@ -3458,8 +3461,12 @@ static int img_rebase(int argc, char **argv)
>  if (compare_buffers(buf_old + written, buf_new + written,
>  n - written, ))
>  {
> -ret = blk_pwrite(blk, offset + written,
> - buf_old + written, pnum, 0);
> +if (buf_old_is_zero) {
> +ret = blk_pwrite_zeroes(blk, offset + written, pnum, 
> 0);

Should we allow BDRV_REQ_MAY_UNMAP here, either unconditionally, or
based on a command line knob that told us whether the user is more
interested in a sparse result (that still reads as zero) vs. a
fully-allocated result?

Reviewed-by: Eric Blake 

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



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [Bug 1825359] Re: cpu_ld*_code() triggers MMU_DATA_LOAD i.s.o. MMU_INST_FETCH

2019-04-18 Thread Shahab Vahedi
This patch has fixed for me both issues. Although I am not very proud of
the changes in the second hunk. Please let me know if there is a better
way.


** Patch added: "respect address type for tlb_fill() and while using the 
address from "tlb_entry""
   
https://bugs.launchpad.net/qemu/+bug/1825359/+attachment/5256796/+files/bug1825359_io_readx.patch

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

Title:
  cpu_ld*_code() triggers MMU_DATA_LOAD i.s.o. MMU_INST_FETCH

Status in QEMU:
  Confirmed

Bug description:
  commit 377b155bde451d5ac545fbdcdfbf6ca17a4228f5
  Merge: c876180938 328eb60dc1
  Author: Peter Maydell ; masked for anti-spamming purposes
  Date:   Mon Mar 11 18:26:37 2019 +
  https://github.com/qemu/qemu/commit/377b155bde451d5ac545fbdcdfbf6ca17a4228f5
  --

  cpu_ld*_code() is used for loading code data as the name suggests. Although, 
it begins accessing memory with MMU_INST_FETCH access type, somewhere down
  the road, when the "io_readx(..., access_type=MMU_INST_FETCH, ...)" is
  called, it is ignoring this "access_type" while calling the "tlb_fill()"
  with a _hardcoded_ MMU_DATA_LOAD:

  cputlb.c
  
  static uint64_t io_readx(..., MMUAccessType access_type, ...)
  {

  if (recheck) {
  CPUTLBEntry *entry;
  target_ulong tlb_addr;

  tlb_fill(cpu, addr, size, MMU_DATA_LOAD, mmu_idx, retaddr);
  ...
  }
  

  This is an issue, because there can exist _small_ regions of memory (smaller
  than the TARGET_PAGE_SIZE) that are only executable and not readable.

  TL;DR

  What happens is at first, a "tlb_fill(..., access_type=MMU_INST_FETCH, ...)"
  is triggered by "tb_lookup_cpu_state()". To be precise, this is the call
  stack which is good behavior:
  ---
  #0  tlb_fill (cs=..., vaddr=684, size=0, access_type=MMU_INST_FETCH, 
mmu_idx=0, retaddr=0) at target/arc/mmu.c:602
  #1  get_page_addr_code (env=..., addr=684) at accel/tcg/cputlb.c:1045
  #2  tb_htable_lookup (cpu=..., pc=684, cs_base=0, flags=0, 
cf_mask=4278190080) at accel/tcg/cpu-exec.c:337
  #3  tb_lookup__cpu_state (cpu=..., pc=..., cs_base=..., flags=..., 
cf_mask=4278190080) at include/exec/tb-lookup.h:43
  #4  tb_find (cpu=..., last_tb=... , tb_exit=0, 
cf_mask=0) at accel/tcg/cpu-exec.c:404
  #5  cpu_exec (cpu=...) at accel/tcg/cpu-exec.c:729
  #6  tcg_cpu_exec (cpu=...) at cpus.c:1430
  #7  qemu_tcg_rr_cpu_thread_fn (arg=...) at cpus.c:1531
  #8  qemu_thread_start (args=...) at util/qemu-thread-posix.c:502
  ---

  After this call, TLB is filled with an entry that its size field is small,
  say 32 bytes. This causes a TLB_RECHECK for consequent memory accesses, which 
  is logical. However, in our decoder, we use cpu_lduw_code() to read the
  instructions and decode them. As mentioned, in the beginning, the
  access_type=MMU_INST_FETCH is lost in "io_readx()" while calling tlb_fill()",
  and now THIS CAUSES A GUEST EXCEPTION BECAUSE THAT REGION IS NOT ALLOWED TO
  BE READ. Here, comes that trace call of the _bad_ behavior:
  ---
  #0  tlb_fill (..., access_type=MMU_DATA_LOAD, ...) at target/arc/mmu.c:605
  #1  io_readx (..., access_type=MMU_INST_FETCH, size=2) at 
accel/tcg/cputlb.c:881
  #2  io_readw (..., access_type=MMU_INST_FETCH) at 
accel/tcg/softmmu_template.h:106
  #3  helper_le_ldw_cmmu (..., oi=16, retaddr=0) at 
accel/tcg/softmmu_template.h:146
  #4  cpu_lduw_code_ra (env=..., ptr=684, retaddr=0) at 
include/exec/cpu_ldst_template.h:102
  #5  cpu_lduw_code (env=..., ptr=684) at include/exec/cpu_ldst_template.h:114
  #6  read_and_decode_context (ctx=..., opcode_p=...) at 
target/arc/arc-decoder.c:1479
  #7  arc_decode (ctx=...) at target/arc/arc-decoder.c:1736
  #8  decode_opc (env=..., ctx=...) at target/arc/translate.c:313
  #9  arc_tr_translate_insn (dcbase=..., cpu=...) at target/arc/translate.c:335
  #10 translator_loop (.. ) at accel/tcg/translator.c:107
  #11 gen_intermediate_code (cpu=..., tb=... ) at 
target/arc/translate.c:413
  #12 tb_gen_code (cpu=..., pc=684, cs_base=0, flags=0, cflags=-16711679) at 
accel/tcg/translate-all.c:1723
  #13 tb_find (cpu=..., last_tb=... , tb_exit=0, 
cf_mask=0) at accel/tcg/cpu-exec.c:407
  #14 cpu_exec (cpu=...) at accel/tcg/cpu-exec.c:729
  #15 tcg_cpu_exec (cpu=...) at cpus.c:1430

  ---

  Do you confirm if this is an issue? Maybe there are other ways to read
  an instruction with MMU_INST_FETCH access that I don't know about.

  Last but not least, although this is not a security issue for QEMU per
  se, but it is hindering a security feature for the guest.

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



[Qemu-devel] [Bug 1825359] Re: cpu_ld*_code() triggers MMU_DATA_LOAD i.s.o. MMU_INST_FETCH

2019-04-18 Thread Shahab Vahedi
** Patch removed: "bug1825359_io_readx.patch"
   
https://bugs.launchpad.net/qemu/+bug/1825359/+attachment/5256724/+files/bug1825359_io_readx.patch

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

Title:
  cpu_ld*_code() triggers MMU_DATA_LOAD i.s.o. MMU_INST_FETCH

Status in QEMU:
  Confirmed

Bug description:
  commit 377b155bde451d5ac545fbdcdfbf6ca17a4228f5
  Merge: c876180938 328eb60dc1
  Author: Peter Maydell ; masked for anti-spamming purposes
  Date:   Mon Mar 11 18:26:37 2019 +
  https://github.com/qemu/qemu/commit/377b155bde451d5ac545fbdcdfbf6ca17a4228f5
  --

  cpu_ld*_code() is used for loading code data as the name suggests. Although, 
it begins accessing memory with MMU_INST_FETCH access type, somewhere down
  the road, when the "io_readx(..., access_type=MMU_INST_FETCH, ...)" is
  called, it is ignoring this "access_type" while calling the "tlb_fill()"
  with a _hardcoded_ MMU_DATA_LOAD:

  cputlb.c
  
  static uint64_t io_readx(..., MMUAccessType access_type, ...)
  {

  if (recheck) {
  CPUTLBEntry *entry;
  target_ulong tlb_addr;

  tlb_fill(cpu, addr, size, MMU_DATA_LOAD, mmu_idx, retaddr);
  ...
  }
  

  This is an issue, because there can exist _small_ regions of memory (smaller
  than the TARGET_PAGE_SIZE) that are only executable and not readable.

  TL;DR

  What happens is at first, a "tlb_fill(..., access_type=MMU_INST_FETCH, ...)"
  is triggered by "tb_lookup_cpu_state()". To be precise, this is the call
  stack which is good behavior:
  ---
  #0  tlb_fill (cs=..., vaddr=684, size=0, access_type=MMU_INST_FETCH, 
mmu_idx=0, retaddr=0) at target/arc/mmu.c:602
  #1  get_page_addr_code (env=..., addr=684) at accel/tcg/cputlb.c:1045
  #2  tb_htable_lookup (cpu=..., pc=684, cs_base=0, flags=0, 
cf_mask=4278190080) at accel/tcg/cpu-exec.c:337
  #3  tb_lookup__cpu_state (cpu=..., pc=..., cs_base=..., flags=..., 
cf_mask=4278190080) at include/exec/tb-lookup.h:43
  #4  tb_find (cpu=..., last_tb=... , tb_exit=0, 
cf_mask=0) at accel/tcg/cpu-exec.c:404
  #5  cpu_exec (cpu=...) at accel/tcg/cpu-exec.c:729
  #6  tcg_cpu_exec (cpu=...) at cpus.c:1430
  #7  qemu_tcg_rr_cpu_thread_fn (arg=...) at cpus.c:1531
  #8  qemu_thread_start (args=...) at util/qemu-thread-posix.c:502
  ---

  After this call, TLB is filled with an entry that its size field is small,
  say 32 bytes. This causes a TLB_RECHECK for consequent memory accesses, which 
  is logical. However, in our decoder, we use cpu_lduw_code() to read the
  instructions and decode them. As mentioned, in the beginning, the
  access_type=MMU_INST_FETCH is lost in "io_readx()" while calling tlb_fill()",
  and now THIS CAUSES A GUEST EXCEPTION BECAUSE THAT REGION IS NOT ALLOWED TO
  BE READ. Here, comes that trace call of the _bad_ behavior:
  ---
  #0  tlb_fill (..., access_type=MMU_DATA_LOAD, ...) at target/arc/mmu.c:605
  #1  io_readx (..., access_type=MMU_INST_FETCH, size=2) at 
accel/tcg/cputlb.c:881
  #2  io_readw (..., access_type=MMU_INST_FETCH) at 
accel/tcg/softmmu_template.h:106
  #3  helper_le_ldw_cmmu (..., oi=16, retaddr=0) at 
accel/tcg/softmmu_template.h:146
  #4  cpu_lduw_code_ra (env=..., ptr=684, retaddr=0) at 
include/exec/cpu_ldst_template.h:102
  #5  cpu_lduw_code (env=..., ptr=684) at include/exec/cpu_ldst_template.h:114
  #6  read_and_decode_context (ctx=..., opcode_p=...) at 
target/arc/arc-decoder.c:1479
  #7  arc_decode (ctx=...) at target/arc/arc-decoder.c:1736
  #8  decode_opc (env=..., ctx=...) at target/arc/translate.c:313
  #9  arc_tr_translate_insn (dcbase=..., cpu=...) at target/arc/translate.c:335
  #10 translator_loop (.. ) at accel/tcg/translator.c:107
  #11 gen_intermediate_code (cpu=..., tb=... ) at 
target/arc/translate.c:413
  #12 tb_gen_code (cpu=..., pc=684, cs_base=0, flags=0, cflags=-16711679) at 
accel/tcg/translate-all.c:1723
  #13 tb_find (cpu=..., last_tb=... , tb_exit=0, 
cf_mask=0) at accel/tcg/cpu-exec.c:407
  #14 cpu_exec (cpu=...) at accel/tcg/cpu-exec.c:729
  #15 tcg_cpu_exec (cpu=...) at cpus.c:1430

  ---

  Do you confirm if this is an issue? Maybe there are other ways to read
  an instruction with MMU_INST_FETCH access that I don't know about.

  Last but not least, although this is not a security issue for QEMU per
  se, but it is hindering a security feature for the guest.

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



[Qemu-devel] [Bug 1825359] Re: cpu_ld*_code() triggers MMU_DATA_LOAD i.s.o. MMU_INST_FETCH

2019-04-18 Thread Shahab Vahedi
The problem seems to be this piece of code:

cputlb.c

static uint64_t io_readx(...)
{

if (recheck) {
...

tlb_fill(cpu, addr, size, MMU_DATA_LOAD, mmu_idx, retaddr);

entry = tlb_entry(env, mmu_idx, addr);
tlb_addr = entry->addr_read;
...
}


"entry->addr_read" is indeed looking for a "reading address". in this case, it 
must look for an
"executing address", i.e. "entry->addr_code".

I see softmmu_template.h does something like this:

...
#ifdef SOFTMMU_CODE_ACCESS
#define READ_ACCESS_TYPE MMU_INST_FETCH
#define ADDR_READ addr_code
#else
#define READ_ACCESS_TYPE MMU_DATA_LOAD
#define ADDR_READ addr_read
#endif
...

WORD_TYPE helper_le_ld_name(...)
{
...
target_ulong tlb_addr = entry->ADDR_READ;
...
}


** Changed in: qemu
 Assignee: (unassigned) => Shahab Vahedi (shahab-vahedi)

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

Title:
  cpu_ld*_code() triggers MMU_DATA_LOAD i.s.o. MMU_INST_FETCH

Status in QEMU:
  Confirmed

Bug description:
  commit 377b155bde451d5ac545fbdcdfbf6ca17a4228f5
  Merge: c876180938 328eb60dc1
  Author: Peter Maydell ; masked for anti-spamming purposes
  Date:   Mon Mar 11 18:26:37 2019 +
  https://github.com/qemu/qemu/commit/377b155bde451d5ac545fbdcdfbf6ca17a4228f5
  --

  cpu_ld*_code() is used for loading code data as the name suggests. Although, 
it begins accessing memory with MMU_INST_FETCH access type, somewhere down
  the road, when the "io_readx(..., access_type=MMU_INST_FETCH, ...)" is
  called, it is ignoring this "access_type" while calling the "tlb_fill()"
  with a _hardcoded_ MMU_DATA_LOAD:

  cputlb.c
  
  static uint64_t io_readx(..., MMUAccessType access_type, ...)
  {

  if (recheck) {
  CPUTLBEntry *entry;
  target_ulong tlb_addr;

  tlb_fill(cpu, addr, size, MMU_DATA_LOAD, mmu_idx, retaddr);
  ...
  }
  

  This is an issue, because there can exist _small_ regions of memory (smaller
  than the TARGET_PAGE_SIZE) that are only executable and not readable.

  TL;DR

  What happens is at first, a "tlb_fill(..., access_type=MMU_INST_FETCH, ...)"
  is triggered by "tb_lookup_cpu_state()". To be precise, this is the call
  stack which is good behavior:
  ---
  #0  tlb_fill (cs=..., vaddr=684, size=0, access_type=MMU_INST_FETCH, 
mmu_idx=0, retaddr=0) at target/arc/mmu.c:602
  #1  get_page_addr_code (env=..., addr=684) at accel/tcg/cputlb.c:1045
  #2  tb_htable_lookup (cpu=..., pc=684, cs_base=0, flags=0, 
cf_mask=4278190080) at accel/tcg/cpu-exec.c:337
  #3  tb_lookup__cpu_state (cpu=..., pc=..., cs_base=..., flags=..., 
cf_mask=4278190080) at include/exec/tb-lookup.h:43
  #4  tb_find (cpu=..., last_tb=... , tb_exit=0, 
cf_mask=0) at accel/tcg/cpu-exec.c:404
  #5  cpu_exec (cpu=...) at accel/tcg/cpu-exec.c:729
  #6  tcg_cpu_exec (cpu=...) at cpus.c:1430
  #7  qemu_tcg_rr_cpu_thread_fn (arg=...) at cpus.c:1531
  #8  qemu_thread_start (args=...) at util/qemu-thread-posix.c:502
  ---

  After this call, TLB is filled with an entry that its size field is small,
  say 32 bytes. This causes a TLB_RECHECK for consequent memory accesses, which 
  is logical. However, in our decoder, we use cpu_lduw_code() to read the
  instructions and decode them. As mentioned, in the beginning, the
  access_type=MMU_INST_FETCH is lost in "io_readx()" while calling tlb_fill()",
  and now THIS CAUSES A GUEST EXCEPTION BECAUSE THAT REGION IS NOT ALLOWED TO
  BE READ. Here, comes that trace call of the _bad_ behavior:
  ---
  #0  tlb_fill (..., access_type=MMU_DATA_LOAD, ...) at target/arc/mmu.c:605
  #1  io_readx (..., access_type=MMU_INST_FETCH, size=2) at 
accel/tcg/cputlb.c:881
  #2  io_readw (..., access_type=MMU_INST_FETCH) at 
accel/tcg/softmmu_template.h:106
  #3  helper_le_ldw_cmmu (..., oi=16, retaddr=0) at 
accel/tcg/softmmu_template.h:146
  #4  cpu_lduw_code_ra (env=..., ptr=684, retaddr=0) at 
include/exec/cpu_ldst_template.h:102
  #5  cpu_lduw_code (env=..., ptr=684) at include/exec/cpu_ldst_template.h:114
  #6  read_and_decode_context (ctx=..., opcode_p=...) at 
target/arc/arc-decoder.c:1479
  #7  arc_decode (ctx=...) at target/arc/arc-decoder.c:1736
  #8  decode_opc (env=..., ctx=...) at target/arc/translate.c:313
  #9  arc_tr_translate_insn (dcbase=..., cpu=...) at target/arc/translate.c:335
  #10 translator_loop (.. ) at accel/tcg/translator.c:107
  #11 gen_intermediate_code (cpu=..., tb=... ) at 
target/arc/translate.c:413
  #12 tb_gen_code (cpu=..., pc=684, cs_base=0, flags=0, cflags=-16711679) at 
accel/tcg/translate-all.c:1723
  #13 tb_find (cpu=..., last_tb=... , tb_exit=0, 
cf_mask=0) at accel/tcg/cpu-exec.c:407
  #14 cpu_exec (cpu=...) at accel/tcg/cpu-exec.c:729
  #15 tcg_cpu_exec (cpu=...) at cpus.c:1430

  ---

  Do you confirm if this is an issue? Maybe there are 

Re: [Qemu-devel] [PATCH v5 1/6] libnvdimm: nd_region flush callback support

2019-04-18 Thread Dan Williams
On Thu, Apr 18, 2019 at 9:18 AM Christoph Hellwig  wrote:
>
> On Thu, Apr 18, 2019 at 09:05:05AM -0700, Dan Williams wrote:
> > > > I'd either add a comment about avoiding retpoline overhead here or just
> > > > make ->flush == NULL mean generic_nvdimm_flush(). Just so that people 
> > > > don't
> > > > get confused by the code.
> > >
> > > Isn't this premature optimization?  I really don't like adding things
> > > like this without some numbers to show it's worth it.
> >
> > I don't think it's premature given this optimization technique is
> > already being deployed elsewhere, see:
> >
> > https://lwn.net/Articles/774347/
>
> For one this one was backed by numbers, and second after feedback
> from Linux we switched to the NULL pointer check instead.

Ok I should have noticed the switch to NULL pointer check. However,
the question still stands do we want everyone to run numbers to
justify this optimization, or make it a new common kernel coding
practice to do:

if (!object->op)
generic_op(object);
else
object->op(object);

...in hot paths? I agree with not doing premature optimization in
principle, but this hack is minimally intrusive from a readability
perspective similar to likely()/unlikely() usage which also don't come
with numbers on a per patch basis.



Re: [Qemu-devel] curses.c: "We need a terminal output" ?

2019-04-18 Thread Joachim Durchholz

Am 18.04.19 um 13:02 schrieb Laszlo Ersek:

On 04/18/19 07:02, Joachim Durchholz wrote:

Am 17.04.19 um 20:27 schrieb Laszlo Ersek:

So, let's look at your original question again (which was not a problem
statement):


So you need an explicit problem statement to know that somebody might
have a problem?


You're on a technical mailing list. An explicit problem statement is
instrumental for subscribers to understand the particulars of the
problem.


Yeah okay, another person who prefers to dismiss points raised on the 
basis of formalities.
The technical term for that behaviour is "passive-aggressive behaviour", 
and I have seen enough of that.


As I said, I have stayed to answer questions that show genuine interest 
- that's not the case, so I'm off.


/logoff



[Qemu-devel] [PATCH for-QEMU-4.1 v5 29/29] hw/arm: Remove hard-enablement of the remaining PCI devices

2019-04-18 Thread Thomas Huth
The PCI devices should be pulled in by default if PCI_DEVICES
is set, so there is no need anymore to enforce them in the configs
file.

Signed-off-by: Thomas Huth 
---
 default-configs/arm-softmmu.mak | 8 
 1 file changed, 8 deletions(-)

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 233937f394..f23ecfd5c5 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -36,14 +36,6 @@ CONFIG_DIGIC=y
 CONFIG_SABRELITE=y
 CONFIG_EMCRAFT_SF2=y
 CONFIG_MICROBIT=y
-
-CONFIG_VGA=y
-
 CONFIG_FSL_IMX25=y
 CONFIG_FSL_IMX7=y
 CONFIG_FSL_IMX6UL=y
-
-CONFIG_PCIE_PORT=y
-CONFIG_XIO3130=y
-CONFIG_IOH3420=y
-CONFIG_I82801B11=y
-- 
2.21.0




[Qemu-devel] [PATCH for-QEMU-4.1 v5 14/29] hw/arm: Express dependencies of collie with Kconfig

2019-04-18 Thread Thomas Huth
Add Kconfig dependencies for the Strongarm collie machine.
This patch is based on earlier work by Ákos Kovács (i.e.
his "hw/arm/Kconfig: Add ARM Kconfig" patch).

Signed-off-by: Thomas Huth 
---
 default-configs/arm-softmmu.mak | 3 +--
 hw/arm/Kconfig  | 7 +++
 hw/arm/Makefile.objs| 2 +-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index af78e7c892..25e8f717ac 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -25,6 +25,7 @@ CONFIG_GUMSTIX=y
 CONFIG_SPITZ=y
 CONFIG_TOSA=y
 CONFIG_Z2=y
+CONFIG_COLLIE=y
 
 CONFIG_VGA=y
 CONFIG_TMP421=y
@@ -97,5 +98,3 @@ CONFIG_GPIO_KEY=y
 CONFIG_MSF2=y
 CONFIG_FW_CFG_DMA=y
 CONFIG_PCI_EXPRESS_DESIGNWARE=y
-
-CONFIG_STRONGARM=y
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index 785e383411..325133c129 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -168,6 +168,13 @@ config STELLARIS
 
 config STRONGARM
 bool
+select PXA2XX
+
+config COLLIE
+bool
+select PFLASH_CFI01
+select ZAURUS  # scoop
+select STRONGARM
 
 config SX1
 bool
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
index 00328d1b0b..729e711b87 100644
--- a/hw/arm/Makefile.objs
+++ b/hw/arm/Makefile.objs
@@ -17,7 +17,7 @@ obj-$(CONFIG_TOSA) += tosa.o
 obj-$(CONFIG_Z2) += z2.o
 obj-$(CONFIG_REALVIEW) += realview.o
 obj-$(CONFIG_STELLARIS) += stellaris.o
-obj-$(CONFIG_STRONGARM) += collie.o
+obj-$(CONFIG_COLLIE) += collie.o
 obj-$(CONFIG_VERSATILE) += versatilepb.o
 obj-$(CONFIG_VEXPRESS) += vexpress.o
 obj-$(CONFIG_ZYNQ) += xilinx_zynq.o
-- 
2.21.0




[Qemu-devel] [PATCH for-QEMU-4.1 v5 28/29] hw/arm: Express dependencies of the musca machines with Kconfig

2019-04-18 Thread Thomas Huth
Dependencies have been determined with trial-and-error and by
looking at the musca.c source file.

Signed-off-by: Thomas Huth 
---
 hw/arm/Kconfig | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index 22be1e1231..eca8387050 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -75,6 +75,12 @@ config MAINSTONE
 select PFLASH_CFI01
 select SMC91C111
 
+config MUSCA
+bool
+select ARMSSE
+select PL011
+select PL031
+
 config MUSICPAL
 bool
 select BITBANG_I2C
@@ -423,6 +429,3 @@ config ARMSSE_CPUID
 
 config ARMSSE_MHU
 bool
-
-config MUSCA
-bool
-- 
2.21.0




[Qemu-devel] [PATCH for-QEMU-4.1 v5 27/29] hw/arm: Express dependencies of the xlnx-versal-virt machine with Kconfig

2019-04-18 Thread Thomas Huth
Dependencies have been determined with trial-and-error and by
looking at the xlnx-versal.c source file.

Signed-off-by: Thomas Huth 
---
 hw/arm/Kconfig | 4 
 1 file changed, 4 insertions(+)

diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index 32e4cc50e5..22be1e1231 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -291,6 +291,10 @@ config XLNX_ZYNQMP_ARM
 
 config XLNX_VERSAL
 bool
+select ARM_GIC
+select PL011
+select CADENCE
+select VIRTIO_MMIO
 
 config FSL_IMX25
 bool
-- 
2.21.0




[Qemu-devel] [PATCH for-QEMU-4.1 v5 20/29] hw/arm: Express dependencies of the raspi machines with Kconfig

2019-04-18 Thread Thomas Huth
Most of the code is directly controlled by the CONFIG_RASPI switch,
so not much to add here additionally.

Signed-off-by: Thomas Huth 
---
 default-configs/arm-softmmu.mak | 4 +---
 hw/arm/Kconfig  | 3 +++
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 31d31d3f4a..22bff20b32 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -31,15 +31,13 @@ CONFIG_COLLIE=y
 CONFIG_ASPEED_SOC=y
 CONFIG_NETDUINO2=y
 CONFIG_MPS2=y
+CONFIG_RASPI=y
 
 CONFIG_VGA=y
 CONFIG_SSI_M25P80=y
 CONFIG_IMX_FEC=y
 
-CONFIG_FRAMEBUFFER=y
-
 CONFIG_DIGIC=y
-CONFIG_RASPI=y
 CONFIG_NRF51_SOC=y
 
 CONFIG_FSL_IMX6=y
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index 466b143fdf..e68a29ca2b 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -257,6 +257,9 @@ config ALLWINNER_A10
 
 config RASPI
 bool
+select FRAMEBUFFER
+select PL011 # UART
+select SDHCI
 
 config STM32F205_SOC
 bool
-- 
2.21.0




[Qemu-devel] [PATCH for-QEMU-4.1 v5 22/29] hw/arm: Express dependencies of sabrelite with Kconfig

2019-04-18 Thread Thomas Huth
Add Kconfig dependencies for the Sabrelite / iMX6 machine.

Signed-off-by: Thomas Huth 
---
 default-configs/arm-softmmu.mak | 4 +---
 hw/arm/Kconfig  | 7 +++
 hw/arm/Makefile.objs| 3 ++-
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 76508e3910..ef7dd7156a 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -33,6 +33,7 @@ CONFIG_NETDUINO2=y
 CONFIG_MPS2=y
 CONFIG_RASPI=y
 CONFIG_DIGIC=y
+CONFIG_SABRELITE=y
 
 CONFIG_VGA=y
 CONFIG_SSI_M25P80=y
@@ -40,13 +41,10 @@ CONFIG_IMX_FEC=y
 
 CONFIG_NRF51_SOC=y
 
-CONFIG_FSL_IMX6=y
 CONFIG_FSL_IMX25=y
 CONFIG_FSL_IMX7=y
 CONFIG_FSL_IMX6UL=y
 
-CONFIG_IMX_I2C=y
-
 CONFIG_PCIE_PORT=y
 CONFIG_XIO3130=y
 CONFIG_IOH3420=y
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index 059fb8282c..065c7acf1b 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -177,6 +177,10 @@ config REALVIEW
 select DS1338 # I2C RTC+NVRAM
 select USB_OHCI
 
+config SABRELITE
+bool
+select FSL_IMX6
+
 config STELLARIS
 bool
 select ARM_V7M
@@ -289,6 +293,9 @@ config FSL_IMX31
 
 config FSL_IMX6
 bool
+select A9MPCORE
+select IMX
+select IMX_I2C
 
 config ASPEED_SOC
 bool
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
index 4f591ca487..fadd69882c 100644
--- a/hw/arm/Makefile.objs
+++ b/hw/arm/Makefile.objs
@@ -22,6 +22,7 @@ obj-$(CONFIG_COLLIE) += collie.o
 obj-$(CONFIG_VERSATILE) += versatilepb.o
 obj-$(CONFIG_VEXPRESS) += vexpress.o
 obj-$(CONFIG_ZYNQ) += xilinx_zynq.o
+obj-$(CONFIG_SABRELITE) += sabrelite.o
 
 obj-$(CONFIG_ARM_V7M) += armv7m.o
 obj-$(CONFIG_EXYNOS4) += exynos4210.o
@@ -36,7 +37,7 @@ obj-$(CONFIG_XLNX_ZYNQMP_ARM) += xlnx-zynqmp.o xlnx-zcu102.o
 obj-$(CONFIG_XLNX_VERSAL) += xlnx-versal.o xlnx-versal-virt.o
 obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o imx25_pdk.o
 obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o
-obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o sabrelite.o
+obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o
 obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o
 obj-$(CONFIG_MPS2) += mps2.o
 obj-$(CONFIG_MPS2) += mps2-tz.o
-- 
2.21.0




[Qemu-devel] [PATCH for-QEMU-4.1 v5 18/29] hw/arm: Express dependencies of allwinner / cubieboard with Kconfig

2019-04-18 Thread Thomas Huth
Add dependencies for the Cubitech Cubieboard.

Signed-off-by: Thomas Huth 
---
 default-configs/arm-softmmu.mak | 6 +-
 hw/arm/Kconfig  | 9 +
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index c86a9f5427..a0b9016e3a 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -7,6 +7,7 @@ CONFIG_ARM_V7M=y
 # CONFIG_TEST_DEVICES=n
 
 CONFIG_ARM_VIRT=y
+CONFIG_CUBIEBOARD=y
 CONFIG_EXYNOS4=y
 CONFIG_HIGHBANK=y
 CONFIG_INTEGRATOR=y
@@ -32,7 +33,6 @@ CONFIG_NETDUINO2=y
 
 CONFIG_VGA=y
 CONFIG_SSI_M25P80=y
-CONFIG_ALLWINNER_EMAC=y
 CONFIG_IMX_FEC=y
 
 CONFIG_FRAMEBUFFER=y
@@ -60,10 +60,6 @@ CONFIG_IOTKIT_SYSINFO=y
 CONFIG_ARMSSE_CPUID=y
 CONFIG_ARMSSE_MHU=y
 
-CONFIG_ALLWINNER_A10_PIT=y
-CONFIG_ALLWINNER_A10_PIC=y
-CONFIG_ALLWINNER_A10=y
-
 CONFIG_FSL_IMX6=y
 CONFIG_FSL_IMX25=y
 CONFIG_FSL_IMX7=y
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index 49306d6419..2ef5696900 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -25,6 +25,10 @@ config CHEETAH
 select OMAP
 select TSC210X
 
+config CUBIEBOARD
+bool
+select ALLWINNER_A10
+
 config DIGIC
 bool
 select PTIMER
@@ -245,6 +249,11 @@ config ARM_V7M
 
 config ALLWINNER_A10
 bool
+select AHCI
+select ALLWINNER_A10_PIT
+select ALLWINNER_A10_PIC
+select ALLWINNER_EMAC
+select SERIAL
 
 config RASPI
 bool
-- 
2.21.0




[Qemu-devel] [PATCH for-QEMU-4.1 v5 25/29] hw/arm: Express dependencies of the microbit / nrf51 machine with Kconfig

2019-04-18 Thread Thomas Huth
Add Kconfig dependencies for the NRF51 / microbit machine.

Signed-off-by: Thomas Huth 
---
 default-configs/arm-softmmu.mak | 3 +--
 hw/arm/Kconfig  | 6 ++
 hw/arm/Makefile.objs| 3 ++-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 6dc388c43e..233937f394 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -35,11 +35,10 @@ CONFIG_RASPI=y
 CONFIG_DIGIC=y
 CONFIG_SABRELITE=y
 CONFIG_EMCRAFT_SF2=y
+CONFIG_MICROBIT=y
 
 CONFIG_VGA=y
 
-CONFIG_NRF51_SOC=y
-
 CONFIG_FSL_IMX25=y
 CONFIG_FSL_IMX7=y
 CONFIG_FSL_IMX6UL=y
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index 58439c492a..708eae19e5 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -347,8 +347,14 @@ config FSL_IMX6UL
 select IMX_I2C
 select SDHCI
 
+config MICROBIT
+bool
+select NRF51_SOC
+
 config NRF51_SOC
 bool
+select I2C
+select ARM_V7M
 
 config EMCRAFT_SF2
 bool
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
index eae9f6c442..994e67dd0d 100644
--- a/hw/arm/Makefile.objs
+++ b/hw/arm/Makefile.objs
@@ -8,6 +8,7 @@ obj-$(CONFIG_EMCRAFT_SF2) += msf2-som.o
 obj-$(CONFIG_HIGHBANK) += highbank.o
 obj-$(CONFIG_INTEGRATOR) += integratorcp.o
 obj-$(CONFIG_MAINSTONE) += mainstone.o
+obj-$(CONFIG_MICROBIT) += microbit.o
 obj-$(CONFIG_MUSICPAL) += musicpal.o
 obj-$(CONFIG_NETDUINO2) += netduino2.o
 obj-$(CONFIG_NSERIES) += nseries.o
@@ -48,4 +49,4 @@ obj-$(CONFIG_ARMSSE) += armsse.o
 obj-$(CONFIG_FSL_IMX7) += fsl-imx7.o mcimx7d-sabre.o
 obj-$(CONFIG_ARM_SMMUV3) += smmu-common.o smmuv3.o
 obj-$(CONFIG_FSL_IMX6UL) += fsl-imx6ul.o mcimx6ul-evk.o
-obj-$(CONFIG_NRF51_SOC) += nrf51_soc.o microbit.o
+obj-$(CONFIG_NRF51_SOC) += nrf51_soc.o
-- 
2.21.0




[Qemu-devel] [PATCH for-QEMU-4.1 v5 16/29] hw/arm: Express dependencies of the virt machine with Kconfig

2019-04-18 Thread Thomas Huth
Dependencies have been determined by looking at hw/arm/virt.c

Signed-off-by: Thomas Huth 
---
 default-configs/arm-softmmu.mak | 11 +--
 hw/arm/Kconfig  | 19 +++
 hw/arm/Makefile.objs|  3 ++-
 3 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 2580584281..f440a2b1cd 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -6,6 +6,7 @@ CONFIG_ARM_V7M=y
 # CONFIG_PCI_DEVICES=n
 # CONFIG_TEST_DEVICES=n
 
+CONFIG_ARM_VIRT=y
 CONFIG_EXYNOS4=y
 CONFIG_HIGHBANK=y
 CONFIG_INTEGRATOR=y
@@ -32,8 +33,6 @@ CONFIG_VGA=y
 CONFIG_SSI_M25P80=y
 CONFIG_ALLWINNER_EMAC=y
 CONFIG_IMX_FEC=y
-CONFIG_PLATFORM_BUS=y
-CONFIG_VIRTIO_MMIO=y
 
 CONFIG_NETDUINO2=y
 
@@ -68,9 +67,6 @@ CONFIG_IOTKIT_SYSINFO=y
 CONFIG_ARMSSE_CPUID=y
 CONFIG_ARMSSE_MHU=y
 
-CONFIG_PCI_EXPRESS=y
-CONFIG_PCI_EXPRESS_GENERIC_BRIDGE=y
-
 CONFIG_ALLWINNER_A10_PIT=y
 CONFIG_ALLWINNER_A10_PIC=y
 CONFIG_ALLWINNER_A10=y
@@ -86,10 +82,5 @@ CONFIG_PCIE_PORT=y
 CONFIG_XIO3130=y
 CONFIG_IOH3420=y
 CONFIG_I82801B11=y
-CONFIG_ACPI=y
-CONFIG_ARM_VIRT=y
-CONFIG_SMBIOS=y
-CONFIG_GPIO_KEY=y
 CONFIG_MSF2=y
-CONFIG_FW_CFG_DMA=y
 CONFIG_PCI_EXPRESS_DESIGNWARE=y
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index abeaa54d88..4d0febf644 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -1,6 +1,24 @@
 config ARM_VIRT
 bool
+imply PCI_DEVICES
+imply TEST_DEVICES
+imply VFIO_AMD_XGBE
 imply VFIO_PLATFORM
+imply VFIO_XGMAC
+select A15MPCORE
+select ACPI
+select ARM_SMMUV3
+select GPIO_KEY
+select FW_CFG_DMA
+select PCI_EXPRESS
+select PCI_EXPRESS_GENERIC_BRIDGE
+select PFLASH_CFI01
+select PL011 # UART
+select PL031 # RTC
+select PL061 # GPIO
+select PLATFORM_BUS
+select SMBIOS
+select VIRTIO_MMIO
 
 config CHEETAH
 bool
@@ -298,6 +316,7 @@ config A9MPCORE
 
 config A15MPCORE
 bool
+select ARM_GIC
 
 config ARM11MPCORE
 bool
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
index 729e711b87..4f591ca487 100644
--- a/hw/arm/Makefile.objs
+++ b/hw/arm/Makefile.objs
@@ -1,4 +1,5 @@
-obj-y += boot.o sysbus-fdt.o
+obj-y += boot.o
+obj-$(CONFIG_PLATFORM_BUS) += sysbus-fdt.o
 obj-$(CONFIG_ARM_VIRT) += virt.o
 obj-$(CONFIG_ACPI) += virt-acpi-build.o
 obj-$(CONFIG_DIGIC) += digic_boards.o
-- 
2.21.0




Re: [Qemu-devel] [PATCH 5/6] pc-bios/s390-ccw: Clean up harmless misuse of isdigit()

2019-04-18 Thread Markus Armbruster
Thomas Huth  writes:

> On 18/04/2019 16.53, Markus Armbruster wrote:
>> atoui() and get_index() pass char values to isdigit().  With a
>> standard isdigit(), we'd get undefined behavior when the value is
>> negative.  But we're using isdigit() from pc-bios/s390-ccw/libc.h
>> here, which behaves nicely.  Clean up anyway, just to avoid setting a
>> bad example.
>> 
>> Cc: Christian Borntraeger 
>> Cc: Thomas Huth 
>> Cc: Cornelia Huck 
>> Cc: qemu-s3...@nongnu.org
>> Signed-off-by: Markus Armbruster 
>> ---
>>  pc-bios/s390-ccw/libc.c | 2 +-
>>  pc-bios/s390-ccw/menu.c | 2 +-
>>  2 files changed, 2 insertions(+), 2 deletions(-)
>> 
>> diff --git a/pc-bios/s390-ccw/libc.c b/pc-bios/s390-ccw/libc.c
>> index a786566c4c..3187923950 100644
>> --- a/pc-bios/s390-ccw/libc.c
>> +++ b/pc-bios/s390-ccw/libc.c
>> @@ -38,7 +38,7 @@ uint64_t atoui(const char *str)
>>  }
>>  
>>  while (*str) {
>> -if (!isdigit(*str)) {
>> +if (!isdigit(*(unsigned char *)str)) {
>>  break;
>>  }
>>  val = val * 10 + *str - '0';
>> diff --git a/pc-bios/s390-ccw/menu.c b/pc-bios/s390-ccw/menu.c
>> index 82a4ae6315..ce3815b201 100644
>> --- a/pc-bios/s390-ccw/menu.c
>> +++ b/pc-bios/s390-ccw/menu.c
>> @@ -134,7 +134,7 @@ static int get_index(void)
>>  
>>  /* Check for erroneous input */
>>  for (i = 0; i < len; i++) {
>> -if (!isdigit(buf[i])) {
>> +if (!isdigit((unsigned char)buf[i])) {
>>  return -1;
>>  }
>>  }
>
> FWIW, "char" is unsigned by default on s390x, so this is doing nothing.

I see.

If we decide to keep the patch, the commit message needs tweaking.
Perhaps:

atoui() and get_index() pass char values to isdigit().  With a
standard isdigit(), we'd get undefined behavior when the value is
negative.  Can't happen as char is unsigned on s390x.  Even if it
could, we're actually using isdigit() from pc-bios/s390-ccw/libc.h
here, which works fine for negative values.  Clean up anyway, just
to avoid setting a bad example.



[Qemu-devel] [PATCH for-QEMU-4.1 v5 24/29] hw/arm: Express dependencies for remaining IMX boards with Kconfig

2019-04-18 Thread Thomas Huth
IMX25, IMX7 and IMX6UL were still missing the Kconfig dependencies.

Signed-off-by: Thomas Huth 
---
 default-configs/arm-softmmu.mak |  2 --
 hw/arm/Kconfig  | 19 +++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 1455d083d8..6dc388c43e 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -37,7 +37,6 @@ CONFIG_SABRELITE=y
 CONFIG_EMCRAFT_SF2=y
 
 CONFIG_VGA=y
-CONFIG_IMX_FEC=y
 
 CONFIG_NRF51_SOC=y
 
@@ -49,4 +48,3 @@ CONFIG_PCIE_PORT=y
 CONFIG_XIO3130=y
 CONFIG_IOH3420=y
 CONFIG_I82801B11=y
-CONFIG_PCI_EXPRESS_DESIGNWARE=y
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index f5cd63860d..58439c492a 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -283,6 +283,10 @@ config XLNX_VERSAL
 
 config FSL_IMX25
 bool
+select IMX
+select IMX_FEC
+select IMX_I2C
+select DS1338
 
 config FSL_IMX31
 bool
@@ -296,6 +300,7 @@ config FSL_IMX6
 select A9MPCORE
 select IMX
 select IMX_I2C
+select SDHCI
 
 config ASPEED_SOC
 bool
@@ -321,12 +326,26 @@ config MPS2
 
 config FSL_IMX7
 bool
+imply PCI_DEVICES
+imply TEST_DEVICES
+select A15MPCORE
+select PCI
+select IMX
+select IMX_FEC
+select IMX_I2C
+select PCI_EXPRESS_DESIGNWARE
+select SDHCI
 
 config ARM_SMMUV3
 bool
 
 config FSL_IMX6UL
 bool
+select A15MPCORE
+select IMX
+select IMX_FEC
+select IMX_I2C
+select SDHCI
 
 config NRF51_SOC
 bool
-- 
2.21.0




[Qemu-devel] [PATCH for-QEMU-4.1 v5 13/29] hw/arm: Express dependencies of xilinx-zynq with Kconfig

2019-04-18 Thread Thomas Huth
Add Kconfig dependencies for the xilinx-zynq-a9 board.
This patch is based on earlier work by Ákos Kovács (i.e.
his "hw/arm/Kconfig: Add ARM Kconfig" patch).

Signed-off-by: Thomas Huth 
---
 default-configs/arm-softmmu.mak |  7 +--
 hw/arm/Kconfig  | 12 
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index f39a854f2e..af78e7c892 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -19,6 +19,7 @@ CONFIG_STELLARIS=y
 CONFIG_REALVIEW=y
 CONFIG_VERSATILE=y
 CONFIG_VEXPRESS=y
+CONFIG_ZYNQ=y
 CONFIG_MAINSTONE=y
 CONFIG_GUMSTIX=y
 CONFIG_SPITZ=y
@@ -38,16 +39,11 @@ CONFIG_VIRTIO_MMIO=y
 
 CONFIG_NETDUINO2=y
 
-CONFIG_PL330=y
-CONFIG_CADENCE=y
 CONFIG_FRAMEBUFFER=y
-CONFIG_XILINX_SPIPS=y
-CONFIG_ZYNQ_DEVCFG=y
 
 CONFIG_DIGIC=y
 CONFIG_MPS2=y
 CONFIG_RASPI=y
-CONFIG_ZYNQ=y
 CONFIG_STM32F2XX_TIMER=y
 CONFIG_STM32F2XX_USART=y
 CONFIG_STM32F2XX_SYSCFG=y
@@ -100,7 +96,6 @@ CONFIG_SMBUS_EEPROM=y
 CONFIG_GPIO_KEY=y
 CONFIG_MSF2=y
 CONFIG_FW_CFG_DMA=y
-CONFIG_XILINX_AXI=y
 CONFIG_PCI_EXPRESS_DESIGNWARE=y
 
 CONFIG_STRONGARM=y
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index 101de74260..785e383411 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -201,6 +201,18 @@ config VEXPRESS
 
 config ZYNQ
 bool
+select A9MPCORE
+select CADENCE # UART
+select PFLASH_CFI02
+select PL330
+select SDHCI
+select SSI_M25P80
+select USB_EHCI_SYSBUS
+select XILINX # UART
+select XILINX_AXI
+select XILINX_SPI
+select XILINX_SPIPS
+select ZYNQ_DEVCFG
 
 config ARM_V7M
 bool
-- 
2.21.0




[Qemu-devel] [PATCH for-QEMU-4.1 v5 07/29] hw/arm: Express dependencies of the fsl-imx31 machine with Kconfig

2019-04-18 Thread Thomas Huth
Add Kconfig dependencies for the fsl-imx31 / kzm machine.
This patch is slightly based on earlier work by Ákos Kovács (i.e.
his "hw/arm/Kconfig: Add ARM Kconfig" patch).

Signed-off-by: Thomas Huth 
---
 default-configs/arm-softmmu.mak | 3 +--
 hw/arm/Kconfig  | 4 
 hw/misc/Kconfig | 2 ++
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 6195b75f48..7f94811ccb 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -10,6 +10,7 @@ CONFIG_PCI_TESTDEV=y
 CONFIG_EXYNOS4=y
 CONFIG_HIGHBANK=y
 CONFIG_INTEGRATOR=y
+CONFIG_FSL_IMX31=y
 
 CONFIG_VGA=y
 CONFIG_NAND=y
@@ -68,7 +69,6 @@ CONFIG_TSC210X=y
 CONFIG_BLIZZARD=y
 CONFIG_ONENAND=y
 CONFIG_TUSB6010=y
-CONFIG_IMX=y
 CONFIG_MAINSTONE=y
 CONFIG_MPS2=y
 CONFIG_MUSCA=y
@@ -115,7 +115,6 @@ CONFIG_ALLWINNER_A10_PIC=y
 CONFIG_ALLWINNER_A10=y
 
 CONFIG_FSL_IMX6=y
-CONFIG_FSL_IMX31=y
 CONFIG_FSL_IMX25=y
 CONFIG_FSL_IMX7=y
 CONFIG_FSL_IMX6UL=y
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index ad3b1f9b40..9087b7d714 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -98,6 +98,10 @@ config FSL_IMX25
 
 config FSL_IMX31
 bool
+select SERIAL
+select IMX
+select IMX_I2C
+select LAN9118
 
 config FSL_IMX6
 bool
diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig
index 5f67d0d6d9..385e1b0cec 100644
--- a/hw/misc/Kconfig
+++ b/hw/misc/Kconfig
@@ -76,6 +76,8 @@ config ECCMEMCTL
 config IMX
 bool
 select PTIMER
+select SSI
+select USB_EHCI_SYSBUS
 
 config STM32F2XX_SYSCFG
 bool
-- 
2.21.0




[Qemu-devel] [PATCH for-QEMU-4.1 v5 26/29] hw/arm: Express dependencies of the ZynqMP zcu102 machine with Kconfig

2019-04-18 Thread Thomas Huth
This cleans up most settings in default-configs/aarch64-softmmu.mak.

Signed-off-by: Thomas Huth 
---
 default-configs/aarch64-softmmu.mak |  4 
 hw/arm/Kconfig  | 11 +++
 hw/display/Kconfig  |  1 +
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/default-configs/aarch64-softmmu.mak 
b/default-configs/aarch64-softmmu.mak
index 4ea9add003..3a4b15e7e8 100644
--- a/default-configs/aarch64-softmmu.mak
+++ b/default-configs/aarch64-softmmu.mak
@@ -3,10 +3,6 @@
 # We support all the 32 bit boards so need all their config
 include arm-softmmu.mak
 
-CONFIG_AUX=y
-CONFIG_DDC=y
-CONFIG_DPCD=y
-CONFIG_XLNX_ZYNQMP=y
 CONFIG_XLNX_ZYNQMP_ARM=y
 CONFIG_XLNX_VERSAL=y
 CONFIG_ARM_SMMUV3=y
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index 708eae19e5..32e4cc50e5 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -277,6 +277,17 @@ config STM32F205_SOC
 
 config XLNX_ZYNQMP_ARM
 bool
+select AHCI
+select ARM_GIC
+select CADENCE
+select DDC
+select DPCD
+select SDHCI
+select SSI
+select SSI_M25P80
+select XILINX_AXI
+select XILINX_SPIPS
+select XLNX_ZYNQMP
 
 config XLNX_VERSAL
 bool
diff --git a/hw/display/Kconfig b/hw/display/Kconfig
index 0577e68c8e..bb95f8d6a4 100644
--- a/hw/display/Kconfig
+++ b/hw/display/Kconfig
@@ -108,6 +108,7 @@ config VIRTIO_VGA
 
 config DPCD
 bool
+select AUX
 
 config ATI_VGA
 bool
-- 
2.21.0




[Qemu-devel] [PATCH for-QEMU-4.1 v5 11/29] hw/arm: Express dependencies of realview, versatile and vexpress with Kconfig

2019-04-18 Thread Thomas Huth
This patch is slightly based on earlier work by Ákos Kovács (i.e.
his "hw/arm/Kconfig: Add ARM Kconfig" patch).

Signed-off-by: Thomas Huth 
---
 default-configs/arm-softmmu.mak | 24 -
 hw/arm/Kconfig  | 48 +
 hw/arm/Makefile.objs|  3 ++-
 hw/display/Kconfig  |  1 +
 hw/i2c/Kconfig  |  2 +-
 5 files changed, 57 insertions(+), 21 deletions(-)

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 3f82d635e4..df7d9421e0 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -3,9 +3,8 @@
 # TODO: ARM_V7M is currently always required - make this more flexible!
 CONFIG_ARM_V7M=y
 
-CONFIG_PCI=y
-CONFIG_PCI_DEVICES=y
-CONFIG_PCI_TESTDEV=y
+# CONFIG_PCI_DEVICES=n
+# CONFIG_TEST_DEVICES=n
 
 CONFIG_EXYNOS4=y
 CONFIG_HIGHBANK=y
@@ -17,6 +16,9 @@ CONFIG_CHEETAH=y
 CONFIG_SX1=y
 CONFIG_NSERIES=y
 CONFIG_STELLARIS=y
+CONFIG_REALVIEW=y
+CONFIG_VERSATILE=y
+CONFIG_VEXPRESS=y
 
 CONFIG_VGA=y
 CONFIG_NAND=y
@@ -25,8 +27,6 @@ CONFIG_SERIAL=y
 CONFIG_MAX7310=y
 CONFIG_TMP421=y
 CONFIG_PCA9552=y
-CONFIG_DDC=y
-CONFIG_SII9022=y
 CONFIG_ADS7846=y
 CONFIG_MAX111X=y
 CONFIG_SSI_M25P80=y
@@ -38,13 +38,8 @@ CONFIG_MICRODRIVE=y
 CONFIG_PLATFORM_BUS=y
 CONFIG_VIRTIO_MMIO=y
 
-CONFIG_ARM11MPCORE=y
-
 CONFIG_NETDUINO2=y
 
-CONFIG_PL041=y
-CONFIG_PL080=y
-CONFIG_PL190=y
 CONFIG_PL330=y
 CONFIG_CADENCE=y
 CONFIG_PXA2XX=y
@@ -52,12 +47,10 @@ CONFIG_FRAMEBUFFER=y
 CONFIG_XILINX_SPIPS=y
 CONFIG_ZYNQ_DEVCFG=y
 
-CONFIG_ARM11SCU=y
 CONFIG_DIGIC=y
 CONFIG_MAINSTONE=y
 CONFIG_MPS2=y
 CONFIG_RASPI=y
-CONFIG_REALVIEW=y
 CONFIG_ZAURUS=y
 CONFIG_ZYNQ=y
 CONFIG_STM32F2XX_TIMER=y
@@ -86,10 +79,6 @@ CONFIG_IOTKIT_SYSINFO=y
 CONFIG_ARMSSE_CPUID=y
 CONFIG_ARMSSE_MHU=y
 
-CONFIG_VERSATILE=y
-CONFIG_VERSATILE_PCI=y
-CONFIG_VERSATILE_I2C=y
-
 CONFIG_PCI_EXPRESS=y
 CONFIG_PCI_EXPRESS_GENERIC_BRIDGE=y
 
@@ -120,6 +109,3 @@ CONFIG_XILINX_AXI=y
 CONFIG_PCI_EXPRESS_DESIGNWARE=y
 
 CONFIG_STRONGARM=y
-
-# for realview and versatilepb
-CONFIG_LSI_SCSI_PCI=y
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index b91503f5a6..b786cfc5bd 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -88,6 +88,30 @@ config PXA2XX
 
 config REALVIEW
 bool
+imply PCI_DEVICES
+imply PCI_TESTDEV
+select SMC91C111
+select LAN9118
+select A9MPCORE
+select A15MPCORE
+select ARM11MPCORE
+select ARM_TIMER
+select VERSATILE_PCI
+select WM8750 # audio codec
+select LSI_SCSI_PCI
+select PCI
+select PL011  # UART
+select PL031  # RTC
+select PL041  # audio codec
+select PL050  # keyboard/mouse
+select PL061  # GPIO
+select PL080  # DMA controller
+select PL110
+select PL181  # display
+select PL310  # cache controller
+select VERSATILE_I2C
+select DS1338 # I2C RTC+NVRAM
+select USB_OHCI
 
 config STELLARIS
 bool
@@ -111,6 +135,29 @@ config SX1
 
 config VERSATILE
 bool
+select ARM_TIMER # sp804
+select PFLASH_CFI01
+select LSI_SCSI_PCI
+select PL050  # keyboard/mouse
+select PL080  # DMA controller
+select PL190  # Vector PIC
+select REALVIEW
+select USB_OHCI
+
+config VEXPRESS
+bool
+select A9MPCORE
+select A15MPCORE
+select ARM_MPTIMER
+select ARM_TIMER # sp804
+select LAN9118
+select PFLASH_CFI01
+select PL011 # UART
+select PL041 # audio codec
+select PL181  # display
+select REALVIEW
+select SII9022
+select VIRTIO_MMIO
 
 config ZYNQ
 bool
@@ -183,6 +230,7 @@ config A15MPCORE
 
 config ARM11MPCORE
 bool
+select ARM11SCU
 
 config ARMSSE
 bool
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
index 8302b8df1d..bd0b45a799 100644
--- a/hw/arm/Makefile.objs
+++ b/hw/arm/Makefile.objs
@@ -15,7 +15,8 @@ obj-$(CONFIG_PXA2XX) += gumstix.o spitz.o tosa.o z2.o
 obj-$(CONFIG_REALVIEW) += realview.o
 obj-$(CONFIG_STELLARIS) += stellaris.o
 obj-$(CONFIG_STRONGARM) += collie.o
-obj-$(CONFIG_VERSATILE) += vexpress.o versatilepb.o
+obj-$(CONFIG_VERSATILE) += versatilepb.o
+obj-$(CONFIG_VEXPRESS) += vexpress.o
 obj-$(CONFIG_ZYNQ) += xilinx_zynq.o
 
 obj-$(CONFIG_ARM_V7M) += armv7m.o
diff --git a/hw/display/Kconfig b/hw/display/Kconfig
index a11815c9af..0577e68c8e 100644
--- a/hw/display/Kconfig
+++ b/hw/display/Kconfig
@@ -26,6 +26,7 @@ config PL110
 config SII9022
 bool
 depends on I2C
+select DDC
 
 config SSD0303
 bool
diff --git a/hw/i2c/Kconfig b/hw/i2c/Kconfig
index 820b24de5b..aee961541c 100644
--- a/hw/i2c/Kconfig
+++ b/hw/i2c/Kconfig
@@ -12,7 +12,7 @@ config DDC
 
 config VERSATILE_I2C
 bool
-select I2C
+select BITBANG_I2C
 
 config ACPI_SMBUS
 bool
-- 
2.21.0




[Qemu-devel] [PATCH for-QEMU-4.1 v5 19/29] hw/arm: Express dependencies of the MPS2 boards with Kconfig

2019-04-18 Thread Thomas Huth
Add Kconfig dependencies for the mps2-an* machines.

Signed-off-by: Thomas Huth 
---
 default-configs/arm-softmmu.mak | 20 +---
 hw/arm/Kconfig  | 18 ++
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index a0b9016e3a..31d31d3f4a 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -30,6 +30,7 @@ CONFIG_Z2=y
 CONFIG_COLLIE=y
 CONFIG_ASPEED_SOC=y
 CONFIG_NETDUINO2=y
+CONFIG_MPS2=y
 
 CONFIG_VGA=y
 CONFIG_SSI_M25P80=y
@@ -38,28 +39,9 @@ CONFIG_IMX_FEC=y
 CONFIG_FRAMEBUFFER=y
 
 CONFIG_DIGIC=y
-CONFIG_MPS2=y
 CONFIG_RASPI=y
 CONFIG_NRF51_SOC=y
 
-CONFIG_CMSDK_APB_TIMER=y
-CONFIG_CMSDK_APB_DUALTIMER=y
-CONFIG_CMSDK_APB_UART=y
-CONFIG_CMSDK_APB_WATCHDOG=y
-
-CONFIG_MPS2_FPGAIO=y
-CONFIG_MPS2_SCC=y
-
-CONFIG_TZ_MPC=y
-CONFIG_TZ_MSC=y
-CONFIG_TZ_PPC=y
-CONFIG_ARMSSE=y
-CONFIG_IOTKIT_SECCTL=y
-CONFIG_IOTKIT_SYSCTL=y
-CONFIG_IOTKIT_SYSINFO=y
-CONFIG_ARMSSE_CPUID=y
-CONFIG_ARMSSE_MHU=y
-
 CONFIG_FSL_IMX6=y
 CONFIG_FSL_IMX25=y
 CONFIG_FSL_IMX7=y
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index 2ef5696900..466b143fdf 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -301,6 +301,12 @@ config ASPEED_SOC
 
 config MPS2
 bool
+select ARMSSE
+select LAN9118
+select MPS2_FPGAIO
+select MPS2_SCC
+select PL022# Serial port
+select PL080# DMA controller
 
 config FSL_IMX7
 bool
@@ -340,6 +346,18 @@ config ARM11MPCORE
 
 config ARMSSE
 bool
+select ARMSSE_CPUID
+select ARMSSE_MHU
+select CMSDK_APB_TIMER
+select CMSDK_APB_DUALTIMER
+select CMSDK_APB_UART
+select CMSDK_APB_WATCHDOG
+select IOTKIT_SECCTL
+select IOTKIT_SYSCTL
+select IOTKIT_SYSINFO
+select TZ_MPC
+select TZ_MSC
+select TZ_PPC
 
 config ARMSSE_CPUID
 bool
-- 
2.21.0




[Qemu-devel] [PATCH for-QEMU-4.1 v5 05/29] hw/arm: Express dependencies of the highbank machines with Kconfig

2019-04-18 Thread Thomas Huth
Add Kconfig dependencies for the highbank machine (and the midway
machine).
This patch is slightly based on earlier work by Ákos Kovács (i.e.
his "hw/arm/Kconfig: Add ARM Kconfig" patch).

Signed-off-by: Thomas Huth 
---
 default-configs/arm-softmmu.mak |  9 +
 hw/arm/Kconfig  | 11 +++
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 2a11e76cc7..50a4be3cad 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -8,6 +8,7 @@ CONFIG_PCI_DEVICES=y
 CONFIG_PCI_TESTDEV=y
 
 CONFIG_EXYNOS4=y
+CONFIG_HIGHBANK=y
 
 CONFIG_VGA=y
 CONFIG_NAND=y
@@ -45,24 +46,17 @@ CONFIG_PLATFORM_BUS=y
 CONFIG_VIRTIO_MMIO=y
 
 CONFIG_ARM11MPCORE=y
-CONFIG_A15MPCORE=y
 
 CONFIG_NETDUINO2=y
 
-CONFIG_ARM_TIMER=y
-CONFIG_PL011=y
-CONFIG_PL022=y
-CONFIG_PL031=y
 CONFIG_PL041=y
 CONFIG_PL050=y
-CONFIG_PL061=y
 CONFIG_PL080=y
 CONFIG_PL110=y
 CONFIG_PL181=y
 CONFIG_PL190=y
 CONFIG_PL330=y
 CONFIG_CADENCE=y
-CONFIG_XGMAC=y
 CONFIG_PXA2XX=y
 CONFIG_BITBANG_I2C=y
 CONFIG_FRAMEBUFFER=y
@@ -150,7 +144,6 @@ CONFIG_XILINX_AXI=y
 CONFIG_PCI_EXPRESS_DESIGNWARE=y
 
 CONFIG_STRONGARM=y
-CONFIG_HIGHBANK=y
 CONFIG_MUSICPAL=y
 
 # for realview and versatilepb
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index acd07b2add..0ba377ac18 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -18,6 +18,17 @@ config EXYNOS4
 
 config HIGHBANK
 bool
+select A9MPCORE
+select A15MPCORE
+select AHCI
+select ARM_TIMER # sp804
+select ARM_V7M
+select PL011 # UART
+select PL022 # Serial port
+select PL031 # RTC
+select PL061 # GPIO
+select PL310 # cache controller
+select XGMAC # ethernet
 
 config INTEGRATOR
 bool
-- 
2.21.0




[Qemu-devel] [PATCH for-QEMU-4.1 v5 23/29] hw/arm: Express dependencies of the MSF2 / EMCRAFT_SF2 machine with Kconfig

2019-04-18 Thread Thomas Huth
Add Kconfig dependencies for the emcraft-sf2 machine - we also
distinguish between the machine (CONFIG_EMCRAFT_SF2) and the SoC
(CONFIG_MSF2) now.

Signed-off-by: Thomas Huth 
---
 default-configs/arm-softmmu.mak | 3 +--
 hw/arm/Kconfig  | 8 
 hw/arm/Makefile.objs| 3 ++-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index ef7dd7156a..1455d083d8 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -34,9 +34,9 @@ CONFIG_MPS2=y
 CONFIG_RASPI=y
 CONFIG_DIGIC=y
 CONFIG_SABRELITE=y
+CONFIG_EMCRAFT_SF2=y
 
 CONFIG_VGA=y
-CONFIG_SSI_M25P80=y
 CONFIG_IMX_FEC=y
 
 CONFIG_NRF51_SOC=y
@@ -49,5 +49,4 @@ CONFIG_PCIE_PORT=y
 CONFIG_XIO3130=y
 CONFIG_IOH3420=y
 CONFIG_I82801B11=y
-CONFIG_MSF2=y
 CONFIG_PCI_EXPRESS_DESIGNWARE=y
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index 065c7acf1b..f5cd63860d 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -331,9 +331,17 @@ config FSL_IMX6UL
 config NRF51_SOC
 bool
 
+config EMCRAFT_SF2
+bool
+select MSF2
+select SSI_M25P80
+
 config MSF2
 bool
+select ARM_V7M
 select PTIMER
+select SERIAL
+select SSI
 
 config ZAURUS
 bool
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
index fadd69882c..eae9f6c442 100644
--- a/hw/arm/Makefile.objs
+++ b/hw/arm/Makefile.objs
@@ -4,6 +4,7 @@ obj-$(CONFIG_ARM_VIRT) += virt.o
 obj-$(CONFIG_ACPI) += virt-acpi-build.o
 obj-$(CONFIG_DIGIC) += digic_boards.o
 obj-$(CONFIG_EXYNOS4) += exynos4_boards.o
+obj-$(CONFIG_EMCRAFT_SF2) += msf2-som.o
 obj-$(CONFIG_HIGHBANK) += highbank.o
 obj-$(CONFIG_INTEGRATOR) += integratorcp.o
 obj-$(CONFIG_MAINSTONE) += mainstone.o
@@ -41,7 +42,7 @@ obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o
 obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o
 obj-$(CONFIG_MPS2) += mps2.o
 obj-$(CONFIG_MPS2) += mps2-tz.o
-obj-$(CONFIG_MSF2) += msf2-soc.o msf2-som.o
+obj-$(CONFIG_MSF2) += msf2-soc.o
 obj-$(CONFIG_MUSCA) += musca.o
 obj-$(CONFIG_ARMSSE) += armsse.o
 obj-$(CONFIG_FSL_IMX7) += fsl-imx7.o mcimx7d-sabre.o
-- 
2.21.0




  1   2   3   >