Re: [PATCH v4 00/10] Further bitmaps improvements

2020-03-11 Thread Vladimir Sementsov-Ogievskiy

11.03.2020 20:03, John Snow wrote:



On 3/11/20 9:58 AM, Vladimir Sementsov-Ogievskiy wrote:

11.03.2020 12:55, Max Reitz wrote:

On 11.03.20 07:17, Vladimir Sementsov-Ogievskiy wrote:

10.03.2020 20:17, Max Reitz wrote:

On 06.03.20 08:45, Vladimir Sementsov-Ogievskiy wrote:

26.02.2020 16:13, Max Reitz wrote:

On 05.02.20 12:20, Vladimir Sementsov-Ogievskiy wrote:

Hi!

The main feature here is improvement of _next_dirty_area API, which
I'm
going to use then for backup / block-copy.

Somehow, I thought that it was merged, but seems I even forgot to
send
v4.


The changes from v3 look good to me, but I’d prefer a review from
Eric
on patch 8.



Hi!

Could you take it now, or do you prefer me to resend?j


I understand that you agreed to drop the comment above
bd_extent_array_convert_to_be(), then do the
“s/further call/so further calls/” replacement, and finally replace the
whole four lines Eric has quoted by “(this ensures that after a
failure,
no further extents can accidentally change the bounds of the last
extent
in the array)”?



Yes, all true.


Hm, I could take it then, but on second thought, John is the maintainer
for 8/10 patches, and Eric is for the other two...  So I’m not sure
whether I’m even the right person to do so.



Hmm, true. Let's wait for John?




I am *VERY* behind on my email, and this patch series is sitting in my
to-review folder. However, if it's ready to go and reviewed, I'm willing
to merge it, test it, and give it a quick look-over and get you on your way.



It would be great, if it is convenient for you. Thanks!
All patches are reviewed now by Max or Eric, so, I'd be very glad if this get 
in 5.0.



--
Best regards,
Vladimir



Re: [PATCH RESEND 1/3] vfio/pci: fix a null pointer reference in vfio_rom_read

2020-03-11 Thread Markus Armbruster
Alex Williamson  writes:

> On Wed, 11 Mar 2020 08:04:28 +0100
> Markus Armbruster  wrote:
>
>> Alex Williamson  writes:
>> 
>> > On Mon, 24 Feb 2020 14:42:17 +0800
>> > "Longpeng(Mike)"  wrote:
>> >  
>> >> From: Longpeng 
>> >> 
>> >> vfio_pci_load_rom() maybe failed and then the vdev->rom is NULL in
>> >> some situation (though I've not encountered yet), maybe we should
>> >> avoid the VM abort.  
>> 
>> What "VM abort" exactly?
>
> There is none because memcpy() does something sane when size is zero,
> but to be ISO whatever spec compliant we shouldn't rely on that.
>
>> >> 
>> >> Signed-off-by: Longpeng 
>> >> ---
>> >>  hw/vfio/pci.c | 13 -
>> >>  1 file changed, 8 insertions(+), 5 deletions(-)
>> >> 
>> >> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
>> >> index 5e75a95..ed798ae 100644
>> >> --- a/hw/vfio/pci.c
>> >> +++ b/hw/vfio/pci.c
>> >> @@ -768,7 +768,7 @@ static void vfio_update_msi(VFIOPCIDevice *vdev)
>> >>  }
>> >>  }
>> >>  
>> >> -static void vfio_pci_load_rom(VFIOPCIDevice *vdev)
>> >> +static bool vfio_pci_load_rom(VFIOPCIDevice *vdev)
>> >>  {
>> >>  struct vfio_region_info *reg_info;
>> >>  uint64_t size;
>> >> @@ -778,7 +778,7 @@ static void vfio_pci_load_rom(VFIOPCIDevice *vdev)
>> >>  if (vfio_get_region_info(>vbasedev,
>> >>   VFIO_PCI_ROM_REGION_INDEX, _info)) {
>> >>  error_report("vfio: Error getting ROM info: %m");
>> >> -return;
>> >> +return false;
>> >>  }
>> >>  
>> >>  trace_vfio_pci_load_rom(vdev->vbasedev.name, (unsigned 
>> >> long)reg_info->size,
>> >> @@ -797,7 +797,7 @@ static void vfio_pci_load_rom(VFIOPCIDevice *vdev)
>> >>  error_printf("Device option ROM contents are probably invalid "
>> >>  "(check dmesg).\nSkip option ROM probe with 
>> >> rombar=0, "
>> >>  "or load from file with romfile=\n");
>> >> -return;
>> >> +return false;
>> >>  }
>> >>  
>> >>  vdev->rom = g_malloc(size);
>> >> @@ -849,6 +849,8 @@ static void vfio_pci_load_rom(VFIOPCIDevice *vdev)
>> >>  data[6] = -csum;
>> >>  }
>> >>  }
>> >> +
>> >> +return true;
>> >>  }
>> >>  
>> >>  static uint64_t vfio_rom_read(void *opaque, hwaddr addr, unsigned size)
>> >> @@ -863,8 +865,9 @@ static uint64_t vfio_rom_read(void *opaque, hwaddr 
>> >> addr, unsigned size)  
>> {
>> VFIOPCIDevice *vdev = opaque;
>> union {
>> uint8_t byte;
>> uint16_t word;
>> uint32_t dword;
>> uint64_t qword;
>> } val;
>> >>  uint64_t data = 0;
>> >>  
>> >>  /* Load the ROM lazily when the guest tries to read it */
>> >> -if (unlikely(!vdev->rom && !vdev->rom_read_failed)) {
>> >> -vfio_pci_load_rom(vdev);
>> >> +if (unlikely(!vdev->rom && !vdev->rom_read_failed) &&
>> >> +!vfio_pci_load_rom(vdev)) {
>> >> +return 0;
>> >>  }
>> >>  
>> >>  memcpy(, vdev->rom + addr,  
>> >
>> > Looks like an obvious bug, until you look at the rest of this memcpy():
>> >
>> > memcpy(, vdev->rom + addr,
>> >(addr < vdev->rom_size) ? MIN(size, vdev->rom_size - addr) : 0);
>> >
>> > IOW, we'll do a zero sized memcpy() if rom_size is zero, so there's no
>> > risk of the concern identified in the commit log.  This patch is
>> > unnecessary.  Thanks,  
>> 
>> I'm blind: why does !vdev->rom imply !vdev->rom_size?
>
> See vfio_pci_load_rom(), rom_size and rom are set and allocated
> together.

What if vfio_pci_load_rom() isn't called, or returns before it sets
these guys?

>> Moreover, when MIN(size, vdev->rom_size - addr) < size, we seem to read
>> uninitialized data from @val:
>
> This is fixed in my patch
> https://lists.gnu.org/archive/html/qemu-devel/2020-03/msg02778.html

Yes.

>> 
>> switch (size) {
>> case 1:
>> data = val.byte;
>> break;
>> case 2:
>> data = le16_to_cpu(val.word);
>> break;
>> case 4:
>> data = le32_to_cpu(val.dword);
>> break;
>> default:
>> hw_error("vfio: unsupported read size, %d bytes\n", size);
>> break;
>> }
>> 
>> trace_vfio_rom_read(vdev->vbasedev.name, addr, size, data);
>> 
>> return data;
>> }
>> 
>> Why is that okay?
>> 
>> Why do we initialize @data?
>
> Bug.  The switch was only added later (75bd0c7253f3) and we failed to
> catch it.  Prior to that we were initializing val and the memcpy() only
> overwrote it as necessary.  In any case, getting back garbage for the
> rom when there isn't one generally works ok since the chances of
> generating a proper rom signature are infinitesimal.  Clearly not what
> was intended though.
>
>> How can we get to the default case?  If we can get there, is hw_error()
>> really the right thing to do?  It almost never is...  If getting there
>> is the guest's fault, we need to tell it off the same 

Qemu master crashing on boot when using file backend for memory

2020-03-11 Thread Raphael Norwitz
When I try run master qemu I am hitting a divide by zero error. It seems
to be coming from util/oslib-posix.c in touch_all_pages(). see line 477:

numpages_per_thread = numpages / memset_num_threads;

Poking around the crash dumps, I can see that the smp_cpus parameter
passed in to touch_all_pages() is 0. Going up the stack to
host_memory_backend_memory_complete() I see backend->prealloc_threads is
also 0.

Here’s how I am running qemu

./x86_64-softmmu/qemu-system-x86_64 \
-kernel /boot/vmlinuz-3.10.0-1062.el7.x86_64  \
-netdev user,id=net0,hostfwd=tcp::2250-:22 \
-device e1000e,netdev=net0 \
-m 1G \
-initrd /boot/initramfs-3.10.0-1062.el7.x86_64.img  \
-object 
memory-backend-file,id=ram-node0,prealloc=yes,mem-path=mem,share=yes,size=1G \
-numa node,nodeid=0,cpus=0,memdev=ram-node0 

I don't see this error on a slightly older qemu, as of commit 105b07f1
(January 27th).

Interestingly when I remove the memory-backend-file parameter I don’t
see the error, i.e. this works:

./x86_64-softmmu/qemu-system-x86_64 \
-kernel /boot/vmlinuz-3.10.0-1062.el7.x86_64  \
-netdev user,id=net0,hostfwd=tcp::2250-:22 \
-device e1000e,netdev=net0 \
-m 1G \
-initrd /boot/initramfs-3.10.0-1062.el7.x86_64.img

Looking at the blame data for backends/hostmem.c I see commit ffac16fa
introduced some churn in this part of the code. Has anyone else seen
this issue? Could I be doing something wrong here?



Re: [PATCH 1/2] Use -isystem for linux-headers dir

2020-03-11 Thread Michael S. Tsirkin
On Wed, Mar 11, 2020 at 07:08:06PM -0400, Eduardo Habkost wrote:
> On Wed, Mar 11, 2020 at 07:05:45PM -0400, Michael S. Tsirkin wrote:
> > On Wed, Mar 11, 2020 at 06:51:29PM -0400, Eduardo Habkost wrote:
> > > glibc and Linux-provided headers are known to generate macro
> > > redefinition warnings when used together.  For example:
> > >  and  duplicate some macro definitions.
> > > 
> > > We normally never see those warnings because GCC suppresses
> > > warnings generated by system headers.  We carry our own copy of
> > > Linux header files, though, and this makes those warnings not be
> > > suppressed when glibc headers are included before Linux headers
> > > (e.g. if  is included before ).
> > > 
> > > Use -isystem instead of -I for linux-headers.  This makes the
> > > compiler treat our linux-headers directory the same way it treats
> > > system-provided Linux headers, and suppress warnings generated by
> > > them.
> > > 
> > > Signed-off-by: Eduardo Habkost 
> > > ---
> > >  Makefile.target | 2 +-
> > >  configure   | 2 +-
> > >  2 files changed, 2 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/Makefile.target b/Makefile.target
> > > index 2d43dc586a..934a9f7431 100644
> > > --- a/Makefile.target
> > > +++ b/Makefile.target
> > > @@ -12,7 +12,7 @@ endif
> > >  
> > >  $(call set-vpath, $(SRC_PATH):$(BUILD_DIR))
> > >  ifdef CONFIG_LINUX
> > > -QEMU_CFLAGS += -I../linux-headers
> > > +QEMU_CFLAGS += -isystem ../linux-headers
> > >  endif
> > >  QEMU_CFLAGS += -iquote .. -iquote $(SRC_PATH)/target/$(TARGET_BASE_ARCH) 
> > > -DNEED_CPU_H
> > >  
> > > diff --git a/configure b/configure
> > > index cbf864bff1..04a2a7f2dd 100755
> > > --- a/configure
> > > +++ b/configure
> > > @@ -899,7 +899,7 @@ Linux)
> > >linux="yes"
> > >linux_user="yes"
> > >kvm="yes"
> > > -  QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$PWD/linux-headers 
> > > $QEMU_INCLUDES"
> > > +  QEMU_INCLUDES="-isystem \$(SRC_PATH)/linux-headers 
> > > -I$PWD/linux-headers $QEMU_INCLUDES"
> > 
> > Shouldn't both be -isystem?
> 
> I haven't noticed we had both.
> 
> This line looks weird, does anybody know why we have
> $PWD/linux-headers here?

Look at the build directory and you'll figure it out:

$ ls -l $PWD/linux-headers/
total 0
lrwxrwxrwx. 1 mst mst 31 Mar 10 05:59 asm -> /scm/qemu/linux-headers/asm-x86


Introduced here:

commit a585140dd546ffb606ec506b362ab9decf1ab14e
Author: Alexey Kardashevskiy 
Date:   Wed May 29 23:30:43 2013 +1000

qemu: fix out of tree cross compile

The symlink to "asm" platform linux headers is made in the build tree by
the configure script but gcc is not told to look for them there.

The patch fixes this.

Signed-off-by: Alexey Kardashevskiy 
Signed-off-by: Michael Tokarev 

-- 
MST




[Bug 1867072] Re: ARM: tag bits cleared in FAR_EL1

2020-03-11 Thread Richard Henderson
As it happens, I posted some cleanups for this last week:
https://patchew.org/QEMU/20200302175829.2183-1-richard.hender...@linaro.org/

Some of them have been queued to Peter's target-arm.next branch,
but that hasn't made it to master yet.

** Changed in: qemu
   Status: New => In Progress

** Changed in: qemu
 Assignee: (unassigned) => Richard Henderson (rth)

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

Title:
  ARM: tag bits cleared in FAR_EL1

Status in QEMU:
  In Progress

Bug description:
  The ARM Architecture Reference Manual provides the following for
  FAR_EL1:

  "For a Data Abort or Watchpoint exception, if address tagging is
  enabled for the address accessed by the data access that caused the
  exception, then this field includes the tag."

  However, I have found that the tag bits in FAR_EL1 are always clear,
  even if the tag bits were set in the original access.

  I can reproduce the problem on both 4.1.1 and master
  (6e8a73e911f066527e775e04b98f31ebd19db600).

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



[Bug 1867072] Re: ARM: tag bits cleared in FAR_EL1

2020-03-11 Thread Richard Henderson
Actually, I take that back: Peter has merged my TBI patch set,
and is included in 6e8a73e911f066.

Do you have a test case?

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

Title:
  ARM: tag bits cleared in FAR_EL1

Status in QEMU:
  In Progress

Bug description:
  The ARM Architecture Reference Manual provides the following for
  FAR_EL1:

  "For a Data Abort or Watchpoint exception, if address tagging is
  enabled for the address accessed by the data access that caused the
  exception, then this field includes the tag."

  However, I have found that the tag bits in FAR_EL1 are always clear,
  even if the tag bits were set in the original access.

  I can reproduce the problem on both 4.1.1 and master
  (6e8a73e911f066527e775e04b98f31ebd19db600).

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



Re: Re: [PATCH] mem-prealloc: initialize cond and mutex(Internet mail)

2020-03-11 Thread 陈蒙蒙
ok ,thanks Paolo

bauer
 
From: Paolo Bonzini
Date: 2020-03-12 02:34
To: bauerchen(陈蒙蒙); Igor Mammedov
CC: borntraeger; qemu-devel; qemu-s390x; mhartmay
Subject: Re: [PATCH] mem-prealloc: initialize cond and mutex(Internet mail)
On 10/03/20 08:06, bauerchen(陈蒙蒙) wrote:
> oh ,yes.Thanks
> I want to know if I submit a new fixed patch or just a patch fixed
> current problem?? 
> if a new fixed patch, maybe need a revert ?
 
Sorry I missed this message.  I have already sent a fixed patch, thanks!
 
Paolo
 
> 
> bauerchen(陈蒙蒙)
>
>  
> *From:* Igor Mammedov 
> *Date:* 2020-03-09 21:19
> *To:* bauerchen(陈蒙蒙) 
> *CC:* borntraeger ; pbonzini
> ; qemu-devel
> ; qemu-s390x
> ; mhartmay 
> *Subject:* Re: [PATCH] mem-prealloc: initialize cond and
> mutex(Internet mail)
> On Mon, 9 Mar 2020 11:16:10 +
> bauerchen(陈蒙蒙)  wrote:
>  
> > Thanks,  in fact,do_touch_pages is called just when vm starts up,
> but using init flag and Gonce maybe more elegant !
> > if needed,I can submit a new patch !
> > thanks very much!
>  
> it's called from os_mem_prealloc() -> touch_all_pages() which is called
> at least once per an instance of hotsmem backend. So if several backends
> are used then it should be called several times.
> The same applies when a hostmem backend is added during runtime
> (hotplug)
>  
>  
>
 
 

Re: [PATCH 02/16] accel/tcg: Add probe_access_flags

2020-03-11 Thread Richard Henderson
On 3/10/20 11:44 PM, Richard Henderson wrote:
> +int probe_access_flags(CPUArchState *env, target_ulong addr,
> +   MMUAccessType access_type, int mmu_idx,
> +   bool nonfault, void **phost, uintptr_t retaddr)
> +{
> +void *host;
> +int flags;
> +
> +flags = probe_access_internal(env, addr, 0, access_type, mmu_idx,
> +  nonfault, , retaddr);

Bug here.  Should have passed along phost to probe_access_internal instead of a
new local host variable.

I've sent a v2 for this patch, in-reply-to.  I'll not repost the whole patch
set until I've also addressed any review.


r~



[PATCH v2 02/16] accel/tcg: Add probe_access_flags

2020-03-11 Thread Richard Henderson
This new interface will allow targets to probe for a page
and then handle watchpoints themselves.  This will be most
useful for vector predicated memory operations, where one
page lookup can be used for many operations, and one test
can avoid many watchpoint checks.

Signed-off-by: Richard Henderson 
---
v2: Fix return of host pointer in softmmu probe_access_flags.
---
 include/exec/cpu-all.h  |  13 ++-
 include/exec/exec-all.h |  22 +
 accel/tcg/cputlb.c  | 177 
 accel/tcg/user-exec.c   |  36 +---
 4 files changed, 149 insertions(+), 99 deletions(-)

diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index 49384bb66a..43ddcf024c 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -328,7 +328,18 @@ CPUArchState *cpu_copy(CPUArchState *env);
  | CPU_INTERRUPT_TGT_EXT_3   \
  | CPU_INTERRUPT_TGT_EXT_4)
 
-#if !defined(CONFIG_USER_ONLY)
+#ifdef CONFIG_USER_ONLY
+
+/*
+ * Allow some level of source compatibility with softmmu.  We do not
+ * support any of the more exotic features, so only invalid pages may
+ * be signaled by probe_access_flags().
+ */
+#define TLB_INVALID_MASK(1 << (TARGET_PAGE_BITS_MIN - 1))
+#define TLB_MMIO0
+#define TLB_WATCHPOINT  0
+
+#else
 
 /*
  * Flags stored in the low bits of the TLB virtual address.
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index d656a1f05c..8792bea07a 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -362,6 +362,28 @@ static inline void *probe_read(CPUArchState *env, 
target_ulong addr, int size,
 return probe_access(env, addr, size, MMU_DATA_LOAD, mmu_idx, retaddr);
 }
 
+/**
+ * probe_access_flags:
+ * @env: CPUArchState
+ * @addr: guest virtual address to look up
+ * @access_type: read, write or execute permission
+ * @mmu_idx: MMU index to use for lookup
+ * @nonfault: suppress the fault
+ * @phost: return value for host address
+ * @retaddr: return address for unwinding
+ *
+ * Similar to probe_access, loosely returning the TLB_FLAGS_MASK for
+ * the page, and storing the host address for RAM in @phost.
+ *
+ * If @nonfault is set, do not raise an exception but return TLB_INVALID_MASK.
+ * Do not handle watchpoints, but include TLB_WATCHPOINT in the returned flags.
+ * Do handle clean pages, so exclude TLB_NOTDIRY from the returned flags.
+ * For simplicity, all "mmio-like" flags are folded to TLB_MMIO.
+ */
+int probe_access_flags(CPUArchState *env, target_ulong addr,
+   MMUAccessType access_type, int mmu_idx,
+   bool nonfault, void **phost, uintptr_t retaddr);
+
 #define CODE_GEN_ALIGN   16 /* must be >= of the size of a icache line 
*/
 
 /* Estimated block size for TB allocation.  */
diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c
index e3b5750c3b..bbe265ce28 100644
--- a/accel/tcg/cputlb.c
+++ b/accel/tcg/cputlb.c
@@ -1231,86 +1231,16 @@ static void notdirty_write(CPUState *cpu, vaddr 
mem_vaddr, unsigned size,
 }
 }
 
-/*
- * Probe for whether the specified guest access is permitted. If it is not
- * permitted then an exception will be taken in the same way as if this
- * were a real access (and we will not return).
- * If the size is 0 or the page requires I/O access, returns NULL; otherwise,
- * returns the address of the host page similar to tlb_vaddr_to_host().
- */
-void *probe_access(CPUArchState *env, target_ulong addr, int size,
-   MMUAccessType access_type, int mmu_idx, uintptr_t retaddr)
+static int probe_access_internal(CPUArchState *env, target_ulong addr,
+ int fault_size, MMUAccessType access_type,
+ int mmu_idx, bool nonfault,
+ void **phost, uintptr_t retaddr)
 {
 uintptr_t index = tlb_index(env, mmu_idx, addr);
 CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr);
-target_ulong tlb_addr;
-size_t elt_ofs;
-int wp_access;
-
-g_assert(-(addr | TARGET_PAGE_MASK) >= size);
-
-switch (access_type) {
-case MMU_DATA_LOAD:
-elt_ofs = offsetof(CPUTLBEntry, addr_read);
-wp_access = BP_MEM_READ;
-break;
-case MMU_DATA_STORE:
-elt_ofs = offsetof(CPUTLBEntry, addr_write);
-wp_access = BP_MEM_WRITE;
-break;
-case MMU_INST_FETCH:
-elt_ofs = offsetof(CPUTLBEntry, addr_code);
-wp_access = BP_MEM_READ;
-break;
-default:
-g_assert_not_reached();
-}
-tlb_addr = tlb_read_ofs(entry, elt_ofs);
-
-if (unlikely(!tlb_hit(tlb_addr, addr))) {
-if (!victim_tlb_hit(env, mmu_idx, index, elt_ofs,
-addr & TARGET_PAGE_MASK)) {
-tlb_fill(env_cpu(env), addr, size, access_type, mmu_idx, retaddr);
-/* TLB resize via tlb_fill may have moved the entry. */
-index = tlb_index(env, mmu_idx, addr);
-entry = tlb_entry(env, mmu_idx, addr);
-

[Bug 1653577] Re: Ability to set umask for 9pfs

2020-03-11 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/1653577

Title:
  Ability to set umask for 9pfs

Status in QEMU:
  Expired

Bug description:
  We should be able to specify the umask for 9pfs so that files created
  by the guest can be accessed by other users on the host. Currently
  they're only accessible by the user running qemu (and of course,
  root).

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



Re: [PATCH v3 2/2] spapr: Enable virtio iommu_platform=on by default

2020-03-11 Thread Alexey Kardashevskiy



On 10/03/2020 21:43, Greg Kurz wrote:
> On Thu, 5 Mar 2020 12:59:03 +0100
> Greg Kurz  wrote:
> 
>> On Thu,  5 Mar 2020 15:30:09 +1100
>> David Gibson  wrote:
>>
>>> Traditionally, virtio devices don't do DMA by the usual path on the
>>> guest platform.  In particular they usually bypass any virtual IOMMU
>>> the guest has, using hypervisor magic to access untranslated guest
>>> physical addresses.
>>>
>>> There's now the optional iommu_platform flag which can tell virtio
>>> devices to use the platform's normal DMA path, including any IOMMUs.
>>> That flag was motiviated for the case of hardware virtio
>>> implementations, but there are other reasons to want it.
>>>
>>> Specifically, the fact that the virtio device doesn't use vIOMMU
>>> translation means that virtio devices are unsafe to pass to nested
>>> guests, or to use with VFIO userspace drivers inside the guest.  This
>>> is particularly noticeable on the pseries platform which *always* has
>>> a guest-visible vIOMMU.
>>>
>>> Not using the normal DMA path also causes difficulties for the guest
>>> side driver when using the upcoming POWER Secure VMs (a.k.a. PEF).
>>> While it's theoretically possible to handle this on the guest side,
>>> it's really fiddly.  Given the other problems with the non-translated
>>> virtio device, let's just enable vIOMMU translation for virtio devices
>>> by default in the pseries-5.0 (and later) machine types.
>>>
>>> This does mean the new machine type will no longer support guest
>>> kernels older than 4.8, unless they have support for the virtio
>>> IOMMU_PLATFORM flag backported (which some distro kernels like RHEL7
>>> do).
>>>
>>> Signed-off-by: David Gibson 
>>> ---
>>
>> The patch looks good but I'm not sure if we're quite ready to merge
>> it yet. With this applied, I get zero output on a virtio-serial based
>> console:
>>
>> ie.
>>   -chardev stdio,id=con0 -device virtio-serial -device 
>> virtconsole,chardev=con0 
>>
>> FYI, virtio-serial is a bit broken for spapr with iommu_platform=off already:
>>
>> (1) pressing a key in the console during SLOF or grub has no effect
>>
>> (2) the guest kernel boot stays stuck around quiesce
>>
>> These are regressions introduced by this SLOF update:
>>
>> a363e9ed8731f45674260932a340a0d81c4b0a6f is the first bad commit
>> commit a363e9ed8731f45674260932a340a0d81c4b0a6f
>> Author: Alexey Kardashevskiy 
>> Date:   Tue Dec 17 11:31:54 2019 +1100
>> pseries: Update SLOF firmware image
>>
>> A trivial fix was already posted on the SLOF list for (1) :
>>
>> https://patchwork.ozlabs.org/patch/1249338/
>>
>> (2) is still under investigation but the console is _at least_
>> functional until the guest OS takes control. This is no longer
>> the case with this patch.
>>
> 
> Some progress was made on the SLOF front:
> 
> https://patchwork.ozlabs.org/project/slof/list/?series=163314
> 
> With these series applied to SLOF, I can now boot a fedora31 guest
> with a virtio-serial console and iommu_platform=on... but now
> I'm trying out other virtio devices supported by SLOF and I'm
> running into issues around virtio-pci.disable-legacy as mentioned
> in some other mail...
> 
> It seems we may not be ready to merge this series yet.


fwiw I sent a pull request:

https://lore.kernel.org/qemu-devel/20200312041010.16229-1-...@ozlabs.ru/T/#u



> 
>>>  hw/ppc/spapr.c | 2 ++
>>>  1 file changed, 2 insertions(+)
>>>
>>> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
>>> index 3cfc98ac61..5ef099536e 100644
>>> --- a/hw/ppc/spapr.c
>>> +++ b/hw/ppc/spapr.c
>>> @@ -4575,6 +4575,7 @@ static void 
>>> spapr_machine_latest_class_options(MachineClass *mc)
>>>   */
>>>  static GlobalProperty compat[] = {
>>>  { TYPE_VIRTIO_PCI, "disable-legacy", "on", },
>>> +{ TYPE_VIRTIO_DEVICE, "iommu_platform", "on", },
>>>  };
>>>  
>>>  mc->alias = "pseries";
>>> @@ -4622,6 +4623,7 @@ static void 
>>> spapr_machine_4_2_class_options(MachineClass *mc)
>>>  SpaprMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
>>>  static GlobalProperty compat[] = {
>>>  { TYPE_VIRTIO_PCI, "disable-legacy", "auto" },
>>> +{ TYPE_VIRTIO_DEVICE, "iommu_platform", "off", },
>>>  };
>>>  
>>>  spapr_machine_5_0_class_options(mc);
>>
> 

-- 
Alexey



[PULL SUBSYSTEM qemu-pseries] pseries: Update SLOF firmware image

2020-03-11 Thread Alexey Kardashevskiy
The following changes since commit 0ba04f78e7c37748db89885249a653b28c962bd9:

  ppc/spapr: Move GPRs setup to one place (2020-03-12 10:21:16 +1100)

are available in the Git repository at:

  g...@github.com:aik/qemu.git tags/qemu-slof-20200312

for you to fetch changes up to 8b1987b232d0da2df1f33bf9e3e25fcb1874b91d:

  pseries: Update SLOF firmware image (2020-03-12 15:04:40 +1100)


Alexey Kardashevskiy (1):
  pseries: Update SLOF firmware image

 pc-bios/README   |   2 +-
 pc-bios/slof.bin | Bin 968616 -> 968848 bytes
 roms/SLOF|   2 +-
 3 files changed, 2 insertions(+), 2 deletions(-)


*** Note: this is not for master, this is for pseries


This mainly fixes virtio-serial with and without
enabled iommu-platform.

The full list of changes is:

Alexey Kardashevskiy (3):
  llfw: Fix debug printf warnings
  virtio-serial: Close device completely
  version: update to 20200312

Cédric Le Goater (1):
  virtio: Fix typo in virtio_serial_init()

Greg Kurz (2):
  virtio-serial: Don't override some words
  virtio-serial: Rework shutdown sequence




Re: [PATCH] acpi: Add Windows ACPI Emulated Device Table (WAET)

2020-03-11 Thread Liran Alon



On 11/03/2020 22:24, Michael S. Tsirkin wrote:

Notice the process as documented in ./tests/qtest/bios-tables-test.c


Thanks for explicitly pointing me to that process.

I have followed the process described there (Both steps 1-3 and steps 4-7).

On step (6), I have noted that many existing ACPI tables don't have 
expected binaries for all the execution-matrix.
E.g. tests/data/acpi/pc/APIC.{bridge, ipmikcs, memhp, numamem} are all 
missing.

Similar missing files exists for FACP, FACS, HPET and MCFG.

I should add for WAET the expected binaries for all the execution-matrix 
right?
Is it just an existing issue that for the existing tables some of the 
expected binaries are missing? But the tests seems to pass.

Can you clarify this for me?

Thanks,
-Liran





Re: [PATCH qemu v8 3/3] spapr: Implement Open Firmware client interface

2020-03-11 Thread Alexey Kardashevskiy



On 11/03/2020 20:43, Paolo Bonzini wrote:
> On 10/03/20 06:07, Alexey Kardashevskiy wrote:
>> The PAPR platform which describes an OS environment that's presented by
>> a combination of a hypervisor and firmware. The features it specifies
>> require collaboration between the firmware and the hypervisor.
>>
>> Since the beginning, the runtime component of the firmware (RTAS) has
>> been implemented as a 20 byte shim which simply forwards it to
>> a hypercall implemented in qemu. The boot time firmware component is
>> SLOF - but a build that's specific to qemu, and has always needed to be
>> updated in sync with it. Even though we've managed to limit the amount
>> of runtime communication we need between qemu and SLOF, there's some,
>> and it has become increasingly awkward to handle as we've implemented
>> new features.
>>
>> This implements a boot time OF client interface (CI) which is
>> enabled by a new "x-vof" pseries machine option (stands for "Virtual Open
>> Firmware). When enabled, QEMU implements the custom H_OF_CLIENT hcall
>> which implements Open Firmware Client Interface (OF CI). This allows
>> using a smaller stateless firmware which does not have to manage
>> the device tree.
>>
>> The new "vof.bin" firmware image is included with source code under
>> pc-bios/. It also includes RTAS blob.
>>
>> This implements a handful of CI methods just to get -kernel/-initrd
>> working. In particular, this implements the device tree fetching and
>> simple memory allocator - "claim" (an OF CI memory allocator) and updates
>> "/memory@0/available" to report the client about available memory.
>>
>> This implements changing some device tree properties which we know how
>> to deal with, the rest is ignored. To allow changes, this skips
>> fdt_pack() when x-vof=on as not packing the blob leaves some room for
>> appending.
>>
>> In absence of SLOF, this assigns "phandles" to device tree nodes to make
>> device tree traversing work.
>>
>> When x-vof=on, this adds "/chosen" every time QEMU (re)builds a tree.
>>
>> This adds basic instances support which are managed by a hashmap
>> ihandle -> [phandle].
>>
>> Before the guest started, the used memory is:
>> 0..4000 - the initial firmware
>> 1..18 - stack
>>
>> This OF CI does not implement "interpret".
>>
>> With this basic support, this can only boot into kernel directly.
>> However this is just enough for the petitboot kernel and initradmdisk to
>> boot from any possible source. Note this requires reasonably recent guest
>> kernel with:
>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=df5be5be8735
>>
>> Signed-off-by: Alexey Kardashevskiy 
> 
> Thank you very much Alexey!  At least, since it can run petitboot, it's
> not completely useless.
> 
> Acked-by: Paolo Bonzini 
> 


Cool, thanks! Have you tried it yourself or you are just taking my word
for it? :)


-- 
Alexey



Re: [PATCH v3 1/2] spapr: Disable legacy virtio devices for pseries-5.0 and later

2020-03-11 Thread David Gibson
On Wed, Mar 11, 2020 at 03:11:16AM -0400, Michael S. Tsirkin wrote:
> On Wed, Mar 11, 2020 at 11:58:57AM +1100, David Gibson wrote:
> > Note that several things that I believe are now in the PCIe spec, but
> > really derive more from PC legacy considerations, don't apply at all
> > for PAPR.  e.g. there's no meaningful distinction between integrated
> > and slotted devices, multiple independent host bridges is routine and
> > doesn't require any (virtual) hardware visible domain numbers.
> 
> Domain numbers are a Linux thing, not a PCIe thing. On x86 they come
> from ACPI segment numbers. As such they aren't usually hardware
> visible on x86, they are supplied by firmware.

Oh, ok.  I thought that at least on the standard IO 0xcf8 host bridge
controller the domain number was written into certain registers to
select the relevant root bus.

On POWER the domain numbers are arbitrarily assigned within Linux.
"Hardware" (well, the firmware/hypervisor) uses a different
identifier, called the BUID (generally a large, 64-bit pseudo-address)
in the device tree and hypercalls.

[As an aside, this means the use of domain numbers in libvirt XML is
complete bogosity]

-- 
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: Upstream QEMU guest support policy ? Re: [PATCH v3 0/2] spapr: Use vIOMMU translation for virtio by default

2020-03-11 Thread David Gibson
On Wed, Mar 11, 2020 at 03:33:59AM -0400, Michael S. Tsirkin wrote:
> On Wed, Mar 11, 2020 at 12:12:47PM +1100, David Gibson wrote:
> > I am wondering if we have to introduce an "svm=on" flag anyway.  It's
> > pretty ugly, since all it would be doing is changing defaults here and
> > there for compatibilty with a possible future SVM transition, but
> > maybe it's the best we can do :/.
> 
> Frankly I'm surprised there's no way for the hypervisor to block VM
> transition to secure mode. To me an inability to disable DRM looks like
> a security problem.

Uh.. I don't immediately see how it's a security problem, though I'm
certainly convinced it's a problem in other ways.

> Does not the ultravisor somehow allow
> enabling/disabling this functionality from the hypervisor?

Not at present, but as mentioned on the other thread, Paul and I came
up with a tentative plan to change that.

> It would be
> even better if the hypervisor could block the guest from poking at the
> ultravisor completely but I guess that would be too much to hope for.

Yeah, probably :/.

-- 
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: Upstream QEMU guest support policy ? Re: [PATCH v3 0/2] spapr: Use vIOMMU translation for virtio by default

2020-03-11 Thread David Gibson
On Wed, Mar 11, 2020 at 07:48:26AM -0400, Michael S. Tsirkin wrote:
> On Wed, Mar 11, 2020 at 10:01:27AM +, Daniel P. Berrangé wrote:
> > On Wed, Mar 11, 2020 at 12:12:47PM +1100, David Gibson wrote:
> > > On Tue, Mar 10, 2020 at 11:43:43AM +, Daniel P. Berrangé wrote:
> > > > On Thu, Mar 05, 2020 at 03:30:07PM +1100, David Gibson wrote:
> > > > > Upcoming Secure VM support for pSeries machines introduces some
> > > > > complications for virtio, since the transfer buffers need to be
> > > > > explicitly shared so that the hypervisor can access them.
> > > > > 
> > > > > While it's not strictly speaking dependent on it, the fact that virtio
> > > > > devices bypass normal platform IOMMU translation complicates the issue
> > > > > on the guest side.  Since there are some significan downsides to
> > > > > bypassing the vIOMMU anyway, let's just disable that.
> > > > > 
> > > > > There's already a flag to do this in virtio, just turn it on by
> > > > > default for forthcoming pseries machine types.
> > > > 
> > > > Breaking existing guest OS to support a new secure VM feature that
> > > > may not even be used/wanted doesn't seems like a sensible tradeoff
> > > > for default out of the box behaviour.
> > > > 
> > > > IOW, if Secure VM needs this, can we tie the change in virtio and
> > > > IOMMU defaults to the machine type flag that enables the use of
> > > > Secure VM.
> > > 
> > > There is no such flag.
> > > 
> > > In the POWER secure VM model, the secure mode option isn't something
> > > that's constructed in when the hypervisor builds the VM.  Instead the
> > > VM is started normally and transitions itself to secure mode by
> > > talking directly with the ultravisor (it then uses TPM shenannigans to
> > > safely get the keys to its real storage backend(s)).
> > 
> > This is pretty suprising to me. The ability to use secure VM mode surely
> > depends on host hardware features. We would need to be able to block the
> > use of this, in order to allow VMs to be live migrated to hosts which
> > lack the feature. Automatically & silently enabling a feature that
> > has a hardware dependancy is something we aim to avoid, unless the user
> > has opted in via some flag (such as -cpu host, or a -cpu $NAME, that
> > implies the feature).
> 
> That's something I don't know. Is migration supported in this mode?

Not at this stage, though there's plans for it later.

-- 
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: Upstream QEMU guest support policy ? Re: [PATCH v3 0/2] spapr: Use vIOMMU translation for virtio by default

2020-03-11 Thread David Gibson
On Wed, Mar 11, 2020 at 10:01:27AM +, Daniel P. Berrangé wrote:
65;5803;1c> On Wed, Mar 11, 2020 at 12:12:47PM +1100, David Gibson wrote:
> > On Tue, Mar 10, 2020 at 11:43:43AM +, Daniel P. Berrangé wrote:
> > > On Thu, Mar 05, 2020 at 03:30:07PM +1100, David Gibson wrote:
> > > > Upcoming Secure VM support for pSeries machines introduces some
> > > > complications for virtio, since the transfer buffers need to be
> > > > explicitly shared so that the hypervisor can access them.
> > > > 
> > > > While it's not strictly speaking dependent on it, the fact that virtio
> > > > devices bypass normal platform IOMMU translation complicates the issue
> > > > on the guest side.  Since there are some significan downsides to
> > > > bypassing the vIOMMU anyway, let's just disable that.
> > > > 
> > > > There's already a flag to do this in virtio, just turn it on by
> > > > default for forthcoming pseries machine types.
> > > 
> > > Breaking existing guest OS to support a new secure VM feature that
> > > may not even be used/wanted doesn't seems like a sensible tradeoff
> > > for default out of the box behaviour.
> > > 
> > > IOW, if Secure VM needs this, can we tie the change in virtio and
> > > IOMMU defaults to the machine type flag that enables the use of
> > > Secure VM.
> > 
> > There is no such flag.
> > 
> > In the POWER secure VM model, the secure mode option isn't something
> > that's constructed in when the hypervisor builds the VM.  Instead the
> > VM is started normally and transitions itself to secure mode by
> > talking directly with the ultravisor (it then uses TPM shenannigans to
> > safely get the keys to its real storage backend(s)).
> 
> This is pretty suprising to me. The ability to use secure VM mode surely
> depends on host hardware features. We would need to be able to block the
> use of this, in order to allow VMs to be live migrated to hosts which
> lack the feature. Automatically & silently enabling a feature that
> has a hardware dependancy is something we aim to avoid, unless the user
> has opted in via some flag (such as -cpu host, or a -cpu $NAME, that
> implies the feature).

That is an excellent point, which I had not previously considered.

I have confirmed that there is indeed not, at present, a way to
disable the secure transition.  But, it looks like it's not too late
to fix it.

I've discussed with Paul Mackerras, and early in the secure transition
apparently the UV makes a call to the HV, which is allowed to fail.

So, we're looking at adding another KVM capability for secure mode.
It will default to disabled, and until it is explicitly enabled, KVM
will always fail that call from the UV, effectively preventing guests
from going into secure mode.

We can then wire that up to a new spapr cap in qemu, which we can also
use to configure these virtio defaults.

-- 
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


[Bug 1867072] [NEW] ARM: tag bits cleared in FAR_EL1

2020-03-11 Thread Peter Collingbourne
Public bug reported:

The ARM Architecture Reference Manual provides the following for
FAR_EL1:

"For a Data Abort or Watchpoint exception, if address tagging is enabled
for the address accessed by the data access that caused the exception,
then this field includes the tag."

However, I have found that the tag bits in FAR_EL1 are always clear,
even if the tag bits were set in the original access.

I can reproduce the problem on both 4.1.1 and master
(6e8a73e911f066527e775e04b98f31ebd19db600).

** Affects: qemu
 Importance: Undecided
 Status: New

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

Title:
  ARM: tag bits cleared in FAR_EL1

Status in QEMU:
  New

Bug description:
  The ARM Architecture Reference Manual provides the following for
  FAR_EL1:

  "For a Data Abort or Watchpoint exception, if address tagging is
  enabled for the address accessed by the data access that caused the
  exception, then this field includes the tag."

  However, I have found that the tag bits in FAR_EL1 are always clear,
  even if the tag bits were set in the original access.

  I can reproduce the problem on both 4.1.1 and master
  (6e8a73e911f066527e775e04b98f31ebd19db600).

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



[PATCH v3 2/2] target/arm: kvm: Handle DABT with no valid ISS

2020-03-11 Thread Beata Michalska
On ARMv7 & ARMv8 some load/store instructions might trigger a data abort
exception with no valid ISS info to be decoded. The lack of decode info
makes it at least tricky to emulate those instruction which is one of the
(many) reasons why KVM will not even try to do so.

Add support for handling those by requesting KVM to inject external
dabt into the quest.

Signed-off-by: Beata Michalska 
---
 target/arm/cpu.h |  3 ++
 target/arm/kvm.c | 81 
 target/arm/kvm32.c   | 26 +
 target/arm/kvm64.c   | 36 +++
 target/arm/kvm_arm.h | 22 ++
 5 files changed, 168 insertions(+)

diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 4ffd991..45fdd2e 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -560,6 +560,9 @@ typedef struct CPUARMState {
 uint64_t esr;
 } serror;
 
+uint8_t ext_dabt_pending:1; /* Request for injecting ext DABT */
+uint8_t ext_dabt_raised:1; /* Tracking/verifying injection of ext DABT */
+
 /* State of our input IRQ/FIQ/VIRQ/VFIQ lines */
 uint32_t irq_line_state;
 
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
index 85860e6..8b7b708 100644
--- a/target/arm/kvm.c
+++ b/target/arm/kvm.c
@@ -39,6 +39,7 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
 
 static bool cap_has_mp_state;
 static bool cap_has_inject_serror_esr;
+static bool cap_has_inject_ext_dabt;
 
 static ARMHostCPUFeatures arm_host_cpu_features;
 
@@ -244,6 +245,16 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
 ret = -EINVAL;
 }
 
+if (kvm_check_extension(s, KVM_CAP_ARM_NISV_TO_USER)) {
+if (kvm_vm_enable_cap(s, KVM_CAP_ARM_NISV_TO_USER, 0)) {
+warn_report("Failed to enable DABT NISV cap");
+} else {
+/* Set status for supporting the external dabt injection */
+cap_has_inject_ext_dabt = kvm_check_extension(s,
+KVM_CAP_ARM_INJECT_EXT_DABT);
+}
+}
+
 return ret;
 }
 
@@ -703,9 +714,20 @@ int kvm_put_vcpu_events(ARMCPU *cpu)
 events.exception.serror_esr = env->serror.esr;
 }
 
+if (cap_has_inject_ext_dabt) {
+events.exception.ext_dabt_pending = env->ext_dabt_pending;
+}
+
 ret = kvm_vcpu_ioctl(CPU(cpu), KVM_SET_VCPU_EVENTS, );
 if (ret) {
 error_report("failed to put vcpu events");
+} else if (env->ext_dabt_pending) {
+/*
+ * Mark that the external DABT has been injected,
+ * if one has been requested
+ */
+env->ext_dabt_raised = env->ext_dabt_pending;
+env->ext_dabt_pending = 0;
 }
 
 return ret;
@@ -737,6 +759,30 @@ int kvm_get_vcpu_events(ARMCPU *cpu)
 
 void kvm_arch_pre_run(CPUState *cs, struct kvm_run *run)
 {
+ARMCPU *cpu = ARM_CPU(cs);
+CPUARMState *env = >env;
+
+if (unlikely(env->ext_dabt_raised)) {
+/*
+ * Verifying that the ext DABT has been properly injected,
+ * otherwise risking indefinitely re-running the faulting instruction
+ * Covering a very narrow case for kernels 5.5..5.5.4
+ * when injected abort was misconfigured to be
+ * an IMPLEMENTATION DEFINED exception (for 32-bit EL1)
+ */
+if (!arm_feature(env, ARM_FEATURE_AARCH64) &&
+unlikely(kvm_arm_verify_ext_dabt_pending(cs))) {
+
+error_report("Data abort exception with no valid ISS generated by "
+   "guest memory access. KVM unable to emulate faulting "
+   "instruction. Failed to inject an external data abort "
+   "into the guest.");
+abort();
+   }
+   /* Clear the status */
+   env->ext_dabt_raised = 0;
+}
+
 }
 
 MemTxAttrs kvm_arch_post_run(CPUState *cs, struct kvm_run *run)
@@ -819,6 +865,11 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
 ret = EXCP_DEBUG;
 } /* otherwise return to guest */
 break;
+case KVM_EXIT_ARM_NISV:
+/* External DABT with no valid iss to decode */
+ret = kvm_arm_handle_dabt_nisv(cs, run->arm_nisv.esr_iss,
+   run->arm_nisv.fault_ipa);
+break;
 default:
 qemu_log_mask(LOG_UNIMP, "%s: un-handled exit reason %d\n",
   __func__, run->exit_reason);
@@ -953,3 +1004,33 @@ int kvm_arch_msi_data_to_gsi(uint32_t data)
 {
 return (data - 32) & 0x;
 }
+
+int kvm_arm_handle_dabt_nisv(CPUState *cs, uint64_t esr_iss,
+ uint64_t fault_ipa)
+{
+ARMCPU *cpu = ARM_CPU(cs);
+CPUARMState *env = >env;
+
+   /*
+* ISS [23:14] is invalid so there is a limited info
+* on what has just happened so the only *useful* thing that can
+* be retrieved from ISS is WnR & DFSC (though in some cases WnR
+* might be less of a value as well)
+*/
+
+/*
+ * Set pending ext dabt and trigger SET_EVENTS so that

[PATCH v3 1/2] target/arm: kvm: Inject events at the last stage of sync

2020-03-11 Thread Beata Michalska
KVM_SET_VCPU_EVENTS might actually lead to vcpu registers being modified.
As such this should be the last step of sync to avoid potential overwriting
of whatever changes KVM might have done.

Signed-off-by: Beata Michalska 
---
 target/arm/kvm32.c | 15 ++-
 target/arm/kvm64.c | 15 ++-
 2 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/target/arm/kvm32.c b/target/arm/kvm32.c
index f703c4f..f271181 100644
--- a/target/arm/kvm32.c
+++ b/target/arm/kvm32.c
@@ -409,17 +409,22 @@ int kvm_arch_put_registers(CPUState *cs, int level)
 return ret;
 }
 
-ret = kvm_put_vcpu_events(cpu);
-if (ret) {
-return ret;
-}
-
 write_cpustate_to_list(cpu, true);
 
 if (!write_list_to_kvmstate(cpu, level)) {
 return EINVAL;
 }
 
+/*
+ * Setting VCPU events should be triggered after syncing the registers
+ * to avoid overwriting potential changes made by KVM upon calling
+ * KVM_SET_VCPU_EVENTS ioctl
+ */
+ret = kvm_put_vcpu_events(cpu);
+if (ret) {
+return ret;
+}
+
 kvm_arm_sync_mpstate_to_kvm(cpu);
 
 return ret;
diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c
index 93ba144..be5b31c 100644
--- a/target/arm/kvm64.c
+++ b/target/arm/kvm64.c
@@ -1094,17 +1094,22 @@ int kvm_arch_put_registers(CPUState *cs, int level)
 return ret;
 }
 
-ret = kvm_put_vcpu_events(cpu);
-if (ret) {
-return ret;
-}
-
 write_cpustate_to_list(cpu, true);
 
 if (!write_list_to_kvmstate(cpu, level)) {
 return -EINVAL;
 }
 
+   /*
+* Setting VCPU events should be triggered after syncing the registers
+* to avoid overwriting potential changes made by KVM upon calling
+* KVM_SET_VCPU_EVENTS ioctl
+*/
+ret = kvm_put_vcpu_events(cpu);
+if (ret) {
+return ret;
+}
+
 kvm_arm_sync_mpstate_to_kvm(cpu);
 
 return ret;
-- 
2.7.4




[PATCH v3 0/2] target/arm: kvm: Support for KVM DABT with no valid ISS

2020-03-11 Thread Beata Michalska
Some of the ARMv7 & ARMv8 load/store instructions might trigger a data abort
exception with no valid ISS info to be decoded. The lack of decode info
makes it at least tricky to emulate the instruction which is one of the
(many) reasons why KVM will not even try to do so.

So far, if a guest made an attempt to access memory outside the memory slot,
KVM reported vague ENOSYS. As a result QEMU exited with no useful information
being provided or even a clue on what has just happened.

ARM KVM introduced support for notifying of an attempt to execute
an instruction that resulted in dabt with no valid ISS decoding info.
This still leaves QEMU to handle the case, but at least now it gives more
control and a start point for more meaningful handling of such cases.

This patchset relies on KVM to insert the external data abort into the guest.

v3:
 - Fix setting KVM cap per vm not per vcpu
 - Simplifying the handler to bare minimum with no default logging to address
   the potential risk of overflooding the host (adding support for rate
   limiting the logs turned out to be bit too invasive to justify the little
   add-on value from logs in this particular case)
 - Adding handling KVM bug (for small range of affected kernels):
   little bit of trade-off between what's reasonable and what's effective:
   aborting qemu when running on buggy host kernel

v2:
- Improving/re-phrasing messaging
- Dropping messing around with forced sync (@see [PATCH v2 1/2])
  and PC alignment


Beata Michalska (2):
  target/arm: kvm: Inject events at the last stage of sync
  target/arm: kvm: Handle DABT with no valid ISS

 target/arm/cpu.h |  3 ++
 target/arm/kvm.c | 81 
 target/arm/kvm32.c   | 41 ++
 target/arm/kvm64.c   | 51 +
 target/arm/kvm_arm.h | 22 ++
 5 files changed, 188 insertions(+), 10 deletions(-)

-- 
2.7.4




Re: [PATCH v2 0/2] Fix MAP_SYNC support when host has older glibc version

2020-03-11 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20200311232342.1614944-1-ehabk...@redhat.com/



Hi,

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

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

PASS 1 fdc-test /x86_64/fdc/cmos
PASS 2 fdc-test /x86_64/fdc/no_media_on_start
PASS 3 fdc-test /x86_64/fdc/read_without_media
==9775==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 4 fdc-test /x86_64/fdc/media_change
PASS 5 fdc-test /x86_64/fdc/sense_interrupt
PASS 6 fdc-test /x86_64/fdc/relative_seek
---
PASS 32 test-opts-visitor /visitor/opts/range/beyond
PASS 33 test-opts-visitor /visitor/opts/dict/unvisited
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-coroutine -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="test-coroutine" 
==9823==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
==9823==WARNING: ASan is ignoring requested __asan_handle_no_return: stack top: 
0x7ffda46dc000; bottom 0x7feed101; size: 0x000ed36cc000 (63676661760)
False positive error reports may follow
For details see https://github.com/google/sanitizers/issues/189
PASS 1 test-coroutine /basic/no-dangling-access
---
PASS 11 test-aio /aio/event/wait
PASS 12 test-aio /aio/event/flush
PASS 13 test-aio /aio/event/wait/no-flush-cb
==9838==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 14 test-aio /aio/timer/schedule
PASS 15 test-aio /aio/coroutine/queue-chaining
PASS 16 test-aio /aio-gsource/flush
---
PASS 12 fdc-test /x86_64/fdc/read_no_dma_19
PASS 13 fdc-test /x86_64/fdc/fuzz-registers
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
QTEST_QEMU_BINARY=x86_64-softmmu/qemu-system-x86_64 QTEST_QEMU_IMG=qemu-img 
tests/qtest/ide-test -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="ide-test" 
==9846==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 ide-test /x86_64/ide/identify
PASS 28 test-aio /aio-gsource/timer/schedule
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-aio-multithread -m=quick -k --tap < /dev/null | 
./scripts/tap-driver.pl --test-name="test-aio-multithread" 
==9855==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 test-aio-multithread /aio/multi/lifecycle
==9852==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 2 ide-test /x86_64/ide/flush
PASS 2 test-aio-multithread /aio/multi/schedule
==9872==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 3 ide-test /x86_64/ide/bmdma/simple_rw
==9883==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 3 test-aio-multithread /aio/multi/mutex/contended
PASS 4 ide-test /x86_64/ide/bmdma/trim
==9894==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 4 test-aio-multithread /aio/multi/mutex/handoff
PASS 5 test-aio-multithread /aio/multi/mutex/mcs
PASS 6 test-aio-multithread /aio/multi/mutex/pthread
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-throttle -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="test-throttle" 
==9911==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 test-throttle /throttle/leak_bucket
PASS 2 test-throttle /throttle/compute_wait
PASS 3 test-throttle /throttle/init
---
PASS 14 test-throttle /throttle/config/max
PASS 15 test-throttle /throttle/config/iops_size
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-thread-pool -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="test-thread-pool" 
==9915==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 test-thread-pool /thread-pool/submit
PASS 2 test-thread-pool /thread-pool/submit-aio
PASS 3 test-thread-pool /thread-pool/submit-co
PASS 4 test-thread-pool /thread-pool/submit-many
==9917==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 5 test-thread-pool /thread-pool/cancel
PASS 6 test-thread-pool /thread-pool/cancel-async
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 

Re: [PATCH 0/2] Fix MAP_SYNC support when host has older glibc version

2020-03-11 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20200311225130.1599619-1-ehabk...@redhat.com/



Hi,

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

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

PASS 1 fdc-test /x86_64/fdc/cmos
PASS 2 fdc-test /x86_64/fdc/no_media_on_start
PASS 3 fdc-test /x86_64/fdc/read_without_media
==9860==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 4 fdc-test /x86_64/fdc/media_change
PASS 5 fdc-test /x86_64/fdc/sense_interrupt
PASS 6 fdc-test /x86_64/fdc/relative_seek
---
PASS 33 test-opts-visitor /visitor/opts/dict/unvisited
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-coroutine -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="test-coroutine" 
PASS 11 fdc-test /x86_64/fdc/read_no_dma_18
==9935==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 test-coroutine /basic/no-dangling-access
==9935==WARNING: ASan is ignoring requested __asan_handle_no_return: stack top: 
0x7ffca8617000; bottom 0x7fe69b8b2000; size: 0x00160cd65000 (94704652288)
False positive error reports may follow
For details see https://github.com/google/sanitizers/issues/189
PASS 2 test-coroutine /basic/lifecycle
---
PASS 12 fdc-test /x86_64/fdc/read_no_dma_19
PASS 13 fdc-test /x86_64/fdc/fuzz-registers
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
QTEST_QEMU_BINARY=x86_64-softmmu/qemu-system-x86_64 QTEST_QEMU_IMG=qemu-img 
tests/qtest/ide-test -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="ide-test" 
==9958==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 ide-test /x86_64/ide/identify
PASS 14 test-aio /aio/timer/schedule
==9950==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 15 test-aio /aio/coroutine/queue-chaining
PASS 16 test-aio /aio-gsource/flush
PASS 17 test-aio /aio-gsource/bh/schedule
---
PASS 25 test-aio /aio-gsource/event/wait
PASS 26 test-aio /aio-gsource/event/flush
PASS 27 test-aio /aio-gsource/event/wait/no-flush-cb
==9964==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 2 ide-test /x86_64/ide/flush
==9970==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 3 ide-test /x86_64/ide/bmdma/simple_rw
PASS 28 test-aio /aio-gsource/timer/schedule
==9976==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-aio-multithread -m=quick -k --tap < /dev/null | 
./scripts/tap-driver.pl --test-name="test-aio-multithread" 
PASS 4 ide-test /x86_64/ide/bmdma/trim
==9983==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 test-aio-multithread /aio/multi/lifecycle
==9985==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 2 test-aio-multithread /aio/multi/schedule
PASS 3 test-aio-multithread /aio/multi/mutex/contended
PASS 4 test-aio-multithread /aio/multi/mutex/handoff
PASS 5 test-aio-multithread /aio/multi/mutex/mcs
==10017==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 6 test-aio-multithread /aio/multi/mutex/pthread
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-throttle -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="test-throttle" 
==10029==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 test-throttle /throttle/leak_bucket
PASS 2 test-throttle /throttle/compute_wait
PASS 3 test-throttle /throttle/init
---
PASS 14 test-throttle /throttle/config/max
PASS 15 test-throttle /throttle/config/iops_size
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-thread-pool -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="test-thread-pool" 
==10033==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 test-thread-pool /thread-pool/submit
PASS 2 test-thread-pool /thread-pool/submit-aio
PASS 3 test-thread-pool /thread-pool/submit-co
---
PASS 2 test-hbitmap /hbitmap/size/0
PASS 3 test-hbitmap /hbitmap/size/unaligned
PASS 4 test-hbitmap 

[PATCH v2 1/2] Use -isystem for linux-headers dir

2020-03-11 Thread Eduardo Habkost
glibc and Linux-provided headers are known to generate macro
redefinition warnings when used together.  For example:
 and  duplicate some macro definitions.

We normally never see those warnings because GCC suppresses
warnings generated by system headers.  We carry our own copy of
Linux header files, though, and this makes those warnings not be
suppressed when glibc headers are included before Linux headers
(e.g. if  is included before ).

Use -isystem instead of -I for linux-headers.  This makes the
compiler treat our linux-headers directory the same way it treats
system-provided Linux headers, and suppress warnings generated by
them.

Signed-off-by: Eduardo Habkost 
---
Changes v1 -> v2:
* Use -isystem for $PWD/linux-headers too
  Reported-by: "Michael S. Tsirkin" 
---
 Makefile.target | 2 +-
 configure   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile.target b/Makefile.target
index 2d43dc586a..934a9f7431 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -12,7 +12,7 @@ endif
 
 $(call set-vpath, $(SRC_PATH):$(BUILD_DIR))
 ifdef CONFIG_LINUX
-QEMU_CFLAGS += -I../linux-headers
+QEMU_CFLAGS += -isystem ../linux-headers
 endif
 QEMU_CFLAGS += -iquote .. -iquote $(SRC_PATH)/target/$(TARGET_BASE_ARCH) 
-DNEED_CPU_H
 
diff --git a/configure b/configure
index cbf864bff1..bf5bf70600 100755
--- a/configure
+++ b/configure
@@ -899,7 +899,7 @@ Linux)
   linux="yes"
   linux_user="yes"
   kvm="yes"
-  QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$PWD/linux-headers 
$QEMU_INCLUDES"
+  QEMU_INCLUDES="-isystem \$(SRC_PATH)/linux-headers -isystem 
$PWD/linux-headers $QEMU_INCLUDES"
   supported_os="yes"
   libudev="yes"
 ;;
-- 
2.24.1




[PATCH v2 2/2] mmap-alloc: Include osdep.h before checking CONFIG_LINUX

2020-03-11 Thread Eduardo Habkost
The CONFIG_LINUX check at the top of mmap-alloc.c never worked
because it was done before including osdep.h.

This means MAP_SYNC and MAP_SHARED_VALIDATE would always be set
to 0 at the beginning of the file.  Luckily, this didn't break
when using recent glibc versions (2.28+), because those macros
were redefined by glibc headers.

Move the CONFIG_LINUX check after the main include lines, so the
CONFIG_LINUX check works and we actually include .
This will make MAP_SYNC and MAP_SHARED_VALIDATE available even if
the host has an older glibc version.

Reported-by: Jingqi Liu 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Eduardo Habkost 
---
Changes v1 -> v2:
* (none)
---
 util/mmap-alloc.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
index 27dcccd8ec..7c2ce98eb0 100644
--- a/util/mmap-alloc.c
+++ b/util/mmap-alloc.c
@@ -9,6 +9,9 @@
  * This work is licensed under the terms of the GNU GPL, version 2 or
  * later.  See the COPYING file in the top-level directory.
  */
+#include "qemu/osdep.h"
+#include "qemu/mmap-alloc.h"
+#include "qemu/host-utils.h"
 
 #ifdef CONFIG_LINUX
 #include 
@@ -17,10 +20,6 @@
 #define MAP_SHARED_VALIDATE   0x0
 #endif /* CONFIG_LINUX */
 
-#include "qemu/osdep.h"
-#include "qemu/mmap-alloc.h"
-#include "qemu/host-utils.h"
-
 #define HUGETLBFS_MAGIC   0x958458f6
 
 #ifdef CONFIG_LINUX
-- 
2.24.1




[PATCH v2 0/2] Fix MAP_SYNC support when host has older glibc version

2020-03-11 Thread Eduardo Habkost
Changes v1 -> v2:
* Use -isystem for $PWD/linux-headers too
  Reported-by: "Michael S. Tsirkin" 

This is an alternative to the patch submitted at:

  From: Jingqi Liu 
  Subject: [PATCH] util: fix to get configuration macros in util/mmap-alloc.c
  Date: Thu,  5 Mar 2020 23:41:42 +0800
  Message-Id: <20200305154142.63070-1-jingqi@intel.com>

Before moving the osdep.h include to the top of the file, we had
to address warnings triggered when  was included
after  (done in patch 1/2).

Eduardo Habkost (2):
  Use -isystem for linux-headers dir
  mmap-alloc: Include osdep.h before checking CONFIG_LINUX

 Makefile.target   | 2 +-
 configure | 2 +-
 util/mmap-alloc.c | 7 +++
 3 files changed, 5 insertions(+), 6 deletions(-)

-- 
2.24.1





Re: [PATCH] acpi: Add Windows ACPI Emulated Device Table (WAET)

2020-03-11 Thread Liran Alon



On 11/03/2020 22:36, Michael S. Tsirkin wrote:

Thanks for the patch! Some questions/comments:

On Wed, Mar 11, 2020 at 07:08:26PM +0200, Liran Alon wrote:

From: Elad Gabay 

Microsoft introduced this ACPI table to avoid Windows guests performing
various workarounds for device erratas. As the virtual device emulated
by VMM may not have the errata.

Currently, WAET allows hypervisor to inform guest about two
specific behaviors: One for RTC and the other for ACPI PM Timer.

Support for WAET have been introduced since Windows Vista. This ACPI
table is also exposed by other hypervisors, such as VMware, by default.

This patch adds WAET ACPI Table to QEMU.

Could you add a bit more info? Why is this so useful we are adding this
by default? How does it change windows behaviour when present?
It changes behavior as documented in the WAET specification linked below 
(and the comments above the flags definitions).
Specifically for ACPI_WAET_PM_TIMER_GOOD (Which is the only bit we set), 
the guest performs only one read of ACPI PM Timer instead of multiple to 
obtain it's value.

Which improves performance as it removes unnecessary VMExits.



It also makes sure to introduce
the new ACPI table only for new machine-types.

OK and why is that?
As ACPI tables are guest-visible, we should make sure to not change it 
between machine-types.
For example, a change in ACPI tables may invalidate a Windows guest 
license activation (As platform have changed).
But this is just a good practice in general and in the past it was said 
by maintainers that this is one of the main reasons that ACPI and SMBIOS 
generation have moved from SeaBIOS to QEMU.



Signed-off-by: Elad Gabay 
Co-developed-by: Liran Alon 
Signed-off-by: Liran Alon 
---
  hw/i386/acpi-build.c| 18 ++
  hw/i386/pc_piix.c   |  2 ++
  hw/i386/pc_q35.c|  2 ++
  include/hw/acpi/acpi-defs.h | 25 +
  include/hw/i386/pc.h|  1 +
  5 files changed, 48 insertions(+)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 9c4e46fa7466..29f70741cd96 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -2512,6 +2512,19 @@ build_dmar_q35(GArray *table_data, BIOSLinker *linker)
  build_header(linker, table_data, (void *)(table_data->data + dmar_start),
   "DMAR", table_data->len - dmar_start, 1, NULL, NULL);
  }
+
+static void
+build_waet(GArray *table_data, BIOSLinker *linker)
+{
+AcpiTableWaet *waet;
+
+waet = acpi_data_push(table_data, sizeof(*waet));

Can combine with the previous line.

Ok. Will do in v2.



+waet->emulated_device_flags = cpu_to_le32(ACPI_WAET_PM_TIMER_GOOD);
+
+build_header(linker, table_data,
+ (void *)waet, "WAET", sizeof(*waet), 1, NULL, NULL);
+}
+
  /*
   *   IVRS table as specified in AMD IOMMU Specification v2.62, Section 5.2
   *   accessible here 
https://urldefense.com/v3/__http://support.amd.com/TechDocs/48882_IOMMU.pdf__;!!GqivPVa7Brio!OAQpLo9QhdHiNDa_aRLR_ma1nWLZU1aQhDozYgUlrqBZiz1vKdZgg-lTDMIj_5g$
@@ -2859,6 +2872,11 @@ void acpi_build(AcpiBuildTables *tables, MachineState 
*machine)
machine->nvdimms_state, machine->ram_slots);
  }
  
+if (!pcmc->do_not_add_waet_acpi) {

+acpi_add_table(table_offsets, tables_blob);
+build_waet(tables_blob, tables->linker);
+}
+
  /* Add tables supplied by user (if any) */
  for (u = acpi_table_first(); u; u = acpi_table_next(u)) {
  unsigned len = acpi_table_len(u);
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 9088db8fb601..2d11a8b50a9c 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -432,9 +432,11 @@ DEFINE_I440FX_MACHINE(v5_0, "pc-i440fx-5.0", NULL,
  
  static void pc_i440fx_4_2_machine_options(MachineClass *m)

  {
+PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
  pc_i440fx_5_0_machine_options(m);
  m->alias = NULL;
  m->is_default = false;
+pcmc->do_not_add_waet_acpi = true;
  compat_props_add(m->compat_props, hw_compat_4_2, hw_compat_4_2_len);
  compat_props_add(m->compat_props, pc_compat_4_2, pc_compat_4_2_len);
  }
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 84cf925cf43a..1e0a726b27a7 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -361,8 +361,10 @@ DEFINE_Q35_MACHINE(v5_0, "pc-q35-5.0", NULL,
  
  static void pc_q35_4_2_machine_options(MachineClass *m)

  {
+PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
  pc_q35_5_0_machine_options(m);
  m->alias = NULL;
+pcmc->do_not_add_waet_acpi = true;
  compat_props_add(m->compat_props, hw_compat_4_2, hw_compat_4_2_len);
  compat_props_add(m->compat_props, pc_compat_4_2, pc_compat_4_2_len);
  }
diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
index 57a3f58b0c9a..803c904471d5 100644
--- a/include/hw/acpi/acpi-defs.h
+++ b/include/hw/acpi/acpi-defs.h
@@ -634,4 +634,29 @@ struct AcpiIortRC {
  } QEMU_PACKED;
  typedef struct AcpiIortRC 

Re: [PATCH 1/2] Use -isystem for linux-headers dir

2020-03-11 Thread Eduardo Habkost
On Wed, Mar 11, 2020 at 07:08:06PM -0400, Eduardo Habkost wrote:
> On Wed, Mar 11, 2020 at 07:05:45PM -0400, Michael S. Tsirkin wrote:
> > On Wed, Mar 11, 2020 at 06:51:29PM -0400, Eduardo Habkost wrote:
> > > glibc and Linux-provided headers are known to generate macro
> > > redefinition warnings when used together.  For example:
> > >  and  duplicate some macro definitions.
> > > 
> > > We normally never see those warnings because GCC suppresses
> > > warnings generated by system headers.  We carry our own copy of
> > > Linux header files, though, and this makes those warnings not be
> > > suppressed when glibc headers are included before Linux headers
> > > (e.g. if  is included before ).
> > > 
> > > Use -isystem instead of -I for linux-headers.  This makes the
> > > compiler treat our linux-headers directory the same way it treats
> > > system-provided Linux headers, and suppress warnings generated by
> > > them.
> > > 
> > > Signed-off-by: Eduardo Habkost 
> > > ---
> > >  Makefile.target | 2 +-
> > >  configure   | 2 +-
> > >  2 files changed, 2 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/Makefile.target b/Makefile.target
> > > index 2d43dc586a..934a9f7431 100644
> > > --- a/Makefile.target
> > > +++ b/Makefile.target
> > > @@ -12,7 +12,7 @@ endif
> > >  
> > >  $(call set-vpath, $(SRC_PATH):$(BUILD_DIR))
> > >  ifdef CONFIG_LINUX
> > > -QEMU_CFLAGS += -I../linux-headers
> > > +QEMU_CFLAGS += -isystem ../linux-headers
> > >  endif
> > >  QEMU_CFLAGS += -iquote .. -iquote $(SRC_PATH)/target/$(TARGET_BASE_ARCH) 
> > > -DNEED_CPU_H
> > >  
> > > diff --git a/configure b/configure
> > > index cbf864bff1..04a2a7f2dd 100755
> > > --- a/configure
> > > +++ b/configure
> > > @@ -899,7 +899,7 @@ Linux)
> > >linux="yes"
> > >linux_user="yes"
> > >kvm="yes"
> > > -  QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$PWD/linux-headers 
> > > $QEMU_INCLUDES"
> > > +  QEMU_INCLUDES="-isystem \$(SRC_PATH)/linux-headers 
> > > -I$PWD/linux-headers $QEMU_INCLUDES"
> > 
> > Shouldn't both be -isystem?
> 
> I haven't noticed we had both.
> 
> This line looks weird, does anybody know why we have
> $PWD/linux-headers here?

This is why:

commit a585140dd546ffb606ec506b362ab9decf1ab14e
Author: Alexey Kardashevskiy 
Date:   Wed May 29 23:30:43 2013 +1000

   qemu: fix out of tree cross compile

   The symlink to "asm" platform linux headers is made in the build tree by
   the configure script but gcc is not told to look for them there.

   The patch fixes this.

   Signed-off-by: Alexey Kardashevskiy 
   Signed-off-by: Michael Tokarev 

-- 
Eduardo




Re: [PATCH 1/2] Use -isystem for linux-headers dir

2020-03-11 Thread Eduardo Habkost
On Wed, Mar 11, 2020 at 07:05:45PM -0400, Michael S. Tsirkin wrote:
> On Wed, Mar 11, 2020 at 06:51:29PM -0400, Eduardo Habkost wrote:
> > glibc and Linux-provided headers are known to generate macro
> > redefinition warnings when used together.  For example:
> >  and  duplicate some macro definitions.
> > 
> > We normally never see those warnings because GCC suppresses
> > warnings generated by system headers.  We carry our own copy of
> > Linux header files, though, and this makes those warnings not be
> > suppressed when glibc headers are included before Linux headers
> > (e.g. if  is included before ).
> > 
> > Use -isystem instead of -I for linux-headers.  This makes the
> > compiler treat our linux-headers directory the same way it treats
> > system-provided Linux headers, and suppress warnings generated by
> > them.
> > 
> > Signed-off-by: Eduardo Habkost 
> > ---
> >  Makefile.target | 2 +-
> >  configure   | 2 +-
> >  2 files changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/Makefile.target b/Makefile.target
> > index 2d43dc586a..934a9f7431 100644
> > --- a/Makefile.target
> > +++ b/Makefile.target
> > @@ -12,7 +12,7 @@ endif
> >  
> >  $(call set-vpath, $(SRC_PATH):$(BUILD_DIR))
> >  ifdef CONFIG_LINUX
> > -QEMU_CFLAGS += -I../linux-headers
> > +QEMU_CFLAGS += -isystem ../linux-headers
> >  endif
> >  QEMU_CFLAGS += -iquote .. -iquote $(SRC_PATH)/target/$(TARGET_BASE_ARCH) 
> > -DNEED_CPU_H
> >  
> > diff --git a/configure b/configure
> > index cbf864bff1..04a2a7f2dd 100755
> > --- a/configure
> > +++ b/configure
> > @@ -899,7 +899,7 @@ Linux)
> >linux="yes"
> >linux_user="yes"
> >kvm="yes"
> > -  QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$PWD/linux-headers 
> > $QEMU_INCLUDES"
> > +  QEMU_INCLUDES="-isystem \$(SRC_PATH)/linux-headers -I$PWD/linux-headers 
> > $QEMU_INCLUDES"
> 
> Shouldn't both be -isystem?

I haven't noticed we had both.

This line looks weird, does anybody know why we have
$PWD/linux-headers here?

-- 
Eduardo




Re: [PATCH 2/2] mmap-alloc: Include osdep.h before checking CONFIG_LINUX

2020-03-11 Thread Michael S. Tsirkin
On Wed, Mar 11, 2020 at 06:51:30PM -0400, Eduardo Habkost wrote:
> The CONFIG_LINUX check at the top of mmap-alloc.c never worked
> because it was done before including osdep.h.
> 
> This means MAP_SYNC and MAP_SHARED_VALIDATE would always be set
> to 0 at the beginning of the file.  Luckily, this didn't break
> when using recent glibc versions (2.28+), because those macros
> were redefined by glibc headers.
> 
> Move the CONFIG_LINUX check after the main include lines, so the
> CONFIG_LINUX check works and we actually include .
> This will make MAP_SYNC and MAP_SHARED_VALIDATE available even if
> the host has an older glibc version.
> 
> Reported-by: Jingqi Liu 
> Signed-off-by: Eduardo Habkost 

Makes sense, and I guess we should CC stable on this?

Reviewed-by: Michael S. Tsirkin 

> ---
>  util/mmap-alloc.c | 7 +++
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
> index 27dcccd8ec..7c2ce98eb0 100644
> --- a/util/mmap-alloc.c
> +++ b/util/mmap-alloc.c
> @@ -9,6 +9,9 @@
>   * This work is licensed under the terms of the GNU GPL, version 2 or
>   * later.  See the COPYING file in the top-level directory.
>   */
> +#include "qemu/osdep.h"
> +#include "qemu/mmap-alloc.h"
> +#include "qemu/host-utils.h"
>  
>  #ifdef CONFIG_LINUX
>  #include 
> @@ -17,10 +20,6 @@
>  #define MAP_SHARED_VALIDATE   0x0
>  #endif /* CONFIG_LINUX */
>  
> -#include "qemu/osdep.h"
> -#include "qemu/mmap-alloc.h"
> -#include "qemu/host-utils.h"
> -
>  #define HUGETLBFS_MAGIC   0x958458f6
>  
>  #ifdef CONFIG_LINUX
> -- 
> 2.24.1




Re: [PATCH 1/2] Use -isystem for linux-headers dir

2020-03-11 Thread Michael S. Tsirkin
On Wed, Mar 11, 2020 at 06:51:29PM -0400, Eduardo Habkost wrote:
> glibc and Linux-provided headers are known to generate macro
> redefinition warnings when used together.  For example:
>  and  duplicate some macro definitions.
> 
> We normally never see those warnings because GCC suppresses
> warnings generated by system headers.  We carry our own copy of
> Linux header files, though, and this makes those warnings not be
> suppressed when glibc headers are included before Linux headers
> (e.g. if  is included before ).
> 
> Use -isystem instead of -I for linux-headers.  This makes the
> compiler treat our linux-headers directory the same way it treats
> system-provided Linux headers, and suppress warnings generated by
> them.
> 
> Signed-off-by: Eduardo Habkost 
> ---
>  Makefile.target | 2 +-
>  configure   | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/Makefile.target b/Makefile.target
> index 2d43dc586a..934a9f7431 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -12,7 +12,7 @@ endif
>  
>  $(call set-vpath, $(SRC_PATH):$(BUILD_DIR))
>  ifdef CONFIG_LINUX
> -QEMU_CFLAGS += -I../linux-headers
> +QEMU_CFLAGS += -isystem ../linux-headers
>  endif
>  QEMU_CFLAGS += -iquote .. -iquote $(SRC_PATH)/target/$(TARGET_BASE_ARCH) 
> -DNEED_CPU_H
>  
> diff --git a/configure b/configure
> index cbf864bff1..04a2a7f2dd 100755
> --- a/configure
> +++ b/configure
> @@ -899,7 +899,7 @@ Linux)
>linux="yes"
>linux_user="yes"
>kvm="yes"
> -  QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$PWD/linux-headers 
> $QEMU_INCLUDES"
> +  QEMU_INCLUDES="-isystem \$(SRC_PATH)/linux-headers -I$PWD/linux-headers 
> $QEMU_INCLUDES"

Shouldn't both be -isystem?

>supported_os="yes"
>libudev="yes"
>  ;;
> -- 
> 2.24.1




Re: [PATCH v8 00/18] Add Allwinner H3 SoC and Orange Pi PC Machine

2020-03-11 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20200311221854.30370-1-nieklinnenb...@gmail.com/



Hi,

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

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

PASS 1 fdc-test /x86_64/fdc/cmos
PASS 2 fdc-test /x86_64/fdc/no_media_on_start
PASS 3 fdc-test /x86_64/fdc/read_without_media
==6199==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 4 fdc-test /x86_64/fdc/media_change
PASS 5 fdc-test /x86_64/fdc/sense_interrupt
PASS 6 fdc-test /x86_64/fdc/relative_seek
---
PASS 32 test-opts-visitor /visitor/opts/range/beyond
PASS 33 test-opts-visitor /visitor/opts/dict/unvisited
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-coroutine -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="test-coroutine" 
==6240==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
==6240==WARNING: ASan is ignoring requested __asan_handle_no_return: stack top: 
0x7ffc6ef02000; bottom 0x7f6fe8dc6000; size: 0x008c8613c000 (603544862720)
False positive error reports may follow
For details see https://github.com/google/sanitizers/issues/189
PASS 1 test-coroutine /basic/no-dangling-access
---
PASS 12 test-aio /aio/event/flush
PASS 13 test-aio /aio/event/wait/no-flush-cb
PASS 14 test-aio /aio/timer/schedule
==6255==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 15 test-aio /aio/coroutine/queue-chaining
PASS 16 test-aio /aio-gsource/flush
PASS 17 test-aio /aio-gsource/bh/schedule
---
PASS 12 fdc-test /x86_64/fdc/read_no_dma_19
PASS 13 fdc-test /x86_64/fdc/fuzz-registers
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
QTEST_QEMU_BINARY=x86_64-softmmu/qemu-system-x86_64 QTEST_QEMU_IMG=qemu-img 
tests/qtest/ide-test -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="ide-test" 
==6263==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 28 test-aio /aio-gsource/timer/schedule
PASS 1 ide-test /x86_64/ide/identify
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-aio-multithread -m=quick -k --tap < /dev/null | 
./scripts/tap-driver.pl --test-name="test-aio-multithread" 
==6272==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 test-aio-multithread /aio/multi/lifecycle
==6269==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 2 test-aio-multithread /aio/multi/schedule
PASS 3 test-aio-multithread /aio/multi/mutex/contended
PASS 2 ide-test /x86_64/ide/flush
PASS 4 test-aio-multithread /aio/multi/mutex/handoff
==6299==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 3 ide-test /x86_64/ide/bmdma/simple_rw
==6310==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 5 test-aio-multithread /aio/multi/mutex/mcs
PASS 4 ide-test /x86_64/ide/bmdma/trim
==6321==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 6 test-aio-multithread /aio/multi/mutex/pthread
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-throttle -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="test-throttle" 
==6328==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 test-throttle /throttle/leak_bucket
PASS 2 test-throttle /throttle/compute_wait
PASS 3 test-throttle /throttle/init
---
PASS 14 test-throttle /throttle/config/max
PASS 15 test-throttle /throttle/config/iops_size
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-thread-pool -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="test-thread-pool" 
==6332==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 test-thread-pool /thread-pool/submit
PASS 2 test-thread-pool /thread-pool/submit-aio
PASS 3 test-thread-pool /thread-pool/submit-co
---
PASS 2 test-hbitmap /hbitmap/size/0
PASS 3 test-hbitmap /hbitmap/size/unaligned
PASS 4 test-hbitmap /hbitmap/iter/empty
==6402==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 5 test-hbitmap /hbitmap/iter/partial
PASS 6 test-hbitmap 

[PATCH v7 09/13] hw/i386: Introduce apicid functions inside X86MachineState

2020-03-11 Thread Babu Moger
Introduce model specific apicid functions inside X86MachineState.
These functions will be loaded from X86CPUDefinition.

Signed-off-by: Babu Moger 
Reviewed-by: Igor Mammedov 
Acked-by: Michael S. Tsirkin 
---
 hw/i386/x86.c |5 +
 include/hw/i386/x86.h |9 +
 2 files changed, 14 insertions(+)

diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index 42834d2319..0a81ab5151 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -911,6 +911,11 @@ static void x86_machine_initfn(Object *obj)
 x86ms->smm = ON_OFF_AUTO_AUTO;
 x86ms->max_ram_below_4g = 0; /* use default */
 x86ms->smp_dies = 1;
+
+x86ms->apicid_from_cpu_idx = x86_apicid_from_cpu_idx;
+x86ms->topo_ids_from_apicid = x86_topo_ids_from_apicid;
+x86ms->apicid_from_topo_ids = x86_apicid_from_topo_ids;
+x86ms->apicid_pkg_offset = apicid_pkg_offset;
 }
 
 static void x86_machine_class_init(ObjectClass *oc, void *data)
diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h
index 22babcb3bb..2643b57629 100644
--- a/include/hw/i386/x86.h
+++ b/include/hw/i386/x86.h
@@ -65,6 +65,15 @@ typedef struct {
 
 OnOffAuto smm;
 
+/* Apic id specific handlers */
+uint32_t (*apicid_from_cpu_idx)(X86CPUTopoInfo *topo_info,
+unsigned cpu_index);
+void (*topo_ids_from_apicid)(apic_id_t apicid, X86CPUTopoInfo *topo_info,
+ X86CPUTopoIDs *topo_ids);
+apic_id_t (*apicid_from_topo_ids)(X86CPUTopoInfo *topo_info,
+  const X86CPUTopoIDs *topo_ids);
+uint32_t (*apicid_pkg_offset)(X86CPUTopoInfo *topo_info);
+
 /*
  * Address space used by IOAPIC device. All IOAPIC interrupts
  * will be translated to MSI messages in the address space.




[PATCH v7 07/13] hw/386: Add EPYC mode topology decoding functions

2020-03-11 Thread Babu Moger
These functions add support for building EPYC mode topology given the smp
details like numa nodes, cores, threads and sockets.

The new apic id decoding is mostly similar to current apic id decoding
except that it adds a new field node_id when numa configured. Removes all
the hardcoded values. Subsequent patches will use these functions to build
the topology.

Following functions are added.
apicid_llc_width_epyc
apicid_llc_offset_epyc
apicid_pkg_offset_epyc
apicid_from_topo_ids_epyc
x86_topo_ids_from_idx_epyc
x86_topo_ids_from_apicid_epyc
x86_apicid_from_cpu_idx_epyc

The topology details are available in Processor Programming Reference (PPR)
for AMD Family 17h Model 01h, Revision B1 Processors. The revision guides are
available from the bugzilla Link below.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537

Signed-off-by: Babu Moger 
Acked-by: Igor Mammedov 
Acked-by: Michael S. Tsirkin 
---
 include/hw/i386/topology.h |  100 
 1 file changed, 100 insertions(+)

diff --git a/include/hw/i386/topology.h b/include/hw/i386/topology.h
index b9593b9905..07239f95f4 100644
--- a/include/hw/i386/topology.h
+++ b/include/hw/i386/topology.h
@@ -47,6 +47,7 @@ typedef uint32_t apic_id_t;
 
 typedef struct X86CPUTopoIDs {
 unsigned pkg_id;
+unsigned node_id;
 unsigned die_id;
 unsigned core_id;
 unsigned smt_id;
@@ -88,6 +89,11 @@ static inline unsigned apicid_die_width(X86CPUTopoInfo 
*topo_info)
 return apicid_bitwidth_for_count(topo_info->dies_per_pkg);
 }
 
+/* Bit width of the node_id field per socket */
+static inline unsigned apicid_node_width_epyc(X86CPUTopoInfo *topo_info)
+{
+return apicid_bitwidth_for_count(MAX(topo_info->nodes_per_pkg, 1));
+}
 /* Bit offset of the Core_ID field
  */
 static inline unsigned apicid_core_offset(X86CPUTopoInfo *topo_info)
@@ -108,6 +114,100 @@ static inline unsigned apicid_pkg_offset(X86CPUTopoInfo 
*topo_info)
 return apicid_die_offset(topo_info) + apicid_die_width(topo_info);
 }
 
+#define NODE_ID_OFFSET 3 /* Minimum node_id offset if numa configured */
+
+/*
+ * Bit offset of the node_id field
+ *
+ * Make sure nodes_per_pkg >  0 if numa configured else zero.
+ */
+static inline unsigned apicid_node_offset_epyc(X86CPUTopoInfo *topo_info)
+{
+unsigned offset = apicid_die_offset(topo_info) +
+  apicid_die_width(topo_info);
+
+if (topo_info->nodes_per_pkg) {
+return MAX(NODE_ID_OFFSET, offset);
+} else {
+return offset;
+}
+}
+
+/* Bit offset of the Pkg_ID (socket ID) field */
+static inline unsigned apicid_pkg_offset_epyc(X86CPUTopoInfo *topo_info)
+{
+return apicid_node_offset_epyc(topo_info) +
+   apicid_node_width_epyc(topo_info);
+}
+
+/*
+ * Make APIC ID for the CPU based on Pkg_ID, Core_ID, SMT_ID
+ *
+ * The caller must make sure core_id < nr_cores and smt_id < nr_threads.
+ */
+static inline apic_id_t
+x86_apicid_from_topo_ids_epyc(X86CPUTopoInfo *topo_info,
+  const X86CPUTopoIDs *topo_ids)
+{
+return (topo_ids->pkg_id  << apicid_pkg_offset_epyc(topo_info)) |
+   (topo_ids->node_id << apicid_node_offset_epyc(topo_info)) |
+   (topo_ids->die_id  << apicid_die_offset(topo_info)) |
+   (topo_ids->core_id << apicid_core_offset(topo_info)) |
+   topo_ids->smt_id;
+}
+
+static inline void x86_topo_ids_from_idx_epyc(X86CPUTopoInfo *topo_info,
+  unsigned cpu_index,
+  X86CPUTopoIDs *topo_ids)
+{
+unsigned nr_nodes = MAX(topo_info->nodes_per_pkg, 1);
+unsigned nr_dies = topo_info->dies_per_pkg;
+unsigned nr_cores = topo_info->cores_per_die;
+unsigned nr_threads = topo_info->threads_per_core;
+unsigned cores_per_node = DIV_ROUND_UP((nr_dies * nr_cores * nr_threads),
+nr_nodes);
+
+topo_ids->pkg_id = cpu_index / (nr_dies * nr_cores * nr_threads);
+topo_ids->node_id = (cpu_index / cores_per_node) % nr_nodes;
+topo_ids->die_id = cpu_index / (nr_cores * nr_threads) % nr_dies;
+topo_ids->core_id = cpu_index / nr_threads % nr_cores;
+topo_ids->smt_id = cpu_index % nr_threads;
+}
+
+/*
+ * Calculate thread/core/package IDs for a specific topology,
+ * based on APIC ID
+ */
+static inline void x86_topo_ids_from_apicid_epyc(apic_id_t apicid,
+X86CPUTopoInfo *topo_info,
+X86CPUTopoIDs *topo_ids)
+{
+topo_ids->smt_id = apicid &
+~(0xUL << apicid_smt_width(topo_info));
+topo_ids->core_id =
+(apicid >> apicid_core_offset(topo_info)) &
+~(0xUL << apicid_core_width(topo_info));
+topo_ids->die_id =
+(apicid >> apicid_die_offset(topo_info)) &
+~(0xUL << apicid_die_width(topo_info));
+topo_ids->node_id =
+(apicid >> 

[PATCH v7 10/13] i386: Introduce use_epyc_apic_id_encoding in X86CPUDefinition

2020-03-11 Thread Babu Moger
Add a boolean variable use_epyc_apic_id_encoding in X86CPUDefinition.
This will be set if this cpu model needs to use new EPYC based
apic id encoding.

Override the handlers with EPYC based handlers if use_epyc_apic_id_encoding
is set. This will be done in x86_cpus_init.

Signed-off-by: Babu Moger 
---
 target/i386/cpu.c |   16 
 target/i386/cpu.h |1 +
 2 files changed, 17 insertions(+)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 7361a53166..1e4400df7a 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -1614,6 +1614,10 @@ typedef struct X86CPUDefinition {
 FeatureWordArray features;
 const char *model_id;
 CPUCaches *cache_info;
+
+/* Use AMD EPYC encoding for apic id */
+bool use_epyc_apic_id_encoding;
+
 /*
  * Definitions for alternative versions of CPU model.
  * List is terminated by item with version == 0.
@@ -1655,6 +1659,18 @@ static const X86CPUVersionDefinition 
*x86_cpu_def_get_versions(X86CPUDefinition
 return def->versions ?: default_version_list;
 }
 
+bool cpu_x86_use_epyc_apic_id_encoding(const char *cpu_type)
+{
+X86CPUClass *xcc = X86_CPU_CLASS(object_class_by_name(cpu_type));
+
+assert(xcc);
+if (xcc->model && xcc->model->cpudef) {
+return xcc->model->cpudef->use_epyc_apic_id_encoding;
+} else {
+return false;
+}
+}
+
 static CPUCaches epyc_cache_info = {
 .l1d_cache = &(CPUCacheInfo) {
 .type = DATA_CACHE,
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 7e9e963d78..6e522fcd34 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -1897,6 +1897,7 @@ void cpu_clear_apic_feature(CPUX86State *env);
 void host_cpuid(uint32_t function, uint32_t count,
 uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
 void host_vendor_fms(char *vendor, int *family, int *model, int *stepping);
+bool cpu_x86_use_epyc_apic_id_encoding(const char *cpu_type);
 
 /* helper.c */
 bool x86_cpu_tlb_fill(CPUState *cs, vaddr address, int size,




Re: [PATCH RESEND v2] block/nvme: introduce PMR support from NVMe 1.4 spec

2020-03-11 Thread Andrzej Jakowski
On 3/11/20 2:20 AM, Stefan Hajnoczi wrote:
> Please try:
> 
>   $ git grep pmem
> 
> backends/hostmem-file.c is the backend that can be used and the
> pmem_persist() API can be used to flush writes.

I've reworked this patch into hostmem-file type of backend.
>From simple tests in virtual machine: writing to PMR region
and then reading from it after VM power cycle I have observed that
there is no persistency.

I guess that persistent behavior can be achieved if memory backend file
resides on actual persistent memory in VMM. I haven't found mechanism to
persist memory backend file when it resides in the file system on block
storage. My original mmap + msync based solution worked well there.
I believe that main problem with mmap was with "ifdef _WIN32" that made it 
platform specific and w/o it patchew CI complained. 
Is there a way that I could rework mmap + msync solution so it would fit
into qemu design?




[PATCH v7 04/13] hw/i386: Remove unnecessary initialization in x86_cpu_new

2020-03-11 Thread Babu Moger
The function pc_cpu_pre_plug takes care of initialization of CPUX86State.
So, remove the initialization here.

Suggested-by: Igor Mammedov 
Signed-off-by: Babu Moger 
Reviewed-by: Igor Mammedov 
Acked-by: Michael S. Tsirkin 
---
 hw/i386/x86.c |4 
 1 file changed, 4 deletions(-)

diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index dbbff46a4b..84d1944a34 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -103,13 +103,9 @@ void x86_cpu_new(X86MachineState *x86ms, int64_t apic_id, 
Error **errp)
 {
 Object *cpu = NULL;
 Error *local_err = NULL;
-CPUX86State *env = NULL;
 
 cpu = object_new(MACHINE(x86ms)->cpu_type);
 
-env = _CPU(cpu)->env;
-env->nr_dies = x86ms->smp_dies;
-
 object_property_set_uint(cpu, apic_id, "apic-id", _err);
 object_property_set_bool(cpu, true, "realized", _err);
 




[PATCH v7 13/13] i386: Fix pkg_id offset for EPYC cpu models

2020-03-11 Thread Babu Moger
If the system is numa configured the pkg_offset needs
to be adjusted for EPYC cpu models. Fix it calling the
model specific handler.

Signed-off-by: Babu Moger 
Reviewed-by: Igor Mammedov 
Acked-by: Michael S. Tsirkin 
---
 hw/i386/pc.c  |1 +
 target/i386/cpu.c |4 ++--
 target/i386/cpu.h |1 +
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 2d7d611184..ab6da19bab 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1526,6 +1526,7 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev,
 
 env->nr_dies = x86ms->smp_dies;
 env->nr_nodes = topo_info.nodes_per_pkg;
+env->pkg_offset = x86ms->apicid_pkg_offset(_info);
 
 /*
  * If APIC ID is not set,
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 9ffaf5e2a0..c58ac38d29 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -5610,7 +5610,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 *ecx |= CPUID_TOPOLOGY_LEVEL_SMT;
 break;
 case 1:
-*eax = apicid_pkg_offset(_info);
+*eax = env->pkg_offset;
 *ebx = cs->nr_cores * cs->nr_threads;
 *ecx |= CPUID_TOPOLOGY_LEVEL_CORE;
 break;
@@ -5644,7 +5644,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 *ecx |= CPUID_TOPOLOGY_LEVEL_CORE;
 break;
 case 2:
-*eax = apicid_pkg_offset(_info);
+*eax = env->pkg_offset;
 *ebx = env->nr_dies * cs->nr_cores * cs->nr_threads;
 *ecx |= CPUID_TOPOLOGY_LEVEL_DIE;
 break;
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 6e522fcd34..92872d2b7a 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -1610,6 +1610,7 @@ typedef struct CPUX86State {
 
 unsigned nr_dies;
 unsigned nr_nodes;
+unsigned pkg_offset;
 } CPUX86State;
 
 struct kvm_msrs;




[PATCH v7 08/13] target/i386: Cleanup and use the EPYC mode topology functions

2020-03-11 Thread Babu Moger
Use the new functions from topology.h and delete the unused code. Given the
sockets, nodes, cores and threads, the new functions generate apic id for EPYC
mode. Removes all the hardcoded values.

Signed-off-by: Babu Moger 
Acked-by: Michael S. Tsirkin 
Acked-by: Igor Mammedov 
---
 target/i386/cpu.c |  161 +++--
 1 file changed, 34 insertions(+), 127 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 2e5be37b21..7361a53166 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -338,68 +338,15 @@ static void encode_cache_cpuid8006(CPUCacheInfo *l2,
 }
 }
 
-/*
- * Definitions used for building CPUID Leaf 0x801D and 0x801E
- * Please refer to the AMD64 Architecture Programmer’s Manual Volume 3.
- * Define the constants to build the cpu topology. Right now, TOPOEXT
- * feature is enabled only on EPYC. So, these constants are based on
- * EPYC supported configurations. We may need to handle the cases if
- * these values change in future.
- */
-/* Maximum core complexes in a node */
-#define MAX_CCX 2
-/* Maximum cores in a core complex */
-#define MAX_CORES_IN_CCX 4
-/* Maximum cores in a node */
-#define MAX_CORES_IN_NODE 8
-/* Maximum nodes in a socket */
-#define MAX_NODES_PER_SOCKET 4
-
-/*
- * Figure out the number of nodes required to build this config.
- * Max cores in a node is 8
- */
-static int nodes_in_socket(int nr_cores)
-{
-int nodes;
-
-nodes = DIV_ROUND_UP(nr_cores, MAX_CORES_IN_NODE);
-
-   /* Hardware does not support config with 3 nodes, return 4 in that case */
-return (nodes == 3) ? 4 : nodes;
-}
-
-/*
- * Decide the number of cores in a core complex with the given nr_cores using
- * following set constants MAX_CCX, MAX_CORES_IN_CCX, MAX_CORES_IN_NODE and
- * MAX_NODES_PER_SOCKET. Maintain symmetry as much as possible
- * L3 cache is shared across all cores in a core complex. So, this will also
- * tell us how many cores are sharing the L3 cache.
- */
-static int cores_in_core_complex(int nr_cores)
-{
-int nodes;
-
-/* Check if we can fit all the cores in one core complex */
-if (nr_cores <= MAX_CORES_IN_CCX) {
-return nr_cores;
-}
-/* Get the number of nodes required to build this config */
-nodes = nodes_in_socket(nr_cores);
-
-/*
- * Divide the cores accros all the core complexes
- * Return rounded up value
- */
-return DIV_ROUND_UP(nr_cores, nodes * MAX_CCX);
-}
-
 /* Encode cache info for CPUID[801D] */
-static void encode_cache_cpuid801d(CPUCacheInfo *cache, CPUState *cs,
-uint32_t *eax, uint32_t *ebx,
-uint32_t *ecx, uint32_t *edx)
+static void encode_cache_cpuid801d(CPUCacheInfo *cache,
+   X86CPUTopoInfo *topo_info,
+   uint32_t *eax, uint32_t *ebx,
+   uint32_t *ecx, uint32_t *edx)
 {
 uint32_t l3_cores;
+unsigned nodes = MAX(topo_info->nodes_per_pkg, 1);
+
 assert(cache->size == cache->line_size * cache->associativity *
   cache->partitions * cache->sets);
 
@@ -408,10 +355,13 @@ static void encode_cache_cpuid801d(CPUCacheInfo 
*cache, CPUState *cs,
 
 /* L3 is shared among multiple cores */
 if (cache->level == 3) {
-l3_cores = cores_in_core_complex(cs->nr_cores);
-*eax |= ((l3_cores * cs->nr_threads) - 1) << 14;
+l3_cores = DIV_ROUND_UP((topo_info->dies_per_pkg *
+ topo_info->cores_per_die *
+ topo_info->threads_per_core),
+ nodes);
+*eax |= (l3_cores - 1) << 14;
 } else {
-*eax |= ((cs->nr_threads - 1) << 14);
+*eax |= ((topo_info->threads_per_core - 1) << 14);
 }
 
 assert(cache->line_size > 0);
@@ -431,55 +381,17 @@ static void encode_cache_cpuid801d(CPUCacheInfo 
*cache, CPUState *cs,
(cache->complex_indexing ? CACHE_COMPLEX_IDX : 0);
 }
 
-/* Data structure to hold the configuration info for a given core index */
-struct core_topology {
-/* core complex id of the current core index */
-int ccx_id;
-/*
- * Adjusted core index for this core in the topology
- * This can be 0,1,2,3 with max 4 cores in a core complex
- */
-int core_id;
-/* Node id for this core index */
-int node_id;
-/* Number of nodes in this config */
-int num_nodes;
-};
-
-/*
- * Build the configuration closely match the EPYC hardware. Using the EPYC
- * hardware configuration values (MAX_CCX, MAX_CORES_IN_CCX, MAX_CORES_IN_NODE)
- * right now. This could change in future.
- * nr_cores : Total number of cores in the config
- * core_id  : Core index of the current CPU
- * topo : Data structure to hold all the config info for this core index
- */
-static void build_core_topology(int nr_cores, int core_id,
-  

[PATCH v7 03/13] machine: Add SMP Sockets in CpuTopology

2020-03-11 Thread Babu Moger
Store the  smp sockets in CpuTopology. The socket information required to
build the apic id in EPYC mode. Right now socket information is not passed
to down when decoding the apic id. Add the socket information here.

Signed-off-by: Babu Moger 
Reviewed-by: Eduardo Habkost 
Reviewed-by: Igor Mammedov 
Acked-by: Michael S. Tsirkin 
---
 hw/core/machine.c   |1 +
 hw/i386/pc.c|1 +
 include/hw/boards.h |2 ++
 softmmu/vl.c|1 +
 4 files changed, 5 insertions(+)

diff --git a/hw/core/machine.c b/hw/core/machine.c
index 4778bc6b08..b958cd1b99 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -757,6 +757,7 @@ static void smp_parse(MachineState *ms, QemuOpts *opts)
 ms->smp.cpus = cpus;
 ms->smp.cores = cores;
 ms->smp.threads = threads;
+ms->smp.sockets = sockets;
 }
 
 if (ms->smp.cpus > 1) {
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 662abb549d..05e7f1090f 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -781,6 +781,7 @@ void pc_smp_parse(MachineState *ms, QemuOpts *opts)
 ms->smp.cpus = cpus;
 ms->smp.cores = cores;
 ms->smp.threads = threads;
+ms->smp.sockets = sockets;
 x86ms->smp_dies = dies;
 }
 
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 9bc42dfb22..d01056286a 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -236,12 +236,14 @@ typedef struct DeviceMemoryState {
  * @cpus: the number of present logical processors on the machine
  * @cores: the number of cores in one package
  * @threads: the number of threads in one core
+ * @sockets: the number of sockets on the machine
  * @max_cpus: the maximum number of logical processors on the machine
  */
 typedef struct CpuTopology {
 unsigned int cpus;
 unsigned int cores;
 unsigned int threads;
+unsigned int sockets;
 unsigned int max_cpus;
 } CpuTopology;
 
diff --git a/softmmu/vl.c b/softmmu/vl.c
index ff2685dff8..dadb798ac7 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -3935,6 +3935,7 @@ void qemu_init(int argc, char **argv, char **envp)
 current_machine->smp.max_cpus = machine_class->default_cpus;
 current_machine->smp.cores = 1;
 current_machine->smp.threads = 1;
+current_machine->smp.sockets = 1;
 
 machine_class->smp_parse(current_machine,
 qemu_opts_find(qemu_find_opts("smp-opts"), NULL));




[PATCH v7 12/13] target/i386: Enable new apic id encoding for EPYC based cpus models

2020-03-11 Thread Babu Moger
The APIC ID is decoded based on the sequence sockets->dies->cores->threads.
This works fine for most standard AMD and other vendors' configurations,
but this decoding sequence does not follow that of AMD's APIC ID enumeration
strictly. In some cases this can cause CPU topology inconsistency.

When booting a guest VM, the kernel tries to validate the topology, and finds
it inconsistent with the enumeration of EPYC cpu models. The more details are
in the bug https://bugzilla.redhat.com/show_bug.cgi?id=1728166.

To fix the problem we need to build the topology as per the Processor
Programming Reference (PPR) for AMD Family 17h Model 01h, Revision B1
Processors. The documentation is available from the bugzilla Link below.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537
It is also available at
https://www.amd.com/system/files/TechDocs/55570-B1_PUB.zip

Here is the text from the PPR.
Operating systems are expected to use Core::X86::Cpuid::SizeId[ApicIdSize], the
number of least significant bits in the Initial APIC ID that indicate core ID
within a processor, in constructing per-core CPUID masks.
Core::X86::Cpuid::SizeId[ApicIdSize] determines the maximum number of cores
(MNC) that the processor could theoretically support, not the actual number of
cores that are actually implemented or enabled on the processor, as indicated
by Core::X86::Cpuid::SizeId[NC].
Each Core::X86::Apic::ApicId[ApicId] register is preset as follows:
• ApicId[6] = Socket ID.
• ApicId[5:4] = Node ID.
• ApicId[3] = Logical CCX L3 complex ID
• ApicId[2:0]= (SMT) ? {LogicalCoreID[1:0],ThreadId} : {1'b0,LogicalCoreID[1:0]}

The new apic id encoding is enabled for EPYC and EPYC-Rome models.

Signed-off-by: Babu Moger 
Acked-by: Michael S. Tsirkin 
Acked-by: Igor Mammedov 
---
 target/i386/cpu.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 1e4400df7a..9ffaf5e2a0 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -3925,6 +3925,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
 .xlevel = 0x801E,
 .model_id = "AMD EPYC Processor",
 .cache_info = _cache_info,
+.use_epyc_apic_id_encoding = 1,
 .versions = (X86CPUVersionDefinition[]) {
 { .version = 1 },
 {
@@ -4052,6 +4053,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
 .xlevel = 0x801E,
 .model_id = "AMD EPYC-Rome Processor",
 .cache_info = _rome_cache_info,
+.use_epyc_apic_id_encoding = 1,
 },
 };
 




[PATCH v7 11/13] hw/i386: Move arch_id decode inside x86_cpus_init

2020-03-11 Thread Babu Moger
Apicid calculation depends on knowing the total number of numa nodes
for EPYC cpu models. Right now, we are calculating the arch_id while
parsing the numa(parse_numa). At this time, it is not known how many
total numa nodes are configured in the system.

Move the arch_id calculation inside x86_cpus_init. At this time, smp
parse is already completed and numa node information is available.

Override the handlers if use_epyc_apic_id_encoding is enabled in
cpu model definition.

Also replace the calling convention to use handlers from
X86MachineState.

Signed-off-by: Babu Moger 
---
 hw/i386/pc.c  |6 +++---
 hw/i386/x86.c |   37 ++---
 2 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 98ee763f68..2d7d611184 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1580,14 +1580,14 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev,
 topo_ids.die_id = cpu->die_id;
 topo_ids.core_id = cpu->core_id;
 topo_ids.smt_id = cpu->thread_id;
-cpu->apic_id = x86_apicid_from_topo_ids(_info, _ids);
+cpu->apic_id = x86ms->apicid_from_topo_ids(_info, _ids);
 }
 
 cpu_slot = pc_find_cpu_slot(MACHINE(pcms), cpu->apic_id, );
 if (!cpu_slot) {
 MachineState *ms = MACHINE(pcms);
 
-x86_topo_ids_from_apicid(cpu->apic_id, _info, _ids);
+x86ms->topo_ids_from_apicid(cpu->apic_id, _info, _ids);
 error_setg(errp,
 "Invalid CPU [socket: %u, die: %u, core: %u, thread: %u] with"
 " APIC ID %" PRIu32 ", valid index range 0:%d",
@@ -1608,7 +1608,7 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev,
 /* TODO: move socket_id/core_id/thread_id checks into x86_cpu_realizefn()
  * once -smp refactoring is complete and there will be CPU private
  * CPUState::nr_cores and CPUState::nr_threads fields instead of globals */
-x86_topo_ids_from_apicid(cpu->apic_id, _info, _ids);
+x86ms->topo_ids_from_apicid(cpu->apic_id, _info, _ids);
 if (cpu->socket_id != -1 && cpu->socket_id != topo_ids.pkg_id) {
 error_setg(errp, "property socket-id: %u doesn't match set apic-id:"
 " 0x%x (socket-id: %u)", cpu->socket_id, cpu->apic_id,
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index 0a81ab5151..023dce1dbd 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -68,6 +68,22 @@ inline void init_topo_info(X86CPUTopoInfo *topo_info,
 topo_info->threads_per_core = ms->smp.threads;
 }
 
+/*
+ * Set up with the new EPYC topology handlers
+ *
+ * AMD uses different apic id encoding for EPYC based cpus. Override
+ * the default topo handlers with EPYC encoding handlers.
+ */
+static void x86_set_epyc_topo_handlers(MachineState *machine)
+{
+X86MachineState *x86ms = X86_MACHINE(machine);
+
+x86ms->apicid_from_cpu_idx = x86_apicid_from_cpu_idx_epyc;
+x86ms->topo_ids_from_apicid = x86_topo_ids_from_apicid_epyc;
+x86ms->apicid_from_topo_ids = x86_apicid_from_topo_ids_epyc;
+x86ms->apicid_pkg_offset = apicid_pkg_offset_epyc;
+}
+
 /*
  * Calculates initial APIC ID for a specific CPU index
  *
@@ -86,7 +102,7 @@ uint32_t x86_cpu_apic_id_from_index(X86MachineState *x86ms,
 
 init_topo_info(_info, x86ms);
 
-correct_id = x86_apicid_from_cpu_idx(_info, cpu_index);
+correct_id = x86ms->apicid_from_cpu_idx(_info, cpu_index);
 if (x86mc->compat_apic_id_mode) {
 if (cpu_index != correct_id && !warned && !qtest_enabled()) {
 error_report("APIC IDs set in compatibility mode, "
@@ -121,6 +137,11 @@ void x86_cpus_init(X86MachineState *x86ms, int 
default_cpu_version)
 MachineState *ms = MACHINE(x86ms);
 MachineClass *mc = MACHINE_GET_CLASS(x86ms);
 
+/* Check for apicid encoding */
+if (cpu_x86_use_epyc_apic_id_encoding(ms->cpu_type)) {
+x86_set_epyc_topo_handlers(ms);
+}
+
 x86_cpu_set_default_version(default_cpu_version);
 
 /*
@@ -134,6 +155,12 @@ void x86_cpus_init(X86MachineState *x86ms, int 
default_cpu_version)
 x86ms->apic_id_limit = x86_cpu_apic_id_from_index(x86ms,
   ms->smp.max_cpus - 1) + 
1;
 possible_cpus = mc->possible_cpu_arch_ids(ms);
+
+for (i = 0; i < ms->smp.cpus; i++) {
+ms->possible_cpus->cpus[i].arch_id =
+x86_cpu_apic_id_from_index(x86ms, i);
+}
+
 for (i = 0; i < ms->smp.cpus; i++) {
 x86_cpu_new(x86ms, possible_cpus->cpus[i].arch_id, _fatal);
 }
@@ -158,8 +185,7 @@ int64_t x86_get_default_cpu_node_id(const MachineState *ms, 
int idx)
init_topo_info(_info, x86ms);
 
assert(idx < ms->possible_cpus->len);
-   x86_topo_ids_from_apicid(ms->possible_cpus->cpus[idx].arch_id,
-_info, _ids);
+   x86_topo_ids_from_idx(_info, idx, _ids);
return topo_ids.pkg_id % ms->numa_state->num_nodes;
 }
 
@@ -190,10 +216,7 @@ const CPUArchIdList 
*x86_possible_cpu_arch_ids(MachineState *ms)
 
 

[PATCH v7 02/13] hw/i386: Consolidate topology functions

2020-03-11 Thread Babu Moger
Now that we have all the parameters in X86CPUTopoInfo, we can just
pass the structure to calculate the offsets and width.

Signed-off-by: Babu Moger 
Reviewed-by: Igor Mammedov 
Acked-by: Michael S. Tsirkin 
---
 include/hw/i386/topology.h |   68 +--
 target/i386/cpu.c  |   23 +++
 tests/test-x86-cpuid.c |   69 +++-
 3 files changed, 75 insertions(+), 85 deletions(-)

diff --git a/include/hw/i386/topology.h b/include/hw/i386/topology.h
index 7ea507f376..ba52d49079 100644
--- a/include/hw/i386/topology.h
+++ b/include/hw/i386/topology.h
@@ -69,56 +69,42 @@ static unsigned apicid_bitwidth_for_count(unsigned count)
 
 /* Bit width of the SMT_ID (thread ID) field on the APIC ID
  */
-static inline unsigned apicid_smt_width(unsigned nr_dies,
-unsigned nr_cores,
-unsigned nr_threads)
+static inline unsigned apicid_smt_width(X86CPUTopoInfo *topo_info)
 {
-return apicid_bitwidth_for_count(nr_threads);
+return apicid_bitwidth_for_count(topo_info->threads_per_core);
 }
 
 /* Bit width of the Core_ID field
  */
-static inline unsigned apicid_core_width(unsigned nr_dies,
- unsigned nr_cores,
- unsigned nr_threads)
+static inline unsigned apicid_core_width(X86CPUTopoInfo *topo_info)
 {
-return apicid_bitwidth_for_count(nr_cores);
+return apicid_bitwidth_for_count(topo_info->cores_per_die);
 }
 
 /* Bit width of the Die_ID field */
-static inline unsigned apicid_die_width(unsigned nr_dies,
-unsigned nr_cores,
-unsigned nr_threads)
+static inline unsigned apicid_die_width(X86CPUTopoInfo *topo_info)
 {
-return apicid_bitwidth_for_count(nr_dies);
+return apicid_bitwidth_for_count(topo_info->dies_per_pkg);
 }
 
 /* Bit offset of the Core_ID field
  */
-static inline unsigned apicid_core_offset(unsigned nr_dies,
-  unsigned nr_cores,
-  unsigned nr_threads)
+static inline unsigned apicid_core_offset(X86CPUTopoInfo *topo_info)
 {
-return apicid_smt_width(nr_dies, nr_cores, nr_threads);
+return apicid_smt_width(topo_info);
 }
 
 /* Bit offset of the Die_ID field */
-static inline unsigned apicid_die_offset(unsigned nr_dies,
-  unsigned nr_cores,
-   unsigned nr_threads)
+static inline unsigned apicid_die_offset(X86CPUTopoInfo *topo_info)
 {
-return apicid_core_offset(nr_dies, nr_cores, nr_threads) +
-   apicid_core_width(nr_dies, nr_cores, nr_threads);
+return apicid_core_offset(topo_info) + apicid_core_width(topo_info);
 }
 
 /* Bit offset of the Pkg_ID (socket ID) field
  */
-static inline unsigned apicid_pkg_offset(unsigned nr_dies,
- unsigned nr_cores,
- unsigned nr_threads)
+static inline unsigned apicid_pkg_offset(X86CPUTopoInfo *topo_info)
 {
-return apicid_die_offset(nr_dies, nr_cores, nr_threads) +
-   apicid_die_width(nr_dies, nr_cores, nr_threads);
+return apicid_die_offset(topo_info) + apicid_die_width(topo_info);
 }
 
 /* Make APIC ID for the CPU based on Pkg_ID, Core_ID, SMT_ID
@@ -128,16 +114,9 @@ static inline unsigned apicid_pkg_offset(unsigned nr_dies,
 static inline apic_id_t apicid_from_topo_ids(X86CPUTopoInfo *topo_info,
  const X86CPUTopoIDs *topo_ids)
 {
-unsigned nr_dies = topo_info->dies_per_pkg;
-unsigned nr_cores = topo_info->cores_per_die;
-unsigned nr_threads = topo_info->threads_per_core;
-
-return (topo_ids->pkg_id  <<
-   apicid_pkg_offset(nr_dies, nr_cores, nr_threads)) |
-   (topo_ids->die_id  <<
-   apicid_die_offset(nr_dies, nr_cores, nr_threads)) |
-   (topo_ids->core_id <<
-   apicid_core_offset(nr_dies, nr_cores, nr_threads)) |
+return (topo_ids->pkg_id  << apicid_pkg_offset(topo_info)) |
+   (topo_ids->die_id  << apicid_die_offset(topo_info)) |
+   (topo_ids->core_id << apicid_core_offset(topo_info)) |
topo_ids->smt_id;
 }
 
@@ -165,20 +144,15 @@ static inline void x86_topo_ids_from_apicid(apic_id_t 
apicid,
 X86CPUTopoInfo *topo_info,
 X86CPUTopoIDs *topo_ids)
 {
-unsigned nr_dies = topo_info->dies_per_pkg;
-unsigned nr_cores = topo_info->cores_per_die;
-unsigned nr_threads = topo_info->threads_per_core;
-
 topo_ids->smt_id = apicid &
-~(0xUL << apicid_smt_width(nr_dies, nr_cores, nr_threads));
+~(0xUL << apicid_smt_width(topo_info));
 topo_ids->core_id =
-

[PATCH v7 05/13] hw/i386: Update structures to save the number of nodes per package

2020-03-11 Thread Babu Moger
Update structures X86CPUTopoIDs and CPUX86State to hold the number of
nodes per package. This is required to build EPYC mode topology.

Signed-off-by: Babu Moger 
Reviewed-by: Igor Mammedov 
Acked-by: Michael S. Tsirkin 
---
 hw/i386/pc.c   |1 +
 hw/i386/x86.c  |1 +
 include/hw/i386/topology.h |1 +
 target/i386/cpu.c  |1 +
 target/i386/cpu.h  |1 +
 tests/test-x86-cpuid.c |   40 
 6 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 05e7f1090f..ee89fcd1c3 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1525,6 +1525,7 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev,
 init_topo_info(_info, x86ms);
 
 env->nr_dies = x86ms->smp_dies;
+env->nr_nodes = topo_info.nodes_per_pkg;
 
 /*
  * If APIC ID is not set,
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index 84d1944a34..42834d2319 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -62,6 +62,7 @@ inline void init_topo_info(X86CPUTopoInfo *topo_info,
 {
 MachineState *ms = MACHINE(x86ms);
 
+topo_info->nodes_per_pkg = ms->numa_state->num_nodes / ms->smp.sockets;
 topo_info->dies_per_pkg = x86ms->smp_dies;
 topo_info->cores_per_die = ms->smp.cores;
 topo_info->threads_per_core = ms->smp.threads;
diff --git a/include/hw/i386/topology.h b/include/hw/i386/topology.h
index ba52d49079..04f01e2a09 100644
--- a/include/hw/i386/topology.h
+++ b/include/hw/i386/topology.h
@@ -53,6 +53,7 @@ typedef struct X86CPUTopoIDs {
 } X86CPUTopoIDs;
 
 typedef struct X86CPUTopoInfo {
+unsigned nodes_per_pkg;
 unsigned dies_per_pkg;
 unsigned cores_per_die;
 unsigned threads_per_core;
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 6df3127fd7..2e5be37b21 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6957,6 +6957,7 @@ static void x86_cpu_initfn(Object *obj)
 FeatureWord w;
 
 env->nr_dies = 1;
+env->nr_nodes = 1;
 cpu_set_cpustate_pointers(cpu);
 
 object_property_add(obj, "family", "int",
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 68b186d258..7e9e963d78 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -1609,6 +1609,7 @@ typedef struct CPUX86State {
 TPRAccess tpr_access_type;
 
 unsigned nr_dies;
+unsigned nr_nodes;
 } CPUX86State;
 
 struct kvm_msrs;
diff --git a/tests/test-x86-cpuid.c b/tests/test-x86-cpuid.c
index bfabc0403a..049030a50e 100644
--- a/tests/test-x86-cpuid.c
+++ b/tests/test-x86-cpuid.c
@@ -31,12 +31,12 @@ static void test_topo_bits(void)
 X86CPUTopoInfo topo_info = {0};
 
 /* simple tests for 1 thread per core, 1 core per die, 1 die per package */
-topo_info = (X86CPUTopoInfo) {1, 1, 1};
+topo_info = (X86CPUTopoInfo) {0, 1, 1, 1};
 g_assert_cmpuint(apicid_smt_width(_info), ==, 0);
 g_assert_cmpuint(apicid_core_width(_info), ==, 0);
 g_assert_cmpuint(apicid_die_width(_info), ==, 0);
 
-topo_info = (X86CPUTopoInfo) {1, 1, 1};
+topo_info = (X86CPUTopoInfo) {0, 1, 1, 1};
 g_assert_cmpuint(x86_apicid_from_cpu_idx(_info, 0), ==, 0);
 g_assert_cmpuint(x86_apicid_from_cpu_idx(_info, 1), ==, 1);
 g_assert_cmpuint(x86_apicid_from_cpu_idx(_info, 2), ==, 2);
@@ -45,39 +45,39 @@ static void test_topo_bits(void)
 
 /* Test field width calculation for multiple values
  */
-topo_info = (X86CPUTopoInfo) {1, 1, 2};
+topo_info = (X86CPUTopoInfo) {0, 1, 1, 2};
 g_assert_cmpuint(apicid_smt_width(_info), ==, 1);
-topo_info = (X86CPUTopoInfo) {1, 1, 3};
+topo_info = (X86CPUTopoInfo) {0, 1, 1, 3};
 g_assert_cmpuint(apicid_smt_width(_info), ==, 2);
-topo_info = (X86CPUTopoInfo) {1, 1, 4};
+topo_info = (X86CPUTopoInfo) {0, 1, 1, 4};
 g_assert_cmpuint(apicid_smt_width(_info), ==, 2);
 
-topo_info = (X86CPUTopoInfo) {1, 1, 14};
+topo_info = (X86CPUTopoInfo) {0, 1, 1, 14};
 g_assert_cmpuint(apicid_smt_width(_info), ==, 4);
-topo_info = (X86CPUTopoInfo) {1, 1, 15};
+topo_info = (X86CPUTopoInfo) {0, 1, 1, 15};
 g_assert_cmpuint(apicid_smt_width(_info), ==, 4);
-topo_info = (X86CPUTopoInfo) {1, 1, 16};
+topo_info = (X86CPUTopoInfo) {0, 1, 1, 16};
 g_assert_cmpuint(apicid_smt_width(_info), ==, 4);
-topo_info = (X86CPUTopoInfo) {1, 1, 17};
+topo_info = (X86CPUTopoInfo) {0, 1, 1, 17};
 g_assert_cmpuint(apicid_smt_width(_info), ==, 5);
 
 
-topo_info = (X86CPUTopoInfo) {1, 30, 2};
+topo_info = (X86CPUTopoInfo) {0, 1, 30, 2};
 g_assert_cmpuint(apicid_core_width(_info), ==, 5);
-topo_info = (X86CPUTopoInfo) {1, 31, 2};
+topo_info = (X86CPUTopoInfo) {0, 1, 31, 2};
 g_assert_cmpuint(apicid_core_width(_info), ==, 5);
-topo_info = (X86CPUTopoInfo) {1, 32, 2};
+topo_info = (X86CPUTopoInfo) {0, 1, 32, 2};
 g_assert_cmpuint(apicid_core_width(_info), ==, 5);
-topo_info = (X86CPUTopoInfo) {1, 33, 2};
+topo_info = (X86CPUTopoInfo) {0, 1, 33, 2};
   

[PATCH v7 06/13] hw/i386: Rename apicid_from_topo_ids to x86_apicid_from_topo_ids

2020-03-11 Thread Babu Moger
For consistency rename apicid_from_topo_ids to x86_apicid_from_topo_ids.
No functional change.

Signed-off-by: Babu Moger 
Reviewed-by: Igor Mammedov 
Acked-by: Michael S. Tsirkin 
---
 hw/i386/pc.c   |2 +-
 include/hw/i386/topology.h |6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index ee89fcd1c3..98ee763f68 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1580,7 +1580,7 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev,
 topo_ids.die_id = cpu->die_id;
 topo_ids.core_id = cpu->core_id;
 topo_ids.smt_id = cpu->thread_id;
-cpu->apic_id = apicid_from_topo_ids(_info, _ids);
+cpu->apic_id = x86_apicid_from_topo_ids(_info, _ids);
 }
 
 cpu_slot = pc_find_cpu_slot(MACHINE(pcms), cpu->apic_id, );
diff --git a/include/hw/i386/topology.h b/include/hw/i386/topology.h
index 04f01e2a09..b9593b9905 100644
--- a/include/hw/i386/topology.h
+++ b/include/hw/i386/topology.h
@@ -112,8 +112,8 @@ static inline unsigned apicid_pkg_offset(X86CPUTopoInfo 
*topo_info)
  *
  * The caller must make sure core_id < nr_cores and smt_id < nr_threads.
  */
-static inline apic_id_t apicid_from_topo_ids(X86CPUTopoInfo *topo_info,
- const X86CPUTopoIDs *topo_ids)
+static inline apic_id_t x86_apicid_from_topo_ids(X86CPUTopoInfo *topo_info,
+ const X86CPUTopoIDs *topo_ids)
 {
 return (topo_ids->pkg_id  << apicid_pkg_offset(topo_info)) |
(topo_ids->die_id  << apicid_die_offset(topo_info)) |
@@ -165,7 +165,7 @@ static inline apic_id_t 
x86_apicid_from_cpu_idx(X86CPUTopoInfo *topo_info,
 {
 X86CPUTopoIDs topo_ids;
 x86_topo_ids_from_idx(topo_info, cpu_index, _ids);
-return apicid_from_topo_ids(topo_info, _ids);
+return x86_apicid_from_topo_ids(topo_info, _ids);
 }
 
 #endif /* HW_I386_TOPOLOGY_H */




[PATCH v7 00/13] APIC ID fixes for AMD EPYC CPU model

2020-03-11 Thread Babu Moger
This series fixes APIC ID encoding problem reported on AMD EPYC cpu models.
https://bugzilla.redhat.com/show_bug.cgi?id=1728166

Currently, the APIC ID is decoded based on the sequence
sockets->dies->cores->threads. This works for most standard AMD and other
vendors' configurations, but this decoding sequence does not follow that of
AMD's APIC ID enumeration strictly. In some cases this can cause CPU topology
inconsistency.  When booting a guest VM, the kernel tries to validate the
topology, and finds it inconsistent with the enumeration of EPYC cpu models.

To fix the problem we need to build the topology as per the Processor
Programming Reference (PPR) for AMD Family 17h Model 01h, Revision B1
Processors. The documentation is available from the bugzilla Link below.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537

Here is the text from the PPR.
Operating systems are expected to use Core::X86::Cpuid::SizeId[ApicIdSize], the
number of least significant bits in the Initial APIC ID that indicate core ID
within a processor, in constructing per-core CPUID masks.
Core::X86::Cpuid::SizeId[ApicIdSize] determines the maximum number of cores
(MNC) that the processor could theoretically support, not the actual number of
cores that are actually implemented or enabled on the processor, as indicated
by Core::X86::Cpuid::SizeId[NC].
Each Core::X86::Apic::ApicId[ApicId] register is preset as follows:
• ApicId[6] = Socket ID.
• ApicId[5:4] = Node ID.
• ApicId[3] = Logical CCX L3 complex ID
• ApicId[2:0]= (SMT) ? {LogicalCoreID[1:0],ThreadId} : {1'b0,LogicalCoreID[1:0]}

v7:
 Generated the patches on top of git://github.com/ehabkost/qemu.git (x86-next).
 Changes from v6.
 1. Added new function x86_set_epyc_topo_handlers to override the apic id
encoding handlers.
 2. Separated the code to set use_epyc_apic_id_encoding and added as a new patch
as it looked more logical.
 3. Fixed minor typos.

v6:
 
https://lore.kernel.org/qemu-devel/158389385028.22020.7608244627303132902.st...@naples-babu.amd.com/
 Generated the patches on top of git://github.com/ehabkost/qemu.git (x86-next).
 Changes from v5.
 1. Eduardo has already queued couple of patches, submitting the rest here.
 2. Major change is how the EPYC mode apic id encoding handlers are loaded.
Added a boolean variable use_epyc_apic_id_encoding in X86CPUDefinition. 
The variable is will be used to tell if we need to use EPYC mode encoding.
 3. Eduardo reported bysectability problem with x86 unit test code.
Quashed the patches in 1 and 2 to resolve it. Problem was change in calling
conventions of topology related functions.
 4. Also set the use_epyc_apic_id_encoding for EPYC-Rome. This model is
added recently to the cpu table.

v5:
 
https://lore.kernel.org/qemu-devel/158326531474.40452.11433722850425537745.st...@naples-babu.amd.com/
 Generated the patches on top of git://github.com/ehabkost/qemu.git (x86-next).
 Changes from v4.
 1. Re-arranged the patches 2 and 4 as suggested by Igor.
 2. Kept the apicid handler functions inside X86MachineState as discussed.
These handlers are loaded from X86CPUDefinitions.
 3. Removed unnecessary X86CPUstate initialization from x86_cpu_new. Suggested
by Igor.
 4. And other minor changes related to patch format.

v4:
 
https://lore.kernel.org/qemu-devel/158161767653.48948.10578064482878399556.st...@naples-babu.amd.com/
 Changes from v3.
 1. Moved the arch_id calculation inside the function x86_cpus_init. With this 
change,
we dont need to change common numa code.(suggested by Igor)
 2. Introduced the model specific handlers inside X86CPUDefinitions.
These handlers are loaded into X86MachineState during the init.
 3. Removed llc_id from x86CPU.
 4. Removed init_apicid_fn hanlder from MachineClass. Kept all the code changes
inside the x86.
 5. Added new handler function apicid_pkg_offset for pkg_offset calculation.
 6. And some Other minor changes.

v3:
  
https://lore.kernel.org/qemu-devel/157541968844.46157.17994918142533791313.st...@naples-babu.amd.com/
 
  1. Consolidated the topology information in structure X86CPUTopoInfo.
  2. Changed the ccx_id to llc_id as commented by upstream.
  3. Generalized the apic id decoding. It is mostly similar to current apic id
 except that it adds new field llc_id when numa configured. Removes all the
 hardcoded values.
  4. Removed the earlier parse_numa split. And moved the numa node 
initialization
 inside the numa_complete_configuration. This is bit cleaner as commented 
by 
 Eduardo.
  5. Added new function init_apicid_fn inside machine_class structure. This
 will be used to update the apic id handler specific to cpu model.
  6. Updated the cpuid unit tests.
  7. TODO : Need to figure out how to dynamically update the handlers using cpu 
models.
 I might some guidance on that.

v2:
  
https://lore.kernel.org/qemu-devel/156779689013.21957.1631551572950676212.stgit@localhost.localdomain/
  1. Introduced the new property 

[PATCH 2/2] mmap-alloc: Include osdep.h before checking CONFIG_LINUX

2020-03-11 Thread Eduardo Habkost
The CONFIG_LINUX check at the top of mmap-alloc.c never worked
because it was done before including osdep.h.

This means MAP_SYNC and MAP_SHARED_VALIDATE would always be set
to 0 at the beginning of the file.  Luckily, this didn't break
when using recent glibc versions (2.28+), because those macros
were redefined by glibc headers.

Move the CONFIG_LINUX check after the main include lines, so the
CONFIG_LINUX check works and we actually include .
This will make MAP_SYNC and MAP_SHARED_VALIDATE available even if
the host has an older glibc version.

Reported-by: Jingqi Liu 
Signed-off-by: Eduardo Habkost 
---
 util/mmap-alloc.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c
index 27dcccd8ec..7c2ce98eb0 100644
--- a/util/mmap-alloc.c
+++ b/util/mmap-alloc.c
@@ -9,6 +9,9 @@
  * This work is licensed under the terms of the GNU GPL, version 2 or
  * later.  See the COPYING file in the top-level directory.
  */
+#include "qemu/osdep.h"
+#include "qemu/mmap-alloc.h"
+#include "qemu/host-utils.h"
 
 #ifdef CONFIG_LINUX
 #include 
@@ -17,10 +20,6 @@
 #define MAP_SHARED_VALIDATE   0x0
 #endif /* CONFIG_LINUX */
 
-#include "qemu/osdep.h"
-#include "qemu/mmap-alloc.h"
-#include "qemu/host-utils.h"
-
 #define HUGETLBFS_MAGIC   0x958458f6
 
 #ifdef CONFIG_LINUX
-- 
2.24.1




[PATCH v7 01/13] hw/i386: Introduce X86CPUTopoInfo to contain topology info

2020-03-11 Thread Babu Moger
This is an effort to re-arrange few data structure for better readability.

1. Add X86CPUTopoInfo which will have all the topology informations
   required to build the cpu topology. There is no functional changes.

2. Introduce init_topo_info to initialize X86CPUTopoInfo members from
   X86MachineState.

3. Update x86 unit tests for new calling convention with parameter 
X86CPUTopoInfo

There is no functional changes.

Signed-off-by: Babu Moger 
---
 hw/i386/pc.c   |   12 ++--
 hw/i386/x86.c  |   32 
 include/hw/i386/topology.h |   38 --
 include/hw/i386/x86.h  |3 +++
 tests/test-x86-cpuid.c |   43 ---
 5 files changed, 81 insertions(+), 47 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index f52e84b2ba..662abb549d 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1513,6 +1513,7 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev,
 X86MachineState *x86ms = X86_MACHINE(pcms);
 unsigned int smp_cores = ms->smp.cores;
 unsigned int smp_threads = ms->smp.threads;
+X86CPUTopoInfo topo_info;
 
 if(!object_dynamic_cast(OBJECT(cpu), ms->cpu_type)) {
 error_setg(errp, "Invalid CPU type, expected cpu type: '%s'",
@@ -1520,6 +1521,8 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev,
 return;
 }
 
+init_topo_info(_info, x86ms);
+
 env->nr_dies = x86ms->smp_dies;
 
 /*
@@ -1575,16 +1578,14 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev,
 topo_ids.die_id = cpu->die_id;
 topo_ids.core_id = cpu->core_id;
 topo_ids.smt_id = cpu->thread_id;
-cpu->apic_id = apicid_from_topo_ids(x86ms->smp_dies, smp_cores,
-smp_threads, _ids);
+cpu->apic_id = apicid_from_topo_ids(_info, _ids);
 }
 
 cpu_slot = pc_find_cpu_slot(MACHINE(pcms), cpu->apic_id, );
 if (!cpu_slot) {
 MachineState *ms = MACHINE(pcms);
 
-x86_topo_ids_from_apicid(cpu->apic_id, x86ms->smp_dies,
- smp_cores, smp_threads, _ids);
+x86_topo_ids_from_apicid(cpu->apic_id, _info, _ids);
 error_setg(errp,
 "Invalid CPU [socket: %u, die: %u, core: %u, thread: %u] with"
 " APIC ID %" PRIu32 ", valid index range 0:%d",
@@ -1605,8 +1606,7 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev,
 /* TODO: move socket_id/core_id/thread_id checks into x86_cpu_realizefn()
  * once -smp refactoring is complete and there will be CPU private
  * CPUState::nr_cores and CPUState::nr_threads fields instead of globals */
-x86_topo_ids_from_apicid(cpu->apic_id, x86ms->smp_dies,
- smp_cores, smp_threads, _ids);
+x86_topo_ids_from_apicid(cpu->apic_id, _info, _ids);
 if (cpu->socket_id != -1 && cpu->socket_id != topo_ids.pkg_id) {
 error_setg(errp, "property socket-id: %u doesn't match set apic-id:"
 " 0x%x (socket-id: %u)", cpu->socket_id, cpu->apic_id,
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index 322fb6abbc..dbbff46a4b 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -57,6 +57,16 @@
 /* Physical Address of PVH entry point read from kernel ELF NOTE */
 static size_t pvh_start_addr;
 
+inline void init_topo_info(X86CPUTopoInfo *topo_info,
+   const X86MachineState *x86ms)
+{
+MachineState *ms = MACHINE(x86ms);
+
+topo_info->dies_per_pkg = x86ms->smp_dies;
+topo_info->cores_per_die = ms->smp.cores;
+topo_info->threads_per_core = ms->smp.threads;
+}
+
 /*
  * Calculates initial APIC ID for a specific CPU index
  *
@@ -68,13 +78,14 @@ static size_t pvh_start_addr;
 uint32_t x86_cpu_apic_id_from_index(X86MachineState *x86ms,
 unsigned int cpu_index)
 {
-MachineState *ms = MACHINE(x86ms);
 X86MachineClass *x86mc = X86_MACHINE_GET_CLASS(x86ms);
+X86CPUTopoInfo topo_info;
 uint32_t correct_id;
 static bool warned;
 
-correct_id = x86_apicid_from_cpu_idx(x86ms->smp_dies, ms->smp.cores,
- ms->smp.threads, cpu_index);
+init_topo_info(_info, x86ms);
+
+correct_id = x86_apicid_from_cpu_idx(_info, cpu_index);
 if (x86mc->compat_apic_id_mode) {
 if (cpu_index != correct_id && !warned && !qtest_enabled()) {
 error_report("APIC IDs set in compatibility mode, "
@@ -145,19 +156,22 @@ int64_t x86_get_default_cpu_node_id(const MachineState 
*ms, int idx)
 {
X86CPUTopoIDs topo_ids;
X86MachineState *x86ms = X86_MACHINE(ms);
+   X86CPUTopoInfo topo_info;
+
+   init_topo_info(_info, x86ms);
 
assert(idx < ms->possible_cpus->len);
x86_topo_ids_from_apicid(ms->possible_cpus->cpus[idx].arch_id,
-x86ms->smp_dies, ms->smp.cores,
-ms->smp.threads, _ids);
+_info, 

[PATCH 0/2] Fix MAP_SYNC support when host has older glibc version

2020-03-11 Thread Eduardo Habkost
This is an alternative to the patch submitted at:

  From: Jingqi Liu 
  Subject: [PATCH] util: fix to get configuration macros in util/mmap-alloc.c
  Date: Thu,  5 Mar 2020 23:41:42 +0800
  Message-Id: <20200305154142.63070-1-jingqi@intel.com>

Before moving the osdep.h include to the top of the file, we had
to address warnings triggered when  was included
after  (done in patch 1/2).

Eduardo Habkost (2):
  Use -isystem for linux-headers dir
  mmap-alloc: Include osdep.h before checking CONFIG_LINUX

 Makefile.target   | 2 +-
 configure | 2 +-
 util/mmap-alloc.c | 7 +++
 3 files changed, 5 insertions(+), 6 deletions(-)

-- 
2.24.1





[PATCH 1/2] Use -isystem for linux-headers dir

2020-03-11 Thread Eduardo Habkost
glibc and Linux-provided headers are known to generate macro
redefinition warnings when used together.  For example:
 and  duplicate some macro definitions.

We normally never see those warnings because GCC suppresses
warnings generated by system headers.  We carry our own copy of
Linux header files, though, and this makes those warnings not be
suppressed when glibc headers are included before Linux headers
(e.g. if  is included before ).

Use -isystem instead of -I for linux-headers.  This makes the
compiler treat our linux-headers directory the same way it treats
system-provided Linux headers, and suppress warnings generated by
them.

Signed-off-by: Eduardo Habkost 
---
 Makefile.target | 2 +-
 configure   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile.target b/Makefile.target
index 2d43dc586a..934a9f7431 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -12,7 +12,7 @@ endif
 
 $(call set-vpath, $(SRC_PATH):$(BUILD_DIR))
 ifdef CONFIG_LINUX
-QEMU_CFLAGS += -I../linux-headers
+QEMU_CFLAGS += -isystem ../linux-headers
 endif
 QEMU_CFLAGS += -iquote .. -iquote $(SRC_PATH)/target/$(TARGET_BASE_ARCH) 
-DNEED_CPU_H
 
diff --git a/configure b/configure
index cbf864bff1..04a2a7f2dd 100755
--- a/configure
+++ b/configure
@@ -899,7 +899,7 @@ Linux)
   linux="yes"
   linux_user="yes"
   kvm="yes"
-  QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$PWD/linux-headers 
$QEMU_INCLUDES"
+  QEMU_INCLUDES="-isystem \$(SRC_PATH)/linux-headers -I$PWD/linux-headers 
$QEMU_INCLUDES"
   supported_os="yes"
   libudev="yes"
 ;;
-- 
2.24.1




[PATCH v8 12/18] hw/arm/allwinner: add RTC device support

2020-03-11 Thread Niek Linnenbank
Allwinner System-on-Chips usually contain a Real Time Clock (RTC)
for non-volatile system date and time keeping. This commit adds a generic
Allwinner RTC device that supports the RTC devices found in Allwinner SoC
family sun4i (A10), sun7i (A20) and sun6i and newer (A31, H2+, H3, etc).
The following RTC functionality and features are implemented:

 * Year-Month-Day read/write
 * Hour-Minute-Second read/write
 * General Purpose storage

The following boards are extended with the RTC device:

 * Cubieboard (hw/arm/cubieboard.c)
 * Orange Pi PC (hw/arm/orangepi.c)

Signed-off-by: Niek Linnenbank 
Reviewed-by: Alex Bennée 
---
 include/hw/arm/allwinner-a10.h |   2 +
 include/hw/arm/allwinner-h3.h  |   3 +
 include/hw/rtc/allwinner-rtc.h | 134 +++
 hw/arm/allwinner-a10.c |   8 +
 hw/arm/allwinner-h3.c  |   9 +-
 hw/rtc/allwinner-rtc.c | 411 +
 hw/rtc/Makefile.objs   |   1 +
 hw/rtc/trace-events|   4 +
 8 files changed, 571 insertions(+), 1 deletion(-)
 create mode 100644 include/hw/rtc/allwinner-rtc.h
 create mode 100644 hw/rtc/allwinner-rtc.c

diff --git a/include/hw/arm/allwinner-a10.h b/include/hw/arm/allwinner-a10.h
index ae33a84b18..77c82a9982 100644
--- a/include/hw/arm/allwinner-a10.h
+++ b/include/hw/arm/allwinner-a10.h
@@ -11,6 +11,7 @@
 #include "hw/ide/ahci.h"
 #include "hw/usb/hcd-ohci.h"
 #include "hw/usb/hcd-ehci.h"
+#include "hw/rtc/allwinner-rtc.h"
 
 #include "target/arm/cpu.h"
 
@@ -33,6 +34,7 @@ typedef struct AwA10State {
 AwEmacState emac;
 AllwinnerAHCIState sata;
 AwSdHostState mmc0;
+AwRtcState rtc;
 MemoryRegion sram_a;
 EHCISysBusState ehci[AW_A10_NUM_USB];
 OHCISysBusState ohci[AW_A10_NUM_USB];
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
index 065d020c73..82e4e59216 100644
--- a/include/hw/arm/allwinner-h3.h
+++ b/include/hw/arm/allwinner-h3.h
@@ -46,6 +46,7 @@
 #include "hw/misc/allwinner-sid.h"
 #include "hw/sd/allwinner-sdhost.h"
 #include "hw/net/allwinner-sun8i-emac.h"
+#include "hw/rtc/allwinner-rtc.h"
 #include "target/arm/cpu.h"
 #include "sysemu/block-backend.h"
 
@@ -88,6 +89,7 @@ enum {
 AW_H3_GIC_CPU,
 AW_H3_GIC_HYP,
 AW_H3_GIC_VCPU,
+AW_H3_RTC,
 AW_H3_CPUCFG,
 AW_H3_SDRAM
 };
@@ -129,6 +131,7 @@ typedef struct AwH3State {
 AwSidState sid;
 AwSdHostState mmc0;
 AwSun8iEmacState emac;
+AwRtcState rtc;
 GICState gic;
 MemoryRegion sram_a1;
 MemoryRegion sram_a2;
diff --git a/include/hw/rtc/allwinner-rtc.h b/include/hw/rtc/allwinner-rtc.h
new file mode 100644
index 00..7893f74795
--- /dev/null
+++ b/include/hw/rtc/allwinner-rtc.h
@@ -0,0 +1,134 @@
+/*
+ * Allwinner Real Time Clock emulation
+ *
+ * Copyright (C) 2019 Niek Linnenbank 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef HW_MISC_ALLWINNER_RTC_H
+#define HW_MISC_ALLWINNER_RTC_H
+
+#include "qom/object.h"
+#include "hw/sysbus.h"
+
+/**
+ * Constants
+ * @{
+ */
+
+/** Highest register address used by RTC device */
+#define AW_RTC_REGS_MAXADDR (0x200)
+
+/** Total number of known registers */
+#define AW_RTC_REGS_NUM (AW_RTC_REGS_MAXADDR / sizeof(uint32_t))
+
+/** @} */
+
+/**
+ * Object model types
+ * @{
+ */
+
+/** Generic Allwinner RTC device (abstract) */
+#define TYPE_AW_RTC  "allwinner-rtc"
+
+/** Allwinner RTC sun4i family (A10, A12) */
+#define TYPE_AW_RTC_SUN4ITYPE_AW_RTC "-sun4i"
+
+/** Allwinner RTC sun6i family and newer (A31, H2+, H3, etc) */
+#define TYPE_AW_RTC_SUN6ITYPE_AW_RTC "-sun6i"
+
+/** Allwinner RTC sun7i family (A20) */
+#define TYPE_AW_RTC_SUN7ITYPE_AW_RTC "-sun7i"
+
+/** @} */
+
+/**
+ * Object model macros
+ * @{
+ */
+
+#define AW_RTC(obj) \
+OBJECT_CHECK(AwRtcState, (obj), TYPE_AW_RTC)
+#define AW_RTC_CLASS(klass) \
+ OBJECT_CLASS_CHECK(AwRtcClass, (klass), TYPE_AW_RTC)
+#define AW_RTC_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(AwRtcClass, (obj), TYPE_AW_RTC)
+
+/** @} */
+
+/**
+ * Allwinner RTC per-object instance state.
+ */
+typedef struct AwRtcState {
+/*< private >*/
+SysBusDevice parent_obj;
+/*< public >*/
+
+/**
+ * Actual year represented by the device when year counter is zero
+ *
+ * Can be overridden by the user using the corresponding 'base-year'
+ * property. The base year used by the 

[PATCH v8 18/18] docs: add Orange Pi PC document

2020-03-11 Thread Niek Linnenbank
The Xunlong Orange Pi PC machine is a functional ARM machine
based on the Allwinner H3 System-on-Chip. It supports mainline
Linux, U-Boot, NetBSD and is covered by acceptance tests.

This commit adds a documentation text file with a description
of the machine and instructions for the user.

Signed-off-by: Niek Linnenbank 
Reviewed-by: Alex Bennée 
---
 docs/system/orangepi.rst   | 253 +
 docs/system/target-arm.rst |   2 +
 MAINTAINERS|   1 +
 3 files changed, 256 insertions(+)
 create mode 100644 docs/system/orangepi.rst

diff --git a/docs/system/orangepi.rst b/docs/system/orangepi.rst
new file mode 100644
index 00..a76d52fb33
--- /dev/null
+++ b/docs/system/orangepi.rst
@@ -0,0 +1,253 @@
+Orange Pi PC Machine Type
+^
+
+The Xunlong Orange Pi PC is an Allwinner H3 System on Chip
+based embedded computer with mainline support in both U-Boot
+and Linux. The board comes with a Quad Core Cortex-A7 @ 1.3GHz,
+1GiB RAM, 100Mbit ethernet, USB, SD/MMC, USB, HDMI and
+various other I/O.
+
+Supported devices
+"
+
+The Orange Pi PC machine supports the following devices:
+
+ * SMP (Quad Core Cortex-A7)
+ * Generic Interrupt Controller configuration
+ * SRAM mappings
+ * SDRAM controller
+ * Real Time Clock
+ * Timer device (re-used from Allwinner A10)
+ * UART
+ * SD/MMC storage controller
+ * EMAC ethernet
+ * USB 2.0 interfaces
+ * Clock Control Unit
+ * System Control module
+ * Security Identifier device
+
+Limitations
+"""
+
+Currently, Orange Pi PC does *not* support the following features:
+
+- Graphical output via HDMI, GPU and/or the Display Engine
+- Audio output
+- Hardware Watchdog
+
+Also see the 'unimplemented' array in the Allwinner H3 SoC module
+for a complete list of unimplemented I/O devices: ``./hw/arm/allwinner-h3.c``
+
+Boot options
+
+
+The Orange Pi PC machine can start using the standard -kernel functionality
+for loading a Linux kernel or ELF executable. Additionally, the Orange Pi PC
+machine can also emulate the BootROM which is present on an actual Allwinner H3
+based SoC, which loads the bootloader from a SD card, specified via the -sd 
argument
+to qemu-system-arm.
+
+Machine-specific options
+
+
+The following machine-specific options are supported:
+
+- allwinner-rtc.base-year=
+
+  The Allwinner RTC device is automatically created by the Orange Pi PC machine
+  and uses a default base year value which can be overridden using the 
'base-year' property.
+  The base year is the actual represented year when the RTC year value is zero.
+  This option can be used in case the target operating system driver uses a 
different
+  base year value. The minimum value for the base year is 1900.
+
+- allwinner-sid.identifier=abcd1122-a000-b000-c000-12345678
+
+  The Security Identifier value can be read by the guest.
+  For example, U-Boot uses it to determine a unique MAC address.
+
+The above machine-specific options can be specified in qemu-system-arm
+via the '-global' argument, for example:
+
+.. code-block:: bash
+
+  $ qemu-system-arm -M orangepi-pc -sd mycard.img \
+   -global allwinner-rtc.base-year=2000
+
+Running mainline Linux
+""
+
+Mainline Linux kernels from 4.19 up to latest master are known to work.
+To build a Linux mainline kernel that can be booted by the Orange Pi PC 
machine,
+simply configure the kernel using the sunxi_defconfig configuration:
+
+.. code-block:: bash
+
+  $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make mrproper
+  $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make sunxi_defconfig
+
+To be able to use USB storage, you need to manually enable the corresponding
+configuration item. Start the kconfig configuration tool:
+
+.. code-block:: bash
+
+  $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make menuconfig
+
+Navigate to the following item, enable it and save your configuration:
+
+  Device Drivers > USB support > USB Mass Storage support
+
+Build the Linux kernel with:
+
+.. code-block:: bash
+
+  $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make
+
+To boot the newly build linux kernel in QEMU with the Orange Pi PC machine, 
use:
+
+.. code-block:: bash
+
+  $ qemu-system-arm -M orangepi-pc -nic user -nographic \
+  -kernel /path/to/linux/arch/arm/boot/zImage \
+  -append 'console=ttyS0,115200' \
+  -dtb /path/to/linux/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dtb
+
+Orange Pi PC images
+"""
+
+Note that the mainline kernel does not have a root filesystem. You may provide 
it
+with an official Orange Pi PC image from the official website:
+
+  http://www.orangepi.org/downloadresources/
+
+Another possibility is to run an Armbian image for Orange Pi PC which
+can be downloaded from:
+
+   https://www.armbian.com/orange-pi-pc/
+
+Alternatively, you can also choose to build you own image with buildroot
+using the orangepi_pc_defconfig. Also see https://buildroot.org 

[PATCH v8 17/18] tests/boot_linux_console: Test booting NetBSD via U-Boot on OrangePi PC

2020-03-11 Thread Niek Linnenbank
From: Philippe Mathieu-Daudé 

This test boots U-Boot then NetBSD (stored on a SD card) on
a OrangePi PC board.

As it requires ~1.3GB of storage, it is disabled by default.

U-Boot is built by the Debian project [1], and the SD card image
is provided by the NetBSD organization [2].

Once the compressed SD card image is downloaded (304MB) and
extracted, this test is fast:

  $ AVOCADO_ALLOW_LARGE_STORAGE=yes \
avocado --show=app,console run -t machine:orangepi-pc \
  tests/acceptance/boot_linux_console.py
  console: U-Boot SPL 2020.01+dfsg-1 (Jan 08 2020 - 08:19:44 +)
  console: DRAM: 1024 MiB
  console: U-Boot 2020.01+dfsg-1 (Jan 08 2020 - 08:19:44 +) Allwinner 
Technology
  console: CPU:   Allwinner H3 (SUN8I )
  console: scanning bus usb@1c1b000 for devices... 1 USB Device(s) found
  console: scanning bus usb@1c1d000 for devices... 1 USB Device(s) found
  console: scanning usb for storage devices... 0 Storage Device(s) found
  console: Hit any key to stop autoboot:  0
  console: => setenv bootargs root=ld0a
  console: => setenv kernel netbsd-GENERIC.ub
  console: => setenv fdtfile dtb/sun8i-h3-orangepi-pc.dtb
  console: => boot
  console: ## Booting kernel from Legacy Image at 4200 ...
  console: Image Name:   NetBSD/earmv7hf 9.0_RC1
  console: Image Type:   ARM Linux Kernel Image (no loading done) (uncompressed)
  console: XIP Kernel Image (no loading done)
  console: Loading Device Tree to 49ff6000, end 49fffe01 ... OK
  console: Starting kernel ...
  console: [   1.000] NetBSD/evbarm (fdt) booting ...
  console: [   1.000] NetBSD 9.0 (GENERIC) #0: Fri Feb 14 00:06:28 UTC 2020
  console: [   1.000] 
mkre...@mkrepro.netbsd.org:/usr/src/sys/arch/evbarm/compile/GENERIC
  console: [   1.000] total memory = 1024 MB
  console: [   1.000] avail memory = 1003 MB
  console: [   1.000] armfdt0 (root)
  console: [   1.000] simplebus0 at armfdt0: Xunlong Orange Pi PC
  console: [   1.000] cpu0 at cpus0: Cortex-A7 r0p5 (Cortex V7A core)
  console: [   1.000] cpu0: DC enabled IC enabled WB enabled LABT branch 
prediction enabled
  console: [   1.000] cpu0: 32KB/64B 2-way L1 VIPT Instruction cache
  console: [   1.000] cpu0: 32KB/64B 2-way write-back-locking-C L1 PIPT 
Data cache
  console: [   1.000] cpu0: 2304KB/64B 16-way write-through L2 PIPT Unified 
cache
  console: [   1.000] vfp0 at cpu0: NEON MPE (VFP 3.0+), rounding, NaN 
propagation, denormals
  ...
  console: [   2.3812082] sdmmc0: SD card status: 4-bit, C0
  console: [   2.3812082] ld0 at sdmmc0: 
<0xaa:0x5859:QEMU!:0x01:0xdeadbeef:0x062>
  console: [   2.4012856] ld0: 1226 MB, 622 cyl, 64 head, 63 sec, 512 
bytes/sect x 2511872 sectors
  console: [   2.5321222] ld0: 4-bit width, High-Speed/SDR25, 50.000 MHz
  console: [   3.1068718] WARNING: 4 errors while detecting hardware; check 
system log.
  console: [   3.1179868] boot device: ld0
  console: [   3.1470623] root on ld0a dumps on ld0b
  console: [   3.2464436] root file system type: ffs
  console: [   3.2897123] kern.module.path=/stand/evbarm/9.0/modules
  console: Mon Feb 17 20:33:35 UTC 2020
  console: Starting root file system check:
  PASS (35.96 s)
  RESULTS: PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | 
CANCEL 0
  JOB TIME   : 36.09 s

Note, this test only took ~65 seconds to run on Travis-CI, see: [3].

This test is based on a description from Niek Linnenbank from [4].

[1] 
https://wiki.debian.org/InstallingDebianOn/Allwinner#Creating_a_bootable_SD_Card_with_u-boot
[2] https://wiki.netbsd.org/ports/evbarm/allwinner/
[3] https://travis-ci.org/philmd/qemu/jobs/638823612#L3778
[4] https://www.mail-archive.com/qemu-devel@nongnu.org/msg669347.html

Signed-off-by: Philippe Mathieu-Daudé 
Signed-off-by: Niek Linnenbank 
Reviewed-by: Alex Bennée 
Tested-by: Alex Bennée 
[NL: changed test to use NetBSD 9.0 final release and -global 
allwinner-rtc.base-year]
---
 tests/acceptance/boot_linux_console.py | 70 ++
 1 file changed, 70 insertions(+)

diff --git a/tests/acceptance/boot_linux_console.py 
b/tests/acceptance/boot_linux_console.py
index e035c88b07..f825cd9ef5 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -16,6 +16,7 @@ import shutil
 from avocado import skipUnless
 from avocado_qemu import Test
 from avocado_qemu import exec_command_and_wait_for_pattern
+from avocado_qemu import interrupt_interactive_console_until_pattern
 from avocado_qemu import wait_for_console_pattern
 from avocado.utils import process
 from avocado.utils import archive
@@ -667,6 +668,75 @@ class BootLinuxConsole(Test):
   'to ')
 self.wait_for_console_pattern('Starting Load Kernel Modules...')
 
+@skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited')
+def test_arm_orangepi_uboot_netbsd9(self):
+"""
+:avocado: tags=arch:arm
+:avocado: 

[PATCH v8 15/18] tests/boot_linux_console: Add a SD card test for the OrangePi PC board

2020-03-11 Thread Niek Linnenbank
From: Philippe Mathieu-Daudé 

The kernel image and DeviceTree blob are built by the Armbian
project (based on Debian):
https://www.armbian.com/orange-pi-pc/

The SD image is from the kernelci.org project:
https://kernelci.org/faq/#the-code

If ARM is a target being built, "make check-acceptance" will
automatically include this test by the use of the "arch:arm" tags.

Alternatively, this test can be run using:

  $ avocado --show=console run -t machine:orangepi-pc 
tests/acceptance/boot_linux_console.py
  console: Uncompressing Linux... done, booting the kernel.
  console: Booting Linux on physical CPU 0x0
  console: Linux version 4.20.7-sunxi (r...@armbian.com) (gcc version 7.2.1 
20171011 (Linaro GCC 7.2-2017.11)) #5.75 SMP Fri Feb 8 09:02:10 CET 2019
  console: CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=50c5387d
  [...]
  console: sunxi-wdt 1c20ca0.watchdog: Watchdog enabled (timeout=16 sec, 
nowayout=0)
  console: sunxi-mmc 1c0f000.mmc: Linked as a consumer to regulator.2
  console: sunxi-mmc 1c0f000.mmc: Got CD GPIO
  console: ledtrig-cpu: registered to indicate activity on CPUs
  console: hidraw: raw HID events driver (C) Jiri Kosina
  console: usbcore: registered new interface driver usbhid
  console: usbhid: USB HID core driver
  console: Initializing XFRM netlink socket
  console: sunxi-mmc 1c0f000.mmc: initialized, max. request size: 16384 KB
  console: NET: Registered protocol family 10
  console: mmc0: host does not support reading read-only switch, assuming 
write-enable
  console: mmc0: Problem switching card into high-speed mode!
  console: mmc0: new SD card at address 4567
  console: mmcblk0: mmc0:4567 QEMU! 60.0 MiB
  [...]
  console: EXT4-fs (mmcblk0): mounting ext2 file system using the ext4 subsystem
  console: EXT4-fs (mmcblk0): mounted filesystem without journal. Opts: (null)
  console: VFS: Mounted root (ext2 filesystem) on device 179:0.
  console: Run /sbin/init as init process
  console: EXT4-fs (mmcblk0): re-mounted. Opts: 
block_validity,barrier,user_xattr,acl
  console: Starting syslogd: OK
  console: Starting klogd: OK
  console: Populating /dev using udev: udevd[203]: starting version 3.2.7
  console: /bin/sh: can't access tty; job control turned off
  console: cat /proc/partitions
  console: / # cat /proc/partitions
  console: major minor  #blocks  name
  console: 10   4096 ram0
  console: 11   4096 ram1
  console: 12   4096 ram2
  console: 13   4096 ram3
  console: 1790  61440 mmcblk0
  console: reboot
  console: / # reboot
  console: umount: devtmpfs busy - remounted read-only
  console: EXT4-fs (mmcblk0): re-mounted. Opts: (null)
  console: The system is going down NOW!
  console: Sent SIGTERM to all processes
  console: Sent SIGKILL to all processes
  console: Requesting system reboot
  console: reboot: Restarting system
  JOB TIME   : 68.64 s

Signed-off-by: Philippe Mathieu-Daudé 
Signed-off-by: Niek Linnenbank 
Reviewed-by: Alex Bennée 
Tested-by: Alex Bennée 
[NL: rename in commit message Raspbian to Armbian, remove vm.set_machine()]
[NL: extend test with ethernet device checks]
---
 tests/acceptance/boot_linux_console.py | 47 ++
 1 file changed, 47 insertions(+)

diff --git a/tests/acceptance/boot_linux_console.py 
b/tests/acceptance/boot_linux_console.py
index dabc8ef2af..0762dbe83a 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -572,6 +572,53 @@ class BootLinuxConsole(Test):
 exec_command_and_wait_for_pattern(self, 'reboot',
 'reboot: Restarting system')
 
+def test_arm_orangepi_sd(self):
+"""
+:avocado: tags=arch:arm
+:avocado: tags=machine:orangepi-pc
+"""
+deb_url = ('https://apt.armbian.com/pool/main/l/'
+   'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb')
+deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315'
+deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
+kernel_path = self.extract_from_deb(deb_path,
+'/boot/vmlinuz-4.20.7-sunxi')
+dtb_path = '/usr/lib/linux-image-dev-sunxi/sun8i-h3-orangepi-pc.dtb'
+dtb_path = self.extract_from_deb(deb_path, dtb_path)
+rootfs_url = ('http://storage.kernelci.org/images/rootfs/buildroot/'
+  'kci-2019.02/armel/base/rootfs.ext2.xz')
+rootfs_hash = '692510cb625efda31640d1de0a8d60e26040f061'
+rootfs_path_xz = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash)
+rootfs_path = os.path.join(self.workdir, 'rootfs.cpio')
+archive.lzma_uncompress(rootfs_path_xz, rootfs_path)
+
+self.vm.set_console()
+kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
+   'console=ttyS0,115200 '
+   'root=/dev/mmcblk0 rootwait rw '
+

[PATCH v8 09/18] hw/arm/allwinner-h3: add EMAC ethernet device

2020-03-11 Thread Niek Linnenbank
The Allwinner Sun8i System on Chip family includes an Ethernet MAC (EMAC)
which provides 10M/100M/1000M Ethernet connectivity. This commit
adds support for the Allwinner EMAC from the Sun8i family (H2+, H3, A33, etc),
including emulation for the following functionality:

 * DMA transfers
 * MII interface
 * Transmit CRC calculation

Signed-off-by: Niek Linnenbank 
Reviewed-by: Alex Bennée 
---
 include/hw/arm/allwinner-h3.h |   3 +
 include/hw/net/allwinner-sun8i-emac.h |  99 +++
 hw/arm/allwinner-h3.c |  16 +-
 hw/arm/orangepi.c |   3 +
 hw/net/allwinner-sun8i-emac.c | 871 ++
 hw/arm/Kconfig|   1 +
 hw/net/Kconfig|   3 +
 hw/net/Makefile.objs  |   1 +
 hw/net/trace-events   |  10 +
 9 files changed, 1006 insertions(+), 1 deletion(-)
 create mode 100644 include/hw/net/allwinner-sun8i-emac.h
 create mode 100644 hw/net/allwinner-sun8i-emac.c

diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
index d71a4917ab..f9b9a02373 100644
--- a/include/hw/arm/allwinner-h3.h
+++ b/include/hw/arm/allwinner-h3.h
@@ -44,6 +44,7 @@
 #include "hw/misc/allwinner-h3-sysctrl.h"
 #include "hw/misc/allwinner-sid.h"
 #include "hw/sd/allwinner-sdhost.h"
+#include "hw/net/allwinner-sun8i-emac.h"
 #include "target/arm/cpu.h"
 
 /**
@@ -77,6 +78,7 @@ enum {
 AW_H3_UART1,
 AW_H3_UART2,
 AW_H3_UART3,
+AW_H3_EMAC,
 AW_H3_GIC_DIST,
 AW_H3_GIC_CPU,
 AW_H3_GIC_HYP,
@@ -120,6 +122,7 @@ typedef struct AwH3State {
 AwH3SysCtrlState sysctrl;
 AwSidState sid;
 AwSdHostState mmc0;
+AwSun8iEmacState emac;
 GICState gic;
 MemoryRegion sram_a1;
 MemoryRegion sram_a2;
diff --git a/include/hw/net/allwinner-sun8i-emac.h 
b/include/hw/net/allwinner-sun8i-emac.h
new file mode 100644
index 00..eda034e96b
--- /dev/null
+++ b/include/hw/net/allwinner-sun8i-emac.h
@@ -0,0 +1,99 @@
+/*
+ * Allwinner Sun8i Ethernet MAC emulation
+ *
+ * Copyright (C) 2019 Niek Linnenbank 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef HW_NET_ALLWINNER_SUN8I_EMAC_H
+#define HW_NET_ALLWINNER_SUN8I_EMAC_H
+
+#include "qom/object.h"
+#include "net/net.h"
+#include "hw/sysbus.h"
+
+/**
+ * Object model
+ * @{
+ */
+
+#define TYPE_AW_SUN8I_EMAC "allwinner-sun8i-emac"
+#define AW_SUN8I_EMAC(obj) \
+OBJECT_CHECK(AwSun8iEmacState, (obj), TYPE_AW_SUN8I_EMAC)
+
+/** @} */
+
+/**
+ * Allwinner Sun8i EMAC object instance state
+ */
+typedef struct AwSun8iEmacState {
+/*< private >*/
+SysBusDevice  parent_obj;
+/*< public >*/
+
+/** Maps I/O registers in physical memory */
+MemoryRegion iomem;
+
+/** Interrupt output signal to notify CPU */
+qemu_irq irq;
+
+/** Generic Network Interface Controller (NIC) for networking API */
+NICState *nic;
+
+/** Generic Network Interface Controller (NIC) configuration */
+NICConf  conf;
+
+/**
+ * @name Media Independent Interface (MII)
+ * @{
+ */
+
+uint8_t  mii_phy_addr;  /**< PHY address */
+uint32_t mii_cr;/**< Control */
+uint32_t mii_st;/**< Status */
+uint32_t mii_adv;   /**< Advertised Abilities */
+
+/** @} */
+
+/**
+ * @name Hardware Registers
+ * @{
+ */
+
+uint32_t basic_ctl0;/**< Basic Control 0 */
+uint32_t basic_ctl1;/**< Basic Control 1 */
+uint32_t int_en;/**< Interrupt Enable */
+uint32_t int_sta;   /**< Interrupt Status */
+uint32_t frm_flt;   /**< Receive Frame Filter */
+
+uint32_t rx_ctl0;   /**< Receive Control 0 */
+uint32_t rx_ctl1;   /**< Receive Control 1 */
+uint32_t rx_desc_head;  /**< Receive Descriptor List Address */
+uint32_t rx_desc_curr;  /**< Current Receive Descriptor Address */
+
+uint32_t tx_ctl0;   /**< Transmit Control 0 */
+uint32_t tx_ctl1;   /**< Transmit Control 1 */
+uint32_t tx_desc_head;  /**< Transmit Descriptor List Address */
+uint32_t tx_desc_curr;  /**< Current Transmit Descriptor Address */
+uint32_t tx_flowctl;/**< Transmit Flow Control */
+
+uint32_t mii_cmd;   /**< Management Interface Command */
+uint32_t mii_data; 

[PATCH v8 14/18] tests/boot_linux_console: Add initrd test for the Orange Pi PC board

2020-03-11 Thread Niek Linnenbank
From: Philippe Mathieu-Daudé 

This test boots a Linux kernel on a OrangePi PC board and verify
the serial output is working.

The kernel image and DeviceTree blob are built by the Armbian
project (based on Debian):
https://www.armbian.com/orange-pi-pc/

The cpio image used comes from the linux-build-test project:
https://github.com/groeck/linux-build-test

If ARM is a target being built, "make check-acceptance" will
automatically include this test by the use of the "arch:arm" tags.

Alternatively, this test can be run using:

  $ avocado --show=console run -t machine:orangepi-pc 
tests/acceptance/boot_linux_console.py
  console: Uncompressing Linux... done, booting the kernel.
  console: Booting Linux on physical CPU 0x0
  console: Linux version 4.20.7-sunxi (r...@armbian.com) (gcc version 7.2.1 
20171011 (Linaro GCC 7.2-2017.11)) #5.75 SMP Fri Feb 8 09:02:10 CET 2019
  console: CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=50c5387d
  console: CPU: div instructions available: patching division code
  console: CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction 
cache
  console: OF: fdt: Machine model: Xunlong Orange Pi PC
  [...]
  console: Trying to unpack rootfs image as initramfs...
  console: Freeing initrd memory: 3256K
  console: Freeing unused kernel memory: 1024K
  console: Run /init as init process
  console: mount: mounting devtmpfs on /dev failed: Device or resource busy
  console: Starting logging: OK
  console: Initializing random number generator... random: dd: uninitialized 
urandom read (512 bytes read)
  console: done.
  console: Starting network: OK
  console: Found console ttyS0
  console: Linux version 4.20.7-sunxi (r...@armbian.com) (gcc version 7.2.1 
20171011 (Linaro GCC 7.2-2017.11)) #5.75 SMP Fri Feb 8 09:02:10 CET 2019
  console: Boot successful.
  console: cat /proc/cpuinfo
  console: / # cat /proc/cpuinfo
  console: processor  : 0
  console: model name : ARMv7 Processor rev 5 (v7l)
  console: BogoMIPS   : 125.00
  console: Features   : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 
idiva idivt vfpd32 lpae evtstrm
  console: CPU implementer: 0x41
  console: CPU architecture: 7
  console: CPU variant: 0x0
  console: CPU part   : 0xc07
  console: CPU revision   : 5
  [...]
  console: processor  : 3
  console: model name : ARMv7 Processor rev 5 (v7l)
  console: BogoMIPS   : 125.00
  console: Features   : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 
idiva idivt vfpd32 lpae evtstrm
  console: CPU implementer: 0x41
  console: CPU architecture: 7
  console: CPU variant: 0x0
  console: CPU part   : 0xc07
  console: CPU revision   : 5
  console: Hardware   : Allwinner sun8i Family
  console: Revision   : 
  console: Serial : 
  console: cat /proc/iomem
  console: / # cat /proc/iomem
  console: 0100-010f : clock@100
  console: 01c0-01c00fff : system-control@1c0
  console: 01c02000-01c02fff : dma-controller@1c02000
  [...]
  console: reboot
  console: / # reboot
  console: / # Found console ttyS0
  console: Stopping network: OK
  console: hrtimer: interrupt took 21852064 ns
  console: Saving random seed... random: dd: uninitialized urandom read (512 
bytes read)
  console: done.
  console: Stopping logging: OK
  console: umount: devtmpfs busy - remounted read-only
  console: umount: can't unmount /: Invalid argument
  console: The system is going down NOW!
  console: Sent SIGTERM to all processes
  console: Sent SIGKILL to all processes
  console: Requesting system reboot
  console: reboot: Restarting system
  PASS (48.32 s)
  JOB TIME   : 49.16 s

Signed-off-by: Philippe Mathieu-Daudé 
Signed-off-by: Niek Linnenbank 
Reviewed-by: Alex Bennée 
Tested-by: Alex Bennée 
[NL: rename in commit message Raspbian to Armbian, remove vm.set_machine()]
---
 tests/acceptance/boot_linux_console.py | 40 ++
 1 file changed, 40 insertions(+)

diff --git a/tests/acceptance/boot_linux_console.py 
b/tests/acceptance/boot_linux_console.py
index 6f5af582f3..dabc8ef2af 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -532,6 +532,46 @@ class BootLinuxConsole(Test):
 console_pattern = 'Kernel command line: %s' % kernel_command_line
 self.wait_for_console_pattern(console_pattern)
 
+def test_arm_orangepi_initrd(self):
+"""
+:avocado: tags=arch:arm
+:avocado: tags=machine:orangepi-pc
+"""
+deb_url = ('https://apt.armbian.com/pool/main/l/'
+   'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb')
+deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315'
+deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
+kernel_path = self.extract_from_deb(deb_path,
+'/boot/vmlinuz-4.20.7-sunxi')
+dtb_path = 

[PATCH v8 11/18] hw/arm/allwinner-h3: add SDRAM controller device

2020-03-11 Thread Niek Linnenbank
In the Allwinner H3 SoC the SDRAM controller is responsible
for interfacing with the external Synchronous Dynamic Random
Access Memory (SDRAM). Types of memory that the SDRAM controller
supports are DDR2/DDR3 and capacities of up to 2GiB. This commit
adds emulation support of the Allwinner H3 SDRAM controller.

Signed-off-by: Niek Linnenbank 
Reviewed-by: Alex Bennée 
---
 include/hw/arm/allwinner-h3.h|   5 +
 include/hw/misc/allwinner-h3-dramc.h | 106 
 hw/arm/allwinner-h3.c|  19 +-
 hw/arm/orangepi.c|   6 +
 hw/misc/allwinner-h3-dramc.c | 358 +++
 hw/misc/Makefile.objs|   1 +
 hw/misc/trace-events |  10 +
 7 files changed, 502 insertions(+), 3 deletions(-)
 create mode 100644 include/hw/misc/allwinner-h3-dramc.h
 create mode 100644 hw/misc/allwinner-h3-dramc.c

diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
index d338003724..065d020c73 100644
--- a/include/hw/arm/allwinner-h3.h
+++ b/include/hw/arm/allwinner-h3.h
@@ -41,6 +41,7 @@
 #include "hw/intc/arm_gic.h"
 #include "hw/misc/allwinner-h3-ccu.h"
 #include "hw/misc/allwinner-cpucfg.h"
+#include "hw/misc/allwinner-h3-dramc.h"
 #include "hw/misc/allwinner-h3-sysctrl.h"
 #include "hw/misc/allwinner-sid.h"
 #include "hw/sd/allwinner-sdhost.h"
@@ -80,6 +81,9 @@ enum {
 AW_H3_UART2,
 AW_H3_UART3,
 AW_H3_EMAC,
+AW_H3_DRAMCOM,
+AW_H3_DRAMCTL,
+AW_H3_DRAMPHY,
 AW_H3_GIC_DIST,
 AW_H3_GIC_CPU,
 AW_H3_GIC_HYP,
@@ -120,6 +124,7 @@ typedef struct AwH3State {
 AwA10PITState timer;
 AwH3ClockCtlState ccu;
 AwCpuCfgState cpucfg;
+AwH3DramCtlState dramc;
 AwH3SysCtrlState sysctrl;
 AwSidState sid;
 AwSdHostState mmc0;
diff --git a/include/hw/misc/allwinner-h3-dramc.h 
b/include/hw/misc/allwinner-h3-dramc.h
new file mode 100644
index 00..bacdf236b7
--- /dev/null
+++ b/include/hw/misc/allwinner-h3-dramc.h
@@ -0,0 +1,106 @@
+/*
+ * Allwinner H3 SDRAM Controller emulation
+ *
+ * Copyright (C) 2019 Niek Linnenbank 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef HW_MISC_ALLWINNER_H3_DRAMC_H
+#define HW_MISC_ALLWINNER_H3_DRAMC_H
+
+#include "qom/object.h"
+#include "hw/sysbus.h"
+#include "exec/hwaddr.h"
+
+/**
+ * Constants
+ * @{
+ */
+
+/** Highest register address used by DRAMCOM module */
+#define AW_H3_DRAMCOM_REGS_MAXADDR  (0x804)
+
+/** Total number of known DRAMCOM registers */
+#define AW_H3_DRAMCOM_REGS_NUM  (AW_H3_DRAMCOM_REGS_MAXADDR / \
+ sizeof(uint32_t))
+
+/** Highest register address used by DRAMCTL module */
+#define AW_H3_DRAMCTL_REGS_MAXADDR  (0x88c)
+
+/** Total number of known DRAMCTL registers */
+#define AW_H3_DRAMCTL_REGS_NUM  (AW_H3_DRAMCTL_REGS_MAXADDR / \
+ sizeof(uint32_t))
+
+/** Highest register address used by DRAMPHY module */
+#define AW_H3_DRAMPHY_REGS_MAXADDR  (0x4)
+
+/** Total number of known DRAMPHY registers */
+#define AW_H3_DRAMPHY_REGS_NUM  (AW_H3_DRAMPHY_REGS_MAXADDR / \
+ sizeof(uint32_t))
+
+/** @} */
+
+/**
+ * Object model
+ * @{
+ */
+
+#define TYPE_AW_H3_DRAMC "allwinner-h3-dramc"
+#define AW_H3_DRAMC(obj) \
+OBJECT_CHECK(AwH3DramCtlState, (obj), TYPE_AW_H3_DRAMC)
+
+/** @} */
+
+/**
+ * Allwinner H3 SDRAM Controller object instance state.
+ */
+typedef struct AwH3DramCtlState {
+/*< private >*/
+SysBusDevice parent_obj;
+/*< public >*/
+
+/** Physical base address for start of RAM */
+hwaddr ram_addr;
+
+/** Total RAM size in megabytes */
+uint32_t ram_size;
+
+/**
+ * @name Memory Regions
+ * @{
+ */
+
+MemoryRegion row_mirror;   /**< Simulates rows for RAM size detection 
*/
+MemoryRegion row_mirror_alias; /**< Alias of the row which is mirrored */
+MemoryRegion dramcom_iomem;/**< DRAMCOM module I/O registers */
+MemoryRegion dramctl_iomem;/**< DRAMCTL module I/O registers */
+MemoryRegion dramphy_iomem;/**< DRAMPHY module I/O registers */
+
+/** @} */
+
+/**
+ * @name Hardware Registers
+ * @{
+ */
+
+uint32_t dramcom[AW_H3_DRAMCOM_REGS_NUM]; /**< Array of DRAMCOM registers 
*/
+uint32_t dramctl[AW_H3_DRAMCTL_REGS_NUM]; /**< Array of DRAMCTL registers 
*/
+

[PATCH v8 16/18] tests/boot_linux_console: Add a SLOW test booting Ubuntu on OrangePi PC

2020-03-11 Thread Niek Linnenbank
From: Philippe Mathieu-Daudé 

This test boots Ubuntu Bionic on a OrangePi PC board.

As it requires 1GB of storage, and is slow, this test is disabled
on automatic CI testing.

It is useful for workstation testing. Currently Avocado timeouts too
quickly, so we can't run userland commands.

The kernel image and DeviceTree blob are built by the Armbian
project (based on Debian):
https://www.armbian.com/orange-pi-pc/

The Ubuntu image is downloaded from:
https://dl.armbian.com/orangepipc/Bionic_current

This test can be run using:

  $ AVOCADO_ALLOW_LARGE_STORAGE=yes \
avocado --show=app,console run -t machine:orangepi-pc \
  tests/acceptance/boot_linux_console.py
  console: U-Boot SPL 2019.04-armbian (Nov 18 2019 - 23:08:35 +0100)
  console: DRAM: 1024 MiB
  console: Failed to set core voltage! Can't set CPU frequency
  console: Trying to boot from MMC1
  console: U-Boot 2019.04-armbian (Nov 18 2019 - 23:08:35 +0100) Allwinner 
Technology
  console: CPU:   Allwinner H3 (SUN8I )
  console: Model: Xunlong Orange Pi PC
  console: DRAM:  1 GiB
  console: MMC:   mmc@1c0f000: 0
  [...]
  console: Uncompressing Linux... done, booting the kernel.
  console: Booting Linux on physical CPU 0x0
  console: Linux version 5.3.9-sunxi (root@builder) (gcc version 8.3.0 (GNU 
Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36))) #19.11.3 
SMP Mon Nov 18 18:49:43 CET 2019
  console: CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=50c5387d
  console: CPU: div instructions available: patching division code
  console: CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction 
cache
  console: OF: fdt: Machine model: Xunlong Orange Pi PC
  [...]
  console: EXT4-fs (mmcblk0p1): mounted filesystem with writeback data mode. 
Opts: (null)
  console: done.
  console: Begin: Running /scripts/local-bottom ... done.
  console: Begin: Running /scripts/init-bottom ... done.
  console: systemd[1]: systemd 237 running in system mode. (...)
  console: systemd[1]: Detected architecture arm.
  console: Welcome to Ubuntu 18.04.3 LTS!
  console: systemd[1]: Set hostname to .

Signed-off-by: Philippe Mathieu-Daudé 
Signed-off-by: Niek Linnenbank 
Reviewed-by: Alex Bennée 
Tested-by: Alex Bennée 
[NL: rename in commit message Raspbian to Armbian, remove vm.set_machine()]
[NL: changed test to boot from SD card via BootROM, added check for 7z]
---
 tests/acceptance/boot_linux_console.py | 48 ++
 1 file changed, 48 insertions(+)

diff --git a/tests/acceptance/boot_linux_console.py 
b/tests/acceptance/boot_linux_console.py
index 0762dbe83a..e035c88b07 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -19,7 +19,13 @@ from avocado_qemu import exec_command_and_wait_for_pattern
 from avocado_qemu import wait_for_console_pattern
 from avocado.utils import process
 from avocado.utils import archive
+from avocado.utils.path import find_command, CmdNotFoundError
 
+P7ZIP_AVAILABLE = True
+try:
+find_command('7z')
+except CmdNotFoundError:
+P7ZIP_AVAILABLE = False
 
 class BootLinuxConsole(Test):
 """
@@ -619,6 +625,48 @@ class BootLinuxConsole(Test):
 exec_command_and_wait_for_pattern(self, 'reboot',
 'reboot: Restarting system')
 
+@skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited')
+@skipUnless(P7ZIP_AVAILABLE, '7z not installed')
+def test_arm_orangepi_bionic(self):
+"""
+:avocado: tags=arch:arm
+:avocado: tags=machine:orangepi-pc
+"""
+
+# This test download a 196MB compressed image and expand it to 932MB...
+image_url = ('https://dl.armbian.com/orangepipc/archive/'
+ 'Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.7z')
+image_hash = '196a8ffb72b0123d92cea4a070894813d305c71e'
+image_path_7z = self.fetch_asset(image_url, asset_hash=image_hash)
+image_name = 'Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.img'
+image_path = os.path.join(self.workdir, image_name)
+process.run("7z e -o%s %s" % (self.workdir, image_path_7z))
+
+self.vm.set_console()
+self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw',
+ '-nic', 'user',
+ '-no-reboot')
+self.vm.launch()
+
+kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
+   'console=ttyS0,115200 '
+   'loglevel=7 '
+   'nosmp '
+   'systemd.default_timeout_start_sec=9000 '
+   'systemd.mask=armbian-zram-config.service '
+   'systemd.mask=armbian-ramlog.service')
+
+self.wait_for_console_pattern('U-Boot SPL')
+self.wait_for_console_pattern('Autoboot in ')
+exec_command_and_wait_for_pattern(self, ' ', '=>')
+ 

[PATCH v8 06/18] hw/arm/allwinner: add CPU Configuration module

2020-03-11 Thread Niek Linnenbank
Various Allwinner System on Chip designs contain multiple processors
that can be configured and reset using the generic CPU Configuration
module interface. This commit adds support for the Allwinner CPU
configuration interface which emulates the following features:

 * CPU reset
 * CPU status

Signed-off-by: Niek Linnenbank 
Reviewed-by: Alex Bennée 
---
 include/hw/arm/allwinner-h3.h  |   3 +
 include/hw/misc/allwinner-cpucfg.h |  52 ++
 hw/arm/allwinner-h3.c  |   9 +-
 hw/misc/allwinner-cpucfg.c | 282 +
 hw/misc/Makefile.objs  |   1 +
 hw/misc/trace-events   |   5 +
 6 files changed, 351 insertions(+), 1 deletion(-)
 create mode 100644 include/hw/misc/allwinner-cpucfg.h
 create mode 100644 hw/misc/allwinner-cpucfg.c

diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
index 43500c4262..dc729176ab 100644
--- a/include/hw/arm/allwinner-h3.h
+++ b/include/hw/arm/allwinner-h3.h
@@ -40,6 +40,7 @@
 #include "hw/timer/allwinner-a10-pit.h"
 #include "hw/intc/arm_gic.h"
 #include "hw/misc/allwinner-h3-ccu.h"
+#include "hw/misc/allwinner-cpucfg.h"
 #include "hw/misc/allwinner-h3-sysctrl.h"
 #include "target/arm/cpu.h"
 
@@ -76,6 +77,7 @@ enum {
 AW_H3_GIC_CPU,
 AW_H3_GIC_HYP,
 AW_H3_GIC_VCPU,
+AW_H3_CPUCFG,
 AW_H3_SDRAM
 };
 
@@ -110,6 +112,7 @@ typedef struct AwH3State {
 const hwaddr *memmap;
 AwA10PITState timer;
 AwH3ClockCtlState ccu;
+AwCpuCfgState cpucfg;
 AwH3SysCtrlState sysctrl;
 GICState gic;
 MemoryRegion sram_a1;
diff --git a/include/hw/misc/allwinner-cpucfg.h 
b/include/hw/misc/allwinner-cpucfg.h
new file mode 100644
index 00..2c3693a8be
--- /dev/null
+++ b/include/hw/misc/allwinner-cpucfg.h
@@ -0,0 +1,52 @@
+/*
+ * Allwinner CPU Configuration Module emulation
+ *
+ * Copyright (C) 2019 Niek Linnenbank 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef HW_MISC_ALLWINNER_CPUCFG_H
+#define HW_MISC_ALLWINNER_CPUCFG_H
+
+#include "qom/object.h"
+#include "hw/sysbus.h"
+
+/**
+ * Object model
+ * @{
+ */
+
+#define TYPE_AW_CPUCFG   "allwinner-cpucfg"
+#define AW_CPUCFG(obj) \
+OBJECT_CHECK(AwCpuCfgState, (obj), TYPE_AW_CPUCFG)
+
+/** @} */
+
+/**
+ * Allwinner CPU Configuration Module instance state
+ */
+typedef struct AwCpuCfgState {
+/*< private >*/
+SysBusDevice parent_obj;
+/*< public >*/
+
+MemoryRegion iomem;
+uint32_t gen_ctrl;
+uint32_t super_standby;
+uint32_t entry_addr;
+
+} AwCpuCfgState;
+
+#endif /* HW_MISC_ALLWINNER_CPUCFG_H */
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
index 0aa46712db..b9a5597f2a 100644
--- a/hw/arm/allwinner-h3.c
+++ b/hw/arm/allwinner-h3.c
@@ -56,6 +56,7 @@ const hwaddr allwinner_h3_memmap[] = {
 [AW_H3_GIC_CPU]= 0x01c82000,
 [AW_H3_GIC_HYP]= 0x01c84000,
 [AW_H3_GIC_VCPU]   = 0x01c86000,
+[AW_H3_CPUCFG] = 0x01f01c00,
 [AW_H3_SDRAM]  = 0x4000
 };
 
@@ -122,7 +123,6 @@ struct AwH3Unimplemented {
 { "r_wdog",0x01f01000, 1 * KiB },
 { "r_prcm",0x01f01400, 1 * KiB },
 { "r_twd", 0x01f01800, 1 * KiB },
-{ "r_cpucfg",  0x01f01c00, 1 * KiB },
 { "r_cir-rx",  0x01f02000, 1 * KiB },
 { "r_twi", 0x01f02400, 1 * KiB },
 { "r_uart",0x01f02800, 1 * KiB },
@@ -195,6 +195,9 @@ static void allwinner_h3_init(Object *obj)
 
 sysbus_init_child_obj(obj, "sysctrl", >sysctrl, sizeof(s->sysctrl),
   TYPE_AW_H3_SYSCTRL);
+
+sysbus_init_child_obj(obj, "cpucfg", >cpucfg, sizeof(s->cpucfg),
+  TYPE_AW_CPUCFG);
 }
 
 static void allwinner_h3_realize(DeviceState *dev, Error **errp)
@@ -308,6 +311,10 @@ static void allwinner_h3_realize(DeviceState *dev, Error 
**errp)
 qdev_init_nofail(DEVICE(>sysctrl));
 sysbus_mmio_map(SYS_BUS_DEVICE(>sysctrl), 0, s->memmap[AW_H3_SYSCTRL]);
 
+/* CPU Configuration */
+qdev_init_nofail(DEVICE(>cpucfg));
+sysbus_mmio_map(SYS_BUS_DEVICE(>cpucfg), 0, s->memmap[AW_H3_CPUCFG]);
+
 /* Universal Serial Bus */
 sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0],
  qdev_get_gpio_in(DEVICE(>gic),
diff --git a/hw/misc/allwinner-cpucfg.c b/hw/misc/allwinner-cpucfg.c
new file mode 100644
index 00..bbd33a7dac
--- /dev/null
+++ 

[PATCH v8 13/18] tests/boot_linux_console: Add a quick test for the OrangePi PC board

2020-03-11 Thread Niek Linnenbank
From: Philippe Mathieu-Daudé 

This test boots a Linux kernel on a OrangePi PC board and verify
the serial output is working.

The kernel image and DeviceTree blob are built by the Armbian
project (based on Debian):
https://www.armbian.com/orange-pi-pc/

If ARM is a target being built, "make check-acceptance" will
automatically include this test by the use of the "arch:arm" tags.

Alternatively, this test can be run using:

  $ make check-venv
  $ ./tests/venv/bin/avocado --show=console,app run -t machine:orangepi-pc 
tests/acceptance/boot_linux_console.py
  JOB ID : 2e4d15eceb13c33672af406f08171e6e9de1414a
  JOB LOG: ~/job-results/job-2019-12-17T05.46-2e4d15e/job.log
  (1/1) 
tests/acceptance/boot_linux_console.py:BootLinuxConsole.test_arm_orangepi:
  console: Uncompressing Linux... done, booting the kernel.
  console: Booting Linux on physical CPU 0x0
  console: Linux version 4.20.7-sunxi (r...@armbian.com) (gcc version 7.2.1 
20171011 (Linaro GCC 7.2-2017.11)) #5.75 SMP Fri Feb 8 09:02:10 CET 2019
  console: CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=50c5387d
  console: CPU: div instructions available: patching division code
  console: CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction 
cache
  console: OF: fdt: Machine model: Xunlong Orange Pi PC
  console: Memory policy: Data cache writealloc
  console: OF: reserved mem: failed to allocate memory for node 'cma@4a00'
  console: cma: Failed to reserve 128 MiB
  console: psci: probing for conduit method from DT.
  console: psci: PSCIv0.2 detected in firmware.
  console: psci: Using standard PSCI v0.2 function IDs
  console: psci: Trusted OS migration not required
  console: random: get_random_bytes called from start_kernel+0x8d/0x3c2 with 
crng_init=0
  console: percpu: Embedded 18 pages/cpu @(ptrval) s41228 r8192 d24308 u73728
  console: Built 1 zonelists, mobility grouping on.  Total pages: 32480
  console: Kernel command line: printk.time=0 console=ttyS0,115200
  PASS (8.59 s)
  JOB TIME   : 8.81 s

Signed-off-by: Philippe Mathieu-Daudé 
Signed-off-by: Niek Linnenbank 
Reviewed-by: Alex Bennée 
Tested-by: Alex Bennée 
[NL: rename in commit message Raspbian to Armbian, remove vm.set_machine()]
---
 tests/acceptance/boot_linux_console.py | 25 +
 1 file changed, 25 insertions(+)

diff --git a/tests/acceptance/boot_linux_console.py 
b/tests/acceptance/boot_linux_console.py
index 34d37eba3b..6f5af582f3 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -507,6 +507,31 @@ class BootLinuxConsole(Test):
 exec_command_and_wait_for_pattern(self, 'reboot',
 'reboot: Restarting system')
 
+def test_arm_orangepi(self):
+"""
+:avocado: tags=arch:arm
+:avocado: tags=machine:orangepi-pc
+"""
+deb_url = ('https://apt.armbian.com/pool/main/l/'
+   'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb')
+deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315'
+deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
+kernel_path = self.extract_from_deb(deb_path,
+'/boot/vmlinuz-4.20.7-sunxi')
+dtb_path = '/usr/lib/linux-image-dev-sunxi/sun8i-h3-orangepi-pc.dtb'
+dtb_path = self.extract_from_deb(deb_path, dtb_path)
+
+self.vm.set_console()
+kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
+   'console=ttyS0,115200n8 '
+   'earlycon=uart,mmio32,0x1c28000')
+self.vm.add_args('-kernel', kernel_path,
+ '-dtb', dtb_path,
+ '-append', kernel_command_line)
+self.vm.launch()
+console_pattern = 'Kernel command line: %s' % kernel_command_line
+self.wait_for_console_pattern(console_pattern)
+
 def test_s390x_s390_ccw_virtio(self):
 """
 :avocado: tags=arch:s390x
-- 
2.17.1




[PATCH v8 08/18] hw/arm/allwinner: add SD/MMC host controller

2020-03-11 Thread Niek Linnenbank
The Allwinner System on Chip families sun4i and above contain
an integrated storage controller for Secure Digital (SD) and
Multi Media Card (MMC) interfaces. This commit adds support
for the Allwinner SD/MMC storage controller with the following
emulated features:

 * DMA transfers
 * Direct FIFO I/O
 * Short/Long format command responses
 * Auto-Stop command (CMD12)
 * Insert & remove card detection

The following boards are extended with the SD host controller:

 * Cubieboard (hw/arm/cubieboard.c)
 * Orange Pi PC (hw/arm/orangepi.c)

Signed-off-by: Niek Linnenbank 
Reviewed-by: Alex Bennée 
Tested-by: Philippe Mathieu-Daudé 
---
 include/hw/arm/allwinner-a10.h   |   2 +
 include/hw/arm/allwinner-h3.h|   3 +
 include/hw/sd/allwinner-sdhost.h | 135 +
 hw/arm/allwinner-a10.c   |  11 +
 hw/arm/allwinner-h3.c|  15 +-
 hw/arm/cubieboard.c  |  15 +
 hw/arm/orangepi.c|  16 +
 hw/sd/allwinner-sdhost.c | 854 +++
 hw/arm/Kconfig   |   1 +
 hw/sd/Makefile.objs  |   1 +
 hw/sd/trace-events   |   7 +
 11 files changed, 1059 insertions(+), 1 deletion(-)
 create mode 100644 include/hw/sd/allwinner-sdhost.h
 create mode 100644 hw/sd/allwinner-sdhost.c

diff --git a/include/hw/arm/allwinner-a10.h b/include/hw/arm/allwinner-a10.h
index 8af724548f..ae33a84b18 100644
--- a/include/hw/arm/allwinner-a10.h
+++ b/include/hw/arm/allwinner-a10.h
@@ -7,6 +7,7 @@
 #include "hw/timer/allwinner-a10-pit.h"
 #include "hw/intc/allwinner-a10-pic.h"
 #include "hw/net/allwinner_emac.h"
+#include "hw/sd/allwinner-sdhost.h"
 #include "hw/ide/ahci.h"
 #include "hw/usb/hcd-ohci.h"
 #include "hw/usb/hcd-ehci.h"
@@ -31,6 +32,7 @@ typedef struct AwA10State {
 AwA10PICState intc;
 AwEmacState emac;
 AllwinnerAHCIState sata;
+AwSdHostState mmc0;
 MemoryRegion sram_a;
 EHCISysBusState ehci[AW_A10_NUM_USB];
 OHCISysBusState ohci[AW_A10_NUM_USB];
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
index 85416d9d64..d71a4917ab 100644
--- a/include/hw/arm/allwinner-h3.h
+++ b/include/hw/arm/allwinner-h3.h
@@ -43,6 +43,7 @@
 #include "hw/misc/allwinner-cpucfg.h"
 #include "hw/misc/allwinner-h3-sysctrl.h"
 #include "hw/misc/allwinner-sid.h"
+#include "hw/sd/allwinner-sdhost.h"
 #include "target/arm/cpu.h"
 
 /**
@@ -60,6 +61,7 @@ enum {
 AW_H3_SRAM_A2,
 AW_H3_SRAM_C,
 AW_H3_SYSCTRL,
+AW_H3_MMC0,
 AW_H3_SID,
 AW_H3_EHCI0,
 AW_H3_OHCI0,
@@ -117,6 +119,7 @@ typedef struct AwH3State {
 AwCpuCfgState cpucfg;
 AwH3SysCtrlState sysctrl;
 AwSidState sid;
+AwSdHostState mmc0;
 GICState gic;
 MemoryRegion sram_a1;
 MemoryRegion sram_a2;
diff --git a/include/hw/sd/allwinner-sdhost.h b/include/hw/sd/allwinner-sdhost.h
new file mode 100644
index 00..d94606a853
--- /dev/null
+++ b/include/hw/sd/allwinner-sdhost.h
@@ -0,0 +1,135 @@
+/*
+ * Allwinner (sun4i and above) SD Host Controller emulation
+ *
+ * Copyright (C) 2019 Niek Linnenbank 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef HW_SD_ALLWINNER_SDHOST_H
+#define HW_SD_ALLWINNER_SDHOST_H
+
+#include "qom/object.h"
+#include "hw/sysbus.h"
+#include "hw/sd/sd.h"
+
+/**
+ * Object model types
+ * @{
+ */
+
+/** Generic Allwinner SD Host Controller (abstract) */
+#define TYPE_AW_SDHOST "allwinner-sdhost"
+
+/** Allwinner sun4i family (A10, A12) */
+#define TYPE_AW_SDHOST_SUN4I TYPE_AW_SDHOST "-sun4i"
+
+/** Allwinner sun5i family and newer (A13, H2+, H3, etc) */
+#define TYPE_AW_SDHOST_SUN5I TYPE_AW_SDHOST "-sun5i"
+
+/** @} */
+
+/**
+ * Object model macros
+ * @{
+ */
+
+#define AW_SDHOST(obj) \
+OBJECT_CHECK(AwSdHostState, (obj), TYPE_AW_SDHOST)
+#define AW_SDHOST_CLASS(klass) \
+ OBJECT_CLASS_CHECK(AwSdHostClass, (klass), TYPE_AW_SDHOST)
+#define AW_SDHOST_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(AwSdHostClass, (obj), TYPE_AW_SDHOST)
+
+/** @} */
+
+/**
+ * Allwinner SD Host Controller object instance state.
+ */
+typedef struct AwSdHostState {
+/*< private >*/
+SysBusDevice busdev;
+/*< public >*/
+
+/** Secure Digital (SD) bus, which connects to SD card (if present) */
+SDBus sdbus;
+
+/** Maps I/O registers in physical memory */
+MemoryRegion iomem;
+
+/** Interrupt output signal to notify CPU */
+qemu_irq 

[PATCH v8 03/18] hw/arm/allwinner-h3: add Clock Control Unit

2020-03-11 Thread Niek Linnenbank
The Clock Control Unit is responsible for clock signal generation,
configuration and distribution in the Allwinner H3 System on Chip.
This commit adds support for the Clock Control Unit which emulates
a simple read/write register interface.

Signed-off-by: Niek Linnenbank 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Alex Bennée 
Tested-by: Philippe Mathieu-Daudé 
---
 include/hw/arm/allwinner-h3.h  |   3 +
 include/hw/misc/allwinner-h3-ccu.h |  66 
 hw/arm/allwinner-h3.c  |   9 +-
 hw/misc/allwinner-h3-ccu.c | 242 +
 hw/misc/Makefile.objs  |   1 +
 5 files changed, 320 insertions(+), 1 deletion(-)
 create mode 100644 include/hw/misc/allwinner-h3-ccu.h
 create mode 100644 hw/misc/allwinner-h3-ccu.c

diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
index 2aac9b78ec..abdc20871a 100644
--- a/include/hw/arm/allwinner-h3.h
+++ b/include/hw/arm/allwinner-h3.h
@@ -39,6 +39,7 @@
 #include "hw/arm/boot.h"
 #include "hw/timer/allwinner-a10-pit.h"
 #include "hw/intc/arm_gic.h"
+#include "hw/misc/allwinner-h3-ccu.h"
 #include "target/arm/cpu.h"
 
 /**
@@ -55,6 +56,7 @@ enum {
 AW_H3_SRAM_A1,
 AW_H3_SRAM_A2,
 AW_H3_SRAM_C,
+AW_H3_CCU,
 AW_H3_PIT,
 AW_H3_UART0,
 AW_H3_UART1,
@@ -97,6 +99,7 @@ typedef struct AwH3State {
 ARMCPU cpus[AW_H3_NUM_CPUS];
 const hwaddr *memmap;
 AwA10PITState timer;
+AwH3ClockCtlState ccu;
 GICState gic;
 MemoryRegion sram_a1;
 MemoryRegion sram_a2;
diff --git a/include/hw/misc/allwinner-h3-ccu.h 
b/include/hw/misc/allwinner-h3-ccu.h
new file mode 100644
index 00..eec59649f3
--- /dev/null
+++ b/include/hw/misc/allwinner-h3-ccu.h
@@ -0,0 +1,66 @@
+/*
+ * Allwinner H3 Clock Control Unit emulation
+ *
+ * Copyright (C) 2019 Niek Linnenbank 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef HW_MISC_ALLWINNER_H3_CCU_H
+#define HW_MISC_ALLWINNER_H3_CCU_H
+
+#include "qom/object.h"
+#include "hw/sysbus.h"
+
+/**
+ * @name Constants
+ * @{
+ */
+
+/** Size of register I/O address space used by CCU device */
+#define AW_H3_CCU_IOSIZE(0x400)
+
+/** Total number of known registers */
+#define AW_H3_CCU_REGS_NUM  (AW_H3_CCU_IOSIZE / sizeof(uint32_t))
+
+/** @} */
+
+/**
+ * @name Object model
+ * @{
+ */
+
+#define TYPE_AW_H3_CCU"allwinner-h3-ccu"
+#define AW_H3_CCU(obj) \
+OBJECT_CHECK(AwH3ClockCtlState, (obj), TYPE_AW_H3_CCU)
+
+/** @} */
+
+/**
+ * Allwinner H3 CCU object instance state.
+ */
+typedef struct AwH3ClockCtlState {
+/*< private >*/
+SysBusDevice parent_obj;
+/*< public >*/
+
+/** Maps I/O registers in physical memory */
+MemoryRegion iomem;
+
+/** Array of hardware registers */
+uint32_t regs[AW_H3_CCU_REGS_NUM];
+
+} AwH3ClockCtlState;
+
+#endif /* HW_MISC_ALLWINNER_H3_CCU_H */
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
index 7958f37685..1fff3c317b 100644
--- a/hw/arm/allwinner-h3.c
+++ b/hw/arm/allwinner-h3.c
@@ -36,6 +36,7 @@ const hwaddr allwinner_h3_memmap[] = {
 [AW_H3_SRAM_A1]= 0x,
 [AW_H3_SRAM_A2]= 0x00044000,
 [AW_H3_SRAM_C] = 0x0001,
+[AW_H3_CCU]= 0x01c2,
 [AW_H3_PIT]= 0x01c20c00,
 [AW_H3_UART0]  = 0x01c28000,
 [AW_H3_UART1]  = 0x01c28400,
@@ -77,7 +78,6 @@ struct AwH3Unimplemented {
 { "usb2-phy",  0x01c1c000, 4 * KiB },
 { "usb3-phy",  0x01c1d000, 4 * KiB },
 { "smc",   0x01c1e000, 4 * KiB },
-{ "ccu",   0x01c2, 1 * KiB },
 { "pio",   0x01c20800, 1 * KiB },
 { "owa",   0x01c21000, 1 * KiB },
 { "pwm",   0x01c21400, 1 * KiB },
@@ -172,6 +172,9 @@ static void allwinner_h3_init(Object *obj)
   "clk0-freq", _abort);
 object_property_add_alias(obj, "clk1-freq", OBJECT(>timer),
   "clk1-freq", _abort);
+
+sysbus_init_child_obj(obj, "ccu", >ccu, sizeof(s->ccu),
+  TYPE_AW_H3_CCU);
 }
 
 static void allwinner_h3_realize(DeviceState *dev, Error **errp)
@@ -277,6 +280,10 @@ static void allwinner_h3_realize(DeviceState *dev, Error 
**errp)
 memory_region_add_subregion(get_system_memory(), s->memmap[AW_H3_SRAM_C],
 >sram_c);
 
+/* Clock Control Unit */
+qdev_init_nofail(DEVICE(>ccu));
+  

[PATCH v8 10/18] hw/arm/allwinner-h3: add Boot ROM support

2020-03-11 Thread Niek Linnenbank
A real Allwinner H3 SoC contains a Boot ROM which is the
first code that runs right after the SoC is powered on.
The Boot ROM is responsible for loading user code (e.g. a bootloader)
from any of the supported external devices and writing the downloaded
code to internal SRAM. After loading the SoC begins executing the code
written to SRAM.

This commits adds emulation of the Boot ROM firmware setup functionality
by loading user code from SD card in the A1 SRAM. While the A1 SRAM is
64KiB, we limit the size to 32KiB because the real H3 Boot ROM also rejects
sizes larger than 32KiB. For reference, this behaviour is documented
by the Linux Sunxi project wiki at:

  https://linux-sunxi.org/BROM#U-Boot_SPL_limitations

Signed-off-by: Niek Linnenbank 
Reviewed-by: Alex Bennée 
---
 include/hw/arm/allwinner-h3.h | 21 +
 hw/arm/allwinner-h3.c | 17 +
 hw/arm/orangepi.c |  5 +
 3 files changed, 43 insertions(+)

diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
index f9b9a02373..d338003724 100644
--- a/include/hw/arm/allwinner-h3.h
+++ b/include/hw/arm/allwinner-h3.h
@@ -46,6 +46,7 @@
 #include "hw/sd/allwinner-sdhost.h"
 #include "hw/net/allwinner-sun8i-emac.h"
 #include "target/arm/cpu.h"
+#include "sysemu/block-backend.h"
 
 /**
  * Allwinner H3 device list
@@ -129,4 +130,24 @@ typedef struct AwH3State {
 MemoryRegion sram_c;
 } AwH3State;
 
+/**
+ * Emulate Boot ROM firmware setup functionality.
+ *
+ * A real Allwinner H3 SoC contains a Boot ROM
+ * which is the first code that runs right after
+ * the SoC is powered on. The Boot ROM is responsible
+ * for loading user code (e.g. a bootloader) from any
+ * of the supported external devices and writing the
+ * downloaded code to internal SRAM. After loading the SoC
+ * begins executing the code written to SRAM.
+ *
+ * This function emulates the Boot ROM by copying 32 KiB
+ * of data from the given block device and writes it to
+ * the start of the first internal SRAM memory.
+ *
+ * @s: Allwinner H3 state object pointer
+ * @blk: Block backend device object pointer
+ */
+void allwinner_h3_bootrom_setup(AwH3State *s, BlockBackend *blk);
+
 #endif /* HW_ARM_ALLWINNER_H3_H */
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
index d1245d2b01..a9767c70c0 100644
--- a/hw/arm/allwinner-h3.c
+++ b/hw/arm/allwinner-h3.c
@@ -29,6 +29,7 @@
 #include "hw/char/serial.h"
 #include "hw/misc/unimp.h"
 #include "hw/usb/hcd-ehci.h"
+#include "hw/loader.h"
 #include "sysemu/sysemu.h"
 #include "hw/arm/allwinner-h3.h"
 
@@ -170,6 +171,22 @@ enum {
 AW_H3_GIC_NUM_SPI   = 128
 };
 
+void allwinner_h3_bootrom_setup(AwH3State *s, BlockBackend *blk)
+{
+const int64_t rom_size = 32 * KiB;
+g_autofree uint8_t *buffer = g_new0(uint8_t, rom_size);
+
+if (blk_pread(blk, 8 * KiB, buffer, rom_size) < 0) {
+error_setg(_fatal, "%s: failed to read BlockBackend data",
+   __func__);
+return;
+}
+
+rom_add_blob("allwinner-h3.bootrom", buffer, rom_size,
+  rom_size, s->memmap[AW_H3_SRAM_A1],
+  NULL, NULL, NULL, NULL, false);
+}
+
 static void allwinner_h3_init(Object *obj)
 {
 AwH3State *s = AW_H3(obj);
diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c
index d65bbf8a2f..b8ebcb08b7 100644
--- a/hw/arm/orangepi.c
+++ b/hw/arm/orangepi.c
@@ -97,6 +97,11 @@ static void orangepi_init(MachineState *machine)
 memory_region_add_subregion(get_system_memory(), h3->memmap[AW_H3_SDRAM],
 machine->ram);
 
+/* Load target kernel or start using BootROM */
+if (!machine->kernel_filename && blk_is_available(blk)) {
+/* Use Boot ROM to copy data from SD card to SRAM */
+allwinner_h3_bootrom_setup(h3, blk);
+}
 orangepi_binfo.loader_start = h3->memmap[AW_H3_SDRAM];
 orangepi_binfo.ram_size = machine->ram_size;
 arm_load_kernel(ARM_CPU(first_cpu), machine, _binfo);
-- 
2.17.1




[PATCH v8 01/18] hw/arm: add Allwinner H3 System-on-Chip

2020-03-11 Thread Niek Linnenbank
The Allwinner H3 is a System on Chip containing four ARM Cortex A7
processor cores. Features and specifications include DDR2/DDR3 memory,
SD/MMC storage cards, 10/100/1000Mbit Ethernet, USB 2.0, HDMI and
various I/O modules. This commit adds support for the Allwinner H3
System on Chip.

Signed-off-by: Niek Linnenbank 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Alex Bennée 
Tested-by: Philippe Mathieu-Daudé 
---
 default-configs/arm-softmmu.mak |   1 +
 include/hw/arm/allwinner-h3.h   | 106 +++
 hw/arm/allwinner-h3.c   | 327 
 MAINTAINERS |   7 +
 hw/arm/Kconfig  |   8 +
 hw/arm/Makefile.objs|   1 +
 6 files changed, 450 insertions(+)
 create mode 100644 include/hw/arm/allwinner-h3.h
 create mode 100644 hw/arm/allwinner-h3.c

diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 645e6201bb..36a0e89daa 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -41,3 +41,4 @@ CONFIG_FSL_IMX25=y
 CONFIG_FSL_IMX7=y
 CONFIG_FSL_IMX6UL=y
 CONFIG_SEMIHOSTING=y
+CONFIG_ALLWINNER_H3=y
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
new file mode 100644
index 00..2aac9b78ec
--- /dev/null
+++ b/include/hw/arm/allwinner-h3.h
@@ -0,0 +1,106 @@
+/*
+ * Allwinner H3 System on Chip emulation
+ *
+ * Copyright (C) 2019 Niek Linnenbank 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+/*
+ * The Allwinner H3 is a System on Chip containing four ARM Cortex A7
+ * processor cores. Features and specifications include DDR2/DDR3 memory,
+ * SD/MMC storage cards, 10/100/1000Mbit Ethernet, USB 2.0, HDMI and
+ * various I/O modules.
+ *
+ * This implementation is based on the following datasheet:
+ *
+ *   https://linux-sunxi.org/File:Allwinner_H3_Datasheet_V1.2.pdf
+ *
+ * The latest datasheet and more info can be found on the Linux Sunxi wiki:
+ *
+ *   https://linux-sunxi.org/H3
+ */
+
+#ifndef HW_ARM_ALLWINNER_H3_H
+#define HW_ARM_ALLWINNER_H3_H
+
+#include "qom/object.h"
+#include "hw/arm/boot.h"
+#include "hw/timer/allwinner-a10-pit.h"
+#include "hw/intc/arm_gic.h"
+#include "target/arm/cpu.h"
+
+/**
+ * Allwinner H3 device list
+ *
+ * This enumeration is can be used refer to a particular device in the
+ * Allwinner H3 SoC. For example, the physical memory base address for
+ * each device can be found in the AwH3State object in the memmap member
+ * using the device enum value as index.
+ *
+ * @see AwH3State
+ */
+enum {
+AW_H3_SRAM_A1,
+AW_H3_SRAM_A2,
+AW_H3_SRAM_C,
+AW_H3_PIT,
+AW_H3_UART0,
+AW_H3_UART1,
+AW_H3_UART2,
+AW_H3_UART3,
+AW_H3_GIC_DIST,
+AW_H3_GIC_CPU,
+AW_H3_GIC_HYP,
+AW_H3_GIC_VCPU,
+AW_H3_SDRAM
+};
+
+/** Total number of CPU cores in the H3 SoC */
+#define AW_H3_NUM_CPUS  (4)
+
+/**
+ * Allwinner H3 object model
+ * @{
+ */
+
+/** Object type for the Allwinner H3 SoC */
+#define TYPE_AW_H3 "allwinner-h3"
+
+/** Convert input object to Allwinner H3 state object */
+#define AW_H3(obj) OBJECT_CHECK(AwH3State, (obj), TYPE_AW_H3)
+
+/** @} */
+
+/**
+ * Allwinner H3 object
+ *
+ * This struct contains the state of all the devices
+ * which are currently emulated by the H3 SoC code.
+ */
+typedef struct AwH3State {
+/*< private >*/
+DeviceState parent_obj;
+/*< public >*/
+
+ARMCPU cpus[AW_H3_NUM_CPUS];
+const hwaddr *memmap;
+AwA10PITState timer;
+GICState gic;
+MemoryRegion sram_a1;
+MemoryRegion sram_a2;
+MemoryRegion sram_c;
+} AwH3State;
+
+#endif /* HW_ARM_ALLWINNER_H3_H */
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
new file mode 100644
index 00..7958f37685
--- /dev/null
+++ b/hw/arm/allwinner-h3.c
@@ -0,0 +1,327 @@
+/*
+ * Allwinner H3 System on Chip emulation
+ *
+ * Copyright (C) 2019 Niek Linnenbank 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public 

[PATCH v8 02/18] hw/arm: add Xunlong Orange Pi PC machine

2020-03-11 Thread Niek Linnenbank
The Xunlong Orange Pi PC is an Allwinner H3 System on Chip
based embedded computer with mainline support in both U-Boot
and Linux. The board comes with a Quad Core Cortex A7 @ 1.3GHz,
1GiB RAM, 100Mbit ethernet, USB, SD/MMC, USB, HDMI and
various other I/O. This commit add support for the Xunlong
Orange Pi PC machine.

Signed-off-by: Niek Linnenbank 
Tested-by: KONRAD Frederic 
Tested-by: Philippe Mathieu-Daudé 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Alex Bennée 
Acked-by: Igor Mammedov 
---
 hw/arm/orangepi.c| 92 
 MAINTAINERS  |  1 +
 hw/arm/Makefile.objs |  2 +-
 3 files changed, 94 insertions(+), 1 deletion(-)
 create mode 100644 hw/arm/orangepi.c

diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c
new file mode 100644
index 00..3fcec1944e
--- /dev/null
+++ b/hw/arm/orangepi.c
@@ -0,0 +1,92 @@
+/*
+ * Orange Pi emulation
+ *
+ * Copyright (C) 2019 Niek Linnenbank 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/units.h"
+#include "exec/address-spaces.h"
+#include "qapi/error.h"
+#include "cpu.h"
+#include "hw/sysbus.h"
+#include "hw/boards.h"
+#include "hw/qdev-properties.h"
+#include "hw/arm/allwinner-h3.h"
+#include "sysemu/sysemu.h"
+
+static struct arm_boot_info orangepi_binfo = {
+.nb_cpus = AW_H3_NUM_CPUS,
+};
+
+static void orangepi_init(MachineState *machine)
+{
+AwH3State *h3;
+
+/* BIOS is not supported by this board */
+if (bios_name) {
+error_report("BIOS not supported for this machine");
+exit(1);
+}
+
+/* This board has fixed size RAM */
+if (machine->ram_size != 1 * GiB) {
+error_report("This machine can only be used with 1GiB of RAM");
+exit(1);
+}
+
+/* Only allow Cortex-A7 for this board */
+if (strcmp(machine->cpu_type, ARM_CPU_TYPE_NAME("cortex-a7")) != 0) {
+error_report("This board can only be used with cortex-a7 CPU");
+exit(1);
+}
+
+h3 = AW_H3(object_new(TYPE_AW_H3));
+object_property_add_child(OBJECT(machine), "soc", OBJECT(h3),
+  _abort);
+object_unref(OBJECT(h3));
+
+/* Setup timer properties */
+object_property_set_int(OBJECT(h3), 32768, "clk0-freq",
+_abort);
+object_property_set_int(OBJECT(h3), 24 * 1000 * 1000, "clk1-freq",
+_abort);
+
+/* Mark H3 object realized */
+object_property_set_bool(OBJECT(h3), true, "realized", _abort);
+
+/* SDRAM */
+memory_region_add_subregion(get_system_memory(), h3->memmap[AW_H3_SDRAM],
+machine->ram);
+
+orangepi_binfo.loader_start = h3->memmap[AW_H3_SDRAM];
+orangepi_binfo.ram_size = machine->ram_size;
+arm_load_kernel(ARM_CPU(first_cpu), machine, _binfo);
+}
+
+static void orangepi_machine_init(MachineClass *mc)
+{
+mc->desc = "Orange Pi PC";
+mc->init = orangepi_init;
+mc->min_cpus = AW_H3_NUM_CPUS;
+mc->max_cpus = AW_H3_NUM_CPUS;
+mc->default_cpus = AW_H3_NUM_CPUS;
+mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a7");
+mc->default_ram_size = 1 * GiB;
+mc->default_ram_id = "orangepi.ram";
+}
+
+DEFINE_MACHINE("orangepi-pc", orangepi_machine_init)
diff --git a/MAINTAINERS b/MAINTAINERS
index c27fe8a4be..ba46545464 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -497,6 +497,7 @@ L: qemu-...@nongnu.org
 S: Maintained
 F: hw/*/allwinner-h3*
 F: include/hw/*/allwinner-h3*
+F: hw/arm/orangepi.c
 
 ARM PrimeCell and CMSDK devices
 M: Peter Maydell 
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
index ae577e875f..534a6a119e 100644
--- a/hw/arm/Makefile.objs
+++ b/hw/arm/Makefile.objs
@@ -35,7 +35,7 @@ obj-$(CONFIG_DIGIC) += digic.o
 obj-$(CONFIG_OMAP) += omap1.o omap2.o
 obj-$(CONFIG_STRONGARM) += strongarm.o
 obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o
-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o
+obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o orangepi.o
 obj-$(CONFIG_RASPI) += bcm2835_peripherals.o bcm2836.o raspi.o
 obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o
 obj-$(CONFIG_STM32F405_SOC) += stm32f405_soc.o
-- 
2.17.1




[PATCH v8 05/18] hw/arm/allwinner-h3: add System Control module

2020-03-11 Thread Niek Linnenbank
The Allwinner H3 System on Chip has an System Control
module that provides system wide generic controls and
device information. This commit adds support for the
Allwinner H3 System Control module.

Signed-off-by: Niek Linnenbank 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Alex Bennée 
Tested-by: Philippe Mathieu-Daudé 
---
 include/hw/arm/allwinner-h3.h  |   3 +
 include/hw/misc/allwinner-h3-sysctrl.h |  67 
 hw/arm/allwinner-h3.c  |   9 +-
 hw/misc/allwinner-h3-sysctrl.c | 140 +
 hw/misc/Makefile.objs  |   1 +
 5 files changed, 219 insertions(+), 1 deletion(-)
 create mode 100644 include/hw/misc/allwinner-h3-sysctrl.h
 create mode 100644 hw/misc/allwinner-h3-sysctrl.c

diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
index 4f4dcbcd17..43500c4262 100644
--- a/include/hw/arm/allwinner-h3.h
+++ b/include/hw/arm/allwinner-h3.h
@@ -40,6 +40,7 @@
 #include "hw/timer/allwinner-a10-pit.h"
 #include "hw/intc/arm_gic.h"
 #include "hw/misc/allwinner-h3-ccu.h"
+#include "hw/misc/allwinner-h3-sysctrl.h"
 #include "target/arm/cpu.h"
 
 /**
@@ -56,6 +57,7 @@ enum {
 AW_H3_SRAM_A1,
 AW_H3_SRAM_A2,
 AW_H3_SRAM_C,
+AW_H3_SYSCTRL,
 AW_H3_EHCI0,
 AW_H3_OHCI0,
 AW_H3_EHCI1,
@@ -108,6 +110,7 @@ typedef struct AwH3State {
 const hwaddr *memmap;
 AwA10PITState timer;
 AwH3ClockCtlState ccu;
+AwH3SysCtrlState sysctrl;
 GICState gic;
 MemoryRegion sram_a1;
 MemoryRegion sram_a2;
diff --git a/include/hw/misc/allwinner-h3-sysctrl.h 
b/include/hw/misc/allwinner-h3-sysctrl.h
new file mode 100644
index 00..af4119e026
--- /dev/null
+++ b/include/hw/misc/allwinner-h3-sysctrl.h
@@ -0,0 +1,67 @@
+/*
+ * Allwinner H3 System Control emulation
+ *
+ * Copyright (C) 2019 Niek Linnenbank 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef HW_MISC_ALLWINNER_H3_SYSCTRL_H
+#define HW_MISC_ALLWINNER_H3_SYSCTRL_H
+
+#include "qom/object.h"
+#include "hw/sysbus.h"
+
+/**
+ * @name Constants
+ * @{
+ */
+
+/** Highest register address used by System Control device */
+#define AW_H3_SYSCTRL_REGS_MAXADDR   (0x30)
+
+/** Total number of known registers */
+#define AW_H3_SYSCTRL_REGS_NUM   ((AW_H3_SYSCTRL_REGS_MAXADDR / \
+  sizeof(uint32_t)) + 1)
+
+/** @} */
+
+/**
+ * @name Object model
+ * @{
+ */
+
+#define TYPE_AW_H3_SYSCTRL"allwinner-h3-sysctrl"
+#define AW_H3_SYSCTRL(obj) \
+OBJECT_CHECK(AwH3SysCtrlState, (obj), TYPE_AW_H3_SYSCTRL)
+
+/** @} */
+
+/**
+ * Allwinner H3 System Control object instance state
+ */
+typedef struct AwH3SysCtrlState {
+/*< private >*/
+SysBusDevice parent_obj;
+/*< public >*/
+
+/** Maps I/O registers in physical memory */
+MemoryRegion iomem;
+
+/** Array of hardware registers */
+uint32_t regs[AW_H3_SYSCTRL_REGS_NUM];
+
+} AwH3SysCtrlState;
+
+#endif /* HW_MISC_ALLWINNER_H3_SYSCTRL_H */
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
index c205f06738..0aa46712db 100644
--- a/hw/arm/allwinner-h3.c
+++ b/hw/arm/allwinner-h3.c
@@ -37,6 +37,7 @@ const hwaddr allwinner_h3_memmap[] = {
 [AW_H3_SRAM_A1]= 0x,
 [AW_H3_SRAM_A2]= 0x00044000,
 [AW_H3_SRAM_C] = 0x0001,
+[AW_H3_SYSCTRL]= 0x01c0,
 [AW_H3_EHCI0]  = 0x01c1a000,
 [AW_H3_OHCI0]  = 0x01c1a400,
 [AW_H3_EHCI1]  = 0x01c1b000,
@@ -66,7 +67,6 @@ struct AwH3Unimplemented {
 } unimplemented[] = {
 { "d-engine",  0x0100, 4 * MiB },
 { "d-inter",   0x0140, 128 * KiB },
-{ "syscon",0x01c0, 4 * KiB },
 { "dma",   0x01c02000, 4 * KiB },
 { "nfdc",  0x01c03000, 4 * KiB },
 { "ts",0x01c06000, 4 * KiB },
@@ -192,6 +192,9 @@ static void allwinner_h3_init(Object *obj)
 
 sysbus_init_child_obj(obj, "ccu", >ccu, sizeof(s->ccu),
   TYPE_AW_H3_CCU);
+
+sysbus_init_child_obj(obj, "sysctrl", >sysctrl, sizeof(s->sysctrl),
+  TYPE_AW_H3_SYSCTRL);
 }
 
 static void allwinner_h3_realize(DeviceState *dev, Error **errp)
@@ -301,6 +304,10 @@ static void allwinner_h3_realize(DeviceState *dev, Error 
**errp)
 qdev_init_nofail(DEVICE(>ccu));
 sysbus_mmio_map(SYS_BUS_DEVICE(>ccu), 0, s->memmap[AW_H3_CCU]);
 
+/* System Control */
+

[PATCH v8 00/18] Add Allwinner H3 SoC and Orange Pi PC Machine

2020-03-11 Thread Niek Linnenbank
Dear QEMU developers,

Hereby I would like to contribute the following set of patches to QEMU
which add support for the Allwinner H3 System on Chip and the
Orange Pi PC machine. The following features and devices are supported:

 * SMP (Quad Core Cortex A7)
 * Generic Interrupt Controller configuration
 * SRAM mappings
 * SDRAM controller
 * Real Time Clock
 * Timer device (re-used from Allwinner A10)
 * UART
 * SD/MMC storage controller
 * EMAC ethernet
 * USB 2.0 interfaces
 * Clock Control Unit
 * System Control module
 * Security Identifier device

Functionality related to graphical output such as HDMI, GPU,
Display Engine and audio are not included. Recently released
mainline Linux kernels (4.19 up to latest master), mainline U-Boot
and NetBSD 9.0 are known to work.

For full details on how to use the Orange Pi PC machine, see the file
docs/system/orangepi.rst which is included as a patch in this series.

The contents of this patch series is available on Github at:

  https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v8

The followings are currently known issues in this series:

  - RTC date & time is not persistent
  - boot0 custom Allwinner bootloader not yet working
  - Watchdog not yet implemented, affects U-Boot 'reset' and shutdown/reboot
 -> This is part of the existing A10 timer that needs to be generalized 
first

Looking forward to your review comments. I will do my best
to update the patches where needed.

= CHANGELOG =
v8:
 * hw/arm/allwinner-h3.c: use g_autofree for buffer variable in BootROM setup 
function
 * hw/arm/orangepi.c: use warn_report to give warning to user when overriding 
SID without H3 SoC prefix

v7: https://lists.gnu.org/archive/html/qemu-devel/2020-03/msg02864.html
https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v7

v6: https://lists.gnu.org/archive/html/qemu-devel/2020-03/msg00046.html
https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v6

v5: https://lists.gnu.org/archive/html/qemu-devel/2020-02/msg04525.html
https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v5

v4: https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg03960.html
https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v4

v3: https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg01534.html
https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v3

v2: https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg03265.html
https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v2

v1: https://lists.gnu.org/archive/html/qemu-devel/2019-12/msg00320.html
https://github.com/nieklinnenbank/qemu/tree/allwinner-h3-v1

With kind regards,

Niek Linnenbank

Niek Linnenbank (13):
  hw/arm: add Allwinner H3 System-on-Chip
  hw/arm: add Xunlong Orange Pi PC machine
  hw/arm/allwinner-h3: add Clock Control Unit
  hw/arm/allwinner-h3: add USB host controller
  hw/arm/allwinner-h3: add System Control module
  hw/arm/allwinner: add CPU Configuration module
  hw/arm/allwinner: add Security Identifier device
  hw/arm/allwinner: add SD/MMC host controller
  hw/arm/allwinner-h3: add EMAC ethernet device
  hw/arm/allwinner-h3: add Boot ROM support
  hw/arm/allwinner-h3: add SDRAM controller device
  hw/arm/allwinner: add RTC device support
  docs: add Orange Pi PC document

Philippe Mathieu-Daudé (5):
  tests/boot_linux_console: Add a quick test for the OrangePi PC board
  tests/boot_linux_console: Add initrd test for the Orange Pi PC board
  tests/boot_linux_console: Add a SD card test for the OrangePi PC board
  tests/boot_linux_console: Add a SLOW test booting Ubuntu on OrangePi
PC
  tests/boot_linux_console: Test booting NetBSD via U-Boot on OrangePi
PC

 docs/system/orangepi.rst   | 253 +++
 docs/system/target-arm.rst |   2 +
 default-configs/arm-softmmu.mak|   1 +
 hw/usb/hcd-ehci.h  |   1 +
 include/hw/arm/allwinner-a10.h |   4 +
 include/hw/arm/allwinner-h3.h  | 161 +
 include/hw/misc/allwinner-cpucfg.h |  52 ++
 include/hw/misc/allwinner-h3-ccu.h |  66 ++
 include/hw/misc/allwinner-h3-dramc.h   | 106 +++
 include/hw/misc/allwinner-h3-sysctrl.h |  67 ++
 include/hw/misc/allwinner-sid.h|  60 ++
 include/hw/net/allwinner-sun8i-emac.h  |  99 +++
 include/hw/rtc/allwinner-rtc.h | 134 
 include/hw/sd/allwinner-sdhost.h   | 135 
 hw/arm/allwinner-a10.c |  19 +
 hw/arm/allwinner-h3.c  | 465 +
 hw/arm/cubieboard.c|  15 +
 hw/arm/orangepi.c  | 130 
 hw/misc/allwinner-cpucfg.c | 282 
 hw/misc/allwinner-h3-ccu.c | 242 +++
 hw/misc/allwinner-h3-dramc.c   | 358 ++
 hw/misc/allwinner-h3-sysctrl.c | 140 
 hw/misc/allwinner-sid.c| 168 +
 hw/net/allwinner-sun8i-emac.c  | 871 +
 hw/rtc/allwinner-rtc.c | 411 
 

[PATCH v8 04/18] hw/arm/allwinner-h3: add USB host controller

2020-03-11 Thread Niek Linnenbank
The Allwinner H3 System on Chip contains multiple USB 2.0 bus
connections which provide software access using the Enhanced
Host Controller Interface (EHCI) and Open Host Controller
Interface (OHCI) interfaces. This commit adds support for
both interfaces in the Allwinner H3 System on Chip.

Signed-off-by: Niek Linnenbank 
Reviewed-by: Gerd Hoffmann 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Alex Bennée 
Tested-by: Philippe Mathieu-Daudé 
---
 hw/usb/hcd-ehci.h |  1 +
 include/hw/arm/allwinner-h3.h |  8 +++
 hw/arm/allwinner-h3.c | 44 +++
 hw/usb/hcd-ehci-sysbus.c  | 17 ++
 hw/arm/Kconfig|  2 ++
 5 files changed, 72 insertions(+)

diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h
index 0298238f0b..edb59311c4 100644
--- a/hw/usb/hcd-ehci.h
+++ b/hw/usb/hcd-ehci.h
@@ -342,6 +342,7 @@ typedef struct EHCIPCIState {
 #define TYPE_SYS_BUS_EHCI "sysbus-ehci-usb"
 #define TYPE_PLATFORM_EHCI "platform-ehci-usb"
 #define TYPE_EXYNOS4210_EHCI "exynos4210-ehci-usb"
+#define TYPE_AW_H3_EHCI "aw-h3-ehci-usb"
 #define TYPE_TEGRA2_EHCI "tegra2-ehci-usb"
 #define TYPE_PPC4xx_EHCI "ppc4xx-ehci-usb"
 #define TYPE_FUSBH200_EHCI "fusbh200-ehci-usb"
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
index abdc20871a..4f4dcbcd17 100644
--- a/include/hw/arm/allwinner-h3.h
+++ b/include/hw/arm/allwinner-h3.h
@@ -56,6 +56,14 @@ enum {
 AW_H3_SRAM_A1,
 AW_H3_SRAM_A2,
 AW_H3_SRAM_C,
+AW_H3_EHCI0,
+AW_H3_OHCI0,
+AW_H3_EHCI1,
+AW_H3_OHCI1,
+AW_H3_EHCI2,
+AW_H3_OHCI2,
+AW_H3_EHCI3,
+AW_H3_OHCI3,
 AW_H3_CCU,
 AW_H3_PIT,
 AW_H3_UART0,
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
index 1fff3c317b..c205f06738 100644
--- a/hw/arm/allwinner-h3.c
+++ b/hw/arm/allwinner-h3.c
@@ -28,6 +28,7 @@
 #include "hw/sysbus.h"
 #include "hw/char/serial.h"
 #include "hw/misc/unimp.h"
+#include "hw/usb/hcd-ehci.h"
 #include "sysemu/sysemu.h"
 #include "hw/arm/allwinner-h3.h"
 
@@ -36,6 +37,14 @@ const hwaddr allwinner_h3_memmap[] = {
 [AW_H3_SRAM_A1]= 0x,
 [AW_H3_SRAM_A2]= 0x00044000,
 [AW_H3_SRAM_C] = 0x0001,
+[AW_H3_EHCI0]  = 0x01c1a000,
+[AW_H3_OHCI0]  = 0x01c1a400,
+[AW_H3_EHCI1]  = 0x01c1b000,
+[AW_H3_OHCI1]  = 0x01c1b400,
+[AW_H3_EHCI2]  = 0x01c1c000,
+[AW_H3_OHCI2]  = 0x01c1c400,
+[AW_H3_EHCI3]  = 0x01c1d000,
+[AW_H3_OHCI3]  = 0x01c1d400,
 [AW_H3_CCU]= 0x01c2,
 [AW_H3_PIT]= 0x01c20c00,
 [AW_H3_UART0]  = 0x01c28000,
@@ -144,6 +153,14 @@ enum {
 AW_H3_GIC_SPI_UART3 =  3,
 AW_H3_GIC_SPI_TIMER0= 18,
 AW_H3_GIC_SPI_TIMER1= 19,
+AW_H3_GIC_SPI_EHCI0 = 72,
+AW_H3_GIC_SPI_OHCI0 = 73,
+AW_H3_GIC_SPI_EHCI1 = 74,
+AW_H3_GIC_SPI_OHCI1 = 75,
+AW_H3_GIC_SPI_EHCI2 = 76,
+AW_H3_GIC_SPI_OHCI2 = 77,
+AW_H3_GIC_SPI_EHCI3 = 78,
+AW_H3_GIC_SPI_OHCI3 = 79,
 };
 
 /* Allwinner H3 general constants */
@@ -284,6 +301,33 @@ static void allwinner_h3_realize(DeviceState *dev, Error 
**errp)
 qdev_init_nofail(DEVICE(>ccu));
 sysbus_mmio_map(SYS_BUS_DEVICE(>ccu), 0, s->memmap[AW_H3_CCU]);
 
+/* Universal Serial Bus */
+sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0],
+ qdev_get_gpio_in(DEVICE(>gic),
+  AW_H3_GIC_SPI_EHCI0));
+sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI1],
+ qdev_get_gpio_in(DEVICE(>gic),
+  AW_H3_GIC_SPI_EHCI1));
+sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI2],
+ qdev_get_gpio_in(DEVICE(>gic),
+  AW_H3_GIC_SPI_EHCI2));
+sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI3],
+ qdev_get_gpio_in(DEVICE(>gic),
+  AW_H3_GIC_SPI_EHCI3));
+
+sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI0],
+ qdev_get_gpio_in(DEVICE(>gic),
+  AW_H3_GIC_SPI_OHCI0));
+sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI1],
+ qdev_get_gpio_in(DEVICE(>gic),
+  AW_H3_GIC_SPI_OHCI1));
+sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI2],
+ qdev_get_gpio_in(DEVICE(>gic),
+  AW_H3_GIC_SPI_OHCI2));
+sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI3],
+ qdev_get_gpio_in(DEVICE(>gic),
+  AW_H3_GIC_SPI_OHCI3));
+
 /* UART0. For future clocktree API: All UARTS are connected to APB2_CLK. */
 serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART0], 2,

[PATCH v8 07/18] hw/arm/allwinner: add Security Identifier device

2020-03-11 Thread Niek Linnenbank
The Security Identifier device found in various Allwinner System on Chip
designs gives applications a per-board unique identifier. This commit
adds support for the Allwinner Security Identifier using a 128-bit
UUID value as input.

Signed-off-by: Niek Linnenbank 
Reviewed-by: Alex Bennée 
---
 include/hw/arm/allwinner-h3.h   |   3 +
 include/hw/misc/allwinner-sid.h |  60 
 hw/arm/allwinner-h3.c   |  11 ++-
 hw/arm/orangepi.c   |   8 ++
 hw/misc/allwinner-sid.c | 168 
 hw/misc/Makefile.objs   |   1 +
 hw/misc/trace-events|   4 +
 7 files changed, 254 insertions(+), 1 deletion(-)
 create mode 100644 include/hw/misc/allwinner-sid.h
 create mode 100644 hw/misc/allwinner-sid.c

diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
index dc729176ab..85416d9d64 100644
--- a/include/hw/arm/allwinner-h3.h
+++ b/include/hw/arm/allwinner-h3.h
@@ -42,6 +42,7 @@
 #include "hw/misc/allwinner-h3-ccu.h"
 #include "hw/misc/allwinner-cpucfg.h"
 #include "hw/misc/allwinner-h3-sysctrl.h"
+#include "hw/misc/allwinner-sid.h"
 #include "target/arm/cpu.h"
 
 /**
@@ -59,6 +60,7 @@ enum {
 AW_H3_SRAM_A2,
 AW_H3_SRAM_C,
 AW_H3_SYSCTRL,
+AW_H3_SID,
 AW_H3_EHCI0,
 AW_H3_OHCI0,
 AW_H3_EHCI1,
@@ -114,6 +116,7 @@ typedef struct AwH3State {
 AwH3ClockCtlState ccu;
 AwCpuCfgState cpucfg;
 AwH3SysCtrlState sysctrl;
+AwSidState sid;
 GICState gic;
 MemoryRegion sram_a1;
 MemoryRegion sram_a2;
diff --git a/include/hw/misc/allwinner-sid.h b/include/hw/misc/allwinner-sid.h
new file mode 100644
index 00..4c1fa4762b
--- /dev/null
+++ b/include/hw/misc/allwinner-sid.h
@@ -0,0 +1,60 @@
+/*
+ * Allwinner Security ID emulation
+ *
+ * Copyright (C) 2019 Niek Linnenbank 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#ifndef HW_MISC_ALLWINNER_SID_H
+#define HW_MISC_ALLWINNER_SID_H
+
+#include "qom/object.h"
+#include "hw/sysbus.h"
+#include "qemu/uuid.h"
+
+/**
+ * Object model
+ * @{
+ */
+
+#define TYPE_AW_SID"allwinner-sid"
+#define AW_SID(obj) \
+OBJECT_CHECK(AwSidState, (obj), TYPE_AW_SID)
+
+/** @} */
+
+/**
+ * Allwinner Security ID object instance state
+ */
+typedef struct AwSidState {
+/*< private >*/
+SysBusDevice parent_obj;
+/*< public >*/
+
+/** Maps I/O registers in physical memory */
+MemoryRegion iomem;
+
+/** Control register defines how and what to read */
+uint32_t control;
+
+/** RdKey register contains the data retrieved by the device */
+uint32_t rdkey;
+
+/** Stores the emulated device identifier */
+QemuUUID identifier;
+
+} AwSidState;
+
+#endif /* HW_MISC_ALLWINNER_SID_H */
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
index b9a5597f2a..deeea63f5f 100644
--- a/hw/arm/allwinner-h3.c
+++ b/hw/arm/allwinner-h3.c
@@ -38,6 +38,7 @@ const hwaddr allwinner_h3_memmap[] = {
 [AW_H3_SRAM_A2]= 0x00044000,
 [AW_H3_SRAM_C] = 0x0001,
 [AW_H3_SYSCTRL]= 0x01c0,
+[AW_H3_SID]= 0x01c14000,
 [AW_H3_EHCI0]  = 0x01c1a000,
 [AW_H3_OHCI0]  = 0x01c1a400,
 [AW_H3_EHCI1]  = 0x01c1b000,
@@ -78,7 +79,6 @@ struct AwH3Unimplemented {
 { "mmc0",  0x01c0f000, 4 * KiB },
 { "mmc1",  0x01c1, 4 * KiB },
 { "mmc2",  0x01c11000, 4 * KiB },
-{ "sid",   0x01c14000, 1 * KiB },
 { "crypto",0x01c15000, 4 * KiB },
 { "msgbox",0x01c17000, 4 * KiB },
 { "spinlock",  0x01c18000, 4 * KiB },
@@ -198,6 +198,11 @@ static void allwinner_h3_init(Object *obj)
 
 sysbus_init_child_obj(obj, "cpucfg", >cpucfg, sizeof(s->cpucfg),
   TYPE_AW_CPUCFG);
+
+sysbus_init_child_obj(obj, "sid", >sid, sizeof(s->sid),
+  TYPE_AW_SID);
+object_property_add_alias(obj, "identifier", OBJECT(>sid),
+  "identifier", _abort);
 }
 
 static void allwinner_h3_realize(DeviceState *dev, Error **errp)
@@ -315,6 +320,10 @@ static void allwinner_h3_realize(DeviceState *dev, Error 
**errp)
 qdev_init_nofail(DEVICE(>cpucfg));
 sysbus_mmio_map(SYS_BUS_DEVICE(>cpucfg), 0, s->memmap[AW_H3_CPUCFG]);
 
+/* Security Identifier */
+qdev_init_nofail(DEVICE(>sid));
+sysbus_mmio_map(SYS_BUS_DEVICE(>sid), 0, s->memmap[AW_H3_SID]);
+
 /* 

Re: [PATCH v4 4/4] via-ide: Also emulate non 100% native mode

2020-03-11 Thread BALATON Zoltan

On Wed, 11 Mar 2020, Mark Cave-Ayland wrote:

On 10/03/2020 19:06, BALATON Zoltan wrote:

Some machines operate in "non 100% native mode" where interrupts are
fixed at legacy IDE interrupts and some guests expect this behaviour
without checking based on knowledge about hardware. Even Linux has
arch specific workarounds for this that are activated on such boards
so this needs to be emulated as well.

Signed-off-by: BALATON Zoltan 
---

Notes:
v2: Don't use PCI_INTERRUPT_LINE in via_ide_set_irq()
v3: Patch pci.c instead of local workaround for PCI reset clearing
PCI_INTERRUPT_PIN config reg

 hw/ide/via.c | 30 --
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/hw/ide/via.c b/hw/ide/via.c
index df0b352b58..1eada23097 100644
--- a/hw/ide/via.c
+++ b/hw/ide/via.c
@@ -1,9 +1,10 @@
 /*
- * QEMU IDE Emulation: PCI VIA82C686B support.
+ * QEMU VIA southbridge IDE emulation (VT82C686B, VT8231)
  *
  * Copyright (c) 2003 Fabrice Bellard
  * Copyright (c) 2006 Openedhand Ltd.
  * Copyright (c) 2010 Huacai Chen 
+ * Copyright (c) 2019-2020 BALATON Zoltan
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to 
deal
@@ -25,6 +26,7 @@
  */

 #include "qemu/osdep.h"
+#include "hw/qdev-properties.h"
 #include "hw/pci/pci.h"
 #include "migration/vmstate.h"
 #include "qemu/module.h"
@@ -111,11 +113,18 @@ static void via_ide_set_irq(void *opaque, int n, int 
level)
 } else {
 d->config[0x70 + n * 8] &= ~0x80;
 }
-
 level = (d->config[0x70] & 0x80) || (d->config[0x78] & 0x80);
-n = pci_get_byte(d->config + PCI_INTERRUPT_LINE);
-if (n) {
-qemu_set_irq(isa_get_irq(NULL, n), level);
+
+/*
+ * Some machines operate in "non 100% native mode" where PCI_INTERRUPT_LINE
+ * is not used but IDE always uses ISA IRQ 14 and 15 even in native mode.
+ * Some guest drivers expect this, often without checking.
+ */
+if (!(pci_get_byte(d->config + PCI_CLASS_PROG) & (n ? 4 : 1)) ||
+PCI_IDE(d)->flags & BIT(PCI_IDE_LEGACY_IRQ)) {
+qemu_set_irq(isa_get_irq(NULL, (n ? 15 : 14)), level);
+} else {
+qemu_set_irq(isa_get_irq(NULL, 14), level);
 }
 }

@@ -169,7 +178,9 @@ static void via_ide_realize(PCIDevice *dev, Error **errp)

 pci_config_set_prog_interface(pci_conf, 0x8f); /* native PCI ATA mode */
 pci_set_long(pci_conf + PCI_CAPABILITY_LIST, 0x00c0);
-dev->wmask[PCI_INTERRUPT_LINE] = 0xf;
+/* Bits 0 and 4 of CLASS_PROG select native mode and are writable */
+dev->wmask[PCI_CLASS_PROG] = 5;
+dev->wmask[PCI_INTERRUPT_LINE] = 0;

 memory_region_init_io(>data_bar[0], OBJECT(d), _ide_data_le_ops,
   >bus[0], "via-ide0-data", 8);
@@ -213,6 +224,12 @@ static void via_ide_exitfn(PCIDevice *dev)
 }
 }

+static Property via_ide_properties[] = {
+DEFINE_PROP_BIT("legacy-irq", PCIIDEState, flags, PCI_IDE_LEGACY_IRQ,
+false),
+DEFINE_PROP_END_OF_LIST(),
+};
+
 static void via_ide_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
@@ -225,6 +242,7 @@ static void via_ide_class_init(ObjectClass *klass, void 
*data)
 k->device_id = PCI_DEVICE_ID_VIA_IDE;
 k->revision = 0x06;
 k->class_id = PCI_CLASS_STORAGE_IDE;
+device_class_set_props(dc, via_ide_properties);
 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
 }


I don't think this (and adding the feature bit) are the right solution here. 
I'll do
my best to look at the test cases you've sent off-list over the next couple of 
days
and report back.


Thanks. No need to hurry as I don't have much free time for this now so 
maybe I'll come back to it when submitting pegasos2 patches. Until then if 
you can take at least the reviewed patches then we can revise the 
remaining ones when cleaning up VT82C686B and VT8231 models as that might 
be related to qdevifying this,


I don't see a way to avoid some property to tell the device that it should 
behave differently on pegasos2 than on fulong2e and using a feature bit 
for this seems to be the least hacky solution to me. Your proposed 
imaginary gpios seem more complex and likely not really match hardware so 
I don't think that would be less of a hack.


I've also tried using PCI_INTERRUPT_PIN config reg which at least the 686B 
datasheet said would switch to legacy IRQ routing but this did not work 
with Linux and MorphOS on pegasos2. We could also abuse another unused 
config reg value for this that clients don't care about but that wouldn't 
be any cleaner either.


Regards,
BALATON Zoltan



Re: [PATCH v4 3/4] Introduce the NVMM impl

2020-03-11 Thread Paolo Bonzini
On 11/03/20 22:21, Maxime Villard wrote:
>> Yes, you don't know how long that run would take.  I don't know about
>> NVMM but for KVM it may even never leave if the guest is in HLT state.
> Ok, I see, thanks.
> 
> In NVMM the runs are short

How do you ensure that a guest with interrupts off exits promptly?

> , the syscalls are fast, and pending signals
> cause returns to userland. Therefore, in practice, it's not a big problem,
> because (1) the window is small and (2) if we have a miss it's not going
> to take long to come back to Qemu.
> 
> I see a quick kernel change I can make to reduce 95% of the window
> already in the current state. The remaining 5% will need a new
> nvmm_vcpu_kick() function.

You can also do what KVM did until a few years ago: swap the signal mask
atomically when you enter the hypervisor (e.g. unmasking SIGUSR1---this
has to be done in the kernel) and when you leave it.  Then in QEMU you
keep SIGUSR1 masked and "eat" it with sigwaitinfo.

> For now this issue is unimportant and no Qemu change is required.

If you say so.

Paolo




Re: [PATCH v4 3/4] Introduce the NVMM impl

2020-03-11 Thread Kamil Rytarowski
On 11.03.2020 22:21, Maxime Villard wrote:
> Le 11/03/2020 à 21:42, Paolo Bonzini a écrit :
>> On 11/03/20 21:14, Maxime Villard wrote:
 The problem is that qcpu->stop is checked _before_ entering the
 hypervisor and not after, so there is a small race window.
>>> Ok. I don't understand what's supposed to be the race here. If we get an
>>> IPI between the check and the call to nvmm_vcpu_run() then we'll just do
>>> one run and stop in the next iteration, because the IPI will have set
>>> qcpu->stop. Is this extra iteration undesired?
>>
>> Yes, you don't know how long that run would take.  I don't know about
>> NVMM but for KVM it may even never leave if the guest is in HLT state.
>
> Ok, I see, thanks.
>
> In NVMM the runs are short, the syscalls are fast, and pending signals
> cause returns to userland. Therefore, in practice, it's not a big problem,
> because (1) the window is small and (2) if we have a miss it's not going
> to take long to come back to Qemu.
>
> I see a quick kernel change I can make to reduce 95% of the window
> already in the current state. The remaining 5% will need a new
> nvmm_vcpu_kick() function.
>
> For now this issue is unimportant and no Qemu change is required.
>
> Kamil, please also drop the XXX in
> /* XXX Needed, otherwise infinite loop. */
> It's not a bug.
>

OK. I will do it.

> Thanks,
> Maxime
>




Re: [PATCH v4 3/4] Introduce the NVMM impl

2020-03-11 Thread Maxime Villard
Le 11/03/2020 à 21:42, Paolo Bonzini a écrit :
> On 11/03/20 21:14, Maxime Villard wrote:
>>> The problem is that qcpu->stop is checked _before_ entering the
>>> hypervisor and not after, so there is a small race window.
>> Ok. I don't understand what's supposed to be the race here. If we get an
>> IPI between the check and the call to nvmm_vcpu_run() then we'll just do
>> one run and stop in the next iteration, because the IPI will have set
>> qcpu->stop. Is this extra iteration undesired?
> 
> Yes, you don't know how long that run would take.  I don't know about
> NVMM but for KVM it may even never leave if the guest is in HLT state.

Ok, I see, thanks.

In NVMM the runs are short, the syscalls are fast, and pending signals
cause returns to userland. Therefore, in practice, it's not a big problem,
because (1) the window is small and (2) if we have a miss it's not going
to take long to come back to Qemu.

I see a quick kernel change I can make to reduce 95% of the window
already in the current state. The remaining 5% will need a new
nvmm_vcpu_kick() function.

For now this issue is unimportant and no Qemu change is required.

Kamil, please also drop the XXX in
/* XXX Needed, otherwise infinite loop. */
It's not a bug.

Thanks,
Maxime



Re: [PATCH v4 4/4] via-ide: Also emulate non 100% native mode

2020-03-11 Thread Mark Cave-Ayland
On 10/03/2020 19:06, BALATON Zoltan wrote:

> Some machines operate in "non 100% native mode" where interrupts are
> fixed at legacy IDE interrupts and some guests expect this behaviour
> without checking based on knowledge about hardware. Even Linux has
> arch specific workarounds for this that are activated on such boards
> so this needs to be emulated as well.
> 
> Signed-off-by: BALATON Zoltan 
> ---
> 
> Notes:
> v2: Don't use PCI_INTERRUPT_LINE in via_ide_set_irq()
> v3: Patch pci.c instead of local workaround for PCI reset clearing
> PCI_INTERRUPT_PIN config reg
> 
>  hw/ide/via.c | 30 --
>  1 file changed, 24 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/ide/via.c b/hw/ide/via.c
> index df0b352b58..1eada23097 100644
> --- a/hw/ide/via.c
> +++ b/hw/ide/via.c
> @@ -1,9 +1,10 @@
>  /*
> - * QEMU IDE Emulation: PCI VIA82C686B support.
> + * QEMU VIA southbridge IDE emulation (VT82C686B, VT8231)
>   *
>   * Copyright (c) 2003 Fabrice Bellard
>   * Copyright (c) 2006 Openedhand Ltd.
>   * Copyright (c) 2010 Huacai Chen 
> + * Copyright (c) 2019-2020 BALATON Zoltan
>   *
>   * Permission is hereby granted, free of charge, to any person obtaining a 
> copy
>   * of this software and associated documentation files (the "Software"), to 
> deal
> @@ -25,6 +26,7 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "hw/qdev-properties.h"
>  #include "hw/pci/pci.h"
>  #include "migration/vmstate.h"
>  #include "qemu/module.h"
> @@ -111,11 +113,18 @@ static void via_ide_set_irq(void *opaque, int n, int 
> level)
>  } else {
>  d->config[0x70 + n * 8] &= ~0x80;
>  }
> -
>  level = (d->config[0x70] & 0x80) || (d->config[0x78] & 0x80);
> -n = pci_get_byte(d->config + PCI_INTERRUPT_LINE);
> -if (n) {
> -qemu_set_irq(isa_get_irq(NULL, n), level);
> +
> +/*
> + * Some machines operate in "non 100% native mode" where 
> PCI_INTERRUPT_LINE
> + * is not used but IDE always uses ISA IRQ 14 and 15 even in native mode.
> + * Some guest drivers expect this, often without checking.
> + */
> +if (!(pci_get_byte(d->config + PCI_CLASS_PROG) & (n ? 4 : 1)) ||
> +PCI_IDE(d)->flags & BIT(PCI_IDE_LEGACY_IRQ)) {
> +qemu_set_irq(isa_get_irq(NULL, (n ? 15 : 14)), level);
> +} else {
> +qemu_set_irq(isa_get_irq(NULL, 14), level);
>  }
>  }
>  
> @@ -169,7 +178,9 @@ static void via_ide_realize(PCIDevice *dev, Error **errp)
>  
>  pci_config_set_prog_interface(pci_conf, 0x8f); /* native PCI ATA mode */
>  pci_set_long(pci_conf + PCI_CAPABILITY_LIST, 0x00c0);
> -dev->wmask[PCI_INTERRUPT_LINE] = 0xf;
> +/* Bits 0 and 4 of CLASS_PROG select native mode and are writable */
> +dev->wmask[PCI_CLASS_PROG] = 5;
> +dev->wmask[PCI_INTERRUPT_LINE] = 0;
>  
>  memory_region_init_io(>data_bar[0], OBJECT(d), _ide_data_le_ops,
>>bus[0], "via-ide0-data", 8);
> @@ -213,6 +224,12 @@ static void via_ide_exitfn(PCIDevice *dev)
>  }
>  }
>  
> +static Property via_ide_properties[] = {
> +DEFINE_PROP_BIT("legacy-irq", PCIIDEState, flags, PCI_IDE_LEGACY_IRQ,
> +false),
> +DEFINE_PROP_END_OF_LIST(),
> +};
> +
>  static void via_ide_class_init(ObjectClass *klass, void *data)
>  {
>  DeviceClass *dc = DEVICE_CLASS(klass);
> @@ -225,6 +242,7 @@ static void via_ide_class_init(ObjectClass *klass, void 
> *data)
>  k->device_id = PCI_DEVICE_ID_VIA_IDE;
>  k->revision = 0x06;
>  k->class_id = PCI_CLASS_STORAGE_IDE;
> +device_class_set_props(dc, via_ide_properties);
>  set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
>  }

I don't think this (and adding the feature bit) are the right solution here. 
I'll do
my best to look at the test cases you've sent off-list over the next couple of 
days
and report back.


ATB,

Mark.



Re: [PATCH v3 02/10] fw_cfg: Migrate ACPI table mr sizes separately

2020-03-11 Thread Michael S. Tsirkin
On Wed, Mar 11, 2020 at 05:20:06PM +, Shameer Kolothum wrote:
> Any sub-page size update to ACPI table MRs will be lost during
> migration, as we use aligned size in ram_load_precopy() ->
> qemu_ram_resize() path. This will result in inconsistency in sizes
> between source and destination. In order to avoid this, save and
> restore them separately during migration.

Hmm but for old machine types we still have a problem right?
How about aligning size on source for them?
Then there won't be an inconsistency across migration.
Wastes some boot time/memory but maybe that's better
than a chance of not booting ...

> Suggested-by: David Hildenbrand 
> Signed-off-by: Shameer Kolothum 
> ---
> Please find the discussion here,
> https://patchwork.kernel.org/patch/11339591/
> ---
>  hw/core/machine.c |  1 +
>  hw/nvram/fw_cfg.c | 86 ++-
>  include/hw/nvram/fw_cfg.h |  6 +++
>  3 files changed, 92 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index 9e8c06036f..6d960bd47f 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -39,6 +39,7 @@ GlobalProperty hw_compat_4_2[] = {
>  { "usb-redir", "suppress-remote-wake", "off" },
>  { "qxl", "revision", "4" },
>  { "qxl-vga", "revision", "4" },
> +{ "fw_cfg", "acpi-mr-restore", "false" },
>  };
>  const size_t hw_compat_4_2_len = G_N_ELEMENTS(hw_compat_4_2);
>  
> diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
> index 179b302f01..36d1e32f83 100644
> --- a/hw/nvram/fw_cfg.c
> +++ b/hw/nvram/fw_cfg.c
> @@ -39,6 +39,7 @@
>  #include "qemu/config-file.h"
>  #include "qemu/cutils.h"
>  #include "qapi/error.h"
> +#include "hw/acpi/aml-build.h"
>  
>  #define FW_CFG_FILE_SLOTS_DFLT 0x20
>  
> @@ -610,6 +611,50 @@ bool fw_cfg_dma_enabled(void *opaque)
>  return s->dma_enabled;
>  }
>  
> +static bool fw_cfg_acpi_mr_restore(void *opaque)
> +{
> +FWCfgState *s = opaque;
> +return s->acpi_mr_restore;
> +}
> +
> +static void fw_cfg_update_mr(FWCfgState *s, uint16_t key, size_t size)
> +{
> +MemoryRegion *mr;
> +ram_addr_t offset;
> +int arch = !!(key & FW_CFG_ARCH_LOCAL);
> +void *ptr;
> +
> +key &= FW_CFG_ENTRY_MASK;
> +assert(key < fw_cfg_max_entry(s));
> +
> +ptr = s->entries[arch][key].data;
> +mr = memory_region_from_host(ptr, );
> +
> +memory_region_ram_resize(mr, size, _abort);
> +}
> +
> +static int fw_cfg_acpi_mr_restore_post_load(void *opaque, int version_id)
> +{
> +FWCfgState *s = opaque;
> +int i, index;
> +
> +assert(s->files);
> +
> +index = be32_to_cpu(s->files->count);
> +
> +for (i = 0; i < index; i++) {
> +if (!strcmp(s->files->f[i].name, ACPI_BUILD_TABLE_FILE)) {
> +fw_cfg_update_mr(s, FW_CFG_FILE_FIRST + i, s->table_mr_size);
> +} else if (!strcmp(s->files->f[i].name, ACPI_BUILD_LOADER_FILE)) {
> +fw_cfg_update_mr(s, FW_CFG_FILE_FIRST + i, s->linker_mr_size);
> +} else if (!strcmp(s->files->f[i].name, ACPI_BUILD_RSDP_FILE)) {
> +fw_cfg_update_mr(s, FW_CFG_FILE_FIRST + i, s->rsdp_mr_size);
> +}
> +}
> +
> +return 0;
> +}
> +
>  static const VMStateDescription vmstate_fw_cfg_dma = {
>  .name = "fw_cfg/dma",
>  .needed = fw_cfg_dma_enabled,
> @@ -619,6 +664,20 @@ static const VMStateDescription vmstate_fw_cfg_dma = {
>  },
>  };
>  
> +static const VMStateDescription vmstate_fw_cfg_acpi_mr = {
> +.name = "fw_cfg/acpi_mr",
> +.version_id = 1,
> +.minimum_version_id = 1,
> +.needed = fw_cfg_acpi_mr_restore,
> +.post_load = fw_cfg_acpi_mr_restore_post_load,
> +.fields = (VMStateField[]) {
> +VMSTATE_UINT64(table_mr_size, FWCfgState),
> +VMSTATE_UINT64(linker_mr_size, FWCfgState),
> +VMSTATE_UINT64(rsdp_mr_size, FWCfgState),
> +VMSTATE_END_OF_LIST()
> +},
> +};
> +
>  static const VMStateDescription vmstate_fw_cfg = {
>  .name = "fw_cfg",
>  .version_id = 2,
> @@ -631,6 +690,7 @@ static const VMStateDescription vmstate_fw_cfg = {
>  },
>  .subsections = (const VMStateDescription*[]) {
>  _fw_cfg_dma,
> +_fw_cfg_acpi_mr,
>  NULL,
>  }
>  };
> @@ -815,6 +875,23 @@ static struct {
>  #define FW_CFG_ORDER_OVERRIDE_LAST 200
>  };
>  
> +/*
> + * Any sub-page size update to these table MRs will be lost during migration,
> + * as we use aligned size in ram_load_precopy() -> qemu_ram_resize() path.
> + * In order to avoid the inconsistency in sizes save them seperately and
> + * migrate over in vmstate post_load().
> + */
> +static void fw_cfg_acpi_mr_save(FWCfgState *s, const char *filename, size_t 
> len)
> +{
> +if (!strcmp(filename, ACPI_BUILD_TABLE_FILE)) {
> +s->table_mr_size = len;
> +} else if (!strcmp(filename, ACPI_BUILD_LOADER_FILE)) {
> +s->linker_mr_size = len;
> +} else if (!strcmp(filename, ACPI_BUILD_RSDP_FILE)) {
> +s->rsdp_mr_size = len;
> +}

Re: [PATCH v4 1/4] ide/via: Get rid of via_init_ide()

2020-03-11 Thread Mark Cave-Ayland
On 10/03/2020 19:06, BALATON Zoltan wrote:

> Follow example of CMD646 and remove via_init_ide function and do it
> directly in board code instead.
> 
> Signed-off-by: BALATON Zoltan 
> ---
>  hw/ide/via.c| 8 
>  hw/mips/mips_fulong2e.c | 5 -
>  include/hw/ide.h| 1 -
>  3 files changed, 4 insertions(+), 10 deletions(-)
> 
> diff --git a/hw/ide/via.c b/hw/ide/via.c
> index 096de8dba0..df0b352b58 100644
> --- a/hw/ide/via.c
> +++ b/hw/ide/via.c
> @@ -213,14 +213,6 @@ static void via_ide_exitfn(PCIDevice *dev)
>  }
>  }
>  
> -void via_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn)
> -{
> -PCIDevice *dev;
> -
> -dev = pci_create_simple(bus, devfn, "via-ide");
> -pci_ide_create_devs(dev, hd_table);
> -}
> -
>  static void via_ide_class_init(ObjectClass *klass, void *data)
>  {
>  DeviceClass *dc = DEVICE_CLASS(klass);
> diff --git a/hw/mips/mips_fulong2e.c b/hw/mips/mips_fulong2e.c
> index 4727b1d3a4..639ba2a091 100644
> --- a/hw/mips/mips_fulong2e.c
> +++ b/hw/mips/mips_fulong2e.c
> @@ -37,6 +37,7 @@
>  #include "qemu/log.h"
>  #include "hw/loader.h"
>  #include "hw/ide.h"
> +#include "hw/ide/pci.h"
>  #include "elf.h"
>  #include "hw/isa/vt82c686.h"
>  #include "hw/rtc/mc146818rtc.h"
> @@ -239,6 +240,7 @@ static void vt82c686b_southbridge_init(PCIBus *pci_bus, 
> int slot, qemu_irq intc,
>  qemu_irq *i8259;
>  ISABus *isa_bus;
>  DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
> +PCIDevice *dev;
>  
>  isa_bus = vt82c686b_isa_init(pci_bus, PCI_DEVFN(slot, 0));
>  if (!isa_bus) {
> @@ -256,8 +258,9 @@ static void vt82c686b_southbridge_init(PCIBus *pci_bus, 
> int slot, qemu_irq intc,
>  /* Super I/O */
>  isa_create_simple(isa_bus, TYPE_VT82C686B_SUPERIO);
>  
> +dev = pci_create_simple(pci_bus, PCI_DEVFN(slot, 1), "via-ide");
>  ide_drive_get(hd, ARRAY_SIZE(hd));
> -via_ide_init(pci_bus, hd, PCI_DEVFN(slot, 1));
> +pci_ide_create_devs(dev, hd);
>  
>  pci_create_simple(pci_bus, PCI_DEVFN(slot, 2), "vt82c686b-usb-uhci");
>  pci_create_simple(pci_bus, PCI_DEVFN(slot, 3), "vt82c686b-usb-uhci");
> diff --git a/include/hw/ide.h b/include/hw/ide.h
> index 0c7080ed92..dea0ecf5be 100644
> --- a/include/hw/ide.h
> +++ b/include/hw/ide.h
> @@ -16,7 +16,6 @@ PCIDevice *pci_piix3_xen_ide_init(PCIBus *bus, DriveInfo 
> **hd_table, int devfn);
>  PCIDevice *pci_piix3_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn);
>  PCIDevice *pci_piix4_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn);
>  int pci_piix3_xen_ide_unplug(DeviceState *dev, bool aux);
> -void via_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn);
>  
>  /* ide-mmio.c */
>  void mmio_ide_init_drives(DeviceState *dev, DriveInfo *hd0, DriveInfo *hd1);

Reviewed-by: Mark Cave-Ayland 


ATB,

Mark.



Re: [PATCH v4 3/4] pci: Honour wmask when resetting PCI_INTERRUPT_LINE

2020-03-11 Thread Mark Cave-Ayland
On 10/03/2020 19:06, BALATON Zoltan wrote:

> The pci_do_device_reset() function (called from pci_device_reset)
> clears the PCI_INTERRUPT_LINE config reg of devices on the bus but did
> this without taking wmask into account. We'll have a device model now
> that needs to set a constant value for this reg and this patch allows
> to do that without additional workaround in device emulation to
> reverse the effect of this PCI bus reset function.
> 
> Suggested-by: Mark Cave-Ayland 
> Signed-off-by: BALATON Zoltan 
> ---
>  hw/pci/pci.c | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index e1ed6677e1..b5bc842fac 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -302,8 +302,11 @@ static void pci_do_device_reset(PCIDevice *dev)
>  pci_word_test_and_clear_mask(dev->config + PCI_STATUS,
>   pci_get_word(dev->wmask + PCI_STATUS) |
>   pci_get_word(dev->w1cmask + PCI_STATUS));
> +/* Some devices make bits of PCI_INTERRUPT_LINE read only */
> +pci_byte_test_and_clear_mask(dev->config + PCI_INTERRUPT_LINE,
> +  pci_get_word(dev->wmask + PCI_INTERRUPT_LINE) |
> +  pci_get_word(dev->w1cmask + 
> PCI_INTERRUPT_LINE));
>  dev->config[PCI_CACHE_LINE_SIZE] = 0x0;
> -dev->config[PCI_INTERRUPT_LINE] = 0x0;
>  for (r = 0; r < PCI_NUM_REGIONS; ++r) {
>  PCIIORegion *region = >io_regions[r];
>  if (!region->size) {
> 

Reviewed-by: Mark Cave-Ayland 


ATB,

Mark.



Re: [PATCH] util: fix to get configuration macros in util/mmap-alloc.c

2020-03-11 Thread Eduardo Habkost
On Wed, Mar 11, 2020 at 12:37:17PM +, Peter Maydell wrote:
> On Wed, 11 Mar 2020 at 00:43, Liu, Jingqi  wrote:
> > 1) If '#include ' first then '#include qemu/osdep.h', it
> > should be fine.
> >
> > 2) Peter mentioned osdep.h should go first.
> >
> > It will  cause redefinitions of other MAP_* macros after '#include
> > '.
> >
> > This is where the conflict lies.
> 
> osdep.h first, always. Other uses of linux-headers headers
> have presumably already dealt with this issue...

Including linux/mman.h before sys/mman.h is just a workaround to
the root cause: both headers really redefine each others' macros,
but gcc hide the warnings if the warnings are generated inside
system-provided headers.

I believe we should use -isystem for linux-headers insteaad of -I.

-- 
Eduardo




Re: [PATCH v3 02/10] fw_cfg: Migrate ACPI table mr sizes separately

2020-03-11 Thread Michael S. Tsirkin
On Wed, Mar 11, 2020 at 05:20:06PM +, Shameer Kolothum wrote:
> Any sub-page size update to ACPI table MRs will be lost during
> migration, as we use aligned size in ram_load_precopy() ->
> qemu_ram_resize() path. This will result in inconsistency in sizes
> between source and destination. In order to avoid this, save and
> restore them separately during migration.
> 
> Suggested-by: David Hildenbrand 
> Signed-off-by: Shameer Kolothum 

Is there a reason this is part of nvdimm patchset?

> ---
> Please find the discussion here,
> https://patchwork.kernel.org/patch/11339591/
> ---
>  hw/core/machine.c |  1 +
>  hw/nvram/fw_cfg.c | 86 ++-
>  include/hw/nvram/fw_cfg.h |  6 +++
>  3 files changed, 92 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index 9e8c06036f..6d960bd47f 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -39,6 +39,7 @@ GlobalProperty hw_compat_4_2[] = {
>  { "usb-redir", "suppress-remote-wake", "off" },
>  { "qxl", "revision", "4" },
>  { "qxl-vga", "revision", "4" },
> +{ "fw_cfg", "acpi-mr-restore", "false" },
>  };
>  const size_t hw_compat_4_2_len = G_N_ELEMENTS(hw_compat_4_2);
>  
> diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
> index 179b302f01..36d1e32f83 100644
> --- a/hw/nvram/fw_cfg.c
> +++ b/hw/nvram/fw_cfg.c
> @@ -39,6 +39,7 @@
>  #include "qemu/config-file.h"
>  #include "qemu/cutils.h"
>  #include "qapi/error.h"
> +#include "hw/acpi/aml-build.h"
>  
>  #define FW_CFG_FILE_SLOTS_DFLT 0x20
>  
> @@ -610,6 +611,50 @@ bool fw_cfg_dma_enabled(void *opaque)
>  return s->dma_enabled;
>  }
>  
> +static bool fw_cfg_acpi_mr_restore(void *opaque)
> +{
> +FWCfgState *s = opaque;
> +return s->acpi_mr_restore;
> +}
> +
> +static void fw_cfg_update_mr(FWCfgState *s, uint16_t key, size_t size)
> +{
> +MemoryRegion *mr;
> +ram_addr_t offset;
> +int arch = !!(key & FW_CFG_ARCH_LOCAL);
> +void *ptr;
> +
> +key &= FW_CFG_ENTRY_MASK;
> +assert(key < fw_cfg_max_entry(s));
> +
> +ptr = s->entries[arch][key].data;
> +mr = memory_region_from_host(ptr, );
> +
> +memory_region_ram_resize(mr, size, _abort);
> +}
> +
> +static int fw_cfg_acpi_mr_restore_post_load(void *opaque, int version_id)
> +{
> +FWCfgState *s = opaque;
> +int i, index;
> +
> +assert(s->files);
> +
> +index = be32_to_cpu(s->files->count);
> +
> +for (i = 0; i < index; i++) {
> +if (!strcmp(s->files->f[i].name, ACPI_BUILD_TABLE_FILE)) {
> +fw_cfg_update_mr(s, FW_CFG_FILE_FIRST + i, s->table_mr_size);
> +} else if (!strcmp(s->files->f[i].name, ACPI_BUILD_LOADER_FILE)) {
> +fw_cfg_update_mr(s, FW_CFG_FILE_FIRST + i, s->linker_mr_size);
> +} else if (!strcmp(s->files->f[i].name, ACPI_BUILD_RSDP_FILE)) {
> +fw_cfg_update_mr(s, FW_CFG_FILE_FIRST + i, s->rsdp_mr_size);
> +}
> +}
> +
> +return 0;
> +}
> +
>  static const VMStateDescription vmstate_fw_cfg_dma = {
>  .name = "fw_cfg/dma",
>  .needed = fw_cfg_dma_enabled,
> @@ -619,6 +664,20 @@ static const VMStateDescription vmstate_fw_cfg_dma = {
>  },
>  };
>  
> +static const VMStateDescription vmstate_fw_cfg_acpi_mr = {
> +.name = "fw_cfg/acpi_mr",
> +.version_id = 1,
> +.minimum_version_id = 1,
> +.needed = fw_cfg_acpi_mr_restore,
> +.post_load = fw_cfg_acpi_mr_restore_post_load,
> +.fields = (VMStateField[]) {
> +VMSTATE_UINT64(table_mr_size, FWCfgState),
> +VMSTATE_UINT64(linker_mr_size, FWCfgState),
> +VMSTATE_UINT64(rsdp_mr_size, FWCfgState),
> +VMSTATE_END_OF_LIST()
> +},
> +};
> +
>  static const VMStateDescription vmstate_fw_cfg = {
>  .name = "fw_cfg",
>  .version_id = 2,
> @@ -631,6 +690,7 @@ static const VMStateDescription vmstate_fw_cfg = {
>  },
>  .subsections = (const VMStateDescription*[]) {
>  _fw_cfg_dma,
> +_fw_cfg_acpi_mr,
>  NULL,
>  }
>  };
> @@ -815,6 +875,23 @@ static struct {
>  #define FW_CFG_ORDER_OVERRIDE_LAST 200
>  };
>  
> +/*
> + * Any sub-page size update to these table MRs will be lost during migration,
> + * as we use aligned size in ram_load_precopy() -> qemu_ram_resize() path.
> + * In order to avoid the inconsistency in sizes save them seperately and
> + * migrate over in vmstate post_load().
> + */
> +static void fw_cfg_acpi_mr_save(FWCfgState *s, const char *filename, size_t 
> len)
> +{
> +if (!strcmp(filename, ACPI_BUILD_TABLE_FILE)) {
> +s->table_mr_size = len;
> +} else if (!strcmp(filename, ACPI_BUILD_LOADER_FILE)) {
> +s->linker_mr_size = len;
> +} else if (!strcmp(filename, ACPI_BUILD_RSDP_FILE)) {
> +s->rsdp_mr_size = len;
> +}
> +}
> +
>  static int get_fw_cfg_order(FWCfgState *s, const char *name)
>  {
>  int i;
> @@ -914,6 +991,7 @@ void fw_cfg_add_file_callback(FWCfgState *s,  const char 
> *filename,
>  

Re: [PATCH v4 3/4] Introduce the NVMM impl

2020-03-11 Thread Paolo Bonzini
On 11/03/20 21:14, Maxime Villard wrote:
>> The problem is that qcpu->stop is checked _before_ entering the
>> hypervisor and not after, so there is a small race window.
> Ok. I don't understand what's supposed to be the race here. If we get an
> IPI between the check and the call to nvmm_vcpu_run() then we'll just do
> one run and stop in the next iteration, because the IPI will have set
> qcpu->stop. Is this extra iteration undesired?

Yes, you don't know how long that run would take.  I don't know about
NVMM but for KVM it may even never leave if the guest is in HLT state.

Paolo




Re: [PATCH] acpi: Add Windows ACPI Emulated Device Table (WAET)

2020-03-11 Thread Michael S. Tsirkin
Thanks for the patch! Some questions/comments:

On Wed, Mar 11, 2020 at 07:08:26PM +0200, Liran Alon wrote:
> From: Elad Gabay 
> 
> Microsoft introduced this ACPI table to avoid Windows guests performing
> various workarounds for device erratas. As the virtual device emulated
> by VMM may not have the errata.
> 
> Currently, WAET allows hypervisor to inform guest about two
> specific behaviors: One for RTC and the other for ACPI PM Timer.
> 
> Support for WAET have been introduced since Windows Vista. This ACPI
> table is also exposed by other hypervisors, such as VMware, by default.
> 
> This patch adds WAET ACPI Table to QEMU.

Could you add a bit more info? Why is this so useful we are adding this
by default? How does it change windows behaviour when present?

> It also makes sure to introduce
> the new ACPI table only for new machine-types.

OK and why is that?

> 
> Signed-off-by: Elad Gabay 
> Co-developed-by: Liran Alon 
> Signed-off-by: Liran Alon 
> ---
>  hw/i386/acpi-build.c| 18 ++
>  hw/i386/pc_piix.c   |  2 ++
>  hw/i386/pc_q35.c|  2 ++
>  include/hw/acpi/acpi-defs.h | 25 +
>  include/hw/i386/pc.h|  1 +
>  5 files changed, 48 insertions(+)
> 
> diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> index 9c4e46fa7466..29f70741cd96 100644
> --- a/hw/i386/acpi-build.c
> +++ b/hw/i386/acpi-build.c
> @@ -2512,6 +2512,19 @@ build_dmar_q35(GArray *table_data, BIOSLinker *linker)
>  build_header(linker, table_data, (void *)(table_data->data + dmar_start),
>   "DMAR", table_data->len - dmar_start, 1, NULL, NULL);
>  }
> +
> +static void
> +build_waet(GArray *table_data, BIOSLinker *linker)
> +{
> +AcpiTableWaet *waet;
> +
> +waet = acpi_data_push(table_data, sizeof(*waet));

Can combine with the previous line.

> +waet->emulated_device_flags = cpu_to_le32(ACPI_WAET_PM_TIMER_GOOD);
> +
> +build_header(linker, table_data,
> + (void *)waet, "WAET", sizeof(*waet), 1, NULL, NULL);
> +}
> +
>  /*
>   *   IVRS table as specified in AMD IOMMU Specification v2.62, Section 5.2
>   *   accessible here http://support.amd.com/TechDocs/48882_IOMMU.pdf
> @@ -2859,6 +2872,11 @@ void acpi_build(AcpiBuildTables *tables, MachineState 
> *machine)
>machine->nvdimms_state, machine->ram_slots);
>  }
>  
> +if (!pcmc->do_not_add_waet_acpi) {
> +acpi_add_table(table_offsets, tables_blob);
> +build_waet(tables_blob, tables->linker);
> +}
> +
>  /* Add tables supplied by user (if any) */
>  for (u = acpi_table_first(); u; u = acpi_table_next(u)) {
>  unsigned len = acpi_table_len(u);
> diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
> index 9088db8fb601..2d11a8b50a9c 100644
> --- a/hw/i386/pc_piix.c
> +++ b/hw/i386/pc_piix.c
> @@ -432,9 +432,11 @@ DEFINE_I440FX_MACHINE(v5_0, "pc-i440fx-5.0", NULL,
>  
>  static void pc_i440fx_4_2_machine_options(MachineClass *m)
>  {
> +PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
>  pc_i440fx_5_0_machine_options(m);
>  m->alias = NULL;
>  m->is_default = false;
> +pcmc->do_not_add_waet_acpi = true;
>  compat_props_add(m->compat_props, hw_compat_4_2, hw_compat_4_2_len);
>  compat_props_add(m->compat_props, pc_compat_4_2, pc_compat_4_2_len);
>  }
> diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
> index 84cf925cf43a..1e0a726b27a7 100644
> --- a/hw/i386/pc_q35.c
> +++ b/hw/i386/pc_q35.c
> @@ -361,8 +361,10 @@ DEFINE_Q35_MACHINE(v5_0, "pc-q35-5.0", NULL,
>  
>  static void pc_q35_4_2_machine_options(MachineClass *m)
>  {
> +PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
>  pc_q35_5_0_machine_options(m);
>  m->alias = NULL;
> +pcmc->do_not_add_waet_acpi = true;
>  compat_props_add(m->compat_props, hw_compat_4_2, hw_compat_4_2_len);
>  compat_props_add(m->compat_props, pc_compat_4_2, pc_compat_4_2_len);
>  }
> diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h
> index 57a3f58b0c9a..803c904471d5 100644
> --- a/include/hw/acpi/acpi-defs.h
> +++ b/include/hw/acpi/acpi-defs.h
> @@ -634,4 +634,29 @@ struct AcpiIortRC {
>  } QEMU_PACKED;
>  typedef struct AcpiIortRC AcpiIortRC;
>  
> +/*
> + * Windows ACPI Emulated Devices Table.
> + * Specification:
> + * 
> http://download.microsoft.com/download/7/E/7/7E7662CF-CBEA-470B-A97E-CE7CE0D98DC2/WAET.docx
> + */
> +
> +/*
> + * Indicates whether the RTC has been enhanced not to require acknowledgment
> + * after it asserts an interrupt. With this bit set, an interrupt handler can
> + * bypass reading the RTC register C to unlatch the pending interrupt.
> + */
> +#define ACPI_WAET_RTC_GOOD  (1 << 0)
> +/*
> + * Indicates whether the ACPI PM timer has been enhanced not to require
> + * multiple reads. With this bit set, only one read of the ACPI PM timer is
> + * necessary to obtain a reliable value.
> + */
> +#define ACPI_WAET_PM_TIMER_GOOD (1 << 1)
> +

ACPI spec is so huge we really 

Re: [PATCH] acpi: Add Windows ACPI Emulated Device Table (WAET)

2020-03-11 Thread Michael S. Tsirkin
On Wed, Mar 11, 2020 at 09:08:56PM +0200, Liran Alon wrote:
> 
> On 11/03/2020 20:59, no-re...@patchew.org wrote:
> > Patchew URL: 
> > https://urldefense.com/v3/__https://patchew.org/QEMU/20200311170826.79419-1-liran.a...@oracle.com/__;!!GqivPVa7Brio!L4XXKjkDknE86ihbnytm45vsQI41J-QWVCZRoXEXtPKIAsMmknrGJWVPZpKgLyM$
> > 
> > Hi,
> > 
> > This series failed the docker-quick@centos7 build test. Please find the 
> > testing commands and
> > their output below. If you have Docker installed, you can probably 
> > reproduce it
> > locally.
> > 
> > === TEST SCRIPT BEGIN ===
> > #!/bin/bash
> > make docker-image-centos7 V=1 NETWORK=1
> > time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1
> > === TEST SCRIPT END ===
> > 
> > Using expected file 'tests/data/acpi/pc/HPET'
> > Looking for expected file 'tests/data/acpi/pc/WAET'
> > **
> > ERROR:/tmp/qemu-test/src/tests/qtest/bios-tables-test.c:367:load_expected_aml:
> >  assertion failed: (exp_sdt.aml_file)
> > ERROR - Bail out! 
> > ERROR:/tmp/qemu-test/src/tests/qtest/bios-tables-test.c:367:load_expected_aml:
> >  assertion failed: (exp_sdt.aml_file)
> 
> My bad. Didn't notice there are tests which verifies ACPI haven't changed
> and requires update for such patch.
> Will submit a patch for this test in v2.
> 
> -Liran
> 

Notice the process as documented in ./tests/qtest/bios-tables-test.c

-- 
MST




Re: [PATCH v3 5/6] virtio-net: add migration support for RSS and hast report

2020-03-11 Thread Michael S. Tsirkin
On Wed, Mar 11, 2020 at 04:00:44PM +0200, Yuri Benditovich wrote:
> 
> 
> On Wed, Mar 11, 2020 at 3:48 PM Michael S. Tsirkin  wrote:
> 
> On Wed, Mar 11, 2020 at 02:35:17PM +0200, Yuri Benditovich wrote:
> > Save and restore RSS/hash report configuration.
> >
> > Signed-off-by: Yuri Benditovich 
> > ---
> >  hw/net/virtio-net.c | 9 +
> >  1 file changed, 9 insertions(+)
> >
> > diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> > index 7b6a929e8c..c8d97d45cd 100644
> > --- a/hw/net/virtio-net.c
> > +++ b/hw/net/virtio-net.c
> > @@ -2869,6 +2869,13 @@ static int virtio_net_post_load_device(void
> *opaque, int version_id)
> >          }
> >      }
> > 
> > +    if (n->rss_data.enabled) {
> > +        trace_virtio_net_rss_enable(n->rss_data.hash_types,
> > +                                    n->rss_data.indirections_len,
> > +                                    sizeof(n->rss_data.key));
> > +    } else {
> > +        trace_virtio_net_rss_disable();
> > +    }
> >      return 0;
> >  }
> > 
> > @@ -3094,6 +3101,8 @@ static const VMStateDescription
> vmstate_virtio_net_device = {
> >                           vmstate_virtio_net_tx_waiting),
> >          VMSTATE_UINT64_TEST(curr_guest_offloads, VirtIONet,
> >                              has_ctrl_guest_offloads),
> > +        VMSTATE_UINT8_ARRAY(rss_data_migration, VirtIONet,
> > +                            sizeof(VirtioNetRssData)),
> >          VMSTATE_END_OF_LIST()
> >     },
> 
> 
> I think we should migrate the length too. Avoid arbitrary limits.
> 
> 
> The length of what?

Of the tables.
> The structure is fixed-length and the intention is just to
> keep/restore it.
> The length of indirection table and the table itself are part of the 
> structure.


And that's a problem, because
1. we are wasting memory for a rarely used feature
2. if we want to make the table bigger, we'll need to break
   migration compatibility

Just allocate these dynamically as needed, and migrate length.


> 
> Yes this means we should allocate the indirection arrays on the fly.
> But that's probably a good idea anyway.
> 
> >  };
> > --
> > 2.17.1
> 
> 




Re: [PATCH v3 1/6] virtio-net: introduce RSS and hash report features

2020-03-11 Thread Michael S. Tsirkin
On Wed, Mar 11, 2020 at 03:57:58PM +0200, Yuri Benditovich wrote:
> 
> 
> On Wed, Mar 11, 2020 at 3:47 PM Michael S. Tsirkin  wrote:
> 
> On Wed, Mar 11, 2020 at 02:35:13PM +0200, Yuri Benditovich wrote:
> > Signed-off-by: Yuri Benditovich 
> > ---
> >  hw/net/virtio-net.c | 95 +
> >  1 file changed, 95 insertions(+)
> >
> > diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> > index 3627bb1717..9545b0e84f 100644
> > --- a/hw/net/virtio-net.c
> > +++ b/hw/net/virtio-net.c
> > @@ -71,6 +71,101 @@
> >  #define VIRTIO_NET_IP6_ADDR_SIZE   32      /* ipv6 saddr + daddr */
> >  #define VIRTIO_NET_MAX_IP6_PAYLOAD VIRTIO_NET_MAX_TCP_PAYLOAD
> > 
> > +/* TODO: remove after virtio-net header update */
> > +#if !defined(VIRTIO_NET_RSS_HASH_TYPE_IPv4)
> > +#define VIRTIO_NET_F_HASH_REPORT    57  /* Supports hash report */
> > +#define VIRTIO_NET_F_RSS            60  /* Supports RSS RX steering */
> > +
> > +/* supported/enabled hash types */
> > +#define VIRTIO_NET_RSS_HASH_TYPE_IPv4          (1 << 0)
> > +#define VIRTIO_NET_RSS_HASH_TYPE_TCPv4         (1 << 1)
> > +#define VIRTIO_NET_RSS_HASH_TYPE_UDPv4         (1 << 2)
> > +#define VIRTIO_NET_RSS_HASH_TYPE_IPv6          (1 << 3)
> > +#define VIRTIO_NET_RSS_HASH_TYPE_TCPv6         (1 << 4)
> > +#define VIRTIO_NET_RSS_HASH_TYPE_UDPv6         (1 << 5)
> > +#define VIRTIO_NET_RSS_HASH_TYPE_IP_EX         (1 << 6)
> > +#define VIRTIO_NET_RSS_HASH_TYPE_TCP_EX        (1 << 7)
> > +#define VIRTIO_NET_RSS_HASH_TYPE_UDP_EX        (1 << 8)
> > +
> > +#define __le16 uint16_t
> > +#define __le32 uint32_t
> > +#define __u8   uint8_t
> > +#define __u16  uint16_t
> > +#define __u32  uint32_t
> 
> Let's just use uint16_t etc directly please.
> 
> > +struct virtio_net_config_with_rss {
> > +    /* The config defining mac address (if VIRTIO_NET_F_MAC) */
> > +    __u8 mac[ETH_ALEN];
> > +    /* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */
> > +    __u16 status;
> > +    /*
> > +     * Maximum number of each of transmit and receive queues;
> > +     * see VIRTIO_NET_F_MQ and VIRTIO_NET_CTRL_MQ.
> > +     * Legal values are between 1 and 0x8000
> > +     */
> > +    __u16 max_virtqueue_pairs;
> > +    /* Default maximum transmit unit advice */
> > +    __u16 mtu;
> > +    /*
> > +     * speed, in units of 1Mb. All values 0 to INT_MAX are legal.
> > +     * Any other value stands for unknown.
> > +     */
> > +    __u32 speed;
> > +    /*
> > +     * 0x00 - half duplex
> > +     * 0x01 - full duplex
> > +     * Any other value stands for unknown.
> > +     */
> > +    __u8 duplex;
> > +    /* maximum size of RSS key */
> > +    __u8 rss_max_key_size;
> > +    /* maximum number of indirection table entries */
> > +    __le16 rss_max_indirection_table_length;
> > +    /* bitmask of supported VIRTIO_NET_RSS_HASH_ types */
> > +    __le32 supported_hash_types;
> > +} __attribute__((packed));
> > +
> > +#define virtio_net_config virtio_net_config_with_rss
> 
> Do we have to? Let's just tweak code to do the right thing...
> 
> 
> Are we going to update the virtio_net some time?
> If yes, IMO makes sense to do less tweaking in the middle of the code.
> Then, upon update of virtio_net.h - easily remove all these defines that were
> added in virtio-net.c 

We'll update it in a month or two. But I'd be reluctant to merge hacks
since people tend to copy-paste code ...

> 
> 
> > +
> > +struct virtio_net_hdr_v1_hash {
> > +    struct virtio_net_hdr_v1 hdr;
> > +    __le32 hash_value;
> > +#define VIRTIO_NET_HASH_REPORT_NONE            0
> > +#define VIRTIO_NET_HASH_REPORT_IPv4            1
> > +#define VIRTIO_NET_HASH_REPORT_TCPv4           2
> > +#define VIRTIO_NET_HASH_REPORT_UDPv4           3
> > +#define VIRTIO_NET_HASH_REPORT_IPv6            4
> > +#define VIRTIO_NET_HASH_REPORT_TCPv6           5
> > +#define VIRTIO_NET_HASH_REPORT_UDPv6           6
> > +#define VIRTIO_NET_HASH_REPORT_IPv6_EX         7
> > +#define VIRTIO_NET_HASH_REPORT_TCPv6_EX        8
> > +#define VIRTIO_NET_HASH_REPORT_UDPv6_EX        9
> > +    __le16 hash_report;
> > +    __le16 padding;
> > +};
> > +
> > +/*
> > + * The command VIRTIO_NET_CTRL_MQ_RSS_CONFIG has the same effect as
> > + * VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET does and additionally configures
> > + * the receive steering to use a hash calculated for incoming packet
> > + * to decide on receive virtqueue to place the packet. The command
> > + * also provides parameters to calculate a hash and receive virtqueue.
> > + */
> > +struct virtio_net_rss_config {
> > +    __le32 hash_types;
> > +    __le16 indirection_table_mask;

Re: [PATCH v4 3/4] Introduce the NVMM impl

2020-03-11 Thread Maxime Villard
Le 11/03/2020 à 19:03, Paolo Bonzini a écrit :
> On 10/03/20 20:14, Maxime Villard wrote:
>> Maybe, whpx_vcpu_kick() causes a WHvRunVpExitReasonCanceled in the
>> WHvRunVirtualProcessor() call that follows, which in turn causes "ret=1"
>> to leave the loop. That is, maybe the next WHvRunVirtualProcessor() acks
>> the cancellation and leaves without doing anything, even if the
>> cancellation was received when this function wasn't executing. So there is
>> no bad effect, given that we still end up leaving the loop, which is the
>> desired functional behavior.
> 
> Yes, that's exactly the effect, and it solves the race in the same way
> as KVM's run->immediate_exit flag.
> 
>> Looking at NVMM now, it seems to me there is the same thing. We do a
>> self-kick but we're the calling thread and know the VCPU isn't executing.
>> As a result of the self-kick the IPI handler sets
>>  qcpu->stop = true;
>> And in the next iteration of the loop, we break because this bool is set
> 
> The problem is that qcpu->stop is checked _before_ entering the
> hypervisor and not after, so there is a small race window.

Ok. I don't understand what's supposed to be the race here. If we get an
IPI between the check and the call to nvmm_vcpu_run() then we'll just do
one run and stop in the next iteration, because the IPI will have set
qcpu->stop. Is this extra iteration undesired?



Re: [PATCH v7 07/18] hw/arm/allwinner: add Security Identifier device

2020-03-11 Thread Niek Linnenbank
On Wed, Mar 11, 2020 at 9:04 PM Alex Bennée  wrote:

>
> Niek Linnenbank  writes:
>
> > On Wed, Mar 11, 2020 at 2:53 PM Alex Bennée 
> wrote:
> >
> >>
> >> Niek Linnenbank  writes:
> >>
> >> > The Security Identifier device found in various Allwinner System on
> Chip
> >> > designs gives applications a per-board unique identifier. This commit
> >> > adds support for the Allwinner Security Identifier using a 128-bit
> >> > UUID value as input.
> >> >
> >> > Signed-off-by: Niek Linnenbank 
> >> > ---
> >> >  include/hw/arm/allwinner-h3.h   |   3 +
> >> >  include/hw/misc/allwinner-sid.h |  60 
> >> >  hw/arm/allwinner-h3.c   |  11 ++-
> >> >  hw/arm/orangepi.c   |   9 ++
> >> >  hw/misc/allwinner-sid.c | 168
> 
> >> >  hw/misc/Makefile.objs   |   1 +
> >> >  hw/misc/trace-events|   4 +
> >> >  7 files changed, 255 insertions(+), 1 deletion(-)
> >> >  create mode 100644 include/hw/misc/allwinner-sid.h
> >> >  create mode 100644 hw/misc/allwinner-sid.c
> >> >
> >> > diff --git a/include/hw/arm/allwinner-h3.h
> >> b/include/hw/arm/allwinner-h3.h
> >> > index dc729176ab..85416d9d64 100644
> >> > --- a/include/hw/arm/allwinner-h3.h
> >> > +++ b/include/hw/arm/allwinner-h3.h
> >> > @@ -42,6 +42,7 @@
> >> >  #include "hw/misc/allwinner-h3-ccu.h"
> >> >  #include "hw/misc/allwinner-cpucfg.h"
> >> >  #include "hw/misc/allwinner-h3-sysctrl.h"
> >> > +#include "hw/misc/allwinner-sid.h"
> >> >  #include "target/arm/cpu.h"
> >> >
> >> >  /**
> >> > @@ -59,6 +60,7 @@ enum {
> >> >  AW_H3_SRAM_A2,
> >> >  AW_H3_SRAM_C,
> >> >  AW_H3_SYSCTRL,
> >> > +AW_H3_SID,
> >> >  AW_H3_EHCI0,
> >> >  AW_H3_OHCI0,
> >> >  AW_H3_EHCI1,
> >> > @@ -114,6 +116,7 @@ typedef struct AwH3State {
> >> >  AwH3ClockCtlState ccu;
> >> >  AwCpuCfgState cpucfg;
> >> >  AwH3SysCtrlState sysctrl;
> >> > +AwSidState sid;
> >> >  GICState gic;
> >> >  MemoryRegion sram_a1;
> >> >  MemoryRegion sram_a2;
> >> > diff --git a/include/hw/misc/allwinner-sid.h
> >> b/include/hw/misc/allwinner-sid.h
> >> > new file mode 100644
> >> > index 00..4c1fa4762b
> >> > --- /dev/null
> >> > +++ b/include/hw/misc/allwinner-sid.h
> >> > @@ -0,0 +1,60 @@
> >> > +/*
> >> > + * Allwinner Security ID emulation
> >> > + *
> >> > + * Copyright (C) 2019 Niek Linnenbank 
> >> > + *
> >> > + * This program is free software: you can redistribute it and/or
> modify
> >> > + * it under the terms of the GNU General Public License as published
> by
> >> > + * the Free Software Foundation, either version 2 of the License, or
> >> > + * (at your option) any later version.
> >> > + *
> >> > + * This program is distributed in the hope that it will be useful,
> >> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> >> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> >> > + * GNU General Public License for more details.
> >> > + *
> >> > + * You should have received a copy of the GNU General Public License
> >> > + * along with this program.  If not, see <
> http://www.gnu.org/licenses/
> >> >.
> >> > + */
> >> > +
> >> > +#ifndef HW_MISC_ALLWINNER_SID_H
> >> > +#define HW_MISC_ALLWINNER_SID_H
> >> > +
> >> > +#include "qom/object.h"
> >> > +#include "hw/sysbus.h"
> >> > +#include "qemu/uuid.h"
> >> > +
> >> > +/**
> >> > + * Object model
> >> > + * @{
> >> > + */
> >> > +
> >> > +#define TYPE_AW_SID"allwinner-sid"
> >> > +#define AW_SID(obj) \
> >> > +OBJECT_CHECK(AwSidState, (obj), TYPE_AW_SID)
> >> > +
> >> > +/** @} */
> >> > +
> >> > +/**
> >> > + * Allwinner Security ID object instance state
> >> > + */
> >> > +typedef struct AwSidState {
> >> > +/*< private >*/
> >> > +SysBusDevice parent_obj;
> >> > +/*< public >*/
> >> > +
> >> > +/** Maps I/O registers in physical memory */
> >> > +MemoryRegion iomem;
> >> > +
> >> > +/** Control register defines how and what to read */
> >> > +uint32_t control;
> >> > +
> >> > +/** RdKey register contains the data retrieved by the device */
> >> > +uint32_t rdkey;
> >> > +
> >> > +/** Stores the emulated device identifier */
> >> > +QemuUUID identifier;
> >> > +
> >> > +} AwSidState;
> >> > +
> >> > +#endif /* HW_MISC_ALLWINNER_SID_H */
> >> > diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
> >> > index b9a5597f2a..deeea63f5f 100644
> >> > --- a/hw/arm/allwinner-h3.c
> >> > +++ b/hw/arm/allwinner-h3.c
> >> > @@ -38,6 +38,7 @@ const hwaddr allwinner_h3_memmap[] = {
> >> >  [AW_H3_SRAM_A2]= 0x00044000,
> >> >  [AW_H3_SRAM_C] = 0x0001,
> >> >  [AW_H3_SYSCTRL]= 0x01c0,
> >> > +[AW_H3_SID]= 0x01c14000,
> >> >  [AW_H3_EHCI0]  = 0x01c1a000,
> >> >  [AW_H3_OHCI0]  = 0x01c1a400,
> >> >  [AW_H3_EHCI1]  = 0x01c1b000,
> >> > @@ -78,7 +79,6 @@ struct AwH3Unimplemented {
> >> >  { "mmc0",  0x01c0f000, 4 * KiB },
> >> >  { 

Re: [PATCH v7 00/18] Add Allwinner H3 SoC and Orange Pi PC Machine

2020-03-11 Thread Niek Linnenbank
On Wed, Mar 11, 2020 at 3:04 PM Alex Bennée  wrote:

>
> Niek Linnenbank  writes:
>
> > Dear QEMU developers,
> >
> > Hereby I would like to contribute the following set of patches to QEMU
> > which add support for the Allwinner H3 System on Chip and the
> > Orange Pi PC machine. The following features and devices are supported:
> 
>
> I've finished my pass through and I think everything has a review tag
> now. As there are some small fixes needed you can you do a v8 respin
> which Peter can apply to target-arm/next.
>

Thanks for taking the time to review Alex. I'm including the small fixes
you suggested and adding the tags and then I'll send v8 to the list.

Regards,
Niek


>
> --
> Alex Bennée
>


-- 
Niek Linnenbank


Re: [PATCH v7 07/18] hw/arm/allwinner: add Security Identifier device

2020-03-11 Thread Alex Bennée


Niek Linnenbank  writes:

> On Wed, Mar 11, 2020 at 2:53 PM Alex Bennée  wrote:
>
>>
>> Niek Linnenbank  writes:
>>
>> > The Security Identifier device found in various Allwinner System on Chip
>> > designs gives applications a per-board unique identifier. This commit
>> > adds support for the Allwinner Security Identifier using a 128-bit
>> > UUID value as input.
>> >
>> > Signed-off-by: Niek Linnenbank 
>> > ---
>> >  include/hw/arm/allwinner-h3.h   |   3 +
>> >  include/hw/misc/allwinner-sid.h |  60 
>> >  hw/arm/allwinner-h3.c   |  11 ++-
>> >  hw/arm/orangepi.c   |   9 ++
>> >  hw/misc/allwinner-sid.c | 168 
>> >  hw/misc/Makefile.objs   |   1 +
>> >  hw/misc/trace-events|   4 +
>> >  7 files changed, 255 insertions(+), 1 deletion(-)
>> >  create mode 100644 include/hw/misc/allwinner-sid.h
>> >  create mode 100644 hw/misc/allwinner-sid.c
>> >
>> > diff --git a/include/hw/arm/allwinner-h3.h
>> b/include/hw/arm/allwinner-h3.h
>> > index dc729176ab..85416d9d64 100644
>> > --- a/include/hw/arm/allwinner-h3.h
>> > +++ b/include/hw/arm/allwinner-h3.h
>> > @@ -42,6 +42,7 @@
>> >  #include "hw/misc/allwinner-h3-ccu.h"
>> >  #include "hw/misc/allwinner-cpucfg.h"
>> >  #include "hw/misc/allwinner-h3-sysctrl.h"
>> > +#include "hw/misc/allwinner-sid.h"
>> >  #include "target/arm/cpu.h"
>> >
>> >  /**
>> > @@ -59,6 +60,7 @@ enum {
>> >  AW_H3_SRAM_A2,
>> >  AW_H3_SRAM_C,
>> >  AW_H3_SYSCTRL,
>> > +AW_H3_SID,
>> >  AW_H3_EHCI0,
>> >  AW_H3_OHCI0,
>> >  AW_H3_EHCI1,
>> > @@ -114,6 +116,7 @@ typedef struct AwH3State {
>> >  AwH3ClockCtlState ccu;
>> >  AwCpuCfgState cpucfg;
>> >  AwH3SysCtrlState sysctrl;
>> > +AwSidState sid;
>> >  GICState gic;
>> >  MemoryRegion sram_a1;
>> >  MemoryRegion sram_a2;
>> > diff --git a/include/hw/misc/allwinner-sid.h
>> b/include/hw/misc/allwinner-sid.h
>> > new file mode 100644
>> > index 00..4c1fa4762b
>> > --- /dev/null
>> > +++ b/include/hw/misc/allwinner-sid.h
>> > @@ -0,0 +1,60 @@
>> > +/*
>> > + * Allwinner Security ID emulation
>> > + *
>> > + * Copyright (C) 2019 Niek Linnenbank 
>> > + *
>> > + * This program is free software: you can redistribute it and/or modify
>> > + * it under the terms of the GNU General Public License as published by
>> > + * the Free Software Foundation, either version 2 of the License, or
>> > + * (at your option) any later version.
>> > + *
>> > + * This program is distributed in the hope that it will be useful,
>> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> > + * GNU General Public License for more details.
>> > + *
>> > + * You should have received a copy of the GNU General Public License
>> > + * along with this program.  If not, see > >.
>> > + */
>> > +
>> > +#ifndef HW_MISC_ALLWINNER_SID_H
>> > +#define HW_MISC_ALLWINNER_SID_H
>> > +
>> > +#include "qom/object.h"
>> > +#include "hw/sysbus.h"
>> > +#include "qemu/uuid.h"
>> > +
>> > +/**
>> > + * Object model
>> > + * @{
>> > + */
>> > +
>> > +#define TYPE_AW_SID"allwinner-sid"
>> > +#define AW_SID(obj) \
>> > +OBJECT_CHECK(AwSidState, (obj), TYPE_AW_SID)
>> > +
>> > +/** @} */
>> > +
>> > +/**
>> > + * Allwinner Security ID object instance state
>> > + */
>> > +typedef struct AwSidState {
>> > +/*< private >*/
>> > +SysBusDevice parent_obj;
>> > +/*< public >*/
>> > +
>> > +/** Maps I/O registers in physical memory */
>> > +MemoryRegion iomem;
>> > +
>> > +/** Control register defines how and what to read */
>> > +uint32_t control;
>> > +
>> > +/** RdKey register contains the data retrieved by the device */
>> > +uint32_t rdkey;
>> > +
>> > +/** Stores the emulated device identifier */
>> > +QemuUUID identifier;
>> > +
>> > +} AwSidState;
>> > +
>> > +#endif /* HW_MISC_ALLWINNER_SID_H */
>> > diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
>> > index b9a5597f2a..deeea63f5f 100644
>> > --- a/hw/arm/allwinner-h3.c
>> > +++ b/hw/arm/allwinner-h3.c
>> > @@ -38,6 +38,7 @@ const hwaddr allwinner_h3_memmap[] = {
>> >  [AW_H3_SRAM_A2]= 0x00044000,
>> >  [AW_H3_SRAM_C] = 0x0001,
>> >  [AW_H3_SYSCTRL]= 0x01c0,
>> > +[AW_H3_SID]= 0x01c14000,
>> >  [AW_H3_EHCI0]  = 0x01c1a000,
>> >  [AW_H3_OHCI0]  = 0x01c1a400,
>> >  [AW_H3_EHCI1]  = 0x01c1b000,
>> > @@ -78,7 +79,6 @@ struct AwH3Unimplemented {
>> >  { "mmc0",  0x01c0f000, 4 * KiB },
>> >  { "mmc1",  0x01c1, 4 * KiB },
>> >  { "mmc2",  0x01c11000, 4 * KiB },
>> > -{ "sid",   0x01c14000, 1 * KiB },
>> >  { "crypto",0x01c15000, 4 * KiB },
>> >  { "msgbox",0x01c17000, 4 * KiB },
>> >  { "spinlock",  0x01c18000, 4 * KiB },
>> > @@ -198,6 +198,11 @@ static void allwinner_h3_init(Object *obj)

Re: [PATCH v7 18/18] docs: add Orange Pi PC document

2020-03-11 Thread Niek Linnenbank
On Wed, Mar 11, 2020 at 3:00 PM Alex Bennée  wrote:

>
> Niek Linnenbank  writes:
>
> > The Xunlong Orange Pi PC machine is a functional ARM machine
> > based on the Allwinner H3 System-on-Chip. It supports mainline
> > Linux, U-Boot, NetBSD and is covered by acceptance tests.
> >
> > This commit adds a documentation text file with a description
> > of the machine and instructions for the user.
>
> Awesome to have such comprehensive documentation for a system. Thanks
> ;-)
>

I'm glad to hear that Alex. Perhaps in another patch series we can begin to
add documentation for other boards as well.

Regards,
Niek


>
> Reviewed-by: Alex Bennée 
>
> --
> Alex Bennée
>


-- 
Niek Linnenbank


Re: [PATCH v4 10/11] 9pfs: T_readdir latency optimization

2020-03-11 Thread Christian Schoenebeck
On Mittwoch, 11. März 2020 17:14:08 CET Greg Kurz wrote:
> On Wed, 11 Mar 2020 02:18:04 +0100
> 
> Christian Schoenebeck  wrote:
> > On Dienstag, 10. März 2020 19:33:36 CET Greg Kurz wrote:
> > > > This patch is also too big for my preference, but I don't see a viable
> > > > way
> > > > to split it further into separate patches. I already separated all the
> > > > patches I could. If you have suggestions, very much appreciated!
> > > 
> > > Well, the patch could be split in two or three parts at least:
> > > 
> > > (1) introduce the new function that reads multiple entries in codir.c
> > > 
> > > (2) use it from 9p.c
> > > 
> > > (3) remove unused stuff if anything remains
> > > 
> > > This doesn't seem to change much but the smaller diffstats
> > > for each individual patch make them less scary :) and with
> > > (1) applied only it is easier to compare what the old code
> > > in 9p.c and the new one in codir.c do.
> > > 
> > > > The reason for this is that in order to fix these issues with current
> > > > T_readdir implementation, it requires to separate what's currently one
> > > > task
> > > > (i.e. one function) into two separate tasks (i.e. two functions).
> > > > There is
> > > > no sensible way to do that.
> > > 
> > > Yeah, I won't ask for finer grain.
> > 
> > Me confused. Does that mean your split suggestion was just theoretical, or
> > do you need it?
> 
> I need it and I won't ask for more splitting. Promised ! :)

Okay then. :)

> > > > Current code on master is much more tricky and error prone due to the
> > > > huge
> > > > amount of potential branches, individual error/cleanup handlers, high
> > > > amount of thread dispatching and much more. In the patched version all
> > > > these code complexities and error sources are removed.
> > > 
> > > Come on :) The 9pfs code has been a can of worms from the beginning.
> > > It produced more than the average amount of security-related bugs,
> > > and most sadly, due to the overall lack of interest, it bitrotted
> > > and missed a lot of cool improvements like an appropriate support of
> > > unlinked files, QOM-ification of fsdev, conversion of proxy fsdev to
> > > vhost-user, hot plug/unplug support, live migration support and
> > > "much more"... The performance aspect of things is a full time job
> > 
> > No, the performance issues are actually very managable in case of 9pfs.
> > I already addressed readdir with this patch (by far the worst performance
> 
> They're very manageable if someone cares and spends time. Thanks again
> for doing this.

Thanks!

> > My intention is not to squeeze out the last fractional percent of
> > performance for 9pfs, but you certainly agree that a simple "ls" blocking
> > for more than 1 second is something that should be fixed, and fortunately
> > the amount of
> I never observed such timeouts with my personal toy use of 9p but
> you did and this motivated you to step in, which is very welcome.

Probably you don't notice it much because of the dirent cache on guest side. 
If guest's dirent cache is cold, and you do a readdir() ("ls") on some 
directory with e.g. several hundred entries, you should notice it.

> > I think the cause of disagreements we have are solely our use cases of
> > 9pfs: your personal use case does not seem to require any performance
> > considerations or multi-user aspects, whereas my use case requires at
> > least some minimum performance grade for utilizing 9pfs for server
> > applications.
> 
> Your point about the personal use case is right indeed but our
> disagreements, if any, aren't uniquely related to that. It's more about
> maintainership and available time really. I'm 100% benevolent "Odd fixer"
> now and I just try to avoid being forced into fixing things after my PR is
> merged. If you want to go faster, then you're welcome to upgrade to
> maintainer and send PRs. This would make sense since you care for 9p, you
> showed a good understanding of the code and you provided beneficial
> contributions so far :)

That maintainership upgrade is planned. The question is just when. What was 
your idea, co-maintainership?

> > > > > Oh, so we'd still have the current implementation being used, even
> > > > > with this patch applied... This would be okay for a RFC patch but
> > > > > in the end I'd really like to merge something that also converts
> > > > > v9fs_do_readdir_with_stat().
> > > > 
> > > > Yes, I know, but I would not recommend mixing these things at this
> > > > point,
> > > > because it would be an entire effort on its own.
> > > > 
> > > > v9fs_do_readdir_with_stat() is used for 9P2000.u, while
> > > > v9fs_do_readdir()
> > > > is used for 9P2000.L. They're behaving very differently, so it would
> > > > not
> > > > only require me to update v9fs_do_readdir_with_stat() and v9fs_read(),
> > > > I
> > > > would also need to write their own test cases (plural, since there are
> > > > none at all yet) and benchmarks, and of course somebody what need to
> > > > review all that 

Re: [PATCH v7 10/18] hw/arm/allwinner-h3: add Boot ROM support

2020-03-11 Thread Niek Linnenbank
On Wed, Mar 11, 2020 at 2:58 PM Alex Bennée  wrote:

>
> Niek Linnenbank  writes:
>
> > A real Allwinner H3 SoC contains a Boot ROM which is the
> > first code that runs right after the SoC is powered on.
> > The Boot ROM is responsible for loading user code (e.g. a bootloader)
> > from any of the supported external devices and writing the downloaded
> > code to internal SRAM. After loading the SoC begins executing the code
> > written to SRAM.
> >
> > This commits adds emulation of the Boot ROM firmware setup functionality
> > by loading user code from SD card in the A1 SRAM. While the A1 SRAM is
> > 64KiB, we limit the size to 32KiB because the real H3 Boot ROM also
> rejects
> > sizes larger than 32KiB. For reference, this behaviour is documented
> > by the Linux Sunxi project wiki at:
> >
> >   https://linux-sunxi.org/BROM#U-Boot_SPL_limitations
> >
> > Signed-off-by: Niek Linnenbank 
> > ---
> >  include/hw/arm/allwinner-h3.h | 21 +
> >  hw/arm/allwinner-h3.c | 18 ++
> >  hw/arm/orangepi.c |  5 +
> >  3 files changed, 44 insertions(+)
> >
> > diff --git a/include/hw/arm/allwinner-h3.h
> b/include/hw/arm/allwinner-h3.h
> > index f9b9a02373..d338003724 100644
> > --- a/include/hw/arm/allwinner-h3.h
> > +++ b/include/hw/arm/allwinner-h3.h
> > @@ -46,6 +46,7 @@
> >  #include "hw/sd/allwinner-sdhost.h"
> >  #include "hw/net/allwinner-sun8i-emac.h"
> >  #include "target/arm/cpu.h"
> > +#include "sysemu/block-backend.h"
> >
> >  /**
> >   * Allwinner H3 device list
> > @@ -129,4 +130,24 @@ typedef struct AwH3State {
> >  MemoryRegion sram_c;
> >  } AwH3State;
> >
> > +/**
> > + * Emulate Boot ROM firmware setup functionality.
> > + *
> > + * A real Allwinner H3 SoC contains a Boot ROM
> > + * which is the first code that runs right after
> > + * the SoC is powered on. The Boot ROM is responsible
> > + * for loading user code (e.g. a bootloader) from any
> > + * of the supported external devices and writing the
> > + * downloaded code to internal SRAM. After loading the SoC
> > + * begins executing the code written to SRAM.
> > + *
> > + * This function emulates the Boot ROM by copying 32 KiB
> > + * of data from the given block device and writes it to
> > + * the start of the first internal SRAM memory.
> > + *
> > + * @s: Allwinner H3 state object pointer
> > + * @blk: Block backend device object pointer
> > + */
> > +void allwinner_h3_bootrom_setup(AwH3State *s, BlockBackend *blk);
> > +
> >  #endif /* HW_ARM_ALLWINNER_H3_H */
> > diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
> > index d1245d2b01..56b5c563a8 100644
> > --- a/hw/arm/allwinner-h3.c
> > +++ b/hw/arm/allwinner-h3.c
> > @@ -29,6 +29,7 @@
> >  #include "hw/char/serial.h"
> >  #include "hw/misc/unimp.h"
> >  #include "hw/usb/hcd-ehci.h"
> > +#include "hw/loader.h"
> >  #include "sysemu/sysemu.h"
> >  #include "hw/arm/allwinner-h3.h"
> >
> > @@ -170,6 +171,23 @@ enum {
> >  AW_H3_GIC_NUM_SPI   = 128
> >  };
> >
> > +void allwinner_h3_bootrom_setup(AwH3State *s, BlockBackend *blk)
> > +{
> > +const int64_t rom_size = 32 * KiB;
> > +uint8_t *buffer = g_new0(uint8_t, rom_size);
>
> There is an opportunity to use g_autofree here so you can skip..
>
> > +g_free(buffer);
> > +}
> > +
> 
>

Thanks Alex, I'll use g_autofree here.

Regards,
Niek


>
> Otherwise:
>
> Reviewed-by: Alex Bennée 
>
> --
> Alex Bennée
>


-- 
Niek Linnenbank


Re: [PATCH v3 00/10] ARM virt: Add NVDIMM support

2020-03-11 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20200311172014.33052-1-shameerali.kolothum.th...@huawei.com/



Hi,

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

=== TEST SCRIPT BEGIN ===
#! /bin/bash
export ARCH=x86_64
make docker-image-fedora V=1 NETWORK=1
time make docker-test-mingw@fedora J=14 NETWORK=1
=== TEST SCRIPT END ===

  CC  hw/timer/arm_timer.o
In file included from /tmp/qemu-test/src/include/qemu/osdep.h:51,
 from /tmp/qemu-test/src/hw/nvram/fw_cfg.c:25:
/tmp/qemu-test/src/include/qemu/compiler.h:81:35: error: invalid operands to 
binary - (have 'uint64_t *' {aka 'long long unsigned int *'} and 'size_t *' 
{aka 'unsigned int *'})
 #define type_check(t1,t2) ((t1*)0 - (t2*)0)
   ^
/tmp/qemu-test/src/include/migration/vmstate.h:254:6: note: in expansion of 
macro 'type_check'
---
/tmp/qemu-test/src/hw/nvram/fw_cfg.c:674:9: note: in expansion of macro 
'VMSTATE_UINT64'
 VMSTATE_UINT64(table_mr_size, FWCfgState),
 ^~
/tmp/qemu-test/src/include/qemu/compiler.h:81:35: error: invalid operands to 
binary - (have 'uint64_t *' {aka 'long long unsigned int *'} and 'size_t *' 
{aka 'unsigned int *'})
 #define type_check(t1,t2) ((t1*)0 - (t2*)0)
   ^
/tmp/qemu-test/src/include/migration/vmstate.h:254:6: note: in expansion of 
macro 'type_check'
---
/tmp/qemu-test/src/hw/nvram/fw_cfg.c:675:9: note: in expansion of macro 
'VMSTATE_UINT64'
 VMSTATE_UINT64(linker_mr_size, FWCfgState),
 ^~
/tmp/qemu-test/src/include/qemu/compiler.h:81:35: error: invalid operands to 
binary - (have 'uint64_t *' {aka 'long long unsigned int *'} and 'size_t *' 
{aka 'unsigned int *'})
 #define type_check(t1,t2) ((t1*)0 - (t2*)0)
   ^
/tmp/qemu-test/src/include/migration/vmstate.h:254:6: note: in expansion of 
macro 'type_check'
---
/tmp/qemu-test/src/hw/nvram/fw_cfg.c:676:9: note: in expansion of macro 
'VMSTATE_UINT64'
 VMSTATE_UINT64(rsdp_mr_size, FWCfgState),
 ^~
make: *** [/tmp/qemu-test/src/rules.mak:69: hw/nvram/fw_cfg.o] Error 1
make: *** Waiting for unfinished jobs
  CC  hw/timer/arm_mptimer.o
Traceback (most recent call last):
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', 
'--label', 'com.qemu.instance.uuid=25b77fea135a4b9993893172efb88f55', '-u', 
'1001', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', 
'-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 
'SHOW_ENV=', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', 
'/home/patchew/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', 
'/var/tmp/patchew-tester-tmp-ijsb_x7a/src/docker-src.2020-03-11-15.27.35.7372:/var/tmp/qemu:z,ro',
 'qemu:fedora', '/var/tmp/qemu/run', 'test-mingw']' returned non-zero exit 
status 2.
filter=--filter=label=com.qemu.instance.uuid=25b77fea135a4b9993893172efb88f55
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-ijsb_x7a/src'
make: *** [docker-run-test-mingw@fedora] Error 2

real5m14.744s
user0m8.333s


The full log is available at
http://patchew.org/logs/20200311172014.33052-1-shameerali.kolothum.th...@huawei.com/testing.docker-mingw@fedora/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

Re: [PATCH v3 00/10] ARM virt: Add NVDIMM support

2020-03-11 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20200311172014.33052-1-shameerali.kolothum.th...@huawei.com/



Hi,

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

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

PASS 1 fdc-test /x86_64/fdc/cmos
PASS 2 fdc-test /x86_64/fdc/no_media_on_start
PASS 3 fdc-test /x86_64/fdc/read_without_media
==6418==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 4 fdc-test /x86_64/fdc/media_change
PASS 5 fdc-test /x86_64/fdc/sense_interrupt
PASS 6 fdc-test /x86_64/fdc/relative_seek
---
PASS 33 test-opts-visitor /visitor/opts/dict/unvisited
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-coroutine -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="test-coroutine" 
PASS 11 fdc-test /x86_64/fdc/read_no_dma_18
==6473==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
==6473==WARNING: ASan is ignoring requested __asan_handle_no_return: stack top: 
0x7fff10aec000; bottom 0x7f8c9dbbb000; size: 0x007272f31000 (491554803712)
False positive error reports may follow
For details see https://github.com/google/sanitizers/issues/189
PASS 1 test-coroutine /basic/no-dangling-access
---
PASS 11 test-aio /aio/event/wait
PASS 12 test-aio /aio/event/flush
PASS 13 test-aio /aio/event/wait/no-flush-cb
==6488==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 ide-test /x86_64/ide/identify
==6502==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 2 ide-test /x86_64/ide/flush
==6508==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 3 ide-test /x86_64/ide/bmdma/simple_rw
==6494==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 14 test-aio /aio/timer/schedule
PASS 15 test-aio /aio/coroutine/queue-chaining
PASS 16 test-aio /aio-gsource/flush
---
PASS 25 test-aio /aio-gsource/event/wait
PASS 26 test-aio /aio-gsource/event/flush
PASS 27 test-aio /aio-gsource/event/wait/no-flush-cb
==6514==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 4 ide-test /x86_64/ide/bmdma/trim
==6520==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 28 test-aio /aio-gsource/timer/schedule
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-aio-multithread -m=quick -k --tap < /dev/null | 
./scripts/tap-driver.pl --test-name="test-aio-multithread" 
==6527==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 test-aio-multithread /aio/multi/lifecycle
PASS 2 test-aio-multithread /aio/multi/schedule
PASS 3 test-aio-multithread /aio/multi/mutex/contended
PASS 4 test-aio-multithread /aio/multi/mutex/handoff
==6550==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 5 test-aio-multithread /aio/multi/mutex/mcs
PASS 6 test-aio-multithread /aio/multi/mutex/pthread
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-throttle -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="test-throttle" 
---
PASS 6 test-throttle /throttle/detach_attach
PASS 7 test-throttle /throttle/config_functions
PASS 8 test-throttle /throttle/accounting
==6567==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 9 test-throttle /throttle/groups
PASS 10 test-throttle /throttle/config/enabled
PASS 11 test-throttle /throttle/config/conflicting
---
PASS 14 test-throttle /throttle/config/max
PASS 15 test-throttle /throttle/config/iops_size
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-thread-pool -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="test-thread-pool" 
==6571==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 test-thread-pool /thread-pool/submit
PASS 2 test-thread-pool /thread-pool/submit-aio
PASS 3 test-thread-pool /thread-pool/submit-co
PASS 4 test-thread-pool /thread-pool/submit-many
PASS 5 test-thread-pool /thread-pool/cancel
==6638==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 6 test-thread-pool 

Re: [PATCH v7 07/18] hw/arm/allwinner: add Security Identifier device

2020-03-11 Thread Niek Linnenbank
On Wed, Mar 11, 2020 at 2:53 PM Alex Bennée  wrote:

>
> Niek Linnenbank  writes:
>
> > The Security Identifier device found in various Allwinner System on Chip
> > designs gives applications a per-board unique identifier. This commit
> > adds support for the Allwinner Security Identifier using a 128-bit
> > UUID value as input.
> >
> > Signed-off-by: Niek Linnenbank 
> > ---
> >  include/hw/arm/allwinner-h3.h   |   3 +
> >  include/hw/misc/allwinner-sid.h |  60 
> >  hw/arm/allwinner-h3.c   |  11 ++-
> >  hw/arm/orangepi.c   |   9 ++
> >  hw/misc/allwinner-sid.c | 168 
> >  hw/misc/Makefile.objs   |   1 +
> >  hw/misc/trace-events|   4 +
> >  7 files changed, 255 insertions(+), 1 deletion(-)
> >  create mode 100644 include/hw/misc/allwinner-sid.h
> >  create mode 100644 hw/misc/allwinner-sid.c
> >
> > diff --git a/include/hw/arm/allwinner-h3.h
> b/include/hw/arm/allwinner-h3.h
> > index dc729176ab..85416d9d64 100644
> > --- a/include/hw/arm/allwinner-h3.h
> > +++ b/include/hw/arm/allwinner-h3.h
> > @@ -42,6 +42,7 @@
> >  #include "hw/misc/allwinner-h3-ccu.h"
> >  #include "hw/misc/allwinner-cpucfg.h"
> >  #include "hw/misc/allwinner-h3-sysctrl.h"
> > +#include "hw/misc/allwinner-sid.h"
> >  #include "target/arm/cpu.h"
> >
> >  /**
> > @@ -59,6 +60,7 @@ enum {
> >  AW_H3_SRAM_A2,
> >  AW_H3_SRAM_C,
> >  AW_H3_SYSCTRL,
> > +AW_H3_SID,
> >  AW_H3_EHCI0,
> >  AW_H3_OHCI0,
> >  AW_H3_EHCI1,
> > @@ -114,6 +116,7 @@ typedef struct AwH3State {
> >  AwH3ClockCtlState ccu;
> >  AwCpuCfgState cpucfg;
> >  AwH3SysCtrlState sysctrl;
> > +AwSidState sid;
> >  GICState gic;
> >  MemoryRegion sram_a1;
> >  MemoryRegion sram_a2;
> > diff --git a/include/hw/misc/allwinner-sid.h
> b/include/hw/misc/allwinner-sid.h
> > new file mode 100644
> > index 00..4c1fa4762b
> > --- /dev/null
> > +++ b/include/hw/misc/allwinner-sid.h
> > @@ -0,0 +1,60 @@
> > +/*
> > + * Allwinner Security ID emulation
> > + *
> > + * Copyright (C) 2019 Niek Linnenbank 
> > + *
> > + * This program is free software: you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License as published by
> > + * the Free Software Foundation, either version 2 of the License, or
> > + * (at your option) any later version.
> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU General Public License
> > + * along with this program.  If not, see  >.
> > + */
> > +
> > +#ifndef HW_MISC_ALLWINNER_SID_H
> > +#define HW_MISC_ALLWINNER_SID_H
> > +
> > +#include "qom/object.h"
> > +#include "hw/sysbus.h"
> > +#include "qemu/uuid.h"
> > +
> > +/**
> > + * Object model
> > + * @{
> > + */
> > +
> > +#define TYPE_AW_SID"allwinner-sid"
> > +#define AW_SID(obj) \
> > +OBJECT_CHECK(AwSidState, (obj), TYPE_AW_SID)
> > +
> > +/** @} */
> > +
> > +/**
> > + * Allwinner Security ID object instance state
> > + */
> > +typedef struct AwSidState {
> > +/*< private >*/
> > +SysBusDevice parent_obj;
> > +/*< public >*/
> > +
> > +/** Maps I/O registers in physical memory */
> > +MemoryRegion iomem;
> > +
> > +/** Control register defines how and what to read */
> > +uint32_t control;
> > +
> > +/** RdKey register contains the data retrieved by the device */
> > +uint32_t rdkey;
> > +
> > +/** Stores the emulated device identifier */
> > +QemuUUID identifier;
> > +
> > +} AwSidState;
> > +
> > +#endif /* HW_MISC_ALLWINNER_SID_H */
> > diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
> > index b9a5597f2a..deeea63f5f 100644
> > --- a/hw/arm/allwinner-h3.c
> > +++ b/hw/arm/allwinner-h3.c
> > @@ -38,6 +38,7 @@ const hwaddr allwinner_h3_memmap[] = {
> >  [AW_H3_SRAM_A2]= 0x00044000,
> >  [AW_H3_SRAM_C] = 0x0001,
> >  [AW_H3_SYSCTRL]= 0x01c0,
> > +[AW_H3_SID]= 0x01c14000,
> >  [AW_H3_EHCI0]  = 0x01c1a000,
> >  [AW_H3_OHCI0]  = 0x01c1a400,
> >  [AW_H3_EHCI1]  = 0x01c1b000,
> > @@ -78,7 +79,6 @@ struct AwH3Unimplemented {
> >  { "mmc0",  0x01c0f000, 4 * KiB },
> >  { "mmc1",  0x01c1, 4 * KiB },
> >  { "mmc2",  0x01c11000, 4 * KiB },
> > -{ "sid",   0x01c14000, 1 * KiB },
> >  { "crypto",0x01c15000, 4 * KiB },
> >  { "msgbox",0x01c17000, 4 * KiB },
> >  { "spinlock",  0x01c18000, 4 * KiB },
> > @@ -198,6 +198,11 @@ static void allwinner_h3_init(Object *obj)
> >
> >  sysbus_init_child_obj(obj, "cpucfg", >cpucfg, sizeof(s->cpucfg),
> >TYPE_AW_CPUCFG);
> > +
> > +sysbus_init_child_obj(obj, 

Re: [PATCH] acpi: Add Windows ACPI Emulated Device Table (WAET)

2020-03-11 Thread Liran Alon



On 11/03/2020 20:59, no-re...@patchew.org wrote:

Patchew URL: 
https://urldefense.com/v3/__https://patchew.org/QEMU/20200311170826.79419-1-liran.a...@oracle.com/__;!!GqivPVa7Brio!L4XXKjkDknE86ihbnytm45vsQI41J-QWVCZRoXEXtPKIAsMmknrGJWVPZpKgLyM$

Hi,

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

=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-centos7 V=1 NETWORK=1
time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1
=== TEST SCRIPT END ===

Using expected file 'tests/data/acpi/pc/HPET'
Looking for expected file 'tests/data/acpi/pc/WAET'
**
ERROR:/tmp/qemu-test/src/tests/qtest/bios-tables-test.c:367:load_expected_aml: 
assertion failed: (exp_sdt.aml_file)
ERROR - Bail out! 
ERROR:/tmp/qemu-test/src/tests/qtest/bios-tables-test.c:367:load_expected_aml: 
assertion failed: (exp_sdt.aml_file)


My bad. Didn't notice there are tests which verifies ACPI haven't 
changed and requires update for such patch.

Will submit a patch for this test in v2.

-Liran





Re: [PATCH] acpi: Add Windows ACPI Emulated Device Table (WAET)

2020-03-11 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20200311170826.79419-1-liran.a...@oracle.com/



Hi,

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

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

PASS 1 fdc-test /x86_64/fdc/cmos
PASS 2 fdc-test /x86_64/fdc/no_media_on_start
PASS 3 fdc-test /x86_64/fdc/read_without_media
==6296==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 check-qstring /public/from_str
PASS 2 check-qstring /public/get_str
PASS 3 check-qstring /public/append_chr
---
PASS 32 test-opts-visitor /visitor/opts/range/beyond
PASS 33 test-opts-visitor /visitor/opts/dict/unvisited
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-coroutine -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="test-coroutine" 
==6371==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
==6371==WARNING: ASan is ignoring requested __asan_handle_no_return: stack top: 
0x7ffe06631000; bottom 0x7fa3eaad3000; size: 0x005a1bb5e000 (387011960832)
False positive error reports may follow
For details see https://github.com/google/sanitizers/issues/189
PASS 11 fdc-test /x86_64/fdc/read_no_dma_18
---
PASS 13 fdc-test /x86_64/fdc/fuzz-registers
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
QTEST_QEMU_BINARY=x86_64-softmmu/qemu-system-x86_64 QTEST_QEMU_IMG=qemu-img 
tests/qtest/ide-test -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="ide-test" 
PASS 14 test-aio /aio/timer/schedule
==6386==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 15 test-aio /aio/coroutine/queue-chaining
PASS 16 test-aio /aio-gsource/flush
PASS 17 test-aio /aio-gsource/bh/schedule
---
PASS 25 test-aio /aio-gsource/event/wait
PASS 26 test-aio /aio-gsource/event/flush
PASS 27 test-aio /aio-gsource/event/wait/no-flush-cb
==6394==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 ide-test /x86_64/ide/identify
==6400==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 2 ide-test /x86_64/ide/flush
PASS 28 test-aio /aio-gsource/timer/schedule
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-aio-multithread -m=quick -k --tap < /dev/null | 
./scripts/tap-driver.pl --test-name="test-aio-multithread" 
==6406==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
==6409==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 1 test-aio-multithread /aio/multi/lifecycle
PASS 3 ide-test /x86_64/ide/bmdma/simple_rw
==6426==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 4 ide-test /x86_64/ide/bmdma/trim
PASS 2 test-aio-multithread /aio/multi/schedule
==6432==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 3 test-aio-multithread /aio/multi/mutex/contended
PASS 4 test-aio-multithread /aio/multi/mutex/handoff
PASS 5 test-aio-multithread /aio/multi/mutex/mcs
==6458==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 6 test-aio-multithread /aio/multi/mutex/pthread
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-throttle -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="test-throttle" 
PASS 1 test-throttle /throttle/leak_bucket
---
PASS 6 test-throttle /throttle/detach_attach
PASS 7 test-throttle /throttle/config_functions
PASS 8 test-throttle /throttle/accounting
==6465==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 9 test-throttle /throttle/groups
PASS 10 test-throttle /throttle/config/enabled
PASS 11 test-throttle /throttle/config/conflicting
---
MALLOC_PERTURB_=${MALLOC_PERTURB_:-$(( ${RANDOM:-0} % 255 + 1))}  
tests/test-thread-pool -m=quick -k --tap < /dev/null | ./scripts/tap-driver.pl 
--test-name="test-thread-pool" 
PASS 1 test-thread-pool /thread-pool/submit
PASS 2 test-thread-pool /thread-pool/submit-aio
==6469==WARNING: ASan doesn't fully support makecontext/swapcontext functions 
and may produce false positives in some cases!
PASS 3 test-thread-pool /thread-pool/submit-co
PASS 4 test-thread-pool /thread-pool/submit-many
PASS 5 test-thread-pool /thread-pool/cancel

Re: [PATCH] acpi: Add Windows ACPI Emulated Device Table (WAET)

2020-03-11 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20200311170826.79419-1-liran.a...@oracle.com/



Hi,

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

=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-centos7 V=1 NETWORK=1
time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1
=== TEST SCRIPT END ===

Using expected file 'tests/data/acpi/pc/HPET'
Looking for expected file 'tests/data/acpi/pc/WAET'
**
ERROR:/tmp/qemu-test/src/tests/qtest/bios-tables-test.c:367:load_expected_aml: 
assertion failed: (exp_sdt.aml_file)
ERROR - Bail out! 
ERROR:/tmp/qemu-test/src/tests/qtest/bios-tables-test.c:367:load_expected_aml: 
assertion failed: (exp_sdt.aml_file)
make: *** [check-qtest-x86_64] Error 1
make: *** Waiting for unfinished jobs
  TESTcheck-unit: tests/test-bufferiszero
qemu-system-aarch64: -accel kvm: invalid accelerator kvm
---
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['sudo', '-n', 'docker', 'run', 
'--label', 'com.qemu.instance.uuid=5598a4498742491c9be76e1225f60fe5', '-u', 
'1001', '--security-opt', 'seccomp=unconfined', '--rm', '-e', 'TARGET_LIST=', 
'-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=14', '-e', 'DEBUG=', '-e', 
'SHOW_ENV=1', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', 
'/home/patchew/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', 
'/var/tmp/patchew-tester-tmp-f5g9sd65/src/docker-src.2020-03-11-14.47.34.6055:/var/tmp/qemu:z,ro',
 'qemu:centos7', '/var/tmp/qemu/run', 'test-quick']' returned non-zero exit 
status 2.
filter=--filter=label=com.qemu.instance.uuid=5598a4498742491c9be76e1225f60fe5
make[1]: *** [docker-run] Error 1
make[1]: Leaving directory `/var/tmp/patchew-tester-tmp-f5g9sd65/src'
make: *** [docker-run-test-quick@centos7] Error 2

real11m45.203s
user0m8.706s


The full log is available at
http://patchew.org/logs/20200311170826.79419-1-liran.a...@oracle.com/testing.docker-quick@centos7/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

Re: [PATCH v2 0/2] buildsys: Fix building with SASL on Windows

2020-03-11 Thread Paolo Bonzini
On 09/03/20 13:24, Philippe Mathieu-Daudé wrote:
> Fix a bug reported by Youry few months ago:
> https://www.mail-archive.com/qemu-devel@nongnu.org/msg625606.html
> 
> Since v1:
> - addressed Daniel review (always define STRUCT_IOVEC_DEFINED)
> 
> The Fedora docker image already uses the libsasl since commit
> 8ea5962f286. Add the similar package to the Debian (host) image.
> 
> Philippe Mathieu-Daudé (2):
>   configure: Fix building with SASL on Windows
>   tests/docker: Install SASL library to extend code coverage on amd64
> 
>  configure| 4 +++-
>  tests/docker/dockerfiles/debian-amd64.docker | 1 +
>  2 files changed, 4 insertions(+), 1 deletion(-)
> 

Queued, thanks.

Paolo




Re: [PATCH] mem-prealloc: initialize cond and mutex(Internet mail)

2020-03-11 Thread Paolo Bonzini
On 10/03/20 08:06, bauerchen(陈蒙蒙) wrote:
> oh ,yes.Thanks
> I want to know if I submit a new fixed patch or just a patch fixed
> current problem?? 
> if a new fixed patch, maybe need a revert ?

Sorry I missed this message.  I have already sent a fixed patch, thanks!

Paolo

> 
> bauerchen(陈蒙蒙)
> 
>  
> *From:* Igor Mammedov 
> *Date:* 2020-03-09 21:19
> *To:* bauerchen(陈蒙蒙) 
> *CC:* borntraeger ; pbonzini
> ; qemu-devel
> ; qemu-s390x
> ; mhartmay 
> *Subject:* Re: [PATCH] mem-prealloc: initialize cond and
> mutex(Internet mail)
> On Mon, 9 Mar 2020 11:16:10 +
> bauerchen(陈蒙蒙)  wrote:
>  
> > Thanks,  in fact,do_touch_pages is called just when vm starts up,
> but using init flag and Gonce maybe more elegant !
> > if needed,I can submit a new patch !
> > thanks very much!
>  
> it's called from os_mem_prealloc() -> touch_all_pages() which is called
> at least once per an instance of hotsmem backend. So if several backends
> are used then it should be called several times.
> The same applies when a hostmem backend is added during runtime
> (hotplug)
>  
>  
> 




  1   2   3   4   5   >