[Qemu-devel] [Bug 639651] Re: DRIVER_IRQL_NOT_LESS_OR_EQUAL booting WIndows XP with Synaptics driver installed

2019-04-17 Thread Thomas Huth
** Changed in: qemu (Debian)
   Status: New => Incomplete

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

Title:
  DRIVER_IRQL_NOT_LESS_OR_EQUAL booting WIndows XP with Synaptics driver
  installed

Status in QEMU:
  Incomplete
Status in qemu package in Debian:
  Incomplete

Bug description:
  Positng the issue here since I did not get any reply on the ML.

  I was trying to update some windows XP (SP3) images in kvm.

  It worked fine several times but last time I added mass storage
  drivers to sysprep and now on the second boot after reseal (the first
  is mini-setup) I get a BSOD with message
  DRIVER_IRQL_NOT_LESS_OR_EQUAL. 

  It turns out that the error is unrelated to storage drivers. It is
  triggered by Synaptics driver installing for the PS2 mouse in kvm
  (which does not happen in VirtualBox or on real hardware).

  The image is originally created on hardware with MP acpi (not
  virtualization).

  qemu-kvm  0.12.5+dfsg-2

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



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

2019-04-17 Thread Joachim Durchholz

Am 17.04.19 um 20:27 schrieb Laszlo Ersek:

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


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



what's the reasoning behind "We need a terminal output" in curses.c?


The reasoning is that "curses.c" is a QEMU display backend written in
terms of the Curses [XCURSES] interface specification, and that
interface specification is inherently based on terminals, as defined by
the General Terminal Interface of the Single Unix Specification.


Sure.


If you tell us what you want to achieve in the end (i.e. you state the
problem),


I described three use cases. I mentioned which of them was mine.
Problem statement: my use case doesn't work. D'oh.


Let me speculate a bit. You mentioned wanting to connect "ui/curses.c"
to a pipe, possibly to transfer the output elsewhere. This is a common
use case -- it's what terminal emulators such as "xterm" do, also what
"ssh" does (when you log in interactively with it). "screen" and "tmux"
are other programs in this class.

The way they all work is, they set up a pseudo-terminal (pty). The pty
has a master end and a slave end.


I know expect, and yeah it works. It's just that TCL is too old-school 
to cleanly handle all edge cases, and I don't have the time budget to 
really learn all the ins and outs of TCL.
pexpect doesn't work, because it would insist on line buffering (try 
doing a login or responding to a prompt).
expectit doesn't work, because it simply opens a pipe. It's otherwise 
the best-maintained, best-structured API. Being Java, it's a bit 
difficult to interface to C, besides opening ptys is pretty nonportable 
so it would have been a biggish project to give the maintainer a patch 
that is useful to him.


So the workaround is to use expect anyway. So happy :-(

> (pexpect)

Then you can read the master-end (pexpect should let you do that as
well) -- the master-end will indeed read similarly to pipe.


Sure, it fails due to line buffering. Can't wait for the login prompt 
because it isn't sending an eoln.


> Just be

aware that all the terminal output goo, such as cursor positioning,
color change sequences, beeps, screen resolution changes, etc, will show
up as binary garbage in the stream.


It's just escape sequences, and while they're a bit of a pain, they can 
be filtered out.
If TCL were a sane language, I could do that with a bit of code, but it 
isn't, so I'm doing that mentally - it's a pain, but it works.



I'm still wondering why there's such a stiff opposition to giving that 
with qemu.
Note that I do agree that it's not what qemu should do by default, 
switching that check off should be an option.
I just never got around to making that suggestion because Gerd was so 
insistent on brushing the use cases aside.


Jo



Re: [Qemu-devel] [PATCH v3 09/10] block/pflash_cfi02: Implement erase suspend/resume

2019-04-17 Thread Thomas Huth
On 18/04/2019 00.01, Stephen Checkoway wrote:
> During a sector erase (but not a chip erase), the embeded erase program
> can be suspended. Once suspended, the sectors not selected for erasure
> may be read and programmed. Autoselect mode is allowed during erase
> suspend mode. Presumably, CFI queries are similarly allowed so this
> commit allows them as well.
> 
> Since guest firmware can use status bits DQ7, DQ6, DQ3, and DQ2 to
> determine the current state of sector erasure, these bits are properly
> implemented.
> 
> Signed-off-by: Stephen Checkoway 
> ---
>  hw/block/pflash_cfi02.c   | 153 ++
>  tests/pflash-cfi02-test.c | 112 
>  2 files changed, 251 insertions(+), 14 deletions(-)

Acked-by: Thomas Huth 



Re: [Qemu-devel] [PATCH 3/5] linux-user: Use lookup_cpu_class()

2019-04-17 Thread Eduardo Habkost
On Tue, Apr 16, 2019 at 11:59:42PM -0300, Eduardo Habkost wrote:
> The return value of cpu_get_model() is just a CPU model name and
> never includes extra options.  We don't need to call
> parse_cpu_option().

Oops.  I was wrong.  linux-user also supports extra features in
the "-cpu" option, so we do need to call parse_cpu_option().

e.g.: this worked before:

  $ qemu-x86_64 -cpu Nehalem,+popcnt /bin/true

and now this is broken:

  $ qemu-x86_64 -cpu Nehalem,+popcnt /bin/true
  unable to find CPU model 'Nehalem,+popcnt'

I will drop patches 2-5 from my queue.  Sorry for the noise.

-- 
Eduardo



Re: [Qemu-devel] [PATCH v3 08/10] block/pflash_cfi02: Implement multi-sector erase

2019-04-17 Thread Thomas Huth
On 18/04/2019 00.01, Stephen Checkoway wrote:
> After two unlock cycles and a sector erase command, the AMD flash chips
> start a 50 us erase time out. Any additional sector erase commands add a
> sector to be erased and restart the 50 us timeout. During the timeout,
> status bit DQ3 is cleared. After the time out, DQ3 is asserted during
> erasure.
> 
> Signed-off-by: Stephen Checkoway 
> ---
>  hw/block/pflash_cfi02.c   | 94 +++
>  tests/pflash-cfi02-test.c | 59 ++--
>  2 files changed, 131 insertions(+), 22 deletions(-)

Acked-by: Thomas Huth 



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

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

Do you maybe want to update that to 2019?

> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
> + * See the COPYING file in the top-level directory.
> + */
> +
> +#include "qemu/osdep.h"
> +#include 

We generally don't use err.h in QEMU ... could you please use the
standard functions from glib instead?

> +#include 

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

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

Re: [Qemu-devel] [PATCH v3 2/2] exec: Introduce qemu_maxrampagesize() and rename qemu_getrampagesize()

2019-04-17 Thread David Gibson
On Wed, Apr 17, 2019 at 01:31:43PM +0200, David Hildenbrand wrote:
> Rename qemu_getrampagesize() to qemu_minrampagesize(). While at it,
> properly rename find_max_supported_pagesize() to
> find_min_backend_pagesize().
> 
> s390x is actually interested into the maximum ram pagesize, so
> introduce and use qemu_maxrampagesize().
> 
> Add a TODO, indicating that looking at any mapped memory backends is not
> 100% correct in some cases.
> 
> Signed-off-by: David Hildenbrand 

Reviewed-by: David Gibson 

> ---
>  exec.c | 44 ++
>  hw/ppc/spapr_caps.c|  4 ++--
>  hw/s390x/s390-virtio-ccw.c |  2 +-
>  hw/vfio/spapr.c|  2 +-
>  include/exec/ram_addr.h|  3 ++-
>  target/ppc/kvm.c   |  2 +-
>  6 files changed, 47 insertions(+), 10 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index 6ab62f4eee..f9b834ef82 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1687,7 +1687,7 @@ void ram_block_dump(Monitor *mon)
>   * when we actually open and map them.  Iterate over the file
>   * descriptors instead, and use qemu_fd_getpagesize().
>   */
> -static int find_max_supported_pagesize(Object *obj, void *opaque)
> +static int find_min_backend_pagesize(Object *obj, void *opaque)
>  {
>  long *hpsize_min = opaque;
>  
> @@ -1703,7 +1703,27 @@ static int find_max_supported_pagesize(Object *obj, 
> void *opaque)
>  return 0;
>  }
>  
> -long qemu_getrampagesize(void)
> +static int find_max_backend_pagesize(Object *obj, void *opaque)
> +{
> +long *hpsize_max = opaque;
> +
> +if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) {
> +HostMemoryBackend *backend = MEMORY_BACKEND(obj);
> +long hpsize = host_memory_backend_pagesize(backend);
> +
> +if (host_memory_backend_is_mapped(backend) && (hpsize > 
> *hpsize_max)) {
> +*hpsize_max = hpsize;
> +}
> +}
> +
> +return 0;
> +}
> +
> +/*
> + * TODO: We assume right now that all mapped host memory backends are
> + * used as RAM, however some might be used for different purposes.
> + */
> +long qemu_minrampagesize(void)
>  {
>  long hpsize = LONG_MAX;
>  long mainrampagesize;
> @@ -1723,7 +1743,7 @@ long qemu_getrampagesize(void)
>   */
>  memdev_root = object_resolve_path("/objects", NULL);
>  if (memdev_root) {
> -object_child_foreach(memdev_root, find_max_supported_pagesize, 
> );
> +object_child_foreach(memdev_root, find_min_backend_pagesize, 
> );
>  }
>  if (hpsize == LONG_MAX) {
>  /* No additional memory regions found ==> Report main RAM page size 
> */
> @@ -1746,8 +1766,24 @@ long qemu_getrampagesize(void)
>  
>  return hpsize;
>  }
> +
> +long qemu_maxrampagesize(void)
> +{
> +long pagesize = qemu_mempath_getpagesize(mem_path);
> +Object *memdev_root = object_resolve_path("/objects", NULL);
> +
> +if (memdev_root) {
> +object_child_foreach(memdev_root, find_max_backend_pagesize,
> + );
> +}
> +return pagesize;
> +}
>  #else
> -long qemu_getrampagesize(void)
> +long qemu_minrampagesize(void)
> +{
> +return getpagesize();
> +}
> +long qemu_maxrampagesize(void)
>  {
>  return getpagesize();
>  }
> diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
> index edc5ed0e0c..9b1c10baa6 100644
> --- a/hw/ppc/spapr_caps.c
> +++ b/hw/ppc/spapr_caps.c
> @@ -347,7 +347,7 @@ static void cap_hpt_maxpagesize_apply(SpaprMachineState 
> *spapr,
>  warn_report("Many guests require at least 64kiB hpt-max-page-size");
>  }
>  
> -spapr_check_pagesize(spapr, qemu_getrampagesize(), errp);
> +spapr_check_pagesize(spapr, qemu_minrampagesize(), errp);
>  }
>  
>  static bool spapr_pagesize_cb(void *opaque, uint32_t seg_pshift,
> @@ -609,7 +609,7 @@ static SpaprCapabilities 
> default_caps_with_cpu(SpaprMachineState *spapr,
>  uint8_t mps;
>  
>  if (kvmppc_hpt_needs_host_contiguous_pages()) {
> -mps = ctz64(qemu_getrampagesize());
> +mps = ctz64(qemu_minrampagesize());
>  } else {
>  mps = 34; /* allow everything up to 16GiB, i.e. everything */
>  }
> diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
> index 3be5679657..7e256d3d31 100644
> --- a/hw/s390x/s390-virtio-ccw.c
> +++ b/hw/s390x/s390-virtio-ccw.c
> @@ -188,7 +188,7 @@ static void s390_memory_init(ram_addr_t mem_size)
>   * Configure the maximum page size. As no memory devices were created
>   * yet, this is the page size of initial memory only.
>   */
> -s390_set_max_pagesize(qemu_getrampagesize(), _err);
> +s390_set_max_pagesize(qemu_maxrampagesize(), _err);
>  if (local_err) {
>  error_report_err(local_err);
>  exit(EXIT_FAILURE);
> diff --git a/hw/vfio/spapr.c b/hw/vfio/spapr.c
> index 57fe758e54..96c0ad9d9b 100644
> --- a/hw/vfio/spapr.c
> +++ b/hw/vfio/spapr.c
> @@ -148,7 +148,7 @@ int vfio_spapr_create_window(VFIOContainer 

Re: [Qemu-devel] [PATCH v3 06/10] block/pflash_cfi02: Fix CFI in autoselect mode

2019-04-17 Thread Thomas Huth
On 18/04/2019 00.01, Stephen Checkoway wrote:
> After a flash device enters CFI mode from autoselect mode, the reset
> command returns the device to autoselect mode. An additional reset
> command is necessary to return to read array mode.
> 
> Signed-off-by: Stephen Checkoway 
> ---
[...]
> diff --git a/tests/pflash-cfi02-test.c b/tests/pflash-cfi02-test.c
> index 82bc5695e1..4039647604 100644
> --- a/tests/pflash-cfi02-test.c
> +++ b/tests/pflash-cfi02-test.c
> @@ -480,6 +480,42 @@ static void test_geometry(const void *opaque)
>  qtest_quit(qtest);
>  }
>  
> +/*
> + * Test that
> + * 1. enter autoselect mode;
> + * 2. enter CFI mode; and then
> + * 3. exit CFI mode
> + * leaves the flash device in autoselect mode.
> + */
> +static void test_cfi_in_autoselect(const void *opaque)
> +{
> +const FlashConfig *config = opaque;
> +QTestState *qtest = qtest_initf("-M musicpal,accel=qtest"
> +" -drive if=pflash,file=%s,format=raw,"
> +"copy-on-read",
> +image_path);

Just a matter of taste, but I think here I'd declare the variable first,
and do the qtest_initf on a separate line, so you don't have to break
the string between "format=raw," and "copy-on-read".

Anyway, it's just a nit, so still:

Acked-by: Thomas Huth 



Re: [Qemu-devel] [PATCH v3 05/10] block/pflash_cfi02: Implement nonuniform sector sizes

2019-04-17 Thread Thomas Huth
On 18/04/2019 00.01, Stephen Checkoway wrote:
> Some flash chips support sectors of different sizes. For example, the
> AMD AM29LV160DT has 31 64 kB sectors, one 32 kB sector, two 8 kB
> sectors, and a 16 kB sector, in that order. The AM29LV160DB has those in
> the reverse order.
> 
> The `num-blocks` and `sector-length` properties work exactly as they did
> before: a flash device with uniform sector lengths. To get non-uniform
> sector lengths for up to four regions, the following properties may be
> set
> - region 0. `num-blocks0` and `sector-length0`;
> - region 1. `num-blocks1` and `sector-length1`;
> - region 2. `num-blocks2` and `sector-length2`; and
> - region 3. `num-blocks3` and `sector-length3`.
> 
> If the uniform and nonuniform properties are set, then both must specify
> a flash device with the same total size. It would be better to disallow
> both being set, or make `num-blocks0` and `sector-length0` alias
> `num-blocks` and `sector-length`, but that would make testing currently
> impossible.
> 
> Signed-off-by: Stephen Checkoway 
> ---
>  hw/block/pflash_cfi02.c   | 177 +---
>  tests/pflash-cfi02-test.c | 185 --
>  2 files changed, 265 insertions(+), 97 deletions(-)

Acked-by: Thomas Huth 



Re: [Qemu-devel] [PATCH v3 04/10] block/pflash_cfi02: Implement intereleaved flash devices

2019-04-17 Thread Thomas Huth
On 18/04/2019 00.01, Stephen Checkoway wrote:
> It's common for multiple narrow flash chips to be hooked up in parallel
> to support wider buses. For example, four 8-bit wide flash chips (x8)
> may be combined in parallel to produce a 32-bit wide device. Similarly,
> two 16-bit wide chips (x16) may be combined.
> 
> This commit introduces `device-width` and `max-device-width` properties,
> similar to pflash_cfi01, with the following meanings:
> - `width`: The width of the logical, qemu device (same as before);
> - `device-width`: The width of an individual flash chip, defaulting to
>   `width`; and
> - `max-device-width`: The maximum width of an individual flash chip,
>   defaulting to `device-width`.
> 
> Nothing needs to change to support reading such interleaved devices but
> commands (e.g., erase and programming) must be sent to all devices at
> the same time or else the various chips will be in different states.
> 
> For example, a 4-byte wide logical device can be composed of four x8/x16
> devices in x8 mode. That is, each device supports both x8 or x16 and
> they're being used in the byte, rather than word, mode. This
> configuration would have `width=4`, `device-width=1`, and
> `max-device-width=2`.
> 
> In addition to commands being sent to all devices, guest firmware
> expects the status and CFI queries to be replicated for each device.
> (The one exception to the response replication is that each device gets
> to report its own status bit DQ7 while programming because its value
> depends on the value being programmed which will usually differ for each
> device.)
> 
> Testing is limited to 16-bit wide devices due to the current inability
> to override the properties set by `pflash_cfi02_register`, but multiple
> configurations are tested.
> 
> Stop using global_qtest. Instead, package the qtest variable inside the
> FlashConfig structure.

Thanks for doing that change wrt global_qtest!

Acked-by: Thomas Huth 



Re: [Qemu-devel] [PATCH v3 03/10] block/pflash_cfi02: Fix command address comparison

2019-04-17 Thread Thomas Huth
On 18/04/2019 00.01, Stephen Checkoway wrote:
> Most AMD commands only examine 11 bits of the address. This masks the
> addresses used in the comparison to 11 bits. The exceptions are word or
> sector addresses which use offset directly rather than the shifted
> offset, boff.
> 
> Signed-off-by: Stephen Checkoway 
> ---
>  hw/block/pflash_cfi02.c   |  8 +++-
>  tests/pflash-cfi02-test.c | 12 ++--
>  2 files changed, 17 insertions(+), 3 deletions(-)

Acked-by: Thomas Huth 



[Qemu-devel] Live migration fails with all 8 memslots used

2019-04-17 Thread suresh gumpula
Hi,
I was trying to migrate a VM(CentOS7) which  started with 4G memory and hot
plugged 5 memslots with 1G each.  So the VM has total of 9G memory and
trying to migrate fails in vhost_dev_init() on destination host


if (used_memslots >
hdev->vhost_ops->vhost_backend_memslots_limit(hdev)) {

error_report("vhost backend memory slots limit is less"

 " than current number of present memory slots");

r = -1;

if (busyloop_timeout) {

goto fail_busyloop;

} else {

goto fail;

}

}


Debugged more into this and understood that, after vhost_dev_init()
used_memslots are 4


(gdb) show-vhost-dev-memory-regions 0x56d27000

n_mem_sections:4

n_regions:4

Region0:

$101 = {

  guest_phys_addr = 0x1,; 1G above 4G

  memory_size = 0x4000,

  userspace_addr = 0x7fffb460,

  flags_padding = 0x0

}

Region1:

$102 = {

  guest_phys_addr = 0xc, ; 768k-896k

  memory_size = 0x2,

  userspace_addr = 0x7ffef420,

  flags_padding = 0x0

}

Region2:

$103 = {

  guest_phys_addr = 0x10, ;;3G from 1M

  memory_size = 0xbff0,

  userspace_addr = 0x7ffef470,

  flags_padding = 0x0

}

Region3:

$104 = {

  guest_phys_addr = 0x0,

  memory_size = 0xa,  ;   First 640K;   0 - 640k;

  userspace_addr = 0x7ffef460,

  flags_padding = 0x0

}

(gdb) p used_memslots

$150 = 4


And later on it coalesced the VGA region of 128k at 0xc( 768-896k) upon
guest config write

with  i440fx_update_memory_mappings(d);

(gdb) f 5

#5  0x5595b920 in i440fx_write_config (dev=0x572b8000,
address=90, val=51, len=1) at hw/pci-host/piix.c:168

168 i440fx_update_memory_mappings(d);

(gdb) l

163

164 /* XXX: implement SMRAM.D_LOCK */

165 pci_default_write_config(dev, address, val, len);

166 if (ranges_overlap(address, len, I440FX_PAM, I440FX_PAM_SIZE) ||

167 range_covers_byte(address, len, I440FX_SMRAM)) {

168 i440fx_update_memory_mappings(d);

169 }

170 }



(gdb) p used_memslots

$150 = 3


Since the destination QEMU does not know that the source host coalesced one
region,  vhost_dev_init for kernel started with 4 slots and  hot plugged 5
slots and then the vhost_dev_init for user fails since 9>8 is true.


if (used_memslots >
hdev->vhost_ops->vhost_backend_memslots_limit(hdev)) {

error_report("vhost backend memory slots limit is less"

 " than current number of present memory slots");

r = -1;

if (busyloop_timeout) {

goto fail_busyloop;

} else {

goto fail;

}

}


Can you guys please answer my questions here:

1)  Why is the VGA region of 128k coalesced on guest vcpu execution with
pci config write?

2)  We have memslots limit of 8 and 3 are pre occupied with initial memory
and we can only use 4 memslots for hotplug instead of 5 to migrate a VM.
Is there any reason for this?  We cannot hotplug 5 slots and migrate the VM.



Thanks much

Suresh.G


[Qemu-devel] [PATCH v7 2/2] hw/arm: Add arm SBSA reference machine, devices part

2019-04-17 Thread Hongbo Zhang
Following the previous patch, this patch adds peripheral devices to the
newly introduced SBSA-ref machine.

Signed-off-by: Hongbo Zhang 
---
 hw/arm/sbsa-ref.c | 451 ++
 1 file changed, 451 insertions(+)

diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
index 652ec13..3fb0027 100644
--- a/hw/arm/sbsa-ref.c
+++ b/hw/arm/sbsa-ref.c
@@ -21,6 +21,7 @@
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "qemu/units.h"
+#include "sysemu/device_tree.h"
 #include "sysemu/numa.h"
 #include "sysemu/sysemu.h"
 #include "exec/address-spaces.h"
@@ -28,11 +29,28 @@
 #include "kvm_arm.h"
 #include "hw/arm/arm.h"
 #include "hw/boards.h"
+#include "hw/ide/internal.h"
+#include "hw/ide/ahci_internal.h"
 #include "hw/intc/arm_gicv3_common.h"
+#include "hw/loader.h"
+#include "hw/pci-host/gpex.h"
+#include "hw/usb.h"
+#include "net/net.h"
 
 #define RAMLIMIT_GB 8192
 #define RAMLIMIT_BYTES (RAMLIMIT_GB * GiB)
 
+#define NUM_IRQS256
+#define NUM_SMMU_IRQS   4
+#define NUM_SATA_PORTS  6
+
+#define VIRTUAL_PMU_IRQ7
+#define ARCH_GIC_MAINT_IRQ 9
+#define ARCH_TIMER_VIRT_IRQ11
+#define ARCH_TIMER_S_EL1_IRQ   13
+#define ARCH_TIMER_NS_EL1_IRQ  14
+#define ARCH_TIMER_NS_EL2_IRQ  10
+
 enum {
 SBSA_FLASH,
 SBSA_MEM,
@@ -115,6 +133,415 @@ static const int sbsa_ref_irqmap[] = {
 [SBSA_EHCI] = 11,
 };
 
+/*
+ * Firmware on this machine only uses ACPI table to load OS, these limited
+ * device tree nodes are just to let firmware know the info which varies from
+ * command line parameters, so it is not necessary to be fully compatible
+ * with the kernel CPU and NUMA binding rules.
+ */
+static void create_fdt(SBSAMachineState *vms)
+{
+void *fdt = create_device_tree(>fdt_size);
+const MachineState *ms = MACHINE(vms);
+int cpu;
+
+if (!fdt) {
+error_report("create_device_tree() failed");
+exit(1);
+}
+
+vms->fdt = fdt;
+
+qemu_fdt_setprop_string(fdt, "/", "compatible", "linux,sbsa-ref");
+qemu_fdt_setprop_cell(fdt, "/", "#address-cells", 0x2);
+qemu_fdt_setprop_cell(fdt, "/", "#size-cells", 0x2);
+
+if (have_numa_distance) {
+int size = nb_numa_nodes * nb_numa_nodes * 3 * sizeof(uint32_t);
+uint32_t *matrix = g_malloc0(size);
+int idx, i, j;
+
+for (i = 0; i < nb_numa_nodes; i++) {
+for (j = 0; j < nb_numa_nodes; j++) {
+idx = (i * nb_numa_nodes + j) * 3;
+matrix[idx + 0] = cpu_to_be32(i);
+matrix[idx + 1] = cpu_to_be32(j);
+matrix[idx + 2] = cpu_to_be32(numa_info[i].distance[j]);
+}
+}
+
+qemu_fdt_add_subnode(fdt, "/distance-map");
+qemu_fdt_setprop(fdt, "/distance-map", "distance-matrix",
+ matrix, size);
+g_free(matrix);
+}
+
+qemu_fdt_add_subnode(vms->fdt, "/cpus");
+
+for (cpu = vms->smp_cpus - 1; cpu >= 0; cpu--) {
+char *nodename = g_strdup_printf("/cpus/cpu@%d", cpu);
+ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(cpu));
+CPUState *cs = CPU(armcpu);
+
+qemu_fdt_add_subnode(vms->fdt, nodename);
+
+if (ms->possible_cpus->cpus[cs->cpu_index].props.has_node_id) {
+qemu_fdt_setprop_cell(vms->fdt, nodename, "numa-node-id",
+ms->possible_cpus->cpus[cs->cpu_index].props.node_id);
+}
+
+g_free(nodename);
+}
+}
+
+static void create_one_flash(const char *name, hwaddr flashbase,
+ hwaddr flashsize, const char *file,
+ MemoryRegion *sysmem)
+{
+/*
+ * Create and map a single flash device. We use the same
+ * parameters as the flash devices on the Versatile Express board.
+ */
+DriveInfo *dinfo = drive_get_next(IF_PFLASH);
+DeviceState *dev = qdev_create(NULL, "cfi.pflash01");
+SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+const uint64_t sectorlength = 256 * 1024;
+
+if (dinfo) {
+qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo),
+_abort);
+}
+
+qdev_prop_set_uint32(dev, "num-blocks", flashsize / sectorlength);
+qdev_prop_set_uint64(dev, "sector-length", sectorlength);
+qdev_prop_set_uint8(dev, "width", 4);
+qdev_prop_set_uint8(dev, "device-width", 2);
+qdev_prop_set_bit(dev, "big-endian", false);
+qdev_prop_set_uint16(dev, "id0", 0x89);
+qdev_prop_set_uint16(dev, "id1", 0x18);
+qdev_prop_set_uint16(dev, "id2", 0x00);
+qdev_prop_set_uint16(dev, "id3", 0x00);
+qdev_prop_set_string(dev, "name", name);
+qdev_init_nofail(dev);
+
+memory_region_add_subregion(sysmem, flashbase,
+sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 
0));
+
+if (file) {
+char *fn;
+int image_size;
+
+if (drive_get(IF_PFLASH, 0, 0)) {
+error_report("The contents of the first flash device may be "
+

[Qemu-devel] [PATCH v7 1/2] hw/arm: Add arm SBSA reference machine, skeleton part

2019-04-17 Thread Hongbo Zhang
For the Aarch64, there is one machine 'virt', it is primarily meant to
run on KVM and execute virtualization workloads, but we need an
environment as faithful as possible to physical hardware, for supporting
firmware and OS development for pysical Aarch64 machines.

This patch introduces new machine type 'sbsa-ref' with main features:
 - Based on 'virt' machine type.
 - A new memory map.
 - CPU type cortex-a57.
 - EL2 and EL3 are enabled.
 - GIC version 3.
 - System bus AHCI controller.
 - System bus EHCI controller.
 - CDROM and hard disc on AHCI bus.
 - E1000E ethernet card on PCIE bus.
 - VGA display adaptor on PCIE bus.
 - No virtio deivces.
 - No fw_cfg device.
 - No ACPI table supplied.
 - Only minimal device tree nodes.

Arm Trusted Firmware and UEFI porting to this are done accordingly, and
it should supply ACPI tables to load OS, the minimal device tree nodes
supplied from this platform are only to pass the dynamic info reflecting
command line input to firmware, not for loading OS.

To make the review easier, this task is split into two patches, the
fundamental sceleton part and the peripheral devices part, this patch is
the first part.

Signed-off-by: Hongbo Zhang 
---
 default-configs/arm-softmmu.mak |   1 +
 hw/arm/Kconfig  |   3 +
 hw/arm/Makefile.objs|   1 +
 hw/arm/sbsa-ref.c   | 306 
 4 files changed, 311 insertions(+)
 create mode 100644 hw/arm/sbsa-ref.c

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 613d19a..1a2352e 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -145,6 +145,7 @@ CONFIG_IOH3420=y
 CONFIG_I82801B11=y
 CONFIG_ACPI=y
 CONFIG_ARM_VIRT=y
+CONFIG_SBSA_REF=y
 CONFIG_SMBIOS=y
 CONFIG_ASPEED_SOC=y
 CONFIG_SMBUS_EEPROM=y
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index d298fbd..6654914 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -38,6 +38,9 @@ config PXA2XX
 config REALVIEW
 bool
 
+config SBSA_REF
+bool
+
 config STELLARIS
 bool
 
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
index fa57c7c..fa812ec 100644
--- a/hw/arm/Makefile.objs
+++ b/hw/arm/Makefile.objs
@@ -12,6 +12,7 @@ obj-$(CONFIG_NSERIES) += nseries.o
 obj-$(CONFIG_OMAP) += omap_sx1.o palm.o
 obj-$(CONFIG_PXA2XX) += gumstix.o spitz.o tosa.o z2.o
 obj-$(CONFIG_REALVIEW) += realview.o
+obj-$(CONFIG_SBSA_REF) += sbsa-ref.o
 obj-$(CONFIG_STELLARIS) += stellaris.o
 obj-$(CONFIG_STRONGARM) += collie.o
 obj-$(CONFIG_VERSATILE) += vexpress.o versatilepb.o
diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
new file mode 100644
index 000..652ec13
--- /dev/null
+++ b/hw/arm/sbsa-ref.c
@@ -0,0 +1,306 @@
+/*
+ * ARM SBSA Reference Platform emulation
+ *
+ * Copyright (c) 2018 Linaro Limited
+ * Written by Hongbo Zhang 
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2 or later, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see .
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qemu/error-report.h"
+#include "qemu/units.h"
+#include "sysemu/numa.h"
+#include "sysemu/sysemu.h"
+#include "exec/address-spaces.h"
+#include "exec/hwaddr.h"
+#include "kvm_arm.h"
+#include "hw/arm/arm.h"
+#include "hw/boards.h"
+#include "hw/intc/arm_gicv3_common.h"
+
+#define RAMLIMIT_GB 8192
+#define RAMLIMIT_BYTES (RAMLIMIT_GB * GiB)
+
+enum {
+SBSA_FLASH,
+SBSA_MEM,
+SBSA_CPUPERIPHS,
+SBSA_GIC_DIST,
+SBSA_GIC_REDIST,
+SBSA_SMMU,
+SBSA_UART,
+SBSA_RTC,
+SBSA_PCIE,
+SBSA_PCIE_MMIO,
+SBSA_PCIE_MMIO_HIGH,
+SBSA_PCIE_PIO,
+SBSA_PCIE_ECAM,
+SBSA_GPIO,
+SBSA_SECURE_UART,
+SBSA_SECURE_UART_MM,
+SBSA_SECURE_MEM,
+SBSA_AHCI,
+SBSA_EHCI,
+};
+
+typedef struct MemMapEntry {
+hwaddr base;
+hwaddr size;
+} MemMapEntry;
+
+typedef struct {
+MachineState parent;
+struct arm_boot_info bootinfo;
+const MemMapEntry *memmap;
+const int *irqmap;
+int smp_cpus;
+void *fdt;
+int fdt_size;
+int psci_conduit;
+} SBSAMachineState;
+
+#define TYPE_SBSA_MACHINE   MACHINE_TYPE_NAME("sbsa-ref")
+#define SBSA_MACHINE(obj) \
+OBJECT_CHECK(SBSAMachineState, (obj), TYPE_SBSA_MACHINE)
+
+static const MemMapEntry sbsa_ref_memmap[] = {
+/* 512M boot ROM */
+[SBSA_FLASH] =  {  0, 0x2000 },
+/* 512M secure memory */
+[SBSA_SECURE_MEM] = { 0x2000, 0x2000 },
+/* Space reserved for CPU peripheral devices */
+

[Qemu-devel] [PATCH v7 0/2] Add Arm SBSA Reference Machine

2019-04-17 Thread Hongbo Zhang
For the Aarch64, there is one machine 'virt', it is primarily meant to
run on KVM and execute virtualization workloads, but we need an
environment as faithful as possible to physical hardware,  to support
firmware and OS development for pysical Aarch64 machines.

This machine comes with:
 - Re-designed memory map.
 - CPU cortex-a57.
 - EL2 and EL3 enabled.
 - GIC version 3.
 - System bus AHCI controller.
 - System bus XHCI controller.
 - CDROM and hard disc on AHCI bus.
 - E1000E ethernet card on PCIE bus.
 - VGA display adaptor on PCIE bus.
 - Only minimal device tree nodes.
And without:
 - virtio deivces.
 - fw_cfg device.
 - ACPI tables.

Arm Trusted Firmware and UEFI porting to this are done accordingly, and
it should supply ACPI tables to load OS, the minimal device tree nodes
supplied from this platform are only to pass the dynamic info reflecting
command line input to firmware, not for loading OS.

v7 changes:
 - edit memory map for PCIE slightly
 - add another secure UART which can be used for RAS and MM from EL0.

v6 changes:
 - rebased to the latest QEMU tree
 - rechecked all the header files included
 - added the newly introduced system bus EHCI controller
 - removed the machine_done callback due to commit 5614ca80
 - updated block comments styles according to checkpatch.pl
 - use Kconfig to add new file
 - use private SBSA* types defination instead of VIRT* in virt.h
   since nobody else using them so they are in the .c file instead
   of a new .h file

v5 changes:
 - removed more lines derived from virt.c
 - designed a new memory map
 - splitted former one patch into two for easier review
 - cancled previous EHCI and new HXCI coming later separately

V4 changes:
 - rebased to v3.0.0
 - removed timer, uart, rtc, *hci device tree nodes
   (others were removerd in v3)
 - other minore codes clean up, mainly unsed header files, comments etc.

V3 changes:
 - rename the platform 'sbsa-ref'
 - move all the codes to a separate file sbsa-ref.c
 - remove paravirtualized fw_cfg device
 - do not supply ACPI tables, since firmware will do it
 - supply only necessary DT nodes
 - and other minor code clean up

Hongbo Zhang (2):
  hw/arm: Add arm SBSA reference machine, skeleton part
  hw/arm: Add arm SBSA reference machine, devices part

 default-configs/arm-softmmu.mak |   1 +
 hw/arm/Kconfig  |   3 +
 hw/arm/Makefile.objs|   1 +
 hw/arm/sbsa-ref.c   | 757 
 4 files changed, 762 insertions(+)
 create mode 100644 hw/arm/sbsa-ref.c

-- 
2.7.4




[Qemu-devel] [PATCH] hppa: Delete unused hppa_cpu_list() function

2019-04-17 Thread Eduardo Habkost
hppa_cpu_list() is dead code and is never called.  Delete it.

Cc: Richard Henderson 
Signed-off-by: Eduardo Habkost 
---
 target/hppa/cpu.c | 22 --
 1 file changed, 22 deletions(-)

diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c
index 00bf444620..b3b1826209 100644
--- a/target/hppa/cpu.c
+++ b/target/hppa/cpu.c
@@ -110,28 +110,6 @@ static void hppa_cpu_realizefn(DeviceState *dev, Error 
**errp)
 #endif
 }
 
-static void hppa_cpu_list_entry(gpointer data, gpointer user_data)
-{
-ObjectClass *oc = data;
-CPUListState *s = user_data;
-
-(*s->cpu_fprintf)(s->file, "  %s\n", object_class_get_name(oc));
-}
-
-void hppa_cpu_list(FILE *f, fprintf_function cpu_fprintf)
-{
-CPUListState s = {
-.file = f,
-.cpu_fprintf = cpu_fprintf,
-};
-GSList *list;
-
-list = object_class_get_list_sorted(TYPE_HPPA_CPU, false);
-(*cpu_fprintf)(f, "Available CPUs:\n");
-g_slist_foreach(list, hppa_cpu_list_entry, );
-g_slist_free(list);
-}
-
 static void hppa_cpu_initfn(Object *obj)
 {
 CPUState *cs = CPU(obj);
-- 
2.18.0.rc1.1.g3f1ff2140




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

2019-04-17 Thread Eduardo Habkost
Fix the following crash:

  $ qemu-system-x86_64 -cpu ''
  qemu-system-x86_64: qom/cpu.c:291: cpu_class_by_name: \
  Assertion `cpu_model && cc->class_by_name' failed.

Regression test script included.

Fixes: commit 99193d8f2ef5 ("cpu: drop unnecessary NULL check and 
cpu_common_class_by_name()")
Signed-off-by: Eduardo Habkost 
---
 exec.c  |  4 
 tests/acceptance/empty_cpu_model.py | 19 +++
 2 files changed, 23 insertions(+)
 create mode 100644 tests/acceptance/empty_cpu_model.py

diff --git a/exec.c b/exec.c
index 1ca95df9d8..d816b38863 100644
--- a/exec.c
+++ b/exec.c
@@ -999,6 +999,10 @@ const char *parse_cpu_option(MachineState *machine, const 
char *cpu_option)
 const char *cpu_type;
 
 model_pieces = g_strsplit(cpu_option, ",", 2);
+if (!model_pieces[0]) {
+error_report("-cpu option cannot be empty");
+exit(1);
+}
 
 cc = lookup_cpu_class(model_pieces[0], _fatal);
 cpu_type = object_class_get_name(OBJECT_CLASS(cc));
diff --git a/tests/acceptance/empty_cpu_model.py 
b/tests/acceptance/empty_cpu_model.py
new file mode 100644
index 00..3f4f663582
--- /dev/null
+++ b/tests/acceptance/empty_cpu_model.py
@@ -0,0 +1,19 @@
+# Check for crash when using empty -cpu option
+#
+# Copyright (c) 2019 Red Hat, Inc.
+#
+# Author:
+#  Eduardo Habkost 
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or
+# later.  See the COPYING file in the top-level directory.
+import subprocess
+from avocado_qemu import Test
+
+class EmptyCPUModel(Test):
+def test(self):
+cmd = [self.qemu_bin, '-S', '-display', 'none', '-machine', 'none', 
'-cpu', '']
+r = subprocess.run(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
+self.assertEquals(r.returncode, 1, "QEMU exit code should be 1")
+self.assertEquals(r.stdout, b'', "QEMU stdout should be empty")
+self.assertNotEquals(r.stderr, b'', "QEMU stderr shouldn't be empty")
-- 
2.18.0.rc1.1.g3f1ff2140




Re: [Qemu-devel] [PATCH 0/5] Remove qdev_get_machine() call from ppc_cpu_parse_featurestr()

2019-04-17 Thread Eduardo Habkost
On Wed, Apr 17, 2019 at 07:45:24AM +0200, Markus Armbruster wrote:
> Eduardo Habkost  writes:
> 
> > My initial goal was simple: removing the qdev_get_machine() call
> > from ppc_cpu_parse_featurestr() because I want to make
> > qdev_get_machine() available only to softmmu code.
> >
> > Before doing this, I had to make *-user not call
> > CPUClass::parse_features() anymore (it was pointless to call it,
> > anyway).
> >
> > While doing this, I decided to rename parse_cpu_model() to
> > something clearer (parse_cpu_option()).
> >
> > As a nice side effect, now the dependency between machine object
> > creation and parse_cpu_option() is not hidden anymore.
> 
> Series
> Reviewed-by: Markus Armbruster 

Thanks.  I'm queueing this even though I agree with the comments
at patch 2/5, because I'm already planning to send a separate
cleanup series for cpu_class_by_name() and other related code.

-- 
Eduardo



Re: [Qemu-devel] Following up questions related to QEMU and I/O Thread

2019-04-17 Thread Wei Li
Sounds good, let's keep in touch. __

Thanks,
Wei

On 4/17/19, 5:17 AM, "Paolo Bonzini"  wrote:

On 17/04/19 03:38, Wei Li wrote:
> Thanks Paolo for your response and clarification.
> 
> Btw, is there any rough schedule about when are you planning to start
> working on the multi queue feature?  Once you start working on the
> feature, I would like to hear more details about the design and
> better understand how this feature will benefit the performance of
> virtio-scsi.

I wish I knew... :)  However, hopefully I will share the details soon
with Sergio and start flushing that queue in 4.1.

Paolo






Re: [Qemu-devel] [Qemu-ppc] [PATCH v3] spapr: add splpar hcalls H_PROD, H_CONFER

2019-04-17 Thread Nicholas Piggin
David Gibson's on April 17, 2019 10:47 pm:
> On Wed, Apr 17, 2019 at 02:01:29PM +0200, Greg Kurz wrote:
>> On Wed, 17 Apr 2019 21:20:00 +1000
>> Nicholas Piggin  wrote:
>> > [...]
>> > >> @@ -1860,6 +1928,9 @@ static void hypercall_register_types(void)
>> > >>  /* hcall-splpar */
>> > >>  spapr_register_hypercall(H_REGISTER_VPA, h_register_vpa);
>> > >>  spapr_register_hypercall(H_CEDE, h_cede);
>> > >> +spapr_register_hypercall(H_CONFER, h_confer);
>> > >> +spapr_register_hypercall(H_PROD, h_prod);
>> > >> +
>> > >>  spapr_register_hypercall(H_SIGNAL_SYS_RESET, h_signal_sys_reset);  
>> > > 
>> > > You're no longer enabling the KVM CONFER and PROD hypercalls.  Are
>> > > they enabled by default, or is that an intentional change?  
>> > 
>> 
>> AFAICT they seem to be enabled by default in HV KVM.
>> 
>> > Oh, it was not intentional, I must not understand how this works. Why
>> > is this no longer enabling the those hcalls?
>> > 
>> 
>> Since linux commit 699a0ea0823d ("KVM: PPC: Book3S: Controls for in-kernel 
>> sPAPR hypercall handling"), in-kernel hypercalls are disabled by default
>> and must be explicitely enabled by userspace. QEMU does that for some
>> hypercalls already (search kvmppc_enable_set_mode_hcall() in QEMU for an
>> example).
>> 
>> Since H_CONFER and H_PROD are listed in default_hcall_list[] in book3s_hv.c,
>> no need for QEMU to enable them in KVM.
> 
> Ah, ok.  Oops, that means the guest environment has been visibly
> different for KVM and TCG all this time, which isn't great.
> 
>> Not sure about David's "no longer" wording though.
> 
> 
> "no longer" meaning the previous patch version had some
> kvmppc_enable_hcall(), but this version doesn't.

Let me do one more iteration with the comment fixed up at least,
and I'll do a bit of testing with KVM vs TCG behaviour and see
if there are any problems around this.

Thanks,
Nick




Re: [Qemu-devel] [Qemu-ppc] [PATCH v3] spapr: add splpar hcalls H_PROD, H_CONFER

2019-04-17 Thread Nicholas Piggin
Greg Kurz's on April 17, 2019 10:01 pm:
> On Wed, 17 Apr 2019 21:20:00 +1000
> Nicholas Piggin  wrote:
>> [...]
>> >> @@ -1860,6 +1928,9 @@ static void hypercall_register_types(void)
>> >>  /* hcall-splpar */
>> >>  spapr_register_hypercall(H_REGISTER_VPA, h_register_vpa);
>> >>  spapr_register_hypercall(H_CEDE, h_cede);
>> >> +spapr_register_hypercall(H_CONFER, h_confer);
>> >> +spapr_register_hypercall(H_PROD, h_prod);
>> >> +
>> >>  spapr_register_hypercall(H_SIGNAL_SYS_RESET, h_signal_sys_reset);  
>> > 
>> > You're no longer enabling the KVM CONFER and PROD hypercalls.  Are
>> > they enabled by default, or is that an intentional change?  
>> 
> 
> AFAICT they seem to be enabled by default in HV KVM.
> 
>> Oh, it was not intentional, I must not understand how this works. Why
>> is this no longer enabling the those hcalls?
>> 
> 
> Since linux commit 699a0ea0823d ("KVM: PPC: Book3S: Controls for in-kernel 
> sPAPR hypercall handling"), in-kernel hypercalls are disabled by default
> and must be explicitely enabled by userspace. QEMU does that for some
> hypercalls already (search kvmppc_enable_set_mode_hcall() in QEMU for an
> example).

Thanks for the explanation, that's a nice feature.

> Since H_CONFER and H_PROD are listed in default_hcall_list[] in book3s_hv.c,
> no need for QEMU to enable them in KVM.

It looks like we can disable even hcalls that are in the default list
which might help with qemu H_JOIN implementation if we need to send
H_PROD to qemu to do the wake-up.

Thanks,
Nick




[Qemu-devel] [PATCH] docs/interop/bitmaps: rewrite and modernize doc

2019-04-17 Thread John Snow
This just about rewrites the entirety of the bitmaps.rst document to
make it consistent with the 4.0 release. I have added new features seen
in the 4.0 release, as well as tried to clarify some points that keep
coming up when discussing this feature both in-house and upstream.

Yes, it's a lot longer, mostly due to examples. I get a bit chatty.
I could use a good editor to help reign in my chattiness.

It does not yet cover pull backups or migration details, but I intend to
keep extending this document to cover those cases.

Please try compiling it with sphinx and look at the rendered output, I
don't have hosting to share my copy at present. I think this new layout
reads nicer in the HTML format than the old one did, at the expense of
looking less readable in the source tree itself (though not completely
unmanagable. We did decide to convert it from Markdown to ReST, after
all, so I am going all-in on ReST.)

Signed-off-by: John Snow 
---
 docs/interop/bitmaps.rst | 1499 ++
 Makefile |2 +-
 2 files changed, 1192 insertions(+), 309 deletions(-)

diff --git a/docs/interop/bitmaps.rst b/docs/interop/bitmaps.rst
index 7bcfe7f461..a39d1fc871 100644
--- a/docs/interop/bitmaps.rst
+++ b/docs/interop/bitmaps.rst
@@ -9,128 +9,481 @@
 Dirty Bitmaps and Incremental Backup
 
 
--  Dirty Bitmaps are objects that track which data needs to be backed up
-   for the next incremental backup.
+Dirty Bitmaps are in-memory objects that track writes to block devices. They 
can
+be used in conjunction with various block job operations to perform incremental
+or differential backup regimens.
 
--  Dirty bitmaps can be created at any time and attached to any node
-   (not just complete drives).
+This document explains the conceptual mechanisms, as well as up-to-date,
+complete and comprehensive documentation on the API to manipulate them.
+(Hopefully, the "why", "what", and "how".)
+
+The intended audience for this document is developers who are adding QEMU 
backup
+features to management applications, or power users who run and administer QEMU
+directly via QMP.
 
 .. contents::
 
+Overview
+
+
+Bitmaps are bit vectors where each '1' bit in the vector indicates a modified
+("dirty") segment of the corresponding block device. The size of the segment
+that is tracked is the granularity of the bitmap. If the granularity of a 
bitmap
+is 64K, each '1' bit means that an entire 64K region changed in some way.
+
+Smaller granularities mean more accurate tracking of modified disk data, but
+requires more computational overhead and larger bitmap sizes. Larger
+granularities mean smaller bitmap sizes, but less targeted backups.
+
+The size of a bitmap (in bytes) can be computed as such:
+``size`` = ((``image_size`` / ``granularity``) / 8)
+
+e.g. the size of a 64KiB granularity bitmap on a 2TiB image is:
+``size`` = ((2147483648K / 64K) / 8)
+ = 4194304B = 4MiB.
+
+QEMU uses these bitmaps when making incremental backups to know which
+sections of the file to copy out. They are not enabled by default and
+must be explicitly added in order to begin tracking writes.
+
+Bitmaps can be created at any time and can be attached to any
+arbitrary block node in the storage graph, but are most useful
+conceptually when attached to the root node attached to the guest's
+storage device model.
+
+(Which is a really chatty way of saying: It's likely most useful to
+track the guest's writes to disk, but you could theoretically track
+things like qcow2 metadata changes by attaching the bitmap elsewhere
+in the storage graph.)
+
+QEMU supports persisting these bitmaps to disk via the qcow2 image format.
+Bitmaps which are stored or loaded in this way are called "persistent", whereas
+bitmaps that are not are called "transient".
+
+QEMU also supports the migration of both transient bitmaps (tracking any
+arbitrary image format) or persistent bitaps (qcow2) via live migration.
+
+Supported Image Formats
+---
+
+QEMU supports all documented features below on the qcow2 image format.
+
+However, qcow2 is only strictly necessary for the persistence feature, which
+writes bitmap data to disk upon close. If persistence is not required for a
+specific use case, all bitmap features excepting persistence are available
+for any arbitrary image format.
+
+For example, Dirty Bitmaps can be combined with the 'raw' image format,
+but any changes to the bitmap will be discarded upon exit.
+
+.. warning:: Transient bitmaps will not be saved on QEMU exit! Persistent
+ bitmaps are available only on qcow2 images.
+
 Dirty Bitmap Names
 --
 
--  A dirty bitmap's name is unique to the node, but bitmaps attached to
-   different nodes can share the same name.
+Bitmap objects need a method to reference them in the API. All API-created and
+managed bitmaps have a human-readable name chosen by the user at creation time.
 

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

2019-04-17 Thread Alex Williamson
On Wed, 17 Apr 2019 21:06:33 +0200
Markus Armbruster  wrote:

> Cc: Alex Williamson 
> Signed-off-by: Markus Armbruster 
> ---
>  hw/vfio/pci.c | 19 +--
>  1 file changed, 13 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index 504019c458..0142819ea6 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -947,8 +947,10 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
>  if (vdev->pdev.romfile || !vdev->pdev.rom_bar) {
>  /* Since pci handles romfile, just print a message and return */
>  if (vfio_blacklist_opt_rom(vdev) && vdev->pdev.romfile) {
> -error_printf("Warning : Device at %s is known to cause system 
> instability issues during option rom execution. Proceeding anyway since user 
> specified romfile\n",
> - vdev->vbasedev.name);
> +warn_report("Device at %s is known to cause system instability"
> +" issues during option rom execution",
> +vdev->vbasedev.name);
> +error_printf("Proceeding anyway since user specified romfile\n");

I'm confused, the original warning is "this device is know to have
issues, proceeding because you asked me to".  Are we categorizing the
first half as a warning and the latter as random uncategorized error
spew?  Did an automated script chunk it this way because of the period
and strict application of the "single phrase" specification of
warn_report()?  If this is the recommended semantics, I'm not sure how
I'd know to generate this myself for similar situations.  Should we
instead try to express this in something acceptable as a single
phrase?  Thanks,

Alex

>  }
>  return;
>  }
> @@ -973,11 +975,16 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev)
>  
>  if (vfio_blacklist_opt_rom(vdev)) {
>  if (dev->opts && qemu_opt_get(dev->opts, "rombar")) {
> -error_printf("Warning : Device at %s is known to cause system 
> instability issues during option rom execution. Proceeding anyway since user 
> specified non zero value for rombar\n",
> - vdev->vbasedev.name);
> +warn_report("Device at %s is known to cause system instability"
> +" issues during option rom execution",
> +vdev->vbasedev.name);
> +error_printf("Proceeding anyway since user specified"
> + " non zero value for rombar\n");
>  } else {
> -error_printf("Warning : Rom loading for device at %s has been 
> disabled due to system instability issues. Specify rombar=1 or romfile to 
> force\n",
> - vdev->vbasedev.name);
> +warn_report("Rom loading for device at %s has been disabled"
> +" due to system instability issues",
> +vdev->vbasedev.name);
> +error_printf("Specify rombar=1 or romfile to force\n");
>  return;
>  }
>  }




[Qemu-devel] [PATCH v3 07/10] block/pflash_cfi02: Fix reset command not ignored during erase

2019-04-17 Thread Stephen Checkoway
When the flash device is performing a chip erase, all commands are
ignored. When it is performing a sector erase, only the erase suspend
command is valid, which is currently not supported.

In particular, the reset command should not cause the device to reset to
read array mode while programming is on going.

Signed-off-by: Stephen Checkoway 
---
 hw/block/pflash_cfi02.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index be10036886..cb1160eb35 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -325,7 +325,8 @@ static void pflash_write(void *opaque, hwaddr offset, 
uint64_t value,
 pfl->bank_width * 2, value);
 }
 
-if (cmd == 0xF0) {
+/* Reset does nothing during chip erase and sector erase. */
+if (cmd == 0xF0 && pfl->cmd != 0x10 && pfl->cmd != 0x30) {
 if (pfl->wcycle == WCYCLE_AUTOSELECT_CFI) {
 /* Return to autoselect mode. */
 pfl->wcycle = 3;
-- 
2.20.1 (Apple Git-117)




[Qemu-devel] [PATCH v3 04/10] block/pflash_cfi02: Implement intereleaved flash devices

2019-04-17 Thread Stephen Checkoway
It's common for multiple narrow flash chips to be hooked up in parallel
to support wider buses. For example, four 8-bit wide flash chips (x8)
may be combined in parallel to produce a 32-bit wide device. Similarly,
two 16-bit wide chips (x16) may be combined.

This commit introduces `device-width` and `max-device-width` properties,
similar to pflash_cfi01, with the following meanings:
- `width`: The width of the logical, qemu device (same as before);
- `device-width`: The width of an individual flash chip, defaulting to
  `width`; and
- `max-device-width`: The maximum width of an individual flash chip,
  defaulting to `device-width`.

Nothing needs to change to support reading such interleaved devices but
commands (e.g., erase and programming) must be sent to all devices at
the same time or else the various chips will be in different states.

For example, a 4-byte wide logical device can be composed of four x8/x16
devices in x8 mode. That is, each device supports both x8 or x16 and
they're being used in the byte, rather than word, mode. This
configuration would have `width=4`, `device-width=1`, and
`max-device-width=2`.

In addition to commands being sent to all devices, guest firmware
expects the status and CFI queries to be replicated for each device.
(The one exception to the response replication is that each device gets
to report its own status bit DQ7 while programming because its value
depends on the value being programmed which will usually differ for each
device.)

Testing is limited to 16-bit wide devices due to the current inability
to override the properties set by `pflash_cfi02_register`, but multiple
configurations are tested.

Stop using global_qtest. Instead, package the qtest variable inside the
FlashConfig structure.

Signed-off-by: Stephen Checkoway 
---
 hw/block/pflash_cfi02.c   | 270 +++--
 tests/pflash-cfi02-test.c | 477 ++
 2 files changed, 577 insertions(+), 170 deletions(-)

diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index e4bff0c8f8..101628b4ec 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -28,7 +28,6 @@
  * - unlock bypass command
  * - CFI queries
  *
- * It does not support flash interleaving.
  * It does not implement boot blocs with reduced size
  * It does not implement software data protection as found in many real chips
  * It does not implement erase suspend/resume commands
@@ -67,15 +66,19 @@ struct PFlashCFI02 {
 BlockBackend *blk;
 uint32_t sector_len;
 uint32_t nb_blocs;
-uint32_t chip_len;
+uint64_t total_len;
+uint64_t interleave_multiplier;
 uint8_t mappings;
-uint8_t width;
+uint8_t bank_width; /* Width of the QEMU device in bytes. */
+uint8_t device_width; /* Width of individual pflash chip. */
+uint8_t max_device_width; /* Maximum width of individual pflash chip. */
 uint8_t be;
+int device_shift; /* Amount to shift an offset to get a device address. */
 int wcycle; /* if 0, the flash is read normally */
 int bypass;
 int ro;
 uint8_t cmd;
-uint8_t status;
+uint64_t status;
 /* FIXME: implement array device properties */
 uint16_t ident0;
 uint16_t ident1;
@@ -103,16 +106,17 @@ struct PFlashCFI02 {
  */
 static inline void toggle_dq7(PFlashCFI02 *pfl)
 {
-pfl->status ^= 0x80;
+pfl->status ^= pfl->interleave_multiplier * 0x80;
 }
 
 /*
  * Set status bit DQ7 to bit 7 of value.
  */
-static inline void set_dq7(PFlashCFI02 *pfl, uint8_t value)
+static inline void set_dq7(PFlashCFI02 *pfl, uint64_t value)
 {
-pfl->status &= 0x7F;
-pfl->status |= value & 0x80;
+uint64_t mask = pfl->interleave_multiplier * 0x80;
+pfl->status &= ~mask;
+pfl->status |= value & mask;
 }
 
 /*
@@ -120,7 +124,7 @@ static inline void set_dq7(PFlashCFI02 *pfl, uint8_t value)
  */
 static inline void toggle_dq6(PFlashCFI02 *pfl)
 {
-pfl->status ^= 0x40;
+pfl->status ^= pfl->interleave_multiplier * 0x40;
 }
 
 /*
@@ -188,7 +192,6 @@ static uint64_t pflash_data_read(PFlashCFI02 *pfl, hwaddr 
offset,
 static uint64_t pflash_read(void *opaque, hwaddr offset, unsigned int width)
 {
 PFlashCFI02 *pfl = opaque;
-hwaddr boff;
 uint64_t ret;
 
 ret = -1;
@@ -198,12 +201,10 @@ static uint64_t pflash_read(void *opaque, hwaddr offset, 
unsigned int width)
 ++pfl->read_counter > PFLASH_LAZY_ROMD_THRESHOLD) {
 pflash_register_memory(pfl, 1);
 }
-offset &= pfl->chip_len - 1;
-boff = offset & 0xFF;
-if (pfl->width == 2)
-boff = boff >> 1;
-else if (pfl->width == 4)
-boff = boff >> 2;
+/* Mask by the total length of the chip to account for alias mappings. */
+offset &= pfl->total_len - 1;
+hwaddr device_addr = offset >> pfl->device_shift;
+
 switch (pfl->cmd) {
 default:
 /* This should never happen : reset state & treat it as a read*/
@@ -215,29 +216,32 @@ static uint64_t pflash_read(void *opaque, 

[Qemu-devel] [PATCH v3 03/10] block/pflash_cfi02: Fix command address comparison

2019-04-17 Thread Stephen Checkoway
Most AMD commands only examine 11 bits of the address. This masks the
addresses used in the comparison to 11 bits. The exceptions are word or
sector addresses which use offset directly rather than the shifted
offset, boff.

Signed-off-by: Stephen Checkoway 
---
 hw/block/pflash_cfi02.c   |  8 +++-
 tests/pflash-cfi02-test.c | 12 ++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index 4b7af71806..e4bff0c8f8 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -296,11 +296,13 @@ static void pflash_write(void *opaque, hwaddr offset, 
uint64_t value,
 
 DPRINTF("%s: offset " TARGET_FMT_plx " %08" PRIx64 " %d\n", __func__,
 offset, value, width);
-boff = offset & (pfl->sector_len - 1);
+boff = offset;
 if (pfl->width == 2)
 boff = boff >> 1;
 else if (pfl->width == 4)
 boff = boff >> 2;
+/* Only the least-significant 11 bits are used in most cases. */
+boff &= 0x7FF;
 switch (pfl->wcycle) {
 case 0:
 /* Set the device in I/O access mode if required */
@@ -519,6 +521,10 @@ static void pflash_cfi02_realize(DeviceState *dev, Error 
**errp)
 return;
 }
 
+/* Only 11 bits are used in the comparison. */
+pfl->unlock_addr0 &= 0x7FF;
+pfl->unlock_addr1 &= 0x7FF;
+
 chip_len = pfl->sector_len * pfl->nb_blocs;
 
 memory_region_init_rom_device(>orig_mem, OBJECT(pfl),
diff --git a/tests/pflash-cfi02-test.c b/tests/pflash-cfi02-test.c
index b113fca5af..b91bb66a79 100644
--- a/tests/pflash-cfi02-test.c
+++ b/tests/pflash-cfi02-test.c
@@ -23,8 +23,8 @@
 
 #define FLASH_WIDTH 2
 #define CFI_ADDR (FLASH_WIDTH * 0x55)
-#define UNLOCK0_ADDR (FLASH_WIDTH * 0x)
-#define UNLOCK1_ADDR (FLASH_WIDTH * 0x2AAA)
+#define UNLOCK0_ADDR (FLASH_WIDTH * 0x555)
+#define UNLOCK1_ADDR (FLASH_WIDTH * 0x2AA)
 
 #define CFI_CMD 0x98
 #define UNLOCK0_CMD 0xAA
@@ -192,6 +192,14 @@ static void test_flash(void)
 g_assert_cmpint(flash_read(6), ==, 0xCDEF);
 g_assert_cmpint(flash_read(8), ==, 0x);
 
+/* Test ignored high order bits of address. */
+flash_write(FLASH_WIDTH * 0x, UNLOCK0_CMD);
+flash_write(FLASH_WIDTH * 0x2AAA, UNLOCK1_CMD);
+flash_write(FLASH_WIDTH * 0x, AUTOSELECT_CMD);
+g_assert_cmpint(flash_read(FLASH_WIDTH * 0x), ==, 0x00BF);
+g_assert_cmpint(flash_read(FLASH_WIDTH * 0x0001), ==, 0x236D);
+reset();
+
 qtest_quit(global_qtest);
 }
 
-- 
2.20.1 (Apple Git-117)




[Qemu-devel] [PATCH v3 08/10] block/pflash_cfi02: Implement multi-sector erase

2019-04-17 Thread Stephen Checkoway
After two unlock cycles and a sector erase command, the AMD flash chips
start a 50 us erase time out. Any additional sector erase commands add a
sector to be erased and restart the 50 us timeout. During the timeout,
status bit DQ3 is cleared. After the time out, DQ3 is asserted during
erasure.

Signed-off-by: Stephen Checkoway 
---
 hw/block/pflash_cfi02.c   | 94 +++
 tests/pflash-cfi02-test.c | 59 ++--
 2 files changed, 131 insertions(+), 22 deletions(-)

diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index cb1160eb35..21ceb0823b 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -30,7 +30,6 @@
  *
  * It does not implement software data protection as found in many real chips
  * It does not implement erase suspend/resume commands
- * It does not implement multiple sectors erase
  */
 
 #include "qemu/osdep.h"
@@ -106,6 +105,7 @@ struct PFlashCFI02 {
 MemoryRegion orig_mem;
 int rom_mode;
 int read_counter; /* used for lazy switch-back to rom mode */
+int sectors_to_erase;
 char *name;
 void *storage;
 };
@@ -136,6 +136,22 @@ static inline void toggle_dq6(PFlashCFI02 *pfl)
 pfl->status ^= pfl->interleave_multiplier * 0x40;
 }
 
+/*
+ * Turn on DQ3.
+ */
+static inline void assert_dq3(PFlashCFI02 *pfl)
+{
+pfl->status |= pfl->interleave_multiplier * 0x08;
+}
+
+/*
+ * Turn off DQ3.
+ */
+static inline void reset_dq3(PFlashCFI02 *pfl)
+{
+pfl->status &= ~(pfl->interleave_multiplier * 0x08);
+}
+
 /*
  * Set up replicated mappings of the same region.
  */
@@ -159,11 +175,37 @@ static void pflash_register_memory(PFlashCFI02 *pfl, int 
rom_mode)
 pfl->rom_mode = rom_mode;
 }
 
-static void pflash_timer (void *opaque)
+static void pflash_timer(void *opaque)
 {
 PFlashCFI02 *pfl = opaque;
 
 trace_pflash_timer_expired(pfl->cmd);
+if (pfl->cmd == 0x30) {
+/*
+ * Sector erase. If DQ3 is 0 when the timer expires, then the 50
+ * us erase timeout has expired so we need to start the timer for the
+ * sector erase algorithm. Otherwise, the erase completed and we should
+ * go back to read array mode.
+ */
+if ((pfl->status & 0x08) == 0) {
+assert_dq3(pfl);
+/*
+ * CFI address 0x21 is "Typical timeout per individual block erase
+ * 2^N ms"
+ */
+uint64_t timeout = ((1ULL << pfl->cfi_table[0x21]) *
+pfl->sectors_to_erase) * 100;
+timer_mod(>timer,
+  qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + timeout);
+DPRINTF("%s: erase timeout fired; erasing %d sectors\n",
+__func__, pfl->sectors_to_erase);
+return;
+}
+DPRINTF("%s: sector erase complete\n", __func__);
+pfl->sectors_to_erase = 0;
+reset_dq3(pfl);
+}
+
 /* Reset flash */
 toggle_dq7(pfl);
 if (pfl->bypass) {
@@ -307,13 +349,30 @@ static void pflash_update(PFlashCFI02 *pfl, int offset, 
int size)
 }
 }
 
+static void pflash_sector_erase(PFlashCFI02 *pfl, hwaddr offset)
+{
+uint64_t sector_len = pflash_sector_len(pfl, offset);
+offset &= ~(sector_len - 1);
+DPRINTF("%s: start sector erase at %0*" PRIx64 "-%0*" PRIx64 "\n",
+__func__, pfl->bank_width * 2, offset,
+pfl->bank_width * 2, offset + sector_len - 1);
+if (!pfl->ro) {
+uint8_t *p = pfl->storage;
+memset(p + offset, 0xFF, sector_len);
+pflash_update(pfl, offset, sector_len);
+}
+set_dq7(pfl, 0x00);
+++pfl->sectors_to_erase;
+/* Set (or reset) the 50 us timer for additional erase commands.  */
+timer_mod(>timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 5);
+}
+
 static void pflash_write(void *opaque, hwaddr offset, uint64_t value,
  unsigned int width)
 {
 PFlashCFI02 *pfl = opaque;
 uint8_t *p;
 uint8_t cmd;
-uint32_t sector_len;
 
 cmd = value;
 if (pfl->cmd != 0xA0) {
@@ -486,20 +545,7 @@ static void pflash_write(void *opaque, hwaddr offset, 
uint64_t value,
 break;
 case 0x30:
 /* Sector erase */
-p = pfl->storage;
-sector_len = pflash_sector_len(pfl, offset);
-offset &= ~(sector_len - 1);
-DPRINTF("%s: start sector erase at %0*" PRIx64 "-%0*" PRIx64 "\n",
-__func__, pfl->bank_width * 2, offset,
-pfl->bank_width * 2, offset + sector_len - 1);
-if (!pfl->ro) {
-memset(p + offset, 0xFF, sector_len);
-pflash_update(pfl, offset, sector_len);
-}
-set_dq7(pfl, 0x00);
-/* Let's wait 1/2 second before sector erase is done */
-timer_mod(>timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
-  (NANOSECONDS_PER_SECOND / 2));
+

[Qemu-devel] [PATCH v3 09/10] block/pflash_cfi02: Implement erase suspend/resume

2019-04-17 Thread Stephen Checkoway
During a sector erase (but not a chip erase), the embeded erase program
can be suspended. Once suspended, the sectors not selected for erasure
may be read and programmed. Autoselect mode is allowed during erase
suspend mode. Presumably, CFI queries are similarly allowed so this
commit allows them as well.

Since guest firmware can use status bits DQ7, DQ6, DQ3, and DQ2 to
determine the current state of sector erasure, these bits are properly
implemented.

Signed-off-by: Stephen Checkoway 
---
 hw/block/pflash_cfi02.c   | 153 ++
 tests/pflash-cfi02-test.c | 112 
 2 files changed, 251 insertions(+), 14 deletions(-)

diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index 21ceb0823b..d9087cafff 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -29,7 +29,6 @@
  * - CFI queries
  *
  * It does not implement software data protection as found in many real chips
- * It does not implement erase suspend/resume commands
  */
 
 #include "qemu/osdep.h"
@@ -37,6 +36,7 @@
 #include "hw/block/block.h"
 #include "hw/block/flash.h"
 #include "qapi/error.h"
+#include "qemu/bitmap.h"
 #include "qemu/timer.h"
 #include "sysemu/block-backend.h"
 #include "qemu/host-utils.h"
@@ -72,6 +72,7 @@ struct PFlashCFI02 {
 BlockBackend *blk;
 uint32_t uniform_nb_blocs;
 uint32_t uniform_sector_len;
+uint32_t total_sectors;
 uint32_t nb_blocs[PFLASH_MAX_ERASE_REGIONS];
 uint32_t sector_len[PFLASH_MAX_ERASE_REGIONS];
 uint64_t total_len;
@@ -106,6 +107,8 @@ struct PFlashCFI02 {
 int rom_mode;
 int read_counter; /* used for lazy switch-back to rom mode */
 int sectors_to_erase;
+uint64_t erase_time_remaining;
+unsigned long *sector_erase_map;
 char *name;
 void *storage;
 };
@@ -152,6 +155,14 @@ static inline void reset_dq3(PFlashCFI02 *pfl)
 pfl->status &= ~(pfl->interleave_multiplier * 0x08);
 }
 
+/*
+ * Toggle status bit DQ2.
+ */
+static inline void toggle_dq2(PFlashCFI02 *pfl)
+{
+pfl->status ^= pfl->interleave_multiplier * 0x04;
+}
+
 /*
  * Set up replicated mappings of the same region.
  */
@@ -175,6 +186,29 @@ static void pflash_register_memory(PFlashCFI02 *pfl, int 
rom_mode)
 pfl->rom_mode = rom_mode;
 }
 
+/*
+ * Returns the time it takes to erase the number of sectors scheduled for
+ * erasure based on CFI address 0x21 which is "Typical timeout per individual
+ * block erase 2^N ms."
+ */
+static uint64_t pflash_erase_time(PFlashCFI02 *pfl)
+{
+/*
+ * If there are no sectors to erase (which can happen if all of the sectors
+ * to be erased are protected), then erase takes 100 us. Protected sectors
+ * aren't supported so this should never happen.
+ */
+return ((1ULL << pfl->cfi_table[0x21]) * pfl->sectors_to_erase) * SCALE_US;
+}
+
+/*
+ * Returns true if the device is currently in erase suspend mode.
+ */
+static inline bool pflash_erase_suspend_mode(PFlashCFI02 *pfl)
+{
+return pfl->erase_time_remaining > 0;
+}
+
 static void pflash_timer(void *opaque)
 {
 PFlashCFI02 *pfl = opaque;
@@ -189,12 +223,7 @@ static void pflash_timer(void *opaque)
  */
 if ((pfl->status & 0x08) == 0) {
 assert_dq3(pfl);
-/*
- * CFI address 0x21 is "Typical timeout per individual block erase
- * 2^N ms"
- */
-uint64_t timeout = ((1ULL << pfl->cfi_table[0x21]) *
-pfl->sectors_to_erase) * 100;
+uint64_t timeout = pflash_erase_time(pfl);
 timer_mod(>timer,
   qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + timeout);
 DPRINTF("%s: erase timeout fired; erasing %d sectors\n",
@@ -202,6 +231,7 @@ static void pflash_timer(void *opaque)
 return;
 }
 DPRINTF("%s: sector erase complete\n", __func__);
+bitmap_zero(pfl->sector_erase_map, pfl->total_sectors);
 pfl->sectors_to_erase = 0;
 reset_dq3(pfl);
 }
@@ -240,25 +270,45 @@ static uint64_t pflash_data_read(PFlashCFI02 *pfl, hwaddr 
offset,
 return ret;
 }
 
+typedef struct {
+uint32_t len;
+uint32_t num;
+} SectorInfo;
+
 /*
  * offset should be a byte offset of the QEMU device and _not_ a device
  * offset.
  */
-static uint32_t pflash_sector_len(PFlashCFI02 *pfl, hwaddr offset)
+static SectorInfo pflash_sector_info(PFlashCFI02 *pfl, hwaddr offset)
 {
 assert(offset < pfl->total_len);
 int nb_regions = pfl->cfi_table[0x2C];
 hwaddr addr = 0;
+uint32_t sector_num = 0;
 for (int i = 0; i < nb_regions; ++i) {
 uint64_t region_size = (uint64_t)pfl->nb_blocs[i] * pfl->sector_len[i];
 if (addr <= offset && offset < addr + region_size) {
-return pfl->sector_len[i];
+return (SectorInfo) {
+.len = pfl->sector_len[i],
+.num = sector_num + (offset - addr) / pfl->sector_len[i],
+};
 

[Qemu-devel] [PATCH v3 10/10] block/pflash_cfi02: Use the chip erase time specified in the CFI table

2019-04-17 Thread Stephen Checkoway
When erasing the chip, use the typical time specified in the CFI table
rather than arbitrarily selecting 5 seconds.

Since the currently unconfigurable value set in the table is 12, this
means a chip erase takes 4096 ms so this isn't a big change in behavior.

Signed-off-by: Stephen Checkoway 
---
 hw/block/pflash_cfi02.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index d9087cafff..76c8af4365 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -633,9 +633,9 @@ static void pflash_write(void *opaque, hwaddr offset, 
uint64_t value,
 pflash_update(pfl, 0, pfl->total_len);
 }
 set_dq7(pfl, 0x00);
-/* Let's wait 5 seconds before chip erase is done */
+/* Wait the time specified at CFI address 0x22. */
 timer_mod(>timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
-  (NANOSECONDS_PER_SECOND * 5));
+  (1ULL << pfl->cfi_table[0x22]) * SCALE_MS);
 break;
 case 0x30:
 /* Sector erase */
-- 
2.20.1 (Apple Git-117)




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

2019-04-17 Thread Stephen Checkoway
Test the AMD command set for parallel flash chips. This test uses an
ARM musicpal board with a pflash drive to test the following list of
currently-supported commands.
- Autoselect
- CFI
- Sector erase
- Chip erase
- Program
- Unlock bypass
- Reset

Signed-off-by: Stephen Checkoway 
---
 tests/Makefile.include|   2 +
 tests/pflash-cfi02-test.c | 227 ++
 2 files changed, 229 insertions(+)
 create mode 100644 tests/pflash-cfi02-test.c

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 6b904d7430..0a26eacce0 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -263,6 +263,7 @@ check-qtest-arm-y += tests/m25p80-test$(EXESUF)
 check-qtest-arm-y += tests/test-arm-mptimer$(EXESUF)
 check-qtest-arm-y += tests/boot-serial-test$(EXESUF)
 check-qtest-arm-y += tests/hexloader-test$(EXESUF)
+check-qtest-arm-$(CONFIG_PFLASH_CFI02) += tests/pflash-cfi02-test$(EXESUF)
 
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
 check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
@@ -773,6 +774,7 @@ tests/device-introspect-test$(EXESUF): 
tests/device-introspect-test.o
 tests/rtc-test$(EXESUF): tests/rtc-test.o
 tests/m48t59-test$(EXESUF): tests/m48t59-test.o
 tests/hexloader-test$(EXESUF): tests/hexloader-test.o
+tests/pflash-cfi02$(EXESUF): tests/pflash-cfi02-test.o
 tests/endianness-test$(EXESUF): tests/endianness-test.o
 tests/prom-env-test$(EXESUF): tests/prom-env-test.o $(libqos-obj-y)
 tests/rtas-test$(EXESUF): tests/rtas-test.o $(libqos-spapr-obj-y)
diff --git a/tests/pflash-cfi02-test.c b/tests/pflash-cfi02-test.c
new file mode 100644
index 00..b113fca5af
--- /dev/null
+++ b/tests/pflash-cfi02-test.c
@@ -0,0 +1,227 @@
+/*
+ * QTest testcase for parallel flash with AMD command set
+ *
+ * Copyright (c) 2018 Stephen Checkoway
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include 
+#include 
+#include "libqtest.h"
+
+/*
+ * To test the pflash_cfi02 device, we run QEMU with the musicpal machine with
+ * a pflash drive. This enables us to test some flash configurations, but not
+ * all. In particular, we're limited to a 16-bit wide flash device.
+ */
+
+#define MP_FLASH_SIZE_MAX (32 * 1024 * 1024)
+#define BASE_ADDR (0x1ULL - MP_FLASH_SIZE_MAX)
+
+#define FLASH_WIDTH 2
+#define CFI_ADDR (FLASH_WIDTH * 0x55)
+#define UNLOCK0_ADDR (FLASH_WIDTH * 0x)
+#define UNLOCK1_ADDR (FLASH_WIDTH * 0x2AAA)
+
+#define CFI_CMD 0x98
+#define UNLOCK0_CMD 0xAA
+#define UNLOCK1_CMD 0x55
+#define AUTOSELECT_CMD 0x90
+#define RESET_CMD 0xF0
+#define PROGRAM_CMD 0xA0
+#define SECTOR_ERASE_CMD 0x30
+#define CHIP_ERASE_CMD 0x10
+#define UNLOCK_BYPASS_CMD 0x20
+#define UNLOCK_BYPASS_RESET_CMD 0x00
+
+static char image_path[] = "/tmp/qtest.XX";
+
+static inline void flash_write(uint64_t byte_addr, uint16_t data)
+{
+qtest_writew(global_qtest, BASE_ADDR + byte_addr, data);
+}
+
+static inline uint16_t flash_read(uint64_t byte_addr)
+{
+return qtest_readw(global_qtest, BASE_ADDR + byte_addr);
+}
+
+static void unlock(void)
+{
+flash_write(UNLOCK0_ADDR, UNLOCK0_CMD);
+flash_write(UNLOCK1_ADDR, UNLOCK1_CMD);
+}
+
+static void reset(void)
+{
+flash_write(0, RESET_CMD);
+}
+
+static void sector_erase(uint64_t byte_addr)
+{
+unlock();
+flash_write(UNLOCK0_ADDR, 0x80);
+unlock();
+flash_write(byte_addr, SECTOR_ERASE_CMD);
+}
+
+static void wait_for_completion(uint64_t byte_addr)
+{
+/* If DQ6 is toggling, step the clock and ensure the toggle stops. */
+if ((flash_read(byte_addr) & 0x40) ^ (flash_read(byte_addr) & 0x40)) {
+/* Wait for erase or program to finish. */
+clock_step_next();
+/* Ensure that DQ6 has stopped toggling. */
+g_assert_cmpint(flash_read(byte_addr), ==, flash_read(byte_addr));
+}
+}
+
+static void bypass_program(uint64_t byte_addr, uint16_t data)
+{
+flash_write(UNLOCK0_ADDR, PROGRAM_CMD);
+flash_write(byte_addr, data);
+/*
+ * Data isn't valid until DQ6 stops toggling. We don't model this as
+ * writes are immediate, but if this changes in the future, we can wait
+ * until the program is complete.
+ */
+wait_for_completion(byte_addr);
+}
+
+static void program(uint64_t byte_addr, uint16_t data)
+{
+unlock();
+bypass_program(byte_addr, data);
+}
+
+static void chip_erase(void)
+{
+unlock();
+flash_write(UNLOCK0_ADDR, 0x80);
+unlock();
+flash_write(UNLOCK0_ADDR, SECTOR_ERASE_CMD);
+}
+
+static void test_flash(void)
+{
+global_qtest = qtest_initf("-M musicpal,accel=qtest "
+   "-drive 
if=pflash,file=%s,format=raw,copy-on-read",
+   image_path);
+/* Check the IDs. */
+unlock();
+flash_write(UNLOCK0_ADDR, AUTOSELECT_CMD);
+g_assert_cmpint(flash_read(FLASH_WIDTH * 0x), ==, 0x00BF);
+

[Qemu-devel] [PATCH v3 05/10] block/pflash_cfi02: Implement nonuniform sector sizes

2019-04-17 Thread Stephen Checkoway
Some flash chips support sectors of different sizes. For example, the
AMD AM29LV160DT has 31 64 kB sectors, one 32 kB sector, two 8 kB
sectors, and a 16 kB sector, in that order. The AM29LV160DB has those in
the reverse order.

The `num-blocks` and `sector-length` properties work exactly as they did
before: a flash device with uniform sector lengths. To get non-uniform
sector lengths for up to four regions, the following properties may be
set
- region 0. `num-blocks0` and `sector-length0`;
- region 1. `num-blocks1` and `sector-length1`;
- region 2. `num-blocks2` and `sector-length2`; and
- region 3. `num-blocks3` and `sector-length3`.

If the uniform and nonuniform properties are set, then both must specify
a flash device with the same total size. It would be better to disallow
both being set, or make `num-blocks0` and `sector-length0` alias
`num-blocks` and `sector-length`, but that would make testing currently
impossible.

Signed-off-by: Stephen Checkoway 
---
 hw/block/pflash_cfi02.c   | 177 +---
 tests/pflash-cfi02-test.c | 185 --
 2 files changed, 265 insertions(+), 97 deletions(-)

diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index 101628b4ec..c4efbe8cdf 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -28,7 +28,6 @@
  * - unlock bypass command
  * - CFI queries
  *
- * It does not implement boot blocs with reduced size
  * It does not implement software data protection as found in many real chips
  * It does not implement erase suspend/resume commands
  * It does not implement multiple sectors erase
@@ -55,6 +54,13 @@ do {   \
 
 #define PFLASH_LAZY_ROMD_THRESHOLD 42
 
+/*
+ * The size of the cfi_table indirectly depends on this and the start of the
+ * PRI table directly depends on it. 4 is the maximum size (and also what
+ * seems common) without changing the PRT table address.
+ */
+#define PFLASH_MAX_ERASE_REGIONS 4
+
 /* Special write cycle for CFI queries. */
 #define WCYCLE_CFI 7
 
@@ -64,8 +70,10 @@ struct PFlashCFI02 {
 /*< public >*/
 
 BlockBackend *blk;
-uint32_t sector_len;
-uint32_t nb_blocs;
+uint32_t uniform_nb_blocs;
+uint32_t uniform_sector_len;
+uint32_t nb_blocs[PFLASH_MAX_ERASE_REGIONS];
+uint32_t sector_len[PFLASH_MAX_ERASE_REGIONS];
 uint64_t total_len;
 uint64_t interleave_multiplier;
 uint8_t mappings;
@@ -86,7 +94,7 @@ struct PFlashCFI02 {
 uint16_t ident3;
 uint16_t unlock_addr0;
 uint16_t unlock_addr1;
-uint8_t cfi_table[0x52];
+uint8_t cfi_table[0x4D];
 QEMUTimer timer;
 /* The device replicates the flash memory across its memory space.  Emulate
  * that by having a container (.mem) filled with an array of aliases
@@ -189,6 +197,25 @@ static uint64_t pflash_data_read(PFlashCFI02 *pfl, hwaddr 
offset,
 return ret;
 }
 
+/*
+ * offset should be a byte offset of the QEMU device and _not_ a device
+ * offset.
+ */
+static uint32_t pflash_sector_len(PFlashCFI02 *pfl, hwaddr offset)
+{
+assert(offset < pfl->total_len);
+int nb_regions = pfl->cfi_table[0x2C];
+hwaddr addr = 0;
+for (int i = 0; i < nb_regions; ++i) {
+uint64_t region_size = (uint64_t)pfl->nb_blocs[i] * pfl->sector_len[i];
+if (addr <= offset && offset < addr + region_size) {
+return pfl->sector_len[i];
+}
+addr += region_size;
+}
+abort();
+}
+
 static uint64_t pflash_read(void *opaque, hwaddr offset, unsigned int width)
 {
 PFlashCFI02 *pfl = opaque;
@@ -285,6 +312,7 @@ static void pflash_write(void *opaque, hwaddr offset, 
uint64_t value,
 PFlashCFI02 *pfl = opaque;
 uint8_t *p;
 uint8_t cmd;
+uint32_t sector_len;
 
 cmd = value;
 if (pfl->cmd != 0xA0) {
@@ -446,12 +474,14 @@ static void pflash_write(void *opaque, hwaddr offset, 
uint64_t value,
 case 0x30:
 /* Sector erase */
 p = pfl->storage;
-offset &= ~(pfl->sector_len - 1);
-DPRINTF("%s: start sector erase at " TARGET_FMT_plx "\n", __func__,
-offset);
+sector_len = pflash_sector_len(pfl, offset);
+offset &= ~(sector_len - 1);
+DPRINTF("%s: start sector erase at %0*" PRIx64 "-%0*" PRIx64 "\n",
+__func__, pfl->bank_width * 2, offset,
+pfl->bank_width * 2, offset + sector_len - 1);
 if (!pfl->ro) {
-memset(p + offset, 0xFF, pfl->sector_len);
-pflash_update(pfl, offset, pfl->sector_len);
+memset(p + offset, 0xFF, sector_len);
+pflash_update(pfl, offset, sector_len);
 }
 set_dq7(pfl, 0x00);
 /* Let's wait 1/2 second before sector erase is done */
@@ -515,15 +545,14 @@ static const MemoryRegionOps pflash_cfi02_ops = {
 static void pflash_cfi02_realize(DeviceState *dev, 

[Qemu-devel] [PATCH v3 06/10] block/pflash_cfi02: Fix CFI in autoselect mode

2019-04-17 Thread Stephen Checkoway
After a flash device enters CFI mode from autoselect mode, the reset
command returns the device to autoselect mode. An additional reset
command is necessary to return to read array mode.

Signed-off-by: Stephen Checkoway 
---
 hw/block/pflash_cfi02.c   | 21 +
 tests/pflash-cfi02-test.c | 39 +++
 2 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index c4efbe8cdf..be10036886 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -61,8 +61,9 @@ do {   \
  */
 #define PFLASH_MAX_ERASE_REGIONS 4
 
-/* Special write cycle for CFI queries. */
+/* Special write cycles for CFI queries. */
 #define WCYCLE_CFI 7
+#define WCYCLE_AUTOSELECT_CFI 8
 
 struct PFlashCFI02 {
 /*< private >*/
@@ -325,6 +326,12 @@ static void pflash_write(void *opaque, hwaddr offset, 
uint64_t value,
 }
 
 if (cmd == 0xF0) {
+if (pfl->wcycle == WCYCLE_AUTOSELECT_CFI) {
+/* Return to autoselect mode. */
+pfl->wcycle = 3;
+pfl->cmd = 0x90;
+return;
+}
 goto reset_flash;
 }
 }
@@ -350,7 +357,6 @@ static void pflash_write(void *opaque, hwaddr offset, 
uint64_t value,
 /* We're in read mode */
 check_unlock0:
 if (masked_addr == 0x55 && cmd == 0x98) {
-enter_CFI_mode:
 /* Enter CFI query mode */
 pfl->wcycle = WCYCLE_CFI;
 pfl->cmd = 0x98;
@@ -427,9 +433,15 @@ static void pflash_write(void *opaque, hwaddr offset, 
uint64_t value,
 /* Unlock bypass reset */
 goto reset_flash;
 }
-/* We can enter CFI query mode from autoselect mode */
+/*
+ * We can enter CFI query mode from autoselect mode, but we must
+ * return to autoselect mode after a reset.
+ */
 if (masked_addr == 0x55 && cmd == 0x98) {
-goto enter_CFI_mode;
+/* Enter autoselect CFI query mode */
+pfl->wcycle = WCYCLE_AUTOSELECT_CFI;
+pfl->cmd = 0x98;
+return;
 }
 /* No break here */
 default:
@@ -510,6 +522,7 @@ static void pflash_write(void *opaque, hwaddr offset, 
uint64_t value,
 }
 break;
 case WCYCLE_CFI: /* Special value for CFI queries */
+case WCYCLE_AUTOSELECT_CFI:
 DPRINTF("%s: invalid write in CFI query mode\n", __func__);
 goto reset_flash;
 default:
diff --git a/tests/pflash-cfi02-test.c b/tests/pflash-cfi02-test.c
index 82bc5695e1..4039647604 100644
--- a/tests/pflash-cfi02-test.c
+++ b/tests/pflash-cfi02-test.c
@@ -480,6 +480,42 @@ static void test_geometry(const void *opaque)
 qtest_quit(qtest);
 }
 
+/*
+ * Test that
+ * 1. enter autoselect mode;
+ * 2. enter CFI mode; and then
+ * 3. exit CFI mode
+ * leaves the flash device in autoselect mode.
+ */
+static void test_cfi_in_autoselect(const void *opaque)
+{
+const FlashConfig *config = opaque;
+QTestState *qtest = qtest_initf("-M musicpal,accel=qtest"
+" -drive if=pflash,file=%s,format=raw,"
+"copy-on-read",
+image_path);
+FlashConfig explicit_config = expand_config_defaults(config);
+explicit_config.qtest = qtest;
+const FlashConfig *c = _config;
+
+/* 1. Enter autoselect. */
+unlock(c);
+flash_cmd(c, UNLOCK0_ADDR, AUTOSELECT_CMD);
+g_assert_cmpint(flash_query(c, FLASH_ADDR(0)), ==, replicate(c, 0xBF));
+
+/* 2. Enter CFI. */
+flash_cmd(c, CFI_ADDR, CFI_CMD);
+g_assert_cmpint(flash_query(c, FLASH_ADDR(0x10)), ==, replicate(c, 'Q'));
+g_assert_cmpint(flash_query(c, FLASH_ADDR(0x11)), ==, replicate(c, 'R'));
+g_assert_cmpint(flash_query(c, FLASH_ADDR(0x12)), ==, replicate(c, 'Y'));
+
+/* 3. Exit CFI. */
+reset(c);
+g_assert_cmpint(flash_query(c, FLASH_ADDR(0)), ==, replicate(c, 0xBF));
+
+qtest_quit(qtest);
+}
+
 static void cleanup(void *opaque)
 {
 unlink(image_path);
@@ -605,6 +641,9 @@ int main(int argc, char **argv)
 qtest_add_data_func(path, config, test_geometry);
 g_free(path);
 }
+
+qtest_add_data_func("pflash-cfi02/cfi-in-autoselect", [0],
+test_cfi_in_autoselect);
 int result = g_test_run();
 cleanup(NULL);
 return result;
-- 
2.20.1 (Apple Git-117)




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

2019-04-17 Thread Stephen Checkoway
The goal of this patch series implement the following AMD command-set parallel
flash functionality:
- flash interleaving;
- nonuniform sector sizes;
- erase suspend/resume commands; and
- multi-sector erase.

During refactoring and implementation, I discovered several bugs that are
fixed here as well:
- flash commands use only 11-bits of the address in most cases, but the
  current code uses all of them [1];
- entering CFI mode from autoselect mode and then exiting CFI mode should
  return the chip to autoselect mode, but the current code returns to read
  array mode; and
- reset command should be ignored during sector/chip erase, but the current
  code performs the reset.

The first patch in the series adds a test for the existing behavior. Tests for
additional behavior/bug fixes are added in the relevant patch.

1. I found firmware in the wild that relies on the 11-bit address behavior,
   probably due to a bug in the firmware itself.

Changes from v1:
- Fix missing spaces around *, -, and ?;
- Fix missing Signed-off-by line on patch 7; and
- Replace use of errc with g_printerr and exit.

Changes from v2:
- Remove global_qtest from tests; and
- Test the CFI table changes.

Stephen Checkoway (10):
  block/pflash_cfi02: Add test for supported commands
  block/pflash_cfi02: Refactor, NFC intended
  block/pflash_cfi02: Fix command address comparison
  block/pflash_cfi02: Implement intereleaved flash devices
  block/pflash_cfi02: Implement nonuniform sector sizes
  block/pflash_cfi02: Fix CFI in autoselect mode
  block/pflash_cfi02: Fix reset command not ignored during erase
  block/pflash_cfi02: Implement multi-sector erase
  block/pflash_cfi02: Implement erase suspend/resume
  block/pflash_cfi02: Use the chip erase time specified in the CFI table

 hw/block/pflash_cfi02.c   | 843 +++---
 tests/Makefile.include|   2 +
 tests/pflash-cfi02-test.c | 815 
 3 files changed, 1423 insertions(+), 237 deletions(-)
 create mode 100644 tests/pflash-cfi02-test.c

-- 
2.20.1 (Apple Git-117)




[Qemu-devel] [PATCH v3 02/10] block/pflash_cfi02: Refactor, NFC intended

2019-04-17 Thread Stephen Checkoway
Simplify and refactor for upcoming commits. In particular, pull out all
of the code to modify the status into simple helper functions. Status
handling becomes more complex once multiple chips are interleaved to
produce a single device.

No change in functionality is intended with this commit.

Signed-off-by: Stephen Checkoway 
---
 hw/block/pflash_cfi02.c | 221 +---
 1 file changed, 95 insertions(+), 126 deletions(-)

diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index f2c6201f81..4b7af71806 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -46,18 +46,19 @@
 #include "hw/sysbus.h"
 #include "trace.h"
 
-//#define PFLASH_DEBUG
-#ifdef PFLASH_DEBUG
+#define PFLASH_DEBUG false
 #define DPRINTF(fmt, ...)  \
 do {   \
-fprintf(stderr, "PFLASH: " fmt , ## __VA_ARGS__);   \
+if (PFLASH_DEBUG) {\
+fprintf(stderr, "PFLASH: " fmt, ## __VA_ARGS__);   \
+}  \
 } while (0)
-#else
-#define DPRINTF(fmt, ...) do { } while (0)
-#endif
 
 #define PFLASH_LAZY_ROMD_THRESHOLD 42
 
+/* Special write cycle for CFI queries. */
+#define WCYCLE_CFI 7
+
 struct PFlashCFI02 {
 /*< private >*/
 SysBusDevice parent_obj;
@@ -97,6 +98,31 @@ struct PFlashCFI02 {
 void *storage;
 };
 
+/*
+ * Toggle status bit DQ7.
+ */
+static inline void toggle_dq7(PFlashCFI02 *pfl)
+{
+pfl->status ^= 0x80;
+}
+
+/*
+ * Set status bit DQ7 to bit 7 of value.
+ */
+static inline void set_dq7(PFlashCFI02 *pfl, uint8_t value)
+{
+pfl->status &= 0x7F;
+pfl->status |= value & 0x80;
+}
+
+/*
+ * Toggle status bit DQ6.
+ */
+static inline void toggle_dq6(PFlashCFI02 *pfl)
+{
+pfl->status ^= 0x40;
+}
+
 /*
  * Set up replicated mappings of the same region.
  */
@@ -126,7 +152,7 @@ static void pflash_timer (void *opaque)
 
 trace_pflash_timer_expired(pfl->cmd);
 /* Reset flash */
-pfl->status ^= 0x80;
+toggle_dq7(pfl);
 if (pfl->bypass) {
 pfl->wcycle = 2;
 } else {
@@ -136,12 +162,34 @@ static void pflash_timer (void *opaque)
 pfl->cmd = 0;
 }
 
-static uint32_t pflash_read(PFlashCFI02 *pfl, hwaddr offset,
-int width, int be)
+/*
+ * Read data from flash.
+ */
+static uint64_t pflash_data_read(PFlashCFI02 *pfl, hwaddr offset,
+ unsigned int width)
 {
+uint8_t *p = (uint8_t *)pfl->storage + offset;
+uint64_t ret = pfl->be ? ldn_be_p(p, width) : ldn_le_p(p, width);
+/* XXX: Need a trace_pflash_data_read(offset, ret, width) */
+switch (width) {
+case 1:
+trace_pflash_data_read8(offset, ret);
+break;
+case 2:
+trace_pflash_data_read16(offset, ret);
+break;
+case 4:
+trace_pflash_data_read32(offset, ret);
+break;
+}
+return ret;
+}
+
+static uint64_t pflash_read(void *opaque, hwaddr offset, unsigned int width)
+{
+PFlashCFI02 *pfl = opaque;
 hwaddr boff;
-uint32_t ret;
-uint8_t *p;
+uint64_t ret;
 
 ret = -1;
 trace_pflash_read(offset, pfl->cmd, width, pfl->wcycle);
@@ -166,39 +214,8 @@ static uint32_t pflash_read(PFlashCFI02 *pfl, hwaddr 
offset,
 case 0x80:
 /* We accept reads during second unlock sequence... */
 case 0x00:
-flash_read:
 /* Flash area read */
-p = pfl->storage;
-switch (width) {
-case 1:
-ret = p[offset];
-trace_pflash_data_read8(offset, ret);
-break;
-case 2:
-if (be) {
-ret = p[offset] << 8;
-ret |= p[offset + 1];
-} else {
-ret = p[offset];
-ret |= p[offset + 1] << 8;
-}
-trace_pflash_data_read16(offset, ret);
-break;
-case 4:
-if (be) {
-ret = p[offset] << 24;
-ret |= p[offset + 1] << 16;
-ret |= p[offset + 2] << 8;
-ret |= p[offset + 3];
-} else {
-ret = p[offset];
-ret |= p[offset + 1] << 8;
-ret |= p[offset + 2] << 16;
-ret |= p[offset + 3] << 24;
-}
-trace_pflash_data_read32(offset, ret);
-break;
-}
+ret = pflash_data_read(pfl, offset, width);
 break;
 case 0x90:
 /* flash ID read */
@@ -213,23 +230,23 @@ static uint32_t pflash_read(PFlashCFI02 *pfl, hwaddr 
offset,
 case 0x0E:
 case 0x0F:
 ret = boff & 0x01 ? pfl->ident3 : pfl->ident2;
-if (ret == (uint8_t)-1) {
-goto flash_read;
+if (ret != (uint8_t)-1) {
+break;
 }
-break;
+/* Fall through to data read. */
 default:
-   

[Qemu-devel] [Bug 1825002] Re: "qemu: Unexpected FPU mode" since 0c1bbedc10e86ea9366b6af8c5520fafa3266b2f

2019-04-17 Thread Daniel Santos
Thanks Peter.  I was just reading up on the CVE process and I agree.
Obviously, it's dangerous to use uninitialized values, but that doesn't
necessarily make it a vulnerability.

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

Title:
  "qemu: Unexpected FPU mode" since
  0c1bbedc10e86ea9366b6af8c5520fafa3266b2f

Status in QEMU:
  New

Bug description:
  This happens every time I attempt to chroot into a gentoo-mips image
  unless I load the executable via ld.so

  /home (root)# chroot gentoo-mips32r2el /bin/sh
  qemu: Unexpected FPU mode
  /home (root)# chroot gentoo-mips32r2el /lib/ld-2.19.so /bin/sh
  sh-4.2# exit
  /home (root)# 

  I don't know the underlying cause, but keep in mind that we may lie
  and claim to have an FPU when our CPU doesn't because of kernel
  emulation that may not be present in the host kernel.  Don't know if
  that's related.

  I get this with various gentoo-mips stage3 tarballs, but not with
  OpenWRT.  (e.g.,
  https://gentoo.osuosl.org/experimental/mips/stages/mips32r2el/2014)


  # emerge --info app-emulation/qemu
  Portage 2.3.51 (python 3.6.5-final-0, 
default/linux/amd64/17.0/desktop/plasma, gcc-8.2.0, glibc-2.27-r6, 
4.14.96-gentoo x86_64)
  =
   System Settings
  =
  System uname: 
Linux-4.14.96-gentoo-x86_64-AMD_Ryzen_7_2700X_Eight-Core_Processor-with-gentoo-2.6
  KiB Mem:32890732 total,   3480024 free
  KiB Swap:   16777212 total,  10575592 free
  Timestamp of repository gentoo: Thu, 11 Apr 2019 06:00:01 +
  Head commit of repository gentoo: 66eaaa28926103e690db0699466a274a17ab1979
  sh bash 4.4_p23-r1
  ld GNU ld (Gentoo 2.30 p5) 2.30.0
  distcc 3.3.2 x86_64-pc-linux-gnu [disabled]
  ccache version 3.3.4 [disabled]
  app-shells/bash:  4.4_p23-r1::gentoo
  dev-java/java-config: 2.2.0-r4::gentoo
  dev-lang/perl:5.26.2::gentoo
  dev-lang/python:  2.7.15::gentoo, 3.6.5::gentoo
  dev-util/ccache:  3.3.4-r1::gentoo
  dev-util/cmake:   3.9.6::gentoo
  dev-util/pkgconfig:   0.29.2::gentoo
  sys-apps/baselayout:  2.6-r1::gentoo
  sys-apps/openrc:  0.38.3-r1::gentoo
  sys-apps/sandbox: 2.13::gentoo
  sys-devel/autoconf:   2.13-r1::gentoo, 2.64-r1::gentoo, 2.69-r4::gentoo
  sys-devel/automake:   1.11.6-r3::gentoo, 1.13.4-r2::gentoo, 
1.15.1-r2::gentoo, 1.16.1-r1::gentoo
  sys-devel/binutils:   2.30-r4::gentoo
  sys-devel/gcc:4.9.4::gentoo, 5.4.0-r6::gentoo, 6.4.0-r5::gentoo, 
7.3.0-r6::gentoo, 8.1.0-r3::gentoo, 8.2.0-r6::gentoo, 8.3.0::gentoo
  sys-devel/gcc-config: 2.0::gentoo
  sys-devel/libtool:2.4.6-r3::gentoo
  sys-devel/make:   4.2.1-r4::gentoo
  sys-kernel/linux-headers: 4.14-r1::gentoo (virtual/os-headers)
  sys-libs/glibc:   2.27-r6::gentoo
  Repositories:

  gentoo
  location: /usr/portage
  sync-type: rsync
  sync-uri: rsync://rsync.gentoo.org/gentoo-portage
  priority: -1000
  sync-rsync-verify-jobs: 1
  sync-rsync-extra-opts: 
  sync-rsync-verify-metamanifest: yes
  sync-rsync-verify-max-age: 24

  love-local
  location: /usr/local/portage
  masters: gentoo
  priority: 0

  chaoslab
  location: /var/lib/layman/chaoslab
  masters: gentoo
  priority: 50

  java
  location: /var/lib/layman/java
  masters: gentoo
  priority: 50

  steam-overlay
  location: /var/lib/layman/steam-overlay
  masters: gentoo
  priority: 50

  zugaina
  location: /var/lib/layman/zugaina
  masters: gentoo
  priority: 50

  ACCEPT_KEYWORDS="amd64"
  ACCEPT_LICENSE="* -@EULA"
  CBUILD="x86_64-pc-linux-gnu"
  CFLAGS="-march=native -O2 -ggdb3 -pipe"
  CHOST="x86_64-pc-linux-gnu"
  CONFIG_PROTECT="/etc /usr/lib64/libreoffice/program/sofficerc 
/usr/share/config /usr/share/gnupg/qualified.txt"
  CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d 
/etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild 
/etc/sandbox.d /etc/splash /etc/terminfo /etc/texmf/language.dat.d 
/etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
  CXXFLAGS="-march=native -O2 -ggdb3 -pipe"
  DISTDIR="/mnt/large/distfiles"
  EMERGE_DEFAULT_OPTS="-j3 --load-average=17.5 --with-bdeps=y --autounmask=n"
  ENV_UNSET="DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN PERL5LIB PERL5OPT 
PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME 
XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
  FCFLAGS="-O2 -pipe"
  FEATURES="assume-digests binpkg-logs buildpkg candy cgroup 
compress-build-logs compressdebug config-protect-if-modified distlocks 
ebuild-locks fixlafiles installsources ipc-sandbox merge-sync multilib-strict 
network-sandbox news parallel-fetch preserve-libs protect-owned sandbox sfperms 

[Qemu-devel] [Bug 1825002] Re: "qemu: Unexpected FPU mode" since 0c1bbedc10e86ea9366b6af8c5520fafa3266b2f

2019-04-17 Thread Daniel Santos
And thank you Thomas for the instructions!

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

Title:
  "qemu: Unexpected FPU mode" since
  0c1bbedc10e86ea9366b6af8c5520fafa3266b2f

Status in QEMU:
  New

Bug description:
  This happens every time I attempt to chroot into a gentoo-mips image
  unless I load the executable via ld.so

  /home (root)# chroot gentoo-mips32r2el /bin/sh
  qemu: Unexpected FPU mode
  /home (root)# chroot gentoo-mips32r2el /lib/ld-2.19.so /bin/sh
  sh-4.2# exit
  /home (root)# 

  I don't know the underlying cause, but keep in mind that we may lie
  and claim to have an FPU when our CPU doesn't because of kernel
  emulation that may not be present in the host kernel.  Don't know if
  that's related.

  I get this with various gentoo-mips stage3 tarballs, but not with
  OpenWRT.  (e.g.,
  https://gentoo.osuosl.org/experimental/mips/stages/mips32r2el/2014)


  # emerge --info app-emulation/qemu
  Portage 2.3.51 (python 3.6.5-final-0, 
default/linux/amd64/17.0/desktop/plasma, gcc-8.2.0, glibc-2.27-r6, 
4.14.96-gentoo x86_64)
  =
   System Settings
  =
  System uname: 
Linux-4.14.96-gentoo-x86_64-AMD_Ryzen_7_2700X_Eight-Core_Processor-with-gentoo-2.6
  KiB Mem:32890732 total,   3480024 free
  KiB Swap:   16777212 total,  10575592 free
  Timestamp of repository gentoo: Thu, 11 Apr 2019 06:00:01 +
  Head commit of repository gentoo: 66eaaa28926103e690db0699466a274a17ab1979
  sh bash 4.4_p23-r1
  ld GNU ld (Gentoo 2.30 p5) 2.30.0
  distcc 3.3.2 x86_64-pc-linux-gnu [disabled]
  ccache version 3.3.4 [disabled]
  app-shells/bash:  4.4_p23-r1::gentoo
  dev-java/java-config: 2.2.0-r4::gentoo
  dev-lang/perl:5.26.2::gentoo
  dev-lang/python:  2.7.15::gentoo, 3.6.5::gentoo
  dev-util/ccache:  3.3.4-r1::gentoo
  dev-util/cmake:   3.9.6::gentoo
  dev-util/pkgconfig:   0.29.2::gentoo
  sys-apps/baselayout:  2.6-r1::gentoo
  sys-apps/openrc:  0.38.3-r1::gentoo
  sys-apps/sandbox: 2.13::gentoo
  sys-devel/autoconf:   2.13-r1::gentoo, 2.64-r1::gentoo, 2.69-r4::gentoo
  sys-devel/automake:   1.11.6-r3::gentoo, 1.13.4-r2::gentoo, 
1.15.1-r2::gentoo, 1.16.1-r1::gentoo
  sys-devel/binutils:   2.30-r4::gentoo
  sys-devel/gcc:4.9.4::gentoo, 5.4.0-r6::gentoo, 6.4.0-r5::gentoo, 
7.3.0-r6::gentoo, 8.1.0-r3::gentoo, 8.2.0-r6::gentoo, 8.3.0::gentoo
  sys-devel/gcc-config: 2.0::gentoo
  sys-devel/libtool:2.4.6-r3::gentoo
  sys-devel/make:   4.2.1-r4::gentoo
  sys-kernel/linux-headers: 4.14-r1::gentoo (virtual/os-headers)
  sys-libs/glibc:   2.27-r6::gentoo
  Repositories:

  gentoo
  location: /usr/portage
  sync-type: rsync
  sync-uri: rsync://rsync.gentoo.org/gentoo-portage
  priority: -1000
  sync-rsync-verify-jobs: 1
  sync-rsync-extra-opts: 
  sync-rsync-verify-metamanifest: yes
  sync-rsync-verify-max-age: 24

  love-local
  location: /usr/local/portage
  masters: gentoo
  priority: 0

  chaoslab
  location: /var/lib/layman/chaoslab
  masters: gentoo
  priority: 50

  java
  location: /var/lib/layman/java
  masters: gentoo
  priority: 50

  steam-overlay
  location: /var/lib/layman/steam-overlay
  masters: gentoo
  priority: 50

  zugaina
  location: /var/lib/layman/zugaina
  masters: gentoo
  priority: 50

  ACCEPT_KEYWORDS="amd64"
  ACCEPT_LICENSE="* -@EULA"
  CBUILD="x86_64-pc-linux-gnu"
  CFLAGS="-march=native -O2 -ggdb3 -pipe"
  CHOST="x86_64-pc-linux-gnu"
  CONFIG_PROTECT="/etc /usr/lib64/libreoffice/program/sofficerc 
/usr/share/config /usr/share/gnupg/qualified.txt"
  CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d 
/etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild 
/etc/sandbox.d /etc/splash /etc/terminfo /etc/texmf/language.dat.d 
/etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
  CXXFLAGS="-march=native -O2 -ggdb3 -pipe"
  DISTDIR="/mnt/large/distfiles"
  EMERGE_DEFAULT_OPTS="-j3 --load-average=17.5 --with-bdeps=y --autounmask=n"
  ENV_UNSET="DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN PERL5LIB PERL5OPT 
PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME 
XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
  FCFLAGS="-O2 -pipe"
  FEATURES="assume-digests binpkg-logs buildpkg candy cgroup 
compress-build-logs compressdebug config-protect-if-modified distlocks 
ebuild-locks fixlafiles installsources ipc-sandbox merge-sync multilib-strict 
network-sandbox news parallel-fetch preserve-libs protect-owned sandbox sfperms 
split-elog split-log splitdebug strict strict-keepdir unknown-features-warn 
unmerge-logs unmerge-orphans userfetch userpriv usersandbox 

Re: [Qemu-devel] [PATCH v7 0/6] target/mips: Optimize MSA interleave instructions

2019-04-17 Thread Aleksandar Markovic
> From: Mateja Marjanovic 
> Subject: [PATCH v7 0/6] target/mips: Optimize MSA interleave instructions
> 
> From: Mateja Marjanovic 
> 
> Optimize and refactor MSA instructions ILVEV.,
> ILVOD., ILVL. and ILVR..

Patch number 5/6 seems to be for some reason lost. Please resend the
complete series.

Thanks,
Aleksandar



Re: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around fprintf_function

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



Hi,

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

Message-id: 20190417191805.28198-1-arm...@redhat.com
Subject: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around 
fprintf_function
Type: series

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

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]patchew/20190417191805.28198-1-arm...@redhat.com -> 
patchew/20190417191805.28198-1-arm...@redhat.com
Switched to a new branch 'test'
db19e834f8 include: Move fprintf_function to disas/
4413299b4d disas: Rename include/disas/bfd.h back to include/disas/dis-asm.h
4daa71b4be monitor: Clean up how monitor_disas() funnels output to monitor
8db320f550 qom/cpu: Simplify how CPUClass:cpu_dump_state() prints
b71147d0c2 qemu-print: New qemu_fprintf(), qemu_vfprintf()
27a5a25b67 qom/cpu: Simplify how CPUClass::dump_statistics() prints
a83cbb831d target/i386: Simplify how x86_cpu_dump_local_apic_state() prints
245613cc1b target: Clean up how the dump_mmu() print
10998140d5 target: Simplify how the TARGET_cpu_list() print
2e76bc9d7c memory: Clean up how mtree_info() prints
fef413a9bc block/qapi: Clean up how we print to monitor or stdout
72de8879b2 qsp: Simplify how qsp_report() prints
89b234381a tcg: Simplify how dump_drift_info() prints
511085a3f7 tcg: Simplify how dump_exec_info() prints
8a89bb3a52 tcg: Simplify how dump_opcount_info() prints
d8a29469b3 trace: Simplify how st_print_trace_file_status() prints
d1ffc558ad include: Include fprintf-fn.h only where needed

=== OUTPUT BEGIN ===
1/17 Checking commit d1ffc558ada9 (include: Include fprintf-fn.h only where 
needed)
2/17 Checking commit d8a29469b38b (trace: Simplify how 
st_print_trace_file_status() prints)
3/17 Checking commit 8a89bb3a523a (tcg: Simplify how dump_opcount_info() prints)
4/17 Checking commit 511085a3f704 (tcg: Simplify how dump_exec_info() prints)
5/17 Checking commit 89b234381aef (tcg: Simplify how dump_drift_info() prints)
6/17 Checking commit 72de8879b2a5 (qsp: Simplify how qsp_report() prints)
7/17 Checking commit fef413a9bc34 (block/qapi: Clean up how we print to monitor 
or stdout)
8/17 Checking commit 2e76bc9d7c92 (memory: Clean up how mtree_info() prints)
9/17 Checking commit 10998140d529 (target: Simplify how the TARGET_cpu_list() 
print)
10/17 Checking commit 245613cc1b1e (target: Clean up how the dump_mmu() print)
WARNING: line over 80 characters
#950: FILE: target/xtensa/mmu_helper.c:784:
+qemu_printf("\tVaddr   Paddr   ASID  Attr RWX 
Cache\n"

total: 0 errors, 1 warnings, 848 lines checked

Patch 10/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
11/17 Checking commit a83cbb831dfb (target/i386: Simplify how 
x86_cpu_dump_local_apic_state() prints)
12/17 Checking commit 27a5a25b6773 (qom/cpu: Simplify how 
CPUClass::dump_statistics() prints)
13/17 Checking commit b71147d0c208 (qemu-print: New qemu_fprintf(), 
qemu_vfprintf())
14/17 Checking commit 8db320f55011 (qom/cpu: Simplify how 
CPUClass:cpu_dump_state() prints)
ERROR: line over 90 characters
#1051: FILE: target/i386/helper.c:419:
+qemu_fprintf(f, "RAX=%016" PRIx64 " RBX=%016" PRIx64 " RCX=%016" 
PRIx64 " RDX=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1052: FILE: target/i386/helper.c:420:
+ "RSI=%016" PRIx64 " RDI=%016" PRIx64 " RBP=%016" PRIx64 " 
RSP=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1053: FILE: target/i386/helper.c:421:
+ "R8 =%016" PRIx64 " R9 =%016" PRIx64 " R10=%016" PRIx64 " 
R11=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1054: FILE: target/i386/helper.c:422:
+ "R12=%016" PRIx64 " R13=%016" PRIx64 " R14=%016" PRIx64 " 
R15=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1055: FILE: target/i386/helper.c:423:
+ "RIP=%016" PRIx64 " RFL=%08x [%c%c%c%c%c%c%c] CPL=%d 
II=%d A20=%d SMM=%d HLT=%d\n",

WARNING: line over 80 characters
#1163: FILE: target/i386/helper.c:494:
+qemu_fprintf(f, "CR0=%08x CR2=%016" PRIx64 " CR3=%016" PRIx64 " 
CR4=%08x\n",

WARNING: line over 80 characters
#1751: FILE: target/mips/translate.c:29791:
+qemu_fprintf(f, "CP0 Status  0x%08x Cause   0x%08x EPC0x" 
TARGET_FMT_lx "\n",

total: 5 errors, 2 warnings, 2551 lines checked

Patch 14/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

15/17 Checking commit 4daa71b4bee9 (monitor: Clean up how monitor_disas() 
funnels output to monitor)
16/17 

[Qemu-devel] [Bug 1825002] Re: "qemu: Unexpected FPU mode" since 0c1bbedc10e86ea9366b6af8c5520fafa3266b2f

2019-04-17 Thread Peter Maydell
This is certainly a bug, but it's not a a CVE, ie not a security bug.
The entire purpose of the linux-user mode is to run the guest ELF file
and let it perform whatever syscalls it likes -- it doesn't need to
exploit any kind of bug in the ELF loader to be able to control what the
process is doing.

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

Title:
  "qemu: Unexpected FPU mode" since
  0c1bbedc10e86ea9366b6af8c5520fafa3266b2f

Status in QEMU:
  New

Bug description:
  This happens every time I attempt to chroot into a gentoo-mips image
  unless I load the executable via ld.so

  /home (root)# chroot gentoo-mips32r2el /bin/sh
  qemu: Unexpected FPU mode
  /home (root)# chroot gentoo-mips32r2el /lib/ld-2.19.so /bin/sh
  sh-4.2# exit
  /home (root)# 

  I don't know the underlying cause, but keep in mind that we may lie
  and claim to have an FPU when our CPU doesn't because of kernel
  emulation that may not be present in the host kernel.  Don't know if
  that's related.

  I get this with various gentoo-mips stage3 tarballs, but not with
  OpenWRT.  (e.g.,
  https://gentoo.osuosl.org/experimental/mips/stages/mips32r2el/2014)


  # emerge --info app-emulation/qemu
  Portage 2.3.51 (python 3.6.5-final-0, 
default/linux/amd64/17.0/desktop/plasma, gcc-8.2.0, glibc-2.27-r6, 
4.14.96-gentoo x86_64)
  =
   System Settings
  =
  System uname: 
Linux-4.14.96-gentoo-x86_64-AMD_Ryzen_7_2700X_Eight-Core_Processor-with-gentoo-2.6
  KiB Mem:32890732 total,   3480024 free
  KiB Swap:   16777212 total,  10575592 free
  Timestamp of repository gentoo: Thu, 11 Apr 2019 06:00:01 +
  Head commit of repository gentoo: 66eaaa28926103e690db0699466a274a17ab1979
  sh bash 4.4_p23-r1
  ld GNU ld (Gentoo 2.30 p5) 2.30.0
  distcc 3.3.2 x86_64-pc-linux-gnu [disabled]
  ccache version 3.3.4 [disabled]
  app-shells/bash:  4.4_p23-r1::gentoo
  dev-java/java-config: 2.2.0-r4::gentoo
  dev-lang/perl:5.26.2::gentoo
  dev-lang/python:  2.7.15::gentoo, 3.6.5::gentoo
  dev-util/ccache:  3.3.4-r1::gentoo
  dev-util/cmake:   3.9.6::gentoo
  dev-util/pkgconfig:   0.29.2::gentoo
  sys-apps/baselayout:  2.6-r1::gentoo
  sys-apps/openrc:  0.38.3-r1::gentoo
  sys-apps/sandbox: 2.13::gentoo
  sys-devel/autoconf:   2.13-r1::gentoo, 2.64-r1::gentoo, 2.69-r4::gentoo
  sys-devel/automake:   1.11.6-r3::gentoo, 1.13.4-r2::gentoo, 
1.15.1-r2::gentoo, 1.16.1-r1::gentoo
  sys-devel/binutils:   2.30-r4::gentoo
  sys-devel/gcc:4.9.4::gentoo, 5.4.0-r6::gentoo, 6.4.0-r5::gentoo, 
7.3.0-r6::gentoo, 8.1.0-r3::gentoo, 8.2.0-r6::gentoo, 8.3.0::gentoo
  sys-devel/gcc-config: 2.0::gentoo
  sys-devel/libtool:2.4.6-r3::gentoo
  sys-devel/make:   4.2.1-r4::gentoo
  sys-kernel/linux-headers: 4.14-r1::gentoo (virtual/os-headers)
  sys-libs/glibc:   2.27-r6::gentoo
  Repositories:

  gentoo
  location: /usr/portage
  sync-type: rsync
  sync-uri: rsync://rsync.gentoo.org/gentoo-portage
  priority: -1000
  sync-rsync-verify-jobs: 1
  sync-rsync-extra-opts: 
  sync-rsync-verify-metamanifest: yes
  sync-rsync-verify-max-age: 24

  love-local
  location: /usr/local/portage
  masters: gentoo
  priority: 0

  chaoslab
  location: /var/lib/layman/chaoslab
  masters: gentoo
  priority: 50

  java
  location: /var/lib/layman/java
  masters: gentoo
  priority: 50

  steam-overlay
  location: /var/lib/layman/steam-overlay
  masters: gentoo
  priority: 50

  zugaina
  location: /var/lib/layman/zugaina
  masters: gentoo
  priority: 50

  ACCEPT_KEYWORDS="amd64"
  ACCEPT_LICENSE="* -@EULA"
  CBUILD="x86_64-pc-linux-gnu"
  CFLAGS="-march=native -O2 -ggdb3 -pipe"
  CHOST="x86_64-pc-linux-gnu"
  CONFIG_PROTECT="/etc /usr/lib64/libreoffice/program/sofficerc 
/usr/share/config /usr/share/gnupg/qualified.txt"
  CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d 
/etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild 
/etc/sandbox.d /etc/splash /etc/terminfo /etc/texmf/language.dat.d 
/etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
  CXXFLAGS="-march=native -O2 -ggdb3 -pipe"
  DISTDIR="/mnt/large/distfiles"
  EMERGE_DEFAULT_OPTS="-j3 --load-average=17.5 --with-bdeps=y --autounmask=n"
  ENV_UNSET="DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN PERL5LIB PERL5OPT 
PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME 
XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
  FCFLAGS="-O2 -pipe"
  FEATURES="assume-digests binpkg-logs buildpkg candy cgroup 
compress-build-logs compressdebug config-protect-if-modified distlocks 
ebuild-locks fixlafiles installsources 

Re: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around fprintf_function

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



Hi,

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

Message-id: 20190417191805.28198-1-arm...@redhat.com
Subject: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around 
fprintf_function
Type: series

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

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]patchew/20190417191805.28198-1-arm...@redhat.com -> 
patchew/20190417191805.28198-1-arm...@redhat.com
Switched to a new branch 'test'
90107e0ecd include: Move fprintf_function to disas/
08c75e94b5 disas: Rename include/disas/bfd.h back to include/disas/dis-asm.h
b35d73a420 monitor: Clean up how monitor_disas() funnels output to monitor
4f0c3493f6 qom/cpu: Simplify how CPUClass:cpu_dump_state() prints
68f63bc7a9 qemu-print: New qemu_fprintf(), qemu_vfprintf()
d41d47ee91 qom/cpu: Simplify how CPUClass::dump_statistics() prints
df73a8c8e6 target/i386: Simplify how x86_cpu_dump_local_apic_state() prints
edc6b2832c target: Clean up how the dump_mmu() print
482f38cd69 target: Simplify how the TARGET_cpu_list() print
18b22c842c memory: Clean up how mtree_info() prints
2dfb27eebe block/qapi: Clean up how we print to monitor or stdout
10b6b38b8a qsp: Simplify how qsp_report() prints
3a161a6792 tcg: Simplify how dump_drift_info() prints
e340f7a5c0 tcg: Simplify how dump_exec_info() prints
bdd8aea085 tcg: Simplify how dump_opcount_info() prints
0cb2f0 trace: Simplify how st_print_trace_file_status() prints
dcae6b30f1 include: Include fprintf-fn.h only where needed

=== OUTPUT BEGIN ===
1/17 Checking commit dcae6b30f156 (include: Include fprintf-fn.h only where 
needed)
2/17 Checking commit 0cb2f029 (trace: Simplify how 
st_print_trace_file_status() prints)
3/17 Checking commit bdd8aea085c0 (tcg: Simplify how dump_opcount_info() prints)
4/17 Checking commit e340f7a5c047 (tcg: Simplify how dump_exec_info() prints)
5/17 Checking commit 3a161a679275 (tcg: Simplify how dump_drift_info() prints)
6/17 Checking commit 10b6b38b8ae9 (qsp: Simplify how qsp_report() prints)
7/17 Checking commit 2dfb27eebe4e (block/qapi: Clean up how we print to monitor 
or stdout)
8/17 Checking commit 18b22c842ccb (memory: Clean up how mtree_info() prints)
9/17 Checking commit 482f38cd6965 (target: Simplify how the TARGET_cpu_list() 
print)
10/17 Checking commit edc6b2832c82 (target: Clean up how the dump_mmu() print)
WARNING: line over 80 characters
#950: FILE: target/xtensa/mmu_helper.c:784:
+qemu_printf("\tVaddr   Paddr   ASID  Attr RWX 
Cache\n"

total: 0 errors, 1 warnings, 848 lines checked

Patch 10/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
11/17 Checking commit df73a8c8e645 (target/i386: Simplify how 
x86_cpu_dump_local_apic_state() prints)
12/17 Checking commit d41d47ee915e (qom/cpu: Simplify how 
CPUClass::dump_statistics() prints)
13/17 Checking commit 68f63bc7a914 (qemu-print: New qemu_fprintf(), 
qemu_vfprintf())
14/17 Checking commit 4f0c3493f69b (qom/cpu: Simplify how 
CPUClass:cpu_dump_state() prints)
ERROR: line over 90 characters
#1051: FILE: target/i386/helper.c:419:
+qemu_fprintf(f, "RAX=%016" PRIx64 " RBX=%016" PRIx64 " RCX=%016" 
PRIx64 " RDX=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1052: FILE: target/i386/helper.c:420:
+ "RSI=%016" PRIx64 " RDI=%016" PRIx64 " RBP=%016" PRIx64 " 
RSP=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1053: FILE: target/i386/helper.c:421:
+ "R8 =%016" PRIx64 " R9 =%016" PRIx64 " R10=%016" PRIx64 " 
R11=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1054: FILE: target/i386/helper.c:422:
+ "R12=%016" PRIx64 " R13=%016" PRIx64 " R14=%016" PRIx64 " 
R15=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1055: FILE: target/i386/helper.c:423:
+ "RIP=%016" PRIx64 " RFL=%08x [%c%c%c%c%c%c%c] CPL=%d 
II=%d A20=%d SMM=%d HLT=%d\n",

WARNING: line over 80 characters
#1163: FILE: target/i386/helper.c:494:
+qemu_fprintf(f, "CR0=%08x CR2=%016" PRIx64 " CR3=%016" PRIx64 " 
CR4=%08x\n",

WARNING: line over 80 characters
#1751: FILE: target/mips/translate.c:29791:
+qemu_fprintf(f, "CP0 Status  0x%08x Cause   0x%08x EPC0x" 
TARGET_FMT_lx "\n",

total: 5 errors, 2 warnings, 2551 lines checked

Patch 14/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

15/17 Checking commit b35d73a42067 (monitor: Clean up how monitor_disas() 
funnels output to monitor)
16/17 

Re: [Qemu-devel] [PATCH] target/mips: Amend tests for MSA binary integer operations

2019-04-17 Thread Aleksandar Markovic
> From: Aleksandar Markovic
> Subject: Re: [PATCH] target/mips: Amend tests for MSA binary integer 
> operations
> 
> > From: Mateja Marjanovic 
> > Subject: [PATCH] target/mips: Amend tests for MSA binary integer operations
> >
> > Amend tests for certain MSA binary integer instructions
> > (for example DIV_S.B) by appending two missing test cases
> > to complete standard battery of 80 test cases for each
> > such instruction. Expected values were pulled from the
> > results of the MIPS64r6 machine that executed those
> > instruction, and QEMU emulation should produce the same
> > results.
> >
> > Signed-off-by: Mateja Marjanovic 
> > ---
> 
> I'm afraid your patch doesn't apply to the tip of the source tree:

Unfortunately, Mateja, even after resolving patch application conflicts,
the code doesn't build.

For example, wrappers for many MSA instructions are missing, and
there are other problems too.

The patch needs a major amending and refactoring, which I will do
tomorrow, or in next few days, so that you can focus on your other
remaining tasks (for example, explaining "active_fpu" role from
another series, and big endian host MSA test failures).

The good thing is that we will eventually expand test coverage.

Thanks,
Aleksandar


Re: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around fprintf_function

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



Hi,

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

Message-id: 20190417191805.28198-1-arm...@redhat.com
Subject: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around 
fprintf_function
Type: series

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

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]patchew/20190417191805.28198-1-arm...@redhat.com -> 
patchew/20190417191805.28198-1-arm...@redhat.com
Switched to a new branch 'test'
dbad74bf63 include: Move fprintf_function to disas/
8056ad6cd3 disas: Rename include/disas/bfd.h back to include/disas/dis-asm.h
90edbaf518 monitor: Clean up how monitor_disas() funnels output to monitor
9dacaf5ef7 qom/cpu: Simplify how CPUClass:cpu_dump_state() prints
5e6905625e qemu-print: New qemu_fprintf(), qemu_vfprintf()
149609b2ad qom/cpu: Simplify how CPUClass::dump_statistics() prints
64fad59c2e target/i386: Simplify how x86_cpu_dump_local_apic_state() prints
d0d676884c target: Clean up how the dump_mmu() print
e62415eb3c target: Simplify how the TARGET_cpu_list() print
6b93fa5e80 memory: Clean up how mtree_info() prints
e55e74cdf1 block/qapi: Clean up how we print to monitor or stdout
922dc9a331 qsp: Simplify how qsp_report() prints
a319820a6d tcg: Simplify how dump_drift_info() prints
7e213bdc95 tcg: Simplify how dump_exec_info() prints
a8dbca91a2 tcg: Simplify how dump_opcount_info() prints
8f9d9b1b12 trace: Simplify how st_print_trace_file_status() prints
7bf430b203 include: Include fprintf-fn.h only where needed

=== OUTPUT BEGIN ===
1/17 Checking commit 7bf430b2033a (include: Include fprintf-fn.h only where 
needed)
2/17 Checking commit 8f9d9b1b1263 (trace: Simplify how 
st_print_trace_file_status() prints)
3/17 Checking commit a8dbca91a2fb (tcg: Simplify how dump_opcount_info() prints)
4/17 Checking commit 7e213bdc9596 (tcg: Simplify how dump_exec_info() prints)
5/17 Checking commit a319820a6d62 (tcg: Simplify how dump_drift_info() prints)
6/17 Checking commit 922dc9a33160 (qsp: Simplify how qsp_report() prints)
7/17 Checking commit e55e74cdf1f9 (block/qapi: Clean up how we print to monitor 
or stdout)
8/17 Checking commit 6b93fa5e8004 (memory: Clean up how mtree_info() prints)
9/17 Checking commit e62415eb3c51 (target: Simplify how the TARGET_cpu_list() 
print)
10/17 Checking commit d0d676884c52 (target: Clean up how the dump_mmu() print)
WARNING: line over 80 characters
#950: FILE: target/xtensa/mmu_helper.c:784:
+qemu_printf("\tVaddr   Paddr   ASID  Attr RWX 
Cache\n"

total: 0 errors, 1 warnings, 848 lines checked

Patch 10/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
11/17 Checking commit 64fad59c2e43 (target/i386: Simplify how 
x86_cpu_dump_local_apic_state() prints)
12/17 Checking commit 149609b2ad9b (qom/cpu: Simplify how 
CPUClass::dump_statistics() prints)
13/17 Checking commit 5e6905625eeb (qemu-print: New qemu_fprintf(), 
qemu_vfprintf())
14/17 Checking commit 9dacaf5ef718 (qom/cpu: Simplify how 
CPUClass:cpu_dump_state() prints)
ERROR: line over 90 characters
#1051: FILE: target/i386/helper.c:419:
+qemu_fprintf(f, "RAX=%016" PRIx64 " RBX=%016" PRIx64 " RCX=%016" 
PRIx64 " RDX=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1052: FILE: target/i386/helper.c:420:
+ "RSI=%016" PRIx64 " RDI=%016" PRIx64 " RBP=%016" PRIx64 " 
RSP=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1053: FILE: target/i386/helper.c:421:
+ "R8 =%016" PRIx64 " R9 =%016" PRIx64 " R10=%016" PRIx64 " 
R11=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1054: FILE: target/i386/helper.c:422:
+ "R12=%016" PRIx64 " R13=%016" PRIx64 " R14=%016" PRIx64 " 
R15=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1055: FILE: target/i386/helper.c:423:
+ "RIP=%016" PRIx64 " RFL=%08x [%c%c%c%c%c%c%c] CPL=%d 
II=%d A20=%d SMM=%d HLT=%d\n",

WARNING: line over 80 characters
#1163: FILE: target/i386/helper.c:494:
+qemu_fprintf(f, "CR0=%08x CR2=%016" PRIx64 " CR3=%016" PRIx64 " 
CR4=%08x\n",

WARNING: line over 80 characters
#1751: FILE: target/mips/translate.c:29791:
+qemu_fprintf(f, "CP0 Status  0x%08x Cause   0x%08x EPC0x" 
TARGET_FMT_lx "\n",

total: 5 errors, 2 warnings, 2551 lines checked

Patch 14/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

15/17 Checking commit 90edbaf518e3 (monitor: Clean up how monitor_disas() 
funnels output to monitor)
16/17 

Re: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around fprintf_function

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



Hi,

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

Message-id: 20190417191805.28198-1-arm...@redhat.com
Subject: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around 
fprintf_function
Type: series

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

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]patchew/20190417191805.28198-1-arm...@redhat.com -> 
patchew/20190417191805.28198-1-arm...@redhat.com
Switched to a new branch 'test'
dfb284c449 include: Move fprintf_function to disas/
dbc3e8039f disas: Rename include/disas/bfd.h back to include/disas/dis-asm.h
71f572cab2 monitor: Clean up how monitor_disas() funnels output to monitor
67cdf8cf8b qom/cpu: Simplify how CPUClass:cpu_dump_state() prints
6a1d72f66f qemu-print: New qemu_fprintf(), qemu_vfprintf()
b6e8226b5c qom/cpu: Simplify how CPUClass::dump_statistics() prints
fea77047bb target/i386: Simplify how x86_cpu_dump_local_apic_state() prints
f850e6e38b target: Clean up how the dump_mmu() print
f36f9982d5 target: Simplify how the TARGET_cpu_list() print
97472bedb7 memory: Clean up how mtree_info() prints
09a19b6e63 block/qapi: Clean up how we print to monitor or stdout
68ff1d89f6 qsp: Simplify how qsp_report() prints
6777d9cdfd tcg: Simplify how dump_drift_info() prints
dc643ac146 tcg: Simplify how dump_exec_info() prints
9801855090 tcg: Simplify how dump_opcount_info() prints
7530ac3e60 trace: Simplify how st_print_trace_file_status() prints
8d5be4b138 include: Include fprintf-fn.h only where needed

=== OUTPUT BEGIN ===
1/17 Checking commit 8d5be4b13878 (include: Include fprintf-fn.h only where 
needed)
2/17 Checking commit 7530ac3e60b5 (trace: Simplify how 
st_print_trace_file_status() prints)
3/17 Checking commit 980185509054 (tcg: Simplify how dump_opcount_info() prints)
4/17 Checking commit dc643ac146c5 (tcg: Simplify how dump_exec_info() prints)
5/17 Checking commit 6777d9cdfd98 (tcg: Simplify how dump_drift_info() prints)
6/17 Checking commit 68ff1d89f658 (qsp: Simplify how qsp_report() prints)
7/17 Checking commit 09a19b6e63c7 (block/qapi: Clean up how we print to monitor 
or stdout)
8/17 Checking commit 97472bedb71b (memory: Clean up how mtree_info() prints)
9/17 Checking commit f36f9982d564 (target: Simplify how the TARGET_cpu_list() 
print)
10/17 Checking commit f850e6e38bf3 (target: Clean up how the dump_mmu() print)
WARNING: line over 80 characters
#950: FILE: target/xtensa/mmu_helper.c:784:
+qemu_printf("\tVaddr   Paddr   ASID  Attr RWX 
Cache\n"

total: 0 errors, 1 warnings, 848 lines checked

Patch 10/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
11/17 Checking commit fea77047bbff (target/i386: Simplify how 
x86_cpu_dump_local_apic_state() prints)
12/17 Checking commit b6e8226b5c46 (qom/cpu: Simplify how 
CPUClass::dump_statistics() prints)
13/17 Checking commit 6a1d72f66f1b (qemu-print: New qemu_fprintf(), 
qemu_vfprintf())
14/17 Checking commit 67cdf8cf8b1f (qom/cpu: Simplify how 
CPUClass:cpu_dump_state() prints)
ERROR: line over 90 characters
#1051: FILE: target/i386/helper.c:419:
+qemu_fprintf(f, "RAX=%016" PRIx64 " RBX=%016" PRIx64 " RCX=%016" 
PRIx64 " RDX=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1052: FILE: target/i386/helper.c:420:
+ "RSI=%016" PRIx64 " RDI=%016" PRIx64 " RBP=%016" PRIx64 " 
RSP=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1053: FILE: target/i386/helper.c:421:
+ "R8 =%016" PRIx64 " R9 =%016" PRIx64 " R10=%016" PRIx64 " 
R11=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1054: FILE: target/i386/helper.c:422:
+ "R12=%016" PRIx64 " R13=%016" PRIx64 " R14=%016" PRIx64 " 
R15=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1055: FILE: target/i386/helper.c:423:
+ "RIP=%016" PRIx64 " RFL=%08x [%c%c%c%c%c%c%c] CPL=%d 
II=%d A20=%d SMM=%d HLT=%d\n",

WARNING: line over 80 characters
#1163: FILE: target/i386/helper.c:494:
+qemu_fprintf(f, "CR0=%08x CR2=%016" PRIx64 " CR3=%016" PRIx64 " 
CR4=%08x\n",

WARNING: line over 80 characters
#1751: FILE: target/mips/translate.c:29791:
+qemu_fprintf(f, "CP0 Status  0x%08x Cause   0x%08x EPC0x" 
TARGET_FMT_lx "\n",

total: 5 errors, 2 warnings, 2551 lines checked

Patch 14/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

15/17 Checking commit 71f572cab24d (monitor: Clean up how monitor_disas() 
funnels output to monitor)
16/17 

Re: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around fprintf_function

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



Hi,

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

Message-id: 20190417191805.28198-1-arm...@redhat.com
Subject: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around 
fprintf_function
Type: series

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

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]patchew/20190417191805.28198-1-arm...@redhat.com -> 
patchew/20190417191805.28198-1-arm...@redhat.com
Switched to a new branch 'test'
c8c93e61d1 include: Move fprintf_function to disas/
f5674f82b2 disas: Rename include/disas/bfd.h back to include/disas/dis-asm.h
08e5c5c637 monitor: Clean up how monitor_disas() funnels output to monitor
5758566368 qom/cpu: Simplify how CPUClass:cpu_dump_state() prints
263852f63a qemu-print: New qemu_fprintf(), qemu_vfprintf()
005251581b qom/cpu: Simplify how CPUClass::dump_statistics() prints
207d3db725 target/i386: Simplify how x86_cpu_dump_local_apic_state() prints
d9cc902329 target: Clean up how the dump_mmu() print
827021bdb4 target: Simplify how the TARGET_cpu_list() print
f5dfd1ae06 memory: Clean up how mtree_info() prints
ea4b4273ed block/qapi: Clean up how we print to monitor or stdout
cf6447c2ca qsp: Simplify how qsp_report() prints
66120f6a1e tcg: Simplify how dump_drift_info() prints
872e71e6a3 tcg: Simplify how dump_exec_info() prints
49dadefa20 tcg: Simplify how dump_opcount_info() prints
ce1a847509 trace: Simplify how st_print_trace_file_status() prints
20ac898544 include: Include fprintf-fn.h only where needed

=== OUTPUT BEGIN ===
1/17 Checking commit 20ac898544d2 (include: Include fprintf-fn.h only where 
needed)
2/17 Checking commit ce1a8475095a (trace: Simplify how 
st_print_trace_file_status() prints)
3/17 Checking commit 49dadefa2093 (tcg: Simplify how dump_opcount_info() prints)
4/17 Checking commit 872e71e6a30d (tcg: Simplify how dump_exec_info() prints)
5/17 Checking commit 66120f6a1e65 (tcg: Simplify how dump_drift_info() prints)
6/17 Checking commit cf6447c2ca7d (qsp: Simplify how qsp_report() prints)
7/17 Checking commit ea4b4273ed42 (block/qapi: Clean up how we print to monitor 
or stdout)
8/17 Checking commit f5dfd1ae06f7 (memory: Clean up how mtree_info() prints)
9/17 Checking commit 827021bdb479 (target: Simplify how the TARGET_cpu_list() 
print)
10/17 Checking commit d9cc9023295d (target: Clean up how the dump_mmu() print)
WARNING: line over 80 characters
#950: FILE: target/xtensa/mmu_helper.c:784:
+qemu_printf("\tVaddr   Paddr   ASID  Attr RWX 
Cache\n"

total: 0 errors, 1 warnings, 848 lines checked

Patch 10/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
11/17 Checking commit 207d3db72502 (target/i386: Simplify how 
x86_cpu_dump_local_apic_state() prints)
12/17 Checking commit 005251581b3b (qom/cpu: Simplify how 
CPUClass::dump_statistics() prints)
13/17 Checking commit 263852f63aa4 (qemu-print: New qemu_fprintf(), 
qemu_vfprintf())
14/17 Checking commit 5758566368d1 (qom/cpu: Simplify how 
CPUClass:cpu_dump_state() prints)
ERROR: line over 90 characters
#1051: FILE: target/i386/helper.c:419:
+qemu_fprintf(f, "RAX=%016" PRIx64 " RBX=%016" PRIx64 " RCX=%016" 
PRIx64 " RDX=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1052: FILE: target/i386/helper.c:420:
+ "RSI=%016" PRIx64 " RDI=%016" PRIx64 " RBP=%016" PRIx64 " 
RSP=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1053: FILE: target/i386/helper.c:421:
+ "R8 =%016" PRIx64 " R9 =%016" PRIx64 " R10=%016" PRIx64 " 
R11=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1054: FILE: target/i386/helper.c:422:
+ "R12=%016" PRIx64 " R13=%016" PRIx64 " R14=%016" PRIx64 " 
R15=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1055: FILE: target/i386/helper.c:423:
+ "RIP=%016" PRIx64 " RFL=%08x [%c%c%c%c%c%c%c] CPL=%d 
II=%d A20=%d SMM=%d HLT=%d\n",

WARNING: line over 80 characters
#1163: FILE: target/i386/helper.c:494:
+qemu_fprintf(f, "CR0=%08x CR2=%016" PRIx64 " CR3=%016" PRIx64 " 
CR4=%08x\n",

WARNING: line over 80 characters
#1751: FILE: target/mips/translate.c:29791:
+qemu_fprintf(f, "CP0 Status  0x%08x Cause   0x%08x EPC0x" 
TARGET_FMT_lx "\n",

total: 5 errors, 2 warnings, 2551 lines checked

Patch 14/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

15/17 Checking commit 08e5c5c637d7 (monitor: Clean up how monitor_disas() 
funnels output to monitor)
16/17 

Re: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around fprintf_function

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



Hi,

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

Message-id: 20190417191805.28198-1-arm...@redhat.com
Subject: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around 
fprintf_function
Type: series

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

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]patchew/20190417191805.28198-1-arm...@redhat.com -> 
patchew/20190417191805.28198-1-arm...@redhat.com
Switched to a new branch 'test'
4efc614089 include: Move fprintf_function to disas/
609b068e91 disas: Rename include/disas/bfd.h back to include/disas/dis-asm.h
b60826bdec monitor: Clean up how monitor_disas() funnels output to monitor
7e0a83951c qom/cpu: Simplify how CPUClass:cpu_dump_state() prints
0310913eaf qemu-print: New qemu_fprintf(), qemu_vfprintf()
de8e759927 qom/cpu: Simplify how CPUClass::dump_statistics() prints
21575fb486 target/i386: Simplify how x86_cpu_dump_local_apic_state() prints
5e14da45f9 target: Clean up how the dump_mmu() print
d38f591f4a target: Simplify how the TARGET_cpu_list() print
f6d226a80d memory: Clean up how mtree_info() prints
dea28d5474 block/qapi: Clean up how we print to monitor or stdout
18cc598399 qsp: Simplify how qsp_report() prints
a2acbfe35b tcg: Simplify how dump_drift_info() prints
746793c924 tcg: Simplify how dump_exec_info() prints
48e5796804 tcg: Simplify how dump_opcount_info() prints
2788f8a6c8 trace: Simplify how st_print_trace_file_status() prints
b667f124bf include: Include fprintf-fn.h only where needed

=== OUTPUT BEGIN ===
1/17 Checking commit b667f124bfd4 (include: Include fprintf-fn.h only where 
needed)
2/17 Checking commit 2788f8a6c887 (trace: Simplify how 
st_print_trace_file_status() prints)
3/17 Checking commit 48e579680473 (tcg: Simplify how dump_opcount_info() prints)
4/17 Checking commit 746793c92494 (tcg: Simplify how dump_exec_info() prints)
5/17 Checking commit a2acbfe35b3f (tcg: Simplify how dump_drift_info() prints)
6/17 Checking commit 18cc59839940 (qsp: Simplify how qsp_report() prints)
7/17 Checking commit dea28d5474ce (block/qapi: Clean up how we print to monitor 
or stdout)
8/17 Checking commit f6d226a80d57 (memory: Clean up how mtree_info() prints)
9/17 Checking commit d38f591f4af4 (target: Simplify how the TARGET_cpu_list() 
print)
10/17 Checking commit 5e14da45f92c (target: Clean up how the dump_mmu() print)
WARNING: line over 80 characters
#950: FILE: target/xtensa/mmu_helper.c:784:
+qemu_printf("\tVaddr   Paddr   ASID  Attr RWX 
Cache\n"

total: 0 errors, 1 warnings, 848 lines checked

Patch 10/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
11/17 Checking commit 21575fb486ef (target/i386: Simplify how 
x86_cpu_dump_local_apic_state() prints)
12/17 Checking commit de8e75992712 (qom/cpu: Simplify how 
CPUClass::dump_statistics() prints)
13/17 Checking commit 0310913eaf37 (qemu-print: New qemu_fprintf(), 
qemu_vfprintf())
14/17 Checking commit 7e0a83951c37 (qom/cpu: Simplify how 
CPUClass:cpu_dump_state() prints)
ERROR: line over 90 characters
#1051: FILE: target/i386/helper.c:419:
+qemu_fprintf(f, "RAX=%016" PRIx64 " RBX=%016" PRIx64 " RCX=%016" 
PRIx64 " RDX=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1052: FILE: target/i386/helper.c:420:
+ "RSI=%016" PRIx64 " RDI=%016" PRIx64 " RBP=%016" PRIx64 " 
RSP=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1053: FILE: target/i386/helper.c:421:
+ "R8 =%016" PRIx64 " R9 =%016" PRIx64 " R10=%016" PRIx64 " 
R11=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1054: FILE: target/i386/helper.c:422:
+ "R12=%016" PRIx64 " R13=%016" PRIx64 " R14=%016" PRIx64 " 
R15=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1055: FILE: target/i386/helper.c:423:
+ "RIP=%016" PRIx64 " RFL=%08x [%c%c%c%c%c%c%c] CPL=%d 
II=%d A20=%d SMM=%d HLT=%d\n",

WARNING: line over 80 characters
#1163: FILE: target/i386/helper.c:494:
+qemu_fprintf(f, "CR0=%08x CR2=%016" PRIx64 " CR3=%016" PRIx64 " 
CR4=%08x\n",

WARNING: line over 80 characters
#1751: FILE: target/mips/translate.c:29791:
+qemu_fprintf(f, "CP0 Status  0x%08x Cause   0x%08x EPC0x" 
TARGET_FMT_lx "\n",

total: 5 errors, 2 warnings, 2551 lines checked

Patch 14/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

15/17 Checking commit b60826bdec60 (monitor: Clean up how monitor_disas() 
funnels output to monitor)
16/17 

Re: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around fprintf_function

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



Hi,

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

Message-id: 20190417191805.28198-1-arm...@redhat.com
Subject: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around 
fprintf_function
Type: series

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

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]patchew/20190417191805.28198-1-arm...@redhat.com -> 
patchew/20190417191805.28198-1-arm...@redhat.com
Switched to a new branch 'test'
587c26c24e include: Move fprintf_function to disas/
416f563f47 disas: Rename include/disas/bfd.h back to include/disas/dis-asm.h
0a17831a3d monitor: Clean up how monitor_disas() funnels output to monitor
7552bb783c qom/cpu: Simplify how CPUClass:cpu_dump_state() prints
f8829004b6 qemu-print: New qemu_fprintf(), qemu_vfprintf()
6e17d7886f qom/cpu: Simplify how CPUClass::dump_statistics() prints
b9e7cc19f9 target/i386: Simplify how x86_cpu_dump_local_apic_state() prints
d0235ec2aa target: Clean up how the dump_mmu() print
5ac5266b18 target: Simplify how the TARGET_cpu_list() print
537efe83e7 memory: Clean up how mtree_info() prints
d8c0a5610f block/qapi: Clean up how we print to monitor or stdout
1f2593e991 qsp: Simplify how qsp_report() prints
8ddded1f2c tcg: Simplify how dump_drift_info() prints
50a002becd tcg: Simplify how dump_exec_info() prints
eb737a179a tcg: Simplify how dump_opcount_info() prints
298229bbdd trace: Simplify how st_print_trace_file_status() prints
8a2715b3db include: Include fprintf-fn.h only where needed

=== OUTPUT BEGIN ===
1/17 Checking commit 8a2715b3db01 (include: Include fprintf-fn.h only where 
needed)
2/17 Checking commit 298229bbddd0 (trace: Simplify how 
st_print_trace_file_status() prints)
3/17 Checking commit eb737a179ad4 (tcg: Simplify how dump_opcount_info() prints)
4/17 Checking commit 50a002becdd9 (tcg: Simplify how dump_exec_info() prints)
5/17 Checking commit 8ddded1f2ce1 (tcg: Simplify how dump_drift_info() prints)
6/17 Checking commit 1f2593e99199 (qsp: Simplify how qsp_report() prints)
7/17 Checking commit d8c0a5610f9d (block/qapi: Clean up how we print to monitor 
or stdout)
8/17 Checking commit 537efe83e7af (memory: Clean up how mtree_info() prints)
9/17 Checking commit 5ac5266b18f3 (target: Simplify how the TARGET_cpu_list() 
print)
10/17 Checking commit d0235ec2aa72 (target: Clean up how the dump_mmu() print)
WARNING: line over 80 characters
#950: FILE: target/xtensa/mmu_helper.c:784:
+qemu_printf("\tVaddr   Paddr   ASID  Attr RWX 
Cache\n"

total: 0 errors, 1 warnings, 848 lines checked

Patch 10/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
11/17 Checking commit b9e7cc19f90d (target/i386: Simplify how 
x86_cpu_dump_local_apic_state() prints)
12/17 Checking commit 6e17d7886f80 (qom/cpu: Simplify how 
CPUClass::dump_statistics() prints)
13/17 Checking commit f8829004b621 (qemu-print: New qemu_fprintf(), 
qemu_vfprintf())
14/17 Checking commit 7552bb783c08 (qom/cpu: Simplify how 
CPUClass:cpu_dump_state() prints)
ERROR: line over 90 characters
#1051: FILE: target/i386/helper.c:419:
+qemu_fprintf(f, "RAX=%016" PRIx64 " RBX=%016" PRIx64 " RCX=%016" 
PRIx64 " RDX=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1052: FILE: target/i386/helper.c:420:
+ "RSI=%016" PRIx64 " RDI=%016" PRIx64 " RBP=%016" PRIx64 " 
RSP=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1053: FILE: target/i386/helper.c:421:
+ "R8 =%016" PRIx64 " R9 =%016" PRIx64 " R10=%016" PRIx64 " 
R11=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1054: FILE: target/i386/helper.c:422:
+ "R12=%016" PRIx64 " R13=%016" PRIx64 " R14=%016" PRIx64 " 
R15=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1055: FILE: target/i386/helper.c:423:
+ "RIP=%016" PRIx64 " RFL=%08x [%c%c%c%c%c%c%c] CPL=%d 
II=%d A20=%d SMM=%d HLT=%d\n",

WARNING: line over 80 characters
#1163: FILE: target/i386/helper.c:494:
+qemu_fprintf(f, "CR0=%08x CR2=%016" PRIx64 " CR3=%016" PRIx64 " 
CR4=%08x\n",

WARNING: line over 80 characters
#1751: FILE: target/mips/translate.c:29791:
+qemu_fprintf(f, "CP0 Status  0x%08x Cause   0x%08x EPC0x" 
TARGET_FMT_lx "\n",

total: 5 errors, 2 warnings, 2551 lines checked

Patch 14/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

15/17 Checking commit 0a17831a3dbe (monitor: Clean up how monitor_disas() 
funnels output to monitor)
16/17 

Re: [Qemu-devel] [Qemu-block] [PATCH 0/5] Few fixes for userspace NVME driver

2019-04-17 Thread Maxim Levitsky
On Tue, 2019-04-16 at 15:50 +0200, Paolo Bonzini wrote:
> On 15/04/19 15:57, Maxim Levitsky wrote:
> > 
> > 
> > Hi!
> > These are few assorted fixes and features for the userspace
> > nvme driver.
> > 
> > Tested that on my laptop with my Samsung X5 thunderbolt drive, which
> > happens to have 4K sectors, support for discard and write zeros.
> > 
> > Also bunch of fixes sitting in my queue from the period when I developed
> > the nvme-mdev driver.
> > 
> > Best regards,
> > Maxim Levitsky
> 
> I only pointed out just two cosmetic changes.  Thanks very much!
> 
> Paolo
> 
Hi Paolo!
Thank you very much!

I have just resent V2 of the series with the fixes.

Best regards,
Maxim Levitsky




Re: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around fprintf_function

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



Hi,

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

Message-id: 20190417191805.28198-1-arm...@redhat.com
Subject: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around 
fprintf_function
Type: series

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

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]patchew/20190417191805.28198-1-arm...@redhat.com -> 
patchew/20190417191805.28198-1-arm...@redhat.com
Switched to a new branch 'test'
9b6bcf include: Move fprintf_function to disas/
5f3c81a6c0 disas: Rename include/disas/bfd.h back to include/disas/dis-asm.h
b1ae46c343 monitor: Clean up how monitor_disas() funnels output to monitor
a00c28ab5f qom/cpu: Simplify how CPUClass:cpu_dump_state() prints
0f55321ae1 qemu-print: New qemu_fprintf(), qemu_vfprintf()
f2dbd0673c qom/cpu: Simplify how CPUClass::dump_statistics() prints
5b67d37795 target/i386: Simplify how x86_cpu_dump_local_apic_state() prints
dc40ad0d34 target: Clean up how the dump_mmu() print
8df164790b target: Simplify how the TARGET_cpu_list() print
17406d3cf6 memory: Clean up how mtree_info() prints
53875f811b block/qapi: Clean up how we print to monitor or stdout
d2f6642515 qsp: Simplify how qsp_report() prints
e380a5d2ef tcg: Simplify how dump_drift_info() prints
aa6873e448 tcg: Simplify how dump_exec_info() prints
f8a56f8a9e tcg: Simplify how dump_opcount_info() prints
5beb1ec556 trace: Simplify how st_print_trace_file_status() prints
5f69e0108f include: Include fprintf-fn.h only where needed

=== OUTPUT BEGIN ===
1/17 Checking commit 5f69e0108f3a (include: Include fprintf-fn.h only where 
needed)
2/17 Checking commit 5beb1ec556b3 (trace: Simplify how 
st_print_trace_file_status() prints)
3/17 Checking commit f8a56f8a9e7a (tcg: Simplify how dump_opcount_info() prints)
4/17 Checking commit aa6873e4485d (tcg: Simplify how dump_exec_info() prints)
5/17 Checking commit e380a5d2ef1f (tcg: Simplify how dump_drift_info() prints)
6/17 Checking commit d2f6642515d9 (qsp: Simplify how qsp_report() prints)
7/17 Checking commit 53875f811b38 (block/qapi: Clean up how we print to monitor 
or stdout)
8/17 Checking commit 17406d3cf6af (memory: Clean up how mtree_info() prints)
9/17 Checking commit 8df164790bf4 (target: Simplify how the TARGET_cpu_list() 
print)
10/17 Checking commit dc40ad0d3487 (target: Clean up how the dump_mmu() print)
WARNING: line over 80 characters
#950: FILE: target/xtensa/mmu_helper.c:784:
+qemu_printf("\tVaddr   Paddr   ASID  Attr RWX 
Cache\n"

total: 0 errors, 1 warnings, 848 lines checked

Patch 10/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
11/17 Checking commit 5b67d377956e (target/i386: Simplify how 
x86_cpu_dump_local_apic_state() prints)
12/17 Checking commit f2dbd0673ce7 (qom/cpu: Simplify how 
CPUClass::dump_statistics() prints)
13/17 Checking commit 0f55321ae1d6 (qemu-print: New qemu_fprintf(), 
qemu_vfprintf())
14/17 Checking commit a00c28ab5fe0 (qom/cpu: Simplify how 
CPUClass:cpu_dump_state() prints)
ERROR: line over 90 characters
#1051: FILE: target/i386/helper.c:419:
+qemu_fprintf(f, "RAX=%016" PRIx64 " RBX=%016" PRIx64 " RCX=%016" 
PRIx64 " RDX=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1052: FILE: target/i386/helper.c:420:
+ "RSI=%016" PRIx64 " RDI=%016" PRIx64 " RBP=%016" PRIx64 " 
RSP=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1053: FILE: target/i386/helper.c:421:
+ "R8 =%016" PRIx64 " R9 =%016" PRIx64 " R10=%016" PRIx64 " 
R11=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1054: FILE: target/i386/helper.c:422:
+ "R12=%016" PRIx64 " R13=%016" PRIx64 " R14=%016" PRIx64 " 
R15=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1055: FILE: target/i386/helper.c:423:
+ "RIP=%016" PRIx64 " RFL=%08x [%c%c%c%c%c%c%c] CPL=%d 
II=%d A20=%d SMM=%d HLT=%d\n",

WARNING: line over 80 characters
#1163: FILE: target/i386/helper.c:494:
+qemu_fprintf(f, "CR0=%08x CR2=%016" PRIx64 " CR3=%016" PRIx64 " 
CR4=%08x\n",

WARNING: line over 80 characters
#1751: FILE: target/mips/translate.c:29791:
+qemu_fprintf(f, "CP0 Status  0x%08x Cause   0x%08x EPC0x" 
TARGET_FMT_lx "\n",

total: 5 errors, 2 warnings, 2551 lines checked

Patch 14/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

15/17 Checking commit b1ae46c3432c (monitor: Clean up how monitor_disas() 
funnels output to monitor)
16/17 

[Qemu-devel] [PATCH v2 3/5] block/nvme: support larger that 512 bytes sector devices

2019-04-17 Thread Maxim Levitsky
Currently the driver hardcodes the sector size to 512,
and doesn't check the underlying device

Also fail if underlying nvme device is formatted with metadata
as this needs special support.

Signed-off-by: Maxim Levitsky 
---
 block/nvme.c | 40 +++-
 1 file changed, 35 insertions(+), 5 deletions(-)

diff --git a/block/nvme.c b/block/nvme.c
index 208242cf1f..0b1da54574 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -101,8 +101,11 @@ typedef struct {
 size_t doorbell_scale;
 bool write_cache_supported;
 EventNotifier irq_notifier;
+
 uint64_t nsze; /* Namespace size reported by identify command */
 int nsid;  /* The namespace id to read/write data. */
+size_t blkshift;
+
 uint64_t max_transfer;
 bool plugged;
 
@@ -415,8 +418,9 @@ static void nvme_identify(BlockDriverState *bs, int 
namespace, Error **errp)
 BDRVNVMeState *s = bs->opaque;
 NvmeIdCtrl *idctrl;
 NvmeIdNs *idns;
+NvmeLBAF *lbaf;
 uint8_t *resp;
-int r;
+int r, hwsect_size;
 uint64_t iova;
 NvmeCmd cmd = {
 .opcode = NVME_ADM_CMD_IDENTIFY,
@@ -463,7 +467,22 @@ static void nvme_identify(BlockDriverState *bs, int 
namespace, Error **errp)
 }
 
 s->nsze = le64_to_cpu(idns->nsze);
+lbaf = >lbaf[NVME_ID_NS_FLBAS_INDEX(idns->flbas)];
+
+if (lbaf->ms) {
+error_setg(errp, "Namespaces with metadata are not yet supported");
+goto out;
+}
+
+hwsect_size = 1 << lbaf->ds;
+
+if (hwsect_size < BDRV_SECTOR_BITS || hwsect_size > s->page_size) {
+error_setg(errp, "Namespace has unsupported block size (%d)",
+hwsect_size);
+goto out;
+}
 
+s->blkshift = lbaf->ds;
 out:
 qemu_vfio_dma_unmap(s->vfio, resp);
 qemu_vfree(resp);
@@ -782,8 +801,17 @@ fail:
 static int64_t nvme_getlength(BlockDriverState *bs)
 {
 BDRVNVMeState *s = bs->opaque;
+return s->nsze << s->blkshift;
+}
+
 
-return s->nsze << BDRV_SECTOR_BITS;
+static int nvme_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz)
+{
+BDRVNVMeState *s = bs->opaque;
+assert(s->blkshift >= 9);
+bsz->phys = 1 << s->blkshift;
+bsz->log = 1 << s->blkshift;
+return 0;
 }
 
 /* Called with s->dma_map_lock */
@@ -914,13 +942,14 @@ static coroutine_fn int 
nvme_co_prw_aligned(BlockDriverState *bs,
 BDRVNVMeState *s = bs->opaque;
 NVMeQueuePair *ioq = s->queues[1];
 NVMeRequest *req;
-uint32_t cdw12 = (((bytes >> BDRV_SECTOR_BITS) - 1) & 0x) |
+
+uint32_t cdw12 = (((bytes >> s->blkshift) - 1) & 0x) |
(flags & BDRV_REQ_FUA ? 1 << 30 : 0);
 NvmeCmd cmd = {
 .opcode = is_write ? NVME_CMD_WRITE : NVME_CMD_READ,
 .nsid = cpu_to_le32(s->nsid),
-.cdw10 = cpu_to_le32((offset >> BDRV_SECTOR_BITS) & 0x),
-.cdw11 = cpu_to_le32(((offset >> BDRV_SECTOR_BITS) >> 32) & 
0x),
+.cdw10 = cpu_to_le32((offset >> s->blkshift) & 0x),
+.cdw11 = cpu_to_le32(((offset >> s->blkshift) >> 32) & 0x),
 .cdw12 = cpu_to_le32(cdw12),
 };
 NVMeCoData data = {
@@ -1151,6 +1180,7 @@ static BlockDriver bdrv_nvme = {
 .bdrv_file_open   = nvme_file_open,
 .bdrv_close   = nvme_close,
 .bdrv_getlength   = nvme_getlength,
+.bdrv_probe_blocksizes= nvme_probe_blocksizes,
 
 .bdrv_co_preadv   = nvme_co_preadv,
 .bdrv_co_pwritev  = nvme_co_pwritev,
-- 
2.17.2




[Qemu-devel] [PATCH v2 5/5] block/nvme: add support for discard

2019-04-17 Thread Maxim Levitsky
Signed-off-by: Maxim Levitsky 
---
 block/nvme.c   | 80 ++
 block/trace-events |  2 ++
 2 files changed, 82 insertions(+)

diff --git a/block/nvme.c b/block/nvme.c
index 35b925899f..b83912c627 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -110,6 +110,7 @@ typedef struct {
 bool plugged;
 
 bool supports_write_zeros;
+bool supports_discard;
 
 CoMutex dma_map_lock;
 CoQueue dma_flush_queue;
@@ -462,6 +463,7 @@ static void nvme_identify(BlockDriverState *bs, int 
namespace, Error **errp)
 
 
 s->supports_write_zeros = (idctrl->oncs & NVME_ONCS_WRITE_ZEROS) != 0;
+s->supports_discard = (idctrl->oncs & NVME_ONCS_DSM) != 0;
 
 memset(resp, 0, 4096);
 
@@ -1144,6 +1146,83 @@ static coroutine_fn int 
nvme_co_pwrite_zeroes(BlockDriverState *bs,
 }
 
 
+static int coroutine_fn nvme_co_pdiscard(BlockDriverState *bs,
+int64_t offset, int bytes)
+{
+BDRVNVMeState *s = bs->opaque;
+NVMeQueuePair *ioq = s->queues[1];
+NVMeRequest *req;
+NvmeDsmRange *buf;
+QEMUIOVector local_qiov;
+int r;
+
+NvmeCmd cmd = {
+.opcode = NVME_CMD_DSM,
+.nsid = cpu_to_le32(s->nsid),
+.cdw10 = 0, /*number of ranges - 0 based*/
+.cdw11 = cpu_to_le32(1 << 2), /*deallocate bit*/
+};
+
+NVMeCoData data = {
+.ctx = bdrv_get_aio_context(bs),
+.ret = -EINPROGRESS,
+};
+
+if (!s->supports_discard) {
+return -ENOTSUP;
+}
+
+assert(s->nr_queues > 1);
+
+buf = qemu_try_blockalign0(bs, 4096);
+if (!buf) {
+return -ENOMEM;
+}
+
+buf->nlb = bytes >> s->blkshift;
+buf->slba = offset >> s->blkshift;
+buf->cattr = 0;
+
+qemu_iovec_init(_qiov, 1);
+qemu_iovec_add(_qiov, buf, 4096);
+
+req = nvme_get_free_req(ioq);
+assert(req);
+
+qemu_co_mutex_lock(>dma_map_lock);
+r = nvme_cmd_map_qiov(bs, , req, _qiov);
+qemu_co_mutex_unlock(>dma_map_lock);
+
+if (r) {
+req->busy = false;
+return r;
+}
+
+trace_nvme_dsm(s, offset, bytes);
+
+nvme_submit_command(s, ioq, req, , nvme_rw_cb, );
+
+data.co = qemu_coroutine_self();
+while (data.ret == -EINPROGRESS) {
+qemu_coroutine_yield();
+}
+
+qemu_co_mutex_lock(>dma_map_lock);
+r = nvme_cmd_unmap_qiov(bs, _qiov);
+qemu_co_mutex_unlock(>dma_map_lock);
+if (r) {
+return r;
+}
+
+trace_nvme_dsm_done(s, offset, bytes, data.ret);
+
+qemu_iovec_destroy(_qiov);
+qemu_vfree(buf);
+return data.ret;
+
+}
+
+
 static int nvme_reopen_prepare(BDRVReopenState *reopen_state,
BlockReopenQueue *queue, Error **errp)
 {
@@ -1250,6 +1329,7 @@ static BlockDriver bdrv_nvme = {
 .bdrv_co_pwritev  = nvme_co_pwritev,
 
 .bdrv_co_pwrite_zeroes= nvme_co_pwrite_zeroes,
+.bdrv_co_pdiscard = nvme_co_pdiscard,
 
 .bdrv_co_flush_to_disk= nvme_co_flush,
 .bdrv_reopen_prepare  = nvme_reopen_prepare,
diff --git a/block/trace-events b/block/trace-events
index 943a58569f..e55ac5c40b 100644
--- a/block/trace-events
+++ b/block/trace-events
@@ -148,6 +148,8 @@ nvme_write_zeros(void *s, uint64_t offset, uint64_t bytes, 
int flags) "s %p offs
 nvme_qiov_unaligned(const void *qiov, int n, void *base, size_t size, int 
align) "qiov %p n %d base %p size 0x%zx align 0x%x"
 nvme_prw_buffered(void *s, uint64_t offset, uint64_t bytes, int niov, int 
is_write) "s %p offset %"PRId64" bytes %"PRId64" niov %d is_write %d"
 nvme_rw_done(void *s, int is_write, uint64_t offset, uint64_t bytes, int ret) 
"s %p is_write %d offset %"PRId64" bytes %"PRId64" ret %d"
+nvme_dsm(void *s, uint64_t offset, uint64_t bytes) "s %p offset %"PRId64" 
bytes %"PRId64""
+nvme_dsm_done(void *s, uint64_t offset, uint64_t bytes, int ret) "s %p offset 
%"PRId64" bytes %"PRId64" ret %d"
 nvme_dma_map_flush(void *s) "s %p"
 nvme_free_req_queue_wait(void *q) "q %p"
 nvme_cmd_map_qiov(void *s, void *cmd, void *req, void *qiov, int entries) "s 
%p cmd %p req %p qiov %p entries %d"
-- 
2.17.2




[Qemu-devel] [PATCH v2 1/5] block/nvme: don't flip CQ phase bits

2019-04-17 Thread Maxim Levitsky
Phase bits are only set by the hardware to indicate new completions
and not by the device driver.

Signed-off-by: Maxim Levitsky 
---
 block/nvme.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/block/nvme.c b/block/nvme.c
index 0684bbd077..2d208000df 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -340,8 +340,6 @@ static bool nvme_process_completion(BDRVNVMeState *s, 
NVMeQueuePair *q)
 qemu_mutex_lock(>lock);
 c->cid = cpu_to_le16(0);
 q->inflight--;
-/* Flip Phase Tag bit. */
-c->status = cpu_to_le16(le16_to_cpu(c->status) ^ 0x1);
 progress = true;
 }
 if (progress) {
-- 
2.17.2




[Qemu-devel] [PATCH v2 2/5] block/nvme: fix doorbell stride

2019-04-17 Thread Maxim Levitsky
Fix the math involving non standard doorbell stride

Signed-off-by: Maxim Levitsky 
---
 block/nvme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/nvme.c b/block/nvme.c
index 2d208000df..208242cf1f 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -216,7 +216,7 @@ static NVMeQueuePair 
*nvme_create_queue_pair(BlockDriverState *bs,
 error_propagate(errp, local_err);
 goto fail;
 }
-q->cq.doorbell = >regs->doorbells[idx * 2 * s->doorbell_scale + 1];
+q->cq.doorbell = >regs->doorbells[(idx * 2 + 1) * s->doorbell_scale];
 
 return q;
 fail:
-- 
2.17.2




[Qemu-devel] [PATCH v2 0/5] Few fixes for userspace NVME driver

2019-04-17 Thread Maxim Levitsky
Hi!
These are few assorted fixes and features for the userspace
nvme driver.

Tested that on my laptop with my Samsung X5 thunderbolt drive, which
happens to have 4K sectors, support for discard and write zeros.

Also bunch of fixes sitting in my queue from the period when I developed
the nvme-mdev driver.

Best regards,
Maxim Levitsky

Maxim Levitsky (5):
  block/nvme: don't flip CQ phase bits
  block/nvme: fix doorbell stride
  block/nvme: support larger that 512 bytes sector devices
  block/nvme: add support for write zeros
  block/nvme: add support for discard

 block/nvme.c | 193 +--
 block/trace-events   |   3 +
 include/block/nvme.h |  19 -
 3 files changed, 205 insertions(+), 10 deletions(-)

-- 
2.17.2




[Qemu-devel] [PATCH v2 4/5] block/nvme: add support for write zeros

2019-04-17 Thread Maxim Levitsky
Signed-off-by: Maxim Levitsky 
---
 block/nvme.c | 69 +++-
 block/trace-events   |  1 +
 include/block/nvme.h | 19 +++-
 3 files changed, 87 insertions(+), 2 deletions(-)

diff --git a/block/nvme.c b/block/nvme.c
index 0b1da54574..35b925899f 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -109,6 +109,8 @@ typedef struct {
 uint64_t max_transfer;
 bool plugged;
 
+bool supports_write_zeros;
+
 CoMutex dma_map_lock;
 CoQueue dma_flush_queue;
 
@@ -457,6 +459,10 @@ static void nvme_identify(BlockDriverState *bs, int 
namespace, Error **errp)
 s->max_transfer = MIN_NON_ZERO(s->max_transfer,
   s->page_size / sizeof(uint64_t) * s->page_size);
 
+
+
+s->supports_write_zeros = (idctrl->oncs & NVME_ONCS_WRITE_ZEROS) != 0;
+
 memset(resp, 0, 4096);
 
 cmd.cdw10 = 0;
@@ -469,6 +475,11 @@ static void nvme_identify(BlockDriverState *bs, int 
namespace, Error **errp)
 s->nsze = le64_to_cpu(idns->nsze);
 lbaf = >lbaf[NVME_ID_NS_FLBAS_INDEX(idns->flbas)];
 
+if (NVME_ID_NS_DLFEAT_WRITE_ZEROS(idns->dlfeat) &&
+NVME_ID_NS_DLFEAT_READ_BEHAVIOR(idns->dlfeat) ==
+NVME_ID_NS_DLFEAT_READ_BEHAVIOR_ZEROS)
+bs->supported_write_flags |= BDRV_REQ_MAY_UNMAP;
+
 if (lbaf->ms) {
 error_setg(errp, "Namespaces with metadata are not yet supported");
 goto out;
@@ -763,6 +774,8 @@ static int nvme_file_open(BlockDriverState *bs, QDict 
*options, int flags,
 int ret;
 BDRVNVMeState *s = bs->opaque;
 
+bs->supported_write_flags = BDRV_REQ_FUA;
+
 opts = qemu_opts_create(_opts, NULL, 0, _abort);
 qemu_opts_absorb_qdict(opts, options, _abort);
 device = qemu_opt_get(opts, NVME_BLOCK_OPT_DEVICE);
@@ -791,7 +804,6 @@ static int nvme_file_open(BlockDriverState *bs, QDict 
*options, int flags,
 goto fail;
 }
 }
-bs->supported_write_flags = BDRV_REQ_FUA;
 return 0;
 fail:
 nvme_close(bs);
@@ -1080,6 +1092,58 @@ static coroutine_fn int nvme_co_flush(BlockDriverState 
*bs)
 }
 
 
+static coroutine_fn int nvme_co_pwrite_zeroes(BlockDriverState *bs,
+int64_t offset, int bytes, BdrvRequestFlags flags)
+{
+BDRVNVMeState *s = bs->opaque;
+NVMeQueuePair *ioq = s->queues[1];
+NVMeRequest *req;
+
+if (!s->supports_write_zeros) {
+return -ENOTSUP;
+}
+
+uint32_t cdw12 = ((bytes >> s->blkshift) - 1) & 0x;
+
+NvmeCmd cmd = {
+.opcode = NVME_CMD_WRITE_ZEROS,
+.nsid = cpu_to_le32(s->nsid),
+.cdw10 = cpu_to_le32((offset >> s->blkshift) & 0x),
+.cdw11 = cpu_to_le32(((offset >> s->blkshift) >> 32) & 0x),
+};
+
+NVMeCoData data = {
+.ctx = bdrv_get_aio_context(bs),
+.ret = -EINPROGRESS,
+};
+
+if (flags & BDRV_REQ_MAY_UNMAP) {
+cdw12 |= (1 << 25);
+}
+
+if (flags & BDRV_REQ_FUA) {
+cdw12 |= (1 << 30);
+}
+
+cmd.cdw12 = cpu_to_le32(cdw12);
+
+trace_nvme_write_zeros(s, offset, bytes, flags);
+assert(s->nr_queues > 1);
+req = nvme_get_free_req(ioq);
+assert(req);
+
+nvme_submit_command(s, ioq, req, , nvme_rw_cb, );
+
+data.co = qemu_coroutine_self();
+while (data.ret == -EINPROGRESS) {
+qemu_coroutine_yield();
+}
+
+trace_nvme_rw_done(s, true, offset, bytes, data.ret);
+return data.ret;
+}
+
+
 static int nvme_reopen_prepare(BDRVReopenState *reopen_state,
BlockReopenQueue *queue, Error **errp)
 {
@@ -1184,6 +1248,9 @@ static BlockDriver bdrv_nvme = {
 
 .bdrv_co_preadv   = nvme_co_preadv,
 .bdrv_co_pwritev  = nvme_co_pwritev,
+
+.bdrv_co_pwrite_zeroes= nvme_co_pwrite_zeroes,
+
 .bdrv_co_flush_to_disk= nvme_co_flush,
 .bdrv_reopen_prepare  = nvme_reopen_prepare,
 
diff --git a/block/trace-events b/block/trace-events
index 7335a42540..943a58569f 100644
--- a/block/trace-events
+++ b/block/trace-events
@@ -144,6 +144,7 @@ nvme_submit_command_raw(int c0, int c1, int c2, int c3, int 
c4, int c5, int c6,
 nvme_handle_event(void *s) "s %p"
 nvme_poll_cb(void *s) "s %p"
 nvme_prw_aligned(void *s, int is_write, uint64_t offset, uint64_t bytes, int 
flags, int niov) "s %p is_write %d offset %"PRId64" bytes %"PRId64" flags %d 
niov %d"
+nvme_write_zeros(void *s, uint64_t offset, uint64_t bytes, int flags) "s %p 
offset %"PRId64" bytes %"PRId64" flags %d"
 nvme_qiov_unaligned(const void *qiov, int n, void *base, size_t size, int 
align) "qiov %p n %d base %p size 0x%zx align 0x%x"
 nvme_prw_buffered(void *s, uint64_t offset, uint64_t bytes, int niov, int 
is_write) "s %p offset %"PRId64" bytes %"PRId64" niov %d is_write %d"
 nvme_rw_done(void *s, int is_write, uint64_t offset, uint64_t bytes, int ret) 
"s %p is_write %d offset %"PRId64" bytes %"PRId64" ret %d"
diff --git a/include/block/nvme.h b/include/block/nvme.h
index 0eae6f9f15..edf8e90557 100644
--- 

Re: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around fprintf_function

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



Hi,

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

Message-id: 20190417191805.28198-1-arm...@redhat.com
Subject: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around 
fprintf_function
Type: series

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

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]patchew/20190417191805.28198-1-arm...@redhat.com -> 
patchew/20190417191805.28198-1-arm...@redhat.com
Switched to a new branch 'test'
d04838b7b7 include: Move fprintf_function to disas/
319ed76db2 disas: Rename include/disas/bfd.h back to include/disas/dis-asm.h
feff1f1103 monitor: Clean up how monitor_disas() funnels output to monitor
c9c4a984c5 qom/cpu: Simplify how CPUClass:cpu_dump_state() prints
f7def015ea qemu-print: New qemu_fprintf(), qemu_vfprintf()
286643ea44 qom/cpu: Simplify how CPUClass::dump_statistics() prints
3d846546c8 target/i386: Simplify how x86_cpu_dump_local_apic_state() prints
f2b3c9abee target: Clean up how the dump_mmu() print
1394894623 target: Simplify how the TARGET_cpu_list() print
1c6016aa83 memory: Clean up how mtree_info() prints
8f6c6a9fe3 block/qapi: Clean up how we print to monitor or stdout
782d9eb94e qsp: Simplify how qsp_report() prints
e6de5c5911 tcg: Simplify how dump_drift_info() prints
9e1aa6472d tcg: Simplify how dump_exec_info() prints
21dba78baa tcg: Simplify how dump_opcount_info() prints
c6d722b62c trace: Simplify how st_print_trace_file_status() prints
ded6f95b0e include: Include fprintf-fn.h only where needed

=== OUTPUT BEGIN ===
1/17 Checking commit ded6f95b0e1b (include: Include fprintf-fn.h only where 
needed)
2/17 Checking commit c6d722b62cc2 (trace: Simplify how 
st_print_trace_file_status() prints)
3/17 Checking commit 21dba78baad3 (tcg: Simplify how dump_opcount_info() prints)
4/17 Checking commit 9e1aa6472d45 (tcg: Simplify how dump_exec_info() prints)
5/17 Checking commit e6de5c591115 (tcg: Simplify how dump_drift_info() prints)
6/17 Checking commit 782d9eb94e8a (qsp: Simplify how qsp_report() prints)
7/17 Checking commit 8f6c6a9fe333 (block/qapi: Clean up how we print to monitor 
or stdout)
8/17 Checking commit 1c6016aa83ad (memory: Clean up how mtree_info() prints)
9/17 Checking commit 139489462353 (target: Simplify how the TARGET_cpu_list() 
print)
10/17 Checking commit f2b3c9abeec5 (target: Clean up how the dump_mmu() print)
WARNING: line over 80 characters
#950: FILE: target/xtensa/mmu_helper.c:784:
+qemu_printf("\tVaddr   Paddr   ASID  Attr RWX 
Cache\n"

total: 0 errors, 1 warnings, 848 lines checked

Patch 10/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
11/17 Checking commit 3d846546c8e2 (target/i386: Simplify how 
x86_cpu_dump_local_apic_state() prints)
12/17 Checking commit 286643ea442b (qom/cpu: Simplify how 
CPUClass::dump_statistics() prints)
13/17 Checking commit f7def015ea17 (qemu-print: New qemu_fprintf(), 
qemu_vfprintf())
14/17 Checking commit c9c4a984c53d (qom/cpu: Simplify how 
CPUClass:cpu_dump_state() prints)
ERROR: line over 90 characters
#1051: FILE: target/i386/helper.c:419:
+qemu_fprintf(f, "RAX=%016" PRIx64 " RBX=%016" PRIx64 " RCX=%016" 
PRIx64 " RDX=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1052: FILE: target/i386/helper.c:420:
+ "RSI=%016" PRIx64 " RDI=%016" PRIx64 " RBP=%016" PRIx64 " 
RSP=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1053: FILE: target/i386/helper.c:421:
+ "R8 =%016" PRIx64 " R9 =%016" PRIx64 " R10=%016" PRIx64 " 
R11=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1054: FILE: target/i386/helper.c:422:
+ "R12=%016" PRIx64 " R13=%016" PRIx64 " R14=%016" PRIx64 " 
R15=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1055: FILE: target/i386/helper.c:423:
+ "RIP=%016" PRIx64 " RFL=%08x [%c%c%c%c%c%c%c] CPL=%d 
II=%d A20=%d SMM=%d HLT=%d\n",

WARNING: line over 80 characters
#1163: FILE: target/i386/helper.c:494:
+qemu_fprintf(f, "CR0=%08x CR2=%016" PRIx64 " CR3=%016" PRIx64 " 
CR4=%08x\n",

WARNING: line over 80 characters
#1751: FILE: target/mips/translate.c:29791:
+qemu_fprintf(f, "CP0 Status  0x%08x Cause   0x%08x EPC0x" 
TARGET_FMT_lx "\n",

total: 5 errors, 2 warnings, 2551 lines checked

Patch 14/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

15/17 Checking commit feff1f11032c (monitor: Clean up how monitor_disas() 
funnels output to monitor)
16/17 

[Qemu-devel] tsan: many race conditions involving mmio

2019-04-17 Thread Frank Yang via Qemu-devel
What's a quick fix for stuff like this?

WARNING: ThreadSanitizer: data race (pid=168036)
  Write of size 8 at 0x7b900017a100 by thread T1 (mutexes: write M2141):
#0 free
/toolchain/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:715:3
(qemu-system-x86_64+0x484028)
#1 phys_sections_free
/usr/local/google/home/lfy/emu/external/qemu/objs/../exec.c:1455:5
(qemu-system-x86_64+0x523608)
#2 address_space_dispatch_free
/usr/local/google/home/lfy/emu/external/qemu/objs/../exec.c:3236
(qemu-system-x86_64+0x523608)
#3 flatview_destroy
/usr/local/google/home/lfy/emu/external/qemu/objs/../memory.c:290:9
(qemu-system-x86_64+0x5bfcd1)
#4 call_rcu_thread
/usr/local/google/home/lfy/emu/external/qemu/objs/../util/rcu.c:284:13
(qemu-system-x86_64+0xb23274)
#5 qemu_thread_trampoline
/usr/local/google/home/lfy/emu/external/qemu/objs/../util/qemu-thread-posix.c:551:17
(qemu-system-x86_64+0xb033c6)

  Previous read of size 8 at 0x7b900017a100 by thread T14:
#0 address_space_lookup_region
/usr/local/google/home/lfy/emu/external/qemu/objs/../exec.c:431:37
(qemu-system-x86_64+0x51b9b8)
#1 address_space_translate_internal
/usr/local/google/home/lfy/emu/external/qemu/objs/../exec.c:447
(qemu-system-x86_64+0x51b9b8)
#2 flatview_do_translate
/usr/local/google/home/lfy/emu/external/qemu/objs/../exec.c:616:15
(qemu-system-x86_64+0x51b318)
#3 flatview_translate
/usr/local/google/home/lfy/emu/external/qemu/objs/../exec.c:680:15
(qemu-system-x86_64+0x52bf20)
#4 address_space_translate
/usr/local/google/home/lfy/emu/external/qemu/objs/../include/exec/memory.h:1896
(qemu-system-x86_64+0x52bf20)
#5 address_space_lduw_internal_cached
/usr/local/google/home/lfy/emu/external/qemu/objs/../memory_ldst.inc.c:264
(qemu-system-x86_64+0x52bf20)
#6 address_space_lduw_le_cached
/usr/local/google/home/lfy/emu/external/qemu/objs/../memory_ldst.inc.c:315:12
(qemu-system-x86_64+0x52c44b)
#7 lduw_le_phys_cached
/usr/local/google/home/lfy/emu/external/qemu/objs/../memory_ldst.inc.c:334
(qemu-system-x86_64+0x52c44b)
#8 virtio_lduw_phys_cached
/usr/local/google/home/lfy/emu/external/qemu/objs/../include/hw/virtio/virtio-access.h:166:12
(qemu-system-x86_64+0x65c97b)
#9 vring_avail_idx
/usr/local/google/home/lfy/emu/external/qemu/objs/../hw/virtio/virtio.c:240
(qemu-system-x86_64+0x65c97b)
#10 virtio_queue_empty
/usr/local/google/home/lfy/emu/external/qemu/objs/../hw/virtio/virtio.c:392
(qemu-system-x86_64+0x65c97b)
#11 virtio_queue_host_notifier_aio_poll
/usr/local/google/home/lfy/emu/external/qemu/objs/../hw/virtio/virtio.c:2427
(qemu-system-x86_64+0x65c97b)
#12 run_poll_handlers_once
/usr/local/google/home/lfy/emu/external/qemu/objs/../util/aio-posix.c:502:13
(qemu-system-x86_64+0xaffd63)
#13 try_poll_mode
/usr/local/google/home/lfy/emu/external/qemu/objs/../util/aio-posix.c:587
(qemu-system-x86_64+0xaffd63)
#14 aio_poll
/usr/local/google/home/lfy/emu/external/qemu/objs/../util/aio-posix.c:618
(qemu-system-x86_64+0xaffd63)
#15 iothread_run
/usr/local/google/home/lfy/emu/external/qemu/objs/../iothread.c:64:9
(qemu-system-x86_64+0xa53344)
#16 qemu_thread_trampoline
/usr/local/google/home/lfy/emu/external/qemu/objs/../util/qemu-thread-posix.c:551:17
(qemu-system-x86_64+0xb033c6)


[Qemu-devel] [PATCH] mips: Fix "Unexpected FPU mode"

2019-04-17 Thread Daniel Santos
In load_elf_binary, struct image_info interp_info is used without being
properly initialized.  One result is that when the ELF's program header
doesn't contain an entry for the ABI flags, then the value of the struct
image_info's fp_abi field is set to whatever happened to be in stack
memory at the time.

This patch both sanitizes interp_info and initializes fp_abi for
TARGET_MIPS to MIPS_ABI_FP_UNKNOWN so that when we don't know the FP
ABI, we don't just blow up.  Currently, this bug is a complete stopper
for some MIPS binaries.

***PLEASE NOTE***
There may be other bugs as a result of struct image_info interp_info
fields not being properly initialized -- this patch only addresses the
fp_abi field.  I reccomend somebody who knows the code better than I
audit this function and the whole of that execution path.

Fixes bug #1825002 and affects 3.1.0 and 4.x, reccomend backporting to
3.1.0.

Signed-off-by: Daniel Santos 
---
 linux-user/elfload.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index c1a26021f8..7f09d572a2 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2698,6 +2698,11 @@ int load_elf_binary(struct linux_binprm *bprm, struct 
image_info *info)
 char *elf_interpreter = NULL;
 char *scratch;
 
+memset(_info, 0, sizeof(interp_info));
+#ifdef TARGET_MIPS
+interp_info.fp_abi = MIPS_ABI_FP_UNKNOWN;
+#endif
+
 info->start_mmap = (abi_ulong)ELF_START_MMAP;
 
 load_elf_image(bprm->filename, bprm->fd, info,
-- 
2.19.2




Re: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around fprintf_function

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



Hi,

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

Message-id: 20190417191805.28198-1-arm...@redhat.com
Subject: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around 
fprintf_function
Type: series

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

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 t [tag update]patchew/20190417191805.28198-1-arm...@redhat.com -> 
patchew/20190417191805.28198-1-arm...@redhat.com
Switched to a new branch 'test'
8b142fc767 include: Move fprintf_function to disas/
d69f01b1b3 disas: Rename include/disas/bfd.h back to include/disas/dis-asm.h
473a1c8779 monitor: Clean up how monitor_disas() funnels output to monitor
363a8f9258 qom/cpu: Simplify how CPUClass:cpu_dump_state() prints
a2be3c05f9 qemu-print: New qemu_fprintf(), qemu_vfprintf()
1f6386c655 qom/cpu: Simplify how CPUClass::dump_statistics() prints
fc33835b61 target/i386: Simplify how x86_cpu_dump_local_apic_state() prints
bea3b777db target: Clean up how the dump_mmu() print
0cf22bb8f4 target: Simplify how the TARGET_cpu_list() print
edae5f9c36 memory: Clean up how mtree_info() prints
409b0a9ef6 block/qapi: Clean up how we print to monitor or stdout
a2db2c108d qsp: Simplify how qsp_report() prints
eeef382c8b tcg: Simplify how dump_drift_info() prints
26f0941f15 tcg: Simplify how dump_exec_info() prints
1befd4787a tcg: Simplify how dump_opcount_info() prints
ca597f2d8e trace: Simplify how st_print_trace_file_status() prints
1c6d436697 include: Include fprintf-fn.h only where needed

=== OUTPUT BEGIN ===
1/17 Checking commit 1c6d43669789 (include: Include fprintf-fn.h only where 
needed)
2/17 Checking commit ca597f2d8e95 (trace: Simplify how 
st_print_trace_file_status() prints)
3/17 Checking commit 1befd4787a61 (tcg: Simplify how dump_opcount_info() prints)
4/17 Checking commit 26f0941f15dc (tcg: Simplify how dump_exec_info() prints)
5/17 Checking commit eeef382c8bdb (tcg: Simplify how dump_drift_info() prints)
6/17 Checking commit a2db2c108d25 (qsp: Simplify how qsp_report() prints)
7/17 Checking commit 409b0a9ef641 (block/qapi: Clean up how we print to monitor 
or stdout)
8/17 Checking commit edae5f9c360a (memory: Clean up how mtree_info() prints)
9/17 Checking commit 0cf22bb8f42e (target: Simplify how the TARGET_cpu_list() 
print)
10/17 Checking commit bea3b777dbfa (target: Clean up how the dump_mmu() print)
WARNING: line over 80 characters
#950: FILE: target/xtensa/mmu_helper.c:784:
+qemu_printf("\tVaddr   Paddr   ASID  Attr RWX 
Cache\n"

total: 0 errors, 1 warnings, 848 lines checked

Patch 10/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
11/17 Checking commit fc33835b6178 (target/i386: Simplify how 
x86_cpu_dump_local_apic_state() prints)
12/17 Checking commit 1f6386c655a5 (qom/cpu: Simplify how 
CPUClass::dump_statistics() prints)
13/17 Checking commit a2be3c05f9fc (qemu-print: New qemu_fprintf(), 
qemu_vfprintf())
14/17 Checking commit 363a8f9258a4 (qom/cpu: Simplify how 
CPUClass:cpu_dump_state() prints)
ERROR: line over 90 characters
#1051: FILE: target/i386/helper.c:419:
+qemu_fprintf(f, "RAX=%016" PRIx64 " RBX=%016" PRIx64 " RCX=%016" 
PRIx64 " RDX=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1052: FILE: target/i386/helper.c:420:
+ "RSI=%016" PRIx64 " RDI=%016" PRIx64 " RBP=%016" PRIx64 " 
RSP=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1053: FILE: target/i386/helper.c:421:
+ "R8 =%016" PRIx64 " R9 =%016" PRIx64 " R10=%016" PRIx64 " 
R11=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1054: FILE: target/i386/helper.c:422:
+ "R12=%016" PRIx64 " R13=%016" PRIx64 " R14=%016" PRIx64 " 
R15=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1055: FILE: target/i386/helper.c:423:
+ "RIP=%016" PRIx64 " RFL=%08x [%c%c%c%c%c%c%c] CPL=%d 
II=%d A20=%d SMM=%d HLT=%d\n",

WARNING: line over 80 characters
#1163: FILE: target/i386/helper.c:494:
+qemu_fprintf(f, "CR0=%08x CR2=%016" PRIx64 " CR3=%016" PRIx64 " 
CR4=%08x\n",

WARNING: line over 80 characters
#1751: FILE: target/mips/translate.c:29791:
+qemu_fprintf(f, "CP0 Status  0x%08x Cause   0x%08x EPC0x" 
TARGET_FMT_lx "\n",

total: 5 errors, 2 warnings, 2551 lines checked

Patch 14/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

15/17 Checking commit 473a1c877930 (monitor: Clean up how monitor_disas() 
funnels output to monitor)
16/17 

Re: [Qemu-devel] [PATCH v2 15/17] monitor: Clean up how monitor_disas() funnels output to monitor

2019-04-17 Thread Eric Blake
On 4/17/19 2:18 PM, Markus Armbruster wrote:
> INIT_DISASSEMBLE_INFO() takes an fprintf()-like callback and a FILE *
> to pass to it.  monitor_disas() passes monitor_fprintf() and the
> current monitor cast to FILE *.  monitor_fprintf() casts it right
> back, and is otherwise identical to monitor_printf().  The
> type-pinning is ugly.

For consistency with other patches in the series, s/pinning/punning/

> 
> Pass qemu_fprintf() and NULL instead.
> 
> monitor_fprintf() is now unused; delete it.
> 
> Signed-off-by: Markus Armbruster 
> Reviewed-by: Dr. David Alan Gilbert 
> ---

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around fprintf_function

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



Hi,

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

Message-id: 20190417191805.28198-1-arm...@redhat.com
Subject: [Qemu-devel] [PATCH v2 00/17] Clean up and simplify around 
fprintf_function
Type: series

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

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag]   patchew/20190417191805.28198-1-arm...@redhat.com -> 
patchew/20190417191805.28198-1-arm...@redhat.com
Switched to a new branch 'test'
d406c1d4cd include: Move fprintf_function to disas/
16ce7b0844 disas: Rename include/disas/bfd.h back to include/disas/dis-asm.h
f8e6976645 monitor: Clean up how monitor_disas() funnels output to monitor
f79afa9517 qom/cpu: Simplify how CPUClass:cpu_dump_state() prints
e1bbc178e1 qemu-print: New qemu_fprintf(), qemu_vfprintf()
7d392f9f86 qom/cpu: Simplify how CPUClass::dump_statistics() prints
090bb102c7 target/i386: Simplify how x86_cpu_dump_local_apic_state() prints
56219b4319 target: Clean up how the dump_mmu() print
4e158b35c2 target: Simplify how the TARGET_cpu_list() print
567d521da5 memory: Clean up how mtree_info() prints
48a4f4d6da block/qapi: Clean up how we print to monitor or stdout
f680529453 qsp: Simplify how qsp_report() prints
8112185742 tcg: Simplify how dump_drift_info() prints
852634721a tcg: Simplify how dump_exec_info() prints
c85405d1e6 tcg: Simplify how dump_opcount_info() prints
21ecaf197a trace: Simplify how st_print_trace_file_status() prints
092f2c47ed include: Include fprintf-fn.h only where needed

=== OUTPUT BEGIN ===
1/17 Checking commit 092f2c47eda6 (include: Include fprintf-fn.h only where 
needed)
2/17 Checking commit 21ecaf197ac6 (trace: Simplify how 
st_print_trace_file_status() prints)
3/17 Checking commit c85405d1e6e5 (tcg: Simplify how dump_opcount_info() prints)
4/17 Checking commit 852634721a33 (tcg: Simplify how dump_exec_info() prints)
5/17 Checking commit 8112185742a2 (tcg: Simplify how dump_drift_info() prints)
6/17 Checking commit f6805294530b (qsp: Simplify how qsp_report() prints)
7/17 Checking commit 48a4f4d6da8d (block/qapi: Clean up how we print to monitor 
or stdout)
8/17 Checking commit 567d521da590 (memory: Clean up how mtree_info() prints)
9/17 Checking commit 4e158b35c234 (target: Simplify how the TARGET_cpu_list() 
print)
10/17 Checking commit 56219b431925 (target: Clean up how the dump_mmu() print)
WARNING: line over 80 characters
#950: FILE: target/xtensa/mmu_helper.c:784:
+qemu_printf("\tVaddr   Paddr   ASID  Attr RWX 
Cache\n"

total: 0 errors, 1 warnings, 848 lines checked

Patch 10/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
11/17 Checking commit 090bb102c765 (target/i386: Simplify how 
x86_cpu_dump_local_apic_state() prints)
12/17 Checking commit 7d392f9f86d6 (qom/cpu: Simplify how 
CPUClass::dump_statistics() prints)
13/17 Checking commit e1bbc178e114 (qemu-print: New qemu_fprintf(), 
qemu_vfprintf())
14/17 Checking commit f79afa951759 (qom/cpu: Simplify how 
CPUClass:cpu_dump_state() prints)
ERROR: line over 90 characters
#1051: FILE: target/i386/helper.c:419:
+qemu_fprintf(f, "RAX=%016" PRIx64 " RBX=%016" PRIx64 " RCX=%016" 
PRIx64 " RDX=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1052: FILE: target/i386/helper.c:420:
+ "RSI=%016" PRIx64 " RDI=%016" PRIx64 " RBP=%016" PRIx64 " 
RSP=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1053: FILE: target/i386/helper.c:421:
+ "R8 =%016" PRIx64 " R9 =%016" PRIx64 " R10=%016" PRIx64 " 
R11=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1054: FILE: target/i386/helper.c:422:
+ "R12=%016" PRIx64 " R13=%016" PRIx64 " R14=%016" PRIx64 " 
R15=%016" PRIx64 "\n"

ERROR: line over 90 characters
#1055: FILE: target/i386/helper.c:423:
+ "RIP=%016" PRIx64 " RFL=%08x [%c%c%c%c%c%c%c] CPL=%d 
II=%d A20=%d SMM=%d HLT=%d\n",

WARNING: line over 80 characters
#1163: FILE: target/i386/helper.c:494:
+qemu_fprintf(f, "CR0=%08x CR2=%016" PRIx64 " CR3=%016" PRIx64 " 
CR4=%08x\n",

WARNING: line over 80 characters
#1751: FILE: target/mips/translate.c:29791:
+qemu_fprintf(f, "CP0 Status  0x%08x Cause   0x%08x EPC0x" 
TARGET_FMT_lx "\n",

total: 5 errors, 2 warnings, 2551 lines checked

Patch 14/17 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

15/17 Checking commit f8e6976645da (monitor: Clean up how monitor_disas() 
funnels output to monitor)
16/17 

Re: [Qemu-devel] [PATCH v7 2/6] target/mips: Optimize ILVEV. MSA instructions

2019-04-17 Thread Richard Henderson
On 4/17/19 5:33 AM, Mateja Marjanovic wrote:
> From: Mateja Marjanovic 
> 
> Optimize set of MSA instructions ILVEV., using
> directly tcg registers and performing logic on them
> instead of using helpers.
> 
> In the following table, the first column is the performance
> before this patch. The second represents the performance
> after converting from helpers to tcg, but without using
> tcg_gen_deposit function. The third one is with using the
> tcg_gen_deposit function and with using a uint64_t constant
> bit mask, and the fourth is with using the tcg_gen_deposit
> function and with a mask which is a tcg constant. The fourth
> is implemented in this patch.
> 
> Performance measurement is done by executing the
> instructions 10 million times on a computer
> with Intel Core i7-3770 CPU @ 3.40GHz×8.
> 
> ==
> || instruction || 1 || 2|| 3|| 4||
> ==
> ||   ilvev.b   || 126.92 ms || 24.52 ms || 25.19 ms || 23.89 ms ||
> ||   ilvev.h   ||  93.67 ms || 23.92 ms || 24.76 ms || 24.31 ms ||
> ||   ilvev.w   || 117.86 ms || 23.83 ms || 21.84 ms || 21.99 ms ||
> ||   ilvev.d   ||  45.49 ms || 19.74 ms || 20.21 ms || 20.07 ms ||
> ==
> 1 - before
> 2 - no-deposit-no-mask-as-tcg-constant
> 3 - with-deposit-no-mask-as-tcg-constant
> 4 - with-deposit-with-mask-as-tcg-constant (final)
> 
> The deposit function is used only in ILVEV.W.
> 
> No-deposit version of the ILVEV.W implementation:
> 
> static inline void gen_ilvev_w(CPUMIPSState *env, uint32_t wd,
>uint32_t ws, uint32_t wt)
> {
> TCGv_i64 t1 = tcg_temp_new_i64();
> TCGv_i64 t2 = tcg_temp_new_i64();
> uint64_t mask = 0xULL;
> 
> tcg_gen_andi_i64(t1, msa_wr_d[wt * 2], mask);
> tcg_gen_andi_i64(t2, msa_wr_d[ws * 2], mask);
> tcg_gen_shli_i64(t2, t2, 32);
> tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2);
> 
> tcg_gen_andi_i64(t1, msa_wr_d[wt * 2 + 1], mask);
> tcg_gen_andi_i64(t2, msa_wr_d[ws * 2 + 1], mask);
> tcg_gen_shli_i64(t2, t2, 32);
> tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2);
> 
> tcg_temp_free_i64(t1);
> tcg_temp_free_i64(t2);
> }
> 
> Suggested-by: Aleksandar Markovic 
> Suggested-by: Philippe Mathieu-Daudé 
> Suggested-by: Richard Henderson 
> Signed-off-by: Mateja Marjanovic 
> ---
>  target/mips/helper.h |  1 -
>  target/mips/msa_helper.c |  9 -
>  target/mips/translate.c  | 87 
> +++-
>  3 files changed, 86 insertions(+), 11 deletions(-)

Reviewed-by: Richard Henderson 


r~



Re: [Qemu-devel] [PATCH v7 1/6] target/mips: Optimize ILVOD. MSA instructions

2019-04-17 Thread Richard Henderson
On 4/17/19 5:33 AM, Mateja Marjanovic wrote:
> From: Mateja Marjanovic 
> 
> Optimize set of MSA instructions ILVOD., using
> directly tcg registers and performing logic on them instead
> of using helpers.
> 
> In the following table, the first column is the performance
> before this patch. The second represents the performance
> after converting from helpers to tcg, but without using
> tcg_gen_deposit function. The third one is with the deposit
> function and with using a uint64_t constant bit mask, and
> the fourth is with the deposit function and with a mask
> which is a tcg constant. The fourth is implemented in this
> patch.
> 
> Performance measurement is done by executing the
> instructions 10 million times on a computer
> with Intel Core i7-3770 CPU @ 3.40GHz×8.
> 
> ==
> || instruction || 1 || 2|| 3|| 4||
> ==
> ||   ilvod.b   || 117.50 ms || 24.13 ms || 24.45 ms || 23.24 ms ||
> ||   ilvod.h   ||  93.16 ms || 24.21 ms || 24.28 ms || 23.20 ms ||
> ||   ilvod.w   || 119.90 ms || 24.15 ms || 23.19 ms || 22.95 ms ||
> ||   ilvod.d   ||  43.01 ms || 21.17 ms || 23.07 ms || 22.59 ms ||
> ==
> 1 - before
> 2 - no-deposit-no-mask-as-tcg-constant
> 3 - with-deposit-no-mask-as-tcg-constant
> 4 - with-deposit-with-mask-as-tcg-constant (final)
> 
> The deposit function is used only in ILVOD.W.
> 
> No-deposit version of the ILVOD.W implementation:
> 
> static inline void gen_ilvod_w(CPUMIPSState *env, uint32_t wd,
>uint32_t ws, uint32_t wt)
> {
> TCGv_i64 t1 = tcg_temp_new_i64();
> TCGv_i64 t2 = tcg_temp_new_i64();
> TCGv_i64 mask = tcg_const_i64(0xULL);
> 
> tcg_gen_and_i64(t1, msa_wr_d[wt * 2], mask);
> tcg_gen_shri_i64(t1, t1, 32);
> tcg_gen_and_i64(t2, msa_wr_d[ws * 2], mask);
> tcg_gen_or_i64(msa_wr_d[wd * 2], t1, t2);
> 
> tcg_gen_and_i64(t1, msa_wr_d[wt * 2 + 1], mask);
> tcg_gen_shri_i64(t1, t1, 32);
> tcg_gen_and_i64(t2, msa_wr_d[ws * 2 + 1], mask);
> tcg_gen_or_i64(msa_wr_d[wd * 2 + 1], t1, t2);
> 
> tcg_temp_free_i64(mask);
> tcg_temp_free_i64(t1);
> tcg_temp_free_i64(t2);
> }
> 
> Suggested-by: Aleksandar Markovic 
> Suggested-by: Philippe Mathieu-Daudé 
> Suggested-by: Richard Henderson 
> Signed-off-by: Mateja Marjanovic 
> ---
>  target/mips/helper.h |  1 -
>  target/mips/msa_helper.c |  7 
>  target/mips/translate.c  | 91 
> +++-
>  3 files changed, 90 insertions(+), 9 deletions(-)

Reviewed-by: Richard Henderson 


r~



Re: [Qemu-devel] [PATCH v3 14/15] char-pty: Print "char device redirected" message to stdout

2019-04-17 Thread Eric Blake
On 4/17/19 2:06 PM, Markus Armbruster wrote:
> char_pty_open() prints a "char device redirected to PTY_NAME (label
> LABEL)" message to the current monitor or else to stderr.  This is not
> an error, so it shouldn't go to stderr.  Print it to stdout instead.
> 
> Why is it even printed?  No other ChardevClass::open() prints anything
> on success.  It's because you need to know PTY_NAME to actually use
> this char device, e.g. like e.g. "socat STDIO,cfmakeraw FILE:PTY_NAME"
> to use the monitor's readline interface.  You can get PTY_NAME with
> "info chardev" (a.k.a. query-chardev for QMP), but only if you already
> have a monitor.
> 
> Signed-off-by: Markus Armbruster 
> ---
>  chardev/char-pty.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Reviewed-by: Eric Blake 

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



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH v2 10/17] target: Clean up how the dump_mmu() print

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

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

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

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

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

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

Re: [Qemu-devel] [PATCH v3] i386: Add new Hygon 'Dhyana' CPU model

2019-04-17 Thread Pavel Hrdina
On Wed, Apr 17, 2019 at 10:53:04PM +0800, Pu Wen wrote:
> On 2019/4/16 22:17, Pavel Hrdina wrote:
> > On Tue, Apr 16, 2019 at 08:06:13PM +0800, Pu Wen wrote:
> > > Add a new base CPU model called 'Dhyana' to model processors from Hygon
> > > Dhyana(family 18h), which derived from AMD EPYC(family 17h).
> > > 
> > > The following features bits have been removed compare to AMD EPYC:
> > > aes, pclmulqdq, sha_ni
> > > 
> > > The Hygon Dhyana support to KVM in Linux is already accepted upstream[1].
> > > So add Hygon Dhyana support to Qemu is necessary to create Hygon's own
> > > CPU model.
> > 
> > I have once question that we will have to solve for EPYC CPUs as well.
> > The name should not be based on the Product name or Model name as that
> > usually doesn't change with introduction of new microarchitecture.
> > 
> > With EPYC we made a mistake to name the CPU like that, luckily with
> > Intel we already use the microarchitecture name, so the EPYC CPU should
> > have been named ZEN-Server and for Ryzen CPUs there should be ZEN-Client
> > if there is any difference or otherwise we can simply use ZEN.
> > 
> > The issue here is what happens once the ZEN2 microarchitecture is out
> > wihch introduces new features and we will have to come up with a CPU
> > name.
> > 
> > Obviously we cannot change/remove the EPYC models so the question is
> > what is the difference between the AMD EPYC CPU and this new Dhyana CPU
> > if they are both based on the ZEN microarchitecture?
> 
> Right now there's no much difference between Dhyana and EPYC from the
> software's view. Dhyana removed the instructions aes, pclmulqdq, sha_ni
> compared to EPYC, but will have it's own implementation such as for aes in
> future CPU models. Hygon also will implement something different from AMD in
> the future.
> 
> > In addition is there any way how we can introduce ZEN-Server &
> > ZEN-Client or simply ZEN, if there is no difference, as an alias or a
> > new model next to the EPYC?
> 
> Also as Eduardo mentioned that there's no CPU model alias or inheritance
> system in x86, so I think it's worthwhile to keep a separate CPU model for
> Hygon.

So what happens once Zen2 is out and there are new Dhyana CPUs based on
the Zen2 microarchitecture with some new features, what CPU models we
will introduce, EPYC-G2 and Dhyana-G2, but that will not correspond to
the CPU model anymore.

My idea was that we should probably introduce CPU model Zen-Server which
could cover both EPYC and Dhyana as they are both based on the Zen
microarchitecture.  The fact that Dhyana doesn't support all the
features is not an issue as QEMU will not use them if they are not
available on the host.

Another possibility is to introduce Zen-Server (or AMD-Zen-Server) and
Hygon-Zen-Server with different set of features.

In the future when new microarchitecture is introduced we can simply use
the exact name of the microarchitecture and we don't have to follow the
road as we did with AMD Opteron CPUs where we have different suffixes.

The whole point is that we should name the CPUs the same way for all
vendors and stop introducing new CPU names that will create more
confusion.

Pavel


signature.asc
Description: PGP signature


[Qemu-devel] [PATCH v2 13/17] qemu-print: New qemu_fprintf(), qemu_vfprintf()

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

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

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
---
 include/qemu/qemu-print.h |  4 
 util/qemu-print.c | 27 +++
 2 files changed, 31 insertions(+)

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




[Qemu-devel] [PATCH v2 07/17] block/qapi: Clean up how we print to monitor or stdout

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

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

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

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

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

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

[Qemu-devel] [PATCH v2 14/17] qom/cpu: Simplify how CPUClass:cpu_dump_state() prints

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

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

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

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

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

[Qemu-devel] [PATCH v2 00/17] Clean up and simplify around fprintf_function

2019-04-17 Thread Markus Armbruster
We pass around fprintf_function callbacks together a FILE * argument.
Three cases:

* We pass fprintf() and stdout, stderr or qemu_log_file.  Okay.

* We pass monitor_fprintf() together with the current monitor cast to
  FILE *.  The type-punning is ugly.

* We pass monitor_printf() cast to fprintf_function together with the
  current monitor cast to FILE *.  Even uglier.

All but two instances can be replaced by using qemu_printf() directly
instead of printing through a callback.

One more can be replace by using new qemu_fprintf() directly.

The last one can use qemu_fprintf() to at least avoid the
type-punning.

Based-on: <20190417190641.26814-1-arm...@redhat.com>

v2:
* PATCH 08: Commit message pasto [Dave]
* PATCH 09: Commit message typo [Dave]
* PATCH 14: Drop spurious change to x86_cpu_dump_local_apic_state()
  [Dave]

Markus Armbruster (17):
  include: Include fprintf-fn.h only where needed
  trace: Simplify how st_print_trace_file_status() prints
  tcg: Simplify how dump_opcount_info() prints
  tcg: Simplify how dump_exec_info() prints
  tcg: Simplify how dump_drift_info() prints
  qsp: Simplify how qsp_report() prints
  block/qapi: Clean up how we print to monitor or stdout
  memory: Clean up how mtree_info() prints
  target: Simplify how the TARGET_cpu_list() print
  target: Clean up how the dump_mmu() print
  target/i386: Simplify how x86_cpu_dump_local_apic_state() prints
  qom/cpu: Simplify how CPUClass::dump_statistics() prints
  qemu-print: New qemu_fprintf(), qemu_vfprintf()
  qom/cpu: Simplify how CPUClass:cpu_dump_state() prints
  monitor: Clean up how monitor_disas() funnels output to monitor
  disas: Rename include/disas/bfd.h back to include/disas/dis-asm.h
  include: Move fprintf_function to disas/

 accel/kvm/kvm-all.c|   4 +-
 accel/tcg/translate-all.c  |  49 ++--
 block/qapi.c   | 120 +-
 bsd-user/main.c|   4 +-
 cpus.c |  21 +-
 disas.c|   5 +-
 disas/alpha.c  |   2 +-
 disas/arm-a64.cc   |   2 +-
 disas/arm.c|   2 +-
 disas/cris.c   |   2 +-
 disas/hppa.c   |   2 +-
 disas/i386.c   |   2 +-
 disas/lm32.c   |   2 +-
 disas/m68k.c   |   2 +-
 disas/microblaze.c |   2 +-
 disas/mips.c   |   2 +-
 disas/moxie.c  |   2 +-
 disas/nanomips.cpp |   2 +-
 disas/nios2.c  |   2 +-
 disas/ppc.c|   2 +-
 disas/riscv.c  |   2 +-
 disas/s390.c   |   2 +-
 disas/sh4.c|   2 +-
 disas/sparc.c  |   2 +-
 disas/tci.c|   2 +-
 disas/xtensa.c |   2 +-
 exec.c |  42 ++--
 hmp.c  |  12 +-
 include/block/qapi.h   |   9 +-
 include/disas/{bfd.h => dis-asm.h} |   5 +-
 include/exec/cpu-all.h |   4 +-
 include/exec/cpu-common.h  |  13 --
 include/exec/log.h |   2 +-
 include/exec/memory-internal.h |   3 +-
 include/exec/memory.h  |   3 +-
 include/monitor/monitor.h  |   1 -
 include/qemu-common.h  |   2 -
 include/qemu/cutils.h  |   2 -
 include/qemu/fprintf-fn.h  |  14 --
 include/qemu/qemu-print.h  |   4 +
 include/qemu/qsp.h |   6 +-
 include/qom/cpu.h  |  24 +-
 include/sysemu/cpus.h  |   4 +-
 linux-user/alpha/cpu_loop.c|   2 +-
 linux-user/cpu_loop-common.h   |   2 +-
 linux-user/cris/cpu_loop.c |   2 +-
 linux-user/main.c  |   2 +-
 linux-user/microblaze/cpu_loop.c   |   4 +-
 linux-user/s390x/cpu_loop.c|   4 +-
 linux-user/sh4/cpu_loop.c  |   2 +-
 linux-user/sparc/cpu_loop.c|   2 +-
 memory.c   | 156 ++---
 monitor.c  |  30 +--
 qemu-img.c |   6 +-
 qemu-io-cmds.c |   2 +-
 qom/cpu.c  |  11 +-
 target/alpha/cpu.c |  15 +-
 target/alpha/cpu.h |   5 +-
 target/alpha/helper.c  |  24 +-
 target/arm/arm-semi.c  |   2 +-
 target/arm/cpu.c   |   1 -
 target/arm/cpu.h   |   5 +-
 target/arm/helper.c|  15 +-
 target/arm/translate-a64.c |  82 +++
 target/arm/translate.c |  58 ++---
 target/arm/translate.h |   7 +-
 target/cris/cpu.c  |  14 +-
 target/cris/cpu.h  |   5 +-
 target/cris/helper.c   |   2 +-
 target/cris/translate.c|  36 +--
 target/hppa/cpu.c  |  14 +-
 target/hppa/cpu.h  

[Qemu-devel] [PATCH v2 15/17] monitor: Clean up how monitor_disas() funnels output to monitor

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

Pass qemu_fprintf() and NULL instead.

monitor_fprintf() is now unused; delete it.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
---
 disas.c   |  3 ++-
 include/monitor/monitor.h |  1 -
 monitor.c | 11 ---
 3 files changed, 2 insertions(+), 13 deletions(-)

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




[Qemu-devel] [PATCH v2 08/17] memory: Clean up how mtree_info() prints

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

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

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

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
---
 exec.c |  40 -
 include/exec/memory-internal.h |   3 +-
 include/exec/memory.h  |   3 +-
 memory.c   | 156 -
 monitor.c  |   3 +-
 5 files changed, 98 insertions(+), 107 deletions(-)

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

[Qemu-devel] [PATCH v2 09/17] target: Simplify how the TARGET_cpu_list() print

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

Drop the callback, and call qemu_printf() instead.

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

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

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

[Qemu-devel] [PATCH v2 03/17] tcg: Simplify how dump_opcount_info() prints

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

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

Drop the callback, and call qemu_printf() instead.

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

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




[Qemu-devel] [PATCH v2 12/17] qom/cpu: Simplify how CPUClass::dump_statistics() prints

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

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

Drop the callback, and call qemu_printf() instead.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
---
 include/qom/cpu.h  | 11 ---
 monitor.c  |  2 +-
 qom/cpu.c  |  5 ++---
 target/ppc/cpu.h   |  3 +--
 target/ppc/translate.c |  9 -
 5 files changed, 12 insertions(+), 18 deletions(-)

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

[Qemu-devel] [PATCH v2 05/17] tcg: Simplify how dump_drift_info() prints

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

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

Drop the callback, and call qemu_printf() instead.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
---
 cpus.c| 15 +--
 include/sysemu/cpus.h |  2 +-
 monitor.c |  2 +-
 3 files changed, 11 insertions(+), 8 deletions(-)

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




[Qemu-devel] [PATCH v2 16/17] disas: Rename include/disas/bfd.h back to include/disas/dis-asm.h

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

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

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

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

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

[Qemu-devel] [PATCH v2 01/17] include: Include fprintf-fn.h only where needed

2019-04-17 Thread Markus Armbruster
Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
---
 include/qemu-common.h | 2 --
 include/qemu/cutils.h | 2 --
 include/sysemu/cpus.h | 1 +
 3 files changed, 1 insertion(+), 4 deletions(-)

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




[Qemu-devel] [PATCH v2 02/17] trace: Simplify how st_print_trace_file_status() prints

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

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

Drop the callback, and call qemu_printf() instead.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
---
 monitor.c  | 2 +-
 trace/simple.c | 7 ---
 trace/simple.h | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

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




[Qemu-devel] [PATCH v2 17/17] include: Move fprintf_function to disas/

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

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

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
---
 include/disas/dis-asm.h   |  5 +++--
 include/qemu/fprintf-fn.h | 14 --
 2 files changed, 3 insertions(+), 16 deletions(-)
 delete mode 100644 include/qemu/fprintf-fn.h

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




[Qemu-devel] [PATCH v2 11/17] target/i386: Simplify how x86_cpu_dump_local_apic_state() prints

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

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

Drop the callback, and call qemu_printf() instead.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
---
 target/i386/cpu.h |  3 +-
 target/i386/helper.c  | 79 ---
 target/i386/monitor.c |  3 +-
 3 files changed, 39 insertions(+), 46 deletions(-)

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

[Qemu-devel] [PATCH v2 04/17] tcg: Simplify how dump_exec_info() prints

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

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

Drop the callback, and call qemu_printf() instead.

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

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

[Qemu-devel] [PATCH v3 02/15] block/ssh: Do not report read/write/flush errors to the user

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

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

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

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




[Qemu-devel] [PATCH v2 06/17] qsp: Simplify how qsp_report() prints

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

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

Drop the callback, and call qemu_printf() instead.

Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
---
 include/block/qapi.h |  1 +
 include/qemu/qsp.h   |  6 ++
 monitor.c|  2 +-
 util/qsp.c   | 21 +++--
 4 files changed, 15 insertions(+), 15 deletions(-)

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




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

2019-04-17 Thread Markus Armbruster
Cc: Alex Williamson 
Signed-off-by: Markus Armbruster 
---
 hw/vfio/pci.c | 19 +--
 1 file changed, 13 insertions(+), 6 deletions(-)

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




[Qemu-devel] [PATCH v3 11/15] qemu-print: New qemu_printf(), qemu_vprintf() etc.

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

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

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

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




[Qemu-devel] [PATCH v3 10/15] monitor error: Make printf()-like functions return a value

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

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

Improve them to return int like printf() does.

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

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

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

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

[Qemu-devel] [PATCH v3 01/15] qemu-img: Use error_vreport() in error_exit()

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

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

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




[Qemu-devel] [PATCH v3 06/15] hpet: Report warnings with warn_report(), not error_printf()

2019-04-17 Thread Markus Armbruster
Cc: "Michael S. Tsirkin" 
Cc: Paolo Bonzini 
Signed-off-by: Markus Armbruster 
---
 hw/timer/hpet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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




[Qemu-devel] [PATCH v3 12/15] blockdev: Make -drive format=help print to stdout

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

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

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




[Qemu-devel] [PATCH v3 05/15] pci: Report fatal errors with error_report(), not error_printf()

2019-04-17 Thread Markus Armbruster
Cc: "Michael S. Tsirkin" 
Cc: Marcel Apfelbaum 
Signed-off-by: Markus Armbruster 
Reviewed-by: Marcel Apfelbaum 
---
 hw/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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




[Qemu-devel] [PATCH v3 08/15] s390x/kvm: Report warnings with warn_report(), not error_printf()

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

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

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

Cc: Thomas Huth 
Cc: qemu-s3...@nongnu.org
Signed-off-by: Markus Armbruster 
Reviewed-by: Thomas Huth 
Reviewed-by: Cornelia Huck 
---
 target/s390x/kvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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




[Qemu-devel] [PATCH v3 13/15] char: Make -chardev help print to stdout

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

Cc: "Marc-André Lureau" 
Cc: Paolo Bonzini 
Signed-off-by: Markus Armbruster 
Reviewed-by: Marc-André Lureau 
Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 
---
 chardev/char.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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




[Qemu-devel] [PATCH v3 09/15] vl: Make -machine $TYPE, help and -accel help print to stdout

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

Cc: Marcel Apfelbaum 
Signed-off-by: Markus Armbruster 
Reviewed-by: Marcel Apfelbaum 
---
 vl.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

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




[Qemu-devel] [PATCH v3 00/15] Clean up use of error_printf()

2019-04-17 Thread Markus Armbruster
This series cleans up two kinds of error_printf() misuse:

* Errors and warnings should be reported with error_report() and
  warn_report().

* Help output should be go to stdout, not stderr.

This is obviously for 4.1.  If nobody objects, I'll take the whole
series through my tree.

Based-on: <20190131164614.19209-1-cferg...@redhat.com>

v3:
* PATCH 03: Replaced by new PATCH 14 [Paolo]
* PATCH 10: Trivial conflict with "[PATCH v7 0/2] log: Make glib
  logging go through QEMU" resolved.

v2:
* PATCH 02: Commit message tweaked, indentation fixed [Eric]
* PATCH 10: Indentation fixed [Marcel]
* PATCH 11: Use-after-free fixed [Patchew]
* PATCH 12: test-util-sockets.c updated along with stubs/monitor.c
* PATCH 14: Commit message typo [Eric]

Markus Armbruster (15):
  qemu-img: Use error_vreport() in error_exit()
  block/ssh: Do not report read/write/flush errors to the user
  loader-fit: Wean off error_printf()
  mips/boston: Report errors with error_report(), not error_printf()
  pci: Report fatal errors with error_report(), not error_printf()
  hpet: Report warnings with warn_report(), not error_printf()
  vfio: Report warnings with warn_report(), not error_printf()
  s390x/kvm: Report warnings with warn_report(), not error_printf()
  vl: Make -machine $TYPE,help and -accel help print to stdout
  monitor error: Make printf()-like functions return a value
  qemu-print: New qemu_printf(), qemu_vprintf() etc.
  blockdev: Make -drive format=help print to stdout
  char: Make -chardev help print to stdout
  char-pty: Print "char device redirected" message to stdout
  monitor: Simplify how -device/device_add print help

 MAINTAINERS |  2 ++
 block/ssh.c | 38 +++-
 block/trace-events  |  3 ++
 blockdev.c  |  9 ++---
 chardev/char-pty.c  |  5 +--
 chardev/char.c  |  3 +-
 hw/core/loader-fit.c| 62 +++--
 hw/mips/boston.c|  6 ++--
 hw/pci/pci.c|  2 +-
 hw/timer/hpet.c |  2 +-
 hw/vfio/pci.c   | 19 ++
 include/monitor/monitor.h   |  7 ++--
 include/qemu/error-report.h |  8 ++---
 include/qemu/qemu-print.h   | 19 ++
 monitor.c   | 69 ++---
 qdev-monitor.c  | 36 ---
 qemu-img.c  |  6 ++--
 stubs/error-printf.c| 13 ---
 stubs/monitor.c |  5 +++
 target/s390x/kvm.c  |  2 +-
 tests/test-util-sockets.c   |  1 +
 util/Makefile.objs  |  1 +
 util/qemu-error.c   | 12 ---
 util/qemu-print.c   | 42 ++
 vl.c| 10 +++---
 25 files changed, 227 insertions(+), 155 deletions(-)
 create mode 100644 include/qemu/qemu-print.h
 create mode 100644 util/qemu-print.c

-- 
2.17.2




[Qemu-devel] [PATCH v3 03/15] loader-fit: Wean off error_printf()

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

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

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

Convert load_fit() to error_report().

Cc: Paul Burton 
Cc: Aleksandar Rikalo 
Signed-off-by: Markus Armbruster 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/core/loader-fit.c | 62 +---
 1 file changed, 36 insertions(+), 26 deletions(-)

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

[Qemu-devel] [PATCH v3 14/15] char-pty: Print "char device redirected" message to stdout

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

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

Signed-off-by: Markus Armbruster 
---
 chardev/char-pty.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

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




[Qemu-devel] [PATCH v3 15/15] monitor: Simplify how -device/device_add print help

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

Cc: Dr. David Alan Gilbert 
Signed-off-by: Markus Armbruster 
Reviewed-by: Dr. David Alan Gilbert 
---
 include/monitor/monitor.h |  3 ---
 monitor.c | 16 
 qdev-monitor.c| 36 ++--
 3 files changed, 18 insertions(+), 37 deletions(-)

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




[Qemu-devel] [PATCH v3 04/15] mips/boston: Report errors with error_report(), not error_printf()

2019-04-17 Thread Markus Armbruster
Cc: Paul Burton 
Cc: Aleksandar Rikalo 
Signed-off-by: Markus Armbruster 
Reviewed-by: Philippe Mathieu-Daudé 
---
 hw/mips/boston.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

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




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

2019-04-17 Thread Laszlo Ersek
Hi Joachim,

On 04/17/19 19:09, Joachim Durchholz wrote:
> Sorry, I'm done having to argue against(!) a person who's stonewalling
> me by wilfully ignoring differences ("doesn't work perfectly"
> interpreted as "does not work at all"), discounting
> just-for-testing-purpose workarounds as if they were actual proposed
> solutions ("not a sane approach"), ignoring the use case (still
> insisting on terminal size mutability), and proposing a nonworking
> solution (-nographic does not give me any output, of course because it
> doesn't have a terminal to talk to).

you use the word "solution" twice above, but in this thread, I haven't
seen a problem statement from you.

What is the end goal you're trying to achieve?

The source file "ui/curses.c" carries the following comment at the top:

  QEMU curses/ncurses display driver

It is a display backend that is based on Curses.

Curses -- in its originally standardized form, XCURSES -- is an
interface specification for manipulating terminals. Please see:

  https://pubs.opengroup.org/onlinepubs/7908799/xcurses/intov.html

It writes:

[...] a comprehensive API lets the application perform terminal
operations. The Curses run-time system receives each terminal
request and sends appropriate commands to the terminal to achieve
the desired effect. [...]  Applications using Curses should not also
control the terminal using capabilities of the general terminal
interface defined in the XBD specification, General Terminal
Interface. [...]

(I sent the link to the General Terminal Interface earlier.)

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

> what's the reasoning behind "We need a terminal output" in curses.c?

The reasoning is that "curses.c" is a QEMU display backend written in
terms of the Curses [XCURSES] interface specification, and that
interface specification is inherently based on terminals, as defined by
the General Terminal Interface of the Single Unix Specification. (BTW
SUS and POSIX have merged into one set of specs at SUSv3.)

If you tell us what you want to achieve in the end (i.e. you state the
problem), maybe we can tell you what to use *instead of* "ui/curses.c",
as the QEMU display backend. We might also be able to suggest ways to
use "ui/curses.c", so that it give you what you need.


Let me speculate a bit. You mentioned wanting to connect "ui/curses.c"
to a pipe, possibly to transfer the output elsewhere. This is a common
use case -- it's what terminal emulators such as "xterm" do, also what
"ssh" does (when you log in interactively with it). "screen" and "tmux"
are other programs in this class.

The way they all work is, they set up a pseudo-terminal (pty). The pty
has a master end and a slave end. The slave end looks like a real
terminal and provides the General Terminal Interface -- so "ui/curses.c"
would consume that. The kernel driver for pseudo-terminals provides all
the necessary terminal features. On the master end, you get a file
descriptor to a bidirectional stream (similar to a unix domain stream
socket). The various terminal emulators (xterm, ssh, screen, tmux) read
and write the master end, and perform various stuff on the data received
(e.g. "screen" passes the data for display to the other screen process
for display, if there is such an "other" screen process; xterm draws the
characters, clears the screen, changes colors, and beeps; sshd encrypts
the data, transfers it over the network, ssh decrypts the data and
writes it to the local *slave* end; and so on).

One interface to check here is posix_openpt():

http://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_openpt.html

What's important here is that the translation between the master end and
the slave end is *thick*. For example, assuming appropriate settings, if
you write the appropriate character ("INTR") to the master-end file
descriptor, the program for which the slave-end is the "controlling
terminal" -- another term to look up in POSIX -- will get a SIGINT. This
translation (i.e. the raising of SIGINT) is done by the kernel's
pseudo-terminal (pty) driver. This is what happens e.g. when you press
"Ctrl-C" in xterm.

Anyway, you mentioned "pexpect":

https://pexpect.readthedocs.io/en/stable/

"pexpect" is a python facility for automating interactions with programs
that require a terminal (such as the QEMU display backend
"ui/curses.c"). I don't know "pexpect"'s internals, but it will
*unavoidably* have to use a pseudo-terminal.

I think that, if you need "just a pipe", you can satisfy "ui/curses.c"'s
need for a terminal by giving it a slave terminal device with "pexpect".
Then you can read the master-end (pexpect should let you do that as
well) -- the master-end will indeed read similarly to pipe. Just be
aware that all the terminal output goo, such as cursor positioning,
color change sequences, beeps, screen resolution changes, etc, will show
up as binary garbage in the stream.

Thanks
Laszlo



Re: [Qemu-devel] [PATCH v2 14.5/15] char-pty: Print "char device redirected" message to stdout

2019-04-17 Thread no-reply
Patchew URL: https://patchew.org/QEMU/87mukov6vk@dusky.pond.sub.org/



Hi,

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

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

  AR  libqemuutil.a
  LINKelf2dmp
  AS  optionrom/multiboot.o
/tmp/qemu-test/src/chardev/char-pty.c:214:5: error: implicit declaration of 
function 'qemu_printf' is invalid in C99 
[-Werror,-Wimplicit-function-declaration]
qemu_printf("char device redirected to %s (label %s)\n",
^
/tmp/qemu-test/src/chardev/char-pty.c:214:5: error: this function declaration 
is not a prototype [-Werror,-Wstrict-prototypes]
2 errors generated.
  LINKivshmem-client
  LINKivshmem-server


The full log is available at
http://patchew.org/logs/87mukov6vk@dusky.pond.sub.org/testing.asan/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

  1   2   >