Re: [Qemu-devel] [PATCH 3/4] pc-bios/s390-ccw: fix non-sequential boot entries (eckd)

2018-04-15 Thread Thomas Huth
On 14.04.2018 00:08, Collin Walling wrote:
> zIPL boot menu entries can be non-sequential. Let's account
> for this issue for the s390 zIPL boot menu. Since this boot
> menu is actually an imitation and is not completely capable
> of everything the real zIPL menu can do, let's also print a
> different banner to the user.
> 
> Signed-off-by: Collin Walling 
> Reported-by: Vasily Gorbik 
> ---
>  pc-bios/s390-ccw/menu.c | 29 -
>  1 file changed, 20 insertions(+), 9 deletions(-)
> 
> diff --git a/pc-bios/s390-ccw/menu.c b/pc-bios/s390-ccw/menu.c
> index 96eec81..aaf5d61 100644
> --- a/pc-bios/s390-ccw/menu.c
> +++ b/pc-bios/s390-ccw/menu.c
> @@ -158,7 +158,7 @@ static void boot_menu_prompt(bool retry)
>  }
>  }
>  
> -static int get_boot_index(int entries)
> +static int get_boot_index(bool *valid_entries)
>  {
>  int boot_index;
>  bool retry = false;
> @@ -168,7 +168,8 @@ static int get_boot_index(int entries)
>  boot_menu_prompt(retry);
>  boot_index = get_index();
>  retry = true;
> -} while (boot_index < 0 || boot_index >= entries);
> +} while (boot_index < 0 || boot_index >= MAX_BOOT_ENTRIES ||
> + !valid_entries[boot_index]);
>  
>  sclp_print("\nBooting entry #");
>  sclp_print(uitoa(boot_index, tmp, sizeof(tmp)));
> @@ -176,7 +177,8 @@ static int get_boot_index(int entries)
>  return boot_index;
>  }
>  
> -static void zipl_println(const char *data, size_t len)
> +/* Returns the entry number that was printed */
> +static int zipl_print_entry(const char *data, size_t len)
>  {
>  char buf[len + 2];
>  
> @@ -185,12 +187,15 @@ static void zipl_println(const char *data, size_t len)
>  buf[len + 1] = '\0';
>  
>  sclp_print(buf);
> +
> +return buf[0] == ' ' ? atoui(buf + 1) : atoui(buf);
>  }
>  
>  int menu_get_zipl_boot_index(const char *menu_data)
>  {
>  size_t len;
> -int entries;
> +int entry;
> +bool valid_entries[MAX_BOOT_ENTRIES] = {false};
>  uint16_t zipl_flag = *(uint16_t *)(menu_data - ZIPL_FLAG_OFFSET);
>  uint16_t zipl_timeout = *(uint16_t *)(menu_data - ZIPL_TIMEOUT_OFFSET);
>  
> @@ -202,19 +207,25 @@ int menu_get_zipl_boot_index(const char *menu_data)
>  timeout = zipl_timeout * 1000;
>  }
>  
> -/* Print and count all menu items, including the banner */
> -for (entries = 0; *menu_data; entries++) {
> +/* Print banner */
> +sclp_print("s390-ccw zIPL Boot Menu\n\n");
> +menu_data += strlen(menu_data) + 1;
> +
> +/* Print entries */
> +while (*menu_data) {
>  len = strlen(menu_data);
> -zipl_println(menu_data, len);
> +entry = zipl_print_entry(menu_data, len);
>  menu_data += len + 1;
>  
> -if (entries < 2) {
> +valid_entries[entry] = true;
> +
> +if (entry == 0) {
>  sclp_print("\n");
>  }
>  }
>  
>  sclp_print("\n");
> -return get_boot_index(entries - 1); /* subtract 1 to exclude banner */
> +return get_boot_index(valid_entries);
>  }

Reviewed-by: Thomas Huth 



Re: [Qemu-devel] [PATCH v3 33/41] hw/net: Use the BYTE-based definitions

2018-04-15 Thread Stefan Weil
Am 16.04.2018 um 01:42 schrieb Philippe Mathieu-Daudé:
> It eases code review, unit is explicit.
> 
> Patch generated using:
> 
>   $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/
> 
> and modified manually.
> 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  include/hw/net/allwinner_emac.h | 5 +++--
>  hw/net/e1000e.c | 7 ---
>  hw/net/e1000x_common.c  | 3 ++-
>  hw/net/eepro100.c   | 7 +++
>  4 files changed, 12 insertions(+), 10 deletions(-)
> 
> diff --git a/include/hw/net/allwinner_emac.h b/include/hw/net/allwinner_emac.h
> index 4cc8aab7ec..4b53b6485c 100644
> --- a/include/hw/net/allwinner_emac.h
> +++ b/include/hw/net/allwinner_emac.h
> @@ -23,6 +23,7 @@
>  #ifndef ALLWINNER_EMAC_H
>  #define ALLWINNER_EMAC_H
>  
> +#include "qemu/units.h"
>  #include "net/net.h"
>  #include "qemu/fifo8.h"
>  #include "hw/net/mii.h"
> @@ -125,8 +126,8 @@
>  #define EMAC_INT_RX (1 << 8)
>  
>  /* Due to lack of specifications, size of fifos is chosen arbitrarily */
> -#define TX_FIFO_SIZE(4 * 1024)
> -#define RX_FIFO_SIZE(32 * 1024)
> +#define TX_FIFO_SIZE(4 * K_BYTE)
> +#define RX_FIFO_SIZE(32 * K_BYTE)
>  
>  #define NUM_TX_FIFOS2
>  #define RX_HDR_SIZE 8
> diff --git a/hw/net/e1000e.c b/hw/net/e1000e.c
> index 16a9417a85..101efe7c83 100644
> --- a/hw/net/e1000e.c
> +++ b/hw/net/e1000e.c
> @@ -34,6 +34,7 @@
>  */
>  
>  #include "qemu/osdep.h"
> +#include "qemu/units.h"
>  #include "net/net.h"
>  #include "net/tap.h"
>  #include "qemu/range.h"
> @@ -81,10 +82,10 @@ typedef struct E1000EState {
>  #define E1000E_IO_IDX   2
>  #define E1000E_MSIX_IDX 3
>  
> -#define E1000E_MMIO_SIZE(128 * 1024)
> -#define E1000E_FLASH_SIZE   (128 * 1024)
> +#define E1000E_MMIO_SIZE(128 * K_BYTE)
> +#define E1000E_FLASH_SIZE   (128 * K_BYTE)
>  #define E1000E_IO_SIZE  (32)
> -#define E1000E_MSIX_SIZE(16 * 1024)
> +#define E1000E_MSIX_SIZE(16 * K_BYTE)
>  
>  #define E1000E_MSIX_TABLE   (0x)
>  #define E1000E_MSIX_PBA (0x2000)
> diff --git a/hw/net/e1000x_common.c b/hw/net/e1000x_common.c
> index eb0e097137..58c8db77e9 100644
> --- a/hw/net/e1000x_common.c
> +++ b/hw/net/e1000x_common.c
> @@ -23,6 +23,7 @@
>  */
>  
>  #include "qemu/osdep.h"
> +#include "qemu/units.h"
>  #include "hw/hw.h"
>  #include "hw/pci/pci.h"
>  #include "net/net.h"
> @@ -111,7 +112,7 @@ bool e1000x_is_oversized(uint32_t *mac, size_t size)
>  static const int maximum_ethernet_vlan_size = 1522;
>  /* this is the size past which hardware will
> drop packets when setting LPE=1 */
> -static const int maximum_ethernet_lpe_size = 16384;
> +static const int maximum_ethernet_lpe_size = 16 * K_BYTE;
>  
>  if ((size > maximum_ethernet_lpe_size ||
>  (size > maximum_ethernet_vlan_size
> diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c
> index a07a63247e..a02e2b55e8 100644
> --- a/hw/net/eepro100.c
> +++ b/hw/net/eepro100.c
> @@ -41,6 +41,7 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "qemu/units.h"
>  #include "hw/hw.h"
>  #include "hw/pci/pci.h"
>  #include "net/net.h"
> @@ -60,8 +61,6 @@
>   * changed to pad short packets itself. */
>  #define CONFIG_PAD_RECEIVED_FRAMES
>  
> -#define KiB 1024
> -
>  /* Debug EEPRO100 card. */
>  #if 0
>  # define DEBUG_EEPRO100
> @@ -104,9 +103,9 @@
>  /* Use 64 word EEPROM. TODO: could be a runtime option. */
>  #define EEPROM_SIZE 64
>  
> -#define PCI_MEM_SIZE(4 * KiB)
> +#define PCI_MEM_SIZE(4 * K_BYTE)
>  #define PCI_IO_SIZE 64
> -#define PCI_FLASH_SIZE  (128 * KiB)
> +#define PCI_FLASH_SIZE  (128 * K_BYTE)
>  
>  #define BITS(n, m) (((0xU << (31 - n)) >> (31 - n + m)) << m)


Technically this is fine, therefore

Reviewed-by: Stefan Weil 

Practically I'd prefer replacing all K_BYTE by KiB, because that is the
standard name with a precise definition:
https://en.wikipedia.org/wiki/Kibibyte.

Stefan



Re: [Qemu-devel] [PATCH for-2.12? 1/4] configure: Really use local libfdt if the system one is too old

2018-04-15 Thread Thomas Huth
On 16.04.2018 01:05, Philippe Mathieu-Daudé wrote:
> QEMU requires libfdt version >= 1.4.2.
> If the host has an older libfdt installed, the configure script will use
> a (git cloned) local version.
> 
> Example with Debian 8:
> $ dpkg-query --showformat='${Version}\n' --show libfdt-dev
> 1.4.0+dfsg-1
> $ ./configure
> [...]
> fdt support   yes  # from git submodule 'dtc'
> 
> If this case occurs, the linker will have 2 different libfdt available in
> the library search path. The default behavior is to search the system path
> first, then the local path.
> 
> Even if the configure script noticed the libfdt is too old and clone a more
> recent locally, when linking the system library is selected first, and the
> link process eventually fails:
> 
>   LINKmips64el-softmmu/qemu-system-mips64el
> ../hw/core/loader-fit.o: In function `load_fit':
> /root/src/github.com/philmd/qemu/hw/core/loader-fit.c:278: undefined 
> reference to `fdt_first_subnode'
> /root/src/github.com/philmd/qemu/hw/core/loader-fit.c:286: undefined 
> reference to `fdt_next_subnode'
> /root/src/github.com/philmd/qemu/hw/core/loader-fit.c:277: undefined 
> reference to `fdt_first_subnode'
> collect2: error: ld returned 1 exit status
> Makefile:201: recipe for target 'qemu-system-mips64el' failed
> make[1]: *** [qemu-system-mips64el] Error 1
> 
> QEMU already uses a kludge to enforce local CFLAGS before system ones for
> libpixman and libfdt, add a similar kludge for the LDFLAGS to enforce using
> the local libfdt.
> 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  configure | 6 +-
>  rules.mak | 2 +-
>  2 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/configure b/configure
> index 0a19b033bc..162e804b49 100755
> --- a/configure
> +++ b/configure
> @@ -3773,7 +3773,8 @@ EOF
>symlink "$source_path/dtc/scripts" "dtc/scripts"
>fi
>fdt_cflags="-I\$(SRC_PATH)/dtc/libfdt"
> -  fdt_libs="-L\$(BUILD_DIR)/dtc/libfdt $fdt_libs"
> +  fdt_ldflags="-L\$(BUILD_DIR)/dtc/libfdt"
> +  fdt_libs="$fdt_libs"
>elif test "$fdt" = "yes" ; then
># Not a git build & no libfdt found, prompt for system install
>error_exit "DTC (libfdt) version >= 1.4.2 not present." \
> @@ -5715,6 +5716,7 @@ echo_version() {
>  
>  # prepend pixman and ftd flags after all config tests are done
>  QEMU_CFLAGS="$pixman_cflags $fdt_cflags $QEMU_CFLAGS"
> +QEMU_LDFLAGS="$fdt_ldflags $QEMU_LDFLAGS"
>  libs_softmmu="$pixman_libs $libs_softmmu"

I think the pixman lines could be removed now that we do not have an
internal pixman version anymore (but that's something for a separate patch)

>  echo "Install prefix$prefix"
> @@ -5745,6 +5747,7 @@ echo "ARFLAGS   $ARFLAGS"
>  echo "CFLAGS$CFLAGS"
>  echo "QEMU_CFLAGS   $QEMU_CFLAGS"
>  echo "LDFLAGS   $LDFLAGS"
> +echo "QEMU_LDFLAGS  $QEMU_LDFLAGS"
>  echo "make  $make"
>  echo "install   $install"
>  echo "python$python"
> @@ -6679,6 +6682,7 @@ else
>  fi
>  echo "LDFLAGS=$LDFLAGS" >> $config_host_mak
>  echo "LDFLAGS_NOPIE=$LDFLAGS_NOPIE" >> $config_host_mak
> +echo "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
>  echo "LD_REL_FLAGS=$LD_REL_FLAGS" >> $config_host_mak
>  echo "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak
>  echo "LIBS+=$LIBS" >> $config_host_mak
> diff --git a/rules.mak b/rules.mak
> index 93a07027b0..04c7f74d07 100644
> --- a/rules.mak
> +++ b/rules.mak
> @@ -73,7 +73,7 @@ expand-objs = $(strip $(sort $(filter %.o,$1)) \
>  # must link with the C++ compiler, not the plain C compiler.
>  LINKPROG = $(or $(CXX),$(CC))
>  
> -LINK = $(call quiet-command, $(LINKPROG) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) 
> -o $@ \
> +LINK = $(call quiet-command, $(LINKPROG) $(QEMU_LDFLAGS) $(QEMU_CFLAGS) 
> $(CFLAGS) $(LDFLAGS) -o $@ \
> $(call process-archive-undefs, $1) \
> $(version-obj-y) $(call extract-libs,$1) 
> $(LIBS),"LINK","$(TARGET_DIR)$@")

Looks reasonable.

Reviewed-by: Thomas Huth 



Re: [Qemu-devel] [PATCH 2/4] configure: Display if libfdt is from system or git

2018-04-15 Thread Thomas Huth
On 16.04.2018 01:05, Philippe Mathieu-Daudé wrote:
> The configure script outputs "yes" regardless which libfdt is used:
> 
>   ./configure
>   [...]
>   fdt support   yes
> 
> Sometimes you can have both system and local git version available,
> change the configure script to display which library got selected:
> 
>   debian8$ dpkg-query --showformat='${Version}\n' --show libfdt-dev
>   1.4.0+dfsg-1
> 
>   debian8$ ./configure
>   [...]
>   fdt support   git
> 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  configure | 9 -
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/configure b/configure
> index 162e804b49..056b391f22 100755
> --- a/configure
> +++ b/configure
> @@ -3758,15 +3758,14 @@ int main(void) { fdt_first_subnode(0, 0); return 0; }
>  EOF
>if compile_prog "" "$fdt_libs" ; then
>  # system DTC is good - use it
> -fdt=yes
> +fdt=system
>else
># have GIT checkout, so activate dtc submodule
>if test -e "${source_path}/.git" ; then
>git_submodules="${git_submodules} dtc"
>fi
>if test -d "${source_path}/dtc/libfdt" || test -e 
> "${source_path}/.git" ; then
> -  fdt=yes
> -  dtc_internal="yes"
> +  fdt=git

That's ok for git checkout, but what about release tarballs? I'd strange
to see "git" here. So maybe better use "internal" instead of "git" here?

OTOH, capstone is also using the term "git" here, so this is just
consistent here...

 Thomas



Re: [Qemu-devel] [PATCH v3 17/41] hw/m68k: Use the BYTE-based definitions

2018-04-15 Thread Thomas Huth
On 16.04.2018 01:42, Philippe Mathieu-Daudé wrote:
> It eases code review, unit is explicit.
> 
> Patch generated using:
> 
>   $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/
> 
> and modified manually.
> 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/m68k/mcf5208.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/m68k/mcf5208.c b/hw/m68k/mcf5208.c
> index fac0d09cbc..673d65f8fd 100644
> --- a/hw/m68k/mcf5208.c
> +++ b/hw/m68k/mcf5208.c
> @@ -6,6 +6,7 @@
>   * This code is licensed under the GPL
>   */
>  #include "qemu/osdep.h"
> +#include "qemu/units.h"
>  #include "qemu/error-report.h"
>  #include "qapi/error.h"
>  #include "qemu-common.h"
> @@ -241,7 +242,7 @@ static void mcf5208evb_init(MachineState *machine)
>  memory_region_add_subregion(address_space_mem, 0x4000, ram);
>  
>  /* Internal SRAM.  */
> -memory_region_init_ram(sram, NULL, "mcf5208.sram", 16384, _fatal);
> +memory_region_init_ram(sram, NULL, "mcf5208.sram", 16 * K_BYTE, 
> _fatal);
>  memory_region_add_subregion(address_space_mem, 0x8000, sram);
>  
>  /* Internal peripherals.  */
> 

Reviewed-by: Thomas Huth 



Re: [Qemu-devel] [PATCH v3 01/41] hw: Clean "hw/devices.h" includes

2018-04-15 Thread Thomas Huth
On 16.04.2018 01:42, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  include/hw/devices.h | 7 ++-
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/include/hw/devices.h b/include/hw/devices.h
> index 861ddea8af..0e27feb0c2 100644
> --- a/include/hw/devices.h
> +++ b/include/hw/devices.h
> @@ -1,13 +1,10 @@
>  #ifndef QEMU_DEVICES_H
>  #define QEMU_DEVICES_H
>  
> -#include "hw/irq.h"
> -
> -/* ??? Not all users of this file can include cpu-common.h.  */
> -struct MemoryRegion;
> -
>  /* Devices that have nowhere better to go.  */
>  
> +#include "hw/hw.h"
> +
>  /* smc91c111.c */
>  void smc91c111_init(NICInfo *, uint32_t, qemu_irq);

IMHO we should rather get rid of devices.h (in a separate patch series)
and introduce proper small headers à la smc91c111.h for the single
sections in here... Just my 0.02 €.

 Thomas



[Qemu-devel] [Bug 1461918] Re: guest hangs after use ethtool to set scatter-gather on

2018-04-15 Thread Launchpad Bug Tracker
[Expired for QEMU because there has been no activity for 60 days.]

** Changed in: qemu
   Status: Incomplete => Expired

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

Title:
  guest hangs after use ethtool to set scatter-gather on

Status in QEMU:
  Expired

Bug description:
  On the guests,  i have a rtl8139 nic,  I use ethtool to set  scatter-gather 
on ( ethtool -K eth0 sg on ),
  after that,   at host side,  I  use scp to send a file into guest.  As a 
result, guest hang.
  At that point qemu is using 100% of one host CPU, about 100% guest.

  If guest is centOS6.5, with no problem.


  The guest system is Fedora release 19(Kernel 3.11.10-200.fc19.x86_64).

  host system is debian 7.1.
  Kernel:3.10.0
  Qemu: 2.3.0

  cmd:
  /boot/qemu-2.3.0-bin/qemu-system-x86_64 -vnc :13 -enable-kvm -name fedora 
-smp sockets=1,cores=2 -cpu core2duo -nodefaults -vga cirrus -k en-us -boot 
menu=on,splash-time=8000 -m 2048 -usb -drive 
file=/boot/vm-disk-1.qcow2,if=none,id=drive-ide0,cache=none,aio=native -device 
ide-hd,bus=ide.0,unit=0,drive=drive-ide0,id=ide0,bootindex=100 -netdev 
type=tap,id=net0,ifname=200,script=/etc/kvm/vtp-bridge -device 
rtl8139,romfile=,mac=FE:FC:FE:5C:58:65,netdev=net0,bus=pci.0,addr=0x12,id=net0

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



Re: [Qemu-devel] [PATCH for-2.13 2/4] platform-bus-device: use device plug callback instead of machine_done notifier

2018-04-15 Thread David Gibson
On Thu, Apr 12, 2018 at 06:40:19PM +0200, Igor Mammedov wrote:
> platform-bus were using machine_done notifier to get and map
> (assign irq/mmio resources) dynamically added sysbus devices
> after all '-device' options had been processed.
> That however creates non obvious dependencies on ordering of
> machine_done notifiers and requires carefull line juggling
> to keep it working. For example see comment above
> create_platform_bus() and 'straitforward' arm_load_kernel()
> had to converted to machine_done notifier and that lead to
> yet another machine_done notifier to keep it working
> arm_register_platform_bus_fdt_creator().
> 
> Instead of hiding resource assignment in platform-bus-device
> to magically initialize sysbus devices, use device plug
> callback and assign resources explicitly at board level
> at the moment each -device option is being processed.
> 
> That adds a bunch of machine declaration boiler plate to
> e500plat board, similar to ARM/x86 but gets rid of hidden
> machine_done notifier and would allow to remove the dependent
> notifiers in ARM code simplifying it and making code flow
> easier to follow.
> 
> Signed-off-by: Igor Mammedov 
> ---
> CC: ag...@suse.de
> CC: da...@gibson.dropbear.id.au
> CC: qemu-...@nongnu.org
> ---
>  hw/ppc/e500.h |  3 +++
>  include/hw/arm/virt.h |  3 +++
>  include/hw/platform-bus.h |  4 ++--
>  hw/arm/sysbus-fdt.c   |  3 ---
>  hw/arm/virt.c | 36 
>  hw/core/platform-bus.c| 29 ---
>  hw/ppc/e500.c | 37 +
>  hw/ppc/e500plat.c | 60 
> +--
>  8 files changed, 129 insertions(+), 46 deletions(-)
> 
> diff --git a/hw/ppc/e500.h b/hw/ppc/e500.h
> index 70ba1d8..d0f8ddd 100644
> --- a/hw/ppc/e500.h
> +++ b/hw/ppc/e500.h
> @@ -2,6 +2,7 @@
>  #define PPCE500_H
>  
>  #include "hw/boards.h"
> +#include "hw/sysbus.h"
>  
>  typedef struct PPCE500Params {
>  int pci_first_slot;
> @@ -26,6 +27,8 @@ typedef struct PPCE500Params {
>  
>  void ppce500_init(MachineState *machine, PPCE500Params *params);
>  
> +void ppce500_plug_dynamic_sysbus_device(SysBusDevice *sbdev);
> +
>  hwaddr booke206_page_size_to_tlb(uint64_t size);
>  
>  #endif
> diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
> index ba0c1a4..5535760 100644
> --- a/include/hw/arm/virt.h
> +++ b/include/hw/arm/virt.h
> @@ -86,11 +86,14 @@ typedef struct {
>  bool no_pmu;
>  bool claim_edge_triggered_timers;
>  bool smbios_old_sys_ver;
> +HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
> +   DeviceState *dev);
>  } VirtMachineClass;
>  
>  typedef struct {
>  MachineState parent;
>  Notifier machine_done;
> +DeviceState *platform_bus_dev;
>  FWCfgState *fw_cfg;
>  bool secure;
>  bool highmem;
> diff --git a/include/hw/platform-bus.h b/include/hw/platform-bus.h
> index a00775c..19e20c5 100644
> --- a/include/hw/platform-bus.h
> +++ b/include/hw/platform-bus.h
> @@ -37,8 +37,6 @@ typedef struct PlatformBusDevice PlatformBusDevice;
>  struct PlatformBusDevice {
>  /*< private >*/
>  SysBusDevice parent_obj;
> -Notifier notifier;
> -bool done_gathering;
>  
>  /*< public >*/
>  uint32_t mmio_size;
> @@ -54,4 +52,6 @@ int platform_bus_get_irqn(PlatformBusDevice *platform_bus, 
> SysBusDevice *sbdev,
>  hwaddr platform_bus_get_mmio_addr(PlatformBusDevice *pbus, SysBusDevice 
> *sbdev,
>int n);
>  
> +void platform_bus_link_device(PlatformBusDevice *pbus, SysBusDevice *sbdev);
> +
>  #endif /* HW_PLATFORM_BUS_H */
> diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c
> index d68e3dc..80ff70e 100644
> --- a/hw/arm/sysbus-fdt.c
> +++ b/hw/arm/sysbus-fdt.c
> @@ -506,9 +506,6 @@ static void 
> add_all_platform_bus_fdt_nodes(ARMPlatformBusFDTParams *fdt_params)
>  dev = qdev_find_recursive(sysbus_get_default(), 
> TYPE_PLATFORM_BUS_DEVICE);
>  pbus = PLATFORM_BUS_DEVICE(dev);
>  
> -/* We can only create dt nodes for dynamic devices when they're ready */
> -assert(pbus->done_gathering);
> -
>  PlatformBusFDTData data = {
>  .fdt = fdt,
>  .irq_start = irq_start,
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index 94dcb12..2e10d8b 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -1087,6 +1087,7 @@ static void create_platform_bus(VirtMachineState *vms, 
> qemu_irq *pic)
>  qdev_prop_set_uint32(dev, "mmio_size",
>  platform_bus_params.platform_bus_size);
>  qdev_init_nofail(dev);
> +vms->platform_bus_dev = dev;
>  s = SYS_BUS_DEVICE(dev);
>  
>  for (i = 0; i < platform_bus_params.platform_bus_num_irqs; i++) {
> @@ -1536,9 +1537,37 @@ static const CPUArchIdList 
> *virt_possible_cpu_arch_ids(MachineState *ms)
>  return ms->possible_cpus;
>  }
>  
> +static void 

Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller

2018-04-15 Thread David Gibson
On Thu, Apr 12, 2018 at 10:36:10AM +0200, Cédric Le Goater wrote:
> On 04/12/2018 07:16 AM, David Gibson wrote:
> > On Mon, Feb 12, 2018 at 09:55:17AM +1100, Benjamin Herrenschmidt wrote:
> >> On Sun, 2018-02-11 at 19:08 +1100, David Gibson wrote:
> >>> On Thu, Jan 18, 2018 at 08:27:52AM +1100, Benjamin Herrenschmidt wrote:
>  On Wed, 2018-01-17 at 15:39 +0100, Cédric Le Goater wrote:
> > Migration is a problem. We will need both backend QEMU objects to be 
> > available anyhow if we want to migrate. So we are back to the current 
> > solution creating both QEMU objects but we can try to defer some of the 
> > KVM inits and create the KVM device on demand at CAS time.
> 
>  Do we have a way to migrate a piece of info from the machine *first*
>  that indicate what type of XICS/XIVE to instanciate ?
> >>>
> >>> Nope.  qemu migration doesn't work like that.  Yes, it should, and
> >>> everyone knows it, but changing it is a really long term project.
> >>
> >> Well, we have a problem then. It looks like Qemu broken migration is
> >> fundamentally incompatible with PAPR and CAS design...
> > 
> > Hrm, the fit is very clunky certainly, but i think we can make it work.
> > 
> >> I know we don't migrate the configuration, that's not exactly what I
> >> had in mind tho... Can we have some piece of *data* from the machine be
> >> migrated first, and use it on the target to reconfigure the interrupt
> >> controller before the stream arrives ?
> > 
> > Sorta.. maybe.. but it would probably get really ugly if we don't
> > preserve the usual way object lifetimes work.
> > 
> >> Otherwise, we have indeed no much choice but the horrible wart of
> >> creating both interrupt controllers with only one "active".
> > 
> > I really think this is the way to go, warts and all.
> > 
> 
> Yes ... KVM makes it a little uglier. 
> 
> A KVM_DEVICE_DESTROY device is needed to cleanup the VM and a 
> DISABLE_CAP to disconnect the vpcu from the current KVM XIVE/XICS 
> device. I have used an extra arg on ENABLE_CAP for the moment.
> 
> At the QEMU level, we need to connect/reconnect at reset time to
> handle possible changes in CAS, and at post_load.

Right.

> Destroying the MemoryRegion is a bit problematic, I have not
> found a common layout compatible with both the emulated mode 
> (std IO regions) and the KVM mode (ram device regions)

That sounds awkward, I guess we'll discuss the details of this later.


Btw, a secondary advantage of starting off with XIVE only under a
different machine type is that we can declare that one not to be
migration stable until we're ready.  So we can merge something that's
ok to experiment with, but reserve the right to incompatibly change
the migration format until we're confident we're ready and can merge
it into the "stable" machine type.

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller

2018-04-15 Thread David Gibson
On Thu, Apr 12, 2018 at 10:18:11AM +0200, Cédric Le Goater wrote:
> On 04/12/2018 07:07 AM, David Gibson wrote:
> > On Wed, Dec 20, 2017 at 08:38:41AM +0100, Cédric Le Goater wrote:
> >> On 12/20/2017 06:09 AM, David Gibson wrote:
> >>> On Sat, Dec 09, 2017 at 09:43:21AM +0100, Cédric Le Goater wrote:
>  With the POWER9 processor comes a new interrupt controller called
>  XIVE. It is composed of three sub-engines :
> 
>    - Interrupt Virtualization Source Engine (IVSE). These are in PHBs,
>  in the main controller for the IPIS and in the PSI host
>  bridge. They are configured to feed the IVRE with events.
> 
>    - Interrupt Virtualization Routing Engine (IVRE). Their job is to
>  match an event source with a Notification Virtualization Target
>  (NVT), a priority and an Event Queue (EQ) to determine if a
>  Virtual Processor can handle the event.
> 
>    - Interrupt Virtualization Presentation Engine (IVPE). It maintains
>  the interrupt state of each hardware thread and present the
>  notification as an external exception.
> 
>  Each of the engines uses a set of internal tables to redirect
>  exceptions from event sources to CPU threads. The first table we
>  introduce is the Interrupt Virtualization Entry (IVE) table, part of
>  the virtualization engine in charge of routing events. It associates
>  event sources (IRQ numbers) to event queues which will forward, or
>  not, the event notification to the presentation controller.
> 
>  The XIVE model is designed to make use of the full range of the IRQ
>  number space and does not use an offset like the XICS mode does.
>  Hence, the IVE table is directly indexed by the IRQ number.
> 
>  Signed-off-by: Cédric Le Goater 
> >>>
> >>> As you've suggested in yourself, I think we might need to more
> >>> explicitly model the different components of the XIVE system.  As part
> >>> of that, I think you need to be clearer in this base skeleton about
> >>> exactly what component your XIVE object represents.
> > 
> > Sorry it's been so long since I looked at these.
> 
> That's fine. I have been working on a XIVE device model for the PowerNV
> machine and KVM support for the pseries. I have a better understanding
> of the overall picture.
> 
> The patchset has not changed much so we can still discuss on this
> basis without me flooding the mailing list.
> 
> >> ok. The base skeleton is the IVRE, the central engine handling 
> >> the routing. 
> >>
> >>> If the answer is "the overall thing" 
> >>
> >> Yes, it is more or less that currently. 
> >>
> >> The sPAPRXive object models the source engine and the routing 
> >> engine in one object.
> > 
> > Yeah, I suspect we don't want that.  Although it might seem simpler in
> > the spapr case, at least at first glance, I think it will cause us
> > problems later.  At the very least, it's likely to make it harder to
> > share code between the spapr and powernv case.  I think it will also
> > make for more confusion about exactly what things belong where.
> 
> I tend to agree. 
> 
> We need to clarify (a bit) what is in the XIVE interrupt controller 
> silicon, and how XIVE works. The XIVE device models for spapr and 
> powernv should be very close as the differences are small. KVM support 
> should be built on the spapr model.
> 
> There are 3 different sub-engines in the XIVE interrupt controller
> device :
> 
> * IVSE (XiveSource model)
> 
>   interrupt sources, which expose their PQ bits through ESB MMIO pages 
>   (there are different levels of support depending on HW revision) 
> 
>   The XIVE interrupt controller has a set of internal sources for 
>   IPIs and CAPI like interrupts.

Ok.  IIUC in hardware there's one of these in each PHB, plus maybe one
or two others.  Is that right?

> 
> * IVRE (No real model)
> 
>   in the middle, doing the routing of source event notification to
>   (cpu) targets. It relies on internal tables which are stored in 
>   the hypervisor/QEMU/KVM for the spapr machine and in the VM RAM 
>   for the powernv machine.

What does VM RAM mean in the powernv context?

>   Configuration updates of the XIVE tables are done through hcalls 
>   on spapr and with MMIOs on the IC regs on powernv. On the latter,
>   the changes are flushed backed in the VM RAM. 
> 
> * IVPE (XiveNVT)
> 
>   set of registers for interrupt management at the CPU level. Exposed
>   in a specific MMIO region called the TIMA.

Ok.

> The XIVE tables are :
> 
> * IVT
> 
>   associate an interrupt source number with an event queue. the data
>   to be pushed in the queue is stored there also.

Ok, so there would be one of these tables for each IVRE, with one
entry for each source managed by that IVSE, yes?

Do the XIVE IPIs have entries here, or do they bypass this?

> * EQDT:
> 
>   describes the queues in the OS RAM, also contains a set of flags,
>   a virtual target, 

Re: [Qemu-devel] [PATCH v3 38/41] hw/rdma: Use the BYTE-based definitions

2018-04-15 Thread Marcel Apfelbaum
On 16/04/2018 2:43, Philippe Mathieu-Daudé wrote:
> It eases code review, unit is explicit.
> 
> Patch generated using:
> 
>   $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/
> 
> and modified manually.
> 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/rdma/vmw/pvrdma.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/rdma/vmw/pvrdma.h b/hw/rdma/vmw/pvrdma.h
> index 8c173cb824..f17143f0e6 100644
> --- a/hw/rdma/vmw/pvrdma.h
> +++ b/hw/rdma/vmw/pvrdma.h
> @@ -16,6 +16,7 @@
>  #ifndef PVRDMA_PVRDMA_H
>  #define PVRDMA_PVRDMA_H
>  
> +#include "qemu/units.h"
>  #include "hw/pci/pci.h"
>  #include "hw/pci/msix.h"
>  
> @@ -30,7 +31,7 @@
>  #define RDMA_MSIX_BAR_IDX0
>  #define RDMA_REG_BAR_IDX 1
>  #define RDMA_UAR_BAR_IDX 2
> -#define RDMA_BAR0_MSIX_SIZE  (16 * 1024)
> +#define RDMA_BAR0_MSIX_SIZE  (16 * K_BYTE)
>  #define RDMA_BAR1_REGS_SIZE  256
>  #define RDMA_BAR2_UAR_SIZE   (0x1000 * MAX_UCS) /* each uc gets page */
>  
> 

Reviewed-by: Marcel Apfelbaum 

Thanks,
Marcel





Re: [Qemu-devel] [Qemu-trivial] [PATCH trivial for-2.12] Makefile: install gtk message catalogs if CONFIG_GTK=y too, not only =m

2018-04-15 Thread Philippe Mathieu-Daudé
Hi Michael,

On 04/14/2018 11:27 AM, Michael Tokarev wrote:
> Signed-off-by: Michael Tokarev 
> ---
>  Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/Makefile b/Makefile
> index 727ef118f3..8644c2e918 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -856,7 +856,7 @@ ifneq ($(BLOBS),)
>   $(INSTALL_DATA) $(SRC_PATH)/pc-bios/$$x 
> "$(DESTDIR)$(qemu_datadir)"; \
>   done
>  endif
> -ifeq ($(CONFIG_GTK),m)
> +ifneq ($(filter $(CONFIG_GTK),y m),)

Or simply:

ifdef CONFIG_GTK

>   $(MAKE) -C po $@
>  endif
>   $(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/keymaps"
> 

Regards,

Phil.



Re: [Qemu-devel] [PATCH for 2.13 v3 12/20] linux-user: move tilegx signal.c parts to tilegx directory

2018-04-15 Thread Philippe Mathieu-Daudé
On 04/11/2018 03:45 PM, Laurent Vivier wrote:
> No code change, only move code from signal.c to
> tilegx/signal.c, except adding includes and
> exporting setup_rt_frame().
> 
> Signed-off-by: Laurent Vivier 
> Reviewed-by: Alex Bennée 
> Reviewed-by: Richard Henderson 

Reviewed-by: Philippe Mathieu-Daudé 

> ---
>  linux-user/signal.c   | 165 -
>  linux-user/tilegx/signal.c| 168 
> ++
>  linux-user/tilegx/target_signal.h |   4 +-
>  3 files changed, 171 insertions(+), 166 deletions(-)
> 
> diff --git a/linux-user/signal.c b/linux-user/signal.c
> index 7c2a963e7c..5a3e5bff5e 100644
> --- a/linux-user/signal.c
> +++ b/linux-user/signal.c
> @@ -3032,171 +3032,6 @@ sigsegv:
>  return -TARGET_QEMU_ESIGRETURN;
>  }
>  
> -#elif defined(TARGET_TILEGX)
> -
> -struct target_sigcontext {
> -union {
> -/* General-purpose registers.  */
> -abi_ulong gregs[56];
> -struct {
> -abi_ulong __gregs[53];
> -abi_ulong tp;/* Aliases gregs[TREG_TP].  */
> -abi_ulong sp;/* Aliases gregs[TREG_SP].  */
> -abi_ulong lr;/* Aliases gregs[TREG_LR].  */
> -};
> -};
> -abi_ulong pc;/* Program counter.  */
> -abi_ulong ics;   /* In Interrupt Critical Section?  */
> -abi_ulong faultnum;  /* Fault number.  */
> -abi_ulong pad[5];
> -};
> -
> -struct target_ucontext {
> -abi_ulong tuc_flags;
> -abi_ulong tuc_link;
> -target_stack_t tuc_stack;
> -struct target_sigcontext tuc_mcontext;
> -target_sigset_t tuc_sigmask;   /* mask last for extensibility */
> -};
> -
> -struct target_rt_sigframe {
> -unsigned char save_area[16]; /* caller save area */
> -struct target_siginfo info;
> -struct target_ucontext uc;
> -abi_ulong retcode[2];
> -};
> -
> -#define INSN_MOVELI_R10_139  0x00045fe551483000ULL /* { moveli r10, 139 } */
> -#define INSN_SWINT1  0x286b180051485000ULL /* { swint1 } */
> -
> -
> -static void setup_sigcontext(struct target_sigcontext *sc,
> - CPUArchState *env, int signo)
> -{
> -int i;
> -
> -for (i = 0; i < TILEGX_R_COUNT; ++i) {
> -__put_user(env->regs[i], >gregs[i]);
> -}
> -
> -__put_user(env->pc, >pc);
> -__put_user(0, >ics);
> -__put_user(signo, >faultnum);
> -}
> -
> -static void restore_sigcontext(CPUTLGState *env, struct target_sigcontext 
> *sc)
> -{
> -int i;
> -
> -for (i = 0; i < TILEGX_R_COUNT; ++i) {
> -__get_user(env->regs[i], >gregs[i]);
> -}
> -
> -__get_user(env->pc, >pc);
> -}
> -
> -static abi_ulong get_sigframe(struct target_sigaction *ka, CPUArchState *env,
> -  size_t frame_size)
> -{
> -unsigned long sp = env->regs[TILEGX_R_SP];
> -
> -if (on_sig_stack(sp) && !likely(on_sig_stack(sp - frame_size))) {
> -return -1UL;
> -}
> -
> -if ((ka->sa_flags & SA_ONSTACK) && !sas_ss_flags(sp)) {
> -sp = target_sigaltstack_used.ss_sp + target_sigaltstack_used.ss_size;
> -}
> -
> -sp -= frame_size;
> -sp &= -16UL;
> -return sp;
> -}
> -
> -static void setup_rt_frame(int sig, struct target_sigaction *ka,
> -   target_siginfo_t *info,
> -   target_sigset_t *set, CPUArchState *env)
> -{
> -abi_ulong frame_addr;
> -struct target_rt_sigframe *frame;
> -unsigned long restorer;
> -
> -frame_addr = get_sigframe(ka, env, sizeof(*frame));
> -trace_user_setup_rt_frame(env, frame_addr);
> -if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) {
> -goto give_sigsegv;
> -}
> -
> -/* Always write at least the signal number for the stack backtracer. */
> -if (ka->sa_flags & TARGET_SA_SIGINFO) {
> -/* At sigreturn time, restore the callee-save registers too. */
> -tswap_siginfo(>info, info);
> -/* regs->flags |= PT_FLAGS_RESTORE_REGS; FIXME: we can skip it? */
> -} else {
> -__put_user(info->si_signo, >info.si_signo);
> -}
> -
> -/* Create the ucontext.  */
> -__put_user(0, >uc.tuc_flags);
> -__put_user(0, >uc.tuc_link);
> -__put_user(target_sigaltstack_used.ss_sp, >uc.tuc_stack.ss_sp);
> -__put_user(sas_ss_flags(env->regs[TILEGX_R_SP]),
> -   >uc.tuc_stack.ss_flags);
> -__put_user(target_sigaltstack_used.ss_size, 
> >uc.tuc_stack.ss_size);
> -setup_sigcontext(>uc.tuc_mcontext, env, info->si_signo);
> -
> -if (ka->sa_flags & TARGET_SA_RESTORER) {
> -restorer = (unsigned long) ka->sa_restorer;
> -} else {
> -__put_user(INSN_MOVELI_R10_139, >retcode[0]);
> -__put_user(INSN_SWINT1, >retcode[1]);
> -restorer = frame_addr + offsetof(struct target_rt_sigframe, retcode);
> -}
> -env->pc = (unsigned 

Re: [Qemu-devel] [PATCH for 2.13 v2 11/19] linux-user: move cris cpu loop to cris directory

2018-04-15 Thread Philippe Mathieu-Daudé
On 04/11/2018 03:56 PM, Laurent Vivier wrote:
> No code change, only move code from main.c to
> cris/cpu_loop.c.
> 
> Signed-off-by: Laurent Vivier 
> Reviewed-by: Richard Henderson 

Reviewed-by: Philippe Mathieu-Daudé 

> ---
> 
> Notes:
> v2: expand tabs
> 
>  linux-user/cris/cpu_loop.c | 89 +
>  linux-user/main.c  | 90 
> --
>  2 files changed, 89 insertions(+), 90 deletions(-)
> 
> diff --git a/linux-user/cris/cpu_loop.c b/linux-user/cris/cpu_loop.c
> index b7700a5561..1c5eca9f83 100644
> --- a/linux-user/cris/cpu_loop.c
> +++ b/linux-user/cris/cpu_loop.c
> @@ -21,6 +21,95 @@
>  #include "qemu.h"
>  #include "cpu_loop-common.h"
>  
> +void cpu_loop(CPUCRISState *env)
> +{
> +CPUState *cs = CPU(cris_env_get_cpu(env));
> +int trapnr, ret;
> +target_siginfo_t info;
> +
> +while (1) {
> +cpu_exec_start(cs);
> +trapnr = cpu_exec(cs);
> +cpu_exec_end(cs);
> +process_queued_cpu_work(cs);
> +
> +switch (trapnr) {
> +case 0xaa:
> +{
> +info.si_signo = TARGET_SIGSEGV;
> +info.si_errno = 0;
> +/* XXX: check env->error_code */
> +info.si_code = TARGET_SEGV_MAPERR;
> +info._sifields._sigfault._addr = env->pregs[PR_EDA];
> +queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
> +}
> +break;
> +case EXCP_INTERRUPT:
> +  /* just indicate that signals should be handled asap */
> +  break;
> +case EXCP_BREAK:
> +ret = do_syscall(env, 
> + env->regs[9], 
> + env->regs[10], 
> + env->regs[11], 
> + env->regs[12], 
> + env->regs[13], 
> + env->pregs[7], 
> + env->pregs[11],
> + 0, 0);
> +if (ret == -TARGET_ERESTARTSYS) {
> +env->pc -= 2;
> +} else if (ret != -TARGET_QEMU_ESIGRETURN) {
> +env->regs[10] = ret;
> +}
> +break;
> +case EXCP_DEBUG:
> +{
> +int sig;
> +
> +sig = gdb_handlesig(cs, TARGET_SIGTRAP);
> +if (sig)
> +  {
> +info.si_signo = sig;
> +info.si_errno = 0;
> +info.si_code = TARGET_TRAP_BRKPT;
> +queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
> +  }
> +}
> +break;
> +case EXCP_ATOMIC:
> +cpu_exec_step_atomic(cs);
> +break;
> +default:
> +printf ("Unhandled trap: 0x%x\n", trapnr);
> +cpu_dump_state(cs, stderr, fprintf, 0);
> +exit(EXIT_FAILURE);
> +}
> +process_pending_signals (env);
> +}
> +}
> +
>  void target_cpu_copy_regs(CPUArchState *env, struct target_pt_regs *regs)
>  {
> +CPUState *cpu = ENV_GET_CPU(env);
> +TaskState *ts = cpu->opaque;
> +struct image_info *info = ts->info;
> +
> +env->regs[0] = regs->r0;
> +env->regs[1] = regs->r1;
> +env->regs[2] = regs->r2;
> +env->regs[3] = regs->r3;
> +env->regs[4] = regs->r4;
> +env->regs[5] = regs->r5;
> +env->regs[6] = regs->r6;
> +env->regs[7] = regs->r7;
> +env->regs[8] = regs->r8;
> +env->regs[9] = regs->r9;
> +env->regs[10] = regs->r10;
> +env->regs[11] = regs->r11;
> +env->regs[12] = regs->r12;
> +env->regs[13] = regs->r13;
> +env->regs[14] = info->start_stack;
> +env->regs[15] = regs->acr;
> +env->pc = regs->erp;
>  }
> diff --git a/linux-user/main.c b/linux-user/main.c
> index d7fee3e3db..9e01325d6a 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -149,76 +149,6 @@ void fork_end(int child)
>  }
>  }
>  
> -#ifdef TARGET_CRIS
> -void cpu_loop(CPUCRISState *env)
> -{
> -CPUState *cs = CPU(cris_env_get_cpu(env));
> -int trapnr, ret;
> -target_siginfo_t info;
> -
> -while (1) {
> -cpu_exec_start(cs);
> -trapnr = cpu_exec(cs);
> -cpu_exec_end(cs);
> -process_queued_cpu_work(cs);
> -
> -switch (trapnr) {
> -case 0xaa:
> -{
> -info.si_signo = TARGET_SIGSEGV;
> -info.si_errno = 0;
> -/* XXX: check env->error_code */
> -info.si_code = TARGET_SEGV_MAPERR;
> -info._sifields._sigfault._addr = env->pregs[PR_EDA];
> -queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
> -}
> -break;
> - case EXCP_INTERRUPT:
> -   /* just indicate that signals should be handled asap */

Re: [Qemu-devel] [PATCH for 2.13 v2 12/19] linux-user: move microblaze cpu loop to microblaze directory

2018-04-15 Thread Philippe Mathieu-Daudé
On 04/11/2018 03:56 PM, Laurent Vivier wrote:
> No code change, only move code from main.c to
> microblaze/cpu_loop.c.
> 
> Signed-off-by: Laurent Vivier 
> Reviewed-by: Richard Henderson 

Reviewed-by: Philippe Mathieu-Daudé 

> ---
> 
> Notes:
> v2: expand tabs
> 
>  linux-user/main.c| 155 
> ---
>  linux-user/microblaze/cpu_loop.c | 150 +
>  2 files changed, 150 insertions(+), 155 deletions(-)
> 
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 9e01325d6a..9e49c8a30c 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -149,125 +149,6 @@ void fork_end(int child)
>  }
>  }
>  
> -#ifdef TARGET_MICROBLAZE
> -void cpu_loop(CPUMBState *env)
> -{
> -CPUState *cs = CPU(mb_env_get_cpu(env));
> -int trapnr, ret;
> -target_siginfo_t info;
> -
> -while (1) {
> -cpu_exec_start(cs);
> -trapnr = cpu_exec(cs);
> -cpu_exec_end(cs);
> -process_queued_cpu_work(cs);
> -
> -switch (trapnr) {
> -case 0xaa:
> -{
> -info.si_signo = TARGET_SIGSEGV;
> -info.si_errno = 0;
> -/* XXX: check env->error_code */
> -info.si_code = TARGET_SEGV_MAPERR;
> -info._sifields._sigfault._addr = 0;
> -queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
> -}
> -break;
> - case EXCP_INTERRUPT:
> -   /* just indicate that signals should be handled asap */
> -   break;
> -case EXCP_BREAK:
> -/* Return address is 4 bytes after the call.  */
> -env->regs[14] += 4;
> -env->sregs[SR_PC] = env->regs[14];
> -ret = do_syscall(env, 
> - env->regs[12], 
> - env->regs[5], 
> - env->regs[6], 
> - env->regs[7], 
> - env->regs[8], 
> - env->regs[9], 
> - env->regs[10],
> - 0, 0);
> -if (ret == -TARGET_ERESTARTSYS) {
> -/* Wind back to before the syscall. */
> -env->sregs[SR_PC] -= 4;
> -} else if (ret != -TARGET_QEMU_ESIGRETURN) {
> -env->regs[3] = ret;
> -}
> -/* All syscall exits result in guest r14 being equal to the
> - * PC we return to, because the kernel syscall exit "rtbd" does
> - * this. (This is true even for sigreturn(); note that r14 is
> - * not a userspace-usable register, as the kernel may clobber it
> - * at any point.)
> - */
> -env->regs[14] = env->sregs[SR_PC];
> -break;
> -case EXCP_HW_EXCP:
> -env->regs[17] = env->sregs[SR_PC] + 4;
> -if (env->iflags & D_FLAG) {
> -env->sregs[SR_ESR] |= 1 << 12;
> -env->sregs[SR_PC] -= 4;
> -/* FIXME: if branch was immed, replay the imm as well.  */
> -}
> -
> -env->iflags &= ~(IMM_FLAG | D_FLAG);
> -
> -switch (env->sregs[SR_ESR] & 31) {
> -case ESR_EC_DIVZERO:
> -info.si_signo = TARGET_SIGFPE;
> -info.si_errno = 0;
> -info.si_code = TARGET_FPE_FLTDIV;
> -info._sifields._sigfault._addr = 0;
> -queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
> -break;
> -case ESR_EC_FPU:
> -info.si_signo = TARGET_SIGFPE;
> -info.si_errno = 0;
> -if (env->sregs[SR_FSR] & FSR_IO) {
> -info.si_code = TARGET_FPE_FLTINV;
> -}
> -if (env->sregs[SR_FSR] & FSR_DZ) {
> -info.si_code = TARGET_FPE_FLTDIV;
> -}
> -info._sifields._sigfault._addr = 0;
> -queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
> -break;
> -default:
> -printf ("Unhandled hw-exception: 0x%x\n",
> -env->sregs[SR_ESR] & ESR_EC_MASK);
> -cpu_dump_state(cs, stderr, fprintf, 0);
> -exit(EXIT_FAILURE);
> -break;
> -}
> -break;
> -case EXCP_DEBUG:
> -{
> -int sig;
> -
> -sig = gdb_handlesig(cs, TARGET_SIGTRAP);
> -if (sig)
> -  {
> -info.si_signo = sig;
> -info.si_errno = 0;
> -info.si_code = TARGET_TRAP_BRKPT;
> -queue_signal(env, 

Re: [Qemu-devel] [PATCH for 2.13 v2 15/19] linux-user: move s390x cpu loop to s390x directory

2018-04-15 Thread Philippe Mathieu-Daudé
On 04/11/2018 03:56 PM, Laurent Vivier wrote:
> No code change, only move code from main.c to
> s390x/cpu_loop.c.
> 
> Signed-off-by: Laurent Vivier 
> Reviewed-by: Richard Henderson 
> Acked-by: Cornelia Huck 

Reviewed-by: Philippe Mathieu-Daudé 

> ---
>  linux-user/main.c   | 146 
> 
>  linux-user/s390x/cpu_loop.c | 139 +
>  2 files changed, 139 insertions(+), 146 deletions(-)
> 
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 37cf3a7d6f..7f6cfa5548 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -149,143 +149,6 @@ void fork_end(int child)
>  }
>  }
>  
> -#ifdef TARGET_S390X
> -
> -/* s390x masks the fault address it reports in si_addr for SIGSEGV and 
> SIGBUS */
> -#define S390X_FAIL_ADDR_MASK -4096LL
> -
> -void cpu_loop(CPUS390XState *env)
> -{
> -CPUState *cs = CPU(s390_env_get_cpu(env));
> -int trapnr, n, sig;
> -target_siginfo_t info;
> -target_ulong addr;
> -abi_long ret;
> -
> -while (1) {
> -cpu_exec_start(cs);
> -trapnr = cpu_exec(cs);
> -cpu_exec_end(cs);
> -process_queued_cpu_work(cs);
> -
> -switch (trapnr) {
> -case EXCP_INTERRUPT:
> -/* Just indicate that signals should be handled asap.  */
> -break;
> -
> -case EXCP_SVC:
> -n = env->int_svc_code;
> -if (!n) {
> -/* syscalls > 255 */
> -n = env->regs[1];
> -}
> -env->psw.addr += env->int_svc_ilen;
> -ret = do_syscall(env, n, env->regs[2], env->regs[3],
> - env->regs[4], env->regs[5],
> - env->regs[6], env->regs[7], 0, 0);
> -if (ret == -TARGET_ERESTARTSYS) {
> -env->psw.addr -= env->int_svc_ilen;
> -} else if (ret != -TARGET_QEMU_ESIGRETURN) {
> -env->regs[2] = ret;
> -}
> -break;
> -
> -case EXCP_DEBUG:
> -sig = gdb_handlesig(cs, TARGET_SIGTRAP);
> -if (sig) {
> -n = TARGET_TRAP_BRKPT;
> -goto do_signal_pc;
> -}
> -break;
> -case EXCP_PGM:
> -n = env->int_pgm_code;
> -switch (n) {
> -case PGM_OPERATION:
> -case PGM_PRIVILEGED:
> -sig = TARGET_SIGILL;
> -n = TARGET_ILL_ILLOPC;
> -goto do_signal_pc;
> -case PGM_PROTECTION:
> -case PGM_ADDRESSING:
> -sig = TARGET_SIGSEGV;
> -/* XXX: check env->error_code */
> -n = TARGET_SEGV_MAPERR;
> -addr = env->__excp_addr & S390X_FAIL_ADDR_MASK;
> -goto do_signal;
> -case PGM_EXECUTE:
> -case PGM_SPECIFICATION:
> -case PGM_SPECIAL_OP:
> -case PGM_OPERAND:
> -do_sigill_opn:
> -sig = TARGET_SIGILL;
> -n = TARGET_ILL_ILLOPN;
> -goto do_signal_pc;
> -
> -case PGM_FIXPT_OVERFLOW:
> -sig = TARGET_SIGFPE;
> -n = TARGET_FPE_INTOVF;
> -goto do_signal_pc;
> -case PGM_FIXPT_DIVIDE:
> -sig = TARGET_SIGFPE;
> -n = TARGET_FPE_INTDIV;
> -goto do_signal_pc;
> -
> -case PGM_DATA:
> -n = (env->fpc >> 8) & 0xff;
> -if (n == 0xff) {
> -/* compare-and-trap */
> -goto do_sigill_opn;
> -} else {
> -/* An IEEE exception, simulated or otherwise.  */
> -if (n & 0x80) {
> -n = TARGET_FPE_FLTINV;
> -} else if (n & 0x40) {
> -n = TARGET_FPE_FLTDIV;
> -} else if (n & 0x20) {
> -n = TARGET_FPE_FLTOVF;
> -} else if (n & 0x10) {
> -n = TARGET_FPE_FLTUND;
> -} else if (n & 0x08) {
> -n = TARGET_FPE_FLTRES;
> -} else {
> -/* ??? Quantum exception; BFP, DFP error.  */
> -goto do_sigill_opn;
> -}
> -sig = TARGET_SIGFPE;
> -goto do_signal_pc;
> -}
> -
> -default:
> -fprintf(stderr, "Unhandled program exception: %#x\n", n);
> -cpu_dump_state(cs, stderr, fprintf, 0);
> -exit(EXIT_FAILURE);
> -}
> -break;
> -
> -do_signal_pc:
> -addr = env->psw.addr;
> -do_signal:
> -info.si_signo = sig;
> -   

Re: [Qemu-devel] [PATCH for 2.13 v2 17/19] linux-user: move riscv cpu loop to riscv directory

2018-04-15 Thread Philippe Mathieu-Daudé
On 04/11/2018 03:56 PM, Laurent Vivier wrote:
> No code change, only move code from main.c to
> riscv/cpu_loop.c.
> 
> Signed-off-by: Laurent Vivier 
> Reviewed-by: Richard Henderson 
> Reviewed-by: Michael Clark 

Reviewed-by: Philippe Mathieu-Daudé 

> ---
>  linux-user/main.c   | 101 
> +---
>  linux-user/riscv/cpu_loop.c |  92 
>  2 files changed, 93 insertions(+), 100 deletions(-)
> 
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 32922110f1..834ec0bfe5 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -149,100 +149,6 @@ void fork_end(int child)
>  }
>  }
>  
> -#ifdef TARGET_RISCV
> -
> -void cpu_loop(CPURISCVState *env)
> -{
> -CPUState *cs = CPU(riscv_env_get_cpu(env));
> -int trapnr, signum, sigcode;
> -target_ulong sigaddr;
> -target_ulong ret;
> -
> -for (;;) {
> -cpu_exec_start(cs);
> -trapnr = cpu_exec(cs);
> -cpu_exec_end(cs);
> -process_queued_cpu_work(cs);
> -
> -signum = 0;
> -sigcode = 0;
> -sigaddr = 0;
> -
> -switch (trapnr) {
> -case EXCP_INTERRUPT:
> -/* just indicate that signals should be handled asap */
> -break;
> -case EXCP_ATOMIC:
> -cpu_exec_step_atomic(cs);
> -break;
> -case RISCV_EXCP_U_ECALL:
> -env->pc += 4;
> -if (env->gpr[xA7] == TARGET_NR_arch_specific_syscall + 15) {
> -/* riscv_flush_icache_syscall is a no-op in QEMU as
> -   self-modifying code is automatically detected */
> -ret = 0;
> -} else {
> -ret = do_syscall(env,
> - env->gpr[xA7],
> - env->gpr[xA0],
> - env->gpr[xA1],
> - env->gpr[xA2],
> - env->gpr[xA3],
> - env->gpr[xA4],
> - env->gpr[xA5],
> - 0, 0);
> -}
> -if (ret == -TARGET_ERESTARTSYS) {
> -env->pc -= 4;
> -} else if (ret != -TARGET_QEMU_ESIGRETURN) {
> -env->gpr[xA0] = ret;
> -}
> -if (cs->singlestep_enabled) {
> -goto gdbstep;
> -}
> -break;
> -case RISCV_EXCP_ILLEGAL_INST:
> -signum = TARGET_SIGILL;
> -sigcode = TARGET_ILL_ILLOPC;
> -break;
> -case RISCV_EXCP_BREAKPOINT:
> -signum = TARGET_SIGTRAP;
> -sigcode = TARGET_TRAP_BRKPT;
> -sigaddr = env->pc;
> -break;
> -case RISCV_EXCP_INST_PAGE_FAULT:
> -case RISCV_EXCP_LOAD_PAGE_FAULT:
> -case RISCV_EXCP_STORE_PAGE_FAULT:
> -signum = TARGET_SIGSEGV;
> -sigcode = TARGET_SEGV_MAPERR;
> -break;
> -case EXCP_DEBUG:
> -gdbstep:
> -signum = gdb_handlesig(cs, TARGET_SIGTRAP);
> -sigcode = TARGET_TRAP_BRKPT;
> -break;
> -default:
> -EXCP_DUMP(env, "\nqemu: unhandled CPU exception %#x - 
> aborting\n",
> - trapnr);
> -exit(EXIT_FAILURE);
> -}
> -
> -if (signum) {
> -target_siginfo_t info = {
> -.si_signo = signum,
> -.si_errno = 0,
> -.si_code = sigcode,
> -._sifields._sigfault._addr = sigaddr
> -};
> -queue_signal(env, info.si_signo, QEMU_SI_KILL, );
> -}
> -
> -process_pending_signals(env);
> -}
> -}
> -
> -#endif /* TARGET_RISCV */
> -
>  #ifdef TARGET_HPPA
>  
>  static abi_ulong hppa_lws(CPUHPPAState *env)
> @@ -1322,12 +1228,7 @@ int main(int argc, char **argv, char **envp)
>  
>  target_cpu_copy_regs(env, regs);
>  
> -#if defined(TARGET_RISCV)
> -{
> -env->pc = regs->sepc;
> -env->gpr[xSP] = regs->sp;
> -}
> -#elif defined(TARGET_HPPA)
> +#if defined(TARGET_HPPA)
>  {
>  int i;
>  for (i = 1; i < 32; i++) {
> diff --git a/linux-user/riscv/cpu_loop.c b/linux-user/riscv/cpu_loop.c
> index b7700a5561..f137d39d7e 100644
> --- a/linux-user/riscv/cpu_loop.c
> +++ b/linux-user/riscv/cpu_loop.c
> @@ -21,6 +21,98 @@
>  #include "qemu.h"
>  #include "cpu_loop-common.h"
>  
> +void cpu_loop(CPURISCVState *env)
> +{
> +CPUState *cs = CPU(riscv_env_get_cpu(env));
> +int trapnr, signum, sigcode;
> +target_ulong sigaddr;
> +target_ulong ret;
> +
> +for (;;) {
> +cpu_exec_start(cs);
> +trapnr = cpu_exec(cs);
> +cpu_exec_end(cs);
> +process_queued_cpu_work(cs);
> +
> +signum = 0;
> +

Re: [Qemu-devel] [PATCH for 2.13 v2 10/19] linux-user: move sh4 cpu loop to sh4 directory

2018-04-15 Thread Philippe Mathieu-Daudé
On 04/11/2018 03:56 PM, Laurent Vivier wrote:
> No code change, only move code from main.c to
> sh4/cpu_loop.c.
> 
> Signed-off-by: Laurent Vivier 
> Reviewed-by: Richard Henderson 

Reviewed-by: Philippe Mathieu-Daudé 

> ---
> 
> Notes:
> v2: expand tabs
> 
>  linux-user/main.c | 90 
> ---
>  linux-user/sh4/cpu_loop.c | 85 
>  2 files changed, 85 insertions(+), 90 deletions(-)
> 
> diff --git a/linux-user/main.c b/linux-user/main.c
> index af26a17c46..d7fee3e3db 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -149,87 +149,6 @@ void fork_end(int child)
>  }
>  }
>  
> -#ifdef TARGET_SH4
> -void cpu_loop(CPUSH4State *env)
> -{
> -CPUState *cs = CPU(sh_env_get_cpu(env));
> -int trapnr, ret;
> -target_siginfo_t info;
> -
> -while (1) {
> -bool arch_interrupt = true;
> -
> -cpu_exec_start(cs);
> -trapnr = cpu_exec(cs);
> -cpu_exec_end(cs);
> -process_queued_cpu_work(cs);
> -
> -switch (trapnr) {
> -case 0x160:
> -env->pc += 2;
> -ret = do_syscall(env,
> - env->gregs[3],
> - env->gregs[4],
> - env->gregs[5],
> - env->gregs[6],
> - env->gregs[7],
> - env->gregs[0],
> - env->gregs[1],
> - 0, 0);
> -if (ret == -TARGET_ERESTARTSYS) {
> -env->pc -= 2;
> -} else if (ret != -TARGET_QEMU_ESIGRETURN) {
> -env->gregs[0] = ret;
> -}
> -break;
> -case EXCP_INTERRUPT:
> -/* just indicate that signals should be handled asap */
> -break;
> -case EXCP_DEBUG:
> -{
> -int sig;
> -
> -sig = gdb_handlesig(cs, TARGET_SIGTRAP);
> -if (sig) {
> -info.si_signo = sig;
> -info.si_errno = 0;
> -info.si_code = TARGET_TRAP_BRKPT;
> -queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
> -} else {
> -arch_interrupt = false;
> -}
> -}
> -break;
> - case 0xa0:
> - case 0xc0:
> -info.si_signo = TARGET_SIGSEGV;
> -info.si_errno = 0;
> -info.si_code = TARGET_SEGV_MAPERR;
> -info._sifields._sigfault._addr = env->tea;
> -queue_signal(env, info.si_signo, QEMU_SI_FAULT, );
> - break;
> -case EXCP_ATOMIC:
> -cpu_exec_step_atomic(cs);
> -arch_interrupt = false;
> -break;
> -default:
> -printf ("Unhandled trap: 0x%x\n", trapnr);
> -cpu_dump_state(cs, stderr, fprintf, 0);
> -exit(EXIT_FAILURE);
> -}
> -process_pending_signals (env);
> -
> -/* Most of the traps imply an exception or interrupt, which
> -   implies an REI instruction has been executed.  Which means
> -   that LDST (aka LOK_ADDR) should be cleared.  But there are
> -   a few exceptions for traps internal to QEMU.  */
> -if (arch_interrupt) {
> -env->lock_addr = -1;
> -}
> -}
> -}
> -#endif
> -
>  #ifdef TARGET_CRIS
>  void cpu_loop(CPUCRISState *env)
>  {
> @@ -2361,15 +2280,6 @@ int main(int argc, char **argv, char **envp)
>  env->pc = regs->sepc;
>  env->gpr[xSP] = regs->sp;
>  }
> -#elif defined(TARGET_SH4)
> -{
> -int i;
> -
> -for(i = 0; i < 16; i++) {
> -env->gregs[i] = regs->regs[i];
> -}
> -env->pc = regs->pc;
> -}
>  #elif defined(TARGET_ALPHA)
>  {
>  int i;
> diff --git a/linux-user/sh4/cpu_loop.c b/linux-user/sh4/cpu_loop.c
> index b7700a5561..418833ea25 100644
> --- a/linux-user/sh4/cpu_loop.c
> +++ b/linux-user/sh4/cpu_loop.c
> @@ -21,6 +21,91 @@
>  #include "qemu.h"
>  #include "cpu_loop-common.h"
>  
> +void cpu_loop(CPUSH4State *env)
> +{
> +CPUState *cs = CPU(sh_env_get_cpu(env));
> +int trapnr, ret;
> +target_siginfo_t info;
> +
> +while (1) {
> +bool arch_interrupt = true;
> +
> +cpu_exec_start(cs);
> +trapnr = cpu_exec(cs);
> +cpu_exec_end(cs);
> +process_queued_cpu_work(cs);
> +
> +switch (trapnr) {
> +case 0x160:
> +env->pc += 2;
> +ret = do_syscall(env,
> + env->gregs[3],
> + env->gregs[4],
> + env->gregs[5],
> + env->gregs[6],
> + env->gregs[7],
> + 

Re: [Qemu-devel] [PATCH for 2.13 v2 05/19] linux-user: move sparc/sparc64 cpu loop to sparc directory

2018-04-15 Thread Philippe Mathieu-Daudé
On 04/11/2018 03:56 PM, Laurent Vivier wrote:
> No code change, only move code from main.c to
> sparc/cpu_loop.c.
> 
> Include sparc/cpu_loop.c in sparc64/cpu_loop.c
> to avoid to duplicate code.
> 
> Signed-off-by: Laurent Vivier 
> Reviewed-by: Richard Henderson 

Reviewed-by: Philippe Mathieu-Daudé 

> ---
>  linux-user/main.c | 288 
> +-
>  linux-user/sparc/cpu_loop.c   | 280 
>  linux-user/sparc64/cpu_loop.c |   8 +-
>  3 files changed, 282 insertions(+), 294 deletions(-)
> 
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 45d1588958..4816ec54bb 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -149,281 +149,6 @@ void fork_end(int child)
>  }
>  }
>  
> -#ifdef TARGET_SPARC
> -#define SPARC64_STACK_BIAS 2047
> -
> -//#define DEBUG_WIN
> -
> -/* WARNING: dealing with register windows _is_ complicated. More info
> -   can be found at http://www.sics.se/~psm/sparcstack.html */
> -static inline int get_reg_index(CPUSPARCState *env, int cwp, int index)
> -{
> -index = (index + cwp * 16) % (16 * env->nwindows);
> -/* wrap handling : if cwp is on the last window, then we use the
> -   registers 'after' the end */
> -if (index < 8 && env->cwp == env->nwindows - 1)
> -index += 16 * env->nwindows;
> -return index;
> -}
> -
> -/* save the register window 'cwp1' */
> -static inline void save_window_offset(CPUSPARCState *env, int cwp1)
> -{
> -unsigned int i;
> -abi_ulong sp_ptr;
> -
> -sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)];
> -#ifdef TARGET_SPARC64
> -if (sp_ptr & 3)
> -sp_ptr += SPARC64_STACK_BIAS;
> -#endif
> -#if defined(DEBUG_WIN)
> -printf("win_overflow: sp_ptr=0x" TARGET_ABI_FMT_lx " save_cwp=%d\n",
> -   sp_ptr, cwp1);
> -#endif
> -for(i = 0; i < 16; i++) {
> -/* FIXME - what to do if put_user() fails? */
> -put_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr);
> -sp_ptr += sizeof(abi_ulong);
> -}
> -}
> -
> -static void save_window(CPUSPARCState *env)
> -{
> -#ifndef TARGET_SPARC64
> -unsigned int new_wim;
> -new_wim = ((env->wim >> 1) | (env->wim << (env->nwindows - 1))) &
> -((1LL << env->nwindows) - 1);
> -save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
> -env->wim = new_wim;
> -#else
> -save_window_offset(env, cpu_cwp_dec(env, env->cwp - 2));
> -env->cansave++;
> -env->canrestore--;
> -#endif
> -}
> -
> -static void restore_window(CPUSPARCState *env)
> -{
> -#ifndef TARGET_SPARC64
> -unsigned int new_wim;
> -#endif
> -unsigned int i, cwp1;
> -abi_ulong sp_ptr;
> -
> -#ifndef TARGET_SPARC64
> -new_wim = ((env->wim << 1) | (env->wim >> (env->nwindows - 1))) &
> -((1LL << env->nwindows) - 1);
> -#endif
> -
> -/* restore the invalid window */
> -cwp1 = cpu_cwp_inc(env, env->cwp + 1);
> -sp_ptr = env->regbase[get_reg_index(env, cwp1, 6)];
> -#ifdef TARGET_SPARC64
> -if (sp_ptr & 3)
> -sp_ptr += SPARC64_STACK_BIAS;
> -#endif
> -#if defined(DEBUG_WIN)
> -printf("win_underflow: sp_ptr=0x" TARGET_ABI_FMT_lx " load_cwp=%d\n",
> -   sp_ptr, cwp1);
> -#endif
> -for(i = 0; i < 16; i++) {
> -/* FIXME - what to do if get_user() fails? */
> -get_user_ual(env->regbase[get_reg_index(env, cwp1, 8 + i)], sp_ptr);
> -sp_ptr += sizeof(abi_ulong);
> -}
> -#ifdef TARGET_SPARC64
> -env->canrestore++;
> -if (env->cleanwin < env->nwindows - 1)
> -env->cleanwin++;
> -env->cansave--;
> -#else
> -env->wim = new_wim;
> -#endif
> -}
> -
> -static void flush_windows(CPUSPARCState *env)
> -{
> -int offset, cwp1;
> -
> -offset = 1;
> -for(;;) {
> -/* if restore would invoke restore_window(), then we can stop */
> -cwp1 = cpu_cwp_inc(env, env->cwp + offset);
> -#ifndef TARGET_SPARC64
> -if (env->wim & (1 << cwp1))
> -break;
> -#else
> -if (env->canrestore == 0)
> -break;
> -env->cansave++;
> -env->canrestore--;
> -#endif
> -save_window_offset(env, cwp1);
> -offset++;
> -}
> -cwp1 = cpu_cwp_inc(env, env->cwp + 1);
> -#ifndef TARGET_SPARC64
> -/* set wim so that restore will reload the registers */
> -env->wim = 1 << cwp1;
> -#endif
> -#if defined(DEBUG_WIN)
> -printf("flush_windows: nb=%d\n", offset - 1);
> -#endif
> -}
> -
> -void cpu_loop (CPUSPARCState *env)
> -{
> -CPUState *cs = CPU(sparc_env_get_cpu(env));
> -int trapnr;
> -abi_long ret;
> -target_siginfo_t info;
> -
> -while (1) {
> -cpu_exec_start(cs);
> -trapnr = cpu_exec(cs);
> -cpu_exec_end(cs);
> -process_queued_cpu_work(cs);
> -
> -/* Compute PSR before exposing state.  */
> -if (env->cc_op != CC_OP_FLAGS) {
> -

Re: [Qemu-devel] [PATCH v1 02/24] configure: add support for --cross-cc-FOO

2018-04-15 Thread Philippe Mathieu-Daudé
On 04/10/2018 04:38 PM, Alex Bennée wrote:
> This allows us to specify cross compilers for our guests. This is
> useful for building test images/programs. Currently we re-run the
> compile test for each target. I couldn't think of a way to cache the
> value for a given arch without getting messier configure code.
> 
> The cross compiler for the guest is visible to each target as
> CROSS_CC_GUEST in config-target.mak.
> 
> Signed-off-by: Alex Bennée 
> ---
>  configure | 50 ++
>  1 file changed, 50 insertions(+)
> 
> diff --git a/configure b/configure
> index b402befe94..b5f3b3fe29 100755
> --- a/configure
> +++ b/configure
> @@ -453,6 +453,13 @@ vxhs=""
>  libxml2=""
>  docker="no"
>  
> +# cross compilers defaults, can be overridden with --cross-cc-ARCH
> +cross_cc_aarch64="aarch64-linux-gnu-gcc"
> +cross_cc_arm="arm-linux-gnueabihf-gcc"
> +cross_cc_powerpc="powerpc-linux-gnu-gcc"

These seems distrib-specific... Should we add a case $distrib) ...?

> +
> +enabled_cross_compilers=""
> +
>  supported_cpu="no"
>  supported_os="no"
>  bogus_os="no"
> @@ -483,6 +490,11 @@ for opt do
>;;
>--disable-debug-info) debug_info="no"
>;;
> +  --cross-cc-*[!a-zA-Z0-9_0]=*) error_exit "Passed bad --cross-cc-FOO option"
> +  ;;
> +  --cross-cc-*) cc_arch=${opt#--cross-cc-}
> +eval "cross_cc_${cc_arch}=\$optarg"
> +  ;;
>esac
>  done
>  # OS specific
> @@ -675,10 +687,12 @@ case "$cpu" in
>i386|i486|i586|i686|i86pc|BePC)
>  cpu="i386"
>  supported_cpu="yes"
> +cross_cc_i386=gcc
>;;
>x86_64|amd64)
>  cpu="x86_64"
>  supported_cpu="yes"
> +cross_cc_x86_64=gcc
>;;
>armv*b|armv*l|arm)
>  cpu="arm"
> @@ -912,6 +926,8 @@ for opt do
>;;
>--disable-debug-info)
>;;
> +  --cross-cc-*)
> +  ;;
>--enable-modules)
>modules="yes"
>;;
> @@ -6766,6 +6782,8 @@ case "$target" in
>  ;;
>  esac
>  
> +target_compiler=""
> +
>  mkdir -p $target_dir
>  echo "# Automatically generated by configure - do not modify" > 
> $config_target_mak
>  
> @@ -6794,6 +6812,7 @@ case "$target_name" in
>  bflt="yes"
>  mttcg="yes"
>  gdb_xml_files="arm-core.xml arm-vfp.xml arm-vfp3.xml arm-neon.xml"
> +target_compiler=$cross_cc_arm
>;;
>aarch64|aarch64_be)
>  TARGET_ARCH=aarch64
> @@ -6801,6 +6820,7 @@ case "$target_name" in
>  bflt="yes"
>  mttcg="yes"
>  gdb_xml_files="aarch64-core.xml aarch64-fpu.xml arm-core.xml arm-vfp.xml 
> arm-vfp3.xml arm-neon.xml"
> +target_compiler=$cross_cc_aarch64
>;;
>cris)
>;;
> @@ -6842,6 +6862,7 @@ case "$target_name" in
>;;
>ppc)
>  gdb_xml_files="power-core.xml power-fpu.xml power-altivec.xml 
> power-spe.xml"
> +target_compiler=$cross_cc_powerpc
>;;
>ppcemb)
>  TARGET_BASE_ARCH=ppc
> @@ -6916,6 +6937,25 @@ if [ "$TARGET_BASE_ARCH" = "" ]; then
>TARGET_BASE_ARCH=$TARGET_ARCH
>  fi
>  
> +# Do we have a cross compiler for this target?
> +if has $target_compiler; then
> +
> +cat > $TMPC << EOF
> +#include 
> +int main(void) {
> +printf("Hello World!\n");
> +}
> +EOF
> +
> +if ! do_compiler $target_compiler -o $TMPE $TMPC -static ; then
> +target_compiler=""
> +else
> +enabled_cross_compilers="${enabled_cross_compilers} 
> ${target_compiler}"
> +fi
> +else
> +target_compiler=""
> +fi
> +
>  symlink "$source_path/Makefile.target" "$target_dir/Makefile"
>  
>  upper() {
> @@ -6989,6 +7029,10 @@ if test "$target_bsd_user" = "yes" ; then
>echo "CONFIG_BSD_USER=y" >> $config_target_mak
>  fi
>  
> +if test -n "$target_compiler"; then
> +  echo "CROSS_CC_GUEST=$target_compiler" >> $config_target_mak
> +fi
> +
>  # generate QEMU_CFLAGS/LDFLAGS for targets
>  
>  cflags=""
> @@ -7111,6 +7155,12 @@ echo "QEMU_CFLAGS+=$cflags" >> $config_target_mak
>  
>  done # for target in $targets
>  
> +if test -n "$enabled_cross_compilers"; then
> +echo
> +echo "NOTE: cross-compilers enabled:"
> +printf '%s\n' $enabled_cross_compilers | sort -u
> +fi
> +
>  if [ "$dtc_internal" = "yes" ]; then
>echo "config-host.h: subdir-dtc" >> $config_host_mak
>  fi
> 



Re: [Qemu-devel] [PATCH v1 24/24] tests/Makefile.include: add (clean-)check-tcg targets

2018-04-15 Thread Philippe Mathieu-Daudé
On 04/10/2018 04:39 PM, Alex Bennée wrote:
> This will ensure all linux-user targets build their guest test
> programs.
> 
> Signed-off-by: Alex Bennée 

Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 

> ---
>  tests/Makefile.include | 19 ++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/Makefile.include b/tests/Makefile.include
> index 3d2f0458ab..c402de901e 100644
> --- a/tests/Makefile.include
> +++ b/tests/Makefile.include
> @@ -10,6 +10,7 @@ check-help:
>   @echo " $(MAKE) check-speed  Run qobject speed tests"
>   @echo " $(MAKE) check-qapi-schemaRun QAPI schema tests"
>   @echo " $(MAKE) check-block  Run block tests"
> + @echo " $(MAKE) check-tcgRun TCG tests"
>   @echo " $(MAKE) check-report.htmlGenerates an HTML test report"
>   @echo " $(MAKE) check-clean  Clean the tests"
>   @echo
> @@ -916,6 +917,23 @@ check-report.xml: $(patsubst %,check-report-qtest-%.xml, 
> $(QTEST_TARGETS)) check
>  check-report.html: check-report.xml
>   $(call quiet-command,gtester-report $< > $@,"GEN","$@")
>  
> +# Per guest TCG tests
> +
> +LINUX_USER_TARGETS=$(filter %-linux-user,$(TARGET_LIST))
> +BUILD_TCG_TARGET_RULES=$(patsubst %,tcg-tests-%, $(LINUX_USER_TARGETS))
> +CLEAN_TCG_TARGET_RULES=$(patsubst %,clean-tcg-tests-%, $(LINUX_USER_TARGETS))
> +
> +tcg-tests-%:
> + $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $* V="$(V)" 
> TARGET_DIR="$*/" guest-tests,)
> +
> +clean-tcg-tests-%:
> + $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $* V="$(V)" 
> TARGET_DIR="$*/" clean-guest-tests,)
> +
> +.PHONY: check-tcg
> +check-tcg: $(BUILD_TCG_TARGET_RULES)
> +
> +.PHONY: clean-tcg
> +clean-tcg: $(CLEAN_TCG_TARGET_RULES)
>  
>  # Other tests
>  
> @@ -958,7 +976,6 @@ check-speed: $(patsubst %,check-%, $(check-speed-y))
>  check-block: $(patsubst %,check-%, $(check-block-y))
>  check: check-qapi-schema check-unit check-qtest check-decodetree
>  check-clean:
> - $(MAKE) -C tests/tcg clean
>   rm -rf $(check-unit-y) tests/*.o $(QEMU_IOTESTS_HELPERS-y)
>   rm -rf $(sort $(foreach target,$(SYSEMU_TARGET_LIST), 
> $(check-qtest-$(target)-y)) $(check-qtest-generic-y))
>   rm -f tests/test-qapi-gen-timestamp
> 



Re: [Qemu-devel] [PATCH v1 23/24] Makefile.target: add (clean-)guest-tests targets

2018-04-15 Thread Philippe Mathieu-Daudé
On 04/10/2018 04:39 PM, Alex Bennée wrote:
> Now all the build infrastructure is in place we can build tests for
> each guest that we support. That support mainly depends on having
> cross compilers installed or docker setup. To keep all the logic for
> that together we put the rules in tests/tcg/Makefile.include and
> include it from the main Makefile.target.
> 
> Signed-off-by: Alex Bennée 
> ---
>  Makefile.target|  5 +++
>  tests/tcg/Makefile.include | 79 
> ++
>  2 files changed, 84 insertions(+)
>  create mode 100644 tests/tcg/Makefile.include
> 
> diff --git a/Makefile.target b/Makefile.target
> index d0ec77a307..a30fd40257 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -36,6 +36,11 @@ endif
>  PROGS=$(QEMU_PROG) $(QEMU_PROGW)
>  STPFILES=
>  
> +# Makefile Tests
> +ifdef CONFIG_USER_ONLY
> +include $(SRC_PATH)/tests/tcg/Makefile.include
> +endif
> +
>  config-target.h: config-target.h-timestamp
>  config-target.h-timestamp: config-target.mak
>  
> diff --git a/tests/tcg/Makefile.include b/tests/tcg/Makefile.include
> new file mode 100644
> index 00..cb8bb36026
> --- /dev/null
> +++ b/tests/tcg/Makefile.include
> @@ -0,0 +1,79 @@
> +# -*- Mode: makefile -*-
> +#
> +# TCG tests (per-target rules)
> +#
> +# This Makefile fragement is included from the per-target
> +# Makefile.target so will be invoked for each linux-user program we
> +# build. We have two options for compiling, either using a configured
> +# guest compiler or calling one of our docker images to do it for us.
> +#
> +
> +# The per ARCH makefile, if it exists holds extra information about
> +# useful docker images or alternative compiler flags. Include it if it
> +# exists
> +
> +ARCH_MAKEFILE=$(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.include
> +CHECK_INCLUDE=$(wildcard $(ARCH_MAKEFILE))
> +
> +ifeq ($(ARCH_MAKEFILE),$(CHECK_INCLUDE))
> +include $(ARCH_MAKEFILE)
> +endif
> +
> +GUEST_BUILD=
> +
> +# Support installed Cross Compilers
> +
> +ifdef CROSS_CC_GUEST
> +
> +.PHONY: cross-build-guest-tests
> +cross-build-guest-tests:
> + $(call quiet-command, \
> +  (mkdir -p tests && cd tests && \
> +make -f $(SRC_PATH)/tests/tcg/Makefile ARCH=$(TARGET_NAME) 
> CC=$(CROSS_CC_GUEST)), \
> +   "CROSS-BUILD","$(TARGET_NAME) guest-tests with $(CROSS_CC_GUEST)")
> +
> +
> +GUEST_BUILD=cross-build-guest-tests
> +
> +endif
> +
> +# Support building with Docker
> +
> +ifeq ($(HAVE_USER_DOCKER)$(GUEST_BUILD),y)
> +ifneq ($(DOCKER_IMAGE),)
> +
> +# We also need the Docker make rules to depend on
> +include $(SRC_PATH)/tests/docker/Makefile.include
> +

Eventually:

DOCKER_CROSS_COMPILER ?= $(DOCKER_CROSS_COMPILER_PREFIX)-gcc

> +DOCKER_COMPILE_CMD="$(DOCKER_SCRIPT) cc --user $(shell id -u) \
> + --cc $(DOCKER_CROSS_COMPILER) \
> + -i qemu:$(DOCKER_IMAGE) \
> + -s $(SRC_PATH) -- "

Should we check $(DOCKER_CROSS_COMPILER) is set?

> +DOCKER_PREREQ=docker-image-$(DOCKER_IMAGE)
> +
> +.PHONY: docker-build-guest-tests
> +docker-build-guest-tests: $(DOCKER_PREREQ)
> + $(call quiet-command, \
> +  (mkdir -p tests && cd tests && \
> +make -f $(SRC_PATH)/tests/tcg/Makefile ARCH=$(TARGET_NAME) 
> CC=$(DOCKER_COMPILE_CMD)), \
> +   "CROSS-BUILD","$(TARGET_NAME) guest-tests with docker 
> qemu:$(DOCKER_IMAGE)")
> +
> +GUEST_BUILD=docker-build-guest-tests
> +
> +endif
> +endif
> +
> +# Final targets
> +.PHONY: guest-tests
> +
> +ifneq ($(GUEST_BUILD),)
> +guest-tests: $(GUEST_BUILD)
> +else
> +guest-tests:
> + $(call quiet-command, /bin/true, "CROSS-BUILD", "$(TARGET_NAME) 
> guest-tests SKIPPED")
> +endif
> +
> +# It doesn't mater if these don't exits
> +.PHONY: clean-guest-tests
> +clean-guest-tests:
> + rm -rf tests || echo "no $(TARGET_NAME) tests to remove"
> 



Re: [Qemu-devel] [PATCH v1 05/24] docker: Add "cc" subcommand

2018-04-15 Thread Philippe Mathieu-Daudé
On 04/10/2018 04:39 PM, Alex Bennée wrote:
> From: Fam Zheng 
> 
> Signed-off-by: Fam Zheng 

Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 

> ---
>  tests/docker/docker.py | 23 +++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/tests/docker/docker.py b/tests/docker/docker.py
> index 1246ba9578..8733266153 100755
> --- a/tests/docker/docker.py
> +++ b/tests/docker/docker.py
> @@ -390,6 +390,29 @@ class ImagesCommand(SubCommand):
>  def run(self, args, argv):
>  return Docker().command("images", argv, args.quiet)
>  
> +class CcCommand(SubCommand):
> +"""Compile sources with cc in images"""
> +name = "cc"
> +
> +def args(self, parser):
> +parser.add_argument("--image", "-i", required=True,
> +help="The docker image in which to run cc")
> +parser.add_argument("--source-path", "-s", nargs="*", dest="paths",
> +help="""Extra paths to (ro) mount into container 
> for
> +reading sources""")
> +
> +def run(self, args, argv):
> +if argv and argv[0] == "--":
> +argv = argv[1:]
> +cwd = os.getcwd()
> +cmd = ["--rm", "-w", cwd,
> +   "-v", "%s:%s:rw" % (cwd, cwd)]
> +for p in args.paths:
> +   cmd += ["-v", "%s:%s:ro,z" % (p, p)]
> +cmd += [args.image, "cc"]
> +cmd += argv
> +return Docker().command("run", cmd, True)
> +
>  def main():
>  parser = argparse.ArgumentParser(description="A Docker helper",
>  usage="%s  ..." % os.path.basename(sys.argv[0]))
> 



Re: [Qemu-devel] [PATCH v1 21/24] tests/tcg: enable building for ppc64

2018-04-15 Thread Philippe Mathieu-Daudé
Hi Alex,

On 04/10/2018 04:39 PM, Alex Bennée wrote:
> Currently this just enables building the multiarch tests.
> 
> Signed-off-by: Alex Bennée 

"make tcg-tests-ppc64-linux-user" works indeed.

Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 

Do we care about ppc[32]?

> ---
>  tests/tcg/ppc64/Makefile.include | 2 ++
>  1 file changed, 2 insertions(+)
>  create mode 100644 tests/tcg/ppc64/Makefile.include
> 
> diff --git a/tests/tcg/ppc64/Makefile.include 
> b/tests/tcg/ppc64/Makefile.include
> new file mode 100644
> index 00..d71cfc9aa7
> --- /dev/null
> +++ b/tests/tcg/ppc64/Makefile.include
> @@ -0,0 +1,2 @@
> +DOCKER_IMAGE=debian-ppc64el-cross
> +DOCKER_CROSS_COMPILER=powerpc64le-linux-gnu-gcc




Re: [Qemu-devel] [PATCH v1 20/24] tests/tcg: enable building for s390x

2018-04-15 Thread Philippe Mathieu-Daudé
On 04/10/2018 04:39 PM, Alex Bennée wrote:
> This doesn't add any additional tests but enables building the
> multiarch tests for s390x.
> 
> Signed-off-by: Alex Bennée 

Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 

> ---
>  tests/tcg/s390x/Makefile.include | 2 ++
>  1 file changed, 2 insertions(+)
>  create mode 100644 tests/tcg/s390x/Makefile.include
> 
> diff --git a/tests/tcg/s390x/Makefile.include 
> b/tests/tcg/s390x/Makefile.include
> new file mode 100644
> index 00..1f58115d96
> --- /dev/null
> +++ b/tests/tcg/s390x/Makefile.include
> @@ -0,0 +1,2 @@
> +DOCKER_IMAGE=debian-s390x-cross
> +DOCKER_CROSS_COMPILER=s390x-linux-gnu-gcc
> 



Re: [Qemu-devel] [PATCH v1 19/24] tests/tcg: move MIPS specific tests into subdir

2018-04-15 Thread Philippe Mathieu-Daudé
On 04/15/2018 10:02 PM, Philippe Mathieu-Daudé wrote:
> On 04/10/2018 04:39 PM, Alex Bennée wrote:
>> These only need to be built for MIPS guests.
>>
>> Signed-off-by: Alex Bennée 
>> ---
>>  tests/tcg/README  | 11 ---
>>  tests/tcg/mips/README |  7 +++
>>  tests/tcg/{ => mips}/hello-mips.c |  0
>>  3 files changed, 7 insertions(+), 11 deletions(-)
>>  create mode 100644 tests/tcg/mips/README
>>  rename tests/tcg/{ => mips}/hello-mips.c (100%)
>>
>> diff --git a/tests/tcg/README b/tests/tcg/README
>> index 625f2326e6..a5643d33e7 100644
>> --- a/tests/tcg/README
>> +++ b/tests/tcg/README
>> @@ -3,17 +3,6 @@ regression testing. Tests are either multi-arch, meaning 
>> they can be
>>  built for all guest architectures that support linux-user executable,
>>  or they are architecture specific.
>>  
>> -
>> -
>> -MIPS
>> -
>> -
>> -hello-mips
>> ---
>> -
>> -hello-mipsel
>> -
>> -
>>  CRIS
>>  
>>  The testsuite for CRIS is in tests/tcg/cris.  You can run it
>> diff --git a/tests/tcg/mips/README b/tests/tcg/mips/README
>> new file mode 100644
>> index 00..e5bbc58ec5
>> --- /dev/null
>> +++ b/tests/tcg/mips/README
>> @@ -0,0 +1,7 @@
>> +MIPS
>> +
>> +
>> +hello-mips
>> +--
>> +
>> +A very simple inline assembly, write syscall based hello world
>> diff --git a/tests/tcg/hello-mips.c b/tests/tcg/mips/hello-mips.c
>> similarity index 100%
>> rename from tests/tcg/hello-mips.c
>> rename to tests/tcg/mips/hello-mips.c
> 
> tested with:
> 
> -- >8 --
> diff --git a/configure b/configure
> index c98eb01c39..aebe928b3c 100755
> --- a/configure
> +++ b/configure
> @@ -455,6 +455,7 @@ docker="no"
>  # cross compilers defaults, can be overridden with --cross-cc-ARCH
>  cross_cc_aarch64="aarch64-linux-gnu-gcc"
>  cross_cc_arm="arm-linux-gnueabihf-gcc"
> +cross_cc_mips="mipsel-linux-gnu-gcc"
>  cross_cc_powerpc="powerpc-linux-gnu-gcc"
>  cross_cc_i386="i386-pc-linux-gnu-gcc"
>  cross_cc_i386_cflags=""
> @@ -6860,6 +6861,7 @@ case "$target_name" in
>mips|mipsel)
>  TARGET_ARCH=mips
>  echo "TARGET_ABI_MIPSO32=y" >> $config_target_mak
> +target_compiler=$cross_cc_mips
>;;
>mipsn32|mipsn32el)
>  TARGET_ARCH=mips64
> diff --git a/tests/tcg/mips/Makefile.target b/tests/tcg/mips/Makefile.target
> new file mode 100644
> index 00..427aafc9e5
> --- /dev/null
> +++ b/tests/tcg/mips/Makefile.target
> @@ -0,0 +1,6 @@
> +# -*- Mode: makefile -*-
> +#
> +# MIPS specific tweaks
> +
> +hello-mips: CFLAGS+=-ffreestanding
> +hello-mips: LDFLAGS+=-nostdlib
> 

oh and tests/tcg/mips/Makefile.include:

-- >8 --
DOCKER_IMAGE=debian-mipsel-cross
DOCKER_CROSS_COMPILER=mipsel-linux-gnu-gcc
--

running "make tcg-tests-mips-linux-user" it works, but "make
tcg-tests-mipsel-linux-user" only build the multiarch tests.

Maybe we need some [mipsel, mips64, mips64el] => "mips" rule somewhere.

Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 



Re: [Qemu-devel] [PATCH v1 18/24] tests/tcg/arm: fix hello-arm

2018-04-15 Thread Philippe Mathieu-Daudé
Hi Alex,

On 04/10/2018 04:39 PM, Alex Bennée wrote:
> As hello-arm is a bare bones syscall test it needs specific compiler
> flags so it doesn't try and link against glibc.
> 
> Signed-off-by: Alex Bennée 
> ---
>  tests/tcg/arm/Makefile.target | 6 ++
>  1 file changed, 6 insertions(+)
>  create mode 100644 tests/tcg/arm/Makefile.target
> 
> diff --git a/tests/tcg/arm/Makefile.target b/tests/tcg/arm/Makefile.target
> new file mode 100644
> index 00..b7c146c88e
> --- /dev/null
> +++ b/tests/tcg/arm/Makefile.target
> @@ -0,0 +1,6 @@
> +# -*- Mode: makefile -*-
> +#
> +# ARM specific tweaks

... (Thumb mode explicitly disabled)

> +
> +hello-arm: CFLAGS+=-marm -ffreestanding
> +hello-arm: LDFLAGS+=-nostdlib

What about enforcing ARM mode for the swi call by the _syscallX()
functions with:

-- >8 --
 #define _syscall0(type,name) \
+__attribute__((target("arm"))) \
 type name(void) { \
   long __res; \
   __asm__ __volatile__ (\
--
(and so for _syscall[1..5])

So main() Thumb mode can also be tested.

tested with the following tests/tcg/arm/Makefile.include:

-- >8 --
DOCKER_IMAGE=debian-armel-cross
DOCKER_CROSS_COMPILER=arm-linux-gnueabi-gcc
--

Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 



Re: [Qemu-devel] [PATCH v1 23/24] Makefile.target: add (clean-)guest-tests targets

2018-04-15 Thread Philippe Mathieu-Daudé
Hi Alex,

On 04/10/2018 04:39 PM, Alex Bennée wrote:
> Now all the build infrastructure is in place we can build tests for
> each guest that we support. That support mainly depends on having
> cross compilers installed or docker setup. To keep all the logic for
> that together we put the rules in tests/tcg/Makefile.include and
> include it from the main Makefile.target.
> 
> Signed-off-by: Alex Bennée 
> ---
>  Makefile.target|  5 +++
>  tests/tcg/Makefile.include | 79 
> ++
>  2 files changed, 84 insertions(+)
>  create mode 100644 tests/tcg/Makefile.include
> 
> diff --git a/Makefile.target b/Makefile.target
> index d0ec77a307..a30fd40257 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -36,6 +36,11 @@ endif
>  PROGS=$(QEMU_PROG) $(QEMU_PROGW)
>  STPFILES=
>  
> +# Makefile Tests
> +ifdef CONFIG_USER_ONLY
> +include $(SRC_PATH)/tests/tcg/Makefile.include
> +endif
> +
>  config-target.h: config-target.h-timestamp
>  config-target.h-timestamp: config-target.mak
>  
> diff --git a/tests/tcg/Makefile.include b/tests/tcg/Makefile.include
> new file mode 100644
> index 00..cb8bb36026
> --- /dev/null
> +++ b/tests/tcg/Makefile.include
> @@ -0,0 +1,79 @@
> +# -*- Mode: makefile -*-
> +#
> +# TCG tests (per-target rules)
> +#
> +# This Makefile fragement is included from the per-target
> +# Makefile.target so will be invoked for each linux-user program we
> +# build. We have two options for compiling, either using a configured
> +# guest compiler or calling one of our docker images to do it for us.
> +#
> +
> +# The per ARCH makefile, if it exists holds extra information about
> +# useful docker images or alternative compiler flags. Include it if it
> +# exists
> +
> +ARCH_MAKEFILE=$(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.include

What about Makefile.cross, cross.mak or even cross-$ARCH.mak?

> +CHECK_INCLUDE=$(wildcard $(ARCH_MAKEFILE))
> +
> +ifeq ($(ARCH_MAKEFILE),$(CHECK_INCLUDE))
> +include $(ARCH_MAKEFILE)
> +endif
> +
> +GUEST_BUILD=
> +
> +# Support installed Cross Compilers
> +
> +ifdef CROSS_CC_GUEST
> +
> +.PHONY: cross-build-guest-tests
> +cross-build-guest-tests:
> + $(call quiet-command, \
> +  (mkdir -p tests && cd tests && \
> +make -f $(SRC_PATH)/tests/tcg/Makefile ARCH=$(TARGET_NAME) 
> CC=$(CROSS_CC_GUEST)), \
> +   "CROSS-BUILD","$(TARGET_NAME) guest-tests with $(CROSS_CC_GUEST)")
> +
> +
> +GUEST_BUILD=cross-build-guest-tests
> +
> +endif
> +
> +# Support building with Docker
> +
> +ifeq ($(HAVE_USER_DOCKER)$(GUEST_BUILD),y)
> +ifneq ($(DOCKER_IMAGE),)
> +
> +# We also need the Docker make rules to depend on
> +include $(SRC_PATH)/tests/docker/Makefile.include
> +
> +DOCKER_COMPILE_CMD="$(DOCKER_SCRIPT) cc --user $(shell id -u) \
> + --cc $(DOCKER_CROSS_COMPILER) \
> + -i qemu:$(DOCKER_IMAGE) \
> + -s $(SRC_PATH) -- "
> +DOCKER_PREREQ=docker-image-$(DOCKER_IMAGE)
> +
> +.PHONY: docker-build-guest-tests
> +docker-build-guest-tests: $(DOCKER_PREREQ)
> + $(call quiet-command, \
> +  (mkdir -p tests && cd tests && \
> +make -f $(SRC_PATH)/tests/tcg/Makefile ARCH=$(TARGET_NAME) 
> CC=$(DOCKER_COMPILE_CMD)), \
> +   "CROSS-BUILD","$(TARGET_NAME) guest-tests with docker 
> qemu:$(DOCKER_IMAGE)")
> +
> +GUEST_BUILD=docker-build-guest-tests
> +
> +endif
> +endif
> +
> +# Final targets
> +.PHONY: guest-tests
> +
> +ifneq ($(GUEST_BUILD),)
> +guest-tests: $(GUEST_BUILD)
> +else
> +guest-tests:
> + $(call quiet-command, /bin/true, "CROSS-BUILD", "$(TARGET_NAME) 
> guest-tests SKIPPED")
> +endif
> +
> +# It doesn't mater if these don't exits
> +.PHONY: clean-guest-tests
> +clean-guest-tests:
> + rm -rf tests || echo "no $(TARGET_NAME) tests to remove"
> 



Re: [Qemu-devel] [PATCH v1 19/24] tests/tcg: move MIPS specific tests into subdir

2018-04-15 Thread Philippe Mathieu-Daudé
On 04/10/2018 04:39 PM, Alex Bennée wrote:
> These only need to be built for MIPS guests.
> 
> Signed-off-by: Alex Bennée 
> ---
>  tests/tcg/README  | 11 ---
>  tests/tcg/mips/README |  7 +++
>  tests/tcg/{ => mips}/hello-mips.c |  0
>  3 files changed, 7 insertions(+), 11 deletions(-)
>  create mode 100644 tests/tcg/mips/README
>  rename tests/tcg/{ => mips}/hello-mips.c (100%)
> 
> diff --git a/tests/tcg/README b/tests/tcg/README
> index 625f2326e6..a5643d33e7 100644
> --- a/tests/tcg/README
> +++ b/tests/tcg/README
> @@ -3,17 +3,6 @@ regression testing. Tests are either multi-arch, meaning 
> they can be
>  built for all guest architectures that support linux-user executable,
>  or they are architecture specific.
>  
> -
> -
> -MIPS
> -
> -
> -hello-mips
> ---
> -
> -hello-mipsel
> -
> -
>  CRIS
>  
>  The testsuite for CRIS is in tests/tcg/cris.  You can run it
> diff --git a/tests/tcg/mips/README b/tests/tcg/mips/README
> new file mode 100644
> index 00..e5bbc58ec5
> --- /dev/null
> +++ b/tests/tcg/mips/README
> @@ -0,0 +1,7 @@
> +MIPS
> +
> +
> +hello-mips
> +--
> +
> +A very simple inline assembly, write syscall based hello world
> diff --git a/tests/tcg/hello-mips.c b/tests/tcg/mips/hello-mips.c
> similarity index 100%
> rename from tests/tcg/hello-mips.c
> rename to tests/tcg/mips/hello-mips.c

tested with:

-- >8 --
diff --git a/configure b/configure
index c98eb01c39..aebe928b3c 100755
--- a/configure
+++ b/configure
@@ -455,6 +455,7 @@ docker="no"
 # cross compilers defaults, can be overridden with --cross-cc-ARCH
 cross_cc_aarch64="aarch64-linux-gnu-gcc"
 cross_cc_arm="arm-linux-gnueabihf-gcc"
+cross_cc_mips="mipsel-linux-gnu-gcc"
 cross_cc_powerpc="powerpc-linux-gnu-gcc"
 cross_cc_i386="i386-pc-linux-gnu-gcc"
 cross_cc_i386_cflags=""
@@ -6860,6 +6861,7 @@ case "$target_name" in
   mips|mipsel)
 TARGET_ARCH=mips
 echo "TARGET_ABI_MIPSO32=y" >> $config_target_mak
+target_compiler=$cross_cc_mips
   ;;
   mipsn32|mipsn32el)
 TARGET_ARCH=mips64
diff --git a/tests/tcg/mips/Makefile.target b/tests/tcg/mips/Makefile.target
new file mode 100644
index 00..427aafc9e5
--- /dev/null
+++ b/tests/tcg/mips/Makefile.target
@@ -0,0 +1,6 @@
+# -*- Mode: makefile -*-
+#
+# MIPS specific tweaks
+
+hello-mips: CFLAGS+=-ffreestanding
+hello-mips: LDFLAGS+=-nostdlib
-- 

Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 



Re: [Qemu-devel] [PATCH v1 14/24] tests/tcg/i386: fix test-i386

2018-04-15 Thread Philippe Mathieu-Daudé
On 04/10/2018 04:39 PM, Alex Bennée wrote:
> The test-i386 test case is a little special as it includes assembler
> files. Add the additional compile magic to assemble these bits and
> link them to the final binary.
> 
> Signed-off-by: Alex Bennée 

Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 

> ---
>  tests/tcg/i386/Makefile.target | 19 +++
>  tests/tcg/i386/test-i386.c |  1 -
>  2 files changed, 19 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/tcg/i386/Makefile.target b/tests/tcg/i386/Makefile.target
> index 7dbb7992e7..1df69e0dab 100644
> --- a/tests/tcg/i386/Makefile.target
> +++ b/tests/tcg/i386/Makefile.target
> @@ -8,3 +8,22 @@ ifdef CROSS_CC_GUEST_CFLAGS
>  CFLAGS+=$(CROSS_CC_GUEST_CFLAGS)
>  endif
>  endif
> +
> +#
> +# test-386 includes a couple of additional objects that need to be linked 
> together
> +#
> +
> +TEST_I386_DEPS=test-i386-code16.o test-i386-vm86.o
> +
> +# override the default compile and link in one go rule
> +test-i386.o: test-i386.c
> + $(CC) $(CFLAGS) -c $< -o $@
> +
> +# and provide a rule to compile .S files
> +%.o: %.S
> + $(CC) $(CFLAGS) -c $< -o $@
> +
> +test-i386: LDFLAGS+=-lm -lc
> +test-i386: test-i386.o $(TEST_I386_DEPS)
> + $(LD) -melf_i386 $(LDFLAGS) $< $(TEST_I386_DEPS) -o $@
> +
> diff --git a/tests/tcg/i386/test-i386.c b/tests/tcg/i386/test-i386.c
> index 9599204895..cae6a7773a 100644
> --- a/tests/tcg/i386/test-i386.c
> +++ b/tests/tcg/i386/test-i386.c
> @@ -17,7 +17,6 @@
>   *  along with this program; if not, see .
>   */
>  #define _GNU_SOURCE
> -#include "qemu/compiler.h"
>  #include 
>  #include 
>  #include 
> 



Re: [Qemu-devel] [PATCH v1 11/24] tests/tcg: move i386 specific tests into subdir

2018-04-15 Thread Philippe Mathieu-Daudé
On 04/10/2018 04:39 PM, Alex Bennée wrote:
> These only need to be built for i386 guests. This includes a stub
> tests/tcg/i386/Makfile.target which absorbs some of what was in

Mak[e]file

> tests/tcg/Makefile.
> 
> Signed-off-by: Alex Bennée 

Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 

> ---
>  tests/tcg/README|  39 
> 
>  tests/tcg/i386/Makefile.target  |  10 
>  tests/tcg/i386/README   |  38 +++
>  tests/tcg/{ => i386}/hello-i386.c   |   0
>  tests/tcg/{ => i386}/pi_10.com  | Bin
>  tests/tcg/{ => i386}/runcom.c   |   0
>  tests/tcg/{ => i386}/test-i386-code16.S |   0
>  tests/tcg/{ => i386}/test-i386-fprem.c  |   0
>  tests/tcg/{ => i386}/test-i386-muldiv.h |   0
>  tests/tcg/{ => i386}/test-i386-shift.h  |   0
>  tests/tcg/{ => i386}/test-i386-ssse3.c  |   0
>  tests/tcg/{ => i386}/test-i386-vm86.S   |   0
>  tests/tcg/{ => i386}/test-i386.c|   0
>  tests/tcg/{ => i386}/test-i386.h|   0
>  14 files changed, 48 insertions(+), 39 deletions(-)
>  create mode 100644 tests/tcg/i386/Makefile.target
>  create mode 100644 tests/tcg/i386/README
>  rename tests/tcg/{ => i386}/hello-i386.c (100%)
>  rename tests/tcg/{ => i386}/pi_10.com (100%)
>  rename tests/tcg/{ => i386}/runcom.c (100%)
>  rename tests/tcg/{ => i386}/test-i386-code16.S (100%)
>  rename tests/tcg/{ => i386}/test-i386-fprem.c (100%)
>  rename tests/tcg/{ => i386}/test-i386-muldiv.h (100%)
>  rename tests/tcg/{ => i386}/test-i386-shift.h (100%)
>  rename tests/tcg/{ => i386}/test-i386-ssse3.c (100%)
>  rename tests/tcg/{ => i386}/test-i386-vm86.S (100%)
>  rename tests/tcg/{ => i386}/test-i386.c (100%)
>  rename tests/tcg/{ => i386}/test-i386.h (100%)
> 
> diff --git a/tests/tcg/README b/tests/tcg/README
> index 0890044cf0..469504c4cb 100644
> --- a/tests/tcg/README
> +++ b/tests/tcg/README
> @@ -3,45 +3,6 @@ regression testing. Tests are either multi-arch, meaning 
> they can be
>  built for all guest architectures that support linux-user executable,
>  or they are architecture specific.
>  
> -i386
> -
> -
> -test-i386
> --
> -
> -This program executes most of the 16 bit and 32 bit x86 instructions and
> -generates a text output, for comparison with the output obtained with
> -a real CPU or another emulator.
> -
> -The Linux system call modify_ldt() is used to create x86 selectors
> -to test some 16 bit addressing and 32 bit with segmentation cases.
> -
> -The Linux system call vm86() is used to test vm86 emulation.
> -
> -Various exceptions are raised to test most of the x86 user space
> -exception reporting.
> -
> -linux-test
> ---
> -
> -This program tests various Linux system calls. It is used to verify
> -that the system call parameters are correctly converted between target
> -and host CPUs.
> -
> -test-i386-fprem
> 
> -
> -runcom
> ---
> -
> -test-mmap
> --
> -
> -sha1
> -
> -
> -hello-i386
> ---
>  
>  
>  ARM
> diff --git a/tests/tcg/i386/Makefile.target b/tests/tcg/i386/Makefile.target
> new file mode 100644
> index 00..7dbb7992e7
> --- /dev/null
> +++ b/tests/tcg/i386/Makefile.target
> @@ -0,0 +1,10 @@
> +# i386 cross compile notes
> +
> +# If we are using a cross compiler config-target.mak may have also
> +# defined some CFLAGs to use.
> +
> +ifeq ($(CC), $(CROSS_CC_GUEST))
> +ifdef CROSS_CC_GUEST_CFLAGS
> +CFLAGS+=$(CROSS_CC_GUEST_CFLAGS)
> +endif
> +endif
> diff --git a/tests/tcg/i386/README b/tests/tcg/i386/README
> new file mode 100644
> index 00..7a0a47bf27
> --- /dev/null
> +++ b/tests/tcg/i386/README
> @@ -0,0 +1,38 @@
> +These are i386 specific guest programs
> +
> +test-i386
> +-
> +
> +This program executes most of the 16 bit and 32 bit x86 instructions and
> +generates a text output, for comparison with the output obtained with
> +a real CPU or another emulator.
> +
> +The Linux system call modify_ldt() is used to create x86 selectors
> +to test some 16 bit addressing and 32 bit with segmentation cases.
> +
> +The Linux system call vm86() is used to test vm86 emulation.
> +
> +Various exceptions are raised to test most of the x86 user space
> +exception reporting.
> +
> +linux-test
> +--
> +
> +This program tests various Linux system calls. It is used to verify
> +that the system call parameters are correctly converted between target
> +and host CPUs.
> +
> +test-i386-fprem
> +---
> +
> +runcom
> +--
> +
> +test-mmap
> +-
> +
> +sha1
> +
> +
> +hello-i386
> +--
> diff --git a/tests/tcg/hello-i386.c b/tests/tcg/i386/hello-i386.c
> similarity index 100%
> rename from tests/tcg/hello-i386.c
> rename to tests/tcg/i386/hello-i386.c
> diff --git a/tests/tcg/pi_10.com b/tests/tcg/i386/pi_10.com
> similarity index 100%
> rename from tests/tcg/pi_10.com
> rename to 

Re: [Qemu-devel] [PATCH v1 15/24] tests/tcg/i368: fix hello-i386

2018-04-15 Thread Philippe Mathieu-Daudé
On 04/10/2018 04:39 PM, Alex Bennée wrote:
> This is a direct syscall test so needs additional CFLAGS and LDFLAGS.
> 
> Signed-off-by: Alex Bennée 

Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 

> ---
>  tests/tcg/i386/Makefile.target | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/tests/tcg/i386/Makefile.target b/tests/tcg/i386/Makefile.target
> index 1df69e0dab..44803c0382 100644
> --- a/tests/tcg/i386/Makefile.target
> +++ b/tests/tcg/i386/Makefile.target
> @@ -9,6 +9,12 @@ CFLAGS+=$(CROSS_CC_GUEST_CFLAGS)
>  endif
>  endif
>  
> +#
> +# hello-i386 is a barebones app
> +#
> +hello-i386: CFLAGS+=-ffreestanding
> +hello-i386: LDFLAGS+=-nostdlib
> +
>  #
>  # test-386 includes a couple of additional objects that need to be linked 
> together
>  #
> 



Re: [Qemu-devel] [PATCH v1 07/24] docker: allow "cc" command to run in user context

2018-04-15 Thread Philippe Mathieu-Daudé
On 04/10/2018 04:39 PM, Alex Bennée wrote:
> Signed-off-by: Alex Bennée 

Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 

> ---
>  tests/docker/docker.py | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/tests/docker/docker.py b/tests/docker/docker.py
> index 9444f4bea4..f79213044d 100755
> --- a/tests/docker/docker.py
> +++ b/tests/docker/docker.py
> @@ -399,6 +399,8 @@ class CcCommand(SubCommand):
>  help="The docker image in which to run cc")
>  parser.add_argument("--cc",
>  help="The compiler executable to call")
> +parser.add_argument("--user",
> +help="The user-id to run under")
>  parser.add_argument("--source-path", "-s", nargs="*", dest="paths",
>  help="""Extra paths to (ro) mount into container 
> for
>  reading sources""")
> @@ -414,6 +416,9 @@ class CcCommand(SubCommand):
>  for p in args.paths:
>  cmd += ["-v", "%s:%s:ro,z" % (p, p)]
>  
> +if args.user:
> +cmd += ["-u", args.user]
> +
>  cmd += [args.image]
>  
>  # The compile command we are running
> 



Re: [Qemu-devel] [PATCH v1 09/24] tests/tcg: move architecture independent tests into subdir

2018-04-15 Thread Philippe Mathieu-Daudé
Hi Alex,

On 04/10/2018 04:39 PM, Alex Bennée wrote:
> We will want to build these for all supported guest architectures so
> lets move them all into one place. We also drop test_path at this
> point because it needs qemu utils and glib bits which is hard to
> support for cross compiling.

Can we keep it for the $target==$host case (or when NOT cross
compiling)? Maybe move it to tests/tcg/host/test_path.c

> 
> Signed-off-by: Alex Bennée 
> ---
>  tests/tcg/README   |  10 +--
>  tests/tcg/multiarch/README |   1 +
>  tests/tcg/{ => multiarch}/linux-test.c |   0
>  tests/tcg/{ => multiarch}/sha1.c   |   0
>  tests/tcg/{ => multiarch}/test-mmap.c  |   0
>  tests/tcg/{ => multiarch}/testthread.c |   0
>  tests/tcg/test_path.c  | 157 
> -
>  7 files changed, 5 insertions(+), 163 deletions(-)
>  create mode 100644 tests/tcg/multiarch/README
>  rename tests/tcg/{ => multiarch}/linux-test.c (100%)
>  rename tests/tcg/{ => multiarch}/sha1.c (100%)
>  rename tests/tcg/{ => multiarch}/test-mmap.c (100%)
>  rename tests/tcg/{ => multiarch}/testthread.c (100%)
>  delete mode 100644 tests/tcg/test_path.c
> 
> diff --git a/tests/tcg/README b/tests/tcg/README
> index 5dcfb4852b..0890044cf0 100644
> --- a/tests/tcg/README
> +++ b/tests/tcg/README
> @@ -1,9 +1,7 @@
> -This directory contains various interesting programs for
> -regression testing.
> -
> -The target "make test" runs the programs and, if applicable,
> -runs "diff" to detect mismatches between output on the host and
> -output on QEMU.
> +This directory contains various interesting guest programs for
> +regression testing. Tests are either multi-arch, meaning they can be
> +built for all guest architectures that support linux-user executable,
> +or they are architecture specific.
>  
>  i386
>  
> diff --git a/tests/tcg/multiarch/README b/tests/tcg/multiarch/README
> new file mode 100644
> index 00..522c9d2ea3
> --- /dev/null
> +++ b/tests/tcg/multiarch/README
> @@ -0,0 +1 @@
> +Multi-architecture linux-user tests
> diff --git a/tests/tcg/linux-test.c b/tests/tcg/multiarch/linux-test.c
> similarity index 100%
> rename from tests/tcg/linux-test.c
> rename to tests/tcg/multiarch/linux-test.c
> diff --git a/tests/tcg/sha1.c b/tests/tcg/multiarch/sha1.c
> similarity index 100%
> rename from tests/tcg/sha1.c
> rename to tests/tcg/multiarch/sha1.c
> diff --git a/tests/tcg/test-mmap.c b/tests/tcg/multiarch/test-mmap.c
> similarity index 100%
> rename from tests/tcg/test-mmap.c
> rename to tests/tcg/multiarch/test-mmap.c
> diff --git a/tests/tcg/testthread.c b/tests/tcg/multiarch/testthread.c
> similarity index 100%
> rename from tests/tcg/testthread.c
> rename to tests/tcg/multiarch/testthread.c
> diff --git a/tests/tcg/test_path.c b/tests/tcg/test_path.c
> deleted file mode 100644
> index 1c29bce263..00
> --- a/tests/tcg/test_path.c
> +++ /dev/null
> @@ -1,157 +0,0 @@
> -/* Test path override code */
> -#include "config-host.h"
> -#include "util/cutils.c"
> -#include "util/hexdump.c"
> -#include "util/iov.c"
> -#include "util/path.c"
> -#include "util/qemu-timer-common.c"
> -#include 
> -#include 
> -#include 
> -
> -void qemu_log(const char *fmt, ...);
> -
> -/* Any log message kills the test. */
> -void qemu_log(const char *fmt, ...)
> -{
> -va_list ap;
> -
> -fprintf(stderr, "FATAL: ");
> -va_start(ap, fmt);
> -vfprintf(stderr, fmt, ap);
> -va_end(ap);
> -exit(1);
> -}
> -
> -#define NO_CHANGE(_path) \
> - do {\
> - if (strcmp(path(_path), _path) != 0) return __LINE__;   \
> - } while(0)
> -
> -#define CHANGE_TO(_path, _newpath)   \
> - do {\
> - if (strcmp(path(_path), _newpath) != 0) return __LINE__;\
> - } while(0)
> -
> -static void cleanup(void)
> -{
> -unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE");
> -unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE2");
> -unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE3");
> -unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE4");
> -unlink("/tmp/qemu-test_path/DIR1/DIR2/FILE5");
> -rmdir("/tmp/qemu-test_path/DIR1/DIR2");
> -rmdir("/tmp/qemu-test_path/DIR1/DIR3");
> -rmdir("/tmp/qemu-test_path/DIR1");
> -rmdir("/tmp/qemu-test_path");
> -}
> -
> -static unsigned int do_test(void)
> -{
> -if (mkdir("/tmp/qemu-test_path", 0700) != 0)
> - return __LINE__;
> -
> -if (mkdir("/tmp/qemu-test_path/DIR1", 0700) != 0)
> - return __LINE__;
> -
> -if (mkdir("/tmp/qemu-test_path/DIR1/DIR2", 0700) != 0)
> - return __LINE__;
> -
> -if (mkdir("/tmp/qemu-test_path/DIR1/DIR3", 0700) != 0)
> - return __LINE__;
> -
> -if (close(creat("/tmp/qemu-test_path/DIR1/DIR2/FILE", 0600)) != 0)
> - return __LINE__;
> -
> 

[Qemu-devel] [PATCH v3 40/41] hw/loader: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/loader.h  | 5 +++--
 hw/core/loader-fit.c | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/include/hw/loader.h b/include/hw/loader.h
index 5ed3fd8ae6..ca4184 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -1,5 +1,6 @@
 #ifndef LOADER_H
 #define LOADER_H
+#include "qemu/units.h"
 #include "hw/nvram/fw_cfg.h"
 
 /* loader.c */
@@ -52,7 +53,7 @@ int load_image_mr(const char *filename, MemoryRegion *mr);
  * load_image_gzipped_buffer() and load_image_gzipped() will read. It prevents
  * g_malloc() in those functions from allocating a huge amount of memory.
  */
-#define LOAD_IMAGE_MAX_GUNZIP_BYTES (256 << 20)
+#define LOAD_IMAGE_MAX_GUNZIP_BYTES (256 * M_BYTE)
 
 int load_image_gzipped_buffer(const char *filename, uint64_t max_sz,
   uint8_t **buffer);
@@ -253,6 +254,6 @@ int rom_add_option(const char *file, int32_t bootindex);
 
 /* This is the usual maximum in uboot, so if a uImage overflows this, it would
  * overflow on real hardware too. */
-#define UBOOT_MAX_GUNZIP_BYTES (64 << 20)
+#define UBOOT_MAX_GUNZIP_BYTES (64 * M_BYTE)
 
 #endif
diff --git a/hw/core/loader-fit.c b/hw/core/loader-fit.c
index 0c4a7207f4..0117104d69 100644
--- a/hw/core/loader-fit.c
+++ b/hw/core/loader-fit.c
@@ -22,7 +22,7 @@
 #include "exec/memory.h"
 #include "hw/loader.h"
 #include "hw/loader-fit.h"
-#include "qemu/cutils.h"
+#include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "sysemu/device_tree.h"
 #include "sysemu/sysemu.h"
-- 
2.17.0




[Qemu-devel] [PATCH v3 41/41] cutils: Do not include "qemu/units.h" directly

2018-04-15 Thread Philippe Mathieu-Daudé
All files using "qemu/units.h" definitions already include it directly,
we can now remove it from "qemu/cutils.h".

Signed-off-by: Philippe Mathieu-Daudé 
---
 include/qemu/cutils.h | 1 -
 hw/core/machine.c | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index 056e6629bb..cdb0f0db75 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -2,7 +2,6 @@
 #define QEMU_CUTILS_H
 
 #include "qemu/fprintf-fn.h"
-#include "qemu/units.h"
 
 /**
  * pstrcpy:
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 2040177664..8f70c5ad94 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -19,7 +19,7 @@
 #include "sysemu/sysemu.h"
 #include "sysemu/numa.h"
 #include "qemu/error-report.h"
-#include "qemu/cutils.h"
+#include "qemu/units.h"
 #include "sysemu/qtest.h"
 
 static char *machine_get_accel(Object *obj, Error **errp)
-- 
2.17.0




Re: [Qemu-devel] [PATCH v1 03/24] configure: move i386_cc to cross_cc_i386

2018-04-15 Thread Philippe Mathieu-Daudé
Hi Alex,

On 04/10/2018 04:38 PM, Alex Bennée wrote:
> We should still be able to use the system cross compiler with the
> appropriate flags on x86_64 hosts.
> 
> Signed-off-by: Alex Bennée 
> ---
>  configure | 23 +++
>  1 file changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/configure b/configure
> index b5f3b3fe29..add87ff4d4 100755
> --- a/configure
> +++ b/configure
> @@ -284,7 +284,6 @@ libs_softmmu=""
>  libs_tools=""
>  audio_pt_int=""
>  audio_win_int=""
> -cc_i386=i386-pc-linux-gnu-gcc
>  libs_qga=""
>  debug_info="yes"
>  stack_protector=""
> @@ -457,6 +456,8 @@ docker="no"
>  cross_cc_aarch64="aarch64-linux-gnu-gcc"
>  cross_cc_arm="arm-linux-gnueabihf-gcc"
>  cross_cc_powerpc="powerpc-linux-gnu-gcc"
> +cross_cc_i386="i386-pc-linux-gnu-gcc"
> +cross_cc_i386_cflags=""

Can you keep this sorted? (arm < i386 < powerpc)

Thanks :)

>  
>  enabled_cross_compilers=""
>  
> @@ -687,12 +688,10 @@ case "$cpu" in

What do you think about renaming $cpu -> host_cpu/target_cpu?

>i386|i486|i586|i686|i86pc|BePC)
>  cpu="i386"
>  supported_cpu="yes"
> -cross_cc_i386=gcc
>;;
>x86_64|amd64)
>  cpu="x86_64"
>  supported_cpu="yes"
> -cross_cc_x86_64=gcc
>;;
>armv*b|armv*l|arm)
>  cpu="arm"
> @@ -1435,7 +1434,6 @@ case "$cpu" in
>  i386)
> CPU_CFLAGS="-m32"
> LDFLAGS="-m32 $LDFLAGS"
> -   cc_i386='$(CC) -m32'
> ;;
>  x86_64)
> # ??? Only extremely old AMD cpus do not have cmpxchg16b.
> @@ -1443,12 +1441,14 @@ case "$cpu" in
> # runtime and generate the fallback to serial emulation.
> CPU_CFLAGS="-m64 -mcx16"
> LDFLAGS="-m64 $LDFLAGS"
> -   cc_i386='$(CC) -m32'
> +   cross_cc_i386=$cc
> +   cross_cc_i386_cflags="-m32"
> ;;
>  x32)
> CPU_CFLAGS="-mx32"
> LDFLAGS="-mx32 $LDFLAGS"
> -   cc_i386='$(CC) -m32'
> +   cross_cc_i386=$cc
> +   cross_cc_i386_cflags="-m32"
> ;;
>  # No special flags required for other host CPUs
>  esac
> @@ -6664,7 +6664,6 @@ echo "CC=$cc" >> $config_host_mak
>  if $iasl -h > /dev/null 2>&1; then
>echo "IASL=$iasl" >> $config_host_mak
>  fi
> -echo "CC_I386=$cc_i386" >> $config_host_mak
>  echo "HOST_CC=$host_cc" >> $config_host_mak
>  echo "CXX=$cxx" >> $config_host_mak
>  echo "OBJCC=$objcc" >> $config_host_mak
> @@ -6783,6 +6782,7 @@ case "$target" in
>  esac
>  
>  target_compiler=""
> +target_compiler_cflags=""
>  
>  mkdir -p $target_dir
>  echo "# Automatically generated by configure - do not modify" > 
> $config_target_mak
> @@ -6799,10 +6799,13 @@ TARGET_ABI_DIR=""
>  case "$target_name" in
>i386)
>  gdb_xml_files="i386-32bit.xml i386-32bit-core.xml i386-32bit-sse.xml"
> +target_compiler=$cross_cc_i386
> +target_compiler_cflags=$cross_cc_i386_cflags
>;;
>x86_64)
>  TARGET_BASE_ARCH=i386
>  gdb_xml_files="i386-64bit.xml i386-64bit-core.xml i386-64bit-sse.xml"
> +target_compiler=$cross_cc_x86_64
>;;
>alpha)
>  mttcg="yes"
> @@ -6947,7 +6950,7 @@ int main(void) {
>  }
>  EOF
>  
> -if ! do_compiler $target_compiler -o $TMPE $TMPC -static ; then
> +if ! do_compiler $target_compiler $target_compiler_cflags -o $TMPE $TMPC 
> -static ; then
>  target_compiler=""
>  else
>  enabled_cross_compilers="${enabled_cross_compilers} 
> ${target_compiler}"
> @@ -7033,6 +7036,10 @@ if test -n "$target_compiler"; then
>echo "CROSS_CC_GUEST=$target_compiler" >> $config_target_mak
>  fi
>  
> +if test -n "$target_compiler_cflags"; then
> +  echo "CROSS_CC_GUEST_CFLAGS=$target_compiler_cflags" >> $config_target_mak
> +fi
> +
>  # generate QEMU_CFLAGS/LDFLAGS for targets
>  
>  cflags=""
> 



[Qemu-devel] [PATCH v3 38/41] hw/rdma: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/rdma/vmw/pvrdma.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/rdma/vmw/pvrdma.h b/hw/rdma/vmw/pvrdma.h
index 8c173cb824..f17143f0e6 100644
--- a/hw/rdma/vmw/pvrdma.h
+++ b/hw/rdma/vmw/pvrdma.h
@@ -16,6 +16,7 @@
 #ifndef PVRDMA_PVRDMA_H
 #define PVRDMA_PVRDMA_H
 
+#include "qemu/units.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/msix.h"
 
@@ -30,7 +31,7 @@
 #define RDMA_MSIX_BAR_IDX0
 #define RDMA_REG_BAR_IDX 1
 #define RDMA_UAR_BAR_IDX 2
-#define RDMA_BAR0_MSIX_SIZE  (16 * 1024)
+#define RDMA_BAR0_MSIX_SIZE  (16 * K_BYTE)
 #define RDMA_BAR1_REGS_SIZE  256
 #define RDMA_BAR2_UAR_SIZE   (0x1000 * MAX_UCS) /* each uc gets page */
 
-- 
2.17.0




[Qemu-devel] [PATCH v3 34/41] hw/usb: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/usb/ccid-card-passthru.c   | 5 +++--
 hw/usb/combined-packet.c  | 3 ++-
 hw/usb/dev-smartcard-reader.c | 3 ++-
 hw/usb/redirect.c | 3 ++-
 4 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c
index b7dd3602dc..4bd1e2232e 100644
--- a/hw/usb/ccid-card-passthru.c
+++ b/hw/usb/ccid-card-passthru.c
@@ -9,6 +9,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include 
 #include "chardev/char-fe.h"
 #include "qemu/error-report.h"
@@ -40,7 +41,7 @@ static const uint8_t DEFAULT_ATR[] = {
  0x13, 0x08
 };
 
-#define VSCARD_IN_SIZE 65536
+#define VSCARD_IN_SIZE  (64 * K_BYTE)
 
 /* maximum size of ATR - from 7816-3 */
 #define MAX_ATR_SIZE40
@@ -276,7 +277,7 @@ static void ccid_card_vscard_read(void *opaque, const 
uint8_t *buf, int size)
 
 if (card->vscard_in_pos + size > VSCARD_IN_SIZE) {
 error_report(
-"no room for data: pos %d +  size %d > %d. dropping connection.",
+"no room for data: pos %d +  size %d > %llu. dropping connection.",
 card->vscard_in_pos, size, VSCARD_IN_SIZE);
 ccid_card_vscard_drop_connection(card);
 return;
diff --git a/hw/usb/combined-packet.c b/hw/usb/combined-packet.c
index 48cac87f6a..2f068af927 100644
--- a/hw/usb/combined-packet.c
+++ b/hw/usb/combined-packet.c
@@ -20,6 +20,7 @@
  * along with this program; if not, see .
  */
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu-common.h"
 #include "hw/usb.h"
 #include "qemu/iov.h"
@@ -171,7 +172,7 @@ void usb_ep_combine_input_packets(USBEndpoint *ep)
 if ((p->iov.size % ep->max_packet_size) != 0 || !p->short_not_ok ||
 next == NULL ||
 /* Work around for Linux usbfs bulk splitting + migration */
-(totalsize == 16348 && p->int_req)) {
+(totalsize == (16 * K_BYTE - 36) && p->int_req)) {
 usb_device_handle_data(ep->dev, first);
 assert(first->status == USB_RET_ASYNC);
 if (first->combined) {
diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c
index e6468057a0..0cdee70f82 100644
--- a/hw/usb/dev-smartcard-reader.c
+++ b/hw/usb/dev-smartcard-reader.c
@@ -35,6 +35,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "qemu/error-report.h"
@@ -63,7 +64,7 @@ do { \
  * or handle the migration complexity - VMState doesn't handle this case.
  * sizes are expected never to be exceeded, unless guest misbehaves.
  */
-#define BULK_OUT_DATA_SIZE 65536
+#define BULK_OUT_DATA_SIZE  (64 * K_BYTE)
 #define PENDING_ANSWERS_NUM 128
 
 #define BULK_IN_BUF_SIZE 384
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index 65a9196c1a..3ed4a39be1 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -26,6 +26,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "qemu/timer.h"
@@ -1298,7 +1299,7 @@ static int usbredir_chardev_can_read(void *opaque)
 }
 
 /* usbredir_parser_do_read will consume *all* data we give it */
-return 1024 * 1024;
+return 1 * M_BYTE;
 }
 
 static void usbredir_chardev_read(void *opaque, const uint8_t *buf, int size)
-- 
2.17.0




[Qemu-devel] [PATCH v3 36/41] hw/vfio: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/vfio/pci-quirks.c | 9 +
 hw/vfio/pci.c| 3 ++-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
index e5779a7ad3..4fa181a977 100644
--- a/hw/vfio/pci-quirks.c
+++ b/hw/vfio/pci-quirks.c
@@ -11,6 +11,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qemu/range.h"
 #include "qapi/error.h"
@@ -1255,9 +1256,9 @@ static int vfio_igd_gtt_max(VFIOPCIDevice *vdev)
 ggms = 1 << ggms;
 }
 
-ggms *= 1024 * 1024;
+ggms *= M_BYTE;
 
-return (ggms / (4 * 1024)) * (gen < 8 ? 4 : 8);
+return (ggms / (4 * K_BYTE)) * (gen < 8 ? 4 : 8);
 }
 
 /*
@@ -1514,7 +1515,7 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice 
*vdev, int nr)
 igd->vdev = vdev;
 igd->index = ~0;
 igd->bdsm = vfio_pci_read_config(>pdev, IGD_BDSM, 4);
-igd->bdsm &= ~((1 << 20) - 1); /* 1MB aligned */
+igd->bdsm &= ~((1 * M_BYTE) - 1); /* 1MB aligned */
 
 memory_region_init_io(>mem[0], OBJECT(vdev), _igd_index_quirk,
   igd, "vfio-igd-index-quirk", 4);
@@ -1561,7 +1562,7 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice 
*vdev, int nr)
  * config offset 0x5C.
  */
 bdsm_size = g_malloc(sizeof(*bdsm_size));
-*bdsm_size = cpu_to_le64((ggms_mb + gms_mb) * 1024 * 1024);
+*bdsm_size = cpu_to_le64((ggms_mb + gms_mb) * M_BYTE);
 fw_cfg_add_file(fw_cfg_find(), "etc/igd-bdsm-size",
 bdsm_size, sizeof(*bdsm_size));
 
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index b9bc6cd310..fb9450b3a4 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -28,6 +28,7 @@
 #include "qemu/error-report.h"
 #include "qemu/option.h"
 #include "qemu/range.h"
+#include "qemu/units.h"
 #include "sysemu/kvm.h"
 #include "sysemu/sysemu.h"
 #include "pci.h"
@@ -1417,7 +1418,7 @@ static void vfio_pci_relocate_msix(VFIOPCIDevice *vdev, 
Error **errp)
 }
 
 /* 2GB max size for 32-bit BARs, cannot double if already > 1G */
-if (vdev->bars[target_bar].size > (1 * 1024 * 1024 * 1024) &&
+if (vdev->bars[target_bar].size > 1 * G_BYTE &&
 !vdev->bars[target_bar].mem64) {
 error_setg(errp, "Invalid MSI-X relocation BAR %d, "
"no space to extend 32-bit BAR", target_bar);
-- 
2.17.0




Re: [Qemu-devel] [PATCH v1 17/24] tests/tcg: move ARM specific tests into subdir

2018-04-15 Thread Philippe Mathieu-Daudé
On 04/10/2018 04:39 PM, Alex Bennée wrote:
> These only need to be built for ARM guests.
> 
> Signed-off-by: Alex Bennée 

Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 

> ---
>  tests/tcg/README  |  9 -
>  tests/tcg/arm/README  | 11 +++
>  tests/tcg/{ => arm}/hello-arm.c   |  0
>  tests/tcg/{ => arm}/test-arm-iwmmxt.s |  0
>  4 files changed, 11 insertions(+), 9 deletions(-)
>  create mode 100644 tests/tcg/arm/README
>  rename tests/tcg/{ => arm}/hello-arm.c (100%)
>  rename tests/tcg/{ => arm}/test-arm-iwmmxt.s (100%)
> 
> diff --git a/tests/tcg/README b/tests/tcg/README
> index 469504c4cb..625f2326e6 100644
> --- a/tests/tcg/README
> +++ b/tests/tcg/README
> @@ -5,15 +5,6 @@ or they are architecture specific.
>  
>  
>  
> -ARM
> -===
> -
> -hello-arm
> --
> -
> -test-arm-iwmmxt
> 
> -
>  MIPS
>  
>  
> diff --git a/tests/tcg/arm/README b/tests/tcg/arm/README
> new file mode 100644
> index 00..e6307116e2
> --- /dev/null
> +++ b/tests/tcg/arm/README
> @@ -0,0 +1,11 @@
> +These are ARM specific guest programs
> +
> +hello-arm
> +-
> +
> +A very simple inline assembly, write syscall based hello world
> +
> +test-arm-iwmmxt
> +---
> +
> +A simple test case for older iwmmxt extended ARMs
> diff --git a/tests/tcg/hello-arm.c b/tests/tcg/arm/hello-arm.c
> similarity index 100%
> rename from tests/tcg/hello-arm.c
> rename to tests/tcg/arm/hello-arm.c
> diff --git a/tests/tcg/test-arm-iwmmxt.s b/tests/tcg/arm/test-arm-iwmmxt.s
> similarity index 100%
> rename from tests/tcg/test-arm-iwmmxt.s
> rename to tests/tcg/arm/test-arm-iwmmxt.s
> 



[Qemu-devel] [PATCH v3 30/41] hw/arm: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Alistair Francis 
---
 include/hw/arm/fsl-imx7.h  |  5 +++--
 include/hw/arm/stm32f205_soc.h |  5 +++--
 hw/arm/bcm2835_peripherals.c   |  3 ++-
 hw/arm/boot.c  |  7 ---
 hw/arm/collie.c|  5 +++--
 hw/arm/digic_boards.c  |  7 ---
 hw/arm/exynos4_boards.c|  3 ++-
 hw/arm/gumstix.c   |  3 ++-
 hw/arm/imx25_pdk.c |  1 +
 hw/arm/integratorcp.c  |  3 ++-
 hw/arm/mainstone.c |  3 ++-
 hw/arm/msf2-soc.c  |  2 +-
 hw/arm/msf2-som.c  |  2 +-
 hw/arm/musicpal.c  |  9 +
 hw/arm/omap_sx1.c  | 11 ++-
 hw/arm/raspi.c |  5 +++--
 hw/arm/stellaris.c |  5 +++--
 hw/arm/versatilepb.c   |  5 +++--
 hw/arm/vexpress.c  |  7 ---
 hw/arm/virt.c  |  5 +++--
 hw/arm/xilinx_zynq.c   |  7 ---
 hw/misc/aspeed_sdmc.c  |  9 +
 hw/misc/imx7_gpr.c |  3 ++-
 hw/misc/omap_gpmc.c|  5 +++--
 hw/pci-host/gpex.c |  3 ++-
 hw/ssi/aspeed_smc.c| 29 +++--
 26 files changed, 88 insertions(+), 64 deletions(-)

diff --git a/include/hw/arm/fsl-imx7.h b/include/hw/arm/fsl-imx7.h
index d848262bfd..fa6bf1c455 100644
--- a/include/hw/arm/fsl-imx7.h
+++ b/include/hw/arm/fsl-imx7.h
@@ -19,6 +19,7 @@
 #ifndef FSL_IMX7_H
 #define FSL_IMX7_H
 
+#include "qemu/units.h"
 #include "hw/arm/arm.h"
 #include "hw/cpu/a15mpcore.h"
 #include "hw/intc/imx_gpcv2.h"
@@ -86,7 +87,7 @@ typedef struct FslIMX7State {
 
 enum FslIMX7MemoryMap {
 FSL_IMX7_MMDC_ADDR= 0x8000,
-FSL_IMX7_MMDC_SIZE= 2 * 1024 * 1024 * 1024UL,
+FSL_IMX7_MMDC_SIZE= 2 * G_BYTE,
 
 FSL_IMX7_GPIO1_ADDR   = 0x3020,
 FSL_IMX7_GPIO2_ADDR   = 0x3021,
@@ -176,7 +177,7 @@ enum FslIMX7MemoryMap {
 FSL_IMX7_A7MPCORE_DAP_ADDR= 0x3000,
 
 FSL_IMX7_PCIE_REG_ADDR= 0x3380,
-FSL_IMX7_PCIE_REG_SIZE= 16 * 1024,
+FSL_IMX7_PCIE_REG_SIZE= 16 * K_BYTE,
 
 FSL_IMX7_GPR_ADDR = 0x3034,
 };
diff --git a/include/hw/arm/stm32f205_soc.h b/include/hw/arm/stm32f205_soc.h
index 922a733f88..aeac3338d0 100644
--- a/include/hw/arm/stm32f205_soc.h
+++ b/include/hw/arm/stm32f205_soc.h
@@ -25,6 +25,7 @@
 #ifndef HW_ARM_STM32F205_SOC_H
 #define HW_ARM_STM32F205_SOC_H
 
+#include "qemu/units.h"
 #include "hw/misc/stm32f2xx_syscfg.h"
 #include "hw/timer/stm32f2xx_timer.h"
 #include "hw/char/stm32f2xx_usart.h"
@@ -43,9 +44,9 @@
 #define STM_NUM_SPIS 3
 
 #define FLASH_BASE_ADDRESS 0x0800
-#define FLASH_SIZE (1024 * 1024)
+#define FLASH_SIZE (1 * M_BYTE)
 #define SRAM_BASE_ADDRESS 0x2000
-#define SRAM_SIZE (128 * 1024)
+#define SRAM_SIZE (128 * K_BYTE)
 
 typedef struct STM32F205State {
 /*< private >*/
diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c
index 13b63970d7..2db04bff6e 100644
--- a/hw/arm/bcm2835_peripherals.c
+++ b/hw/arm/bcm2835_peripherals.c
@@ -9,6 +9,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "hw/arm/bcm2835_peripherals.h"
 #include "hw/misc/bcm2835_mbox_defs.h"
@@ -150,7 +151,7 @@ static void bcm2835_peripherals_realize(DeviceState *dev, 
Error **errp)
 for (n = 0; n < 4; n++) {
 memory_region_init_alias(>ram_alias[n], OBJECT(s),
  "bcm2835-gpu-ram-alias[*]", ram, 0, ram_size);
-memory_region_add_subregion_overlap(>gpu_bus_mr, (hwaddr)n << 30,
+memory_region_add_subregion_overlap(>gpu_bus_mr, n * G_BYTE,
 >ram_alias[n], 0);
 }
 
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index 26184bcd7c..ad169708d8 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -8,6 +8,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include 
@@ -1039,7 +1040,7 @@ static void arm_load_kernel_notify(Notifier *notifier, 
void *data)
  * the initrd at 128MB.
  */
 info->initrd_start = info->loader_start +
-MIN(info->ram_size / 2, 128 * 1024 * 1024);
+MIN(info->ram_size / 2, 128 * M_BYTE);
 
 /* Assume that raw images are linux kernels, and ELF images are not.  */
 kernel_size = arm_load_elf(info, _entry, _low_addr,
@@ -1126,13 +1127,13 @@ static void arm_load_kernel_notify(Notifier *notifier, 
void *data)
  *
  * Let's play safe and prealign it to 2MB to give us some 
space.
  */
-align = 2 * 1024 * 1024;
+align = 2 * M_BYTE;
 } 

[Qemu-devel] [PATCH v3 27/41] hw/lm32: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/lm32/lm32_boards.c | 13 +++--
 hw/lm32/milkymist.c   | 10 +-
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/hw/lm32/lm32_boards.c b/hw/lm32/lm32_boards.c
index 527bcc229c..ef229dd315 100644
--- a/hw/lm32/lm32_boards.c
+++ b/hw/lm32/lm32_boards.c
@@ -18,6 +18,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qemu-common.h"
 #include "cpu.h"
@@ -88,10 +89,10 @@ static void lm32_evr_init(MachineState *machine)
 
 /* memory map */
 hwaddr flash_base  = 0x0400;
-size_t flash_sector_size   = 256 * 1024;
-size_t flash_size  = 32 * 1024 * 1024;
+size_t flash_sector_size   = 256 * K_BYTE;
+size_t flash_size  = 32 * M_BYTE;
 hwaddr ram_base= 0x0800;
-size_t ram_size= 64 * 1024 * 1024;
+size_t ram_size= 64 * M_BYTE;
 hwaddr timer0_base = 0x80002000;
 hwaddr uart0_base  = 0x80006000;
 hwaddr timer1_base = 0x8000a000;
@@ -174,10 +175,10 @@ static void lm32_uclinux_init(MachineState *machine)
 
 /* memory map */
 hwaddr flash_base   = 0x0400;
-size_t flash_sector_size= 256 * 1024;
-size_t flash_size   = 32 * 1024 * 1024;
+size_t flash_sector_size= 256 * K_BYTE;
+size_t flash_size   = 32 * M_BYTE;
 hwaddr ram_base = 0x0800;
-size_t ram_size = 64 * 1024 * 1024;
+size_t ram_size = 64 * M_BYTE;
 hwaddr uart0_base   = 0x8000;
 hwaddr timer0_base  = 0x80002000;
 hwaddr timer1_base  = 0x8001;
diff --git a/hw/lm32/milkymist.c b/hw/lm32/milkymist.c
index 85d64fe58d..f530997abb 100644
--- a/hw/lm32/milkymist.c
+++ b/hw/lm32/milkymist.c
@@ -18,6 +18,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qemu-common.h"
 #include "cpu.h"
@@ -34,11 +35,10 @@
 #include "milkymist-hw.h"
 #include "lm32.h"
 #include "exec/address-spaces.h"
-#include "qemu/cutils.h"
 
 #define BIOS_FILENAME"mmone-bios.bin"
 #define BIOS_OFFSET  0x0086
-#define BIOS_SIZE(512*1024)
+#define BIOS_SIZE(512 * K_BYTE)
 #define KERNEL_LOAD_ADDR 0x4000
 
 typedef struct {
@@ -97,10 +97,10 @@ milkymist_init(MachineState *machine)
 
 /* memory map */
 hwaddr flash_base   = 0x;
-size_t flash_sector_size= 128 * 1024;
-size_t flash_size   = 32 * 1024 * 1024;
+size_t flash_sector_size= 128 * K_BYTE;
+size_t flash_size   = 32 * M_BYTE;
 hwaddr sdram_base   = 0x4000;
-size_t sdram_size   = 128 * 1024 * 1024;
+size_t sdram_size   = 128 * M_BYTE;
 
 hwaddr initrd_base  = sdram_base + 0x1002000;
 hwaddr cmdline_base = sdram_base + 0x100;
-- 
2.17.0




Re: [Qemu-devel] [PATCH v1 12/24] tests/tcg/i386: Build fix for hello-i386

2018-04-15 Thread Philippe Mathieu-Daudé
Hi Fam, Alex,

On 04/10/2018 04:39 PM, Alex Bennée wrote:
> From: Fam Zheng 
> 
> We have -Werror=missing-prototype, add a dummy prototype to avoid that
> warning.
> 
> Signed-off-by: Fam Zheng 
> ---
>  tests/tcg/i386/hello-i386.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tests/tcg/i386/hello-i386.c b/tests/tcg/i386/hello-i386.c
> index fa00380de2..cfeb24b2f5 100644
> --- a/tests/tcg/i386/hello-i386.c
> +++ b/tests/tcg/i386/hello-i386.c
> @@ -20,6 +20,7 @@ static inline int write(int fd, const char * buf, int len)
>return status;
>  }
>  
> +void _start(void);

What about adding that in a common base file include by all tcg tests?
Such tests/tcg/include/tcg-common.h or better name...

>  void _start(void)
>  {
>  write(1, "Hello World\n", 12);
> 



[Qemu-devel] [PATCH v3 28/41] hw/sh4: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/sh4/r2d.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c
index f5f3deab37..e488fd49b1 100644
--- a/hw/sh4/r2d.c
+++ b/hw/sh4/r2d.c
@@ -24,6 +24,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "cpu.h"
@@ -291,7 +292,7 @@ static void r2d_init(MachineState *machine)
 dinfo = drive_get(IF_PFLASH, 0, 0);
 pflash_cfi02_register(0x0, NULL, "r2d.flash", FLASH_SIZE,
   dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-  (16 * 1024), FLASH_SIZE >> 16,
+  16 * K_BYTE, FLASH_SIZE >> 16,
   1, 4, 0x, 0x, 0x, 0x,
   0x555, 0x2aa, 0);
 
-- 
2.17.0




[Qemu-devel] [PATCH v3 29/41] hw/mips: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/intc/mips_gic.h |  3 ++-
 include/hw/mips/bios.h |  3 ++-
 hw/mips/boston.c   |  4 ++--
 hw/mips/mips_fulong2e.c|  7 ---
 hw/mips/mips_malta.c   | 23 +--
 hw/mips/mips_r4k.c | 11 ++-
 hw/misc/mips_itu.c |  3 ++-
 hw/pci-host/xilinx-pcie.c  |  5 +++--
 8 files changed, 34 insertions(+), 25 deletions(-)

diff --git a/include/hw/intc/mips_gic.h b/include/hw/intc/mips_gic.h
index b98d50094a..c0da44bdb3 100644
--- a/include/hw/intc/mips_gic.h
+++ b/include/hw/intc/mips_gic.h
@@ -11,6 +11,7 @@
 #ifndef MIPS_GIC_H
 #define MIPS_GIC_H
 
+#include "qemu/units.h"
 #include "hw/timer/mips_gictimer.h"
 #include "cpu.h"
 /*
@@ -19,7 +20,7 @@
 
 /* The MIPS default location */
 #define GIC_BASE_ADDR   0x1bdcULL
-#define GIC_ADDRSPACE_SZ(128 * 1024)
+#define GIC_ADDRSPACE_SZ(128 * K_BYTE)
 
 /* Constants */
 #define GIC_POL_POS 1
diff --git a/include/hw/mips/bios.h b/include/hw/mips/bios.h
index b4b88ac43d..b4c97ce87c 100644
--- a/include/hw/mips/bios.h
+++ b/include/hw/mips/bios.h
@@ -1,6 +1,7 @@
+#include "qemu/units.h"
 #include "cpu.h"
 
-#define BIOS_SIZE (4 * 1024 * 1024)
+#define BIOS_SIZE (4 * M_BYTE)
 #ifdef TARGET_WORDS_BIGENDIAN
 #define BIOS_FILENAME "mips_bios.bin"
 #else
diff --git a/hw/mips/boston.c b/hw/mips/boston.c
index fb23161b33..edc39e91f7 100644
--- a/hw/mips/boston.c
+++ b/hw/mips/boston.c
@@ -32,7 +32,7 @@
 #include "hw/mips/cpudevs.h"
 #include "hw/pci-host/xilinx-pcie.h"
 #include "qapi/error.h"
-#include "qemu/cutils.h"
+#include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qemu/log.h"
 #include "chardev/char.h"
@@ -437,7 +437,7 @@ static void boston_mach_init(MachineState *machine)
 bool is_64b;
 
 if ((machine->ram_size % G_BYTE) ||
-(machine->ram_size > (2 * G_BYTE))) {
+(machine->ram_size > 2 * G_BYTE)) {
 error_report("Memory size must be 1GB or 2GB");
 exit(1);
 }
diff --git a/hw/mips/mips_fulong2e.c b/hw/mips/mips_fulong2e.c
index 02fb2fdcc4..779883db7c 100644
--- a/hw/mips/mips_fulong2e.c
+++ b/hw/mips/mips_fulong2e.c
@@ -19,6 +19,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "hw/hw.h"
 #include "hw/i386/pc.h"
@@ -159,7 +160,7 @@ static int64_t load_kernel (CPUMIPSState *env)
 /* Setup minimum environment variables */
 prom_set(prom_buf, index++, "busclock=3300");
 prom_set(prom_buf, index++, "cpuclock=1");
-prom_set(prom_buf, index++, "memsize=%i", loaderparams.ram_size/1024/1024);
+prom_set(prom_buf, index++, "memsize=%llu", loaderparams.ram_size / 
M_BYTE);
 prom_set(prom_buf, index++, "modetty0=38400n8r");
 prom_set(prom_buf, index++, NULL);
 
@@ -303,10 +304,10 @@ static void mips_fulong2e_init(MachineState *machine)
 qemu_register_reset(main_cpu_reset, cpu);
 
 /* fulong 2e has 256M ram. */
-ram_size = 256 * 1024 * 1024;
+ram_size = 256 * M_BYTE;
 
 /* fulong 2e has a 1M flash.Winbond W39L040AP70Z */
-bios_size = 1024 * 1024;
+bios_size = 1 * M_BYTE;
 
 /* allocate RAM */
 memory_region_allocate_system_memory(ram, NULL, "fulong2e.ram", ram_size);
diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c
index f6513a4fd5..240dd762be 100644
--- a/hw/mips/mips_malta.c
+++ b/hw/mips/mips_malta.c
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu-common.h"
 #include "cpu.h"
 #include "hw/hw.h"
@@ -844,7 +845,8 @@ static int64_t load_kernel (void)
 /* The kernel allocates the bootmap memory in the low memory after
the initrd.  It takes at most 128kiB for 2GB RAM and 4kiB
pages.  */
-initrd_offset = (loaderparams.ram_low_size - initrd_size - 131072
+initrd_offset = (loaderparams.ram_low_size - initrd_size
+ - (128 * K_BYTE)
  - ~INITRD_PAGE_MASK) & INITRD_PAGE_MASK;
 if (kernel_high >= initrd_offset) {
 error_report("memory too small for initial ram disk '%s'",
@@ -1022,9 +1024,9 @@ void mips_malta_init(MachineState *machine)
 mips_create_cpu(s, machine->cpu_type, _irq, _irq);
 
 /* allocate RAM */
-if (ram_size > (2048u << 20)) {
-error_report("Too much memory for this machine: %dMB, maximum 2048MB",
- ((unsigned int)ram_size / (1 << 20)));
+if (ram_size > 2 * G_BYTE) {
+error_report("Too much memory for this machine: %lluMB, maximum 
2048MB",
+ ram_size / M_BYTE);
 exit(1);
 }
 
@@ -1035,17 +1037,18 @@ void mips_malta_init(MachineState *machine)
 
 /* alias for pre IO hole access */
 

[Qemu-devel] [PATCH v3 25/41] hw/nios2: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/nios2/boot.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/nios2/boot.c b/hw/nios2/boot.c
index 94f436e7fb..1cc924805b 100644
--- a/hw/nios2/boot.c
+++ b/hw/nios2/boot.c
@@ -29,6 +29,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu-common.h"
 #include "cpu.h"
 #include "qemu/option.h"
@@ -38,7 +39,6 @@
 #include "sysemu/sysemu.h"
 #include "hw/loader.h"
 #include "elf.h"
-#include "qemu/cutils.h"
 
 #include "boot.h"
 
@@ -177,7 +177,7 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base,
 high = ddr_base + kernel_size;
 }
 
-high = ROUND_UP(high, 1024 * 1024);
+high = ROUND_UP(high, 1 * M_BYTE);
 
 /* If initrd is available, it goes after the kernel, aligned to 1M. */
 if (initrd_filename) {
@@ -213,7 +213,7 @@ void nios2_load_kernel(Nios2CPU *cpu, hwaddr ddr_base,
 high += fdt_size;
 
 /* Kernel command is at the end, 4k aligned. */
-boot_info.cmdline = ROUND_UP(high, 4096);
+boot_info.cmdline = ROUND_UP(high, 4 * K_BYTE);
 if (kernel_cmdline && strlen(kernel_cmdline)) {
 pstrcpy_targphys("cmdline", boot_info.cmdline, 256, 
kernel_cmdline);
 }
-- 
2.17.0




[Qemu-devel] [PATCH v3 24/41] hw/microblaze: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/microblaze/petalogix_ml605_mmu.c  | 7 ---
 hw/microblaze/petalogix_s3adsp1800_mmu.c | 7 ---
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/hw/microblaze/petalogix_ml605_mmu.c 
b/hw/microblaze/petalogix_ml605_mmu.c
index b664dc0f9c..5c4fe2345c 100644
--- a/hw/microblaze/petalogix_ml605_mmu.c
+++ b/hw/microblaze/petalogix_ml605_mmu.c
@@ -26,6 +26,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "cpu.h"
@@ -45,8 +46,8 @@
 
 #include "hw/stream.h"
 
-#define LMB_BRAM_SIZE  (128 * 1024)
-#define FLASH_SIZE (32 * 1024 * 1024)
+#define LMB_BRAM_SIZE  (128 * K_BYTE)
+#define FLASH_SIZE (32 * M_BYTE)
 
 #define BINARY_DEVICE_TREE_FILE "petalogix-ml605.dtb"
 
@@ -110,7 +111,7 @@ petalogix_ml605_init(MachineState *machine)
 pflash_cfi01_register(FLASH_BASEADDR,
   NULL, "petalogix_ml605.flash", FLASH_SIZE,
   dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-  (64 * 1024), FLASH_SIZE >> 16,
+  64 * K_BYTE, FLASH_SIZE >> 16,
   2, 0x89, 0x18, 0x, 0x0, 0);
 
 
diff --git a/hw/microblaze/petalogix_s3adsp1800_mmu.c 
b/hw/microblaze/petalogix_s3adsp1800_mmu.c
index 5cb4deb69e..32e73a589f 100644
--- a/hw/microblaze/petalogix_s3adsp1800_mmu.c
+++ b/hw/microblaze/petalogix_s3adsp1800_mmu.c
@@ -24,6 +24,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "cpu.h"
@@ -40,8 +41,8 @@
 
 #include "boot.h"
 
-#define LMB_BRAM_SIZE  (128 * 1024)
-#define FLASH_SIZE (16 * 1024 * 1024)
+#define LMB_BRAM_SIZE  (128 * K_BYTE)
+#define FLASH_SIZE (16 * M_BYTE)
 
 #define BINARY_DEVICE_TREE_FILE "petalogix-s3adsp1800.dtb"
 
@@ -88,7 +89,7 @@ petalogix_s3adsp1800_init(MachineState *machine)
 pflash_cfi01_register(FLASH_BASEADDR,
   NULL, "petalogix_s3adsp1800.flash", FLASH_SIZE,
   dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
-  (64 * 1024), FLASH_SIZE >> 16,
+  64 * K_BYTE, FLASH_SIZE >> 16,
   1, 0x89, 0x18, 0x, 0x0, 1);
 
 dev = qdev_create(NULL, "xlnx.xps-intc");
-- 
2.17.0




[Qemu-devel] [PATCH v3 26/41] hw/cris: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/cris/axis_dev88.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/cris/axis_dev88.c b/hw/cris/axis_dev88.c
index 1775e53e25..a0f83f53d2 100644
--- a/hw/cris/axis_dev88.c
+++ b/hw/cris/axis_dev88.c
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "cpu.h"
@@ -242,7 +243,7 @@ static const MemoryRegionOps gpio_ops = {
 },
 };
 
-#define INTMEM_SIZE (128 * 1024)
+#define INTMEM_SIZE (128 * K_BYTE)
 
 static struct cris_load_info li;
 
-- 
2.17.0




[Qemu-devel] [PATCH v3 20/41] hw/hppa: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/hppa/dino.c|  3 ++-
 hw/hppa/machine.c | 10 +-
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/hw/hppa/dino.c b/hw/hppa/dino.c
index 15aefde09c..31d69ae61b 100644
--- a/hw/hppa/dino.c
+++ b/hw/hppa/dino.c
@@ -11,6 +11,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "cpu.h"
 #include "hw/hw.h"
@@ -76,7 +77,7 @@
 /* #define xxx0x200 - bit 9 not used */
 #define RS232INT  0x400
 
-#define DINO_MEM_CHUNK_SIZE (8 * 1024 * 1024) /* 8MB */
+#define DINO_MEM_CHUNK_SIZE (8 * M_BYTE)
 
 #define DINO_PCI_HOST_BRIDGE(obj) \
 OBJECT_CHECK(DinoState, (obj), TYPE_DINO_PCI_HOST_BRIDGE)
diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c
index 19033e268d..87dbb77987 100644
--- a/hw/hppa/machine.c
+++ b/hw/hppa/machine.c
@@ -17,7 +17,7 @@
 #include "hw/timer/i8254.h"
 #include "hw/char/serial.h"
 #include "hw/hppa/hppa_sys.h"
-#include "qemu/cutils.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu/log.h"
 
@@ -178,8 +178,8 @@ static void machine_hppa_init(MachineState *machine)
 }
 qemu_log_mask(CPU_LOG_PAGE, "Kernel loaded at 0x%08" PRIx64
   "-0x%08" PRIx64 ", entry at 0x%08" PRIx64
-  ", size %ld kB.\n",
-  kernel_low, kernel_high, kernel_entry, size / 1024);
+  ", size %llu kB\n",
+  kernel_low, kernel_high, kernel_entry, size / K_BYTE);
 
 if (kernel_cmdline) {
 cpu[0]->env.gr[24] = 0x4000;
@@ -203,8 +203,8 @@ static void machine_hppa_init(MachineState *machine)
(1) Due to sign-extension problems and PDC,
put the initrd no higher than 1G.
(2) Reserve 64k for stack.  */
-initrd_base = MIN(ram_size, 1024 * 1024 * 1024);
-initrd_base = initrd_base - 64 * 1024;
+initrd_base = MIN(ram_size, 1 * G_BYTE);
+initrd_base = initrd_base - 64 * K_BYTE;
 initrd_base = (initrd_base - initrd_size) & TARGET_PAGE_MASK;
 
 if (initrd_base < kernel_high) {
-- 
2.17.0




[Qemu-devel] [PATCH v3 22/41] hw/alpha: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/alpha/typhoon.c | 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/hw/alpha/typhoon.c b/hw/alpha/typhoon.c
index 6a40869488..85fe072063 100644
--- a/hw/alpha/typhoon.c
+++ b/hw/alpha/typhoon.c
@@ -7,6 +7,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "cpu.h"
 #include "hw/hw.h"
@@ -812,8 +813,6 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus **isa_bus,
  qemu_irq *p_rtc_irq,
  AlphaCPU *cpus[4], pci_map_irq_fn sys_map_irq)
 {
-const uint64_t MB = 1024 * 1024;
-const uint64_t GB = 1024 * MB;
 MemoryRegion *addr_space = get_system_memory();
 DeviceState *dev;
 TyphoonState *s;
@@ -854,30 +853,30 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus 
**isa_bus,
 
 /* Pchip0 CSRs, 0x801.8000., 256MB.  */
 memory_region_init_io(>pchip.region, OBJECT(s), _ops, s, "pchip0",
-  256*MB);
+  256 * M_BYTE);
 memory_region_add_subregion(addr_space, 0x8018000ULL,
 >pchip.region);
 
 /* Cchip CSRs, 0x801.A000., 256MB.  */
 memory_region_init_io(>cchip.region, OBJECT(s), _ops, s, "cchip0",
-  256*MB);
+  256 * M_BYTE);
 memory_region_add_subregion(addr_space, 0x801a000ULL,
 >cchip.region);
 
 /* Dchip CSRs, 0x801.B000., 256MB.  */
 memory_region_init_io(>dchip_region, OBJECT(s), _ops, s, "dchip0",
-  256*MB);
+  256 * M_BYTE);
 memory_region_add_subregion(addr_space, 0x801b000ULL,
 >dchip_region);
 
 /* Pchip0 PCI memory, 0x800.., 4GB.  */
-memory_region_init(>pchip.reg_mem, OBJECT(s), "pci0-mem", 4*GB);
+memory_region_init(>pchip.reg_mem, OBJECT(s), "pci0-mem", 4 * G_BYTE);
 memory_region_add_subregion(addr_space, 0x800ULL,
 >pchip.reg_mem);
 
 /* Pchip0 PCI I/O, 0x801.FC00., 32MB.  */
 memory_region_init_io(>pchip.reg_io, OBJECT(s), _pci_ignore_ops,
-  NULL, "pci0-io", 32*MB);
+  NULL, "pci0-io", 32 * M_BYTE);
 memory_region_add_subregion(addr_space, 0x801fc00ULL,
 >pchip.reg_io);
 
@@ -898,13 +897,13 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus 
**isa_bus,
 
 /* Pchip0 PCI special/interrupt acknowledge, 0x801.F800., 64MB.  */
 memory_region_init_io(>pchip.reg_iack, OBJECT(s), _pci_iack_ops,
-  b, "pci0-iack", 64*MB);
+  b, "pci0-iack", 64 * M_BYTE);
 memory_region_add_subregion(addr_space, 0x801f800ULL,
 >pchip.reg_iack);
 
 /* Pchip0 PCI configuration, 0x801.FE00., 16MB.  */
 memory_region_init_io(>pchip.reg_conf, OBJECT(s), _pci_conf1_ops,
-  b, "pci0-conf", 16*MB);
+  b, "pci0-conf", 16 * M_BYTE);
 memory_region_add_subregion(addr_space, 0x801fe00ULL,
 >pchip.reg_conf);
 
-- 
2.17.0




[Qemu-devel] [PATCH v3 23/41] hw/tricore: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Acked-by: Bastian Koppelmann 
---
 hw/tricore/tricore_testboard.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/hw/tricore/tricore_testboard.c b/hw/tricore/tricore_testboard.c
index 8e61dfc3e6..a30a2f8345 100644
--- a/hw/tricore/tricore_testboard.c
+++ b/hw/tricore/tricore_testboard.c
@@ -19,6 +19,7 @@
 
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "cpu.h"
@@ -72,17 +73,17 @@ static void tricore_testboard_init(MachineState *machine, 
int board_id)
 cpu = TRICORE_CPU(cpu_create(machine->cpu_type));
 env = >env;
 memory_region_init_ram(ext_cram, NULL, "powerlink_ext_c.ram",
-   2 * 1024 * 1024, _fatal);
+   2 * M_BYTE, _fatal);
 memory_region_init_ram(ext_dram, NULL, "powerlink_ext_d.ram",
-   4 * 1024 * 1024, _fatal);
-memory_region_init_ram(int_cram, NULL, "powerlink_int_c.ram", 48 * 1024,
+   4 * M_BYTE, _fatal);
+memory_region_init_ram(int_cram, NULL, "powerlink_int_c.ram", 48 * K_BYTE,
_fatal);
-memory_region_init_ram(int_dram, NULL, "powerlink_int_d.ram", 48 * 1024,
+memory_region_init_ram(int_dram, NULL, "powerlink_int_d.ram", 48 * K_BYTE,
_fatal);
 memory_region_init_ram(pcp_data, NULL, "powerlink_pcp_data.ram",
-   16 * 1024, _fatal);
+   16 * K_BYTE, _fatal);
 memory_region_init_ram(pcp_text, NULL, "powerlink_pcp_text.ram",
-   32 * 1024, _fatal);
+   32 * K_BYTE, _fatal);
 
 memory_region_add_subregion(sysmem, 0x8000, ext_cram);
 memory_region_add_subregion(sysmem, 0xa100, ext_dram);
-- 
2.17.0




[Qemu-devel] [PATCH v3 17/41] hw/m68k: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/m68k/mcf5208.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/m68k/mcf5208.c b/hw/m68k/mcf5208.c
index fac0d09cbc..673d65f8fd 100644
--- a/hw/m68k/mcf5208.c
+++ b/hw/m68k/mcf5208.c
@@ -6,6 +6,7 @@
  * This code is licensed under the GPL
  */
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
@@ -241,7 +242,7 @@ static void mcf5208evb_init(MachineState *machine)
 memory_region_add_subregion(address_space_mem, 0x4000, ram);
 
 /* Internal SRAM.  */
-memory_region_init_ram(sram, NULL, "mcf5208.sram", 16384, _fatal);
+memory_region_init_ram(sram, NULL, "mcf5208.sram", 16 * K_BYTE, 
_fatal);
 memory_region_add_subregion(address_space_mem, 0x8000, sram);
 
 /* Internal peripherals.  */
-- 
2.17.0




[Qemu-devel] [PATCH v3 39/41] hw/nvdimm: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/mem/nvdimm.h | 3 ++-
 hw/mem/nvdimm.c | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/hw/mem/nvdimm.h b/include/hw/mem/nvdimm.h
index 7fd87c4e1c..fda855ad1a 100644
--- a/include/hw/mem/nvdimm.h
+++ b/include/hw/mem/nvdimm.h
@@ -23,6 +23,7 @@
 #ifndef QEMU_NVDIMM_H
 #define QEMU_NVDIMM_H
 
+#include "qemu/units.h"
 #include "hw/mem/pc-dimm.h"
 #include "hw/acpi/bios-linker-loader.h"
 
@@ -40,7 +41,7 @@
  *   "NVDIMMs following the NVDIMM Block Mode Specification use an area
  *at least 128KB in size, which holds around 1000 labels."
  */
-#define MIN_NAMESPACE_LABEL_SIZE  (128UL << 10)
+#define MIN_NAMESPACE_LABEL_SIZE  (128 * K_BYTE)
 
 #define TYPE_NVDIMM  "nvdimm"
 #define NVDIMM(obj)  OBJECT_CHECK(NVDIMMDevice, (obj), TYPE_NVDIMM)
diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c
index acb656b672..0f83e9fb4c 100644
--- a/hw/mem/nvdimm.c
+++ b/hw/mem/nvdimm.c
@@ -54,7 +54,7 @@ static void nvdimm_set_label_size(Object *obj, Visitor *v, 
const char *name,
 }
 if (value < MIN_NAMESPACE_LABEL_SIZE) {
 error_setg(_err, "Property '%s.%s' (0x%" PRIx64 ") is required"
-   " at least 0x%lx", object_get_typename(obj),
+   " at least 0x%llx", object_get_typename(obj),
name, value, MIN_NAMESPACE_LABEL_SIZE);
 goto out;
 }
-- 
2.17.0




[Qemu-devel] [PATCH v3 21/41] hw/xtensa: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Acked-by: Max Filippov 
---
 hw/xtensa/xtfpga.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
index 70686a2eb1..2d1cce1d31 100644
--- a/hw/xtensa/xtfpga.c
+++ b/hw/xtensa/xtfpga.c
@@ -26,6 +26,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "cpu.h"
 #include "sysemu/sysemu.h"
@@ -153,7 +154,7 @@ static void xtfpga_net_init(MemoryRegion *address_space,
 sysbus_mmio_get_region(s, 1));
 
 ram = g_malloc(sizeof(*ram));
-memory_region_init_ram_nomigrate(ram, OBJECT(s), "open_eth.ram", 16384,
+memory_region_init_ram_nomigrate(ram, OBJECT(s), "open_eth.ram", 16 * 
K_BYTE,
_fatal);
 vmstate_register_ram_global(ram);
 memory_region_add_subregion(address_space, buffers, ram);
@@ -230,7 +231,7 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, 
MachineState *machine)
 const char *kernel_cmdline = qemu_opt_get(machine_opts, "append");
 const char *dtb_filename = qemu_opt_get(machine_opts, "dtb");
 const char *initrd_filename = qemu_opt_get(machine_opts, "initrd");
-const unsigned system_io_size = 224 * 1024 * 1024;
+const unsigned system_io_size = 224 * M_BYTE;
 int n;
 
 for (n = 0; n < smp_cpus; n++) {
-- 
2.17.0




[Qemu-devel] [PATCH v3 13/41] hw/block: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/block/nvme.c| 3 ++-
 hw/block/tc58128.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 811084b6a7..273d36de76 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -25,6 +25,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/block/block.h"
 #include "hw/hw.h"
 #include "hw/pci/msix.h"
@@ -648,7 +649,7 @@ static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeIdentify 
*c)
 
 static uint16_t nvme_identify_nslist(NvmeCtrl *n, NvmeIdentify *c)
 {
-static const int data_len = 4096;
+static const int data_len = 4 * K_BYTE;
 uint32_t min_nsid = le32_to_cpu(c->nsid);
 uint64_t prp1 = le64_to_cpu(c->prp1);
 uint64_t prp2 = le64_to_cpu(c->prp2);
diff --git a/hw/block/tc58128.c b/hw/block/tc58128.c
index 1d9f7ee000..42e1269546 100644
--- a/hw/block/tc58128.c
+++ b/hw/block/tc58128.c
@@ -1,4 +1,5 @@
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/hw.h"
 #include "hw/sh4/sh.h"
 #include "hw/loader.h"
@@ -26,7 +27,7 @@ typedef struct {
 
 static tc58128_dev tc58128_devs[2];
 
-#define FLASH_SIZE (16*1024*1024)
+#define FLASH_SIZE (16 * M_BYTE)
 
 static void init_dev(tc58128_dev * dev, const char *filename)
 {
-- 
2.17.0




[Qemu-devel] [PATCH v3 37/41] hw/virtio: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/virtio/virtio-net.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index 02484dc94c..8765f6546e 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -14,6 +14,7 @@
 #ifndef QEMU_VIRTIO_NET_H
 #define QEMU_VIRTIO_NET_H
 
+#include "qemu/units.h"
 #include "standard-headers/linux/virtio_net.h"
 #include "hw/virtio/virtio.h"
 
@@ -44,7 +45,7 @@ typedef struct virtio_net_conf
 } virtio_net_conf;
 
 /* Maximum packet size we can receive from tap device: header + 64k */
-#define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 << 10))
+#define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 * K_BYTE))
 
 typedef struct VirtIONetQueue {
 VirtQueue *rx_vq;
-- 
2.17.0




[Qemu-devel] [PATCH v3 12/41] hw/tpm: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Marc-André Lureau 
---
 include/hw/acpi/tpm.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/hw/acpi/tpm.h b/include/hw/acpi/tpm.h
index 46ac4dc581..5c72efe999 100644
--- a/include/hw/acpi/tpm.h
+++ b/include/hw/acpi/tpm.h
@@ -16,6 +16,7 @@
 #ifndef HW_ACPI_TPM_H
 #define HW_ACPI_TPM_H
 
+#include "qemu/units.h"
 #include "hw/registerfields.h"
 
 #define TPM_TIS_ADDR_BASE   0xFED4
@@ -176,7 +177,7 @@ REG32(CRB_DATA_BUFFER, 0x80)
 #define TPM_CRB_ADDR_CTRL   (TPM_CRB_ADDR_BASE + A_CRB_CTRL_REQ)
 #define TPM_CRB_R_MAX   R_CRB_DATA_BUFFER
 
-#define TPM_LOG_AREA_MINIMUM_SIZE   (64 * 1024)
+#define TPM_LOG_AREA_MINIMUM_SIZE   (64 * K_BYTE)
 
 #define TPM_TCPA_ACPI_CLASS_CLIENT  0
 #define TPM_TCPA_ACPI_CLASS_SERVER  1
-- 
2.17.0




[Qemu-devel] [PATCH v3 19/41] hw/s390x: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Thomas Huth 
Acked-by: Cornelia Huck 
---
 hw/s390x/s390-skeys.c| 3 ++-
 hw/s390x/s390-stattrib.c | 3 ++-
 hw/s390x/sclp.c  | 5 +++--
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c
index 76241c240e..a95373af94 100644
--- a/hw/s390x/s390-skeys.c
+++ b/hw/s390x/s390-skeys.c
@@ -10,6 +10,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/boards.h"
 #include "hw/s390x/storage-keys.h"
 #include "qapi/error.h"
@@ -19,7 +20,7 @@
 #include "sysemu/kvm.h"
 #include "migration/register.h"
 
-#define S390_SKEYS_BUFFER_SIZE 131072  /* Room for 128k storage keys */
+#define S390_SKEYS_BUFFER_SIZE (128 * K_BYTE)  /* Room for 128k storage keys */
 #define S390_SKEYS_SAVE_FLAG_EOS 0x01
 #define S390_SKEYS_SAVE_FLAG_SKEYS 0x02
 #define S390_SKEYS_SAVE_FLAG_ERROR 0x04
diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c
index 70b95550a8..7a4a4e61d3 100644
--- a/hw/s390x/s390-stattrib.c
+++ b/hw/s390x/s390-stattrib.c
@@ -10,6 +10,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/boards.h"
 #include "cpu.h"
 #include "migration/qemu-file.h"
@@ -20,7 +21,7 @@
 #include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
 
-#define CMMA_BLOCK_SIZE  (1 << 10)
+#define CMMA_BLOCK_SIZE  (1 * K_BYTE)
 
 #define STATTR_FLAG_EOS 0x01ULL
 #define STATTR_FLAG_MORE0x02ULL
diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
index 047d577313..4cd6548d49 100644
--- a/hw/s390x/sclp.c
+++ b/hw/s390x/sclp.c
@@ -13,6 +13,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "cpu.h"
 #include "sysemu/sysemu.h"
@@ -288,8 +289,8 @@ static void sclp_realize(DeviceState *dev, Error **errp)
 
 ret = s390_set_memory_limit(machine->maxram_size, _limit);
 if (ret == -E2BIG) {
-error_setg(, "host supports a maximum of %" PRIu64 " GB",
-   hw_limit >> 30);
+error_setg(, "host supports a maximum of %llu GB",
+   hw_limit / G_BYTE);
 } else if (ret) {
 error_setg(, "setting the guest size failed");
 }
-- 
2.17.0




[Qemu-devel] [PATCH v3 11/41] hw/xen: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Alan Robinson 
---
 hw/block/xen_disk.c|  5 +++--
 hw/i386/xen/xen-mapcache.c |  3 ++-
 hw/xenpv/xen_domainbuild.c | 13 +++--
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
index f74fcd42d1..c342106fd5 100644
--- a/hw/block/xen_disk.c
+++ b/hw/block/xen_disk.c
@@ -20,6 +20,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include 
 #include 
 
@@ -1153,9 +1154,9 @@ static int blk_connect(struct XenDevice *xendev)
 }
 
 xen_pv_printf(xendev, 1, "type \"%s\", fileproto \"%s\", filename \"%s\","
-  " size %" PRId64 " (%" PRId64 " MB)\n",
+  " size %" PRId64 " (%llu MB)\n",
   blkdev->type, blkdev->fileproto, blkdev->filename,
-  blkdev->file_size, blkdev->file_size >> 20);
+  blkdev->file_size, blkdev->file_size / M_BYTE);
 
 /* Fill in number of sector size and number of sectors */
 xenstore_write_be_int(>xendev, "sector-size", blkdev->file_blk);
diff --git a/hw/i386/xen/xen-mapcache.c b/hw/i386/xen/xen-mapcache.c
index efa35dc6e0..068347495c 100644
--- a/hw/i386/xen/xen-mapcache.c
+++ b/hw/i386/xen/xen-mapcache.c
@@ -9,6 +9,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/error-report.h"
 
 #include 
@@ -47,7 +48,7 @@
  * From empirical tests I observed that qemu use 75MB more than the
  * max_mcache_size.
  */
-#define NON_MCACHE_MEMORY_SIZE (80 * 1024 * 1024)
+#define NON_MCACHE_MEMORY_SIZE (80 * M_BYTE)
 
 typedef struct MapCacheEntry {
 hwaddr paddr_index;
diff --git a/hw/xenpv/xen_domainbuild.c b/hw/xenpv/xen_domainbuild.c
index 027f76fad1..4c77bb70a7 100644
--- a/hw/xenpv/xen_domainbuild.c
+++ b/hw/xenpv/xen_domainbuild.c
@@ -1,4 +1,5 @@
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/xen/xen_backend.h"
 #include "xen_domainbuild.h"
 #include "qemu/timer.h"
@@ -75,9 +76,9 @@ int xenstore_domain_init1(const char *kernel, const char 
*ramdisk,
 xenstore_write_str(dom, "vm", vm);
 
 /* memory */
-xenstore_write_int(dom, "memory/target", ram_size >> 10);  // kB
-xenstore_write_int(vm, "memory", ram_size >> 20);  // MB
-xenstore_write_int(vm, "maxmem", ram_size >> 20);  // MB
+xenstore_write_int(dom, "memory/target", ram_size / K_BYTE);
+xenstore_write_int(vm, "memory", ram_size / M_BYTE);
+xenstore_write_int(vm, "maxmem", ram_size / M_BYTE);
 
 /* cpus */
 for (i = 0; i < smp_cpus; i++) {
@@ -113,7 +114,7 @@ int xenstore_domain_init2(int xenstore_port, int 
xenstore_mfn,
 
 /* console */
 xenstore_write_str(dom, "console/type", "ioemu");
-xenstore_write_int(dom, "console/limit",128 * 1024);
+xenstore_write_int(dom, "console/limit",128 * K_BYTE);
 xenstore_write_int(dom, "console/ring-ref", console_mfn);
 xenstore_write_int(dom, "console/port", console_port);
 xen_config_dev_console(0);
@@ -260,7 +261,7 @@ int xen_domain_build_pv(const char *kernel, const char 
*ramdisk,
 }
 #endif
 
-rc = xc_domain_setmaxmem(xen_xc, xen_domid, ram_size >> 10);
+rc = xc_domain_setmaxmem(xen_xc, xen_domid, ram_size / K_BYTE);
 if (rc < 0) {
 fprintf(stderr, "xen: xc_domain_setmaxmem() failed\n");
 goto err;
@@ -269,7 +270,7 @@ int xen_domain_build_pv(const char *kernel, const char 
*ramdisk,
 xenstore_port = xc_evtchn_alloc_unbound(xen_xc, xen_domid, 0);
 console_port = xc_evtchn_alloc_unbound(xen_xc, xen_domid, 0);
 
-rc = xc_linux_build(xen_xc, xen_domid, ram_size >> 20,
+rc = xc_linux_build(xen_xc, xen_domid, ram_size / M_BYTE,
 kernel, ramdisk, cmdline,
 0, flags,
 xenstore_port, _mfn,
-- 
2.17.0




[Qemu-devel] [PATCH v3 35/41] hw/sd: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/sd/sd.c| 4 ++--
 hw/sd/sdhci.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 235e0518d6..3b2f925ae6 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -30,6 +30,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/qdev.h"
 #include "hw/hw.h"
 #include "hw/registerfields.h"
@@ -37,7 +38,6 @@
 #include "hw/sd/sd.h"
 #include "qapi/error.h"
 #include "qemu/bitmap.h"
-#include "qemu/cutils.h"
 #include "hw/qdev-properties.h"
 #include "qemu/error-report.h"
 #include "qemu/timer.h"
@@ -394,7 +394,7 @@ static void sd_set_csd(SDState *sd, uint64_t size)
 ((HWBLOCK_SHIFT << 6) & 0xc0);
 sd->csd[14] = 0x00;/* File format group */
 } else {   /* SDHC */
-size /= 512 * 1024;
+size /= 512 * K_BYTE;
 size -= 1;
 sd->csd[0] = 0x40;
 sd->csd[1] = 0x0e;
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 63c44a4ee8..55e2054148 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "hw/hw.h"
@@ -34,7 +35,6 @@
 #include "hw/sd/sdhci.h"
 #include "sdhci-internal.h"
 #include "qemu/log.h"
-#include "qemu/cutils.h"
 #include "trace.h"
 
 #define TYPE_SDHCI_BUS "sdhci-bus"
@@ -792,7 +792,7 @@ static void sdhci_do_adma(SDHCIState *s)
 return;
 }
 
-length = dscr.length ? dscr.length : 65536;
+length = dscr.length ? dscr.length : 64 * K_BYTE;
 
 switch (dscr.attr & SDHC_ADMA_ATTR_ACT_MASK) {
 case SDHC_ADMA_ATTR_ACT_TRAN:  /* data transfer */
-- 
2.17.0




[Qemu-devel] [PATCH v3 09/41] hw/scsi: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/scsi/scsi-disk.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index ded23d36ca..a67e7ffce5 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -29,6 +29,7 @@ do { printf("scsi-disk: " fmt , ## __VA_ARGS__); } while (0)
 #endif
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "hw/scsi/scsi.h"
@@ -44,13 +45,13 @@ do { printf("scsi-disk: " fmt , ## __VA_ARGS__); } while (0)
 #include 
 #endif
 
-#define SCSI_WRITE_SAME_MAX 524288
-#define SCSI_DMA_BUF_SIZE   131072
+#define SCSI_WRITE_SAME_MAX (512 * K_BYTE)
+#define SCSI_DMA_BUF_SIZE   (128 * K_BYTE)
 #define SCSI_MAX_INQUIRY_LEN256
 #define SCSI_MAX_MODE_LEN   256
 
-#define DEFAULT_DISCARD_GRANULARITY 4096
-#define DEFAULT_MAX_UNMAP_SIZE  (1 << 30)   /* 1 GB */
+#define DEFAULT_DISCARD_GRANULARITY (4 * K_BYTE)
+#define DEFAULT_MAX_UNMAP_SIZE  (1 * G_BYTE)
 #define DEFAULT_MAX_IO_SIZE INT_MAX /* 2 GB - 1 block */
 
 #define TYPE_SCSI_DISK_BASE "scsi-disk-base"
-- 
2.17.0




[Qemu-devel] [PATCH v3 16/41] hw/riscv: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

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

diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
index e2c214e86a..eb465a0158 100644
--- a/hw/riscv/virt.c
+++ b/hw/riscv/virt.c
@@ -19,6 +19,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/log.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
@@ -95,7 +96,7 @@ static hwaddr load_initrd(const char *filename, uint64_t 
mem_size,
  * halfway into RAM, and for boards with 256MB of RAM or more we put
  * the initrd at 128MB.
  */
-*start = kernel_entry + MIN(mem_size / 2, 128 * 1024 * 1024);
+*start = kernel_entry + MIN(mem_size / 2, 128 * M_BYTE);
 
 size = load_ramdisk(filename, *start, mem_size - *start);
 if (size == -1) {
-- 
2.17.0




[Qemu-devel] [PATCH v3 10/41] hw/smbios: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/smbios/smbios.c | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c
index 27a07e96f4..a72f35d9f5 100644
--- a/hw/smbios/smbios.c
+++ b/hw/smbios/smbios.c
@@ -16,6 +16,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu/config-file.h"
 #include "qemu/error-report.h"
@@ -625,10 +626,6 @@ static void smbios_build_type_11_table(void)
 SMBIOS_BUILD_TABLE_POST;
 }
 
-#define ONE_KB ((ram_addr_t)1 << 10)
-#define ONE_MB ((ram_addr_t)1 << 20)
-#define ONE_GB ((ram_addr_t)1 << 30)
-
 #define MAX_T16_STD_SZ 0x8000 /* 2T in Kilobytes */
 
 static void smbios_build_type_16_table(unsigned dimm_cnt)
@@ -640,7 +637,7 @@ static void smbios_build_type_16_table(unsigned dimm_cnt)
 t->location = 0x01; /* Other */
 t->use = 0x03; /* System memory */
 t->error_correction = 0x06; /* Multi-bit ECC (for Microsoft, per SeaBIOS) 
*/
-size_kb = QEMU_ALIGN_UP(ram_size, ONE_KB) / ONE_KB;
+size_kb = QEMU_ALIGN_UP(ram_size, K_BYTE) / K_BYTE;
 if (size_kb < MAX_T16_STD_SZ) {
 t->maximum_capacity = cpu_to_le32(size_kb);
 t->extended_maximum_capacity = cpu_to_le64(0);
@@ -668,7 +665,7 @@ static void smbios_build_type_17_table(unsigned instance, 
uint64_t size)
 t->memory_error_information_handle = cpu_to_le16(0xFFFE); /* Not provided 
*/
 t->total_width = cpu_to_le16(0x); /* Unknown */
 t->data_width = cpu_to_le16(0x); /* Unknown */
-size_mb = QEMU_ALIGN_UP(size, ONE_MB) / ONE_MB;
+size_mb = QEMU_ALIGN_UP(size, M_BYTE) / M_BYTE;
 if (size_mb < MAX_T17_STD_SZ) {
 t->size = cpu_to_le16(size_mb);
 t->extended_size = cpu_to_le32(0);
@@ -707,8 +704,8 @@ static void smbios_build_type_19_table(unsigned instance,
 
 end = start + size - 1;
 assert(end > start);
-start_kb = start / ONE_KB;
-end_kb = end / ONE_KB;
+start_kb = start / K_BYTE;
+end_kb = end / K_BYTE;
 if (start_kb < UINT32_MAX && end_kb < UINT32_MAX) {
 t->starting_address = cpu_to_le32(start_kb);
 t->ending_address = cpu_to_le32(end_kb);
@@ -869,7 +866,7 @@ void smbios_get_tables(const struct smbios_phys_mem_area 
*mem_array,
 
 smbios_build_type_11_table();
 
-#define MAX_DIMM_SZ (16ll * ONE_GB)
+#define MAX_DIMM_SZ (16 * G_BYTE)
 #define GET_DIMM_SZ ((i < dimm_cnt - 1) ? MAX_DIMM_SZ \
 : ((ram_size - 1) % MAX_DIMM_SZ) + 1)
 
-- 
2.17.0




[Qemu-devel] [PATCH v3 06/41] cutils: Extract byte-based definitions into a new header: "qemu/units.h"

2018-04-15 Thread Philippe Mathieu-Daudé
(added in 076b35b5a56)

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Marc-André Lureau 
Reviewed-by: Daniel P. Berrangé 
---
 include/qemu/cutils.h |  8 +---
 include/qemu/units.h  | 11 +++
 2 files changed, 12 insertions(+), 7 deletions(-)
 create mode 100644 include/qemu/units.h

diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index a663340b23..056e6629bb 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -2,6 +2,7 @@
 #define QEMU_CUTILS_H
 
 #include "qemu/fprintf-fn.h"
+#include "qemu/units.h"
 
 /**
  * pstrcpy:
@@ -147,13 +148,6 @@ int qemu_strtosz(const char *nptr, char **end, uint64_t 
*result);
 int qemu_strtosz_MiB(const char *nptr, char **end, uint64_t *result);
 int qemu_strtosz_metric(const char *nptr, char **end, uint64_t *result);
 
-#define K_BYTE (1ULL << 10)
-#define M_BYTE (1ULL << 20)
-#define G_BYTE (1ULL << 30)
-#define T_BYTE (1ULL << 40)
-#define P_BYTE (1ULL << 50)
-#define E_BYTE (1ULL << 60)
-
 /* used to print char* safely */
 #define STR_OR_NULL(str) ((str) ? (str) : "null")
 
diff --git a/include/qemu/units.h b/include/qemu/units.h
new file mode 100644
index 00..81f5cc6f7f
--- /dev/null
+++ b/include/qemu/units.h
@@ -0,0 +1,11 @@
+#ifndef QEMU_UNITS_H
+#define QEMU_UNITS_H
+
+#define K_BYTE (1ULL << 10)
+#define M_BYTE (1ULL << 20)
+#define G_BYTE (1ULL << 30)
+#define T_BYTE (1ULL << 40)
+#define P_BYTE (1ULL << 50)
+#define E_BYTE (1ULL << 60)
+
+#endif
-- 
2.17.0




[Qemu-devel] [PATCH v3 33/41] hw/net: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/net/allwinner_emac.h | 5 +++--
 hw/net/e1000e.c | 7 ---
 hw/net/e1000x_common.c  | 3 ++-
 hw/net/eepro100.c   | 7 +++
 4 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/include/hw/net/allwinner_emac.h b/include/hw/net/allwinner_emac.h
index 4cc8aab7ec..4b53b6485c 100644
--- a/include/hw/net/allwinner_emac.h
+++ b/include/hw/net/allwinner_emac.h
@@ -23,6 +23,7 @@
 #ifndef ALLWINNER_EMAC_H
 #define ALLWINNER_EMAC_H
 
+#include "qemu/units.h"
 #include "net/net.h"
 #include "qemu/fifo8.h"
 #include "hw/net/mii.h"
@@ -125,8 +126,8 @@
 #define EMAC_INT_RX (1 << 8)
 
 /* Due to lack of specifications, size of fifos is chosen arbitrarily */
-#define TX_FIFO_SIZE(4 * 1024)
-#define RX_FIFO_SIZE(32 * 1024)
+#define TX_FIFO_SIZE(4 * K_BYTE)
+#define RX_FIFO_SIZE(32 * K_BYTE)
 
 #define NUM_TX_FIFOS2
 #define RX_HDR_SIZE 8
diff --git a/hw/net/e1000e.c b/hw/net/e1000e.c
index 16a9417a85..101efe7c83 100644
--- a/hw/net/e1000e.c
+++ b/hw/net/e1000e.c
@@ -34,6 +34,7 @@
 */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "net/net.h"
 #include "net/tap.h"
 #include "qemu/range.h"
@@ -81,10 +82,10 @@ typedef struct E1000EState {
 #define E1000E_IO_IDX   2
 #define E1000E_MSIX_IDX 3
 
-#define E1000E_MMIO_SIZE(128 * 1024)
-#define E1000E_FLASH_SIZE   (128 * 1024)
+#define E1000E_MMIO_SIZE(128 * K_BYTE)
+#define E1000E_FLASH_SIZE   (128 * K_BYTE)
 #define E1000E_IO_SIZE  (32)
-#define E1000E_MSIX_SIZE(16 * 1024)
+#define E1000E_MSIX_SIZE(16 * K_BYTE)
 
 #define E1000E_MSIX_TABLE   (0x)
 #define E1000E_MSIX_PBA (0x2000)
diff --git a/hw/net/e1000x_common.c b/hw/net/e1000x_common.c
index eb0e097137..58c8db77e9 100644
--- a/hw/net/e1000x_common.c
+++ b/hw/net/e1000x_common.c
@@ -23,6 +23,7 @@
 */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
 #include "net/net.h"
@@ -111,7 +112,7 @@ bool e1000x_is_oversized(uint32_t *mac, size_t size)
 static const int maximum_ethernet_vlan_size = 1522;
 /* this is the size past which hardware will
drop packets when setting LPE=1 */
-static const int maximum_ethernet_lpe_size = 16384;
+static const int maximum_ethernet_lpe_size = 16 * K_BYTE;
 
 if ((size > maximum_ethernet_lpe_size ||
 (size > maximum_ethernet_vlan_size
diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c
index a07a63247e..a02e2b55e8 100644
--- a/hw/net/eepro100.c
+++ b/hw/net/eepro100.c
@@ -41,6 +41,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/hw.h"
 #include "hw/pci/pci.h"
 #include "net/net.h"
@@ -60,8 +61,6 @@
  * changed to pad short packets itself. */
 #define CONFIG_PAD_RECEIVED_FRAMES
 
-#define KiB 1024
-
 /* Debug EEPRO100 card. */
 #if 0
 # define DEBUG_EEPRO100
@@ -104,9 +103,9 @@
 /* Use 64 word EEPROM. TODO: could be a runtime option. */
 #define EEPROM_SIZE 64
 
-#define PCI_MEM_SIZE(4 * KiB)
+#define PCI_MEM_SIZE(4 * K_BYTE)
 #define PCI_IO_SIZE 64
-#define PCI_FLASH_SIZE  (128 * KiB)
+#define PCI_FLASH_SIZE  (128 * K_BYTE)
 
 #define BITS(n, m) (((0xU << (31 - n)) >> (31 - n + m)) << m)
 
-- 
2.17.0




[Qemu-devel] [PATCH v3 15/41] hw/misc: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/misc/auxbus.c | 3 ++-
 hw/misc/edu.c| 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/misc/auxbus.c b/hw/misc/auxbus.c
index b4cacd664b..0252c72654 100644
--- a/hw/misc/auxbus.c
+++ b/hw/misc/auxbus.c
@@ -27,6 +27,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/log.h"
 #include "hw/misc/auxbus.h"
 #include "hw/i2c/i2c.h"
@@ -68,7 +69,7 @@ AUXBus *aux_init_bus(DeviceState *parent, const char *name)
 
 /* Memory related. */
 bus->aux_io = g_malloc(sizeof(*bus->aux_io));
-memory_region_init(bus->aux_io, OBJECT(bus), "aux-io", (1 << 20));
+memory_region_init(bus->aux_io, OBJECT(bus), "aux-io", 1 * M_BYTE);
 address_space_init(>aux_addr_space, bus->aux_io, "aux-io");
 return bus;
 }
diff --git a/hw/misc/edu.c b/hw/misc/edu.c
index 34eb05d213..ceaa2e1679 100644
--- a/hw/misc/edu.c
+++ b/hw/misc/edu.c
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/msi.h"
 #include "qemu/timer.h"
@@ -357,7 +358,7 @@ static void pci_edu_realize(PCIDevice *pdev, Error **errp)
edu, QEMU_THREAD_JOINABLE);
 
 memory_region_init_io(>mmio, OBJECT(edu), _mmio_ops, edu,
-"edu-mmio", 1 << 20);
+"edu-mmio", 1 * M_BYTE);
 pci_register_bar(pdev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, >mmio);
 }
 
-- 
2.17.0




[Qemu-devel] [PATCH v3 07/41] hw/ivshmem: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Marc-André Lureau 
---
 hw/misc/ivshmem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index 16f03701b7..2f4715abad 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -17,6 +17,7 @@
  * GNU GPL, version 2 or (at your option) any later version.
  */
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu/cutils.h"
 #include "hw/hw.h"
@@ -1302,7 +1303,7 @@ static void ivshmem_realize(PCIDevice *dev, Error **errp)
 }
 
 if (s->sizearg == NULL) {
-s->legacy_size = 4 << 20; /* 4 MB default */
+s->legacy_size = 4 * M_BYTE; /* 4 MB default */
 } else {
 int ret;
 uint64_t size;
-- 
2.17.0




[Qemu-devel] [PATCH v3 03/41] hw/block/nvme: Include the "qemu/cutils.h" in the source file

2018-04-15 Thread Philippe Mathieu-Daudé
where it is used.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Thomas Huth 
---
 hw/block/nvme.h | 1 -
 hw/block/nvme.c | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/block/nvme.h b/hw/block/nvme.h
index 8f3981121d..cabcf20c32 100644
--- a/hw/block/nvme.h
+++ b/hw/block/nvme.h
@@ -1,6 +1,5 @@
 #ifndef HW_NVME_H
 #define HW_NVME_H
-#include "qemu/cutils.h"
 #include "block/nvme.h"
 
 typedef struct NvmeAsyncEvent {
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 85d2406400..811084b6a7 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -35,6 +35,7 @@
 #include "sysemu/block-backend.h"
 
 #include "qemu/log.h"
+#include "qemu/cutils.h"
 #include "trace.h"
 #include "nvme.h"
 
-- 
2.17.0




[Qemu-devel] [PATCH v3 18/41] hw/sparc: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/sparc/leon3.c | 9 +
 hw/sparc/sun4m.c | 9 -
 hw/sparc64/niagara.c | 3 ++-
 hw/sparc64/sun4u.c   | 4 ++--
 4 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
index bba3aa3dee..97e13fab6d 100644
--- a/hw/sparc/leon3.c
+++ b/hw/sparc/leon3.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
@@ -139,9 +140,9 @@ static void leon3_generic_hw_init(MachineState *machine)
 env->qemu_irq_ack = leon3_irq_manager;
 
 /* Allocate RAM */
-if ((uint64_t)ram_size > (1UL << 30)) {
-error_report("Too much memory for this machine: %d, maximum 1G",
- (unsigned int)(ram_size / (1024 * 1024)));
+if (ram_size > 1 * G_BYTE) {
+error_report("Too much memory for this machine: %lluMB, maximum 1G",
+ ram_size / M_BYTE);
 exit(1);
 }
 
@@ -149,7 +150,7 @@ static void leon3_generic_hw_init(MachineState *machine)
 memory_region_add_subregion(address_space_mem, 0x4000, ram);
 
 /* Allocate BIOS */
-prom_size = 8 * 1024 * 1024; /* 8Mb */
+prom_size = 8 * M_BYTE;
 memory_region_init_ram(prom, NULL, "Leon3.bios", prom_size, _fatal);
 memory_region_set_readonly(prom, true);
 memory_region_add_subregion(address_space_mem, 0x, prom);
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index 6471aca25d..320122f1b5 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
 #include "cpu.h"
@@ -45,7 +46,6 @@
 #include "hw/loader.h"
 #include "elf.h"
 #include "trace.h"
-#include "qemu/cutils.h"
 
 /*
  * Sun4m architecture was used in the following machines:
@@ -66,7 +66,7 @@
 #define KERNEL_LOAD_ADDR 0x4000
 #define CMDLINE_ADDR 0x007ff000
 #define INITRD_LOAD_ADDR 0x0080
-#define PROM_SIZE_MAX(1024 * 1024)
+#define PROM_SIZE_MAX(1 * M_BYTE)
 #define PROM_VADDR   0xffd0
 #define PROM_FILENAME"openbios-sparc32"
 #define CFG_ADDR 0xd0510ULL
@@ -741,9 +741,8 @@ static void ram_init(hwaddr addr, ram_addr_t RAM_size,
 
 /* allocate RAM */
 if ((uint64_t)RAM_size > max_mem) {
-error_report("Too much memory for this machine: %d, maximum %d",
- (unsigned int)(RAM_size / (1024 * 1024)),
- (unsigned int)(max_mem / (1024 * 1024)));
+error_report("Too much memory for this machine: %llu, maximum %llu",
+ RAM_size / M_BYTE, max_mem / M_BYTE);
 exit(1);
 }
 dev = qdev_create(NULL, "memory");
diff --git a/hw/sparc64/niagara.c b/hw/sparc64/niagara.c
index 1874477ef6..957d98ef83 100644
--- a/hw/sparc64/niagara.c
+++ b/hw/sparc64/niagara.c
@@ -23,6 +23,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu-common.h"
 #include "cpu.h"
 #include "hw/hw.h"
@@ -84,7 +85,7 @@ typedef struct NiagaraBoardState {
 #define NIAGARA_PROM_BASE   0xfff000ULL
 #define NIAGARA_Q_OFFSET0x1ULL
 #define NIAGARA_OBP_OFFSET  0x8ULL
-#define PROM_SIZE_MAX   (4 * 1024 * 1024)
+#define PROM_SIZE_MAX   (4 * M_BYTE)
 
 static void add_rom_or_fail(const char *file, const hwaddr addr)
 {
diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c
index 2044a52ded..f424f362ac 100644
--- a/hw/sparc64/sun4u.c
+++ b/hw/sparc64/sun4u.c
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "qemu-common.h"
@@ -52,11 +53,10 @@
 #include "hw/loader.h"
 #include "elf.h"
 #include "trace.h"
-#include "qemu/cutils.h"
 
 #define KERNEL_LOAD_ADDR 0x00404000
 #define CMDLINE_ADDR 0x003ff000
-#define PROM_SIZE_MAX(4 * 1024 * 1024)
+#define PROM_SIZE_MAX(4 * M_BYTE)
 #define PROM_VADDR   0x000ffd0ULL
 #define PBM_SPECIAL_BASE 0x1feULL
 #define PBM_MEM_BASE 0x1ffULL
-- 
2.17.0




[Qemu-devel] [PATCH v3 08/41] hw/ipack: Use the BYTE-based definitions

2018-04-15 Thread Philippe Mathieu-Daudé
It eases code review, unit is explicit.

Patch generated using:

  $ git grep -E '(1024|2048|4096|8192|(<<|>>).?(10|20|30))' hw/ include/hw/

and modified manually.

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Alberto Garcia 
---
 hw/ipack/tpci200.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/ipack/tpci200.c b/hw/ipack/tpci200.c
index da05c8589d..8451bf8ad3 100644
--- a/hw/ipack/tpci200.c
+++ b/hw/ipack/tpci200.c
@@ -9,6 +9,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/units.h"
 #include "hw/ipack/ipack.h"
 #include "hw/pci/pci.h"
 #include "qemu/bitops.h"
@@ -597,9 +598,9 @@ static void tpci200_realize(PCIDevice *pci_dev, Error 
**errp)
 memory_region_init_io(>las1, OBJECT(s), _las1_ops,
   s, "tpci200_las1", 1024);
 memory_region_init_io(>las2, OBJECT(s), _las2_ops,
-  s, "tpci200_las2", 1024*1024*32);
+  s, "tpci200_las2", 32 * M_BYTE);
 memory_region_init_io(>las3, OBJECT(s), _las3_ops,
-  s, "tpci200_las3", 1024*1024*16);
+  s, "tpci200_las3", 16 * M_BYTE);
 pci_register_bar(>dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, >mmio);
 pci_register_bar(>dev, 1, PCI_BASE_ADDRESS_SPACE_IO, >io);
 pci_register_bar(>dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, >las0);
-- 
2.17.0




[Qemu-devel] [PATCH v3 04/41] hw/misc/mips_itu: Sort includes

2018-04-15 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/misc/mips_itu.h | 2 ++
 hw/misc/mips_itu.c | 5 +
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/include/hw/misc/mips_itu.h b/include/hw/misc/mips_itu.h
index b3a4532036..030eb4ac62 100644
--- a/include/hw/misc/mips_itu.h
+++ b/include/hw/misc/mips_itu.h
@@ -20,6 +20,8 @@
 #ifndef MIPS_ITU_H
 #define MIPS_ITU_H
 
+#include "hw/sysbus.h"
+
 #define TYPE_MIPS_ITU "mips-itu"
 #define MIPS_ITU(obj) OBJECT_CHECK(MIPSITUState, (obj), TYPE_MIPS_ITU)
 
diff --git a/hw/misc/mips_itu.c b/hw/misc/mips_itu.c
index c84a48bbb7..ccc4c7d98a 100644
--- a/hw/misc/mips_itu.c
+++ b/hw/misc/mips_itu.c
@@ -18,13 +18,10 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/log.h"
 #include "qapi/error.h"
 #include "cpu.h"
-#include "qemu/log.h"
 #include "exec/exec-all.h"
-#include "hw/hw.h"
-#include "hw/sysbus.h"
-#include "sysemu/sysemu.h"
 #include "hw/misc/mips_itu.h"
 
 #define ITC_TAG_ADDRSPACE_SZ (ITC_ADDRESSMAP_NUM * 8)
-- 
2.17.0




[Qemu-devel] [PATCH v3 01/41] hw: Clean "hw/devices.h" includes

2018-04-15 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 include/hw/devices.h | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/include/hw/devices.h b/include/hw/devices.h
index 861ddea8af..0e27feb0c2 100644
--- a/include/hw/devices.h
+++ b/include/hw/devices.h
@@ -1,13 +1,10 @@
 #ifndef QEMU_DEVICES_H
 #define QEMU_DEVICES_H
 
-#include "hw/irq.h"
-
-/* ??? Not all users of this file can include cpu-common.h.  */
-struct MemoryRegion;
-
 /* Devices that have nowhere better to go.  */
 
+#include "hw/hw.h"
+
 /* smc91c111.c */
 void smc91c111_init(NICInfo *, uint32_t, qemu_irq);
 
-- 
2.17.0




[Qemu-devel] [PATCH v3 02/41] hw: Do not include "sysemu/block-backend.h" if it is not necessary

2018-04-15 Thread Philippe Mathieu-Daudé
Remove those unneeded includes to speed up the compilation
process a little bit. (Missed in 7eceff5b5a1fa)

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/cris/axis_dev88.c | 1 -
 hw/sh4/r2d.c | 1 -
 2 files changed, 2 deletions(-)

diff --git a/hw/cris/axis_dev88.c b/hw/cris/axis_dev88.c
index 9ccc4350a5..1775e53e25 100644
--- a/hw/cris/axis_dev88.c
+++ b/hw/cris/axis_dev88.c
@@ -34,7 +34,6 @@
 #include "hw/loader.h"
 #include "elf.h"
 #include "boot.h"
-#include "sysemu/block-backend.h"
 #include "exec/address-spaces.h"
 #include "sysemu/qtest.h"
 #include "sysemu/sysemu.h"
diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c
index 458ed83297..f5f3deab37 100644
--- a/hw/sh4/r2d.c
+++ b/hw/sh4/r2d.c
@@ -40,7 +40,6 @@
 #include "hw/loader.h"
 #include "hw/usb.h"
 #include "hw/block/flash.h"
-#include "sysemu/block-backend.h"
 #include "exec/address-spaces.h"
 
 #define FLASH_BASE 0x
-- 
2.17.0




[Qemu-devel] [PATCH v3 05/41] hw/mips/r4k: Constify params_size

2018-04-15 Thread Philippe Mathieu-Daudé
Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/mips/mips_r4k.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c
index aeadc4a340..c26a44da06 100644
--- a/hw/mips/mips_r4k.c
+++ b/hw/mips/mips_r4k.c
@@ -80,8 +80,9 @@ typedef struct ResetData {
 
 static int64_t load_kernel(void)
 {
+const size_t params_size = 264;
 int64_t entry, kernel_high;
-long kernel_size, initrd_size, params_size;
+long kernel_size, initrd_size;
 ram_addr_t initrd_offset;
 uint32_t *params_buf;
 int big_endian;
@@ -129,7 +130,6 @@ static int64_t load_kernel(void)
 }
 
 /* Store command line.  */
-params_size = 264;
 params_buf = g_malloc(params_size);
 
 params_buf[0] = tswap32(ram_size);
@@ -144,7 +144,7 @@ static int64_t load_kernel(void)
 }
 
 rom_add_blob_fixed("params", params_buf, params_size,
-   (16 << 20) - 264);
+   (16 << 20) - params_size);
 
 g_free(params_buf);
 return entry;
-- 
2.17.0




[Qemu-devel] [PATCH v3 00/41] hw: Use the BYTE-based definitions when useful

2018-04-15 Thread Philippe Mathieu-Daudé
Hi,

This series:

- split the byte-based definitions from "qemu/cutils.h" to "qemu/units.h"
- clean hw/ includes;
- replace different constants used for byte size with their corresponding
  BYTE-based definitions.

Since v2:
- use "qemu/units.h" instead of "qemu/cunits.h" (Daniel P. Berrangé)
- avoid rebuilding the world including "qemu/units.h" in "hw/hw.h" (Thomas Huth)
- more constant replaced

Since v1:
- corrected Xen mult -> div (Alan Robinson)
- tagged 'include "qemu/cunits.h" in "hw/hw.h" as RFC
- fixed mips_r4k 'params_size' (Thomas Huth)
- added command used to generate patch in each commit (Alistair Francis)
- use G_BYTE for the raspi3 machine
- added Reviewed-by tags

Regards,

Phil.

$ git backport-diff -r master.. -u v2
001/41:[down] 'hw: Clean "hw/devices.h" includes'
002/41:[down] 'hw: Do not include "sysemu/block-backend.h" if it is not 
necessary'
003/41:[] [--] 'hw/block/nvme: include the "qemu/cutils.h" in the source 
file'
004/41:[down] 'hw/misc/mips_itu: sort includes'
005/41:[] [--] 'hw/mips/r4k: constify params_size'
006/41:[down] 'cutils: extract byte-based definitions into a new header: 
"qemu/units.h"'
007/41:[down] 'hw/ivshmem: use the BYTE-based definitions'
008/41:[0001] [FC] 'hw/ipack: use the BYTE-based definitions'
009/41:[0001] [FC] 'hw/scsi: use the BYTE-based definitions'
010/41:[0001] [FC] 'hw/smbios: use the BYTE-based definitions'
011/41:[down] 'hw/xen: use the BYTE-based definitions'
012/41:[down] 'hw/tpm: use the BYTE-based definitions'
013/41:[down] 'hw/block: use the BYTE-based definitions'
014/41:[0015] [FC] 'hw/display: use the BYTE-based definitions'
015/41:[0004] [FC] 'hw/misc: use the BYTE-based definitions'
016/41:[down] 'hw/riscv: use the BYTE-based definitions'
017/41:[down] 'hw/m68k: use the BYTE-based definitions'
018/41:[0006] [FC] 'hw/sparc: use the BYTE-based definitions'
019/41:[0007] [FC] 'hw/s390x: use the BYTE-based definitions'
020/41:[0003] [FC] 'hw/hppa: use the BYTE-based definitions'
021/41:[0003] [FC] 'hw/xtensa: use the BYTE-based definitions'
022/41:[0001] [FC] 'hw/alpha: use the BYTE-based definitions'
023/41:[0001] [FC] 'hw/tricore: use the BYTE-based definitions'
024/41:[0002] [FC] 'hw/microblaze: use the BYTE-based definitions'
025/41:[0004] [FC] 'hw/nios2: use the BYTE-based definitions'
026/41:[0001] [FC] 'hw/cris: use the BYTE-based definitions'
027/41:[0003] [FC] 'hw/lm32: use the BYTE-based definitions'
028/41:[0003] [FC] 'hw/sh4: use the BYTE-based definitions'
029/41:[0012] [FC] 'hw/mips: use the BYTE-based definitions'
030/41:[0052] [FC] 'hw/arm: use the BYTE-based definitions'
031/41:[0065] [FC] 'hw/ppc: use the BYTE-based definitions'
032/41:[0014] [FC] 'hw/i386: use the BYTE-based definitions'
033/41:[0006] [FC] 'hw/net: use the BYTE-based definitions'
034/41:[down] 'hw/usb: use the BYTE-based definitions'
035/41:[down] 'hw/sd: use the BYTE-based definitions'
036/41:[down] 'hw/vfio: use the BYTE-based definitions'
037/41:[down] 'hw/virtio: use the BYTE-based definitions'
038/41:[down] 'hw/rdma: use the BYTE-based definitions'
039/41:[down] 'hw/nvdimm: use the BYTE-based definitions'
040/41:[down] 'hw/loader: use the BYTE-based definitions'
041/41:[down] 'cutils: do not include "units.h" directly'

Philippe Mathieu-Daudé (41):
  hw: Clean "hw/devices.h" includes
  hw: Do not include "sysemu/block-backend.h" if it is not necessary
  hw/block/nvme: include the "qemu/cutils.h" in the source file
  hw/misc/mips_itu: sort includes
  hw/mips/r4k: constify params_size
  cutils: extract byte-based definitions into a new header: "qemu/units.h"
  hw/ivshmem: use the BYTE-based definitions
  hw/ipack: use the BYTE-based definitions
  hw/scsi: use the BYTE-based definitions
  hw/smbios: use the BYTE-based definitions
  hw/xen: use the BYTE-based definitions
  hw/tpm: use the BYTE-based definitions
  hw/block: use the BYTE-based definitions
  hw/display: use the BYTE-based definitions
  hw/misc: use the BYTE-based definitions
  hw/riscv: use the BYTE-based definitions
  hw/m68k: use the BYTE-based definitions
  hw/sparc: use the BYTE-based definitions
  hw/s390x: use the BYTE-based definitions
  hw/hppa: use the BYTE-based definitions
  hw/xtensa: use the BYTE-based definitions
  hw/alpha: use the BYTE-based definitions
  hw/tricore: use the BYTE-based definitions
  hw/microblaze: use the BYTE-based definitions
  hw/nios2: use the BYTE-based definitions
  hw/cris: use the BYTE-based definitions
  hw/lm32: use the BYTE-based definitions
  hw/sh4: use the BYTE-based definitions
  hw/mips: use the BYTE-based definitions
  hw/arm: use the BYTE-based definitions
  hw/ppc: use the BYTE-based definitions
  hw/i386: use the BYTE-based definitions
  hw/net: use the BYTE-based definitions
  hw/usb: use the BYTE-based definitions
  hw/sd: use the BYTE-based definitions
  hw/vfio: use the BYTE-based definitions
  hw/virtio: use the BYTE-based definitions
  hw/rdma: use the BYTE-based definitions
  hw/nvdimm: use the BYTE-based definitions
  

[Qemu-devel] [PATCH 4/4] build: Silence dtc directory creation

2018-04-15 Thread Philippe Mathieu-Daudé
From: Jan Kiszka 

Align with other mkdir calls.

Signed-off-by: Jan Kiszka 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <0dd4c8f5-d60e-e564-652f-cd0101f6e...@web.de>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 727ef118f3..fc6f21001f 100644
--- a/Makefile
+++ b/Makefile
@@ -485,7 +485,7 @@ subdir-dtc: .git-submodule-status dtc/libfdt dtc/tests
$(call quiet-command,$(MAKE) $(DTC_MAKE_ARGS) 
CPPFLAGS="$(DTC_CPPFLAGS)" CFLAGS="$(DTC_CFLAGS)" LDFLAGS="$(LDFLAGS)" 
ARFLAGS="$(ARFLAGS)" CC="$(CC)" AR="$(AR)" LD="$(LD)" $(SUBDIR_MAKEFLAGS) 
libfdt/libfdt.a,)
 
 dtc/%: .git-submodule-status
-   mkdir -p $@
+   @mkdir -p $@
 
 # Overriding CFLAGS causes us to lose defines added in the sub-makefile.
 # Not overriding CFLAGS leads to mis-matches between compilation modes.
-- 
2.17.0




[Qemu-devel] [PATCH 3/4] shippable: Remove Debian 8 libfdt kludge

2018-04-15 Thread Philippe Mathieu-Daudé
This kludge was added in a825ca06137, but a cleaner and more generic
fix is now available (see ##COMMIT_CONFIGURE_LIBFDT_LDFLAGS_SHA##).

Signed-off-by: Philippe Mathieu-Daudé 
---
If a maintainer take the whole series, I hope he'll be kind enough to update
##COMMIT_CONFIGURE_LIBFDT_LDFLAGS_SHA## with the sha of the patch #1 :) Thanks!

 .shippable.yml | 8 
 1 file changed, 8 deletions(-)

diff --git a/.shippable.yml b/.shippable.yml
index 60f2ce9218..f74a3de3ff 100644
--- a/.shippable.yml
+++ b/.shippable.yml
@@ -35,13 +35,5 @@ build:
 options: "-e HOME=/root"
   ci:
 - unset CC
-# some targets require newer up to date packages, for example TARGET_LIST 
matching
-# 
aarch64*-softmmu|arm*-softmmu|ppc*-softmmu|microblaze*-softmmu|mips64el-softmmu)
-# see the configure script:
-#error_exit "DTC (libfdt) version >= 1.4.2 not present. Your options:"
-#"  (1) Preferred: Install the DTC (libfdt) devel package"
-#"  (2) Fetch the DTC submodule, using:"
-#"  git submodule update --init dtc"
-- dpkg --compare-versions `dpkg-query --showformat='${Version}' --show 
libfdt-dev` ge 1.4.2 || git submodule update --init dtc
 - ./configure ${QEMU_CONFIGURE_OPTS} --target-list=${TARGET_LIST}
 - make -j$(($(getconf _NPROCESSORS_ONLN) + 1))
-- 
2.17.0




[Qemu-devel] [PATCH 2/4] configure: Display if libfdt is from system or git

2018-04-15 Thread Philippe Mathieu-Daudé
The configure script outputs "yes" regardless which libfdt is used:

  ./configure
  [...]
  fdt support   yes

Sometimes you can have both system and local git version available,
change the configure script to display which library got selected:

  debian8$ dpkg-query --showformat='${Version}\n' --show libfdt-dev
  1.4.0+dfsg-1

  debian8$ ./configure
  [...]
  fdt support   git

Signed-off-by: Philippe Mathieu-Daudé 
---
 configure | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/configure b/configure
index 162e804b49..056b391f22 100755
--- a/configure
+++ b/configure
@@ -3758,15 +3758,14 @@ int main(void) { fdt_first_subnode(0, 0); return 0; }
 EOF
   if compile_prog "" "$fdt_libs" ; then
 # system DTC is good - use it
-fdt=yes
+fdt=system
   else
   # have GIT checkout, so activate dtc submodule
   if test -e "${source_path}/.git" ; then
   git_submodules="${git_submodules} dtc"
   fi
   if test -d "${source_path}/dtc/libfdt" || test -e "${source_path}/.git" 
; then
-  fdt=yes
-  dtc_internal="yes"
+  fdt=git
   mkdir -p dtc
   if [ "$pwd_is_source_path" != "y" ] ; then
   symlink "$source_path/dtc/Makefile" "dtc/Makefile"
@@ -6307,7 +6306,7 @@ fi
 if test "$preadv" = "yes" ; then
   echo "CONFIG_PREADV=y" >> $config_host_mak
 fi
-if test "$fdt" = "yes" ; then
+if test "$fdt" != "no" ; then
   echo "CONFIG_FDT=y" >> $config_host_mak
 fi
 if test "$membarrier" = "yes" ; then
@@ -7109,7 +7108,7 @@ echo "QEMU_CFLAGS+=$cflags" >> $config_target_mak
 
 done # for target in $targets
 
-if [ "$dtc_internal" = "yes" ]; then
+if [ "$fdt" = "git" ]; then
   echo "config-host.h: subdir-dtc" >> $config_host_mak
 fi
 if [ "$capstone" = "git" -o "$capstone" = "internal" ]; then
-- 
2.17.0




[Qemu-devel] [PATCH for-2.12? 1/4] configure: Really use local libfdt if the system one is too old

2018-04-15 Thread Philippe Mathieu-Daudé
QEMU requires libfdt version >= 1.4.2.
If the host has an older libfdt installed, the configure script will use
a (git cloned) local version.

Example with Debian 8:
$ dpkg-query --showformat='${Version}\n' --show libfdt-dev
1.4.0+dfsg-1
$ ./configure
[...]
fdt support   yes  # from git submodule 'dtc'

If this case occurs, the linker will have 2 different libfdt available in
the library search path. The default behavior is to search the system path
first, then the local path.

Even if the configure script noticed the libfdt is too old and clone a more
recent locally, when linking the system library is selected first, and the
link process eventually fails:

  LINKmips64el-softmmu/qemu-system-mips64el
../hw/core/loader-fit.o: In function `load_fit':
/root/src/github.com/philmd/qemu/hw/core/loader-fit.c:278: undefined 
reference to `fdt_first_subnode'
/root/src/github.com/philmd/qemu/hw/core/loader-fit.c:286: undefined 
reference to `fdt_next_subnode'
/root/src/github.com/philmd/qemu/hw/core/loader-fit.c:277: undefined 
reference to `fdt_first_subnode'
collect2: error: ld returned 1 exit status
Makefile:201: recipe for target 'qemu-system-mips64el' failed
make[1]: *** [qemu-system-mips64el] Error 1

QEMU already uses a kludge to enforce local CFLAGS before system ones for
libpixman and libfdt, add a similar kludge for the LDFLAGS to enforce using
the local libfdt.

Signed-off-by: Philippe Mathieu-Daudé 
---
 configure | 6 +-
 rules.mak | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 0a19b033bc..162e804b49 100755
--- a/configure
+++ b/configure
@@ -3773,7 +3773,8 @@ EOF
   symlink "$source_path/dtc/scripts" "dtc/scripts"
   fi
   fdt_cflags="-I\$(SRC_PATH)/dtc/libfdt"
-  fdt_libs="-L\$(BUILD_DIR)/dtc/libfdt $fdt_libs"
+  fdt_ldflags="-L\$(BUILD_DIR)/dtc/libfdt"
+  fdt_libs="$fdt_libs"
   elif test "$fdt" = "yes" ; then
   # Not a git build & no libfdt found, prompt for system install
   error_exit "DTC (libfdt) version >= 1.4.2 not present." \
@@ -5715,6 +5716,7 @@ echo_version() {
 
 # prepend pixman and ftd flags after all config tests are done
 QEMU_CFLAGS="$pixman_cflags $fdt_cflags $QEMU_CFLAGS"
+QEMU_LDFLAGS="$fdt_ldflags $QEMU_LDFLAGS"
 libs_softmmu="$pixman_libs $libs_softmmu"
 
 echo "Install prefix$prefix"
@@ -5745,6 +5747,7 @@ echo "ARFLAGS   $ARFLAGS"
 echo "CFLAGS$CFLAGS"
 echo "QEMU_CFLAGS   $QEMU_CFLAGS"
 echo "LDFLAGS   $LDFLAGS"
+echo "QEMU_LDFLAGS  $QEMU_LDFLAGS"
 echo "make  $make"
 echo "install   $install"
 echo "python$python"
@@ -6679,6 +6682,7 @@ else
 fi
 echo "LDFLAGS=$LDFLAGS" >> $config_host_mak
 echo "LDFLAGS_NOPIE=$LDFLAGS_NOPIE" >> $config_host_mak
+echo "QEMU_LDFLAGS=$QEMU_LDFLAGS" >> $config_host_mak
 echo "LD_REL_FLAGS=$LD_REL_FLAGS" >> $config_host_mak
 echo "LD_I386_EMULATION=$ld_i386_emulation" >> $config_host_mak
 echo "LIBS+=$LIBS" >> $config_host_mak
diff --git a/rules.mak b/rules.mak
index 93a07027b0..04c7f74d07 100644
--- a/rules.mak
+++ b/rules.mak
@@ -73,7 +73,7 @@ expand-objs = $(strip $(sort $(filter %.o,$1)) \
 # must link with the C++ compiler, not the plain C compiler.
 LINKPROG = $(or $(CXX),$(CC))
 
-LINK = $(call quiet-command, $(LINKPROG) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) 
-o $@ \
+LINK = $(call quiet-command, $(LINKPROG) $(QEMU_LDFLAGS) $(QEMU_CFLAGS) 
$(CFLAGS) $(LDFLAGS) -o $@ \
$(call process-archive-undefs, $1) \
$(version-obj-y) $(call extract-libs,$1) 
$(LIBS),"LINK","$(TARGET_DIR)$@")
 
-- 
2.17.0




[Qemu-devel] [PATCH 0/4] build: fix failure when host provides too old libfdt

2018-04-15 Thread Philippe Mathieu-Daudé
Hi, I already hit this problem on Shippable and tried to resolve it for 2.10;
and shamefully hit it again yesterday on a Debian 8 host with distrib libfdt
installed. I wondered how to fix this without root access and realized my
previous Shippable kludge wasn't the best fix :)

Here we go adding the QEMU_LDFLAGS to enforce local libfdt in library path
before the system one.
This time it looks like the correct fix, also scalable for other libraries.

It would be great to have QEMU 2.12 buildable in Debian<9, but nobody
complained since 2.10 so this can wait 2.13 (this is not a regression neither).

Regards,

Phil.

Jan Kiszka (1):
  build: Silence dtc directory creation

Philippe Mathieu-Daudé (3):
  configure: Really use local libfdt if the system one is too old
  configure: Display if libfdt is from system or git
  shippable: Remove Debian 8 libfdt kludge

 configure  | 15 +--
 Makefile   |  2 +-
 rules.mak  |  2 +-
 .shippable.yml |  8 
 4 files changed, 11 insertions(+), 16 deletions(-)

-- 
2.17.0




Re: [Qemu-devel] [PATCH v4 0/5] s390x: vfio-ap: guest dedicated crypto adapters

2018-04-15 Thread no-reply
Hi,

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

Type: series
Message-id: 1523819244-29954-1-git-send-email-akrow...@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH v4 0/5] s390x: vfio-ap: guest dedicated crypto 
adapters

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag]   
patchew/1523819244-29954-1-git-send-email-akrow...@linux.vnet.ibm.com -> 
patchew/1523819244-29954-1-git-send-email-akrow...@linux.vnet.ibm.com
Switched to a new branch 'test'
05c25cd0f2 s390: doc: detailed specifications for AP virtualization
543e5cbc46 s390x/vfio: ap: Introduce VFIO AP device
994913441f s390x/cpumodel: Set up CPU model for AP device support
e7f90b1258 s390x/ap: base Adjunct Processor (AP) object
13602d236e linux-headers: linux header updates for AP support

=== OUTPUT BEGIN ===
Checking PATCH 1/5: linux-headers: linux header updates for AP support...
Checking PATCH 2/5: s390x/ap: base Adjunct Processor (AP) object...
Checking PATCH 3/5: s390x/cpumodel: Set up CPU model for AP device support...
WARNING: line over 80 characters
#43: FILE: target/s390x/cpu_features.c:43:
+FEAT_INIT("apqci", S390_FEAT_TYPE_STFL, 12, "Query AP Configuration 
facility"),

ERROR: line over 90 characters
#46: FILE: target/s390x/cpu_features.c:46:
+FEAT_INIT("apft", S390_FEAT_TYPE_STFL, 15, "Adjunct Processor Facilities 
Test facility"),

total: 1 errors, 1 warnings, 58 lines checked

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

Checking PATCH 4/5: s390x/vfio: ap: Introduce VFIO AP device...
Checking PATCH 5/5: s390: doc: detailed specifications for AP virtualization...
=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

[Qemu-devel] [PATCH for-2.12?] m25p80: Correct the at25128a/at25256a eeproms size

2018-04-15 Thread Philippe Mathieu-Daudé
>From the datasheet (3368J–SEEPR) description:
The AT25128A/256A provides 131,072/262,144 bits of serial
electrically-erasable programmable read only memory (EEPROM)
organized as 16,384/32,768 words of 8 bits each.

However QEMU models the flash size in bytes.
Correct the at25128a/at25256a entries to reflect the datasheet size.

Signed-off-by: Philippe Mathieu-Daudé 
---
This is not a regression, so can now wait for 2.13.

 hw/block/m25p80.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index b49c8e9caa..d0b9fbfc50 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -196,8 +196,8 @@ static const FlashPartInfo known_devices[] = {
 /* Atmel EEPROMS - it is assumed, that don't care bit in command
  * is set to 0. Block protection is not supported.
  */
-{ INFO("at25128a-nonjedec", 0x0, 0, 1, 131072, EEPROM) },
-{ INFO("at25256a-nonjedec", 0x0, 0, 1, 262144, EEPROM) },
+{ INFO("at25128a-nonjedec", 0x0, 0, 1, 16384, EEPROM) },
+{ INFO("at25256a-nonjedec", 0x0, 0, 1, 32768, EEPROM) },
 
 /* EON -- en25xxx */
 { INFO("en25f32", 0x1c3116,  0,  64 << 10,  64, ER_4K) },
-- 
2.17.0




[Qemu-devel] [PATCH v4 5/5] s390: doc: detailed specifications for AP virtualization

2018-04-15 Thread Tony Krowiak
This patch provides documentation describing the AP architecture and
design concepts behind the virtualization of AP devices. It also
includes an example of how to configure AP devices for exclusive
use of KVM guests.

Signed-off-by: Tony Krowiak 
---
 docs/vfio-ap.txt |  649 ++
 1 files changed, 649 insertions(+), 0 deletions(-)
 create mode 100644 docs/vfio-ap.txt

diff --git a/docs/vfio-ap.txt b/docs/vfio-ap.txt
new file mode 100644
index 000..e0d826c
--- /dev/null
+++ b/docs/vfio-ap.txt
@@ -0,0 +1,649 @@
+Adjunct Processor (AP) Device
+=
+
+Contents:
+=
+* Introduction
+* AP Architectural Overview
+* Start Interpretive Execution (SIE) Instruction
+* AP Matrix Configuration on Linux Host
+* AP Matrix Configuration for a Linux Guest
+* Starting a Linux Guest Configured with an AP Matrix
+* Example: Configure AP Matrices for Two Linux Guests
+
+Introduction:
+
+The IBM Adjunct Processor (AP) Cryptographic Facility is comprised
+of three AP instructions and from 1 to 256 PCIe cryptographic adapter cards.
+These AP devices provide cryptographic functions to all CPUs assigned to a
+linux system running in an IBM Z system LPAR.
+
+On s390x, AP adapter cards are exposed via the AP bus. This document
+describes how those cards may be made available to KVM guests using the
+VFIO mediated device framework.
+
+AP Architectural Overview:
+=
+In order understand the terminology used in the rest of this document, let's
+start with some definitions:
+
+* AP adapter
+
+  An AP adapter is an IBM Z adapter card that can perform cryptographic
+  functions. There can be from 0 to 256 adapters assigned to an LPAR. Adapters
+  assigned to the LPAR in which a linux host is running will be available to
+  the linux host. Each adapter is identified by a number from 0 to 255. When
+  installed, an AP adapter is accessed by AP instructions executed by any CPU.
+
+* AP domain
+
+  An adapter is partitioned into domains. Each domain can be thought of as
+  a set of hardware registers for processing AP instructions. An adapter can
+  hold up to 256 domains. Each domain is identified by a number from 0 to 255.
+  Domains can be further classified into two types:
+
+* Usage domains are domains that can be accessed directly to process AP
+  commands
+
+* Control domains are domains that are accessed indirectly by AP
+  commands sent to a usage domain to control or change the domain, for
+  example; to set a secure private key for the domain.
+
+  The AP usage and control domains are assigned to a given LPAR via the 
system's
+  Activation Profile which can be edited via the HMC. When the system is IPL'd,
+  the AP bus module is loaded and detects the AP usage and control domains
+  assigned to the LPAR. The domain number of each usage domain will be coupled
+  with the adapter number of each AP adapter assigned to the LPAR to identify
+  the AP queues (see AP Queue section below). The domain number of each control
+  domain will be represented in a bitmask and stored in a sysfs file
+  /sys/bus/ap/ap_control_domain_mask created by the bus. The bits in the mask,
+  from most to least significant bit, correspond to domains 0-255.
+
+  A domain may be assigned to a system as both a usage and control domain, or
+  as a control domain only. Consequently, all domains assigned as both a usage
+  and control domain can both process AP commands as well as be changed by an 
AP
+  command sent to any usage domain assigned to the same system. Domains 
assigned
+  only as control domains can not process AP commands but can be changed by AP
+  commands sent to any usage domain assigned to the system.
+
+* AP Queue
+
+  An AP queue is the means by which an AP command-request message is sent to an
+  AP usage domain inside a specific AP. An AP queue is identified by a tuple
+  comprised of an AP adapter ID (APID) and an AP queue index (APQI). The
+  APQI corresponds to a given usage domain number within the adapter. This 
tuple
+  forms an AP Queue Number (APQN) uniquely identifying an AP queue. AP
+  instructions include a field containing the APQN to identify the AP queue to
+  which the AP command-request message is to be sent for processing.
+
+* AP Instructions:
+
+  There are three AP instructions:
+
+  * NQAP: to enqueue an AP command-request message to a queue
+  * DQAP: to dequeue an AP command-reply message from a queue
+  * PQAP: to administer the queues
+
+Start Interpretive Execution (SIE) Instruction
+==
+A KVM guest is started by executing the Start Interpretive Execution (SIE)
+instruction. The SIE state description is a control block that contains the
+state information for a KVM guest and is supplied as input to the SIE
+instruction. The SIE state description contains a field that references
+a Crypto Control Block 

[Qemu-devel] [PATCH v4 2/5] s390x/ap: base Adjunct Processor (AP) object

2018-04-15 Thread Tony Krowiak
This patch introduces the base object for an AP device.

Signed-off-by: Tony Krowiak 
---
 hw/s390x/Makefile.objs   |1 +
 hw/s390x/ap-device.c |   39 +++
 include/hw/s390x/ap-device.h |   38 ++
 ui/keycodemapdb  |2 +-
 4 files changed, 79 insertions(+), 1 deletions(-)
 create mode 100644 hw/s390x/ap-device.c
 create mode 100644 include/hw/s390x/ap-device.h

diff --git a/hw/s390x/Makefile.objs b/hw/s390x/Makefile.objs
index dc704b5..3247a07 100644
--- a/hw/s390x/Makefile.objs
+++ b/hw/s390x/Makefile.objs
@@ -17,3 +17,4 @@ obj-y += s390-stattrib.o
 obj-$(CONFIG_KVM) += s390-skeys-kvm.o
 obj-$(CONFIG_KVM) += s390-stattrib-kvm.o
 obj-y += s390-ccw.o
+obj-y += ap-device.o
diff --git a/hw/s390x/ap-device.c b/hw/s390x/ap-device.c
new file mode 100644
index 000..3cd4bae
--- /dev/null
+++ b/hw/s390x/ap-device.c
@@ -0,0 +1,39 @@
+/*
+ * Adjunct Processor (AP) matrix device
+ *
+ * Copyright 2018 IBM Corp.
+ * Author(s): Tony Krowiak 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+#include "qemu/osdep.h"
+#include "qemu/module.h"
+#include "qapi/error.h"
+#include "hw/qdev.h"
+#include "hw/s390x/ap-device.h"
+
+static void ap_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+
+dc->desc = "AP device class";
+dc->hotpluggable = false;
+}
+
+static const TypeInfo ap_device_info = {
+.name = AP_DEVICE_TYPE,
+.parent = TYPE_DEVICE,
+.instance_size = sizeof(APDevice),
+.class_size = sizeof(APDeviceClass),
+.class_init = ap_class_init,
+.abstract = true,
+};
+
+static void ap_device_register(void)
+{
+type_register_static(_device_info);
+}
+
+type_init(ap_device_register)
diff --git a/include/hw/s390x/ap-device.h b/include/hw/s390x/ap-device.h
new file mode 100644
index 000..693df90
--- /dev/null
+++ b/include/hw/s390x/ap-device.h
@@ -0,0 +1,38 @@
+/*
+ * Adjunct Processor (AP) matrix device interfaces
+ *
+ * Copyright 2018 IBM Corp.
+ * Author(s): Tony Krowiak 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+#ifndef HW_S390X_AP_DEVICE_H
+#define HW_S390X_AP_DEVICE_H
+
+#define AP_DEVICE_TYPE   "ap-device"
+
+typedef struct APDevice {
+DeviceState parent_obj;
+} APDevice;
+
+typedef struct APDeviceClass {
+DeviceClass parent_class;
+} APDeviceClass;
+
+static inline APDevice *to_ap_dev(DeviceState *dev)
+{
+return container_of(dev, APDevice, parent_obj);
+}
+
+#define AP_DEVICE(obj) \
+OBJECT_CHECK(APDevice, (obj), AP_DEVICE_TYPE)
+
+#define AP_DEVICE_GET_CLASS(obj) \
+OBJECT_GET_CLASS(APDeviceClass, (obj), AP_DEVICE_TYPE)
+
+#define AP_DEVICE_CLASS(klass) \
+OBJECT_CLASS_CHECK(APDeviceClass, (klass), AP_DEVICE_TYPE)
+
+#endif /* HW_S390X_AP_DEVICE_H */
diff --git a/ui/keycodemapdb b/ui/keycodemapdb
index 6b3d716..16e5b07 16
--- a/ui/keycodemapdb
+++ b/ui/keycodemapdb
@@ -1 +1 @@
-Subproject commit 6b3d716e2b6472eb7189d3220552280ef3d832ce
+Subproject commit 16e5b0787687d8904dad2c026107409eb9bfcb95
-- 
1.7.1




[Qemu-devel] [PATCH v4 4/5] s390x/vfio: ap: Introduce VFIO AP device

2018-04-15 Thread Tony Krowiak
Introduces a VFIO based AP device. The device is defined via
the QEMU command line by specifying:

-device vfio-ap,sysfsdev=

There may be only one vfio-ap device configured for a guest.

The mediated matrix device is created by the VFIO AP device
driver by writing a UUID to a sysfs attribute file (see
docs/vfio-ap.txt). The mediated matrix device will be named
after the UUID. Symbolic links to the $uuid are created in
many places, so the path to the mediated matrix device $uuid
can be specified in any of the following ways:

/sys/devices/vfio_ap/matrix/$uuid
/sys/devices/vfio_ap/matrix/mdev_supported_types/vfio_ap-passthrough/devices/$uuid
/sys/bus/mdev/devices/$uuid
/sys/bus/mdev/drivers/vfio_mdev/$uuid

When the vfio-ap device is realized, it acquires and opens the
VFIO iommu group to which the mediated matrix device is
bound. This causes a VFIO group notification event to be
signaled. The vfio_ap device driver's group notification
handler will get called at which time the device driver
will configure the the AP devices to which the guest will
be granted access.

Signed-off-by: Tony Krowiak 
---
 default-configs/s390x-softmmu.mak |1 +
 hw/vfio/Makefile.objs |1 +
 hw/vfio/ap.c  |  191 +
 include/hw/vfio/vfio-common.h |1 +
 4 files changed, 194 insertions(+), 0 deletions(-)
 create mode 100644 hw/vfio/ap.c

diff --git a/default-configs/s390x-softmmu.mak 
b/default-configs/s390x-softmmu.mak
index 2f4bfe7..0b784b6 100644
--- a/default-configs/s390x-softmmu.mak
+++ b/default-configs/s390x-softmmu.mak
@@ -9,3 +9,4 @@ CONFIG_S390_FLIC=y
 CONFIG_S390_FLIC_KVM=$(CONFIG_KVM)
 CONFIG_VFIO_CCW=$(CONFIG_LINUX)
 CONFIG_WDT_DIAG288=y
+CONFIG_VFIO_AP=$(CONFIG_LINUX)
diff --git a/hw/vfio/Makefile.objs b/hw/vfio/Makefile.objs
index a2e7a0a..8b3f664 100644
--- a/hw/vfio/Makefile.objs
+++ b/hw/vfio/Makefile.objs
@@ -6,4 +6,5 @@ obj-$(CONFIG_SOFTMMU) += platform.o
 obj-$(CONFIG_VFIO_XGMAC) += calxeda-xgmac.o
 obj-$(CONFIG_VFIO_AMD_XGBE) += amd-xgbe.o
 obj-$(CONFIG_SOFTMMU) += spapr.o
+obj-$(CONFIG_VFIO_AP) += ap.o
 endif
diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c
new file mode 100644
index 000..7b48a3a
--- /dev/null
+++ b/hw/vfio/ap.c
@@ -0,0 +1,191 @@
+/*
+ * VFIO based AP matrix device assignment
+ *
+ * Copyright 2018 IBM Corp.
+ * Author(s): Tony Krowiak 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include 
+#include 
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "hw/sysbus.h"
+#include "hw/vfio/vfio.h"
+#include "hw/vfio/vfio-common.h"
+#include "hw/s390x/ap-device.h"
+#include "qemu/error-report.h"
+#include "qemu/queue.h"
+#include "qemu/option.h"
+#include "qemu/config-file.h"
+#include "cpu.h"
+#include "kvm_s390x.h"
+#include "sysemu/sysemu.h"
+
+#define VFIO_AP_DEVICE_TYPE  "vfio-ap"
+
+typedef struct VFIOAPDevice {
+APDevice apdev;
+VFIODevice vdev;
+QTAILQ_ENTRY(VFIOAPDevice) sibling;
+} VFIOAPDevice;
+
+VFIOAPDevice *vfio_apdev;
+
+static void vfio_ap_compute_needs_reset(VFIODevice *vdev)
+{
+vdev->needs_reset = false;
+}
+
+/*
+ * We don't need vfio_hot_reset_multi and vfio_eoi operations for
+ * vfio-ap-matrix device now.
+ */
+struct VFIODeviceOps vfio_ap_ops = {
+.vfio_compute_needs_reset = vfio_ap_compute_needs_reset,
+};
+
+static void vfio_put_device(VFIOAPDevice *vapdev)
+{
+g_free(vapdev->vdev.name);
+vfio_put_base_device(>vdev);
+}
+
+static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
+{
+char *tmp, group_path[PATH_MAX];
+ssize_t len;
+int groupid;
+
+tmp = g_strdup_printf("%s/iommu_group", vapdev->vdev.sysfsdev);
+len = readlink(tmp, group_path, sizeof(group_path));
+g_free(tmp);
+
+if (len <= 0 || len >= sizeof(group_path)) {
+error_setg(errp, "%s: no iommu_group found for %s",
+   VFIO_AP_DEVICE_TYPE, vapdev->vdev.sysfsdev);
+return NULL;
+}
+
+group_path[len] = 0;
+
+if (sscanf(basename(group_path), "%d", ) != 1) {
+error_setg(errp, "vfio: failed to read %s", group_path);
+return NULL;
+}
+
+return vfio_get_group(groupid, _space_memory, errp);
+}
+
+static void vfio_ap_realize(DeviceState *dev, Error **errp)
+{
+VFIODevice *vbasedev;
+VFIOGroup *vfio_group;
+APDevice *apdev = DO_UPCAST(APDevice, parent_obj, dev);
+char *mdevid;
+Error *local_err = NULL;
+int ret;
+
+/*
+ * Since a guest's matrix is configured in its entirety by the mediated
+ * matrix device and hot plug is not currently supported, there is no
+ * need to have more than one vfio-ap device. Check if a vfio-ap device
+ * has already been defined.
+ */
+if (vfio_apdev) {
+error_setg(_err, "Only one %s device is allowed",
+

[Qemu-devel] [PATCH v4 1/5] linux-headers: linux header updates for AP support

2018-04-15 Thread Tony Krowiak
Updates the linux header files in preparation for introduction
of the VFIO AP device:

* Added a feature ID to indicate AP facilities are installed

* Added a device attribute to the KVM_S390_VM_CRYPTO group to
  indicate whether AP instructions are to be interpreted

* Added VFIO device information for AP devices

Signed-off-by: Tony Krowiak 
---
 linux-headers/asm-s390/kvm.h |2 ++
 linux-headers/linux/vfio.h   |2 ++
 2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/linux-headers/asm-s390/kvm.h b/linux-headers/asm-s390/kvm.h
index 11def14..391b250 100644
--- a/linux-headers/asm-s390/kvm.h
+++ b/linux-headers/asm-s390/kvm.h
@@ -130,6 +130,7 @@ struct kvm_s390_vm_cpu_machine {
 #define KVM_S390_VM_CPU_FEAT_PFMFI 11
 #define KVM_S390_VM_CPU_FEAT_SIGPIF12
 #define KVM_S390_VM_CPU_FEAT_KSS   13
+#define KVM_S390_VM_CPU_FEAT_AP14
 struct kvm_s390_vm_cpu_feat {
__u64 feat[16];
 };
@@ -160,6 +161,7 @@ struct kvm_s390_vm_cpu_subfunc {
 #define KVM_S390_VM_CRYPTO_ENABLE_DEA_KW   1
 #define KVM_S390_VM_CRYPTO_DISABLE_AES_KW  2
 #define KVM_S390_VM_CRYPTO_DISABLE_DEA_KW  3
+#define KVM_S390_VM_CRYPTO_INTERPRET_AP4
 
 /* kvm attributes for migration mode */
 #define KVM_S390_VM_MIGRATION_STOP 0
diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h
index 3a0a305..1bb9897 100644
--- a/linux-headers/linux/vfio.h
+++ b/linux-headers/linux/vfio.h
@@ -200,6 +200,7 @@ struct vfio_device_info {
 #define VFIO_DEVICE_FLAGS_PLATFORM (1 << 2)/* vfio-platform device */
 #define VFIO_DEVICE_FLAGS_AMBA  (1 << 3)   /* vfio-amba device */
 #define VFIO_DEVICE_FLAGS_CCW  (1 << 4)/* vfio-ccw device */
+#define VFIO_DEVICE_FLAGS_AP (1 << 5)  /* vfio-ap device */
__u32   num_regions;/* Max region index + 1 */
__u32   num_irqs;   /* Max IRQ index + 1 */
 };
@@ -215,6 +216,7 @@ struct vfio_device_info {
 #define VFIO_DEVICE_API_PLATFORM_STRING"vfio-platform"
 #define VFIO_DEVICE_API_AMBA_STRING"vfio-amba"
 #define VFIO_DEVICE_API_CCW_STRING "vfio-ccw"
+#define VFIO_DEVICE_API_AP_STRING  "vfio-ap"
 
 /**
  * VFIO_DEVICE_GET_REGION_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 8,
-- 
1.7.1




[Qemu-devel] [PATCH v4 0/5] s390x: vfio-ap: guest dedicated crypto adapters

2018-04-15 Thread Tony Krowiak
This patch series is the QEMU counterpart to the KVM/kernel support for 
guest dedicated crypto adapters. The KVM/kernel model is built on the 
VFIO mediated device framework and provides the infrastructure for 
granting exclusive guest access to crypto devices installed on the linux 
host. This patch series introduces a new QEMU command line option, QEMU 
object model and CPU model features to exploit the KVM/kernel model.

See the detailed specifications for AP virtualization provided by this 
patch set in docs/vfio-ap.txt for a more complete discussion of the 
design introduced by this patch series.

Note: This series implements the minimal viable product (MVP) and does not
  provide support for hot plug/unplug, migration, or VSIE. The goal
  of the MVP model is to solidify a base upon which these additional 
  features will be built.

v3 => v4 Change log:
===
* Made vfio-ap device unpluggable for now
* Renamed command line CPU model feature for QCI: qci=on -> apqci=on
* Removed call to KVM_S390_VM_CRYPTO_INTERPRET_AP ioctl - ioctl was 
  removed from kernel and AP instruction interpretation is set from the
  VFIO device driver
* Added check to ensure only one vfio-ap device can be configured per 
  guest
* Removed AP instruction interception handlers: AP instructions will be 
  interpreted by default if AP facilities are installed to handle the case
  where feature ap=on and no vfio-ap device is configured for the guest.

Tony Krowiak (5):
  linux-headers: linux header updates for AP support
  s390x/ap: base Adjunct Processor (AP) object
  s390x/cpumodel: Set up CPU model for AP device support
  s390x/vfio: ap: Introduce VFIO AP device
  s390: doc: detailed specifications for AP virtualization

 default-configs/s390x-softmmu.mak |1 +
 docs/vfio-ap.txt  |  649 +
 hw/s390x/Makefile.objs|1 +
 hw/s390x/ap-device.c  |   39 +++
 hw/vfio/Makefile.objs |1 +
 hw/vfio/ap.c  |  191 +++
 include/hw/s390x/ap-device.h  |   38 +++
 include/hw/vfio/vfio-common.h |1 +
 linux-headers/asm-s390/kvm.h  |2 +
 linux-headers/linux/vfio.h|2 +
 target/s390x/cpu_features.c   |3 +
 target/s390x/cpu_features_def.h   |3 +
 target/s390x/cpu_models.c |2 +
 target/s390x/gen-features.c   |3 +
 target/s390x/kvm.c|1 +
 ui/keycodemapdb   |2 +-
 16 files changed, 938 insertions(+), 1 deletions(-)
 create mode 100644 docs/vfio-ap.txt
 create mode 100644 hw/s390x/ap-device.c
 create mode 100644 hw/vfio/ap.c
 create mode 100644 include/hw/s390x/ap-device.h




[Qemu-devel] [PATCH v4 3/5] s390x/cpumodel: Set up CPU model for AP device support

2018-04-15 Thread Tony Krowiak
A new CPU model feature and two new CPU model facilities are
introduced to support AP devices for a KVM guest.

CPU model features:

1. The KVM_S390_VM_CPU_FEAT_AP CPU model feature indicates that
   AP facilities are installed. This feature will be enabled by
   the kernel only if the AP facilities are installed on the linux
   host. This feature must be turned on from userspace to access
   AP devices from the KVM guest. The QEMU command line to turn
   this feature looks something like this:

qemu-system-s390x ... -cpu xxx,ap=on

CPU model facilities:

1. The S390_FEAT_AP_QUERY_CONFIG_INFO feature indicates the AP Query
   Configuration Information (QCI) facility is installed. This feature
   will be enabled by the kernel only if the QCI is installed on
   the host.

2. The S390_FEAT_AP_FACILITY_TEST feature indicates that the AP
   Facility Test (APFT) facility is installed. This feature will
   be enabled by the kernel only if the APFT facility is installed
   on the host.

Signed-off-by: Tony Krowiak 
---
 target/s390x/cpu_features.c |3 +++
 target/s390x/cpu_features_def.h |3 +++
 target/s390x/cpu_models.c   |2 ++
 target/s390x/gen-features.c |3 +++
 target/s390x/kvm.c  |1 +
 5 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/target/s390x/cpu_features.c b/target/s390x/cpu_features.c
index 3b9e274..5ee3a2d 100644
--- a/target/s390x/cpu_features.c
+++ b/target/s390x/cpu_features.c
@@ -40,8 +40,10 @@ static const S390FeatDef s390_features[] = {
 FEAT_INIT("srs", S390_FEAT_TYPE_STFL, 9, "Sense-running-status facility"),
 FEAT_INIT("csske", S390_FEAT_TYPE_STFL, 10, "Conditional-SSKE facility"),
 FEAT_INIT("ctop", S390_FEAT_TYPE_STFL, 11, "Configuration-topology 
facility"),
+FEAT_INIT("apqci", S390_FEAT_TYPE_STFL, 12, "Query AP Configuration 
facility"),
 FEAT_INIT("ipter", S390_FEAT_TYPE_STFL, 13, "IPTE-range facility"),
 FEAT_INIT("nonqks", S390_FEAT_TYPE_STFL, 14, "Nonquiescing key-setting 
facility"),
+FEAT_INIT("apft", S390_FEAT_TYPE_STFL, 15, "Adjunct Processor Facilities 
Test facility"),
 FEAT_INIT("etf2", S390_FEAT_TYPE_STFL, 16, "Extended-translation facility 
2"),
 FEAT_INIT("msa-base", S390_FEAT_TYPE_STFL, 17, "Message-security-assist 
facility (excluding subfunctions)"),
 FEAT_INIT("ldisp", S390_FEAT_TYPE_STFL, 18, "Long-displacement facility"),
@@ -129,6 +131,7 @@ static const S390FeatDef s390_features[] = {
 
 FEAT_INIT_MISC("dateh2", "DAT-enhancement facility 2"),
 FEAT_INIT_MISC("cmm", "Collaborative-memory-management facility"),
+FEAT_INIT_MISC("ap", "AP facilities installed"),
 
 FEAT_INIT("plo-cl", S390_FEAT_TYPE_PLO, 0, "PLO Compare and load (32 bit 
in general registers)"),
 FEAT_INIT("plo-clg", S390_FEAT_TYPE_PLO, 1, "PLO Compare and load (64 bit 
in parameter list)"),
diff --git a/target/s390x/cpu_features_def.h b/target/s390x/cpu_features_def.h
index 7c5915c..8998b65 100644
--- a/target/s390x/cpu_features_def.h
+++ b/target/s390x/cpu_features_def.h
@@ -27,8 +27,10 @@ typedef enum {
 S390_FEAT_SENSE_RUNNING_STATUS,
 S390_FEAT_CONDITIONAL_SSKE,
 S390_FEAT_CONFIGURATION_TOPOLOGY,
+S390_FEAT_AP_QUERY_CONFIG_INFO,
 S390_FEAT_IPTE_RANGE,
 S390_FEAT_NONQ_KEY_SETTING,
+S390_FEAT_AP_FACILITIES_TEST,
 S390_FEAT_EXTENDED_TRANSLATION_2,
 S390_FEAT_MSA,
 S390_FEAT_LONG_DISPLACEMENT,
@@ -118,6 +120,7 @@ typedef enum {
 /* Misc */
 S390_FEAT_DAT_ENH_2,
 S390_FEAT_CMM,
+S390_FEAT_AP,
 
 /* PLO */
 S390_FEAT_PLO_CL,
diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c
index 2741b68..2ab59cd 100644
--- a/target/s390x/cpu_models.c
+++ b/target/s390x/cpu_models.c
@@ -770,6 +770,8 @@ static void check_consistency(const S390CPUModel *model)
 { S390_FEAT_PRNO_TRNG_QRTCR, S390_FEAT_MSA_EXT_5 },
 { S390_FEAT_PRNO_TRNG, S390_FEAT_MSA_EXT_5 },
 { S390_FEAT_SIE_KSS, S390_FEAT_SIE_F2 },
+{ S390_FEAT_AP_QUERY_CONFIG_INFO, S390_FEAT_AP },
+{ S390_FEAT_AP_FACILITIES_TEST, S390_FEAT_AP },
 };
 int i;
 
diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c
index 0cdbc15..0d5b0f7 100644
--- a/target/s390x/gen-features.c
+++ b/target/s390x/gen-features.c
@@ -447,6 +447,9 @@ static uint16_t full_GEN12_GA1[] = {
 S390_FEAT_ADAPTER_INT_SUPPRESSION,
 S390_FEAT_EDAT_2,
 S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2,
+S390_FEAT_AP_QUERY_CONFIG_INFO,
+S390_FEAT_AP_FACILITIES_TEST,
+S390_FEAT_AP,
 };
 
 static uint16_t full_GEN12_GA2[] = {
diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
index fb59d92..8c251b4 100644
--- a/target/s390x/kvm.c
+++ b/target/s390x/kvm.c
@@ -2100,6 +2100,7 @@ static int kvm_to_feat[][2] = {
 { KVM_S390_VM_CPU_FEAT_PFMFI, S390_FEAT_SIE_PFMFI},
 { KVM_S390_VM_CPU_FEAT_SIGPIF, S390_FEAT_SIE_SIGPIF},
 { KVM_S390_VM_CPU_FEAT_KSS, S390_FEAT_SIE_KSS},
+{ 

[Qemu-devel] [PULL 0/1] m68k fixes for 2.12-rc4

2018-04-15 Thread Laurent Vivier
The following changes since commit 38e83a71d02e026d4a6d0ab1ef9855c4924c2c68:

  Update version for v2.12.0-rc3 release (2018-04-11 19:03:24 +0100)

are available in the Git repository at:

  git://github.com/vivier/qemu-m68k.git tags/m68k-for-2.12-pull-request

for you to fetch changes up to 000761dc0c97d70e7314db3e8f52783880325a22:

  m68k: fix exception stack frame for 68000 (2018-04-15 11:37:58 +0200)


This patch fixes a problem with the exception stack for
68000 only CPU. As we use 68040 for linux-user and coldfire
for softmmu, I don't think we should trigger a -rc4
only for that, so merge this only if a -rc4 is needed
by something else.


Pavel Dovgalyuk (1):
  m68k: fix exception stack frame for 68000

 target/m68k/op_helper.c | 33 ++---
 1 file changed, 18 insertions(+), 15 deletions(-)

-- 
2.14.3




[Qemu-devel] [PULL 1/1] m68k: fix exception stack frame for 68000

2018-04-15 Thread Laurent Vivier
From: Pavel Dovgalyuk 

68000 CPUs do not save format in the exception stack frame.
This patch adds feature checking to prevent format saving for 68000.
m68k_ret() already includes this modification, this patch fixes
the exception processing function too.

Signed-off-by: Pavel Dovgalyuk 
Reviewed-by: Laurent Vivier 
Message-Id: <20180413133041.29509.59064.stgit@pasha-VirtualBox>
Signed-off-by: Laurent Vivier 
---
 target/m68k/op_helper.c | 33 ++---
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/target/m68k/op_helper.c b/target/m68k/op_helper.c
index 3a7f7f2219..8d09ed91c4 100644
--- a/target/m68k/op_helper.c
+++ b/target/m68k/op_helper.c
@@ -287,22 +287,25 @@ static inline void do_stack_frame(CPUM68KState *env, 
uint32_t *sp,
   uint16_t format, uint16_t sr,
   uint32_t addr, uint32_t retaddr)
 {
-CPUState *cs = CPU(m68k_env_get_cpu(env));
-switch (format) {
-case 4:
-*sp -= 4;
-cpu_stl_kernel(env, *sp, env->pc);
-*sp -= 4;
-cpu_stl_kernel(env, *sp, addr);
-break;
-case 3:
-case 2:
-*sp -= 4;
-cpu_stl_kernel(env, *sp, addr);
-break;
+if (m68k_feature(env, M68K_FEATURE_QUAD_MULDIV)) {
+/*  all except 68000 */
+CPUState *cs = CPU(m68k_env_get_cpu(env));
+switch (format) {
+case 4:
+*sp -= 4;
+cpu_stl_kernel(env, *sp, env->pc);
+*sp -= 4;
+cpu_stl_kernel(env, *sp, addr);
+break;
+case 3:
+case 2:
+*sp -= 4;
+cpu_stl_kernel(env, *sp, addr);
+break;
+}
+*sp -= 2;
+cpu_stw_kernel(env, *sp, (format << 12) + (cs->exception_index << 2));
 }
-*sp -= 2;
-cpu_stw_kernel(env, *sp, (format << 12) + (cs->exception_index << 2));
 *sp -= 4;
 cpu_stl_kernel(env, *sp, retaddr);
 *sp -= 2;
-- 
2.14.3