[PATCH v2 1/1] hw/i386/amd_iommu: Fix IOMMU event log encoding errors

2022-04-21 Thread Wei Huang
Coverity issues several UNINIT warnings against amd_iommu.c [1]. This
patch fixes them by clearing evt before encoding. On top of it, this
patch changes the event log size to 16 bytes per IOMMU specification,
and fixes the event log entry format in amdvi_encode_event().

[1] CID 1487116/1487200/1487190/1487232/1487115/1487258

Reported-by: Peter Maydell 
Signed-off-by: Wei Huang 
---
 hw/i386/amd_iommu.c | 24 ++--
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index ea8eaeb330b6..725f69095b9e 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -201,15 +201,18 @@ static void amdvi_setevent_bits(uint64_t *buffer, 
uint64_t value, int start,
 /*
  * AMDVi event structure
  *0:15   -> DeviceID
- *55:63  -> event type + miscellaneous info
- *63:127 -> related address
+ *48:63  -> event type + miscellaneous info
+ *64:127 -> related address
  */
 static void amdvi_encode_event(uint64_t *evt, uint16_t devid, uint64_t addr,
uint16_t info)
 {
+evt[0] = 0;
+evt[1] = 0;
+
 amdvi_setevent_bits(evt, devid, 0, 16);
-amdvi_setevent_bits(evt, info, 55, 8);
-amdvi_setevent_bits(evt, addr, 63, 64);
+amdvi_setevent_bits(evt, info, 48, 16);
+amdvi_setevent_bits(evt, addr, 64, 64);
 }
 /* log an error encountered during a page walk
  *
@@ -218,7 +221,7 @@ static void amdvi_encode_event(uint64_t *evt, uint16_t 
devid, uint64_t addr,
 static void amdvi_page_fault(AMDVIState *s, uint16_t devid,
  hwaddr addr, uint16_t info)
 {
-uint64_t evt[4];
+uint64_t evt[2];
 
 info |= AMDVI_EVENT_IOPF_I | AMDVI_EVENT_IOPF;
 amdvi_encode_event(evt, devid, addr, info);
@@ -234,7 +237,7 @@ static void amdvi_page_fault(AMDVIState *s, uint16_t devid,
 static void amdvi_log_devtab_error(AMDVIState *s, uint16_t devid,
hwaddr devtab, uint16_t info)
 {
-uint64_t evt[4];
+uint64_t evt[2];
 
 info |= AMDVI_EVENT_DEV_TAB_HW_ERROR;
 
@@ -248,7 +251,8 @@ static void amdvi_log_devtab_error(AMDVIState *s, uint16_t 
devid,
  */
 static void amdvi_log_command_error(AMDVIState *s, hwaddr addr)
 {
-uint64_t evt[4], info = AMDVI_EVENT_COMMAND_HW_ERROR;
+uint64_t evt[2];
+uint16_t info = AMDVI_EVENT_COMMAND_HW_ERROR;
 
 amdvi_encode_event(evt, 0, addr, info);
 amdvi_log_event(s, evt);
@@ -261,7 +265,7 @@ static void amdvi_log_command_error(AMDVIState *s, hwaddr 
addr)
 static void amdvi_log_illegalcom_error(AMDVIState *s, uint16_t info,
hwaddr addr)
 {
-uint64_t evt[4];
+uint64_t evt[2];
 
 info |= AMDVI_EVENT_ILLEGAL_COMMAND_ERROR;
 amdvi_encode_event(evt, 0, addr, info);
@@ -276,7 +280,7 @@ static void amdvi_log_illegalcom_error(AMDVIState *s, 
uint16_t info,
 static void amdvi_log_illegaldevtab_error(AMDVIState *s, uint16_t devid,
   hwaddr addr, uint16_t info)
 {
-uint64_t evt[4];
+uint64_t evt[2];
 
 info |= AMDVI_EVENT_ILLEGAL_DEVTAB_ENTRY;
 amdvi_encode_event(evt, devid, addr, info);
@@ -288,7 +292,7 @@ static void amdvi_log_illegaldevtab_error(AMDVIState *s, 
uint16_t devid,
 static void amdvi_log_pagetab_error(AMDVIState *s, uint16_t devid,
 hwaddr addr, uint16_t info)
 {
-uint64_t evt[4];
+uint64_t evt[2];
 
 info |= AMDVI_EVENT_PAGE_TAB_HW_ERROR;
 amdvi_encode_event(evt, devid, addr, info);
-- 
2.35.1




[PATCH 1/1] hw/i386/amd_iommu: Fix IOMMU event log encoding errors

2022-04-21 Thread Wei Huang
Coverity issues several UNINIT warnings against AMD IOMMU device [1]. This
patch fixes them by initializing the variables. On top of it, this patch
changes the event log size to 16 bytes per IOMMU specification. Also the
event encoding function incorrectly defines the format of event log entry,
which is also fixed.

[1] CID 1487116/1487200/1487190/1487232/1487115/1487258

Reported-by: Peter Maydell 
Signed-off-by: Wei Huang 
---
 hw/i386/amd_iommu.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index ea8eaeb330b6..0f7f8929a687 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -208,8 +208,8 @@ static void amdvi_encode_event(uint64_t *evt, uint16_t 
devid, uint64_t addr,
uint16_t info)
 {
 amdvi_setevent_bits(evt, devid, 0, 16);
-amdvi_setevent_bits(evt, info, 55, 8);
-amdvi_setevent_bits(evt, addr, 63, 64);
+amdvi_setevent_bits(evt, info, 48, 16);
+amdvi_setevent_bits(evt, addr, 64, 64);
 }
 /* log an error encountered during a page walk
  *
@@ -218,7 +218,7 @@ static void amdvi_encode_event(uint64_t *evt, uint16_t 
devid, uint64_t addr,
 static void amdvi_page_fault(AMDVIState *s, uint16_t devid,
  hwaddr addr, uint16_t info)
 {
-uint64_t evt[4];
+uint64_t evt[2] = { 0 };
 
 info |= AMDVI_EVENT_IOPF_I | AMDVI_EVENT_IOPF;
 amdvi_encode_event(evt, devid, addr, info);
@@ -234,7 +234,7 @@ static void amdvi_page_fault(AMDVIState *s, uint16_t devid,
 static void amdvi_log_devtab_error(AMDVIState *s, uint16_t devid,
hwaddr devtab, uint16_t info)
 {
-uint64_t evt[4];
+uint64_t evt[2] = { 0 };
 
 info |= AMDVI_EVENT_DEV_TAB_HW_ERROR;
 
@@ -248,7 +248,8 @@ static void amdvi_log_devtab_error(AMDVIState *s, uint16_t 
devid,
  */
 static void amdvi_log_command_error(AMDVIState *s, hwaddr addr)
 {
-uint64_t evt[4], info = AMDVI_EVENT_COMMAND_HW_ERROR;
+uint64_t evt[2] = { 0 };
+uint16_t info = AMDVI_EVENT_COMMAND_HW_ERROR;
 
 amdvi_encode_event(evt, 0, addr, info);
 amdvi_log_event(s, evt);
@@ -261,7 +262,7 @@ static void amdvi_log_command_error(AMDVIState *s, hwaddr 
addr)
 static void amdvi_log_illegalcom_error(AMDVIState *s, uint16_t info,
hwaddr addr)
 {
-uint64_t evt[4];
+uint64_t evt[2] = { 0 };
 
 info |= AMDVI_EVENT_ILLEGAL_COMMAND_ERROR;
 amdvi_encode_event(evt, 0, addr, info);
@@ -276,7 +277,7 @@ static void amdvi_log_illegalcom_error(AMDVIState *s, 
uint16_t info,
 static void amdvi_log_illegaldevtab_error(AMDVIState *s, uint16_t devid,
   hwaddr addr, uint16_t info)
 {
-uint64_t evt[4];
+uint64_t evt[2] = { 0 };
 
 info |= AMDVI_EVENT_ILLEGAL_DEVTAB_ENTRY;
 amdvi_encode_event(evt, devid, addr, info);
@@ -288,7 +289,7 @@ static void amdvi_log_illegaldevtab_error(AMDVIState *s, 
uint16_t devid,
 static void amdvi_log_pagetab_error(AMDVIState *s, uint16_t devid,
 hwaddr addr, uint16_t info)
 {
-uint64_t evt[4];
+uint64_t evt[2] = { 0 };
 
 info |= AMDVI_EVENT_PAGE_TAB_HW_ERROR;
 amdvi_encode_event(evt, devid, addr, info);
-- 
2.35.1




Re: [PATCH 1/1] hw/i386/amd_iommu: Fix IOMMU event log encoding errors

2022-04-21 Thread Wei Huang




On 4/21/22 11:08, Peter Maydell wrote:

On Thu, 21 Apr 2022 at 17:01, Wei Huang  wrote:


Coverity issues several UNINIT warnings against AMD IOMMU device [1]. This
patch fixes them by initializing the variables. On top of it, this patch
changes the event log size to 16 bytes per IOMMU specification. Also the
event encoding function incorrectly defines the format of event log entry,
which is also fixed.

[1] CID 1487116/1487200/1487190/1487232/1487115/1487258

Reported-by: Peter Maydell 
Signed-off-by: Wei Huang 
---
  hw/i386/amd_iommu.c | 17 +
  1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index ea8eaeb330b6..0f7f8929a687 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -208,8 +208,8 @@ static void amdvi_encode_event(uint64_t *evt, uint16_t 
devid, uint64_t addr,
 uint16_t info)
  {
  amdvi_setevent_bits(evt, devid, 0, 16);
-amdvi_setevent_bits(evt, info, 55, 8);
-amdvi_setevent_bits(evt, addr, 63, 64);
+amdvi_setevent_bits(evt, info, 48, 16);
+amdvi_setevent_bits(evt, addr, 64, 64);


There's a comment just above this function which also needs updating.


Will do.



Would it be better to have this function start with
   evt[0] = 0;
   evt[1] = 0;

rather than requiring every caller to zero-initialize the buffer?


Assuming that Coverity is smart enough to poke one function further for 
checking UNINIT, I will fix it in the next spin. I will send another rev 
later today.




thanks
-- PMM




Re: who's maintaining amd_iommu.c these days?

2022-04-01 Thread Wei Huang




On 4/1/22 11:14, Peter Maydell wrote:

On Fri, 1 Apr 2022 at 17:11, Wei Huang  wrote:




On 3/31/22 21:09, Jason Wang wrote:

On Fri, Apr 1, 2022 at 2:30 AM Peter Xu  wrote:


On Thu, Mar 31, 2022 at 05:01:52PM +0100, Peter Maydell wrote:

(4) The claimed bit layout of the event structure doesn't
match up with the one in the spec document I found. This
could be because I found a document for some other bit
of hardware, of course.

Could you elaborate? Are you referring to amdvi_setevent_bits(evt, info,
55, 8)?


https://www.amd.com/system/files/TechDocs/48882_IOMMU.pdf
was the spec I found through random googling, but the event
structure layouts in chapter 2.5 of that document aren't
at all like the one that amdvi_encode_event() is using.
Maybe that's the wrong spec, as I say.


The spec is up-to-date. But it seems amdvi_setevent_bits(evt, info, 55, 
8) is problematic. Use amdvi_log_illegaldevtab_error() as an example:


info |= AMDVI_EVENT_ILLEGAL_DEVTAB_ENTRY;
amdvi_encode_event(evt, devid, addr, info);
amdvi_log_event(s, evt);

info is encoded with AMDVI_EVENT_ILLEGAL_DEVTAB_ENTRY (1U << 12) and is 
used by amdvi_encode_event() via amdvi_setevent_bits(evt, info, 55, 8) 
into event log bits[63:55]. This should instead be written into 
bits[63:48] to match ILLEGAL_DEV_TABLE_ENTRY event format in Chapter 2.5.2.




thanks
-- PMM




Re: who's maintaining amd_iommu.c these days?

2022-04-01 Thread Wei Huang




On 3/31/22 21:09, Jason Wang wrote:

On Fri, Apr 1, 2022 at 2:30 AM Peter Xu  wrote:


On Thu, Mar 31, 2022 at 05:01:52PM +0100, Peter Maydell wrote:

Coverity points out some problems with hw/i386/amd_iommu.c's event
logging code -- specifically, CID 1487115 1487116 1487190 1487200
1487232 1487258 are all the same basic problem, which is that various
functions declare a local "uint64_t evt[4]", populate only some
bits of it and then write it to guest memory, so we end up using
uninitialized host data and leaking it to the guest. I was going to
write a fix for this, but in looking at the code I noticed that
it has more extensive problems:

(1) these functions allocate an array of 4 64-bit values,
but we only copy 2 to the guest, because AMDVI_EVENT_LEN is 16.
Looking at the spec, I think that the length is right and it's
really 4 32-bit values (or 2 64-bit values, if you like).


Yes, amd event log entry size is 16 bytes. This should be easy to fixed.



(2) There are host-endianness bugs, because we assemble the
event as a set of host-endianness values but then write them
to guest memory as a bag-of-bytes with dma_memory_write()


I doubt people will enable AMD IOMMUs in QEMU on non-x86 host. 
Nevertheless this can be problematic and should be addressed.




(3) amdvi_encode_event() is throwing away most of its
"addr" argument, because it calls
   amdvi_setevent_bits(evt, addr, 63, 64) apparently intending
that to write 64 bits starting at 63 bits into the packet, but
the amdvi_setevent_bits() function only ever updates one
uint64_t in the array, so it will in fact write bit 63 and
nothing else.


Agreed



(4) The claimed bit layout of the event structure doesn't
match up with the one in the spec document I found. This
could be because I found a document for some other bit
of hardware, of course.
Could you elaborate? Are you referring to amdvi_setevent_bits(evt, info, 
55, 8)?




Anyway, adding all these up, the event logging probably
needs a bit of a restructuring, and that should ideally be
done by somebody who (a) knows the hardware we're emulating
here and (b) is in a position to test things. Any volunteers?


Copying some AMD developers (from where I saw the last patches from)...


Btw, the AMD IOMMU seems not to work for a while (just boot it with
virtio-blk and it still doesn't work).



This can be related to address space notifier problem I encountered. We 
will take care of these issues mentioned in this email thread.



Thanks



--
Peter Xu







Re: constant_tsc support for SVM guest

2021-04-24 Thread Wei Huang




On 4/23/21 4:27 PM, Eduardo Habkost wrote:

On Fri, Apr 23, 2021 at 12:32:00AM -0500, Wei Huang wrote:

There was a customer request for const_tsc support on AMD guests. Right now
this feature is turned off by default for QEMU x86 CPU types (in
CPUID_Fn8007_EDX[8]). However we are seeing a discrepancy in guest VM
behavior between Intel and AMD.

In Linux kernel, Intel x86 code enables X86_FEATURE_CONSTANT_TSC based on
vCPU's family & model. So it ignores CPUID_Fn8007_EDX[8] and guest VMs
have const_tsc enabled. On AMD, however, the kernel checks
CPUID_Fn8007_EDX[8]. So const_tsc is disabled on AMD by default.


Oh.  This seems to defeat the purpose of the invtsc migration
blocker we have.

Do we know when this behavior was introduced in Linux?


This code has existed in the kernel for a long time:

  commit 2b16a2353814a513cdb5c5c739b76a19d7ea39ce
  Author: Andi Kleen 
  Date:   Wed Jan 30 13:32:40 2008 +0100

 x86: move X86_FEATURE_CONSTANT_TSC into early cpu feature detection

There was another related commit which might explain the reasoning of 
turning on CONSTANT_TSC based on CPU family on Intel:


  commit 40fb17152c50a69dc304dd632131c2f41281ce44
  Author: Venki Pallipadi 
  Date:   Mon Nov 17 16:11:37 2008 -0800

 x86: support always running TSC on Intel CPUs

According to the commit above, there are two kernel features: 
CONSTANT_TSC and NONSTOP_TSC:


  * CONSTANT_TSC: TSC runs at constant rate
  * NONSTOP_TSC: TSC not stop in deep C-states

If CPUID_Fn8007_EDX[8] == 1, both CONSTANT_TSC and NONSTOP_TSC are 
turned on. This applies to all x86 vendors. For Intel CPU with certain 
CPU families (i.e. c->x86 == 0x6 && c->x86_model >= 0x0e), it will turn 
on CONSTANT_TSC (but no NONSTOP_TSC) with CPUID_Fn8007_EDX[8]=0.


I believe the migration blocker was created for the CONSTANT_TSC case: 
if vCPU claims to have a constant TSC rate, we have to make sure 
src/dest are matched with each other (having the same CPU frequency or 
have tsc_ratio). NONSTOP_TSC doesn't matter in this scope.






I am thinking turning on invtsc for EPYC CPU types (see example below). Most
AMD server CPUs have supported invariant TSC for a long time. So this change
is compatible with the hardware behavior. The only problem is live migration
support, which will be blocked because of invtsc. However this problem
should be considered very minor because most server CPUs support TscRateMsr
(see CPUID_Fn800A_EDX[4]), allowing VMs to migrate among CPUs with
different TSC rates. This live migration restriction can be lifted as long
as the destination supports TscRateMsr or has the same frequency as the
source (QEMU/libvirt do it).

[BTW I believe this migration limitation might be unnecessary because it is
apparently OK for Intel guests to ignore invtsc while claiming const_tsc.
Have anyone reported issues?]


CCing Marcelo, who originally added the migration blocker in QEMU.



Do I miss anything here? Any comments about the proposal?

Thanks,
-Wei

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index ad99cad0e7..3c48266884 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -4077,6 +4076,21 @@ static X86CPUDefinition builtin_x86_defs[] = {
  { /* end of list */ }
  }
  },
+{
+.version = 4,
+.alias = "EPYC-IBPB",
+.props = (PropValue[]) {
+{ "ibpb", "on" },
+{ "perfctr-core", "on" },
+{ "clzero", "on" },
+{ "xsaveerptr", "on" },
+{ "xsaves", "on" },


You don't need to copy the properties from the previous version.
The properties of version N are applied on top of the properties
of version (N-1).


Will fix




+{ "invtsc", "on" },
+{ "model-id",
+  "AMD EPYC Processor" },
+{ /* end of list */ }
+}
+},
  { /* end of list */ }
  }
  },
@@ -4189,6 +4203,15 @@ static X86CPUDefinition builtin_x86_defs[] = {
  { /* end of list */ }
  }
  },
+{
+.version = 3,
+.props = (PropValue[]) {
+{ "ibrs", "on" },
+{ "amd-ssbd", "on" },
+{ "invtsc", "on" },
+{ /* end of list */ }
+}
+},
  { /* end of list */ }
  }
  },
@@ -4246,6 +4269,17 @@ static X86CPUDefinition builtin_x86_defs[] = {
  .xlevel = 0x801E,
  .model_id = "AMD EPYC-Milan Processor",
  .cache_info = _milan_cache_info,

constant_tsc support for SVM guest

2021-04-22 Thread Wei Huang
There was a customer request for const_tsc support on AMD guests. Right 
now this feature is turned off by default for QEMU x86 CPU types (in 
CPUID_Fn8007_EDX[8]). However we are seeing a discrepancy in guest 
VM behavior between Intel and AMD.


In Linux kernel, Intel x86 code enables X86_FEATURE_CONSTANT_TSC based 
on vCPU's family & model. So it ignores CPUID_Fn8007_EDX[8] and 
guest VMs have const_tsc enabled. On AMD, however, the kernel checks 
CPUID_Fn8007_EDX[8]. So const_tsc is disabled on AMD by default.


I am thinking turning on invtsc for EPYC CPU types (see example below). 
Most AMD server CPUs have supported invariant TSC for a long time. So 
this change is compatible with the hardware behavior. The only problem 
is live migration support, which will be blocked because of invtsc. 
However this problem should be considered very minor because most server 
CPUs support TscRateMsr (see CPUID_Fn800A_EDX[4]), allowing VMs to 
migrate among CPUs with different TSC rates. This live migration 
restriction can be lifted as long as the destination supports TscRateMsr 
or has the same frequency as the source (QEMU/libvirt do it).


[BTW I believe this migration limitation might be unnecessary because it 
is apparently OK for Intel guests to ignore invtsc while claiming 
const_tsc. Have anyone reported issues?]


Do I miss anything here? Any comments about the proposal?

Thanks,
-Wei

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index ad99cad0e7..3c48266884 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -4077,6 +4076,21 @@ static X86CPUDefinition builtin_x86_defs[] = {
 { /* end of list */ }
 }
 },
+{
+.version = 4,
+.alias = "EPYC-IBPB",
+.props = (PropValue[]) {
+{ "ibpb", "on" },
+{ "perfctr-core", "on" },
+{ "clzero", "on" },
+{ "xsaveerptr", "on" },
+{ "xsaves", "on" },
+{ "invtsc", "on" },
+{ "model-id",
+  "AMD EPYC Processor" },
+{ /* end of list */ }
+}
+},
 { /* end of list */ }
 }
 },
@@ -4189,6 +4203,15 @@ static X86CPUDefinition builtin_x86_defs[] = {
 { /* end of list */ }
 }
 },
+{
+.version = 3,
+.props = (PropValue[]) {
+{ "ibrs", "on" },
+{ "amd-ssbd", "on" },
+{ "invtsc", "on" },
+{ /* end of list */ }
+}
+},
 { /* end of list */ }
 }
 },
@@ -4246,6 +4269,17 @@ static X86CPUDefinition builtin_x86_defs[] = {
 .xlevel = 0x801E,
 .model_id = "AMD EPYC-Milan Processor",
 .cache_info = _milan_cache_info,
+.versions = (X86CPUVersionDefinition[]) {
+{ .version = 1 },
+{
+.version = 2,
+.props = (PropValue[]) {
+{ "invtsc", "on" },
+{ /* end of list */ }
+}
+},
+{ /* end of list */ }
+}



[PATCH 1/1] x86/cpu: Populate SVM CPUID feature bits

2021-01-26 Thread Wei Huang
Newer AMD CPUs will add CPUID_0x800A_EDX[28] bit, which indicates
that SVM instructions (VMRUN/VMSAVE/VMLOAD) will trigger #VMEXIT before
CPU checking their EAX against reserved memory regions. This change will
allow the hypervisor to avoid intercepting #GP and emulating SVM
instructions. KVM turns on this CPUID bit for nested VMs. In order to
support it, let us populate this bit, along with other SVM feature bits,
in FEAT_SVM.

Signed-off-by: Wei Huang 
---
 target/i386/cpu.c |  6 +++---
 target/i386/cpu.h | 24 ++--
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 72a79e6019b5..85e529157659 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -926,11 +926,11 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = 
{
 "npt", "lbrv", "svm-lock", "nrip-save",
 "tsc-scale", "vmcb-clean",  "flushbyasid", "decodeassists",
 NULL, NULL, "pause-filter", NULL,
-"pfthreshold", NULL, NULL, NULL,
-NULL, NULL, NULL, NULL,
-NULL, NULL, NULL, NULL,
+"pfthreshold", "avic", NULL, "v-vmsave-vmload",
+"vgif", NULL, NULL, NULL,
 NULL, NULL, NULL, NULL,
 NULL, NULL, NULL, NULL,
+"svme-addr-chk", NULL, NULL, NULL,
 },
 .cpuid = { .eax = 0x800A, .reg = R_EDX, },
 .tcg_features = TCG_SVM_FEATURES,
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index d23a5b340a8d..b39ec505de96 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -670,16 +670,20 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS];
 #define CPUID_EXT3_PERFCORE (1U << 23)
 #define CPUID_EXT3_PERFNB  (1U << 24)
 
-#define CPUID_SVM_NPT  (1U << 0)
-#define CPUID_SVM_LBRV (1U << 1)
-#define CPUID_SVM_SVMLOCK  (1U << 2)
-#define CPUID_SVM_NRIPSAVE (1U << 3)
-#define CPUID_SVM_TSCSCALE (1U << 4)
-#define CPUID_SVM_VMCBCLEAN(1U << 5)
-#define CPUID_SVM_FLUSHASID(1U << 6)
-#define CPUID_SVM_DECODEASSIST (1U << 7)
-#define CPUID_SVM_PAUSEFILTER  (1U << 10)
-#define CPUID_SVM_PFTHRESHOLD  (1U << 12)
+#define CPUID_SVM_NPT (1U << 0)
+#define CPUID_SVM_LBRV(1U << 1)
+#define CPUID_SVM_SVMLOCK (1U << 2)
+#define CPUID_SVM_NRIPSAVE(1U << 3)
+#define CPUID_SVM_TSCSCALE(1U << 4)
+#define CPUID_SVM_VMCBCLEAN   (1U << 5)
+#define CPUID_SVM_FLUSHASID   (1U << 6)
+#define CPUID_SVM_DECODEASSIST(1U << 7)
+#define CPUID_SVM_PAUSEFILTER (1U << 10)
+#define CPUID_SVM_PFTHRESHOLD (1U << 12)
+#define CPUID_SVM_AVIC(1U << 13)
+#define CPUID_SVM_V_VMSAVE_VMLOAD (1U << 15)
+#define CPUID_SVM_VGIF(1U << 16)
+#define CPUID_SVM_SVME_ADDR_CHK   (1U << 28)
 
 /* Support RDFSBASE/RDGSBASE/WRFSBASE/WRGSBASE */
 #define CPUID_7_0_EBX_FSGSBASE  (1U << 0)
-- 
2.29.2




[PATCH V2 2/3] amd-iommu: Sync IOVA-to-GPA translation during page invalidation

2020-10-02 Thread Wei Huang
Add support to sync the IOVA-to-GPA translation at the time of IOMMU
page invalidation. This function is called when two IOMMU commands,
AMDVI_CMD_INVAL_AMDVI_PAGES and AMDVI_CMD_INVAL_AMDVI_ALL, are
intercepted. Address space notifiers are called accordingly.

Co-developed-by: Wei Huang 
Signed-off-by: Suravee Suthikulpanit 
---
 hw/i386/amd_iommu.c | 177 
 hw/i386/amd_iommu.h |  10 +++
 2 files changed, 187 insertions(+)

diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index c7d24a05484d..7ce68289d20c 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -76,6 +76,12 @@ typedef struct AMDVIIOTLBEntry {
 uint64_t page_mask; /* physical page size  */
 } AMDVIIOTLBEntry;
 
+static bool amdvi_get_dte(AMDVIState *s, int devid, uint64_t *entry);
+static void amdvi_sync_domain(AMDVIState *s, uint32_t domid,
+  uint64_t addr, uint16_t flags);
+static void amdvi_walk_level(AMDVIAddressSpace *as, uint64_t pte,
+ uint64_t iova, uint64_t partial);
+
 /* configure MMIO registers at startup/reset */
 static void amdvi_set_quad(AMDVIState *s, hwaddr addr, uint64_t val,
uint64_t romask, uint64_t w1cmask)
@@ -443,6 +449,78 @@ static void amdvi_address_space_unmap(AMDVIAddressSpace 
*as, IOMMUNotifier *n)
 memory_region_notify_one(n, );
 }
 
+/*
+ * Sync the IOVA-to-GPA translation at the time of IOMMU page invalidation.
+ * This function is called when IOMMU commands, AMDVI_CMD_INVAL_AMDVI_PAGES
+ * and AMDVI_CMD_INVAL_AMDVI_ALL, are triggred.
+ *
+ * The range of addr invalidation is determined by addr and flags, using
+ * the following rules:
+ *   - All pages
+ * In this case, we unmap the whole address space and then re-walk the
+ * I/O page table to sync the mapping relationship.
+ *   - Single page
+ * Re-walk the page based on the specified iova, and only sync the
+ * newly mapped page.
+ */
+static void amdvi_sync_domain(AMDVIState *s, uint32_t domid,
+  uint64_t addr, uint16_t flags)
+{
+AMDVIAddressSpace *as;
+bool sync_all_domains = false;
+uint64_t mask, size = 0x1000;
+
+if (domid == AMDVI_DOMAIN_ALL) {
+sync_all_domains = true;
+}
+
+ /* S=1 means the invalidation size is from addr field; otherwise 4KB */
+if (flags & AMDVI_CMD_INVAL_IOMMU_PAGES_S_BIT) {
+uint32_t zbit = cto64(addr | 0xFFF) + 1;
+
+size = 1ULL << zbit;
+
+if (size < 0x1000) {
+addr = 0;
+size = AMDVI_PGSZ_ENTIRE;
+} else {
+mask = ~(size - 1);
+addr &= mask;
+}
+}
+
+QLIST_FOREACH(as, >amdvi_as_with_notifiers, next) {
+uint64_t dte[4];
+IOMMUNotifier *n;
+
+if (!amdvi_get_dte(s, as->devfn, dte)) {
+continue;
+}
+
+if (!sync_all_domains && (domid != (dte[1] & 0xFFFULL))) {
+continue;
+}
+
+/*
+ * In case of syncing more than a page, we invalidate the entire
+ * address range and re-walk the whole page table.
+ */
+if (size == AMDVI_PGSZ_ENTIRE) {
+IOMMU_NOTIFIER_FOREACH(n, >iommu) {
+amdvi_address_space_unmap(as, n);
+}
+} else if (size > 0x1000) {
+IOMMU_NOTIFIER_FOREACH(n, >iommu) {
+if (n->start <= addr && addr + size < n->end) {
+amdvi_address_space_unmap(as, n);
+}
+}
+}
+
+amdvi_walk_level(as, dte[0], addr, 0);
+}
+}
+
 static gboolean amdvi_iotlb_remove_by_domid(gpointer key, gpointer value,
 gpointer user_data)
 {
@@ -455,6 +533,8 @@ static gboolean amdvi_iotlb_remove_by_domid(gpointer key, 
gpointer value,
 static void amdvi_inval_pages(AMDVIState *s, uint64_t *cmd)
 {
 uint16_t domid = cpu_to_le16((uint16_t)extract64(cmd[0], 32, 16));
+uint64_t addr  = cpu_to_le64(extract64(cmd[1], 12, 52)) << 12;
+uint16_t flags = cpu_to_le16((uint16_t)extract64(cmd[1], 0, 12));
 
 if (extract64(cmd[0], 20, 12) || extract64(cmd[0], 48, 12) ||
 extract64(cmd[1], 3, 9)) {
@@ -465,6 +545,8 @@ static void amdvi_inval_pages(AMDVIState *s, uint64_t *cmd)
 g_hash_table_foreach_remove(s->iotlb, amdvi_iotlb_remove_by_domid,
 );
 trace_amdvi_pages_inval(domid);
+
+amdvi_sync_domain(s, domid, addr, flags);
 }
 
 static void amdvi_prefetch_pages(AMDVIState *s, uint64_t *cmd)
@@ -910,6 +992,101 @@ static inline uint64_t amdvi_get_pte_entry(AMDVIState *s, 
uint64_t pte_addr,
 return pte;
 }
 
+static inline uint64_t pte_get_page_size(uint64_t level)
+{
+return 1UL << ((level * 9) + 3);
+}
+
+static void amdvi_sync_iova(AMDVIAddressSpace *as, uint64_t pte, uint64_t iova)
+{
+IOMMUT

[PATCH V2 1/3] amd-iommu: Add address space notifier and replay support

2020-10-02 Thread Wei Huang
Currently the emulated amd-iommu device does not support memory address
space notifier and replay. These two functions are required to have I/O
devices supported inside guest VMs as passthru devices. This patch adds
basic as_notifier infrastructure and replay function in amd_iommu.

Co-developed-by: Wei Huang 
Signed-off-by: Suravee Suthikulpanit 
---
 hw/i386/amd_iommu.c | 45 +++--
 hw/i386/amd_iommu.h |  3 +++
 2 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index 74a93a5d93f4..c7d24a05484d 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -63,6 +63,8 @@ struct AMDVIAddressSpace {
 IOMMUMemoryRegion iommu;/* Device's address translation region  */
 MemoryRegion iommu_ir;  /* Device's interrupt remapping region  */
 AddressSpace as;/* device's corresponding address space */
+IOMMUNotifierFlag notifier_flags; /* notifier flags of address space */
+QLIST_ENTRY(AMDVIAddressSpace) next; /* notifier linked list */
 };
 
 /* AMDVI cache entry */
@@ -425,6 +427,22 @@ static void amdvi_inval_all(AMDVIState *s, uint64_t *cmd)
 trace_amdvi_all_inval();
 }
 
+static void amdvi_address_space_unmap(AMDVIAddressSpace *as, IOMMUNotifier *n)
+{
+IOMMUTLBEntry entry;
+hwaddr start = n->start;
+hwaddr end = n->end;
+hwaddr size = end - start + 1;
+
+entry.target_as = _space_memory;
+entry.iova = start;
+entry.translated_addr = 0;
+entry.perm = IOMMU_NONE;
+entry.addr_mask = size - 1;
+
+memory_region_notify_one(n, );
+}
+
 static gboolean amdvi_iotlb_remove_by_domid(gpointer key, gpointer value,
 gpointer user_data)
 {
@@ -1473,14 +1491,17 @@ static int 
amdvi_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu,
Error **errp)
 {
 AMDVIAddressSpace *as = container_of(iommu, AMDVIAddressSpace, iommu);
+AMDVIState *s = as->iommu_state;
 
-if (new & IOMMU_NOTIFIER_MAP) {
-error_setg(errp,
-   "device %02x.%02x.%x requires iommu notifier which is not "
-   "currently supported", as->bus_num, PCI_SLOT(as->devfn),
-   PCI_FUNC(as->devfn));
-return -EINVAL;
+/* Update address space notifier flags */
+as->notifier_flags = new;
+
+if (old == IOMMU_NOTIFIER_NONE) {
+QLIST_INSERT_HEAD(>amdvi_as_with_notifiers, as, next);
+} else if (new == IOMMU_NOTIFIER_NONE) {
+QLIST_REMOVE(as, next);
 }
+
 return 0;
 }
 
@@ -1573,6 +1594,8 @@ static void amdvi_realize(DeviceState *dev, Error **errp)
 /* Pseudo address space under root PCI bus. */
 x86ms->ioapic_as = amdvi_host_dma_iommu(bus, s, AMDVI_IOAPIC_SB_DEVID);
 
+QLIST_INIT(>amdvi_as_with_notifiers);
+
 /* set up MMIO */
 memory_region_init_io(>mmio, OBJECT(s), _mem_ops, s, "amdvi-mmio",
   AMDVI_MMIO_SIZE);
@@ -1631,12 +1654,22 @@ static const TypeInfo amdviPCI = {
 },
 };
 
+static void amdvi_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier *n)
+{
+AMDVIAddressSpace *as = container_of(iommu_mr, AMDVIAddressSpace, iommu);
+
+amdvi_address_space_unmap(as, n);
+
+return;
+}
+
 static void amdvi_iommu_memory_region_class_init(ObjectClass *klass, void 
*data)
 {
 IOMMUMemoryRegionClass *imrc = IOMMU_MEMORY_REGION_CLASS(klass);
 
 imrc->translate = amdvi_translate;
 imrc->notify_flag_changed = amdvi_iommu_notify_flag_changed;
+imrc->replay = amdvi_iommu_replay;
 }
 
 static const TypeInfo amdvi_iommu_memory_region_info = {
diff --git a/hw/i386/amd_iommu.h b/hw/i386/amd_iommu.h
index 79d38a3e4184..29b7a35a51a5 100644
--- a/hw/i386/amd_iommu.h
+++ b/hw/i386/amd_iommu.h
@@ -362,6 +362,9 @@ struct AMDVIState {
 /* for each served device */
 AMDVIAddressSpace **address_spaces[PCI_BUS_MAX];
 
+/* list of registered notifiers */
+QLIST_HEAD(, AMDVIAddressSpace) amdvi_as_with_notifiers;
+
 /* IOTLB */
 GHashTable *iotlb;
 
-- 
2.25.2




[PATCH V2 0/3] Passthru device support under emulated amd-iommu

2020-10-02 Thread Wei Huang
This patchset adds support for passthru devices to run inside VMs under
the management of an emulated amd-iommu device (vIOMMU). This feature
has a variety of benefits, including enhanced I/O security and user-mode
driver support, for guest VMs.

This patchset has been tested with various 1G and 10G (SR-IOV) NICs on
AMD boxes.

V1->V2:
 * Remove unnecessary VFIO_IOMMU_MAP_DMA errno check (Alex Williamson)

Thanks,
-Wei

Wei Huang (3):
  amd-iommu: Add address space notifier and replay support
  amd-iommu: Sync IOVA-to-GPA translation during page invalidation
  amd-iommu: Fix amdvi_mmio_trace() to differentiate MMIO R/W

 hw/i386/amd_iommu.c | 243 ++--
 hw/i386/amd_iommu.h |  13 +++
 2 files changed, 245 insertions(+), 11 deletions(-)

-- 
2.25.2




[PATCH V2 3/3] amd-iommu: Fix amdvi_mmio_trace() to differentiate MMIO R/W

2020-10-02 Thread Wei Huang
amd-iommu MMIO trace function does not differentiate MMIO writes from
reads. Let us extend it to support both types.

Co-developed-by: Wei Huang 
Signed-off-by: Suravee Suthikulpanit 
---
 hw/i386/amd_iommu.c | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index 7ce68289d20c..914368f0e4b7 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -662,17 +662,28 @@ static void amdvi_cmdbuf_run(AMDVIState *s)
 }
 }
 
-static void amdvi_mmio_trace(hwaddr addr, unsigned size)
+static void amdvi_mmio_trace(hwaddr addr, unsigned size, bool iswrite,
+ uint64_t val)
 {
 uint8_t index = (addr & ~0x2000) / 8;
 
 if ((addr & 0x2000)) {
 /* high table */
 index = index >= AMDVI_MMIO_REGS_HIGH ? AMDVI_MMIO_REGS_HIGH : index;
-trace_amdvi_mmio_read(amdvi_mmio_high[index], addr, size, addr & 
~0x07);
+if (!iswrite)
+trace_amdvi_mmio_read(amdvi_mmio_high[index], addr, size,
+  addr & ~0x07);
+else
+trace_amdvi_mmio_write(amdvi_mmio_high[index], addr, size, val,
+   addr & ~0x07);
 } else {
 index = index >= AMDVI_MMIO_REGS_LOW ? AMDVI_MMIO_REGS_LOW : index;
-trace_amdvi_mmio_read(amdvi_mmio_low[index], addr, size, addr & ~0x07);
+if (!iswrite)
+trace_amdvi_mmio_read(amdvi_mmio_low[index], addr, size,
+  addr & ~0x07);
+else
+trace_amdvi_mmio_write(amdvi_mmio_low[index], addr, size, val,
+   addr & ~0x07);
 }
 }
 
@@ -693,7 +704,7 @@ static uint64_t amdvi_mmio_read(void *opaque, hwaddr addr, 
unsigned size)
 } else if (size == 8) {
 val = amdvi_readq(s, addr);
 }
-amdvi_mmio_trace(addr, size);
+amdvi_mmio_trace(addr, size, 0, val);
 
 return val;
 }
@@ -840,7 +851,7 @@ static void amdvi_mmio_write(void *opaque, hwaddr addr, 
uint64_t val,
 return;
 }
 
-amdvi_mmio_trace(addr, size);
+amdvi_mmio_trace(addr, size, 1, val);
 switch (addr & ~0x07) {
 case AMDVI_MMIO_CONTROL:
 amdvi_mmio_reg_write(s, size, val, addr);
-- 
2.25.2




Re: [PATCH V1 2/3] amd-iommu: Sync IOVA-to-GPA translation during page invalidation

2020-09-30 Thread Wei Huang
On 09/29 01:34, Alex Williamson wrote:
> On Mon, 28 Sep 2020 15:05:05 -0500
> Wei Huang  wrote:
> 
> > Add support to sync the IOVA-to-GPA translation at the time of IOMMU
> > page invalidation. This function is called when two IOMMU commands,
> > AMDVI_CMD_INVAL_AMDVI_PAGES and AMDVI_CMD_INVAL_AMDVI_ALL, are
> > intercepted. Address space notifiers are called accordingly.
> > 
> > Co-developed-by: Wei Huang 
> > Signed-off-by: Suravee Suthikulpanit 
> > ---
> >  hw/i386/amd_iommu.c | 177 
> >  hw/i386/amd_iommu.h |  10 +++
> >  hw/vfio/common.c|   3 +-
> >  3 files changed, 189 insertions(+), 1 deletion(-)
> ...
> > diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> > index 13471ae29436..243216499ce0 100644
> > --- a/hw/vfio/common.c
> > +++ b/hw/vfio/common.c
> > @@ -346,7 +346,8 @@ static int vfio_dma_map(VFIOContainer *container, 
> > hwaddr iova,
> >   * the VGA ROM space.
> >   */
> >  if (ioctl(container->fd, VFIO_IOMMU_MAP_DMA, ) == 0 ||
> > -(errno == EBUSY && vfio_dma_unmap(container, iova, size) == 0 &&
> > +((errno == EEXIST || errno == EBUSY) &&
> > + vfio_dma_unmap(container, iova, size) == 0 &&
> >   ioctl(container->fd, VFIO_IOMMU_MAP_DMA, ) == 0)) {
> >  return 0;
> >  }
> 
> 
> This seems like it should be a separate patch.  AFAICT the commit log
> doesn't even hint at why this change is necessary.  I think the -EBUSY
> error pre-dates vIOMMU as well.  Responding the same for an -EEXIST
> almost suggests a coherency issue between QEMU and the kernel, or a
> direct mapping replacement without an invalidation, which doesn't seem
> to be what this patch is implementing.  Thanks,

I went back to check it. Removing this checking code (original code) didn't
trigger any issues with Intel 10G passthru NIC. I think this was from the
residual debugging code when we started to implement it. Sorry for the
confusion. I will remove this code in V2 with more tests.

-Wei

> 
> Alex
> 



[PATCH V1 0/3] Passthru device support under emulated amd-iommu

2020-09-28 Thread Wei Huang
This patchset adds support for passthru devices to run inside VMs under
the management of an emulated amd-iommu device (vIOMMU). This feature
has a variety of benefits, including enhanced I/O security and user-mode
driver support, for guest VMs.

This patchset has been tested with both 1G and 10G NICs on AMD boxes.

Thanks,
-Wei

Wei Huang (3):
  amd-iommu: Add address space notifier and replay support
  amd-iommu: Sync IOVA-to-GPA translation during page invalidation
  amd-iommu: Fix up amdvi_mmio_trace() to differentiate MMIO R/W

 hw/i386/amd_iommu.c | 243 ++--
 hw/i386/amd_iommu.h |  13 +++
 hw/vfio/common.c|   3 +-
 3 files changed, 247 insertions(+), 12 deletions(-)

-- 
2.25.2




[PATCH V1 3/3] amd-iommu: Fix amdvi_mmio_trace() to differentiate MMIO R/W

2020-09-28 Thread Wei Huang
amd-iommu MMIO trace function does not differentiate MMIO writes from
reads. Let us extend it to support both types.

Co-developed-by: Wei Huang 
Signed-off-by: Suravee Suthikulpanit 
---
 hw/i386/amd_iommu.c | 21 -
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index 7604e2080595..827818b9f781 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -662,17 +662,28 @@ static void amdvi_cmdbuf_run(AMDVIState *s)
 }
 }
 
-static void amdvi_mmio_trace(hwaddr addr, unsigned size)
+static void amdvi_mmio_trace(hwaddr addr, unsigned size, bool iswrite,
+ uint64_t val)
 {
 uint8_t index = (addr & ~0x2000) / 8;
 
 if ((addr & 0x2000)) {
 /* high table */
 index = index >= AMDVI_MMIO_REGS_HIGH ? AMDVI_MMIO_REGS_HIGH : index;
-trace_amdvi_mmio_read(amdvi_mmio_high[index], addr, size, addr & 
~0x07);
+if (!iswrite)
+trace_amdvi_mmio_read(amdvi_mmio_high[index], addr, size,
+  addr & ~0x07);
+else
+trace_amdvi_mmio_write(amdvi_mmio_high[index], addr, size, val,
+   addr & ~0x07);
 } else {
 index = index >= AMDVI_MMIO_REGS_LOW ? AMDVI_MMIO_REGS_LOW : index;
-trace_amdvi_mmio_read(amdvi_mmio_low[index], addr, size, addr & ~0x07);
+if (!iswrite)
+trace_amdvi_mmio_read(amdvi_mmio_low[index], addr, size,
+  addr & ~0x07);
+else
+trace_amdvi_mmio_write(amdvi_mmio_low[index], addr, size, val,
+   addr & ~0x07);
 }
 }
 
@@ -693,7 +704,7 @@ static uint64_t amdvi_mmio_read(void *opaque, hwaddr addr, 
unsigned size)
 } else if (size == 8) {
 val = amdvi_readq(s, addr);
 }
-amdvi_mmio_trace(addr, size);
+amdvi_mmio_trace(addr, size, 0, val);
 
 return val;
 }
@@ -840,7 +851,7 @@ static void amdvi_mmio_write(void *opaque, hwaddr addr, 
uint64_t val,
 return;
 }
 
-amdvi_mmio_trace(addr, size);
+amdvi_mmio_trace(addr, size, 1, val);
 switch (addr & ~0x07) {
 case AMDVI_MMIO_CONTROL:
 amdvi_mmio_reg_write(s, size, val, addr);
-- 
2.25.2




[PATCH V1 1/3] amd-iommu: Add address space notifier and replay support

2020-09-28 Thread Wei Huang
Currently the emulated amd-iommu device does not support memory address
space notifier and replay. These two functions are required to have I/O
devices supported inside guest VMs as passthru devices. This patch adds
basic as_notifier infrastructure and replay function in amd_iommu.

Co-developed-by: Wei Huang 
Signed-off-by: Suravee Suthikulpanit 
---
 hw/i386/amd_iommu.c | 45 +++--
 hw/i386/amd_iommu.h |  3 +++
 2 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index 74a93a5d93f4..c7d24a05484d 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -63,6 +63,8 @@ struct AMDVIAddressSpace {
 IOMMUMemoryRegion iommu;/* Device's address translation region  */
 MemoryRegion iommu_ir;  /* Device's interrupt remapping region  */
 AddressSpace as;/* device's corresponding address space */
+IOMMUNotifierFlag notifier_flags; /* notifier flags of address space */
+QLIST_ENTRY(AMDVIAddressSpace) next; /* notifier linked list */
 };
 
 /* AMDVI cache entry */
@@ -425,6 +427,22 @@ static void amdvi_inval_all(AMDVIState *s, uint64_t *cmd)
 trace_amdvi_all_inval();
 }
 
+static void amdvi_address_space_unmap(AMDVIAddressSpace *as, IOMMUNotifier *n)
+{
+IOMMUTLBEntry entry;
+hwaddr start = n->start;
+hwaddr end = n->end;
+hwaddr size = end - start + 1;
+
+entry.target_as = _space_memory;
+entry.iova = start;
+entry.translated_addr = 0;
+entry.perm = IOMMU_NONE;
+entry.addr_mask = size - 1;
+
+memory_region_notify_one(n, );
+}
+
 static gboolean amdvi_iotlb_remove_by_domid(gpointer key, gpointer value,
 gpointer user_data)
 {
@@ -1473,14 +1491,17 @@ static int 
amdvi_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu,
Error **errp)
 {
 AMDVIAddressSpace *as = container_of(iommu, AMDVIAddressSpace, iommu);
+AMDVIState *s = as->iommu_state;
 
-if (new & IOMMU_NOTIFIER_MAP) {
-error_setg(errp,
-   "device %02x.%02x.%x requires iommu notifier which is not "
-   "currently supported", as->bus_num, PCI_SLOT(as->devfn),
-   PCI_FUNC(as->devfn));
-return -EINVAL;
+/* Update address space notifier flags */
+as->notifier_flags = new;
+
+if (old == IOMMU_NOTIFIER_NONE) {
+QLIST_INSERT_HEAD(>amdvi_as_with_notifiers, as, next);
+} else if (new == IOMMU_NOTIFIER_NONE) {
+QLIST_REMOVE(as, next);
 }
+
 return 0;
 }
 
@@ -1573,6 +1594,8 @@ static void amdvi_realize(DeviceState *dev, Error **errp)
 /* Pseudo address space under root PCI bus. */
 x86ms->ioapic_as = amdvi_host_dma_iommu(bus, s, AMDVI_IOAPIC_SB_DEVID);
 
+QLIST_INIT(>amdvi_as_with_notifiers);
+
 /* set up MMIO */
 memory_region_init_io(>mmio, OBJECT(s), _mem_ops, s, "amdvi-mmio",
   AMDVI_MMIO_SIZE);
@@ -1631,12 +1654,22 @@ static const TypeInfo amdviPCI = {
 },
 };
 
+static void amdvi_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier *n)
+{
+AMDVIAddressSpace *as = container_of(iommu_mr, AMDVIAddressSpace, iommu);
+
+amdvi_address_space_unmap(as, n);
+
+return;
+}
+
 static void amdvi_iommu_memory_region_class_init(ObjectClass *klass, void 
*data)
 {
 IOMMUMemoryRegionClass *imrc = IOMMU_MEMORY_REGION_CLASS(klass);
 
 imrc->translate = amdvi_translate;
 imrc->notify_flag_changed = amdvi_iommu_notify_flag_changed;
+imrc->replay = amdvi_iommu_replay;
 }
 
 static const TypeInfo amdvi_iommu_memory_region_info = {
diff --git a/hw/i386/amd_iommu.h b/hw/i386/amd_iommu.h
index fa5feb183c03..aeed9fd1cbb0 100644
--- a/hw/i386/amd_iommu.h
+++ b/hw/i386/amd_iommu.h
@@ -364,6 +364,9 @@ struct AMDVIState {
 /* for each served device */
 AMDVIAddressSpace **address_spaces[PCI_BUS_MAX];
 
+/* list of registered notifiers */
+QLIST_HEAD(, AMDVIAddressSpace) amdvi_as_with_notifiers;
+
 /* IOTLB */
 GHashTable *iotlb;
 
-- 
2.25.2




[PATCH V1 2/3] amd-iommu: Sync IOVA-to-GPA translation during page invalidation

2020-09-28 Thread Wei Huang
Add support to sync the IOVA-to-GPA translation at the time of IOMMU
page invalidation. This function is called when two IOMMU commands,
AMDVI_CMD_INVAL_AMDVI_PAGES and AMDVI_CMD_INVAL_AMDVI_ALL, are
intercepted. Address space notifiers are called accordingly.

Co-developed-by: Wei Huang 
Signed-off-by: Suravee Suthikulpanit 
---
 hw/i386/amd_iommu.c | 177 
 hw/i386/amd_iommu.h |  10 +++
 hw/vfio/common.c|   3 +-
 3 files changed, 189 insertions(+), 1 deletion(-)

diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index c7d24a05484d..7604e2080595 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -76,6 +76,12 @@ typedef struct AMDVIIOTLBEntry {
 uint64_t page_mask; /* physical page size  */
 } AMDVIIOTLBEntry;
 
+static bool amdvi_get_dte(AMDVIState *s, int devid, uint64_t *entry);
+static void amdvi_sync_domain(AMDVIState *s, uint32_t domid,
+  uint64_t addr, uint16_t flags);
+static void amdvi_walk_level(AMDVIAddressSpace *as, uint64_t pte,
+ uint64_t iova, uint64_t partial);
+
 /* configure MMIO registers at startup/reset */
 static void amdvi_set_quad(AMDVIState *s, hwaddr addr, uint64_t val,
uint64_t romask, uint64_t w1cmask)
@@ -443,6 +449,78 @@ static void amdvi_address_space_unmap(AMDVIAddressSpace 
*as, IOMMUNotifier *n)
 memory_region_notify_one(n, );
 }
 
+/*
+ * Sync the IOVA-to-GPA translation at the time of IOMMU page invalidation.
+ * This function is called when IOMMU commands, AMDVI_CMD_INVAL_AMDVI_PAGES
+ * and AMDVI_CMD_INVAL_AMDVI_ALL, are triggred.
+ *
+ * The range of addr invalidation is determined by addr and flags, using
+ * the following rules:
+ *   - All pages
+ * In this case, we unmap the whole address space and then re-walk the
+ * I/O page table to sync the mapping relationship.
+ *   - Single page:
+ * Re-walk the page based on the specified iova, and only sync the
+ * newly mapped page.
+ */
+static void amdvi_sync_domain(AMDVIState *s, uint32_t domid,
+  uint64_t addr, uint16_t flags)
+{
+AMDVIAddressSpace *as;
+bool sync_all_domains = false;
+uint64_t mask, size = 0x1000;
+
+if (domid == AMDVI_DOMAIN_ALL) {
+sync_all_domains = true;
+}
+
+ /* S=1 means the invalidation size is from addr field; otherwise 4KB */
+if (flags & AMDVI_CMD_INVAL_IOMMU_PAGES_S_BIT) {
+uint32_t zbit = cto64(addr | 0xFFF) + 1;
+
+size = 1ULL << zbit;
+
+if (size < 0x1000) {
+addr = 0;
+size = AMDVI_PGSZ_ENTIRE;
+} else {
+mask = ~(size - 1);
+addr &= mask;
+}
+}
+
+QLIST_FOREACH(as, >amdvi_as_with_notifiers, next) {
+uint64_t dte[4];
+IOMMUNotifier *n;
+
+if (!amdvi_get_dte(s, as->devfn, dte)) {
+continue;
+}
+
+if (!sync_all_domains && (domid != (dte[1] & 0xFFFULL))) {
+continue;
+}
+
+/*
+ * In case of syncing more than a page, we invalidate the entire
+ * address range and re-walk the whole page table.
+ */
+if (size == AMDVI_PGSZ_ENTIRE) {
+IOMMU_NOTIFIER_FOREACH(n, >iommu) {
+amdvi_address_space_unmap(as, n);
+}
+} else if (size > 0x1000) {
+IOMMU_NOTIFIER_FOREACH(n, >iommu) {
+if (n->start <= addr && addr + size < n->end) {
+amdvi_address_space_unmap(as, n);
+}
+}
+}
+
+amdvi_walk_level(as, dte[0], addr, 0);
+}
+}
+
 static gboolean amdvi_iotlb_remove_by_domid(gpointer key, gpointer value,
 gpointer user_data)
 {
@@ -455,6 +533,8 @@ static gboolean amdvi_iotlb_remove_by_domid(gpointer key, 
gpointer value,
 static void amdvi_inval_pages(AMDVIState *s, uint64_t *cmd)
 {
 uint16_t domid = cpu_to_le16((uint16_t)extract64(cmd[0], 32, 16));
+uint64_t addr  = cpu_to_le64(extract64(cmd[1], 12, 52)) << 12;
+uint16_t flags = cpu_to_le16((uint16_t)extract64(cmd[1], 0, 12));
 
 if (extract64(cmd[0], 20, 12) || extract64(cmd[0], 48, 12) ||
 extract64(cmd[1], 3, 9)) {
@@ -465,6 +545,8 @@ static void amdvi_inval_pages(AMDVIState *s, uint64_t *cmd)
 g_hash_table_foreach_remove(s->iotlb, amdvi_iotlb_remove_by_domid,
 );
 trace_amdvi_pages_inval(domid);
+
+amdvi_sync_domain(s, domid, addr, flags);
 }
 
 static void amdvi_prefetch_pages(AMDVIState *s, uint64_t *cmd)
@@ -910,6 +992,101 @@ static inline uint64_t amdvi_get_pte_entry(AMDVIState *s, 
uint64_t pte_addr,
 return pte;
 }
 
+static inline uint64_t pte_get_page_size(uint64_t level)
+{
+return 1UL << ((level * 9) + 3);
+}
+
+static void amdvi_sync_iova(AMDVIAddressSpace *a

[PATCH] hw/i386/amd_iommu: Fix the reserved bits definition of IOMMU commands

2020-04-17 Thread Wei Huang
Many reserved bits of amd_iommu commands are defined incorrectly in QEMU.
Because of it, QEMU incorrectly injects lots of illegal commands into guest
VM's IOMMU event log.

Signed-off-by: Wei Huang 
---
 hw/i386/amd_iommu.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index fd75cae02437..4346060e6223 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -370,7 +370,7 @@ static void amdvi_completion_wait(AMDVIState *s, uint64_t 
*cmd)
 hwaddr addr = cpu_to_le64(extract64(cmd[0], 3, 49)) << 3;
 uint64_t data = cpu_to_le64(cmd[1]);
 
-if (extract64(cmd[0], 51, 8)) {
+if (extract64(cmd[0], 52, 8)) {
 amdvi_log_illegalcom_error(s, extract64(cmd[0], 60, 4),
s->cmdbuf + s->cmdbuf_head);
 }
@@ -395,7 +395,7 @@ static void amdvi_inval_devtab_entry(AMDVIState *s, 
uint64_t *cmd)
 uint16_t devid = cpu_to_le16((uint16_t)extract64(cmd[0], 0, 16));
 
 /* This command should invalidate internal caches of which there isn't */
-if (extract64(cmd[0], 15, 16) || cmd[1]) {
+if (extract64(cmd[0], 16, 44) || cmd[1]) {
 amdvi_log_illegalcom_error(s, extract64(cmd[0], 60, 4),
s->cmdbuf + s->cmdbuf_head);
 }
@@ -405,9 +405,9 @@ static void amdvi_inval_devtab_entry(AMDVIState *s, 
uint64_t *cmd)
 
 static void amdvi_complete_ppr(AMDVIState *s, uint64_t *cmd)
 {
-if (extract64(cmd[0], 15, 16) ||  extract64(cmd[0], 19, 8) ||
+if (extract64(cmd[0], 16, 16) ||  extract64(cmd[0], 52, 8) ||
 extract64(cmd[1], 0, 2) || extract64(cmd[1], 3, 29)
-|| extract64(cmd[1], 47, 16)) {
+|| extract64(cmd[1], 48, 16)) {
 amdvi_log_illegalcom_error(s, extract64(cmd[0], 60, 4),
s->cmdbuf + s->cmdbuf_head);
 }
@@ -438,8 +438,8 @@ static void amdvi_inval_pages(AMDVIState *s, uint64_t *cmd)
 {
 uint16_t domid = cpu_to_le16((uint16_t)extract64(cmd[0], 32, 16));
 
-if (extract64(cmd[0], 20, 12) || extract64(cmd[0], 16, 12) ||
-extract64(cmd[0], 3, 10)) {
+if (extract64(cmd[0], 20, 12) || extract64(cmd[0], 48, 12) ||
+extract64(cmd[1], 3, 9)) {
 amdvi_log_illegalcom_error(s, extract64(cmd[0], 60, 4),
s->cmdbuf + s->cmdbuf_head);
 }
@@ -451,7 +451,7 @@ static void amdvi_inval_pages(AMDVIState *s, uint64_t *cmd)
 
 static void amdvi_prefetch_pages(AMDVIState *s, uint64_t *cmd)
 {
-if (extract64(cmd[0], 16, 8) || extract64(cmd[0], 20, 8) ||
+if (extract64(cmd[0], 16, 8) || extract64(cmd[0], 52, 8) ||
 extract64(cmd[1], 1, 1) || extract64(cmd[1], 3, 1) ||
 extract64(cmd[1], 5, 7)) {
 amdvi_log_illegalcom_error(s, extract64(cmd[0], 60, 4),
@@ -463,7 +463,7 @@ static void amdvi_prefetch_pages(AMDVIState *s, uint64_t 
*cmd)
 
 static void amdvi_inval_inttable(AMDVIState *s, uint64_t *cmd)
 {
-if (extract64(cmd[0], 16, 16) || cmd[1]) {
+if (extract64(cmd[0], 16, 44) || cmd[1]) {
 amdvi_log_illegalcom_error(s, extract64(cmd[0], 60, 4),
s->cmdbuf + s->cmdbuf_head);
 return;
@@ -479,7 +479,8 @@ static void iommu_inval_iotlb(AMDVIState *s, uint64_t *cmd)
 {
 
 uint16_t devid = extract64(cmd[0], 0, 16);
-if (extract64(cmd[1], 1, 1) || extract64(cmd[1], 3, 9)) {
+if (extract64(cmd[1], 1, 1) || extract64(cmd[1], 3, 1) ||
+extract64(cmd[1], 6, 6)) {
 amdvi_log_illegalcom_error(s, extract64(cmd[0], 60, 4),
s->cmdbuf + s->cmdbuf_head);
 return;
-- 
2.24.1




Re: [Qemu-devel] [PULL 2/7] tests/migration: Enable the migration test on s390x, too

2018-10-18 Thread Wei Huang



On 10/18/2018 07:43 AM, Emilio G. Cota wrote:
> On Thu, Oct 18, 2018 at 14:38:01 +0200, Thomas Huth wrote:
>> On 2018-10-17 21:28, Emilio G. Cota wrote:
>>> Can anyone reproduce this? Otherwise, let me know what other info
>>> I could provide.
>>
>> I've finally been able to reproduce it - seems like it only happens here
>> when the host is under heavy load.

Given that it only happens under heavy load, could the failure be caused
by migration thresholds defined in migrate_postcopy_prepare()? You can
play with "max-bandwidth", "downtime-limit" and others to see if it helps.

>>
>> ... not sure whether I've got time to debug this before KVM forum, so if
>> it bugs you, feel free to send a patch to disable the test in
>> tests/Makefile.include for s390x again.
> 
> Glad you could reproduce! I'll disable the test locally for now.
> 
> Thanks,
> 
>   Emilio
> 



Re: [Qemu-devel] [PATCH 1/1] tests: Add migration test for aarch64

2018-10-04 Thread Wei Huang



On 10/04/2018 09:17 AM, Thomas Huth wrote:
> On 2018-10-04 15:48, Andrew Jones wrote:
>> On Fri, Sep 28, 2018 at 03:47:35PM -0400, Wei Huang wrote:
> [...]
>>> diff --git a/tests/migration/aarch64/Makefile 
>>> b/tests/migration/aarch64/Makefile
>>> new file mode 100644
>>> index 000..d440fa8
>>> --- /dev/null
>>> +++ b/tests/migration/aarch64/Makefile
>>> @@ -0,0 +1,20 @@
>>> +# To specify cross compiler prefix, use CROSS_PREFIX=
>>> +#   $ make CROSS_PREFIX=aarch64-linux-gnu-
>>> +
>>> +.PHONY: all clean
>>> +all: a-b-kernel.h
>>> +
>>> +a-b-kernel.h: aarch64.kernel
>>> +   echo "$$__note" > header.tmp
>>> +   xxd -i $< | sed -e 's/.*int.*//' >> header.tmp
>>> +   mv header.tmp $@
>>> +
>>> +aarch64.kernel: aarch64.elf
>>> +   $(CROSS_PREFIX)objcopy -O binary $< $@
>>> +
>>> +aarch64.elf: a-b-kernel.S
>>> +   $(CROSS_PREFIX)gcc -o $@ -nostdlib -Wl,--build-id=none $<
>>> +
>>> +clean:
>>> +   @rm -rf *.kernel *.elf
>>
>> I don't think we need/want '-f'. Why not use $(RM)?
> 
> Does $(RM) work now in the QEMU Makefiles? AFAIK we are disabling the
> standard variables in rules.mak ("MAKEFLAGS += -rR"), but never set RM
> again...

This Makefile isn't part of QEMU regular build process (as Juan pointed
it out before: most people won't run/care it unless they want to change
the aarch64 migration test case themselves). So rules.mak isn't
included. As a result, $(RM) is still available.

I just sent in a V2 version to address Philippe's comments, in which I
fix @rm anyway.

PS: No cover letter to show V1->V2 difference as it is a very
straightforward.



> 
>  Thomas
> 



[Qemu-devel] [PATCH V2 1/1] tests: Add migration test for aarch64

2018-10-04 Thread Wei Huang
This patch adds migration test support for aarch64. The test code, which
implements the same functionality as x86, is booted as a kernel in qemu.
Here are the design choices we make for aarch64:

 * We choose this -kernel approach because aarch64 QEMU doesn't provide a
   built-in fw like x86 does. So instead of relying on a boot loader, we
   use -kernel approach for aarch64.
 * The serial output is sent to PL011 directly.
 * The physical memory base for mach-virt machine is 0x4000. We change
   the start_address and end_address for aarch64.

In addition to providing the binary, this patch also includes the source
code and the build script in tests/migration/aarch64. So users can change
the source and/or re-compile the binary as they wish.

Reviewed-by: Juan Quintela 
Reviewed-by: Andrew Jones 
Signed-off-by: Wei Huang 
---
 tests/Makefile.include   |  1 +
 tests/migration-test.c   | 27 +++--
 tests/migration/Makefile |  2 +-
 tests/migration/aarch64/Makefile | 19 +
 tests/migration/aarch64/a-b-kernel.S | 75 
 tests/migration/aarch64/a-b-kernel.h | 19 +
 tests/migration/migration-test.h |  9 +
 7 files changed, 147 insertions(+), 5 deletions(-)
 create mode 100644 tests/migration/aarch64/Makefile
 create mode 100644 tests/migration/aarch64/a-b-kernel.S
 create mode 100644 tests/migration/aarch64/a-b-kernel.h

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 175d013..857e7cc 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -402,6 +402,7 @@ check-qtest-arm-y += tests/hexloader-test$(EXESUF)
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
 check-qtest-aarch64-$(CONFIG_SDHCI) += tests/sdhci-test$(EXESUF)
 check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
+check-qtest-aarch64-y += tests/migration-test$(EXESUF)
 
 check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
 
diff --git a/tests/migration-test.c b/tests/migration-test.c
index 20f38f1..5bdc0bd 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -86,12 +86,13 @@ static const char *tmpfs;
  * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
  */
 #include "tests/migration/i386/a-b-bootblock.h"
+#include "tests/migration/aarch64/a-b-kernel.h"
 
-static void init_bootfile_x86(const char *bootpath)
+static void init_bootfile(const char *bootpath, void *content)
 {
 FILE *bootfile = fopen(bootpath, "wb");
 
-g_assert_cmpint(fwrite(x86_bootsect, 512, 1, bootfile), ==, 1);
+g_assert_cmpint(fwrite(content, 512, 1, bootfile), ==, 1);
 fclose(bootfile);
 }
 
@@ -428,7 +429,7 @@ static int test_migrate_start(QTestState **from, QTestState 
**to,
 got_stop = false;
 
 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-init_bootfile_x86(bootpath);
+init_bootfile(bootpath, x86_bootsect);
 cmd_src = g_strdup_printf("-machine accel=%s -m 150M"
   " -name source,debug-threads=on"
   " -serial file:%s/src_serial"
@@ -459,6 +460,24 @@ static int test_migrate_start(QTestState **from, 
QTestState **to,
 
 start_address = PPC_TEST_MEM_START;
 end_address = PPC_TEST_MEM_END;
+} else if (strcmp(arch, "aarch64") == 0) {
+init_bootfile(bootpath, aarch64_kernel);
+cmd_src = g_strdup_printf("-machine virt,accel=%s,gic-version=max "
+  "-name vmsource,debug-threads=on -cpu max "
+  "-m 150M -serial file:%s/src_serial "
+  "-kernel %s ",
+  accel, tmpfs, bootpath);
+cmd_dst = g_strdup_printf("-machine virt,accel=%s,gic-version=max "
+  "-name vmdest,debug-threads=on -cpu max "
+  "-m 150M -serial file:%s/dest_serial "
+  "-kernel %s "
+  "-incoming %s ",
+  accel, tmpfs, bootpath, uri);
+
+start_address = ARM_TEST_MEM_START;
+end_address = ARM_TEST_MEM_END;
+
+g_assert(sizeof(aarch64_kernel) <= ARM_TEST_MAX_KERNEL_SIZE);
 } else {
 g_assert_not_reached();
 }
@@ -545,7 +564,7 @@ static void test_deprecated(void)
 {
 QTestState *from;
 
-from = qtest_start("");
+from = qtest_start("-machine none");
 
 deprecated_set_downtime(from, 0.12345);
 deprecated_set_speed(from, 12345);
diff --git a/tests/migration/Makefile b/tests/migration/Makefile
index dc3b551..91237a8 100644
--- a/tests/migration/Makefile
+++ b/tests/migration/Makefile
@@ -5,7 +5,7 @@
 # See the COPYING file in the 

Re: [Qemu-devel] [PATCH 1/1] tests: Add migration test for aarch64

2018-10-04 Thread Wei Huang



On 10/04/2018 10:30 AM, Philippe Mathieu-Daudé wrote:
> On 04/10/2018 17:27, Wei Huang wrote:
>> On 10/04/2018 10:07 AM, Philippe Mathieu-Daudé wrote:
>>> On 28/09/2018 21:47, Wei Huang wrote:
>>> [...]> +++ b/tests/migration/aarch64/Makefile
>>>> @@ -0,0 +1,20 @@
>>>> +# To specify cross compiler prefix, use CROSS_PREFIX=
>>>> +#   $ make CROSS_PREFIX=aarch64-linux-gnu-
>>>> +
>>>> +.PHONY: all clean
>>>> +all: a-b-kernel.h
>>>> +
>>>> +a-b-kernel.h: aarch64.kernel
>>>> +  echo "$$__note" > header.tmp
>>>
>>> This won't work on a read-only fs.
>>
>> Under which setting? If tmp file can't be generated on a read-only fs,
>> wouldn't $@ have the same problem?
> 
> Yes you are right :)
> 
>>>
>>> Why don't you use $@ directly?
> 
> What about this?

Yes, I can address it with the following, along with $(RM) as Drew
pointed it out.

a-b-kernel.h: aarch64.kernel
   echo "$$__note" > $@
   xxd -i $< | sed -e 's/.*int.*//' >> $@


> 
>>>
>>>> +  xxd -i $< | sed -e 's/.*int.*//' >> header.tmp
>>>
>>> Please use:
>>>
>>> xxd -g4 ...
>>
>> This option doesn't work with -i (the include file style output) which
>> is what we want. From xxd manual:
>>
>> "-g bytes | -groupsize bytes
>> separate the output of every  bytes (two hex characters or
>> eight bit-digits each) by a whitespace. Specify -g 0 to suppress
>> grouping.   defaults to 2 in normal mode and 1 in bits
>> mode. Grouping does not apply to postscript or include style."
> 
> Indeed, too bad.
> 
>>>
>>> xxd might not be installed on the host.
>>
>> xxd is provided by vim packages. So it should be available in most distros.
>>
>>>
>>> That said we should however install it on the docker cross images.
>>
>> Agreed.
>>
>>>
>>>> +  mv header.tmp $@
>>>> +
>>>> +aarch64.kernel: aarch64.elf
>>>> +  $(CROSS_PREFIX)objcopy -O binary $< $@
>>>> +
>>>> +aarch64.elf: a-b-kernel.S
>>>> +  $(CROSS_PREFIX)gcc -o $@ -nostdlib -Wl,--build-id=none $<
>>>> +
>>>> +clean:
>>>> +  @rm -rf *.kernel *.elf
>>>



Re: [Qemu-devel] [PATCH 1/1] tests: Add migration test for aarch64

2018-10-04 Thread Wei Huang



On 10/04/2018 10:07 AM, Philippe Mathieu-Daudé wrote:
> On 28/09/2018 21:47, Wei Huang wrote:
> [...]> +++ b/tests/migration/aarch64/Makefile
>> @@ -0,0 +1,20 @@
>> +# To specify cross compiler prefix, use CROSS_PREFIX=
>> +#   $ make CROSS_PREFIX=aarch64-linux-gnu-
>> +
>> +.PHONY: all clean
>> +all: a-b-kernel.h
>> +
>> +a-b-kernel.h: aarch64.kernel
>> +echo "$$__note" > header.tmp
> 
> This won't work on a read-only fs.

Under which setting? If tmp file can't be generated on a read-only fs,
wouldn't $@ have the same problem?

> 
> Why don't you use $@ directly?
> 
>> +xxd -i $< | sed -e 's/.*int.*//' >> header.tmp
> 
> Please use:
> 
> xxd -g4 ...

This option doesn't work with -i (the include file style output) which
is what we want. From xxd manual:

"-g bytes | -groupsize bytes
separate the output of every  bytes (two hex characters or
eight bit-digits each) by a whitespace. Specify -g 0 to suppress
grouping.   defaults to 2 in normal mode and 1 in bits
mode. Grouping does not apply to postscript or include style."


> 
> xxd might not be installed on the host.

xxd is provided by vim packages. So it should be available in most distros.

> 
> That said we should however install it on the docker cross images.

Agreed.

> 
>> +mv header.tmp $@
>> +
>> +aarch64.kernel: aarch64.elf
>> +$(CROSS_PREFIX)objcopy -O binary $< $@
>> +
>> +aarch64.elf: a-b-kernel.S
>> +$(CROSS_PREFIX)gcc -o $@ -nostdlib -Wl,--build-id=none $<
>> +
>> +clean:
>> +@rm -rf *.kernel *.elf
> 



Re: [Qemu-devel] [PATCH 1/1] tests: Add migration test for aarch64

2018-10-04 Thread Wei Huang



On 10/04/2018 08:48 AM, Andrew Jones wrote:
> On Fri, Sep 28, 2018 at 03:47:35PM -0400, Wei Huang wrote:
>> This patch adds migration test support for aarch64. The test code, which
>> implements the same functionality as x86, is booted as a kernel in qemu.
>> Here are the design choices we make for aarch64:
>>
>>  * We choose this -kernel approach because aarch64 QEMU doesn't provide a
>>built-in fw like x86 does. So instead of relying on a boot loader, we
>>use -kernel approach for aarch64.
>>  * The serial output is sent to PL011 directly.
>>  * The physical memory base for mach-virt machine is 0x4000. We change
>>the start_address and end_address for aarch64.
>>
>> In addition to providing the binary, this patch also includes the source
>> code and the build script in tests/migration/aarch64. So users can change
>> the source and/or re-compile the binary as they wish.
>>
>> Reviewed-by: Juan Quintela 
>> Signed-off-by: Wei Huang 
> 
> As many times as I've looked at this patch, I feel like I should already
> have some tag here...

Sorry, Drew. You have provided lots of comments on this patch and
Reviewed-by name should be in this patch. The last revision was a bigger
one in other patches (but not this one). So I removed most names in
order to get more attention.

> 
>> ---
>>  tests/Makefile.include   |  1 +
>>  tests/migration-test.c   | 27 +++--
>>  tests/migration/Makefile |  2 +-
>>  tests/migration/aarch64/Makefile | 20 ++
>>  tests/migration/aarch64/a-b-kernel.S | 75 
>> 
>>  tests/migration/aarch64/a-b-kernel.h | 19 +
>>  tests/migration/migration-test.h |  9 +
>>  7 files changed, 148 insertions(+), 5 deletions(-)
>>  create mode 100644 tests/migration/aarch64/Makefile
>>  create mode 100644 tests/migration/aarch64/a-b-kernel.S
>>  create mode 100644 tests/migration/aarch64/a-b-kernel.h
>>
>> diff --git a/tests/Makefile.include b/tests/Makefile.include
>> index d0c0a92..c16e3d1 100644
>> --- a/tests/Makefile.include
>> +++ b/tests/Makefile.include
>> @@ -402,6 +402,7 @@ check-qtest-arm-y += tests/hexloader-test$(EXESUF)
>>  check-qtest-aarch64-y = tests/numa-test$(EXESUF)
>>  check-qtest-aarch64-$(CONFIG_SDHCI) += tests/sdhci-test$(EXESUF)
>>  check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
>> +check-qtest-aarch64-y += tests/migration-test$(EXESUF)
>>  
>>  check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
>>  
>> diff --git a/tests/migration-test.c b/tests/migration-test.c
>> index 20f38f1..5bdc0bd 100644
>> --- a/tests/migration-test.c
>> +++ b/tests/migration-test.c
>> @@ -86,12 +86,13 @@ static const char *tmpfs;
>>   * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
>>   */
>>  #include "tests/migration/i386/a-b-bootblock.h"
>> +#include "tests/migration/aarch64/a-b-kernel.h"
>>  
>> -static void init_bootfile_x86(const char *bootpath)
>> +static void init_bootfile(const char *bootpath, void *content)
>>  {
>>  FILE *bootfile = fopen(bootpath, "wb");
>>  
>> -g_assert_cmpint(fwrite(x86_bootsect, 512, 1, bootfile), ==, 1);
>> +g_assert_cmpint(fwrite(content, 512, 1, bootfile), ==, 1);
>>  fclose(bootfile);
>>  }
>>  
>> @@ -428,7 +429,7 @@ static int test_migrate_start(QTestState **from, 
>> QTestState **to,
>>  got_stop = false;
>>  
>>  if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
>> -init_bootfile_x86(bootpath);
>> +init_bootfile(bootpath, x86_bootsect);
>>  cmd_src = g_strdup_printf("-machine accel=%s -m 150M"
>>" -name source,debug-threads=on"
>>" -serial file:%s/src_serial"
>> @@ -459,6 +460,24 @@ static int test_migrate_start(QTestState **from, 
>> QTestState **to,
>>  
>>  start_address = PPC_TEST_MEM_START;
>>  end_address = PPC_TEST_MEM_END;
>> +} else if (strcmp(arch, "aarch64") == 0) {
>> +init_bootfile(bootpath, aarch64_kernel);
>> +cmd_src = g_strdup_printf("-machine virt,accel=%s,gic-version=max "
>> +  "-name vmsource,debug-threads=on -cpu max 
>> "
>> +  "-m 150M -serial file:%s/src_serial "
>> +   

[Qemu-devel] [PATCH 1/1] tests: Add migration test for aarch64

2018-09-28 Thread Wei Huang
This patch adds migration test support for aarch64. The test code, which
implements the same functionality as x86, is booted as a kernel in qemu.
Here are the design choices we make for aarch64:

 * We choose this -kernel approach because aarch64 QEMU doesn't provide a
   built-in fw like x86 does. So instead of relying on a boot loader, we
   use -kernel approach for aarch64.
 * The serial output is sent to PL011 directly.
 * The physical memory base for mach-virt machine is 0x4000. We change
   the start_address and end_address for aarch64.

In addition to providing the binary, this patch also includes the source
code and the build script in tests/migration/aarch64. So users can change
the source and/or re-compile the binary as they wish.

Reviewed-by: Juan Quintela 
Signed-off-by: Wei Huang 
---
 tests/Makefile.include   |  1 +
 tests/migration-test.c   | 27 +++--
 tests/migration/Makefile |  2 +-
 tests/migration/aarch64/Makefile | 20 ++
 tests/migration/aarch64/a-b-kernel.S | 75 
 tests/migration/aarch64/a-b-kernel.h | 19 +
 tests/migration/migration-test.h |  9 +
 7 files changed, 148 insertions(+), 5 deletions(-)
 create mode 100644 tests/migration/aarch64/Makefile
 create mode 100644 tests/migration/aarch64/a-b-kernel.S
 create mode 100644 tests/migration/aarch64/a-b-kernel.h

diff --git a/tests/Makefile.include b/tests/Makefile.include
index d0c0a92..c16e3d1 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -402,6 +402,7 @@ check-qtest-arm-y += tests/hexloader-test$(EXESUF)
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
 check-qtest-aarch64-$(CONFIG_SDHCI) += tests/sdhci-test$(EXESUF)
 check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
+check-qtest-aarch64-y += tests/migration-test$(EXESUF)
 
 check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
 
diff --git a/tests/migration-test.c b/tests/migration-test.c
index 20f38f1..5bdc0bd 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -86,12 +86,13 @@ static const char *tmpfs;
  * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
  */
 #include "tests/migration/i386/a-b-bootblock.h"
+#include "tests/migration/aarch64/a-b-kernel.h"
 
-static void init_bootfile_x86(const char *bootpath)
+static void init_bootfile(const char *bootpath, void *content)
 {
 FILE *bootfile = fopen(bootpath, "wb");
 
-g_assert_cmpint(fwrite(x86_bootsect, 512, 1, bootfile), ==, 1);
+g_assert_cmpint(fwrite(content, 512, 1, bootfile), ==, 1);
 fclose(bootfile);
 }
 
@@ -428,7 +429,7 @@ static int test_migrate_start(QTestState **from, QTestState 
**to,
 got_stop = false;
 
 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-init_bootfile_x86(bootpath);
+init_bootfile(bootpath, x86_bootsect);
 cmd_src = g_strdup_printf("-machine accel=%s -m 150M"
   " -name source,debug-threads=on"
   " -serial file:%s/src_serial"
@@ -459,6 +460,24 @@ static int test_migrate_start(QTestState **from, 
QTestState **to,
 
 start_address = PPC_TEST_MEM_START;
 end_address = PPC_TEST_MEM_END;
+} else if (strcmp(arch, "aarch64") == 0) {
+init_bootfile(bootpath, aarch64_kernel);
+cmd_src = g_strdup_printf("-machine virt,accel=%s,gic-version=max "
+  "-name vmsource,debug-threads=on -cpu max "
+  "-m 150M -serial file:%s/src_serial "
+  "-kernel %s ",
+  accel, tmpfs, bootpath);
+cmd_dst = g_strdup_printf("-machine virt,accel=%s,gic-version=max "
+  "-name vmdest,debug-threads=on -cpu max "
+  "-m 150M -serial file:%s/dest_serial "
+  "-kernel %s "
+  "-incoming %s ",
+  accel, tmpfs, bootpath, uri);
+
+start_address = ARM_TEST_MEM_START;
+end_address = ARM_TEST_MEM_END;
+
+g_assert(sizeof(aarch64_kernel) <= ARM_TEST_MAX_KERNEL_SIZE);
 } else {
 g_assert_not_reached();
 }
@@ -545,7 +564,7 @@ static void test_deprecated(void)
 {
 QTestState *from;
 
-from = qtest_start("");
+from = qtest_start("-machine none");
 
 deprecated_set_downtime(from, 0.12345);
 deprecated_set_speed(from, 12345);
diff --git a/tests/migration/Makefile b/tests/migration/Makefile
index dc3b551..91237a8 100644
--- a/tests/migration/Makefile
+++ b/tests/migration/Makefile
@@ -5,7 +5,7 @@
 # See the COPYING file in the top-level directory.
 #
 
-TARG

Re: [Qemu-devel] [PATCH V9 4/4] tests: Add migration test for aarch64

2018-09-28 Thread Wei Huang



On 09/28/2018 10:20 AM, Dr. David Alan Gilbert wrote:
> * Dr. David Alan Gilbert (dgilb...@redhat.com) wrote:
>> * Wei Huang (w...@redhat.com) wrote:
>>>
>>>
>>> On 09/28/2018 09:04 AM, Dr. David Alan Gilbert wrote:
>>>> * Wei Huang (w...@redhat.com) wrote:
>>>>>
>>>>>
>>>>> On 09/26/2018 11:31 AM, Dr. David Alan Gilbert wrote:
>>>>>> * Wei Huang (w...@redhat.com) wrote:
>>>>>>> This patch adds migration test support for aarch64. The test code, which
>>>>>>> implements the same functionality as x86, is booted as a kernel in qemu.
>>>>>>> Here are the design choices we make for aarch64:
>>>>>>>
>>>>>>>  * We choose this -kernel approach because aarch64 QEMU doesn't provide 
>>>>>>> a
>>>>>>>built-in fw like x86 does. So instead of relying on a boot loader, we
>>>>>>>use -kernel approach for aarch64.
>>>>>>>  * The serial output is sent to PL011 directly.
>>>>>>>  * The physical memory base for mach-virt machine is 0x4000. We 
>>>>>>> change
>>>>>>>    the start_address and end_address for aarch64.
>>>>>>>
>>>>>>> In addition to providing the binary, this patch also includes the source
>>>>>>> code and the build script in tests/migration/aarch64. So users can 
>>>>>>> change
>>>>>>> the source and/or re-compile the binary as they wish.
>>>>>>>
>>>>>>> Reviewed-by: Juan Quintela 
>>>>>>> Signed-off-by: Wei Huang 
>>>>>>
>>>>>> I've had to bounce this patch (kept the other 3) because the test
>>>>>> is actually failing on aarch64 kvm.
>>>>>> It's about 1 in 5 for me on one of the larger (40ish core) boxes which
>>>>>> is otherwise idle.
>>>>>>
>>>>>> /aarch64/migration/precopy/unix: Memory content inconsistency at 
>>>>>> 43cf1000 first_byte = 5 last_byte = 4 current = 5 hit_edge = 1
>>>>>> Memory content inconsistency at 43cf2000 first_byte = 5 last_byte = 4 
>>>>>> current = 5 hit_edge = 1
>>>>>> Memory content inconsistency at 43cf3000 first_byte = 5 last_byte = 4 
>>>>>> current = 5 hit_edge = 1
>>>>>> Memory content inconsistency at 43cf4000 first_byte = 5 last_byte = 4 
>>>>>> current = 5 hit_edge = 1
>>>>>> Memory content inconsistency at 43cf5000 first_byte = 5 last_byte = 4 
>>>>>> current = 5 hit_edge = 1
>>>>>> Memory content inconsistency at 43cf6000 first_byte = 5 last_byte = 4 
>>>>>> current = 5 hit_edge = 1
>>>>>> Memory content inconsistency at 43cf7000 first_byte = 5 last_byte = 4 
>>>>>> current = 5 hit_edge = 1
>>>>>
>>>>> Thanks, Dave. The root cause is the wrong place of cache invalidation.
>>>>> Here is the fix which has been tested on Amberwing. Could you please
>>>>> verify it from your side? After that, I can either send in a new patch
>>>>> or you can help me revise the existing one.
>>>>
>>>> Thanks, I'll grab a box and try it.
>>>> If it works I'd prefer if you can resubmit the patch with the fix in.
>>>>
>>>> However, this fix looks suspicious to me.  We check the guest ram
>>>> contents after we stop the guest;  if the guests RAM is inconsistent as
>>>> seen by QEMU without the 'dc' then how will this work with normal
>>>> applications?
>>>
>>> Such cases happened before. Here is the one presentation given at KVM
>>> Forum:
>>> https://events.static.linuxfound.org/sites/events/files/slides/slides_10.pdf.
>>
>> I have seen that presentation but I don't understand how it relates to
>> your case.   Imagine that we're migrating some totally arbitrary
>> application - how do we know we get consistent memory  - if you're
>> having to put cache clears in the application that sounds like it's a
>> real kvm/arm bug that needs fixing.
> 
> The change does seem to be working; but I really would like to
> understand what's going on with the caches here.

We did have a same discussion when v1 was posted. Here is the thread:
https://lists.gnu.org/archive/html/qemu-devel/2018-01/msg05964.html and
it answers most questions. In summary, if gues

Re: [Qemu-devel] [PATCH V9 4/4] tests: Add migration test for aarch64

2018-09-28 Thread Wei Huang



On 09/28/2018 09:04 AM, Dr. David Alan Gilbert wrote:
> * Wei Huang (w...@redhat.com) wrote:
>>
>>
>> On 09/26/2018 11:31 AM, Dr. David Alan Gilbert wrote:
>>> * Wei Huang (w...@redhat.com) wrote:
>>>> This patch adds migration test support for aarch64. The test code, which
>>>> implements the same functionality as x86, is booted as a kernel in qemu.
>>>> Here are the design choices we make for aarch64:
>>>>
>>>>  * We choose this -kernel approach because aarch64 QEMU doesn't provide a
>>>>built-in fw like x86 does. So instead of relying on a boot loader, we
>>>>use -kernel approach for aarch64.
>>>>  * The serial output is sent to PL011 directly.
>>>>  * The physical memory base for mach-virt machine is 0x4000. We change
>>>>the start_address and end_address for aarch64.
>>>>
>>>> In addition to providing the binary, this patch also includes the source
>>>> code and the build script in tests/migration/aarch64. So users can change
>>>> the source and/or re-compile the binary as they wish.
>>>>
>>>> Reviewed-by: Juan Quintela 
>>>> Signed-off-by: Wei Huang 
>>>
>>> I've had to bounce this patch (kept the other 3) because the test
>>> is actually failing on aarch64 kvm.
>>> It's about 1 in 5 for me on one of the larger (40ish core) boxes which
>>> is otherwise idle.
>>>
>>> /aarch64/migration/precopy/unix: Memory content inconsistency at 43cf1000 
>>> first_byte = 5 last_byte = 4 current = 5 hit_edge = 1
>>> Memory content inconsistency at 43cf2000 first_byte = 5 last_byte = 4 
>>> current = 5 hit_edge = 1
>>> Memory content inconsistency at 43cf3000 first_byte = 5 last_byte = 4 
>>> current = 5 hit_edge = 1
>>> Memory content inconsistency at 43cf4000 first_byte = 5 last_byte = 4 
>>> current = 5 hit_edge = 1
>>> Memory content inconsistency at 43cf5000 first_byte = 5 last_byte = 4 
>>> current = 5 hit_edge = 1
>>> Memory content inconsistency at 43cf6000 first_byte = 5 last_byte = 4 
>>> current = 5 hit_edge = 1
>>> Memory content inconsistency at 43cf7000 first_byte = 5 last_byte = 4 
>>> current = 5 hit_edge = 1
>>
>> Thanks, Dave. The root cause is the wrong place of cache invalidation.
>> Here is the fix which has been tested on Amberwing. Could you please
>> verify it from your side? After that, I can either send in a new patch
>> or you can help me revise the existing one.
> 
> Thanks, I'll grab a box and try it.
> If it works I'd prefer if you can resubmit the patch with the fix in.
> 
> However, this fix looks suspicious to me.  We check the guest ram
> contents after we stop the guest;  if the guests RAM is inconsistent as
> seen by QEMU without the 'dc' then how will this work with normal
> applications?

Such cases happened before. Here is the one presentation given at KVM
Forum:
https://events.static.linuxfound.org/sites/events/files/slides/slides_10.pdf.

> 
> Shouldn't this be something qemu or kvm is doing when it stops the
> guest?
> 
> Dave
> 
>> Thanks,
>> -Wei
>>
>>
>> diff --git a/tests/migration/aarch64/a-b-kernel.S
>> b/tests/migration/aarch64/a-b-
>> index 507af30..c8d2720 100644
>> --- a/tests/migration/aarch64/a-b-kernel.S
>> +++ b/tests/migration/aarch64/a-b-kernel.S
>> @@ -50,15 +50,15 @@ mainloop:
>>  mov x4, x0
>>
>>  innerloop:
>> -/* clean cache because el2 might still cache guest data under
>> KVM */
>> -dc  civac, x4
>> -
>>  /* increment the first byte of each page by 1 */
>>  ldrbw3, [x4]
>>  add w3, w3, #1
>>  and w3, w3, #0xff
>>  strbw3, [x4]
>>
>> +/* clean cache because el2 might still cache guest data under
>> KVM */
>> +dc  civac, x4
>> +
>>  add x4, x4, #TEST_MEM_PAGE_SIZE
>>  cmp x4, x1
>>  blt innerloop
>>
>>
>>>
>>> Dave
>>>
>>>> ---
>>>>  tests/Makefile.include   |  1 +
>>>>  tests/migration-test.c   | 27 +++--
>>>>  tests/migration/Makefile |  2 +-
>>>>  tests/migration/aarch64/Makefile | 20 ++
>>>>  tests/migration/aarch64/a-b-kernel.S | 75 
>>>> 
>>>>  tests/migration/aarch64/a-b-kernel.h | 19 +
>>>>

Re: [Qemu-devel] [PATCH V9 4/4] tests: Add migration test for aarch64

2018-09-28 Thread Wei Huang



On 09/26/2018 11:31 AM, Dr. David Alan Gilbert wrote:
> * Wei Huang (w...@redhat.com) wrote:
>> This patch adds migration test support for aarch64. The test code, which
>> implements the same functionality as x86, is booted as a kernel in qemu.
>> Here are the design choices we make for aarch64:
>>
>>  * We choose this -kernel approach because aarch64 QEMU doesn't provide a
>>built-in fw like x86 does. So instead of relying on a boot loader, we
>>use -kernel approach for aarch64.
>>  * The serial output is sent to PL011 directly.
>>  * The physical memory base for mach-virt machine is 0x4000. We change
>>the start_address and end_address for aarch64.
>>
>> In addition to providing the binary, this patch also includes the source
>> code and the build script in tests/migration/aarch64. So users can change
>> the source and/or re-compile the binary as they wish.
>>
>> Reviewed-by: Juan Quintela 
>> Signed-off-by: Wei Huang 
> 
> I've had to bounce this patch (kept the other 3) because the test
> is actually failing on aarch64 kvm.
> It's about 1 in 5 for me on one of the larger (40ish core) boxes which
> is otherwise idle.
> 
> /aarch64/migration/precopy/unix: Memory content inconsistency at 43cf1000 
> first_byte = 5 last_byte = 4 current = 5 hit_edge = 1
> Memory content inconsistency at 43cf2000 first_byte = 5 last_byte = 4 current 
> = 5 hit_edge = 1
> Memory content inconsistency at 43cf3000 first_byte = 5 last_byte = 4 current 
> = 5 hit_edge = 1
> Memory content inconsistency at 43cf4000 first_byte = 5 last_byte = 4 current 
> = 5 hit_edge = 1
> Memory content inconsistency at 43cf5000 first_byte = 5 last_byte = 4 current 
> = 5 hit_edge = 1
> Memory content inconsistency at 43cf6000 first_byte = 5 last_byte = 4 current 
> = 5 hit_edge = 1
> Memory content inconsistency at 43cf7000 first_byte = 5 last_byte = 4 current 
> = 5 hit_edge = 1

Thanks, Dave. The root cause is the wrong place of cache invalidation.
Here is the fix which has been tested on Amberwing. Could you please
verify it from your side? After that, I can either send in a new patch
or you can help me revise the existing one.

Thanks,
-Wei


diff --git a/tests/migration/aarch64/a-b-kernel.S
b/tests/migration/aarch64/a-b-
index 507af30..c8d2720 100644
--- a/tests/migration/aarch64/a-b-kernel.S
+++ b/tests/migration/aarch64/a-b-kernel.S
@@ -50,15 +50,15 @@ mainloop:
 mov x4, x0

 innerloop:
-/* clean cache because el2 might still cache guest data under
KVM */
-dc  civac, x4
-
 /* increment the first byte of each page by 1 */
 ldrbw3, [x4]
 add w3, w3, #1
 and w3, w3, #0xff
 strbw3, [x4]

+/* clean cache because el2 might still cache guest data under
KVM */
+dc  civac, x4
+
 add x4, x4, #TEST_MEM_PAGE_SIZE
 cmp x4, x1
 blt innerloop


> 
> Dave
> 
>> ---
>>  tests/Makefile.include   |  1 +
>>  tests/migration-test.c   | 27 +++--
>>  tests/migration/Makefile |  2 +-
>>  tests/migration/aarch64/Makefile | 20 ++
>>  tests/migration/aarch64/a-b-kernel.S | 75 
>> 
>>  tests/migration/aarch64/a-b-kernel.h | 19 +
>>  tests/migration/migration-test.h |  9 +
>>  7 files changed, 148 insertions(+), 5 deletions(-)
>>  create mode 100644 tests/migration/aarch64/Makefile
>>  create mode 100644 tests/migration/aarch64/a-b-kernel.S
>>  create mode 100644 tests/migration/aarch64/a-b-kernel.h
>>
>> diff --git a/tests/Makefile.include b/tests/Makefile.include
>> index 87c81d1..fab8fb9 100644
>> --- a/tests/Makefile.include
>> +++ b/tests/Makefile.include
>> @@ -390,6 +390,7 @@ check-qtest-arm-y += tests/hexloader-test$(EXESUF)
>>  check-qtest-aarch64-y = tests/numa-test$(EXESUF)
>>  check-qtest-aarch64-$(CONFIG_SDHCI) += tests/sdhci-test$(EXESUF)
>>  check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
>> +check-qtest-aarch64-y += tests/migration-test$(EXESUF)
>>  
>>  check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
>>  
>> diff --git a/tests/migration-test.c b/tests/migration-test.c
>> index 17c6896..ecfae0b 100644
>> --- a/tests/migration-test.c
>> +++ b/tests/migration-test.c
>> @@ -86,12 +86,13 @@ static const char *tmpfs;
>>   * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
>>   */
>>  #include "tests/migration/i386/a-b-bootblock.h"
>> +#include "tests/migration/aarch64/a-b-kernel.h"
>>  
>> -static void init_bootfile_x86(const char *bootp

Re: [Qemu-devel] [PATCH V9 2/4] tests/migration: Support cross compilation in generating boot header file

2018-09-10 Thread Wei Huang



On 09/10/2018 11:18 AM, Alex Bennée wrote:
> 
> Wei Huang  writes:
> 
>> Recently a new configure option, CROSS_CC_GUEST, was added to
>> $(TARGET)-softmmu/config-target.mak to support TCG-related tests. This
>> patch tries to leverage this option to support cross compilation when the
>> migration boot block file is being re-generated:
>>
>>  * The x86 related files are moved to a new sub-dir (named ./i386).
>>  * A new top-layer Makefile is created in tests/migration/ directory.
>>This Makefile searches and parses CROSS_CC_GUEST to generate CROSS_PREFIX.
>>The CROSS_PREFIX, if available, is then passed to 
>> migration/$ARCH/Makefile.
>>
>> Reviewed-by: Juan Quintela 
>> Signed-off-by: Wei Huang 
>> ---
>>  tests/migration-test.c |  2 +-
>>  tests/migration/Makefile   | 44 
>> --
>>  tests/migration/i386/Makefile  | 22 +++
>>  .../{x86-a-b-bootblock.S => i386/a-b-bootblock.S}  |  4 --
>>  .../{x86-a-b-bootblock.h => i386/a-b-bootblock.h}  |  8 ++--
>>  5 files changed, 51 insertions(+), 29 deletions(-)
>>  create mode 100644 tests/migration/i386/Makefile
>>  rename tests/migration/{x86-a-b-bootblock.S => i386/a-b-bootblock.S} (93%)
>>  rename tests/migration/{x86-a-b-bootblock.h => i386/a-b-bootblock.h} (92%)
>>
>> diff --git a/tests/migration-test.c b/tests/migration-test.c
>> index 0e687b7..fe6b41a 100644
>> --- a/tests/migration-test.c
>> +++ b/tests/migration-test.c
>> @@ -83,7 +83,7 @@ static const char *tmpfs;
>>  /* A simple PC boot sector that modifies memory (1-100MB) quickly
>>   * outputting a 'B' every so often if it's still running.
>>   */
>> -#include "tests/migration/x86-a-b-bootblock.h"
>> +#include "tests/migration/i386/a-b-bootblock.h"
>>
>>  static void init_bootfile_x86(const char *bootpath)
>>  {
>> diff --git a/tests/migration/Makefile b/tests/migration/Makefile
>> index c0824b4..a9ed875 100644
>> --- a/tests/migration/Makefile
>> +++ b/tests/migration/Makefile
>> @@ -1,31 +1,35 @@
>> -# To specify cross compiler prefix, use CROSS_PREFIX=
>> -#   $ make CROSS_PREFIX=x86_64-linux-gnu-
>> +#
>> +# Copyright (c) 2018 Red Hat, Inc. and/or its affiliates
>> +#
>> +# This work is licensed under the terms of the GNU GPL, version 2 or later.
>> +# See the COPYING file in the top-level directory.
>> +#
>> +
>> +TARGET_LIST = i386
>> +
>> +SRC_PATH = ../..
>>
>>  override define __note
>> -/* This file is automatically generated from
>> - * tests/migration/x86-a-b-bootblock.S, edit that and then run
>> - * tests/migration/rebuild-x86-bootblock.sh to update,
>> - * and then remember to send both in your patch submission.
>> +/* This file is automatically generated from the assembly file in
>> + * tests/migration/$@. Edit that file and then run "make all"
>> + * inside tests/migration to update, and then remember to send both
>> + * the header and the assembler differences in your patch submission.
>>   */
>>  endef
>>  export __note
>>
>> -.PHONY: all clean
>> -all: x86-a-b-bootblock.h
>> -
>> -x86-a-b-bootblock.h: x86.bootsect
>> -echo "$$__note" > header.tmp
>> -xxd -i $< | sed -e 's/.*int.*//' >> header.tmp
>> -mv header.tmp $@
>> +find-arch-cross-cc = $(lastword $(shell grep -h "CROSS_CC_GUEST=" 
>> $(wildcard $(SRC_PATH)/$(patsubst 
>> i386,*86*,$(1))-softmmu/config-target.mak)))
>> +parse-cross-prefix = $(subst gcc,,$(patsubst cc,gcc,$(patsubst 
>> CROSS_CC_GUEST="%",%,$(call find-arch-cross-cc,$(1)
>> +gen-cross-prefix = $(patsubst %-,CROSS_PREFIX=%-,$(call
>> parse-cross-prefix,$(1)))
> 
> This all seems awfully fiddly compared to moving the code to tests/tcg
> and building with the existing machinery. You don't even get the docker
> fall-back this way.
> 
> The aim being to have the ability to build the binary and manually
> update the .hex/.S encoded version actually used in the test when you
> don't have cross compilers available right?

The purpose is to generate migration test binary (in the .h files) when
a cross compiler is available. If you can do it with docker, it is a plus.

But to be honest, unless people are updating the migration test code
themselves, it would be extremely rare for them to change (or invoke)
this Makefile.

> 
> I've got some TODOs in tests/tcg to start building the various system
> tests. Perhaps I s

Re: [Qemu-devel] [PATCH V9 2/4] tests/migration: Support cross compilation in generating boot header file

2018-09-07 Thread Wei Huang



On 09/07/2018 02:04 AM, Andrew Jones wrote:
> On Thu, Sep 06, 2018 at 12:23:45PM -0400, Wei Huang wrote:
>>
>>
>> - Original Message -
>>> From: "Andrew Jones" 
>>> To: "Wei Huang" 
>>> Cc: lviv...@redhat.com, "peter maydell" , 
>>> quint...@redhat.com, qemu-devel@nongnu.org,
>>> dgilb...@redhat.com, "alex bennee" 
>>> Sent: Thursday, September 6, 2018 9:00:33 AM
>>> Subject: Re: [Qemu-devel] [PATCH V9 2/4] tests/migration: Support cross 
>>> compilation in generating boot header file
>>>
>>> On Thu, Sep 06, 2018 at 09:37:04AM -0400, Wei Huang wrote:
>>>>
>>>>
>>>> - Original Message -
>>>>> From: "Andrew Jones" 
>>>>> To: "Wei Huang" 
>>>>> Cc: qemu-devel@nongnu.org, lviv...@redhat.com, "peter maydell"
>>>>> , quint...@redhat.com,
>>>>> dgilb...@redhat.com, "alex bennee" 
>>>>> Sent: Thursday, September 6, 2018 7:03:32 AM
>>>>> Subject: Re: [Qemu-devel] [PATCH V9 2/4] tests/migration: Support cross
>>>>> compilation in generating boot header file
>>>>>
>>>>> On Wed, Sep 05, 2018 at 03:15:32PM -0400, Wei Huang wrote:
>>>>>> Recently a new configure option, CROSS_CC_GUEST, was added to
>>>>>> $(TARGET)-softmmu/config-target.mak to support TCG-related tests. This
>>>>>> patch tries to leverage this option to support cross compilation when
>>>>>> the
>>>>>> migration boot block file is being re-generated:
>>>>>>
>>>>>>  * The x86 related files are moved to a new sub-dir (named ./i386).
>>>>>>  * A new top-layer Makefile is created in tests/migration/ directory.
>>>>>>This Makefile searches and parses CROSS_CC_GUEST to generate
>>>>>>CROSS_PREFIX.
>>>>>>The CROSS_PREFIX, if available, is then passed to
>>>>>>migration/$ARCH/Makefile.
>>>>>>
>>>>>> Reviewed-by: Juan Quintela 
>>>>>> Signed-off-by: Wei Huang 
>>>>>> ---
>>>>>>  tests/migration-test.c |  2 +-
>>>>>>  tests/migration/Makefile   | 44
>>>>>>  --
>>>>>>  tests/migration/i386/Makefile  | 22 +++
>>>>>>  .../{x86-a-b-bootblock.S => i386/a-b-bootblock.S}  |  4 --
>>>>>>  .../{x86-a-b-bootblock.h => i386/a-b-bootblock.h}  |  8 ++--
>>>>>>  5 files changed, 51 insertions(+), 29 deletions(-)
>>>>>>  create mode 100644 tests/migration/i386/Makefile
>>>>>>  rename tests/migration/{x86-a-b-bootblock.S => i386/a-b-bootblock.S}
>>>>>>  (93%)
>>>>>>  rename tests/migration/{x86-a-b-bootblock.h => i386/a-b-bootblock.h}
>>>>>>  (92%)
>>>>>>
>>>>>> diff --git a/tests/migration-test.c b/tests/migration-test.c
>>>>>> index 0e687b7..fe6b41a 100644
>>>>>> --- a/tests/migration-test.c
>>>>>> +++ b/tests/migration-test.c
>>>>>> @@ -83,7 +83,7 @@ static const char *tmpfs;
>>>>>>  /* A simple PC boot sector that modifies memory (1-100MB) quickly
>>>>>>   * outputting a 'B' every so often if it's still running.
>>>>>>   */
>>>>>> -#include "tests/migration/x86-a-b-bootblock.h"
>>>>>> +#include "tests/migration/i386/a-b-bootblock.h"
>>>>>>  
>>>>>>  static void init_bootfile_x86(const char *bootpath)
>>>>>>  {
>>>>>> diff --git a/tests/migration/Makefile b/tests/migration/Makefile
>>>>>> index c0824b4..a9ed875 100644
>>>>>> --- a/tests/migration/Makefile
>>>>>> +++ b/tests/migration/Makefile
>>>>>> @@ -1,31 +1,35 @@
>>>>>> -# To specify cross compiler prefix, use CROSS_PREFIX=
>>>>>> -#   $ make CROSS_PREFIX=x86_64-linux-gnu-
>>>>>> +#
>>>>>> +# Copyright (c) 2018 Red Hat, Inc. and/or its affiliates
>>>>>> +#
>>>>>> +# This work is licensed under the terms of the GNU GPL, version 2 or
>>>>>> later.
>>>>>> +# See the COPYING file in the top-level directory.
>>>&

Re: [Qemu-devel] [PATCH V9 2/4] tests/migration: Support cross compilation in generating boot header file

2018-09-06 Thread Wei Huang



- Original Message -
> From: "Andrew Jones" 
> To: "Wei Huang" 
> Cc: lviv...@redhat.com, "peter maydell" , 
> quint...@redhat.com, qemu-devel@nongnu.org,
> dgilb...@redhat.com, "alex bennee" 
> Sent: Thursday, September 6, 2018 9:00:33 AM
> Subject: Re: [Qemu-devel] [PATCH V9 2/4] tests/migration: Support cross 
> compilation in generating boot header file
> 
> On Thu, Sep 06, 2018 at 09:37:04AM -0400, Wei Huang wrote:
> > 
> > 
> > - Original Message -
> > > From: "Andrew Jones" 
> > > To: "Wei Huang" 
> > > Cc: qemu-devel@nongnu.org, lviv...@redhat.com, "peter maydell"
> > > , quint...@redhat.com,
> > > dgilb...@redhat.com, "alex bennee" 
> > > Sent: Thursday, September 6, 2018 7:03:32 AM
> > > Subject: Re: [Qemu-devel] [PATCH V9 2/4] tests/migration: Support cross
> > > compilation in generating boot header file
> > > 
> > > On Wed, Sep 05, 2018 at 03:15:32PM -0400, Wei Huang wrote:
> > > > Recently a new configure option, CROSS_CC_GUEST, was added to
> > > > $(TARGET)-softmmu/config-target.mak to support TCG-related tests. This
> > > > patch tries to leverage this option to support cross compilation when
> > > > the
> > > > migration boot block file is being re-generated:
> > > > 
> > > >  * The x86 related files are moved to a new sub-dir (named ./i386).
> > > >  * A new top-layer Makefile is created in tests/migration/ directory.
> > > >This Makefile searches and parses CROSS_CC_GUEST to generate
> > > >CROSS_PREFIX.
> > > >The CROSS_PREFIX, if available, is then passed to
> > > >migration/$ARCH/Makefile.
> > > > 
> > > > Reviewed-by: Juan Quintela 
> > > > Signed-off-by: Wei Huang 
> > > > ---
> > > >  tests/migration-test.c |  2 +-
> > > >  tests/migration/Makefile   | 44
> > > >  --
> > > >  tests/migration/i386/Makefile  | 22 +++
> > > >  .../{x86-a-b-bootblock.S => i386/a-b-bootblock.S}  |  4 --
> > > >  .../{x86-a-b-bootblock.h => i386/a-b-bootblock.h}  |  8 ++--
> > > >  5 files changed, 51 insertions(+), 29 deletions(-)
> > > >  create mode 100644 tests/migration/i386/Makefile
> > > >  rename tests/migration/{x86-a-b-bootblock.S => i386/a-b-bootblock.S}
> > > >  (93%)
> > > >  rename tests/migration/{x86-a-b-bootblock.h => i386/a-b-bootblock.h}
> > > >  (92%)
> > > > 
> > > > diff --git a/tests/migration-test.c b/tests/migration-test.c
> > > > index 0e687b7..fe6b41a 100644
> > > > --- a/tests/migration-test.c
> > > > +++ b/tests/migration-test.c
> > > > @@ -83,7 +83,7 @@ static const char *tmpfs;
> > > >  /* A simple PC boot sector that modifies memory (1-100MB) quickly
> > > >   * outputting a 'B' every so often if it's still running.
> > > >   */
> > > > -#include "tests/migration/x86-a-b-bootblock.h"
> > > > +#include "tests/migration/i386/a-b-bootblock.h"
> > > >  
> > > >  static void init_bootfile_x86(const char *bootpath)
> > > >  {
> > > > diff --git a/tests/migration/Makefile b/tests/migration/Makefile
> > > > index c0824b4..a9ed875 100644
> > > > --- a/tests/migration/Makefile
> > > > +++ b/tests/migration/Makefile
> > > > @@ -1,31 +1,35 @@
> > > > -# To specify cross compiler prefix, use CROSS_PREFIX=
> > > > -#   $ make CROSS_PREFIX=x86_64-linux-gnu-
> > > > +#
> > > > +# Copyright (c) 2018 Red Hat, Inc. and/or its affiliates
> > > > +#
> > > > +# This work is licensed under the terms of the GNU GPL, version 2 or
> > > > later.
> > > > +# See the COPYING file in the top-level directory.
> > > > +#
> > > > +
> > > > +TARGET_LIST = i386
> > > > +
> > > > +SRC_PATH = ../..
> > > >  
> > > >  override define __note
> > > > -/* This file is automatically generated from
> > > > - * tests/migration/x86-a-b-bootblock.S, edit that and then run
> > > > - * tests/migration/rebuild-x86-bootblock.sh to update,
> > > > - * and then remember to send both in your patch submission.
> > > > +/* This file is automatically g

Re: [Qemu-devel] [PATCH V9 2/4] tests/migration: Support cross compilation in generating boot header file

2018-09-06 Thread Wei Huang



- Original Message -
> From: "Andrew Jones" 
> To: "Wei Huang" 
> Cc: qemu-devel@nongnu.org, lviv...@redhat.com, "peter maydell" 
> , quint...@redhat.com,
> dgilb...@redhat.com, "alex bennee" 
> Sent: Thursday, September 6, 2018 7:03:32 AM
> Subject: Re: [Qemu-devel] [PATCH V9 2/4] tests/migration: Support cross 
> compilation in generating boot header file
> 
> On Wed, Sep 05, 2018 at 03:15:32PM -0400, Wei Huang wrote:
> > Recently a new configure option, CROSS_CC_GUEST, was added to
> > $(TARGET)-softmmu/config-target.mak to support TCG-related tests. This
> > patch tries to leverage this option to support cross compilation when the
> > migration boot block file is being re-generated:
> > 
> >  * The x86 related files are moved to a new sub-dir (named ./i386).
> >  * A new top-layer Makefile is created in tests/migration/ directory.
> >This Makefile searches and parses CROSS_CC_GUEST to generate
> >CROSS_PREFIX.
> >The CROSS_PREFIX, if available, is then passed to
> >migration/$ARCH/Makefile.
> > 
> > Reviewed-by: Juan Quintela 
> > Signed-off-by: Wei Huang 
> > ---
> >  tests/migration-test.c |  2 +-
> >  tests/migration/Makefile   | 44
> >  --
> >  tests/migration/i386/Makefile  | 22 +++
> >  .../{x86-a-b-bootblock.S => i386/a-b-bootblock.S}  |  4 --
> >  .../{x86-a-b-bootblock.h => i386/a-b-bootblock.h}  |  8 ++--
> >  5 files changed, 51 insertions(+), 29 deletions(-)
> >  create mode 100644 tests/migration/i386/Makefile
> >  rename tests/migration/{x86-a-b-bootblock.S => i386/a-b-bootblock.S} (93%)
> >  rename tests/migration/{x86-a-b-bootblock.h => i386/a-b-bootblock.h} (92%)
> > 
> > diff --git a/tests/migration-test.c b/tests/migration-test.c
> > index 0e687b7..fe6b41a 100644
> > --- a/tests/migration-test.c
> > +++ b/tests/migration-test.c
> > @@ -83,7 +83,7 @@ static const char *tmpfs;
> >  /* A simple PC boot sector that modifies memory (1-100MB) quickly
> >   * outputting a 'B' every so often if it's still running.
> >   */
> > -#include "tests/migration/x86-a-b-bootblock.h"
> > +#include "tests/migration/i386/a-b-bootblock.h"
> >  
> >  static void init_bootfile_x86(const char *bootpath)
> >  {
> > diff --git a/tests/migration/Makefile b/tests/migration/Makefile
> > index c0824b4..a9ed875 100644
> > --- a/tests/migration/Makefile
> > +++ b/tests/migration/Makefile
> > @@ -1,31 +1,35 @@
> > -# To specify cross compiler prefix, use CROSS_PREFIX=
> > -#   $ make CROSS_PREFIX=x86_64-linux-gnu-
> > +#
> > +# Copyright (c) 2018 Red Hat, Inc. and/or its affiliates
> > +#
> > +# This work is licensed under the terms of the GNU GPL, version 2 or
> > later.
> > +# See the COPYING file in the top-level directory.
> > +#
> > +
> > +TARGET_LIST = i386
> > +
> > +SRC_PATH = ../..
> >  
> >  override define __note
> > -/* This file is automatically generated from
> > - * tests/migration/x86-a-b-bootblock.S, edit that and then run
> > - * tests/migration/rebuild-x86-bootblock.sh to update,
> > - * and then remember to send both in your patch submission.
> > +/* This file is automatically generated from the assembly file in
> > + * tests/migration/$@. Edit that file and then run "make all"
> > + * inside tests/migration to update, and then remember to send both
> > + * the header and the assembler differences in your patch submission.
> >   */
> >  endef
> >  export __note
> >  
> > -.PHONY: all clean
> > -all: x86-a-b-bootblock.h
> > -
> > -x86-a-b-bootblock.h: x86.bootsect
> > -   echo "$$__note" > header.tmp
> > -   xxd -i $< | sed -e 's/.*int.*//' >> header.tmp
> > -   mv header.tmp $@
> > +find-arch-cross-cc = $(lastword $(shell grep -h "CROSS_CC_GUEST="
> > $(wildcard $(SRC_PATH)/$(patsubst
> > i386,*86*,$(1))-softmmu/config-target.mak)))
> 
> The above function hangs unless configuring with
> '--target-list=x86_64-softmmu,aarch64-softmmu'. I tried just x86_64 alone,
> just aarch64 alone, and also configuring both x86_64 and i386, but none
> of those worked. For some reason grep isn't happy with the generated path
> list. I tested like this
> 
>  ./configure --target-list=x86_64-softmmu,i386-softmmu
>  make -C tests/migration
> 
> And, while not an issue of this series, I had to manually add
> CROSS_CC_GUEST="

[Qemu-devel] [PATCH V9 4/4] tests: Add migration test for aarch64

2018-09-05 Thread Wei Huang
This patch adds migration test support for aarch64. The test code, which
implements the same functionality as x86, is booted as a kernel in qemu.
Here are the design choices we make for aarch64:

 * We choose this -kernel approach because aarch64 QEMU doesn't provide a
   built-in fw like x86 does. So instead of relying on a boot loader, we
   use -kernel approach for aarch64.
 * The serial output is sent to PL011 directly.
 * The physical memory base for mach-virt machine is 0x4000. We change
   the start_address and end_address for aarch64.

In addition to providing the binary, this patch also includes the source
code and the build script in tests/migration/aarch64. So users can change
the source and/or re-compile the binary as they wish.

Reviewed-by: Juan Quintela 
Signed-off-by: Wei Huang 
---
 tests/Makefile.include   |  1 +
 tests/migration-test.c   | 27 +++--
 tests/migration/Makefile |  2 +-
 tests/migration/aarch64/Makefile | 20 ++
 tests/migration/aarch64/a-b-kernel.S | 75 
 tests/migration/aarch64/a-b-kernel.h | 19 +
 tests/migration/migration-test.h |  9 +
 7 files changed, 148 insertions(+), 5 deletions(-)
 create mode 100644 tests/migration/aarch64/Makefile
 create mode 100644 tests/migration/aarch64/a-b-kernel.S
 create mode 100644 tests/migration/aarch64/a-b-kernel.h

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 87c81d1..fab8fb9 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -390,6 +390,7 @@ check-qtest-arm-y += tests/hexloader-test$(EXESUF)
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
 check-qtest-aarch64-$(CONFIG_SDHCI) += tests/sdhci-test$(EXESUF)
 check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
+check-qtest-aarch64-y += tests/migration-test$(EXESUF)
 
 check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
 
diff --git a/tests/migration-test.c b/tests/migration-test.c
index 17c6896..ecfae0b 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -86,12 +86,13 @@ static const char *tmpfs;
  * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
  */
 #include "tests/migration/i386/a-b-bootblock.h"
+#include "tests/migration/aarch64/a-b-kernel.h"
 
-static void init_bootfile_x86(const char *bootpath)
+static void init_bootfile(const char *bootpath, void *content)
 {
 FILE *bootfile = fopen(bootpath, "wb");
 
-g_assert_cmpint(fwrite(x86_bootsect, 512, 1, bootfile), ==, 1);
+g_assert_cmpint(fwrite(content, 512, 1, bootfile), ==, 1);
 fclose(bootfile);
 }
 
@@ -428,7 +429,7 @@ static int test_migrate_start(QTestState **from, QTestState 
**to,
 got_stop = false;
 
 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-init_bootfile_x86(bootpath);
+init_bootfile(bootpath, x86_bootsect);
 cmd_src = g_strdup_printf("-machine accel=%s -m 150M"
   " -name source,debug-threads=on"
   " -serial file:%s/src_serial"
@@ -459,6 +460,24 @@ static int test_migrate_start(QTestState **from, 
QTestState **to,
 
 start_address = PPC_TEST_MEM_START;
 end_address = PPC_TEST_MEM_END;
+} else if (strcmp(arch, "aarch64") == 0) {
+init_bootfile(bootpath, aarch64_kernel);
+cmd_src = g_strdup_printf("-machine virt,accel=%s,gic-version=max "
+  "-name vmsource,debug-threads=on -cpu max "
+  "-m 150M -serial file:%s/src_serial "
+  "-kernel %s ",
+  accel, tmpfs, bootpath);
+cmd_dst = g_strdup_printf("-machine virt,accel=%s,gic-version=max "
+  "-name vmdest,debug-threads=on -cpu max "
+  "-m 150M -serial file:%s/dest_serial "
+  "-kernel %s "
+  "-incoming %s ",
+  accel, tmpfs, bootpath, uri);
+
+start_address = ARM_TEST_MEM_START;
+end_address = ARM_TEST_MEM_END;
+
+g_assert(sizeof(aarch64_kernel) <= ARM_TEST_MAX_KERNEL_SIZE);
 } else {
 g_assert_not_reached();
 }
@@ -545,7 +564,7 @@ static void test_deprecated(void)
 {
 QTestState *from;
 
-from = qtest_start("");
+from = qtest_start("-machine none");
 
 deprecated_set_downtime(from, 0.12345);
 deprecated_set_speed(from, 12345);
diff --git a/tests/migration/Makefile b/tests/migration/Makefile
index a9ed875..13af934 100644
--- a/tests/migration/Makefile
+++ b/tests/migration/Makefile
@@ -5,7 +5,7 @@
 # See the COPYING file in the top-level directory.
 #
 
-TARG

[Qemu-devel] [PATCH V9 1/4] tests/migration: Convert x86 boot block compilation script into Makefile

2018-09-05 Thread Wei Huang
The x86 boot block header currently is generated with a shell script.
To better support other CPUs (e.g. aarch64), we convert the script
into Makefile. This allows us to 1) support cross-compilation easily,
and 2) avoid creating a script file for every architecture.

Note that, in the new design, the cross compiler prefix can be specified by
setting the CROSS_PREFIX in "make" command. Also to allow gcc pre-processor
to include the C-style file correctly, it also renames the
x86-a-b-bootblock.s file extension from .s to .S.

Reviewed-by: Juan Quintela 
Signed-off-by: Wei Huang 
---
 tests/migration/Makefile   | 31 
 tests/migration/rebuild-x86-bootblock.sh   | 33 --
 .../{x86-a-b-bootblock.s => x86-a-b-bootblock.S}   |  0
 3 files changed, 31 insertions(+), 33 deletions(-)
 create mode 100644 tests/migration/Makefile
 delete mode 100755 tests/migration/rebuild-x86-bootblock.sh
 rename tests/migration/{x86-a-b-bootblock.s => x86-a-b-bootblock.S} (100%)

diff --git a/tests/migration/Makefile b/tests/migration/Makefile
new file mode 100644
index 000..c0824b4
--- /dev/null
+++ b/tests/migration/Makefile
@@ -0,0 +1,31 @@
+# To specify cross compiler prefix, use CROSS_PREFIX=
+#   $ make CROSS_PREFIX=x86_64-linux-gnu-
+
+override define __note
+/* This file is automatically generated from
+ * tests/migration/x86-a-b-bootblock.S, edit that and then run
+ * tests/migration/rebuild-x86-bootblock.sh to update,
+ * and then remember to send both in your patch submission.
+ */
+endef
+export __note
+
+.PHONY: all clean
+all: x86-a-b-bootblock.h
+
+x86-a-b-bootblock.h: x86.bootsect
+   echo "$$__note" > header.tmp
+   xxd -i $< | sed -e 's/.*int.*//' >> header.tmp
+   mv header.tmp $@
+
+x86.bootsect: x86.boot
+   dd if=$< of=$@ bs=256 count=2 skip=124
+
+x86.boot: x86.o
+   $(CROSS_PREFIX)objcopy -O binary $< $@
+
+x86.o: x86-a-b-bootblock.S
+   $(CROSS_PREFIX)gcc -m32 -march=i486 -c $< -o $@
+
+clean:
+   @rm -rf *.boot *.o *.bootsect
diff --git a/tests/migration/rebuild-x86-bootblock.sh 
b/tests/migration/rebuild-x86-bootblock.sh
deleted file mode 100755
index 86cec5d..000
--- a/tests/migration/rebuild-x86-bootblock.sh
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/sh
-# Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
-# This work is licensed under the terms of the GNU GPL, version 2 or later.
-# See the COPYING file in the top-level directory.
-#
-# Author: dgilb...@redhat.com
-
-ASMFILE=$PWD/tests/migration/x86-a-b-bootblock.s
-HEADER=$PWD/tests/migration/x86-a-b-bootblock.h
-
-if [ ! -e "$ASMFILE" ]
-then
-  echo "Couldn't find $ASMFILE" >&2
-  exit 1
-fi
-
-ASM_WORK_DIR=$(mktemp -d --tmpdir X86BB.XX)
-cd "$ASM_WORK_DIR" &&
-as --32 -march=i486 "$ASMFILE" -o x86.o &&
-objcopy -O binary x86.o x86.boot &&
-dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124 &&
-xxd -i x86.bootsect |
-sed -e 's/.*int.*//' > x86.hex &&
-cat - x86.hex < "$HEADER"
-/* This file is automatically generated from
- * tests/migration/x86-a-b-bootblock.s, edit that and then run
- * tests/migration/rebuild-x86-bootblock.sh to update,
- * and then remember to send both in your patch submission.
- */
-HERE
-
-rm x86.hex x86.bootsect x86.boot x86.o
-cd .. && rmdir "$ASM_WORK_DIR"
diff --git a/tests/migration/x86-a-b-bootblock.s 
b/tests/migration/x86-a-b-bootblock.S
similarity index 100%
rename from tests/migration/x86-a-b-bootblock.s
rename to tests/migration/x86-a-b-bootblock.S
-- 
1.8.3.1




[Qemu-devel] [PATCH V9 3/4] tests/migration: Add migration-test header file

2018-09-05 Thread Wei Huang
This patch moves the settings related migration-test from the
migration-test.c file to a new header file.

Reviewed-by: Juan Quintela 
Reviewed-by: Andrew Jones 
Signed-off-by: Wei Huang 
---
 tests/migration-test.c   | 28 ++--
 tests/migration/migration-test.h | 21 +
 2 files changed, 39 insertions(+), 10 deletions(-)
 create mode 100644 tests/migration/migration-test.h

diff --git a/tests/migration-test.c b/tests/migration-test.c
index fe6b41a..17c6896 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -21,11 +21,13 @@
 #include "chardev/char.h"
 #include "sysemu/sysemu.h"
 
+#include "migration/migration-test.h"
+
 /* TODO actually test the results and get rid of this */
 #define qtest_qmp_discard_response(...) qobject_unref(qtest_qmp(__VA_ARGS__))
 
-const unsigned start_address = 1024 * 1024;
-const unsigned end_address = 100 * 1024 * 1024;
+unsigned start_address;
+unsigned end_address;
 bool got_stop;
 static bool uffd_feature_thread_id;
 
@@ -80,8 +82,8 @@ static bool ufd_version_check(void)
 
 static const char *tmpfs;
 
-/* A simple PC boot sector that modifies memory (1-100MB) quickly
- * outputting a 'B' every so often if it's still running.
+/* The boot file modifies memory area in [start_address, end_address)
+ * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
  */
 #include "tests/migration/i386/a-b-bootblock.h"
 
@@ -270,11 +272,11 @@ static void wait_for_migration_pass(QTestState *who)
 static void check_guests_ram(QTestState *who)
 {
 /* Our ASM test will have been incrementing one byte from each page from
- * 1MB to <100MB in order.
- * This gives us a constraint that any page's byte should be equal or less
- * than the previous pages byte (mod 256); and they should all be equal
- * except for one transition at the point where we meet the incrementer.
- * (We're running this with the guest stopped).
+ * start_address to < end_address in order. This gives us a constraint
+ * that any page's byte should be equal or less than the previous pages
+ * byte (mod 256); and they should all be equal except for one transition
+ * at the point where we meet the incrementer. (We're running this with
+ * the guest stopped).
  */
 unsigned address;
 uint8_t first_byte;
@@ -285,7 +287,8 @@ static void check_guests_ram(QTestState *who)
 qtest_memread(who, start_address, _byte, 1);
 last_byte = first_byte;
 
-for (address = start_address + 4096; address < end_address; address += 
4096)
+for (address = start_address + TEST_MEM_PAGE_SIZE; address < end_address;
+ address += TEST_MEM_PAGE_SIZE)
 {
 uint8_t b;
 qtest_memread(who, address, , 1);
@@ -437,6 +440,8 @@ static int test_migrate_start(QTestState **from, QTestState 
**to,
   " -drive file=%s,format=raw"
   " -incoming %s",
   accel, tmpfs, bootpath, uri);
+start_address = X86_TEST_MEM_START;
+end_address = X86_TEST_MEM_END;
 } else if (strcmp(arch, "ppc64") == 0) {
 cmd_src = g_strdup_printf("-machine accel=%s -m 256M"
   " -name source,debug-threads=on"
@@ -451,6 +456,9 @@ static int test_migrate_start(QTestState **from, QTestState 
**to,
   " -serial file:%s/dest_serial"
   " -incoming %s",
   accel, tmpfs, uri);
+
+start_address = PPC_TEST_MEM_START;
+end_address = PPC_TEST_MEM_END;
 } else {
 g_assert_not_reached();
 }
diff --git a/tests/migration/migration-test.h b/tests/migration/migration-test.h
new file mode 100644
index 000..c4c0c52
--- /dev/null
+++ b/tests/migration/migration-test.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2018 Red Hat, Inc. and/or its affiliates
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#ifndef _TEST_MIGRATION_H_
+#define _TEST_MIGRATION_H_
+
+/* Common */
+#define TEST_MEM_PAGE_SIZE 4096
+
+/* x86 */
+#define X86_TEST_MEM_START (1 * 1024 * 1024)
+#define X86_TEST_MEM_END   (100 * 1024 * 1024)
+
+/* PPC */
+#define PPC_TEST_MEM_START (1 * 1024 * 1024)
+#define PPC_TEST_MEM_END   (100 * 1024 * 1024)
+
+#endif /* _TEST_MIGRATION_H_ */
-- 
1.8.3.1




[Qemu-devel] [PATCH V9 0/4] tests: Add migration test for aarch64

2018-09-05 Thread Wei Huang
This patchset adds a migration test for aarch64. It leverages
Dave Gilbert's migration boot block patches to create a new test case
for aarch64.

V8->V9:
 * Remove accel= setting for AArch64. It uses the default "kvm:tcg" now
 * Revise the header file comment (suggested by drjones)
 * Name x86 directory to i386 instead of x86_64; change Makefile accordingly
 * Remove $(ARCH) from the assembly and header file names

V7->V8:
 * Support cross compilation by searching for CROSS_CC_GUEST option,
   instead of using the find-cross-prefix defined in roms/Makefile
 * Use the "max" options for ARM guest VM's CPU and GIC types
 * $(TARGET)/Makefile rules are rewritten based on Laurent Vivier's comment
 * NOTE: because Patch 1/2 is re-written, I remove the "Reviewed-by" for
   reviewers to take a look again. Thanks.

V6->V7:
 * Define test memory start/end addresses for all architectures
 * Check aarch64 kernel binary size, limit under 512KB

V5->V6:
 * Add Reviewed-by to patch 1-3
 * Add more design notes in patch 4 (aarch64 assembly compilation, bin space)

V4->V5:
 * Extract cross compilation detection code into rules.mak for sharing
 * Minor comment and code revision in migration-test.c & aarch64-a-b-kernel.S
 
V3->V4:
 * Rename .s to .S, allowing assembly to include C-style header file
 * Move test defines into a new migration-test.h file
 * Use different cpu & gic settings for kvm and tcg modes on aarch64
 * Clean up aarch64-a-b-kernel.S based on Andrew Jones' comments
 
V2->V3:
 * Convert build script to Makefile
 * Add cross-compilation support
 * Fix CPU type for "tcg" machine type
 * Revise asm code and the compilation process from asm to header file

V1->V2:
 * Similar to Dave Gilbert's recent changes to migration-test, we
   provide the test source and a build script in V2.
 * aarch64 kernel blob is defined as "unsigned char" because the source
   is now provided in V2.
 * Add "-machine none" to test_deprecated() because aarch64 doesn't have
   a default machine type.

RFC->V1:
 * aarch64 kernel blob is defined as an uint32_t array
 * The test code is re-written to address a data caching issue under KVM.
   Tests passed under both x86 and aarch64.
 * Re-use init_bootfile_x86() for both x86 and aarch64
 * Other minor fixes

Thanks,
-Wei

Wei Huang (4):
  tests/migration: Convert x86 boot block compilation script into
Makefile
  tests/migration: Support cross compilation in generating boot header
file
  tests/migration: Add migration-test header file
  tests: Add migration test for aarch64

 tests/Makefile.include |  1 +
 tests/migration-test.c | 57 +++-
 tests/migration/Makefile   | 35 ++
 tests/migration/aarch64/Makefile   | 20 ++
 tests/migration/aarch64/a-b-kernel.S   | 75 ++
 tests/migration/aarch64/a-b-kernel.h   | 19 ++
 tests/migration/i386/Makefile  | 22 +++
 .../{x86-a-b-bootblock.s => i386/a-b-bootblock.S}  |  4 --
 .../{x86-a-b-bootblock.h => i386/a-b-bootblock.h}  |  8 +--
 tests/migration/migration-test.h   | 30 +
 tests/migration/rebuild-x86-bootblock.sh   | 33 --
 11 files changed, 248 insertions(+), 56 deletions(-)
 create mode 100644 tests/migration/Makefile
 create mode 100644 tests/migration/aarch64/Makefile
 create mode 100644 tests/migration/aarch64/a-b-kernel.S
 create mode 100644 tests/migration/aarch64/a-b-kernel.h
 create mode 100644 tests/migration/i386/Makefile
 rename tests/migration/{x86-a-b-bootblock.s => i386/a-b-bootblock.S} (93%)
 rename tests/migration/{x86-a-b-bootblock.h => i386/a-b-bootblock.h} (92%)
 create mode 100644 tests/migration/migration-test.h
 delete mode 100755 tests/migration/rebuild-x86-bootblock.sh

-- 
1.8.3.1




[Qemu-devel] [PATCH V9 2/4] tests/migration: Support cross compilation in generating boot header file

2018-09-05 Thread Wei Huang
Recently a new configure option, CROSS_CC_GUEST, was added to
$(TARGET)-softmmu/config-target.mak to support TCG-related tests. This
patch tries to leverage this option to support cross compilation when the
migration boot block file is being re-generated:

 * The x86 related files are moved to a new sub-dir (named ./i386).
 * A new top-layer Makefile is created in tests/migration/ directory.
   This Makefile searches and parses CROSS_CC_GUEST to generate CROSS_PREFIX.
   The CROSS_PREFIX, if available, is then passed to migration/$ARCH/Makefile.

Reviewed-by: Juan Quintela 
Signed-off-by: Wei Huang 
---
 tests/migration-test.c |  2 +-
 tests/migration/Makefile   | 44 --
 tests/migration/i386/Makefile  | 22 +++
 .../{x86-a-b-bootblock.S => i386/a-b-bootblock.S}  |  4 --
 .../{x86-a-b-bootblock.h => i386/a-b-bootblock.h}  |  8 ++--
 5 files changed, 51 insertions(+), 29 deletions(-)
 create mode 100644 tests/migration/i386/Makefile
 rename tests/migration/{x86-a-b-bootblock.S => i386/a-b-bootblock.S} (93%)
 rename tests/migration/{x86-a-b-bootblock.h => i386/a-b-bootblock.h} (92%)

diff --git a/tests/migration-test.c b/tests/migration-test.c
index 0e687b7..fe6b41a 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -83,7 +83,7 @@ static const char *tmpfs;
 /* A simple PC boot sector that modifies memory (1-100MB) quickly
  * outputting a 'B' every so often if it's still running.
  */
-#include "tests/migration/x86-a-b-bootblock.h"
+#include "tests/migration/i386/a-b-bootblock.h"
 
 static void init_bootfile_x86(const char *bootpath)
 {
diff --git a/tests/migration/Makefile b/tests/migration/Makefile
index c0824b4..a9ed875 100644
--- a/tests/migration/Makefile
+++ b/tests/migration/Makefile
@@ -1,31 +1,35 @@
-# To specify cross compiler prefix, use CROSS_PREFIX=
-#   $ make CROSS_PREFIX=x86_64-linux-gnu-
+#
+# Copyright (c) 2018 Red Hat, Inc. and/or its affiliates
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+#
+
+TARGET_LIST = i386
+
+SRC_PATH = ../..
 
 override define __note
-/* This file is automatically generated from
- * tests/migration/x86-a-b-bootblock.S, edit that and then run
- * tests/migration/rebuild-x86-bootblock.sh to update,
- * and then remember to send both in your patch submission.
+/* This file is automatically generated from the assembly file in
+ * tests/migration/$@. Edit that file and then run "make all"
+ * inside tests/migration to update, and then remember to send both
+ * the header and the assembler differences in your patch submission.
  */
 endef
 export __note
 
-.PHONY: all clean
-all: x86-a-b-bootblock.h
-
-x86-a-b-bootblock.h: x86.bootsect
-   echo "$$__note" > header.tmp
-   xxd -i $< | sed -e 's/.*int.*//' >> header.tmp
-   mv header.tmp $@
+find-arch-cross-cc = $(lastword $(shell grep -h "CROSS_CC_GUEST=" $(wildcard 
$(SRC_PATH)/$(patsubst i386,*86*,$(1))-softmmu/config-target.mak)))
+parse-cross-prefix = $(subst gcc,,$(patsubst cc,gcc,$(patsubst 
CROSS_CC_GUEST="%",%,$(call find-arch-cross-cc,$(1)
+gen-cross-prefix = $(patsubst %-,CROSS_PREFIX=%-,$(call 
parse-cross-prefix,$(1)))
 
-x86.bootsect: x86.boot
-   dd if=$< of=$@ bs=256 count=2 skip=124
+.PHONY: all $(TARGET_LIST)
 
-x86.boot: x86.o
-   $(CROSS_PREFIX)objcopy -O binary $< $@
+all: $(TARGET_LIST)
 
-x86.o: x86-a-b-bootblock.S
-   $(CROSS_PREFIX)gcc -m32 -march=i486 -c $< -o $@
+$(TARGET_LIST):
+   $(MAKE) -C $@ $(call gen-cross-prefix,$@)
 
 clean:
-   @rm -rf *.boot *.o *.bootsect
+   for target in $(TARGET_LIST); do \
+   $(MAKE) -C $$target clean; \
+   done
diff --git a/tests/migration/i386/Makefile b/tests/migration/i386/Makefile
new file mode 100644
index 000..5c03241
--- /dev/null
+++ b/tests/migration/i386/Makefile
@@ -0,0 +1,22 @@
+# To specify cross compiler prefix, use CROSS_PREFIX=
+#   $ make CROSS_PREFIX=x86_64-linux-gnu-
+
+.PHONY: all clean
+all: a-b-bootblock.h
+
+a-b-bootblock.h: x86.bootsect
+   echo "$$__note" > header.tmp
+   xxd -i $< | sed -e 's/.*int.*//' >> header.tmp
+   mv header.tmp $@
+
+x86.bootsect: x86.boot
+   dd if=$< of=$@ bs=256 count=2 skip=124
+
+x86.boot: x86.o
+   $(CROSS_PREFIX)objcopy -O binary $< $@
+
+x86.o: a-b-bootblock.S
+   $(CROSS_PREFIX)gcc -m32 -march=i486 -c $< -o $@
+
+clean:
+   @rm -rf *.boot *.o *.bootsect
diff --git a/tests/migration/x86-a-b-bootblock.S 
b/tests/migration/i386/a-b-bootblock.S
similarity index 93%
rename from tests/migration/x86-a-b-bootblock.S
rename to tests/migration/i386/a-b-bootblock.S
index b164264..3f97f28 100644
--- a/tests/migration/x86-a-b-bootblock.S
+++ b/tests/migration/i386/a-b-bootblock.S
@@ -3,10 +3,6 @@
 #

Re: [Qemu-devel] [PATCH V8 2/4] tests/migration: Support cross compilation in generating boot header file

2018-09-04 Thread Wei Huang



- Original Message -
> From: "Andrew Jones" 
> To: "Wei Huang" 
> Cc: qemu-devel@nongnu.org, lviv...@redhat.com, "peter maydell" 
> , quint...@redhat.com,
> dgilb...@redhat.com
> Sent: Monday, September 3, 2018 6:26:39 AM
> Subject: Re: [Qemu-devel] [PATCH V8 2/4] tests/migration: Support cross 
> compilation in generating boot header file
> 
> On Sat, Sep 01, 2018 at 01:11:13AM -0400, Wei Huang wrote:
> > Recently a new configure option, CROSS_CC_GUEST, was added to
> > $(TARGET)-softmmu/config-target.mak to support TCG-related tests. This
> > patch tries to leverage this option to support cross compilation when the
> > migration boot block file is being re-generated:
> > 
> >  * The x86_64 related files are moved to a new sub-dir (named ./x86_64).
> >  * A new top-layer Makefile is created in tests/migration/ directory.
> >This Makefile searches and parses CROSS_CC_GUEST to generate
> >CROSS_PREFIX.
> >The CROSS_PREFIX, if available, is then passed to
> >migration/$ARCH/Makefile.
> > 
> > Signed-off-by: Wei Huang 
> > ---
> >  tests/migration-test.c   |  2 +-
> >  tests/migration/Makefile | 43
> >  +---
> >  tests/migration/x86_64/Makefile  | 22 
> >  tests/migration/{ => x86_64}/x86-a-b-bootblock.S |  0
> >  tests/migration/{ => x86_64}/x86-a-b-bootblock.h |  8 ++---
> >  5 files changed, 50 insertions(+), 25 deletions(-)
> >  create mode 100644 tests/migration/x86_64/Makefile
> >  rename tests/migration/{ => x86_64}/x86-a-b-bootblock.S (100%)
> >  rename tests/migration/{ => x86_64}/x86-a-b-bootblock.h (93%)
> > 
> > diff --git a/tests/migration-test.c b/tests/migration-test.c
> > index 0e687b7..c4d79e9 100644
> > --- a/tests/migration-test.c
> > +++ b/tests/migration-test.c
> > @@ -83,7 +83,7 @@ static const char *tmpfs;
> >  /* A simple PC boot sector that modifies memory (1-100MB) quickly
> >   * outputting a 'B' every so often if it's still running.
> >   */
> > -#include "tests/migration/x86-a-b-bootblock.h"
> > +#include "tests/migration/x86_64/x86-a-b-bootblock.h"
> 
> Is x86-a-b-bootblock.h specific to x86_64, or both i386 and x86_64?
> I think we want the dir name to be i386 if it's the later. Also,
> we could drop the 'x86-' prefix from the filename, now that the
> directory identifies the arch.

Well, I can try it. But this will make the Makefile more complicated as we have 
to detect x86_64 compiler for i386 binary (most distros only ship x86_64 cross 
compiler).

> 
> >  
> >  static void init_bootfile_x86(const char *bootpath)
> >  {
> > diff --git a/tests/migration/Makefile b/tests/migration/Makefile
> > index 5d5fa07..1de480e 100644
> > --- a/tests/migration/Makefile
> > +++ b/tests/migration/Makefile
> > @@ -1,31 +1,34 @@
> > -# To specify cross compiler prefix, use CROSS_PREFIX=
> > -#   > make CROSS_PREFIX=x86_64-linux-gnu-
> > +#
> > +# Copyright (c) 2018 Red Hat, Inc. and/or its affiliates
> > +#
> > +# This work is licensed under the terms of the GNU GPL, version 2 or
> > later.
> > +# See the COPYING file in the top-level directory.
> > +#
> > +
> > +TARGET_LIST = x86_64
> > +
> > +SRC_PATH = ../..
> >  
> >  override define __note
> > -/* This file is automatically generated from
> > - * tests/migration/x86-a-b-bootblock.s, edit that and then run
> > - * tests/migration/rebuild-x86-bootblock.sh to update,
> > - * and then remember to send both in your patch submission.
> > +/* This file is automatically generated from the assembly file in
> > + * tests/migration/$@, edit that and then run "make all"
> 
> nit: /, edit that/. Edit that file/
> 
> > + * inside tests/migration to update, and then remember to send both
> > + * in your patch submission.
> nit: ^ the header and the assembler differences
> 
> >   */
> >  endef
> >  export __note
> >  
> > -.PHONY: all clean
> > -all: x86-a-b-bootblock.h
> > -
> > -x86-a-b-bootblock.h: x86.bootsect
> > -   echo "$$__note" > header.tmp
> > -   xxd -i $< | sed -e 's/.*int.*//' >> header.tmp
> > -   mv header.tmp $@
> > +parse-cross-prefix = $(subst gcc,,$(patsubst cc,gcc,$(patsubst
> > CROSS_CC_GUEST="%",%,$(shell grep "CROSS_CC_GUEST="
> > $(SRC_PATH)/$(1)-softmmu/config-target.mak
> > +gen-cross-prefix = $(patsubst %-,CROSS_PREFIX=%-,$(call
> > pars

Re: [Qemu-devel] [PATCH V8 4/4] tests: Add migration test for aarch64

2018-09-04 Thread Wei Huang



- Original Message -
> From: "Andrew Jones" 
> To: "Wei Huang" 
> Cc: qemu-devel@nongnu.org, lviv...@redhat.com, "peter maydell" 
> , quint...@redhat.com,
> dgilb...@redhat.com
> Sent: Monday, September 3, 2018 6:53:35 AM
> Subject: Re: [Qemu-devel] [PATCH V8 4/4] tests: Add migration test for aarch64
> 
> On Sat, Sep 01, 2018 at 01:11:15AM -0400, Wei Huang wrote:
> > +.section .text
> > +
> > +.globl  _start
> > +
> > +_start:
> > +/* disable MMU to use phys mem address */
> > +mrs x0, sctlr_el1
> > +bic x0, x0, #(1<<0)
> > +msr sctlr_el1, x0
> > +isb
> > +
> > +/* traverse test memory region */
> > +mov x0, #ARM_TEST_MEM_START
> > +mov x1, #ARM_TEST_MEM_END
> 
> I don't think there's any reason to require the start and
> end addresses to be hard coded. We should be able to get
> the start address with

Are you saying that we should make the .S file as independent as possible? 
These variables need to be defined for migration-test.c anyway. Why can't we 
just use them here?

> 
> #define KERNEL_OFFSET 0x8
>adr x0, _start
>add x0, x0, #(1024 * 1024 - KERNEL_OFFSET)
> 
> and the end address with
> 
>add x1, x0, #(99 * 1024 * 1024)
> 
> Thanks,
> drew
> 



Re: [Qemu-devel] [PATCH V8 1/4] tests/migration: Convert x86 boot block compilation script into Makefile

2018-09-04 Thread Wei Huang



On 09/03/2018 06:08 AM, Andrew Jones wrote:
> On Sat, Sep 01, 2018 at 01:11:12AM -0400, Wei Huang wrote:
>> The x86 boot block header currently is generated with a shell script.
>> To better support other CPUs (e.g. aarch64), we convert the script
>> into Makefile. This allows us to 1) support cross-compilation easily,
>> and 2) avoid creating a script file for every architecture.
>>
>> Note that, in the new design, the cross compiler prefix can be specified by
>> setting the CROSS_PREFIX in "make" command. Also to allow gcc pre-processor
>> to include the C-style file correctly, it also renames the
>> x86-a-b-bootblock.s file extension from .s to .S.
>>
>> Signed-off-by: Wei Huang 
>> ---
>>  tests/migration/Makefile   | 31 
>>  tests/migration/rebuild-x86-bootblock.sh   | 33 
>> --
>>  .../{x86-a-b-bootblock.s => x86-a-b-bootblock.S}   |  0
>>  3 files changed, 31 insertions(+), 33 deletions(-)
>>  create mode 100644 tests/migration/Makefile
>>  delete mode 100755 tests/migration/rebuild-x86-bootblock.sh
>>  rename tests/migration/{x86-a-b-bootblock.s => x86-a-b-bootblock.S} (100%)
>>
>> diff --git a/tests/migration/Makefile b/tests/migration/Makefile
>> new file mode 100644
>> index 000..5d5fa07
>> --- /dev/null
>> +++ b/tests/migration/Makefile
>> @@ -0,0 +1,31 @@
>> +# To specify cross compiler prefix, use CROSS_PREFIX=
>> +#   > make CROSS_PREFIX=x86_64-linux-gnu-
>^ nit: this prompt symbol is weird (at least to me, what shell uses
>   this?) To me it looks like a sh/bash redirect symbol. Can
>   we change it to '$' or use nothing at all?

I will replace '>' with '$', which is indeed the commonly-used one.

>> +
>> +override define __note
>> +/* This file is automatically generated from
>> + * tests/migration/x86-a-b-bootblock.s, edit that and then run
> ^ should be 'S'

OK, will do.

> 
>> + * tests/migration/rebuild-x86-bootblock.sh to update,
>> + * and then remember to send both in your patch submission.
>> + */
>> +endef
>> +export __note
>> +
>> +.PHONY: all clean
>> +all: x86-a-b-bootblock.h
>> +
>> +x86-a-b-bootblock.h: x86.bootsect
>> +echo "$$__note" > header.tmp
>> +xxd -i $< | sed -e 's/.*int.*//' >> header.tmp
>> +mv header.tmp $@
> 
> The shell script this Makefile is replacing used mktemp
> for a randomly named tmp dir. Shouldn't we continue to
> use random names?>
>> +
>> +x86.bootsect: x86.boot
>> +dd if=$< of=$@ bs=256 count=2 skip=124
>> +
>> +x86.boot: x86.o
>> +$(CROSS_PREFIX)objcopy -O binary $< $@
>> +
>> +x86.o: x86-a-b-bootblock.S
>> +$(CROSS_PREFIX)gcc -m32 -march=i486 -c $< -o $@
>> +
>> +clean:
>> +@rm -rf *.boot *.o *.bootsect
> 
> We don't want to remove the generated header file when cleaning?
> 
>> diff --git a/tests/migration/rebuild-x86-bootblock.sh 
>> b/tests/migration/rebuild-x86-bootblock.sh
>> deleted file mode 100755
>> index 86cec5d..000
>> --- a/tests/migration/rebuild-x86-bootblock.sh
>> +++ /dev/null
>> @@ -1,33 +0,0 @@
>> -#!/bin/sh
>> -# Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
>> -# This work is licensed under the terms of the GNU GPL, version 2 or later.
>> -# See the COPYING file in the top-level directory.
>> -#
>> -# Author: dgilb...@redhat.com
>> -
>> -ASMFILE=$PWD/tests/migration/x86-a-b-bootblock.s
>> -HEADER=$PWD/tests/migration/x86-a-b-bootblock.h
>> -
>> -if [ ! -e "$ASMFILE" ]
>> -then
>> -  echo "Couldn't find $ASMFILE" >&2
>> -  exit 1
>> -fi
>> -
>> -ASM_WORK_DIR=$(mktemp -d --tmpdir X86BB.XX)
>> -cd "$ASM_WORK_DIR" &&
>> -as --32 -march=i486 "$ASMFILE" -o x86.o &&
>> -objcopy -O binary x86.o x86.boot &&
>> -dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124 &&
>> -xxd -i x86.bootsect |
>> -sed -e 's/.*int.*//' > x86.hex &&
>> -cat - x86.hex < "$HEADER"
>> -/* This file is automatically generated from
>> - * tests/migration/x86-a-b-bootblock.s, edit that and then run
>> - * tests/migration/rebuild-x86-bootblock.sh to update,
>> - * and then remember to send both in your patch submission.
>> - */
>> -HERE
>> -
>> -rm x86.hex x86.bootsect x86.boot x86.o
>> -cd .. && rmdir "$ASM_WORK_DIR"
>> diff --git a/tests/migration/x86-a-b-bootblock.s 
>> b/tests/migration/x86-a-b-bootblock.S
>> similarity index 100%
>> rename from tests/migration/x86-a-b-bootblock.s
>> rename to tests/migration/x86-a-b-bootblock.S
>> -- 
>> 1.8.3.1
>>
>>
> 
> Thanks,
> drew 
> 



Re: [Qemu-devel] [PATCH V8 4/4] tests: Add migration test for aarch64

2018-09-01 Thread Wei Huang



On 09/01/2018 05:07 AM, Peter Maydell wrote:
> On 1 September 2018 at 06:11, Wei Huang  wrote:
>> This patch adds migration test support for aarch64. The test code, which
>> implements the same functionality as x86, is booted as a kernel in qemu.
>> Here are the design choices we make for aarch64:
>>
>>  * We choose this -kernel approach because aarch64 QEMU doesn't provide a
>>built-in fw like x86 does. So instead of relying on a boot loader, we
>>use -kernel approach for aarch64.
>>  * The serial output is sent to PL011 directly.
>>  * The physical memory base for mach-virt machine is 0x4000. We change
>>the start_address and end_address for aarch64.
>>
>> In addition to providing the binary, this patch also includes the source
>> code and the build script in tests/migration/aarch64. So users can change
>> the source and/or re-compile the binary as they wish.
>> +} else if (strcmp(arch, "aarch64") == 0) {
>> +struct utsname utsname;
>> +
> 
> The comment says:
> 
>> +/* kvm and tcg need different cpu and gic-version configs */
> 
> ...but the code below it doesn't change the cpu or gic-version
> based on 'accel'.

My bad. The code below can be removed.

> 
>> +if (access("/dev/kvm", F_OK) == 0 && uname() == 0 &&
>> +strcmp(utsname.machine, "aarch64") == 0) {
>> +accel = "kvm";
>> +} else {
>> +accel = "tcg";
>> +}
> 
> Maybe we could just use -accel=kvm,tcg rather than guessing
> whether kvm is going to work ? If this is how the x86 code
> works then probably best to do the same as that, though.

Yes, "kvm,tcg" work work (I just verified with "tcg" only). I will
update the code after more comments are collected.

> 
>> +
>> +init_bootfile(bootpath, aarch64_kernel);
>> +cmd_src = g_strdup_printf("-machine virt,accel=%s,gic-version=max "
>> +  "-name vmsource,debug-threads=on -cpu max 
>> "
>> +  "-m 150M -serial file:%s/src_serial "
>> +  "-kernel %s ",
>> +  accel, tmpfs, bootpath);
>> +cmd_dst = g_strdup_printf("-machine virt,accel=%s,gic-version=max "
>> +  "-name vmdest,debug-threads=on -cpu max "
>> +  "-m 150M -serial file:%s/dest_serial "
>> +  "-kernel %s "
>> +  "-incoming %s ",
>> +  accel, tmpfs, bootpath, uri);
>> +
>> +start_address = ARM_TEST_MEM_START;
>> +end_address = ARM_TEST_MEM_END;
>> +
>> +g_assert(sizeof(aarch64_kernel) <= ARM_TEST_MAX_KERNEL_SIZE);
> 
> thanks
> -- PMM
> 



[Qemu-devel] [PATCH V8 3/4] tests/migration: Add migration-test header file

2018-08-31 Thread Wei Huang
This patch moves the settings related migration-test from the
migration-test.c file to a new header file.

Signed-off-by: Wei Huang 
---
 tests/migration-test.c   | 28 ++--
 tests/migration/migration-test.h | 21 +
 2 files changed, 39 insertions(+), 10 deletions(-)
 create mode 100644 tests/migration/migration-test.h

diff --git a/tests/migration-test.c b/tests/migration-test.c
index c4d79e9..bf60fa0 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -21,11 +21,13 @@
 #include "chardev/char.h"
 #include "sysemu/sysemu.h"
 
+#include "migration/migration-test.h"
+
 /* TODO actually test the results and get rid of this */
 #define qtest_qmp_discard_response(...) qobject_unref(qtest_qmp(__VA_ARGS__))
 
-const unsigned start_address = 1024 * 1024;
-const unsigned end_address = 100 * 1024 * 1024;
+unsigned start_address;
+unsigned end_address;
 bool got_stop;
 static bool uffd_feature_thread_id;
 
@@ -80,8 +82,8 @@ static bool ufd_version_check(void)
 
 static const char *tmpfs;
 
-/* A simple PC boot sector that modifies memory (1-100MB) quickly
- * outputting a 'B' every so often if it's still running.
+/* The boot file modifies memory area in [start_address, end_address)
+ * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
  */
 #include "tests/migration/x86_64/x86-a-b-bootblock.h"
 
@@ -270,11 +272,11 @@ static void wait_for_migration_pass(QTestState *who)
 static void check_guests_ram(QTestState *who)
 {
 /* Our ASM test will have been incrementing one byte from each page from
- * 1MB to <100MB in order.
- * This gives us a constraint that any page's byte should be equal or less
- * than the previous pages byte (mod 256); and they should all be equal
- * except for one transition at the point where we meet the incrementer.
- * (We're running this with the guest stopped).
+ * start_address to < end_address in order. This gives us a constraint
+ * that any page's byte should be equal or less than the previous pages
+ * byte (mod 256); and they should all be equal except for one transition
+ * at the point where we meet the incrementer. (We're running this with
+ * the guest stopped).
  */
 unsigned address;
 uint8_t first_byte;
@@ -285,7 +287,8 @@ static void check_guests_ram(QTestState *who)
 qtest_memread(who, start_address, _byte, 1);
 last_byte = first_byte;
 
-for (address = start_address + 4096; address < end_address; address += 
4096)
+for (address = start_address + TEST_MEM_PAGE_SIZE; address < end_address;
+ address += TEST_MEM_PAGE_SIZE)
 {
 uint8_t b;
 qtest_memread(who, address, , 1);
@@ -437,6 +440,8 @@ static int test_migrate_start(QTestState **from, QTestState 
**to,
   " -drive file=%s,format=raw"
   " -incoming %s",
   accel, tmpfs, bootpath, uri);
+start_address = X86_TEST_MEM_START;
+end_address = X86_TEST_MEM_END;
 } else if (strcmp(arch, "ppc64") == 0) {
 cmd_src = g_strdup_printf("-machine accel=%s -m 256M"
   " -name source,debug-threads=on"
@@ -451,6 +456,9 @@ static int test_migrate_start(QTestState **from, QTestState 
**to,
   " -serial file:%s/dest_serial"
   " -incoming %s",
   accel, tmpfs, uri);
+
+start_address = PPC_TEST_MEM_START;
+end_address = PPC_TEST_MEM_END;
 } else {
 g_assert_not_reached();
 }
diff --git a/tests/migration/migration-test.h b/tests/migration/migration-test.h
new file mode 100644
index 000..c4c0c52
--- /dev/null
+++ b/tests/migration/migration-test.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2018 Red Hat, Inc. and/or its affiliates
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#ifndef _TEST_MIGRATION_H_
+#define _TEST_MIGRATION_H_
+
+/* Common */
+#define TEST_MEM_PAGE_SIZE 4096
+
+/* x86 */
+#define X86_TEST_MEM_START (1 * 1024 * 1024)
+#define X86_TEST_MEM_END   (100 * 1024 * 1024)
+
+/* PPC */
+#define PPC_TEST_MEM_START (1 * 1024 * 1024)
+#define PPC_TEST_MEM_END   (100 * 1024 * 1024)
+
+#endif /* _TEST_MIGRATION_H_ */
-- 
1.8.3.1




[Qemu-devel] [PATCH V8 2/4] tests/migration: Support cross compilation in generating boot header file

2018-08-31 Thread Wei Huang
Recently a new configure option, CROSS_CC_GUEST, was added to
$(TARGET)-softmmu/config-target.mak to support TCG-related tests. This
patch tries to leverage this option to support cross compilation when the
migration boot block file is being re-generated:

 * The x86_64 related files are moved to a new sub-dir (named ./x86_64).
 * A new top-layer Makefile is created in tests/migration/ directory.
   This Makefile searches and parses CROSS_CC_GUEST to generate CROSS_PREFIX.
   The CROSS_PREFIX, if available, is then passed to migration/$ARCH/Makefile.

Signed-off-by: Wei Huang 
---
 tests/migration-test.c   |  2 +-
 tests/migration/Makefile | 43 +---
 tests/migration/x86_64/Makefile  | 22 
 tests/migration/{ => x86_64}/x86-a-b-bootblock.S |  0
 tests/migration/{ => x86_64}/x86-a-b-bootblock.h |  8 ++---
 5 files changed, 50 insertions(+), 25 deletions(-)
 create mode 100644 tests/migration/x86_64/Makefile
 rename tests/migration/{ => x86_64}/x86-a-b-bootblock.S (100%)
 rename tests/migration/{ => x86_64}/x86-a-b-bootblock.h (93%)

diff --git a/tests/migration-test.c b/tests/migration-test.c
index 0e687b7..c4d79e9 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -83,7 +83,7 @@ static const char *tmpfs;
 /* A simple PC boot sector that modifies memory (1-100MB) quickly
  * outputting a 'B' every so often if it's still running.
  */
-#include "tests/migration/x86-a-b-bootblock.h"
+#include "tests/migration/x86_64/x86-a-b-bootblock.h"
 
 static void init_bootfile_x86(const char *bootpath)
 {
diff --git a/tests/migration/Makefile b/tests/migration/Makefile
index 5d5fa07..1de480e 100644
--- a/tests/migration/Makefile
+++ b/tests/migration/Makefile
@@ -1,31 +1,34 @@
-# To specify cross compiler prefix, use CROSS_PREFIX=
-#   > make CROSS_PREFIX=x86_64-linux-gnu-
+#
+# Copyright (c) 2018 Red Hat, Inc. and/or its affiliates
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+#
+
+TARGET_LIST = x86_64
+
+SRC_PATH = ../..
 
 override define __note
-/* This file is automatically generated from
- * tests/migration/x86-a-b-bootblock.s, edit that and then run
- * tests/migration/rebuild-x86-bootblock.sh to update,
- * and then remember to send both in your patch submission.
+/* This file is automatically generated from the assembly file in
+ * tests/migration/$@, edit that and then run "make all"
+ * inside tests/migration to update, and then remember to send both
+ * in your patch submission.
  */
 endef
 export __note
 
-.PHONY: all clean
-all: x86-a-b-bootblock.h
-
-x86-a-b-bootblock.h: x86.bootsect
-   echo "$$__note" > header.tmp
-   xxd -i $< | sed -e 's/.*int.*//' >> header.tmp
-   mv header.tmp $@
+parse-cross-prefix = $(subst gcc,,$(patsubst cc,gcc,$(patsubst 
CROSS_CC_GUEST="%",%,$(shell grep "CROSS_CC_GUEST=" 
$(SRC_PATH)/$(1)-softmmu/config-target.mak
+gen-cross-prefix = $(patsubst %-,CROSS_PREFIX=%-,$(call 
parse-cross-prefix,$(1)))
 
-x86.bootsect: x86.boot
-   dd if=$< of=$@ bs=256 count=2 skip=124
+.PHONY: all $(TARGET_LIST)
 
-x86.boot: x86.o
-   $(CROSS_PREFIX)objcopy -O binary $< $@
+all: $(TARGET_LIST)
 
-x86.o: x86-a-b-bootblock.S
-   $(CROSS_PREFIX)gcc -m32 -march=i486 -c $< -o $@
+$(TARGET_LIST):
+   $(MAKE) -C $@ $(call gen-cross-prefix,$@)
 
 clean:
-   @rm -rf *.boot *.o *.bootsect
+   for target in $(TARGET_LIST); do \
+   $(MAKE) -C $$target clean; \
+   done
diff --git a/tests/migration/x86_64/Makefile b/tests/migration/x86_64/Makefile
new file mode 100644
index 000..6dc849f
--- /dev/null
+++ b/tests/migration/x86_64/Makefile
@@ -0,0 +1,22 @@
+# To specify cross compiler prefix, use CROSS_PREFIX=
+#   > make CROSS_PREFIX=x86_64-linux-gnu-
+
+.PHONY: all clean
+all: x86-a-b-bootblock.h
+
+x86-a-b-bootblock.h: x86.bootsect
+   echo "$$__note" > header.tmp
+   xxd -i $< | sed -e 's/.*int.*//' >> header.tmp
+   mv header.tmp $@
+
+x86.bootsect: x86.boot
+   dd if=$< of=$@ bs=256 count=2 skip=124
+
+x86.boot: x86.o
+   $(CROSS_PREFIX)objcopy -O binary $< $@
+
+x86.o: x86-a-b-bootblock.S
+   $(CROSS_PREFIX)gcc -m32 -march=i486 -c $< -o $@
+
+clean:
+   @rm -rf *.boot *.o *.bootsect
diff --git a/tests/migration/x86-a-b-bootblock.S 
b/tests/migration/x86_64/x86-a-b-bootblock.S
similarity index 100%
rename from tests/migration/x86-a-b-bootblock.S
rename to tests/migration/x86_64/x86-a-b-bootblock.S
diff --git a/tests/migration/x86-a-b-bootblock.h 
b/tests/migration/x86_64/x86-a-b-bootblock.h
similarity index 93%
rename from tests/migration/x86-a-b-bootblock.h
rename to tests/migration/x86_64/x86-a-b-bootblock.h
index 78a151f..73670ef 100644
--- a/tests/migration/x86-a-b-bootblock.h
+++ b/te

[Qemu-devel] [PATCH V8 1/4] tests/migration: Convert x86 boot block compilation script into Makefile

2018-08-31 Thread Wei Huang
The x86 boot block header currently is generated with a shell script.
To better support other CPUs (e.g. aarch64), we convert the script
into Makefile. This allows us to 1) support cross-compilation easily,
and 2) avoid creating a script file for every architecture.

Note that, in the new design, the cross compiler prefix can be specified by
setting the CROSS_PREFIX in "make" command. Also to allow gcc pre-processor
to include the C-style file correctly, it also renames the
x86-a-b-bootblock.s file extension from .s to .S.

Signed-off-by: Wei Huang 
---
 tests/migration/Makefile   | 31 
 tests/migration/rebuild-x86-bootblock.sh   | 33 --
 .../{x86-a-b-bootblock.s => x86-a-b-bootblock.S}   |  0
 3 files changed, 31 insertions(+), 33 deletions(-)
 create mode 100644 tests/migration/Makefile
 delete mode 100755 tests/migration/rebuild-x86-bootblock.sh
 rename tests/migration/{x86-a-b-bootblock.s => x86-a-b-bootblock.S} (100%)

diff --git a/tests/migration/Makefile b/tests/migration/Makefile
new file mode 100644
index 000..5d5fa07
--- /dev/null
+++ b/tests/migration/Makefile
@@ -0,0 +1,31 @@
+# To specify cross compiler prefix, use CROSS_PREFIX=
+#   > make CROSS_PREFIX=x86_64-linux-gnu-
+
+override define __note
+/* This file is automatically generated from
+ * tests/migration/x86-a-b-bootblock.s, edit that and then run
+ * tests/migration/rebuild-x86-bootblock.sh to update,
+ * and then remember to send both in your patch submission.
+ */
+endef
+export __note
+
+.PHONY: all clean
+all: x86-a-b-bootblock.h
+
+x86-a-b-bootblock.h: x86.bootsect
+   echo "$$__note" > header.tmp
+   xxd -i $< | sed -e 's/.*int.*//' >> header.tmp
+   mv header.tmp $@
+
+x86.bootsect: x86.boot
+   dd if=$< of=$@ bs=256 count=2 skip=124
+
+x86.boot: x86.o
+   $(CROSS_PREFIX)objcopy -O binary $< $@
+
+x86.o: x86-a-b-bootblock.S
+   $(CROSS_PREFIX)gcc -m32 -march=i486 -c $< -o $@
+
+clean:
+   @rm -rf *.boot *.o *.bootsect
diff --git a/tests/migration/rebuild-x86-bootblock.sh 
b/tests/migration/rebuild-x86-bootblock.sh
deleted file mode 100755
index 86cec5d..000
--- a/tests/migration/rebuild-x86-bootblock.sh
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/sh
-# Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
-# This work is licensed under the terms of the GNU GPL, version 2 or later.
-# See the COPYING file in the top-level directory.
-#
-# Author: dgilb...@redhat.com
-
-ASMFILE=$PWD/tests/migration/x86-a-b-bootblock.s
-HEADER=$PWD/tests/migration/x86-a-b-bootblock.h
-
-if [ ! -e "$ASMFILE" ]
-then
-  echo "Couldn't find $ASMFILE" >&2
-  exit 1
-fi
-
-ASM_WORK_DIR=$(mktemp -d --tmpdir X86BB.XX)
-cd "$ASM_WORK_DIR" &&
-as --32 -march=i486 "$ASMFILE" -o x86.o &&
-objcopy -O binary x86.o x86.boot &&
-dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124 &&
-xxd -i x86.bootsect |
-sed -e 's/.*int.*//' > x86.hex &&
-cat - x86.hex < "$HEADER"
-/* This file is automatically generated from
- * tests/migration/x86-a-b-bootblock.s, edit that and then run
- * tests/migration/rebuild-x86-bootblock.sh to update,
- * and then remember to send both in your patch submission.
- */
-HERE
-
-rm x86.hex x86.bootsect x86.boot x86.o
-cd .. && rmdir "$ASM_WORK_DIR"
diff --git a/tests/migration/x86-a-b-bootblock.s 
b/tests/migration/x86-a-b-bootblock.S
similarity index 100%
rename from tests/migration/x86-a-b-bootblock.s
rename to tests/migration/x86-a-b-bootblock.S
-- 
1.8.3.1




[Qemu-devel] [PATCH V8 4/4] tests: Add migration test for aarch64

2018-08-31 Thread Wei Huang
This patch adds migration test support for aarch64. The test code, which
implements the same functionality as x86, is booted as a kernel in qemu.
Here are the design choices we make for aarch64:

 * We choose this -kernel approach because aarch64 QEMU doesn't provide a
   built-in fw like x86 does. So instead of relying on a boot loader, we
   use -kernel approach for aarch64.
 * The serial output is sent to PL011 directly.
 * The physical memory base for mach-virt machine is 0x4000. We change
   the start_address and end_address for aarch64.

In addition to providing the binary, this patch also includes the source
code and the build script in tests/migration/aarch64. So users can change
the source and/or re-compile the binary as they wish.

Signed-off-by: Wei Huang 
---
 tests/Makefile.include   |  1 +
 tests/migration-test.c   | 38 --
 tests/migration/Makefile |  2 +-
 tests/migration/aarch64/Makefile | 20 
 tests/migration/aarch64/aarch64-a-b-kernel.S | 75 
 tests/migration/aarch64/aarch64-a-b-kernel.h | 19 +++
 tests/migration/migration-test.h |  9 
 7 files changed, 159 insertions(+), 5 deletions(-)
 create mode 100644 tests/migration/aarch64/Makefile
 create mode 100644 tests/migration/aarch64/aarch64-a-b-kernel.S
 create mode 100644 tests/migration/aarch64/aarch64-a-b-kernel.h

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 87c81d1..fab8fb9 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -390,6 +390,7 @@ check-qtest-arm-y += tests/hexloader-test$(EXESUF)
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
 check-qtest-aarch64-$(CONFIG_SDHCI) += tests/sdhci-test$(EXESUF)
 check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
+check-qtest-aarch64-y += tests/migration-test$(EXESUF)
 
 check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
 
diff --git a/tests/migration-test.c b/tests/migration-test.c
index bf60fa0..9df7bce 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -34,6 +34,7 @@ static bool uffd_feature_thread_id;
 #if defined(__linux__)
 #include 
 #include 
+#include 
 #endif
 
 #if defined(__linux__) && defined(__NR_userfaultfd) && defined(CONFIG_EVENTFD)
@@ -86,12 +87,13 @@ static const char *tmpfs;
  * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
  */
 #include "tests/migration/x86_64/x86-a-b-bootblock.h"
+#include "tests/migration/aarch64/aarch64-a-b-kernel.h"
 
-static void init_bootfile_x86(const char *bootpath)
+static void init_bootfile(const char *bootpath, void *content)
 {
 FILE *bootfile = fopen(bootpath, "wb");
 
-g_assert_cmpint(fwrite(x86_bootsect, 512, 1, bootfile), ==, 1);
+g_assert_cmpint(fwrite(content, 512, 1, bootfile), ==, 1);
 fclose(bootfile);
 }
 
@@ -428,7 +430,7 @@ static int test_migrate_start(QTestState **from, QTestState 
**to,
 got_stop = false;
 
 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-init_bootfile_x86(bootpath);
+init_bootfile(bootpath, x86_bootsect);
 cmd_src = g_strdup_printf("-machine accel=%s -m 150M"
   " -name source,debug-threads=on"
   " -serial file:%s/src_serial"
@@ -459,6 +461,34 @@ static int test_migrate_start(QTestState **from, 
QTestState **to,
 
 start_address = PPC_TEST_MEM_START;
 end_address = PPC_TEST_MEM_END;
+} else if (strcmp(arch, "aarch64") == 0) {
+struct utsname utsname;
+
+/* kvm and tcg need different cpu and gic-version configs */
+if (access("/dev/kvm", F_OK) == 0 && uname() == 0 &&
+strcmp(utsname.machine, "aarch64") == 0) {
+accel = "kvm";
+} else {
+accel = "tcg";
+}
+
+init_bootfile(bootpath, aarch64_kernel);
+cmd_src = g_strdup_printf("-machine virt,accel=%s,gic-version=max "
+  "-name vmsource,debug-threads=on -cpu max "
+  "-m 150M -serial file:%s/src_serial "
+  "-kernel %s ",
+  accel, tmpfs, bootpath);
+cmd_dst = g_strdup_printf("-machine virt,accel=%s,gic-version=max "
+  "-name vmdest,debug-threads=on -cpu max "
+  "-m 150M -serial file:%s/dest_serial "
+  "-kernel %s "
+  "-incoming %s ",
+  accel, tmpfs, bootpath, uri);
+
+start_address = ARM_TEST_MEM_START;
+end_address = ARM_TEST_MEM_

[Qemu-devel] [PATCH V8 0/4] tests: Add migration test for aarch64

2018-08-31 Thread Wei Huang
This patchset adds a migration test for aarch64. It leverages
Dave Gilbert's migration boot block patches to create a new test case
for aarch64.

V7->V8:
 * Support cross compilation by searching for CROSS_CC_GUEST option,
   instead of using the find-cross-prefix defined in roms/Makefile
 * Use the "max" options for ARM guest VM's CPU and GIC types
 * $(TARGET)/Makefile rules are rewritten based on Laurent Vivier's comment
 * NOTE: because Patch 1/2 is re-written, I remove the "Reviewed-by" for
   reviewers to take a look again. Thanks.

V6->V7:
 * Define test memory start/end addresses for all architectures
 * Check aarch64 kernel binary size, limit under 512KB

V5->V6:
 * Add Reviewed-by to patch 1-3
 * Add more design notes in patch 4 (aarch64 assembly compilation, bin space)

V4->V5:
 * Extract cross compilation detection code into rules.mak for sharing
 * Minor comment and code revision in migration-test.c & aarch64-a-b-kernel.S
 
V3->V4:
 * Rename .s to .S, allowing assembly to include C-style header file
 * Move test defines into a new migration-test.h file
 * Use different cpu & gic settings for kvm and tcg modes on aarch64
 * Clean up aarch64-a-b-kernel.S based on Andrew Jones' comments
 
V2->V3:
 * Convert build script to Makefile
 * Add cross-compilation support
 * Fix CPU type for "tcg" machine type
 * Revise asm code and the compilation process from asm to header file

V1->V2:
 * Similar to Dave Gilbert's recent changes to migration-test, we
   provide the test source and a build script in V2.
 * aarch64 kernel blob is defined as "unsigned char" because the source
   is now provided in V2.
 * Add "-machine none" to test_deprecated() because aarch64 doesn't have
   a default machine type.

RFC->V1:
 * aarch64 kernel blob is defined as an uint32_t array
 * The test code is re-written to address a data caching issue under KVM.
   Tests passed under both x86 and aarch64.
 * Re-use init_bootfile_x86() for both x86 and aarch64
 * Other minor fixes

Thanks,
-Wei

Wei Huang (4):
  tests/migration: Convert x86 boot block compilation script into
Makefile
  tests/migration: Support cross compiler in generating boot block
header file
  tests/migration: Add migration-test header file
  tests: Add migration test for aarch64

 tests/Makefile.include |  1 +
 tests/migration-test.c | 68 +++-
 tests/migration/Makefile   | 34 ++
 tests/migration/aarch64/Makefile   | 20 ++
 tests/migration/aarch64/aarch64-a-b-kernel.S   | 75 ++
 tests/migration/aarch64/aarch64-a-b-kernel.h   | 19 ++
 tests/migration/migration-test.h   | 30 +
 tests/migration/rebuild-x86-bootblock.sh   | 33 --
 tests/migration/x86_64/Makefile| 22 +++
 .../x86-a-b-bootblock.S}   |  0
 tests/migration/{ => x86_64}/x86-a-b-bootblock.h   |  8 +--
 11 files changed, 258 insertions(+), 52 deletions(-)
 create mode 100644 tests/migration/Makefile
 create mode 100644 tests/migration/aarch64/Makefile
 create mode 100644 tests/migration/aarch64/aarch64-a-b-kernel.S
 create mode 100644 tests/migration/aarch64/aarch64-a-b-kernel.h
 create mode 100644 tests/migration/migration-test.h
 delete mode 100755 tests/migration/rebuild-x86-bootblock.sh
 create mode 100644 tests/migration/x86_64/Makefile
 rename tests/migration/{x86-a-b-bootblock.s => x86_64/x86-a-b-bootblock.S} 
(100%)
 rename tests/migration/{ => x86_64}/x86-a-b-bootblock.h (93%)

-- 
1.8.3.1




Re: [Qemu-devel] [PATCH 1/1] mach-virt: Change default cpu and gic-version setting to "max"

2018-04-09 Thread Wei Huang


On 04/09/2018 10:55 AM, Peter Maydell wrote:
> On 9 April 2018 at 16:49, Wei Huang <w...@redhat.com> wrote:
>> Running mach-virt machine types (i.e. "-M virt") on different systems can
>> result in various misleading warnings if -cpu and/or gic-version not 
>> specified.
>> For KVM, this can be solved mostly by using "host" type. But the "host" type
>> doesn't work for TCG. Compared with "host", the "max" type not only supports
>> auto detection under KVM mode, but also works with TCG.
>> So this patch set "max" as the default types for both -cpu and gic-version.
> 
> Using "max" will make the VM not migratable by default, and also
> means that the behaviour might differ between host machines and
> between different QEMU versions. I'm not sure we want that for the
> default ?

Understood. If you think the -cpu shouldn't be changed due to the
reasons list above, we should at lease give a better warning message
when cpu doesn't match. Right now, the error msg is something like
"kvm_init_vcpu failed, ...".

Secondly, how about gic-version part? Should we use "max" as the default
gic-version?

> 
>> Signed-off-by: Wei Huang <w...@redhat.com>
>> ---
>>  hw/arm/virt.c | 10 +-
>>  1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
>> index 94dcb125d3..1a9d68b8d5 100644
>> --- a/hw/arm/virt.c
>> +++ b/hw/arm/virt.c
>> @@ -1555,7 +1555,7 @@ static void virt_machine_class_init(ObjectClass *oc, 
>> void *data)
>>  mc->minimum_page_bits = 12;
>>  mc->possible_cpu_arch_ids = virt_possible_cpu_arch_ids;
>>  mc->cpu_index_to_instance_props = virt_cpu_index_to_props;
>> -mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a15");
>> +mc->default_cpu_type = ARM_CPU_TYPE_NAME("max");
>>  mc->get_default_cpu_node_id = virt_get_default_cpu_node_id;
>>  }
>>
>> @@ -1609,13 +1609,13 @@ static void virt_2_12_instance_init(Object *obj)
>>  "Set on/off to enable/disable using "
>>  "physical address space above 32 bits",
>>  NULL);
>> -/* Default GIC type is v2 */
>> -vms->gic_version = 2;
>> +/* Default GIC type is max */
>> +vms->gic_version = -1;
>>  object_property_add_str(obj, "gic-version", virt_get_gic_version,
>>  virt_set_gic_version, NULL);
>>  object_property_set_description(obj, "gic-version",
>> -"Set GIC version. "
>> -"Valid values are 2, 3 and host", NULL);
>> +"Set GIC version. Valid values are 2, 
>> 3, "
>> +"host, and max", NULL);
> 
> This change in the help string is a bug fix not related to the
> rest of the patch. You should send that as a separate patch,
> because we want that regardless of what we do about the default
> value.
> 
> thanks
> -- PMM
> 



Re: [Qemu-devel] [PATCH 1/1] mach-virt: Change default cpu and gic-version setting to "max"

2018-04-09 Thread Wei Huang


On 04/09/2018 10:56 AM, Daniel P. Berrangé wrote:
> On Mon, Apr 09, 2018 at 10:49:21AM -0500, Wei Huang wrote:
>> Running mach-virt machine types (i.e. "-M virt") on different systems can
>> result in various misleading warnings if -cpu and/or gic-version not 
>> specified.
>> For KVM, this can be solved mostly by using "host" type. But the "host" type
>> doesn't work for TCG. Compared with "host", the "max" type not only supports
>> auto detection under KVM mode, but also works with TCG. So this patch set
>> "max" as the default types for both -cpu and gic-version.
> 
> Hmm, generally we aim for the config provided by a machine type to be stable
> across QEMU versions.

I understand this principle. But in reality, under KVM mode, the default
config most time doesn't work. If end users specify cpu type manually,
it still doesn't work because the host CPU is vendor-specific design
(e.g. "cortex-a57" doesn't work on QCOM's machine). So we end up with
using "-cpu host" all the time. My argument for this patch is that "-cpu
max" isn't worse than "-cpu host".

> 
> By specifying "max", the machine type will potentially change if new QEMU
> turns on new features in the "max" CPU model, as well as also varying
> depending on what the host OS supports.
> 
> This is a general conceptual problem with the "host" CPU model for all
> target arches and is unfixable by design. This is fine if you accept
> the caveats with using "-cpu host" and opt-in to using it knowing the
> tradeoffs. I'm just not convinced it is reasonable to make "-cpu host"
> be the default value for a machine type out of the box.
> 
> 
>> Signed-off-by: Wei Huang <w...@redhat.com>
>> ---
>>  hw/arm/virt.c | 10 +-
>>  1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
>> index 94dcb125d3..1a9d68b8d5 100644
>> --- a/hw/arm/virt.c
>> +++ b/hw/arm/virt.c
>> @@ -1555,7 +1555,7 @@ static void virt_machine_class_init(ObjectClass *oc, 
>> void *data)
>>  mc->minimum_page_bits = 12;
>>  mc->possible_cpu_arch_ids = virt_possible_cpu_arch_ids;
>>  mc->cpu_index_to_instance_props = virt_cpu_index_to_props;
>> -mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a15");
>> +mc->default_cpu_type = ARM_CPU_TYPE_NAME("max");
>>  mc->get_default_cpu_node_id = virt_get_default_cpu_node_id;
>>  }
>>  
>> @@ -1609,13 +1609,13 @@ static void virt_2_12_instance_init(Object *obj)
>>  "Set on/off to enable/disable using "
>>  "physical address space above 32 bits",
>>  NULL);
>> -/* Default GIC type is v2 */
>> -vms->gic_version = 2;
>> +/* Default GIC type is max */
>> +vms->gic_version = -1;
>>  object_property_add_str(obj, "gic-version", virt_get_gic_version,
>>  virt_set_gic_version, NULL);
>>  object_property_set_description(obj, "gic-version",
>> -"Set GIC version. "
>> -"Valid values are 2, 3 and host", NULL);
>> +"Set GIC version. Valid values are 2, 
>> 3, "
>> +"host, and max", NULL);
>>  
>>  if (vmc->no_its) {
>>  vms->its = false;
>> -- 
>> 2.14.3
>>
>>
> 
> Regards,
> Daniel
> 



[Qemu-devel] [PATCH 1/1] mach-virt: Change default cpu and gic-version setting to "max"

2018-04-09 Thread Wei Huang
Running mach-virt machine types (i.e. "-M virt") on different systems can
result in various misleading warnings if -cpu and/or gic-version not specified.
For KVM, this can be solved mostly by using "host" type. But the "host" type
doesn't work for TCG. Compared with "host", the "max" type not only supports
auto detection under KVM mode, but also works with TCG. So this patch set
"max" as the default types for both -cpu and gic-version.

Signed-off-by: Wei Huang <w...@redhat.com>
---
 hw/arm/virt.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 94dcb125d3..1a9d68b8d5 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -1555,7 +1555,7 @@ static void virt_machine_class_init(ObjectClass *oc, void 
*data)
 mc->minimum_page_bits = 12;
 mc->possible_cpu_arch_ids = virt_possible_cpu_arch_ids;
 mc->cpu_index_to_instance_props = virt_cpu_index_to_props;
-mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a15");
+mc->default_cpu_type = ARM_CPU_TYPE_NAME("max");
 mc->get_default_cpu_node_id = virt_get_default_cpu_node_id;
 }
 
@@ -1609,13 +1609,13 @@ static void virt_2_12_instance_init(Object *obj)
 "Set on/off to enable/disable using "
 "physical address space above 32 bits",
 NULL);
-/* Default GIC type is v2 */
-vms->gic_version = 2;
+/* Default GIC type is max */
+vms->gic_version = -1;
 object_property_add_str(obj, "gic-version", virt_get_gic_version,
 virt_set_gic_version, NULL);
 object_property_set_description(obj, "gic-version",
-"Set GIC version. "
-"Valid values are 2, 3 and host", NULL);
+"Set GIC version. Valid values are 2, 3, "
+"host, and max", NULL);
 
 if (vmc->no_its) {
 vms->its = false;
-- 
2.14.3




[Qemu-devel] [PATCH V2 1/1] mach-virt: Set VM's SMBIOS system version to mc->name

2018-03-22 Thread Wei Huang
Instead of using "1.0" as the system version of SMBIOS, we should use
mc->name for mach-virt machine type to be consistent other architectures.
With this patch, "dmidecode -t 1" (e.g., "-M virt-2.12,accel=kvm") will
show:

Handle 0x0100, DMI type 1, 27 bytes
System Information
Manufacturer: QEMU
Product Name: KVM Virtual Machine
Version: virt-2.12
Serial Number: Not Specified
...

instead of:

Handle 0x0100, DMI type 1, 27 bytes
System Information
Manufacturer: QEMU
Product Name: KVM Virtual Machine
Version: 1.0
Serial Number: Not Specified
...

For backward compatibility, we allow older machine types to keep "1.0"
as the default system version.

Signed-off-by: Wei Huang <w...@redhat.com>
---
 hw/arm/virt.c | 8 +++-
 include/hw/arm/virt.h | 1 +
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 2c07245047..94dcb125d3 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -1132,6 +1132,8 @@ static void *machvirt_dtb(const struct arm_boot_info 
*binfo, int *fdt_size)
 
 static void virt_build_smbios(VirtMachineState *vms)
 {
+MachineClass *mc = MACHINE_GET_CLASS(vms);
+VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(vms);
 uint8_t *smbios_tables, *smbios_anchor;
 size_t smbios_tables_len, smbios_anchor_len;
 const char *product = "QEMU Virtual Machine";
@@ -1145,7 +1147,8 @@ static void virt_build_smbios(VirtMachineState *vms)
 }
 
 smbios_set_defaults("QEMU", product,
-"1.0", false, true, SMBIOS_ENTRY_POINT_30);
+vmc->smbios_old_sys_ver ? "1.0" : mc->name, false,
+true, SMBIOS_ENTRY_POINT_30);
 
 smbios_get_tables(NULL, 0, _tables, _tables_len,
   _anchor, _anchor_len);
@@ -1646,8 +1649,11 @@ static void virt_2_11_instance_init(Object *obj)
 
 static void virt_machine_2_11_options(MachineClass *mc)
 {
+VirtMachineClass *vmc = VIRT_MACHINE_CLASS(OBJECT_CLASS(mc));
+
 virt_machine_2_12_options(mc);
 SET_MACHINE_COMPAT(mc, VIRT_COMPAT_2_11);
+vmc->smbios_old_sys_ver = true;
 }
 DEFINE_VIRT_MACHINE(2, 11)
 
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
index 33b0ff3892..ba0c1a4faa 100644
--- a/include/hw/arm/virt.h
+++ b/include/hw/arm/virt.h
@@ -85,6 +85,7 @@ typedef struct {
 bool no_its;
 bool no_pmu;
 bool claim_edge_triggered_timers;
+bool smbios_old_sys_ver;
 } VirtMachineClass;
 
 typedef struct {
-- 
2.14.3




Re: [Qemu-devel] [PATCH 1/1] mach-virt: Set VM's SMBIOS system version to mc->desc

2018-03-22 Thread Wei Huang


On 03/22/2018 05:53 AM, Peter Maydell wrote:
> On 22 March 2018 at 08:01, Andrew Jones  wrote:
>> I agree we should change the useless 1.0, but shouldn't we use
>> mc->name instead of mc->desc? mc->name would make it consistent
>> with pc-piix and q35 and also be a less verbose "version". We'd
>> get e.g.
>>
>>  System Information
>> Manufacturer: QEMU
>> Product Name: KVM Virtual Machine
>> Version: virt-2.12
>> Serial Number: Not Specified
> 
> I would vote for consistency with x86, I think.

Drew and you like ->name better because of its conciseness consistency
with x86. In my view virt-2.xx is not very informative. "Version" info
in real machine could be verbose. Using my Thinkpad as example:

Manufacturer: LENOVO
Product Name: 20FAS1EG0N
Version: ThinkPad T460s

With that said, I will change it to mc->name.

> 
> thanks
> -- PMM
> 



[Qemu-devel] [PATCH 1/1] mach-virt: Set VM's SMBIOS system version to mc->desc

2018-03-21 Thread Wei Huang
Instead of using "1.0" as the system version of SMBIOS, we should use
mc->desc for mach-virt machine type. With this patch, "dmidecode -t 1"
(e.g., "-M virt-2.12,accel=kvm") will show:

Handle 0x0100, DMI type 1, 27 bytes
System Information
Manufacturer: QEMU
Product Name: KVM Virtual Machine
Version: QEMU 2.12 ARM Virtual Machine
Serial Number: Not Specified
...

instead of:
Handle 0x0100, DMI type 1, 27 bytes
System Information
Manufacturer: QEMU
Product Name: KVM Virtual Machine
Version: 1.0
Serial Number: Not Specified
    ...

Signed-off-by: Wei Huang <w...@redhat.com>
---
 hw/arm/virt.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 2c07245047..da7228b297 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -1132,6 +1132,7 @@ static void *machvirt_dtb(const struct arm_boot_info 
*binfo, int *fdt_size)
 
 static void virt_build_smbios(VirtMachineState *vms)
 {
+MachineClass *mc = MACHINE_GET_CLASS(vms);
 uint8_t *smbios_tables, *smbios_anchor;
 size_t smbios_tables_len, smbios_anchor_len;
 const char *product = "QEMU Virtual Machine";
@@ -1145,7 +1146,7 @@ static void virt_build_smbios(VirtMachineState *vms)
 }
 
 smbios_set_defaults("QEMU", product,
-"1.0", false, true, SMBIOS_ENTRY_POINT_30);
+mc->desc, false, true, SMBIOS_ENTRY_POINT_30);
 
 smbios_get_tables(NULL, 0, _tables, _tables_len,
   _anchor, _anchor_len);
-- 
2.14.3




[Qemu-devel] [PATCH 1/1] dump: Update correct kdump phys_base field for AArch64

2018-03-09 Thread Wei Huang
For guest kernel that supports KASLR, the load address can change every
time when guest VM runs. To find the physical base address correctly,
current QEMU dump searches VMCOREINFO for the string "NUMBER(phys_base)=".
However this string pattern is only available on x86_64. AArch64 uses a
different field, called "NUMBER(PHYS_OFFSET)=". This patch makes sure
QEMU dump uses the correct string on AArch64.

Signed-off-by: Wei Huang <w...@redhat.com>
---
 dump.c | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/dump.c b/dump.c
index 097e60b..6bdb0db 100644
--- a/dump.c
+++ b/dump.c
@@ -1609,10 +1609,18 @@ static void vmcoreinfo_update_phys_base(DumpState *s)
 
 lines = g_strsplit((char *)vmci, "\n", -1);
 for (i = 0; lines[i]; i++) {
-if (g_str_has_prefix(lines[i], "NUMBER(phys_base)=")) {
-if (qemu_strtou64(lines[i] + 18, NULL, 16,
+const char *prefix = NULL;
+
+if (s->dump_info.d_machine == EM_X86_64) {
+prefix = "NUMBER(phys_base)=";
+} else if (s->dump_info.d_machine == EM_AARCH64) {
+prefix = "NUMBER(PHYS_OFFSET)=";
+}
+
+if (prefix && g_str_has_prefix(lines[i], prefix)) {
+if (qemu_strtou64(lines[i] + strlen(prefix), NULL, 16,
   _base) < 0) {
-warn_report("Failed to read NUMBER(phys_base)=");
+warn_report("Failed to read %s", prefix);
 } else {
 s->dump_info.phys_base = phys_base;
 }
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH V7 1/4] rules: Move cross compilation auto detection functions to rules.mak

2018-03-05 Thread Wei Huang


On 03/05/2018 07:52 AM, Dr. David Alan Gilbert wrote:
> * Andrew Jones (drjo...@redhat.com) wrote:
>> On Mon, Mar 05, 2018 at 11:01:23AM +, Dr. David Alan Gilbert wrote:
>>> * Laurent Vivier (lviv...@redhat.com) wrote:
>>>> On 28/02/2018 19:02, Wei Huang wrote:
>>>>> This patch moves the auto detection functions for cross compilation from
>>>>> roms/Makefile to rules.mak. So the functions can be shared among Makefiles
>>>>> in QEMU.
>>>>>
>>>>> Signed-off-by: Wei Huang <w...@redhat.com>
>>>>> Reviewed-by: Andrew Jones <drjo...@redhat.com>
>>>>> ---
>>>>>  roms/Makefile | 24 +++-
>>>>>  rules.mak | 15 +++
>>>>>  2 files changed, 22 insertions(+), 17 deletions(-)
>>>>>
>>>>> diff --git a/roms/Makefile b/roms/Makefile
>>>>> index b5e5a69e91..e972c65333 100644
>>>>> --- a/roms/Makefile
>>>>> +++ b/roms/Makefile
>>>>> @@ -21,23 +21,6 @@ pxe-rom-virtio   efi-rom-virtio   : DID := 1000
>>>>>  pxe-rom-vmxnet3  efi-rom-vmxnet3  : VID := 15ad
>>>>>  pxe-rom-vmxnet3  efi-rom-vmxnet3  : DID := 07b0
>>>>>  
>>>>> -#
>>>>> -# cross compiler auto detection
>>>>> -#
>>>>> -path := $(subst :, ,$(PATH))
>>>>> -system := $(shell uname -s | tr "A-Z" "a-z")
>>>>> -
>>>>> -# first find cross binutils in path
>>>>> -find-cross-ld = $(firstword $(wildcard $(patsubst 
>>>>> %,%/$(1)-*$(system)*-ld,$(path
>>>>> -# then check we have cross gcc too
>>>>> -find-cross-gcc = $(firstword $(wildcard $(patsubst %ld,%gcc,$(call 
>>>>> find-cross-ld,$(1)
>>>>> -# finally strip off path + toolname so we get the prefix
>>>>> -find-cross-prefix = $(subst gcc,,$(notdir $(call find-cross-gcc,$(1
>>>>> -
>>>>> -powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64)
>>>>> -powerpc_cross_prefix := $(call find-cross-prefix,powerpc)
>>>>> -x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
>>>>> -
>>>>>  # tag our seabios builds
>>>>>  SEABIOS_EXTRAVERSION="-prebuilt.qemu-project.org"
>>>>>  
>>>>> @@ -66,6 +49,13 @@ default:
>>>>>   @echo "  skiboot-- update skiboot.lid"
>>>>>   @echo "  u-boot.e500-- update u-boot.e500"
>>>>>  
>>>>> +SRC_PATH=..
>>>>> +include $(SRC_PATH)/rules.mak
>>>>> +
>>>>> +powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64)
>>>>> +powerpc_cross_prefix := $(call find-cross-prefix,powerpc)
>>>>> +x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
>>>>> +
>>>>>  bios: build-seabios-config-seabios-128k build-seabios-config-seabios-256k
>>>>>   cp seabios/builds/seabios-128k/bios.bin ../pc-bios/bios.bin
>>>>>   cp seabios/builds/seabios-256k/bios.bin ../pc-bios/bios-256k.bin
>>>>> diff --git a/rules.mak b/rules.mak
>>>>> index 6e943335f3..ef8adee3f8 100644
>>>>> --- a/rules.mak
>>>>> +++ b/rules.mak
>>>>> @@ -62,6 +62,21 @@ expand-objs = $(strip $(sort $(filter %.o,$1)) \
>>>>>$(foreach o,$(filter %.mo,$1),$($o-objs)) \
>>>>>$(filter-out %.o %.mo,$1))
>>>>>  
>>>>> +# Cross compilation auto detection. Use find-cross-prefix to detect the
>>>>> +# target archtecture's prefix, and then append it to the build tool or 
>>>>> pass
>>>>> +# it to CROSS_COMPILE directly. Here is one example:
>>>>> +#  x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
>>>>> +#  $(x86_64_cross_prefix)gcc -c test.c -o test.o
>>>>> +#  make -C testdir CROSS_COMPILE=$(x86_64_cross_prefix)
>>>>> +cross-search-path := $(subst :, ,$(PATH))
>>>>> +cross-host-system := $(shell uname -s | tr "A-Z" "a-z")
>>>>> +
>>>>> +find-cross-ld = $(firstword $(wildcard $(patsubst \
>>>>> +
>>>>> %,%/$(1)-*$(cross-host-system)*-ld,$(cross-search-path
>>>>> +find-cross-gcc = $(firstword $(wildcard \
>>>>> +$(patsubst %ld,%gcc,

Re: [Qemu-devel] [PATCH V7 2/4] tests/migration: Convert the boot block compilation script into Makefile

2018-03-02 Thread Wei Huang


On 03/02/2018 09:25 AM, Laurent Vivier wrote:
> On 28/02/2018 19:02, Wei Huang wrote:
>> The x86 boot block header currently is generated with a shell script.
>> To better support other CPUs (e.g. aarch64), we convert the script
>> into Makefile. This allows us to 1) support cross-compilation easily,
>> and 2) avoid creating a script file for every architecture.
>>
>> Signed-off-by: Wei Huang <w...@redhat.com>
>> Reviewed-by: Andrew Jones <drjo...@redhat.com>
>> ---
>>  tests/migration/Makefile | 36 
>> 
>>  tests/migration/rebuild-x86-bootblock.sh | 33 -
>>  tests/migration/x86-a-b-bootblock.h  |  2 +-
>>  tests/migration/x86-a-b-bootblock.s  |  5 ++---
>>  4 files changed, 39 insertions(+), 37 deletions(-)
>>  create mode 100644 tests/migration/Makefile
>>  delete mode 100755 tests/migration/rebuild-x86-bootblock.sh
>>
>> diff --git a/tests/migration/Makefile b/tests/migration/Makefile
>> new file mode 100644
>> index 00..8fbedaa8b8
>> --- /dev/null
>> +++ b/tests/migration/Makefile
>> @@ -0,0 +1,36 @@
>> +#
>> +# Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
>> +#
>> +# Authors:
>> +#   Dave Gilbert <dgilb...@redhat.com>
>> +#
>> +# This work is licensed under the terms of the GNU GPL, version 2 or later.
>> +# See the COPYING file in the top-level directory.
>> +#
>> +export __note
>> +override define __note
>> +/* This file is automatically generated from
>> + * tests/migration/$<, edit that and then run
>> + * "make $@" inside tests/migration to update,
>> + * and then remember to send both in your patch submission.
>> + */
>> +endef
>> +
>> +all: x86-a-b-bootblock.h
>> +# Dummy command so that make thinks it has done something
>> +@true
>> +
>> +SRC_PATH=../..
>> +include $(SRC_PATH)/rules.mak
> 
> does it work in not in-tree build?

Yes, I tried it with a out-of-tree build and it worked. More
specifically, because .h file (e.g. x86-a-b-bootblock.h) is provided,
this Makefile is disjoint from the main build system and it has to be
invoked explicitly. So it won't be affected by out-of-tree build.

> 
>> +
>> +x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
>> +
>> +x86-a-b-bootblock.h: x86-a-b-bootblock.s
>> +$(x86_64_cross_prefix)as --32 -march=i486 $< -o x86.o
>> +$(x86_64_cross_prefix)objcopy -O binary x86.o x86.boot
>> +dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124
>> +echo "$$__note" > $@
>> +xxd -i x86.bootsect | sed -e 's/.*int.*//' >> $@
> 
> To be really in the spirit of a makefile, you should have a rule by target:
> 
> x86.o: x86-a-b-bootblock.s
>   $(x86_64_cross_prefix)as --32 -march=i486 $< -o x86.o
> 
> x86.boot: x86.o
>   $(x86_64_cross_prefix)objcopy -O binary x86.o x86.boot
> 
> x86.bootsect: x86.boot
>   dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124
> 
> x86-a-b-bootblock.h: x86.bootsect
>   echo "$$__note" > header.tmp
>   xxd -i x86.bootsect | sed -e 's/.*int.*//' >> header.tmp
>   mv header.tmp $@
> 

It is cleaner, I agree. But it will make the Makefile quite bulky
(remember that we have to do the same for aarch64 and others).

> Thanks,
> Laurent
> 



[Qemu-devel] [PATCH V7 4/4] tests: Add migration test for aarch64

2018-02-28 Thread Wei Huang
This patch adds migration test support for aarch64. The test code, which
implements the same functionality as x86, is booted as a kernel in qemu.
Here are the design choices we make for aarch64:

 * We choose this -kernel approach because aarch64 QEMU doesn't provide a
   built-in fw like x86 does. So instead of relying on a boot loader, we
   use -kernel approach for aarch64.
 * The serial output is sent to PL011 directly.
 * The physical memory base for mach-virt machine is 0x4000. We change
   the start_address and end_address for aarch64.

In addition to providing the binary, this patch also includes the source
code and the build script in tests/migration/. So users can change the
source and/or re-compile the binary as they wish.

Signed-off-by: Wei Huang <w...@redhat.com>
---
 tests/Makefile.include   |  1 +
 tests/migration-test.c   | 44 +++--
 tests/migration/Makefile | 12 +-
 tests/migration/aarch64-a-b-kernel.S | 75 
 tests/migration/aarch64-a-b-kernel.h | 19 +
 tests/migration/migration-test.h |  9 +
 6 files changed, 154 insertions(+), 6 deletions(-)
 create mode 100644 tests/migration/aarch64-a-b-kernel.S
 create mode 100644 tests/migration/aarch64-a-b-kernel.h

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 577eb573a2..538173866c 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -372,6 +372,7 @@ check-qtest-arm-y += tests/sdhci-test$(EXESUF)
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
 check-qtest-aarch64-y += tests/sdhci-test$(EXESUF)
 check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
+check-qtest-aarch64-y += tests/migration-test$(EXESUF)
 
 check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
 
diff --git a/tests/migration-test.c b/tests/migration-test.c
index 12c04a9648..ff424330a1 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -11,6 +11,7 @@
  */
 
 #include "qemu/osdep.h"
+#include 
 
 #include "libqtest.h"
 #include "qapi/qmp/qdict.h"
@@ -81,12 +82,13 @@ static const char *tmpfs;
  * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
  */
 #include "tests/migration/x86-a-b-bootblock.h"
+#include "tests/migration/aarch64-a-b-kernel.h"
 
-static void init_bootfile_x86(const char *bootpath)
+static void init_bootfile(const char *bootpath, void *content)
 {
 FILE *bootfile = fopen(bootpath, "wb");
 
-g_assert_cmpint(fwrite(x86_bootsect, 512, 1, bootfile), ==, 1);
+g_assert_cmpint(fwrite(content, 512, 1, bootfile), ==, 1);
 fclose(bootfile);
 }
 
@@ -392,7 +394,7 @@ static void test_migrate_start(QTestState **from, 
QTestState **to,
 got_stop = false;
 
 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-init_bootfile_x86(bootpath);
+init_bootfile(bootpath, x86_bootsect);
 cmd_src = g_strdup_printf("-machine accel=%s -m 150M"
   " -name source,debug-threads=on"
   " -serial file:%s/src_serial"
@@ -427,6 +429,40 @@ static void test_migrate_start(QTestState **from, 
QTestState **to,
 
 start_address = PPC_TEST_MEM_START;
 end_address = PPC_TEST_MEM_END;
+} else if (strcmp(arch, "aarch64") == 0) {
+const char *cpu;
+const char *gic_ver;
+struct utsname utsname;
+
+/* kvm and tcg need different cpu and gic-version configs */
+if (access("/dev/kvm", F_OK) == 0 && uname() == 0 &&
+strcmp(utsname.machine, "aarch64") == 0) {
+accel = "kvm";
+cpu = "host";
+gic_ver = "host";
+} else {
+accel = "tcg";
+cpu = "cortex-a57";
+gic_ver = "2";
+}
+
+init_bootfile(bootpath, aarch64_kernel);
+cmd_src = g_strdup_printf("-machine virt,accel=%s,gic-version=%s "
+  "-name vmsource,debug-threads=on -cpu %s "
+  "-m 150M -serial file:%s/src_serial "
+  "-kernel %s ",
+  accel, gic_ver, cpu, tmpfs, bootpath);
+cmd_dst = g_strdup_printf("-machine virt,accel=%s,gic-version=%s "
+  "-name vmdest,debug-threads=on -cpu %s "
+  "-m 150M -serial file:%s/dest_serial "
+  "-kernel %s "
+  "-incoming %s ",
+  accel, gic_ver, cpu, tmpfs, bootpath, uri);
+
+start_address = ARM_TEST_MEM_START;
+

[Qemu-devel] [PATCH V7 3/4] tests/migration: Add migration-test header file

2018-02-28 Thread Wei Huang
This patch moves the settings related migration-test from the
migration-test.c file to a seperate header file. It also renames the
x86-a-b-bootblock.s file extension from .s to .S, allowing gcc
pre-processor to include the C-style header file correctly.

Signed-off-by: Wei Huang <w...@redhat.com>
---
 tests/migration-test.c | 34 +-
 tests/migration/Makefile   |  4 +--
 tests/migration/migration-test.h   | 22 ++
 .../{x86-a-b-bootblock.s => x86-a-b-bootblock.S}   |  7 +++--
 tests/migration/x86-a-b-bootblock.h|  2 +-
 5 files changed, 49 insertions(+), 20 deletions(-)
 create mode 100644 tests/migration/migration-test.h
 rename tests/migration/{x86-a-b-bootblock.s => x86-a-b-bootblock.S} (94%)

diff --git a/tests/migration-test.c b/tests/migration-test.c
index 74f9361bdd..12c04a9648 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -21,10 +21,10 @@
 #include "sysemu/sysemu.h"
 #include "hw/nvram/chrp_nvram.h"
 
-#define MIN_NVRAM_SIZE 8192 /* from spapr_nvram.c */
+#include "migration/migration-test.h"
 
-const unsigned start_address = 1024 * 1024;
-const unsigned end_address = 100 * 1024 * 1024;
+unsigned start_address;
+unsigned end_address;
 bool got_stop;
 
 #if defined(__linux__)
@@ -77,8 +77,8 @@ static bool ufd_version_check(void)
 
 static const char *tmpfs;
 
-/* A simple PC boot sector that modifies memory (1-100MB) quickly
- * outputting a 'B' every so often if it's still running.
+/* The boot file modifies memory area in [start_address, end_address)
+ * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
  */
 #include "tests/migration/x86-a-b-bootblock.h"
 
@@ -104,9 +104,8 @@ static void init_bootfile_ppc(const char *bootpath)
 memcpy(header->name, "common", 6);
 chrp_nvram_finish_partition(header, MIN_NVRAM_SIZE);
 
-/* FW_MAX_SIZE is 4MB, but slof.bin is only 900KB,
- * so let's modify memory between 1MB and 100MB
- * to do like PC bootsector
+/* FW_MAX_SIZE is 4MB, but slof.bin is only 900KB. So it is OK to modify
+ * memory between start_address and end_address like PC bootsector does.
  */
 
 sprintf(buf + 16,
@@ -263,11 +262,11 @@ static void wait_for_migration_pass(QTestState *who)
 static void check_guests_ram(QTestState *who)
 {
 /* Our ASM test will have been incrementing one byte from each page from
- * 1MB to <100MB in order.
- * This gives us a constraint that any page's byte should be equal or less
- * than the previous pages byte (mod 256); and they should all be equal
- * except for one transition at the point where we meet the incrementer.
- * (We're running this with the guest stopped).
+ * start_address to < end_address in order. This gives us a constraint
+ * that any page's byte should be equal or less than the previous pages
+ * byte (mod 256); and they should all be equal except for one transition
+ * at the point where we meet the incrementer. (We're running this with
+ * the guest stopped).
  */
 unsigned address;
 uint8_t first_byte;
@@ -278,7 +277,8 @@ static void check_guests_ram(QTestState *who)
 qtest_memread(who, start_address, _byte, 1);
 last_byte = first_byte;
 
-for (address = start_address + 4096; address < end_address; address += 
4096)
+for (address = start_address + TEST_MEM_PAGE_SIZE; address < end_address;
+ address += TEST_MEM_PAGE_SIZE)
 {
 uint8_t b;
 qtest_memread(who, address, , 1);
@@ -404,6 +404,9 @@ static void test_migrate_start(QTestState **from, 
QTestState **to,
   " -drive file=%s,format=raw"
   " -incoming %s",
   accel, tmpfs, bootpath, uri);
+
+start_address = X86_TEST_MEM_START;
+end_address = X86_TEST_MEM_END;
 } else if (strcmp(arch, "ppc64") == 0) {
 
 /* On ppc64, the test only works with kvm-hv, but not with kvm-pr */
@@ -421,6 +424,9 @@ static void test_migrate_start(QTestState **from, 
QTestState **to,
   " -serial file:%s/dest_serial"
   " -incoming %s",
   accel, tmpfs, uri);
+
+start_address = PPC_TEST_MEM_START;
+end_address = PPC_TEST_MEM_END;
 } else {
 g_assert_not_reached();
 }
diff --git a/tests/migration/Makefile b/tests/migration/Makefile
index 8fbedaa8b8..013b8d1f44 100644
--- a/tests/migration/Makefile
+++ b/tests/migration/Makefile
@@ -25,8 +25,8 @@ include $(SRC_PATH)/rules.mak
 
 x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
 
-x86-a-b-bootblock.h: x86-a-b-bootblock.s
-   $(x86_64_cross_prefix)as --32 -march=i486 $< -o x86.o
+x86-a-b-bootbl

[Qemu-devel] [PATCH V7 0/4] tests: Add migration test for aarch64

2018-02-28 Thread Wei Huang
This patchset adds a migration test for aarch64. It leverages
Dave Gilbert's recent patch "tests/migration: Add source to PC boot block"
to create a new test case for aarch64.

V6->V7:
 * Define test memory start/end addresses for all architectures
 * Check aarch64 kernel binary size, limit under 512KB

V5->V6:
 * Add Reviewed-by to patch 1-3
 * Add more design notes in patch 4 (aarch64 assembly compilation, bin space)

V4->V5:
 * Extract cross compilation detection code into rules.mak for sharing
 * Minor comment and code revision in migration-test.c & aarch64-a-b-kernel.S
 
V3->V4:
 * Rename .s to .S, allowing assembly to include C-style header file
 * Move test defines into a new migration-test.h file
 * Use different cpu & gic settings for kvm and tcg modes on aarch64
 * Clean up aarch64-a-b-kernel.S based on Andrew Jones' comments
 
V2->V3:
 * Convert build script to Makefile
 * Add cross-compilation support
 * Fix CPU type for "tcg" machine type
 * Revise asm code and the compilation process from asm to header file

V1->V2:
 * Similar to Dave Gilbert's recent changes to migration-test, we
   provide the test source and a build script in V2.
 * aarch64 kernel blob is defined as "unsigned char" because the source
   is now provided in V2.
 * Add "-machine none" to test_deprecated() because aarch64 doesn't have
   a default machine type.

RFC->V1:
 * aarch64 kernel blob is defined as an uint32_t array
 * The test code is re-written to address a data caching issue under KVM.
   Tests passed under both x86 and aarch64.
 * Re-use init_bootfile_x86() for both x86 and aarch64
 * Other minor fixes

Thanks,
-Wei

Wei Huang (4):
  rules: Move cross compilation auto detection functions to rules.mak
  tests/migration: Convert the boot block compilation script into
Makefile
  tests/migration: Add migration-test header file
  tests: Add migration test for aarch64

 roms/Makefile  | 24 ++-
 rules.mak  | 15 +
 tests/Makefile.include |  1 +
 tests/migration-test.c | 78 +-
 tests/migration/Makefile   | 44 
 tests/migration/aarch64-a-b-kernel.S   | 75 +
 tests/migration/aarch64-a-b-kernel.h   | 19 ++
 tests/migration/migration-test.h   | 31 +
 tests/migration/rebuild-x86-bootblock.sh   | 33 -
 .../{x86-a-b-bootblock.s => x86-a-b-bootblock.S}   | 12 ++--
 tests/migration/x86-a-b-bootblock.h|  4 +-
 11 files changed, 260 insertions(+), 76 deletions(-)
 create mode 100644 tests/migration/Makefile
 create mode 100644 tests/migration/aarch64-a-b-kernel.S
 create mode 100644 tests/migration/aarch64-a-b-kernel.h
 create mode 100644 tests/migration/migration-test.h
 delete mode 100755 tests/migration/rebuild-x86-bootblock.sh
 rename tests/migration/{x86-a-b-bootblock.s => x86-a-b-bootblock.S} (88%)

-- 
2.14.3




[Qemu-devel] [PATCH V7 2/4] tests/migration: Convert the boot block compilation script into Makefile

2018-02-28 Thread Wei Huang
The x86 boot block header currently is generated with a shell script.
To better support other CPUs (e.g. aarch64), we convert the script
into Makefile. This allows us to 1) support cross-compilation easily,
and 2) avoid creating a script file for every architecture.

Signed-off-by: Wei Huang <w...@redhat.com>
Reviewed-by: Andrew Jones <drjo...@redhat.com>
---
 tests/migration/Makefile | 36 
 tests/migration/rebuild-x86-bootblock.sh | 33 -
 tests/migration/x86-a-b-bootblock.h  |  2 +-
 tests/migration/x86-a-b-bootblock.s  |  5 ++---
 4 files changed, 39 insertions(+), 37 deletions(-)
 create mode 100644 tests/migration/Makefile
 delete mode 100755 tests/migration/rebuild-x86-bootblock.sh

diff --git a/tests/migration/Makefile b/tests/migration/Makefile
new file mode 100644
index 00..8fbedaa8b8
--- /dev/null
+++ b/tests/migration/Makefile
@@ -0,0 +1,36 @@
+#
+# Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
+#
+# Authors:
+#   Dave Gilbert <dgilb...@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+#
+export __note
+override define __note
+/* This file is automatically generated from
+ * tests/migration/$<, edit that and then run
+ * "make $@" inside tests/migration to update,
+ * and then remember to send both in your patch submission.
+ */
+endef
+
+all: x86-a-b-bootblock.h
+# Dummy command so that make thinks it has done something
+   @true
+
+SRC_PATH=../..
+include $(SRC_PATH)/rules.mak
+
+x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
+
+x86-a-b-bootblock.h: x86-a-b-bootblock.s
+   $(x86_64_cross_prefix)as --32 -march=i486 $< -o x86.o
+   $(x86_64_cross_prefix)objcopy -O binary x86.o x86.boot
+   dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124
+   echo "$$__note" > $@
+   xxd -i x86.bootsect | sed -e 's/.*int.*//' >> $@
+
+clean:
+   rm -f *.bootsect *.boot *.o
diff --git a/tests/migration/rebuild-x86-bootblock.sh 
b/tests/migration/rebuild-x86-bootblock.sh
deleted file mode 100755
index 86cec5d284..00
--- a/tests/migration/rebuild-x86-bootblock.sh
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/sh
-# Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
-# This work is licensed under the terms of the GNU GPL, version 2 or later.
-# See the COPYING file in the top-level directory.
-#
-# Author: dgilb...@redhat.com
-
-ASMFILE=$PWD/tests/migration/x86-a-b-bootblock.s
-HEADER=$PWD/tests/migration/x86-a-b-bootblock.h
-
-if [ ! -e "$ASMFILE" ]
-then
-  echo "Couldn't find $ASMFILE" >&2
-  exit 1
-fi
-
-ASM_WORK_DIR=$(mktemp -d --tmpdir X86BB.XX)
-cd "$ASM_WORK_DIR" &&
-as --32 -march=i486 "$ASMFILE" -o x86.o &&
-objcopy -O binary x86.o x86.boot &&
-dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124 &&
-xxd -i x86.bootsect |
-sed -e 's/.*int.*//' > x86.hex &&
-cat - x86.hex < "$HEADER"
-/* This file is automatically generated from
- * tests/migration/x86-a-b-bootblock.s, edit that and then run
- * tests/migration/rebuild-x86-bootblock.sh to update,
- * and then remember to send both in your patch submission.
- */
-HERE
-
-rm x86.hex x86.bootsect x86.boot x86.o
-cd .. && rmdir "$ASM_WORK_DIR"
diff --git a/tests/migration/x86-a-b-bootblock.h 
b/tests/migration/x86-a-b-bootblock.h
index 78a151fe2a..9e8e2e028b 100644
--- a/tests/migration/x86-a-b-bootblock.h
+++ b/tests/migration/x86-a-b-bootblock.h
@@ -1,6 +1,6 @@
 /* This file is automatically generated from
  * tests/migration/x86-a-b-bootblock.s, edit that and then run
- * tests/migration/rebuild-x86-bootblock.sh to update,
+ * "make x86-a-b-bootblock.h" inside tests/migration to update,
  * and then remember to send both in your patch submission.
  */
 unsigned char x86_bootsect[] = {
diff --git a/tests/migration/x86-a-b-bootblock.s 
b/tests/migration/x86-a-b-bootblock.s
index b1642641a7..98dbfab084 100644
--- a/tests/migration/x86-a-b-bootblock.s
+++ b/tests/migration/x86-a-b-bootblock.s
@@ -3,9 +3,8 @@
 #  range.
 #  Outputs an initial 'A' on serial followed by repeated 'B's
 #
-# run   tests/migration/rebuild-x86-bootblock.sh
-#   to regenerate the hex, and remember to include both the .h and .s
-#   in any patches.
+#  In tests/migration dir, run 'make x86-a-b-bootblock.h' to regenerate
+#  the hex, and remember to include both the .h and .s in any patches.
 #
 # Copyright (c) 2016 Red Hat, Inc. and/or its affiliates
 # This work is licensed under the terms of the GNU GPL, version 2 or later.
-- 
2.14.3




[Qemu-devel] [PATCH V7 1/4] rules: Move cross compilation auto detection functions to rules.mak

2018-02-28 Thread Wei Huang
This patch moves the auto detection functions for cross compilation from
roms/Makefile to rules.mak. So the functions can be shared among Makefiles
in QEMU.

Signed-off-by: Wei Huang <w...@redhat.com>
Reviewed-by: Andrew Jones <drjo...@redhat.com>
---
 roms/Makefile | 24 +++-
 rules.mak | 15 +++
 2 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/roms/Makefile b/roms/Makefile
index b5e5a69e91..e972c65333 100644
--- a/roms/Makefile
+++ b/roms/Makefile
@@ -21,23 +21,6 @@ pxe-rom-virtio   efi-rom-virtio   : DID := 1000
 pxe-rom-vmxnet3  efi-rom-vmxnet3  : VID := 15ad
 pxe-rom-vmxnet3  efi-rom-vmxnet3  : DID := 07b0
 
-#
-# cross compiler auto detection
-#
-path := $(subst :, ,$(PATH))
-system := $(shell uname -s | tr "A-Z" "a-z")
-
-# first find cross binutils in path
-find-cross-ld = $(firstword $(wildcard $(patsubst 
%,%/$(1)-*$(system)*-ld,$(path
-# then check we have cross gcc too
-find-cross-gcc = $(firstword $(wildcard $(patsubst %ld,%gcc,$(call 
find-cross-ld,$(1)
-# finally strip off path + toolname so we get the prefix
-find-cross-prefix = $(subst gcc,,$(notdir $(call find-cross-gcc,$(1
-
-powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64)
-powerpc_cross_prefix := $(call find-cross-prefix,powerpc)
-x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
-
 # tag our seabios builds
 SEABIOS_EXTRAVERSION="-prebuilt.qemu-project.org"
 
@@ -66,6 +49,13 @@ default:
@echo "  skiboot-- update skiboot.lid"
@echo "  u-boot.e500-- update u-boot.e500"
 
+SRC_PATH=..
+include $(SRC_PATH)/rules.mak
+
+powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64)
+powerpc_cross_prefix := $(call find-cross-prefix,powerpc)
+x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
+
 bios: build-seabios-config-seabios-128k build-seabios-config-seabios-256k
cp seabios/builds/seabios-128k/bios.bin ../pc-bios/bios.bin
cp seabios/builds/seabios-256k/bios.bin ../pc-bios/bios-256k.bin
diff --git a/rules.mak b/rules.mak
index 6e943335f3..ef8adee3f8 100644
--- a/rules.mak
+++ b/rules.mak
@@ -62,6 +62,21 @@ expand-objs = $(strip $(sort $(filter %.o,$1)) \
   $(foreach o,$(filter %.mo,$1),$($o-objs)) \
   $(filter-out %.o %.mo,$1))
 
+# Cross compilation auto detection. Use find-cross-prefix to detect the
+# target archtecture's prefix, and then append it to the build tool or pass
+# it to CROSS_COMPILE directly. Here is one example:
+#  x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
+#  $(x86_64_cross_prefix)gcc -c test.c -o test.o
+#  make -C testdir CROSS_COMPILE=$(x86_64_cross_prefix)
+cross-search-path := $(subst :, ,$(PATH))
+cross-host-system := $(shell uname -s | tr "A-Z" "a-z")
+
+find-cross-ld = $(firstword $(wildcard $(patsubst \
+%,%/$(1)-*$(cross-host-system)*-ld,$(cross-search-path
+find-cross-gcc = $(firstword $(wildcard \
+$(patsubst %ld,%gcc,$(call find-cross-ld,$(1)
+find-cross-prefix = $(subst gcc,,$(notdir $(call find-cross-gcc,$(1
+
 %.o: %.c
$(call quiet-command,$(CC) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \
   $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) \
-- 
2.14.3




Re: [Qemu-devel] [PATCH V6 3/4] tests/migration: Add migration-test header file

2018-02-27 Thread Wei Huang


On 02/27/2018 05:57 AM, Dr. David Alan Gilbert wrote:
> * Wei Huang (w...@redhat.com) wrote:
>> This patch moves the settings related migration-test from the
>> migration-test.c file to a seperate header file. It also renames the
>> x86-a-b-bootblock.s file extension from .s to .S, allowing gcc
>> pre-processor to include the C-style header file correctly.
>>
>> Signed-off-by: Wei Huang <w...@redhat.com>
>> Reviewed-by: Andrew Jones <drjo...@redhat.com>
>> ---
>>  tests/migration-test.c | 28 
>> +++---
>>  tests/migration/Makefile   |  4 ++--
>>  tests/migration/migration-test.h   | 18 ++
>>  .../{x86-a-b-bootblock.s => x86-a-b-bootblock.S}   |  7 +++---
>>  tests/migration/x86-a-b-bootblock.h|  2 +-
>>  5 files changed, 39 insertions(+), 20 deletions(-)
>>  create mode 100644 tests/migration/migration-test.h
>>  rename tests/migration/{x86-a-b-bootblock.s => x86-a-b-bootblock.S} (94%)
>>
>> diff --git a/tests/migration-test.c b/tests/migration-test.c
>> index 74f9361bdd..c88b7e7a19 100644
>> --- a/tests/migration-test.c
>> +++ b/tests/migration-test.c
>> @@ -21,10 +21,10 @@
>>  #include "sysemu/sysemu.h"
>>  #include "hw/nvram/chrp_nvram.h"
>>  
>> -#define MIN_NVRAM_SIZE 8192 /* from spapr_nvram.c */
>> +#include "migration/migration-test.h"
>>  
>> -const unsigned start_address = 1024 * 1024;
>> -const unsigned end_address = 100 * 1024 * 1024;
>> +const unsigned start_address = TEST_MEM_START;
>> +const unsigned end_address = TEST_MEM_END;
>>  bool got_stop;
>>  
>>  #if defined(__linux__)
>> @@ -77,8 +77,8 @@ static bool ufd_version_check(void)
>>  
>>  static const char *tmpfs;
>>  
>> -/* A simple PC boot sector that modifies memory (1-100MB) quickly
>> - * outputting a 'B' every so often if it's still running.
>> +/* The boot file modifies memory area in [start_address, end_address)
>> + * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
>>   */
>>  #include "tests/migration/x86-a-b-bootblock.h"
>>  
>> @@ -104,9 +104,8 @@ static void init_bootfile_ppc(const char *bootpath)
>>  memcpy(header->name, "common", 6);
>>  chrp_nvram_finish_partition(header, MIN_NVRAM_SIZE);
>>  
>> -/* FW_MAX_SIZE is 4MB, but slof.bin is only 900KB,
>> - * so let's modify memory between 1MB and 100MB
>> - * to do like PC bootsector
>> +/* FW_MAX_SIZE is 4MB, but slof.bin is only 900KB. So it is OK to modify
>> + * memory between start_address and end_address like PC bootsector does.
>>   */
>>  
>>  sprintf(buf + 16,
>> @@ -263,11 +262,11 @@ static void wait_for_migration_pass(QTestState *who)
>>  static void check_guests_ram(QTestState *who)
>>  {
>>  /* Our ASM test will have been incrementing one byte from each page from
>> - * 1MB to <100MB in order.
>> - * This gives us a constraint that any page's byte should be equal or 
>> less
>> - * than the previous pages byte (mod 256); and they should all be equal
>> - * except for one transition at the point where we meet the incrementer.
>> - * (We're running this with the guest stopped).
>> + * start_address to < end_address in order. This gives us a constraint
>> + * that any page's byte should be equal or less than the previous pages
>> + * byte (mod 256); and they should all be equal except for one 
>> transition
>> + * at the point where we meet the incrementer. (We're running this with
>> + * the guest stopped).
> 
> No, please don't modify the other architectures.
> 
> It's OK for you to get the start/end value from the define in the header
> but we can't assume they're movable; they're architecture specific
> values that are chosen to fit where we know we have RAM.

Drew didn't like the idea of having #define TEST_MEM_START/TEST_MEM_END
in headerfile, and in the meanwhile, we still use 1MB/100MB in comments.
Anyway we didn't modify the underneath semantic for other architectures.

> 
> Dave
> 
>>   */
>>  unsigned address;
>>  uint8_t first_byte;
>> @@ -278,7 +277,8 @@ static void check_guests_ram(QTestState *who)
>>  qtest_memread(who, start_address, _byte, 1);
>>  last_byte = first_byte;
>>  
>> -for (address = start_address + 4096; address < end_address; address += 
>> 4096)
>> +for (address = start_address

Re: [Qemu-devel] [PATCH V5 2/4] tests/migration: Convert the boot block compilation script into Makefile

2018-02-27 Thread Wei Huang


On 02/27/2018 05:38 AM, Dr. David Alan Gilbert wrote:
> * Wei Huang (w...@redhat.com) wrote:
>>
>>
>> On 02/26/2018 12:01 PM, Dr. David Alan Gilbert wrote:
>>> * Wei Huang (w...@redhat.com) wrote:
>>>> The x86 boot block header currently is generated with a shell script.
>>>> To better support other CPUs (e.g. aarch64), we convert the script
>>>> into Makefile. This allows us to 1) support cross-compilation easily,
>>>> and 2) avoid creating a script file for every architecture.
>>>>
>>>> Signed-off-by: Wei Huang <w...@redhat.com>
>>>
>>> But what happens if you're on a system that doesn't have the cross
>>> compilers?  I found it's too easy to get stuck with it trying
>>> to rebuild the header when there's no need.
>>
>> I think it is fine. If no cross compiler is present, NNN_cross_prefix
>> won't find anything. So it ends up with using the gcc tools on host
>> systems. Obviously the compilation will fail. This should become the
>> problem to solve for whoever wants to do cross-compile. For us, we have
>> done our part because the .h files have been provided.
> 
> But isn't it a problem for people just trying to make check?

"make check" doesn't invoke the Makefile in tests/migration/. This
Makefile is only invoked when people manually run "make" or "make
x86-a-b-bootblock.h" inside the tests/migration/ directory.

> One of the things that convinced me to move it out of the makefile and
> into a separate script was that it was too easy to get into a situation
> where Make wanted to rebuild the headerilfe on a system.

This could be potentially one concern. But the real reason behind this
concern is the cross-compilation doesn't always work (it depends on the
availability of cross-compiler tools). My argument is this problem also
exists in the original script approach. As long as QEMU doesn't include
tests/migration/Makefile in "make" or "make check", I think this rebuild
headerfile situation won't happen.

Also, using Makefile, we don't need to write a script for each single
architecture. And it is easier to support cross-compilation detection
(than script).

Thanks,
-Wei

> 
> Dave
> 
>>>
>>> Dave
>>>
>>>> ---
>>>>  tests/migration/Makefile | 36 
>>>> 
>>>>  tests/migration/rebuild-x86-bootblock.sh | 33 
>>>> -
>>>>  tests/migration/x86-a-b-bootblock.h  |  2 +-
>>>>  tests/migration/x86-a-b-bootblock.s  |  5 ++---
>>>>  4 files changed, 39 insertions(+), 37 deletions(-)
>>>>  create mode 100644 tests/migration/Makefile
>>>>  delete mode 100755 tests/migration/rebuild-x86-bootblock.sh
>>>>
>>>> diff --git a/tests/migration/Makefile b/tests/migration/Makefile
>>>> new file mode 100644
>>>> index 00..8fbedaa8b8
>>>> --- /dev/null
>>>> +++ b/tests/migration/Makefile
>>>> @@ -0,0 +1,36 @@
>>>> +#
>>>> +# Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
>>>> +#
>>>> +# Authors:
>>>> +#   Dave Gilbert <dgilb...@redhat.com>
>>>> +#
>>>> +# This work is licensed under the terms of the GNU GPL, version 2 or 
>>>> later.
>>>> +# See the COPYING file in the top-level directory.
>>>> +#
>>>> +export __note
>>>> +override define __note
>>>> +/* This file is automatically generated from
>>>> + * tests/migration/$<, edit that and then run
>>>> + * "make $@" inside tests/migration to update,
>>>> + * and then remember to send both in your patch submission.
>>>> + */
>>>> +endef
>>>> +
>>>> +all: x86-a-b-bootblock.h
>>>> +# Dummy command so that make thinks it has done something
>>>> +  @true
>>>> +
>>>> +SRC_PATH=../..
>>>> +include $(SRC_PATH)/rules.mak
>>>> +
>>>> +x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
>>>> +
>>>> +x86-a-b-bootblock.h: x86-a-b-bootblock.s
>>>> +  $(x86_64_cross_prefix)as --32 -march=i486 $< -o x86.o
>>>> +  $(x86_64_cross_prefix)objcopy -O binary x86.o x86.boot
>>>> +  dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124
>>>> +  echo "$$__note" > $@
>>>> +  xxd -i x86.bootsect | sed -e 's/.*int.*//' >> $@
>>>> +
>>>> +clean:
>>>

Re: [Qemu-devel] [PATCH V5 2/4] tests/migration: Convert the boot block compilation script into Makefile

2018-02-26 Thread Wei Huang


On 02/26/2018 12:01 PM, Dr. David Alan Gilbert wrote:
> * Wei Huang (w...@redhat.com) wrote:
>> The x86 boot block header currently is generated with a shell script.
>> To better support other CPUs (e.g. aarch64), we convert the script
>> into Makefile. This allows us to 1) support cross-compilation easily,
>> and 2) avoid creating a script file for every architecture.
>>
>> Signed-off-by: Wei Huang <w...@redhat.com>
> 
> But what happens if you're on a system that doesn't have the cross
> compilers?  I found it's too easy to get stuck with it trying
> to rebuild the header when there's no need.

I think it is fine. If no cross compiler is present, NNN_cross_prefix
won't find anything. So it ends up with using the gcc tools on host
systems. Obviously the compilation will fail. This should become the
problem to solve for whoever wants to do cross-compile. For us, we have
done our part because the .h files have been provided.

> 
> Dave
> 
>> ---
>>  tests/migration/Makefile | 36 
>> 
>>  tests/migration/rebuild-x86-bootblock.sh | 33 -
>>  tests/migration/x86-a-b-bootblock.h  |  2 +-
>>  tests/migration/x86-a-b-bootblock.s  |  5 ++---
>>  4 files changed, 39 insertions(+), 37 deletions(-)
>>  create mode 100644 tests/migration/Makefile
>>  delete mode 100755 tests/migration/rebuild-x86-bootblock.sh
>>
>> diff --git a/tests/migration/Makefile b/tests/migration/Makefile
>> new file mode 100644
>> index 00..8fbedaa8b8
>> --- /dev/null
>> +++ b/tests/migration/Makefile
>> @@ -0,0 +1,36 @@
>> +#
>> +# Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
>> +#
>> +# Authors:
>> +#   Dave Gilbert <dgilb...@redhat.com>
>> +#
>> +# This work is licensed under the terms of the GNU GPL, version 2 or later.
>> +# See the COPYING file in the top-level directory.
>> +#
>> +export __note
>> +override define __note
>> +/* This file is automatically generated from
>> + * tests/migration/$<, edit that and then run
>> + * "make $@" inside tests/migration to update,
>> + * and then remember to send both in your patch submission.
>> + */
>> +endef
>> +
>> +all: x86-a-b-bootblock.h
>> +# Dummy command so that make thinks it has done something
>> +@true
>> +
>> +SRC_PATH=../..
>> +include $(SRC_PATH)/rules.mak
>> +
>> +x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
>> +
>> +x86-a-b-bootblock.h: x86-a-b-bootblock.s
>> +$(x86_64_cross_prefix)as --32 -march=i486 $< -o x86.o
>> +$(x86_64_cross_prefix)objcopy -O binary x86.o x86.boot
>> +dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124
>> +echo "$$__note" > $@
>> +xxd -i x86.bootsect | sed -e 's/.*int.*//' >> $@
>> +
>> +clean:
>> +rm -f *.bootsect *.boot *.o
>> diff --git a/tests/migration/rebuild-x86-bootblock.sh 
>> b/tests/migration/rebuild-x86-bootblock.sh
>> deleted file mode 100755
>> index 86cec5d284..00
>> --- a/tests/migration/rebuild-x86-bootblock.sh
>> +++ /dev/null
>> @@ -1,33 +0,0 @@
>> -#!/bin/sh
>> -# Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
>> -# This work is licensed under the terms of the GNU GPL, version 2 or later.
>> -# See the COPYING file in the top-level directory.
>> -#
>> -# Author: dgilb...@redhat.com
>> -
>> -ASMFILE=$PWD/tests/migration/x86-a-b-bootblock.s
>> -HEADER=$PWD/tests/migration/x86-a-b-bootblock.h
>> -
>> -if [ ! -e "$ASMFILE" ]
>> -then
>> -  echo "Couldn't find $ASMFILE" >&2
>> -  exit 1
>> -fi
>> -
>> -ASM_WORK_DIR=$(mktemp -d --tmpdir X86BB.XX)
>> -cd "$ASM_WORK_DIR" &&
>> -as --32 -march=i486 "$ASMFILE" -o x86.o &&
>> -objcopy -O binary x86.o x86.boot &&
>> -dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124 &&
>> -xxd -i x86.bootsect |
>> -sed -e 's/.*int.*//' > x86.hex &&
>> -cat - x86.hex < "$HEADER"
>> -/* This file is automatically generated from
>> - * tests/migration/x86-a-b-bootblock.s, edit that and then run
>> - * tests/migration/rebuild-x86-bootblock.sh to update,
>> - * and then remember to send both in your patch submission.
>> - */
>> -HERE
>> -
>> -rm x86.hex x86.bootsect x86.boot x86.o
>> -cd .. && rmdir "$ASM_WORK_DIR"
>> diff --git a/tests/migration/x86-a-b-bootbl

Re: [Qemu-devel] [PATCH V4 3/3] tests: Add migration test for aarch64

2018-02-26 Thread Wei Huang


On 02/26/2018 03:03 AM, Andrew Jones wrote:
> On Fri, Feb 23, 2018 at 04:13:08PM -0600, Wei Huang wrote:
>>
>>
>> On 02/22/2018 03:00 AM, Andrew Jones wrote:
>>> On Wed, Feb 21, 2018 at 10:44:17PM -0600, Wei Huang wrote:
>>>> This patch adds migration test support for aarch64. The test code, which
>>>> implements the same functionality as x86, is booted as a kernel in qemu.
>>>> Here are the design choices we make for aarch64:
>>>>
>>>>  * We choose this -kernel approach because aarch64 QEMU doesn't provide a
>>>>built-in fw like x86 does. So instead of relying on a boot loader, we
>>>>use -kernel approach for aarch64.
>>>>  * The serial output is sent to PL011 directly.
>>>>  * The physical memory base for mach-virt machine is 0x4000. We change
>>>>the start_address and end_address for aarch64.
>>>>
>>>> In addition to providing the binary, this patch also includes the source
>>>> code and the build script in tests/migration/. So users can change the
>>>> source and/or re-compile the binary as they wish.
>>>>
>>>> Signed-off-by: Wei Huang <w...@redhat.com>
>>>> ---
>>>>  tests/Makefile.include   |  1 +
>>>>  tests/migration-test.c   | 47 +---
>>>>  tests/migration/Makefile | 12 +-
>>>>  tests/migration/aarch64-a-b-kernel.S | 71 
>>>> 
>>>>  tests/migration/aarch64-a-b-kernel.h | 19 ++
>>>>  tests/migration/migration-test.h |  5 +++
>>>>  6 files changed, 147 insertions(+), 8 deletions(-)
>>>>  create mode 100644 tests/migration/aarch64-a-b-kernel.S
>>>>  create mode 100644 tests/migration/aarch64-a-b-kernel.h
>>>>
>>>> diff --git a/tests/Makefile.include b/tests/Makefile.include
>>>> index a1bcbffe12..df9f64438f 100644
>>>> --- a/tests/Makefile.include
>>>> +++ b/tests/Makefile.include
>>>> @@ -372,6 +372,7 @@ check-qtest-arm-y += tests/sdhci-test$(EXESUF)
>>>>  check-qtest-aarch64-y = tests/numa-test$(EXESUF)
>>>>  check-qtest-aarch64-y += tests/sdhci-test$(EXESUF)
>>>>  check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
>>>> +check-qtest-aarch64-y += tests/migration-test$(EXESUF)
>>>>  
>>>>  check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
>>>>  
>>>> diff --git a/tests/migration-test.c b/tests/migration-test.c
>>>> index e2e06ed337..a4f6732a59 100644
>>>> --- a/tests/migration-test.c
>>>> +++ b/tests/migration-test.c
>>>> @@ -11,6 +11,7 @@
>>>>   */
>>>>  
>>>>  #include "qemu/osdep.h"
>>>> +#include 
>>>>  
>>>>  #include "libqtest.h"
>>>>  #include "qapi/qmp/qdict.h"
>>>> @@ -23,8 +24,8 @@
>>>>  
>>>>  #include "migration/migration-test.h"
>>>>  
>>>> -const unsigned start_address = TEST_MEM_START;
>>>> -const unsigned end_address = TEST_MEM_END;
>>>> +unsigned start_address = TEST_MEM_START;
>>>> +unsigned end_address = TEST_MEM_END;
>>>>  bool got_stop;
>>>>  
>>>>  #if defined(__linux__)
>>>> @@ -81,12 +82,13 @@ static const char *tmpfs;
>>>>   * outputting a 'B' every so often if it's still running.
>>>>   */
>>>>  #include "tests/migration/x86-a-b-bootblock.h"
>>>> +#include "tests/migration/aarch64-a-b-kernel.h"
>>>>  
>>>> -static void init_bootfile_x86(const char *bootpath)
>>>> +static void init_bootfile(const char *bootpath, void *content)
>>>>  {
>>>>  FILE *bootfile = fopen(bootpath, "wb");
>>>>  
>>>> -g_assert_cmpint(fwrite(x86_bootsect, 512, 1, bootfile), ==, 1);
>>>> +g_assert_cmpint(fwrite(content, 512, 1, bootfile), ==, 1);
>>>>  fclose(bootfile);
>>>>  }
>>>>  
>>>> @@ -393,7 +395,7 @@ static void test_migrate_start(QTestState **from, 
>>>> QTestState **to,
>>>>  got_stop = false;
>>>>  
>>>>  if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
>>>> -init_bootfile_x86(bootpath);
>>>> +init_bootfile(bootpath, x86_bootsect);
>>&g

[Qemu-devel] [PATCH V6 1/4] rules: Move cross compilation auto detection functions to rules.mak

2018-02-26 Thread Wei Huang
This patch moves the auto detection functions for cross compilation from
roms/Makefile to rules.mak. So the functions can be shared among Makefiles
in QEMU.

Signed-off-by: Wei Huang <w...@redhat.com>
Reviewed-by: Andrew Jones <drjo...@redhat.com>
---
 roms/Makefile | 24 +++-
 rules.mak | 15 +++
 2 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/roms/Makefile b/roms/Makefile
index b5e5a69e91..e972c65333 100644
--- a/roms/Makefile
+++ b/roms/Makefile
@@ -21,23 +21,6 @@ pxe-rom-virtio   efi-rom-virtio   : DID := 1000
 pxe-rom-vmxnet3  efi-rom-vmxnet3  : VID := 15ad
 pxe-rom-vmxnet3  efi-rom-vmxnet3  : DID := 07b0
 
-#
-# cross compiler auto detection
-#
-path := $(subst :, ,$(PATH))
-system := $(shell uname -s | tr "A-Z" "a-z")
-
-# first find cross binutils in path
-find-cross-ld = $(firstword $(wildcard $(patsubst 
%,%/$(1)-*$(system)*-ld,$(path
-# then check we have cross gcc too
-find-cross-gcc = $(firstword $(wildcard $(patsubst %ld,%gcc,$(call 
find-cross-ld,$(1)
-# finally strip off path + toolname so we get the prefix
-find-cross-prefix = $(subst gcc,,$(notdir $(call find-cross-gcc,$(1
-
-powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64)
-powerpc_cross_prefix := $(call find-cross-prefix,powerpc)
-x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
-
 # tag our seabios builds
 SEABIOS_EXTRAVERSION="-prebuilt.qemu-project.org"
 
@@ -66,6 +49,13 @@ default:
@echo "  skiboot-- update skiboot.lid"
@echo "  u-boot.e500-- update u-boot.e500"
 
+SRC_PATH=..
+include $(SRC_PATH)/rules.mak
+
+powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64)
+powerpc_cross_prefix := $(call find-cross-prefix,powerpc)
+x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
+
 bios: build-seabios-config-seabios-128k build-seabios-config-seabios-256k
cp seabios/builds/seabios-128k/bios.bin ../pc-bios/bios.bin
cp seabios/builds/seabios-256k/bios.bin ../pc-bios/bios-256k.bin
diff --git a/rules.mak b/rules.mak
index 6e943335f3..ef8adee3f8 100644
--- a/rules.mak
+++ b/rules.mak
@@ -62,6 +62,21 @@ expand-objs = $(strip $(sort $(filter %.o,$1)) \
   $(foreach o,$(filter %.mo,$1),$($o-objs)) \
   $(filter-out %.o %.mo,$1))
 
+# Cross compilation auto detection. Use find-cross-prefix to detect the
+# target archtecture's prefix, and then append it to the build tool or pass
+# it to CROSS_COMPILE directly. Here is one example:
+#  x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
+#  $(x86_64_cross_prefix)gcc -c test.c -o test.o
+#  make -C testdir CROSS_COMPILE=$(x86_64_cross_prefix)
+cross-search-path := $(subst :, ,$(PATH))
+cross-host-system := $(shell uname -s | tr "A-Z" "a-z")
+
+find-cross-ld = $(firstword $(wildcard $(patsubst \
+%,%/$(1)-*$(cross-host-system)*-ld,$(cross-search-path
+find-cross-gcc = $(firstword $(wildcard \
+$(patsubst %ld,%gcc,$(call find-cross-ld,$(1)
+find-cross-prefix = $(subst gcc,,$(notdir $(call find-cross-gcc,$(1
+
 %.o: %.c
$(call quiet-command,$(CC) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \
   $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) \
-- 
2.14.3




[Qemu-devel] [PATCH V6 3/4] tests/migration: Add migration-test header file

2018-02-26 Thread Wei Huang
This patch moves the settings related migration-test from the
migration-test.c file to a seperate header file. It also renames the
x86-a-b-bootblock.s file extension from .s to .S, allowing gcc
pre-processor to include the C-style header file correctly.

Signed-off-by: Wei Huang <w...@redhat.com>
Reviewed-by: Andrew Jones <drjo...@redhat.com>
---
 tests/migration-test.c | 28 +++---
 tests/migration/Makefile   |  4 ++--
 tests/migration/migration-test.h   | 18 ++
 .../{x86-a-b-bootblock.s => x86-a-b-bootblock.S}   |  7 +++---
 tests/migration/x86-a-b-bootblock.h|  2 +-
 5 files changed, 39 insertions(+), 20 deletions(-)
 create mode 100644 tests/migration/migration-test.h
 rename tests/migration/{x86-a-b-bootblock.s => x86-a-b-bootblock.S} (94%)

diff --git a/tests/migration-test.c b/tests/migration-test.c
index 74f9361bdd..c88b7e7a19 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -21,10 +21,10 @@
 #include "sysemu/sysemu.h"
 #include "hw/nvram/chrp_nvram.h"
 
-#define MIN_NVRAM_SIZE 8192 /* from spapr_nvram.c */
+#include "migration/migration-test.h"
 
-const unsigned start_address = 1024 * 1024;
-const unsigned end_address = 100 * 1024 * 1024;
+const unsigned start_address = TEST_MEM_START;
+const unsigned end_address = TEST_MEM_END;
 bool got_stop;
 
 #if defined(__linux__)
@@ -77,8 +77,8 @@ static bool ufd_version_check(void)
 
 static const char *tmpfs;
 
-/* A simple PC boot sector that modifies memory (1-100MB) quickly
- * outputting a 'B' every so often if it's still running.
+/* The boot file modifies memory area in [start_address, end_address)
+ * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
  */
 #include "tests/migration/x86-a-b-bootblock.h"
 
@@ -104,9 +104,8 @@ static void init_bootfile_ppc(const char *bootpath)
 memcpy(header->name, "common", 6);
 chrp_nvram_finish_partition(header, MIN_NVRAM_SIZE);
 
-/* FW_MAX_SIZE is 4MB, but slof.bin is only 900KB,
- * so let's modify memory between 1MB and 100MB
- * to do like PC bootsector
+/* FW_MAX_SIZE is 4MB, but slof.bin is only 900KB. So it is OK to modify
+ * memory between start_address and end_address like PC bootsector does.
  */
 
 sprintf(buf + 16,
@@ -263,11 +262,11 @@ static void wait_for_migration_pass(QTestState *who)
 static void check_guests_ram(QTestState *who)
 {
 /* Our ASM test will have been incrementing one byte from each page from
- * 1MB to <100MB in order.
- * This gives us a constraint that any page's byte should be equal or less
- * than the previous pages byte (mod 256); and they should all be equal
- * except for one transition at the point where we meet the incrementer.
- * (We're running this with the guest stopped).
+ * start_address to < end_address in order. This gives us a constraint
+ * that any page's byte should be equal or less than the previous pages
+ * byte (mod 256); and they should all be equal except for one transition
+ * at the point where we meet the incrementer. (We're running this with
+ * the guest stopped).
  */
 unsigned address;
 uint8_t first_byte;
@@ -278,7 +277,8 @@ static void check_guests_ram(QTestState *who)
 qtest_memread(who, start_address, _byte, 1);
 last_byte = first_byte;
 
-for (address = start_address + 4096; address < end_address; address += 
4096)
+for (address = start_address + TEST_MEM_PAGE_SIZE; address < end_address;
+ address += TEST_MEM_PAGE_SIZE)
 {
 uint8_t b;
 qtest_memread(who, address, , 1);
diff --git a/tests/migration/Makefile b/tests/migration/Makefile
index 8fbedaa8b8..013b8d1f44 100644
--- a/tests/migration/Makefile
+++ b/tests/migration/Makefile
@@ -25,8 +25,8 @@ include $(SRC_PATH)/rules.mak
 
 x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
 
-x86-a-b-bootblock.h: x86-a-b-bootblock.s
-   $(x86_64_cross_prefix)as --32 -march=i486 $< -o x86.o
+x86-a-b-bootblock.h: x86-a-b-bootblock.S
+   $(x86_64_cross_prefix)gcc -m32 -march=i486 -c $< -o x86.o
$(x86_64_cross_prefix)objcopy -O binary x86.o x86.boot
dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124
echo "$$__note" > $@
diff --git a/tests/migration/migration-test.h b/tests/migration/migration-test.h
new file mode 100644
index 00..48b59b3281
--- /dev/null
+++ b/tests/migration/migration-test.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2018 Red Hat, Inc. and/or its affiliates
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#ifndef _TEST_MIGRATION_H_
+#define _TEST_MIGRATION_H_
+
+/* Common */
+#define TEST_MEM_START  (1 * 1024 * 1024)
+#define TEST_MEM_END(100 * 1024 * 1

[Qemu-devel] [PATCH V6 4/4] tests: Add migration test for aarch64

2018-02-26 Thread Wei Huang
This patch adds migration test support for aarch64. The test code, which
implements the same functionality as x86, is booted as a kernel in qemu.
Here are the design choices we make for aarch64:

 * We choose this -kernel approach because aarch64 QEMU doesn't provide a
   built-in fw like x86 does. So instead of relying on a boot loader, we
   use -kernel approach for aarch64.
 * The serial output is sent to PL011 directly.
 * The physical memory base for mach-virt machine is 0x4000. We change
   the start_address and end_address for aarch64.

In addition to providing the binary, this patch also includes the source
code and the build script in tests/migration/. So users can change the
source and/or re-compile the binary as they wish.

Signed-off-by: Wei Huang <w...@redhat.com>
---
 tests/Makefile.include   |  1 +
 tests/migration-test.c   | 46 +++---
 tests/migration/Makefile | 12 +-
 tests/migration/aarch64-a-b-kernel.S | 75 
 tests/migration/aarch64-a-b-kernel.h | 19 +
 tests/migration/migration-test.h |  9 +
 6 files changed, 154 insertions(+), 8 deletions(-)
 create mode 100644 tests/migration/aarch64-a-b-kernel.S
 create mode 100644 tests/migration/aarch64-a-b-kernel.h

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 577eb573a2..538173866c 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -372,6 +372,7 @@ check-qtest-arm-y += tests/sdhci-test$(EXESUF)
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
 check-qtest-aarch64-y += tests/sdhci-test$(EXESUF)
 check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
+check-qtest-aarch64-y += tests/migration-test$(EXESUF)
 
 check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
 
diff --git a/tests/migration-test.c b/tests/migration-test.c
index c88b7e7a19..9cc98445b0 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -11,6 +11,7 @@
  */
 
 #include "qemu/osdep.h"
+#include 
 
 #include "libqtest.h"
 #include "qapi/qmp/qdict.h"
@@ -23,8 +24,8 @@
 
 #include "migration/migration-test.h"
 
-const unsigned start_address = TEST_MEM_START;
-const unsigned end_address = TEST_MEM_END;
+unsigned start_address = TEST_MEM_START;
+unsigned end_address = TEST_MEM_END;
 bool got_stop;
 
 #if defined(__linux__)
@@ -81,12 +82,13 @@ static const char *tmpfs;
  * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
  */
 #include "tests/migration/x86-a-b-bootblock.h"
+#include "tests/migration/aarch64-a-b-kernel.h"
 
-static void init_bootfile_x86(const char *bootpath)
+static void init_bootfile(const char *bootpath, void *content)
 {
 FILE *bootfile = fopen(bootpath, "wb");
 
-g_assert_cmpint(fwrite(x86_bootsect, 512, 1, bootfile), ==, 1);
+g_assert_cmpint(fwrite(content, 512, 1, bootfile), ==, 1);
 fclose(bootfile);
 }
 
@@ -392,7 +394,7 @@ static void test_migrate_start(QTestState **from, 
QTestState **to,
 got_stop = false;
 
 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-init_bootfile_x86(bootpath);
+init_bootfile(bootpath, x86_bootsect);
 cmd_src = g_strdup_printf("-machine accel=%s -m 150M"
   " -name source,debug-threads=on"
   " -serial file:%s/src_serial"
@@ -421,6 +423,38 @@ static void test_migrate_start(QTestState **from, 
QTestState **to,
   " -serial file:%s/dest_serial"
   " -incoming %s",
   accel, tmpfs, uri);
+} else if (strcmp(arch, "aarch64") == 0) {
+const char *cpu;
+const char *gic_ver;
+struct utsname utsname;
+
+/* kvm and tcg need different cpu and gic-version configs */
+if (access("/dev/kvm", F_OK) == 0 && uname() == 0 &&
+strcmp(utsname.machine, "aarch64") == 0) {
+accel = "kvm";
+cpu = "host";
+gic_ver = "host";
+} else {
+accel = "tcg";
+cpu = "cortex-a57";
+gic_ver = "2";
+}
+
+init_bootfile(bootpath, aarch64_kernel);
+cmd_src = g_strdup_printf("-machine virt,accel=%s,gic-version=%s "
+  "-name vmsource,debug-threads=on -cpu %s "
+  "-m 150M -serial file:%s/src_serial "
+  "-kernel %s ",
+  accel, gic_ver, cpu, tmpfs, bootpath);
+cmd_dst = g_strdup_printf("-machine virt,accel=%s,gic-version=%s "
+  "-name vmdes

[Qemu-devel] [PATCH V6 0/4] tests: Add migration test for aarch64

2018-02-26 Thread Wei Huang
This patchset adds a migration test for aarch64. It leverages
Dave Gilbert's recent patch "tests/migration: Add source to PC boot block"
to create a new test case for aarch64.

V5->V6:
 * Add Reviewed-by to patch 1-3
 * Add more design notes in patch 4 (aarch64 assembly compilation, bin space)

V4->V5:
 * Extract cross compilation detection code into rules.mak for sharing
 * Minor comment and code revision in migration-test.c & aarch64-a-b-kernel.S
 
V3->V4:
 * Rename .s to .S, allowing assembly to include C-style header file
 * Move test defines into a new migration-test.h file
 * Use different cpu & gic settings for kvm and tcg modes on aarch64
 * Clean up aarch64-a-b-kernel.S based on Andrew Jones' comments
 
V2->V3:
 * Convert build script to Makefile
 * Add cross-compilation support
 * Fix CPU type for "tcg" machine type
 * Revise asm code and the compilation process from asm to header file

V1->V2:
 * Similar to Dave Gilbert's recent changes to migration-test, we
   provide the test source and a build script in V2.
 * aarch64 kernel blob is defined as "unsigned char" because the source
   is now provided in V2.
 * Add "-machine none" to test_deprecated() because aarch64 doesn't have
   a default machine type.

RFC->V1:
 * aarch64 kernel blob is defined as an uint32_t array
 * The test code is re-written to address a data caching issue under KVM.
   Tests passed under both x86 and aarch64.
 * Re-use init_bootfile_x86() for both x86 and aarch64
 * Other minor fixes

Thanks,
-Wei

Wei Huang (4):
  rules: Move cross compilation auto detection functions to rules.mak
  tests/migration: Convert the boot block compilation script into
Makefile
  tests/migration: Add migration-test header file
  tests: Add migration test for aarch64

 roms/Makefile  | 24 ++-
 rules.mak  | 15 +
 tests/Makefile.include |  1 +
 tests/migration-test.c | 70 ++--
 tests/migration/Makefile   | 44 +
 tests/migration/aarch64-a-b-kernel.S   | 75 ++
 tests/migration/aarch64-a-b-kernel.h   | 19 ++
 tests/migration/migration-test.h   | 27 
 tests/migration/rebuild-x86-bootblock.sh   | 33 --
 .../{x86-a-b-bootblock.s => x86-a-b-bootblock.S}   | 12 ++--
 tests/migration/x86-a-b-bootblock.h|  4 +-
 11 files changed, 248 insertions(+), 76 deletions(-)
 create mode 100644 tests/migration/Makefile
 create mode 100644 tests/migration/aarch64-a-b-kernel.S
 create mode 100644 tests/migration/aarch64-a-b-kernel.h
 create mode 100644 tests/migration/migration-test.h
 delete mode 100755 tests/migration/rebuild-x86-bootblock.sh
 rename tests/migration/{x86-a-b-bootblock.s => x86-a-b-bootblock.S} (88%)

-- 
2.14.3




[Qemu-devel] [PATCH V6 2/4] tests/migration: Convert the boot block compilation script into Makefile

2018-02-26 Thread Wei Huang
The x86 boot block header currently is generated with a shell script.
To better support other CPUs (e.g. aarch64), we convert the script
into Makefile. This allows us to 1) support cross-compilation easily,
and 2) avoid creating a script file for every architecture.

Signed-off-by: Wei Huang <w...@redhat.com>
Reviewed-by: Andrew Jones <drjo...@redhat.com>
---
 tests/migration/Makefile | 36 
 tests/migration/rebuild-x86-bootblock.sh | 33 -
 tests/migration/x86-a-b-bootblock.h  |  2 +-
 tests/migration/x86-a-b-bootblock.s  |  5 ++---
 4 files changed, 39 insertions(+), 37 deletions(-)
 create mode 100644 tests/migration/Makefile
 delete mode 100755 tests/migration/rebuild-x86-bootblock.sh

diff --git a/tests/migration/Makefile b/tests/migration/Makefile
new file mode 100644
index 00..8fbedaa8b8
--- /dev/null
+++ b/tests/migration/Makefile
@@ -0,0 +1,36 @@
+#
+# Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
+#
+# Authors:
+#   Dave Gilbert <dgilb...@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+#
+export __note
+override define __note
+/* This file is automatically generated from
+ * tests/migration/$<, edit that and then run
+ * "make $@" inside tests/migration to update,
+ * and then remember to send both in your patch submission.
+ */
+endef
+
+all: x86-a-b-bootblock.h
+# Dummy command so that make thinks it has done something
+   @true
+
+SRC_PATH=../..
+include $(SRC_PATH)/rules.mak
+
+x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
+
+x86-a-b-bootblock.h: x86-a-b-bootblock.s
+   $(x86_64_cross_prefix)as --32 -march=i486 $< -o x86.o
+   $(x86_64_cross_prefix)objcopy -O binary x86.o x86.boot
+   dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124
+   echo "$$__note" > $@
+   xxd -i x86.bootsect | sed -e 's/.*int.*//' >> $@
+
+clean:
+   rm -f *.bootsect *.boot *.o
diff --git a/tests/migration/rebuild-x86-bootblock.sh 
b/tests/migration/rebuild-x86-bootblock.sh
deleted file mode 100755
index 86cec5d284..00
--- a/tests/migration/rebuild-x86-bootblock.sh
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/sh
-# Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
-# This work is licensed under the terms of the GNU GPL, version 2 or later.
-# See the COPYING file in the top-level directory.
-#
-# Author: dgilb...@redhat.com
-
-ASMFILE=$PWD/tests/migration/x86-a-b-bootblock.s
-HEADER=$PWD/tests/migration/x86-a-b-bootblock.h
-
-if [ ! -e "$ASMFILE" ]
-then
-  echo "Couldn't find $ASMFILE" >&2
-  exit 1
-fi
-
-ASM_WORK_DIR=$(mktemp -d --tmpdir X86BB.XX)
-cd "$ASM_WORK_DIR" &&
-as --32 -march=i486 "$ASMFILE" -o x86.o &&
-objcopy -O binary x86.o x86.boot &&
-dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124 &&
-xxd -i x86.bootsect |
-sed -e 's/.*int.*//' > x86.hex &&
-cat - x86.hex < "$HEADER"
-/* This file is automatically generated from
- * tests/migration/x86-a-b-bootblock.s, edit that and then run
- * tests/migration/rebuild-x86-bootblock.sh to update,
- * and then remember to send both in your patch submission.
- */
-HERE
-
-rm x86.hex x86.bootsect x86.boot x86.o
-cd .. && rmdir "$ASM_WORK_DIR"
diff --git a/tests/migration/x86-a-b-bootblock.h 
b/tests/migration/x86-a-b-bootblock.h
index 78a151fe2a..9e8e2e028b 100644
--- a/tests/migration/x86-a-b-bootblock.h
+++ b/tests/migration/x86-a-b-bootblock.h
@@ -1,6 +1,6 @@
 /* This file is automatically generated from
  * tests/migration/x86-a-b-bootblock.s, edit that and then run
- * tests/migration/rebuild-x86-bootblock.sh to update,
+ * "make x86-a-b-bootblock.h" inside tests/migration to update,
  * and then remember to send both in your patch submission.
  */
 unsigned char x86_bootsect[] = {
diff --git a/tests/migration/x86-a-b-bootblock.s 
b/tests/migration/x86-a-b-bootblock.s
index b1642641a7..98dbfab084 100644
--- a/tests/migration/x86-a-b-bootblock.s
+++ b/tests/migration/x86-a-b-bootblock.s
@@ -3,9 +3,8 @@
 #  range.
 #  Outputs an initial 'A' on serial followed by repeated 'B's
 #
-# run   tests/migration/rebuild-x86-bootblock.sh
-#   to regenerate the hex, and remember to include both the .h and .s
-#   in any patches.
+#  In tests/migration dir, run 'make x86-a-b-bootblock.h' to regenerate
+#  the hex, and remember to include both the .h and .s in any patches.
 #
 # Copyright (c) 2016 Red Hat, Inc. and/or its affiliates
 # This work is licensed under the terms of the GNU GPL, version 2 or later.
-- 
2.14.3




Re: [Qemu-devel] [PATCH V4 3/3] tests: Add migration test for aarch64

2018-02-23 Thread Wei Huang


On 02/22/2018 03:00 AM, Andrew Jones wrote:
> On Wed, Feb 21, 2018 at 10:44:17PM -0600, Wei Huang wrote:
>> This patch adds migration test support for aarch64. The test code, which
>> implements the same functionality as x86, is booted as a kernel in qemu.
>> Here are the design choices we make for aarch64:
>>
>>  * We choose this -kernel approach because aarch64 QEMU doesn't provide a
>>built-in fw like x86 does. So instead of relying on a boot loader, we
>>use -kernel approach for aarch64.
>>  * The serial output is sent to PL011 directly.
>>  * The physical memory base for mach-virt machine is 0x4000. We change
>>the start_address and end_address for aarch64.
>>
>> In addition to providing the binary, this patch also includes the source
>> code and the build script in tests/migration/. So users can change the
>> source and/or re-compile the binary as they wish.
>>
>> Signed-off-by: Wei Huang <w...@redhat.com>
>> ---
>>  tests/Makefile.include   |  1 +
>>  tests/migration-test.c   | 47 +---
>>  tests/migration/Makefile | 12 +-
>>  tests/migration/aarch64-a-b-kernel.S | 71 
>> 
>>  tests/migration/aarch64-a-b-kernel.h | 19 ++
>>  tests/migration/migration-test.h |  5 +++
>>  6 files changed, 147 insertions(+), 8 deletions(-)
>>  create mode 100644 tests/migration/aarch64-a-b-kernel.S
>>  create mode 100644 tests/migration/aarch64-a-b-kernel.h
>>
>> diff --git a/tests/Makefile.include b/tests/Makefile.include
>> index a1bcbffe12..df9f64438f 100644
>> --- a/tests/Makefile.include
>> +++ b/tests/Makefile.include
>> @@ -372,6 +372,7 @@ check-qtest-arm-y += tests/sdhci-test$(EXESUF)
>>  check-qtest-aarch64-y = tests/numa-test$(EXESUF)
>>  check-qtest-aarch64-y += tests/sdhci-test$(EXESUF)
>>  check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
>> +check-qtest-aarch64-y += tests/migration-test$(EXESUF)
>>  
>>  check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
>>  
>> diff --git a/tests/migration-test.c b/tests/migration-test.c
>> index e2e06ed337..a4f6732a59 100644
>> --- a/tests/migration-test.c
>> +++ b/tests/migration-test.c
>> @@ -11,6 +11,7 @@
>>   */
>>  
>>  #include "qemu/osdep.h"
>> +#include 
>>  
>>  #include "libqtest.h"
>>  #include "qapi/qmp/qdict.h"
>> @@ -23,8 +24,8 @@
>>  
>>  #include "migration/migration-test.h"
>>  
>> -const unsigned start_address = TEST_MEM_START;
>> -const unsigned end_address = TEST_MEM_END;
>> +unsigned start_address = TEST_MEM_START;
>> +unsigned end_address = TEST_MEM_END;
>>  bool got_stop;
>>  
>>  #if defined(__linux__)
>> @@ -81,12 +82,13 @@ static const char *tmpfs;
>>   * outputting a 'B' every so often if it's still running.
>>   */
>>  #include "tests/migration/x86-a-b-bootblock.h"
>> +#include "tests/migration/aarch64-a-b-kernel.h"
>>  
>> -static void init_bootfile_x86(const char *bootpath)
>> +static void init_bootfile(const char *bootpath, void *content)
>>  {
>>  FILE *bootfile = fopen(bootpath, "wb");
>>  
>> -g_assert_cmpint(fwrite(x86_bootsect, 512, 1, bootfile), ==, 1);
>> +g_assert_cmpint(fwrite(content, 512, 1, bootfile), ==, 1);
>>  fclose(bootfile);
>>  }
>>  
>> @@ -393,7 +395,7 @@ static void test_migrate_start(QTestState **from, 
>> QTestState **to,
>>  got_stop = false;
>>  
>>  if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
>> -init_bootfile_x86(bootpath);
>> +init_bootfile(bootpath, x86_bootsect);
>>  cmd_src = g_strdup_printf("-machine accel=%s -m 150M"
>>" -name source,debug-threads=on"
>>" -serial file:%s/src_serial"
>> @@ -422,6 +424,39 @@ static void test_migrate_start(QTestState **from, 
>> QTestState **to,
>>" -serial file:%s/dest_serial"
>>" -incoming %s",
>>accel, tmpfs, uri);
>> +} else if (strcmp(arch, "aarch64") == 0) {
>> +const char *cpu;
>> +const char *gic_ver;
>> +struct utsname utsname;
>> +
>> +/* kvm and tcg need different cpu and gic-version configs */
>

[Qemu-devel] [PATCH V5 4/4] tests: Add migration test for aarch64

2018-02-23 Thread Wei Huang
This patch adds migration test support for aarch64. The test code, which
implements the same functionality as x86, is booted as a kernel in qemu.
Here are the design choices we make for aarch64:

 * We choose this -kernel approach because aarch64 QEMU doesn't provide a
   built-in fw like x86 does. So instead of relying on a boot loader, we
   use -kernel approach for aarch64.
 * The serial output is sent to PL011 directly.
 * The physical memory base for mach-virt machine is 0x4000. We change
   the start_address and end_address for aarch64.

In addition to providing the binary, this patch also includes the source
code and the build script in tests/migration/. So users can change the
source and/or re-compile the binary as they wish.

Signed-off-by: Wei Huang <w...@redhat.com>
---
 tests/Makefile.include   |  1 +
 tests/migration-test.c   | 50 ++---
 tests/migration/Makefile | 12 +-
 tests/migration/aarch64-a-b-kernel.S | 71 
 tests/migration/aarch64-a-b-kernel.h | 19 ++
 tests/migration/migration-test.h |  5 +++
 6 files changed, 150 insertions(+), 8 deletions(-)
 create mode 100644 tests/migration/aarch64-a-b-kernel.S
 create mode 100644 tests/migration/aarch64-a-b-kernel.h

diff --git a/tests/Makefile.include b/tests/Makefile.include
index a1bcbffe12..df9f64438f 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -372,6 +372,7 @@ check-qtest-arm-y += tests/sdhci-test$(EXESUF)
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
 check-qtest-aarch64-y += tests/sdhci-test$(EXESUF)
 check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
+check-qtest-aarch64-y += tests/migration-test$(EXESUF)
 
 check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
 
diff --git a/tests/migration-test.c b/tests/migration-test.c
index ce2922df6a..d60e34c82d 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -11,6 +11,7 @@
  */
 
 #include "qemu/osdep.h"
+#include 
 
 #include "libqtest.h"
 #include "qapi/qmp/qdict.h"
@@ -23,8 +24,8 @@
 
 #include "migration/migration-test.h"
 
-const unsigned start_address = TEST_MEM_START;
-const unsigned end_address = TEST_MEM_END;
+unsigned start_address = TEST_MEM_START;
+unsigned end_address = TEST_MEM_END;
 bool got_stop;
 
 #if defined(__linux__)
@@ -81,12 +82,13 @@ static const char *tmpfs;
  * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
  */
 #include "tests/migration/x86-a-b-bootblock.h"
+#include "tests/migration/aarch64-a-b-kernel.h"
 
-static void init_bootfile_x86(const char *bootpath)
+static void init_bootfile(const char *bootpath, void *content)
 {
 FILE *bootfile = fopen(bootpath, "wb");
 
-g_assert_cmpint(fwrite(x86_bootsect, 512, 1, bootfile), ==, 1);
+g_assert_cmpint(fwrite(content, 512, 1, bootfile), ==, 1);
 fclose(bootfile);
 }
 
@@ -392,7 +394,7 @@ static void test_migrate_start(QTestState **from, 
QTestState **to,
 got_stop = false;
 
 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-init_bootfile_x86(bootpath);
+init_bootfile(bootpath, x86_bootsect);
 cmd_src = g_strdup_printf("-machine accel=%s -m 150M"
   " -name source,debug-threads=on"
   " -serial file:%s/src_serial"
@@ -421,6 +423,42 @@ static void test_migrate_start(QTestState **from, 
QTestState **to,
   " -serial file:%s/dest_serial"
   " -incoming %s",
   accel, tmpfs, uri);
+} else if (strcmp(arch, "aarch64") == 0) {
+const char *cpu;
+const char *gic_ver;
+struct utsname utsname;
+
+/* kvm and tcg need different cpu and gic-version configs */
+if (access("/dev/kvm", F_OK) == 0 && uname() == 0 &&
+strcmp(utsname.machine, "aarch64") == 0) {
+accel = "kvm";
+cpu = "host";
+gic_ver = "host";
+} else {
+accel = "tcg";
+cpu = "cortex-a57";
+gic_ver = "2";
+}
+
+init_bootfile(bootpath, aarch64_kernel);
+cmd_src = g_strdup_printf("-machine virt,accel=%s,gic-version=%s "
+  "-name vmsource,debug-threads=on -cpu %s "
+  "-m 150M -serial file:%s/src_serial "
+  "-kernel %s ",
+  accel, gic_ver, cpu, tmpfs, bootpath);
+cmd_dst = g_strdup_printf("-machine virt,accel=%s,gic-version=%s "
+  "-name vmdest,

[Qemu-devel] [PATCH V5 2/4] tests/migration: Convert the boot block compilation script into Makefile

2018-02-23 Thread Wei Huang
The x86 boot block header currently is generated with a shell script.
To better support other CPUs (e.g. aarch64), we convert the script
into Makefile. This allows us to 1) support cross-compilation easily,
and 2) avoid creating a script file for every architecture.

Signed-off-by: Wei Huang <w...@redhat.com>
---
 tests/migration/Makefile | 36 
 tests/migration/rebuild-x86-bootblock.sh | 33 -
 tests/migration/x86-a-b-bootblock.h  |  2 +-
 tests/migration/x86-a-b-bootblock.s  |  5 ++---
 4 files changed, 39 insertions(+), 37 deletions(-)
 create mode 100644 tests/migration/Makefile
 delete mode 100755 tests/migration/rebuild-x86-bootblock.sh

diff --git a/tests/migration/Makefile b/tests/migration/Makefile
new file mode 100644
index 00..8fbedaa8b8
--- /dev/null
+++ b/tests/migration/Makefile
@@ -0,0 +1,36 @@
+#
+# Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
+#
+# Authors:
+#   Dave Gilbert <dgilb...@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+#
+export __note
+override define __note
+/* This file is automatically generated from
+ * tests/migration/$<, edit that and then run
+ * "make $@" inside tests/migration to update,
+ * and then remember to send both in your patch submission.
+ */
+endef
+
+all: x86-a-b-bootblock.h
+# Dummy command so that make thinks it has done something
+   @true
+
+SRC_PATH=../..
+include $(SRC_PATH)/rules.mak
+
+x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
+
+x86-a-b-bootblock.h: x86-a-b-bootblock.s
+   $(x86_64_cross_prefix)as --32 -march=i486 $< -o x86.o
+   $(x86_64_cross_prefix)objcopy -O binary x86.o x86.boot
+   dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124
+   echo "$$__note" > $@
+   xxd -i x86.bootsect | sed -e 's/.*int.*//' >> $@
+
+clean:
+   rm -f *.bootsect *.boot *.o
diff --git a/tests/migration/rebuild-x86-bootblock.sh 
b/tests/migration/rebuild-x86-bootblock.sh
deleted file mode 100755
index 86cec5d284..00
--- a/tests/migration/rebuild-x86-bootblock.sh
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/sh
-# Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
-# This work is licensed under the terms of the GNU GPL, version 2 or later.
-# See the COPYING file in the top-level directory.
-#
-# Author: dgilb...@redhat.com
-
-ASMFILE=$PWD/tests/migration/x86-a-b-bootblock.s
-HEADER=$PWD/tests/migration/x86-a-b-bootblock.h
-
-if [ ! -e "$ASMFILE" ]
-then
-  echo "Couldn't find $ASMFILE" >&2
-  exit 1
-fi
-
-ASM_WORK_DIR=$(mktemp -d --tmpdir X86BB.XX)
-cd "$ASM_WORK_DIR" &&
-as --32 -march=i486 "$ASMFILE" -o x86.o &&
-objcopy -O binary x86.o x86.boot &&
-dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124 &&
-xxd -i x86.bootsect |
-sed -e 's/.*int.*//' > x86.hex &&
-cat - x86.hex < "$HEADER"
-/* This file is automatically generated from
- * tests/migration/x86-a-b-bootblock.s, edit that and then run
- * tests/migration/rebuild-x86-bootblock.sh to update,
- * and then remember to send both in your patch submission.
- */
-HERE
-
-rm x86.hex x86.bootsect x86.boot x86.o
-cd .. && rmdir "$ASM_WORK_DIR"
diff --git a/tests/migration/x86-a-b-bootblock.h 
b/tests/migration/x86-a-b-bootblock.h
index 78a151fe2a..9e8e2e028b 100644
--- a/tests/migration/x86-a-b-bootblock.h
+++ b/tests/migration/x86-a-b-bootblock.h
@@ -1,6 +1,6 @@
 /* This file is automatically generated from
  * tests/migration/x86-a-b-bootblock.s, edit that and then run
- * tests/migration/rebuild-x86-bootblock.sh to update,
+ * "make x86-a-b-bootblock.h" inside tests/migration to update,
  * and then remember to send both in your patch submission.
  */
 unsigned char x86_bootsect[] = {
diff --git a/tests/migration/x86-a-b-bootblock.s 
b/tests/migration/x86-a-b-bootblock.s
index b1642641a7..98dbfab084 100644
--- a/tests/migration/x86-a-b-bootblock.s
+++ b/tests/migration/x86-a-b-bootblock.s
@@ -3,9 +3,8 @@
 #  range.
 #  Outputs an initial 'A' on serial followed by repeated 'B's
 #
-# run   tests/migration/rebuild-x86-bootblock.sh
-#   to regenerate the hex, and remember to include both the .h and .s
-#   in any patches.
+#  In tests/migration dir, run 'make x86-a-b-bootblock.h' to regenerate
+#  the hex, and remember to include both the .h and .s in any patches.
 #
 # Copyright (c) 2016 Red Hat, Inc. and/or its affiliates
 # This work is licensed under the terms of the GNU GPL, version 2 or later.
-- 
2.14.3




[Qemu-devel] [PATCH V5 1/4] rules: Move cross compilation auto detection functions to rules.mak

2018-02-23 Thread Wei Huang
This patch moves the auto detection functions for cross compilation from
roms/Makefile to rules.mak. So the functions can be shared among Makefiles
in QEMU.

Signed-off-by: Wei Huang <w...@redhat.com>
---
 roms/Makefile | 24 +++-
 rules.mak | 15 +++
 2 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/roms/Makefile b/roms/Makefile
index b5e5a69e91..e972c65333 100644
--- a/roms/Makefile
+++ b/roms/Makefile
@@ -21,23 +21,6 @@ pxe-rom-virtio   efi-rom-virtio   : DID := 1000
 pxe-rom-vmxnet3  efi-rom-vmxnet3  : VID := 15ad
 pxe-rom-vmxnet3  efi-rom-vmxnet3  : DID := 07b0
 
-#
-# cross compiler auto detection
-#
-path := $(subst :, ,$(PATH))
-system := $(shell uname -s | tr "A-Z" "a-z")
-
-# first find cross binutils in path
-find-cross-ld = $(firstword $(wildcard $(patsubst 
%,%/$(1)-*$(system)*-ld,$(path
-# then check we have cross gcc too
-find-cross-gcc = $(firstword $(wildcard $(patsubst %ld,%gcc,$(call 
find-cross-ld,$(1)
-# finally strip off path + toolname so we get the prefix
-find-cross-prefix = $(subst gcc,,$(notdir $(call find-cross-gcc,$(1
-
-powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64)
-powerpc_cross_prefix := $(call find-cross-prefix,powerpc)
-x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
-
 # tag our seabios builds
 SEABIOS_EXTRAVERSION="-prebuilt.qemu-project.org"
 
@@ -66,6 +49,13 @@ default:
@echo "  skiboot-- update skiboot.lid"
@echo "  u-boot.e500-- update u-boot.e500"
 
+SRC_PATH=..
+include $(SRC_PATH)/rules.mak
+
+powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64)
+powerpc_cross_prefix := $(call find-cross-prefix,powerpc)
+x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
+
 bios: build-seabios-config-seabios-128k build-seabios-config-seabios-256k
cp seabios/builds/seabios-128k/bios.bin ../pc-bios/bios.bin
cp seabios/builds/seabios-256k/bios.bin ../pc-bios/bios-256k.bin
diff --git a/rules.mak b/rules.mak
index 6e943335f3..ef8adee3f8 100644
--- a/rules.mak
+++ b/rules.mak
@@ -62,6 +62,21 @@ expand-objs = $(strip $(sort $(filter %.o,$1)) \
   $(foreach o,$(filter %.mo,$1),$($o-objs)) \
   $(filter-out %.o %.mo,$1))
 
+# Cross compilation auto detection. Use find-cross-prefix to detect the
+# target archtecture's prefix, and then append it to the build tool or pass
+# it to CROSS_COMPILE directly. Here is one example:
+#  x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
+#  $(x86_64_cross_prefix)gcc -c test.c -o test.o
+#  make -C testdir CROSS_COMPILE=$(x86_64_cross_prefix)
+cross-search-path := $(subst :, ,$(PATH))
+cross-host-system := $(shell uname -s | tr "A-Z" "a-z")
+
+find-cross-ld = $(firstword $(wildcard $(patsubst \
+%,%/$(1)-*$(cross-host-system)*-ld,$(cross-search-path
+find-cross-gcc = $(firstword $(wildcard \
+$(patsubst %ld,%gcc,$(call find-cross-ld,$(1)
+find-cross-prefix = $(subst gcc,,$(notdir $(call find-cross-gcc,$(1
+
 %.o: %.c
$(call quiet-command,$(CC) $(QEMU_LOCAL_INCLUDES) $(QEMU_INCLUDES) \
   $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) \
-- 
2.14.3




[Qemu-devel] [PATCH V5 0/4] tests: Add migration test for aarch64

2018-02-23 Thread Wei Huang
This patchset adds a migration test for aarch64. It leverages
Dave Gilbert's recent patch "tests/migration: Add source to PC boot block"
to create a new test case for aarch64.

V4->V5:
 * Extract cross compilation detection code into rules.mak for sharing
 * Minor comment and code revision in migration-test.c & aarch64-a-b-kernel.S
 
V3->V4:
 * Rename .s to .S, allowing assembly to include C-style header file
 * Move test defines into a new migration-test.h file
 * Use different cpu & gic settings for kvm and tcg modes on aarch64
 * Clean up aarch64-a-b-kernel.S based on Andrew Jones' comments
 
V2->V3:
 * Convert build script to Makefile
 * Add cross-compilation support
 * Fix CPU type for "tcg" machine type
 * Revise asm code and the compilation process from asm to header file

V1->V2:
 * Similar to Dave Gilbert's recent changes to migration-test, we
   provide the test source and a build script in V2.
 * aarch64 kernel blob is defined as "unsigned char" because the source
   is now provided in V2.
 * Add "-machine none" to test_deprecated() because aarch64 doesn't have
   a default machine type.

RFC->V1:
 * aarch64 kernel blob is defined as an uint32_t array
 * The test code is re-written to address a data caching issue under KVM.
   Tests passed under both x86 and aarch64.
 * Re-use init_bootfile_x86() for both x86 and aarch64
 * Other minor fixes

Thanks,
-Wei

Wei Huang (4):
  rules: Move cross compilation auto detection functions to rules.mak
  tests/migration: Convert the boot block compilation script into
Makefile
  tests/migration: Add migration-test header file
  tests: Add migration test for aarch64

 roms/Makefile  | 24 ++-
 rules.mak  | 15 +
 tests/Makefile.include |  1 +
 tests/migration-test.c | 74 --
 tests/migration/Makefile   | 44 +
 tests/migration/aarch64-a-b-kernel.S   | 71 +
 tests/migration/aarch64-a-b-kernel.h   | 19 ++
 tests/migration/migration-test.h   | 23 +++
 tests/migration/rebuild-x86-bootblock.sh   | 33 --
 .../{x86-a-b-bootblock.s => x86-a-b-bootblock.S}   | 12 ++--
 tests/migration/x86-a-b-bootblock.h|  4 +-
 11 files changed, 244 insertions(+), 76 deletions(-)
 create mode 100644 tests/migration/Makefile
 create mode 100644 tests/migration/aarch64-a-b-kernel.S
 create mode 100644 tests/migration/aarch64-a-b-kernel.h
 create mode 100644 tests/migration/migration-test.h
 delete mode 100755 tests/migration/rebuild-x86-bootblock.sh
 rename tests/migration/{x86-a-b-bootblock.s => x86-a-b-bootblock.S} (88%)

-- 
2.14.3




[Qemu-devel] [PATCH V5 3/4] tests/migration: Add migration-test header file

2018-02-23 Thread Wei Huang
This patch moves the settings related migration-test from the
migration-test.c file to a seperate header file. It also renames the
x86-a-b-bootblock.s file extension from .s to .S, allowing gcc
pre-processor to include the C-style header file correctly.

Signed-off-by: Wei Huang <w...@redhat.com>
---
 tests/migration-test.c | 28 +++---
 tests/migration/Makefile   |  4 ++--
 tests/migration/migration-test.h   | 18 ++
 .../{x86-a-b-bootblock.s => x86-a-b-bootblock.S}   |  7 +++---
 tests/migration/x86-a-b-bootblock.h|  2 +-
 5 files changed, 39 insertions(+), 20 deletions(-)
 create mode 100644 tests/migration/migration-test.h
 rename tests/migration/{x86-a-b-bootblock.s => x86-a-b-bootblock.S} (94%)

diff --git a/tests/migration-test.c b/tests/migration-test.c
index 74f9361bdd..ce2922df6a 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -21,10 +21,10 @@
 #include "sysemu/sysemu.h"
 #include "hw/nvram/chrp_nvram.h"
 
-#define MIN_NVRAM_SIZE 8192 /* from spapr_nvram.c */
+#include "migration/migration-test.h"
 
-const unsigned start_address = 1024 * 1024;
-const unsigned end_address = 100 * 1024 * 1024;
+const unsigned start_address = TEST_MEM_START;
+const unsigned end_address = TEST_MEM_END;
 bool got_stop;
 
 #if defined(__linux__)
@@ -77,8 +77,8 @@ static bool ufd_version_check(void)
 
 static const char *tmpfs;
 
-/* A simple PC boot sector that modifies memory (1-100MB) quickly
- * outputting a 'B' every so often if it's still running.
+/* The boot file modifies memory area in [start_address, end_address)
+ * repeatedly. It outputs a 'B' at a fixed rate while it's still running.
  */
 #include "tests/migration/x86-a-b-bootblock.h"
 
@@ -104,9 +104,8 @@ static void init_bootfile_ppc(const char *bootpath)
 memcpy(header->name, "common", 6);
 chrp_nvram_finish_partition(header, MIN_NVRAM_SIZE);
 
-/* FW_MAX_SIZE is 4MB, but slof.bin is only 900KB,
- * so let's modify memory between 1MB and 100MB
- * to do like PC bootsector
+/* FW_MAX_SIZE is 4MB, but slof.bin is only 900KB. So it is OK to modify
+ * memory between start_address and end_address like PC bootsector does.
  */
 
 sprintf(buf + 16,
@@ -263,11 +262,11 @@ static void wait_for_migration_pass(QTestState *who)
 static void check_guests_ram(QTestState *who)
 {
 /* Our ASM test will have been incrementing one byte from each page from
- * 1MB to <100MB in order.
- * This gives us a constraint that any page's byte should be equal or less
- * than the previous pages byte (mod 256); and they should all be equal
- * except for one transition at the point where we meet the incrementer.
- * (We're running this with the guest stopped).
+ * start_address to  $@
diff --git a/tests/migration/migration-test.h b/tests/migration/migration-test.h
new file mode 100644
index 00..48b59b3281
--- /dev/null
+++ b/tests/migration/migration-test.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2018 Red Hat, Inc. and/or its affiliates
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#ifndef _TEST_MIGRATION_H_
+#define _TEST_MIGRATION_H_
+
+/* Common */
+#define TEST_MEM_START  (1 * 1024 * 1024)
+#define TEST_MEM_END(100 * 1024 * 1024)
+#define TEST_MEM_PAGE_SIZE  4096
+
+/* PPC */
+#define MIN_NVRAM_SIZE 8192 /* from spapr_nvram.c */
+
+#endif /* _TEST_MIGRATION_H_ */
diff --git a/tests/migration/x86-a-b-bootblock.s 
b/tests/migration/x86-a-b-bootblock.S
similarity index 94%
rename from tests/migration/x86-a-b-bootblock.s
rename to tests/migration/x86-a-b-bootblock.S
index 98dbfab084..08b51f9e7f 100644
--- a/tests/migration/x86-a-b-bootblock.s
+++ b/tests/migration/x86-a-b-bootblock.S
@@ -12,6 +12,7 @@
 #
 # Author: dgilb...@redhat.com
 
+#include "migration-test.h"
 
 .code16
 .org 0x7c00
@@ -45,11 +46,11 @@ start: # at 0x7c00 ?
 mov $0, %bl
 mainloop:
 # Start from 1MB
-mov $(1024*1024),%eax
+mov $TEST_MEM_START,%eax
 innerloop:
 incb (%eax)
-add $4096,%eax
-cmp $(100*1024*1024),%eax
+add $TEST_MEM_PAGE_SIZE,%eax
+cmp $TEST_MEM_END,%eax
 jl innerloop
 
 inc %bl
diff --git a/tests/migration/x86-a-b-bootblock.h 
b/tests/migration/x86-a-b-bootblock.h
index 9e8e2e028b..44e4b99506 100644
--- a/tests/migration/x86-a-b-bootblock.h
+++ b/tests/migration/x86-a-b-bootblock.h
@@ -1,5 +1,5 @@
 /* This file is automatically generated from
- * tests/migration/x86-a-b-bootblock.s, edit that and then run
+ * tests/migration/x86-a-b-bootblock.S, edit that and then run
  * "make x86-a-b-bootblock.h" inside tests/migration to update,
  * and then remember to send both in your patch submission.
  */
-- 
2.14.3




[Qemu-devel] [PATCH V4 0/3] tests: Add migration test for aarch64

2018-02-21 Thread Wei Huang
This patchset adds a migration test for aarch64. It leverages
Dave Gilbert's recent patch "tests/migration: Add source to PC boot block"
to create a new test case for aarch64.

V3->V4:
 * Rename .s to .S, allowing assembly to include C-style header file
 * Move test defines into a new migration-test.h file
 * Use different cpu & gic settings for kvm and tcg modes on aarch64
 * Clean up aarch64-a-b-kernel.S based on Andrew Jones' comments
 
V2->V3:
 * Convert build script to Makefile
 * Add cross-compilation support
 * Fix CPU type for "tcg" machine type
 * Revise asm code and the compilation process from asm to header file

V1->V2:
 * Similar to Dave Gilbert's recent changes to migration-test, we
   provide the test source and a build script in V2.
 * aarch64 kernel blob is defined as "unsigned char" because the source
   is now provided in V2.
 * Add "-machine none" to test_deprecated() because aarch64 doesn't have
   a default machine type.

RFC->V1:
 * aarch64 kernel blob is defined as an uint32_t array
 * The test code is re-written to address a data caching issue under KVM.
   Tests passed under both x86 and aarch64.
 * Re-use init_bootfile_x86() for both x86 and aarch64
 * Other minor fixes

Thanks,
-Wei

Wei Huang (3):
  tests/migration: Convert the boot block compilation script into
Makefile
  tests/migration: Add migration-test header file
  tests: Add migration test for aarch64

 tests/Makefile.include |  1 +
 tests/migration-test.c | 52 +---
 tests/migration/Makefile   | 46 ++
 tests/migration/aarch64-a-b-kernel.S   | 71 ++
 tests/migration/aarch64-a-b-kernel.h   | 19 ++
 tests/migration/migration-test.h   | 24 
 tests/migration/rebuild-x86-bootblock.sh   | 33 --
 .../{x86-a-b-bootblock.s => x86-a-b-bootblock.S}   | 12 ++--
 tests/migration/x86-a-b-bootblock.h|  4 +-
 9 files changed, 213 insertions(+), 49 deletions(-)
 create mode 100644 tests/migration/Makefile
 create mode 100644 tests/migration/aarch64-a-b-kernel.S
 create mode 100644 tests/migration/aarch64-a-b-kernel.h
 create mode 100644 tests/migration/migration-test.h
 delete mode 100755 tests/migration/rebuild-x86-bootblock.sh
 rename tests/migration/{x86-a-b-bootblock.s => x86-a-b-bootblock.S} (88%)

-- 
2.14.3




[Qemu-devel] [PATCH V4 3/3] tests: Add migration test for aarch64

2018-02-21 Thread Wei Huang
This patch adds migration test support for aarch64. The test code, which
implements the same functionality as x86, is booted as a kernel in qemu.
Here are the design choices we make for aarch64:

 * We choose this -kernel approach because aarch64 QEMU doesn't provide a
   built-in fw like x86 does. So instead of relying on a boot loader, we
   use -kernel approach for aarch64.
 * The serial output is sent to PL011 directly.
 * The physical memory base for mach-virt machine is 0x4000. We change
   the start_address and end_address for aarch64.

In addition to providing the binary, this patch also includes the source
code and the build script in tests/migration/. So users can change the
source and/or re-compile the binary as they wish.

Signed-off-by: Wei Huang <w...@redhat.com>
---
 tests/Makefile.include   |  1 +
 tests/migration-test.c   | 47 +---
 tests/migration/Makefile | 12 +-
 tests/migration/aarch64-a-b-kernel.S | 71 
 tests/migration/aarch64-a-b-kernel.h | 19 ++
 tests/migration/migration-test.h |  5 +++
 6 files changed, 147 insertions(+), 8 deletions(-)
 create mode 100644 tests/migration/aarch64-a-b-kernel.S
 create mode 100644 tests/migration/aarch64-a-b-kernel.h

diff --git a/tests/Makefile.include b/tests/Makefile.include
index a1bcbffe12..df9f64438f 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -372,6 +372,7 @@ check-qtest-arm-y += tests/sdhci-test$(EXESUF)
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
 check-qtest-aarch64-y += tests/sdhci-test$(EXESUF)
 check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
+check-qtest-aarch64-y += tests/migration-test$(EXESUF)
 
 check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
 
diff --git a/tests/migration-test.c b/tests/migration-test.c
index e2e06ed337..a4f6732a59 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -11,6 +11,7 @@
  */
 
 #include "qemu/osdep.h"
+#include 
 
 #include "libqtest.h"
 #include "qapi/qmp/qdict.h"
@@ -23,8 +24,8 @@
 
 #include "migration/migration-test.h"
 
-const unsigned start_address = TEST_MEM_START;
-const unsigned end_address = TEST_MEM_END;
+unsigned start_address = TEST_MEM_START;
+unsigned end_address = TEST_MEM_END;
 bool got_stop;
 
 #if defined(__linux__)
@@ -81,12 +82,13 @@ static const char *tmpfs;
  * outputting a 'B' every so often if it's still running.
  */
 #include "tests/migration/x86-a-b-bootblock.h"
+#include "tests/migration/aarch64-a-b-kernel.h"
 
-static void init_bootfile_x86(const char *bootpath)
+static void init_bootfile(const char *bootpath, void *content)
 {
 FILE *bootfile = fopen(bootpath, "wb");
 
-g_assert_cmpint(fwrite(x86_bootsect, 512, 1, bootfile), ==, 1);
+g_assert_cmpint(fwrite(content, 512, 1, bootfile), ==, 1);
 fclose(bootfile);
 }
 
@@ -393,7 +395,7 @@ static void test_migrate_start(QTestState **from, 
QTestState **to,
 got_stop = false;
 
 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-init_bootfile_x86(bootpath);
+init_bootfile(bootpath, x86_bootsect);
 cmd_src = g_strdup_printf("-machine accel=%s -m 150M"
   " -name source,debug-threads=on"
   " -serial file:%s/src_serial"
@@ -422,6 +424,39 @@ static void test_migrate_start(QTestState **from, 
QTestState **to,
   " -serial file:%s/dest_serial"
   " -incoming %s",
   accel, tmpfs, uri);
+} else if (strcmp(arch, "aarch64") == 0) {
+const char *cpu;
+const char *gic_ver;
+struct utsname utsname;
+
+/* kvm and tcg need different cpu and gic-version configs */
+if (access("/dev/kvm", F_OK) == 0 && uname() == 0 &&
+strcmp(utsname.machine, "aarch64") == 0) {
+accel = "kvm";
+cpu = "host";
+gic_ver = "host";
+} else {
+accel = "tcg";
+cpu = "cortex-a57";
+gic_ver = "2";
+}
+
+init_bootfile(bootpath, aarch64_kernel);
+cmd_src = g_strdup_printf("-machine virt,accel=%s,gic-version=%s "
+  "-name vmsource,debug-threads=on -cpu %s "
+  "-m 150M -serial file:%s/src_serial "
+  "-kernel %s ",
+  accel, gic_ver, cpu, tmpfs, bootpath);
+cmd_dst = g_strdup_printf("-machine virt,accel=%s,gic-version=%s "
+  "-name vmdest,debug-threads=on 

[Qemu-devel] [PATCH V4 1/3] tests/migration: Convert the boot block compilation script into Makefile

2018-02-21 Thread Wei Huang
The x86 boot block header currently is generated with a shell script.
To better support other CPUs (e.g. aarch64), we convert the script
into Makefile. This allows us to 1) support cross-compilation easily,
and 2) avoid creating a script file for every architecture.

Signed-off-by: Wei Huang <w...@redhat.com>
---
 tests/migration/Makefile | 38 
 tests/migration/rebuild-x86-bootblock.sh | 33 ---
 tests/migration/x86-a-b-bootblock.h  |  2 +-
 tests/migration/x86-a-b-bootblock.s  |  5 ++---
 4 files changed, 41 insertions(+), 37 deletions(-)
 create mode 100644 tests/migration/Makefile
 delete mode 100755 tests/migration/rebuild-x86-bootblock.sh

diff --git a/tests/migration/Makefile b/tests/migration/Makefile
new file mode 100644
index 00..1c07dd7be9
--- /dev/null
+++ b/tests/migration/Makefile
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
+#
+# Authors:
+#   Dave Gilbert <dgilb...@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+#
+path := $(subst :, ,$(PATH))
+system := $(shell uname -s | tr "A-Z" "a-z")
+
+cross-ld = $(firstword $(wildcard $(patsubst %,%/$(1)-*$(system)*-ld,$(path
+cross-gcc = $(firstword $(wildcard $(patsubst %ld,%gcc,$(call cross-ld,$(1)
+find-cross-prefix = $(subst gcc,,$(notdir $(call cross-gcc,$(1
+
+x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
+
+export __note
+override define __note
+/* This file is automatically generated from
+ * tests/migration/$<, edit that and then run
+ * "make $@" inside tests/migration to update,
+ * and then remember to send both in your patch submission.
+ */
+endef
+
+all: x86-a-b-bootblock.h
+
+x86-a-b-bootblock.h: x86-a-b-bootblock.s
+   $(x86_64_cross_prefix)as --32 -march=i486 $< -o x86.o
+   $(x86_64_cross_prefix)objcopy -O binary x86.o x86.boot
+   dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124
+   echo "$$__note" > $@
+   xxd -i x86.bootsect | sed -e 's/.*int.*//' >> $@
+
+clean:
+   rm -f *.bootsect *.boot *.o
diff --git a/tests/migration/rebuild-x86-bootblock.sh 
b/tests/migration/rebuild-x86-bootblock.sh
deleted file mode 100755
index 86cec5d284..00
--- a/tests/migration/rebuild-x86-bootblock.sh
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/sh
-# Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
-# This work is licensed under the terms of the GNU GPL, version 2 or later.
-# See the COPYING file in the top-level directory.
-#
-# Author: dgilb...@redhat.com
-
-ASMFILE=$PWD/tests/migration/x86-a-b-bootblock.s
-HEADER=$PWD/tests/migration/x86-a-b-bootblock.h
-
-if [ ! -e "$ASMFILE" ]
-then
-  echo "Couldn't find $ASMFILE" >&2
-  exit 1
-fi
-
-ASM_WORK_DIR=$(mktemp -d --tmpdir X86BB.XX)
-cd "$ASM_WORK_DIR" &&
-as --32 -march=i486 "$ASMFILE" -o x86.o &&
-objcopy -O binary x86.o x86.boot &&
-dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124 &&
-xxd -i x86.bootsect |
-sed -e 's/.*int.*//' > x86.hex &&
-cat - x86.hex < "$HEADER"
-/* This file is automatically generated from
- * tests/migration/x86-a-b-bootblock.s, edit that and then run
- * tests/migration/rebuild-x86-bootblock.sh to update,
- * and then remember to send both in your patch submission.
- */
-HERE
-
-rm x86.hex x86.bootsect x86.boot x86.o
-cd .. && rmdir "$ASM_WORK_DIR"
diff --git a/tests/migration/x86-a-b-bootblock.h 
b/tests/migration/x86-a-b-bootblock.h
index 78a151fe2a..9e8e2e028b 100644
--- a/tests/migration/x86-a-b-bootblock.h
+++ b/tests/migration/x86-a-b-bootblock.h
@@ -1,6 +1,6 @@
 /* This file is automatically generated from
  * tests/migration/x86-a-b-bootblock.s, edit that and then run
- * tests/migration/rebuild-x86-bootblock.sh to update,
+ * "make x86-a-b-bootblock.h" inside tests/migration to update,
  * and then remember to send both in your patch submission.
  */
 unsigned char x86_bootsect[] = {
diff --git a/tests/migration/x86-a-b-bootblock.s 
b/tests/migration/x86-a-b-bootblock.s
index b1642641a7..98dbfab084 100644
--- a/tests/migration/x86-a-b-bootblock.s
+++ b/tests/migration/x86-a-b-bootblock.s
@@ -3,9 +3,8 @@
 #  range.
 #  Outputs an initial 'A' on serial followed by repeated 'B's
 #
-# run   tests/migration/rebuild-x86-bootblock.sh
-#   to regenerate the hex, and remember to include both the .h and .s
-#   in any patches.
+#  In tests/migration dir, run 'make x86-a-b-bootblock.h' to regenerate
+#  the hex, and remember to include both the .h and .s in any patches.
 #
 # Copyright (c) 2016 Red Hat, Inc. and/or its affiliates
 # This work is licensed under the terms of the GNU GPL, version 2 or later.
-- 
2.14.3




[Qemu-devel] [PATCH V4 2/3] tests/migration: Add migration-test header file

2018-02-21 Thread Wei Huang
This patch moves the settings related migration-test from the
migration-test.c file to a seperate header file. It also renames the
x86-a-b-bootblock.s file extension from .s to .S, allowing gcc
pre-processor to include the C-style header file correctly.

Signed-off-by: Wei Huang <w...@redhat.com>
---
 tests/migration-test.c|  9 +
 tests/migration/Makefile  |  4 ++--
 tests/migration/migration-test.h  | 19 +++
 .../{x86-a-b-bootblock.s => x86-a-b-bootblock.S}  |  7 ---
 tests/migration/x86-a-b-bootblock.h   |  2 +-
 5 files changed, 31 insertions(+), 10 deletions(-)
 create mode 100644 tests/migration/migration-test.h
 rename tests/migration/{x86-a-b-bootblock.s => x86-a-b-bootblock.S} (94%)

diff --git a/tests/migration-test.c b/tests/migration-test.c
index 74f9361bdd..e2e06ed337 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -21,10 +21,10 @@
 #include "sysemu/sysemu.h"
 #include "hw/nvram/chrp_nvram.h"
 
-#define MIN_NVRAM_SIZE 8192 /* from spapr_nvram.c */
+#include "migration/migration-test.h"
 
-const unsigned start_address = 1024 * 1024;
-const unsigned end_address = 100 * 1024 * 1024;
+const unsigned start_address = TEST_MEM_START;
+const unsigned end_address = TEST_MEM_END;
 bool got_stop;
 
 #if defined(__linux__)
@@ -278,7 +278,8 @@ static void check_guests_ram(QTestState *who)
 qtest_memread(who, start_address, _byte, 1);
 last_byte = first_byte;
 
-for (address = start_address + 4096; address < end_address; address += 
4096)
+for (address = start_address + TEST_MEM_PAGE_SIZE; address < end_address;
+ address += TEST_MEM_PAGE_SIZE)
 {
 uint8_t b;
 qtest_memread(who, address, , 1);
diff --git a/tests/migration/Makefile b/tests/migration/Makefile
index 1c07dd7be9..b768d0729d 100644
--- a/tests/migration/Makefile
+++ b/tests/migration/Makefile
@@ -27,8 +27,8 @@ endef
 
 all: x86-a-b-bootblock.h
 
-x86-a-b-bootblock.h: x86-a-b-bootblock.s
-   $(x86_64_cross_prefix)as --32 -march=i486 $< -o x86.o
+x86-a-b-bootblock.h: x86-a-b-bootblock.S
+   $(x86_64_cross_prefix)gcc -m32 -march=i486 -c $< -o x86.o
$(x86_64_cross_prefix)objcopy -O binary x86.o x86.boot
dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124
echo "$$__note" > $@
diff --git a/tests/migration/migration-test.h b/tests/migration/migration-test.h
new file mode 100644
index 00..a618fe069e
--- /dev/null
+++ b/tests/migration/migration-test.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2018 Red Hat, Inc. and/or its affiliates
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#ifndef _TEST_MIGRATION_H_
+#define _TEST_MIGRATION_H_
+
+/* Common */
+#define TEST_MEM_START  (1 * 1024 * 1024)
+#define TEST_MEM_END(100 * 1024 * 1024)
+#define TEST_MEM_PAGE_SIZE  4096
+
+/* PPC */
+#define MIN_NVRAM_SIZE 8192 /* from spapr_nvram.c */
+
+#endif /* _TEST_MIGRATION_H_ */
+
diff --git a/tests/migration/x86-a-b-bootblock.s 
b/tests/migration/x86-a-b-bootblock.S
similarity index 94%
rename from tests/migration/x86-a-b-bootblock.s
rename to tests/migration/x86-a-b-bootblock.S
index 98dbfab084..08b51f9e7f 100644
--- a/tests/migration/x86-a-b-bootblock.s
+++ b/tests/migration/x86-a-b-bootblock.S
@@ -12,6 +12,7 @@
 #
 # Author: dgilb...@redhat.com
 
+#include "migration-test.h"
 
 .code16
 .org 0x7c00
@@ -45,11 +46,11 @@ start: # at 0x7c00 ?
 mov $0, %bl
 mainloop:
 # Start from 1MB
-mov $(1024*1024),%eax
+mov $TEST_MEM_START,%eax
 innerloop:
 incb (%eax)
-add $4096,%eax
-cmp $(100*1024*1024),%eax
+add $TEST_MEM_PAGE_SIZE,%eax
+cmp $TEST_MEM_END,%eax
 jl innerloop
 
 inc %bl
diff --git a/tests/migration/x86-a-b-bootblock.h 
b/tests/migration/x86-a-b-bootblock.h
index 9e8e2e028b..44e4b99506 100644
--- a/tests/migration/x86-a-b-bootblock.h
+++ b/tests/migration/x86-a-b-bootblock.h
@@ -1,5 +1,5 @@
 /* This file is automatically generated from
- * tests/migration/x86-a-b-bootblock.s, edit that and then run
+ * tests/migration/x86-a-b-bootblock.S, edit that and then run
  * "make x86-a-b-bootblock.h" inside tests/migration to update,
  * and then remember to send both in your patch submission.
  */
-- 
2.14.3




[Qemu-devel] [PATCH V3 2/2] tests: Add migration test for aarch64

2018-02-14 Thread Wei Huang
This patch adds migration test support for aarch64. The test code, which
implements the same functionality as x86, is booted as a kernel in qemu.
Here are the design choices we make for aarch64:

 * We choose this -kernel approach because aarch64 QEMU doesn't provide a
   built-in fw like x86 does. So instead of relying on a boot loader, we
   use -kernel approach for aarch64.
 * The serial output is sent to PL011 directly.
 * The physical memory base for mach-virt machine is 0x4000. We change
   the start_address and end_address for aarch64.

In addition to providing the binary, this patch also includes the source
code and the build script in tests/migration/. So users can change the
source and/or re-compile the binary as they wish.

Signed-off-by: Wei Huang <w...@redhat.com>
---
 tests/Makefile.include   |  1 +
 tests/migration-test.c   | 39 ---
 tests/migration/Makefile | 12 +-
 tests/migration/aarch64-a-b-kernel.h | 19 +
 tests/migration/aarch64-a-b-kernel.s | 74 
 5 files changed, 137 insertions(+), 8 deletions(-)
 create mode 100644 tests/migration/aarch64-a-b-kernel.h
 create mode 100644 tests/migration/aarch64-a-b-kernel.s

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 278c13a..5b1605a 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -372,6 +372,7 @@ check-qtest-arm-y += tests/sdhci-test$(EXESUF)
 
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
 check-qtest-aarch64-y += tests/sdhci-test$(EXESUF)
+check-qtest-aarch64-y += tests/migration-test$(EXESUF)
 
 check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
 
diff --git a/tests/migration-test.c b/tests/migration-test.c
index 97fdb19..0b6ab5c 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -23,8 +23,8 @@
 
 #define MIN_NVRAM_SIZE 8192 /* from spapr_nvram.c */
 
-const unsigned start_address = 1024 * 1024;
-const unsigned end_address = 100 * 1024 * 1024;
+unsigned start_address = 1024 * 1024;
+unsigned end_address = 100 * 1024 * 1024;
 bool got_stop;
 
 #if defined(__linux__)
@@ -81,12 +81,13 @@ static const char *tmpfs;
  * outputting a 'B' every so often if it's still running.
  */
 #include "tests/migration/x86-a-b-bootblock.h"
+#include "tests/migration/aarch64-a-b-kernel.h"
 
-static void init_bootfile_x86(const char *bootpath)
+static void init_bootfile(const char *bootpath, void *content)
 {
 FILE *bootfile = fopen(bootpath, "wb");
 
-g_assert_cmpint(fwrite(x86_bootsect, 512, 1, bootfile), ==, 1);
+g_assert_cmpint(fwrite(content, 512, 1, bootfile), ==, 1);
 fclose(bootfile);
 }
 
@@ -392,7 +393,7 @@ static void test_migrate_start(QTestState **from, 
QTestState **to,
 got_stop = false;
 
 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-init_bootfile_x86(bootpath);
+init_bootfile(bootpath, x86_bootsect);
 cmd_src = g_strdup_printf("-machine accel=%s -m 150M"
   " -name source,debug-threads=on"
   " -serial file:%s/src_serial"
@@ -421,6 +422,32 @@ static void test_migrate_start(QTestState **from, 
QTestState **to,
   " -serial file:%s/dest_serial"
   " -incoming %s",
   accel, tmpfs, uri);
+} else if (strcmp(arch, "aarch64") == 0) {
+const char *cpu;
+
+if (access("/dev/kvm", F_OK)) {
+accel = "kvm";
+cpu = "host";
+} else {
+accel = "tcg";
+cpu = "cortex-a57";
+}
+
+init_bootfile(bootpath, aarch64_kernel);
+cmd_src = g_strdup_printf("-machine virt,accel=%s -m 150M "
+  "-name vmsource,debug-threads=on -cpu %s "
+  "-serial file:%s/src_serial "
+  "-kernel %s ",
+  accel, cpu, tmpfs, bootpath);
+cmd_dst = g_strdup_printf("-machine virt,accel=%s -m 150M "
+  "-name vmdest,debug-threads=on -cpu %s "
+  "-serial file:%s/dest_serial "
+  "-kernel %s "
+  "-incoming %s ",
+  accel, cpu, tmpfs, bootpath, uri);
+/* aarch64 virt machine physical memory starts at 0x4000 */
+start_address += 0x4000;
+end_address += 0x4000;
 } else {
 g_assert_not_reached();
 }
@@ -502,7 +529,7 @@ static void test_deprecated(void)
 {
 QTestState *from;
 
-from = qtest_start(""

[Qemu-devel] [PATCH V3 1/2] tests/migration: Convert the boot block compilation script into Makefile

2018-02-14 Thread Wei Huang
The x86 boot block header currently is generated with a shell script.
To better support other CPUs (e.g. aarch64), we convert the script
into Makefile. This allows us to 1) support cross-compilation easily; 2)
avoid creating a script file for every architecture.

Signed-off-by: Wei Huang <w...@redhat.com>
---
 tests/migration/Makefile | 38 
 tests/migration/rebuild-x86-bootblock.sh | 34 
 tests/migration/x86-a-b-bootblock.h  |  2 +-
 3 files changed, 39 insertions(+), 35 deletions(-)
 create mode 100644 tests/migration/Makefile
 delete mode 100755 tests/migration/rebuild-x86-bootblock.sh

diff --git a/tests/migration/Makefile b/tests/migration/Makefile
new file mode 100644
index 000..e8e6026
--- /dev/null
+++ b/tests/migration/Makefile
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
+#
+# Authors:
+#   Dave Gilbert <dgilb...@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later.
+# See the COPYING file in the top-level directory.
+#
+path := $(subst :, ,$(PATH))
+system := $(shell uname -s | tr "A-Z" "a-z")
+
+cross-ld = $(firstword $(wildcard $(patsubst %,%/$(1)-*$(system)*-ld,$(path
+cross-gcc = $(firstword $(wildcard $(patsubst %ld,%gcc,$(call cross-ld,$(1)
+find-cross-prefix = $(subst gcc,,$(notdir $(call cross-gcc,$(1
+
+x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
+
+export __note
+override define __note
+/* This file is automatically generated from
+ * tests/migration/$<, edit that and then run
+ * "make $@" inside tests/migration to update,
+ * and then remember to send both in your patch submission.
+ */
+endef
+
+all: x86-a-b-bootblock.h
+
+x86-a-b-bootblock.h: x86-a-b-bootblock.s
+   $(x86_64_cross_prefix)as --32 -march=i486 $< -o x86.o
+   $(x86_64_cross_prefix)objcopy -O binary x86.o x86.boot
+   dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124
+   echo "$$__note" > $@
+   xxd -i x86.bootsect | sed -e 's/.*int.*//' >> $@
+
+clean:
+   rm -rf *.bootsect *.boot *.o
diff --git a/tests/migration/rebuild-x86-bootblock.sh 
b/tests/migration/rebuild-x86-bootblock.sh
deleted file mode 100755
index 05ed9ba..000
--- a/tests/migration/rebuild-x86-bootblock.sh
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/sh
-# Copyright (c) 2016-2018 Red Hat, Inc. and/or its affiliates
-# This work is licensed under the terms of the GNU GPL, version 2 or later.
-# See the COPYING file in the top-level directory.
-#
-# Author: dgilb...@redhat.com
-
-ASMFILE=$PWD/tests/migration/x86-a-b-bootblock.s
-HEADER=$PWD/tests/migration/x86-a-b-bootblock.h
-
-if [ ! -e "$ASMFILE" ]
-then
-  echo "Couldn't find $ASMFILE" >&2
-  exit 1
-fi
-
-ASM_WORK_DIR=$(mktemp -d --tmpdir X86BB.XX)
-cd "$ASM_WORK_DIR" &&
-as --32 -march=i486 "$ASMFILE" -o x86.o &&
-objcopy -O binary x86.o x86.boot &&
-dd if=x86.boot of=x86.bootsect bs=256 count=2 skip=124 &&
-xxd -i x86.bootsect |
-sed -e 's/.*int.*//' > x86.hex &&
-cat - x86.hex < "$HEADER"
-/* This file is automatically generated from
- * tests/migration/x86-a-b-bootblock.s, edit that and then run
- * tests/migration/rebuild-x86-bootblock.sh to update,
- * and then remember to send both in your patch submission.
- */
-HERE
-
-rm x86.hex x86.bootsect x86.boot x86.o
-cd .. && rmdir "$ASM_WORK_DIR"
-
diff --git a/tests/migration/x86-a-b-bootblock.h 
b/tests/migration/x86-a-b-bootblock.h
index 78a151f..9e8e2e0 100644
--- a/tests/migration/x86-a-b-bootblock.h
+++ b/tests/migration/x86-a-b-bootblock.h
@@ -1,6 +1,6 @@
 /* This file is automatically generated from
  * tests/migration/x86-a-b-bootblock.s, edit that and then run
- * tests/migration/rebuild-x86-bootblock.sh to update,
+ * "make x86-a-b-bootblock.h" inside tests/migration to update,
  * and then remember to send both in your patch submission.
  */
 unsigned char x86_bootsect[] = {
-- 
1.8.3.1




[Qemu-devel] [PATCH V3 0/2] tests: Add migration test for aarch64

2018-02-14 Thread Wei Huang
This is a new version of migration-test for aarch64. This version needs to
be applied on top of Dave Gilbert's recent patch "[v4] tests/migration: Add
source to PC boot block".

V2->V3:
 * Convert build script to Makefile
 * Add cross-compilation support
 * Fix CPU type for "tcg" machine type
 * Revise asm code and the compilation process from asm to header file

V1->V2:
 * Similar to Dave Gilbert's recent changes to migration-test, we
   provide the test source and a build script in V2.
 * aarch64 kernel blob is defined as "unsigned char" because the source
   is now provided in V2.
 * Add "-machine none" to test_deprecated() because aarch64 doesn't have
   a default machine type.

RFC->V1:
 * aarch64 kernel blob is defined as an uint32_t array
 * The test code is re-written to address a data caching issue under KVM.
   Tests passed under both x86 and aarch64.
 * Re-use init_bootfile_x86() for both x86 and aarch64
 * Other minor fixes

Thanks,
-Wei

Wei Huang (2):
  tests/migration: Convert the boot block compilation script into
Makefile
  tests: Add migration test for aarch64

 tests/Makefile.include   |  1 +
 tests/migration-test.c   | 39 ++---
 tests/migration/Makefile | 46 
 tests/migration/aarch64-a-b-kernel.h | 19 
 tests/migration/aarch64-a-b-kernel.s | 74 
 tests/migration/rebuild-x86-bootblock.sh | 34 ---
 tests/migration/x86-a-b-bootblock.h  |  2 +-
 7 files changed, 174 insertions(+), 41 deletions(-)
 create mode 100644 tests/migration/Makefile
 create mode 100644 tests/migration/aarch64-a-b-kernel.h
 create mode 100644 tests/migration/aarch64-a-b-kernel.s
 delete mode 100755 tests/migration/rebuild-x86-bootblock.sh

-- 
1.8.3.1




Re: [Qemu-devel] [PATCH V2 1/1] tests: Add migration test for aarch64

2018-02-14 Thread Wei Huang


On 02/12/2018 11:31 AM, Andrew Jones wrote:
> On Fri, Feb 09, 2018 at 04:42:42PM -0500, Wei Huang wrote:
>> This patch adds migration test support for aarch64. The test code, which
>> implements the same functionality as x86, is booted as a kernel in qemu.
>> Here are the design choices we make for aarch64:
>>
>>  * We choose this -kernel approach because aarch64 QEMU doesn't provide a
>>built-in fw like x86 does. So instead of relying on a boot loader, we
>>use -kernel approach for aarch64.
>>  * The serial output is sent to PL011 directly.
>>  * The physical memory base for mach-virt machine is 0x4000. We change
>>the start_address and end_address for aarch64.
>>
>> In addition to providing the binary, this patch also includes the test source
>> and the build script in tests/migration. So users can change/re-compile
>> the binary as they wish.
>>
>> Signed-off-by: Wei Huang <w...@redhat.com>
>> ---
>>  tests/Makefile.include|  1 +
>>  tests/migration-test.c| 29 ++---
>>  tests/migration/aarch64-a-b-kernel.h  | 19 +
>>  tests/migration/aarch64-a-b-kernel.s  | 67 
>> +++
>>  tests/migration/rebuild-aarch64-kernel.sh | 67 
>> +++
>>  5 files changed, 177 insertions(+), 6 deletions(-)
>>  create mode 100644 tests/migration/aarch64-a-b-kernel.h
>>  create mode 100644 tests/migration/aarch64-a-b-kernel.s
>>  create mode 100755 tests/migration/rebuild-aarch64-kernel.sh
>>
>> diff --git a/tests/Makefile.include b/tests/Makefile.include
>> index f41da23..0fd18fd 100644
>> --- a/tests/Makefile.include
>> +++ b/tests/Makefile.include
>> @@ -369,6 +369,7 @@ gcov-files-arm-y += hw/timer/arm_mptimer.c
>>  check-qtest-arm-y += tests/boot-serial-test$(EXESUF)
>>  
>>  check-qtest-aarch64-y = tests/numa-test$(EXESUF)
>> +check-qtest-aarch64-y += tests/migration-test$(EXESUF)
>>  
>>  check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
>>  
>> diff --git a/tests/migration-test.c b/tests/migration-test.c
>> index 85d4014..b16944c 100644
>> --- a/tests/migration-test.c
>> +++ b/tests/migration-test.c
>> @@ -22,8 +22,8 @@
>>  
>>  #define MIN_NVRAM_SIZE 8192 /* from spapr_nvram.c */
>>  
>> -const unsigned start_address = 1024 * 1024;
>> -const unsigned end_address = 100 * 1024 * 1024;
>> +unsigned start_address = 1024 * 1024;
>> +unsigned end_address = 100 * 1024 * 1024;
>>  bool got_stop;
>>  
>>  #if defined(__linux__)
>> @@ -80,12 +80,13 @@ static const char *tmpfs;
>>   * outputing a 'B' every so often if it's still running.
>>   */
>>  #include "tests/migration/x86-a-b-bootblock.h"
>> +#include "tests/migration/aarch64-a-b-kernel.h"
>>  
>> -static void init_bootfile_x86(const char *bootpath)
>> +static void init_bootfile(const char *bootpath, void *content)
>>  {
>>  FILE *bootfile = fopen(bootpath, "wb");
>>  
>> -g_assert_cmpint(fwrite(x86_bootsect, 512, 1, bootfile), ==, 1);
>> +g_assert_cmpint(fwrite(content, 512, 1, bootfile), ==, 1);
>>  fclose(bootfile);
>>  }
>>  
>> @@ -391,7 +392,7 @@ static void test_migrate_start(QTestState **from, 
>> QTestState **to,
>>  got_stop = false;
>>  
>>  if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
>> -init_bootfile_x86(bootpath);
>> +init_bootfile(bootpath, x86_bootsect);
>>  cmd_src = g_strdup_printf("-machine accel=%s -m 150M"
>>" -name source,debug-threads=on"
>>" -serial file:%s/src_serial"
>> @@ -420,6 +421,22 @@ static void test_migrate_start(QTestState **from, 
>> QTestState **to,
>>" -serial file:%s/dest_serial"
>>" -incoming %s",
>>accel, tmpfs, uri);
>> +} else if (strcmp(arch, "aarch64") == 0) {
>> +init_bootfile(bootpath, aarch64_kernel);
>> +cmd_src = g_strdup_printf("-machine virt,accel=kvm:tcg -m 150M "
>> +  "-name vmsource,debug-threads=on -cpu 
>> host "
> 
> We can't use '-cpu host' with tcg, so the accel fallback won't work.

Will fix

> 
>> +  "-serial file:%s/src_serial "
>>

Re: [Qemu-devel] [PATCH v2] tests/migration: Add source to PC boot block

2018-02-12 Thread Wei Huang


On 02/12/2018 09:07 AM, Dr. David Alan Gilbert wrote:
> * Andrew Jones (drjo...@redhat.com) wrote:
>> On Mon, Feb 05, 2018 at 06:18:46PM +, Dr. David Alan Gilbert (git) wrote:
>>> diff --git a/tests/migration/rebuild-x86-bootblock.sh 
>>> b/tests/migration/rebuild-x86-bootblock.sh
>>> new file mode 100755
>>> index 00..c40f025e1a
>>> --- /dev/null
>>> +++ b/tests/migration/rebuild-x86-bootblock.sh
>>> @@ -0,0 +1,37 @@
>>> +#!/bin/sh
>>> +# Copyright (c) 2016 Red Hat, Inc. and/or its affiliates
>>> +# This work is licensed under the terms of the GNU GPL, version 2 or later.
>>> +# See the COPYING file in the top-level directory.
>>> +#
>>> +# Author: dgilb...@redhat.com
>>> +
>>> +ASMFILE=tests/migration/x86-a-b-bootblock.s
>>> +HEADER=tests/migration/x86-a-b-bootblock.h
>>> +
>>> +if [ ! -e "$ASMFILE" ]
>>> +then
>>> +  echo "Couldn't find $ASMFILE" >&2
>>> +  exit 1
>>> +fi
>>> +
>>> +ASM_WORK_DIR=/tmp/X86BB$$
>>
>> mktemp?
> 
> Yes, that's probably fair.

I echo this. So we will use something like:

-ASM_WORK_DIR=/tmp/AARCH64BB$$
+ASM_WORK_DIR="$(mktemp -d /tmp/AARCH64XX)"

-mkdir $ASM_WORK_DIR &&


> 
>>> +mkdir $ASM_WORK_DIR &&
>>> +as --32 -march=i486 "$ASMFILE" -o $ASM_WORK_DIR/bb.o &&
>>> +objcopy -O binary $ASM_WORK_DIR/bb.o $ASM_WORK_DIR/bb.boot &&
>>> +dd if=$ASM_WORK_DIR/bb.boot of=$ASM_WORK_DIR/bb.bootsect \
>>> +  bs=256 count=2 skip=124 &&
>>> +xxd -i $ASM_WORK_DIR/bb.bootsect |
>>
>> Is xxd now considered a common enough tool for portable scripts? I've
>> always liked xxd for manual use, but scripted with 'od'.
> 
> This script isn't part of a normal build or make check or anything, so
> jumping through hoops to make it portable for the mythical other person
> who might ever run it seems OTT, especially since xxd is very common,

xxd isn't installed by default (at least on my aarch64 server). But it
is part of vim-common package; so it is fair to say xxd command is
available on all major distros.

> and I'm not sure how much I'd bet on the portability of od's output
> format either.
> 
> Dave
> 
>>> +sed -e 's/_tmp.*_bootsect/x86_bootsect/' -e 's/.*int.*//' > \
>>> +  $ASM_WORK_DIR/bb.hex &&
>>> +cat - $ASM_WORK_DIR/bb.hex < "$HEADER"
>>> +/* This file is automatically generated from
>>> + * tests/migration/x86-a-b-bootblock.s, edit that and then run
>>> + * tests/migration/rebuild-x86-bootblock.sh to update,
>>> + * and then remember to send both in your patch submission.
>>> + */
>>> +HERE
>>> +
>>> +rm $ASM_WORK_DIR/bb.hex $ASM_WORK_DIR/bb.bootsect $ASM_WORK_DIR/bb.boot
>>> +rm $ASM_WORK_DIR/bb.o
>>> +rmdir $ASM_WORK_DIR
>>> +
>>
>> Thanks,
>> drew
> --
> Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK
> 



Re: [Qemu-devel] [PATCH v2] tests/migration: Add source to PC boot block

2018-02-09 Thread Wei Huang
00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa
> +};
> +
> diff --git a/tests/migration/x86-a-b-bootblock.s 
> b/tests/migration/x86-a-b-bootblock.s
> new file mode 100644
> index 00..b1642641a7
> --- /dev/null
> +++ b/tests/migration/x86-a-b-bootblock.s
> @@ -0,0 +1,92 @@
> +# x86 bootblock used in migration test
> +#  repeatedly increments the first byte of each page in a 100MB
> +#  range.
> +#  Outputs an initial 'A' on serial followed by repeated 'B's
> +#
> +# run   tests/migration/rebuild-x86-bootblock.sh
> +#   to regenerate the hex, and remember to include both the .h and .s
> +#   in any patches.
> +#
> +# Copyright (c) 2016 Red Hat, Inc. and/or its affiliates
> +# This work is licensed under the terms of the GNU GPL, version 2 or later.
> +# See the COPYING file in the top-level directory.
> +#
> +# Author: dgilb...@redhat.com
> +
> +
> +.code16
> +.org 0x7c00
> +.file   "fill.s"
> +.text
> +.globl  start
> +.type   start, @function
> +start: # at 0x7c00 ?
> +cli
> +lgdt gdtdesc
> +mov $1,%eax
> +mov %eax,%cr0  # Protected mode enable
> +data32 ljmp $8,$0x7c20
> +
> +.org 0x7c20
> +.code32
> +# A20 enable - not sure I actually need this
> +inb $0x92,%al
> +or  $2,%al
> +outb %al, $0x92
> +
> +# set up DS for the whole of RAM (needed on KVM)
> +mov $16,%eax
> +mov %eax,%ds
> +
> +mov $65,%ax
> +mov $0x3f8,%dx
> +outb %al,%dx
> +
> +# bl keeps a counter so we limit the output speed
> +mov $0, %bl
> +mainloop:
> +# Start from 1MB
> +mov $(1024*1024),%eax
> +innerloop:
> +incb (%eax)
> +add $4096,%eax
> +cmp $(100*1024*1024),%eax
> +jl innerloop
> +
> +inc %bl
> +jnz mainloop
> +
> +mov $66,%ax
> +mov $0x3f8,%dx
> +outb %al,%dx
> +
> +jmp mainloop
> +
> +# GDT magic from old (GPLv2)  Grub startup.S
> +.p2align2   /* force 4-byte alignment */
> +gdt:
> +    .word   0, 0
> +.byte   0, 0, 0, 0
> +
> +/* -- code segment --
> + * base = 0x, limit = 0xF (4 KiB Granularity), present
> + * type = 32bit code execute/read, DPL = 0
> + */
> +.word   0x, 0
> +.byte   0, 0x9A, 0xCF, 0
> +
> +/* -- data segment --
> + * base = 0x, limit 0xF (4 KiB Granularity), present
> + * type = 32 bit data read/write, DPL = 0
> + */
> +.word   0x, 0
> +.byte   0, 0x92, 0xCF, 0
> +
> +gdtdesc:
> +.word   0x27/* limit */
> +.long   gdt /* addr */
> +
> +/* I'm a bootable disk */
> +.org 0x7dfe
> +.byte 0x55
> +.byte 0xAA
> 

I tested this patch and it worked on my x86 machine. Also using the same
approach, I just submitted a new version of migration-test for aarch64. So,

Reviewed-by: Wei Huang <w...@redhat.com>
Tested-by: Wei Huang <w...@redhat.com>




[Qemu-devel] [PATCH V2 0/1] tests: Add migration test for aarch64

2018-02-09 Thread Wei Huang
This is a new version of migration-test for aarch64. This version needs to
be applied on top of Dave Gilbert's recent patch "[v2] tests/migration: Add
source to PC boot block".

V1->V2:
 * Similar to Dave Gilbert's recent changes to migration-test, we
   provide the test source and a build script in V2.
 * aarch64 kernel blob is defined as "unsigned char" because the source
   is now provided in V2.
 * Add "-machine none" to test_deprecated() because aarch64 doesn't have
   a default machine type.

RFC->V1:
 * aarch64 kernel blob is defined as an uint32_t array
 * The test code is re-written to address a data caching issue under KVM.
   Tests passed under both x86 and aarch64.
 * Re-use init_bootfile_x86() for both x86 and aarch64
 * Other minor fixes


Thanks,
-Wei

Wei Huang (1):
  tests: Add migration test for aarch64

 tests/Makefile.include|  1 +
 tests/migration-test.c| 29 ++---
 tests/migration/aarch64-a-b-kernel.h  | 19 +
 tests/migration/aarch64-a-b-kernel.s  | 67 +++
 tests/migration/rebuild-aarch64-kernel.sh | 67 +++
 5 files changed, 177 insertions(+), 6 deletions(-)
 create mode 100644 tests/migration/aarch64-a-b-kernel.h
 create mode 100644 tests/migration/aarch64-a-b-kernel.s
 create mode 100755 tests/migration/rebuild-aarch64-kernel.sh

-- 
1.8.3.1




[Qemu-devel] [PATCH V2 1/1] tests: Add migration test for aarch64

2018-02-09 Thread Wei Huang
This patch adds migration test support for aarch64. The test code, which
implements the same functionality as x86, is booted as a kernel in qemu.
Here are the design choices we make for aarch64:

 * We choose this -kernel approach because aarch64 QEMU doesn't provide a
   built-in fw like x86 does. So instead of relying on a boot loader, we
   use -kernel approach for aarch64.
 * The serial output is sent to PL011 directly.
 * The physical memory base for mach-virt machine is 0x4000. We change
   the start_address and end_address for aarch64.

In addition to providing the binary, this patch also includes the test source
and the build script in tests/migration. So users can change/re-compile
the binary as they wish.

Signed-off-by: Wei Huang <w...@redhat.com>
---
 tests/Makefile.include|  1 +
 tests/migration-test.c| 29 ++---
 tests/migration/aarch64-a-b-kernel.h  | 19 +
 tests/migration/aarch64-a-b-kernel.s  | 67 +++
 tests/migration/rebuild-aarch64-kernel.sh | 67 +++
 5 files changed, 177 insertions(+), 6 deletions(-)
 create mode 100644 tests/migration/aarch64-a-b-kernel.h
 create mode 100644 tests/migration/aarch64-a-b-kernel.s
 create mode 100755 tests/migration/rebuild-aarch64-kernel.sh

diff --git a/tests/Makefile.include b/tests/Makefile.include
index f41da23..0fd18fd 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -369,6 +369,7 @@ gcov-files-arm-y += hw/timer/arm_mptimer.c
 check-qtest-arm-y += tests/boot-serial-test$(EXESUF)
 
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
+check-qtest-aarch64-y += tests/migration-test$(EXESUF)
 
 check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
 
diff --git a/tests/migration-test.c b/tests/migration-test.c
index 85d4014..b16944c 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -22,8 +22,8 @@
 
 #define MIN_NVRAM_SIZE 8192 /* from spapr_nvram.c */
 
-const unsigned start_address = 1024 * 1024;
-const unsigned end_address = 100 * 1024 * 1024;
+unsigned start_address = 1024 * 1024;
+unsigned end_address = 100 * 1024 * 1024;
 bool got_stop;
 
 #if defined(__linux__)
@@ -80,12 +80,13 @@ static const char *tmpfs;
  * outputing a 'B' every so often if it's still running.
  */
 #include "tests/migration/x86-a-b-bootblock.h"
+#include "tests/migration/aarch64-a-b-kernel.h"
 
-static void init_bootfile_x86(const char *bootpath)
+static void init_bootfile(const char *bootpath, void *content)
 {
 FILE *bootfile = fopen(bootpath, "wb");
 
-g_assert_cmpint(fwrite(x86_bootsect, 512, 1, bootfile), ==, 1);
+g_assert_cmpint(fwrite(content, 512, 1, bootfile), ==, 1);
 fclose(bootfile);
 }
 
@@ -391,7 +392,7 @@ static void test_migrate_start(QTestState **from, 
QTestState **to,
 got_stop = false;
 
 if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
-init_bootfile_x86(bootpath);
+init_bootfile(bootpath, x86_bootsect);
 cmd_src = g_strdup_printf("-machine accel=%s -m 150M"
   " -name source,debug-threads=on"
   " -serial file:%s/src_serial"
@@ -420,6 +421,22 @@ static void test_migrate_start(QTestState **from, 
QTestState **to,
   " -serial file:%s/dest_serial"
   " -incoming %s",
   accel, tmpfs, uri);
+} else if (strcmp(arch, "aarch64") == 0) {
+init_bootfile(bootpath, aarch64_kernel);
+cmd_src = g_strdup_printf("-machine virt,accel=kvm:tcg -m 150M "
+  "-name vmsource,debug-threads=on -cpu host "
+  "-serial file:%s/src_serial "
+  "-kernel %s ",
+  tmpfs, bootpath);
+cmd_dst = g_strdup_printf("-machine virt,accel=kvm:tcg -m 150M "
+  "-name vmdest,debug-threads=on -cpu host "
+  "-serial file:%s/dest_serial "
+  "-kernel %s "
+  "-incoming %s ",
+  tmpfs, bootpath, uri);
+/* aarch64 virt machine physical mem started from 0x4000 */
+start_address += 0x4000;
+end_address += 0x4000;
 } else {
 g_assert_not_reached();
 }
@@ -501,7 +518,7 @@ static void test_deprecated(void)
 {
 QTestState *from;
 
-from = qtest_start("");
+from = qtest_start("-machine none");
 
 deprecated_set_downtime(from, 0.12345);
 deprecated_set_speed(from, "12345");
diff --git a/tests/migration/aarch64-a-b-kern

Re: [Qemu-devel] [PATCH] tests/migration: Add source to PC boot block

2018-02-02 Thread Wei Huang


On 01/31/2018 02:16 PM, Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" 
> 
> The boot block used in the migration test is currently only
> shipped as a hex (with the source in the git commit message),
> change this to actually include the source.
> 
> A makefile rule is added, but the expectation is that
> the generated hex is shipped as well as the .s, so that
> there's no requirement to have just the right assembler etc.
> 
> Signed-off-by: Dr. David Alan Gilbert 
> ---
>  tests/Makefile.include  | 18 
>  tests/migration-test.c  | 46 +--
>  tests/migration/x86-a-b-bootblock.h | 52 +
>  tests/migration/x86-a-b-bootblock.s | 92 
> +
>  4 files changed, 163 insertions(+), 45 deletions(-)
>  create mode 100644 tests/migration/x86-a-b-bootblock.h
>  create mode 100644 tests/migration/x86-a-b-bootblock.s
> 
> diff --git a/tests/Makefile.include b/tests/Makefile.include
> index 851aafe9d1..2a0889479c 100644
> --- a/tests/Makefile.include
> +++ b/tests/Makefile.include
> @@ -831,6 +831,24 @@ tests/migration/initrd-stress.img: 
> tests/migration/stress$(EXESUF)
>   rm $(INITRD_WORK_DIR)/init
>   rmdir $(INITRD_WORK_DIR)
>  
> +ASM_WORK_DIR=tests/asm-temp
> +$(SRC_PATH)/tests/migration/x86-a-b-bootblock.h: 
> $(SRC_PATH)/tests/migration/x86-a-b-bootblock.s
> + mkdir $(ASM_WORK_DIR)
> + as --32 -march=i486 $< -o $(ASM_WORK_DIR).o
> + objcopy -O binary $(ASM_WORK_DIR).o $(ASM_WORK_DIR).boot
> + dd if=$(ASM_WORK_DIR).boot of=$(ASM_WORK_DIR).bootsect bs=256 count=2 
> skip=124
> + xxd -i $(ASM_WORK_DIR).bootsect | \
> +sed -e 's/tests_asm_temp_bootsect/bootsect/' -e 's/.*int.*//' > 
> $(ASM_WORK_DIR).hex
> + echo -e "/* This file is automatically generated from\n" \
> + " * tests/migration/x86-a-b-bootblock.s, edit that and then\n" \
> + " * make tests/migration/x86-a-b-bootblock.h to update,\n" \
> + " * and then remember to send both in your patch submission.\n" 
> \
> + " */\n" | cat - $(ASM_WORK_DIR).hex > $@
> + rm $(ASM_WORK_DIR).hex $(ASM_WORK_DIR).bootsect $(ASM_WORK_DIR).boot
> + rm $(ASM_WORK_DIR).o
> + rmdir $(ASM_WORK_DIR)
> +
> +

Could we create a new Makefile.include under tests/migration/ and move
the code above there? The code above is very large and can distract
people working on tests/Makefile.include.

>  ifeq ($(CONFIG_POSIX),y)
>  LIBS += -lutil
>  endif
> diff --git a/tests/migration-test.c b/tests/migration-test.c
> index 799e24ebc6..7550fd8d56 100644
> --- a/tests/migration-test.c
> +++ b/tests/migration-test.c
> @@ -79,51 +79,7 @@ static const char *tmpfs;
>  /* A simple PC boot sector that modifies memory (1-100MB) quickly
>   * outputing a 'B' every so often if it's still running.
>   */
> -unsigned char bootsect[] = {
> -  0xfa, 0x0f, 0x01, 0x16, 0x74, 0x7c, 0x66, 0xb8, 0x01, 0x00, 0x00, 0x00,
> -  0x0f, 0x22, 0xc0, 0x66, 0xea, 0x20, 0x7c, 0x00, 0x00, 0x08, 0x00, 0x00,
> -  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe4, 0x92, 0x0c, 0x02,
> -  0xe6, 0x92, 0xb8, 0x10, 0x00, 0x00, 0x00, 0x8e, 0xd8, 0x66, 0xb8, 0x41,
> -  0x00, 0x66, 0xba, 0xf8, 0x03, 0xee, 0xb3, 0x00, 0xb8, 0x00, 0x00, 0x10,
> -  0x00, 0xfe, 0x00, 0x05, 0x00, 0x10, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x40,
> -  0x06, 0x7c, 0xf2, 0xfe, 0xc3, 0x75, 0xe9, 0x66, 0xb8, 0x42, 0x00, 0x66,
> -  0xba, 0xf8, 0x03, 0xee, 0xeb, 0xde, 0x66, 0x90, 0x00, 0x00, 0x00, 0x00,
> -  0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x9a, 0xcf, 0x00,
> -  0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0xcf, 0x00, 0x27, 0x00, 0x5c, 0x7c,
> -  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> -  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> -  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> -  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> -  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> -  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> -  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> -  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> -  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> -  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> -  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> -  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> -  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> -  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> -  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> -  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> -  0x00, 0x00, 0x00, 0x00, 0x00, 

[Qemu-devel] [PATCH 4/4] tests: Enable xhci test arm/aarch64

2018-02-01 Thread Wei Huang
Signed-off-by: Wei Huang <w...@redhat.com>
---
 tests/Makefile.include | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index e28277c..a79a7b8 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -366,10 +366,12 @@ check-qtest-arm-y += tests/test-arm-mptimer$(EXESUF)
 gcov-files-arm-y += hw/timer/arm_mptimer.c
 check-qtest-arm-y += tests/boot-serial-test$(EXESUF)
 check-qtest-arm-y += tests/drive_del-test$(EXESUF)
+check-qtest-arm-y += tests/usb-hcd-xhci-test$(EXESUF)
 
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
 check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
 check-qtest-aarch64-y += tests/drive_del-test$(EXESUF)
+check-qtest-aarch64-y += tests/usb-hcd-xhci-test$(EXESUF)
 
 check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
 
-- 
1.8.3.1




[Qemu-devel] [PATCH 2/4] tests/boot-serial-test: Add support for the aarch64 virt machine

2018-02-01 Thread Wei Huang
This patch adds a small binary kernel to test aarch64 virt machine's
UART.

Signed-off-by: Wei Huang <w...@redhat.com>
---
 tests/Makefile.include   | 1 +
 tests/boot-serial-test.c | 9 +
 2 files changed, 10 insertions(+)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index ca82e0c..ebdb151 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -367,6 +367,7 @@ gcov-files-arm-y += hw/timer/arm_mptimer.c
 check-qtest-arm-y += tests/boot-serial-test$(EXESUF)
 
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
+check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
 
 check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
 
diff --git a/tests/boot-serial-test.c b/tests/boot-serial-test.c
index 418c5b9..66f7a84 100644
--- a/tests/boot-serial-test.c
+++ b/tests/boot-serial-test.c
@@ -55,6 +55,13 @@ static const uint8_t bios_raspi2[] = {
 0x00, 0x10, 0x20, 0x3f, /* 0x3f201000 = UART0 base addr */
 };
 
+static const uint8_t kernel_aarch64[] = {
+0x81, 0x0a, 0x80, 0x52, /* mov w1, #0x54 */
+0x02, 0x20, 0xa1, 0xd2, /* mov x2, #0x900 */
+0x41, 0x00, 0x00, 0x39, /* strbw1, [x2] */
+0xfd, 0xff, 0xff, 0x17, /* b   -12 (loop) */
+};
+
 typedef struct testdef {
 const char *arch;   /* Target architecture */
 const char *machine;/* Name of the machine */
@@ -87,6 +94,8 @@ static testdef_t tests[] = {
   sizeof(kernel_plml605), kernel_plml605 },
 { "moxie", "moxiesim", "", "TT", sizeof(bios_moxiesim), 0, bios_moxiesim },
 { "arm", "raspi2", "", "TT", sizeof(bios_raspi2), 0, bios_raspi2 },
+{ "aarch64", "virt", "-cpu cortex-a57", "TT", sizeof(kernel_aarch64),
+  kernel_aarch64 },
 
 { NULL }
 };
-- 
1.8.3.1




[Qemu-devel] [PATCH 3/4] tests: Enable drive_del-test on arm/aarch64

2018-02-01 Thread Wei Huang
Signed-off-by: Wei Huang <w...@redhat.com>
---
 tests/Makefile.include | 2 ++
 tests/drive_del-test.c | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index ebdb151..e28277c 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -365,9 +365,11 @@ gcov-files-arm-y += arm-softmmu/hw/block/virtio-blk.c
 check-qtest-arm-y += tests/test-arm-mptimer$(EXESUF)
 gcov-files-arm-y += hw/timer/arm_mptimer.c
 check-qtest-arm-y += tests/boot-serial-test$(EXESUF)
+check-qtest-arm-y += tests/drive_del-test$(EXESUF)
 
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
 check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
+check-qtest-aarch64-y += tests/drive_del-test$(EXESUF)
 
 check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
 
diff --git a/tests/drive_del-test.c b/tests/drive_del-test.c
index c9ac997..2e39442 100644
--- a/tests/drive_del-test.c
+++ b/tests/drive_del-test.c
@@ -123,7 +123,8 @@ int main(int argc, char **argv)
 /* TODO I guess any arch with a hot-pluggable virtio bus would do */
 if (!strcmp(arch, "i386") || !strcmp(arch, "x86_64") ||
 !strcmp(arch, "ppc") || !strcmp(arch, "ppc64") ||
-!strcmp(arch, "s390x")) {
+!strcmp(arch, "s390x") || !strcmp(arch, "arm") ||
+!strcmp(arch, "aarch64")) {
 qtest_add_func("/drive_del/after_failed_device_add",
test_after_failed_device_add);
 qtest_add_func("/blockdev/drive_del_device_del",
-- 
1.8.3.1




[Qemu-devel] [PATCH 1/4] hw/arm/virt: Set default machine and CPU types for mach-virt

2018-02-01 Thread Wei Huang
Unlike most other QEMU architectures, the default machine type for
mach-virt is not set. This causes problems in situations where the
default machine types are not provided (e.g. qtest_start() function
in many QEMU tests). This patch designates the latest mach-virt
machine type (alias of "virt") as the default machine type. It also
changes the default CPU depending on the target.

Signed-off-by: Wei Huang <w...@redhat.com>
---
 hw/arm/virt.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index b334c82..f6b1408 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -68,6 +68,7 @@
 mc->desc = "QEMU " # major "." # minor " ARM Virtual Machine"; \
 if (latest) { \
 mc->alias = "virt"; \
+mc->is_default = 1; \
 } \
 } \
 static const TypeInfo machvirt_##major##_##minor##_info = { \
@@ -1603,7 +1604,12 @@ static void virt_machine_class_init(ObjectClass *oc, 
void *data)
 mc->minimum_page_bits = 12;
 mc->possible_cpu_arch_ids = virt_possible_cpu_arch_ids;
 mc->cpu_index_to_instance_props = virt_cpu_index_to_props;
+#ifdef TARGET_AARCH64
+mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a57");
+#else
 mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a15");
+#endif
+
 mc->get_default_cpu_node_id = virt_get_default_cpu_node_id;
 }
 
-- 
1.8.3.1




Re: [Qemu-devel] [PATCH V1 1/1] tests: Add migration test for aarch64

2018-01-26 Thread Wei Huang


On 01/26/2018 10:39 AM, Peter Maydell wrote:
> On 26 January 2018 at 15:47, Wei Huang <w...@redhat.com> wrote:
>>
>>
>> On 01/25/2018 02:05 PM, Dr. David Alan Gilbert wrote:
>>> * Wei Huang (w...@redhat.com) wrote:
>>>> innerloop:
>>>> /* clean cache because el2 might still cache guest data under KVM 
>>>> */
>>>> dc  civac, x2
>>>
>>> Can you explain a bit more about that please;  if it's guest
>>> visible acorss migration, doesn't that suggest we need the cache clear
>>> in KVM or QEMU?
>>
>> I think this is ARM specific. This is caused by the inconsistency
>> between guest VM's data accesses and userspace's accesses (in
>> check_guest_ram) at the destination:
>>
>> 1) Because uncacheable (guest) + cacheable (host) ==> uncacheable. So
>> the data accesses from guest VM go directly into memory.
>> 2) QEMU user space will use the cacheable version. So it is possible
>> that data can come from cache, instead of RAM. The difference between
>> (1) and (2) obviously can cause check_guest_ram() to fail sometimes.
> 
> I think the correct fix here is that your test code should turn
> its MMU on. Trying to treat guest RAM as uncacheable doesn't work

I did try MMU-on while debugging this problem. It was a migration unit
test written on top of kvm-unit-tests and I forced QEMU's
tests/migration-test.c to use this .flat file as -kernel parameter. I
didn't see any memory check failures using this approach. So I can
confirm your suggestion.

But turning MMU on means a much larger binary blob. I know you don't
like the existing migration-test.c approach. Building a more complicated
test case and embedding it in migration-test.c code will make the
situation worse. Because of this, I chose the current version: small and
manageable (even with one extra cache flush instruction).

> for Arm KVM guests (for the same reason that VGA device video memory
> doesn't work). If it's RAM your guest has to arrange to map it as
> Normal Cacheable, and then everything should work fine.
> 
> thanks
> -- PMM
> 



Re: [Qemu-devel] [PATCH V1 1/1] tests: Add migration test for aarch64

2018-01-26 Thread Wei Huang


On 01/25/2018 02:05 PM, Dr. David Alan Gilbert wrote:
> * Wei Huang (w...@redhat.com) wrote:
>> This patch adds the migration test support for aarch64. The test code,
>> which implements the same functionality as x86, is compiled into a binary
>> and booted as a kernel in qemu. Here are the design ideas:
>>
>>  * We choose this -kernel design because aarch64 QEMU doesn't provide a
>>built-in fw like x86 does. So instead of relying on a boot loader, we
>>use -kernel approach for aarch64.
>>  * The serial output is sent to PL011 directly.
>>  * The physical memory base for mach-virt machine is 0x4000. We change
>>the start_address and end_address for aarch64.
>>
>> RFC->V1:
>>  * aarch64 kernel blob is defined as an uint32_t array
>>  * The test code is re-written to address a data caching issue under KVM.
>>Tests passed under both x86 and aarch64.
>>  * Re-use init_bootfile_x86() for both x86 and aarch64
>>  * Other minor fixes
>>
>> Note that the test code is as the following:
>>
>> .section .text
>>
>> .globl  start
>> 
>> start:
>> /* disable MMU to use phys mem address */
>> mrs x0, sctlr_el1
>> bic x0, x0, #(1<<0)
>> msr sctlr_el1, x0
>> isb
>>
>> /* output char 'A' to PL011 */
>> mov w4, #65
>> mov x5, #0x900
>> strbw4, [x5]
>>
>> /* w6 keeps a counter so we can limit the output speed */
>> mov w6, #0
>>
>> /* phys mem base addr = 0x4000 */
>> mov x3, #(0x4000 + 100 *1024*1024) /* traverse 1M-100M */
>> mov x2, #(0x4000 + 1 * 1024*1024)
>>
>> /* clean up memory first */
>> mov w1, #0  
>> clean:
>> strbw1, [x2]
>> add x2, x2, #(4096)
>> cmp x2, x3
>> ble clean
>>
>> /* main body */
>> mainloop:
>> mov x2, #(0x4000 + 1 * 1024*1024)
>> 
>> innerloop:
>> /* clean cache because el2 might still cache guest data under KVM */
>> dc  civac, x2
> 
> Can you explain a bit more about that please;  if it's guest
> visible acorss migration, doesn't that suggest we need the cache clear
> in KVM or QEMU?

I think this is ARM specific. This is caused by the inconsistency
between guest VM's data accesses and userspace's accesses (in
check_guest_ram) at the destination:

1) Because uncacheable (guest) + cacheable (host) ==> uncacheable. So
the data accesses from guest VM go directly into memory.
2) QEMU user space will use the cacheable version. So it is possible
that data can come from cache, instead of RAM. The difference between
(1) and (2) obviously can cause check_guest_ram() to fail sometimes.

x86's EPT has the capability to ignore guest-provided memory type. So it
is possible to have consistent data views between guest and QEMU user-space.


> 
> Dave
> 
>> ldrbw1, [x2]
>> add w1, w1, #1
>> and w1, w1, #(0xff)
>> strbw1, [x2]
>>
>> add x2, x2, #(4096)
>> cmp x2, x3
>> blt innerloop
>>
>> add w6, w6, #1
>> and w6, w6, #(0xff)
>> cmp w6, #0
>> bne mainloop
>> 
>> /* output char 'B' to PL011 */
>> mov w4, #66
>> mov x5, #0x900
>> strbw4, [x5]
>>
>> bl  mainloop
>>
>> The code is compiled with the following commands:
>>  > gcc -c -o fill.o fill.s
>>  > gcc -O2 -o fill.elf -Wl,-T,/tmp/flat.lds,--build-id=none,-Ttext=4008 \
>>-nostdlib fill.o
>>  > objcopy -O binary fill.elf fill.flat
>>  > truncate -c -s 144 ./fill.flat
>>  > xxd -g 4 -c 24 -e fill.flat | awk '{print "0x"$2 ", " "0x"$3 ", " "0x"C$4 
>> ", " "0x"C$5 ", " "0x"$6 ", " "0x"C$7 "," }'
>>
>> The linker file (borrowed from KVM unit test) is defined as:
>>
>> SECTIONS
>> {
>> .text : { *(.init) *(.text) *(.text.*) }
>> . = ALIGN(64K);
>> etext = .;
>> .data : {
>> *(.data)
>> }
>> . = ALIGN(16);
>> .rodata : { *(.rodata) }
>> . = ALIGN(16);
>> .bss : { *(.bss) }
>> . = ALIGN(64K);
>> edata = .;
>&

[Qemu-devel] [PATCH V1 1/1] tests: Add migration test for aarch64

2018-01-24 Thread Wei Huang
This patch adds the migration test support for aarch64. The test code,
which implements the same functionality as x86, is compiled into a binary
and booted as a kernel in qemu. Here are the design ideas:

 * We choose this -kernel design because aarch64 QEMU doesn't provide a
   built-in fw like x86 does. So instead of relying on a boot loader, we
   use -kernel approach for aarch64.
 * The serial output is sent to PL011 directly.
 * The physical memory base for mach-virt machine is 0x4000. We change
   the start_address and end_address for aarch64.

RFC->V1:
 * aarch64 kernel blob is defined as an uint32_t array
 * The test code is re-written to address a data caching issue under KVM.
   Tests passed under both x86 and aarch64.
 * Re-use init_bootfile_x86() for both x86 and aarch64
 * Other minor fixes

Note that the test code is as the following:

.section .text

.globl  start

start:
/* disable MMU to use phys mem address */
mrs x0, sctlr_el1
bic x0, x0, #(1<<0)
msr sctlr_el1, x0
isb

/* output char 'A' to PL011 */
mov w4, #65
mov x5, #0x900
strbw4, [x5]

/* w6 keeps a counter so we can limit the output speed */
mov w6, #0

/* phys mem base addr = 0x4000 */
mov x3, #(0x4000 + 100 *1024*1024) /* traverse 1M-100M */
mov x2, #(0x4000 + 1 * 1024*1024)

/* clean up memory first */
mov w1, #0  
clean:
strbw1, [x2]
add x2, x2, #(4096)
cmp x2, x3
ble clean

/* main body */
mainloop:
mov x2, #(0x4000 + 1 * 1024*1024)

innerloop:
/* clean cache because el2 might still cache guest data under KVM */
dc  civac, x2
ldrbw1, [x2]
add w1, w1, #1
and w1, w1, #(0xff)
strbw1, [x2]

add x2, x2, #(4096)
cmp x2, x3
blt innerloop

add w6, w6, #1
and w6, w6, #(0xff)
cmp w6, #0
bne mainloop

/* output char 'B' to PL011 */
mov w4, #66
mov x5, #0x900
strbw4, [x5]

bl  mainloop

The code is compiled with the following commands:
 > gcc -c -o fill.o fill.s
 > gcc -O2 -o fill.elf -Wl,-T,/tmp/flat.lds,--build-id=none,-Ttext=4008 \
   -nostdlib fill.o
 > objcopy -O binary fill.elf fill.flat
 > truncate -c -s 144 ./fill.flat
 > xxd -g 4 -c 24 -e fill.flat | awk '{print "0x"$2 ", " "0x"$3 ", " "0x"C$4 ", 
 > " "0x"C$5 ", " "0x"$6 ", " "0x"C$7 "," }'

The linker file (borrowed from KVM unit test) is defined as:

SECTIONS
{
.text : { *(.init) *(.text) *(.text.*) }
. = ALIGN(64K);
etext = .;
.data : {
*(.data)
}
. = ALIGN(16);
.rodata : { *(.rodata) }
. = ALIGN(16);
.bss : { *(.bss) }
. = ALIGN(64K);
edata = .;
. += 64K;
. = ALIGN(64K);
/*
 * stack depth is 16K for arm and PAGE_SIZE for arm64, see THREAD_SIZE
 * sp must be 16 byte aligned for arm64, and 8 byte aligned for arm
 * sp must always be strictly less than the true stacktop
 */
stackptr = . - 16;
stacktop = .;
}

ENTRY(start)

Signed-off-by: Wei Huang <w...@redhat.com>
---
 tests/Makefile.include |  1 +
 tests/migration-test.c | 37 +++--
 2 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index b4bcc872f2..2a520e53ab 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -357,6 +357,7 @@ check-qtest-arm-y += tests/test-arm-mptimer$(EXESUF)
 gcov-files-arm-y += hw/timer/arm_mptimer.c
 
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
+check-qtest-aarch64-y += tests/migration-test$(EXESUF)
 
 check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
 
diff --git a/tests/migration-test.c b/tests/migration-test.c
index be598d3257..3237fe93b2 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -22,8 +22,8 @@
 
 #define MIN_NVRAM_SIZE 8192 /* from spapr_nvram.c */
 
-const unsigned start_address = 1024 * 1024;
-const unsigned end_address = 100 * 1024 * 1024;
+unsigned start_address = 1024 * 1024;
+unsigned end_address = 100 * 1024 * 1024;
 bool got_stop;
 
 #if defined(__linux__)
@@ -79,7 +79,7 @@ static const char *tmpfs;
 /* A simple PC boot sector that modifies memory (1-100MB) quickly
  * outputing a 'B' every so often if it's still running.
  */
-unsigned char bootsect[] = {
+unsigned char x86_bootsect[] = {
   0xfa, 0x0f, 0x01, 0x16, 0x74, 0x7c, 0x66, 0xb8, 0x01, 0x00, 0x00, 0x00,
   0x0f, 0x22, 0xc0, 0x66, 0xea, 0x20, 0x7c, 0x00, 0x00, 0x08, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe4, 0x92, 0x0c, 0

Re: [Qemu-devel] [PATCH RFC 1/1] tests: Add migration test for aarch64

2018-01-05 Thread Wei Huang


On 01/04/2018 02:10 PM, Juan Quintela wrote:
> Wei Huang <w...@redhat.com> wrote:
>> This patch adds the migration test support for aarch64. The test code,
>> which implements the same functionality as x86, is compiled into a binary
>> and booted as a kernel to qemu. Here are the design ideas:
>>
>> * We choose this -kernel design because aarch64 QEMU doesn't provide a
>>   built-in fw like x86 does. So instead of relying on a boot loader, we
>>   use -kernel approach for aarch64.
>> * The serial output is sent to PL011 directly.
>> * The physical memory base for mach-virt machine is 0x4000. We have
>>   to change the start_address and end_address for aarch64.
>> * The downtime is changed from 0.001 to 0.1. Without this change, we saw
>>   migration stalled. This problem is still under analysis and needs to be
>>   resolved before removing RFC for this patch.
> 
> 
> Hi
> 
> I don't have a good solution for how to go from ASM -> binary array, I
> think that Dave suggestion is good.

This is related to a bug Dave Gilbert recently fixed. The reason is
because there were 16 4K dirty pages unaccounted during migration. It is
impossible to migrate them under 0.001 downtime. We are good now with
this issue now.

> 
>>  check-qtest-aarch64-y = tests/numa-test$(EXESUF)
>> +check-qtest-aarch64-y += tests/migration-test$(EXESUF)
>>  
>>  check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
>>  
>> diff --git a/tests/migration-test.c b/tests/migration-test.c
>> index be598d3..b0dd365 100644
>> --- a/tests/migration-test.c
>> +++ b/tests/migration-test.c
>> @@ -22,8 +22,8 @@
>>  
>>  #define MIN_NVRAM_SIZE 8192 /* from spapr_nvram.c */
>>  
>> -const unsigned start_address = 1024 * 1024;
>> -const unsigned end_address = 100 * 1024 * 1024;
>> +unsigned start_address = 1024 * 1024;
>> +unsigned end_address = 100 * 1024 * 1024;
>>  bool got_stop;
>>  
>>  #if defined(__linux__)
>> @@ -125,6 +125,18 @@ unsigned char bootsect[] = {
>>0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa
>>  };
>>  
>> +unsigned char aarch64_kernel[] = {
>> +0x00, 0x10, 0x38, 0xd5, 0x00, 0xf8, 0x7f, 0x92, 0x00, 0x10, 0x18, 0xd5,
>> +0xdf, 0x3f, 0x03, 0xd5, 0x24, 0x08, 0x80, 0x52, 0x05, 0x20, 0xa1, 0xd2,
>> +0xa4, 0x00, 0x00, 0x39, 0x06, 0x00, 0x80, 0x52, 0x03, 0xc8, 0xa8, 0xd2,
>> +0x02, 0x02, 0xa8, 0xd2, 0x41, 0x00, 0x40, 0x39, 0x21, 0x04, 0x00, 0x11,
>> +0x41, 0x00, 0x00, 0x39, 0x42, 0x04, 0x40, 0x91, 0x5f, 0x00, 0x03, 0xeb,
>> +0x6b, 0xff, 0xff, 0x54, 0xc6, 0x04, 0x00, 0x11, 0xc6, 0x1c, 0x00, 0x12,
>> +0xdf, 0x00, 0x00, 0x71, 0xc1, 0xfe, 0xff, 0x54, 0x44, 0x08, 0x80, 0x52,
>> +0x05, 0x20, 0xa1, 0xd2, 0xa4, 0x00, 0x00, 0x39, 0xf2, 0xff, 0xff, 0x97
>> +};
>> +unsigned int aarch64_kernel_len = 96;
> 
> Just wondering, what is wrong with sizeof(aarch64_kernel)?
> 
> (Yes, existing code already do it this bad.)
> 

Yes, we can fix both of them together.

> 
> 
> 
>> +
>>  static void init_bootfile_x86(const char *bootpath)
>>  {
>>  FILE *bootfile = fopen(bootpath, "wb");
>> @@ -163,6 +175,15 @@ static void init_bootfile_ppc(const char *bootpath)
>>  fclose(bootfile);
>>  }
>>  
>> +static void init_bootfile_aarch64(const char *bootpath)
>> +{
>> +FILE *kernelfile = fopen(bootpath, "wb");
>> +
>> +g_assert_cmpint(fwrite(aarch64_kernel, aarch64_kernel_len, 1, 
>> kernelfile),
>> +==, 1);
>> +fclose(kernelfile);
>> +}
> 
> This function is identical to init_bootfile_x86(), just that we are
> using aarch64_kernel instead of bootsect.  Would be a good idea to
> abstract it?

Sure

> 
>> @@ -470,6 +491,22 @@ static void test_migrate_start(QTestState **from, 
>> QTestState **to,
>>" -serial file:%s/dest_serial"
>>" -incoming %s",
>>accel, tmpfs, uri);
>> +} else if (strcmp(arch, "aarch64") == 0) {
>> +init_bootfile_aarch64(bootpath);
>> +cmd_src = g_strdup_printf("-machine virt,accel=kvm:cg -m
>>1024M"
> 
> We are missing a "t" in "tcg", right?
> 
> I see that PC uses 150M, PPC uses 256M and now arm uses 1G.  Any reason
> for that?

It should be kvm:tcg in this case. Also my goal is to use 150M for
AArch64. But I was facing another issue (under debug) which made me to
t

Re: [Qemu-devel] [PATCH] cpu_physical_memory_sync_dirty_bitmap: Another alignment fix

2018-01-03 Thread Wei Huang


On 01/03/2018 12:33 PM, Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" <dgilb...@redhat.com>
> 
> This code has an optimised, word aligned version, and a boring
> unaligned version. My commit f70d345 fixed one alignment issue, but
> there's another.
> 
> The optimised version operates on 'longs' dealing with (typically) 64
> pages at a time, replacing the whole long by a 0 and counting the bits.
> If the Ramblock is less than 64bits in length that long can contain bits
> representing two different RAMBlocks, but the code will update the
> bmap belinging to the 1st RAMBlock only while having updated the total
> dirty page count for both.
> 
> This probably didn't matter prior to 6b6712ef which split the dirty
> bitmap by RAMBlock, but now they're separate RAMBlocks we end up
> with a count that doesn't match the state in the bitmaps.
> 
> Symptom:
>   Migration showing a few dirty pages left to be sent constantly
>   Seen on aarch64 and x86 with x86+ovmf
> 
> Signed-off-by: Dr. David Alan Gilbert <dgilb...@redhat.com>
> Reported-by: Wei Huang <w...@redhat.com>
> Fixes: 6b6712efccd383b48a909bee0b29e079a57601ec

This solves the failure I saw in the migration test case.

Acked-by: Wei Huang <w...@redhat.com>

> ---
>  include/exec/ram_addr.h | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
> index 6cbc02aa0f..7633ef6342 100644
> --- a/include/exec/ram_addr.h
> +++ b/include/exec/ram_addr.h
> @@ -391,9 +391,10 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock 
> *rb,
>  uint64_t num_dirty = 0;
>  unsigned long *dest = rb->bmap;
>  
> -/* start address is aligned at the start of a word? */
> +/* start address and length is aligned at the start of a word? */
>  if (((word * BITS_PER_LONG) << TARGET_PAGE_BITS) ==
> - (start + rb->offset)) {
> + (start + rb->offset) &&
> +!(length & ((BITS_PER_LONG << TARGET_PAGE_BITS) - 1))) {
>  int k;
>  int nr = BITS_TO_LONGS(length >> TARGET_PAGE_BITS);
>  unsigned long * const *src;
> 



Re: [Qemu-devel] [PATCH RFC 1/1] tests: Add migration test for aarch64

2017-12-17 Thread Wei Huang


On 12/16/2017 07:49 AM, Peter Maydell wrote:
> On 15 December 2017 at 20:37, Wei Huang <w...@redhat.com> wrote:
>> This patch adds the migration test support for aarch64. The test code,
>> which implements the same functionality as x86, is compiled into a binary
>> and booted as a kernel to qemu. Here are the design ideas:
>>
>> * We choose this -kernel design because aarch64 QEMU doesn't provide a
>>   built-in fw like x86 does. So instead of relying on a boot loader, we
>>   use -kernel approach for aarch64.
>> * The serial output is sent to PL011 directly.
>> * The physical memory base for mach-virt machine is 0x4000. We have
>>   to change the start_address and end_address for aarch64.
>> * The downtime is changed from 0.001 to 0.1. Without this change, we saw
>>   migration stalled. This problem is still under analysis and needs to be
>>   resolved before removing RFC for this patch.
>>
>> The test code is as the following:
>>
>> .section .text
> 
> 
>>  #if defined(__linux__)
>> @@ -125,6 +125,18 @@ unsigned char bootsect[] = {
>>0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa
>>  };
>>
>> +unsigned char aarch64_kernel[] = {
>> +0x00, 0x10, 0x38, 0xd5, 0x00, 0xf8, 0x7f, 0x92, 0x00, 0x10, 0x18, 0xd5,
>> +0xdf, 0x3f, 0x03, 0xd5, 0x24, 0x08, 0x80, 0x52, 0x05, 0x20, 0xa1, 0xd2,
>> +0xa4, 0x00, 0x00, 0x39, 0x06, 0x00, 0x80, 0x52, 0x03, 0xc8, 0xa8, 0xd2,
>> +0x02, 0x02, 0xa8, 0xd2, 0x41, 0x00, 0x40, 0x39, 0x21, 0x04, 0x00, 0x11,
>> +0x41, 0x00, 0x00, 0x39, 0x42, 0x04, 0x40, 0x91, 0x5f, 0x00, 0x03, 0xeb,
>> +0x6b, 0xff, 0xff, 0x54, 0xc6, 0x04, 0x00, 0x11, 0xc6, 0x1c, 0x00, 0x12,
>> +0xdf, 0x00, 0x00, 0x71, 0xc1, 0xfe, 0xff, 0x54, 0x44, 0x08, 0x80, 0x52,
>> +0x05, 0x20, 0xa1, 0xd2, 0xa4, 0x00, 0x00, 0x39, 0xf2, 0xff, 0xff, 0x97
>> +};
>> +unsigned int aarch64_kernel_len = 96;
> 
> I'm not really a fan of this steadily increasing number of hex-encoded
> target binary blobs in the tests directory, but if we must, I
> think this would be easier to read as an array of uint32_t,
> so that each entry is one instruction word.

This make sense given that ARM has fixed-length instructions.

> 
> (If your claim is that nobody cares about the hex because
> they'll just rebuild from the source code in the commit
> message, I would suggest that that makes the source code
> the 'preferred form for modification' under the GPL...)
> 

Overall I agree with your comments. For this specific migration-test,
PPC's approach is my preferred one. But unfortunately, ARM doesn't have
a built-in firmware in QEMU to run a scripting test. So either we have
to use a per-compiled binary blob, or find a way to build this blob from
source inside QEMU. The second one might take a while to complete though.

> But I think at some point we really need to stop doing
> this and instead figure out a mechanism for building
> target code as part of the QEMU build-and-test.
> It is coming up increasingly often:
>  * code to run on the guest in tests
>  * the bios blobs (at the moment we special case
>the x86 bios blobs and assume we can compile them
>with the host C compiler, which is not great)
>  * for linux-user on several architectures we would like
>to properly implement a guest VDSO
> 
> thanks
> -- PMM
> 



[Qemu-devel] [PATCH RFC 1/1] tests: Add migration test for aarch64

2017-12-15 Thread Wei Huang
This patch adds the migration test support for aarch64. The test code,
which implements the same functionality as x86, is compiled into a binary
and booted as a kernel to qemu. Here are the design ideas:

* We choose this -kernel design because aarch64 QEMU doesn't provide a
  built-in fw like x86 does. So instead of relying on a boot loader, we
  use -kernel approach for aarch64.
* The serial output is sent to PL011 directly.
* The physical memory base for mach-virt machine is 0x4000. We have
  to change the start_address and end_address for aarch64.
* The downtime is changed from 0.001 to 0.1. Without this change, we saw
  migration stalled. This problem is still under analysis and needs to be
  resolved before removing RFC for this patch.

The test code is as the following:

.section .text

.globl  start

start:
/* disable MMU to use phys mem address, just in case */
mrs x0, sctlr_el1
bic x0, x0, #(1<<0)
msr sctlr_el1, x0
isb

/* output char 'A' to PL011 */
mov w4, #65
mov x5, #0x900
strbw4, [x5]

/* w6 keeps a counter so we limit the output speed */
mov w6, #0

mov x3, #(0x4000 + 100 * 1024 * 1024)
mainloop:
mov x2, #(0x4000 + 1024*1024) /* base addr = 0x4000 */

innerloop:
ldrbw1, [x2]
add w1, w1, #1
strbw1, [x2]

add x2, x2, #(4096)
cmp x2, x3
blt innerloop

add w6, w6, #1
and w6, w6, #(0xff)
cmp w6, #0
bne mainloop

/* output char 'B' to PL011 */
mov w4, #66
mov x5, #0x900
strbw4, [x5]

bl  mainloop

The code is compiled with the following command:
 * gcc -c -o fill.o fill.s
 * gcc -O2 -o fill.elf -Wl,-T,/tmp/flat.lds,--build-id=none,-Ttext=4008 \
   -nostdlib fill.o
 * objcopy -O binary fill.elf fill.flat
 * xxd -i fill.flat

The linker file (borrowed from KVM unit test) is defined as:

SECTIONS
{
.text : { *(.init) *(.text) *(.text.*) }
. = ALIGN(64K);
etext = .;
.data : {
*(.data)
}
. = ALIGN(16);
.rodata : { *(.rodata) }
. = ALIGN(16);
.bss : { *(.bss) }
. = ALIGN(64K);
edata = .;
. += 64K;
. = ALIGN(64K);
/*
 * stack depth is 16K for arm and PAGE_SIZE for arm64, see THREAD_SIZE
 * sp must be 16 byte aligned for arm64, and 8 byte aligned for arm
 * sp must always be strictly less than the true stacktop
 */
stackptr = . - 16;
stacktop = .;
}

ENTRY(start)

Signed-off-by: Wei Huang <w...@redhat.com>
---
 tests/Makefile.include |  1 +
 tests/migration-test.c | 43 ---
 2 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index c002352..d5828c4 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -357,6 +357,7 @@ check-qtest-arm-y += tests/test-arm-mptimer$(EXESUF)
 gcov-files-arm-y += hw/timer/arm_mptimer.c
 
 check-qtest-aarch64-y = tests/numa-test$(EXESUF)
+check-qtest-aarch64-y += tests/migration-test$(EXESUF)
 
 check-qtest-microblazeel-y = $(check-qtest-microblaze-y)
 
diff --git a/tests/migration-test.c b/tests/migration-test.c
index be598d3..b0dd365 100644
--- a/tests/migration-test.c
+++ b/tests/migration-test.c
@@ -22,8 +22,8 @@
 
 #define MIN_NVRAM_SIZE 8192 /* from spapr_nvram.c */
 
-const unsigned start_address = 1024 * 1024;
-const unsigned end_address = 100 * 1024 * 1024;
+unsigned start_address = 1024 * 1024;
+unsigned end_address = 100 * 1024 * 1024;
 bool got_stop;
 
 #if defined(__linux__)
@@ -125,6 +125,18 @@ unsigned char bootsect[] = {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa
 };
 
+unsigned char aarch64_kernel[] = {
+0x00, 0x10, 0x38, 0xd5, 0x00, 0xf8, 0x7f, 0x92, 0x00, 0x10, 0x18, 0xd5,
+0xdf, 0x3f, 0x03, 0xd5, 0x24, 0x08, 0x80, 0x52, 0x05, 0x20, 0xa1, 0xd2,
+0xa4, 0x00, 0x00, 0x39, 0x06, 0x00, 0x80, 0x52, 0x03, 0xc8, 0xa8, 0xd2,
+0x02, 0x02, 0xa8, 0xd2, 0x41, 0x00, 0x40, 0x39, 0x21, 0x04, 0x00, 0x11,
+0x41, 0x00, 0x00, 0x39, 0x42, 0x04, 0x40, 0x91, 0x5f, 0x00, 0x03, 0xeb,
+0x6b, 0xff, 0xff, 0x54, 0xc6, 0x04, 0x00, 0x11, 0xc6, 0x1c, 0x00, 0x12,
+0xdf, 0x00, 0x00, 0x71, 0xc1, 0xfe, 0xff, 0x54, 0x44, 0x08, 0x80, 0x52,
+0x05, 0x20, 0xa1, 0xd2, 0xa4, 0x00, 0x00, 0x39, 0xf2, 0xff, 0xff, 0x97
+};
+unsigned int aarch64_kernel_len = 96;
+
 static void init_bootfile_x86(const char *bootpath)
 {
 FILE *bootfile = fopen(bootpath, "wb");
@@ -163,6 +175,15 @@ static void init_bootfile_ppc(const char *bootpath)
 fclose(bootfile);
 }
 
+static void init_bootfile_aarch64(const char *bootpath)
+{
+FILE *kernelfile = fopen(bootpath, "wb");
+
+g_assert_cmpint(fwrite(aarch64_kernel, aarch64_kernel_len, 1, kernelfile),
+==, 1);
+fclos

Re: [Qemu-devel] [PATCH] hw/arm: Silence xlnx-ep108 deprecation warning during tests

2017-11-16 Thread Wei Huang


On 11/16/2017 09:29 AM, Thomas Huth wrote:
> The new deprecation warning for the xlnx-ep108 machine also pops up
> during "make check" which is kind of confusing. Silence it if testing
> mode is enabled.
> 
> Signed-off-by: Thomas Huth <th...@redhat.com>
> ---
>  Note: I slightly shortened the message so that the code still fits
>  into the 80-columns limit.
> 
>  hw/arm/xlnx-zcu102.c | 7 +--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/arm/xlnx-zcu102.c b/hw/arm/xlnx-zcu102.c
> index 9631a53..bbe7d04 100644
> --- a/hw/arm/xlnx-zcu102.c
> +++ b/hw/arm/xlnx-zcu102.c
> @@ -24,6 +24,7 @@
>  #include "qemu/error-report.h"
>  #include "exec/address-spaces.h"
>  #include "qemu/log.h"
> +#include "sysemu/qtest.h"
>  
>  typedef struct XlnxZCU102 {
>  MachineState parent_obj;
> @@ -164,8 +165,10 @@ static void xlnx_ep108_init(MachineState *machine)
>  {
>  XlnxZCU102 *s = EP108_MACHINE(machine);
>  
> -info_report("The Xilinx EP108 machine is deprecated, please use the "
> -"ZCU102 machine instead. It has the same features 
> supported.");
> +if (!qtest_enabled()) {
> +info_report("The Xilinx EP108 machine is deprecated, please use the "
> +        "ZCU102 machine (which has the same features) instead.");
> +}
>  
>  xlnx_zynqmp_init(s, machine);
>  }
> 

I tested it and it did solve the problem.

Acked-by: Wei Huang <w...@redhat.com>



  1   2   3   4   >