[Qemu-devel] [Bug 1581936] Re: Frozen Windows 7 VMs with VGA CVE-2016-3712 fix (2.6.0 and 2.5.1.1)

2016-05-26 Thread Francis
I experience the same behavior on RHEL 7.2 since I installed the lastest
patch.

** Bug watch added: Red Hat Bugzilla #1339267
   https://bugzilla.redhat.com/show_bug.cgi?id=1339267

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

Title:
  Frozen Windows 7 VMs with VGA CVE-2016-3712 fix (2.6.0 and 2.5.1.1)

Status in QEMU:
  Confirmed

Bug description:
  Hi,

  As already posted on the QEMU devel list [1] I stumbled upon a problem
  with QEMU in version 2.5.1.1 and 2.6.0.

  the VM shows Windows loading
  files for the installation, then the "Starting Windows" screen appears
  here it hangs and never continues.

  Changing the "-vga" option to cirrus solves this, the installation can
  proceed and finish. When changing back to std (or also qxl, vmware) the
  installed VM also hangs on the "Starting Windows" screen while qemu
  showing a little but no excessive load.

  This phenomena appears also with QEMU 2.6.0 but not with 2.6.0-rc4, a
  git bisect shows fd3c136b3e1482cd0ec7285d6bc2a3e6a62c38d7 (vga: make
  sure vga register setup for vbe stays intact (CVE-2016-3712)) as the
  culprit for this regression, as its a fix for a DoS its not an option to
  just revert it, I guess.

  The bisect log is:

  git bisect start
  # bad: [bfc766d38e1fae5767d43845c15c79ac8fa6d6af] Update version for v2.6.0 
release
  git bisect bad bfc766d38e1fae5767d43845c15c79ac8fa6d6af
  # good: [975eb6a547f809608ccb08c221552f11af25] Update version for 
v2.6.0-rc4 release
  git bisect good 975eb6a547f809608ccb08c221552f11af25
  # good: [2068192dcccd8a80dddfcc8df6164cf9c26e0fc4] vga: update vga register 
setup on vbe changes
  git bisect good 2068192dcccd8a80dddfcc8df6164cf9c26e0fc4
  # bad: [53db932604dfa7bb9241d132e0173894cf54261c] Merge remote-tracking 
branch 'remotes/kraxel/tags/pull-vga-20160509-1' into staging
  git bisect bad 53db932604dfa7bb9241d132e0173894cf54261c
  # bad: [fd3c136b3e1482cd0ec7285d6bc2a3e6a62c38d7] vga: make sure vga register 
setup for vbe stays intact (CVE-2016-3712).
  git bisect bad fd3c136b3e1482cd0ec7285d6bc2a3e6a62c38d7
  # first bad commit: [fd3c136b3e1482cd0ec7285d6bc2a3e6a62c38d7] vga: make sure 
vga register setup for vbe stays intact (CVE-2016-3712).

  
  I could reproduce that with QEMU 2.5.1 and QEMU 2.6 on a Debian derivate
  (Promox VE) with 4.4 Kernel and also with QEMU 2.6 on an Arch Linux
  System with a 4.5 Kernel, so it should not be host distro depended. Both
  machines have Intel x86_64 processors.
  The problem should be reproducible with said Versions or a build from
  git including the above mentioned commit (fd3c136) by starting a VM with
  an Windows 7 ISO, e.g.:

  Freezing installation (as vga defaults to std I marked it as optional):
  ./x86_64-softmmu/qemu-system-x86_64 -boot d -cdrom win7.iso -m 1024 [-vga 
(std|qxl|vmware)]

  Working installation:
  ./x86_64-softmmu/qemu-system-x86_64 -boot d -cdrom win7.iso -m 1024 -vga 
cirrus

  If someone has already an installed Windows 7 VM this behaviour should be
  also observable when trying to start it with the new versions of QEMU.

  Noteworthy may be that Windows 10 is working, I do not had time to get
  other Windows versions and test them, I'll do that as soon as possible.
  Various Linux system also seems do work fine, at least I did not ran
  into an issue there yet.

  I also tried testing with SeaBIOS and OVMF as firmware, as initially I
  had no idea what broke, both lead to the same result - without the 
  CVE-2016-3712 fix they both work, with not.
  Further, KVM enabled and disabled does not make any difference.

  
  [1] http://lists.nongnu.org/archive/html/qemu-devel/2016-05/msg02416.html

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



[Qemu-devel] [Bug 1581936] Re: Frozen Windows 7 VMs with VGA CVE-2016-3712 fix (2.6.0 and 2.5.1.1)

2016-05-26 Thread Francis
Seem to be a RHEL/Fedora on the same issue: 
https://bugzilla.redhat.com/show_bug.cgi?id=1339267

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

Title:
  Frozen Windows 7 VMs with VGA CVE-2016-3712 fix (2.6.0 and 2.5.1.1)

Status in QEMU:
  Confirmed

Bug description:
  Hi,

  As already posted on the QEMU devel list [1] I stumbled upon a problem
  with QEMU in version 2.5.1.1 and 2.6.0.

  the VM shows Windows loading
  files for the installation, then the "Starting Windows" screen appears
  here it hangs and never continues.

  Changing the "-vga" option to cirrus solves this, the installation can
  proceed and finish. When changing back to std (or also qxl, vmware) the
  installed VM also hangs on the "Starting Windows" screen while qemu
  showing a little but no excessive load.

  This phenomena appears also with QEMU 2.6.0 but not with 2.6.0-rc4, a
  git bisect shows fd3c136b3e1482cd0ec7285d6bc2a3e6a62c38d7 (vga: make
  sure vga register setup for vbe stays intact (CVE-2016-3712)) as the
  culprit for this regression, as its a fix for a DoS its not an option to
  just revert it, I guess.

  The bisect log is:

  git bisect start
  # bad: [bfc766d38e1fae5767d43845c15c79ac8fa6d6af] Update version for v2.6.0 
release
  git bisect bad bfc766d38e1fae5767d43845c15c79ac8fa6d6af
  # good: [975eb6a547f809608ccb08c221552f11af25] Update version for 
v2.6.0-rc4 release
  git bisect good 975eb6a547f809608ccb08c221552f11af25
  # good: [2068192dcccd8a80dddfcc8df6164cf9c26e0fc4] vga: update vga register 
setup on vbe changes
  git bisect good 2068192dcccd8a80dddfcc8df6164cf9c26e0fc4
  # bad: [53db932604dfa7bb9241d132e0173894cf54261c] Merge remote-tracking 
branch 'remotes/kraxel/tags/pull-vga-20160509-1' into staging
  git bisect bad 53db932604dfa7bb9241d132e0173894cf54261c
  # bad: [fd3c136b3e1482cd0ec7285d6bc2a3e6a62c38d7] vga: make sure vga register 
setup for vbe stays intact (CVE-2016-3712).
  git bisect bad fd3c136b3e1482cd0ec7285d6bc2a3e6a62c38d7
  # first bad commit: [fd3c136b3e1482cd0ec7285d6bc2a3e6a62c38d7] vga: make sure 
vga register setup for vbe stays intact (CVE-2016-3712).

  
  I could reproduce that with QEMU 2.5.1 and QEMU 2.6 on a Debian derivate
  (Promox VE) with 4.4 Kernel and also with QEMU 2.6 on an Arch Linux
  System with a 4.5 Kernel, so it should not be host distro depended. Both
  machines have Intel x86_64 processors.
  The problem should be reproducible with said Versions or a build from
  git including the above mentioned commit (fd3c136) by starting a VM with
  an Windows 7 ISO, e.g.:

  Freezing installation (as vga defaults to std I marked it as optional):
  ./x86_64-softmmu/qemu-system-x86_64 -boot d -cdrom win7.iso -m 1024 [-vga 
(std|qxl|vmware)]

  Working installation:
  ./x86_64-softmmu/qemu-system-x86_64 -boot d -cdrom win7.iso -m 1024 -vga 
cirrus

  If someone has already an installed Windows 7 VM this behaviour should be
  also observable when trying to start it with the new versions of QEMU.

  Noteworthy may be that Windows 10 is working, I do not had time to get
  other Windows versions and test them, I'll do that as soon as possible.
  Various Linux system also seems do work fine, at least I did not ran
  into an issue there yet.

  I also tried testing with SeaBIOS and OVMF as firmware, as initially I
  had no idea what broke, both lead to the same result - without the 
  CVE-2016-3712 fix they both work, with not.
  Further, KVM enabled and disabled does not make any difference.

  
  [1] http://lists.nongnu.org/archive/html/qemu-devel/2016-05/msg02416.html

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



Re: [Qemu-devel] [PATCH v2 0/3] target/riscv: use tcg_lookup_and_goto_ptr

2018-09-04 Thread Alistair Francis
On Fri, Aug 31, 2018 at 3:22 PM, Emilio G. Cota  wrote:
> On Fri, Aug 10, 2018 at 13:39:38 -0400, Emilio G. Cota wrote:
>> Changes wrt v1: changed patch 3 as suggested by Richard. Also
>> added his R-b's.
>>
>> You can fetch this series from:
>>   https://github.com/cota/qemu/tree/riscv-lookup_ptr-v2
>
> RISC-V maintainers: any plans of picking this up for 3.1?

Thanks for CCing me.

I think Michael must be really busy, I haven't seen any activity for
awhile. I'm going to send a PR with everything that has been reviewed
and applies cleanly.

Alistair

>
> (Cc'ing Alistair since he recently submitted some riscv-related
> pull requests; BTW Alistair, should you be listed as a RISC-V
> maintainer?)
>
> Thanks,
>
> Emilio
>



[Qemu-devel] [PULL 1/9] RISC-V: Update address bits to support sv39 and sv48

2018-09-04 Thread Alistair Francis
From: Michael Clark 

Cc: Sagar Karandikar 
Cc: Bastian Koppelmann 
Cc: Palmer Dabbelt 
Cc: Alistair Francis 
Signed-off-by: Palmer Dabbelt 
Reviewed-by: Alistair Francis 
Signed-off-by: Alistair Francis 
---
 target/riscv/cpu.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index 34abc383e3..e0608e6d5f 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -24,12 +24,12 @@
 #define TARGET_PAGE_BITS 12 /* 4 KiB Pages */
 #if defined(TARGET_RISCV64)
 #define TARGET_LONG_BITS 64
-#define TARGET_PHYS_ADDR_SPACE_BITS 50
-#define TARGET_VIRT_ADDR_SPACE_BITS 39
+#define TARGET_PHYS_ADDR_SPACE_BITS 56 /* 44-bit PPN */
+#define TARGET_VIRT_ADDR_SPACE_BITS 48 /* sv48 */
 #elif defined(TARGET_RISCV32)
 #define TARGET_LONG_BITS 32
-#define TARGET_PHYS_ADDR_SPACE_BITS 34
-#define TARGET_VIRT_ADDR_SPACE_BITS 32
+#define TARGET_PHYS_ADDR_SPACE_BITS 34 /* 22-bit PPN */
+#define TARGET_VIRT_ADDR_SPACE_BITS 32 /* sv32 */
 #endif
 
 #define TCG_GUEST_DEFAULT_MO 0
-- 
2.17.1




[Qemu-devel] [PULL 0/9] riscv-pullreq queue

2018-09-04 Thread Alistair Francis
The following changes since commit 19b599f7664b2ebfd0f405fb79c14dd241557452:

  Merge remote-tracking branch 'remotes/armbru/tags/pull-error-2018-08-27-v2' 
into staging (2018-08-27 16:44:20 +0100)

are available in the Git repository at:

  g...@github.com:alistair23/qemu.git tags/pull-riscv-pullreq-20180904

for you to fetch changes up to 3b18c3fa870f11b8a1841bb7537e5bc11100160c:

  riscv: remove define cpu_init() (2018-09-04 13:24:39 -0700)


A misc collection of RISC-V related patches for 3.1.


Alistair Francis (2):
  hw/riscv/virtio: Set the soc device tree node as a simple-bus
  hw/riscv/spike: Set the soc device tree node as a simple-bus

Emilio G. Cota (2):
  target/riscv: optimize indirect branches
  target/riscv: call gen_goto_tb on DISAS_TOO_MANY

Igor Mammedov (1):
  riscv: remove define cpu_init()

Michael Clark (4):
  RISC-V: Update address bits to support sv39 and sv48
  RISC-V: Improve page table walker spec compliance
  RISC-V: Use atomic_cmpxchg to update PLIC bitmaps
  RISC-V: Simplify riscv_cpu_local_irqs_pending

 hw/riscv/sifive_plic.c | 49 ++---
 hw/riscv/spike.c   |  2 +-
 hw/riscv/virt.c|  2 +-
 include/hw/riscv/sifive_plic.h |  1 -
 target/riscv/cpu.h |  9 ++--
 target/riscv/cpu_bits.h|  2 -
 target/riscv/helper.c  | 98 --
 target/riscv/translate.c   |  9 +---
 8 files changed, 87 insertions(+), 85 deletions(-)



[Qemu-devel] [PULL 2/9] RISC-V: Improve page table walker spec compliance

2018-09-04 Thread Alistair Francis
From: Michael Clark 

- Inline PTE_TABLE check for better readability
- Change access checks from ternary operator to if
- Improve readibility of User page U mode and SUM test
- Disallow non U mode from fetching from User pages
- Add reserved PTE flag check: W or W|X
- Add misaligned PPN check
- Set READ protection for PTE X flag and mstatus.mxr
- Use memory_region_is_ram in pte update

Cc: Sagar Karandikar 
Cc: Bastian Koppelmann 
Cc: Palmer Dabbelt 
Cc: Alistair Francis 
Signed-off-by: Michael Clark 
Reviewed-by: Alistair Francis 
Signed-off-by: Alistair Francis 
---
 target/riscv/cpu_bits.h |  2 --
 target/riscv/helper.c   | 64 +
 2 files changed, 45 insertions(+), 21 deletions(-)

diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
index 64aa097181..12b4757088 100644
--- a/target/riscv/cpu_bits.h
+++ b/target/riscv/cpu_bits.h
@@ -407,5 +407,3 @@
 #define PTE_SOFT  0x300 /* Reserved for Software */
 
 #define PTE_PPN_SHIFT 10
-
-#define PTE_TABLE(PTE) (((PTE) & (PTE_V | PTE_R | PTE_W | PTE_X)) == PTE_V)
diff --git a/target/riscv/helper.c b/target/riscv/helper.c
index 29e1a603dc..1f0527e07f 100644
--- a/target/riscv/helper.c
+++ b/target/riscv/helper.c
@@ -185,16 +185,39 @@ restart:
 #endif
 target_ulong ppn = pte >> PTE_PPN_SHIFT;
 
-if (PTE_TABLE(pte)) { /* next level of page table */
+if (!(pte & PTE_V)) {
+/* Invalid PTE */
+return TRANSLATE_FAIL;
+} else if (!(pte & (PTE_R | PTE_W | PTE_X))) {
+/* Inner PTE, continue walking */
 base = ppn << PGSHIFT;
-} else if ((pte & PTE_U) ? (mode == PRV_S) && !sum : !(mode == PRV_S)) 
{
-break;
-} else if (!(pte & PTE_V) || (!(pte & PTE_R) && (pte & PTE_W))) {
-break;
-} else if (access_type == MMU_INST_FETCH ? !(pte & PTE_X) :
-  access_type == MMU_DATA_LOAD ?  !(pte & PTE_R) &&
-  !(mxr && (pte & PTE_X)) : !((pte & PTE_R) && (pte & PTE_W))) 
{
-break;
+} else if ((pte & (PTE_R | PTE_W | PTE_X)) == PTE_W) {
+/* Reserved leaf PTE flags: PTE_W */
+return TRANSLATE_FAIL;
+} else if ((pte & (PTE_R | PTE_W | PTE_X)) == (PTE_W | PTE_X)) {
+/* Reserved leaf PTE flags: PTE_W + PTE_X */
+return TRANSLATE_FAIL;
+} else if ((pte & PTE_U) && ((mode != PRV_U) &&
+   (!sum || access_type == MMU_INST_FETCH))) {
+/* User PTE flags when not U mode and mstatus.SUM is not set,
+   or the access type is an instruction fetch */
+return TRANSLATE_FAIL;
+} else if (!(pte & PTE_U) && (mode != PRV_S)) {
+/* Supervisor PTE flags when not S mode */
+return TRANSLATE_FAIL;
+} else if (ppn & ((1ULL << ptshift) - 1)) {
+/* Misaligned PPN */
+return TRANSLATE_FAIL;
+} else if (access_type == MMU_DATA_LOAD && !((pte & PTE_R) ||
+   ((pte & PTE_X) && mxr))) {
+/* Read access check failed */
+return TRANSLATE_FAIL;
+} else if (access_type == MMU_DATA_STORE && !(pte & PTE_W)) {
+/* Write access check failed */
+return TRANSLATE_FAIL;
+} else if (access_type == MMU_INST_FETCH && !(pte & PTE_X)) {
+/* Fetch access check failed */
+return TRANSLATE_FAIL;
 } else {
 /* if necessary, set accessed and dirty bits. */
 target_ulong updated_pte = pte | PTE_A |
@@ -202,16 +225,19 @@ restart:
 
 /* Page table updates need to be atomic with MTTCG enabled */
 if (updated_pte != pte) {
-/* if accessed or dirty bits need updating, and the PTE is
- * in RAM, then we do so atomically with a compare and swap.
- * if the PTE is in IO space, then it can't be updated.
- * if the PTE changed, then we must re-walk the page table
-   as the PTE is no longer valid */
+/*
+ * - if accessed or dirty bits need updating, and the PTE is
+ *   in RAM, then we do so atomically with a compare and swap.
+ * - if the PTE is in IO space or ROM, then it can't be updated
+ *   and we return TRANSLATE_FAIL.
+ * - if the PTE changed by the time we went to update it, then
+ *   it is no longer valid and we must re-walk the page table.
+ */
 MemoryRegion *mr;
 hwaddr l = sizeof(target_ulong), addr1;
 mr = address_space_translate(cs->as, pte_addr,
 &addr1, &l, false, MEMTXATTRS_U

[Qemu-devel] [PULL 6/9] target/riscv: call gen_goto_tb on DISAS_TOO_MANY

2018-09-04 Thread Alistair Francis
From: "Emilio G. Cota" 

Performance impact of this and the previous commits, measured with
the very-easy-to-cross-compile rv8-bench:
  https://github.com/rv8-io/rv8-bench

Host: Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz

- Key:
  before: master
  after1,2,3: the 3 commits in this series (i.e. 3 is this commit)

- User-mode:

 bench  before  after1  after2  after3  final speedup
-
 aes1.12s   1.12s   1.10s   1.00s   1.12
 bigint 0.78s   0.78s   0.78s   0.78s   1
 dhrystone  0.96s   0.97s   0.49s   0.49s   1.9591837
 miniz  1.94s   1.94s   1.88s   1.86s   1.0430108
 norx   0.51s   0.51s   0.49s   0.48s   1.0625
 primes 0.85s   0.85s   0.84s   0.84s   1.0119048
 qsort  4.87s   4.88s   1.86s   1.86s   2.6182796
 sha512 0.76s   0.77s   0.64s   0.64s   1.1875

(after1 only applies to softmmu, so no surprises here)

- Full-system (fedora):

 bench  before  after1  after2  after3  final speedup
-
 aes2.68s   2.54s   2.60s   2.34s   1.1452991
 bigint 1.61s   1.56s   1.55s   1.64s   0.98170732
 dhrystone  1.78s   1.67s   1.25s   1.24s   1.4354839
 miniz  3.53s   3.35s   3.28s   3.35s   1.0537313
 norx   1.13s   1.09s   1.07s   1.06s   1.0660377
 primes 15.37s  15.41s  15.20s  15.37s  1
 qsort  7.20s   6.71s   3.85s   3.96s   1.8181818
 sha512 1.07s   1.04s   0.90s   0.90s   1.189

SoftMMU slows things down, so the numbers are less sensitive.
Cross-page jumps improve things a little bit, though.

Note that I'm not showing here averages, just results from a
single run, so with primes there isn't much to worry about.

Signed-off-by: Emilio G. Cota 
Reviewed-by: Richard Henderson 
Signed-off-by: Alistair Francis 
---
 target/riscv/translate.c | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/target/riscv/translate.c b/target/riscv/translate.c
index c769edc359..72d34cd4b1 100644
--- a/target/riscv/translate.c
+++ b/target/riscv/translate.c
@@ -1868,12 +1868,7 @@ static void riscv_tr_tb_stop(DisasContextBase *dcbase, 
CPUState *cpu)
 
 switch (ctx->base.is_jmp) {
 case DISAS_TOO_MANY:
-tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next);
-if (ctx->base.singlestep_enabled) {
-gen_exception_debug();
-} else {
-tcg_gen_exit_tb(NULL, 0);
-}
+gen_goto_tb(ctx, 0, ctx->base.pc_next);
 break;
 case DISAS_NORETURN:
 break;
-- 
2.17.1




[Qemu-devel] [PULL 3/9] RISC-V: Use atomic_cmpxchg to update PLIC bitmaps

2018-09-04 Thread Alistair Francis
From: Michael Clark 

The PLIC previously used a mutex to protect against concurrent
access to the claimed and pending bitfields. Instead of using
a mutex, we update the bitfields using atomic_cmpxchg.

Rename sifive_plic_num_irqs_pending to sifive_plic_irqs_pending
and add an early out if any interrupts are pending as the
count of pending interrupts is not used.

Cc: Sagar Karandikar 
Cc: Bastian Koppelmann 
Cc: Palmer Dabbelt 
Cc: Alistair Francis 
Signed-off-by: Michael Clark 
Reviewed-by: Richard Henderson 
Signed-off-by: Alistair Francis 
---
 hw/riscv/sifive_plic.c | 49 +++---
 include/hw/riscv/sifive_plic.h |  1 -
 2 files changed, 22 insertions(+), 28 deletions(-)

diff --git a/hw/riscv/sifive_plic.c b/hw/riscv/sifive_plic.c
index a91aeb97ab..f635e6ff67 100644
--- a/hw/riscv/sifive_plic.c
+++ b/hw/riscv/sifive_plic.c
@@ -81,36 +81,32 @@ static void sifive_plic_print_state(SiFivePLICState *plic)
 }
 }
 
-static
-void sifive_plic_set_pending(SiFivePLICState *plic, int irq, bool pending)
+static uint32_t atomic_set_masked(uint32_t *a, uint32_t mask, uint32_t value)
 {
-qemu_mutex_lock(&plic->lock);
-uint32_t word = irq >> 5;
-if (pending) {
-plic->pending[word] |= (1 << (irq & 31));
-} else {
-plic->pending[word] &= ~(1 << (irq & 31));
-}
-qemu_mutex_unlock(&plic->lock);
+uint32_t old, new, cmp = atomic_read(a);
+
+do {
+old = cmp;
+new = (old & ~mask) | (value & mask);
+cmp = atomic_cmpxchg(a, old, new);
+} while (old != cmp);
+
+return old;
 }
 
-static
-void sifive_plic_set_claimed(SiFivePLICState *plic, int irq, bool claimed)
+static void sifive_plic_set_pending(SiFivePLICState *plic, int irq, bool level)
 {
-qemu_mutex_lock(&plic->lock);
-uint32_t word = irq >> 5;
-if (claimed) {
-plic->claimed[word] |= (1 << (irq & 31));
-} else {
-plic->claimed[word] &= ~(1 << (irq & 31));
-}
-qemu_mutex_unlock(&plic->lock);
+atomic_set_masked(&plic->pending[irq >> 5], 1 << (irq & 31), -!!level);
 }
 
-static
-int sifive_plic_num_irqs_pending(SiFivePLICState *plic, uint32_t addrid)
+static void sifive_plic_set_claimed(SiFivePLICState *plic, int irq, bool level)
 {
-int i, j, count = 0;
+atomic_set_masked(&plic->claimed[irq >> 5], 1 << (irq & 31), -!!level);
+}
+
+static int sifive_plic_irqs_pending(SiFivePLICState *plic, uint32_t addrid)
+{
+int i, j;
 for (i = 0; i < plic->bitfield_words; i++) {
 uint32_t pending_enabled_not_claimed =
 (plic->pending[i] & ~plic->claimed[i]) &
@@ -123,11 +119,11 @@ int sifive_plic_num_irqs_pending(SiFivePLICState *plic, 
uint32_t addrid)
 uint32_t prio = plic->source_priority[irq];
 int enabled = pending_enabled_not_claimed & (1 << j);
 if (enabled && prio > plic->target_priority[addrid]) {
-count++;
+return 1;
 }
 }
 }
-return count;
+return 0;
 }
 
 static void sifive_plic_update(SiFivePLICState *plic)
@@ -143,7 +139,7 @@ static void sifive_plic_update(SiFivePLICState *plic)
 if (!env) {
 continue;
 }
-int level = sifive_plic_num_irqs_pending(plic, addrid) > 0;
+int level = sifive_plic_irqs_pending(plic, addrid);
 switch (mode) {
 case PLICMode_M:
 riscv_set_local_interrupt(RISCV_CPU(cpu), MIP_MEIP, level);
@@ -439,7 +435,6 @@ static void sifive_plic_realize(DeviceState *dev, Error 
**errp)
 memory_region_init_io(&plic->mmio, OBJECT(dev), &sifive_plic_ops, plic,
   TYPE_SIFIVE_PLIC, plic->aperture_size);
 parse_hart_config(plic);
-qemu_mutex_init(&plic->lock);
 plic->bitfield_words = (plic->num_sources + 31) >> 5;
 plic->source_priority = g_new0(uint32_t, plic->num_sources);
 plic->target_priority = g_new(uint32_t, plic->num_addrs);
diff --git a/include/hw/riscv/sifive_plic.h b/include/hw/riscv/sifive_plic.h
index 2f2af7e686..688cd97f82 100644
--- a/include/hw/riscv/sifive_plic.h
+++ b/include/hw/riscv/sifive_plic.h
@@ -55,7 +55,6 @@ typedef struct SiFivePLICState {
 uint32_t *pending;
 uint32_t *claimed;
 uint32_t *enable;
-QemuMutex lock;
 
 /* config */
 char *hart_config;
-- 
2.17.1




[Qemu-devel] [PULL 9/9] riscv: remove define cpu_init()

2018-09-04 Thread Alistair Francis
From: Igor Mammedov 

cpu_init() was removed since 2.12, so drop the define that is now unused.

Signed-off-by: Igor Mammedov 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Michael Clark 
Signed-off-by: Alistair Francis 
---
 target/riscv/cpu.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index e0608e6d5f..d4f36295f0 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -251,7 +251,6 @@ int riscv_cpu_handle_mmu_fault(CPUState *cpu, vaddr 
address, int size,
 char *riscv_isa_string(RISCVCPU *cpu);
 void riscv_cpu_list(FILE *f, fprintf_function cpu_fprintf);
 
-#define cpu_init(cpu_model) cpu_generic_init(TYPE_RISCV_CPU, cpu_model)
 #define cpu_signal_handler cpu_riscv_signal_handler
 #define cpu_list riscv_cpu_list
 #define cpu_mmu_index riscv_cpu_mmu_index
-- 
2.17.1




[Qemu-devel] [PULL 7/9] hw/riscv/virtio: Set the soc device tree node as a simple-bus

2018-09-04 Thread Alistair Francis
To allow Linux to enumerate devices on the /soc/ node set it as a
"simple-bus".

Signed-off-by: Alistair Francis 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/riscv/virt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
index 248bbdffd3..e8ba4d192d 100644
--- a/hw/riscv/virt.c
+++ b/hw/riscv/virt.c
@@ -121,7 +121,7 @@ static void *create_fdt(RISCVVirtState *s, const struct 
MemmapEntry *memmap,
 
 qemu_fdt_add_subnode(fdt, "/soc");
 qemu_fdt_setprop(fdt, "/soc", "ranges", NULL, 0);
-qemu_fdt_setprop_string(fdt, "/soc", "compatible", "riscv-virtio-soc");
+qemu_fdt_setprop_string(fdt, "/soc", "compatible", "simple-bus");
 qemu_fdt_setprop_cell(fdt, "/soc", "#size-cells", 0x2);
 qemu_fdt_setprop_cell(fdt, "/soc", "#address-cells", 0x2);
 
-- 
2.17.1




[Qemu-devel] [PULL 4/9] RISC-V: Simplify riscv_cpu_local_irqs_pending

2018-09-04 Thread Alistair Francis
From: Michael Clark 

This commit is intended to improve readability.
There is no change to the logic.

Cc: Sagar Karandikar 
Cc: Bastian Koppelmann 
Cc: Palmer Dabbelt 
Cc: Alistair Francis 
Signed-off-by: Michael Clark 
Reviewed-by: Alistair Francis 
Signed-off-by: Alistair Francis 
---
 target/riscv/helper.c | 34 --
 1 file changed, 12 insertions(+), 22 deletions(-)

diff --git a/target/riscv/helper.c b/target/riscv/helper.c
index 1f0527e07f..63b3386b76 100644
--- a/target/riscv/helper.c
+++ b/target/riscv/helper.c
@@ -35,28 +35,18 @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch)
 }
 
 #ifndef CONFIG_USER_ONLY
-/*
- * Return RISC-V IRQ number if an interrupt should be taken, else -1.
- * Used in cpu-exec.c
- *
- * Adapted from Spike's processor_t::take_interrupt()
- */
-static int riscv_cpu_hw_interrupts_pending(CPURISCVState *env)
+static int riscv_cpu_local_irq_pending(CPURISCVState *env)
 {
-target_ulong pending_interrupts = atomic_read(&env->mip) & env->mie;
-
-target_ulong mie = get_field(env->mstatus, MSTATUS_MIE);
-target_ulong m_enabled = env->priv < PRV_M || (env->priv == PRV_M && mie);
-target_ulong enabled_interrupts = pending_interrupts &
-  ~env->mideleg & -m_enabled;
-
-target_ulong sie = get_field(env->mstatus, MSTATUS_SIE);
-target_ulong s_enabled = env->priv < PRV_S || (env->priv == PRV_S && sie);
-enabled_interrupts |= pending_interrupts & env->mideleg &
-  -s_enabled;
-
-if (enabled_interrupts) {
-return ctz64(enabled_interrupts); /* since non-zero */
+target_ulong mstatus_mie = get_field(env->mstatus, MSTATUS_MIE);
+target_ulong mstatus_sie = get_field(env->mstatus, MSTATUS_SIE);
+target_ulong pending = atomic_read(&env->mip) & env->mie;
+target_ulong mie = env->priv < PRV_M || (env->priv == PRV_M && 
mstatus_mie);
+target_ulong sie = env->priv < PRV_S || (env->priv == PRV_S && 
mstatus_sie);
+target_ulong irqs = (pending & ~env->mideleg & -mie) |
+(pending &  env->mideleg & -sie);
+
+if (irqs) {
+return ctz64(irqs); /* since non-zero */
 } else {
 return EXCP_NONE; /* indicates no pending interrupt */
 }
@@ -69,7 +59,7 @@ bool riscv_cpu_exec_interrupt(CPUState *cs, int 
interrupt_request)
 if (interrupt_request & CPU_INTERRUPT_HARD) {
 RISCVCPU *cpu = RISCV_CPU(cs);
 CPURISCVState *env = &cpu->env;
-int interruptno = riscv_cpu_hw_interrupts_pending(env);
+int interruptno = riscv_cpu_local_irq_pending(env);
 if (interruptno >= 0) {
 cs->exception_index = RISCV_EXCP_INT_FLAG | interruptno;
 riscv_cpu_do_interrupt(cs);
-- 
2.17.1




[Qemu-devel] [PULL 5/9] target/riscv: optimize indirect branches

2018-09-04 Thread Alistair Francis
From: "Emilio G. Cota" 

Signed-off-by: Emilio G. Cota 
Reviewed-by: Richard Henderson 
Signed-off-by: Alistair Francis 
---
 target/riscv/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/riscv/translate.c b/target/riscv/translate.c
index 0b6be74f2d..c769edc359 100644
--- a/target/riscv/translate.c
+++ b/target/riscv/translate.c
@@ -548,7 +548,7 @@ static void gen_jalr(CPURISCVState *env, DisasContext *ctx, 
uint32_t opc,
 if (rd != 0) {
 tcg_gen_movi_tl(cpu_gpr[rd], ctx->pc_succ_insn);
 }
-tcg_gen_exit_tb(NULL, 0);
+tcg_gen_lookup_and_goto_ptr();
 
 if (misaligned) {
 gen_set_label(misaligned);
-- 
2.17.1




[Qemu-devel] [PULL 8/9] hw/riscv/spike: Set the soc device tree node as a simple-bus

2018-09-04 Thread Alistair Francis
To allow Linux to enumerate devices on the /soc/ node set it as a
"simple-bus".

Signed-off-by: Alistair Francis 
---
 hw/riscv/spike.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c
index c8c056c50b..eb857c434e 100644
--- a/hw/riscv/spike.c
+++ b/hw/riscv/spike.c
@@ -90,7 +90,7 @@ static void create_fdt(SpikeState *s, const struct 
MemmapEntry *memmap,
 
 qemu_fdt_add_subnode(fdt, "/soc");
 qemu_fdt_setprop(fdt, "/soc", "ranges", NULL, 0);
-qemu_fdt_setprop_string(fdt, "/soc", "compatible", 
"ucbbar,spike-bare-soc");
+qemu_fdt_setprop_string(fdt, "/soc", "compatible", "simple-bus");
 qemu_fdt_setprop_cell(fdt, "/soc", "#size-cells", 0x2);
 qemu_fdt_setprop_cell(fdt, "/soc", "#address-cells", 0x2);
 
-- 
2.17.1




Re: [Qemu-devel] [PATCH v2 0/3] target/riscv: use tcg_lookup_and_goto_ptr

2018-09-04 Thread Alistair Francis
On Tue, Sep 4, 2018 at 4:39 PM, Emilio G. Cota  wrote:
> On Tue, Sep 04, 2018 at 13:18:28 -0700, Alistair Francis wrote:
>> On Fri, Aug 31, 2018 at 3:22 PM, Emilio G. Cota  wrote:
>> > On Fri, Aug 10, 2018 at 13:39:38 -0400, Emilio G. Cota wrote:
>> >> Changes wrt v1: changed patch 3 as suggested by Richard. Also
>> >> added his R-b's.
>> >>
>> >> You can fetch this series from:
>> >>   https://github.com/cota/qemu/tree/riscv-lookup_ptr-v2
>> >
>> > RISC-V maintainers: any plans of picking this up for 3.1?
>>
>> Thanks for CCing me.
>>
>> I think Michael must be really busy, I haven't seen any activity for
>> awhile. I'm going to send a PR with everything that has been reviewed
>> and applies cleanly.
>
> Thanks!
>
> Did patch 1 not apply cleanly? I see it's not part of the pullreq
> you just sent.
>
> I'd like the three patches to go in in the original order, since
> the perf numbers in patch 3's commit log are laid out assuming
> that is the case.

The content of patch 1 was applied in this commit:

commit 07ea28b41830f946de3841b0ac61a3413679feb9
Author: Richard Henderson 
Date:   Wed May 30 18:06:23 2018 -0700

tcg: Pass tb and index to tcg_gen_exit_tb separately

Do the cast to uintptr_t within the helper, so that the compiler
can type check the pointer argument.  We can also do some more
sanity checking of the index argument.

Reviewed-by: Laurent Vivier 
Signed-off-by: Richard Henderson 

https://github.com/qemu/qemu/commit/07ea28b41830f946de3841b0ac61a3413679feb9

so unfortunately the patch no longer applies.

Alistair

>
> Cheers,
>
> Emilio



Re: [Qemu-devel] [PATCH 02/15] gdbstub: add multiprocess support to '?' packets

2018-09-04 Thread Alistair Francis
On Sat, Sep 1, 2018 at 5:46 AM, Luc Michel  wrote:
> The gdb_get_cpu_pid() function does the PID lookup for the given CPU. It
> checks if the CPU is in a QOM container named after the
> GDB_CPU_GROUP_NAME macro. If found, it returns the correponding PID,
> which is the group ID plus one (group IDs start at 0, GDB PIDs at 1).
> When the CPU is not a child of such a container, PID 1 is returned.
>
> The get_thread_id() function generates the string to be used to identify
> a given thread, in a response packet for the peer. This function
> supports generating thread IDs when multiprocess mode is enabled (in the
> form `p.').
>
> Use it in the reply to a '?' request.
>
> Signed-off-by: Luc Michel 

Reviewed-by: Alistair Francis 

Alistair

> ---
>  gdbstub.c | 46 --
>  1 file changed, 44 insertions(+), 2 deletions(-)
>
> diff --git a/gdbstub.c b/gdbstub.c
> index 5c86218f49..ec3105dbc1 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -640,10 +640,37 @@ static int memtox(char *buf, const char *mem, int len)
>  }
>  }
>  return p - buf;
>  }
>
> +static uint32_t gdb_get_cpu_pid(const GDBState *s, CPUState *cpu)
> +{
> +gchar *path;
> +gchar *cont;
> +const char *left;
> +unsigned long pid;
> +
> +if (!s->multiprocess || (s->process_num == 1)) {
> +return 1;
> +}
> +
> +path = object_get_canonical_path(OBJECT(cpu));
> +cont = g_strrstr(path, "/" GDB_CPU_GROUP_NAME "[");
> +
> +if (cont == NULL) {
> +return 1;
> +}
> +
> +cont += strlen("/" GDB_CPU_GROUP_NAME "[");
> +
> +if (qemu_strtoul(cont, &left, 10, &pid)) {
> +return 1;
> +}
> +
> +return pid + 1;
> +}
> +
>  static const char *get_feature_xml(const char *p, const char **newp,
> CPUClass *cc)
>  {
>  size_t len;
>  int i;
> @@ -909,10 +936,24 @@ static CPUState *find_cpu(uint32_t thread_id)
>  }
>
>  return NULL;
>  }
>
> +static char *get_thread_id(const GDBState *s, CPUState *cpu,
> +   char *buf, size_t buf_size)
> +{
> +if (s->multiprocess) {
> +snprintf(buf, buf_size, "p%02x.%02x",
> + gdb_get_cpu_pid(s, cpu), cpu_gdb_index(cpu));
> +} else {
> +snprintf(buf, buf_size, "%02x", cpu_gdb_index(cpu));
> +
> +}
> +
> +return buf;
> +}
> +
>  static int is_query_packet(const char *p, const char *query, char separator)
>  {
>  unsigned int query_len = strlen(query);
>
>  return strncmp(p, query, query_len) == 0 &&
> @@ -1020,22 +1061,23 @@ static int gdb_handle_packet(GDBState *s, const char 
> *line_buf)
>  const char *p;
>  uint32_t thread;
>  int ch, reg_size, type, res;
>  uint8_t mem_buf[MAX_PACKET_LENGTH];
>  char buf[sizeof(mem_buf) + 1 /* trailing NUL */];
> +char thread_id[16];
>  uint8_t *registers;
>  target_ulong addr, len;
>
>  trace_gdbstub_io_command(line_buf);
>
>  p = line_buf;
>  ch = *p++;
>  switch(ch) {
>  case '?':
>  /* TODO: Make this return the correct value for user-mode.  */
> -snprintf(buf, sizeof(buf), "T%02xthread:%02x;", GDB_SIGNAL_TRAP,
> - cpu_gdb_index(s->c_cpu));
> +snprintf(buf, sizeof(buf), "T%02xthread:%s;", GDB_SIGNAL_TRAP,
> + get_thread_id(s, s->c_cpu, thread_id, sizeof(thread_id)));
>  put_packet(s, buf);
>  /* Remove all the breakpoints when this query is issued,
>   * because gdb is doing and initial connect and the state
>   * should be cleaned up.
>   */
> --
> 2.18.0
>
>



Re: [Qemu-devel] [PATCH 03/16] test/qgraph: arm/xlinx-zynq-a9 machine node

2018-09-04 Thread Alistair Francis
On Mon, Aug 20, 2018 at 5:02 AM, Emanuele Giuseppe Esposito
 wrote:
> Add xlinx-zynq-a9 machine to the graph. This machine contains generic-sdhci, 
> so
> its constructor must take care of setting it properly when called.
>
> Signed-off-by: Emanuele Giuseppe Esposito 

Acked-by: Alistair Francis 

Alistair

> ---
>  tests/Makefile.include|  1 +
>  tests/libqos/xilinx-zynq-a9-machine.c | 84 +++
>  tests/sdhci-test.c|  8 +--
>  3 files changed, 89 insertions(+), 4 deletions(-)
>  create mode 100644 tests/libqos/xilinx-zynq-a9-machine.c
>
> diff --git a/tests/Makefile.include b/tests/Makefile.include
> index 4690d5f5e9..d559218b1c 100644
> --- a/tests/Makefile.include
> +++ b/tests/Makefile.include
> @@ -760,6 +760,7 @@ libqgraph-arm-machines-obj-y = 
> tests/libqos/raspi2-machine.o
>  libqgraph-arm-machines-obj-y += tests/libqos/virt-machine.o
>  libqgraph-arm-machines-obj-y += tests/libqos/smdkc210-machine.o
>  libqgraph-arm-machines-obj-y += tests/libqos/sabrelite-machine.o
> +libqgraph-arm-machines-obj-y += tests/libqos/xilinx-zynq-a9-machine.o
>
>  libqgraph-machines-obj-y = $(libqgraph-arm-machines-obj-y)
>  libqgraph-machines-obj-y += tests/libqos/x86_64_pc-machine.o
> diff --git a/tests/libqos/xilinx-zynq-a9-machine.c 
> b/tests/libqos/xilinx-zynq-a9-machine.c
> new file mode 100644
> index 00..025cd80eb2
> --- /dev/null
> +++ b/tests/libqos/xilinx-zynq-a9-machine.c
> @@ -0,0 +1,84 @@
> +/*
> + * libqos driver framework
> + *
> + * Copyright (c) 2018 Emanuele Giuseppe Esposito 
> 
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License version 2 as published by the Free Software Foundation.
> + *
> + * This library 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
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, see 
> <http://www.gnu.org/licenses/>
> + */
> +
> +#include "qemu/osdep.h"
> +#include "libqtest.h"
> +#include "libqos/malloc.h"
> +#include "libqos/qgraph.h"
> +#include "sdhci.h"
> +
> +typedef struct QXilinx_zynq_a9Machine QXilinx_zynq_a9Machine;
> +
> +struct QXilinx_zynq_a9Machine {
> +QOSGraphObject obj;
> +QGuestAllocator *alloc;
> +QSDHCI_MemoryMapped sdhci;
> +};
> +
> +static void xilinx_zynq_a9_destructor(QOSGraphObject *obj)
> +{
> +g_free(obj);
> +}
> +
> +static void *xilinx_zynq_a9_get_driver(void *object, const char *interface)
> +{
> +QXilinx_zynq_a9Machine *machine = object;
> +if (!g_strcmp0(interface, "memory")) {
> +return &machine->alloc;
> +}
> +
> +fprintf(stderr, "%s not present in arm/xilinx-zynq-a9\n", interface);
> +g_assert_not_reached();
> +}
> +
> +static QOSGraphObject *xilinx_zynq_a9_get_device(void *obj, const char 
> *device)
> +{
> +QXilinx_zynq_a9Machine *machine = obj;
> +if (!g_strcmp0(device, "generic-sdhci")) {
> +return &machine->sdhci.obj;
> +}
> +
> +fprintf(stderr, "%s not present in arm/xilinx-zynq-a9\n", device);
> +g_assert_not_reached();
> +}
> +
> +static void *qos_create_machine_arm_xilinx_zynq_a9(void)
> +{
> +QXilinx_zynq_a9Machine *machine = g_new0(QXilinx_zynq_a9Machine, 1);
> +
> +machine->obj.get_device = xilinx_zynq_a9_get_device;
> +machine->obj.get_driver = xilinx_zynq_a9_get_driver;
> +machine->obj.destructor = xilinx_zynq_a9_destructor;
> +/* Datasheet: UG585 (v1.12.1) */
> +qos_init_sdhci_smm(&machine->sdhci, 0xe010, &(QSDHCIProperties) {
> +.version = 2,
> +.baseclock = 0,
> +.capab.sdma = true,
> +.capab.reg = 0x69ec0080,
> +});
> +return &machine->obj;
> +}
> +
> +static void xilinx_zynq_a9_register_nodes(void)
> +{
> +qos_node_create_machine("arm/xilinx-zynq-a9",
> +qos_create_machine_arm_xilinx_zynq_a9);
> +qos_node_contains("arm/xilinx-zynq-a9", "generic-sdhci", NULL);
> +}
> +
> +libqos_init(xilinx_zynq_a9_register_nodes);
> diff --git a/tests/sdhci-test.c b/tests/sdhci-test.c
> index 31ecc06159..0a8efd8554 100644
> --- a/tests/sdhci-test.c
> +++ b/tests/sdhci-test.c
>

Re: [Qemu-devel] [PATCH 04/16] test/qgraph: aarch64/xlnx-zcu102 machine node

2018-09-04 Thread Alistair Francis
On Mon, Aug 20, 2018 at 5:02 AM, Emanuele Giuseppe Esposito
 wrote:
> Add xlnx-zcu102 machine to the graph. This machine contains generic-sdhci, so
> its constructor must take care of setting it properly when called.
>
> Signed-off-by: Emanuele Giuseppe Esposito 

Acked-by: Alistair Francis 

Alistair

> ---
>  tests/Makefile.include |  1 +
>  tests/libqos/xlnx-zcu102-machine.c | 83 ++
>  tests/sdhci-test.c | 51 --
>  3 files changed, 84 insertions(+), 51 deletions(-)
>  create mode 100644 tests/libqos/xlnx-zcu102-machine.c
>
> diff --git a/tests/Makefile.include b/tests/Makefile.include
> index d559218b1c..bad4de3d61 100644
> --- a/tests/Makefile.include
> +++ b/tests/Makefile.include
> @@ -765,6 +765,7 @@ libqgraph-arm-machines-obj-y += 
> tests/libqos/xilinx-zynq-a9-machine.o
>  libqgraph-machines-obj-y = $(libqgraph-arm-machines-obj-y)
>  libqgraph-machines-obj-y += tests/libqos/x86_64_pc-machine.o
>  libqgraph-machines-obj-y += tests/libqos/ppc64_pseries-machine.o
> +libqgraph-machines-obj-y += tests/libqos/xlnx-zcu102-machine.o
>
>  libqgraph-virtio-obj-y = tests/libqos/virtio-serial.o
>  libqgraph-virtio-obj-y += tests/libqos/virtio-9p.o
> diff --git a/tests/libqos/xlnx-zcu102-machine.c 
> b/tests/libqos/xlnx-zcu102-machine.c
> new file mode 100644
> index 00..9932cf39a8
> --- /dev/null
> +++ b/tests/libqos/xlnx-zcu102-machine.c
> @@ -0,0 +1,83 @@
> +/*
> + * libqos driver framework
> + *
> + * Copyright (c) 2018 Emanuele Giuseppe Esposito 
> 
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License version 2 as published by the Free Software Foundation.
> + *
> + * This library 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
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, see 
> <http://www.gnu.org/licenses/>
> + */
> +
> +#include "qemu/osdep.h"
> +#include "libqtest.h"
> +#include "libqos/malloc.h"
> +#include "libqos/qgraph.h"
> +#include "sdhci.h"
> +
> +typedef struct QXlnx_zcu102Machine QXlnx_zcu102Machine;
> +
> +struct QXlnx_zcu102Machine {
> +QOSGraphObject obj;
> +QGuestAllocator *alloc;
> +QSDHCI_MemoryMapped sdhci;
> +};
> +
> +static void xlnx_zcu102_destructor(QOSGraphObject *obj)
> +{
> +g_free(obj);
> +}
> +
> +static void *xlnx_zcu102_get_driver(void *object, const char *interface)
> +{
> +QXlnx_zcu102Machine *machine = object;
> +if (!g_strcmp0(interface, "memory")) {
> +return &machine->alloc;
> +}
> +
> +fprintf(stderr, "%s not present in aarch64/xlnx-zcu102\n", interface);
> +g_assert_not_reached();
> +}
> +
> +static QOSGraphObject *xlnx_zcu102_get_device(void *obj, const char *device)
> +{
> +QXlnx_zcu102Machine *machine = obj;
> +if (!g_strcmp0(device, "generic-sdhci")) {
> +return &machine->sdhci.obj;
> +}
> +
> +fprintf(stderr, "%s not present in aarch64/xlnx-zcu102\n", device);
> +g_assert_not_reached();
> +}
> +
> +static void *qos_create_machine_aarch64_xlnx_zcu102(void)
> +{
> +QXlnx_zcu102Machine *machine = g_new0(QXlnx_zcu102Machine, 1);
> +
> +machine->obj.get_device = xlnx_zcu102_get_device;
> +machine->obj.get_driver = xlnx_zcu102_get_driver;
> +machine->obj.destructor = xlnx_zcu102_destructor;
> +/* Datasheet: UG1085 (v1.7) */
> +qos_init_sdhci_smm(&machine->sdhci, 0xff16, &(QSDHCIProperties) {
> +.version = 3,
> +.baseclock = 0,
> +.capab.sdma = true,
> +.capab.reg = 0x280737ec6481
> +});
> +return &machine->obj;
> +}
> +
> +static void xlnx_zcu102_register_nodes(void)
> +{
> +qos_node_create_machine("aarch64/xlnx-zcu102", 
> qos_create_machine_aarch64_xlnx_zcu102);
> +qos_node_contains("aarch64/xlnx-zcu102", "generic-sdhci", NULL);
> +}
> +
> +libqos_init(xlnx_zcu102_register_nodes);
> diff --git a/tests/sdhci-test.c b/tests/sdhci-test.c
> index 0a8efd8554..deb42be493 100644
> --- a/tests/sdhci-test.c
> +++ b/tests/sdhci-test.c
> @@ -22,57 +22,6 @@ FIELD(SDHC_CAPAB, SDR,  32, 3); /* 
> since v3 */
>  FIELD(SDHC_CA

Re: [Qemu-devel] [PATCH v2 0/3] target/riscv: use tcg_lookup_and_goto_ptr

2018-09-05 Thread Alistair Francis
On Tue, Sep 4, 2018 at 6:07 PM, Emilio G. Cota  wrote:
> On Tue, Sep 04, 2018 at 16:42:32 -0700, Alistair Francis wrote:
>> On Tue, Sep 4, 2018 at 4:39 PM, Emilio G. Cota  wrote:
>> > On Tue, Sep 04, 2018 at 13:18:28 -0700, Alistair Francis wrote:
>> >> On Fri, Aug 31, 2018 at 3:22 PM, Emilio G. Cota  wrote:
>> >> > On Fri, Aug 10, 2018 at 13:39:38 -0400, Emilio G. Cota wrote:
>> >> >> Changes wrt v1: changed patch 3 as suggested by Richard. Also
>> >> >> added his R-b's.
>> >> >>
>> >> >> You can fetch this series from:
>> >> >>   https://github.com/cota/qemu/tree/riscv-lookup_ptr-v2
>> >> >
>> >> > RISC-V maintainers: any plans of picking this up for 3.1?
>> >>
>> >> Thanks for CCing me.
>> >>
>> >> I think Michael must be really busy, I haven't seen any activity for
>> >> awhile. I'm going to send a PR with everything that has been reviewed
>> >> and applies cleanly.
>> >
>> > Thanks!
>> >
>> > Did patch 1 not apply cleanly? I see it's not part of the pullreq
>> > you just sent.
>> >
>> > I'd like the three patches to go in in the original order, since
>> > the perf numbers in patch 3's commit log are laid out assuming
>> > that is the case.
>>
>> The content of patch 1 was applied in this commit:
>>
>> commit 07ea28b41830f946de3841b0ac61a3413679feb9
>> Author: Richard Henderson 
>> Date:   Wed May 30 18:06:23 2018 -0700
>>
>> tcg: Pass tb and index to tcg_gen_exit_tb separately
>>
>> Do the cast to uintptr_t within the helper, so that the compiler
>> can type check the pointer argument.  We can also do some more
>> sanity checking of the index argument.
>>
>> Reviewed-by: Laurent Vivier 
>> Signed-off-by: Richard Henderson 
>>
>> https://github.com/qemu/qemu/commit/07ea28b41830f946de3841b0ac61a3413679feb9
>>
>> so unfortunately the patch no longer applies.
>
> If I rebase the 3 patches on top of the current master (19b599f7),
> the 3 patches apply cleanly, including patch 1:
>
> --- a/target/riscv/translate.c
> +++ b/target/riscv/translate.c
> @@ -135,7 +135,7 @@ static void gen_goto_tb(DisasContext *ctx, int n, targ
>  if (ctx->base.singlestep_enabled) {
>  gen_exception_debug();
>  } else {
> -tcg_gen_exit_tb(NULL, 0);
> +tcg_gen_lookup_and_goto_ptr();
>  }
>  }
>  }
>
> Did you apply the patches manually or pull from a branch?
> The latest branch I have on this is:
>https://github.com/cota/qemu/tree/riscv-lookup_ptr-v2
> (although note that that branch doesn't have Richard's
> R-b tag for patch 3)

I thought I cherry picked them directly from your branch and I saw
conflicts. It seems to be working now, maybe I cherry picked the wrong
patch. I'll update the PR.

Thanks for double checking for me.

Alistair

>
> Thanks,
>
> Emilio



[Qemu-devel] [PULL v2 01/10] RISC-V: Update address bits to support sv39 and sv48

2018-09-05 Thread Alistair Francis
From: Michael Clark 

Cc: Sagar Karandikar 
Cc: Bastian Koppelmann 
Cc: Palmer Dabbelt 
Cc: Alistair Francis 
Signed-off-by: Palmer Dabbelt 
Reviewed-by: Alistair Francis 
Signed-off-by: Alistair Francis 
---
 target/riscv/cpu.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index 34abc383e3..e0608e6d5f 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -24,12 +24,12 @@
 #define TARGET_PAGE_BITS 12 /* 4 KiB Pages */
 #if defined(TARGET_RISCV64)
 #define TARGET_LONG_BITS 64
-#define TARGET_PHYS_ADDR_SPACE_BITS 50
-#define TARGET_VIRT_ADDR_SPACE_BITS 39
+#define TARGET_PHYS_ADDR_SPACE_BITS 56 /* 44-bit PPN */
+#define TARGET_VIRT_ADDR_SPACE_BITS 48 /* sv48 */
 #elif defined(TARGET_RISCV32)
 #define TARGET_LONG_BITS 32
-#define TARGET_PHYS_ADDR_SPACE_BITS 34
-#define TARGET_VIRT_ADDR_SPACE_BITS 32
+#define TARGET_PHYS_ADDR_SPACE_BITS 34 /* 22-bit PPN */
+#define TARGET_VIRT_ADDR_SPACE_BITS 32 /* sv32 */
 #endif
 
 #define TCG_GUEST_DEFAULT_MO 0
-- 
2.17.1




[Qemu-devel] [PULL v2 02/10] RISC-V: Improve page table walker spec compliance

2018-09-05 Thread Alistair Francis
From: Michael Clark 

- Inline PTE_TABLE check for better readability
- Change access checks from ternary operator to if
- Improve readibility of User page U mode and SUM test
- Disallow non U mode from fetching from User pages
- Add reserved PTE flag check: W or W|X
- Add misaligned PPN check
- Set READ protection for PTE X flag and mstatus.mxr
- Use memory_region_is_ram in pte update

Cc: Sagar Karandikar 
Cc: Bastian Koppelmann 
Cc: Palmer Dabbelt 
Cc: Alistair Francis 
Signed-off-by: Michael Clark 
Reviewed-by: Alistair Francis 
Signed-off-by: Alistair Francis 
---
 target/riscv/cpu_bits.h |  2 --
 target/riscv/helper.c   | 64 +
 2 files changed, 45 insertions(+), 21 deletions(-)

diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h
index 64aa097181..12b4757088 100644
--- a/target/riscv/cpu_bits.h
+++ b/target/riscv/cpu_bits.h
@@ -407,5 +407,3 @@
 #define PTE_SOFT  0x300 /* Reserved for Software */
 
 #define PTE_PPN_SHIFT 10
-
-#define PTE_TABLE(PTE) (((PTE) & (PTE_V | PTE_R | PTE_W | PTE_X)) == PTE_V)
diff --git a/target/riscv/helper.c b/target/riscv/helper.c
index 29e1a603dc..1f0527e07f 100644
--- a/target/riscv/helper.c
+++ b/target/riscv/helper.c
@@ -185,16 +185,39 @@ restart:
 #endif
 target_ulong ppn = pte >> PTE_PPN_SHIFT;
 
-if (PTE_TABLE(pte)) { /* next level of page table */
+if (!(pte & PTE_V)) {
+/* Invalid PTE */
+return TRANSLATE_FAIL;
+} else if (!(pte & (PTE_R | PTE_W | PTE_X))) {
+/* Inner PTE, continue walking */
 base = ppn << PGSHIFT;
-} else if ((pte & PTE_U) ? (mode == PRV_S) && !sum : !(mode == PRV_S)) 
{
-break;
-} else if (!(pte & PTE_V) || (!(pte & PTE_R) && (pte & PTE_W))) {
-break;
-} else if (access_type == MMU_INST_FETCH ? !(pte & PTE_X) :
-  access_type == MMU_DATA_LOAD ?  !(pte & PTE_R) &&
-  !(mxr && (pte & PTE_X)) : !((pte & PTE_R) && (pte & PTE_W))) 
{
-break;
+} else if ((pte & (PTE_R | PTE_W | PTE_X)) == PTE_W) {
+/* Reserved leaf PTE flags: PTE_W */
+return TRANSLATE_FAIL;
+} else if ((pte & (PTE_R | PTE_W | PTE_X)) == (PTE_W | PTE_X)) {
+/* Reserved leaf PTE flags: PTE_W + PTE_X */
+return TRANSLATE_FAIL;
+} else if ((pte & PTE_U) && ((mode != PRV_U) &&
+   (!sum || access_type == MMU_INST_FETCH))) {
+/* User PTE flags when not U mode and mstatus.SUM is not set,
+   or the access type is an instruction fetch */
+return TRANSLATE_FAIL;
+} else if (!(pte & PTE_U) && (mode != PRV_S)) {
+/* Supervisor PTE flags when not S mode */
+return TRANSLATE_FAIL;
+} else if (ppn & ((1ULL << ptshift) - 1)) {
+/* Misaligned PPN */
+return TRANSLATE_FAIL;
+} else if (access_type == MMU_DATA_LOAD && !((pte & PTE_R) ||
+   ((pte & PTE_X) && mxr))) {
+/* Read access check failed */
+return TRANSLATE_FAIL;
+} else if (access_type == MMU_DATA_STORE && !(pte & PTE_W)) {
+/* Write access check failed */
+return TRANSLATE_FAIL;
+} else if (access_type == MMU_INST_FETCH && !(pte & PTE_X)) {
+/* Fetch access check failed */
+return TRANSLATE_FAIL;
 } else {
 /* if necessary, set accessed and dirty bits. */
 target_ulong updated_pte = pte | PTE_A |
@@ -202,16 +225,19 @@ restart:
 
 /* Page table updates need to be atomic with MTTCG enabled */
 if (updated_pte != pte) {
-/* if accessed or dirty bits need updating, and the PTE is
- * in RAM, then we do so atomically with a compare and swap.
- * if the PTE is in IO space, then it can't be updated.
- * if the PTE changed, then we must re-walk the page table
-   as the PTE is no longer valid */
+/*
+ * - if accessed or dirty bits need updating, and the PTE is
+ *   in RAM, then we do so atomically with a compare and swap.
+ * - if the PTE is in IO space or ROM, then it can't be updated
+ *   and we return TRANSLATE_FAIL.
+ * - if the PTE changed by the time we went to update it, then
+ *   it is no longer valid and we must re-walk the page table.
+ */
 MemoryRegion *mr;
 hwaddr l = sizeof(target_ulong), addr1;
 mr = address_space_translate(cs->as, pte_addr,
 &addr1, &l, false, MEMTXATTRS_U

[Qemu-devel] [PULL v2 00/10] riscv-pullreq queue

2018-09-05 Thread Alistair Francis
The following changes since commit 19b599f7664b2ebfd0f405fb79c14dd241557452:

  Merge remote-tracking branch 'remotes/armbru/tags/pull-error-2018-08-27-v2' 
into staging (2018-08-27 16:44:20 +0100)

are available in the Git repository at:

  g...@github.com:alistair23/qemu.git tags/pull-riscv-pullreq-20180905

for you to fetch changes up to 1ca79ece35a5bcdcefb5a2582bc6da91f0640bf2:

  riscv: remove define cpu_init() (2018-09-05 09:58:38 -0700)


A misc collection of RISC-V related patches for 3.1.


Alistair Francis (2):
  hw/riscv/virtio: Set the soc device tree node as a simple-bus
  hw/riscv/spike: Set the soc device tree node as a simple-bus

Emilio G. Cota (3):
  target/riscv: optimize cross-page direct jumps in softmmu
  target/riscv: optimize indirect branches
  target/riscv: call gen_goto_tb on DISAS_TOO_MANY

Igor Mammedov (1):
  riscv: remove define cpu_init()

Michael Clark (4):
  RISC-V: Update address bits to support sv39 and sv48
  RISC-V: Improve page table walker spec compliance
  RISC-V: Use atomic_cmpxchg to update PLIC bitmaps
  RISC-V: Simplify riscv_cpu_local_irqs_pending

 hw/riscv/sifive_plic.c | 49 ++---
 hw/riscv/spike.c   |  2 +-
 hw/riscv/virt.c|  2 +-
 include/hw/riscv/sifive_plic.h |  1 -
 target/riscv/cpu.h |  9 ++--
 target/riscv/cpu_bits.h|  2 -
 target/riscv/helper.c  | 98 --
 target/riscv/translate.c   | 11 ++---
 8 files changed, 88 insertions(+), 86 deletions(-)



[Qemu-devel] [PULL v2 05/10] target/riscv: optimize cross-page direct jumps in softmmu

2018-09-05 Thread Alistair Francis
From: "Emilio G. Cota" 

Signed-off-by: Emilio G. Cota 
Reviewed-by: Richard Henderson 
Signed-off-by: Alistair Francis 
---
 target/riscv/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/riscv/translate.c b/target/riscv/translate.c
index 0b6be74f2d..ec2988b4f6 100644
--- a/target/riscv/translate.c
+++ b/target/riscv/translate.c
@@ -135,7 +135,7 @@ static void gen_goto_tb(DisasContext *ctx, int n, 
target_ulong dest)
 if (ctx->base.singlestep_enabled) {
 gen_exception_debug();
 } else {
-tcg_gen_exit_tb(NULL, 0);
+tcg_gen_lookup_and_goto_ptr();
 }
 }
 }
-- 
2.17.1




[Qemu-devel] [PULL v2 09/10] hw/riscv/spike: Set the soc device tree node as a simple-bus

2018-09-05 Thread Alistair Francis
To allow Linux to enumerate devices on the /soc/ node set it as a
"simple-bus".

Signed-off-by: Alistair Francis 
---
 hw/riscv/spike.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c
index c8c056c50b..eb857c434e 100644
--- a/hw/riscv/spike.c
+++ b/hw/riscv/spike.c
@@ -90,7 +90,7 @@ static void create_fdt(SpikeState *s, const struct 
MemmapEntry *memmap,
 
 qemu_fdt_add_subnode(fdt, "/soc");
 qemu_fdt_setprop(fdt, "/soc", "ranges", NULL, 0);
-qemu_fdt_setprop_string(fdt, "/soc", "compatible", 
"ucbbar,spike-bare-soc");
+qemu_fdt_setprop_string(fdt, "/soc", "compatible", "simple-bus");
 qemu_fdt_setprop_cell(fdt, "/soc", "#size-cells", 0x2);
 qemu_fdt_setprop_cell(fdt, "/soc", "#address-cells", 0x2);
 
-- 
2.17.1




[Qemu-devel] [PULL v2 08/10] hw/riscv/virtio: Set the soc device tree node as a simple-bus

2018-09-05 Thread Alistair Francis
To allow Linux to enumerate devices on the /soc/ node set it as a
"simple-bus".

Signed-off-by: Alistair Francis 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/riscv/virt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
index 248bbdffd3..e8ba4d192d 100644
--- a/hw/riscv/virt.c
+++ b/hw/riscv/virt.c
@@ -121,7 +121,7 @@ static void *create_fdt(RISCVVirtState *s, const struct 
MemmapEntry *memmap,
 
 qemu_fdt_add_subnode(fdt, "/soc");
 qemu_fdt_setprop(fdt, "/soc", "ranges", NULL, 0);
-qemu_fdt_setprop_string(fdt, "/soc", "compatible", "riscv-virtio-soc");
+qemu_fdt_setprop_string(fdt, "/soc", "compatible", "simple-bus");
 qemu_fdt_setprop_cell(fdt, "/soc", "#size-cells", 0x2);
 qemu_fdt_setprop_cell(fdt, "/soc", "#address-cells", 0x2);
 
-- 
2.17.1




[Qemu-devel] [PULL v2 03/10] RISC-V: Use atomic_cmpxchg to update PLIC bitmaps

2018-09-05 Thread Alistair Francis
From: Michael Clark 

The PLIC previously used a mutex to protect against concurrent
access to the claimed and pending bitfields. Instead of using
a mutex, we update the bitfields using atomic_cmpxchg.

Rename sifive_plic_num_irqs_pending to sifive_plic_irqs_pending
and add an early out if any interrupts are pending as the
count of pending interrupts is not used.

Cc: Sagar Karandikar 
Cc: Bastian Koppelmann 
Cc: Palmer Dabbelt 
Cc: Alistair Francis 
Signed-off-by: Michael Clark 
Reviewed-by: Richard Henderson 
Signed-off-by: Alistair Francis 
---
 hw/riscv/sifive_plic.c | 49 +++---
 include/hw/riscv/sifive_plic.h |  1 -
 2 files changed, 22 insertions(+), 28 deletions(-)

diff --git a/hw/riscv/sifive_plic.c b/hw/riscv/sifive_plic.c
index a91aeb97ab..f635e6ff67 100644
--- a/hw/riscv/sifive_plic.c
+++ b/hw/riscv/sifive_plic.c
@@ -81,36 +81,32 @@ static void sifive_plic_print_state(SiFivePLICState *plic)
 }
 }
 
-static
-void sifive_plic_set_pending(SiFivePLICState *plic, int irq, bool pending)
+static uint32_t atomic_set_masked(uint32_t *a, uint32_t mask, uint32_t value)
 {
-qemu_mutex_lock(&plic->lock);
-uint32_t word = irq >> 5;
-if (pending) {
-plic->pending[word] |= (1 << (irq & 31));
-} else {
-plic->pending[word] &= ~(1 << (irq & 31));
-}
-qemu_mutex_unlock(&plic->lock);
+uint32_t old, new, cmp = atomic_read(a);
+
+do {
+old = cmp;
+new = (old & ~mask) | (value & mask);
+cmp = atomic_cmpxchg(a, old, new);
+} while (old != cmp);
+
+return old;
 }
 
-static
-void sifive_plic_set_claimed(SiFivePLICState *plic, int irq, bool claimed)
+static void sifive_plic_set_pending(SiFivePLICState *plic, int irq, bool level)
 {
-qemu_mutex_lock(&plic->lock);
-uint32_t word = irq >> 5;
-if (claimed) {
-plic->claimed[word] |= (1 << (irq & 31));
-} else {
-plic->claimed[word] &= ~(1 << (irq & 31));
-}
-qemu_mutex_unlock(&plic->lock);
+atomic_set_masked(&plic->pending[irq >> 5], 1 << (irq & 31), -!!level);
 }
 
-static
-int sifive_plic_num_irqs_pending(SiFivePLICState *plic, uint32_t addrid)
+static void sifive_plic_set_claimed(SiFivePLICState *plic, int irq, bool level)
 {
-int i, j, count = 0;
+atomic_set_masked(&plic->claimed[irq >> 5], 1 << (irq & 31), -!!level);
+}
+
+static int sifive_plic_irqs_pending(SiFivePLICState *plic, uint32_t addrid)
+{
+int i, j;
 for (i = 0; i < plic->bitfield_words; i++) {
 uint32_t pending_enabled_not_claimed =
 (plic->pending[i] & ~plic->claimed[i]) &
@@ -123,11 +119,11 @@ int sifive_plic_num_irqs_pending(SiFivePLICState *plic, 
uint32_t addrid)
 uint32_t prio = plic->source_priority[irq];
 int enabled = pending_enabled_not_claimed & (1 << j);
 if (enabled && prio > plic->target_priority[addrid]) {
-count++;
+return 1;
 }
 }
 }
-return count;
+return 0;
 }
 
 static void sifive_plic_update(SiFivePLICState *plic)
@@ -143,7 +139,7 @@ static void sifive_plic_update(SiFivePLICState *plic)
 if (!env) {
 continue;
 }
-int level = sifive_plic_num_irqs_pending(plic, addrid) > 0;
+int level = sifive_plic_irqs_pending(plic, addrid);
 switch (mode) {
 case PLICMode_M:
 riscv_set_local_interrupt(RISCV_CPU(cpu), MIP_MEIP, level);
@@ -439,7 +435,6 @@ static void sifive_plic_realize(DeviceState *dev, Error 
**errp)
 memory_region_init_io(&plic->mmio, OBJECT(dev), &sifive_plic_ops, plic,
   TYPE_SIFIVE_PLIC, plic->aperture_size);
 parse_hart_config(plic);
-qemu_mutex_init(&plic->lock);
 plic->bitfield_words = (plic->num_sources + 31) >> 5;
 plic->source_priority = g_new0(uint32_t, plic->num_sources);
 plic->target_priority = g_new(uint32_t, plic->num_addrs);
diff --git a/include/hw/riscv/sifive_plic.h b/include/hw/riscv/sifive_plic.h
index 2f2af7e686..688cd97f82 100644
--- a/include/hw/riscv/sifive_plic.h
+++ b/include/hw/riscv/sifive_plic.h
@@ -55,7 +55,6 @@ typedef struct SiFivePLICState {
 uint32_t *pending;
 uint32_t *claimed;
 uint32_t *enable;
-QemuMutex lock;
 
 /* config */
 char *hart_config;
-- 
2.17.1




[Qemu-devel] [PULL v2 06/10] target/riscv: optimize indirect branches

2018-09-05 Thread Alistair Francis
From: "Emilio G. Cota" 

Signed-off-by: Emilio G. Cota 
Reviewed-by: Richard Henderson 
Signed-off-by: Alistair Francis 
---
 target/riscv/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/riscv/translate.c b/target/riscv/translate.c
index ec2988b4f6..66a80ca772 100644
--- a/target/riscv/translate.c
+++ b/target/riscv/translate.c
@@ -548,7 +548,7 @@ static void gen_jalr(CPURISCVState *env, DisasContext *ctx, 
uint32_t opc,
 if (rd != 0) {
 tcg_gen_movi_tl(cpu_gpr[rd], ctx->pc_succ_insn);
 }
-tcg_gen_exit_tb(NULL, 0);
+tcg_gen_lookup_and_goto_ptr();
 
 if (misaligned) {
 gen_set_label(misaligned);
-- 
2.17.1




[Qemu-devel] [PULL v2 04/10] RISC-V: Simplify riscv_cpu_local_irqs_pending

2018-09-05 Thread Alistair Francis
From: Michael Clark 

This commit is intended to improve readability.
There is no change to the logic.

Cc: Sagar Karandikar 
Cc: Bastian Koppelmann 
Cc: Palmer Dabbelt 
Cc: Alistair Francis 
Signed-off-by: Michael Clark 
Reviewed-by: Alistair Francis 
Signed-off-by: Alistair Francis 
---
 target/riscv/helper.c | 34 --
 1 file changed, 12 insertions(+), 22 deletions(-)

diff --git a/target/riscv/helper.c b/target/riscv/helper.c
index 1f0527e07f..63b3386b76 100644
--- a/target/riscv/helper.c
+++ b/target/riscv/helper.c
@@ -35,28 +35,18 @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch)
 }
 
 #ifndef CONFIG_USER_ONLY
-/*
- * Return RISC-V IRQ number if an interrupt should be taken, else -1.
- * Used in cpu-exec.c
- *
- * Adapted from Spike's processor_t::take_interrupt()
- */
-static int riscv_cpu_hw_interrupts_pending(CPURISCVState *env)
+static int riscv_cpu_local_irq_pending(CPURISCVState *env)
 {
-target_ulong pending_interrupts = atomic_read(&env->mip) & env->mie;
-
-target_ulong mie = get_field(env->mstatus, MSTATUS_MIE);
-target_ulong m_enabled = env->priv < PRV_M || (env->priv == PRV_M && mie);
-target_ulong enabled_interrupts = pending_interrupts &
-  ~env->mideleg & -m_enabled;
-
-target_ulong sie = get_field(env->mstatus, MSTATUS_SIE);
-target_ulong s_enabled = env->priv < PRV_S || (env->priv == PRV_S && sie);
-enabled_interrupts |= pending_interrupts & env->mideleg &
-  -s_enabled;
-
-if (enabled_interrupts) {
-return ctz64(enabled_interrupts); /* since non-zero */
+target_ulong mstatus_mie = get_field(env->mstatus, MSTATUS_MIE);
+target_ulong mstatus_sie = get_field(env->mstatus, MSTATUS_SIE);
+target_ulong pending = atomic_read(&env->mip) & env->mie;
+target_ulong mie = env->priv < PRV_M || (env->priv == PRV_M && 
mstatus_mie);
+target_ulong sie = env->priv < PRV_S || (env->priv == PRV_S && 
mstatus_sie);
+target_ulong irqs = (pending & ~env->mideleg & -mie) |
+(pending &  env->mideleg & -sie);
+
+if (irqs) {
+return ctz64(irqs); /* since non-zero */
 } else {
 return EXCP_NONE; /* indicates no pending interrupt */
 }
@@ -69,7 +59,7 @@ bool riscv_cpu_exec_interrupt(CPUState *cs, int 
interrupt_request)
 if (interrupt_request & CPU_INTERRUPT_HARD) {
 RISCVCPU *cpu = RISCV_CPU(cs);
 CPURISCVState *env = &cpu->env;
-int interruptno = riscv_cpu_hw_interrupts_pending(env);
+int interruptno = riscv_cpu_local_irq_pending(env);
 if (interruptno >= 0) {
 cs->exception_index = RISCV_EXCP_INT_FLAG | interruptno;
 riscv_cpu_do_interrupt(cs);
-- 
2.17.1




Re: [Qemu-devel] [PULL 0/9] riscv-pullreq queue

2018-09-05 Thread Alistair Francis
On Tue, Sep 4, 2018 at 4:14 PM, Alistair Francis
 wrote:
> The following changes since commit 19b599f7664b2ebfd0f405fb79c14dd241557452:
>
>   Merge remote-tracking branch 'remotes/armbru/tags/pull-error-2018-08-27-v2' 
> into staging (2018-08-27 16:44:20 +0100)
>
> are available in the Git repository at:
>
>   g...@github.com:alistair23/qemu.git tags/pull-riscv-pullreq-20180904
>
> for you to fetch changes up to 3b18c3fa870f11b8a1841bb7537e5bc11100160c:
>
>   riscv: remove define cpu_init() (2018-09-04 13:24:39 -0700)

Disregard this, I have sent a v2.

Alistair

>
> 
> A misc collection of RISC-V related patches for 3.1.
>
> --------
> Alistair Francis (2):
>   hw/riscv/virtio: Set the soc device tree node as a simple-bus
>   hw/riscv/spike: Set the soc device tree node as a simple-bus
>
> Emilio G. Cota (2):
>   target/riscv: optimize indirect branches
>   target/riscv: call gen_goto_tb on DISAS_TOO_MANY
>
> Igor Mammedov (1):
>   riscv: remove define cpu_init()
>
> Michael Clark (4):
>   RISC-V: Update address bits to support sv39 and sv48
>   RISC-V: Improve page table walker spec compliance
>   RISC-V: Use atomic_cmpxchg to update PLIC bitmaps
>   RISC-V: Simplify riscv_cpu_local_irqs_pending
>
>  hw/riscv/sifive_plic.c | 49 ++---
>  hw/riscv/spike.c   |  2 +-
>  hw/riscv/virt.c|  2 +-
>  include/hw/riscv/sifive_plic.h |  1 -
>  target/riscv/cpu.h |  9 ++--
>  target/riscv/cpu_bits.h|  2 -
>  target/riscv/helper.c  | 98 
> --
>  target/riscv/translate.c   |  9 +---
>  8 files changed, 87 insertions(+), 85 deletions(-)
>



[Qemu-devel] [PULL v2 07/10] target/riscv: call gen_goto_tb on DISAS_TOO_MANY

2018-09-05 Thread Alistair Francis
From: "Emilio G. Cota" 

Performance impact of this and the previous commits, measured with
the very-easy-to-cross-compile rv8-bench:
  https://github.com/rv8-io/rv8-bench

Host: Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz

- Key:
  before: master
  after1,2,3: the 3 commits in this series (i.e. 3 is this commit)

- User-mode:

 bench  before  after1  after2  after3  final speedup
-
 aes1.12s   1.12s   1.10s   1.00s   1.12
 bigint 0.78s   0.78s   0.78s   0.78s   1
 dhrystone  0.96s   0.97s   0.49s   0.49s   1.9591837
 miniz  1.94s   1.94s   1.88s   1.86s   1.0430108
 norx   0.51s   0.51s   0.49s   0.48s   1.0625
 primes 0.85s   0.85s   0.84s   0.84s   1.0119048
 qsort  4.87s   4.88s   1.86s   1.86s   2.6182796
 sha512 0.76s   0.77s   0.64s   0.64s   1.1875

(after1 only applies to softmmu, so no surprises here)

- Full-system (fedora):

 bench  before  after1  after2  after3  final speedup
-
 aes2.68s   2.54s   2.60s   2.34s   1.1452991
 bigint 1.61s   1.56s   1.55s   1.64s   0.98170732
 dhrystone  1.78s   1.67s   1.25s   1.24s   1.4354839
 miniz  3.53s   3.35s   3.28s   3.35s   1.0537313
 norx   1.13s   1.09s   1.07s   1.06s   1.0660377
 primes 15.37s  15.41s  15.20s  15.37s  1
 qsort  7.20s   6.71s   3.85s   3.96s   1.8181818
 sha512 1.07s   1.04s   0.90s   0.90s   1.189

SoftMMU slows things down, so the numbers are less sensitive.
Cross-page jumps improve things a little bit, though.

Note that I'm not showing here averages, just results from a
single run, so with primes there isn't much to worry about.

Signed-off-by: Emilio G. Cota 
Reviewed-by: Richard Henderson 
Signed-off-by: Alistair Francis 
---
 target/riscv/translate.c | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/target/riscv/translate.c b/target/riscv/translate.c
index 66a80ca772..18d7b6d147 100644
--- a/target/riscv/translate.c
+++ b/target/riscv/translate.c
@@ -1868,12 +1868,7 @@ static void riscv_tr_tb_stop(DisasContextBase *dcbase, 
CPUState *cpu)
 
 switch (ctx->base.is_jmp) {
 case DISAS_TOO_MANY:
-tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next);
-if (ctx->base.singlestep_enabled) {
-gen_exception_debug();
-} else {
-tcg_gen_exit_tb(NULL, 0);
-}
+gen_goto_tb(ctx, 0, ctx->base.pc_next);
 break;
 case DISAS_NORETURN:
 break;
-- 
2.17.1




Re: [Qemu-devel] [RFC v1 3/4] util/oslib-win32: Fix up if conditional

2017-06-29 Thread Alistair Francis
On Thu, Jun 29, 2017 at 5:25 AM, Paolo Bonzini  wrote:
>
>
> On 28/06/2017 01:57, Alistair Francis wrote:
>> Signed-off-by: Alistair Francis 
>> Acked-by: Edgar E. Iglesias 
>> ---
>>
>>  util/oslib-win32.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
>> index 7ec0f8e083..a015e1ac96 100644
>> --- a/util/oslib-win32.c
>> +++ b/util/oslib-win32.c
>> @@ -438,7 +438,7 @@ static int poll_rest(gboolean poll_msgs, HANDLE 
>> *handles, gint nhandles,
>>  if (timeout == 0 && nhandles > 1) {
>>  /* Remove the handle that fired */
>>  int i;
>> -if (ready < nhandles - 1) {
>> +if ((ready - WAIT_OBJECT_0) < nhandles - 1) {
>>  for (i = ready - WAIT_OBJECT_0 + 1; i < nhandles; i++) {
>>  handles[i-1] = handles[i];
>>  }
>>
>
> WAIT_OBJECT_0 is zero, but I agree it's better to add it.
>
> However, the condition can be rewritten as ready - WAIT_OBJECT_0 + 1 <
> nhandles, which is the same as the first iteration's "i < nhandles".  So
> I'd just remove the "if" and "unindent" the for loop.

Ah, good spot. I'll remove it.

Thanks,
Alistair

>
> Paolo



Re: [Qemu-devel] [RFC v1 4/4] util/oslib-win32: Recursivly pass the timeout

2017-06-29 Thread Alistair Francis
On Thu, Jun 29, 2017 at 5:34 AM, Paolo Bonzini  wrote:
>
>
> On 28/06/2017 01:57, Alistair Francis wrote:
>> +/* We only found one and we are waiting on more then one. Let's try
>> + * again.
>>   */
>> -if (timeout == 0 && nhandles > 1) {
>> +if (nhandles > 1) {
>>  /* Remove the handle that fired */
>>  int i;
>>  if ((ready - WAIT_OBJECT_0) < nhandles - 1) {
>> @@ -444,7 +444,20 @@ static int poll_rest(gboolean poll_msgs, HANDLE 
>> *handles, gint nhandles,
>>  }
>>  }
>>  nhandles--;
>> -recursed_result = poll_rest(FALSE, handles, nhandles, fds, 
>> nfds, 0);
>> +
>> +/* If we just had a very small timeout let's increase it when we
>> + * recurse to ensure we don't just busy wait. This ensures we 
>> let
>> + * the Windows threads block at least a little. If we previously
>> + * had some wait let's set it to zero to avoid blocking for too
>> + * long.
>> + */
>> +if (timeout < 10) {
>> +timeout = timeout + 1;
>> +} else {
>> +timeout = 0;
>> +}
>> +recursed_result = poll_rest(FALSE, handles, nhandles, fds,
>> +nfds, timeout);
>>  return (recursed_result == -1) ? -1 : 1 + recursed_result;
>
> I'm not sure I agree with this change, which is effectively delaying the
> processing of events.  The question to me is which handles are
> triggering so fast that QEMU effectively busy waits.

Yeah, that is what I was trying to figure out, but didn't make much headway.

I kept seeing zero timeouts, which means that the thread never blocks
and this patch helps a lot.

>
> Maybe your QEMUs can get some breath with commit 12f8def0e0 ("win32:
> replace custom mutex and condition variable with native primitives",
> 2017-03-27), since the native primitives are more efficient and TCG 2.8
> used condvars a lot for qemu_io_proceeded_cond.

Ok, I will try that.

Does this mean you don't see the same slowness on QEMU 2.9?

Thanks,
Alistair

>
> Paolo



Re: [Qemu-devel] [RFC v1 2/4] util/oslib-win32: Remove invalid check

2017-06-29 Thread Alistair Francis
On Thu, Jun 29, 2017 at 6:32 AM, Paolo Bonzini  wrote:
> On 28/06/2017 01:57, Alistair Francis wrote:
>> There is no way nhandles can be zero in this section so that part of the
>> if statement will always be false. Let's just remove it to make the code
>> easier to read.
>>
>> Signed-off-by: Alistair Francis 
>> Acked-by: Edgar E. Iglesias 
>> ---
>>
>>  util/oslib-win32.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
>> index 80e4668935..7ec0f8e083 100644
>> --- a/util/oslib-win32.c
>> +++ b/util/oslib-win32.c
>> @@ -414,7 +414,7 @@ static int poll_rest(gboolean poll_msgs, HANDLE 
>> *handles, gint nhandles,
>>  /* If we have a timeout, or no handles to poll, be satisfied
>>   * with just noticing we have messages waiting.
>>   */
>> -if (timeout != 0 || nhandles == 0) {
>> +if (timeout != 0) {
>>  return 1;
>>  }
>>
>>
>
> Hmm, I think it's possible, poll_msgs is true here.

poll_msgs?

If nhandles is 0 then we have already entered an earlier if statement
and set ready to either WAIT_FAILED or WAIT_TIMEOUT in which case we
can't enter this part of the if statement.

Thanks,
Alistair

>
> Paolo



[Qemu-devel] [PATCH v1 1/3] util/aio-win32: Only select on what we are actually waiting for

2017-06-29 Thread Alistair Francis
Signed-off-by: Alistair Francis 
Acked-by: Edgar E. Iglesias 
---
Changes since RFC:
 - Include more bitmasks for the select call

 util/aio-win32.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/util/aio-win32.c b/util/aio-win32.c
index bca496a47a..d6d5e02f00 100644
--- a/util/aio-win32.c
+++ b/util/aio-win32.c
@@ -71,6 +71,7 @@ void aio_set_fd_handler(AioContext *ctx,
 }
 } else {
 HANDLE event;
+long bitmask = 0;
 
 if (node == NULL) {
 /* Alloc and insert if it's not already there */
@@ -95,10 +96,16 @@ void aio_set_fd_handler(AioContext *ctx,
 node->io_write = io_write;
 node->is_external = is_external;
 
+if (io_read) {
+bitmask |= FD_READ | FD_ACCEPT | FD_CLOSE;
+}
+
+if (io_write) {
+bitmask |= FD_WRITE | FD_CONNECT;
+}
+
 event = event_notifier_get_handle(&ctx->notifier);
-WSAEventSelect(node->pfd.fd, event,
-   FD_READ | FD_ACCEPT | FD_CLOSE |
-   FD_CONNECT | FD_WRITE | FD_OOB);
+WSAEventSelect(node->pfd.fd, event, bitmask);
 }
 
 qemu_lockcnt_unlock(&ctx->list_lock);
-- 
2.11.0




[Qemu-devel] [PATCH v1 0/3] Windows runtime improvements

2017-06-29 Thread Alistair Francis
Changes since RFC:
 - Remove controversial timeout increate patch (util/oslib-win32:
   Recursivly pass the timeout) from the series
 - Small adjustments based on comments
 - Change from RFC to patch series

Original cover letter:

At Xilinx we have started to run our fork of QEMU on Windows and are
starting to distrubute this to customers. As part of this QEMU is
launched from an Eclipse based GUI on Windows hosts. This uncovered a
few performance issues in QEMU when running on CPU restricted machines.

What we see is that when QEMU is run on a machine where there aren't
enough spare CPUs on the host, QEMU is extreamly slow. We especially see
this when running our multi-architecture QEMU setup (MicroBlaze and ARM)
because we are running two QEMU instances as well as what else is
running on the machine.

Generally two instances of QEMU will never reach a Linux login prompt
when run on four host CPUs, but will reach the login prompt when run on
eight CPUs.

We investigated the issue and realised that it is mostly because QEMU
did not block and instead the IO thread just busy looped. This basically
locked up two CPUs (two QEMU instances) with IO threads not leaving
enough resources on the machine.

This patch series fixed the issue for us on our fork of QEMU. Our fork
is based on QEMU 2.8.1 and does not include MTTCG support. I have not
tested this on the mainline QEMU or with MTTCG. It is on my todo list to
see if I can repdouce the same issue on Windows with mainline QEMU. In
the meantime I wanted to send this series to see if anyone else has seen
Windows performance issues and if this helps with the problems. In order
to see the issue we had to do a full Linux boot, smaller baremetal
applications generally don't reproduce the same issue.

Also, most of these patches are editing the QEMU implementation of Glib,
obviously these fixes (if applicable) will need to be ported to Glib and
applied there as well. I just wanted to start here.

Alistair Francis (3):
  util/aio-win32: Only select on what we are actually waiting for
  util/oslib-win32: Remove invalid check
  util/oslib-win32: Remove if conditional

 util/aio-win32.c   | 13 ++---
 util/oslib-win32.c |  8 +++-
 2 files changed, 13 insertions(+), 8 deletions(-)

-- 
2.11.0




[Qemu-devel] [PATCH v1 3/3] util/oslib-win32: Remove if conditional

2017-06-29 Thread Alistair Francis
The original ready < nhandles - 1 can be re-written as ready + 1 <
nhandles which is the same confition that we are checking on the first
itteration of the for loop. This means we can remove the if statement
and let the for loop check the code.

This also has the side effect of removing an invalid check as
WAIT_OBJECT_0 was not subtracted from ready.

Signed-off-by: Alistair Francis 
---

 util/oslib-win32.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 7ec0f8e083..d42d695050 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -438,10 +438,8 @@ static int poll_rest(gboolean poll_msgs, HANDLE *handles, 
gint nhandles,
 if (timeout == 0 && nhandles > 1) {
 /* Remove the handle that fired */
 int i;
-if (ready < nhandles - 1) {
-for (i = ready - WAIT_OBJECT_0 + 1; i < nhandles; i++) {
-handles[i-1] = handles[i];
-}
+for (i = ready - WAIT_OBJECT_0 + 1; i < nhandles; i++) {
+handles[i-1] = handles[i];
 }
 nhandles--;
 recursed_result = poll_rest(FALSE, handles, nhandles, fds, nfds, 
0);
-- 
2.11.0




[Qemu-devel] [PATCH v1 2/3] util/oslib-win32: Remove invalid check

2017-06-29 Thread Alistair Francis
There is no way nhandles can be zero in this section so that part of the
if statement will always be false. Let's just remove it to make the code
easier to read.

Signed-off-by: Alistair Francis 
Acked-by: Edgar E. Iglesias 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Fam Zheng 
---

 util/oslib-win32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 80e4668935..7ec0f8e083 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -414,7 +414,7 @@ static int poll_rest(gboolean poll_msgs, HANDLE *handles, 
gint nhandles,
 /* If we have a timeout, or no handles to poll, be satisfied
  * with just noticing we have messages waiting.
  */
-if (timeout != 0 || nhandles == 0) {
+if (timeout != 0) {
 return 1;
 }
 
-- 
2.11.0




[Qemu-devel] [RFC v2 2/3] qemu-error: Implement a more generic error reporting

2017-06-29 Thread Alistair Francis
This patch removes the exisinting error_vreport() function and replaces it
with a more generic vreport() function that takes an enum describing the
information to be reported.

As part of this change a report() function is added as well with the
same capability.

To maintain full compatibility the original error_report() function is
maintained and no changes to the way errors are printed have been made.

Signed-off-by: Alistair Francis 
---

 hw/virtio/virtio.c  |  2 +-
 include/qemu/error-report.h | 10 +-
 scripts/checkpatch.pl   |  3 ++-
 util/qemu-error.c   | 33 ++---
 4 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 464947f76d..bd3d26abb7 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -2448,7 +2448,7 @@ void GCC_FMT_ATTR(2, 3) virtio_error(VirtIODevice *vdev, 
const char *fmt, ...)
 va_list ap;
 
 va_start(ap, fmt);
-error_vreport(fmt, ap);
+vreport(ERROR, fmt, ap);
 va_end(ap);
 
 if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) {
diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index 3001865896..39b554c3b9 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -21,6 +21,12 @@ typedef struct Location {
 struct Location *prev;
 } Location;
 
+typedef enum {
+ERROR,
+WARN,
+INFO,
+} report_types;
+
 Location *loc_push_restore(Location *loc);
 Location *loc_push_none(Location *loc);
 Location *loc_pop(Location *loc);
@@ -30,12 +36,14 @@ 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 vreport(report_types type, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 
0);
+void report(report_types type, const char *fmt, ...)  GCC_FMT_ATTR(2, 3);
+
 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 error_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
 const char *error_get_progname(void);
 extern bool enable_timestamp_msg;
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 45027b9281..4a3074e758 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2530,7 +2530,8 @@ sub process {
error_set|
error_prepend|
error_reportf_err|
-   error_vreport|
+   vreport|
+   report|
error_report}x;
 
if ($rawline =~ /\b(?:$qemu_error_funcs)\s*\(.*\".*\\n/) {
diff --git a/util/qemu-error.c b/util/qemu-error.c
index 1c5e35ecdb..83206532dd 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -179,17 +179,28 @@ static void print_loc(void)
 
 bool enable_timestamp_msg;
 /*
- * Print an error message to current monitor if we have one, else to stderr.
+ * Print a message to current monitor if we have one, else to stderr.
  * Format arguments like vsprintf().  The resulting message should be
  * a single phrase, with no newline or trailing punctuation.
  * Prepend the current location and append a newline.
  * It's wrong to call this in a QMP monitor.  Use error_setg() there.
  */
-void error_vreport(const char *fmt, va_list ap)
+void vreport(report_types type, const char *fmt, va_list ap)
 {
 GTimeVal tv;
 gchar *timestr;
 
+switch (type) {
+case ERROR:
+/* To maintin compatibility we don't add anything here */
+break;
+case WARN:
+error_printf("warning: ");
+break;
+case INFO:
+error_printf("info: ");
+break;
+}
 if (enable_timestamp_msg && !cur_mon) {
 g_get_current_time(&tv);
 timestr = g_time_val_to_iso8601(&tv);
@@ -203,6 +214,22 @@ void error_vreport(const char *fmt, va_list ap)
 }
 
 /*
+ * Print a message to current monitor if we have one, else to stderr.
+ * Format arguments like sprintf().  The resulting message should be a
+ * single phrase, with no newline or trailing punctuation.
+ * Prepend the current location and append a newline.
+ * It's wrong to call this in a QMP monitor.  Use error_setg() there.
+ */
+void report(report_types type, const char *fmt, ...)
+{
+va_list ap;
+
+va_start(ap, fmt);
+vreport(type, fmt, ap);
+va_end(ap);
+}
+
+/*
  * Print an error message to current monitor if we have one, else to stderr.
  * Format arguments like sprintf().  The resulting message should be a
  * single phrase, with no newline or trailing punctuation.
@@ -214,6 +241,6

[Qemu-devel] [RFC v2 0/3] Implement a warning_report function

2017-06-29 Thread Alistair Francis
QEMU currently has a standard method to report errors with
error_repot(). This ensure a sane and standard format when printing
errors. This series is attempting to extend this functionality for
warnings and information as well.

At the moment only one error is being converted, I wanted to get the
implementation nailed down a little bit before I started converting
others.

This patch renames error_print_loc() function to be more clear, but I
didn't bother renaming the others. It seems silly to change
error_printf() to error_warning_printf() and printf is already taken so
I just left it as is.

I also didn't change the current error output as that would probably
break backwards compatibilty for anyone who is parsing logs.

RFCv2:
 - Use enums for ERROR, WARN and INFO with a generic report() function
   instead of adding new functions

Alistair Francis (3):
  util/qemu-error: Rename error_print_loc() to be more generic
  qemu-error: Implement a more generic error reporting
  char-socket: Report TCP socket waiting as information

 chardev/char-socket.c   |  2 +-
 hw/virtio/virtio.c  |  2 +-
 include/qemu/error-report.h | 10 +-
 scripts/checkpatch.pl   |  3 ++-
 util/qemu-error.c   | 37 -
 5 files changed, 45 insertions(+), 9 deletions(-)

-- 
2.11.0




[Qemu-devel] [RFC v2 1/3] util/qemu-error: Rename error_print_loc() to be more generic

2017-06-29 Thread Alistair Francis
Rename the error_print_loc() function in preparation for using it to
print warnings as well.

Signed-off-by: Alistair Francis 
Reviewed-by: Philippe Mathieu-Daudé 
---

 util/qemu-error.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/util/qemu-error.c b/util/qemu-error.c
index b331f8f4a4..1c5e35ecdb 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -146,7 +146,7 @@ const char *error_get_progname(void)
 /*
  * Print current location to current monitor if we have one, else to stderr.
  */
-static void error_print_loc(void)
+static void print_loc(void)
 {
 const char *sep = "";
 int i;
@@ -197,7 +197,7 @@ void error_vreport(const char *fmt, va_list ap)
 g_free(timestr);
 }
 
-error_print_loc();
+print_loc();
 error_vprintf(fmt, ap);
 error_printf("\n");
 }
-- 
2.11.0




[Qemu-devel] [RFC v2 3/3] char-socket: Report TCP socket waiting as information

2017-06-29 Thread Alistair Francis
When QEMU is waiting for a TCP socket connection it reports that message as
an error. This isn't an error it is just informaiton so let's change the
report to use report() instead.

Signed-off-by: Alistair Francis 
---

 chardev/char-socket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index ccc499cfa1..ad1b3d6e93 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -765,7 +765,7 @@ static int tcp_chr_wait_connected(Chardev *chr, Error 
**errp)
  * in TLS and telnet cases, only wait for an accepted socket */
 while (!s->ioc) {
 if (s->is_listen) {
-error_report("QEMU waiting for connection on: %s",
+report(INFO, "QEMU waiting for connection on: %s",
  chr->filename);
 qio_channel_set_blocking(QIO_CHANNEL(s->listen_ioc), true, NULL);
 tcp_chr_accept(QIO_CHANNEL(s->listen_ioc), G_IO_IN, chr);
-- 
2.11.0




Re: [Qemu-devel] [RFC v1 4/4] util/oslib-win32: Recursivly pass the timeout

2017-06-29 Thread Alistair Francis
On Thu, Jun 29, 2017 at 12:47 PM, Paolo Bonzini  wrote:
>> On Thu, Jun 29, 2017 at 5:34 AM, Paolo Bonzini  wrote:
>> > On 28/06/2017 01:57, Alistair Francis wrote:
>> > I'm not sure I agree with this change, which is effectively delaying the
>> > processing of events.  The question to me is which handles are
>> > triggering so fast that QEMU effectively busy waits.
>>
>> Yeah, that is what I was trying to figure out, but didn't make much headway.
>>
>> I kept seeing zero timeouts, which means that the thread never blocks
>> and this patch helps a lot.
>
> Perhaps you can use tracepoints?  There shouldn't be many handles registered,
> since on Windows even the GUI actions all go through messages.
>
>> > Maybe your QEMUs can get some breath with commit 12f8def0e0 ("win32:
>> > replace custom mutex and condition variable with native primitives",
>> > 2017-03-27), since the native primitives are more efficient and TCG 2.8
>> > used condvars a lot for qemu_io_proceeded_cond.
>>
>> Ok, I will try that.

No luck, I tried applying that and it didn't make any difference.

>>
>> Does this mean you don't see the same slowness on QEMU 2.9?
>
> I have not tried, but the patch is only working around the real issue,
> as Fam pointed out.

Agreed. I'll keep digging and see what I can find.

Thanks,
Alistair

>
> Paolo
>



Re: [Qemu-devel] [RFC v2 3/3] char-socket: Report TCP socket waiting as information

2017-06-29 Thread Alistair Francis
On Thu, Jun 29, 2017 at 1:48 PM, Eric Blake  wrote:
> On 06/29/2017 02:42 PM, Alistair Francis wrote:
>> When QEMU is waiting for a TCP socket connection it reports that message as
>> an error. This isn't an error it is just informaiton so let's change the
>> report to use report() instead.
>>
>> Signed-off-by: Alistair Francis 
>> ---
>>
>>  chardev/char-socket.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/chardev/char-socket.c b/chardev/char-socket.c
>> index ccc499cfa1..ad1b3d6e93 100644
>> --- a/chardev/char-socket.c
>> +++ b/chardev/char-socket.c
>> @@ -765,7 +765,7 @@ static int tcp_chr_wait_connected(Chardev *chr, Error 
>> **errp)
>>   * in TLS and telnet cases, only wait for an accepted socket */
>>  while (!s->ioc) {
>>  if (s->is_listen) {
>> -error_report("QEMU waiting for connection on: %s",
>> +report(INFO, "QEMU waiting for connection on: %s",
>>   chr->filename);
>
> Indentation looks off now; I'd scoot chr->filename to live right under INFO.

Woops I missed that. Thanks, I made your fixes to both patches.

Thanks,
Alistair

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



Re: [Qemu-devel] [RFC v1 2/4] util/oslib-win32: Remove invalid check

2017-07-05 Thread Alistair Francis
On Fri, Jun 30, 2017 at 3:37 AM, Paolo Bonzini  wrote:
>
>
> On 29/06/2017 18:37, Alistair Francis wrote:
>>> Hmm, I think it's possible, poll_msgs is true here.
>> poll_msgs?
>>
>> If nhandles is 0 then we have already entered an earlier if statement
>> and set ready to either WAIT_FAILED or WAIT_TIMEOUT in which case we
>> can't enter this part of the if statement.
>
> No, that's not correct.  The code is:
>
> if (poll_msgs) {
> /* Wait for either messages or handles
>  * -> Use MsgWaitForMultipleObjectsEx
>  */
> ready = MsgWaitForMultipleObjectsEx(nhandles, handles, timeout,
> QS_ALLINPUT, MWMO_ALERTABLE);
>
> if (ready == WAIT_FAILED) {
> gchar *emsg = g_win32_error_message(GetLastError());
> g_warning("MsgWaitForMultipleObjectsEx failed: %s", emsg);
> g_free(emsg);
> }
> } else if (nhandles == 0) {
> /* No handles to wait for, just the timeout */
> if (timeout == INFINITE) {
> ready = WAIT_FAILED;
> } else {
> SleepEx(timeout, TRUE);
> ready = WAIT_TIMEOUT;
> }
>
> You can have poll_msgs == TRUE && nhandles == 0.  This happens for
>
>GPollFD fds[1] = { .fd = G_WIN32_MSG_HANDLE, .events = G_IO_IN };
>g_poll(fds, 1, timeout);

Ah. Yeah good point.

Ok, I'll respin the series without this patch then.

Thanks,
Alistair

>
> Thanks,
>
> Paolo
>



Re: [Qemu-devel] [RFC v2 2/3] qemu-error: Implement a more generic error reporting

2017-07-05 Thread Alistair Francis
On Mon, Jul 3, 2017 at 11:53 PM, Markus Armbruster  wrote:
> "Daniel P. Berrange"  writes:
>
>> On Mon, Jul 03, 2017 at 04:07:21PM +0200, Markus Armbruster wrote:
>>> "Daniel P. Berrange"  writes:
>>>
>>> > On Thu, Jun 29, 2017 at 12:42:38PM -0700, Alistair Francis wrote:
>>> >> This patch removes the exisinting error_vreport() function and replaces 
>>> >> it
>>> >> with a more generic vreport() function that takes an enum describing the
>>> >> information to be reported.
>>>
>>> Why remove error_vreport()?

I just thought that the name didn't make sense now that we are using
it for info and warning reports as well.

>>>
>>> >> As part of this change a report() function is added as well with the
>>> >> same capability.
>>> >>
>>> >> To maintain full compatibility the original error_report() function is
>>> >> maintained and no changes to the way errors are printed have been made.
>>> >>
>>> >> Signed-off-by: Alistair Francis 
>>> >> ---
>>> >>
>>> >>  hw/virtio/virtio.c  |  2 +-
>>> >>  include/qemu/error-report.h | 10 +-
>>> >>  scripts/checkpatch.pl   |  3 ++-
>>> >>  util/qemu-error.c   | 33 ++---
>>> >>  4 files changed, 42 insertions(+), 6 deletions(-)
>>> >>
>>> >> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
>>> >> index 464947f76d..bd3d26abb7 100644
>>> >> --- a/hw/virtio/virtio.c
>>> >> +++ b/hw/virtio/virtio.c
>>> >> @@ -2448,7 +2448,7 @@ void GCC_FMT_ATTR(2, 3) virtio_error(VirtIODevice 
>>> >> *vdev, const char *fmt, ...)
>>> >>  va_list ap;
>>> >>
>>> >>  va_start(ap, fmt);
>>> >> -error_vreport(fmt, ap);
>>> >> +vreport(ERROR, fmt, ap);
>>> >>  va_end(ap);
>>> >>
>>> >>  if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) {
>>> >> diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
>>> >> index 3001865896..39b554c3b9 100644
>>> >> --- a/include/qemu/error-report.h
>>> >> +++ b/include/qemu/error-report.h
>>> >> @@ -21,6 +21,12 @@ typedef struct Location {
>>> >>  struct Location *prev;
>>> >>  } Location;
>>> >>
>>> >> +typedef enum {
>>> >> +ERROR,
>>> >> +WARN,
>>> >> +INFO,
>>> >> +} report_types;
>>> >
>>> > Woah, those are faaar to generic names to be used. There is way too much
>>> > chance of those clashing with definitions from headers we pull in - 
>>> > particularly
>>> > windows which pollutes its system headers with loads of generic names.
>>> >
>>> > I'd suggest  QMSG_ERROR, QMSG_WARN, QMSG_INFO
>>> >
>>> >> +
>>> >>  Location *loc_push_restore(Location *loc);
>>> >>  Location *loc_push_none(Location *loc);
>>> >>  Location *loc_pop(Location *loc);
>>> >> @@ -30,12 +36,14 @@ 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 vreport(report_types type, const char *fmt, va_list ap) 
>>> >> GCC_FMT_ATTR(2, 0);
>>> >> +void report(report_types type, const char *fmt, ...)  GCC_FMT_ATTR(2, 
>>> >> 3);
>>> >
>>> > Those names are too generic too IMHO.  I'd suggest  qmsg_report, 
>>> > qmsg_vreport

Ok, I was trying to make them as short as possible to allow less line
wrapping, but I agree report() is too generic.

>>> >
>>> > As mentioned in the previous review, there should be wrappers which
>>> > call these with suitable enum to make usage less verbose. eg
>>> >
>>> >   qmsg_info(fmt, )  should call qmsg_report(QMSG_INFO, fmt, ...)
>>> >   qmsg_vinfo(fmt, )  should call qmsg_vreport(QMSG_INFO, fmt, ...)
>>> >
>>> > likewise, for other message levels
>>>
>>> We then have qmsg_warning() for warnings, and error_report() for errors.
>>> Ugh!
>>>
>>> If I had known back then what I know now, I wouldn't have used the
>>> error_ prefix.
>>>
>>> Naming things is hard.
>>>
>>> Ideas anyone?
>>
>> I guess implicit in my suggestion would be to switch to qmsg_error()
>> over some (long) period of time, but that would be a massive amount
>> of churn that would harm backporting.
>>
>> So perhaps, just have error_report warning_report, info_report, and
>> accept that the naming convention is slightly reversed from "normality"
>
> That's not half bad.
>
> The matching enum would be
>
> typedef enum {
> REPORT_TYPE_ERROR,
> REPORT_TYPE_WARNING,
> REPORT_TYPE_INFO,
> } report_type;
>
> Note the typedef name is *singular*.  Compare
>
> report_type rtype;
>
> to
>
> report_types rtype;
>
> @rtype is *one* report type, not multiple.
>
> Let's stick report_type, report() and vreport() into qemu-error.c
> (static linkage) until we have a genuine need for them elsewhere.

Ok, I'll send out another version later today then.

Thanks,
Alistair



[Qemu-devel] [RFC v3 0/3] Implement a warning_report function

2017-07-05 Thread Alistair Francis
QEMU currently has a standard method to report errors with
error_repot(). This ensure a sane and standard format when printing
errors. This series is attempting to extend this functionality for
warnings and information as well.

At the moment only one error is being converted, I wanted to get the
implementation nailed down a little bit before I started converting
others.

This patch renames error_print_loc() function to be more clear, but I
didn't bother renaming the others. It seems silly to change
error_printf() to error_warning_printf() and printf is already taken so
I just left it as is.

I also didn't change the current error output as that would probably
break backwards compatibilty for anyone who is parsing logs.

RFCv3:
 - Use more detailed enum and function names
 - Add wrapper functions for the info and warning reporting
RFCv2:
 - Use enums for ERROR, WARN and INFO with a generic report() function
   instead of adding new functions

Alistair Francis (3):
  util/qemu-error: Rename error_print_loc() to be more generic
  qemu-error: Implement a more generic error reporting
  char-socket: Report TCP socket waiting as information

 chardev/char-socket.c   |  4 +--
 include/qemu/error-report.h | 16 +
 scripts/checkpatch.pl   |  8 -
 util/qemu-error.c   | 84 ++---
 4 files changed, 104 insertions(+), 8 deletions(-)

-- 
2.11.0




[Qemu-devel] [RFC v3 1/3] util/qemu-error: Rename error_print_loc() to be more generic

2017-07-05 Thread Alistair Francis
Rename the error_print_loc() function in preparation for using it to
print warnings as well.

Signed-off-by: Alistair Francis 
Reviewed-by: Philippe Mathieu-Daudé 
---

 util/qemu-error.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/util/qemu-error.c b/util/qemu-error.c
index b331f8f4a4..1c5e35ecdb 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -146,7 +146,7 @@ const char *error_get_progname(void)
 /*
  * Print current location to current monitor if we have one, else to stderr.
  */
-static void error_print_loc(void)
+static void print_loc(void)
 {
 const char *sep = "";
 int i;
@@ -197,7 +197,7 @@ void error_vreport(const char *fmt, va_list ap)
 g_free(timestr);
 }
 
-error_print_loc();
+print_loc();
 error_vprintf(fmt, ap);
 error_printf("\n");
 }
-- 
2.11.0




[Qemu-devel] [RFC v3 3/3] char-socket: Report TCP socket waiting as information

2017-07-05 Thread Alistair Francis
When QEMU is waiting for a TCP socket connection it reports that message as
an error. This isn't an error it is just information so let's change the
report to use info_report() instead.

Signed-off-by: Alistair Francis 
---

 chardev/char-socket.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index ccc499cfa1..a050a686ea 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -765,8 +765,8 @@ static int tcp_chr_wait_connected(Chardev *chr, Error 
**errp)
  * in TLS and telnet cases, only wait for an accepted socket */
 while (!s->ioc) {
 if (s->is_listen) {
-error_report("QEMU waiting for connection on: %s",
- chr->filename);
+info_report("QEMU waiting for connection on: %s",
+chr->filename);
 qio_channel_set_blocking(QIO_CHANNEL(s->listen_ioc), true, NULL);
 tcp_chr_accept(QIO_CHANNEL(s->listen_ioc), G_IO_IN, chr);
 qio_channel_set_blocking(QIO_CHANNEL(s->listen_ioc), false, NULL);
-- 
2.11.0




[Qemu-devel] [RFC v3 2/3] qemu-error: Implement a more generic error reporting

2017-07-05 Thread Alistair Francis
This patch converts the existing error_vreport() function into a generic
qmesg_vreport() function that takes an enum describing the
information to be reported.

As part of this change a new qmesg_report() function is added as well with the
same capability.

To maintain full compatibility the original error_report() function is
maintained and no changes to the way errors are printed have been made.
To improve access to the new informaiton and warning options wrapper functions
similar to error_report() have been added for warnings and information
printing.

Signed-off-by: Alistair Francis 
---
RFC V3:
 - Change the function and enum names to be more descriptive
 - Add wrapper functions for *_report() and *_vreport()

 include/qemu/error-report.h | 16 +
 scripts/checkpatch.pl   |  8 -
 util/qemu-error.c   | 80 +++--
 3 files changed, 100 insertions(+), 4 deletions(-)

diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index 3001865896..62fc167ace 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -21,6 +21,12 @@ typedef struct Location {
 struct Location *prev;
 } Location;
 
+typedef enum {
+REPORT_TYPE_ERROR,
+REPORT_TYPE_WARNING,
+REPORT_TYPE_INFO,
+} report_type;
+
 Location *loc_push_restore(Location *loc);
 Location *loc_push_none(Location *loc);
 Location *loc_pop(Location *loc);
@@ -30,13 +36,23 @@ 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 qmsg_vreport(report_type type, const char *fmt, va_list ap) 
GCC_FMT_ATTR(2, 0);
+void qmsg_report(report_type type, const char *fmt, ...)  GCC_FMT_ATTR(2, 3);
+
 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);
+void info_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
+
 void error_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+void warn_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+void info_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+
 const char *error_get_progname(void);
 extern bool enable_timestamp_msg;
 
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 45027b9281..8b02621739 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2530,8 +2530,14 @@ sub process {
error_set|
error_prepend|
error_reportf_err|
+   qmsg_vreport|
error_vreport|
-   error_report}x;
+   warn_vreport|
+   info_vreport|
+   qmsg_report|
+   error_report|
+   warn_report|
+   info_report}x;
 
if ($rawline =~ /\b(?:$qemu_error_funcs)\s*\(.*\".*\\n/) {
ERROR("Error messages should not contain newlines\n" . 
$herecurr);
diff --git a/util/qemu-error.c b/util/qemu-error.c
index 1c5e35ecdb..63fdc0e174 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -179,17 +179,29 @@ static void print_loc(void)
 
 bool enable_timestamp_msg;
 /*
- * Print an error message to current monitor if we have one, else to stderr.
+ * Print a message to current monitor if we have one, else to stderr.
  * Format arguments like vsprintf().  The resulting message should be
  * a single phrase, with no newline or trailing punctuation.
  * Prepend the current location and append a newline.
  * It's wrong to call this in a QMP monitor.  Use error_setg() there.
  */
-void error_vreport(const char *fmt, va_list ap)
+void qmsg_vreport(report_type type, const char *fmt, va_list ap)
 {
 GTimeVal tv;
 gchar *timestr;
 
+switch (type) {
+case REPORT_TYPE_ERROR:
+/* To maintain compatibility we don't add anything here */
+break;
+case REPORT_TYPE_WARNING:
+error_printf("warning: ");
+break;
+case REPORT_TYPE_INFO:
+error_printf("info: ");
+break;
+}
+
 if (enable_timestamp_msg && !cur_mon) {
 g_get_current_time(&tv);
 timestr = g_time_val_to_iso8601(&tv);
@@ -204,16 +216,78 @@ void error_vreport(const char *fmt, va_list ap)
 
 /*
  * Print an error message to current monitor if we have one, else to stderr.
+ */
+void error_vreport(const char *fmt, va_list ap)
+{
+qmsg_vreport(REPORT_TYPE_ERROR, fmt, ap);
+}
+
+/*
+ * Pr

Re: [Qemu-devel] [Qemu devel v6 PATCH 1/5] msf2: Add Smartfusion2 System timer

2017-07-05 Thread Alistair Francis
; +case R_TIM_VAL:
> +ret = ptimer_get_count(st->ptimer);
> +break;
> +
> +case R_TIM_MIS:
> +isr = !!(st->regs[R_TIM_RIS] & TIMER_RIS_ACK);
> +ier = !!(st->regs[R_TIM_CTRL] & TIMER_CTRL_INTR);
> +ret = ier & isr;
> +break;
> +
> +default:
> +if (addr < NUM_TIMERS * R_TIM1_MAX) {

Shouldn't this just be: addr < R_TIM1_MAX?

At this point you have already subjected the offset for multiple timers.

> +ret = st->regs[addr];
> +} else {
> +qemu_log_mask(LOG_GUEST_ERROR,
> +TYPE_MSS_TIMER": 64-bit mode not supported\n");

Maybe add a return here so you don't print the other debug message after this.

> +}
> +break;
> +}
> +
> +DB_PRINT("timer=%d 0x%" HWADDR_PRIx "=0x%" PRIx32, timer, offset,
> +ret);
> +return ret;
> +}
> +
> +static void
> +timer_write(void *opaque, hwaddr offset,
> +uint64_t val64, unsigned int size)
> +{
> +MSSTimerState *t = opaque;
> +hwaddr addr;
> +struct Msf2Timer *st;
> +int timer = 0;
> +uint32_t value = val64;
> +
> +addr = offset >> 2;
> +/*
> + * Two independent timers has same base address.
> + * Based on addr passed figure out which timer is being used.
> + */
> +if ((addr >= R_TIM1_MAX) && (addr < NUM_TIMERS * R_TIM1_MAX)) {
> +timer = 1;
> +addr -= R_TIM1_MAX;
> +}
> +
> +st = &t->timers[timer];
> +
> +DB_PRINT("addr=0x%" HWADDR_PRIx " val=0x%" PRIx32 " (timer=%d)", offset,
> +value, timer);
> +
> +switch (addr) {
> +case R_TIM_CTRL:
> +st->regs[R_TIM_CTRL] = value;
> +timer_update(st);
> +break;
> +
> +case R_TIM_RIS:
> +if (value & TIMER_RIS_ACK) {
> +st->regs[R_TIM_RIS] &= ~TIMER_RIS_ACK;
> +}
> +break;
> +
> +case R_TIM_LOADVAL:
> +st->regs[R_TIM_LOADVAL] = value;
> +if (st->regs[R_TIM_CTRL] & TIMER_CTRL_ENBL) {
> +timer_update(st);
> +}
> +break;
> +
> +case R_TIM_BGLOADVAL:
> +st->regs[R_TIM_BGLOADVAL] = value;
> +st->regs[R_TIM_LOADVAL] = value;
> +break;
> +
> +case R_TIM_VAL:
> +case R_TIM_MIS:
> +break;
> +
> +default:
> +if (addr < NUM_TIMERS * R_TIM1_MAX) {

Same comment as above.

> +st->regs[addr] = value;
> +} else {
> +qemu_log_mask(LOG_GUEST_ERROR,
> +TYPE_MSS_TIMER": 64-bit mode not supported\n");
> +return;
> +}
> +break;
> +}
> +timer_update_irq(st);
> +}

Once those comments above are addressed:

Reviewed-by: Alistair Francis 

Thanks,
Alistair



Re: [Qemu-devel] [Qemu devel v6 PATCH 1/5] msf2: Add Smartfusion2 System timer

2017-07-05 Thread Alistair Francis
On Wed, Jul 5, 2017 at 10:56 AM, Alistair Francis  wrote:
> On Sun, Jul 2, 2017 at 9:45 PM, Subbaraya Sundeep
>  wrote:
>> Modelled System Timer in Microsemi's Smartfusion2 Soc.
>> Timer has two 32bit down counters and two interrupts.
>>
>> Signed-off-by: Subbaraya Sundeep 
>> ---
>>  hw/timer/Makefile.objs   |   1 +
>>  hw/timer/mss-timer.c | 261 
>> +++
>>  include/hw/timer/mss-timer.h |  67 +++
>>  3 files changed, 329 insertions(+)
>>  create mode 100644 hw/timer/mss-timer.c
>>  create mode 100644 include/hw/timer/mss-timer.h
>>
>> diff --git a/hw/timer/Makefile.objs b/hw/timer/Makefile.objs
>> index dd6f27e..fc4d2da 100644
>> --- a/hw/timer/Makefile.objs
>> +++ b/hw/timer/Makefile.objs
>> @@ -41,3 +41,4 @@ common-obj-$(CONFIG_STM32F2XX_TIMER) += stm32f2xx_timer.o
>>  common-obj-$(CONFIG_ASPEED_SOC) += aspeed_timer.o
>>
>>  common-obj-$(CONFIG_SUN4V_RTC) += sun4v-rtc.o
>> +common-obj-$(CONFIG_MSF2) += mss-timer.o
>> diff --git a/hw/timer/mss-timer.c b/hw/timer/mss-timer.c
>> new file mode 100644
>> index 000..e46d118
>> --- /dev/null
>> +++ b/hw/timer/mss-timer.c
>> @@ -0,0 +1,261 @@
>> +/*
>> + * Block model of System timer present in
>> + * Microsemi's SmartFusion2 and SmartFusion SoCs.
>> + *
>> + * Copyright (c) 2017 Subbaraya Sundeep .
>> + *
>> + * Permission is hereby granted, free of charge, to any person obtaining a 
>> copy
>> + * of this software and associated documentation files (the "Software"), to 
>> deal
>> + * in the Software without restriction, including without limitation the 
>> rights
>> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
>> + * copies of the Software, and to permit persons to whom the Software is
>> + * furnished to do so, subject to the following conditions:
>> + *
>> + * The above copyright notice and this permission notice shall be included 
>> in
>> + * all copies or substantial portions of the Software.
>> + *
>> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
>> OR
>> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
>> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
>> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 
>> OTHER
>> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
>> FROM,
>> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
>> + * THE SOFTWARE.
>> + */
>> +
>> +#include "hw/timer/mss-timer.h"

Also just noticed (this applies to the whole series) that you need the
headers in the C file.

Move every #include that you can from the mss-timer.h files to this
file, headers should be local to where they are called. Also make sure
you include the os-dep header in every file.

Thanks,
Alistair

>> +
>> +#ifndef MSS_TIMER_ERR_DEBUG
>> +#define MSS_TIMER_ERR_DEBUG  0
>> +#endif
>> +
>> +#define DB_PRINT_L(lvl, fmt, args...) do { \
>> +if (MSS_TIMER_ERR_DEBUG >= lvl) { \
>> +qemu_log("%s: " fmt "\n", __func__, ## args); \
>> +} \
>> +} while (0);
>> +
>> +#define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
>> +
>> +#define R_TIM_VAL 0
>> +#define R_TIM_LOADVAL 1
>> +#define R_TIM_BGLOADVAL   2
>> +#define R_TIM_CTRL3
>> +#define R_TIM_RIS 4
>> +#define R_TIM_MIS 5
>> +
>> +#define TIMER_CTRL_ENBL (1 << 0)
>> +#define TIMER_CTRL_ONESHOT  (1 << 1)
>> +#define TIMER_CTRL_INTR (1 << 2)
>> +#define TIMER_RIS_ACK   (1 << 0)
>> +#define TIMER_RST_CLR   (1 << 6)
>> +#define TIMER_MODE  (1 << 0)
>> +
>> +static void timer_update_irq(struct Msf2Timer *st)
>> +{
>> +bool isr, ier;
>> +
>> +isr = !!(st->regs[R_TIM_RIS] & TIMER_RIS_ACK);
>> +ier = !!(st->regs[R_TIM_CTRL] & TIMER_CTRL_INTR);
>> +qemu_set_irq(st->irq, (ier && isr));
>> +}
>> +
>> +static void timer_update(struct Msf2Timer *st)
>> +{
>> +uint64_t count;
>> +
>> +if (!(st->regs[R_TIM_CTRL] & TIMER_CTRL_ENBL)) {
>> +ptimer_stop(st->ptimer);
>> +return;
>> +}
>> +
>> +count = st->regs[R_TIM_LOADVAL];
>> +ptimer_set_limit(st->ptimer,

Re: [Qemu-devel] [Qemu devel v6 PATCH 2/5] msf2: Microsemi Smartfusion2 System Register block.

2017-07-05 Thread Alistair Francis
On Sun, Jul 2, 2017 at 9:45 PM, Subbaraya Sundeep
 wrote:
> Added Sytem register block of Smartfusion2.
> This block has PLL registers which are accessed by guest.
>
> Signed-off-by: Subbaraya Sundeep 
> ---
>  hw/misc/Makefile.objs |   1 +
>  hw/misc/msf2-sysreg.c | 200 
> ++
>  include/hw/misc/msf2-sysreg.h |  82 +
>  3 files changed, 283 insertions(+)
>  create mode 100644 hw/misc/msf2-sysreg.c
>  create mode 100644 include/hw/misc/msf2-sysreg.h
>
> diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
> index c8b4893..0f52354 100644
> --- a/hw/misc/Makefile.objs
> +++ b/hw/misc/Makefile.objs
> @@ -56,3 +56,4 @@ obj-$(CONFIG_EDU) += edu.o
>  obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o
>  obj-$(CONFIG_AUX) += auxbus.o
>  obj-$(CONFIG_ASPEED_SOC) += aspeed_scu.o aspeed_sdmc.o
> +obj-$(CONFIG_MSF2) += msf2-sysreg.o
> diff --git a/hw/misc/msf2-sysreg.c b/hw/misc/msf2-sysreg.c
> new file mode 100644
> index 000..64ee141
> --- /dev/null
> +++ b/hw/misc/msf2-sysreg.c
> @@ -0,0 +1,200 @@
> +/*
> + * System Register block model of Microsemi SmartFusion2.
> + *
> + * Copyright (c) 2017 Subbaraya Sundeep 
> + *
> + * 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.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, see .
> + */
> +
> +#include "hw/misc/msf2-sysreg.h"

Same #include comment from patch 1.

> +
> +#ifndef MSF2_SYSREG_ERR_DEBUG
> +#define MSF2_SYSREG_ERR_DEBUG  0
> +#endif
> +
> +#define DB_PRINT_L(lvl, fmt, args...) do { \
> +if (MSF2_SYSREG_ERR_DEBUG >= lvl) { \
> +qemu_log("%s: " fmt "\n", __func__, ## args); \
> +} \
> +} while (0);
> +
> +#define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
> +
> +static inline int msf2_divbits(uint32_t div)
> +{
> +int ret = 0;
> +
> +switch (div) {
> +case 1:
> +ret = 0;
> +break;
> +case 2:
> +ret = 1;
> +break;
> +case 4:
> +ret = 2;
> +break;
> +case 8:
> +ret = 4;
> +break;
> +case 16:
> +ret = 5;
> +break;
> +case 32:
> +ret = 6;
> +break;
> +default:
> +break;
> +}
> +
> +return ret;
> +}
> +
> +static void msf2_sysreg_reset(DeviceState *d)
> +{
> +MSF2SysregState *s = MSF2_SYSREG(d);
> +
> +DB_PRINT("RESET");
> +
> +s->regs[MSSDDR_PLL_STATUS_LOW_CR] = 0x021A2358;
> +s->regs[MSSDDR_PLL_STATUS] = 0x3;
> +s->regs[MSSDDR_FACC1_CR] = msf2_divbits(s->apb0div) << 5 |
> +   msf2_divbits(s->apb1div) << 2;
> +}
> +
> +static uint64_t msf2_sysreg_read(void *opaque, hwaddr offset,
> +unsigned size)
> +{
> +MSF2SysregState *s = opaque;
> +offset /= 4;

Probably best to use a bitshift.

> +uint32_t ret = 0;
> +
> +if (offset < ARRAY_SIZE(s->regs)) {
> +ret = s->regs[offset];
> +DB_PRINT("addr: 0x%08" HWADDR_PRIx " data: 0x%08" PRIx32,
> +offset * 4, ret);

Bitshift here as well.

> +} else {
> +qemu_log_mask(LOG_GUEST_ERROR,
> +"%s: Bad offset 0x%08" HWADDR_PRIx "\n", __func__,
> +offset * 4);
> +}
> +
> +return ret;
> +}
> +
> +static void msf2_sysreg_write(void *opaque, hwaddr offset,
> +  uint64_t val, unsigned size)
> +{
> +MSF2SysregState *s = (MSF2SysregState *)opaque;
> +uint32_t newval = val;
> +uint32_t oldval;
> +
> +DB_PRINT("addr: 0x%08" HWADDR_PRIx " data: 0x%08" PRIx64,
> +offset, val);
> +
> +offset /= 4;

Same here

> +
> +switch (offset) {
> +case MSSDDR_PLL_STATUS:
> +break;
> +
> +case ESRAM_CR:
> +oldval = s->regs[ESRAM_CR];
> +if (oldval ^ newval) {
> +qemu_log_mask(LOG_GUEST_ERROR,
> +   TYPE_MSF2_SYSREG": eSRAM remapping not supported\n");
> +abort();

The guest should not be able to kill QEMU, a guest error should never
result in an abort.

> +}
> +break;
> +
> +case DDR_CR:
> +oldval = s->regs[DDR_CR];
> +if (oldval ^ newval) {
> +qemu_log_mask(LOG_GUEST_ERROR,
> +   TYPE_MSF2_SYSREG": DDR remapping not supported\n");
> +abort();
> +}
> +break;
> +
> +case ENVM_REMAP_BASE_CR:
> +oldval = s->regs[ENVM_REMAP_BASE_CR];
> +if (oldval ^ newval) {
> +qemu_log_mask(LOG_GUEST_ERROR,
> +   TYPE_MSF2_SYSREG": eNVM remapping not supported\n");
> +abort();
> +}
> +break;
> +
> +default:
> +if (offset < ARRAY_SIZE(s->regs)) {
>

Re: [Qemu-devel] [Qemu devel v6 PATCH 3/5] msf2: Add Smartfusion2 SPI controller

2017-07-05 Thread Alistair Francis
On Sun, Jul 2, 2017 at 9:45 PM, Subbaraya Sundeep
 wrote:
> Modelled Microsemi's Smartfusion2 SPI controller.
>
> Signed-off-by: Subbaraya Sundeep 
> ---
>  hw/ssi/Makefile.objs |   1 +
>  hw/ssi/mss-spi.c | 414 
> +++
>  include/hw/ssi/mss-spi.h |  62 +++
>  3 files changed, 477 insertions(+)
>  create mode 100644 hw/ssi/mss-spi.c
>  create mode 100644 include/hw/ssi/mss-spi.h
>
> diff --git a/hw/ssi/Makefile.objs b/hw/ssi/Makefile.objs
> index 487add2..f5bcc65 100644
> --- a/hw/ssi/Makefile.objs
> +++ b/hw/ssi/Makefile.objs
> @@ -4,6 +4,7 @@ common-obj-$(CONFIG_XILINX_SPI) += xilinx_spi.o
>  common-obj-$(CONFIG_XILINX_SPIPS) += xilinx_spips.o
>  common-obj-$(CONFIG_ASPEED_SOC) += aspeed_smc.o
>  common-obj-$(CONFIG_STM32F2XX_SPI) += stm32f2xx_spi.o
> +common-obj-$(CONFIG_MSF2) += mss-spi.o
>
>  obj-$(CONFIG_OMAP) += omap_spi.o
>  obj-$(CONFIG_IMX) += imx_spi.o
> diff --git a/hw/ssi/mss-spi.c b/hw/ssi/mss-spi.c
> new file mode 100644
> index 000..a572abc
> --- /dev/null
> +++ b/hw/ssi/mss-spi.c
> @@ -0,0 +1,414 @@
> +/*
> + * Block model of SPI controller present in
> + * Microsemi's SmartFusion2 and SmartFusion SoCs.
> + *
> + * Copyright (C) 2017 Subbaraya Sundeep 
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a 
> copy
> + * of this software and associated documentation files (the "Software"), to 
> deal
> + * in the Software without restriction, including without limitation the 
> rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
> FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + */
> +
> +#include "hw/ssi/mss-spi.h"

Same comment as earlier patches.

> +
> +#ifndef MSS_SPI_ERR_DEBUG
> +#define MSS_SPI_ERR_DEBUG   0
> +#endif
> +
> +#define DB_PRINT_L(lvl, fmt, args...) do { \
> +if (MSS_SPI_ERR_DEBUG >= lvl) { \
> +qemu_log("%s: " fmt "\n", __func__, ## args); \
> +} \
> +} while (0);
> +
> +#define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
> +
> +#define FIFO_CAPACITY 32
> +#define FIFO_CAPACITY 32
> +
> +#define R_SPI_CONTROL 0
> +#define R_SPI_DFSIZE  1
> +#define R_SPI_STATUS  2
> +#define R_SPI_INTCLR  3
> +#define R_SPI_RX  4
> +#define R_SPI_TX  5
> +#define R_SPI_CLKGEN  6
> +#define R_SPI_SS  7
> +#define R_SPI_MIS 8
> +#define R_SPI_RIS 9
> +
> +#define S_TXDONE (1 << 0)
> +#define S_RXRDY  (1 << 1)
> +#define S_RXCHOVRF   (1 << 2)
> +#define S_RXFIFOFUL  (1 << 4)
> +#define S_RXFIFOFULNXT   (1 << 5)
> +#define S_RXFIFOEMP  (1 << 6)
> +#define S_RXFIFOEMPNXT   (1 << 7)
> +#define S_TXFIFOFUL  (1 << 8)
> +#define S_TXFIFOFULNXT   (1 << 9)
> +#define S_TXFIFOEMP  (1 << 10)
> +#define S_TXFIFOEMPNXT   (1 << 11)
> +#define S_FRAMESTART (1 << 12)
> +#define S_SSEL   (1 << 13)
> +#define S_ACTIVE (1 << 14)
> +
> +#define C_ENABLE (1 << 0)
> +#define C_MODE   (1 << 1)
> +#define C_INTRXDATA  (1 << 4)
> +#define C_INTTXDATA  (1 << 5)
> +#define C_INTRXOVRFLO(1 << 6)
> +#define C_SPS(1 << 26)
> +#define C_BIGFIFO(1 << 29)
> +#define C_RESET  (1 << 31)
> +
> +#define FRAMESZ_MASK 0x1F
> +#define FMCOUNT_MASK 0x0000
> +#define FMCOUNT_SHIFT8
> +
> +static void txfifo_reset(MSSSpiState *s)
> +{
> +fifo32_reset(&s->tx_fifo);
> +
> +s->regs[R_SPI_STATUS] &= ~S_TXFIFOFUL;
> +s->regs[R_SPI_STATUS] |= S_TXFIFOEMP;
> +}
> +
> +static void rxfifo_reset(MSSSpiState *s)
> +{
> +fifo32_reset(&s->rx_fifo);
> +
> +s->regs[R_SPI_STATUS] &= ~S_RXFIFOFUL;
> +s->regs[R_SPI_STATUS] |= S_RXFIFOEMP;
> +}
> +
> +static void set_fifodepth(MSSSpiState *s)
> +{
> +unsigned int size = s->regs[R_SPI_DFSIZE] & FRAMESZ_MASK;
> +
> +if (size <= 8) {
> +s->fifo_depth = 32;
> +} else if (size <= 16) {
> +s->fifo_depth = 16;
> +} else if (size <= 32) {
> +s->fifo_depth = 8;
> +} else {
> +s->fifo_depth = 4;
> +}
> +}
> +
> 

Re: [Qemu-devel] [Qemu devel v6 PATCH 4/5] msf2: Add Smartfusion2 SoC.

2017-07-05 Thread Alistair Francis
On Sun, Jul 2, 2017 at 9:45 PM, Subbaraya Sundeep
 wrote:

The patch title shouldn't end in a full stop.

> Smartfusion2 SoC has hardened Microcontroller subsystem
> and flash based FPGA fabric. This patch adds support for
> Microcontroller subsystem in the SoC.
>
> Signed-off-by: Subbaraya Sundeep 

Once you have fixed up the title.

Reviewed-by: Alistair Francis 

Thanks,
Alistair


> ---
>  default-configs/arm-softmmu.mak |   1 +
>  hw/arm/Makefile.objs|   1 +
>  hw/arm/msf2-soc.c   | 216 
> 
>  include/hw/arm/msf2-soc.h   |  67 +
>  4 files changed, 285 insertions(+)
>  create mode 100644 hw/arm/msf2-soc.c
>  create mode 100644 include/hw/arm/msf2-soc.h
>
> diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
> index 78d7af0..7062512 100644
> --- a/default-configs/arm-softmmu.mak
> +++ b/default-configs/arm-softmmu.mak
> @@ -122,3 +122,4 @@ CONFIG_ACPI=y
>  CONFIG_SMBIOS=y
>  CONFIG_ASPEED_SOC=y
>  CONFIG_GPIO_KEY=y
> +CONFIG_MSF2=y
> diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
> index 4c5c4ee..c828061 100644
> --- a/hw/arm/Makefile.objs
> +++ b/hw/arm/Makefile.objs
> @@ -18,3 +18,4 @@ 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_ASPEED_SOC) += aspeed_soc.o aspeed.o
> +obj-$(CONFIG_MSF2) += msf2-soc.o
> diff --git a/hw/arm/msf2-soc.c b/hw/arm/msf2-soc.c
> new file mode 100644
> index 000..d45827f
> --- /dev/null
> +++ b/hw/arm/msf2-soc.c
> @@ -0,0 +1,216 @@
> +/*
> + * SmartFusion2 SoC emulation.
> + *
> + * Copyright (c) 2017 Subbaraya Sundeep 
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a 
> copy
> + * of this software and associated documentation files (the "Software"), to 
> deal
> + * in the Software without restriction, including without limitation the 
> rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
> FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + */
> +
> +#include "qemu/osdep.h"
> +#include "qapi/error.h"
> +#include "qemu-common.h"
> +#include "hw/arm/arm.h"
> +#include "exec/address-spaces.h"
> +#include "hw/char/serial.h"
> +#include "hw/boards.h"
> +#include "sysemu/block-backend.h"
> +#include "hw/arm/msf2-soc.h"
> +
> +#define MSF2_TIMER_BASE 0x40004000
> +#define MSF2_SYSREG_BASE0x40038000
> +
> +#define ENVM_BASE_ADDRESS 0x6000
> +
> +#define SRAM_BASE_ADDRESS 0x2000
> +
> +#define MSF2_ENVM_SIZE(512 * K_BYTE)
> +#define MSF2_ESRAM_SIZE   (64 * K_BYTE)
> +
> +static const uint32_t spi_addr[MSF2_NUM_SPIS] = { 0x40001000 , 0x40011000 };
> +static const uint32_t uart_addr[MSF2_NUM_UARTS] = { 0x4000 , 0x4001 
> };
> +
> +static const int spi_irq[MSF2_NUM_SPIS] = { 2, 3 };
> +static const int uart_irq[MSF2_NUM_UARTS] = { 10, 11 };
> +static const int timer_irq[MSF2_NUM_TIMERS] = { 14, 15 };
> +
> +static void m2sxxx_soc_initfn(Object *obj)
> +{
> +MSF2State *s = MSF2_SOC(obj);
> +int i;
> +
> +object_initialize(&s->armv7m, sizeof(s->armv7m), TYPE_ARMV7M);
> +qdev_set_parent_bus(DEVICE(&s->armv7m), sysbus_get_default());
> +
> +object_initialize(&s->sysreg, sizeof(s->sysreg), TYPE_MSF2_SYSREG);
> +qdev_set_parent_bus(DEVICE(&s->sysreg), sysbus_get_default());
> +
> +object_initialize(&s->timer, sizeof(s->timer), TYPE_MSS_TIMER);
> +qdev_set_parent_bus(DEVICE(&s->timer), sysbus_get_default());
> +
> +for (i = 0; i < MSF2_NUM_SPIS; i++) {
> +object_initialize(&s->spi[i], sizeof(s->spi[i]),
> +  TYPE_MSS_SPI);
> +  

Re: [Qemu-devel] [PATCH v1 1/2] target-arm: Move the regime_xxx helpers

2017-07-05 Thread Alistair Francis
On Fri, Jun 30, 2017 at 6:45 AM, Edgar E. Iglesias
 wrote:
> From: "Edgar E. Iglesias" 
>
> Move the regime_xxx helpers in preparation for future code
> that will reuse them.
>
> No functional change.
>
> Signed-off-by: Edgar E. Iglesias 

Reviewed-by: Alistair Francis 

Thanks,
Alistair

> ---
>  target/arm/helper.c | 404 
> ++--
>  1 file changed, 202 insertions(+), 202 deletions(-)
>
> diff --git a/target/arm/helper.c b/target/arm/helper.c
> index 2594faa..fd1027e 100644
> --- a/target/arm/helper.c
> +++ b/target/arm/helper.c
> @@ -35,6 +35,208 @@ static bool get_phys_addr_lpae(CPUARMState *env, 
> target_ulong address,
>  #define PMCRD   0x8
>  #define PMCRC   0x4
>  #define PMCRE   0x1
> +
> +/* Return the exception level which controls this address translation regime 
> */
> +static inline uint32_t regime_el(CPUARMState *env, ARMMMUIdx mmu_idx)
> +{
> +switch (mmu_idx) {
> +case ARMMMUIdx_S2NS:
> +case ARMMMUIdx_S1E2:
> +return 2;
> +case ARMMMUIdx_S1E3:
> +return 3;
> +case ARMMMUIdx_S1SE0:
> +return arm_el_is_aa64(env, 3) ? 1 : 3;
> +case ARMMMUIdx_S1SE1:
> +case ARMMMUIdx_S1NSE0:
> +case ARMMMUIdx_S1NSE1:
> +case ARMMMUIdx_MPriv:
> +case ARMMMUIdx_MNegPri:
> +case ARMMMUIdx_MUser:
> +return 1;
> +default:
> +g_assert_not_reached();
> +}
> +}
> +
> +/* Return true if this address translation regime is secure */
> +static inline bool regime_is_secure(CPUARMState *env, ARMMMUIdx mmu_idx)
> +{
> +switch (mmu_idx) {
> +case ARMMMUIdx_S12NSE0:
> +case ARMMMUIdx_S12NSE1:
> +case ARMMMUIdx_S1NSE0:
> +case ARMMMUIdx_S1NSE1:
> +case ARMMMUIdx_S1E2:
> +case ARMMMUIdx_S2NS:
> +case ARMMMUIdx_MPriv:
> +case ARMMMUIdx_MNegPri:
> +case ARMMMUIdx_MUser:
> +return false;
> +case ARMMMUIdx_S1E3:
> +case ARMMMUIdx_S1SE0:
> +case ARMMMUIdx_S1SE1:
> +return true;
> +default:
> +g_assert_not_reached();
> +}
> +}
> +
> +/* Return the SCTLR value which controls this address translation regime */
> +static inline uint32_t regime_sctlr(CPUARMState *env, ARMMMUIdx mmu_idx)
> +{
> +return env->cp15.sctlr_el[regime_el(env, mmu_idx)];
> +}
> +
> +/* Return true if the specified stage of address translation is disabled */
> +static inline bool regime_translation_disabled(CPUARMState *env,
> +   ARMMMUIdx mmu_idx)
> +{
> +if (arm_feature(env, ARM_FEATURE_M)) {
> +switch (env->v7m.mpu_ctrl &
> +(R_V7M_MPU_CTRL_ENABLE_MASK | R_V7M_MPU_CTRL_HFNMIENA_MASK)) 
> {
> +case R_V7M_MPU_CTRL_ENABLE_MASK:
> +/* Enabled, but not for HardFault and NMI */
> +return mmu_idx == ARMMMUIdx_MNegPri;
> +case R_V7M_MPU_CTRL_ENABLE_MASK | R_V7M_MPU_CTRL_HFNMIENA_MASK:
> +/* Enabled for all cases */
> +return false;
> +case 0:
> +default:
> +/* HFNMIENA set and ENABLE clear is UNPREDICTABLE, but
> + * we warned about that in armv7m_nvic.c when the guest set it.
> + */
> +return true;
> +}
> +}
> +
> +if (mmu_idx == ARMMMUIdx_S2NS) {
> +return (env->cp15.hcr_el2 & HCR_VM) == 0;
> +}
> +return (regime_sctlr(env, mmu_idx) & SCTLR_M) == 0;
> +}
> +
> +static inline bool regime_translation_big_endian(CPUARMState *env,
> + ARMMMUIdx mmu_idx)
> +{
> +return (regime_sctlr(env, mmu_idx) & SCTLR_EE) != 0;
> +}
> +
> +/* Return the TCR controlling this translation regime */
> +static inline TCR *regime_tcr(CPUARMState *env, ARMMMUIdx mmu_idx)
> +{
> +if (mmu_idx == ARMMMUIdx_S2NS) {
> +return &env->cp15.vtcr_el2;
> +}
> +return &env->cp15.tcr_el[regime_el(env, mmu_idx)];
> +}
> +
> +/* Convert a possible stage1+2 MMU index into the appropriate
> + * stage 1 MMU index
> + */
> +static inline ARMMMUIdx stage_1_mmu_idx(ARMMMUIdx mmu_idx)
> +{
> +if (mmu_idx == ARMMMUIdx_S12NSE0 || mmu_idx == ARMMMUIdx_S12NSE1) {
> +mmu_idx += (ARMMMUIdx_S1NSE0 - ARMMMUIdx_S12NSE0);
> +}
> +return mmu_idx;
> +}
> +
> +/* Returns TBI0 value for current regime el */
> +uint32_t arm_regime_tbi0(CPUARMState *env, ARMMMUIdx mmu_idx)
> +{
> +TCR *tcr;
> +uint32_t el;
> +
> +/* For EL0 and EL1, TBI is controlled by stage 1's TCR, so convert
> + * a stage 1+2 mmu ind

Re: [Qemu-devel] [RFC v3 2/3] qemu-error: Implement a more generic error reporting

2017-07-06 Thread Alistair Francis
On Thu, Jul 6, 2017 at 7:44 AM, Markus Armbruster  wrote:
> "Daniel P. Berrange"  writes:
>
>> On Thu, Jul 06, 2017 at 02:20:51PM +0200, Markus Armbruster wrote:
>>> "Daniel P. Berrange"  writes:
>>>
>>> > On Thu, Jul 06, 2017 at 01:27:15PM +0200, Markus Armbruster wrote:
>>> >> "Daniel P. Berrange"  writes:
> [...]
>>> >> > Do we really need to care about compatibility of the precise way we 
>>> >> > output
>>> >> > error messages. It has never been something we call a "stable API", as 
>>> >> > we
>>> >> > don't guarantee error message text will remain the same across 
>>> >> > releases. So
>>> >> > anyone relying on scraping QEMU stderr to match some error message has 
>>> >> > always
>>> >> > been liable to break.
>>> >> >
>>> >> > IOW, just add an "error: " prefix to the text
>>> >>
>>> >> I agree the error message format isn't ABI.
>>> >>
>>> >> But what would adding "error: " buy us?
>>> >
>>> > It would clearly distinguish errors from any other output on stderr, which
>>> > may not be error related (for example SPICE commonly pollutes stderr with
>>> > lots of messages).
>>>
>>> Changing the current error message format
>>>
>>> :
>>>
>>> to
>>>
>>> :error: 
>>>
>>> makes recognizing error messages a bit easier, but it also makes them
>>> even longer.  Can't we make do with recognizing :?
>>
>> I'm not convinced 7 extra characters is a big deal compared with the
>> size of the timestamps, program name, location & error message itself.
>> We'll already have such a prefix for info & warnings, so consistency is
>> good IMHO.
>
> I don't see the value of consistency here.  What matters is whether
> errors are easy to spot and recognize.
>
> GCC doesn't put "error:" into its error messages.  Clang does.  Feels
> like a matter of taste to me.
>
> If adding "error:" solves a problem people have, let's do it.  If not, I
> don't see why we should change what we have.

Ok, adding "error: " actually helps with what I was originally trying
to do, so I have added it in my next version.

I have also removed the qmsg_* prefix and updated the commit message.

Thanks,
Alistair

>
>> If line length is a concern, perhaps we should make the error printing
>> function able to intelligently line wrap at 80 chars, taking into account
>> the size of the metadata (timestamp, program, location, msg type prefix).
>
> Uh, that cure feels worse than the disease :)



[Qemu-devel] [PATCH v2 1/1] util/aio-win32: Only select on what we are actually waiting for

2017-07-06 Thread Alistair Francis
Signed-off-by: Alistair Francis 
Acked-by: Edgar E. Iglesias 
Reviewed-by: Philippe Mathieu-Daudé 
---
Changes in V2:
 - Rebase on master
Changes since RFC:
 - Include more bitmasks for the select call

 util/aio-win32.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/util/aio-win32.c b/util/aio-win32.c
index bca496a47a..d6d5e02f00 100644
--- a/util/aio-win32.c
+++ b/util/aio-win32.c
@@ -71,6 +71,7 @@ void aio_set_fd_handler(AioContext *ctx,
 }
 } else {
 HANDLE event;
+long bitmask = 0;
 
 if (node == NULL) {
 /* Alloc and insert if it's not already there */
@@ -95,10 +96,16 @@ void aio_set_fd_handler(AioContext *ctx,
 node->io_write = io_write;
 node->is_external = is_external;
 
+if (io_read) {
+bitmask |= FD_READ | FD_ACCEPT | FD_CLOSE;
+}
+
+if (io_write) {
+bitmask |= FD_WRITE | FD_CONNECT;
+}
+
 event = event_notifier_get_handle(&ctx->notifier);
-WSAEventSelect(node->pfd.fd, event,
-   FD_READ | FD_ACCEPT | FD_CLOSE |
-   FD_CONNECT | FD_WRITE | FD_OOB);
+WSAEventSelect(node->pfd.fd, event, bitmask);
 }
 
 qemu_lockcnt_unlock(&ctx->list_lock);
-- 
2.11.0




[Qemu-devel] [PATCH v1 1/6] util/qemu-error: Rename error_print_loc() to be more generic

2017-07-06 Thread Alistair Francis
Rename the error_print_loc() function in preparation for using it to
print warnings as well.

Signed-off-by: Alistair Francis 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Thomas Huth 
---

 util/qemu-error.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/util/qemu-error.c b/util/qemu-error.c
index b331f8f4a4..1c5e35ecdb 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -146,7 +146,7 @@ const char *error_get_progname(void)
 /*
  * Print current location to current monitor if we have one, else to stderr.
  */
-static void error_print_loc(void)
+static void print_loc(void)
 {
 const char *sep = "";
 int i;
@@ -197,7 +197,7 @@ void error_vreport(const char *fmt, va_list ap)
 g_free(timestr);
 }
 
-error_print_loc();
+print_loc();
 error_vprintf(fmt, ap);
 error_printf("\n");
 }
-- 
2.11.0




[Qemu-devel] [PATCH v1 4/6] char-socket: Report TCP socket waiting as information

2017-07-06 Thread Alistair Francis
When QEMU is waiting for a TCP socket connection it reports that message as
an error. This isn't an error it is just information so let's change the
report to use info_report() instead.

Signed-off-by: Alistair Francis 
Reviewed-by: Thomas Huth 
---

 chardev/char-socket.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index ccc499cfa1..a050a686ea 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -765,8 +765,8 @@ static int tcp_chr_wait_connected(Chardev *chr, Error 
**errp)
  * in TLS and telnet cases, only wait for an accepted socket */
 while (!s->ioc) {
 if (s->is_listen) {
-error_report("QEMU waiting for connection on: %s",
- chr->filename);
+info_report("QEMU waiting for connection on: %s",
+chr->filename);
 qio_channel_set_blocking(QIO_CHANNEL(s->listen_ioc), true, NULL);
 tcp_chr_accept(QIO_CHANNEL(s->listen_ioc), G_IO_IN, chr);
 qio_channel_set_blocking(QIO_CHANNEL(s->listen_ioc), false, NULL);
-- 
2.11.0




[Qemu-devel] [PATCH v1 5/6] error: Implement the warn and free Error functions

2017-07-06 Thread Alistair Francis
Implement warn_report_err() and warn_reportf_err() functions which
are the same as the error_report_err() and error_reportf_err()
functions except report a warning instead of an error.

Signed-off-by: Alistair Francis 
---

 include/qapi/error.h  | 11 +++
 scripts/checkpatch.pl |  1 +
 util/error.c  | 19 +++
 3 files changed, 31 insertions(+)

diff --git a/include/qapi/error.h b/include/qapi/error.h
index 7e532d00e9..af53b34410 100644
--- a/include/qapi/error.h
+++ b/include/qapi/error.h
@@ -267,11 +267,22 @@ void error_free(Error *err);
 void error_free_or_abort(Error **errp);
 
 /*
+ * Convenience function to warn_report() and free @err.
+ */
+void warn_report_err(Error *err);
+
+/*
  * Convenience function to error_report() and free @err.
  */
 void error_report_err(Error *err);
 
 /*
+ * Convenience function to error_prepend(), warn_report() and free @err.
+ */
+void warn_reportf_err(Error *err, const char *fmt, ...)
+GCC_FMT_ATTR(2, 3);
+
+/*
  * Convenience function to error_prepend(), error_report() and free @err.
  */
 void error_reportf_err(Error *err, const char *fmt, ...)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 1fdd7f624a..d1e7dd92ee 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2533,6 +2533,7 @@ sub process {
error_setg_file_open|
error_set|
error_prepend|
+   warn_reportf_err|
error_reportf_err|
vreport|
error_vreport|
diff --git a/util/error.c b/util/error.c
index 020b86b9f0..373566fb77 100644
--- a/util/error.c
+++ b/util/error.c
@@ -223,6 +223,15 @@ const char *error_get_pretty(const Error *err)
 return err->msg;
 }
 
+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_free(err);
+}
+
 void error_report_err(Error *err)
 {
 error_report("%s", error_get_pretty(err));
@@ -232,6 +241,16 @@ void error_report_err(Error *err)
 error_free(err);
 }
 
+void warn_reportf_err(Error *err, const char *fmt, ...)
+{
+va_list ap;
+
+va_start(ap, fmt);
+error_vprepend(&err, fmt, ap);
+va_end(ap);
+warn_report_err(err);
+}
+
 void error_reportf_err(Error *err, const char *fmt, ...)
 {
 va_list ap;
-- 
2.11.0




[Qemu-devel] [PATCH v1 6/6] Convert error_report*_err() to warn_report*_err()

2017-07-06 Thread Alistair Francis
Convert all uses of error_report*_err("[Ww]arning:"... to use
warn_report*_err() instead. This helps standardise on a single
method of printing warnings to the user.

Signed-off-by: Alistair Francis 
Cc: Paolo Bonzini 
Cc: Richard Henderson 
Cc: Eduardo Habkost 
Cc: "Michael S. Tsirkin" 
---

 hw/core/qdev-properties.c | 2 +-
 hw/i386/pc.c  | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index f5983c83da..3d0bba21a2 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -1169,7 +1169,7 @@ static void qdev_prop_set_globals_for_type(DeviceState 
*dev,
 error_propagate(prop->errp, err);
 } else {
 assert(prop->user_provided);
-error_reportf_err(err, "Warning: ");
+warn_report_err(err);
 }
 }
 }
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 58f8a4f4a5..5c2cc3f836 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1320,8 +1320,7 @@ void pc_acpi_init(const char *default_dsdt)
 
 acpi_table_add_builtin(opts, &err);
 if (err) {
-error_reportf_err(err, "WARNING: failed to load %s: ",
-  filename);
+warn_reportf_err(err, "failed to load %s: ", filename);
 }
 g_free(filename);
 }
-- 
2.11.0




[Qemu-devel] [PATCH v1 0/6] Implement a warning_report function

2017-07-06 Thread Alistair Francis
QEMU currently has a standard method to report errors with
error_repot(). This ensure a sane and standard format when printing
errors. This series is attempting to extend this functionality for
warnings and information as well.

This patch renames error_print_loc() function to be more clear, but I
didn't bother renaming the others. It seems silly to change
error_printf() to error_warning_printf() and printf is already taken so
I just left it as is.

v1:
 - Convert all of the existing warning messages in QEMU
 - Add a error_report*_err() functions as well
RFCv3:
 - Use more detailed enum and function names
 - Add wrapper functions for the info and warning reporting
RFCv2:
 - Use enums for ERROR, WARN and INFO with a generic report() function
   instead of adding new functions

Alistair Francis (6):
  util/qemu-error: Rename error_print_loc() to be more generic
  error: Functions to report warnings and informational messages
  Convert error_report() to warn_report()
  char-socket: Report TCP socket waiting as information
  error: Implement the warn and free Error functions
  Convert error_report*_err() to warn_report*_err()

 block/backup.c | 10 +++---
 block/gluster.c|  2 +-
 block/iscsi.c  |  2 +-
 block/nfs.c| 12 +++
 block/rbd.c|  6 ++--
 block/ssh.c|  4 +--
 blockdev.c |  2 +-
 chardev/char-socket.c  |  4 +--
 cpus.c |  2 +-
 hw/9pfs/9p.c   |  2 +-
 hw/arm/highbank.c  |  6 ++--
 hw/arm/imx25_pdk.c |  6 ++--
 hw/arm/kzm.c   |  6 ++--
 hw/core/machine.c  | 10 +++---
 hw/core/qdev-properties.c  | 10 +++---
 hw/i386/acpi-build.c   | 10 +++---
 hw/i386/kvm/pci-assign.c   |  6 ++--
 hw/i386/pc.c   | 15 
 hw/i386/pc_piix.c  |  8 ++---
 hw/i386/pc_q35.c   |  6 ++--
 hw/misc/aspeed_sdmc.c  |  8 ++---
 hw/nvram/fw_cfg.c  |  2 +-
 hw/pci-host/piix.c |  2 +-
 hw/ppc/pnv.c   |  6 ++--
 hw/ppc/spapr.c |  4 +--
 hw/ppc/spapr_iommu.c   |  2 +-
 hw/scsi/scsi-bus.c |  6 ++--
 hw/usb/dev-smartcard-reader.c  |  6 ++--
 hw/usb/redirect.c  |  2 +-
 include/qapi/error.h   | 11 ++
 include/qemu/error-report.h|  7 
 net/tap-linux.c|  2 +-
 scripts/checkpatch.pl  |  8 -
 target/i386/cpu.c  | 22 ++--
 target/i386/kvm.c  | 10 +++---
 target/s390x/cpu_models.c  |  6 ++--
 target/s390x/kvm.c |  4 +--
 tests/test-qdev-global-props.c |  6 ++--
 trace/control.c|  8 ++---
 util/error.c   | 19 ++
 util/qemu-error.c  | 82 +-
 vl.c   | 20 +--
 42 files changed, 239 insertions(+), 133 deletions(-)

-- 
2.11.0




[Qemu-devel] [PATCH v1 2/6] error: Functions to report warnings and informational messages

2017-07-06 Thread Alistair Francis
Add warn_report(), warn_vreport() for reporting warnings, and
info_report(), info_vreport() for informational messages.

These are implemented them with a helper function factored out of
error_vreport(), suitably generalized. As we don't regard error
messages as a stable API the original error messages now have an
'error: ' prefix.

Signed-off-by: Alistair Francis 
---
v1:
 - Don't expose the generic report and vreport() functions
 - Prefix error messages
 - Use vreport instead of qmsg_vreport()
RFC V3:
 - Change the function and enum names to be more descriptive
 - Add wrapper functions for *_report() and *_vreport()

 include/qemu/error-report.h |  7 
 scripts/checkpatch.pl   |  7 +++-
 util/qemu-error.c   | 78 +
 3 files changed, 84 insertions(+), 8 deletions(-)

diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index 3001865896..e1c8ae1a52 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -35,8 +35,15 @@ 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);
+void info_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
+
 void error_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+void warn_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+void info_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+
 const char *error_get_progname(void);
 extern bool enable_timestamp_msg;
 
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 73efc927a9..1fdd7f624a 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2534,8 +2534,13 @@ sub process {
error_set|
error_prepend|
error_reportf_err|
+   vreport|
error_vreport|
-   error_report}x;
+   warn_vreport|
+   info_vreport|
+   error_report|
+   warn_report|
+   info_report}x;
 
if ($rawline =~ /\b(?:$qemu_error_funcs)\s*\(.*\".*\\n/) {
ERROR("Error messages should not contain newlines\n" . 
$herecurr);
diff --git a/util/qemu-error.c b/util/qemu-error.c
index 1c5e35ecdb..f2fc9d5a1e 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -14,6 +14,12 @@
 #include "monitor/monitor.h"
 #include "qemu/error-report.h"
 
+typedef enum {
+REPORT_TYPE_ERROR,
+REPORT_TYPE_WARNING,
+REPORT_TYPE_INFO,
+} report_type;
+
 void error_printf(const char *fmt, ...)
 {
 va_list ap;
@@ -179,17 +185,29 @@ static void print_loc(void)
 
 bool enable_timestamp_msg;
 /*
- * Print an error message to current monitor if we have one, else to stderr.
+ * Print a message to current monitor if we have one, else to stderr.
  * Format arguments like vsprintf().  The resulting message should be
  * a single phrase, with no newline or trailing punctuation.
  * Prepend the current location and append a newline.
  * It's wrong to call this in a QMP monitor.  Use error_setg() there.
  */
-void error_vreport(const char *fmt, va_list ap)
+static void vreport(report_type type, const char *fmt, va_list ap)
 {
 GTimeVal tv;
 gchar *timestr;
 
+switch (type) {
+case REPORT_TYPE_ERROR:
+error_printf("error: ");
+break;
+case REPORT_TYPE_WARNING:
+error_printf("warning: ");
+break;
+case REPORT_TYPE_INFO:
+error_printf("info: ");
+break;
+}
+
 if (enable_timestamp_msg && !cur_mon) {
 g_get_current_time(&tv);
 timestr = g_time_val_to_iso8601(&tv);
@@ -204,16 +222,62 @@ void error_vreport(const char *fmt, va_list ap)
 
 /*
  * Print an error message to current monitor if we have one, else to stderr.
- * Format arguments like sprintf().  The resulting message should be a
- * single phrase, with no newline or trailing punctuation.
- * Prepend the current location and append a newline.
- * It's wrong to call this in a QMP monitor.  Use error_setg() there.
+ */
+void error_vreport(const char *fmt, va_list ap)
+{
+vreport(REPORT_TYPE_ERROR, fmt, ap);
+}
+
+/*
+ * Print a warning message to current monitor if we have one, else to stderr.
+ */
+void warn_vreport(const char *fmt, va_list ap)
+{
+vreport(REPORT_TYPE_WARNING, fmt, ap);
+}
+
+/*
+ * Print an information message to current monitor if we have one, else to
+ * stderr.
+ */
+void info_vreport(const char *fmt, va_li

[Qemu-devel] [PATCH v1 3/6] Convert error_report() to warn_report()

2017-07-06 Thread Alistair Francis
Convert all uses of error_report("[Ww]arning:"... to use warn_report()
instead. This helps standardise on a single method of printing warnings
to the user.

All of the warnings were found using this regex expression:
error_report.*[Ww]arning:
and replaced with:
warn_report("

Signed-off-by: Alistair Francis 
Suggested-by: Thomas Huth 
Cc: Jeff Cody 
Cc: Kevin Wolf 
Cc: Max Reitz 
Cc: Ronnie Sahlberg 
Cc: Paolo Bonzini 
Cc: Peter Lieven 
Cc: Josh Durgin 
Cc: "Richard W.M. Jones" 
Cc: Markus Armbruster 
Cc: Peter Crosthwaite 
Cc: Richard Henderson 
Cc: "Aneesh Kumar K.V" 
Cc: Greg Kurz 
Cc: Rob Herring 
Cc: Peter Maydell 
Cc: Peter Chubb 
Cc: Eduardo Habkost 
Cc: Marcel Apfelbaum 
Cc: "Michael S. Tsirkin" 
Cc: Igor Mammedov 
Cc: David Gibson 
Cc: Alexander Graf 
Cc: Gerd Hoffmann 
Cc: Jason Wang 
Cc: Marcelo Tosatti 
Cc: Christian Borntraeger 
Cc: Cornelia Huck 
Cc: Stefan Hajnoczi 
---

 block/backup.c | 10 +-
 block/gluster.c|  2 +-
 block/iscsi.c  |  2 +-
 block/nfs.c| 12 ++--
 block/rbd.c|  6 +++---
 block/ssh.c|  4 ++--
 blockdev.c |  2 +-
 cpus.c |  2 +-
 hw/9pfs/9p.c   |  2 +-
 hw/arm/highbank.c  |  6 +++---
 hw/arm/imx25_pdk.c |  6 +++---
 hw/arm/kzm.c   |  6 +++---
 hw/core/machine.c  | 10 +-
 hw/core/qdev-properties.c  |  8 
 hw/i386/acpi-build.c   | 10 +-
 hw/i386/kvm/pci-assign.c   |  6 +++---
 hw/i386/pc.c   | 12 ++--
 hw/i386/pc_piix.c  |  8 
 hw/i386/pc_q35.c   |  6 +++---
 hw/misc/aspeed_sdmc.c  |  8 
 hw/nvram/fw_cfg.c  |  2 +-
 hw/pci-host/piix.c |  2 +-
 hw/ppc/pnv.c   |  6 +++---
 hw/ppc/spapr.c |  4 ++--
 hw/ppc/spapr_iommu.c   |  2 +-
 hw/scsi/scsi-bus.c |  6 +++---
 hw/usb/dev-smartcard-reader.c  |  6 +++---
 hw/usb/redirect.c  |  2 +-
 net/tap-linux.c|  2 +-
 target/i386/cpu.c  | 22 +++---
 target/i386/kvm.c  | 10 +-
 target/s390x/cpu_models.c  |  6 +++---
 target/s390x/kvm.c |  4 ++--
 tests/test-qdev-global-props.c |  6 +++---
 trace/control.c|  8 
 vl.c   | 20 ++--
 36 files changed, 118 insertions(+), 118 deletions(-)

diff --git a/block/backup.c b/block/backup.c
index 5387fbd84e..a0f059a0b6 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -657,11 +657,11 @@ BlockJob *backup_job_create(const char *job_id, 
BlockDriverState *bs,
 ret = bdrv_get_info(target, &bdi);
 if (ret == -ENOTSUP && !target->backing) {
 /* Cluster size is not defined */
-error_report("WARNING: The target block device doesn't provide "
- "information about the block size and it doesn't have a "
- "backing file. The default block size of %u bytes is "
- "used. If the actual block size of the target exceeds "
- "this default, the backup may be unusable",
+warn_report("The target block device doesn't provide "
+"information about the block size and it doesn't have a "
+"backing file. The default block size of %u bytes is "
+"used. If the actual block size of the target exceeds "
+"this default, the backup may be unusable",
  BACKUP_CLUSTER_SIZE_DEFAULT);
 job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT;
 } else if (ret < 0 && !target->backing) {
diff --git a/block/gluster.c b/block/gluster.c
index addceed6eb..79b790c4fc 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -345,7 +345,7 @@ static int qemu_gluster_parse_uri(BlockdevOptionsGluster 
*gconf,
 is_unix = true;
 } else if (!strcmp(uri->scheme, "gluster+rdma")) {
 gsconf->type = SOCKET_ADDRESS_TYPE_INET;
-error_report("Warning: rdma feature is not supported, falling "
+warn_report(rdma feature is not supported, falling "
  "back to tcp");
 } else {
 ret = -EINVAL;
diff --git a/block/iscsi.c b/block/iscsi.c
index 54067e2620..22911e7526 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1761,7 +1761,7 @@ static int iscsi_open(BlockDriverState *bs, QDict 
*options, int flags,
  * filename encoded options */
 filename = qdict_get_try_str(options, "filename");
 if (filename) {
-error_report("Warning: 'filename' opt

Re: [Qemu-devel] [Qemu devel v6 PATCH 2/5] msf2: Microsemi Smartfusion2 System Register block.

2017-07-07 Thread Alistair Francis
On Fri, Jul 7, 2017 at 12:08 AM, sundeep subbaraya
 wrote:
> Hi Alistair,
>
> On Wed, Jul 5, 2017 at 11:36 PM, Alistair Francis 
> wrote:
>>
>> On Sun, Jul 2, 2017 at 9:45 PM, Subbaraya Sundeep
>>  wrote:
>> > Added Sytem register block of Smartfusion2.
>> > This block has PLL registers which are accessed by guest.
>> >
>> > Signed-off-by: Subbaraya Sundeep 
>> > ---
>> >  hw/misc/Makefile.objs |   1 +
>> >  hw/misc/msf2-sysreg.c | 200
>> > ++
>> >  include/hw/misc/msf2-sysreg.h |  82 +
>> >  3 files changed, 283 insertions(+)
>> >  create mode 100644 hw/misc/msf2-sysreg.c
>> >  create mode 100644 include/hw/misc/msf2-sysreg.h
>> >
>> > diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
>> > index c8b4893..0f52354 100644
>> > --- a/hw/misc/Makefile.objs
>> > +++ b/hw/misc/Makefile.objs
>> > @@ -56,3 +56,4 @@ obj-$(CONFIG_EDU) += edu.o
>> >  obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o
>> >  obj-$(CONFIG_AUX) += auxbus.o
>> >  obj-$(CONFIG_ASPEED_SOC) += aspeed_scu.o aspeed_sdmc.o
>> > +obj-$(CONFIG_MSF2) += msf2-sysreg.o
>> > diff --git a/hw/misc/msf2-sysreg.c b/hw/misc/msf2-sysreg.c
>> > new file mode 100644
>> > index 000..64ee141
>> > --- /dev/null
>> > +++ b/hw/misc/msf2-sysreg.c
>> > @@ -0,0 +1,200 @@
>> > +/*
>> > + * System Register block model of Microsemi SmartFusion2.
>> > + *
>> > + * Copyright (c) 2017 Subbaraya Sundeep 
>> > + *
>> > + * 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.
>> > + *
>> > + * You should have received a copy of the GNU General Public License
>> > along
>> > + * with this program; if not, see <http://www.gnu.org/licenses/>.
>> > + */
>> > +
>> > +#include "hw/misc/msf2-sysreg.h"
>>
>> Same #include comment from patch 1.
>
>
> Ok will change.
>>
>>
>> > +
>> > +#ifndef MSF2_SYSREG_ERR_DEBUG
>> > +#define MSF2_SYSREG_ERR_DEBUG  0
>> > +#endif
>> > +
>> > +#define DB_PRINT_L(lvl, fmt, args...) do { \
>> > +if (MSF2_SYSREG_ERR_DEBUG >= lvl) { \
>> > +qemu_log("%s: " fmt "\n", __func__, ## args); \
>> > +} \
>> > +} while (0);
>> > +
>> > +#define DB_PRINT(fmt, args...) DB_PRINT_L(1, fmt, ## args)
>> > +
>> > +static inline int msf2_divbits(uint32_t div)
>> > +{
>> > +int ret = 0;
>> > +
>> > +switch (div) {
>> > +case 1:
>> > +ret = 0;
>> > +break;
>> > +case 2:
>> > +ret = 1;
>> > +break;
>> > +case 4:
>> > +ret = 2;
>> > +break;
>> > +case 8:
>> > +ret = 4;
>> > +break;
>> > +case 16:
>> > +ret = 5;
>> > +break;
>> > +case 32:
>> > +ret = 6;
>> > +break;
>> > +default:
>> > +break;
>> > +}
>> > +
>> > +return ret;
>> > +}
>> > +
>> > +static void msf2_sysreg_reset(DeviceState *d)
>> > +{
>> > +MSF2SysregState *s = MSF2_SYSREG(d);
>> > +
>> > +DB_PRINT("RESET");
>> > +
>> > +s->regs[MSSDDR_PLL_STATUS_LOW_CR] = 0x021A2358;
>> > +s->regs[MSSDDR_PLL_STATUS] = 0x3;
>> > +s->regs[MSSDDR_FACC1_CR] = msf2_divbits(s->apb0div) << 5 |
>> > +   msf2_divbits(s->apb1div) << 2;
>> > +}
>> > +
>> > +static uint64_t msf2_sysreg_read(void *opaque, hwaddr offset,
>> > +unsigned size)
>> > +{
>> > +MSF2SysregState *s = opaque;
>> > +offset /= 4;
>>
>> Probably best to use a bitshift.
>
>
> Ok will change.
>>
>>
>> > +uint32_t ret = 0;
>> > +
>> > +if (offset < ARRAY_SIZE(s->regs)) {
>> > +ret = s->regs[offset];
>> > +DB_PRINT("addr: 0x%08" HWADDR_PRIx " data: 0x%08" PRIx32,
>>

Re: [Qemu-devel] [PATCH v1 2/6] error: Functions to report warnings and informational messages

2017-07-07 Thread Alistair Francis
On Fri, Jul 7, 2017 at 5:59 AM, Markus Armbruster  wrote:
> Alistair Francis  writes:
>
>> Add warn_report(), warn_vreport() for reporting warnings, and
>> info_report(), info_vreport() for informational messages.
>>
>> These are implemented them with a helper function factored out of
>> error_vreport(), suitably generalized. As we don't regard error
>> messages as a stable API the original error messages now have an
>> 'error: ' prefix.
>>
>> Signed-off-by: Alistair Francis 
>
> The patch squashes two changes together: the new functions and the error
> message format change.  Please split it, so we can debate either change
> on its merit more easily, and to make them both properly visible in the
> commit log.

Ok,  I have split the patches.

>
>> ---
>> v1:
>>  - Don't expose the generic report and vreport() functions
>>  - Prefix error messages
>>  - Use vreport instead of qmsg_vreport()
>> RFC V3:
>>  - Change the function and enum names to be more descriptive
>>  - Add wrapper functions for *_report() and *_vreport()
>>
>>  include/qemu/error-report.h |  7 
>>  scripts/checkpatch.pl   |  7 +++-
>>  util/qemu-error.c   | 78 
>> +
>>  3 files changed, 84 insertions(+), 8 deletions(-)
>>
>> diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
>> index 3001865896..e1c8ae1a52 100644
>> --- a/include/qemu/error-report.h
>> +++ b/include/qemu/error-report.h
>> @@ -35,8 +35,15 @@ 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);
>> +void info_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
>> +
>>  void error_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
>> +void warn_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
>> +void info_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
>> +
>>  const char *error_get_progname(void);
>>  extern bool enable_timestamp_msg;
>>
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>> index 73efc927a9..1fdd7f624a 100755
>> --- a/scripts/checkpatch.pl
>> +++ b/scripts/checkpatch.pl
>> @@ -2534,8 +2534,13 @@ sub process {
>>   error_set|
>>   error_prepend|
>>   error_reportf_err|
>> + vreport|
>
> Is this one needed?

No, none of the vreport() functions are needed. I have removed them.

>
>>   error_vreport|
>> - error_report}x;
>> + warn_vreport|
>> + info_vreport|
>> + error_report|
>> + warn_report|
>> + info_report}x;
>>
>>   if ($rawline =~ /\b(?:$qemu_error_funcs)\s*\(.*\".*\\n/) {
>>   ERROR("Error messages should not contain newlines\n" . 
>> $herecurr);
>> diff --git a/util/qemu-error.c b/util/qemu-error.c
>> index 1c5e35ecdb..f2fc9d5a1e 100644
>> --- a/util/qemu-error.c
>> +++ b/util/qemu-error.c
>> @@ -14,6 +14,12 @@
>>  #include "monitor/monitor.h"
>>  #include "qemu/error-report.h"
>>
>> +typedef enum {
>> +REPORT_TYPE_ERROR,
>> +REPORT_TYPE_WARNING,
>> +REPORT_TYPE_INFO,
>> +} report_type;
>> +
>>  void error_printf(const char *fmt, ...)
>>  {
>>  va_list ap;
>> @@ -179,17 +185,29 @@ static void print_loc(void)
>>
>>  bool enable_timestamp_msg;
>>  /*
>> - * Print an error message to current monitor if we have one, else to stderr.
>> + * Print a message to current monitor if we have one, else to stderr.
>
> Need a sentence on @report_type right here.  Perhaps
>
> * @report_type is the type of message: error, warning or
> * informational.
>
>>   * Format arguments like vsprintf().  The resulting message should be
>>   * a single phrase, with no newline or trailing punctuation.
>>   * Prepend the current location and append a newline.
>>   * It's wrong to call this in a QMP monitor.  Use error

Re: [Qemu-devel] [PATCH v1 3/6] Convert error_report() to warn_report()

2017-07-07 Thread Alistair Francis
On Thu, Jul 6, 2017 at 5:14 PM,   wrote:
>>>>>> "Alistair" == Alistair Francis  writes:
>
> Alistair> Convert all uses of error_report("[Ww]arning:"... to use
> Alistair> warn_report() instead. This helps standardise on a single
> Alistair> method of printing warnings to the user.
>
> In a number of cases the initial double quote has been removed as
> well.  This will have to be fixed.
> e.g.,
> -error_report("Warning: 'filename' option specified. "
> +warn_report('filename' option specified. "

Yeah, I thought I saw this when I was doing it, but then everything
compiled so I figured it was fine.

It must not all be included with the default ./configure, because I
just tried again and it all compiles for me.

I'll fix these up in the next version.

Thanks,
Alistair

>
> I'm surprised the result compiled cleanly.
>
> Peter C
>
>
> --
> Dr Peter Chubb Tel: +61 2 9490 5852  http://ts.data61.csiro.au/
> Trustworthy Systems Group   Data61 (formerly NICTA)



Re: [Qemu-devel] [PATCH v1 3/6] Convert error_report() to warn_report()

2017-07-07 Thread Alistair Francis
On Fri, Jul 7, 2017 at 5:48 AM, Markus Armbruster  wrote:
> Alistair Francis  writes:
>
>> Convert all uses of error_report("[Ww]arning:"... to use warn_report()
>> instead. This helps standardise on a single method of printing warnings
>> to the user.
>>
>> All of the warnings were found using this regex expression:
>> error_report.*[Ww]arning:
>> and replaced with:
>> warn_report("
>>
>> Signed-off-by: Alistair Francis 
>> Suggested-by: Thomas Huth 
>
> Doesn't compile.  Moreover, you obviously changed more than just lines
> matching the regexp you quoted.
>
> To ease review, I please split the patch as follows:
>
> * First patch:
>
>   sed -i 's/error_report("warning: \([^"]*"\)/warn_report("\1/i' ...
>
>   plus indentation fixups.  Put exact sed command (or whatever else you
>   use) in the commit message.
>
> * Second patch with additional conversions.

The only additional conversion is fixing the test cases, which I
really don't want to have in a separate patch because then this patch
fails make check.

Thanks,
Alistair

>
> This way the bulk of the changes is mechanical, and the non-mechanical
> changes don't get lost in the sea of mechanical ones.



Re: [Qemu-devel] [PATCH v1 3/6] Convert error_report() to warn_report()

2017-07-07 Thread Alistair Francis
On Fri, Jul 7, 2017 at 5:06 AM, Eduardo Habkost  wrote:
> On Thu, Jul 06, 2017 at 04:49:44PM -0700, Alistair Francis wrote:
>> Convert all uses of error_report("[Ww]arning:"... to use warn_report()
>> instead. This helps standardise on a single method of printing warnings
>> to the user.
>>
>> All of the warnings were found using this regex expression:
>> error_report.*[Ww]arning:
>> and replaced with:
>> warn_report("
>>
>> Signed-off-by: Alistair Francis 
>> Suggested-by: Thomas Huth 
>
> I have reviewed the changes in: */i386/*, qdev-properties.c,
> vl.c, and tests/test-qdev-global-props.c.  They look good, except
> for kvm_arch_init_vcpu() below.
>
> There are also a few places below where we could improve the
> error messages in a follow-up patch (or in a new version of this
> patch if you prefer).

I split your comments into a new patch as I wasn't trying to fix the
messages in this patch.

>
> [...]
>> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
>> index 5464977424..6b7bade183 100644
>> --- a/hw/i386/acpi-build.c
>> +++ b/hw/i386/acpi-build.c
>> @@ -2766,17 +2766,17 @@ void acpi_build(AcpiBuildTables *tables, 
>> MachineState *machine)
>>   ACPI_BUILD_ALIGN_SIZE);
>>  if (tables_blob->len > legacy_table_size) {
>>  /* Should happen only with PCI bridges and -M pc-i440fx-2.0.  */
>> -error_report("Warning: migration may not work.");
>> +warn_report("migration may not work.");
>
> I suggest removing the period.
>
> Adding a justification to why migration may not work is a good
> idea, too.  We could copy the messages below (replacing "64k"
> with legacy_table_size).

Done.

>
>
>>  }
>>  g_array_set_size(tables_blob, legacy_table_size);
>>  } else {
>>  /* Make sure we have a buffer in case we need to resize the tables. 
>> */
>>  if (tables_blob->len > ACPI_BUILD_TABLE_SIZE / 2) {
>>  /* As of QEMU 2.1, this fires with 160 VCPUs and 255 memory 
>> slots.  */
>> -error_report("Warning: ACPI tables are larger than 64k.");
>> -error_report("Warning: migration may not work.");
>> -error_report("Warning: please remove CPUs, NUMA nodes, "
>> - "memory slots or PCI bridges.");
>> +warn_report("ACPI tables are larger than 64k.");
>> +warn_report("migration may not work.");
>> +warn_report("please remove CPUs, NUMA nodes, "
>> +"memory slots or PCI bridges.");
>
> I was going to suggest removing the periods here, but I'm not
> sure because we have multiple full sentences.
>
> However, if we are going to keep full sentences, I believe we
> should use uppercase letters.

They aren't really sentences when every message has a prefix, so I
just removed the periods.

>
>>  }
>>  acpi_align_size(tables_blob, ACPI_BUILD_TABLE_SIZE);
>>  }
>> diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
>> index 9f2615cbe0..33e20cb3e8 100644
>> --- a/hw/i386/kvm/pci-assign.c
>> +++ b/hw/i386/kvm/pci-assign.c
>> @@ -1353,9 +1353,9 @@ static int assigned_device_pci_cap_init(PCIDevice 
>> *pci_dev, Error **errp)
>> PCI_CAP_ID_EXP);
>>  return -EINVAL;
>>  } else if (size != 0x3c) {
>> -error_report("WARNING, %s: PCIe cap-id 0x%x has "
>> - "non-standard size 0x%x; std size should be 
>> 0x3c",
>> - __func__, PCI_CAP_ID_EXP, size);
>> +warn_report("%s: PCIe cap-id 0x%x has "
>> +"non-standard size 0x%x; std size should be 
>> 0x3c",
>> +__func__, PCI_CAP_ID_EXP, size);
>>  }
>>  } else if (version == 0) {
>>  uint16_t vid, did;
>> diff --git a/hw/i386/pc.c b/hw/i386/pc.c
>> index 224fe58fe7..58f8a4f4a5 100644
>> --- a/hw/i386/pc.c
>> +++ b/hw/i386/pc.c
>> @@ -381,8 +381,8 @@ ISADevice *pc_find_fdc0(void)
>>  }
>>
>>  if (state.multiple) {
>> -error_report("warning: multiple floppy disk controllers with "
>> - "iobase=0x3f0 have been found");
>> +warn_report("multip

[Qemu-devel] [PATCH v2 0/8] Implement a warning_report function

2017-07-07 Thread Alistair Francis
QEMU currently has a standard method to report errors with
error_repot(). This ensure a sane and standard format when printing
errors. This series is attempting to extend this functionality for
warnings and information as well.

This patch renames error_print_loc() function to be more clear, but I
didn't bother renaming the others. It seems silly to change
error_printf() to error_warning_printf() and printf is already taken so
I just left it as is.

v2:
 - Don't add *vreport() functions to checkpatch
 - Maintain original comments for the reporting functions
 - Don't change the error report output in this patch
 - Fixup some of the warning messages after the fact
 - Split the change to the error printing to be a seperate patch
v1:
 - Convert all of the existing warning messages in QEMU
 - Add a error_report*_err() functions as well
RFCv3:
 - Use more detailed enum and function names
 - Add wrapper functions for the info and warning reporting
RFCv2:
 - Use enums for ERROR, WARN and INFO with a generic report() function
   instead of adding new functions

Alistair Francis (8):
  util/qemu-error: Rename error_print_loc() to be more generic
  error: Functions to report warnings and informational messages
  Convert error_report() to warn_report()
  hw/i386: Improve some of the warning messages
  char-socket: Report TCP socket waiting as information
  error: Implement the warn and free Error functions
  Convert error_report*_err() to warn_report*_err()
  error: Add a 'error: ' prefix to error_report()

 block/backup.c |  10 ++--
 block/gluster.c|   2 +-
 block/iscsi.c  |   6 +--
 block/nfs.c|  12 ++---
 block/rbd.c|   6 +--
 block/ssh.c|   4 +-
 blockdev.c |   2 +-
 chardev/char-socket.c  |   4 +-
 cpus.c |   2 +-
 hw/9pfs/9p.c   |   2 +-
 hw/arm/highbank.c  |   6 +--
 hw/arm/imx25_pdk.c |   6 +--
 hw/arm/kzm.c   |   6 +--
 hw/core/machine.c  |  10 ++--
 hw/core/qdev-properties.c  |  10 ++--
 hw/i386/acpi-build.c   |  11 +++--
 hw/i386/kvm/pci-assign.c   |   6 +--
 hw/i386/pc.c   |  18 
 hw/i386/pc_piix.c  |   8 ++--
 hw/i386/pc_q35.c   |   6 +--
 hw/misc/aspeed_sdmc.c  |   8 ++--
 hw/nvram/fw_cfg.c  |   2 +-
 hw/pci-host/piix.c |   2 +-
 hw/ppc/pnv.c   |   6 +--
 hw/ppc/spapr.c |   4 +-
 hw/ppc/spapr_iommu.c   |   2 +-
 hw/scsi/scsi-bus.c |   6 +--
 hw/usb/dev-smartcard-reader.c  |   6 +--
 hw/usb/redirect.c  |   2 +-
 include/qapi/error.h   |  11 +
 include/qemu/error-report.h|   7 +++
 net/tap-linux.c|   2 +-
 scripts/checkpatch.pl  |   6 ++-
 target/i386/cpu.c  |  22 -
 target/i386/kvm.c  |  12 ++---
 target/s390x/cpu_models.c  |   6 +--
 target/s390x/kvm.c |   4 +-
 tests/test-qdev-global-props.c |   6 +--
 trace/control.c|   8 ++--
 util/error.c   |  19 
 util/qemu-error.c  | 102 ++---
 vl.c   |  20 
 42 files changed, 263 insertions(+), 137 deletions(-)

-- 
2.11.0




[Qemu-devel] [PATCH v2 1/8] util/qemu-error: Rename error_print_loc() to be more generic

2017-07-07 Thread Alistair Francis
Rename the error_print_loc() function in preparation for using it to
print warnings as well.

Signed-off-by: Alistair Francis 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Thomas Huth 
---

 util/qemu-error.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/util/qemu-error.c b/util/qemu-error.c
index b331f8f4a4..1c5e35ecdb 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -146,7 +146,7 @@ const char *error_get_progname(void)
 /*
  * Print current location to current monitor if we have one, else to stderr.
  */
-static void error_print_loc(void)
+static void print_loc(void)
 {
 const char *sep = "";
 int i;
@@ -197,7 +197,7 @@ void error_vreport(const char *fmt, va_list ap)
 g_free(timestr);
 }
 
-error_print_loc();
+print_loc();
 error_vprintf(fmt, ap);
 error_printf("\n");
 }
-- 
2.11.0




[Qemu-devel] [PATCH v2 6/8] error: Implement the warn and free Error functions

2017-07-07 Thread Alistair Francis
Implement warn_report_err() and warn_reportf_err() functions which
are the same as the error_report_err() and error_reportf_err()
functions except report a warning instead of an error.

Signed-off-by: Alistair Francis 
---

 include/qapi/error.h  | 11 +++
 scripts/checkpatch.pl |  1 +
 util/error.c  | 19 +++
 3 files changed, 31 insertions(+)

diff --git a/include/qapi/error.h b/include/qapi/error.h
index 7e532d00e9..af53b34410 100644
--- a/include/qapi/error.h
+++ b/include/qapi/error.h
@@ -267,11 +267,22 @@ void error_free(Error *err);
 void error_free_or_abort(Error **errp);
 
 /*
+ * Convenience function to warn_report() and free @err.
+ */
+void warn_report_err(Error *err);
+
+/*
  * Convenience function to error_report() and free @err.
  */
 void error_report_err(Error *err);
 
 /*
+ * Convenience function to error_prepend(), warn_report() and free @err.
+ */
+void warn_reportf_err(Error *err, const char *fmt, ...)
+GCC_FMT_ATTR(2, 3);
+
+/*
  * Convenience function to error_prepend(), error_report() and free @err.
  */
 void error_reportf_err(Error *err, const char *fmt, ...)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b76fe30ad3..8f5cbaa12e 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2533,6 +2533,7 @@ sub process {
error_setg_file_open|
error_set|
error_prepend|
+   warn_reportf_err|
error_reportf_err|
error_report|
warn_report|
diff --git a/util/error.c b/util/error.c
index 020b86b9f0..373566fb77 100644
--- a/util/error.c
+++ b/util/error.c
@@ -223,6 +223,15 @@ const char *error_get_pretty(const Error *err)
 return err->msg;
 }
 
+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_free(err);
+}
+
 void error_report_err(Error *err)
 {
 error_report("%s", error_get_pretty(err));
@@ -232,6 +241,16 @@ void error_report_err(Error *err)
 error_free(err);
 }
 
+void warn_reportf_err(Error *err, const char *fmt, ...)
+{
+va_list ap;
+
+va_start(ap, fmt);
+error_vprepend(&err, fmt, ap);
+va_end(ap);
+warn_report_err(err);
+}
+
 void error_reportf_err(Error *err, const char *fmt, ...)
 {
 va_list ap;
-- 
2.11.0




[Qemu-devel] [PATCH v2 4/8] hw/i386: Improve some of the warning messages

2017-07-07 Thread Alistair Francis
Signed-off-by: Alistair Francis 
Suggested-by: Eduardo Habkost 
---

 hw/i386/acpi-build.c | 7 ---
 hw/i386/pc.c | 9 -
 hw/i386/pc_q35.c | 4 ++--
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 6b7bade183..f9efb6be41 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -2766,7 +2766,8 @@ void acpi_build(AcpiBuildTables *tables, MachineState 
*machine)
  ACPI_BUILD_ALIGN_SIZE);
 if (tables_blob->len > legacy_table_size) {
 /* Should happen only with PCI bridges and -M pc-i440fx-2.0.  */
-warn_report("migration may not work.");
+warn_report("ACPI tables are larger than legacy_table_size");
+warn_report("migration may not work");
 }
 g_array_set_size(tables_blob, legacy_table_size);
 } else {
@@ -2774,9 +2775,9 @@ void acpi_build(AcpiBuildTables *tables, MachineState 
*machine)
 if (tables_blob->len > ACPI_BUILD_TABLE_SIZE / 2) {
 /* As of QEMU 2.1, this fires with 160 VCPUs and 255 memory slots. 
 */
 warn_report("ACPI tables are larger than 64k.");
-warn_report("migration may not work.");
+warn_report("migration may not work");
 warn_report("please remove CPUs, NUMA nodes, "
-"memory slots or PCI bridges.");
+"memory slots or PCI bridges");
 }
 acpi_align_size(tables_blob, ACPI_BUILD_TABLE_SIZE);
 }
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 58f8a4f4a5..3cc580a245 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -383,8 +383,8 @@ ISADevice *pc_find_fdc0(void)
 if (state.multiple) {
 warn_report("multiple floppy disk controllers with "
 "iobase=0x3f0 have been found");
-error_printf("the one being picked for CMOS setup might not reflect "
- "your intent\n");
+warn_report("the one being picked for CMOS setup might not reflect "
+"your intent");
 }
 
 return state.floppy;
@@ -2087,9 +2087,8 @@ static void pc_machine_set_max_ram_below_4g(Object *obj, 
Visitor *v,
 }
 
 if (value < (1ULL << 20)) {
-warn_report("small max_ram_below_4g(%"PRIu64
-") less than 1M.  BIOS may not work..",
-value);
+warn_report("max_ram_below_4g (%" PRIu64 ") is less than 1M; "
+"BIOS may not work.", value);
 }
 
 pcms->max_ram_below_4g = value;
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 1653a47f0a..682c576cf1 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -101,8 +101,8 @@ static void pc_q35_init(MachineState *machine)
 lowmem = pcms->max_ram_below_4g;
 if (machine->ram_size - lowmem > lowmem &&
 lowmem & ((1ULL << 30) - 1)) {
-warn_report("Large machine and max_ram_below_4g(%"PRIu64
-") not a multiple of 1G; possible bad performance.",
+warn_report("Large machine and max_ram_below_4g (%"PRIu64") not a "
+"multiple of 1G; possible bad performance.",
 pcms->max_ram_below_4g);
 }
 }
-- 
2.11.0




[Qemu-devel] [PATCH v2 2/8] error: Functions to report warnings and informational messages

2017-07-07 Thread Alistair Francis
Add warn_report(), warn_vreport() for reporting warnings, and
info_report(), info_vreport() for informational messages.

These are implemented them with a helper function factored out of
error_vreport(), suitably generalized. This patch makes no changes
to the output of the original error_report() function.

Signed-off-by: Alistair Francis 
---
v2:
 - Don't add *vreport() functions to checkpatch
 - Maintain original comments for the reporting functions
 - Don't change the error report output in this patch
v1:
 - Don't expose the generic report and vreport() functions
 - Prefix error messages
 - Use vreport instead of qmsg_vreport()
RFC V3:
 - Change the function and enum names to be more descriptive
 - Add wrapper functions for *_report() and *_vreport()

 include/qemu/error-report.h |  7 
 scripts/checkpatch.pl   |  5 ++-
 util/qemu-error.c   | 97 ++---
 3 files changed, 102 insertions(+), 7 deletions(-)

diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index 3001865896..e1c8ae1a52 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -35,8 +35,15 @@ 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);
+void info_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
+
 void error_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+void warn_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+void info_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+
 const char *error_get_progname(void);
 extern bool enable_timestamp_msg;
 
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 73efc927a9..b76fe30ad3 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2534,8 +2534,9 @@ sub process {
error_set|
error_prepend|
error_reportf_err|
-   error_vreport|
-   error_report}x;
+   error_report|
+   warn_report|
+   info_report}x;
 
if ($rawline =~ /\b(?:$qemu_error_funcs)\s*\(.*\".*\\n/) {
ERROR("Error messages should not contain newlines\n" . 
$herecurr);
diff --git a/util/qemu-error.c b/util/qemu-error.c
index 1c5e35ecdb..b555247e24 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -14,6 +14,16 @@
 #include "monitor/monitor.h"
 #include "qemu/error-report.h"
 
+/*
+ * @report_type is the type of message: error, warning or
+ * informational.
+ */
+typedef enum {
+REPORT_TYPE_ERROR,
+REPORT_TYPE_WARNING,
+REPORT_TYPE_INFO,
+} report_type;
+
 void error_printf(const char *fmt, ...)
 {
 va_list ap;
@@ -179,17 +189,28 @@ static void print_loc(void)
 
 bool enable_timestamp_msg;
 /*
- * Print an error message to current monitor if we have one, else to stderr.
+ * Print a message to current monitor if we have one, else to stderr.
  * Format arguments like vsprintf().  The resulting message should be
  * a single phrase, with no newline or trailing punctuation.
  * Prepend the current location and append a newline.
  * It's wrong to call this in a QMP monitor.  Use error_setg() there.
  */
-void error_vreport(const char *fmt, va_list ap)
+static void vreport(report_type type, const char *fmt, va_list ap)
 {
 GTimeVal tv;
 gchar *timestr;
 
+switch (type) {
+case REPORT_TYPE_ERROR:
+break;
+case REPORT_TYPE_WARNING:
+error_printf("warning: ");
+break;
+case REPORT_TYPE_INFO:
+error_printf("info: ");
+break;
+}
+
 if (enable_timestamp_msg && !cur_mon) {
 g_get_current_time(&tv);
 timestr = g_time_val_to_iso8601(&tv);
@@ -204,8 +225,41 @@ void error_vreport(const char *fmt, va_list ap)
 
 /*
  * Print an error message to current monitor if we have one, else to stderr.
- * Format arguments like sprintf().  The resulting message should be a
- * single phrase, with no newline or trailing punctuation.
+ * Format arguments like vsprintf().  The resulting message should be
+ * a single phrase, with no newline or trailing punctuation.
+ * Prepend the current location and append a newline.
+ * It's wrong to call this in a QMP monitor.  Use error_setg() there.
+ */
+void error_vreport(const char *fmt, va_list ap)
+{
+vreport(REPORT_TYPE_ERROR, fmt, ap);
+}
+
+/*
+ * Print a warning message to current monitor if we have one, else to stderr.
+ */
+void warn_vreport(const char *fmt, va_list ap)
+{
+vreport(R

[Qemu-devel] [PATCH v2 3/8] Convert error_report() to warn_report()

2017-07-07 Thread Alistair Francis
Convert all uses of error_report("[Ww]arning:"... to use warn_report()
instead. This helps standardise on a single method of printing warnings
to the user.

All of the warnings were changed using this command:
find ./* -type f -exec sed -i \
's|error_report.*[Ww]arning: |warn_report("|g' {} +

Then the white space changes where manually fixed afterwards.

The test-qdev-global-props test case was manually updated to ensure that
this patch passes make check (as the test cases are case sensitive).

Signed-off-by: Alistair Francis 
Suggested-by: Thomas Huth 
Cc: Jeff Cody 
Cc: Kevin Wolf 
Cc: Max Reitz 
Cc: Ronnie Sahlberg 
Cc: Paolo Bonzini 
Cc: Peter Lieven 
Cc: Josh Durgin 
Cc: "Richard W.M. Jones" 
Cc: Markus Armbruster 
Cc: Peter Crosthwaite 
Cc: Richard Henderson 
Cc: "Aneesh Kumar K.V" 
Cc: Greg Kurz 
Cc: Rob Herring 
Cc: Peter Maydell 
Cc: Peter Chubb 
Cc: Eduardo Habkost 
Cc: Marcel Apfelbaum 
Cc: "Michael S. Tsirkin" 
Cc: Igor Mammedov 
Cc: David Gibson 
Cc: Alexander Graf 
Cc: Gerd Hoffmann 
Cc: Jason Wang 
Cc: Marcelo Tosatti 
Cc: Christian Borntraeger 
Cc: Cornelia Huck 
Cc: Stefan Hajnoczi 
Acked-by: David Gibson 
Acked-by: Greg Kurz 
Acked-by: Cornelia Huck 
Reviewed-by: Stefan Hajnoczi 
---
V2:
 - Fix quotation issues
 - Update commit message
 - Include full command

 block/backup.c | 10 +-
 block/gluster.c|  2 +-
 block/iscsi.c  |  6 +++---
 block/nfs.c| 12 ++--
 block/rbd.c|  6 +++---
 block/ssh.c|  4 ++--
 blockdev.c |  2 +-
 cpus.c |  2 +-
 hw/9pfs/9p.c   |  2 +-
 hw/arm/highbank.c  |  6 +++---
 hw/arm/imx25_pdk.c |  6 +++---
 hw/arm/kzm.c   |  6 +++---
 hw/core/machine.c  | 10 +-
 hw/core/qdev-properties.c  |  8 
 hw/i386/acpi-build.c   | 10 +-
 hw/i386/kvm/pci-assign.c   |  6 +++---
 hw/i386/pc.c   | 12 ++--
 hw/i386/pc_piix.c  |  8 
 hw/i386/pc_q35.c   |  6 +++---
 hw/misc/aspeed_sdmc.c  |  8 
 hw/nvram/fw_cfg.c  |  2 +-
 hw/pci-host/piix.c |  2 +-
 hw/ppc/pnv.c   |  6 +++---
 hw/ppc/spapr.c |  4 ++--
 hw/ppc/spapr_iommu.c   |  2 +-
 hw/scsi/scsi-bus.c |  6 +++---
 hw/usb/dev-smartcard-reader.c  |  6 +++---
 hw/usb/redirect.c  |  2 +-
 net/tap-linux.c|  2 +-
 target/i386/cpu.c  | 22 +++---
 target/i386/kvm.c  | 12 ++--
 target/s390x/cpu_models.c  |  6 +++---
 target/s390x/kvm.c |  4 ++--
 tests/test-qdev-global-props.c |  6 +++---
 trace/control.c|  8 
 vl.c   | 20 ++--
 36 files changed, 121 insertions(+), 121 deletions(-)

diff --git a/block/backup.c b/block/backup.c
index 5387fbd84e..a0f059a0b6 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -657,11 +657,11 @@ BlockJob *backup_job_create(const char *job_id, 
BlockDriverState *bs,
 ret = bdrv_get_info(target, &bdi);
 if (ret == -ENOTSUP && !target->backing) {
 /* Cluster size is not defined */
-error_report("WARNING: The target block device doesn't provide "
- "information about the block size and it doesn't have a "
- "backing file. The default block size of %u bytes is "
- "used. If the actual block size of the target exceeds "
- "this default, the backup may be unusable",
+warn_report("The target block device doesn't provide "
+"information about the block size and it doesn't have a "
+"backing file. The default block size of %u bytes is "
+"used. If the actual block size of the target exceeds "
+"this default, the backup may be unusable",
  BACKUP_CLUSTER_SIZE_DEFAULT);
 job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT;
 } else if (ret < 0 && !target->backing) {
diff --git a/block/gluster.c b/block/gluster.c
index addceed6eb..531e72df56 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -345,7 +345,7 @@ static int qemu_gluster_parse_uri(BlockdevOptionsGluster 
*gconf,
 is_unix = true;
 } else if (!strcmp(uri->scheme, "gluster+rdma")) {
 gsconf->type = SOCKET_ADDRESS_TYPE_INET;
-error_report("Warning: rdma feature is not supported, falling "
+warn_report("rdma feature is not supported, falling "
  "back to tcp"

[Qemu-devel] [PATCH v2 5/8] char-socket: Report TCP socket waiting as information

2017-07-07 Thread Alistair Francis
When QEMU is waiting for a TCP socket connection it reports that message as
an error. This isn't an error it is just information so let's change the
report to use info_report() instead.

Signed-off-by: Alistair Francis 
Reviewed-by: Thomas Huth 
Reviewed-by: Philippe Mathieu-Daudé 
---

 chardev/char-socket.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index ccc499cfa1..a050a686ea 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -765,8 +765,8 @@ static int tcp_chr_wait_connected(Chardev *chr, Error 
**errp)
  * in TLS and telnet cases, only wait for an accepted socket */
 while (!s->ioc) {
 if (s->is_listen) {
-error_report("QEMU waiting for connection on: %s",
- chr->filename);
+info_report("QEMU waiting for connection on: %s",
+chr->filename);
 qio_channel_set_blocking(QIO_CHANNEL(s->listen_ioc), true, NULL);
 tcp_chr_accept(QIO_CHANNEL(s->listen_ioc), G_IO_IN, chr);
 qio_channel_set_blocking(QIO_CHANNEL(s->listen_ioc), false, NULL);
-- 
2.11.0




[Qemu-devel] [PATCH v2 7/8] Convert error_report*_err() to warn_report*_err()

2017-07-07 Thread Alistair Francis
Convert all uses of error_report*_err("Warning:"... to use
warn_report*_err() instead. This helps standardise on a single
method of printing warnings to the user.

Signed-off-by: Alistair Francis 
Cc: Paolo Bonzini 
Cc: Richard Henderson 
Cc: Eduardo Habkost 
Cc: "Michael S. Tsirkin" 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Eduardo Habkost 
---

 hw/core/qdev-properties.c | 2 +-
 hw/i386/pc.c  | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index f5983c83da..3d0bba21a2 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -1169,7 +1169,7 @@ static void qdev_prop_set_globals_for_type(DeviceState 
*dev,
 error_propagate(prop->errp, err);
 } else {
 assert(prop->user_provided);
-error_reportf_err(err, "Warning: ");
+warn_report_err(err);
 }
 }
 }
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 3cc580a245..b825492888 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1320,8 +1320,7 @@ void pc_acpi_init(const char *default_dsdt)
 
 acpi_table_add_builtin(opts, &err);
 if (err) {
-error_reportf_err(err, "WARNING: failed to load %s: ",
-  filename);
+warn_reportf_err(err, "failed to load %s: ", filename);
 }
 g_free(filename);
 }
-- 
2.11.0




[Qemu-devel] [PATCH v2 8/8] error: Add a 'error: ' prefix to error_report()

2017-07-07 Thread Alistair Francis
As we don't regard error messages as a stable API the let's add a
'error: ' prefix to the original error_report() messages.

Signed-off-by: Alistair Francis 
---

 util/qemu-error.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/util/qemu-error.c b/util/qemu-error.c
index b555247e24..cf1eb8e8b9 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -202,6 +202,7 @@ static void vreport(report_type type, const char *fmt, 
va_list ap)
 
 switch (type) {
 case REPORT_TYPE_ERROR:
+error_printf("error: ");
 break;
 case REPORT_TYPE_WARNING:
 error_printf("warning: ");
-- 
2.11.0




[Qemu-devel] [PATCH v3 1/8] util/qemu-error: Rename error_print_loc() to be more generic

2017-07-11 Thread Alistair Francis
Rename the error_print_loc() function in preparation for using it to
print warnings as well.

Signed-off-by: Alistair Francis 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Thomas Huth 
---

 util/qemu-error.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/util/qemu-error.c b/util/qemu-error.c
index b331f8f4a4..1c5e35ecdb 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -146,7 +146,7 @@ const char *error_get_progname(void)
 /*
  * Print current location to current monitor if we have one, else to stderr.
  */
-static void error_print_loc(void)
+static void print_loc(void)
 {
 const char *sep = "";
 int i;
@@ -197,7 +197,7 @@ void error_vreport(const char *fmt, va_list ap)
 g_free(timestr);
 }
 
-error_print_loc();
+print_loc();
 error_vprintf(fmt, ap);
 error_printf("\n");
 }
-- 
2.11.0




[Qemu-devel] [PATCH v3 0/8] Implement a warning_report function

2017-07-11 Thread Alistair Francis
QEMU currently has a standard method to report errors with
error_repot(). This ensure a sane and standard format when printing
errors. This series is attempting to extend this functionality for
warnings and information as well.

This patch renames error_print_loc() function to be more clear, but I
didn't bother renaming the others. It seems silly to change
error_printf() to error_warning_printf() and printf is already taken so
I just left it as is.
v3:
 - Regenerate the replacement patch
v1:
 - Convert all of the existing warning messages in QEMU
 - Add a error_report*_err() functions as well
RFCv3:
 - Use more detailed enum and function names
 - Add wrapper functions for the info and warning reporting
RFCv2:
 - Use enums for ERROR, WARN and INFO with a generic report() function
   instead of adding new functions



Alistair Francis (8):
  util/qemu-error: Rename error_print_loc() to be more generic
  error: Functions to report warnings and informational messages
  Convert error_report() to warn_report()
  hw/i386: Improve some of the warning messages
  char-socket: Report TCP socket waiting as information
  error: Implement the warn and free Error functions
  Convert error_report*_err() to warn_report*_err()
  error: Add a 'error: ' prefix to error_report()

 block/backup.c |  10 ++--
 block/gluster.c|   4 +-
 block/iscsi.c  |   6 +--
 block/nfs.c|  12 ++---
 block/rbd.c|   6 +--
 block/ssh.c|   4 +-
 blockdev.c |   2 +-
 chardev/char-socket.c  |   4 +-
 cpus.c |   2 +-
 hw/9pfs/9p.c   |   2 +-
 hw/arm/highbank.c  |   6 +--
 hw/arm/imx25_pdk.c |   6 +--
 hw/arm/kzm.c   |   6 +--
 hw/core/machine.c  |  10 ++--
 hw/core/qdev-properties.c  |  10 ++--
 hw/i386/acpi-build.c   |  11 +++--
 hw/i386/kvm/pci-assign.c   |   6 +--
 hw/i386/pc.c   |  16 +++---
 hw/i386/pc_piix.c  |   8 +--
 hw/i386/pc_q35.c   |   6 +--
 hw/misc/aspeed_sdmc.c  |   8 +--
 hw/nvram/fw_cfg.c  |   2 +-
 hw/pci-host/piix.c |   2 +-
 hw/ppc/pnv.c   |   6 +--
 hw/ppc/spapr.c |   4 +-
 hw/ppc/spapr_iommu.c   |   2 +-
 hw/scsi/scsi-bus.c |   6 +--
 hw/usb/dev-smartcard-reader.c  |   4 +-
 hw/usb/redirect.c  |   2 +-
 include/qapi/error.h   |  11 +
 include/qemu/error-report.h|   7 +++
 net/tap-linux.c|   2 +-
 scripts/checkpatch.pl  |   7 ++-
 target/i386/cpu.c  |   8 +--
 target/i386/kvm.c  |   4 +-
 target/s390x/cpu_models.c  |   2 +-
 target/s390x/kvm.c |   2 +-
 tests/test-qdev-global-props.c |   6 +--
 trace/control.c|   4 +-
 util/error.c   |  20 
 util/qemu-error.c  | 107 ++---
 vl.c   |  20 
 42 files changed, 254 insertions(+), 119 deletions(-)

-- 
2.11.0




[Qemu-devel] [PATCH v3 5/8] char-socket: Report TCP socket waiting as information

2017-07-11 Thread Alistair Francis
When QEMU is waiting for a TCP socket connection it reports that message as
an error. This isn't an error it is just information so let's change the
report to use info_report() instead.

Signed-off-by: Alistair Francis 
Reviewed-by: Thomas Huth 
Reviewed-by: Philippe Mathieu-Daudé 
---

 chardev/char-socket.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index ccc499cfa1..a050a686ea 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -765,8 +765,8 @@ static int tcp_chr_wait_connected(Chardev *chr, Error 
**errp)
  * in TLS and telnet cases, only wait for an accepted socket */
 while (!s->ioc) {
 if (s->is_listen) {
-error_report("QEMU waiting for connection on: %s",
- chr->filename);
+info_report("QEMU waiting for connection on: %s",
+chr->filename);
 qio_channel_set_blocking(QIO_CHANNEL(s->listen_ioc), true, NULL);
 tcp_chr_accept(QIO_CHANNEL(s->listen_ioc), G_IO_IN, chr);
 qio_channel_set_blocking(QIO_CHANNEL(s->listen_ioc), false, NULL);
-- 
2.11.0




[Qemu-devel] [PATCH v3 3/8] Convert error_report() to warn_report()

2017-07-11 Thread Alistair Francis
Convert all uses of error_report("warning:"... to use warn_report()
instead. This helps standardise on a single method of printing warnings
to the user.

All of the warnings where changed using these two commands:
find ./* -type f -exec sed -i \
  's|error_report(".*warning[,:] |warn_report("|Ig' {} +

Then the white space changes where manually fixed afterwards.

The test-qdev-global-props test case was manually updated to ensure that
this patch passes make check (as the test cases are case sensitive).

Signed-off-by: Alistair Francis 
Suggested-by: Thomas Huth 
Cc: Jeff Cody 
Cc: Kevin Wolf 
Cc: Max Reitz 
Cc: Ronnie Sahlberg 
Cc: Paolo Bonzini 
Cc: Peter Lieven 
Cc: Josh Durgin 
Cc: "Richard W.M. Jones" 
Cc: Markus Armbruster 
Cc: Peter Crosthwaite 
Cc: Richard Henderson 
Cc: "Aneesh Kumar K.V" 
Cc: Greg Kurz 
Cc: Rob Herring 
Cc: Peter Maydell 
Cc: Peter Chubb 
Cc: Eduardo Habkost 
Cc: Marcel Apfelbaum 
Cc: "Michael S. Tsirkin" 
Cc: Igor Mammedov 
Cc: David Gibson 
Cc: Alexander Graf 
Cc: Gerd Hoffmann 
Cc: Jason Wang 
Cc: Marcelo Tosatti 
Cc: Christian Borntraeger 
Cc: Cornelia Huck 
Cc: Stefan Hajnoczi 
Acked-by: David Gibson 
Acked-by: Greg Kurz 
Acked-by: Cornelia Huck 
Reviewed-by: Stefan Hajnoczi 
Reviewed by: Peter Chubb 
Acked-by: Max Reitz 
Acked-by: Marcel Apfelbaum 
---
V3:
 - Regenerate patch to ensure no manual edits where made
 - Tighten regex matches
V2:
 - Fix quotation issues
 - Update commit message
 - Include full command

Just a note:
We will need to do a similar thing for fprintf. There are patches on
the list at the moment that conflict with this series (by adding
error_report() calls that shsould be warning), so I think I'm giong to
have to do a follow up series converting more cases. I'll cover the
fprintf cases when I do that. There are some manual cases as
well that don't say warning or info, but really should. They will have
to be converted as well.


 block/backup.c | 10 +-
 block/gluster.c|  4 ++--
 block/iscsi.c  |  6 +++---
 block/nfs.c| 12 ++--
 block/rbd.c|  6 +++---
 block/ssh.c|  4 ++--
 blockdev.c |  2 +-
 cpus.c |  2 +-
 hw/9pfs/9p.c   |  2 +-
 hw/arm/highbank.c  |  6 +++---
 hw/arm/imx25_pdk.c |  6 +++---
 hw/arm/kzm.c   |  6 +++---
 hw/core/machine.c  | 10 +-
 hw/core/qdev-properties.c  |  8 
 hw/i386/acpi-build.c   | 10 +-
 hw/i386/kvm/pci-assign.c   |  6 +++---
 hw/i386/pc.c   | 10 +-
 hw/i386/pc_piix.c  |  8 
 hw/i386/pc_q35.c   |  6 +++---
 hw/misc/aspeed_sdmc.c  |  8 
 hw/nvram/fw_cfg.c  |  2 +-
 hw/pci-host/piix.c |  2 +-
 hw/ppc/pnv.c   |  6 +++---
 hw/ppc/spapr.c |  4 ++--
 hw/ppc/spapr_iommu.c   |  2 +-
 hw/scsi/scsi-bus.c |  6 +++---
 hw/usb/dev-smartcard-reader.c  |  4 ++--
 hw/usb/redirect.c  |  2 +-
 net/tap-linux.c|  2 +-
 target/i386/cpu.c  |  8 
 target/i386/kvm.c  |  4 ++--
 target/s390x/cpu_models.c  |  2 +-
 target/s390x/kvm.c |  2 +-
 tests/test-qdev-global-props.c |  6 +++---
 trace/control.c|  4 ++--
 vl.c   | 20 ++--
 36 files changed, 104 insertions(+), 104 deletions(-)

diff --git a/block/backup.c b/block/backup.c
index b69184eac5..44cc2b22ab 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -639,11 +639,11 @@ BlockJob *backup_job_create(const char *job_id, 
BlockDriverState *bs,
 ret = bdrv_get_info(target, &bdi);
 if (ret == -ENOTSUP && !target->backing) {
 /* Cluster size is not defined */
-error_report("WARNING: The target block device doesn't provide "
- "information about the block size and it doesn't have a "
- "backing file. The default block size of %u bytes is "
- "used. If the actual block size of the target exceeds "
- "this default, the backup may be unusable",
+warn_report("The target block device doesn't provide "
+"information about the block size and it doesn't have a "
+"backing file. The default block size of %u bytes is "
+"used. If the actual block size of the target exceeds "
+"this default, the backup may be unusable",
  BACKUP_CLUSTER_SIZE_DEFAULT);
 job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT;
 } else if (ret < 0 &&

[Qemu-devel] [PATCH v3 2/8] error: Functions to report warnings and informational messages

2017-07-11 Thread Alistair Francis
Add warn_report(), warn_vreport() for reporting warnings, and
info_report(), info_vreport() for informational messages.

These are implemented them with a helper function factored out of
error_vreport(), suitably generalized. This patch makes no changes
to the output of the original error_report() function.

Signed-off-by: Alistair Francis 
Reviewed-by: Markus Armbruster 
---
v2:
 - Don't add *vreport() functions to checkpatch
 - Maintain original comments for the reporting functions
 - Don't change the error report output in this patch
v1:
 - Don't expose the generic report and vreport() functions
 - Prefix error messages
 - Use vreport instead of qmsg_vreport()
RFC V3:
 - Change the function and enum names to be more descriptive
 - Add wrapper functions for *_report() and *_vreport()

 include/qemu/error-report.h |   7 +++
 scripts/checkpatch.pl   |   6 ++-
 util/qemu-error.c   | 102 +---
 3 files changed, 109 insertions(+), 6 deletions(-)

diff --git a/include/qemu/error-report.h b/include/qemu/error-report.h
index 3001865896..e1c8ae1a52 100644
--- a/include/qemu/error-report.h
+++ b/include/qemu/error-report.h
@@ -35,8 +35,15 @@ 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);
+void info_vreport(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
+
 void error_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+void warn_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+void info_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
+
 const char *error_get_progname(void);
 extern bool enable_timestamp_msg;
 
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 73efc927a9..60b1f320a1 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2535,7 +2535,11 @@ sub process {
error_prepend|
error_reportf_err|
error_vreport|
-   error_report}x;
+   report_vreport|
+   info_vreport|
+   error_report|
+   warn_report|
+   info_report}x;
 
if ($rawline =~ /\b(?:$qemu_error_funcs)\s*\(.*\".*\\n/) {
ERROR("Error messages should not contain newlines\n" . 
$herecurr);
diff --git a/util/qemu-error.c b/util/qemu-error.c
index 1c5e35ecdb..c557c6ae47 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -14,6 +14,16 @@
 #include "monitor/monitor.h"
 #include "qemu/error-report.h"
 
+/*
+ * @report_type is the type of message: error, warning or
+ * informational.
+ */
+typedef enum {
+REPORT_TYPE_ERROR,
+REPORT_TYPE_WARNING,
+REPORT_TYPE_INFO,
+} report_type;
+
 void error_printf(const char *fmt, ...)
 {
 va_list ap;
@@ -179,17 +189,29 @@ static void print_loc(void)
 
 bool enable_timestamp_msg;
 /*
- * Print an error message to current monitor if we have one, else to stderr.
+ * Print a message to current monitor if we have one, else to stderr.
+ * @report_type is the type of message: error, warning or informational.
  * Format arguments like vsprintf().  The resulting message should be
  * a single phrase, with no newline or trailing punctuation.
  * Prepend the current location and append a newline.
  * It's wrong to call this in a QMP monitor.  Use error_setg() there.
  */
-void error_vreport(const char *fmt, va_list ap)
+static void vreport(report_type type, const char *fmt, va_list ap)
 {
 GTimeVal tv;
 gchar *timestr;
 
+switch (type) {
+case REPORT_TYPE_ERROR:
+break;
+case REPORT_TYPE_WARNING:
+error_printf("warning: ");
+break;
+case REPORT_TYPE_INFO:
+error_printf("info: ");
+break;
+}
+
 if (enable_timestamp_msg && !cur_mon) {
 g_get_current_time(&tv);
 timestr = g_time_val_to_iso8601(&tv);
@@ -204,8 +226,45 @@ void error_vreport(const char *fmt, va_list ap)
 
 /*
  * Print an error message to current monitor if we have one, else to stderr.
- * Format arguments like sprintf().  The resulting message should be a
- * single phrase, with no newline or trailing punctuation.
+ * Format arguments like vsprintf().  The resulting message should be
+ * a single phrase, with no newline or trailing punctuation.
+ * Prepend the current location and append a newline.
+ * It's wrong to call this in a QMP monitor.  Use error_setg() there.
+ */
+void error_vreport(const char *fmt, va_list ap)
+{
+vreport(REPORT_TYPE_ERROR, 

[Qemu-devel] [PATCH v3 4/8] hw/i386: Improve some of the warning messages

2017-07-11 Thread Alistair Francis
Signed-off-by: Alistair Francis 
Suggested-by: Eduardo Habkost 
---

 hw/i386/acpi-build.c | 7 ---
 hw/i386/pc.c | 9 -
 hw/i386/pc_q35.c | 4 ++--
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 6b7bade183..f9efb6be41 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -2766,7 +2766,8 @@ void acpi_build(AcpiBuildTables *tables, MachineState 
*machine)
  ACPI_BUILD_ALIGN_SIZE);
 if (tables_blob->len > legacy_table_size) {
 /* Should happen only with PCI bridges and -M pc-i440fx-2.0.  */
-warn_report("migration may not work.");
+warn_report("ACPI tables are larger than legacy_table_size");
+warn_report("migration may not work");
 }
 g_array_set_size(tables_blob, legacy_table_size);
 } else {
@@ -2774,9 +2775,9 @@ void acpi_build(AcpiBuildTables *tables, MachineState 
*machine)
 if (tables_blob->len > ACPI_BUILD_TABLE_SIZE / 2) {
 /* As of QEMU 2.1, this fires with 160 VCPUs and 255 memory slots. 
 */
 warn_report("ACPI tables are larger than 64k.");
-warn_report("migration may not work.");
+warn_report("migration may not work");
 warn_report("please remove CPUs, NUMA nodes, "
-"memory slots or PCI bridges.");
+"memory slots or PCI bridges");
 }
 acpi_align_size(tables_blob, ACPI_BUILD_TABLE_SIZE);
 }
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 465e91cc5b..084ca796c2 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -383,8 +383,8 @@ ISADevice *pc_find_fdc0(void)
 if (state.multiple) {
 warn_report("multiple floppy disk controllers with "
 "iobase=0x3f0 have been found");
-error_printf("the one being picked for CMOS setup might not reflect "
- "your intent\n");
+warn_report("the one being picked for CMOS setup might not reflect "
+"your intent");
 }
 
 return state.floppy;
@@ -2087,9 +2087,8 @@ static void pc_machine_set_max_ram_below_4g(Object *obj, 
Visitor *v,
 }
 
 if (value < (1ULL << 20)) {
-warn_report("small max_ram_below_4g(%"PRIu64
-") less than 1M.  BIOS may not work..",
-value);
+warn_report("max_ram_below_4g (%" PRIu64 ") is less than 1M; "
+"BIOS may not work.", value);
 }
 
 pcms->max_ram_below_4g = value;
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 1653a47f0a..682c576cf1 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -101,8 +101,8 @@ static void pc_q35_init(MachineState *machine)
 lowmem = pcms->max_ram_below_4g;
 if (machine->ram_size - lowmem > lowmem &&
 lowmem & ((1ULL << 30) - 1)) {
-warn_report("Large machine and max_ram_below_4g(%"PRIu64
-") not a multiple of 1G; possible bad performance.",
+warn_report("Large machine and max_ram_below_4g (%"PRIu64") not a "
+"multiple of 1G; possible bad performance.",
 pcms->max_ram_below_4g);
 }
 }
-- 
2.11.0




[Qemu-devel] [PATCH v3 7/8] Convert error_report*_err() to warn_report*_err()

2017-07-11 Thread Alistair Francis
Convert all uses of error_report*_err("Warning:"... to use
warn_report*_err() instead. This helps standardise on a single
method of printing warnings to the user.

Signed-off-by: Alistair Francis 
Cc: Paolo Bonzini 
Cc: Richard Henderson 
Cc: Eduardo Habkost 
Cc: "Michael S. Tsirkin" 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Eduardo Habkost 
Reviewed-by: Markus Armbruster 
---

 hw/core/qdev-properties.c | 2 +-
 hw/i386/pc.c  | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index f5983c83da..3d0bba21a2 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -1169,7 +1169,7 @@ static void qdev_prop_set_globals_for_type(DeviceState 
*dev,
 error_propagate(prop->errp, err);
 } else {
 assert(prop->user_provided);
-error_reportf_err(err, "Warning: ");
+warn_report_err(err);
 }
 }
 }
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 084ca796c2..4d5bc6e5f3 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1320,8 +1320,7 @@ void pc_acpi_init(const char *default_dsdt)
 
 acpi_table_add_builtin(opts, &err);
 if (err) {
-error_reportf_err(err, "WARNING: failed to load %s: ",
-  filename);
+warn_reportf_err(err, "failed to load %s: ", filename);
 }
 g_free(filename);
 }
-- 
2.11.0




[Qemu-devel] [PATCH v3 6/8] error: Implement the warn and free Error functions

2017-07-11 Thread Alistair Francis
Implement warn_report_err() and warn_reportf_err() functions which
are the same as the error_report_err() and error_reportf_err()
functions except report a warning instead of an error.

Signed-off-by: Alistair Francis 
Reviewed-by: Markus Armbruster 
---

 include/qapi/error.h  | 11 +++
 scripts/checkpatch.pl |  1 +
 util/error.c  | 20 
 3 files changed, 32 insertions(+)

diff --git a/include/qapi/error.h b/include/qapi/error.h
index 7e532d00e9..af53b34410 100644
--- a/include/qapi/error.h
+++ b/include/qapi/error.h
@@ -267,11 +267,22 @@ void error_free(Error *err);
 void error_free_or_abort(Error **errp);
 
 /*
+ * Convenience function to warn_report() and free @err.
+ */
+void warn_report_err(Error *err);
+
+/*
  * Convenience function to error_report() and free @err.
  */
 void error_report_err(Error *err);
 
 /*
+ * Convenience function to error_prepend(), warn_report() and free @err.
+ */
+void warn_reportf_err(Error *err, const char *fmt, ...)
+GCC_FMT_ATTR(2, 3);
+
+/*
  * Convenience function to error_prepend(), error_report() and free @err.
  */
 void error_reportf_err(Error *err, const char *fmt, ...)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 60b1f320a1..dba8c84ca5 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2533,6 +2533,7 @@ sub process {
error_setg_file_open|
error_set|
error_prepend|
+   warn_reportf_err|
error_reportf_err|
error_vreport|
report_vreport|
diff --git a/util/error.c b/util/error.c
index 020b86b9f0..3efdd69162 100644
--- a/util/error.c
+++ b/util/error.c
@@ -232,6 +232,15 @@ void error_report_err(Error *err)
 error_free(err);
 }
 
+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_free(err);
+}
+
 void error_reportf_err(Error *err, const char *fmt, ...)
 {
 va_list ap;
@@ -242,6 +251,17 @@ void error_reportf_err(Error *err, const char *fmt, ...)
 error_report_err(err);
 }
 
+
+void warn_reportf_err(Error *err, const char *fmt, ...)
+{
+va_list ap;
+
+va_start(ap, fmt);
+error_vprepend(&err, fmt, ap);
+va_end(ap);
+warn_report_err(err);
+}
+
 void error_free(Error *err)
 {
 if (err) {
-- 
2.11.0




[Qemu-devel] [PATCH v3 8/8] error: Add a 'error: ' prefix to error_report()

2017-07-11 Thread Alistair Francis
As we don't regard error messages as a stable API the let's add a
'error: ' prefix to the original error_report() messages.

Signed-off-by: Alistair Francis 
---

 util/qemu-error.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/util/qemu-error.c b/util/qemu-error.c
index c557c6ae47..3a3372b68b 100644
--- a/util/qemu-error.c
+++ b/util/qemu-error.c
@@ -203,6 +203,7 @@ static void vreport(report_type type, const char *fmt, 
va_list ap)
 
 switch (type) {
 case REPORT_TYPE_ERROR:
+error_printf("error: ");
 break;
 case REPORT_TYPE_WARNING:
 error_printf("warning: ");
-- 
2.11.0




Re: [Qemu-devel] [PATCH 1/7] hw/arm/mps2: Implement skeleton mps2-an385 and mps2-an511 board models

2017-07-11 Thread Alistair Francis
On Tue, Jul 11, 2017 at 1:17 PM, Peter Maydell  wrote:
> Model the ARM MPS2/MPS2+ FPGA based development board.
>
> The MPS2 and MPS2+ dev boards are FPGA based (the 2+ has a bigger
> FPGA but is otherwise the same as the 2). Since the CPU itself
> and most of the devices are in the FPGA, the details of the board
> as seen by the guest depend significantly on the FPGA image.
>
> We model the following FPGA images:
>  "mps2_an385" -- Cortex-M3 as documented in ARM Application Note AN385
>  "mps2_an511" -- Cortex-M3 'DesignStart' as documented in AN511
>
> They are fairly similar but differ in the details for some
> peripherals.
>
> Signed-off-by: Peter Maydell 
> ---
>  hw/arm/Makefile.objs|   1 +
>  hw/arm/mps2.c   | 273 
> 
>  default-configs/arm-softmmu.mak |   1 +
>  3 files changed, 275 insertions(+)
>  create mode 100644 hw/arm/mps2.c
>
> diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
> index 4c5c4ee..a2e56ec 100644
> --- a/hw/arm/Makefile.objs
> +++ b/hw/arm/Makefile.objs
> @@ -18,3 +18,4 @@ 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_ASPEED_SOC) += aspeed_soc.o aspeed.o
> +obj-$(CONFIG_MPS2) += mps2.o

Is this file name possibly too generic? Should it be arm-mps2 instead.

I don't see any other boards with the same name from a Google search,
but it just seems a bit vague having a three letter acronym.

> diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c
> new file mode 100644
> index 000..28838bc
> --- /dev/null
> +++ b/hw/arm/mps2.c
> @@ -0,0 +1,273 @@
> +/*
> + * ARM V2M MPS2 board emulation.
> + *
> + * Copyright (c) 2017 Linaro Limited
> + * Written by Peter Maydell
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License version 2 or
> + *  (at your option) any later version.
> + */
> +
> +/* The MPS2 and MPS2+ dev boards are FPGA based (the 2+ has a bigger
> + * FPGA but is otherwise the same as the 2). Since the CPU itself
> + * and most of the devices are in the FPGA, the details of the board
> + * as seen by the guest depend significantly on the FPGA image.
> + * We model the following FPGA images:
> + *  "mps2_an385" -- Cortex-M3 as documented in ARM Application Note AN385
> + *  "mps2_an511" -- Cortex-M3 'DesignStart' as documented in AN511
> + *
> + * Links to the TRM for the board itself and to the various Application
> + * Notes which document the FPGA images can be found here:
> + *   
> https://developer.arm.com/products/system-design/development-boards/cortex-m-prototyping-system
> + */
> +
> +#include "qemu/osdep.h"
> +#include "qapi/error.h"
> +#include "qemu/error-report.h"
> +#include "hw/arm/arm.h"
> +#include "hw/arm/armv7m.h"
> +#include "hw/boards.h"
> +#include "exec/address-spaces.h"
> +#include "hw/misc/unimp.h"
> +
> +typedef enum MPS2FPGAType {
> +FPGA_AN385,
> +FPGA_AN511,
> +} MPS2FPGAType;
> +
> +typedef struct {
> +MachineClass parent;
> +MPS2FPGAType fpga_type;
> +const char *cpu_model;
> +} MPS2MachineClass;
> +
> +typedef struct {
> +MachineState parent;
> +
> +ARMv7MState armv7m;
> +MemoryRegion psram;
> +MemoryRegion ssram1;
> +MemoryRegion ssram1_m;
> +MemoryRegion ssram23;
> +MemoryRegion ssram23_m;
> +MemoryRegion blockram;
> +MemoryRegion blockram_m1;
> +MemoryRegion blockram_m2;
> +MemoryRegion blockram_m3;
> +MemoryRegion sram;
> +} MPS2MachineState;
> +
> +#define TYPE_MPS2_MACHINE "mps2"

This public name seems too common as well. I am just worried it'll
conflict with something one day.

> +#define TYPE_MPS2_AN385_MACHINE MACHINE_TYPE_NAME("mps2-an385")
> +#define TYPE_MPS2_AN511_MACHINE MACHINE_TYPE_NAME("mps2-an511")
> +
> +#define MPS2_MACHINE(obj)   \
> +OBJECT_CHECK(MPS2MachineState, obj, TYPE_MPS2_MACHINE)
> +#define MPS2_MACHINE_GET_CLASS(obj) \
> +OBJECT_GET_CLASS(MPS2MachineClass, obj, TYPE_MPS2_MACHINE)
> +#define MPS2_MACHINE_CLASS(klass) \
> +OBJECT_CLASS_CHECK(MPS2MachineClass, klass, TYPE_MPS2_MACHINE)
> +
> +/* Main SYSCLK frequency in Hz */
> +#define SYSCLK_FRQ 2500
> +
> +/* Initialize the auxiliary RAM region @mr and map it into
> + * the memory map at @base.
> + */
> +static void make_ram(MemoryRegion *mr, const char *name,
> + hwaddr base, hwaddr size)
> +{
> +memory_region_init_ram(mr, NULL, name, size, &error_fatal);
> +vmstate_register_ram_global(mr);
> +memory_region_add_subregion(get_system_memory(), base, mr);
> +}
> +
> +/* Create an alias of an entire original MemoryRegion @orig
> + * located at @base in the memory map.
> + */
> +static void make_ram_alias(MemoryRegion *mr, const char *name,
> +   MemoryRegion *orig, hwaddr base)
> +{
> +memory_region_init_alias(mr, NULL

Re: [Qemu-devel] [PATCH 2/7] hw/char/cmsdk-apb-uart.c: Implement CMSDK APB UART

2017-07-11 Thread Alistair Francis
On Tue, Jul 11, 2017 at 1:17 PM, Peter Maydell  wrote:
> Implement a model of the simple "APB UART" provided in
> the Cortex-M System Design Kit (CMSDK).
>
> Signed-off-by: Peter Maydell 
> ---
>  hw/char/Makefile.objs|   1 +
>  include/hw/char/cmsdk-apb-uart.h |  78 
>  hw/char/cmsdk-apb-uart.c | 390 
> +++
>  default-configs/arm-softmmu.mak  |   2 +
>  hw/char/trace-events |   9 +
>  5 files changed, 480 insertions(+)
>  create mode 100644 include/hw/char/cmsdk-apb-uart.h
>  create mode 100644 hw/char/cmsdk-apb-uart.c
>
> diff --git a/hw/char/Makefile.objs b/hw/char/Makefile.objs
> index 55fcb68..1bcd37e 100644
> --- a/hw/char/Makefile.objs
> +++ b/hw/char/Makefile.objs
> @@ -19,6 +19,7 @@ obj-$(CONFIG_DIGIC) += digic-uart.o
>  obj-$(CONFIG_STM32F2XX_USART) += stm32f2xx_usart.o
>  obj-$(CONFIG_RASPI) += bcm2835_aux.o
>
> +common-obj-$(CONFIG_CMSDK_APB_UART) += cmsdk-apb-uart.o
>  common-obj-$(CONFIG_ETRAXFS) += etraxfs_ser.o
>  common-obj-$(CONFIG_ISA_DEBUG) += debugcon.o
>  common-obj-$(CONFIG_GRLIB) += grlib_apbuart.o
> diff --git a/include/hw/char/cmsdk-apb-uart.h 
> b/include/hw/char/cmsdk-apb-uart.h
> new file mode 100644
> index 000..c41fba9
> --- /dev/null
> +++ b/include/hw/char/cmsdk-apb-uart.h
> @@ -0,0 +1,78 @@
> +/*
> + * ARM CMSDK APB UART emulation
> + *
> + * Copyright (c) 2017 Linaro Limited
> + * Written by Peter Maydell
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License version 2 or
> + *  (at your option) any later version.
> + */
> +
> +#ifndef CMSDK_APB_UART_H
> +#define CMSDK_APB_UART_H
> +
> +#include "hw/sysbus.h"
> +#include "chardev/char-fe.h"
> +
> +#define TYPE_CMSDK_APB_UART "cmsdk-apb-uart"
> +#define CMSDK_APB_UART(obj) OBJECT_CHECK(CMSDKAPBUART, (obj), \
> + TYPE_CMSDK_APB_UART)
> +
> +typedef struct {
> +/*< private >*/
> +SysBusDevice parent_obj;
> +
> +/*< public >*/
> +MemoryRegion iomem;
> +CharBackend chr;
> +qemu_irq txint;
> +qemu_irq rxint;
> +qemu_irq txovrint;
> +qemu_irq rxovrint;
> +qemu_irq uartint;
> +guint watch_tag;
> +uint32_t pclk_frq;
> +
> +uint32_t state;
> +uint32_t ctrl;
> +uint32_t intstatus;
> +uint32_t bauddiv;
> +/* This UART has no FIFO, only a 1-character buffer for each of Tx and 
> Rx */
> +uint8_t txbuf;
> +uint8_t rxbuf;
> +} CMSDKAPBUART;

This should be CamelCase.

> +
> +/**
> + * cmsdk_apb_uart_create - convenience function to create TYPE_CMSDK_APB_UART
> + * @addr: location in system memory to map registers
> + * @chr: Chardev backend to connect UART to, or NULL if no backend
> + * @pclk_frq: frequency in Hz of the PCLK clock (used for calculating baud 
> rate)
> + */
> +static inline DeviceState *cmsdk_apb_uart_create(hwaddr addr,
> + qemu_irq txint,
> + qemu_irq rxint,
> + qemu_irq txovrint,
> + qemu_irq rxovrint,
> + qemu_irq uartint,
> + Chardev *chr,
> + uint32_t pclk_frq)
> +{
> +DeviceState *dev;
> +SysBusDevice *s;
> +
> +dev = qdev_create(NULL, TYPE_CMSDK_APB_UART);
> +s = SYS_BUS_DEVICE(dev);
> +qdev_prop_set_chr(dev, "chardev", chr);
> +qdev_prop_set_uint32(dev, "pclk-frq", pclk_frq);
> +qdev_init_nofail(dev);
> +sysbus_mmio_map(s, 0, addr);
> +sysbus_connect_irq(s, 0, txint);
> +sysbus_connect_irq(s, 1, rxint);
> +sysbus_connect_irq(s, 2, txovrint);
> +sysbus_connect_irq(s, 3, rxovrint);
> +sysbus_connect_irq(s, 4, uartint);
> +return dev;
> +}
> +
> +#endif
> diff --git a/hw/char/cmsdk-apb-uart.c b/hw/char/cmsdk-apb-uart.c
> new file mode 100644
> index 000..a2f55db
> --- /dev/null
> +++ b/hw/char/cmsdk-apb-uart.c
> @@ -0,0 +1,390 @@
> +/*
> + * ARM CMSDK APB UART emulation
> + *
> + * Copyright (c) 2017 Linaro Limited
> + * Written by Peter Maydell
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License version 2 or
> + *  (at your option) any later version.
> + */
> +
> +/* This is a model of the "APB UART" which is part of the Cortex-M
> + * System Design Kit (CMSDK) and documented in the Cortex-M System
> + * Design Kit Technical Reference Manual (ARM DDI0479C):
> + * 
> https://developer.arm.com/products/system-design/system-design-kits/cortex-m-system-design-kit

I can't find the spec from this site. Is it possible to link directly
to the guides? I have found a few dead links from some of these
marketing focused site.

> + */
> +
> +#include "qemu/osdep.h"
> +#i

Re: [Qemu-devel] [PATCH 2/7] hw/char/cmsdk-apb-uart.c: Implement CMSDK APB UART

2017-07-11 Thread Alistair Francis
On Tue, Jul 11, 2017 at 5:33 PM, Peter Maydell  wrote:
> On 11 July 2017 at 16:12, Alistair Francis  wrote:
>> On Tue, Jul 11, 2017 at 1:17 PM, Peter Maydell  
>> wrote:
>>> Implement a model of the simple "APB UART" provided in
>>> the Cortex-M System Design Kit (CMSDK).
>>>
>>> Signed-off-by: Peter Maydell 
>
>>> +} CMSDKAPBUART;
>>
>> This should be CamelCase.
>
> Yes, but CamelCase where all the words are all-uppercase
> (as with CMSDK, APB and UART) is indistinguishable from
> all-uppercase. (Compare the way we say "PCIIORegion" rather
> than "PciIoRegion".)

Good point, I feel like it just looks strange being all caps though.

>
>>> +/* This is a model of the "APB UART" which is part of the Cortex-M
>>> + * System Design Kit (CMSDK) and documented in the Cortex-M System
>>> + * Design Kit Technical Reference Manual (ARM DDI0479C):
>>> + * 
>>> https://developer.arm.com/products/system-design/system-design-kits/cortex-m-system-design-kit
>>
>> I can't find the spec from this site. Is it possible to link directly
>> to the guides? I have found a few dead links from some of these
>> marketing focused site.
>
> It's the link with the big blue button "Cortex-M System Design Kit
> TRM". I didn't want to link directly to the TRM, because that is
> (currently) an infocenter.arm.com URL which may eventually go
> away as content migrates to developer.arm.com. (The DDI document
> reference number is unique and sufficient to find the document
> in future even in the face of broken links.)
>
>>> +static void uart_update_parameters(CMSDKAPBUART *s)
>>> +{
>>> +QEMUSerialSetParams ssp;
>>> +
>>> +/* This UART is always 8N1 but the baud rate is programmable.
>>> + * The minimum permitted bauddiv setting is 16, so we just ignore
>>> + * settings below that (usually this means the device has just
>>> + * been reset and not yet programmed).
>>> + */
>>> +if (s->bauddiv < 16 || s->bauddiv > s->pclk_frq) {
>>> +return;
>>> +}
>>
>> This seems like it should deserve a guest error print.
>
> As the comment says, that would cause us to print a spurious
> warning every time the device was reset.

I just see this being hard to debug. What about if not printing if
baud rate is 0 but guest error otherwise?

Or can this not be called from reset?

>
>>> +static int uart_can_receive(void *opaque)
>>> +{
>>> +CMSDKAPBUART *s = CMSDK_APB_UART(opaque);
>>> +
>>> +/* We can take a char if RX is enabled and the buffer is empty */
>>> +if (s->ctrl & R_CTRL_RX_EN_MASK && !(s->state & R_STATE_RXFULL_MASK)) {
>>> +return 1;
>>> +}
>>> +return 0;
>>> +}
>>> +
>>> +static void uart_receive(void *opaque, const uint8_t *buf, int size)
>>> +{
>>> +CMSDKAPBUART *s = CMSDK_APB_UART(opaque);
>>> +
>>> +trace_cmsdk_apb_uart_receive(*buf);
>>> +
>>> +if (!(s->ctrl & R_CTRL_RX_EN_MASK)) {
>>> +/* Just drop the character on the floor */
>>> +return;
>>
>> Doesn't this also deserve a guest error print.
>
> It's a can't-happen case because uart_can_receive() won't
> return 1 if the EN bit is clear. Checking again here is
> perhaps unnecessary paranoia, but it's not a guest error.

Ah good point. Maybe that is worth stating?

Thanks,
Alistair

>
>>> +}
>>> +
>>> +if (s->state & R_STATE_RXFULL_MASK) {
>>> +s->state |= R_STATE_RXOVERRUN_MASK;
>>> +}
>>> +
>>> +s->rxbuf = *buf;
>>> +s->state |= R_STATE_RXFULL_MASK;
>>> +if (s->ctrl & R_CTRL_RX_INTEN_MASK) {
>>> +s->intstatus |= R_INTSTATUS_RX_MASK;
>>> +}
>>> +cmsdk_apb_uart_update(s);
>>> +}
>>> +
>>> +static uint64_t uart_read(void *opaque, hwaddr offset, unsigned size)
>>> +{
>>> +CMSDKAPBUART *s = CMSDK_APB_UART(opaque);
>>> +uint64_t r;
>>> +
>>> +switch (offset) {
>>> +case A_DATA:
>>> +r = s->rxbuf;
>>> +s->state &= ~R_STATE_RXFULL_MASK;
>>> +cmsdk_apb_uart_update(s);
>>> +break;
>>> +case A_STATE:
>>> +r = s->state;
>>> +break;
>>> +case A_CTRL

Re: [Qemu-devel] [PATCH for 2.10 02/35] loader: check get_image_size() return value

2017-07-24 Thread Alistair Francis
On Mon, Jul 24, 2017 at 11:38 AM, Eric Blake  wrote:
> On 07/24/2017 01:27 PM, Philippe Mathieu-Daudé wrote:
>> since a negative value means it errored.
>>
>> hw/core/loader.c:149:9: warning: Loss of sign in implicit conversion
>> if (size > max_sz) {
>> ^~~~
>> hw/core/loader.c:171:9: warning: Loss of sign in implicit conversion
>> if (size > memory_region_size(mr)) {
>> ^~~~
>>
>> Reported-by: Clang Static Analyzer
>> Signed-off-by: Philippe Mathieu-Daudé 
>> ---
>>  hw/core/loader.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> Reviewed-by: Eric Blake 

Reviewed-by: Alistair Francis 

Thanks,
Alistair

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



Re: [Qemu-devel] Slow tests on "make check" (was Re: [PULL 6/9] Convert error_report() to warn_report())

2017-07-25 Thread Alistair Francis
On Tue, Jul 25, 2017 at 12:08 PM, Eduardo Habkost  wrote:
> On Mon, Jul 24, 2017 at 09:30:06AM +0200, Paolo Bonzini wrote:
>> On 24/07/2017 08:30, Markus Armbruster wrote:
>> > Markus Armbruster  writes:
>> >
>> >> Kevin Wolf  writes:
>> >>
>> >>> Am 13.07.2017 um 15:27 hat Markus Armbruster geschrieben:
>> >>>> From: Alistair Francis 
>> >>>>
>> >>>> Convert all uses of error_report("warning:"... to use warn_report()
>> >>>> instead. This helps standardise on a single method of printing warnings
>> >>>> to the user.
>> >>>>
>> >>>> All of the warnings were changed using these two commands:
>> >>>> find ./* -type f -exec sed -i \
>> >>>>   's|error_report(".*warning[,:] |warn_report("|Ig' {} +
>> >>>>
>> >>>> Indentation fixed up manually afterwards.
>> >>>>
>> >>>> The test-qdev-global-props test case was manually updated to ensure that
>> >>>> this patch passes make check (as the test cases are case sensitive).
>> >>>
>> >>> This patch broke qemu-iotests 051 because it neglected to update the
>> >>> reference output. Not sure if a change of the message was even intended,
>> >>> but with a error location prefix, the order changes:
>> >>>
>> >>> -(qemu) QEMU_PROG: -drive if=scsi,media=cdrom: warning: bus=0,unit=0 is 
>> >>> deprecated with this machine type
>> >>> +(qemu) warning: qemu-system-x86_64: -drive if=scsi,media=cdrom: 
>> >>> bus=0,unit=0 is deprecated with this machine type
>> >>>
>> >>> Personally, I would expect the error location or at least the program
>> >>> name to come first even for warnings.
>> >>
>> >> I'll fix it.
>> >>
>> >> While focusing on something other than block, I forget qemu-iotests
>> >> exist.  My fault, but it's a pretty common fault.  I reiterate my plea
>> >> to include (a sensible subset of) it in "make check".
>> >
>> > Oh, 051 isn't run by "make check-block".  It could just as well not
>> > exist then.
>> >
>> > What's the recommended way to run all iotests a build of QEMU can run?
>>
>> I use "path-to-srcdir/tests/check-block.sh".  It takes about 20 minutes.
>>
>> There are two issues with check-block:
>>
>> * tests that require QEMU are skipped (rationale: you might be building
>> without the x86_64-softmmu target).
>>
>> * it only runs the "quick" group, but I think we should reverse the
>> direction and mark slow tests specifically (that would cut about 10
>> minutes out of the 20).
>
> About slow tests: I never included device-crash-test on "make
> check" because it would take too long to run.  Also, "make
> check-help" lies when it says "make check" runs all tests,
> because it doesn't run check-block.
>
> Should we add a new Makefile target (check-all?) that includes
> slower tests?

Or a make check-slow?

I think that is a great idea, having tests but not running them isn't
helping anyone.

Thanks,
Alistair

>
> --
> Eduardo
>



Re: [Qemu-devel] Slow tests on "make check" (was Re: [PULL 6/9] Convert error_report() to warn_report())

2017-07-25 Thread Alistair Francis
On Tue, Jul 25, 2017 at 4:24 PM, Alistair Francis
 wrote:
> On Tue, Jul 25, 2017 at 12:08 PM, Eduardo Habkost  wrote:
>> On Mon, Jul 24, 2017 at 09:30:06AM +0200, Paolo Bonzini wrote:
>>> On 24/07/2017 08:30, Markus Armbruster wrote:
>>> > Markus Armbruster  writes:
>>> >
>>> >> Kevin Wolf  writes:
>>> >>
>>> >>> Am 13.07.2017 um 15:27 hat Markus Armbruster geschrieben:
>>> >>>> From: Alistair Francis 
>>> >>>>
>>> >>>> Convert all uses of error_report("warning:"... to use warn_report()
>>> >>>> instead. This helps standardise on a single method of printing warnings
>>> >>>> to the user.
>>> >>>>
>>> >>>> All of the warnings were changed using these two commands:
>>> >>>> find ./* -type f -exec sed -i \
>>> >>>>   's|error_report(".*warning[,:] |warn_report("|Ig' {} +
>>> >>>>
>>> >>>> Indentation fixed up manually afterwards.
>>> >>>>
>>> >>>> The test-qdev-global-props test case was manually updated to ensure 
>>> >>>> that
>>> >>>> this patch passes make check (as the test cases are case sensitive).
>>> >>>
>>> >>> This patch broke qemu-iotests 051 because it neglected to update the
>>> >>> reference output. Not sure if a change of the message was even intended,
>>> >>> but with a error location prefix, the order changes:
>>> >>>
>>> >>> -(qemu) QEMU_PROG: -drive if=scsi,media=cdrom: warning: bus=0,unit=0 is 
>>> >>> deprecated with this machine type
>>> >>> +(qemu) warning: qemu-system-x86_64: -drive if=scsi,media=cdrom: 
>>> >>> bus=0,unit=0 is deprecated with this machine type
>>> >>>
>>> >>> Personally, I would expect the error location or at least the program
>>> >>> name to come first even for warnings.
>>> >>
>>> >> I'll fix it.
>>> >>
>>> >> While focusing on something other than block, I forget qemu-iotests
>>> >> exist.  My fault, but it's a pretty common fault.  I reiterate my plea
>>> >> to include (a sensible subset of) it in "make check".
>>> >
>>> > Oh, 051 isn't run by "make check-block".  It could just as well not
>>> > exist then.
>>> >
>>> > What's the recommended way to run all iotests a build of QEMU can run?
>>>
>>> I use "path-to-srcdir/tests/check-block.sh".  It takes about 20 minutes.
>>>
>>> There are two issues with check-block:
>>>
>>> * tests that require QEMU are skipped (rationale: you might be building
>>> without the x86_64-softmmu target).
>>>
>>> * it only runs the "quick" group, but I think we should reverse the
>>> direction and mark slow tests specifically (that would cut about 10
>>> minutes out of the 20).
>>
>> About slow tests: I never included device-crash-test on "make
>> check" because it would take too long to run.  Also, "make
>> check-help" lies when it says "make check" runs all tests,
>> because it doesn't run check-block.
>>
>> Should we add a new Makefile target (check-all?) that includes
>> slower tests?
>
> Or a make check-slow?

Actually, what about to avoid duplication we can add a make check-slow
that runs all the slow tests that make check doesn't run. Then make
check-all can run both make check and make check-slow.

That way you can run make check for a quick sanity test and then run
make check-slow to test everything, without duplicating tests.

>
> I think that is a great idea, having tests but not running them isn't
> helping anyone.
>
> Thanks,
> Alistair
>
>>
>> --
>> Eduardo
>>



[Qemu-devel] [PATCH v1 1/5] hw/i386: Improve some of the warning messages

2017-07-26 Thread Alistair Francis
Signed-off-by: Alistair Francis 
Suggested-by: Eduardo Habkost 
Cc: Eduardo Habkost 
---
V3:
 - Improve the messages

 hw/i386/acpi-build.c | 15 ++-
 hw/i386/pc.c |  7 +++
 hw/i386/pc_q35.c |  8 +---
 3 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 6b7bade183..7130c7409d 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -2766,17 +2766,22 @@ void acpi_build(AcpiBuildTables *tables, MachineState 
*machine)
  ACPI_BUILD_ALIGN_SIZE);
 if (tables_blob->len > legacy_table_size) {
 /* Should happen only with PCI bridges and -M pc-i440fx-2.0.  */
-warn_report("migration may not work.");
+warn_report("ACPI table size %u exceeds %d bytes,"
+" migration may not work",
+tables_blob->len, legacy_table_size);
+error_printf("Try removing CPUs, NUMA nodes, memory slots"
+ " or PCI bridges.");
 }
 g_array_set_size(tables_blob, legacy_table_size);
 } else {
 /* Make sure we have a buffer in case we need to resize the tables. */
 if (tables_blob->len > ACPI_BUILD_TABLE_SIZE / 2) {
 /* As of QEMU 2.1, this fires with 160 VCPUs and 255 memory slots. 
 */
-warn_report("ACPI tables are larger than 64k.");
-warn_report("migration may not work.");
-warn_report("please remove CPUs, NUMA nodes, "
-"memory slots or PCI bridges.");
+warn_report("ACPI table size %u exceeds %d bytes,"
+" migration may not work",
+tables_blob->len, ACPI_BUILD_TABLE_SIZE / 2);
+error_printf("Try removing CPUs, NUMA nodes, memory slots"
+ " or PCI bridges.");
 }
 acpi_align_size(tables_blob, ACPI_BUILD_TABLE_SIZE);
 }
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 22e16031b0..a67440f2a1 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -384,7 +384,7 @@ ISADevice *pc_find_fdc0(void)
 warn_report("multiple floppy disk controllers with "
 "iobase=0x3f0 have been found");
 error_printf("the one being picked for CMOS setup might not reflect "
- "your intent\n");
+ "your intent");
 }
 
 return state.floppy;
@@ -2085,9 +2085,8 @@ static void pc_machine_set_max_ram_below_4g(Object *obj, 
Visitor *v,
 }
 
 if (value < (1ULL << 20)) {
-warn_report("small max_ram_below_4g(%"PRIu64
-") less than 1M.  BIOS may not work..",
-value);
+warn_report("Only %" PRIu64 " bytes of RAM below the 4GiB boundary,"
+"BIOS may not work with less than 1MiB", value);
 }
 
 pcms->max_ram_below_4g = value;
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 169a214d50..435eb2c458 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -101,9 +101,11 @@ static void pc_q35_init(MachineState *machine)
 lowmem = pcms->max_ram_below_4g;
 if (machine->ram_size - lowmem > lowmem &&
 lowmem & ((1ULL << 30) - 1)) {
-warn_report("Large machine and max_ram_below_4g(%"PRIu64
-") not a multiple of 1G; possible bad performance.",
-pcms->max_ram_below_4g);
+warn_report("Large machine as the ram size (0x%" PRIx64 ") is more"
+" then twice the size of the internal limit"
+" (0x%" PRIx64 ") and max-ram-below-4g (%"PRIu64")"
+" note a multiple of 1G; possible bad performance.",
+machine->ram_size, lowmem, pcms->max_ram_below_4g);
 }
 }
 
-- 
2.11.0




[Qemu-devel] [PATCH v1 2/5] Convert remaining error_report() to warn_report()

2017-07-26 Thread Alistair Francis
In a previous patch (3dc6f8693694a649a9c83f1e2746565b47683923) we
converted uses of error_report("warning:"... to use warn_report()
instead. This was to help standardise on a single method of printing
warnings to the user.

There appears to have been some cases that slipped through in patch sets
applied around the same time, this patch catches the few remaining
cases.

All of the warnings were changed using this command:
  find ./* -type f -exec sed -i \
's|error_report(".*warning[,:] |warn_report("|Ig' {} +

Indentation fixed up manually afterwards.

Signed-off-by: Alistair Francis 
Cc: Kevin Wolf 
Cc: Max Reitz 
Cc: Christian Borntraeger 
Cc: Cornelia Huck 
Cc: Alexander Graf 
Cc: Richard Henderson 
Cc: Stefan Hajnoczi 
---

 block/qcow2.c  | 10 +-
 target/s390x/kvm.c |  4 ++--
 trace/control.c|  4 ++--
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index 90efa4477b..e6c6be0822 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -302,11 +302,11 @@ static int qcow2_read_extensions(BlockDriverState *bs, 
uint64_t start_offset,
 }
 
 if (!(s->autoclear_features & QCOW2_AUTOCLEAR_BITMAPS)) {
-error_report("WARNING: a program lacking bitmap support "
- "modified this file, so all bitmaps are now "
- "considered inconsistent. Some clusters may be "
- "leaked, run 'qemu-img check -r' on the image "
- "file to fix.");
+warn_report("a program lacking bitmap support "
+"modified this file, so all bitmaps are now "
+"considered inconsistent. Some clusters may be "
+"leaked, run 'qemu-img check -r' on the image "
+"file to fix.");
 if (need_update_header != NULL) {
 /* Updating is needed to drop invalid bitmap extension. */
 *need_update_header = true;
diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
index c4c5791d27..1084923adb 100644
--- a/target/s390x/kvm.c
+++ b/target/s390x/kvm.c
@@ -222,8 +222,8 @@ static void kvm_s390_enable_cmma(void)
 };
 
 if (mem_path) {
-error_report("Warning: CMM will not be enabled because it is not "
- "compatible to hugetlbfs.");
+warn_report("CMM will not be enabled because it is not "
+"compatible to hugetlbfs.");
 return;
 }
 rc = kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
diff --git a/trace/control.c b/trace/control.c
index 82d8989c4d..2769934bec 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -72,8 +72,8 @@ void trace_event_register_group(TraceEvent **events)
 if (likely(next_vcpu_id < CPU_TRACE_DSTATE_MAX_EVENTS)) {
 events[i]->vcpu_id = next_vcpu_id++;
 } else {
-error_report("WARNING: too many vcpu trace events; dropping '%s'",
- events[i]->name);
+warn_report("too many vcpu trace events; dropping '%s'",
+events[i]->name);
 }
 }
 event_groups = g_renew(TraceEventGroup, event_groups, nevent_groups + 1);
-- 
2.11.0




[Qemu-devel] [PATCH v1 0/5] More warning reporting fixed

2017-07-26 Thread Alistair Francis
This series expands on my previous series by converting more existing
prints to use warn_report() instead of error_report() or fprintf().

Alistair Francis (5):
  hw/i386: Improve some of the warning messages
  Convert remaining error_report() to warn_report()
  Convert single line fprintf() to warn_report()
  Convert multi-line fprintf() to warn_report()
  Convert single line fprintf() to warn_report()

 accel/kvm/kvm-all.c |  7 +++
 block/qcow2.c   | 10 +-
 block/vvfat.c   |  8 +---
 hw/acpi/core.c  | 10 +-
 hw/arm/vexpress.c   |  4 ++--
 hw/i386/acpi-build.c| 15 ++-
 hw/i386/pc.c|  9 -
 hw/i386/pc_q35.c|  8 +---
 hw/i386/xen/xen-mapcache.c  |  4 ++--
 hw/mips/mips_malta.c|  4 ++--
 hw/mips/mips_r4k.c  |  7 ---
 hw/misc/applesmc.c  |  2 +-
 hw/s390x/s390-virtio.c  | 16 
 hw/usb/hcd-ehci.c   |  5 +++--
 hw/virtio/virtio-balloon.c  |  3 ++-
 net/hub.c   | 12 ++--
 net/net.c   | 14 +++---
 net/socket.c|  7 +--
 qga/vss-win32.c |  2 +-
 target/i386/cpu.c   | 12 ++--
 target/i386/hax-mem.c   |  6 +++---
 target/mips/kvm.c   |  4 ++--
 target/ppc/translate_init.c | 18 +-
 target/s390x/kvm.c  |  4 ++--
 tests/Makefile.include  |  4 ++--
 trace/control.c |  4 ++--
 trace/simple.c  |  2 +-
 ui/keymaps.c| 11 ++-
 ui/spice-display.c  |  2 +-
 util/cutils.c   |  3 ++-
 util/main-loop.c|  6 +++---
 31 files changed, 119 insertions(+), 104 deletions(-)

-- 
2.11.0




[Qemu-devel] [PATCH v1 4/5] Convert multi-line fprintf() to warn_report()

2017-07-26 Thread Alistair Francis
Convert all the multi-line uses of fprintf(stderr, "warning:"..."\n"...
to use warn_report() instead. This helps standardise on a single
method of printing warnings to the user.

All of the warnings were changed using these commands:
  find ./* -type f -exec sed -i \
'N; {s|fprintf(.*".*warning[,:] 
\(.*\)\\n"\(.*\));|warn_report("\1"\2);|Ig}' \
{} +
  find ./* -type f -exec sed -i \
'N;N; {s|fprintf(.*".*warning[,:] 
\(.*\)\\n"\(.*\));|warn_report("\1"\2);|Ig}' \
{} +
  find ./* -type f -exec sed -i \
'N;N;N; {s|fprintf(.*".*warning[,:] 
\(.*\)\\n"\(.*\));|warn_report("\1"\2);|Ig}' \
{} +
  find ./* -type f -exec sed -i \
'N;N;N;N {s|fprintf(.*".*warning[,:] 
\(.*\)\\n"\(.*\));|warn_report("\1"\2);|Ig}' \
{} +
  find ./* -type f -exec sed -i \
'N;N;N;N;N {s|fprintf(.*".*warning[,:] 
\(.*\)\\n"\(.*\));|warn_report("\1"\2);|Ig}' \
{} +
  find ./* -type f -exec sed -i \
'N;N;N;N;N;N {s|fprintf(.*".*warning[,:] 
\(.*\)\\n"\(.*\));|warn_report("\1"\2);|Ig}' \
{} +
  find ./* -type f -exec sed -i \
'N;N;N;N;N;N;N; {s|fprintf(.*".*warning[,:] 
\(.*\)\\n"\(.*\));|warn_report("\1"\2);|Ig}' \
{} +

Indentation fixed up manually afterwards.

Some of the lines were manually edited to reduce the line length to below
80 charecters. Some of the lines with newlines in the middle of the
string were also manually edit to avoid checkpatch errrors.

The #include lines were manually updated to allow the code to compile.

Signed-off-by: Alistair Francis 
Cc: Paolo Bonzini 
Cc: Kevin Wolf 
Cc: Max Reitz 
Cc: "Michael S. Tsirkin" 
Cc: Igor Mammedov 
Cc: Peter Maydell 
Cc: Stefano Stabellini 
Cc: Anthony Perard 
Cc: Richard Henderson 
Cc: Eduardo Habkost 
Cc: Aurelien Jarno 
Cc: Yongbok Kim 
Cc: Cornelia Huck 
Cc: Christian Borntraeger 
Cc: Alexander Graf 
Cc: Jason Wang 
Cc: David Gibson 
Cc: Gerd Hoffmann 
---
I couldn't figure out any nice way (it is possible with some more logic
inside the sed apparently) to do this is one command, so I had to use
all of the commands above.

 accel/kvm/kvm-all.c |  7 +++
 block/vvfat.c   |  4 ++--
 hw/acpi/core.c  |  7 +++
 hw/arm/vexpress.c   |  4 ++--
 hw/i386/xen/xen-mapcache.c  |  4 ++--
 hw/mips/mips_malta.c|  4 ++--
 hw/mips/mips_r4k.c  |  7 ---
 hw/s390x/s390-virtio.c  | 16 
 net/hub.c   |  9 -
 net/net.c   | 14 +++---
 target/i386/cpu.c   | 12 ++--
 target/i386/hax-mem.c   |  6 +++---
 target/ppc/translate_init.c | 18 +-
 ui/keymaps.c|  9 +
 util/main-loop.c|  6 +++---
 15 files changed, 63 insertions(+), 64 deletions(-)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 46ce479dc3..03e26e5a07 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -1629,10 +1629,9 @@ static int kvm_init(MachineState *ms)
 
 while (nc->name) {
 if (nc->num > soft_vcpus_limit) {
-fprintf(stderr,
-"Warning: Number of %s cpus requested (%d) exceeds "
-"the recommended cpus supported by KVM (%d)\n",
-nc->name, nc->num, soft_vcpus_limit);
+warn_report("Number of %s cpus requested (%d) exceeds "
+"the recommended cpus supported by KVM (%d)",
+nc->name, nc->num, soft_vcpus_limit);
 
 if (nc->num > hard_vcpus_limit) {
 fprintf(stderr, "Number of %s cpus requested (%d) exceeds "
diff --git a/block/vvfat.c b/block/vvfat.c
index d682f0a9dc..04801f3136 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -1227,8 +1227,8 @@ static int vvfat_open(BlockDriverState *bs, QDict 
*options, int flags,
 
 switch (s->fat_type) {
 case 32:
-fprintf(stderr, "Big fat greek warning: FAT32 has not been tested. 
"
-"You are welcome to do so!\n");
+warn_report("FAT32 has not been tested. "
+"You are welcome to do so!");
 break;
 case 16:
 case 12:
diff --git a/hw/acpi/core.c b/hw/acpi/core.c
index 2a1b79c838..cd0a1d357b 100644
--- a/hw/acpi/core.c
+++ b/hw/acpi/core.c
@@ -184,10 +184,9 @@ static void acpi_table_install(const char unsigned *blob, 
size_t bloblen,
 }
 
 if (has_header && le32_to_cpu(ext_hdr->length) != acpi_payload_size) {
-fprintf(stderr,
-"warning: ACPI table has wrong length, header says "
-"%" PRIu32 ", actual size %zu bytes\n",
-  

[Qemu-devel] [PATCH v1 3/5] Convert single line fprintf() to warn_report()

2017-07-26 Thread Alistair Francis
Convert all the single line uses of fprintf(stderr, "warning:"..."\n"...
to use warn_report() instead. This helps standardise on a single
method of printing warnings to the user.

All of the warnings were changed using this command:
  find ./* -type f -exec sed -i \
's|fprintf(.*".*warning[,:] \(.*\)\\n"\(.*\));|warn_report("\1"\2);|Ig' \
{} +

Some of the lines were manually edited to reduce the line length to below
80 charecters.

The #include lines were manually updated to allow the code to compile.

Signed-off-by: Alistair Francis 
Cc: Kevin Wolf 
Cc: Max Reitz 
Cc: "Michael S. Tsirkin" 
Cc: Igor Mammedov 
Cc: Paolo Bonzini 
Cc: Richard Henderson 
Cc: Eduardo Habkost 
Cc: Gerd Hoffmann 
Cc: Jason Wang 
Cc: Michael Roth 
Cc: James Hogan 
Cc: Aurelien Jarno 
Cc: Yongbok Kim 
Cc: Stefan Hajnoczi 
---

 block/vvfat.c  | 4 +++-
 hw/acpi/core.c | 3 ++-
 hw/i386/pc.c   | 2 +-
 hw/misc/applesmc.c | 2 +-
 hw/usb/hcd-ehci.c  | 5 +++--
 hw/virtio/virtio-balloon.c | 3 ++-
 net/hub.c  | 3 ++-
 net/socket.c   | 7 +--
 qga/vss-win32.c| 2 +-
 target/mips/kvm.c  | 4 ++--
 trace/simple.c | 2 +-
 ui/keymaps.c   | 2 +-
 ui/spice-display.c | 2 +-
 13 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/block/vvfat.c b/block/vvfat.c
index a9e207f7f0..d682f0a9dc 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -32,6 +32,7 @@
 #include "qapi/qmp/qbool.h"
 #include "qapi/qmp/qstring.h"
 #include "qemu/cutils.h"
+#include "qemu/error-report.h"
 
 #ifndef S_IWGRP
 #define S_IWGRP 0
@@ -3028,7 +3029,8 @@ DLOG(checkpoint());
 if (memcmp(direntries + k,
 array_get(&(s->directory), dir_index + k),
 sizeof(direntry_t))) {
-fprintf(stderr, "Warning: tried to write to 
write-protected file\n");
+warn_report("tried to write to write-protected "
+"file");
 return -1;
 }
 }
diff --git a/hw/acpi/core.c b/hw/acpi/core.c
index 95fcac95a2..2a1b79c838 100644
--- a/hw/acpi/core.c
+++ b/hw/acpi/core.c
@@ -28,6 +28,7 @@
 #include "qapi/opts-visitor.h"
 #include "qapi-visit.h"
 #include "qapi-event.h"
+#include "qemu/error-report.h"
 
 struct acpi_table_header {
 uint16_t _length; /* our length, not actual part of the hdr */
@@ -221,7 +222,7 @@ static void acpi_table_install(const char unsigned *blob, 
size_t bloblen,
 }
 
 if (!has_header && changed_fields == 0) {
-fprintf(stderr, "warning: ACPI table: no headers are specified\n");
+warn_report("ACPI table: no headers are specified");
 }
 
 /* recalculate checksum */
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index a67440f2a1..2f4ba4cd4f 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1310,7 +1310,7 @@ void pc_acpi_init(const char *default_dsdt)
 
 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, default_dsdt);
 if (filename == NULL) {
-fprintf(stderr, "WARNING: failed to find %s\n", default_dsdt);
+warn_report("failed to find %s", default_dsdt);
 } else {
 QemuOpts *opts = qemu_opts_create(qemu_find_opts("acpi"), NULL, 0,
   &error_abort);
diff --git a/hw/misc/applesmc.c b/hw/misc/applesmc.c
index 7896812304..7be8b5f13c 100644
--- a/hw/misc/applesmc.c
+++ b/hw/misc/applesmc.c
@@ -331,7 +331,7 @@ static void applesmc_isa_realize(DeviceState *dev, Error 
**errp)
 s->iobase + APPLESMC_ERR_PORT);
 
 if (!s->osk || (strlen(s->osk) != 64)) {
-fprintf(stderr, "WARNING: Using AppleSMC with invalid key\n");
+warn_report("Using AppleSMC with invalid key");
 s->osk = default_osk;
 }
 
diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 604912cb3e..46fd30b075 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -32,6 +32,7 @@
 #include "hw/usb/ehci-regs.h"
 #include "hw/usb/hcd-ehci.h"
 #include "trace.h"
+#include "qemu/error-report.h"
 
 #define FRAME_TIMER_FREQ 1000
 #define FRAME_TIMER_NS   (NANOSECONDS_PER_SECOND / FRAME_TIMER_FREQ)
@@ -348,7 +349,7 @@ static void ehci_trace_sitd(EHCIState *s, hwaddr addr,
 static void ehci_trace_guest_bug(EHCIState *s, const char *message)
 {
 trace_usb_ehci_guest_bug(message);
-fprintf(stderr, "ehci warning: %s\n", message);
+warn_report("%s", message);
 }
 
 static inline bool ehci_enabled(EHCIState *s)
@@ -1728,7 +1729,7 @@ sta

[Qemu-devel] [PATCH v1 5/5] Convert single line fprintf() to warn_report()

2017-07-26 Thread Alistair Francis
Convert any remaining uses of fprintf(stderr, "warning:"...
to use warn_report() instead. This helps standardise on a single
method of printing warnings to the user.

All of the warnings were changed using this command:
  find ./* -type f -exec sed -i 's|fprintf(.*".*warning[,:] |warn_report("|Ig' 
{} +

The #include lines and chagnes to the test Makefile were manually
updated to allow the code to compile.

Signed-off-by: Alistair Francis 
---

 tests/Makefile.include | 4 ++--
 util/cutils.c  | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 7af278db55..4886caf565 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -560,8 +560,8 @@ tests/test-thread-pool$(EXESUF): tests/test-thread-pool.o 
$(test-block-obj-y)
 tests/test-iov$(EXESUF): tests/test-iov.o $(test-util-obj-y)
 tests/test-hbitmap$(EXESUF): tests/test-hbitmap.o $(test-util-obj-y) 
$(test-crypto-obj-y)
 tests/test-x86-cpuid$(EXESUF): tests/test-x86-cpuid.o
-tests/test-xbzrle$(EXESUF): tests/test-xbzrle.o migration/xbzrle.o 
migration/page_cache.o $(test-util-obj-y)
-tests/test-cutils$(EXESUF): tests/test-cutils.o util/cutils.o
+tests/test-xbzrle$(EXESUF): tests/test-xbzrle.o migration/xbzrle.o 
migration/page_cache.o $(test-qom-obj-y)
+tests/test-cutils$(EXESUF): tests/test-cutils.o util/cutils.o $(test-qom-obj-y)
 tests/test-int128$(EXESUF): tests/test-int128.o
 tests/rcutorture$(EXESUF): tests/rcutorture.o $(test-util-obj-y)
 tests/test-rcu-list$(EXESUF): tests/test-rcu-list.o $(test-util-obj-y)
diff --git a/util/cutils.c b/util/cutils.c
index 1534682083..b33ede83d1 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -30,6 +30,7 @@
 #include "qemu/iov.h"
 #include "net/net.h"
 #include "qemu/cutils.h"
+#include "qemu/error-report.h"
 
 void strpadcpy(char *buf, int buf_size, const char *str, char pad)
 {
@@ -601,7 +602,7 @@ int parse_debug_env(const char *name, int max, int initial)
 return initial;
 }
 if (debug < 0 || debug > max || errno != 0) {
-fprintf(stderr, "warning: %s not in [0, %d]", name, max);
+warn_report("%s not in [0, %d]", name, max);
 return initial;
 }
 return debug;
-- 
2.11.0




Re: [Qemu-devel] [PATCH v1 5/5] Convert single line fprintf() to warn_report()

2017-07-26 Thread Alistair Francis
On Wed, Jul 26, 2017 at 9:28 AM, Daniel P. Berrange  wrote:
> On Wed, Jul 26, 2017 at 09:07:59AM -0700, Alistair Francis wrote:
>> Convert any remaining uses of fprintf(stderr, "warning:"...
>> to use warn_report() instead. This helps standardise on a single
>> method of printing warnings to the user.
>>
>> All of the warnings were changed using this command:
>>   find ./* -type f -exec sed -i 's|fprintf(.*".*warning[,:] 
>> |warn_report("|Ig' {} +
>>
>> The #include lines and chagnes to the test Makefile were manually
>> updated to allow the code to compile.
>>
>> Signed-off-by: Alistair Francis 
>> ---
>>
>>  tests/Makefile.include | 4 ++--
>>  util/cutils.c  | 3 ++-
>>  2 files changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/tests/Makefile.include b/tests/Makefile.include
>> index 7af278db55..4886caf565 100644
>> --- a/tests/Makefile.include
>> +++ b/tests/Makefile.include
>> @@ -560,8 +560,8 @@ tests/test-thread-pool$(EXESUF): 
>> tests/test-thread-pool.o $(test-block-obj-y)
>>  tests/test-iov$(EXESUF): tests/test-iov.o $(test-util-obj-y)
>>  tests/test-hbitmap$(EXESUF): tests/test-hbitmap.o $(test-util-obj-y) 
>> $(test-crypto-obj-y)
>>  tests/test-x86-cpuid$(EXESUF): tests/test-x86-cpuid.o
>> -tests/test-xbzrle$(EXESUF): tests/test-xbzrle.o migration/xbzrle.o 
>> migration/page_cache.o $(test-util-obj-y)
>> -tests/test-cutils$(EXESUF): tests/test-cutils.o util/cutils.o
>> +tests/test-xbzrle$(EXESUF): tests/test-xbzrle.o migration/xbzrle.o 
>> migration/page_cache.o $(test-qom-obj-y)
>> +tests/test-cutils$(EXESUF): tests/test-cutils.o util/cutils.o 
>> $(test-qom-obj-y)
>
> This doesn't look right to me - $(test-qom-obj-y) is the same as
> $(test-util-obj-y), but with $(qom-obj-y) added.  AFAIK, your
> warn_report function doesn't use any code from $(qom-obj-y), so
> we should not need to link to that. So I think there's something
> else going on here.

The problem I was seeing is that monitor_get_fd() is getting called in
stubs/monitor.c which then requires error_setg_internal() to be linked
in. Apparently this doesn't happen without this change as I kept
seeing linker errors.

Thanks,
Alistair

>
>> diff --git a/util/cutils.c b/util/cutils.c
>> index 1534682083..b33ede83d1 100644
>> --- a/util/cutils.c
>> +++ b/util/cutils.c
>> @@ -30,6 +30,7 @@
>>  #include "qemu/iov.h"
>>  #include "net/net.h"
>>  #include "qemu/cutils.h"
>> +#include "qemu/error-report.h"
>>
>>  void strpadcpy(char *buf, int buf_size, const char *str, char pad)
>>  {
>> @@ -601,7 +602,7 @@ int parse_debug_env(const char *name, int max, int 
>> initial)
>>  return initial;
>>  }
>>  if (debug < 0 || debug > max || errno != 0) {
>> -fprintf(stderr, "warning: %s not in [0, %d]", name, max);
>> +warn_report("%s not in [0, %d]", name, max);
>>  return initial;
>>  }
>>  return debug;
>> --
>> 2.11.0
>>
>>
>
> Regards,
> Daniel
> --
> |: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org -o-https://fstop138.berrange.com :|
> |: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|



Re: [Qemu-devel] [PATCH v1 5/5] Convert single line fprintf() to warn_report()

2017-07-26 Thread Alistair Francis
On Wed, Jul 26, 2017 at 9:36 AM, Daniel P. Berrange  wrote:
> On Wed, Jul 26, 2017 at 09:33:56AM -0700, Alistair Francis wrote:
>> On Wed, Jul 26, 2017 at 9:28 AM, Daniel P. Berrange  
>> wrote:
>> > On Wed, Jul 26, 2017 at 09:07:59AM -0700, Alistair Francis wrote:
>> >> Convert any remaining uses of fprintf(stderr, "warning:"...
>> >> to use warn_report() instead. This helps standardise on a single
>> >> method of printing warnings to the user.
>> >>
>> >> All of the warnings were changed using this command:
>> >>   find ./* -type f -exec sed -i 's|fprintf(.*".*warning[,:] 
>> >> |warn_report("|Ig' {} +
>> >>
>> >> The #include lines and chagnes to the test Makefile were manually
>> >> updated to allow the code to compile.
>> >>
>> >> Signed-off-by: Alistair Francis 
>> >> ---
>> >>
>> >>  tests/Makefile.include | 4 ++--
>> >>  util/cutils.c  | 3 ++-
>> >>  2 files changed, 4 insertions(+), 3 deletions(-)
>> >>
>> >> diff --git a/tests/Makefile.include b/tests/Makefile.include
>> >> index 7af278db55..4886caf565 100644
>> >> --- a/tests/Makefile.include
>> >> +++ b/tests/Makefile.include
>> >> @@ -560,8 +560,8 @@ tests/test-thread-pool$(EXESUF): 
>> >> tests/test-thread-pool.o $(test-block-obj-y)
>> >>  tests/test-iov$(EXESUF): tests/test-iov.o $(test-util-obj-y)
>> >>  tests/test-hbitmap$(EXESUF): tests/test-hbitmap.o $(test-util-obj-y) 
>> >> $(test-crypto-obj-y)
>> >>  tests/test-x86-cpuid$(EXESUF): tests/test-x86-cpuid.o
>> >> -tests/test-xbzrle$(EXESUF): tests/test-xbzrle.o migration/xbzrle.o 
>> >> migration/page_cache.o $(test-util-obj-y)
>> >> -tests/test-cutils$(EXESUF): tests/test-cutils.o util/cutils.o
>> >> +tests/test-xbzrle$(EXESUF): tests/test-xbzrle.o migration/xbzrle.o 
>> >> migration/page_cache.o $(test-qom-obj-y)
>> >> +tests/test-cutils$(EXESUF): tests/test-cutils.o util/cutils.o 
>> >> $(test-qom-obj-y)
>> >
>> > This doesn't look right to me - $(test-qom-obj-y) is the same as
>> > $(test-util-obj-y), but with $(qom-obj-y) added.  AFAIK, your
>> > warn_report function doesn't use any code from $(qom-obj-y), so
>> > we should not need to link to that. So I think there's something
>> > else going on here.
>>
>> The problem I was seeing is that monitor_get_fd() is getting called in
>> stubs/monitor.c which then requires error_setg_internal() to be linked
>> in. Apparently this doesn't happen without this change as I kept
>> seeing linker errors.
>
> That's bizarre because  error_setg_internal is included in libqemuutil.la
> that we're already linking to.

That's what I thought too, but this is the only solution I could find.
I'm open to suggestions, I'm not too familiar with all these linker
scripts.

Thanks,
Alistair

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



  1   2   3   4   5   6   7   8   9   10   >