Re: [Qemu-devel] [PATCH v3 30/40] s390x/tcg: Implement VECTOR SHIFT LEFT DOUBLE BY BYTE

2019-05-02 Thread Richard Henderson
On 5/2/19 7:10 AM, David Hildenbrand wrote:
> Inline expansion courtesy of Richard H.
> 
> Signed-off-by: David Hildenbrand 
> ---
>  target/s390x/insn-data.def  |  2 ++
>  target/s390x/translate_vx.inc.c | 29 +
>  2 files changed, 31 insertions(+)

Reviewed-by: Richard Henderson 

r~




Re: [Qemu-devel] [PATCH v3 34/40] s390x/tcg: Implement VECTOR SUBTRACT COMPUTE BORROW INDICATION

2019-05-02 Thread Richard Henderson
On 5/2/19 7:10 AM, David Hildenbrand wrote:
> Let's keep it simple for now and handle 8/16 bit elements via helpers.
> Especially for 8/16, we could come up with some bit tricks.
> 
> Signed-off-by: David Hildenbrand 
> ---
>  target/s390x/helper.h   |  2 ++
>  target/s390x/insn-data.def  |  2 ++
>  target/s390x/translate_vx.inc.c | 52 +
>  target/s390x/vec_int_helper.c   | 16 ++
>  4 files changed, 72 insertions(+)

Reviewed-by: Richard Henderson 

r~





[Qemu-devel] [QEMU-PPC] [PATCH 06/13] target/ppc: Enforce that the root page directory size must be at least 5

2019-05-02 Thread Suraj Jitindar Singh
According to the ISA the root page directory size of a radix tree for
either process or partition scoped translation must be >= 5.

Thus add this to the list of conditions checked when validating the
partition table entry in validate_pate();

Signed-off-by: Suraj Jitindar Singh 
---
 target/ppc/mmu-radix64.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c
index a6ab290323..afa5ba506a 100644
--- a/target/ppc/mmu-radix64.c
+++ b/target/ppc/mmu-radix64.c
@@ -249,6 +249,8 @@ static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, 
ppc_v3_pate_t *pate)
 if (lpid == 0 && !msr_hv) {
 return false;
 }
+if ((pate->dw0 & PATE1_R_PRTS) < 5)
+return false;
 /* More checks ... */
 return true;
 }
-- 
2.13.6




[Qemu-devel] [QEMU-PPC] [PATCH 09/13] target/ppc: Implement hcall H_ENTER_NESTED

2019-05-02 Thread Suraj Jitindar Singh
The hcall H_ENTER_NESTED is used by a guest acting as a nested
hypervisor to provide the state of one of its guests which it would
like the real hypervisor to load onto the cpu and execute on its behalf.

The hcall takes as arguments 2 guest real addresses which provide the
location of a regs struct and a hypervisor regs struct which provide the
values to use to execute the guest. These are loaded into the cpu state
and then the function returns to continue tcg execution in the new
context. When an interrupt requires us to context switch back we restore
the old register values and save the cpu state back into the guest
memory.

Signed-off-by: Suraj Jitindar Singh 
---
 hw/ppc/spapr_hcall.c | 285 +++
 include/hw/ppc/spapr.h   |   3 +-
 target/ppc/cpu.h |  55 +
 target/ppc/excp_helper.c |  13 ++-
 4 files changed, 353 insertions(+), 3 deletions(-)

diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index 704ceff8e1..68f3282214 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -16,6 +16,7 @@
 #include "hw/ppc/spapr_ovec.h"
 #include "mmu-book3s-v3.h"
 #include "hw/mem/memory-device.h"
+#include "hw/ppc/ppc.h"
 
 static bool has_spr(PowerPCCPU *cpu, int spr)
 {
@@ -1847,6 +1848,289 @@ static target_ulong h_set_partition_table(PowerPCCPU 
*cpu,
 return H_SUCCESS;
 }
 
+static void byteswap_pt_regs(struct pt_regs *regs)
+{
+target_ulong *addr = (target_ulong *) regs;
+
+for (; addr < ((target_ulong *) (regs + 1)); addr++) {
+*addr = bswap64(*addr);
+}
+}
+
+static void byteswap_hv_regs(struct hv_guest_state *hr)
+{
+hr->version = bswap64(hr->version);
+hr->lpid = bswap32(hr->lpid);
+hr->vcpu_token = bswap32(hr->vcpu_token);
+hr->lpcr = bswap64(hr->lpcr);
+hr->pcr = bswap64(hr->pcr);
+hr->amor = bswap64(hr->amor);
+hr->dpdes = bswap64(hr->dpdes);
+hr->hfscr = bswap64(hr->hfscr);
+hr->tb_offset = bswap64(hr->tb_offset);
+hr->dawr0 = bswap64(hr->dawr0);
+hr->dawrx0 = bswap64(hr->dawrx0);
+hr->ciabr = bswap64(hr->ciabr);
+hr->hdec_expiry = bswap64(hr->hdec_expiry);
+hr->purr = bswap64(hr->purr);
+hr->spurr = bswap64(hr->spurr);
+hr->ic = bswap64(hr->ic);
+hr->vtb = bswap64(hr->vtb);
+hr->hdar = bswap64(hr->hdar);
+hr->hdsisr = bswap64(hr->hdsisr);
+hr->heir = bswap64(hr->heir);
+hr->asdr = bswap64(hr->asdr);
+hr->srr0 = bswap64(hr->srr0);
+hr->srr1 = bswap64(hr->srr1);
+hr->sprg[0] = bswap64(hr->sprg[0]);
+hr->sprg[1] = bswap64(hr->sprg[1]);
+hr->sprg[2] = bswap64(hr->sprg[2]);
+hr->sprg[3] = bswap64(hr->sprg[3]);
+hr->pidr = bswap64(hr->pidr);
+hr->cfar = bswap64(hr->cfar);
+hr->ppr = bswap64(hr->ppr);
+}
+
+static void save_regs(PowerPCCPU *cpu, struct pt_regs *regs)
+{
+CPUPPCState env = cpu->env;
+int i;
+
+for (i = 0; i < 32; i++)
+regs->gpr[i] = env.gpr[i];
+regs->nip = env.nip;
+regs->msr = env.msr;
+regs->ctr = env.ctr;
+regs->link = env.lr;
+regs->xer = env.xer;
+regs->ccr = 0UL;
+for (i = 0; i < 8; i++)
+regs->ccr |= ((env.crf[i] & 0xF) << ((7 - i) * 4));
+regs->dar = env.spr[SPR_DAR];
+regs->dsisr = env.spr[SPR_DSISR];
+}
+
+static void save_hv_regs(PowerPCCPU *cpu, struct hv_guest_state *hv_regs)
+{
+CPUPPCState env = cpu->env;
+
+hv_regs->lpid = env.spr[SPR_LPIDR];
+hv_regs->lpcr = env.spr[SPR_LPCR];
+hv_regs->pcr = env.spr[SPR_PCR];
+hv_regs->amor = env.spr[SPR_AMOR];
+hv_regs->dpdes = !!(env.pending_interrupts & (1 << 
PPC_INTERRUPT_DOORBELL));
+hv_regs->hfscr = env.spr[SPR_HFSCR];
+hv_regs->tb_offset = env.tb_env->tb_offset;
+hv_regs->dawr0 = env.spr[SPR_DAWR];
+hv_regs->dawrx0 = env.spr[SPR_DAWRX];
+hv_regs->ciabr = env.spr[SPR_CIABR];
+hv_regs->purr = cpu_ppc_load_purr(&env);
+hv_regs->spurr = cpu_ppc_load_purr(&env);
+hv_regs->ic = env.spr[SPR_IC];
+hv_regs->vtb = cpu_ppc_load_vtb(&env);
+hv_regs->hdar = env.spr[SPR_HDAR];
+hv_regs->hdsisr = env.spr[SPR_HDSISR];
+hv_regs->asdr = env.spr[SPR_ASDR];
+hv_regs->srr0 = env.spr[SPR_SRR0];
+hv_regs->srr1 = env.spr[SPR_SRR1];
+hv_regs->sprg[0] = env.spr[SPR_SPRG0];
+hv_regs->sprg[1] = env.spr[SPR_SPRG1];
+hv_regs->sprg[2] = env.spr[SPR_SPRG2];
+hv_regs->sprg[3] = env.spr[SPR_SPRG3];
+hv_regs->pidr = env.spr[SPR_BOOKS_PID];
+hv_regs->cfar = env.cfar;
+hv_regs->ppr = env.spr[SPR_PPR];
+}
+
+static void restore_regs(PowerPCCPU *cpu, struct pt_regs regs)
+{
+CPUPPCState *env = &cpu->env;
+int i;
+
+for (i = 0; i < 32; i++)
+env->gpr[i] = regs.gpr[i];
+env->nip = regs.nip;
+ppc_store_msr(env, regs.msr);
+env->ctr = regs.ctr;
+env->lr = regs.link;
+env->xer = regs.xer;
+for (i = 0; i < 8; i++)
+env->crf[i] = (regs.ccr >> ((7 - i) * 4)) & 0xF;
+env->spr[SPR_DAR] = regs.dar;
+env->spr[SPR_DSISR] = regs.dsisr;
+}

[Qemu-devel] [QEMU-PPC] [PATCH 08/13] target/ppc: Implement hcall H_SET_PARTITION_TABLE

2019-05-02 Thread Suraj Jitindar Singh
The hcall H_SET_PARTITION_TABLE is used by a guest acting as a nested
hypervisor to register the partition table entry for one of its guests
with the real hypervisor.

Implement this hcall for a spapr guest.

Signed-off-by: Suraj Jitindar Singh 
---
 hw/ppc/spapr_hcall.c   | 22 ++
 include/hw/ppc/spapr.h |  4 +++-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index 4d7fe337a1..704ceff8e1 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -1828,6 +1828,25 @@ static target_ulong h_update_dt(PowerPCCPU *cpu, 
SpaprMachineState *spapr,
 return H_SUCCESS;
 }
 
+static target_ulong h_set_partition_table(PowerPCCPU *cpu,
+  SpaprMachineState *spapr,
+  target_ulong opcode,
+  target_ulong *args)
+{
+CPUPPCState *env = &cpu->env;
+target_ulong ptcr = args[0];
+
+if (spapr_get_cap(spapr, SPAPR_CAP_NESTED_KVM_HV) == 0) {
+return H_FUNCTION;
+}
+
+if ((ptcr & PTCR_PATS) > 24)
+return H_PARAMETER;
+
+env->spr[SPR_PTCR] = ptcr;
+return H_SUCCESS;
+}
+
 static spapr_hcall_fn papr_hypercall_table[(MAX_HCALL_OPCODE / 4) + 1];
 static spapr_hcall_fn kvmppc_hypercall_table[KVMPPC_HCALL_MAX - 
KVMPPC_HCALL_BASE + 1];
 
@@ -1934,6 +1953,9 @@ static void hypercall_register_types(void)
 
 spapr_register_hypercall(KVMPPC_H_UPDATE_DT, h_update_dt);
 
+/* Platform-specific hcalls used for nested HV KVM */
+spapr_register_hypercall(H_SET_PARTITION_TABLE, h_set_partition_table);
+
 /* Virtual Processor Home Node */
 spapr_register_hypercall(H_HOME_NODE_ASSOCIATIVITY,
  h_home_node_associativity);
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 4251215908..e591ee0ba0 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -501,7 +501,9 @@ struct SpaprMachineState {
 /* Client Architecture support */
 #define KVMPPC_H_CAS(KVMPPC_HCALL_BASE + 0x2)
 #define KVMPPC_H_UPDATE_DT  (KVMPPC_HCALL_BASE + 0x3)
-#define KVMPPC_HCALL_MAXKVMPPC_H_UPDATE_DT
+/* Platform-specific hcalls used for nested HV KVM */
+#define H_SET_PARTITION_TABLE   0xF800
+#define KVMPPC_HCALL_MAXH_SET_PARTITION_TABLE
 
 typedef struct SpaprDeviceTreeUpdateHeader {
 uint32_t version_id;
-- 
2.13.6




[Qemu-devel] [QEMU-PPC] [PATCH 13/13] target/ppc: Enable SPAPR_CAP_NESTED_KVM_HV under tcg

2019-05-02 Thread Suraj Jitindar Singh
It is now possible to use nested kvm-hv under tcg, thus allow for it to
be enabled.

Note that nested kvm-hv requires that rc updates to ptes be done by
software, otherwise the page tables get out of sync. So disable hardware
rc updates when nested kvm-hv is enabled.

Signed-off-by: Suraj Jitindar Singh 
---
 hw/ppc/spapr_caps.c  | 22 ++
 target/ppc/cpu.h |  1 +
 target/ppc/mmu-radix64.c |  4 ++--
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
index 3278c09b0f..7fe07d83dd 100644
--- a/hw/ppc/spapr_caps.c
+++ b/hw/ppc/spapr_caps.c
@@ -389,10 +389,7 @@ static void cap_nested_kvm_hv_apply(SpaprMachineState 
*spapr,
 return;
 }
 
-if (tcg_enabled()) {
-error_setg(errp,
-   "No Nested KVM-HV support in tcg, try cap-nested-hv=off");
-} else if (kvm_enabled()) {
+if (kvm_enabled()) {
 if (!kvmppc_has_cap_nested_kvm_hv()) {
 error_setg(errp,
 "KVM implementation does not support Nested KVM-HV, try cap-nested-hv=off");
@@ -400,6 +397,22 @@ static void cap_nested_kvm_hv_apply(SpaprMachineState 
*spapr,
 error_setg(errp,
 "Error enabling cap-nested-hv with KVM, try cap-nested-hv=off");
 }
+} /* else { nothing required for tcg } */
+}
+
+static void cap_nested_kvm_hv_cpu_apply(SpaprMachineState *spapr,
+PowerPCCPU *cpu,
+uint8_t val, Error **errp)
+{
+CPUPPCState *env = &cpu->env;
+
+if (tcg_enabled() && val) {
+if (env->spr[SPR_PVR] != 0x004E1202) {
+error_setg(errp, "Nested KVM-HV only supported on POWER9 DD2.2, "
+ "try cap-nested-hv=off or -cpu power9_v2.2");
+return;
+}
+env->disable_hw_rc_updates = true;
 }
 }
 
@@ -544,6 +557,7 @@ SpaprCapabilityInfo capability_table[SPAPR_CAP_NUM] = {
 .set = spapr_cap_set_bool,
 .type = "bool",
 .apply = cap_nested_kvm_hv_apply,
+.cpu_apply = cap_nested_kvm_hv_cpu_apply,
 },
 [SPAPR_CAP_LARGE_DECREMENTER] = {
 .name = "large-decr",
diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
index 426015c9cd..6502e0de82 100644
--- a/target/ppc/cpu.h
+++ b/target/ppc/cpu.h
@@ -1237,6 +1237,7 @@ struct CPUPPCState {
 target_ulong hv_ptr, regs_ptr;
 struct hv_guest_state l2_hv, l1_saved_hv;
 struct pt_regs l2_regs, l1_saved_regs;
+bool disable_hw_rc_updates;
 };
 
 #define SET_FIT_PERIOD(a_, b_, c_, d_)  \
diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c
index 2a8147fc38..cc06967dbe 100644
--- a/target/ppc/mmu-radix64.c
+++ b/target/ppc/mmu-radix64.c
@@ -31,9 +31,9 @@
 static inline bool ppc_radix64_hw_rc_updates(CPUPPCState *env)
 {
 #ifdef CONFIG_ATOMIC64
-return true;
+return !env->disable_hw_rc_updates;
 #else
-return !qemu_tcg_mttcg_enabled();
+return !qemu_tcg_mttcg_enabled() && !env->disable_hw_rc_updates;
 #endif
 }
 
-- 
2.13.6




Re: [Qemu-devel] [QEMU-PPC] [PATCH 00/13] target/ppc: Implement KVM support under TCG

2019-05-02 Thread Suraj Jitindar Singh
On Fri, 2019-05-03 at 15:53 +1000, Suraj Jitindar Singh wrote:
> This patch series adds the necessary parts so that a tcg guest is
> able to use
> kvm facilities. That is a tcg guest can boot its own kvm guests.
> 
> The main requirements for this were a few registers and instructions
> as well as
> some hcalls and the addition of partition scoped translation in the
> radix mmu
> emulation.
> 
> This can be used to boot a kvm guest under a pseries tcg guest:
> Use power9_v2.2 cpu and add -machine cap-nested-hv=on for the first
> guest.
> Then inside that guest boot a kvm guest as normal.
> This takes advantage of the new hcalls with qemu emulating them as a
> normal
> hypervisor would on a real machine.
> 
> This can also be used to boot a kvm guest under a powernv tcg guest:
> Use any power9 cpu type.
> This takes advantage of the new hv register access added.
> Note that for powernv there is no xive interrupt excalation for KVM
> which means
> that while the guest will boot, it won't receive any interrupts.

Ah so I'm suddenly aware I based this on the wrong tree so it won't
apply to your dwg-ppc-for-4.1 David.

Consider this a RFC and I'll rebase and resend when required.

> 
> Suraj Jitindar Singh (13):
>   target/ppc: Implement the VTB for HV access
>   target/ppc: Work [S]PURR implementation and add HV support
>   target/ppc: Add SPR ASDR
>   target/ppc: Add SPR TBU40
>   target/ppc: Add privileged message send facilities
>   target/ppc: Enforce that the root page directory size must be at
> least
> 5
>   target/ppc: Handle partition scoped radix tree translation
>   target/ppc: Implement hcall H_SET_PARTITION_TABLE
>   target/ppc: Implement hcall H_ENTER_NESTED
>   target/ppc: Implement hcall H_TLB_INVALIDATE
>   target/ppc: Implement hcall H_COPY_TOFROM_GUEST
>   target/ppc: Introduce POWER9 DD2.2 cpu type
>   target/ppc: Enable SPAPR_CAP_NESTED_KVM_HV under tcg
> 
>  hw/ppc/ppc.c|  46 -
>  hw/ppc/spapr_caps.c |  22 ++-
>  hw/ppc/spapr_cpu_core.c |   1 +
>  hw/ppc/spapr_hcall.c| 409
> +++
>  include/hw/ppc/ppc.h|   4 +-
>  include/hw/ppc/spapr.h  |   7 +-
>  linux-user/ppc/cpu_loop.c   |   5 +
>  target/ppc/cpu-models.c |   2 +
>  target/ppc/cpu-models.h |   1 +
>  target/ppc/cpu.h|  70 +++
>  target/ppc/excp_helper.c|  79 +++-
>  target/ppc/helper.h |   9 +
>  target/ppc/misc_helper.c|  46 +
>  target/ppc/mmu-radix64.c| 412 
> 
>  target/ppc/mmu-radix64.h|   4 +
>  target/ppc/timebase_helper.c|  20 ++
>  target/ppc/translate.c  |  28 +++
>  target/ppc/translate_init.inc.c | 107 +--
>  18 files changed, 1115 insertions(+), 157 deletions(-)
> 



[Qemu-devel] [QEMU-PPC] [PATCH 10/13] target/ppc: Implement hcall H_TLB_INVALIDATE

2019-05-02 Thread Suraj Jitindar Singh
The hcall H_TLB_INVALIDATE is used by a guest acting as a nested
hypervisor to perform partition scoped tlb invalidation since these
instructions are hypervisor privileged.

Check the arguments are valid and then invalidate the entire tlb since
this is about all we can do in tcg.

Signed-off-by: Suraj Jitindar Singh 
---
 hw/ppc/spapr_hcall.c   | 28 
 include/hw/ppc/spapr.h |  3 ++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index 68f3282214..a84d5e2163 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -2131,6 +2131,33 @@ void h_exit_nested(PowerPCCPU *cpu)
 env->gpr[3] = trap;
 }
 
+static target_ulong h_nested_tlb_invalidate(PowerPCCPU *cpu,
+SpaprMachineState *spapr,
+target_ulong opcode,
+target_ulong *args)
+{
+target_ulong instr = args[0];
+target_ulong rbval = args[2];
+int r, ric, prs, is;
+
+if (spapr_get_cap(spapr, SPAPR_CAP_NESTED_KVM_HV) == 0) {
+return H_FUNCTION;
+}
+
+ric = (instr >> 18) & 0x3;
+prs = (instr >> 17) & 0x1;
+r = (instr >> 16) & 0x1;
+is = (rbval >> 10) & 0x3;
+
+if ((!r) || (prs) || (ric == 3) || (is == 1) || ((!is) && (ric == 1 ||
+   ric == 2)))
+return H_PARAMETER;
+
+/* Invalidate everything, not much else we can do */
+cpu->env.tlb_need_flush = TLB_NEED_GLOBAL_FLUSH | TLB_NEED_LOCAL_FLUSH;
+return H_SUCCESS;
+}
+
 static spapr_hcall_fn papr_hypercall_table[(MAX_HCALL_OPCODE / 4) + 1];
 static spapr_hcall_fn kvmppc_hypercall_table[KVMPPC_HCALL_MAX - 
KVMPPC_HCALL_BASE + 1];
 
@@ -2240,6 +2267,7 @@ static void hypercall_register_types(void)
 /* Platform-specific hcalls used for nested HV KVM */
 spapr_register_hypercall(H_SET_PARTITION_TABLE, h_set_partition_table);
 spapr_register_hypercall(H_ENTER_NESTED, h_enter_nested);
+spapr_register_hypercall(H_TLB_INVALIDATE, h_nested_tlb_invalidate);
 
 /* Virtual Processor Home Node */
 spapr_register_hypercall(H_HOME_NODE_ASSOCIATIVITY,
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 7083dea9ef..6a614c445f 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -504,7 +504,8 @@ struct SpaprMachineState {
 /* Platform-specific hcalls used for nested HV KVM */
 #define H_SET_PARTITION_TABLE   0xF800
 #define H_ENTER_NESTED  0xF804
-#define KVMPPC_HCALL_MAXH_ENTER_NESTED
+#define H_TLB_INVALIDATE0xF808
+#define KVMPPC_HCALL_MAXH_TLB_INVALIDATE
 
 typedef struct SpaprDeviceTreeUpdateHeader {
 uint32_t version_id;
-- 
2.13.6




[Qemu-devel] [QEMU-PPC] [PATCH 11/13] target/ppc: Implement hcall H_COPY_TOFROM_GUEST

2019-05-02 Thread Suraj Jitindar Singh
The hcall H_COPY_TOFROM_GUEST of used by a guest acting as a nested
hypervisor to access quadrants since quadrant access is hypervisor
privileged.

Translate the guest address to be accessed, map the memory and perform
the access on behalf of the guest. If the parameters are invalid, the
address can't be translated or the memory cannot be mapped then fail
the access.

Signed-off-by: Suraj Jitindar Singh 
---
 hw/ppc/spapr_hcall.c | 74 
 include/hw/ppc/spapr.h   |  3 +-
 target/ppc/mmu-radix64.c |  7 ++---
 target/ppc/mmu-radix64.h |  4 +++
 4 files changed, 83 insertions(+), 5 deletions(-)

diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index a84d5e2163..a370d70500 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -17,6 +17,7 @@
 #include "mmu-book3s-v3.h"
 #include "hw/mem/memory-device.h"
 #include "hw/ppc/ppc.h"
+#include "mmu-radix64.h"
 
 static bool has_spr(PowerPCCPU *cpu, int spr)
 {
@@ -2158,6 +2159,78 @@ static target_ulong h_nested_tlb_invalidate(PowerPCCPU 
*cpu,
 return H_SUCCESS;
 }
 
+static target_ulong h_copy_tofrom_guest(PowerPCCPU *cpu,
+SpaprMachineState *spapr,
+target_ulong opcode, target_ulong 
*args)
+{
+target_ulong lpid = args[0];
+target_ulong pid = args[1];
+vaddr eaddr = args[2];
+target_ulong gp_to = args[3];
+target_ulong gp_from = args[4];
+target_ulong n = args[5];
+int is_load = !!gp_to;
+void *from, *to;
+int prot, psize;
+hwaddr raddr, to_len, from_len;
+
+if (spapr_get_cap(spapr, SPAPR_CAP_NESTED_KVM_HV) == 0) {
+return H_FUNCTION;
+}
+
+if ((gp_to && gp_from) || (!gp_to && !gp_from)) {
+return H_PARAMETER;
+}
+
+if (eaddr & (0xFFFUL << 52)) {
+return H_PARAMETER;
+}
+
+if (!lpid) {
+return H_PARAMETER;
+}
+
+/* Translate eaddr to raddr */
+if (ppc_radix64_xlate(cpu, eaddr, is_load, lpid, pid, 1, &raddr, &psize,
+  &prot, 0)) {
+return H_NOT_FOUND;
+}
+if (((raddr & ((1UL << psize) - 1)) + n) >= (1UL << psize)) {
+return H_PARAMETER;
+}
+
+if (is_load) {
+gp_from = raddr;
+} else {
+gp_to = raddr;
+}
+
+/* Map the memory regions and perform a memory copy */
+from = cpu_physical_memory_map(gp_from, &from_len, 0);
+if (!from) {
+return H_NOT_FOUND;
+}
+if (from_len < n) {
+cpu_physical_memory_unmap(from, from_len, 0, 0);
+return H_PARAMETER;
+}
+to = cpu_physical_memory_map(gp_to, &to_len, 1);
+if (!to) {
+cpu_physical_memory_unmap(from, from_len, 0, 0);
+return H_PARAMETER;
+}
+if (to_len < n) {
+cpu_physical_memory_unmap(from, from_len, 0, 0);
+cpu_physical_memory_unmap(to, to_len, 1, 0);
+return H_PARAMETER;
+}
+memcpy(to, from, n);
+cpu_physical_memory_unmap(from, from_len, 0, n);
+cpu_physical_memory_unmap(to, to_len, 1, n);
+
+return H_SUCCESS;
+}
+
 static spapr_hcall_fn papr_hypercall_table[(MAX_HCALL_OPCODE / 4) + 1];
 static spapr_hcall_fn kvmppc_hypercall_table[KVMPPC_HCALL_MAX - 
KVMPPC_HCALL_BASE + 1];
 
@@ -2268,6 +2341,7 @@ static void hypercall_register_types(void)
 spapr_register_hypercall(H_SET_PARTITION_TABLE, h_set_partition_table);
 spapr_register_hypercall(H_ENTER_NESTED, h_enter_nested);
 spapr_register_hypercall(H_TLB_INVALIDATE, h_nested_tlb_invalidate);
+spapr_register_hypercall(H_COPY_TOFROM_GUEST, h_copy_tofrom_guest);
 
 /* Virtual Processor Home Node */
 spapr_register_hypercall(H_HOME_NODE_ASSOCIATIVITY,
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 6a614c445f..d62f4108d4 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -505,7 +505,8 @@ struct SpaprMachineState {
 #define H_SET_PARTITION_TABLE   0xF800
 #define H_ENTER_NESTED  0xF804
 #define H_TLB_INVALIDATE0xF808
-#define KVMPPC_HCALL_MAXH_TLB_INVALIDATE
+#define H_COPY_TOFROM_GUEST 0xF80C
+#define KVMPPC_HCALL_MAXH_COPY_TOFROM_GUEST
 
 typedef struct SpaprDeviceTreeUpdateHeader {
 uint32_t version_id;
diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c
index 6118ad1b00..2a8147fc38 100644
--- a/target/ppc/mmu-radix64.c
+++ b/target/ppc/mmu-radix64.c
@@ -429,10 +429,9 @@ static bool validate_pate(PowerPCCPU *cpu, uint64_t lpid, 
ppc_v3_pate_t *pate)
 return true;
 }
 
-static int ppc_radix64_xlate(PowerPCCPU *cpu, vaddr eaddr, int rwx,
- uint64_t lpid, uint64_t pid, bool relocation,
- hwaddr *raddr, int *psizep, int *protp,
- bool cause_excp)
+int ppc_radix64_xlate(PowerPCCPU *cpu, vaddr eaddr, int rwx, uint64_t lpid,
+  uint64_t pid, bool relocation, hwaddr *raddr, int 
*psizep,
+  

[Qemu-devel] [QEMU-PPC] [PATCH 05/13] target/ppc: Add privileged message send facilities

2019-05-02 Thread Suraj Jitindar Singh
Privileged message send facilities exist on POWER8 processors and later
and include a register and instructions which can be used to generate,
observe/modify the state of and clear privileged doorbell exceptions as
described below.

The Directed Privileged Doorbell Exception State (DPDES) register
reflects the state of pending privileged doorbell exceptions and can
also be used to modify that state. The register can be used to read and
modify the state of privileged doorbell exceptions for all threads of a
subprocessor and thus is a shared facility for that subprocessor. The
register can be read/written by the hypervisor and read by the
supervisor if enabled in the HFSCR, otherwise a hypervisor facility
unavailable exception is generated.

The privileged message send and clear instructions (msgsndp & msgclrp)
are used to generate and clear the presence of a directed privileged
doorbell exception, respectively. The msgsndp instruction can be used to
target any thread of the current subprocessor, msgclrp acts on the
thread issuing the instruction. These instructions are privileged, but
will generate a hypervisor facility unavailable exception if not enabled
in the HFSCR and executed in privileged non-hypervisor state.

Add and implement this register and instructions by reading or modifying the
pending interrupt state of the cpu.

Note that TCG only supports one thread per core and so we only need to
worry about the cpu making the access.

Signed-off-by: Suraj Jitindar Singh 
---
 target/ppc/cpu.h|  7 +
 target/ppc/excp_helper.c| 63 +
 target/ppc/helper.h |  5 
 target/ppc/misc_helper.c| 46 ++
 target/ppc/translate.c  | 28 ++
 target/ppc/translate_init.inc.c | 40 ++
 6 files changed, 184 insertions(+), 5 deletions(-)

diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
index e324064111..1d2a088391 100644
--- a/target/ppc/cpu.h
+++ b/target/ppc/cpu.h
@@ -425,6 +425,10 @@ typedef struct ppc_v3_pate_t {
 #define PSSCR_ESL PPC_BIT(42) /* Enable State Loss */
 #define PSSCR_EC  PPC_BIT(43) /* Exit Criterion */
 
+/* HFSCR bits */
+#define HFSCR_MSGSNDP PPC_BIT(53) /* Privileged Message Send Facilities */
+#define HFSCR_IC_MSGSNDP  0xA
+
 #define msr_sf   ((env->msr >> MSR_SF)   & 1)
 #define msr_isf  ((env->msr >> MSR_ISF)  & 1)
 #define msr_shv  ((env->msr >> MSR_SHV)  & 1)
@@ -1355,6 +1359,8 @@ void cpu_ppc_set_vhyp(PowerPCCPU *cpu, 
PPCVirtualHypervisor *vhyp);
 #endif
 
 void store_fpscr(CPUPPCState *env, uint64_t arg, uint32_t mask);
+void gen_hfscr_facility_check(DisasContext *ctx, int facility_sprn, int bit,
+  int sprn, int cause);
 
 static inline uint64_t ppc_dump_gpr(CPUPPCState *env, int gprn)
 {
@@ -1501,6 +1507,7 @@ void ppc_compat_add_property(Object *obj, const char 
*name,
 #define SPR_MPC_ICTRL (0x09E)
 #define SPR_MPC_BAR   (0x09F)
 #define SPR_PSPB  (0x09F)
+#define SPR_DPDES (0x0B0)
 #define SPR_DAWR  (0x0B4)
 #define SPR_RPR   (0x0BA)
 #define SPR_CIABR (0x0BB)
diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c
index beafcf1ebd..7a4da7bdba 100644
--- a/target/ppc/excp_helper.c
+++ b/target/ppc/excp_helper.c
@@ -461,6 +461,13 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int 
excp_model, int excp)
 env->spr[SPR_FSCR] |= ((target_ulong)env->error_code << 56);
 #endif
 break;
+case POWERPC_EXCP_HV_FU: /* Hypervisor Facility Unavailable Exception 
*/
+env->spr[SPR_HFSCR] |= ((target_ulong)env->error_code << FSCR_IC_POS);
+srr0 = SPR_HSRR0;
+srr1 = SPR_HSRR1;
+new_msr |= (target_ulong)MSR_HVB;
+new_msr |= env->msr & ((target_ulong)1 << MSR_RI);
+break;
 case POWERPC_EXCP_PIT:   /* Programmable interval timer interrupt*/
 LOG_EXCP("PIT exception\n");
 break;
@@ -884,7 +891,11 @@ static void ppc_hw_interrupt(CPUPPCState *env)
 }
 if (env->pending_interrupts & (1 << PPC_INTERRUPT_DOORBELL)) {
 env->pending_interrupts &= ~(1 << PPC_INTERRUPT_DOORBELL);
-powerpc_excp(cpu, env->excp_model, POWERPC_EXCP_DOORI);
+if (env->insns_flags & PPC_SEGMENT_64B) {
+powerpc_excp(cpu, env->excp_model, POWERPC_EXCP_SDOOR);
+} else {
+powerpc_excp(cpu, env->excp_model, POWERPC_EXCP_DOORI);
+}
 return;
 }
 if (env->pending_interrupts & (1 << PPC_INTERRUPT_HDOORBELL)) {
@@ -1202,19 +1213,26 @@ void helper_msgsnd(target_ulong rb)
 }
 
 /* Server Processor Control */
-static int book3s_dbell2irq(target_ulong rb)
+static int book3s_dbell2irq(target_ulong rb, bool hv_dbell)
 {
 int msg = rb & DBELL_TYPE_MASK;
 
 /* A Directed Hypervisor Doorbell message is sent only if the
  * 

[Qemu-devel] [QEMU-PPC] [PATCH 12/13] target/ppc: Introduce POWER9 DD2.2 cpu type

2019-05-02 Thread Suraj Jitindar Singh
Introduce a POWER9 DD2.2 cpu type with pvr 0x004E1202.

A DD2.2 POWER9 cpu type is needed to enable kvm for pseries tcg guests
since it means they will use the H_ENTER_NESTED hcall to run a guest
rather than trying the generic entry path which will fail.

Signed-off-by: Suraj Jitindar Singh 
---
 hw/ppc/spapr_cpu_core.c | 1 +
 target/ppc/cpu-models.c | 2 ++
 target/ppc/cpu-models.h | 1 +
 3 files changed, 4 insertions(+)

diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index 40e7010cf0..98d46c6edb 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -399,6 +399,7 @@ static const TypeInfo spapr_cpu_core_type_infos[] = {
 DEFINE_SPAPR_CPU_CORE_TYPE("power8nvl_v1.0"),
 DEFINE_SPAPR_CPU_CORE_TYPE("power9_v1.0"),
 DEFINE_SPAPR_CPU_CORE_TYPE("power9_v2.0"),
+DEFINE_SPAPR_CPU_CORE_TYPE("power9_v2.2"),
 #ifdef CONFIG_KVM
 DEFINE_SPAPR_CPU_CORE_TYPE("host"),
 #endif
diff --git a/target/ppc/cpu-models.c b/target/ppc/cpu-models.c
index 7c75963e3c..603ae7f5b4 100644
--- a/target/ppc/cpu-models.c
+++ b/target/ppc/cpu-models.c
@@ -773,6 +773,8 @@
 "POWER9 v1.0")
 POWERPC_DEF("power9_v2.0",   CPU_POWERPC_POWER9_DD20,POWER9,
 "POWER9 v2.0")
+POWERPC_DEF("power9_v2.2",   CPU_POWERPC_POWER9_DD22,POWER9,
+"POWER9 v2.2")
 #endif /* defined (TARGET_PPC64) */
 
 /***/
diff --git a/target/ppc/cpu-models.h b/target/ppc/cpu-models.h
index efdb2fa53c..820e94b0c8 100644
--- a/target/ppc/cpu-models.h
+++ b/target/ppc/cpu-models.h
@@ -373,6 +373,7 @@ enum {
 CPU_POWERPC_POWER9_BASE= 0x004E,
 CPU_POWERPC_POWER9_DD1 = 0x004E0100,
 CPU_POWERPC_POWER9_DD20= 0x004E1200,
+CPU_POWERPC_POWER9_DD22= 0x004E1202,
 CPU_POWERPC_970_v22= 0x00390202,
 CPU_POWERPC_970FX_v10  = 0x00391100,
 CPU_POWERPC_970FX_v20  = 0x003C0200,
-- 
2.13.6




[Qemu-devel] [QEMU-PPC] [PATCH 04/13] target/ppc: Add SPR TBU40

2019-05-02 Thread Suraj Jitindar Singh
The spr TBU40 is used to set the upper 40 bits of the timebase
register, present on POWER5+ and later processors.

This register can only be written by the hypervisor, and cannot be read.

Signed-off-by: Suraj Jitindar Singh 
---
 hw/ppc/ppc.c| 13 +
 target/ppc/cpu.h|  1 +
 target/ppc/helper.h |  1 +
 target/ppc/timebase_helper.c|  5 +
 target/ppc/translate_init.inc.c | 19 +++
 5 files changed, 39 insertions(+)

diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
index b567156f97..b618c6f615 100644
--- a/hw/ppc/ppc.c
+++ b/hw/ppc/ppc.c
@@ -710,6 +710,19 @@ void cpu_ppc_store_vtb(CPUPPCState *env, uint64_t value)
  &tb_env->vtb_offset, value);
 }
 
+void cpu_ppc_store_tbu40(CPUPPCState *env, uint64_t value)
+{
+ppc_tb_t *tb_env = env->tb_env;
+uint64_t tb;
+
+tb = cpu_ppc_get_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
+tb_env->tb_offset);
+tb &= 0xFFUL;
+tb |= (value & ~0xFFUL);
+cpu_ppc_store_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
+ &tb_env->tb_offset, tb);
+}
+
 static void cpu_ppc_tb_stop (CPUPPCState *env)
 {
 ppc_tb_t *tb_env = env->tb_env;
diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
index 8d66265e5a..e324064111 100644
--- a/target/ppc/cpu.h
+++ b/target/ppc/cpu.h
@@ -1334,6 +1334,7 @@ target_ulong cpu_ppc_load_decr (CPUPPCState *env);
 void cpu_ppc_store_decr (CPUPPCState *env, target_ulong value);
 target_ulong cpu_ppc_load_hdecr (CPUPPCState *env);
 void cpu_ppc_store_hdecr (CPUPPCState *env, target_ulong value);
+void cpu_ppc_store_tbu40(CPUPPCState *env, uint64_t value);
 uint64_t cpu_ppc_load_purr (CPUPPCState *env);
 void cpu_ppc_store_purr(CPUPPCState *env, uint64_t value);
 uint32_t cpu_ppc601_load_rtcl (CPUPPCState *env);
diff --git a/target/ppc/helper.h b/target/ppc/helper.h
index 336e7802fb..6aee195528 100644
--- a/target/ppc/helper.h
+++ b/target/ppc/helper.h
@@ -703,6 +703,7 @@ DEF_HELPER_FLAGS_2(store_decr, TCG_CALL_NO_RWG, void, env, 
tl)
 DEF_HELPER_FLAGS_1(load_hdecr, TCG_CALL_NO_RWG, tl, env)
 DEF_HELPER_FLAGS_2(store_hdecr, TCG_CALL_NO_RWG, void, env, tl)
 DEF_HELPER_FLAGS_2(store_vtb, TCG_CALL_NO_RWG, void, env, tl)
+DEF_HELPER_FLAGS_2(store_tbu40, TCG_CALL_NO_RWG, void, env, tl)
 DEF_HELPER_2(store_hid0_601, void, env, tl)
 DEF_HELPER_3(store_403_pbr, void, env, i32, tl)
 DEF_HELPER_FLAGS_1(load_40x_pit, TCG_CALL_NO_RWG, tl, env)
diff --git a/target/ppc/timebase_helper.c b/target/ppc/timebase_helper.c
index 2395295b77..703bd9ed18 100644
--- a/target/ppc/timebase_helper.c
+++ b/target/ppc/timebase_helper.c
@@ -128,6 +128,11 @@ void helper_store_vtb(CPUPPCState *env, target_ulong val)
 cpu_ppc_store_vtb(env, val);
 }
 
+void helper_store_tbu40(CPUPPCState *env, target_ulong val)
+{
+cpu_ppc_store_tbu40(env, val);
+}
+
 target_ulong helper_load_40x_pit(CPUPPCState *env)
 {
 return load_40x_pit(env);
diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.inc.c
index a0cae58e19..8e287066e5 100644
--- a/target/ppc/translate_init.inc.c
+++ b/target/ppc/translate_init.inc.c
@@ -325,6 +325,11 @@ static void spr_write_vtb(DisasContext *ctx, int sprn, int 
gprn)
 gen_helper_store_vtb(cpu_env, cpu_gpr[gprn]);
 }
 
+static void spr_write_tbu40(DisasContext *ctx, int sprn, int gprn)
+{
+gen_helper_store_tbu40(cpu_env, cpu_gpr[gprn]);
+}
+
 #endif
 #endif
 
@@ -7812,6 +7817,16 @@ static void gen_spr_power5p_ear(CPUPPCState *env)
  0x);
 }
 
+static void gen_spr_power5p_tb(CPUPPCState *env)
+{
+/* TBU40 (High 40 bits of the Timebase register */
+spr_register_hv(env, SPR_TBU40, "TBU40",
+SPR_NOACCESS, SPR_NOACCESS,
+SPR_NOACCESS, SPR_NOACCESS,
+SPR_NOACCESS, &spr_write_tbu40,
+0x);
+}
+
 #if !defined(CONFIG_USER_ONLY)
 static void spr_write_hmer(DisasContext *ctx, int sprn, int gprn)
 {
@@ -8352,6 +8367,7 @@ static void init_proc_power5plus(CPUPPCState *env)
 gen_spr_power5p_common(env);
 gen_spr_power5p_lpar(env);
 gen_spr_power5p_ear(env);
+gen_spr_power5p_tb(env);
 
 /* env variables */
 env->dcache_line_size = 128;
@@ -8464,6 +8480,7 @@ static void init_proc_POWER7(CPUPPCState *env)
 gen_spr_power5p_common(env);
 gen_spr_power5p_lpar(env);
 gen_spr_power5p_ear(env);
+gen_spr_power5p_tb(env);
 gen_spr_power6_common(env);
 gen_spr_power6_dbg(env);
 gen_spr_power7_book4(env);
@@ -8605,6 +8622,7 @@ static void init_proc_POWER8(CPUPPCState *env)
 gen_spr_power5p_common(env);
 gen_spr_power5p_lpar(env);
 gen_spr_power5p_ear(env);
+gen_spr_power5p_tb(env);
 gen_spr_power6_common(env);
 gen_spr_power6_dbg(env);
 gen_spr_power8_tce_address_control(env);
@@ -8793,6 +8811,7 @@ static void init_proc_POWER9(CPUPPCState *env)
 gen_spr_power5p_common(env);
 gen_spr_power5p_l

[Qemu-devel] [QEMU-PPC] [PATCH 02/13] target/ppc: Work [S]PURR implementation and add HV support

2019-05-02 Thread Suraj Jitindar Singh
The Processor Utilisation of Resources Register (PURR) and Scaled
Processor Utilisation of Resources Register (SPURR) provide an estimate
of the resources used by the thread, present on POWER7 and later
processors.

Currently the [S]PURR registers simply count at the rate of the
timebase.

Preserve this behaviour but rework the implementation to store an offset
like the timebase rather than doing the calculation manually. Also allow
hypervisor write access to the register along with the currently
available read access.

Signed-off-by: Suraj Jitindar Singh 
---
 hw/ppc/ppc.c| 17 +++--
 include/hw/ppc/ppc.h|  3 +--
 target/ppc/cpu.h|  1 +
 target/ppc/helper.h |  1 +
 target/ppc/timebase_helper.c|  5 +
 target/ppc/translate_init.inc.c | 23 +++
 6 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
index a57ca64626..b567156f97 100644
--- a/hw/ppc/ppc.c
+++ b/hw/ppc/ppc.c
@@ -819,12 +819,9 @@ target_ulong cpu_ppc_load_hdecr (CPUPPCState *env)
 uint64_t cpu_ppc_load_purr (CPUPPCState *env)
 {
 ppc_tb_t *tb_env = env->tb_env;
-uint64_t diff;
 
-diff = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - tb_env->purr_start;
-
-return tb_env->purr_load +
-muldiv64(diff, tb_env->tb_freq, NANOSECONDS_PER_SECOND);
+return cpu_ppc_get_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
+  tb_env->purr_offset);
 }
 
 /* When decrementer expires,
@@ -980,12 +977,12 @@ static void cpu_ppc_hdecr_cb(void *opaque)
 cpu_ppc_hdecr_excp(cpu);
 }
 
-static void cpu_ppc_store_purr(PowerPCCPU *cpu, uint64_t value)
+void cpu_ppc_store_purr(CPUPPCState *env, uint64_t value)
 {
-ppc_tb_t *tb_env = cpu->env.tb_env;
+ppc_tb_t *tb_env = env->tb_env;
 
-tb_env->purr_load = value;
-tb_env->purr_start = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
+cpu_ppc_store_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
+ &tb_env->purr_offset, value);
 }
 
 static void cpu_ppc_set_tb_clk (void *opaque, uint32_t freq)
@@ -1002,7 +999,7 @@ static void cpu_ppc_set_tb_clk (void *opaque, uint32_t 
freq)
  */
 _cpu_ppc_store_decr(cpu, 0x, 0x, 32);
 _cpu_ppc_store_hdecr(cpu, 0x, 0x, 32);
-cpu_ppc_store_purr(cpu, 0xULL);
+cpu_ppc_store_purr(env, 0xULL);
 }
 
 static void timebase_save(PPCTimebase *tb)
diff --git a/include/hw/ppc/ppc.h b/include/hw/ppc/ppc.h
index 205150e6b4..b09ffbf300 100644
--- a/include/hw/ppc/ppc.h
+++ b/include/hw/ppc/ppc.h
@@ -32,8 +32,7 @@ struct ppc_tb_t {
 /* Hypervisor decrementer management */
 uint64_t hdecr_next;/* Tick for next hdecr interrupt  */
 QEMUTimer *hdecr_timer;
-uint64_t purr_load;
-uint64_t purr_start;
+int64_t purr_offset;
 void *opaque;
 uint32_t flags;
 };
diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
index 70167bae22..19b3e1de0e 100644
--- a/target/ppc/cpu.h
+++ b/target/ppc/cpu.h
@@ -1335,6 +1335,7 @@ void cpu_ppc_store_decr (CPUPPCState *env, target_ulong 
value);
 target_ulong cpu_ppc_load_hdecr (CPUPPCState *env);
 void cpu_ppc_store_hdecr (CPUPPCState *env, target_ulong value);
 uint64_t cpu_ppc_load_purr (CPUPPCState *env);
+void cpu_ppc_store_purr(CPUPPCState *env, uint64_t value);
 uint32_t cpu_ppc601_load_rtcl (CPUPPCState *env);
 uint32_t cpu_ppc601_load_rtcu (CPUPPCState *env);
 #if !defined(CONFIG_USER_ONLY)
diff --git a/target/ppc/helper.h b/target/ppc/helper.h
index 3701bcbf1b..336e7802fb 100644
--- a/target/ppc/helper.h
+++ b/target/ppc/helper.h
@@ -686,6 +686,7 @@ DEF_HELPER_FLAGS_1(load_601_rtcu, TCG_CALL_NO_RWG, tl, env)
 #if !defined(CONFIG_USER_ONLY)
 #if defined(TARGET_PPC64)
 DEF_HELPER_FLAGS_1(load_purr, TCG_CALL_NO_RWG, tl, env)
+DEF_HELPER_FLAGS_2(store_purr, TCG_CALL_NO_RWG, void, env, tl)
 DEF_HELPER_2(store_ptcr, void, env, tl)
 #endif
 DEF_HELPER_2(store_sdr1, void, env, tl)
diff --git a/target/ppc/timebase_helper.c b/target/ppc/timebase_helper.c
index 8c3c2fe67c..2395295b77 100644
--- a/target/ppc/timebase_helper.c
+++ b/target/ppc/timebase_helper.c
@@ -55,6 +55,11 @@ target_ulong helper_load_purr(CPUPPCState *env)
 {
 return (target_ulong)cpu_ppc_load_purr(env);
 }
+
+void helper_store_purr(CPUPPCState *env, target_ulong val)
+{
+cpu_ppc_store_purr(env, val);
+}
 #endif
 
 target_ulong helper_load_601_rtcl(CPUPPCState *env)
diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.inc.c
index e3f941800b..9cd33e79ef 100644
--- a/target/ppc/translate_init.inc.c
+++ b/target/ppc/translate_init.inc.c
@@ -285,6 +285,11 @@ static void spr_read_purr(DisasContext *ctx, int gprn, int 
sprn)
 gen_helper_load_purr(cpu_gpr[gprn], cpu_env);
 }
 
+static void spr_write_purr(DisasContext *ctx, int sprn, int gprn)
+{
+gen_helper_store_purr(cpu_env, cpu_gpr[gprn]);
+}
+
 /* HDECR */
 static void spr_read_hdecr(DisasContext *ctx, int gp

[Qemu-devel] [QEMU-PPC] [PATCH 07/13] target/ppc: Handle partition scoped radix tree translation

2019-05-02 Thread Suraj Jitindar Singh
Radix tree translation is a 2 step process:

Process Scoped Translation:
Effective Address (EA) -> Virtual Address (VA)

Paritition Scoped Translation:
Virtual Address (VA) -> Real Address (RA)

Performed based on:
  MSR[HV]
   ---
   | | HV = 0| HV = 1|
   ---
   | Relocation  |   Partition   |  No   |
   | = Off   |Scoped |  Translation  |
Relocation ---
   | Relocation  |  Partition &  |Process|
   | = On|Process Scoped |Scoped |
   ---

Currently only process scoped translation is handled.
Implement partitition scoped translation.

The process of using the radix trees to perform partition scoped
translation is identical to process scoped translation, however
hypervisor exceptions are generated, and thus we can reuse the radix
tree traversing code.

Signed-off-by: Suraj Jitindar Singh 
---
 target/ppc/cpu.h |   2 +
 target/ppc/excp_helper.c |   3 +-
 target/ppc/mmu-radix64.c | 407 +--
 3 files changed, 293 insertions(+), 119 deletions(-)

diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
index 1d2a088391..3acc248f40 100644
--- a/target/ppc/cpu.h
+++ b/target/ppc/cpu.h
@@ -501,6 +501,8 @@ typedef struct ppc_v3_pate_t {
 /* Unsupported Radix Tree Configuration */
 #define DSISR_R_BADCONFIG0x0008
 #define DSISR_ATOMIC_RC  0x0004
+/* Unable to translate address of (guest) pde or process/page table entry */
+#define DSISR_PRTABLE_FAULT  0x0002
 
 /* SRR1 error code fields */
 
diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c
index 7a4da7bdba..10091d4624 100644
--- a/target/ppc/excp_helper.c
+++ b/target/ppc/excp_helper.c
@@ -441,9 +441,10 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int 
excp_model, int excp)
 case POWERPC_EXCP_ISEG:  /* Instruction segment exception*/
 case POWERPC_EXCP_TRACE: /* Trace exception  */
 break;
+case POWERPC_EXCP_HISI:  /* Hypervisor instruction storage exception */
+msr |= env->error_code;
 case POWERPC_EXCP_HDECR: /* Hypervisor decrementer exception */
 case POWERPC_EXCP_HDSI:  /* Hypervisor data storage exception*/
-case POWERPC_EXCP_HISI:  /* Hypervisor instruction storage exception */
 case POWERPC_EXCP_HDSEG: /* Hypervisor data segment exception*/
 case POWERPC_EXCP_HISEG: /* Hypervisor instruction segment exception */
 case POWERPC_EXCP_SDOOR_HV:  /* Hypervisor Doorbell interrupt*/
diff --git a/target/ppc/mmu-radix64.c b/target/ppc/mmu-radix64.c
index afa5ba506a..6118ad1b00 100644
--- a/target/ppc/mmu-radix64.c
+++ b/target/ppc/mmu-radix64.c
@@ -112,9 +112,31 @@ static void ppc_radix64_raise_si(PowerPCCPU *cpu, int rwx, 
vaddr eaddr,
 }
 }
 
+static void ppc_radix64_raise_hsi(PowerPCCPU *cpu, int rwx, vaddr eaddr,
+  hwaddr g_raddr, uint32_t cause)
+{
+CPUState *cs = CPU(cpu);
+CPUPPCState *env = &cpu->env;
+
+if (rwx == 2) { /* H Instruction Storage Interrupt */
+cs->exception_index = POWERPC_EXCP_HISI;
+env->spr[SPR_ASDR] = g_raddr;
+env->error_code = cause;
+} else { /* H Data Storage Interrupt */
+cs->exception_index = POWERPC_EXCP_HDSI;
+if (rwx == 1) { /* Write -> Store */
+cause |= DSISR_ISSTORE;
+}
+env->spr[SPR_HDSISR] = cause;
+env->spr[SPR_HDAR] = eaddr;
+env->spr[SPR_ASDR] = g_raddr;
+env->error_code = 0;
+}
+}
 
 static bool ppc_radix64_check_prot(PowerPCCPU *cpu, int rwx, uint64_t pte,
-   int *fault_cause, int *prot)
+   int *fault_cause, int *prot,
+   bool partition_scoped)
 {
 CPUPPCState *env = &cpu->env;
 const int need_prot[] = { PAGE_READ, PAGE_WRITE, PAGE_EXEC };
@@ -130,11 +152,11 @@ static bool ppc_radix64_check_prot(PowerPCCPU *cpu, int 
rwx, uint64_t pte,
 }
 
 /* Determine permissions allowed by Encoded Access Authority */
-if ((pte & R_PTE_EAA_PRIV) && msr_pr) { /* Insufficient Privilege */
+if (!partition_scoped && (pte & R_PTE_EAA_PRIV) && msr_pr) {
 *prot = 0;
-} else if (msr_pr || (pte & R_PTE_EAA_PRIV)) {
+} else if (msr_pr || (pte & R_PTE_EAA_PRIV) || partition_scoped) {
 *prot = ppc_radix64_get_prot_eaa(pte);
-} else { /* !msr_pr && !(pte & R_PTE_EAA_PRIV) */
+} else { /* !msr_pr && !(pte & R_PTE_EAA_PRIV) && !partition_scoped */
 *prot = ppc_radix64_get_prot_eaa(pte);
 *prot &= ppc_radix64_get_prot_amr(cpu); /* Least combined 

[Qemu-devel] [QEMU-PPC] [PATCH 00/13] target/ppc: Implement KVM support under TCG

2019-05-02 Thread Suraj Jitindar Singh
This patch series adds the necessary parts so that a tcg guest is able to use
kvm facilities. That is a tcg guest can boot its own kvm guests.

The main requirements for this were a few registers and instructions as well as
some hcalls and the addition of partition scoped translation in the radix mmu
emulation.

This can be used to boot a kvm guest under a pseries tcg guest:
Use power9_v2.2 cpu and add -machine cap-nested-hv=on for the first guest.
Then inside that guest boot a kvm guest as normal.
This takes advantage of the new hcalls with qemu emulating them as a normal
hypervisor would on a real machine.

This can also be used to boot a kvm guest under a powernv tcg guest:
Use any power9 cpu type.
This takes advantage of the new hv register access added.
Note that for powernv there is no xive interrupt excalation for KVM which means
that while the guest will boot, it won't receive any interrupts.

Suraj Jitindar Singh (13):
  target/ppc: Implement the VTB for HV access
  target/ppc: Work [S]PURR implementation and add HV support
  target/ppc: Add SPR ASDR
  target/ppc: Add SPR TBU40
  target/ppc: Add privileged message send facilities
  target/ppc: Enforce that the root page directory size must be at least
5
  target/ppc: Handle partition scoped radix tree translation
  target/ppc: Implement hcall H_SET_PARTITION_TABLE
  target/ppc: Implement hcall H_ENTER_NESTED
  target/ppc: Implement hcall H_TLB_INVALIDATE
  target/ppc: Implement hcall H_COPY_TOFROM_GUEST
  target/ppc: Introduce POWER9 DD2.2 cpu type
  target/ppc: Enable SPAPR_CAP_NESTED_KVM_HV under tcg

 hw/ppc/ppc.c|  46 -
 hw/ppc/spapr_caps.c |  22 ++-
 hw/ppc/spapr_cpu_core.c |   1 +
 hw/ppc/spapr_hcall.c| 409 +++
 include/hw/ppc/ppc.h|   4 +-
 include/hw/ppc/spapr.h  |   7 +-
 linux-user/ppc/cpu_loop.c   |   5 +
 target/ppc/cpu-models.c |   2 +
 target/ppc/cpu-models.h |   1 +
 target/ppc/cpu.h|  70 +++
 target/ppc/excp_helper.c|  79 +++-
 target/ppc/helper.h |   9 +
 target/ppc/misc_helper.c|  46 +
 target/ppc/mmu-radix64.c| 412 
 target/ppc/mmu-radix64.h|   4 +
 target/ppc/timebase_helper.c|  20 ++
 target/ppc/translate.c  |  28 +++
 target/ppc/translate_init.inc.c | 107 +--
 18 files changed, 1115 insertions(+), 157 deletions(-)

-- 
2.13.6




Re: [Qemu-devel] [PATCH v2] hw/virtio/virtio-mmio: Convert DPRINTF to traces

2019-05-02 Thread LI, BO XUAN
Hi Yuval and Alex,

Thanks for the suggestions. I'll update and send a patch v3 soon.

Best regards,
Boxuan Li

On Wed, May 1, 2019 at 11:17 PM Alex Bennée  wrote:

>
> Yuval Shaia  writes:
>
> > On Wed, May 01, 2019 at 08:42:35PM +0800, LI, BO XUAN wrote:
> >>On Wed, May 1, 2019 at 4:58 PM Yuval Shaia <[1]
> yuval.sh...@oracle.com>
> >>wrote:
> >>
> >>  On Wed, May 01, 2019 at 04:10:39PM +0800, Boxuan Li wrote:
> >>  > Signed-off-by: Boxuan Li <[2]libox...@connect.hku.hk>
> >>  > ---
> >>  > v2: Instead of using conditional debugs, convert DPRINTF to
> traces
> >>  > ---
> >>  >  hw/virtio/trace-events  | 13 +
> >>  >  hw/virtio/virtio-mmio.c | 35 ---
> >>  >  2 files changed, 25 insertions(+), 23 deletions(-)
> >>  >
> >>  > diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events
> >>  > index 60c649c4bc..37c781b487 100644
> >>  > --- a/hw/virtio/trace-events
> >>  > +++ b/hw/virtio/trace-events
> >>  > @@ -46,3 +46,16 @@ virtio_balloon_handle_output(const char *name,
> >>  uint64_t gpa) "section name: %s g
> >>  >  virtio_balloon_get_config(uint32_t num_pages, uint32_t actual)
> >>  "num_pages: %d actual: %d"
> >>  >  virtio_balloon_set_config(uint32_t actual, uint32_t oldactual)
> >>  "actual: %d oldactual: %d"
> >>  >  virtio_balloon_to_target(uint64_t target, uint32_t num_pages)
> >>  "balloon target: 0x%"PRIx64" num_pages: %d"
> >>  > +
> >>  > +# virtio-mmio.c
> >>  > +virtio_mmio_read(int offset) "virtio_mmio_read offset 0x%x"
> >>  > +virtio_mmio_wrong_size_read(void) "wrong size access to
> >>  register!"
> >>  > +virtio_mmio_read_interrupt(void) "read of write-only register"
> >>  > +virtio_mmio_bad_read_offset(void) "bad register offset"
> >>  > +virtio_mmio_write_offset(int offset, uint64_t value)
> >>  "virtio_mmio_write offset 0x%x value 0x%" PRIx64
> >>  > +virtio_mmio_wrong_size_write(void) "wrong size access to
> >>  register!"
> >>  > +virtio_mmio_guest_page(uint64_t size, int shift) "guest page
> size
> >>  0x%" PRIx64 " shift %d"
> >>  > +virtio_mmio_queue_write(int value, int max_size) "mmio_queue
> >>  write %d max %d"
> >>  > +virtio_mmio_write_interrupt(void) "write to readonly register"
> >>  > +virtio_mmio_bad_write_offset(void) "bad register offset"
> >>  > +virtio_mmio_setting_irq(int level) "virtio_mmio setting IRQ %d"
> >>  > diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c
> >>  > index 5807aa87fe..4251df399d 100644
> >>  > --- a/hw/virtio/virtio-mmio.c
> >>  > +++ b/hw/virtio/virtio-mmio.c
> >>  > @@ -27,16 +27,7 @@
> >>  >  #include "sysemu/kvm.h"
> >>  >  #include "hw/virtio/virtio-bus.h"
> >>  >  #include "qemu/error-report.h"
> >>  > -
> >>  > -/* #define DEBUG_VIRTIO_MMIO */
> >>  > -
> >>  > -#ifdef DEBUG_VIRTIO_MMIO
> >>  > -
> >>  > -#define DPRINTF(fmt, ...) \
> >>  > -do { printf("virtio_mmio: " fmt , ## __VA_ARGS__); } while (0)
> >>  > -#else
> >>  > -#define DPRINTF(fmt, ...) do {} while (0)
> >>  > -#endif
> >>  > +#include "trace.h"
> >>  >
> >>  >  /* QOM macros */
> >>  >  /* virtio-mmio-bus */
> >>  > @@ -107,7 +98,7 @@ static uint64_t virtio_mmio_read(void *opaque,
> >>  hwaddr offset, unsigned size)
> >>  >  VirtIOMMIOProxy *proxy = (VirtIOMMIOProxy *)opaque;
> >>  >  VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
> >>  >
> >>  > -DPRINTF("virtio_mmio_read offset 0x%x\n", (int)offset);
> >>  > +trace_virtio_mmio_read((int)offset);
> >>  >
> >>  >  if (!vdev) {
> >>  >  /* If no backend is present, we treat most registers as
> >>  > @@ -144,7 +135,7 @@ static uint64_t virtio_mmio_read(void
> *opaque,
> >>  hwaddr offset, unsigned size)
> >>  >  }
> >>  >  }
> >>  >  if (size != 4) {
> >>  > -DPRINTF("wrong size access to register!\n");
> >>  > +trace_virtio_mmio_wrong_size_read();
> >>  Have you considered using qemu_error_report to report such errors?
> >>
> >>Thanks for the suggestion. I am a newcomer here so my question might
> be
> >>a bit dumb: I thought they are warnings instead of errors since
> return
> >>values are 0. Do you suggest using error_report function and changing
> >>return values from 0 to -1?
> >>Best regards,
> >>Boxuan Li
> >
> > I think that when driver store invalid data in device register it is an
> > error but the best is to check what other devices do.
>
> We could have:
>
> qemu_log_mask(LOG_GUEST_ERROR, "%s: wrong size access to
> register!\n". __func__);
>
> --
> Alex Bennée
>


[Qemu-devel] [QEMU-PPC] [PATCH 01/13] target/ppc: Implement the VTB for HV access

2019-05-02 Thread Suraj Jitindar Singh
The virtual timebase register (VTB) is a 64-bit register which
increments at the same rate as the timebase register, present on POWER8
and later processors.

The register is able to be read/written by the hypervisor and read by
the supervisor. All other accesses are illegal.

Currently the VTB is just an alias for the timebase (TB) register.

Implement the VTB so that is can be read/written independent of the TB.
Make use of the existing method for accessing timebase facilities where
by the compensation is stored and used to compute the value on reads/is
updated on writes.

Signed-off-by: Suraj Jitindar Singh 
---
 hw/ppc/ppc.c| 16 
 include/hw/ppc/ppc.h|  1 +
 linux-user/ppc/cpu_loop.c   |  5 +
 target/ppc/cpu.h|  2 ++
 target/ppc/helper.h |  2 ++
 target/ppc/timebase_helper.c| 10 ++
 target/ppc/translate_init.inc.c | 19 +++
 7 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
index b2ff99ec66..a57ca64626 100644
--- a/hw/ppc/ppc.c
+++ b/hw/ppc/ppc.c
@@ -694,6 +694,22 @@ void cpu_ppc_store_atbu (CPUPPCState *env, uint32_t value)
  &tb_env->atb_offset, ((uint64_t)value << 32) | tb);
 }
 
+uint64_t cpu_ppc_load_vtb(CPUPPCState *env)
+{
+ppc_tb_t *tb_env = env->tb_env;
+
+return cpu_ppc_get_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
+  tb_env->vtb_offset);
+}
+
+void cpu_ppc_store_vtb(CPUPPCState *env, uint64_t value)
+{
+ppc_tb_t *tb_env = env->tb_env;
+
+cpu_ppc_store_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
+ &tb_env->vtb_offset, value);
+}
+
 static void cpu_ppc_tb_stop (CPUPPCState *env)
 {
 ppc_tb_t *tb_env = env->tb_env;
diff --git a/include/hw/ppc/ppc.h b/include/hw/ppc/ppc.h
index 4bdcb8bacd..205150e6b4 100644
--- a/include/hw/ppc/ppc.h
+++ b/include/hw/ppc/ppc.h
@@ -23,6 +23,7 @@ struct ppc_tb_t {
 /* Time base management */
 int64_t  tb_offset;/* Compensation*/
 int64_t  atb_offset;   /* Compensation*/
+int64_t  vtb_offset;
 uint32_t tb_freq;  /* TB frequency*/
 /* Decrementer management */
 uint64_t decr_next;/* Tick for next decr interrupt*/
diff --git a/linux-user/ppc/cpu_loop.c b/linux-user/ppc/cpu_loop.c
index 801f5ace29..c715861804 100644
--- a/linux-user/ppc/cpu_loop.c
+++ b/linux-user/ppc/cpu_loop.c
@@ -46,6 +46,11 @@ uint32_t cpu_ppc_load_atbu(CPUPPCState *env)
 return cpu_ppc_get_tb(env) >> 32;
 }
 
+uint64_t cpu_ppc_load_vtb(CPUPPCState *env)
+{
+return cpu_ppc_get_tb(env);
+}
+
 uint32_t cpu_ppc601_load_rtcu(CPUPPCState *env)
 __attribute__ (( alias ("cpu_ppc_load_tbu") ));
 
diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
index fe93cf0555..70167bae22 100644
--- a/target/ppc/cpu.h
+++ b/target/ppc/cpu.h
@@ -1327,6 +1327,8 @@ uint64_t cpu_ppc_load_atbl (CPUPPCState *env);
 uint32_t cpu_ppc_load_atbu (CPUPPCState *env);
 void cpu_ppc_store_atbl (CPUPPCState *env, uint32_t value);
 void cpu_ppc_store_atbu (CPUPPCState *env, uint32_t value);
+uint64_t cpu_ppc_load_vtb(CPUPPCState *env);
+void cpu_ppc_store_vtb(CPUPPCState *env, uint64_t value);
 bool ppc_decr_clear_on_delivery(CPUPPCState *env);
 target_ulong cpu_ppc_load_decr (CPUPPCState *env);
 void cpu_ppc_store_decr (CPUPPCState *env, target_ulong value);
diff --git a/target/ppc/helper.h b/target/ppc/helper.h
index 69cbf7922f..3701bcbf1b 100644
--- a/target/ppc/helper.h
+++ b/target/ppc/helper.h
@@ -680,6 +680,7 @@ DEF_HELPER_FLAGS_1(load_tbl, TCG_CALL_NO_RWG, tl, env)
 DEF_HELPER_FLAGS_1(load_tbu, TCG_CALL_NO_RWG, tl, env)
 DEF_HELPER_FLAGS_1(load_atbl, TCG_CALL_NO_RWG, tl, env)
 DEF_HELPER_FLAGS_1(load_atbu, TCG_CALL_NO_RWG, tl, env)
+DEF_HELPER_FLAGS_1(load_vtb, TCG_CALL_NO_RWG, tl, env)
 DEF_HELPER_FLAGS_1(load_601_rtcl, TCG_CALL_NO_RWG, tl, env)
 DEF_HELPER_FLAGS_1(load_601_rtcu, TCG_CALL_NO_RWG, tl, env)
 #if !defined(CONFIG_USER_ONLY)
@@ -700,6 +701,7 @@ DEF_HELPER_FLAGS_1(load_decr, TCG_CALL_NO_RWG, tl, env)
 DEF_HELPER_FLAGS_2(store_decr, TCG_CALL_NO_RWG, void, env, tl)
 DEF_HELPER_FLAGS_1(load_hdecr, TCG_CALL_NO_RWG, tl, env)
 DEF_HELPER_FLAGS_2(store_hdecr, TCG_CALL_NO_RWG, void, env, tl)
+DEF_HELPER_FLAGS_2(store_vtb, TCG_CALL_NO_RWG, void, env, tl)
 DEF_HELPER_2(store_hid0_601, void, env, tl)
 DEF_HELPER_3(store_403_pbr, void, env, i32, tl)
 DEF_HELPER_FLAGS_1(load_40x_pit, TCG_CALL_NO_RWG, tl, env)
diff --git a/target/ppc/timebase_helper.c b/target/ppc/timebase_helper.c
index 73363e08ae..8c3c2fe67c 100644
--- a/target/ppc/timebase_helper.c
+++ b/target/ppc/timebase_helper.c
@@ -45,6 +45,11 @@ target_ulong helper_load_atbu(CPUPPCState *env)
 return cpu_ppc_load_atbu(env);
 }
 
+target_ulong helper_load_vtb(CPUPPCState *env)
+{
+return cpu_ppc_load_vtb(env);
+}
+
 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
 target_ulong helper_load_purr(CPUPPCSt

[Qemu-devel] [QEMU-PPC] [PATCH 03/13] target/ppc: Add SPR ASDR

2019-05-02 Thread Suraj Jitindar Singh
The Access Segment Descriptor Register (ASDR) provides information about
the storage element when taking a hypervisor storage interrupt. When
performing nested radix address translation, this is normally the guest
real address. This register is present on POWER9 processors and later.

Implement the ADSR, note read and write access is limited to the
hypervisor.

Signed-off-by: Suraj Jitindar Singh 
---
 target/ppc/cpu.h| 1 +
 target/ppc/translate_init.inc.c | 6 ++
 2 files changed, 7 insertions(+)

diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h
index 19b3e1de0e..8d66265e5a 100644
--- a/target/ppc/cpu.h
+++ b/target/ppc/cpu.h
@@ -1797,6 +1797,7 @@ void ppc_compat_add_property(Object *obj, const char 
*name,
 #define SPR_MPC_MD_DBRAM1 (0x32A)
 #define SPR_RCPU_L2U_RA3  (0x32B)
 #define SPR_TAR   (0x32F)
+#define SPR_ASDR  (0x330)
 #define SPR_IC(0x350)
 #define SPR_VTB   (0x351)
 #define SPR_MMCRC (0x353)
diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.inc.c
index 9cd33e79ef..a0cae58e19 100644
--- a/target/ppc/translate_init.inc.c
+++ b/target/ppc/translate_init.inc.c
@@ -8243,6 +8243,12 @@ static void gen_spr_power9_mmu(CPUPPCState *env)
 SPR_NOACCESS, SPR_NOACCESS,
 &spr_read_generic, &spr_write_ptcr,
 KVM_REG_PPC_PTCR, 0x);
+/* Address Segment Descriptor Register */
+spr_register_hv(env, SPR_ASDR, "ASDR",
+SPR_NOACCESS, SPR_NOACCESS,
+SPR_NOACCESS, SPR_NOACCESS,
+&spr_read_generic, &spr_write_generic,
+0x);
 #endif
 }
 
-- 
2.13.6




Re: [Qemu-devel] [PATCH v3 4/4] osdep: Fix mingw compilation regarding stdio formats

2019-05-02 Thread Stefan Weil
On 03.05.19 07:11, Thomas Huth wrote:
> On 03/05/2019 02.37, Cao Jiaxi wrote:
>> I encountered the following compilation error on mingw:
>>
>> /mnt/d/qemu/include/qemu/osdep.h:97:9: error: '__USE_MINGW_ANSI_STDIO' macro 
>> redefined [-Werror,-Wmacro-redefined]
>>  #define __USE_MINGW_ANSI_STDIO 1
>> ^
>> /mnt/d/llvm-mingw/aarch64-w64-mingw32/include/_mingw.h:433:9: note: previous 
>> definition is here
>>  #define __USE_MINGW_ANSI_STDIO 0  /* was not defined so it should be 0 
>> */
>>
>> It turns out that __USE_MINGW_ANSI_STDIO must be set before any
>> system headers are included, not just before stdio.h.
>>
>> Signed-off-by: Cao Jiaxi 
>> ---
>>  include/qemu/osdep.h | 10 +-
>>  1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
>> index 303d315c5d..af2b91f0b8 100644
>> --- a/include/qemu/osdep.h
>> +++ b/include/qemu/osdep.h
>> @@ -85,17 +85,17 @@ extern int daemon(int, int);
>>  #endif
>>  #endif
>>  
>> +/* enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later) */
>> +#ifdef __MINGW32__
>> +#define __USE_MINGW_ANSI_STDIO 1
>> +#endif
>> +
>>  #include 
>>  #include 
>>  #include 
>>  #include 
>>  #include 
>>  #include 
>> -
>> -/* enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later) */
>> -#ifdef __MINGW32__
>> -#define __USE_MINGW_ANSI_STDIO 1
>> -#endif
>>  #include 
>>  
>>  #include 
>>
> 
> Reviewed-by: Thomas Huth 

Reviewed-by: Stefan Weil 



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v3 27/40] s390x/tcg: Implement VECTOR ELEMENT ROTATE AND INSERT UNDER MASK

2019-05-02 Thread Richard Henderson
On 5/2/19 7:10 AM, David Hildenbrand wrote:
> Use the new vector expansion for GVecGen3i.
> 
> Signed-off-by: David Hildenbrand 
> ---
>  target/s390x/helper.h   |  2 ++
>  target/s390x/insn-data.def  |  2 ++
>  target/s390x/translate_vx.inc.c | 51 +
>  target/s390x/vec_int_helper.c   | 20 +
>  4 files changed, 75 insertions(+)

Reviewed-by: Richard Henderson 

r~




Re: [Qemu-devel] [PATCH v3 12/40] s390x/tcg: Implement VECTOR COUNT TRAILING ZEROS

2019-05-02 Thread Richard Henderson
On 5/2/19 7:09 AM, David Hildenbrand wrote:
> Implement it similar to VECTOR COUNT LEADING ZEROS.
> 
> Signed-off-by: David Hildenbrand 
> ---
>  target/s390x/helper.h   |  2 ++
>  target/s390x/insn-data.def  |  2 ++
>  target/s390x/translate_vx.inc.c | 28 
>  target/s390x/vec_int_helper.c   | 14 ++
>  4 files changed, 46 insertions(+)

Reviewed-by: Richard Henderson 

r~




Re: [Qemu-devel] [PATCH v3 4/4] osdep: Fix mingw compilation regarding stdio formats

2019-05-02 Thread Thomas Huth
On 03/05/2019 02.37, Cao Jiaxi wrote:
> I encountered the following compilation error on mingw:
> 
> /mnt/d/qemu/include/qemu/osdep.h:97:9: error: '__USE_MINGW_ANSI_STDIO' macro 
> redefined [-Werror,-Wmacro-redefined]
>  #define __USE_MINGW_ANSI_STDIO 1
> ^
> /mnt/d/llvm-mingw/aarch64-w64-mingw32/include/_mingw.h:433:9: note: previous 
> definition is here
>  #define __USE_MINGW_ANSI_STDIO 0  /* was not defined so it should be 0 */
> 
> It turns out that __USE_MINGW_ANSI_STDIO must be set before any
> system headers are included, not just before stdio.h.
> 
> Signed-off-by: Cao Jiaxi 
> ---
>  include/qemu/osdep.h | 10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> index 303d315c5d..af2b91f0b8 100644
> --- a/include/qemu/osdep.h
> +++ b/include/qemu/osdep.h
> @@ -85,17 +85,17 @@ extern int daemon(int, int);
>  #endif
>  #endif
>  
> +/* enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later) */
> +#ifdef __MINGW32__
> +#define __USE_MINGW_ANSI_STDIO 1
> +#endif
> +
>  #include 
>  #include 
>  #include 
>  #include 
>  #include 
>  #include 
> -
> -/* enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later) */
> -#ifdef __MINGW32__
> -#define __USE_MINGW_ANSI_STDIO 1
> -#endif
>  #include 
>  
>  #include 
> 

Reviewed-by: Thomas Huth 



Re: [Qemu-devel] [PATCH v3 3/4] util/cacheinfo: Use uint64_t on LLP64 model to satisfy Windows ARM64

2019-05-02 Thread Thomas Huth
On 03/05/2019 02.37, Cao Jiaxi wrote:
> Windows ARM64 uses LLP64 model, which breaks current assumptions.
> 
> Signed-off-by: Cao Jiaxi 
> ---
>  util/cacheinfo.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/util/cacheinfo.c b/util/cacheinfo.c
> index 3cd080b83d..eebe1ce9c5 100644
> --- a/util/cacheinfo.c
> +++ b/util/cacheinfo.c
> @@ -107,7 +107,7 @@ static void sys_cache_info(int *isize, int *dsize)
>  static void arch_cache_info(int *isize, int *dsize)
>  {
>  if (*isize == 0 || *dsize == 0) {
> -unsigned long ctr;
> +uint64_t ctr;
>  
>  /* The real cache geometry is in CCSIDR_EL1/CLIDR_EL1/CSSELR_EL1,
> but (at least under Linux) these are marked protected by the
> 

Reviewed-by: Thomas Huth 



Re: [Qemu-devel] [PATCH v3 2/4] qga: Fix mingw compilation warnings on enum conversion

2019-05-02 Thread Thomas Huth
On 03/05/2019 02.36, Cao Jiaxi wrote:
> The win2qemu[] is supposed to be the conversion table to convert between
> STORAGE_BUS_TYPE in Windows SDK and GuestDiskBusType in qga.
> 
> But it was incorrectly written that it forces to set a GuestDiskBusType
> value to STORAGE_BUS_TYPE, which generates an enum conversion warning in 
> clang.
> 
> Signed-off-by: Cao Jiaxi 
> ---
>  qga/commands-win32.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> index d40d61f605..6b67f16faf 100644
> --- a/qga/commands-win32.c
> +++ b/qga/commands-win32.c
> @@ -457,7 +457,7 @@ void qmp_guest_file_flush(int64_t handle, Error **errp)
>  
>  #ifdef CONFIG_QGA_NTDDSCSI
>  
> -static STORAGE_BUS_TYPE win2qemu[] = {
> +static GuestDiskBusType win2qemu[] = {
>  [BusTypeUnknown] = GUEST_DISK_BUS_TYPE_UNKNOWN,
>  [BusTypeScsi] = GUEST_DISK_BUS_TYPE_SCSI,
>  [BusTypeAtapi] = GUEST_DISK_BUS_TYPE_IDE,

Reviewed-by: Thomas Huth 



Re: [Qemu-devel] [PATCH v3 1/4] QEMU_PACKED: Remove gcc_struct attribute in Windows non x86 targets

2019-05-02 Thread Thomas Huth
On 03/05/2019 02.36, Cao Jiaxi wrote:
> gcc_struct is for x86 only, and it generates an warning on ARM64 Clang/MinGW 
> targets.
> 
> Signed-off-by: Cao Jiaxi 
> ---
>  contrib/libvhost-user/libvhost-user.h | 2 +-
>  include/qemu/compiler.h   | 2 +-
>  scripts/cocci-macro-file.h| 7 ++-
>  slirp/src/util.h  | 2 +-
>  4 files changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/contrib/libvhost-user/libvhost-user.h 
> b/contrib/libvhost-user/libvhost-user.h
> index 414ceb0a2f..78b33306e8 100644
> --- a/contrib/libvhost-user/libvhost-user.h
> +++ b/contrib/libvhost-user/libvhost-user.h
> @@ -148,7 +148,7 @@ typedef struct VhostUserInflight {
>  uint16_t queue_size;
>  } VhostUserInflight;
>  
> -#if defined(_WIN32)
> +#if defined(_WIN32) && (defined(__x86_64__) || defined(__i386__))
>  # define VU_PACKED __attribute__((gcc_struct, packed))
>  #else
>  # define VU_PACKED __attribute__((packed))
> diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
> index 296b2fd572..09fc44cca4 100644
> --- a/include/qemu/compiler.h
> +++ b/include/qemu/compiler.h
> @@ -28,7 +28,7 @@
>  
>  #define QEMU_SENTINEL __attribute__((sentinel))
>  
> -#if defined(_WIN32)
> +#if defined(_WIN32) && (defined(__x86_64__) || defined(__i386__))
>  # define QEMU_PACKED __attribute__((gcc_struct, packed))
>  #else
>  # define QEMU_PACKED __attribute__((packed))
> diff --git a/scripts/cocci-macro-file.h b/scripts/cocci-macro-file.h
> index e485cdccae..c6bbc05ba3 100644
> --- a/scripts/cocci-macro-file.h
> +++ b/scripts/cocci-macro-file.h
> @@ -23,7 +23,12 @@
>  #define QEMU_NORETURN __attribute__ ((__noreturn__))
>  #define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
>  #define QEMU_SENTINEL __attribute__((sentinel))
> -#define QEMU_PACKED __attribute__((gcc_struct, packed))
> +
> +#if defined(_WIN32) && (defined(__x86_64__) || defined(__i386__))
> +# define QEMU_PACKED __attribute__((gcc_struct, packed))
> +#else
> +# define QEMU_PACKED __attribute__((packed))
> +#endif
>  
>  #define cat(x,y) x ## y
>  #define cat2(x,y) cat(x,y)
> diff --git a/slirp/src/util.h b/slirp/src/util.h
> index 01f1e0e068..278828fe3f 100644
> --- a/slirp/src/util.h
> +++ b/slirp/src/util.h
> @@ -43,7 +43,7 @@
>  #include 
>  #endif
>  
> -#if defined(_WIN32)
> +#if defined(_WIN32) && (defined(__x86_64__) || defined(__i386__))
>  # define SLIRP_PACKED __attribute__((gcc_struct, packed))
>  #else
>  # define SLIRP_PACKED __attribute__((packed))
> 

The slirp code is currently on its way into a separate module, so you
might need to provide that hunk to the libslirp folks again... I'm
putting the slirp maintainers on CC:, maybe they can pick it up from here.

Anyway:

Reviewed-by: Thomas Huth 



Re: [Qemu-devel] Failing QEMU iotest 221

2019-05-02 Thread Thomas Huth
On 03/05/2019 00.02, Eric Blake wrote:
> On 4/28/19 10:21 AM, Thomas Huth wrote:
>> QEMU iotest 221 is failing for me, too, when I run it with -raw:
> 
> Which filesystem?

ext4 again.

$ stat -f /home/thuth/tmp/qemu-build/tests/qemu-iotests/
  File: "/home/thuth/tmp/qemu-build/tests/qemu-iotests/"
ID: 1e68b4a412e09716 Namelen: 255 Type: ext2/ext3
Block size: 1024   Fundamental block size: 1024

Maybe the "check" script should report the output of "stat -f", too?

>> tests/qemu-iotests$ ./check -raw 221
>> QEMU  -- 
>> "/home/thuth/tmp/qemu-build/tests/qemu-iotests/../../x86_64-softmmu/qemu-system-x86_64"
>>  -nodefaults -machine accel=qtest
>> QEMU_IMG  -- 
>> "/home/thuth/tmp/qemu-build/tests/qemu-iotests/../../qemu-img" 
>> QEMU_IO   -- 
>> "/home/thuth/tmp/qemu-build/tests/qemu-iotests/../../qemu-io"  --cache 
>> writeback -f raw
>> QEMU_NBD  -- 
>> "/home/thuth/tmp/qemu-build/tests/qemu-iotests/../../qemu-nbd" 
>> IMGFMT-- raw
>> IMGPROTO  -- file
>> PLATFORM  -- Linux/x86_64 thuth 3.10.0-957.10.1.el7.x86_64
>> TEST_DIR  -- /home/thuth/tmp/qemu-build/tests/qemu-iotests/scratch
>> SOCKET_SCM_HELPER -- 
>> /home/thuth/tmp/qemu-build/tests/qemu-iotests/socket_scm_helper
>>
>> 221 - output mismatch (see 221.out.bad)
>> --- /home/thuth/devel/qemu/tests/qemu-iotests/221.out2019-04-23 
>> 16:43:12.0 +0200
>> +++ /home/thuth/tmp/qemu-build/tests/qemu-iotests/221.out.bad
>> 2019-04-28 17:18:52.0 +0200
>> @@ -7,10 +7,10 @@
>>  [{ "start": 0, "length": 43520, "depth": 0, "zero": true, "data": false, 
>> "offset": OFFSET}]
>>  wrote 1/1 bytes at offset 43008
>>  1 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
>> -[{ "start": 0, "length": 40960, "depth": 0, "zero": true, "data": false, 
>> "offset": OFFSET},
>> -{ "start": 40960, "length": 2049, "depth": 0, "zero": false, "data": true, 
>> "offset": OFFSET},
>> +[{ "start": 0, "length": 43008, "depth": 0, "zero": true, "data": false, 
>> "offset": OFFSET},
>> +{ "start": 43008, "length": 1, "depth": 0, "zero": false, "data": true, 
>> "offset": OFFSET},
> 
> Ugh. Hole granularities are file-system specific, so we need to figure
> out some way to fuzz the input. It might also be possible to pick nicer
> size numbers - perhaps if the test image is sized at 64k+1 instead of
> 43009 (84*512, but NOT evenly divisible by 4k), the +1 byte is more
> likely to be directly one a hole boundary, rather than being somewhere
> that causes rounding the hole boundary 2k earlier because of 4k or 64k
> sizing constraints.

Ok ... sounds like that's definitely something I'd like to leave to you
or one of the block guys to fix.

 Thomas



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] Failing QEMU iotest 175

2019-05-02 Thread Thomas Huth
On 02/05/2019 23.56, Eric Blake wrote:
> On 4/28/19 10:18 AM, Thomas Huth wrote:
>> QEMU iotest 175 is failing for me when I run it with -raw:
>>
> 
>>  == creating image with default preallocation ==
>>  Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576
>> -size=1048576, blocks=0
>> +size=1048576, blocks=2
> 
> What filesystem?

ext4

> It should be fairly obvious that 'stat -c blocks=%b' is
> file-system dependent (some allocate slightly more or less space, based
> on granularities and on predictions of future use), so we may need to
> update the test to apply a filter or otherwise allow a bit of fuzz in
> the answer. But 0/2 is definitely different than...
>>
>>  == creating image with preallocation off ==
>>  Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=off
>> -size=1048576, blocks=0
>> +size=1048576, blocks=2
>>
>>  == creating image with preallocation full ==
>>  Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=full
>> -size=1048576, blocks=2048
>> +size=1048576, blocks=2050
> 
> 2048/2050, so we DO have some indication of whether the file is sparse
> or fully allocated.

Maybe we could check that the value after "blocks=" is a single digit in
the first case, and matches "blocks=20.." in the second case?

 Thomas



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v3 04/40] s390x/tcg: Implement VECTOR ADD WITH CARRY COMPUTE CARRY

2019-05-02 Thread Richard Henderson
On 5/2/19 7:09 AM, David Hildenbrand wrote:
> Similar to VECTOR ADD COMPUTE CARRY, however 128-bit handling only.
> Courtesy of Richard H.
> 
> Signed-off-by: David Hildenbrand 
> ---
>  target/s390x/insn-data.def  |  2 ++
>  target/s390x/translate_vx.inc.c | 32 
>  2 files changed, 34 insertions(+)

Reviewed-by: Richard Henderson 

r~




Re: [Qemu-devel] [PATCH v3 02/40] s390x/tcg: Implement VECTOR ADD COMPUTE CARRY

2019-05-02 Thread Richard Henderson
On 5/2/19 7:09 AM, David Hildenbrand wrote:
> 128-bit handling courtesy of Richard H.
> 
> Signed-off-by: David Hildenbrand 
> ---
>  target/s390x/insn-data.def  |  2 +
>  target/s390x/translate_vx.inc.c | 94 +
>  2 files changed, 96 insertions(+)

Reviewed-by: Richard Henderson 

> +static void gen_acc(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b, uint8_t es)
> +{
> +const uint8_t msb_bit_nr = NUM_VEC_ELEMENT_BITS(es) - 1;
> +TCGv_i64 msb_mask = tcg_const_i64(dup_const(es, 1ull << msb_bit_nr));
> +TCGv_i64 t1 = tcg_temp_new_i64();
> +TCGv_i64 t2 = tcg_temp_new_i64();
> +TCGv_i64 t3 = tcg_temp_new_i64();
> +
> +/* Calculate the carry into the MSB, ignoring the old MSBs */
> +tcg_gen_andc_i64(t1, a, msb_mask);
> +tcg_gen_andc_i64(t2, b, msb_mask);
> +tcg_gen_add_i64(t1, t1, t2);
> +/* Calculate the MSB without any carry into it */
> +tcg_gen_xor_i64(t3, a, b);
> +/* Calculate the carry out of the MSB in the MSB bit position */
> +tcg_gen_and_i64(d, a, b);
> +tcg_gen_and_i64(t1, t1, t3);
> +tcg_gen_or_i64(d, d, t1);
> +/* Isolate and shift the carry into position */
> +tcg_gen_and_i64(d, d, msb_mask);
> +tcg_gen_shri_i64(d, d, msb_bit_nr);
> +
> +tcg_temp_free_i64(t1);
> +tcg_temp_free_i64(t2);
> +tcg_temp_free_i64(t3);
> +}
...> +static void gen_acc32_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
> +{
> +gen_acc(d, a, b, ES_32);
> +}
> +
> +static void gen_acc_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
> +{
> +TCGv_i64 t = tcg_temp_new_i64();
> +
> +tcg_gen_add_i64(t, a, b);
> +tcg_gen_setcond_i64(TCG_COND_LTU, d, t, b);
> +tcg_temp_free_i64(t);
> +}

As an aside, I think the 32-bit version should use 32-bit ops, as per
gen_acc_i64.  That would be 4 * 2 operations instead of 2 * 9 over the 128-bit
vector.


r~



Re: [Qemu-devel] [PATCH v3 2/4] qga: Fix mingw compilation warnings on enum conversion

2019-05-02 Thread Richard Henderson
On 5/2/19 5:36 PM, Cao Jiaxi wrote:
> The win2qemu[] is supposed to be the conversion table to convert between
> STORAGE_BUS_TYPE in Windows SDK and GuestDiskBusType in qga.
> 
> But it was incorrectly written that it forces to set a GuestDiskBusType
> value to STORAGE_BUS_TYPE, which generates an enum conversion warning in 
> clang.
> 
> Signed-off-by: Cao Jiaxi 
> ---
>  qga/commands-win32.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> index d40d61f605..6b67f16faf 100644
> --- a/qga/commands-win32.c
> +++ b/qga/commands-win32.c
> @@ -457,7 +457,7 @@ void qmp_guest_file_flush(int64_t handle, Error **errp)
>  
>  #ifdef CONFIG_QGA_NTDDSCSI
>  
> -static STORAGE_BUS_TYPE win2qemu[] = {
> +static GuestDiskBusType win2qemu[] = {
>  [BusTypeUnknown] = GUEST_DISK_BUS_TYPE_UNKNOWN,
>  [BusTypeScsi] = GUEST_DISK_BUS_TYPE_SCSI,
>  [BusTypeAtapi] = GUEST_DISK_BUS_TYPE_IDE,
> 


Reviewed-by: Richard Henderson 

r~




Re: [Qemu-devel] [PATCH v3 3/4] util/cacheinfo: Use uint64_t on LLP64 model to satisfy Windows ARM64

2019-05-02 Thread Richard Henderson
On 5/2/19 5:37 PM, Cao Jiaxi wrote:
> Windows ARM64 uses LLP64 model, which breaks current assumptions.
> 
> Signed-off-by: Cao Jiaxi 
> ---
>  util/cacheinfo.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/util/cacheinfo.c b/util/cacheinfo.c
> index 3cd080b83d..eebe1ce9c5 100644
> --- a/util/cacheinfo.c
> +++ b/util/cacheinfo.c
> @@ -107,7 +107,7 @@ static void sys_cache_info(int *isize, int *dsize)
>  static void arch_cache_info(int *isize, int *dsize)
>  {
>  if (*isize == 0 || *dsize == 0) {
> -unsigned long ctr;
> +uint64_t ctr;
>  
>  /* The real cache geometry is in CCSIDR_EL1/CLIDR_EL1/CSSELR_EL1,
> but (at least under Linux) these are marked protected by the
> 

Reviewed-by: Richard Henderson 

r~



[Qemu-devel] [PATCH v2] arm: aspeed: Set SDRAM size

2019-05-02 Thread Joel Stanley
We currently use Qemu's default of 128MB. As we know how much ram each
machine ships with, make it easier on users by setting a default.

It can still be overridden with -m on the command line.

Signed-off-by: Joel Stanley 
Reviewed-by: Andrew Jeffery 
Reviewed-by: Richard Henderson 
---
v2:
 - Fix 'if' style issue. Thanks patchew
 - Use units.h defines

 hw/arm/aspeed.c | 8 
 include/hw/arm/aspeed.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
index 1c23ebd99252..29d225ed1405 100644
--- a/hw/arm/aspeed.c
+++ b/hw/arm/aspeed.c
@@ -25,6 +25,7 @@
 #include "sysemu/block-backend.h"
 #include "hw/loader.h"
 #include "qemu/error-report.h"
+#include "qemu/units.h"
 
 static struct arm_boot_info aspeed_board_binfo = {
 .board_id = -1, /* device-tree-only board */
@@ -331,6 +332,9 @@ static void aspeed_machine_class_init(ObjectClass *oc, void 
*data)
 mc->no_floppy = 1;
 mc->no_cdrom = 1;
 mc->no_parallel = 1;
+if (board->ram) {
+mc->default_ram_size = board->ram;
+}
 amc->board = board;
 }
 
@@ -352,6 +356,7 @@ static const AspeedBoardConfig aspeed_boards[] = {
 .spi_model = "mx25l25635e",
 .num_cs= 1,
 .i2c_init  = palmetto_bmc_i2c_init,
+.ram   = 256 * MiB,
 }, {
 .name  = MACHINE_TYPE_NAME("ast2500-evb"),
 .desc  = "Aspeed AST2500 EVB (ARM1176)",
@@ -361,6 +366,7 @@ static const AspeedBoardConfig aspeed_boards[] = {
 .spi_model = "mx25l25635e",
 .num_cs= 1,
 .i2c_init  = ast2500_evb_i2c_init,
+.ram   = 512 * MiB,
 }, {
 .name  = MACHINE_TYPE_NAME("romulus-bmc"),
 .desc  = "OpenPOWER Romulus BMC (ARM1176)",
@@ -370,6 +376,7 @@ static const AspeedBoardConfig aspeed_boards[] = {
 .spi_model = "mx66l1g45g",
 .num_cs= 2,
 .i2c_init  = romulus_bmc_i2c_init,
+.ram   = 512 * MiB,
 }, {
 .name  = MACHINE_TYPE_NAME("witherspoon-bmc"),
 .desc  = "OpenPOWER Witherspoon BMC (ARM1176)",
@@ -379,6 +386,7 @@ static const AspeedBoardConfig aspeed_boards[] = {
 .spi_model = "mx66l1g45g",
 .num_cs= 2,
 .i2c_init  = witherspoon_bmc_i2c_init,
+.ram   = 512 * MiB,
 },
 };
 
diff --git a/include/hw/arm/aspeed.h b/include/hw/arm/aspeed.h
index 325c091d09e4..02073a6b4d61 100644
--- a/include/hw/arm/aspeed.h
+++ b/include/hw/arm/aspeed.h
@@ -22,6 +22,7 @@ typedef struct AspeedBoardConfig {
 const char *spi_model;
 uint32_t num_cs;
 void (*i2c_init)(AspeedBoardState *bmc);
+uint32_t ram;
 } AspeedBoardConfig;
 
 #define TYPE_ASPEED_MACHINE   MACHINE_TYPE_NAME("aspeed")
-- 
2.20.1




Re: [Qemu-devel] [PATCH] Revert "armv7m: Guard against no -kernel argument"

2019-05-02 Thread Joel Stanley
On Wed, 1 May 2019 at 16:23, Stefan Hajnoczi  wrote:
>
> On Mon, Apr 29, 2019 at 12:53:48PM +, Joel Stanley wrote:
> > On Fri, 26 Apr 2019 at 09:17, Stefan Hajnoczi  wrote:
> > >
> > > A user-friendly error message is needed here.  The check for -kernel was
> > > too specific and is not desirable for microbit where we use -device
> > > loader.
> > >
> > > Old boards probably want to continue using -kernel.  New boards like
> > > microbit may use just -device loader.  Perhaps there is even a group
> > > that wants both options.
> >
> > FWIW, I used -kernel exclusively when working on the microbit model.
> > Other users may chose to use the device loader/hex file.
> >
> > I am all for usability, but getting rid of the ability to use -kernel
> > on some machine types would be a step in the wrong direction.
>
> -kernel doesn't support the .hex file format that is most commonly used
> for micro:bit programs.  Are you loading ELFs?

Yes, I am loading ELFs.



Re: [Qemu-devel] [PATCH 2/9] cpu/topology: add general support for machine properties

2019-05-02 Thread Eduardo Habkost
On Thu, May 02, 2019 at 05:09:28PM +0200, Igor Mammedov wrote:
> On Tue, 30 Apr 2019 15:30:31 +0800
> Like Xu  wrote:
> 
> > On 2019/4/4 22:25, Igor Mammedov wrote:
> > > On Fri, 29 Mar 2019 16:48:38 +0800
> > > Like Xu  wrote:
> > > 
> 
> [...]
> 
> > 
> > The division of responsibility for this case (refactoring 
> > qemu_init_vcpu) seems to be a poisonous apple.
> > 
> > The prerequisite for setting cpu-> nr_cores / nr_threads from the parent 
> > is that the CPU has been created, so if any process during 
> > initialization needs this topo information, it will use the default 
> > values form cpu_common_initfn() instead of user-configured parameters.
> 
> can you point to concrete place that needs access to nr_cores / nr_threads
> before cpu is 'realized'?

We have very few architectures actually using
nr_cores/nr_threads/smp_cores/smp_threads.  I think those
variables are used only on x86, ppc, and mips.

I believe I suggested some time ago that we should get rid of the
nr_cores/nr_threads CPUState fields and move them to
arch-specific types.  This would help us avoid confusion when
different architectures have different semantics for
nr_cores/nr_threads.

See https://www.mail-archive.com/qemu-devel@nongnu.org/msg587105.html
("[Qemu-devel] Meaning of '-smp threads' on mips_malta") for one
example of confusing arch-specific semantics.

-- 
Eduardo



Re: [Qemu-devel] [PATCH 2/9] cpu/topology: add general support for machine properties

2019-05-02 Thread Eduardo Habkost
On Tue, Apr 30, 2019 at 03:30:31PM +0800, Like Xu wrote:
> On 2019/4/4 22:25, Igor Mammedov wrote:
> > On Fri, 29 Mar 2019 16:48:38 +0800
> > Like Xu  wrote:
> > 
> 
> 
> > 
> > > diff --git a/cpus.c b/cpus.c
> > > index e83f72b..834a697 100644
> > > --- a/cpus.c
> > > +++ b/cpus.c
> > > @@ -2067,6 +2067,10 @@ static void qemu_dummy_start_vcpu(CPUState *cpu)
> > >   void qemu_init_vcpu(CPUState *cpu)
> > >   {
> > > +MachineState *ms = MACHINE(qdev_get_machine());
> > > +unsigned int smp_cores = ms->topo.smp_cores;
> > > +unsigned int smp_threads = ms->topo.smp_threads;
> > 
> > (***)
> > for once it probably will crash *-user builds

Will it?  cpus.o is compiled only on CONFIG_SOFTMMU.

> > and secondly the purpose of getting rid of smp_foo globals
> > is disentangle layer violations and not replace it with another global
> > (qdev_get_machine()).
> 
> I am happy to follow this rule on cpu-topo refactoring work, but sometimes
> calling qdev_get_machine() is inevitable.

I agree with Igor's goal, but let's do it one step at a time.
Replacing the smp_* globals with qdev_get_machine() is a step in
the right direction, IMO.


> 
> > 
> > What should be done is to make a properties of nr_cores/nr_threads and set
> > them from the parent object that creates CPUs. The point is CPUs shouldn't
> > reach out outside itself to fish out data bits it needs, it's responsibility
> > of creator to feed to being create CPU needed properties.
> > 
> > This kind of refactoring probably deserves its own series and should precede
> > -smp refactoring as it doesn't depend on CpuTopology at all.

I don't see why it should precede -smp refactoring.

We have a very specific user-visible goal here: making one extra
CPU topology option (CPU dies) available on PC only.  Asking the
author to refactor some code while implementing that is
reasonable.  Requiring the author to touch every single place
where a CPU object is created in QEMU just to avoid a
qdev_get_machine() call doesn't seem reasonable.


> > 
> 
> The division of responsibility for this case (refactoring qemu_init_vcpu)
> seems to be a poisonous apple.
> 
> The prerequisite for setting cpu-> nr_cores / nr_threads from the parent is
> that the CPU has been created, so if any process during initialization needs
> this topo information, it will use the default values form
> cpu_common_initfn() instead of user-configured parameters.
> 
> We may not want to repeat those assignment operations using the new values
> and what do you think, Igor?

I believe we need a better CPU creation API that all machines can
use, otherwise all of them will have to duplicate the same code
between object_new() and object_propert_set_bool("realized", true).

But I really don't think designing and implementing this new API
should be a requirement to get useful work done.

-- 
Eduardo



[Qemu-devel] [PULL 19/19] configure: automatically pick python3 is available

2019-05-02 Thread Eduardo Habkost
From: Daniel P. Berrangé 

Unless overridden via an env var or configure arg, QEMU will only look
for the 'python' binary in $PATH. This is unhelpful on distros which
are only shipping Python 3.x (eg Fedora) in their default install as,
if they comply with PEP 394, the bare 'python' binary won't exist.

This changes configure so that by default it will search for all three
common python binaries, preferring to find Python 3.x versions.

Signed-off-by: Daniel P. Berrangé 
Message-Id: <20190327170701.23798-1-berra...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 configure | 18 +++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 60719ddcc5..f88011b94d 100755
--- a/configure
+++ b/configure
@@ -899,7 +899,18 @@ fi
 
 : ${make=${MAKE-make}}
 : ${install=${INSTALL-install}}
-: ${python=${PYTHON-python}}
+# We prefer python 3.x. A bare 'python' is traditionally
+# python 2.x, but some distros have it as python 3.x, so
+# we check that before python2
+python=
+for binary in "${PYTHON-python3}" python python2
+do
+if has "$binary"
+then
+python="$binary"
+break
+fi
+done
 : ${smbd=${SMBD-/usr/sbin/smbd}}
 
 # Default objcc to clang if available, otherwise use CC
@@ -1818,8 +1829,9 @@ EOF
 exit 0
 fi
 
-if ! has $python; then
-  error_exit "Python not found. Use --python=/path/to/python"
+if test -z "$python"
+then
+error_exit "Python not found. Use --python=/path/to/python"
 fi
 
 # Note that if the Python conditional here evaluates True we will exit
-- 
2.18.0.rc1.1.g3f1ff2140




[Qemu-devel] [PULL 15/19] tests/boot_linux_console: add a test for aarch64 + virt

2019-05-02 Thread Eduardo Habkost
From: Cleber Rosa 

Just like the previous tests, boots a Linux kernel on a aarch64 target
using the virt machine.

One special option added is the CPU type, given that the kernel
selected fails to boot on the virt machine's default CPU (cortex-a15).

Signed-off-by: Cleber Rosa 
Reviewed-by: Caio Carrara 
Message-Id: <20190312171824.5134-18-cr...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 .travis.yml|  2 +-
 tests/acceptance/boot_linux_console.py | 21 +
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index cb46098972..753e40a115 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -223,7 +223,7 @@ matrix:
 
 # Acceptance (Functional) tests
 - env:
-- CONFIG="--python=/usr/bin/python3 
--target-list=x86_64-softmmu,mips-softmmu,mips64el-softmmu"
+- CONFIG="--python=/usr/bin/python3 
--target-list=x86_64-softmmu,mips-softmmu,mips64el-softmmu,aarch64-softmmu"
 - TEST_CMD="make check-acceptance"
   addons:
 apt:
diff --git a/tests/acceptance/boot_linux_console.py 
b/tests/acceptance/boot_linux_console.py
index 38b33b25f7..6d9362922f 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -134,3 +134,24 @@ class BootLinuxConsole(Test):
 self.vm.launch()
 console_pattern = 'Kernel command line: %s' % kernel_command_line
 self.wait_for_console_pattern(console_pattern)
+
+def test_aarch64_virt(self):
+"""
+:avocado: tags=arch:aarch64
+:avocado: tags=machine:virt
+"""
+kernel_url = ('https://download.fedoraproject.org/pub/fedora/linux/'
+  
'releases/29/Everything/aarch64/os/images/pxeboot/vmlinuz')
+kernel_hash = '8c73e469fc6ea06a58dc83a628fc695b693b8493'
+kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
+
+self.vm.set_machine('virt')
+self.vm.set_console()
+kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
+   'console=ttyAMA0')
+self.vm.add_args('-cpu', 'cortex-a53',
+ '-kernel', kernel_path,
+ '-append', kernel_command_line)
+self.vm.launch()
+console_pattern = 'Kernel command line: %s' % kernel_command_line
+self.wait_for_console_pattern(console_pattern)
-- 
2.18.0.rc1.1.g3f1ff2140




[Qemu-devel] [PULL 14/19] tests/boot_linux_console: add a test for mips64el + malta

2019-05-02 Thread Eduardo Habkost
From: Cleber Rosa 

Similar to the x86_64 + pc test, it boots a Linux kernel on a Malta
board and verify the serial is working.

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

Alternatively, this test can be run using:

$ avocado run -t arch:mips64el tests/acceptance
$ avocado run -t machine:malta tests/acceptance

Signed-off-by: Philippe Mathieu-Daudé 
Signed-off-by: Cleber Rosa 
Reviewed-by: Aleksandar Markovic 
Message-Id: <20190312171824.5134-15-cr...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 .travis.yml|  2 +-
 tests/acceptance/boot_linux_console.py | 33 ++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index f6f5d39aca..cb46098972 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -223,7 +223,7 @@ matrix:
 
 # Acceptance (Functional) tests
 - env:
-- CONFIG="--python=/usr/bin/python3 
--target-list=x86_64-softmmu,mips-softmmu"
+- CONFIG="--python=/usr/bin/python3 
--target-list=x86_64-softmmu,mips-softmmu,mips64el-softmmu"
 - TEST_CMD="make check-acceptance"
   addons:
 apt:
diff --git a/tests/acceptance/boot_linux_console.py 
b/tests/acceptance/boot_linux_console.py
index 028fefd7ee..38b33b25f7 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -101,3 +101,36 @@ class BootLinuxConsole(Test):
 self.vm.launch()
 console_pattern = 'Kernel command line: %s' % kernel_command_line
 self.wait_for_console_pattern(console_pattern)
+
+def test_mips64el_malta(self):
+"""
+This test requires the ar tool to extract "data.tar.gz" from
+the Debian package.
+
+The kernel can be rebuilt using this Debian kernel source [1] and
+following the instructions on [2].
+
+[1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/
+#linux-source-2.6.32_2.6.32-48
+[2] https://kernel-team.pages.debian.net/kernel-handbook/
+ch-common-tasks.html#s-common-official
+
+:avocado: tags=arch:mips64el
+:avocado: tags=machine:malta
+"""
+deb_url = ('http://snapshot.debian.org/archive/debian/'
+   '20130217T032700Z/pool/main/l/linux-2.6/'
+   'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb')
+deb_hash = '1aaec92083bf22fda31e0d27fa8d9a388e5fc3d5'
+deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
+kernel_path = self.extract_from_deb(deb_path,
+'/boot/vmlinux-2.6.32-5-5kc-malta')
+
+self.vm.set_machine('malta')
+self.vm.set_console()
+kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
+self.vm.add_args('-kernel', kernel_path,
+ '-append', kernel_command_line)
+self.vm.launch()
+console_pattern = 'Kernel command line: %s' % kernel_command_line
+self.wait_for_console_pattern(console_pattern)
-- 
2.18.0.rc1.1.g3f1ff2140




[Qemu-devel] [PULL 18/19] tests/boot_linux_console: add a test for alpha + clipper

2019-05-02 Thread Eduardo Habkost
From: Cleber Rosa 

Similar to the x86_64 + pc test, it boots a Linux kernel on a Malta
board and verify the serial is working.  One extra command added to
the QEMU command line is '-vga std', because the kernel used is
known to crash without it.

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

Alternatively, this test can be run using:

$ avocado run -t arch:alpha tests/acceptance
$ avocado run -t machine:clipper tests/acceptance

Signed-off-by: Philippe Mathieu-Daudé 
Signed-off-by: Cleber Rosa 
Reviewed-by: Caio Carrara 
Message-Id: <20190312171824.5134-21-cr...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 .travis.yml|  2 +-
 tests/acceptance/boot_linux_console.py | 22 ++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 9b271b963d..66448d99d6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -223,7 +223,7 @@ matrix:
 
 # Acceptance (Functional) tests
 - env:
-- CONFIG="--python=/usr/bin/python3 
--target-list=x86_64-softmmu,mips-softmmu,mips64el-softmmu,aarch64-softmmu,arm-softmmu,s390x-softmmu"
+- CONFIG="--python=/usr/bin/python3 
--target-list=x86_64-softmmu,mips-softmmu,mips64el-softmmu,aarch64-softmmu,arm-softmmu,s390x-softmmu,alpha-softmmu"
 - TEST_CMD="make check-acceptance"
   addons:
 apt:
diff --git a/tests/acceptance/boot_linux_console.py 
b/tests/acceptance/boot_linux_console.py
index 7c1099e5c8..d5c500ea30 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -195,3 +195,25 @@ class BootLinuxConsole(Test):
 self.vm.launch()
 console_pattern = 'Kernel command line: %s' % kernel_command_line
 self.wait_for_console_pattern(console_pattern)
+
+def test_alpha_clipper(self):
+"""
+:avocado: tags=arch:alpha
+:avocado: tags=machine:clipper
+"""
+kernel_url = ('http://archive.debian.org/debian/dists/lenny/main/'
+  'installer-alpha/current/images/cdrom/vmlinuz')
+kernel_hash = '3a943149335529e2ed3e74d0d787b85fb5671ba3'
+kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
+
+uncompressed_kernel = archive.uncompress(kernel_path, self.workdir)
+
+self.vm.set_machine('clipper')
+self.vm.set_console()
+kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
+self.vm.add_args('-vga', 'std',
+ '-kernel', uncompressed_kernel,
+ '-append', kernel_command_line)
+self.vm.launch()
+console_pattern = 'Kernel command line: %s' % kernel_command_line
+self.wait_for_console_pattern(console_pattern)
-- 
2.18.0.rc1.1.g3f1ff2140




[Qemu-devel] [PATCH v3] hw/usb/hcd-xhci: Fix GCC 9 build warning

2019-05-02 Thread Alistair Francis
Fix this build warning with GCC 9 on Fedora 30:
hw/usb/hcd-xhci.c:3339:66: error: ‘%d’ directive output may be truncated 
writing between 1 and 10 bytes into a region of size 5 
[-Werror=format-truncation=]
 3339 | snprintf(port->name, sizeof(port->name), "usb2 port #%d", 
i+1);
  |  ^~
hw/usb/hcd-xhci.c:3339:54: note: directive argument in the range [1, 2147483647]
 3339 | snprintf(port->name, sizeof(port->name), "usb2 port #%d", 
i+1);
  |  ^~~
In file included from /usr/include/stdio.h:867,
 from /home/alistair/qemu/include/qemu/osdep.h:99,
 from hw/usb/hcd-xhci.c:21:
/usr/include/bits/stdio2.h:67:10: note: ‘__builtin___snprintf_chk’ output 
between 13 and 22 bytes into a destination of size 16
   67 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
  |  ^~~~
   68 |__bos (__s), __fmt, __va_arg_pack ());
  |~

Signed-off-by: Alistair Francis 
Reviewed-by: Laurent Vivier 
Reviewed-by: Daniel P. Berrangé 
Reviewed-by: Philippe Mathieu-Daudé 
---
This is the onl patch left if my original series "Fix some GCC 9 build
warnings" that hasn't either been accepeted into a maintainers tree or
fixed by someone else.

 hw/usb/hcd-xhci.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index ec28bee319..a15b103b65 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -3321,6 +3321,8 @@ static void usb_xhci_init(XHCIState *xhci)
 
 usb_bus_new(&xhci->bus, sizeof(xhci->bus), &xhci_bus_ops, dev);
 
+g_assert(usbports <= MAX(MAXPORTS_2, MAXPORTS_3));
+
 for (i = 0; i < usbports; i++) {
 speedmask = 0;
 if (i < xhci->numports_2) {
-- 
2.21.0



[Qemu-devel] [PULL 17/19] tests/boot_linux_console: add a test for s390x + s390-ccw-virtio

2019-05-02 Thread Eduardo Habkost
From: Cleber Rosa 

Just like the previous tests, boots a Linux kernel on a s390x target
using the s390-ccw-virtio machine.

Because it's not possible to have multiple VT220 consoles,
'-nodefaults' is used, so that the one set with set_console() works
correctly.

Signed-off-by: Cleber Rosa 
Reviewed-by: Cornelia Huck 
Reviewed-by: Caio Carrara 
Message-Id: <20190312171824.5134-20-cr...@redhat.com>
[ehabkost: Updated kernel URL to point to fedoraproject.org]
Signed-off-by: Eduardo Habkost 
---
 .travis.yml|  2 +-
 tests/acceptance/boot_linux_console.py | 20 
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 268df60345..9b271b963d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -223,7 +223,7 @@ matrix:
 
 # Acceptance (Functional) tests
 - env:
-- CONFIG="--python=/usr/bin/python3 
--target-list=x86_64-softmmu,mips-softmmu,mips64el-softmmu,aarch64-softmmu,arm-softmmu"
+- CONFIG="--python=/usr/bin/python3 
--target-list=x86_64-softmmu,mips-softmmu,mips64el-softmmu,aarch64-softmmu,arm-softmmu,s390x-softmmu"
 - TEST_CMD="make check-acceptance"
   addons:
 apt:
diff --git a/tests/acceptance/boot_linux_console.py 
b/tests/acceptance/boot_linux_console.py
index 54b6e2625d..7c1099e5c8 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -175,3 +175,23 @@ class BootLinuxConsole(Test):
 self.vm.launch()
 console_pattern = 'Kernel command line: %s' % kernel_command_line
 self.wait_for_console_pattern(console_pattern)
+
+def test_s390x_s390_ccw_virtio(self):
+"""
+:avocado: tags=arch:s390x
+:avocado: tags=machine:s390_ccw_virtio
+"""
+kernel_url = 
('https://download.fedoraproject.org/pub/fedora-secondary/'
+  'releases/29/Everything/s390x/os/images/kernel.img')
+kernel_hash = 'e8e8439103ef8053418ef062644ffd46a7919313'
+kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
+
+self.vm.set_machine('s390-ccw-virtio')
+self.vm.set_console()
+kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=sclp0'
+self.vm.add_args('-nodefaults',
+ '-kernel', kernel_path,
+ '-append', kernel_command_line)
+self.vm.launch()
+console_pattern = 'Kernel command line: %s' % kernel_command_line
+self.wait_for_console_pattern(console_pattern)
-- 
2.18.0.rc1.1.g3f1ff2140




[Qemu-devel] [PULL 16/19] tests/boot_linux_console: add a test for arm + virt

2019-05-02 Thread Eduardo Habkost
From: Cleber Rosa 

Just like the previous tests, boots a Linux kernel on an arm target
using the virt machine.

Signed-off-by: Cleber Rosa 
Reviewed-by: Caio Carrara 
Message-Id: <20190312171824.5134-19-cr...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 .travis.yml|  2 +-
 tests/acceptance/boot_linux_console.py | 20 
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 753e40a115..268df60345 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -223,7 +223,7 @@ matrix:
 
 # Acceptance (Functional) tests
 - env:
-- CONFIG="--python=/usr/bin/python3 
--target-list=x86_64-softmmu,mips-softmmu,mips64el-softmmu,aarch64-softmmu"
+- CONFIG="--python=/usr/bin/python3 
--target-list=x86_64-softmmu,mips-softmmu,mips64el-softmmu,aarch64-softmmu,arm-softmmu"
 - TEST_CMD="make check-acceptance"
   addons:
 apt:
diff --git a/tests/acceptance/boot_linux_console.py 
b/tests/acceptance/boot_linux_console.py
index 6d9362922f..54b6e2625d 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -155,3 +155,23 @@ class BootLinuxConsole(Test):
 self.vm.launch()
 console_pattern = 'Kernel command line: %s' % kernel_command_line
 self.wait_for_console_pattern(console_pattern)
+
+def test_arm_virt(self):
+"""
+:avocado: tags=arch:arm
+:avocado: tags=machine:virt
+"""
+kernel_url = ('https://download.fedoraproject.org/pub/fedora/linux/'
+  
'releases/29/Everything/armhfp/os/images/pxeboot/vmlinuz')
+kernel_hash = 'e9826d741b4fb04cadba8d4824d1ed3b7fb8b4d4'
+kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
+
+self.vm.set_machine('virt')
+self.vm.set_console()
+kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
+   'console=ttyAMA0')
+self.vm.add_args('-kernel', kernel_path,
+ '-append', kernel_command_line)
+self.vm.launch()
+console_pattern = 'Kernel command line: %s' % kernel_command_line
+self.wait_for_console_pattern(console_pattern)
-- 
2.18.0.rc1.1.g3f1ff2140




[Qemu-devel] [PULL 10/19] tests/boot_linux_console: increase timeout

2019-05-02 Thread Eduardo Habkost
From: Cleber Rosa 

When running on very low powered environments, some tests may time out
causing false negatives.  As a conservative change, and for
considering that human time (investigating false negatives) is worth
more than some extra machine cycles (and time), let's increase the
overall timeout.

CC: Alex Bennée 
Signed-off-by: Cleber Rosa 
Reviewed-by: Cornelia Huck 
Message-Id: <20190312171824.5134-11-cr...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 tests/acceptance/boot_linux_console.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/acceptance/boot_linux_console.py 
b/tests/acceptance/boot_linux_console.py
index a94f5cd2c8..bfcae3771b 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -19,7 +19,7 @@ class BootLinuxConsole(Test):
 kernel command line is properly passed from QEMU to the kernel
 """
 
-timeout = 60
+timeout = 90
 
 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
 
-- 
2.18.0.rc1.1.g3f1ff2140




[Qemu-devel] [PULL 09/19] tests/boot_linux_console: add common kernel command line options

2019-05-02 Thread Eduardo Habkost
From: Cleber Rosa 

The 'printk.time=0' option makes it easier to parse the console
output.  Let's set it as a default, and reusable, kernel command line
options for this and future similar tests.

Signed-off-by: Cleber Rosa 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Cornelia Huck 
Message-Id: <20190312171824.5134-10-cr...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 tests/acceptance/boot_linux_console.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tests/acceptance/boot_linux_console.py 
b/tests/acceptance/boot_linux_console.py
index 03a4445176..a94f5cd2c8 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -21,6 +21,8 @@ class BootLinuxConsole(Test):
 
 timeout = 60
 
+KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
+
 def test_x86_64_pc(self):
 """
 :avocado: tags=arch:x86_64
@@ -33,7 +35,7 @@ class BootLinuxConsole(Test):
 
 self.vm.set_machine('pc')
 self.vm.set_console()
-kernel_command_line = 'console=ttyS0'
+kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
 self.vm.add_args('-kernel', kernel_path,
  '-append', kernel_command_line)
 self.vm.launch()
-- 
2.18.0.rc1.1.g3f1ff2140




[Qemu-devel] [PULL 13/19] tests/boot_linux_console: add a test for mips + malta

2019-05-02 Thread Eduardo Habkost
From: Philippe Mathieu-Daudé 

Similar to the x86_64 + pc test, it boots a Linux kernel on a Malta
board and verify the serial is working.  Also, it relies on the serial
device set by the machine itself.

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

Alternatively, this test can be run using:

$ avocado run -t arch:mips tests/acceptance
$ avocado run -t machine:malta tests/acceptance
$ avocado run -t endian:big tests/acceptance

Signed-off-by: Philippe Mathieu-Daudé 
Signed-off-by: Cleber Rosa 
Reviewed-by: Aleksandar Markovic 
Tested-by: Philippe Mathieu-Daudé 
Message-Id: <20190312171824.5134-14-cr...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 .travis.yml|  2 +-
 tests/acceptance/boot_linux_console.py | 41 ++
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index e6f951e01a..f6f5d39aca 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -223,7 +223,7 @@ matrix:
 
 # Acceptance (Functional) tests
 - env:
-- CONFIG="--python=/usr/bin/python3 --target-list=x86_64-softmmu"
+- CONFIG="--python=/usr/bin/python3 
--target-list=x86_64-softmmu,mips-softmmu"
 - TEST_CMD="make check-acceptance"
   addons:
 apt:
diff --git a/tests/acceptance/boot_linux_console.py 
b/tests/acceptance/boot_linux_console.py
index 32f1d4d0bf..028fefd7ee 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -8,9 +8,12 @@
 # This work is licensed under the terms of the GNU GPL, version 2 or
 # later.  See the COPYING file in the top-level directory.
 
+import os
 import logging
 
 from avocado_qemu import Test
+from avocado.utils import process
+from avocado.utils import archive
 
 
 class BootLinuxConsole(Test):
@@ -42,6 +45,21 @@ class BootLinuxConsole(Test):
 fail = 'Failure message found in console: %s' % failure_message
 self.fail(fail)
 
+def extract_from_deb(self, deb, path):
+"""
+Extracts a file from a deb package into the test workdir
+
+:param deb: path to the deb archive
+:param file: path within the deb archive of the file to be extracted
+:returns: path of the extracted file
+"""
+cwd = os.getcwd()
+os.chdir(self.workdir)
+process.run("ar x %s data.tar.gz" % deb)
+archive.extract("data.tar.gz", self.workdir)
+os.chdir(cwd)
+return self.workdir + path
+
 def test_x86_64_pc(self):
 """
 :avocado: tags=arch:x86_64
@@ -60,3 +78,26 @@ class BootLinuxConsole(Test):
 self.vm.launch()
 console_pattern = 'Kernel command line: %s' % kernel_command_line
 self.wait_for_console_pattern(console_pattern)
+
+def test_mips_malta(self):
+"""
+:avocado: tags=arch:mips
+:avocado: tags=machine:malta
+:avocado: tags=endian:big
+"""
+deb_url = ('http://snapshot.debian.org/archive/debian/'
+   '20130217T032700Z/pool/main/l/linux-2.6/'
+   'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb')
+deb_hash = 'a8cfc28ad8f45f54811fc6cf74fc43ffcfe0ba04'
+deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
+kernel_path = self.extract_from_deb(deb_path,
+'/boot/vmlinux-2.6.32-5-4kc-malta')
+
+self.vm.set_machine('malta')
+self.vm.set_console()
+kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
+self.vm.add_args('-kernel', kernel_path,
+ '-append', kernel_command_line)
+self.vm.launch()
+console_pattern = 'Kernel command line: %s' % kernel_command_line
+self.wait_for_console_pattern(console_pattern)
-- 
2.18.0.rc1.1.g3f1ff2140




[Qemu-devel] [PULL 11/19] tests/boot_linux_console: refactor the console watcher into utility method

2019-05-02 Thread Eduardo Habkost
From: Cleber Rosa 

This introduces a utility method that monitors the console device and
looks for either a message that signals the test success or failure.

Signed-off-by: Cleber Rosa 
Reviewed-by: Caio Carrara 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Cornelia Huck 
Message-Id: <20190312171824.5134-12-cr...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 tests/acceptance/boot_linux_console.py | 30 ++
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/tests/acceptance/boot_linux_console.py 
b/tests/acceptance/boot_linux_console.py
index bfcae3771b..32f1d4d0bf 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -23,6 +23,25 @@ class BootLinuxConsole(Test):
 
 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
 
+def wait_for_console_pattern(self, success_message,
+ failure_message='Kernel panic - not syncing'):
+"""
+Waits for messages to appear on the console, while logging the content
+
+:param success_message: if this message appears, test succeeds
+:param failure_message: if this message appears, test fails
+"""
+console = self.vm.console_socket.makefile()
+console_logger = logging.getLogger('console')
+while True:
+msg = console.readline()
+console_logger.debug(msg.strip())
+if success_message in msg:
+break
+if failure_message in msg:
+fail = 'Failure message found in console: %s' % failure_message
+self.fail(fail)
+
 def test_x86_64_pc(self):
 """
 :avocado: tags=arch:x86_64
@@ -39,12 +58,5 @@ class BootLinuxConsole(Test):
 self.vm.add_args('-kernel', kernel_path,
  '-append', kernel_command_line)
 self.vm.launch()
-console = self.vm.console_socket.makefile()
-console_logger = logging.getLogger('console')
-while True:
-msg = console.readline()
-console_logger.debug(msg.strip())
-if 'Kernel command line: %s' % kernel_command_line in msg:
-break
-if 'Kernel panic - not syncing' in msg:
-self.fail("Kernel panic reached")
+console_pattern = 'Kernel command line: %s' % kernel_command_line
+self.wait_for_console_pattern(console_pattern)
-- 
2.18.0.rc1.1.g3f1ff2140




[Qemu-devel] [PULL 06/19] tests/acceptance: look for target architecture in test tags first

2019-05-02 Thread Eduardo Habkost
From: Cleber Rosa 

A test can, optionally, be tagged for one or many architectures.  If a
test has been tagged for a single architecture, there's a high chance
that the test won't run on other architectures.  This changes the
default order of choosing a default target architecture to use based
on the 'arch' tag value first.

The precedence order is for choosing a QEMU binary to use for a test
is now:

 * qemu_bin parameter
 * arch parameter
 * arch tag value (for example, x86_64 if ":avocado: tags=arch:x86_64
   is used)

This means that if one runs:

 $ avocado run -p qemu_bin=/usr/bin/qemu-system-x86_64 test.py

No arch parameter or tag will influence the selection of the QEMU
target binary.  If one runs:

 $ avocado run -p arch=ppc64 test.py

The target binary selection mechanism will attempt to find a binary
such as "ppc64-softmmu/qemu-system-ppc64".  And finally, if one runs
a test that is tagged (in its docstring) with "arch:aarch64":

 $ avocado run aarch64.py

The target binary selection mechanism will attempt to find a binary
such as "aarch64-softmmu/qemu-system-aarch64".

At this time, no provision is made to cancel the execution of tests if
the arch parameter given (manually) does not match the test "arch"
tag, but it may be a useful default behavior to be added in the
future.

Signed-off-by: Cleber Rosa 
Reviewed-by: Cornelia Huck 
Message-Id: <20190312171824.5134-7-cr...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 docs/devel/testing.rst| 4 +++-
 tests/acceptance/avocado_qemu/__init__.py | 7 ++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst
index 83bf9f09ac..da2d0fc964 100644
--- a/docs/devel/testing.rst
+++ b/docs/devel/testing.rst
@@ -740,7 +740,9 @@ A test may, for instance, use the same value when selecting 
the
 architecture of a kernel or disk image to boot a VM with.
 
 The ``arch`` attribute will be set to the test parameter of the same
-name, and if one is not given explicitly, it will be set to ``None``.
+name.  If one is not given explicitly, it will either be set to
+``None``, or, if the test is tagged with one (and only one)
+``:avocado: tags=arch:VALUE`` tag, it will be set to ``VALUE``.
 
 qemu_bin
 
diff --git a/tests/acceptance/avocado_qemu/__init__.py 
b/tests/acceptance/avocado_qemu/__init__.py
index 688a0746a2..2b236a1cf0 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -53,7 +53,12 @@ def pick_default_qemu_bin(arch=None):
 class Test(avocado.Test):
 def setUp(self):
 self._vms = {}
-self.arch = self.params.get('arch')
+arches = self.tags.get('arch', [])
+if len(arches) == 1:
+arch = arches.pop()
+else:
+arch = None
+self.arch = self.params.get('arch', default=arch)
 default_qemu_bin = pick_default_qemu_bin(arch=self.arch)
 self.qemu_bin = self.params.get('qemu_bin',
 default=default_qemu_bin)
-- 
2.18.0.rc1.1.g3f1ff2140




[Qemu-devel] [PULL 08/19] tests/boot_linux_console: update the x86_64 kernel

2019-05-02 Thread Eduardo Habkost
From: Cleber Rosa 

Update to the stock Fedora 29 kernel, from the Fedora 28.  New tests
will be added using the 29 kernel, so for consistency, let's also
update it here.

Signed-off-by: Cleber Rosa 
Reviewed-by: Caio Carrara 
Reviewed-by: Philippe Mathieu-Daudé 
Tested-by: Philippe Mathieu-Daudé 
Acked-by: Cornelia Huck 
CC: Daniel P. Berrangé 
Message-Id: <20190312171824.5134-9-cr...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 tests/acceptance/boot_linux_console.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests/acceptance/boot_linux_console.py 
b/tests/acceptance/boot_linux_console.py
index 4d57741bd8..03a4445176 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -26,9 +26,9 @@ class BootLinuxConsole(Test):
 :avocado: tags=arch:x86_64
 :avocado: tags=machine:pc
 """
-kernel_url = ('https://mirrors.kernel.org/fedora/releases/28/'
-  'Everything/x86_64/os/images/pxeboot/vmlinuz')
-kernel_hash = '238e083e114c48200f80d889f7e32eeb2793e02a'
+kernel_url = ('https://download.fedoraproject.org/pub/fedora/linux/'
+  
'releases/29/Everything/x86_64/os/images/pxeboot/vmlinuz')
+kernel_hash = '23bebd2680757891cf7adedb033532163a792495'
 kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
 
 self.vm.set_machine('pc')
-- 
2.18.0.rc1.1.g3f1ff2140




[Qemu-devel] [PULL 12/19] scripts/qemu.py: support adding a console with the default serial device

2019-05-02 Thread Eduardo Habkost
From: Cleber Rosa 

The set_console() utility function either adds a device based on the
explicitly given device type, or adds a known good type of device
based on the machine type.

But, for a number of machine types, it may be impossible or
inconvenient to add the devices by means of "-device" command line
options, and then it may better to just use the "-serial" option and
let QEMU itself, based on the machine type, set the device
accordingly.

To achieve that, the behavior of set_console() now flags the intention
to add a console device on launch(), and if no explicit device type is
given the "-serial" option is going to be added to the QEMU command
line, instead of raising exceptions.

Based on testing with different machine types, the CONSOLE_DEV_TYPES
is not necessary anymore, so it's being removed, as is the logic to
use it.

Signed-off-by: Cleber Rosa 
Reviewed-by: Cornelia Huck 
Message-Id: <20190312171824.5134-13-cr...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 python/qemu/__init__.py | 50 ++---
 1 file changed, 17 insertions(+), 33 deletions(-)

diff --git a/python/qemu/__init__.py b/python/qemu/__init__.py
index fd144c0006..81d9657ec0 100644
--- a/python/qemu/__init__.py
+++ b/python/qemu/__init__.py
@@ -41,17 +41,6 @@ def kvm_available(target_arch=None):
 return os.access("/dev/kvm", os.R_OK | os.W_OK)
 
 
-#: Maps machine types to the preferred console device types
-CONSOLE_DEV_TYPES = {
-r'^clipper$': 'isa-serial',
-r'^malta': 'isa-serial',
-r'^(pc.*|q35.*|isapc)$': 'isa-serial',
-r'^(40p|powernv|prep)$': 'isa-serial',
-r'^pseries.*': 'spapr-vty',
-r'^s390-ccw-virtio.*': 'sclpconsole',
-}
-
-
 class QEMUMachineError(Exception):
 """
 Exception called when an error in QEMUMachine happens.
@@ -130,6 +119,7 @@ class QEMUMachine(object):
 self._temp_dir = None
 self._launched = False
 self._machine = None
+self._console_set = False
 self._console_device_type = None
 self._console_address = None
 self._console_socket = None
@@ -248,13 +238,17 @@ class QEMUMachine(object):
 '-display', 'none', '-vga', 'none']
 if self._machine is not None:
 args.extend(['-machine', self._machine])
-if self._console_device_type is not None:
+if self._console_set:
 self._console_address = os.path.join(self._temp_dir,
  self._name + "-console.sock")
 chardev = ('socket,id=console,path=%s,server,nowait' %
self._console_address)
-device = '%s,chardev=console' % self._console_device_type
-args.extend(['-chardev', chardev, '-device', device])
+args.extend(['-chardev', chardev])
+if self._console_device_type is None:
+args.extend(['-serial', 'chardev:console'])
+else:
+device = '%s,chardev=console' % self._console_device_type
+args.extend(['-device', device])
 return args
 
 def _pre_launch(self):
@@ -480,30 +474,20 @@ class QEMUMachine(object):
 line.
 
 This is a convenience method that will either use the provided
-device type, of if not given, it will used the device type set
-on CONSOLE_DEV_TYPES.
+device type, or default to a "-serial chardev:console" command
+line argument.
 
 The actual setting of command line arguments will be be done at
 machine launch time, as it depends on the temporary directory
 to be created.
 
-@param device_type: the device type, such as "isa-serial"
-@raises: QEMUMachineAddDeviceError if the device type is not given
- and can not be determined.
-"""
-if device_type is None:
-if self._machine is None:
-raise QEMUMachineAddDeviceError("Can not add a console device:"
-" QEMU instance without a "
-"defined machine type")
-for regex, device in CONSOLE_DEV_TYPES.items():
-if re.match(regex, self._machine):
-device_type = device
-break
-if device_type is None:
-raise QEMUMachineAddDeviceError("Can not add a console device:"
-" no matching console device "
-"type definition")
+@param device_type: the device type, such as "isa-serial".  If
+None is given (the default value) a "-serial
+chardev:console" command line argument will
+be used instead, resorting to the machine's
+default device type.
+"""
+self._console_set = True
 se

[Qemu-devel] [PULL 04/19] tests/acceptance: introduce arch parameter and attribute

2019-05-02 Thread Eduardo Habkost
From: Cleber Rosa 

It's useful to define the architecture that should be used in
situations such as:
 * the intended target of the QEMU binary to be used on tests
 * the architecture of code to be run within the QEMU binary, such
   as a kernel image or a full blown guest OS image

This commit introduces both a test parameter and a test instance
attribute, that will contain such a value.

Now, when the "arch" test parameter is given, it will influence the
selection of the default QEMU binary, if one is not given explicitly
by means of the "qemu_img" parameter.

Signed-off-by: Cleber Rosa 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Cornelia Huck 
Message-Id: <20190312171824.5134-5-cr...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 docs/devel/testing.rst| 28 +++
 tests/acceptance/avocado_qemu/__init__.py | 14 +---
 2 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst
index 7c1b199323..83bf9f09ac 100644
--- a/docs/devel/testing.rst
+++ b/docs/devel/testing.rst
@@ -727,6 +727,21 @@ vm
 A QEMUMachine instance, initially configured according to the given
 ``qemu_bin`` parameter.
 
+arch
+
+
+The architecture can be used on different levels of the stack, e.g. by
+the framework or by the test itself.  At the framework level, it will
+currently influence the selection of a QEMU binary (when one is not
+explicitly given).
+
+Tests are also free to use this attribute value, for their own needs.
+A test may, for instance, use the same value when selecting the
+architecture of a kernel or disk image to boot a VM with.
+
+The ``arch`` attribute will be set to the test parameter of the same
+name, and if one is not given explicitly, it will be set to ``None``.
+
 qemu_bin
 
 
@@ -749,6 +764,19 @@ like the following:
 
   PARAMS (key=qemu_bin, path=*, default=x86_64-softmmu/qemu-system-x86_64) => 
'x86_64-softmmu/qemu-system-x86_64
 
+arch
+
+
+The architecture that will influence the selection of a QEMU binary
+(when one is not explicitly given).
+
+Tests are also free to use this parameter value, for their own needs.
+A test may, for instance, use the same value when selecting the
+architecture of a kernel or disk image to boot a VM with.
+
+This parameter has a direct relation with the ``arch`` attribute.  If
+not given, it will default to None.
+
 qemu_bin
 
 
diff --git a/tests/acceptance/avocado_qemu/__init__.py 
b/tests/acceptance/avocado_qemu/__init__.py
index b7c5d598d8..688a0746a2 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -23,16 +23,22 @@ def is_readable_executable_file(path):
 return os.path.isfile(path) and os.access(path, os.R_OK | os.X_OK)
 
 
-def pick_default_qemu_bin():
+def pick_default_qemu_bin(arch=None):
 """
 Picks the path of a QEMU binary, starting either in the current working
 directory or in the source tree root directory.
 
+:param arch: the arch to use when looking for a QEMU binary (the target
+ will match the arch given).  If None (the default), arch
+ will be the current host system arch (as given by
+ :func:`os.uname`).
+:type arch: str
 :returns: the path to the default QEMU binary or None if one could not
   be found
 :rtype: str or None
 """
-arch = os.uname()[4]
+if arch is None:
+arch = os.uname()[4]
 qemu_bin_relative_path = os.path.join("%s-softmmu" % arch,
   "qemu-system-%s" % arch)
 if is_readable_executable_file(qemu_bin_relative_path):
@@ -47,8 +53,10 @@ def pick_default_qemu_bin():
 class Test(avocado.Test):
 def setUp(self):
 self._vms = {}
+self.arch = self.params.get('arch')
+default_qemu_bin = pick_default_qemu_bin(arch=self.arch)
 self.qemu_bin = self.params.get('qemu_bin',
-default=pick_default_qemu_bin())
+default=default_qemu_bin)
 if self.qemu_bin is None:
 self.cancel("No QEMU binary defined or found in the source tree")
 
-- 
2.18.0.rc1.1.g3f1ff2140




[Qemu-devel] [PULL 03/19] tests/acceptance: fix doc reference to avocado_qemu directory

2019-05-02 Thread Eduardo Habkost
From: Cleber Rosa 

The "this directory" reference is misleading and confusing, it's a
leftover from when this text was proposed in a README file inside
the "tests/acceptance/avocado_qemu" directory.

When that text was moved to the top level docs directory, the
reference was not updated.

Signed-off-by: Cleber Rosa 
Reviewed-by: Caio Carrara 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Cornelia Huck 
Message-Id: <20190312171824.5134-4-cr...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 docs/devel/testing.rst | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst
index 60f897d915..7c1b199323 100644
--- a/docs/devel/testing.rst
+++ b/docs/devel/testing.rst
@@ -590,8 +590,9 @@ Alternatively, follow the instructions on this link:
 Overview
 
 
-This directory provides the ``avocado_qemu`` Python module, containing
-the ``avocado_qemu.Test`` class.  Here's a simple usage example:
+The ``tests/acceptance/avocado_qemu`` directory provides the
+``avocado_qemu`` Python module, containing the ``avocado_qemu.Test``
+class.  Here's a simple usage example:
 
 .. code::
 
-- 
2.18.0.rc1.1.g3f1ff2140




[Qemu-devel] [PULL 05/19] tests/acceptance: use "arch:" tag to filter target specific tests

2019-05-02 Thread Eduardo Habkost
From: Cleber Rosa 

Currently, some tests contains target architecture information, in the
form of a "x86_64" tag.  But that tag is not respected in the default
execution, that is, "make check-acceptance" doesn't do anything with
it.

That said, even the target architecture handling currently present in
the "avocado_qemu.Test" class is pretty limited.  For instance, by
default, it chooses a target based on the host architecture.

Because the original implementation of the tags feature in Avocado did
not include any time of namespace or "key:val" mechanism, no tag has
relation to another tag.  The new implementation of the tags feature
from version 67.0 onwards, allows "key:val" tags, and because of that,
a test can be classified with a tag in a given key.  For instance, the
new proposed version of the "boot_linux_console.py" test, which
downloads and attempts to run a x86_64 kernel, is now tagged as:

  :avocado: tags=arch:x86_64

This means that it can be filtered (out) when no x86_64 target is
available.  At the same time, tests that don't have a "arch:" tag,
will not be filtered out.

Signed-off-by: Cleber Rosa 
Reviewed-by: Cornelia Huck 
Message-Id: <20190312171824.5134-6-cr...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 tests/Makefile.include | 3 +++
 tests/acceptance/boot_linux_console.py | 2 +-
 tests/acceptance/linux_initrd.py   | 2 +-
 tests/acceptance/virtio_version.py | 2 +-
 4 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/tests/Makefile.include b/tests/Makefile.include
index 445aa0bb12..7c8b9c84b2 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -1134,6 +1134,7 @@ TESTS_RESULTS_DIR=$(BUILD_DIR)/tests/results
 # Any number of command separated loggers are accepted.  For more
 # information please refer to "avocado --help".
 AVOCADO_SHOW=app
+AVOCADO_TAGS=$(patsubst %-softmmu,-t arch:%, $(filter 
%-softmmu,$(TARGET_DIRS)))
 
 ifneq ($(findstring v2,"v$(PYTHON_VERSION)"),v2)
 $(TESTS_VENV_DIR): $(TESTS_VENV_REQ)
@@ -1159,6 +1160,8 @@ check-acceptance: check-venv $(TESTS_RESULTS_DIR)
$(call quiet-command, \
 $(TESTS_VENV_DIR)/bin/python -m avocado \
 --show=$(AVOCADO_SHOW) run --job-results-dir=$(TESTS_RESULTS_DIR) \
+--filter-by-tags-include-empty --filter-by-tags-include-empty-key \
+$(AVOCADO_TAGS) \
 --failfast=on $(SRC_PATH)/tests/acceptance, \
 "AVOCADO", "tests/acceptance")
 
diff --git a/tests/acceptance/boot_linux_console.py 
b/tests/acceptance/boot_linux_console.py
index beeb1e59e8..fa4594f612 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -18,7 +18,7 @@ class BootLinuxConsole(Test):
 Boots a x86_64 Linux kernel and checks that the console is operational
 and the kernel command line is properly passed from QEMU to the kernel
 
-:avocado: tags=x86_64
+:avocado: tags=arch:x86_64
 """
 
 timeout = 60
diff --git a/tests/acceptance/linux_initrd.py b/tests/acceptance/linux_initrd.py
index fbdb48e43f..23be5a63aa 100644
--- a/tests/acceptance/linux_initrd.py
+++ b/tests/acceptance/linux_initrd.py
@@ -19,7 +19,7 @@ class LinuxInitrd(Test):
 """
 Checks QEMU evaluates correctly the initrd file passed as -initrd option.
 
-:avocado: tags=x86_64
+:avocado: tags=arch:x86_64
 """
 
 timeout = 300
diff --git a/tests/acceptance/virtio_version.py 
b/tests/acceptance/virtio_version.py
index 37fc01ea18..8b97453ff8 100644
--- a/tests/acceptance/virtio_version.py
+++ b/tests/acceptance/virtio_version.py
@@ -61,7 +61,7 @@ class VirtioVersionCheck(Test):
 same device tree created by `disable-modern` and
 `disable-legacy`.
 
-:avocado: tags=x86_64
+:avocado: tags=arch:x86_64
 """
 
 # just in case there are failures, show larger diff:
-- 
2.18.0.rc1.1.g3f1ff2140




[Qemu-devel] [PULL 00/19] Python queue, 2019-05-02

2019-05-02 Thread Eduardo Habkost
The following changes since commit 8482ff2eb3bb95020eb2f370a9b3ea26511e41df:

  Merge remote-tracking branch 'remotes/jnsnow/tags/bitmaps-pull-request' into 
staging (2019-05-02 12:04:51 +0100)

are available in the Git repository at:

  git://github.com/ehabkost/qemu.git tags/python-next-pull-request

for you to fetch changes up to faf441429adfe5767be52c5dcdb8bc03161d064f:

  configure: automatically pick python3 is available (2019-05-02 21:33:27 -0300)


Python queue, 2019-05-02

* configure: automatically pick python3 is available
  (Daniel P. Berrangé)

* tests/acceptance (Cleber Rosa, Philippe Mathieu-Daudé):
  * Multi-architecture test support
  * Multiple arch-specific boot_linux_console test cases
  * Increase verbosity of avocado by default
  * docstring improvements



Cleber Rosa (17):
  tests/acceptance: show avocado test execution by default
  tests/acceptance: improve docstring on pick_default_qemu_bin()
  tests/acceptance: fix doc reference to avocado_qemu directory
  tests/acceptance: introduce arch parameter and attribute
  tests/acceptance: use "arch:" tag to filter target specific tests
  tests/acceptance: look for target architecture in test tags first
  tests/boot_linux_console: rename the x86_64 after the arch and machine
  tests/boot_linux_console: update the x86_64 kernel
  tests/boot_linux_console: add common kernel command line options
  tests/boot_linux_console: increase timeout
  tests/boot_linux_console: refactor the console watcher into utility
method
  scripts/qemu.py: support adding a console with the default serial
device
  tests/boot_linux_console: add a test for mips64el + malta
  tests/boot_linux_console: add a test for aarch64 + virt
  tests/boot_linux_console: add a test for arm + virt
  tests/boot_linux_console: add a test for s390x + s390-ccw-virtio
  tests/boot_linux_console: add a test for alpha + clipper

Daniel P. Berrangé (1):
  configure: automatically pick python3 is available

Philippe Mathieu-Daudé (1):
  tests/boot_linux_console: add a test for mips + malta

 docs/devel/testing.rst|  35 +++-
 configure |  18 +-
 .travis.yml   |   4 +-
 python/qemu/__init__.py   |  50 ++---
 tests/Makefile.include|   5 +-
 tests/acceptance/avocado_qemu/__init__.py |  23 ++-
 tests/acceptance/boot_linux_console.py| 211 --
 tests/acceptance/linux_initrd.py  |   2 +-
 tests/acceptance/virtio_version.py|   2 +-
 9 files changed, 285 insertions(+), 65 deletions(-)

-- 
2.18.0.rc1.1.g3f1ff2140




[Qemu-devel] [PULL 02/19] tests/acceptance: improve docstring on pick_default_qemu_bin()

2019-05-02 Thread Eduardo Habkost
From: Cleber Rosa 

Making it clear what is returned by this utility function.

Signed-off-by: Cleber Rosa 
Reviewed-by: Caio Carrara 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Cornelia Huck 
Message-Id: <20190312171824.5134-3-cr...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 tests/acceptance/avocado_qemu/__init__.py | 4 
 1 file changed, 4 insertions(+)

diff --git a/tests/acceptance/avocado_qemu/__init__.py 
b/tests/acceptance/avocado_qemu/__init__.py
index a66ec72daa..b7c5d598d8 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -27,6 +27,10 @@ def pick_default_qemu_bin():
 """
 Picks the path of a QEMU binary, starting either in the current working
 directory or in the source tree root directory.
+
+:returns: the path to the default QEMU binary or None if one could not
+  be found
+:rtype: str or None
 """
 arch = os.uname()[4]
 qemu_bin_relative_path = os.path.join("%s-softmmu" % arch,
-- 
2.18.0.rc1.1.g3f1ff2140




[Qemu-devel] [PULL 07/19] tests/boot_linux_console: rename the x86_64 after the arch and machine

2019-05-02 Thread Eduardo Habkost
From: Cleber Rosa 

Given that the test is specific to x86_64 and pc, and new tests are
going to be added to the same class, let's rename it accordingly.
Also, let's make the class documentation not architecture specific.

Signed-off-by: Cleber Rosa 
Reviewed-by: Caio Carrara 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Cornelia Huck 
Message-Id: <20190312171824.5134-8-cr...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 tests/acceptance/boot_linux_console.py | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/tests/acceptance/boot_linux_console.py 
b/tests/acceptance/boot_linux_console.py
index fa4594f612..4d57741bd8 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -15,15 +15,17 @@ from avocado_qemu import Test
 
 class BootLinuxConsole(Test):
 """
-Boots a x86_64 Linux kernel and checks that the console is operational
-and the kernel command line is properly passed from QEMU to the kernel
-
-:avocado: tags=arch:x86_64
+Boots a Linux kernel and checks that the console is operational and the
+kernel command line is properly passed from QEMU to the kernel
 """
 
 timeout = 60
 
-def test(self):
+def test_x86_64_pc(self):
+"""
+:avocado: tags=arch:x86_64
+:avocado: tags=machine:pc
+"""
 kernel_url = ('https://mirrors.kernel.org/fedora/releases/28/'
   'Everything/x86_64/os/images/pxeboot/vmlinuz')
 kernel_hash = '238e083e114c48200f80d889f7e32eeb2793e02a'
-- 
2.18.0.rc1.1.g3f1ff2140




[Qemu-devel] [PULL 01/19] tests/acceptance: show avocado test execution by default

2019-05-02 Thread Eduardo Habkost
From: Cleber Rosa 

The current version of the "check-acceptance" target will only show
one line for execution of all tests.  That's probably OK if the tests
to be run are quick enough and they're always the same.

But, there's already one test alone that takes on average ~5 seconds
to run, we intend to adapt the list of tests to match the user's build
environment (among other choices).

Because of that, let's present the default Avocado UI by default.
Users can always choose a different output by setting the AVOCADO_SHOW
variable.

Signed-off-by: Cleber Rosa 
Reviewed-by: Caio Carrara 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Alex Bennée 
Reviewed-by: Cornelia Huck 
Message-Id: <20190312171824.5134-2-cr...@redhat.com>
Signed-off-by: Eduardo Habkost 
---
 .travis.yml| 2 +-
 tests/Makefile.include | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 2e06aee9d0..e6f951e01a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -224,7 +224,7 @@ matrix:
 # Acceptance (Functional) tests
 - env:
 - CONFIG="--python=/usr/bin/python3 --target-list=x86_64-softmmu"
-- TEST_CMD="make AVOCADO_SHOW=app check-acceptance"
+- TEST_CMD="make check-acceptance"
   addons:
 apt:
   packages:
diff --git a/tests/Makefile.include b/tests/Makefile.include
index e2432d5e77..445aa0bb12 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -1133,7 +1133,7 @@ TESTS_RESULTS_DIR=$(BUILD_DIR)/tests/results
 # Controls the output generated by Avocado when running tests.
 # Any number of command separated loggers are accepted.  For more
 # information please refer to "avocado --help".
-AVOCADO_SHOW=none
+AVOCADO_SHOW=app
 
 ifneq ($(findstring v2,"v$(PYTHON_VERSION)"),v2)
 $(TESTS_VENV_DIR): $(TESTS_VENV_REQ)
-- 
2.18.0.rc1.1.g3f1ff2140




[Qemu-devel] [PATCH v3 3/4] util/cacheinfo: Use uint64_t on LLP64 model to satisfy Windows ARM64

2019-05-02 Thread Cao Jiaxi
Windows ARM64 uses LLP64 model, which breaks current assumptions.

Signed-off-by: Cao Jiaxi 
---
 util/cacheinfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/cacheinfo.c b/util/cacheinfo.c
index 3cd080b83d..eebe1ce9c5 100644
--- a/util/cacheinfo.c
+++ b/util/cacheinfo.c
@@ -107,7 +107,7 @@ static void sys_cache_info(int *isize, int *dsize)
 static void arch_cache_info(int *isize, int *dsize)
 {
 if (*isize == 0 || *dsize == 0) {
-unsigned long ctr;
+uint64_t ctr;
 
 /* The real cache geometry is in CCSIDR_EL1/CLIDR_EL1/CSSELR_EL1,
but (at least under Linux) these are marked protected by the
-- 
2.17.1




[Qemu-devel] [PATCH v3 3/4] util/cacheinfo: Use uint64_t on LLP64 model to satisfy Windows ARM64

2019-05-02 Thread Cao Jiaxi
Windows ARM64 uses LLP64 model, which breaks current assumptions.

Signed-off-by: Cao Jiaxi 
---
 util/cacheinfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/cacheinfo.c b/util/cacheinfo.c
index 3cd080b83d..eebe1ce9c5 100644
--- a/util/cacheinfo.c
+++ b/util/cacheinfo.c
@@ -107,7 +107,7 @@ static void sys_cache_info(int *isize, int *dsize)
 static void arch_cache_info(int *isize, int *dsize)
 {
 if (*isize == 0 || *dsize == 0) {
-unsigned long ctr;
+uint64_t ctr;
 
 /* The real cache geometry is in CCSIDR_EL1/CLIDR_EL1/CSSELR_EL1,
but (at least under Linux) these are marked protected by the
-- 
2.17.1




[Qemu-devel] [PATCH v3 4/4] osdep: Fix mingw compilation regarding stdio formats

2019-05-02 Thread Cao Jiaxi
I encountered the following compilation error on mingw:

/mnt/d/qemu/include/qemu/osdep.h:97:9: error: '__USE_MINGW_ANSI_STDIO' macro 
redefined [-Werror,-Wmacro-redefined]
 #define __USE_MINGW_ANSI_STDIO 1
^
/mnt/d/llvm-mingw/aarch64-w64-mingw32/include/_mingw.h:433:9: note: previous 
definition is here
 #define __USE_MINGW_ANSI_STDIO 0  /* was not defined so it should be 0 */

It turns out that __USE_MINGW_ANSI_STDIO must be set before any
system headers are included, not just before stdio.h.

Signed-off-by: Cao Jiaxi 
---
 include/qemu/osdep.h | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 303d315c5d..af2b91f0b8 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -85,17 +85,17 @@ extern int daemon(int, int);
 #endif
 #endif
 
+/* enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later) */
+#ifdef __MINGW32__
+#define __USE_MINGW_ANSI_STDIO 1
+#endif
+
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
-
-/* enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later) */
-#ifdef __MINGW32__
-#define __USE_MINGW_ANSI_STDIO 1
-#endif
 #include 
 
 #include 
-- 
2.17.1






[Qemu-devel] [PATCH v3 1/4] QEMU_PACKED: Remove gcc_struct attribute in Windows non x86 targets

2019-05-02 Thread Cao Jiaxi
gcc_struct is for x86 only, and it generates an warning on ARM64 Clang/MinGW 
targets.

Signed-off-by: Cao Jiaxi 
---
 contrib/libvhost-user/libvhost-user.h | 2 +-
 include/qemu/compiler.h   | 2 +-
 scripts/cocci-macro-file.h| 7 ++-
 slirp/src/util.h  | 2 +-
 4 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/contrib/libvhost-user/libvhost-user.h 
b/contrib/libvhost-user/libvhost-user.h
index 414ceb0a2f..78b33306e8 100644
--- a/contrib/libvhost-user/libvhost-user.h
+++ b/contrib/libvhost-user/libvhost-user.h
@@ -148,7 +148,7 @@ typedef struct VhostUserInflight {
 uint16_t queue_size;
 } VhostUserInflight;
 
-#if defined(_WIN32)
+#if defined(_WIN32) && (defined(__x86_64__) || defined(__i386__))
 # define VU_PACKED __attribute__((gcc_struct, packed))
 #else
 # define VU_PACKED __attribute__((packed))
diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index 296b2fd572..09fc44cca4 100644
--- a/include/qemu/compiler.h
+++ b/include/qemu/compiler.h
@@ -28,7 +28,7 @@
 
 #define QEMU_SENTINEL __attribute__((sentinel))
 
-#if defined(_WIN32)
+#if defined(_WIN32) && (defined(__x86_64__) || defined(__i386__))
 # define QEMU_PACKED __attribute__((gcc_struct, packed))
 #else
 # define QEMU_PACKED __attribute__((packed))
diff --git a/scripts/cocci-macro-file.h b/scripts/cocci-macro-file.h
index e485cdccae..c6bbc05ba3 100644
--- a/scripts/cocci-macro-file.h
+++ b/scripts/cocci-macro-file.h
@@ -23,7 +23,12 @@
 #define QEMU_NORETURN __attribute__ ((__noreturn__))
 #define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
 #define QEMU_SENTINEL __attribute__((sentinel))
-#define QEMU_PACKED __attribute__((gcc_struct, packed))
+
+#if defined(_WIN32) && (defined(__x86_64__) || defined(__i386__))
+# define QEMU_PACKED __attribute__((gcc_struct, packed))
+#else
+# define QEMU_PACKED __attribute__((packed))
+#endif
 
 #define cat(x,y) x ## y
 #define cat2(x,y) cat(x,y)
diff --git a/slirp/src/util.h b/slirp/src/util.h
index 01f1e0e068..278828fe3f 100644
--- a/slirp/src/util.h
+++ b/slirp/src/util.h
@@ -43,7 +43,7 @@
 #include 
 #endif
 
-#if defined(_WIN32)
+#if defined(_WIN32) && (defined(__x86_64__) || defined(__i386__))
 # define SLIRP_PACKED __attribute__((gcc_struct, packed))
 #else
 # define SLIRP_PACKED __attribute__((packed))
-- 
2.17.1






[Qemu-devel] [PATCH v3 2/4] qga: Fix mingw compilation warnings on enum conversion

2019-05-02 Thread Cao Jiaxi
The win2qemu[] is supposed to be the conversion table to convert between
STORAGE_BUS_TYPE in Windows SDK and GuestDiskBusType in qga.

But it was incorrectly written that it forces to set a GuestDiskBusType
value to STORAGE_BUS_TYPE, which generates an enum conversion warning in clang.

Signed-off-by: Cao Jiaxi 
---
 qga/commands-win32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index d40d61f605..6b67f16faf 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -457,7 +457,7 @@ void qmp_guest_file_flush(int64_t handle, Error **errp)
 
 #ifdef CONFIG_QGA_NTDDSCSI
 
-static STORAGE_BUS_TYPE win2qemu[] = {
+static GuestDiskBusType win2qemu[] = {
 [BusTypeUnknown] = GUEST_DISK_BUS_TYPE_UNKNOWN,
 [BusTypeScsi] = GUEST_DISK_BUS_TYPE_SCSI,
 [BusTypeAtapi] = GUEST_DISK_BUS_TYPE_IDE,
-- 
2.17.1






[Qemu-devel] [PATCH v3 4/4] osdep: Fix mingw compilation regarding stdio formats

2019-05-02 Thread Cao Jiaxi
I encountered the following compilation error on mingw:

/mnt/d/qemu/include/qemu/osdep.h:97:9: error: '__USE_MINGW_ANSI_STDIO' macro 
redefined [-Werror,-Wmacro-redefined]
 #define __USE_MINGW_ANSI_STDIO 1
^
/mnt/d/llvm-mingw/aarch64-w64-mingw32/include/_mingw.h:433:9: note: previous 
definition is here
 #define __USE_MINGW_ANSI_STDIO 0  /* was not defined so it should be 0 */

It turns out that __USE_MINGW_ANSI_STDIO must be set before any
system headers are included, not just before stdio.h.

Signed-off-by: Cao Jiaxi 
---
 include/qemu/osdep.h | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 303d315c5d..af2b91f0b8 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -85,17 +85,17 @@ extern int daemon(int, int);
 #endif
 #endif
 
+/* enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later) */
+#ifdef __MINGW32__
+#define __USE_MINGW_ANSI_STDIO 1
+#endif
+
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
-
-/* enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later) */
-#ifdef __MINGW32__
-#define __USE_MINGW_ANSI_STDIO 1
-#endif
 #include 
 
 #include 
-- 
2.17.1




[Qemu-devel] [PATCH v3 2/4] qga: Fix mingw compilation warnings on enum conversion

2019-05-02 Thread Cao Jiaxi
The win2qemu[] is supposed to be the conversion table to convert between
STORAGE_BUS_TYPE in Windows SDK and GuestDiskBusType in qga.

But it was incorrectly written that it forces to set a GuestDiskBusType
value to STORAGE_BUS_TYPE, which generates an enum conversion warning in clang.

Signed-off-by: Cao Jiaxi 
---
 qga/commands-win32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index d40d61f605..6b67f16faf 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -457,7 +457,7 @@ void qmp_guest_file_flush(int64_t handle, Error **errp)
 
 #ifdef CONFIG_QGA_NTDDSCSI
 
-static STORAGE_BUS_TYPE win2qemu[] = {
+static GuestDiskBusType win2qemu[] = {
 [BusTypeUnknown] = GUEST_DISK_BUS_TYPE_UNKNOWN,
 [BusTypeScsi] = GUEST_DISK_BUS_TYPE_SCSI,
 [BusTypeAtapi] = GUEST_DISK_BUS_TYPE_IDE,
-- 
2.17.1




[Qemu-devel] [PATCH v3 1/4] QEMU_PACKED: Remove gcc_struct attribute in Windows non x86 targets

2019-05-02 Thread Cao Jiaxi
gcc_struct is for x86 only, and it generates an warning on ARM64 Clang/MinGW 
targets.

Signed-off-by: Cao Jiaxi 
---
 contrib/libvhost-user/libvhost-user.h | 2 +-
 include/qemu/compiler.h   | 2 +-
 scripts/cocci-macro-file.h| 7 ++-
 slirp/src/util.h  | 2 +-
 4 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/contrib/libvhost-user/libvhost-user.h 
b/contrib/libvhost-user/libvhost-user.h
index 414ceb0a2f..78b33306e8 100644
--- a/contrib/libvhost-user/libvhost-user.h
+++ b/contrib/libvhost-user/libvhost-user.h
@@ -148,7 +148,7 @@ typedef struct VhostUserInflight {
 uint16_t queue_size;
 } VhostUserInflight;
 
-#if defined(_WIN32)
+#if defined(_WIN32) && (defined(__x86_64__) || defined(__i386__))
 # define VU_PACKED __attribute__((gcc_struct, packed))
 #else
 # define VU_PACKED __attribute__((packed))
diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
index 296b2fd572..09fc44cca4 100644
--- a/include/qemu/compiler.h
+++ b/include/qemu/compiler.h
@@ -28,7 +28,7 @@
 
 #define QEMU_SENTINEL __attribute__((sentinel))
 
-#if defined(_WIN32)
+#if defined(_WIN32) && (defined(__x86_64__) || defined(__i386__))
 # define QEMU_PACKED __attribute__((gcc_struct, packed))
 #else
 # define QEMU_PACKED __attribute__((packed))
diff --git a/scripts/cocci-macro-file.h b/scripts/cocci-macro-file.h
index e485cdccae..c6bbc05ba3 100644
--- a/scripts/cocci-macro-file.h
+++ b/scripts/cocci-macro-file.h
@@ -23,7 +23,12 @@
 #define QEMU_NORETURN __attribute__ ((__noreturn__))
 #define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
 #define QEMU_SENTINEL __attribute__((sentinel))
-#define QEMU_PACKED __attribute__((gcc_struct, packed))
+
+#if defined(_WIN32) && (defined(__x86_64__) || defined(__i386__))
+# define QEMU_PACKED __attribute__((gcc_struct, packed))
+#else
+# define QEMU_PACKED __attribute__((packed))
+#endif
 
 #define cat(x,y) x ## y
 #define cat2(x,y) cat(x,y)
diff --git a/slirp/src/util.h b/slirp/src/util.h
index 01f1e0e068..278828fe3f 100644
--- a/slirp/src/util.h
+++ b/slirp/src/util.h
@@ -43,7 +43,7 @@
 #include 
 #endif
 
-#if defined(_WIN32)
+#if defined(_WIN32) && (defined(__x86_64__) || defined(__i386__))
 # define SLIRP_PACKED __attribute__((gcc_struct, packed))
 #else
 # define SLIRP_PACKED __attribute__((packed))
-- 
2.17.1






[Qemu-devel] [PATCH v3 0/4] Initial Windows on ARM (AArch64 64-Bit) host support

2019-05-02 Thread Cao Jiaxi
Initial Windows on ARM (AArch64 64-Bit) host support

This series of patches is for initial support of Windows 10 on ARM as a QEMU 
host.
Currently only TCG intepreter is working correctly, it crashes when TCG JIT is 
enabled.

For now we assume it is built using the clang aarch64-w64-mingw32 toolchain,
you can get a prebuilt toolchain at https://github.com/mstorsjo/llvm-mingw.

Cao Jiaxi (4):
  QEMU_PACKED: Remove gcc_struct attribute in Windows non x86 targets
  qga: Fix mingw compilation warnings on enum conversion
  util/cacheinfo: Use uint64_t on LLP64 model to satisfy Windows ARM64
  osdep: Fix mingw compilation regarding stdio formats

 contrib/libvhost-user/libvhost-user.h |  2 +-
 include/qemu/compiler.h   |  2 +-
 include/qemu/osdep.h  | 10 +-
 qga/commands-win32.c  |  2 +-
 scripts/cocci-macro-file.h|  7 ++-
 slirp/src/util.h  |  2 +-
 util/cacheinfo.c  |  2 +-
 7 files changed, 16 insertions(+), 11 deletions(-)

-- 
2.17.1






Re: [Qemu-devel] [PATCH 0/3] Cleanup migration/ram.c

2019-05-02 Thread Wei Yang
On Thu, May 02, 2019 at 09:35:50AM +0100, Dr. David Alan Gilbert wrote:
>* Wei Yang (richard.weiy...@gmail.com) wrote:
>> On Wed, May 01, 2019 at 09:24:06PM -0700, no-re...@patchew.org wrote:
>> >Patchew URL: 
>> >https://patchew.org/QEMU/20190430034412.12935-1-richardw.y...@linux.intel.com/
>> >
>> >
>> >
>> >Hi,
>> >
>> >This series failed the asan build test. Please find the testing commands and
>> >their output below. If you have Docker installed, you can probably 
>> >reproduce it
>> >locally.
>> >
>> >=== TEST SCRIPT BEGIN ===
>> >#!/bin/bash
>> >time make docker-test-debug@fedora TARGET_LIST=x86_64-softmmu J=14 NETWORK=1
>> >=== TEST SCRIPT END ===
>> >
>> >  COPYRUNNER
>> >RUN test-debug in qemu:fedora 
>> >container_linux.go:247: starting container process caused 
>> >"process_linux.go:258: applying cgroup configuration for process caused 
>> >\"The maximum number of active connections for UID 0 has been reached\""
>> >/usr/bin/docker-current: Error response from daemon: oci runtime error: The 
>> >maximum number of active connections for UID 0 has been reached.
>> >Traceback (most recent call last):
>> >  File "./tests/docker/docker.py", line 615, in 
>> >sys.exit(main())
>> >
>> 
>> May I ask how I can reproduce this?
>
>To me this just looks like patchew having a problem, I don't think it's
>a real qemu bug.

Ah, thanks. 

>
>Dave
>
>> >
>> >The full log is available at
>> >http://patchew.org/logs/20190430034412.12935-1-richardw.y...@linux.intel.com/testing.asan/?type=message.
>> >---
>> >Email generated automatically by Patchew [https://patchew.org/].
>> >Please send your feedback to patchew-de...@redhat.com
>> 
>> -- 
>> Wei Yang
>> Help you, Help me
>--
>Dr. David Alan Gilbert / dgilb...@redhat.com / Manchester, UK

-- 
Wei Yang
Help you, Help me



[Qemu-devel] [PULL 0/2] slirp: move slirp as git submodule project

2019-05-02 Thread Samuel Thibault
The following changes since commit 8482ff2eb3bb95020eb2f370a9b3ea26511e41df:

  Merge remote-tracking branch 'remotes/jnsnow/tags/bitmaps-pull-request' into 
staging (2019-05-02 12:04:51 +0100)

are available in the Git repository at:

  https://people.debian.org/~sthibault/qemu.git tags/samuel-thibault

for you to fetch changes up to 7c57bdd82026ba03f3158bbcd841afde7c2dc43a:

  build-sys: move slirp as git submodule project (2019-05-03 00:15:37 +0200)


slirp: move slirp as git submodule project

Marc-André Lureau (2):
  build-sys: pass CFLAGS & LDFLAGS to subdir-slirp
  build-sys: move slirp as git submodule project


Marc-André Lureau (2):
  build-sys: pass CFLAGS & LDFLAGS to subdir-slirp
  build-sys: move slirp as git submodule project

 .gitmodules   |3 +
 Makefile  |2 +-
 configure |   11 +-
 scripts/archive-source.sh |2 +-
 slirp |1 +
 slirp/COPYRIGHT   |   62 --
 slirp/Makefile|   47 --
 slirp/src/arp_table.c |   92 ---
 slirp/src/bootp.c |  371 ---
 slirp/src/bootp.h |  129 
 slirp/src/cksum.c |  161 -
 slirp/src/debug.h |   46 --
 slirp/src/dhcpv6.c|  224 ---
 slirp/src/dhcpv6.h|   53 --
 slirp/src/dnssearch.c |  311 -
 slirp/src/if.c|  218 ---
 slirp/src/if.h|   21 -
 slirp/src/ip.h|  242 ---
 slirp/src/ip6.h   |  160 -
 slirp/src/ip6_icmp.c  |  438 -
 slirp/src/ip6_icmp.h  |  232 ---
 slirp/src/ip6_input.c |   78 ---
 slirp/src/ip6_output.c|   39 --
 slirp/src/ip_icmp.c   |  470 --
 slirp/src/ip_icmp.h   |  166 -
 slirp/src/ip_input.c  |  469 --
 slirp/src/ip_output.c |  170 -
 slirp/src/libslirp.h  |  118 
 slirp/src/main.h  |   16 -
 slirp/src/mbuf.c  |  235 ---
 slirp/src/mbuf.h  |  127 
 slirp/src/misc.c  |  321 --
 slirp/src/misc.h  |   66 --
 slirp/src/ncsi-pkt.h  |  445 -
 slirp/src/ncsi.c  |  194 --
 slirp/src/ndp_table.c |   87 ---
 slirp/src/qtailq.h|  194 --
 slirp/src/sbuf.c  |  186 --
 slirp/src/sbuf.h  |   27 -
 slirp/src/slirp.c | 1118 
 slirp/src/slirp.h |  275 
 slirp/src/socket.c|  945 ---
 slirp/src/socket.h|  160 -
 slirp/src/state.c |  388 ---
 slirp/src/stream.c|  120 
 slirp/src/stream.h|   35 -
 slirp/src/tcp.h   |  181 --
 slirp/src/tcp_input.c | 1554 -
 slirp/src/tcp_output.c|  522 ---
 slirp/src/tcp_subr.c  |  987 
 slirp/src/tcp_timer.c |  294 -
 slirp/src/tcp_timer.h |  128 
 slirp/src/tcp_var.h   |  162 -
 slirp/src/tcpip.h |  102 ---
 slirp/src/tftp.c  |  463 --
 slirp/src/tftp.h  |   52 --
 slirp/src/udp.c   |  363 ---
 slirp/src/udp.h   |   92 ---
 slirp/src/udp6.c  |  173 -
 slirp/src/util.c  |  368 ---
 slirp/src/util.h  |  175 -
 slirp/src/vmstate.c   |  441 -
 slirp/src/vmstate.h   |  409 
 63 files changed, 15 insertions(+), 15726 deletions(-)
 create mode 16 slirp
 delete mode 100644 slirp/COPYRIGHT
 delete mode 100644 slirp/Makefile
 delete mode 100644 slirp/src/arp_table.c
 delete mode 100644 slirp/src/bootp.c
 delete mode 100644 slirp/src/bootp.h
 delete mode 100644 slirp/src/cksum.c
 delete mode 100644 slirp/src/debug.h
 delete mode 100644 slirp/src/dhcpv6.c
 delete mode 100644 slirp/src/dhcpv6.h
 delete mode 100644 slirp/src/dnssearch.c
 delete mode 100644 slirp/src/if.c
 delete mode 100644 slirp/src/if.h
 delete mode 100644 slirp/src/ip.h
 delete mode 100644 slirp/src/ip6.h
 delete mode 100644 slirp/src/ip6_icmp.c
 delete mode 100644 slirp/src/ip6_icmp.h
 delete mode 100644 slirp/src/ip6_input.c
 delete mode 100644 slirp/src/ip6_output.c
 delete mode 100644 slirp/src/ip_icmp.c
 delete mode 100644 slirp/src/ip_icmp.h
 delete mode 100644 slirp/src/ip_input.c
 delete mode 100644 slirp/src/ip_output.c
 delete mode 100644 slirp/src/libslirp.h
 delete mode 100644 slirp/src/main.h
 delete mode 100644 slirp/src/mbuf.c
 delete mode 100644 slirp/src/mbuf.h
 delete mode 100644 slirp/src/misc.c
 delete mode 100644 slirp/src/misc.h
 delete mode 100644 slirp/src/ncsi-pkt.h
 delete mode 100644 slirp/src/ncsi.c
 delete mode 100644 slirp/src/ndp_table.c
 delete mode 100644 slirp/src/qtailq.h
 delete mode 100644 slirp/src/sbuf.c
 delete mode 100644 slirp/src/sbuf.h
 delete mode 100644 slirp/src

[Qemu-devel] [PULL 1/2] build-sys: pass CFLAGS & LDFLAGS to subdir-slirp

2019-05-02 Thread Samuel Thibault
From: Marc-André Lureau 

CFLAGS/LDFLAGS have debug and sanitizers flags, which should be passed
to slirp compilation.

Signed-off-by: Marc-André Lureau 
Message-Id: <20190424110041.8175-2-marcandre.lur...@redhat.com>
Signed-off-by: Samuel Thibault 
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 1211e78c91..d372493042 100644
--- a/Makefile
+++ b/Makefile
@@ -480,7 +480,7 @@ subdir-capstone: .git-submodule-status
$(call quiet-command,$(MAKE) -C $(SRC_PATH)/capstone CAPSTONE_SHARED=no 
BUILDDIR="$(BUILD_DIR)/capstone" CC="$(CC)" AR="$(AR)" LD="$(LD)" 
RANLIB="$(RANLIB)" CFLAGS="$(CAP_CFLAGS)" $(SUBDIR_MAKEFLAGS) 
$(BUILD_DIR)/capstone/$(LIBCAPSTONE))
 
 subdir-slirp: .git-submodule-status
-   $(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp 
BUILD_DIR="$(BUILD_DIR)/slirp" CC="$(CC)" AR="$(AR)" LD="$(LD)" 
RANLIB="$(RANLIB)" CFLAGS="$(QEMU_CFLAGS)")
+   $(call quiet-command,$(MAKE) -C $(SRC_PATH)/slirp 
BUILD_DIR="$(BUILD_DIR)/slirp" CC="$(CC)" AR="$(AR)" LD="$(LD)" 
RANLIB="$(RANLIB)" CFLAGS="$(QEMU_CFLAGS) $(CFLAGS)" LDFLAGS="$(LDFLAGS)")
 
 $(SUBDIR_RULES): libqemuutil.a $(common-obj-y) $(chardev-obj-y) \
$(qom-obj-y) $(crypto-aes-obj-$(CONFIG_USER_ONLY))
-- 
2.20.1




Re: [Qemu-devel] [PATCH v2 2/4] qga: Fix an enum conversion warningincommands-win32.c, hit by clang.

2019-05-02 Thread GH Cao
On 5/3/19 6:20 AM, Eric Blake wrote:

> Where is enum STORAGE_BUS_TYPE defined? 
In the Windows SDK (winioctl.h), so a two-way conversion table is needed.

> In fact, it looks like win2qemu[] is supposed to be that table,
> but it was incorrectly written.  You WANT to do:

> diff --git i/qga/commands-win32.c w/qga/commands-win32.c
> index d40d61f605c..6b67f16faf1 100644
> --- i/qga/commands-win32.c
> +++ w/qga/commands-win32.c
> @@ -457,7 +457,7 @@ void qmp_guest_file_flush(int64_t handle, Error **errp)
>
> #ifdef CONFIG_QGA_NTDDSCSI
>
> -static STORAGE_BUS_TYPE win2qemu[] = {
> +static GuestDiskBusType win2qemu[] = {
> [BusTypeUnknown] = GUEST_DISK_BUS_TYPE_UNKNOWN,
> [BusTypeScsi] = GUEST_DISK_BUS_TYPE_SCSI,
> [BusTypeAtapi] = GUEST_DISK_BUS_TYPE_IDE,
>
> with no casts needed, either in the table or in the function that
> references the table.

Yes, I can confirm that fixes the issue, and clearly better than my previous 
effort.
I'll use this instead in my upcoming v3 patch set.

Re: [Qemu-devel] Failing QEMU iotest 221

2019-05-02 Thread Eric Blake
On 4/28/19 10:21 AM, Thomas Huth wrote:
> QEMU iotest 221 is failing for me, too, when I run it with -raw:

Which filesystem?

> 
> tests/qemu-iotests$ ./check -raw 221
> QEMU  -- 
> "/home/thuth/tmp/qemu-build/tests/qemu-iotests/../../x86_64-softmmu/qemu-system-x86_64"
>  -nodefaults -machine accel=qtest
> QEMU_IMG  -- 
> "/home/thuth/tmp/qemu-build/tests/qemu-iotests/../../qemu-img" 
> QEMU_IO   -- 
> "/home/thuth/tmp/qemu-build/tests/qemu-iotests/../../qemu-io"  --cache 
> writeback -f raw
> QEMU_NBD  -- 
> "/home/thuth/tmp/qemu-build/tests/qemu-iotests/../../qemu-nbd" 
> IMGFMT-- raw
> IMGPROTO  -- file
> PLATFORM  -- Linux/x86_64 thuth 3.10.0-957.10.1.el7.x86_64
> TEST_DIR  -- /home/thuth/tmp/qemu-build/tests/qemu-iotests/scratch
> SOCKET_SCM_HELPER -- 
> /home/thuth/tmp/qemu-build/tests/qemu-iotests/socket_scm_helper
> 
> 221 - output mismatch (see 221.out.bad)
> --- /home/thuth/devel/qemu/tests/qemu-iotests/221.out 2019-04-23 
> 16:43:12.0 +0200
> +++ /home/thuth/tmp/qemu-build/tests/qemu-iotests/221.out.bad 2019-04-28 
> 17:18:52.0 +0200
> @@ -7,10 +7,10 @@
>  [{ "start": 0, "length": 43520, "depth": 0, "zero": true, "data": false, 
> "offset": OFFSET}]
>  wrote 1/1 bytes at offset 43008
>  1 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
> -[{ "start": 0, "length": 40960, "depth": 0, "zero": true, "data": false, 
> "offset": OFFSET},
> -{ "start": 40960, "length": 2049, "depth": 0, "zero": false, "data": true, 
> "offset": OFFSET},
> +[{ "start": 0, "length": 43008, "depth": 0, "zero": true, "data": false, 
> "offset": OFFSET},
> +{ "start": 43008, "length": 1, "depth": 0, "zero": false, "data": true, 
> "offset": OFFSET},

Ugh. Hole granularities are file-system specific, so we need to figure
out some way to fuzz the input. It might also be possible to pick nicer
size numbers - perhaps if the test image is sized at 64k+1 instead of
43009 (84*512, but NOT evenly divisible by 4k), the +1 byte is more
likely to be directly one a hole boundary, rather than being somewhere
that causes rounding the hole boundary 2k earlier because of 4k or 64k
sizing constraints.

> Any ideas how to fix this?
> 
>  Thomas
> 

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] Failing QEMU iotest 175

2019-05-02 Thread Eric Blake
On 4/28/19 10:18 AM, Thomas Huth wrote:
> QEMU iotest 175 is failing for me when I run it with -raw:
> 

>  == creating image with default preallocation ==
>  Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576
> -size=1048576, blocks=0
> +size=1048576, blocks=2

What filesystem? It should be fairly obvious that 'stat -c blocks=%b' is
file-system dependent (some allocate slightly more or less space, based
on granularities and on predictions of future use), so we may need to
update the test to apply a filter or otherwise allow a bit of fuzz in
the answer. But 0/2 is definitely different than...
> 
>  == creating image with preallocation off ==
>  Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=off
> -size=1048576, blocks=0
> +size=1048576, blocks=2
> 
>  == creating image with preallocation full ==
>  Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 preallocation=full
> -size=1048576, blocks=2048
> +size=1048576, blocks=2050

2048/2050, so we DO have some indication of whether the file is sparse
or fully allocated.

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v2 2/4] qga: Fix an enum conversion warningin commands-win32.c, hit by clang.

2019-05-02 Thread Eric Blake
On 5/2/19 4:18 PM, driver1998 wrote:
> On 5/1/19 2:25 AM, Eric Blake wrote:
>> This adds lots of explicit casts. Are they actually necessary? Without
>> seeing the actual warning, it seems fishy to have to be this explicit.
> 
> So here are the warnings, on clang version 9.0.0 (trunk 351977).
> 
> qga/commands-win32.c:461:24: error: implicit conversion from enumeration type 
> 'enum GuestDiskBusType' to different
>   enumeration type 'STORAGE_BUS_TYPE' (aka 'enum _STORAGE_BUS_TYPE') 
> [-Werror,-Wenum-conversion]
> [BusTypeUnknown] = GUEST_DISK_BUS_TYPE_UNKNOWN,
>^~~

> qga/commands-win32.c:486:12: error: implicit conversion from enumeration type 
> 'STORAGE_BUS_TYPE'
>   (aka 'enum _STORAGE_BUS_TYPE') to different enumeration type 
> 'GuestDiskBusType' (aka 'enum GuestDiskBusType')
>   [-Werror,-Wenum-conversion]
> return win2qemu[(int)bus];
> ~~ ^~

Where is enum STORAGE_BUS_TYPE defined? I see GuestDiskBusType (via
qga/qapi-schema.json's 'enum':'GuestDiskBusType'), but if
STORAGE_BUS_TYPE is a type declared by some external project, we are
probably better off writing a two-way conversion table or switch
statement, rather than relying on the two enums currently happening to
have identical values (but where that might break if we accidentally
rearrange our .json QAPI file or if the external file changes their
enum).  In fact, it looks like win2qemu[] is supposed to be that table,
but it was incorrectly written.  You WANT to do:

diff --git i/qga/commands-win32.c w/qga/commands-win32.c
index d40d61f605c..6b67f16faf1 100644
--- i/qga/commands-win32.c
+++ w/qga/commands-win32.c
@@ -457,7 +457,7 @@ void qmp_guest_file_flush(int64_t handle, Error **errp)

 #ifdef CONFIG_QGA_NTDDSCSI

-static STORAGE_BUS_TYPE win2qemu[] = {
+static GuestDiskBusType win2qemu[] = {
 [BusTypeUnknown] = GUEST_DISK_BUS_TYPE_UNKNOWN,
 [BusTypeScsi] = GUEST_DISK_BUS_TYPE_SCSI,
 [BusTypeAtapi] = GUEST_DISK_BUS_TYPE_IDE,

with no casts needed, either in the table or in the function that
references the table.

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v2 4/4] include/qemu/osdep.h: Move the__USE_MINGW_ANSI_STDIO define up to avoid confliction.

2019-05-02 Thread Eric Blake
On 5/2/19 4:05 PM, driver1998 wrote:
> On 5/1/19 2:30 AM, Eric Blake wrote:
>> Your entire series is missing 'In-Reply-To:' and 'References:' headers,
>> making each message show up as individual new threads rather than
>> properly threaded to a 0/4 cover letter. You'll want to fix your sending
>> habits to avoid that problem in future submissions.
> 
> I am terribly sorry about that, this is the first time I summit patches, and 
> I am still getting used to the tooling.

That's okay, we were all first-timers once; and most human maintainers
try to be more forgiving than automated tools when it comes to working
around first-timer learning curves. There may be other useful hints you
can use at https://wiki.qemu.org/Contribute/SubmitAPatch

> Thank you for pointing out the issue though.
> 
>> It's unusual to use a trailing '.' in the subject line. Also, your
>> subject is very long; commit message summaries should typically be
>> around 60-70 characters because 'git log' shows them with further
>> indentation, where an 80-column terminal window makes it hard to see the
>> tail at a glance.  Better might be a short subject line explaining the
>> "what", and then a non-empty commit message explaining the "why"
> 
> Thank you for pointing out, I'll update that in the upcoming v3 set.
> 
>> Question - does it hurt to make the define of __USE_MINGW_ANSI_STDIO
>> unconditional?  In other words, we're unlikely to break any non-mingw
>> platform if we drop the #ifdef __MINGW32__ line.
> 
> I personally have no idea, so I'll keep it as is.

Fair enough for your patch.

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v2 2/4] qga: Fix an enum conversion warningin commands-win32.c, hit by clang.

2019-05-02 Thread driver1998
On 5/1/19 2:25 AM, Eric Blake wrote:
> This adds lots of explicit casts. Are they actually necessary? Without
> seeing the actual warning, it seems fishy to have to be this explicit.

So here are the warnings, on clang version 9.0.0 (trunk 351977).

qga/commands-win32.c:461:24: error: implicit conversion from enumeration type 
'enum GuestDiskBusType' to different
  enumeration type 'STORAGE_BUS_TYPE' (aka 'enum _STORAGE_BUS_TYPE') 
[-Werror,-Wenum-conversion]
[BusTypeUnknown] = GUEST_DISK_BUS_TYPE_UNKNOWN,
   ^~~
qga/commands-win32.c:462:21: error: implicit conversion from enumeration type 
'enum GuestDiskBusType' to different
  enumeration type 'STORAGE_BUS_TYPE' (aka 'enum _STORAGE_BUS_TYPE') 
[-Werror,-Wenum-conversion]
[BusTypeScsi] = GUEST_DISK_BUS_TYPE_SCSI,
^~~~
qga/commands-win32.c:463:22: error: implicit conversion from enumeration type 
'enum GuestDiskBusType' to different
  enumeration type 'STORAGE_BUS_TYPE' (aka 'enum _STORAGE_BUS_TYPE') 
[-Werror,-Wenum-conversion]
[BusTypeAtapi] = GUEST_DISK_BUS_TYPE_IDE,
 ^~~
qga/commands-win32.c:464:20: error: implicit conversion from enumeration type 
'enum GuestDiskBusType' to different
  enumeration type 'STORAGE_BUS_TYPE' (aka 'enum _STORAGE_BUS_TYPE') 
[-Werror,-Wenum-conversion]
[BusTypeAta] = GUEST_DISK_BUS_TYPE_IDE,
   ^~~
qga/commands-win32.c:465:21: error: implicit conversion from enumeration type 
'enum GuestDiskBusType' to different
  enumeration type 'STORAGE_BUS_TYPE' (aka 'enum _STORAGE_BUS_TYPE') 
[-Werror,-Wenum-conversion]
[BusType1394] = GUEST_DISK_BUS_TYPE_IEEE1394,
^~~~
qga/commands-win32.c:466:20: error: implicit conversion from enumeration type 
'enum GuestDiskBusType' to different
  enumeration type 'STORAGE_BUS_TYPE' (aka 'enum _STORAGE_BUS_TYPE') 
[-Werror,-Wenum-conversion]
[BusTypeSsa] = GUEST_DISK_BUS_TYPE_SSA,
   ^~~
qga/commands-win32.c:467:22: error: implicit conversion from enumeration type 
'enum GuestDiskBusType' to different
  enumeration type 'STORAGE_BUS_TYPE' (aka 'enum _STORAGE_BUS_TYPE') 
[-Werror,-Wenum-conversion]
[BusTypeFibre] = GUEST_DISK_BUS_TYPE_SSA,
 ^~~
qga/commands-win32.c:468:20: error: implicit conversion from enumeration type 
'enum GuestDiskBusType' to different
  enumeration type 'STORAGE_BUS_TYPE' (aka 'enum _STORAGE_BUS_TYPE') 
[-Werror,-Wenum-conversion]
[BusTypeUsb] = GUEST_DISK_BUS_TYPE_USB,
   ^~~
qga/commands-win32.c:469:21: error: implicit conversion from enumeration type 
'enum GuestDiskBusType' to different
  enumeration type 'STORAGE_BUS_TYPE' (aka 'enum _STORAGE_BUS_TYPE') 
[-Werror,-Wenum-conversion]
[BusTypeRAID] = GUEST_DISK_BUS_TYPE_RAID,
^~~~
qga/commands-win32.c:470:22: error: implicit conversion from enumeration type 
'enum GuestDiskBusType' to different
  enumeration type 'STORAGE_BUS_TYPE' (aka 'enum _STORAGE_BUS_TYPE') 
[-Werror,-Wenum-conversion]
[BusTypeiScsi] = GUEST_DISK_BUS_TYPE_ISCSI,
  CC  qga/qapi-generated/qga-qapi-visit.o
 ^
qga/commands-win32.c:471:20: error: implicit conversion from enumeration type 
'enum GuestDiskBusType' to different
  enumeration type 'STORAGE_BUS_TYPE' (aka 'enum _STORAGE_BUS_TYPE') 
[-Werror,-Wenum-conversion]
[BusTypeSas] = GUEST_DISK_BUS_TYPE_SAS,
   ^~~
qga/commands-win32.c:472:21: error: implicit conversion from enumeration type 
'enum GuestDiskBusType' to different
  enumeration type 'STORAGE_BUS_TYPE' (aka 'enum _STORAGE_BUS_TYPE') 
[-Werror,-Wenum-conversion]
[BusTypeSata] = GUEST_DISK_BUS_TYPE_SATA,
^~~~
qga/commands-win32.c:473:20: error: implicit conversion from enumeration type 
'enum GuestDiskBusType' to different
  enumeration type 'STORAGE_BUS_TYPE' (aka 'enum _STORAGE_BUS_TYPE') 
[-Werror,-Wenum-conversion]
[BusTypeSd] =  GUEST_DISK_BUS_TYPE_SD,
   ^~
qga/commands-win32.c:474:20: error: implicit conversion from enumeration type 
'enum GuestDiskBusType' to different
  enumeration type 'STORAGE_BUS_TYPE' (aka 'enum _STORAGE_BUS_TYPE') 
[-Werror,-Wenum-conversion]
[BusTypeMmc] = GUEST_DISK_BUS_TYPE_MMC,
   ^~~
qga/commands-win32.c:486:12: error: implicit conversion from enumeration type 
'STORAGE_BUS_TYPE'
  (aka 'enum _STORAGE_BUS_TYPE') to different enumeration type 
'GuestDiskBusType' (aka 'enum GuestDiskBusType')
  [-Werror,-Wenum-conversion]
return win2qemu[(int)bus];
~~ ^~

> Or is it complaining that GuestDiskBusType and STORAGE_BUS_TYPE ar

Re: [Qemu-devel] [PATCH v2 4/4] include/qemu/osdep.h: Move the__USE_MINGW_ANSI_STDIO define up to avoid confliction.

2019-05-02 Thread driver1998
On 5/1/19 2:30 AM, Eric Blake wrote:
> Your entire series is missing 'In-Reply-To:' and 'References:' headers,
> making each message show up as individual new threads rather than
> properly threaded to a 0/4 cover letter. You'll want to fix your sending
> habits to avoid that problem in future submissions.

I am terribly sorry about that, this is the first time I summit patches, and I 
am still getting used to the tooling.
Thank you for pointing out the issue though.

> It's unusual to use a trailing '.' in the subject line. Also, your
> subject is very long; commit message summaries should typically be
> around 60-70 characters because 'git log' shows them with further
> indentation, where an 80-column terminal window makes it hard to see the
> tail at a glance.  Better might be a short subject line explaining the
> "what", and then a non-empty commit message explaining the "why"

Thank you for pointing out, I'll update that in the upcoming v3 set.

> Question - does it hurt to make the define of __USE_MINGW_ANSI_STDIO
> unconditional?  In other words, we're unlikely to break any non-mingw
> platform if we drop the #ifdef __MINGW32__ line.

I personally have no idea, so I'll keep it as is.

Re: [Qemu-devel] [PATCH for-4.1 6/8] target/riscv: Split RVC32 and RVC64 insns into separate files

2019-05-02 Thread Alistair Francis
On Thu, Apr 25, 2019 at 9:04 AM Palmer Dabbelt  wrote:
>
> On Sun, 31 Mar 2019 20:11:53 PDT (-0700), richard.hender...@linaro.org wrote:
> > This eliminates all functions in insn_trans/trans_rvc.inc.c,
> > so the entire file can be removed.
> >
> > Signed-off-by: Richard Henderson 

You need to remove the line in: target/riscv/translate.c:710
#include "insn_trans/trans_rvc.inc.c"

otherwise this patch doesn't compile.

Alistair

> > ---
> >  target/riscv/insn_trans/trans_rvc.inc.c | 115 
> >  target/riscv/translate.c|   2 -
> >  target/riscv/Makefile.objs  |   9 +-
> >  target/riscv/insn16-32.decode   |  28 ++
> >  target/riscv/insn16-64.decode   |  30 +++
> >  target/riscv/insn16.decode  |  35 +---
> >  6 files changed, 67 insertions(+), 152 deletions(-)
> >  delete mode 100644 target/riscv/insn_trans/trans_rvc.inc.c
> >  create mode 100644 target/riscv/insn16-32.decode
> >  create mode 100644 target/riscv/insn16-64.decode
> >
> > diff --git a/target/riscv/insn_trans/trans_rvc.inc.c 
> > b/target/riscv/insn_trans/trans_rvc.inc.c
> > deleted file mode 100644
> > index 43bff97f66..00
> > --- a/target/riscv/insn_trans/trans_rvc.inc.c
> > +++ /dev/null
> > @@ -1,115 +0,0 @@
> > -/*
> > - * RISC-V translation routines for the RVC Compressed Instruction Set.
> > - *
> > - * Copyright (c) 2016-2017 Sagar Karandikar, sag...@eecs.berkeley.edu
> > - * Copyright (c) 2018 Peer Adelt, peer.ad...@hni.uni-paderborn.de
> > - *Bastian Koppelmann, kbast...@mail.uni-paderborn.de
> > - *
> > - * This program is free software; you can redistribute it and/or modify it
> > - * under the terms and conditions of the GNU General Public License,
> > - * version 2 or later, as published by the Free Software Foundation.
> > - *
> > - * This program is distributed in the hope it will be useful, but WITHOUT
> > - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> > - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
> > for
> > - * more details.
> > - *
> > - * You should have received a copy of the GNU General Public License along 
> > with
> > - * this program.  If not, see .
> > - */
> > -
> > -static bool trans_c_flw_ld(DisasContext *ctx, arg_c_flw_ld *a)
> > -{
> > -#ifdef TARGET_RISCV32
> > -/* C.FLW ( RV32FC-only ) */
> > -REQUIRE_FPU;
> > -REQUIRE_EXT(ctx, RVF);
> > -
> > -arg_i arg;
> > -decode_insn16_extract_cl_w(&arg, ctx->opcode);
> > -return trans_flw(ctx, &arg);
> > -#else
> > -/* C.LD ( RV64C/RV128C-only ) */
> > -arg_i arg;
> > -decode_insn16_extract_cl_d(&arg, ctx->opcode);
> > -return trans_ld(ctx, &arg);
> > -#endif
> > -}
> > -
> > -static bool trans_c_fsw_sd(DisasContext *ctx, arg_c_fsw_sd *a)
> > -{
> > -#ifdef TARGET_RISCV32
> > -/* C.FSW ( RV32FC-only ) */
> > -REQUIRE_FPU;
> > -REQUIRE_EXT(ctx, RVF);
> > -
> > -arg_s arg;
> > -decode_insn16_extract_cs_w(&arg, ctx->opcode);
> > -return trans_fsw(ctx, &arg);
> > -#else
> > -/* C.SD ( RV64C/RV128C-only ) */
> > -arg_s arg;
> > -decode_insn16_extract_cs_d(&arg, ctx->opcode);
> > -return trans_sd(ctx, &arg);
> > -#endif
> > -}
> > -
> > -static bool trans_c_jal_addiw(DisasContext *ctx, arg_c_jal_addiw *a)
> > -{
> > -#ifdef TARGET_RISCV32
> > -/* C.JAL */
> > -arg_j tmp;
> > -decode_insn16_extract_cj(&tmp, ctx->opcode);
> > -arg_jal arg = { .rd = 1, .imm = tmp.imm };
> > -return trans_jal(ctx, &arg);
> > -#else
> > -/* C.ADDIW */
> > -arg_addiw arg = { .rd = a->rd, .rs1 = a->rd, .imm = a->imm };
> > -return trans_addiw(ctx, &arg);
> > -#endif
> > -}
> > -
> > -static bool trans_c_subw(DisasContext *ctx, arg_c_subw *a)
> > -{
> > -#ifdef TARGET_RISCV64
> > -return trans_subw(ctx, a);
> > -#else
> > -return false;
> > -#endif
> > -}
> > -
> > -static bool trans_c_addw(DisasContext *ctx, arg_c_addw *a)
> > -{
> > -#ifdef TARGET_RISCV64
> > -return trans_addw(ctx, a);
> > -#else
> > -return false;
> > -#endif
> > -}
> > -
> > -static bool trans_c_flwsp_ldsp(DisasContext *ctx, arg_c_flwsp_ldsp *a)
> > -{
> > -#ifdef TARGET_RISCV32
> > -/* C.FLWSP */
> > -arg_flw arg_flw = { .rd = a->rd, .rs1 = 2, .imm = a->uimm_flwsp };
> > -return trans_flw(ctx, &arg_flw);
> > -#else
> > -/* C.LDSP */
> > -arg_ld arg_ld = { .rd = a->rd, .rs1 = 2, .imm = a->uimm_ldsp };
> > -return trans_ld(ctx, &arg_ld);
> > -#endif
> > -return false;
> > -}
> > -
> > -static bool trans_c_fswsp_sdsp(DisasContext *ctx, arg_c_fswsp_sdsp *a)
> > -{
> > -#ifdef TARGET_RISCV32
> > -/* C.FSWSP */
> > -arg_fsw a_fsw = { .rs1 = 2, .rs2 = a->rs2, .imm = a->uimm_fswsp };
> > -return trans_fsw(ctx, &a_fsw);
> > -#else
> > -/* C.SDSP */
> > -arg_sd a_sd = { .rs1 = 2, .rs2 = a->rs2, .imm = a->uimm_sdsp };
> > -return trans_sd(ctx, &a_sd);
> > 

Re: [Qemu-devel] [PATCH 0/4] Remove some qdev_get_machine() calls from CONFIG_USER_ONLY

2019-05-02 Thread Eduardo Habkost
On Fri, Apr 26, 2019 at 04:55:17PM +0800, Like Xu wrote:
> On 2019/4/26 4:00, Eduardo Habkost wrote:
> > This series moves some qdev code outside qdev.o, so it can be
> > compiled only in CONFIG_SOFTMMU.
> > 
> > The code being moved includes two qdev_get_machine() calls, so
> > this will make it easier to move qdev_get_machine() to
> > CONFIG_SOFTMMU later.
> > 
> > After this series, there's one remaining qdev_get_machine() call
> > that seems more difficult to remove:
> > 
> >  static void device_set_realized(Object *obj, bool value, Error **errp)
> >  {
> >  /* [...] */
> >  if (!obj->parent) {
> >  gchar *name = g_strdup_printf("device[%d]", 
> > unattached_count++);
> > 
> >  object_property_add_child(container_get(qdev_get_machine(),
> >  "/unattached"),
> >name, obj, &error_abort);
> >  unattached_parent = true;
> >  g_free(name);
> >  }
> >  /* [...] */
> >  }
> > 
> 
> I may have an experimental patch to fix device_set_realized issue:
> 
> 1. in qdev_get_machine():
> replace
>   dev = container_get(object_get_root(), "/machine");
> with
>   dev = object_resolve_path("/machine", NULL);
> 
> 2. in device_set_realized():
> 
> Using
>   Object *container = qdev_get_machine() ?
>   qdev_get_machine() : object_get_root();
> and pass it to
>   object_property_add_child(
>   container_get(container, "/unattached"),
>   name, obj, &error_abort);

I wouldn't like to call qdev_get_machine() here (see below[1]),
but trying "/machine" first and falling back to object_get_root()
sounds good, for two reasons:

* It won't require "/machine" to exist at all, on *-user;
* It will allow machines to create unattached devices on
  instance_init without crashing (which is not possible today).

> 
> With this fix, we could say the qdev_get_machine() does
> return the "/machine" object (or null) not a confused "/container".
> 
> We could continue to use qdev_get_machine() in system emulation mode,
> getting rid of its surprising side effect as Markus said.
> 
> The return value of qdev_get_machine() in user-only mode
> is the same object returned by object_get_root(),
> so no semantic changes.

[1] I wouldn't like to have a different qdev_get_machine()
function in user-only mode.  I would like to simply not call
qdev_get_machine() at all unless we're in system emulation mode.

-- 
Eduardo



[Qemu-devel] [PULL 12/13] hw/sparc/leon3: Allow load of uImage firmwares

2019-05-02 Thread Laurent Vivier
From: Philippe Mathieu-Daudé 

Currently the Leon3 machine doesn't allow to load legacy u-boot images:

  $ qemu-system-sparc -M leon3_generic -d in_asm \
  -kernel HelenOS-0.6.0-sparc32-leon3.bin
  qemu-system-sparc: could not load kernel 'HelenOS-0.6.0-sparc32-leon3.bin'

  $ file HelenOS-0.6.0-sparc32-leon3.bin
  HelenOS-0.6.0-sparc32-leon3.bin: u-boot legacy uImage, HelenOS-0.6.0,\
Linux/ARM, OS Kernel Image (Not compressed), 2424229 bytes,\
Sun Dec 21 19:18:09 2014,\
Load Address: 0x4000, Entry Point: 0x4000,\
Header CRC: 0x8BCFA236, Data CRC: 0x37AD87DF

Since QEMU can load uImages, add the necessary code,
so the Leon3 machine can load these images:

  $ qemu-system-sparc -M leon3_generic -d in_asm \
  -kernel HelenOS-0.6.0-sparc32-leon3.bin
  
  IN:
  0x4000:  b  0x47a8
  0x4004:  nop
  
  IN:
  0x47a8:  save  %sp, -136, %sp
  0x47ac:  call  0x4020
  0x47b0:  sethi  %hi(0x4000b800), %i1
  ...

Tested with the following firmware:
http://www.helenos.org/releases/HelenOS-0.6.0-sparc32-leon3.bin

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: KONRAD Frederic 
Tested-by: KONRAD Frederic 
Message-Id: <20190427162922.4207-1-f4...@amsat.org>
Signed-off-by: Laurent Vivier 
---
 hw/sparc/leon3.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
index 774639af3393..0383b17c298f 100644
--- a/hw/sparc/leon3.c
+++ b/hw/sparc/leon3.c
@@ -193,6 +193,10 @@ static void leon3_generic_hw_init(MachineState *machine)
 kernel_size = load_elf(kernel_filename, NULL, NULL, NULL,
&entry, NULL, NULL,
1 /* big endian */, EM_SPARC, 0, 0);
+if (kernel_size < 0) {
+kernel_size = load_uimage(kernel_filename, NULL, &entry,
+  NULL, NULL, NULL);
+}
 if (kernel_size < 0) {
 error_report("could not load kernel '%s'", kernel_filename);
 exit(1);
-- 
2.20.1




[Qemu-devel] [PULL 07/13] configure: fix pam test warning

2019-05-02 Thread Laurent Vivier
From: "Dr. David Alan Gilbert" 

The pam test generates a warning on Fedora 29 with -O3 compilation
because the headers declare that the pam_conversation pointer to
pam_start must be non-NULL.  Change it to use the same 0 initialised
structure as we actually use in qauthz.

Signed-off-by: Dr. David Alan Gilbert 
Acked-by: Daniel P. Berrangé 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20190404091725.20595-1-dgilb...@redhat.com>
Signed-off-by: Laurent Vivier 
---
 configure | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 60719ddcc5b0..a2607afb3408 100755
--- a/configure
+++ b/configure
@@ -2940,9 +2940,9 @@ if test "$auth_pam" != "no"; then
 int main(void) {
const char *service_name = "qemu";
const char *user = "frank";
-   const struct pam_conv *pam_conv = NULL;
+   const struct pam_conv pam_conv = { 0 };
pam_handle_t *pamh = NULL;
-   pam_start(service_name, user, pam_conv, &pamh);
+   pam_start(service_name, user, &pam_conv, &pamh);
return 0;
 }
 EOF
-- 
2.20.1




[Qemu-devel] [PULL 13/13] sockets: avoid string truncation warnings when copying UNIX path

2019-05-02 Thread Laurent Vivier
From: Daniel P. Berrangé 

In file included from /usr/include/string.h:494,
 from include/qemu/osdep.h:101,
 from util/qemu-sockets.c:18:
In function ‘strncpy’,
inlined from ‘unix_connect_saddr.isra.0’ at util/qemu-sockets.c:925:5:
/usr/include/bits/string_fortified.h:106:10: warning: ‘__builtin_strncpy’ 
specified bound 108 equals destination size [-Wstringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
  |  ^~
In function ‘strncpy’,
inlined from ‘unix_listen_saddr.isra.0’ at util/qemu-sockets.c:880:5:
/usr/include/bits/string_fortified.h:106:10: warning: ‘__builtin_strncpy’ 
specified bound 108 equals destination size [-Wstringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
  |  ^~

We are already validating the UNIX socket path length earlier in
the functions. If we save this string length when we first check
it, then we can simply use memcpy instead of strcpy later, avoiding
the gcc truncation warnings.

Signed-off-by: Daniel P. Berrangé 
Reviewed-by: Eric Blake 
Reviewed-by: Stefano Garzarella 
Message-Id: <20190501145052.12579-1-berra...@redhat.com>
Signed-off-by: Laurent Vivier 
---
 util/qemu-sockets.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 970505169000..ba6335e71a95 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -830,6 +830,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,
 int sock, fd;
 char *pathbuf = NULL;
 const char *path;
+size_t pathlen;
 
 sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
 if (sock < 0) {
@@ -845,7 +846,8 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,
 path = pathbuf = g_strdup_printf("%s/qemu-socket-XX", tmpdir);
 }
 
-if (strlen(path) > sizeof(un.sun_path)) {
+pathlen = strlen(path);
+if (pathlen > sizeof(un.sun_path)) {
 error_setg(errp, "UNIX socket path '%s' is too long", path);
 error_append_hint(errp, "Path must be less than %zu bytes\n",
   sizeof(un.sun_path));
@@ -877,7 +879,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,
 
 memset(&un, 0, sizeof(un));
 un.sun_family = AF_UNIX;
-strncpy(un.sun_path, path, sizeof(un.sun_path));
+memcpy(un.sun_path, path, pathlen);
 
 if (bind(sock, (struct sockaddr*) &un, sizeof(un)) < 0) {
 error_setg_errno(errp, errno, "Failed to bind socket to %s", path);
@@ -901,6 +903,7 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, 
Error **errp)
 {
 struct sockaddr_un un;
 int sock, rc;
+size_t pathlen;
 
 if (saddr->path == NULL) {
 error_setg(errp, "unix connect: no path specified");
@@ -913,7 +916,8 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, 
Error **errp)
 return -1;
 }
 
-if (strlen(saddr->path) > sizeof(un.sun_path)) {
+pathlen = strlen(saddr->path);
+if (pathlen > sizeof(un.sun_path)) {
 error_setg(errp, "UNIX socket path '%s' is too long", saddr->path);
 error_append_hint(errp, "Path must be less than %zu bytes\n",
   sizeof(un.sun_path));
@@ -922,7 +926,7 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, 
Error **errp)
 
 memset(&un, 0, sizeof(un));
 un.sun_family = AF_UNIX;
-strncpy(un.sun_path, saddr->path, sizeof(un.sun_path));
+memcpy(un.sun_path, saddr->path, pathlen);
 
 /* connect to peer */
 do {
-- 
2.20.1




[Qemu-devel] [PULL 02/13] CODING_STYLE: specify the indent rule for multiline code

2019-05-02 Thread Laurent Vivier
From: Wei Yang 

We didn't specify the indent rule for multiline code here, which may
mislead users. And in current code, the code use various styles.

Add this rule in CODING_STYLE to make sure this is clear to every one.

Signed-off-by: Wei Yang 
Suggested-by: Igor Mammedov 
Reviewed-by: Igor Mammedov 
Reviewed-by: Stefano Garzarella 
Message-Id: <20190304071631.27567-2-richardw.y...@linux.intel.com>
Signed-off-by: Laurent Vivier 
---
 CODING_STYLE | 39 +++
 1 file changed, 39 insertions(+)

diff --git a/CODING_STYLE b/CODING_STYLE
index ec075dedc4a8..90321e9c2821 100644
--- a/CODING_STYLE
+++ b/CODING_STYLE
@@ -29,6 +29,45 @@ Spaces of course are superior to tabs because:
 
 Do not leave whitespace dangling off the ends of lines.
 
+1.1 Multiline Indent
+
+There are several places where indent is necessary:
+
+ - if/else
+ - while/for
+ - function definition & call
+
+When breaking up a long line to fit within line width, we need a proper indent
+for the following lines.
+
+In case of if/else, while/for, align the secondary lines just after the
+opening parenthesis of the first.
+
+For example:
+
+if (a == 1 &&
+b == 2) {
+
+while (a == 1 &&
+   b == 2) {
+
+In case of function, there are several variants:
+
+* 4 spaces indent from the beginning
+* align the secondary lines just after the opening parenthesis of the
+  first
+
+For example:
+
+do_something(x, y,
+z);
+
+do_something(x, y,
+ z);
+
+do_something(x, do_another(y,
+   z));
+
 2. Line width
 
 Lines should be 80 characters; try not to make them longer.
-- 
2.20.1




[Qemu-devel] [PULL 10/13] net: Print output of "-net nic, model=help" to stdout instead of stderr

2019-05-02 Thread Laurent Vivier
From: Thomas Huth 

We are printing all other help output to stdout already (e.g. "-help",
"-cpu help" and "-machine help" output). So the "-net nic,model=help"
output should go to stdout instead of stderr, too. And while we're at
it, also print the NICs line by line, like we do it e.g. with the
"-cpu help" or "-M help" output, too.

Buglink: https://bugs.launchpad.net/qemu/+bug/1574327
Signed-off-by: Thomas Huth 
Reviewed-by: Eric Blake 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20190423160608.7519-1-th...@redhat.com>
Signed-off-by: Laurent Vivier 
---
 net/net.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/net.c b/net/net.c
index f3a3c5444cc3..2cf5e7646997 100644
--- a/net/net.c
+++ b/net/net.c
@@ -837,9 +837,10 @@ int qemu_show_nic_models(const char *arg, const char 
*const *models)
 return 0;
 }
 
-fprintf(stderr, "qemu: Supported NIC models: ");
-for (i = 0 ; models[i]; i++)
-fprintf(stderr, "%s%c", models[i], models[i+1] ? ',' : '\n');
+printf("Supported NIC models:\n");
+for (i = 0 ; models[i]; i++) {
+printf("%s\n", models[i]);
+}
 return 1;
 }
 
-- 
2.20.1




[Qemu-devel] [PULL 06/13] qom: use object_new_with_type in object_new_with_propv

2019-05-02 Thread Laurent Vivier
From: Wei Yang 

Function object_new_with_propv already get the Type of the object, so we
could leverage object_new_with_type here.

Signed-off-by: Wei Yang 
Reviewed-by: Marc-André Lureau 
Reviewed-by: Stefano Garzarella 
Message-Id: <20190311083234.20841-1-richardw.y...@linux.intel.com>
Signed-off-by: Laurent Vivier 
---
 qom/object.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qom/object.c b/qom/object.c
index e3206d6799ee..d3412e7fdca6 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -679,7 +679,7 @@ Object *object_new_with_propv(const char *typename,
 error_setg(errp, "object type '%s' is abstract", typename);
 return NULL;
 }
-obj = object_new(typename);
+obj = object_new_with_type(klass->type);
 
 if (object_set_propv(obj, &local_err, vargs) < 0) {
 goto error;
-- 
2.20.1




[Qemu-devel] [PULL 11/13] Makefile: Let the 'clean' rule remove qemu-ga.exe on Windows hosts

2019-05-02 Thread Laurent Vivier
From: Philippe Mathieu-Daudé 

Commit 48ff7a625b36 added the QEMU Guest Agent tool with the
optional ".exe" suffix for Windows hosts, but forgot to use
this suffix in the 'clean' rule. Calling this rule let a dangling
executable in the build directory.
Correct this by using the proper optional suffix.

Fixes: 48ff7a625b36
Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Stefan Weil 
Message-Id: <20190427161322.24642-1-phi...@redhat.com>
Signed-off-by: Laurent Vivier 
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 43a7a047b452..e223bfe2a3a1 100644
--- a/Makefile
+++ b/Makefile
@@ -639,7 +639,7 @@ clean:
! -path ./roms/edk2/BaseTools/Source/Python/UPT/Dll/sqlite3.dll 
\
-exec rm {} +
rm -f $(edk2-decompressed)
-   rm -f $(filter-out %.tlb,$(TOOLS)) $(HELPERS-y) qemu-ga TAGS cscope.* 
*.pod *~ */*~
+   rm -f $(filter-out %.tlb,$(TOOLS)) $(HELPERS-y) qemu-ga$(EXESUF) TAGS 
cscope.* *.pod *~ */*~
rm -f fsdev/*.pod scsi/*.pod
rm -f qemu-img-cmds.h
rm -f ui/shader/*-vert.h ui/shader/*-frag.h
-- 
2.20.1




[Qemu-devel] [PULL 03/13] CODING_STYLE: indent example code as all others

2019-05-02 Thread Laurent Vivier
From: Wei Yang 

All the example code are indented with four spaces except this one.

Fix this by adding four spaces here.

Signed-off-by: Wei Yang 
Reviewed-by: Eric Blake 
Reviewed-by: Philippe Mathieu-Daudé 
Reviewed-by: Igor Mammedov 
Reviewed-by: Stefano Garzarella 
Message-Id: <20190304071631.27567-3-richardw.y...@linux.intel.com>
Signed-off-by: Laurent Vivier 
---
 CODING_STYLE | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/CODING_STYLE b/CODING_STYLE
index 90321e9c2821..cb8edcbb3692 100644
--- a/CODING_STYLE
+++ b/CODING_STYLE
@@ -147,10 +147,10 @@ block to a separate function altogether.
 When comparing a variable for (in)equality with a constant, list the
 constant on the right, as in:
 
-if (a == 1) {
-/* Reads like: "If a equals 1" */
-do_something();
-}
+if (a == 1) {
+/* Reads like: "If a equals 1" */
+do_something();
+}
 
 Rationale: Yoda conditions (as in 'if (1 == a)') are awkward to read.
 Besides, good compilers already warn users when '==' is mis-typed as '=',
-- 
2.20.1




[Qemu-devel] [PULL 05/13] doc: fix the configuration path

2019-05-02 Thread Laurent Vivier
From: Marc-André Lureau 

Use a CONFDIR variable to show the configured sysconf path in the
generated documentations (html, man pages etc).

Related to:
https://bugzilla.redhat.com/show_bug.cgi?id=1644985

Signed-off-by: Marc-André Lureau 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20181126105125.30973-1-marcandre.lur...@redhat.com>
Signed-off-by: Laurent Vivier 
---
 qemu-ga.texi | 4 ++--
 Makefile | 9 ++---
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/qemu-ga.texi b/qemu-ga.texi
index 4c7a8fd16329..f00ad830f283 100644
--- a/qemu-ga.texi
+++ b/qemu-ga.texi
@@ -30,7 +30,7 @@ set user's password
 @end itemize
 
 qemu-ga will read a system configuration file on startup (located at
-@file{/etc/qemu/qemu-ga.conf} by default), then parse remaining
+@file{@value{CONFDIR}/qemu-ga.conf} by default), then parse remaining
 configuration options on the command line. For the same key, the last
 option wins, but the lists accumulate (see below for configuration
 file format).
@@ -58,7 +58,7 @@ file format).
   Enable fsfreeze hook. Accepts an optional argument that specifies
   script to run on freeze/thaw. Script will be called with
   'freeze'/'thaw' arguments accordingly (default is
-  @samp{/etc/qemu/fsfreeze-hook}). If using -F with an argument, do
+  @samp{@value{CONFDIR}/fsfreeze-hook}). If using -F with an argument, do
   not follow -F with a space (for example:
   @samp{-F/var/run/fsfreezehook.sh}).
 
diff --git a/Makefile b/Makefile
index 1211e78c91ed..43a7a047b452 100644
--- a/Makefile
+++ b/Makefile
@@ -899,11 +899,14 @@ ui/shader.o: $(SRC_PATH)/ui/shader.c \
 MAKEINFO=makeinfo
 MAKEINFOINCLUDES= -I docs -I $( $@,"GEN","$@")
+docs/version.texi: $(SRC_PATH)/VERSION config-host.mak
+   $(call quiet-command,(\
+   echo "@set VERSION $(VERSION)" && \
+   echo "@set CONFDIR $(qemu_confdir)" \
+   )> $@,"GEN","$@")
 
 %.html: %.texi docs/version.texi
$(call quiet-command,LC_ALL=C $(MAKEINFO) $(MAKEINFOFLAGS) --no-headers 
\
-- 
2.20.1




[Qemu-devel] [PULL 09/13] Header cleanups

2019-05-02 Thread Laurent Vivier
From: Aruna Jayasena 

Removed unwanted includes from cpu-common.h
This task was under https://wiki.qemu.org/Contribute/BiteSizedTasks

Signed-off-by: Aruna Jayasena 
Reviewed-by: Peter Maydell 
Reviewed-by: Thomas Huth 
Message-Id: <20190409155635.10276-1-aruna...@cse.mrt.ac.lk>
[lv: fix conflict on rebase]
Signed-off-by: Laurent Vivier 
---
 include/exec/cpu-common.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 848a4b94ab73..f7dbe75fbc38 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -7,9 +7,6 @@
 #include "exec/hwaddr.h"
 #endif
 
-#include "qemu/bswap.h"
-#include "qemu/queue.h"
-
 /* The CPU list lock nests outside page_(un)lock or mmap_(un)lock */
 void qemu_init_cpu_list(void);
 void cpu_list_lock(void);
-- 
2.20.1




[Qemu-devel] [PULL 00/13] Trivial branch patches

2019-05-02 Thread Laurent Vivier
The following changes since commit 8482ff2eb3bb95020eb2f370a9b3ea26511e41df:

  Merge remote-tracking branch 'remotes/jnsnow/tags/bitmaps-pull-request' into 
staging (2019-05-02 12:04:51 +0100)

are available in the Git repository at:

  git://github.com/vivier/qemu.git tags/trivial-branch-pull-request

for you to fetch changes up to f7c03a68b814254df414977ff299468fbf0fa1c0:

  sockets: avoid string truncation warnings when copying UNIX path (2019-05-02 
20:50:47 +0200)


Pull request trivial branch 2019-05-02



Aruna Jayasena (1):
  Header cleanups

Daniel P. Berrangé (1):
  sockets: avoid string truncation warnings when copying UNIX path

Dr. David Alan Gilbert (1):
  configure: fix pam test warning

Marc-André Lureau (1):
  doc: fix the configuration path

Markus Armbruster (1):
  Clean up includes

Philippe Mathieu-Daudé (3):
  hw/net/pcnet: Use qemu_log_mask(GUEST_ERROR) instead of printf
  Makefile: Let the 'clean' rule remove qemu-ga.exe on Windows hosts
  hw/sparc/leon3: Allow load of uImage firmwares

Stefan Weil (1):
  Update configure

Thomas Huth (1):
  net: Print output of "-net nic, model=help" to stdout instead of
stderr

Wei Yang (3):
  CODING_STYLE: specify the indent rule for multiline code
  CODING_STYLE: indent example code as all others
  qom: use object_new_with_type in object_new_with_propv

 qemu-ga.texi  |  4 ++--
 configure |  5 ++---
 Makefile  | 11 +
 hw/display/ati_int.h  |  1 -
 include/exec/cpu-common.h |  3 ---
 include/hw/cpu/cluster.h  |  1 -
 tests/fp/platform.h   |  1 -
 tests/libqos/qgraph.h |  4 
 contrib/elf2dmp/main.c|  3 +--
 contrib/elf2dmp/pdb.c |  3 +--
 hw/display/ati.c  |  1 +
 hw/display/ati_2d.c   |  1 +
 hw/display/ati_dbg.c  |  1 +
 hw/net/pcnet.c|  4 +++-
 hw/sparc/leon3.c  |  4 
 net/net.c |  7 +++---
 qom/object.c  |  2 +-
 tests/qos-test.c  |  2 +-
 util/qemu-sockets.c   | 12 ++
 CODING_STYLE  | 47 +++
 20 files changed, 80 insertions(+), 37 deletions(-)

-- 
2.20.1




[Qemu-devel] [PULL 04/13] Clean up includes

2019-05-02 Thread Laurent Vivier
From: Markus Armbruster 

Clean up includes so that osdep.h is included first and headers
which it implies are not included manually.

This commit was created with scripts/clean-includes, with the changes
to the following files manually reverted:

contrib/libvhost-user/libvhost-user-glib.h
contrib/libvhost-user/libvhost-user.c
contrib/libvhost-user/libvhost-user.h
linux-user/mips64/cpu_loop.c
linux-user/mips64/signal.c
linux-user/sparc64/cpu_loop.c
linux-user/sparc64/signal.c
linux-user/x86_64/cpu_loop.c
linux-user/x86_64/signal.c
slirp/src/*
target/s390x/gen-features.c
tests/migration/s390x/a-b-bios.c
tests/test-rcu-simpleq.c
tests/test-rcu-tailq.c
tests/uefi-test-tools/UefiTestToolsPkg/BiosTablesTest/BiosTablesTest.c

We're in the process of spinning out slirp/.  tests/uefi-test-tools/
is guest software.  The remaining reverts are the same as in commit
b7d89466dde.

Signed-off-by: Markus Armbruster 
Reviewed-by: Eric Blake 
Reviewed-by: Thomas Huth 
Message-Id: <20190313162812.8885-1-arm...@redhat.com>
Signed-off-by: Laurent Vivier 
---
 hw/display/ati_int.h | 1 -
 include/hw/cpu/cluster.h | 1 -
 tests/fp/platform.h  | 1 -
 tests/libqos/qgraph.h| 4 
 contrib/elf2dmp/main.c   | 3 +--
 contrib/elf2dmp/pdb.c| 3 +--
 hw/display/ati.c | 1 +
 hw/display/ati_2d.c  | 1 +
 hw/display/ati_dbg.c | 1 +
 tests/qos-test.c | 2 +-
 10 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/hw/display/ati_int.h b/hw/display/ati_int.h
index a6f3e20e6319..2f426064cf7d 100644
--- a/hw/display/ati_int.h
+++ b/hw/display/ati_int.h
@@ -9,7 +9,6 @@
 #ifndef ATI_INT_H
 #define ATI_INT_H
 
-#include "qemu/osdep.h"
 #include "hw/pci/pci.h"
 #include "vga_int.h"
 
diff --git a/include/hw/cpu/cluster.h b/include/hw/cpu/cluster.h
index 549c2d31d438..01c1e50cd221 100644
--- a/include/hw/cpu/cluster.h
+++ b/include/hw/cpu/cluster.h
@@ -20,7 +20,6 @@
 #ifndef HW_CPU_CLUSTER_H
 #define HW_CPU_CLUSTER_H
 
-#include "qemu/osdep.h"
 #include "hw/qdev.h"
 
 /*
diff --git a/tests/fp/platform.h b/tests/fp/platform.h
index c20ba70baa07..f8c423dde3dc 100644
--- a/tests/fp/platform.h
+++ b/tests/fp/platform.h
@@ -29,7 +29,6 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 
THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-#include "config-host.h"
 
 #ifndef HOST_WORDS_BIGENDIAN
 #define LITTLEENDIAN 1
diff --git a/tests/libqos/qgraph.h b/tests/libqos/qgraph.h
index ef0c73837a60..e799095b308a 100644
--- a/tests/libqos/qgraph.h
+++ b/tests/libqos/qgraph.h
@@ -19,11 +19,7 @@
 #ifndef QGRAPH_H
 #define QGRAPH_H
 
-#include 
-#include 
-#include 
 #include 
-#include 
 #include "qemu/module.h"
 #include "malloc.h"
 
diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c
index 1bfeb89ba7bd..9a2dbc290214 100644
--- a/contrib/elf2dmp/main.c
+++ b/contrib/elf2dmp/main.c
@@ -5,9 +5,8 @@
  *
  */
 
-#include 
-
 #include "qemu/osdep.h"
+
 #include "err.h"
 #include "addrspace.h"
 #include "pe.h"
diff --git a/contrib/elf2dmp/pdb.c b/contrib/elf2dmp/pdb.c
index 64af20f5842e..a5bd40c99dca 100644
--- a/contrib/elf2dmp/pdb.c
+++ b/contrib/elf2dmp/pdb.c
@@ -18,9 +18,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include 
-
 #include "qemu/osdep.h"
+
 #include "pdb.h"
 #include "err.h"
 
diff --git a/hw/display/ati.c b/hw/display/ati.c
index db409be3c958..75716dd944ec 100644
--- a/hw/display/ati.c
+++ b/hw/display/ati.c
@@ -16,6 +16,7 @@
  * No 3D at all yet (maybe after 2D works, but feel free to improve it)
  */
 
+#include "qemu/osdep.h"
 #include "ati_int.h"
 #include "ati_regs.h"
 #include "vga_regs.h"
diff --git a/hw/display/ati_2d.c b/hw/display/ati_2d.c
index bc98ba6eebf6..f31b3c27c7d8 100644
--- a/hw/display/ati_2d.c
+++ b/hw/display/ati_2d.c
@@ -7,6 +7,7 @@
  * This work is licensed under the GNU GPL license version 2 or later.
  */
 
+#include "qemu/osdep.h"
 #include "ati_int.h"
 #include "ati_regs.h"
 #include "qemu/log.h"
diff --git a/hw/display/ati_dbg.c b/hw/display/ati_dbg.c
index 1e6c32624e5a..b045f81d0602 100644
--- a/hw/display/ati_dbg.c
+++ b/hw/display/ati_dbg.c
@@ -1,3 +1,4 @@
+#include "qemu/osdep.h"
 #include "ati_int.h"
 
 #ifdef DEBUG_ATI
diff --git a/tests/qos-test.c b/tests/qos-test.c
index 6b1145ecccff..ae2fb5de1c9b 100644
--- a/tests/qos-test.c
+++ b/tests/qos-test.c
@@ -16,8 +16,8 @@
  * License along with this library; if not, see 
  */
 
-#include 
 #include "qemu/osdep.h"
+#include 
 #include "libqtest.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qbool.h"
-- 
2.20.1




[Qemu-devel] [PULL 08/13] Update configure

2019-05-02 Thread Laurent Vivier
From: Stefan Weil 

The last *.aml file was removed in commit 
13b1881aacc7e5018773bd545bbaf8d5476699ee.

Signed-off-by: Stefan Weil 
Reviewed-by: Igor Mammedov 
Reviewed-by: Philippe Mathieu-Daudé 
Message-Id: <20190409053320.14612-1...@weilnetz.de>
Signed-off-by: Laurent Vivier 
---
 configure | 1 -
 1 file changed, 1 deletion(-)

diff --git a/configure b/configure
index a2607afb3408..14f02452f9d4 100755
--- a/configure
+++ b/configure
@@ -7880,7 +7880,6 @@ LINKS="$LINKS python"
 for bios_file in \
 $source_path/pc-bios/*.bin \
 $source_path/pc-bios/*.lid \
-$source_path/pc-bios/*.aml \
 $source_path/pc-bios/*.rom \
 $source_path/pc-bios/*.dtb \
 $source_path/pc-bios/*.img \
-- 
2.20.1




[Qemu-devel] [PULL 01/13] hw/net/pcnet: Use qemu_log_mask(GUEST_ERROR) instead of printf

2019-05-02 Thread Laurent Vivier
From: Philippe Mathieu-Daudé 

Avoid to clutter stdout until explicitly requested
(with -d guest_errors):

  $ qemu-system-mips -M malta -m 512 -kernel vmlinux-3.2.0-4-4kc-malta
  Bad SWSTYLE=0x04

Signed-off-by: Philippe Mathieu-Daudé 
Reviewed-by: Thomas Huth 
Message-Id: <20190311102712.8572-1-phi...@redhat.com>
Signed-off-by: Laurent Vivier 
---
 hw/net/pcnet.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/net/pcnet.c b/hw/net/pcnet.c
index d9ba04bdfc62..16683091c939 100644
--- a/hw/net/pcnet.c
+++ b/hw/net/pcnet.c
@@ -36,6 +36,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/log.h"
 #include "hw/qdev.h"
 #include "net/net.h"
 #include "net/eth.h"
@@ -1501,7 +1502,8 @@ static void pcnet_bcr_writew(PCNetState *s, uint32_t rap, 
uint32_t val)
 val |= 0x0300;
 break;
 default:
-printf("Bad SWSTYLE=0x%02x\n", val & 0xff);
+qemu_log_mask(LOG_GUEST_ERROR, "pcnet: Bad SWSTYLE=0x%02x\n",
+  val & 0xff);
 val = 0x0200;
 break;
 }
-- 
2.20.1




Re: [Qemu-devel] [PATCH v4 13/15] tests: acpi: add simple arm/virt testcase

2019-05-02 Thread Laszlo Ersek
On 05/02/19 16:52, Igor Mammedov wrote:
> adds simple arm/virt test case that starts guest with
> bios-tables-test.aarch64.iso.qcow2 boot image which
> initializes UefiTestSupport* structure in RAM once
> guest is booted.
> 
>  * see commit: tests: acpi: add acpi_find_rsdp_address_uefi() helper
> 
> Signed-off-by: Igor Mammedov 
> Reviewed-by: Laszlo Ersek 
> Reviewed-by: Philippe Mathieu-Daudé 
> Tested-by: Philippe Mathieu-Daudé 
> ---
> v4:
>   * force test to use TCG accelerator
> v3:
>   * use firmware blobs directly from pc-bios directory
>   * use bios-tables-test.aarch64.iso.qcow2 as test boot image
>   * drop leftover qtest-uefi-images-aarch64 iMakefile rule from
> previos version (Laszlo)
>   * add Makefile rule to include bios-tables-test into
> check-qtest-aarch64 target
> v2:
>   * specify in test_data where board's RAM starts and RAM size
> 
> fixup! tests: acpi: add simple arm/virt testcase
> 
> Signed-off-by: Igor Mammedov 
> ---
>  tests/Makefile.include   |  1 +
>  tests/bios-tables-test.c | 18 ++
>  2 files changed, 19 insertions(+)
> 
> diff --git a/tests/Makefile.include b/tests/Makefile.include
> index e2432d5..983c8b1 100644
> --- a/tests/Makefile.include
> +++ b/tests/Makefile.include
> @@ -267,6 +267,7 @@ check-qtest-arm-y += tests/hexloader-test$(EXESUF)
>  check-qtest-aarch64-y = tests/numa-test$(EXESUF)
>  check-qtest-aarch64-y += tests/boot-serial-test$(EXESUF)
>  check-qtest-aarch64-y += tests/migration-test$(EXESUF)
> +check-qtest-aarch64-y += tests/bios-tables-test$(EXESUF)
>  
>  check-qtest-microblazeel-y += $(check-qtest-microblaze-y)
>  
> diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c
> index 39c1e24..eaa1b0c 100644
> --- a/tests/bios-tables-test.c
> +++ b/tests/bios-tables-test.c
> @@ -810,6 +810,22 @@ static void test_acpi_piix4_tcg_dimm_pxm(void)
>  test_acpi_tcg_dimm_pxm(MACHINE_PC);
>  }
>  
> +static void test_acpi_virt_tcg(void)
> +{
> +test_data data = {
> +.machine = "virt",
> +.accel = "tcg",
> +.uefi_fl1 = "pc-bios/edk2-aarch64-code.fd",
> +.uefi_fl2 = "pc-bios/edk2-arm-vars.fd",
> +.cd = 
> "tests/data/uefi-boot-images/bios-tables-test.aarch64.iso.qcow2",
> +.ram_start = 0x4000ULL,
> +.scan_len = 128ULL * 1024 * 1024,
> +};
> +
> +test_acpi_one("-cpu cortex-a57", &data);
> +free_test_data(&data);
> +}
> +
>  int main(int argc, char *argv[])
>  {
>  const char *arch = qtest_get_arch();
> @@ -838,6 +854,8 @@ int main(int argc, char *argv[])
>  qtest_add_func("acpi/q35/numamem", test_acpi_q35_tcg_numamem);
>  qtest_add_func("acpi/piix4/dimmpxm", test_acpi_piix4_tcg_dimm_pxm);
>  qtest_add_func("acpi/q35/dimmpxm", test_acpi_q35_tcg_dimm_pxm);
> +} else if (strcmp(arch, "aarch64") == 0) {
> +qtest_add_func("acpi/virt", test_acpi_virt_tcg);
>  }
>  ret = g_test_run();
>  boot_sector_cleanup(disk);
> 

my R-b stands

thanks
Laszlo



Re: [Qemu-devel] [PATCH v4 11/15] tests: acpi: allow to override default accelerator

2019-05-02 Thread Laszlo Ersek
On 05/02/19 16:51, Igor Mammedov wrote:
> By default test cases were run with 'kvm:tcg' accelerators to speed up
> tests execution. While it works for x86, were change of accelerator
> doesn't affect ACPI tables, the approach doesn't works for ARM usecase
> though.
> 
> In arm/virt case, KVM mode requires using 'host' cpu model, which
> isn't available in TCG mode. That could be worked around with 'max'
> cpu model, which works both for KVM and TCG. However in KVM mode it
> is necessary to specify matching GIC version, which also could use
> 'max' value to automatically pick GIC version suitable for host's CPU.
> Depending on host cpu type, different GIC versions would be used,
> which in turn leads to different ACPI tables (APIC) generated.
> As result while comparing with reference blobs, test would fail if
> host's GIC version won't match the version on the host where
> reference blobs where generated.
> 
> Let's keep testing simple for now and allow ARM tests run in TCG only
> mode. To do so introduce 'accel' parameter in test configuration, so
> test case could override default "kvm:tcg" with accelerator of choice.
> 
> Signed-off-by: Igor Mammedov 
> ---
>  tests/bios-tables-test.c | 8 +---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c
> index 8302ffc..39c1e24 100644
> --- a/tests/bios-tables-test.c
> +++ b/tests/bios-tables-test.c
> @@ -24,6 +24,7 @@
>  #define ACPI_REBUILD_EXPECTED_AML "TEST_ACPI_REBUILD_AML"
>  
>  typedef struct {
> +const char *accel;
>  const char *machine;
>  const char *variant;
>  const char *uefi_fl1;
> @@ -532,8 +533,8 @@ static void test_acpi_one(const char *params, test_data 
> *data)
>  args = g_strdup_printf("-machine %s,accel=%s -nodefaults -nographic "
>  "-drive if=pflash,format=raw,file=%s,readonly "
>  "-drive if=pflash,format=raw,file=%s,snapshot=on -cdrom %s %s",
> -data->machine, "kvm:tcg", data->uefi_fl1, data->uefi_fl2,
> -data->cd, params ? params : "");
> +data->machine, data->accel ? data->accel : "kvm:tcg",
> +data->uefi_fl1, data->uefi_fl2, data->cd, params ? params : "");
>  
>  } else {
>  /* Disable kernel irqchip to be able to override apic irq0. */
> @@ -541,7 +542,8 @@ static void test_acpi_one(const char *params, test_data 
> *data)
>  "-net none -display none %s "
>  "-drive id=hd0,if=none,file=%s,format=raw "
>  "-device ide-hd,drive=hd0 ",
> - data->machine, "kvm:tcg", params ? params : "", disk);
> + data->machine, data->accel ? data->accel : "kvm:tcg",
> + params ? params : "", disk);
>  }
>  
>  data->qts = qtest_init(args);
> 

Reviewed-by: Laszlo Ersek 



Re: [Qemu-devel] [PATCH v2 1/5] util/qemu-sockets: Fix GCC 9 build warnings

2019-05-02 Thread Alistair Francis
On Wed, May 1, 2019 at 2:41 AM Daniel P. Berrangé  wrote:
>
> On Tue, Apr 30, 2019 at 11:28:22PM +, Alistair Francis wrote:
> > Fix this warning when building with GCC9 on Fedora 30:
> > In function ‘strncpy’,
> > inlined from ‘unix_connect_saddr.isra.0’ at util/qemu-sockets.c:925:5:
> > /usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ 
> > specified bound 108 equals destination size [-Werror=stringop-truncation]
> >   106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos 
> > (__dest));
> >   |  
> > ^~
> > In function ‘strncpy’,
> > inlined from ‘unix_listen_saddr.isra.0’ at util/qemu-sockets.c:880:5:
> >
> > Signed-off-by: Alistair Francis 
> > ---
> >  util/qemu-sockets.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
> > index 9705051690..8c3322958f 100644
> > --- a/util/qemu-sockets.c
> > +++ b/util/qemu-sockets.c
> > @@ -829,7 +829,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,
> >  struct sockaddr_un un;
> >  int sock, fd;
> >  char *pathbuf = NULL;
> > -const char *path;
> > +const char *path QEMU_NONSTRING;
> >
> >  sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
> >  if (sock < 0) {
> > @@ -922,7 +922,7 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, 
> > Error **errp)
> >
> >  memset(&un, 0, sizeof(un));
> >  un.sun_family = AF_UNIX;
> > -strncpy(un.sun_path, saddr->path, sizeof(un.sun_path));
> > +memcpy(un.sun_path, saddr->path, MIN(strlen(saddr->path), 
> > sizeof(un.sun_path)));
> >
> >  /* connect to peer */
> >  do {
>
> I think my proposed fix for this file is preferrable as it avoids
> repeated strlen calls
>
>   https://lists.gnu.org/archive/html/qemu-devel/2019-04/msg02124.html

That's fine with me, I have dropped this patch.

Alistair

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



Re: [Qemu-devel] [RFC] Virtio RNG: Consider changing the default entropy source to /dev/urandom?

2019-05-02 Thread Kashyap Chamarthy
[Reviving this old thread as I don't think we came to a conclusion on
this.]

On Fri, Sep 21, 2018 at 05:43:23PM +0200, Kashyap Chamarthy wrote:
> Hi folks,
> 
> As Markus pointed out in this 'qemu-devel' thread[1],
> backends/rng-random.c uses '/dev/random' in TYPE_RNG_RANDOM's
> instance_init() method:
> 
> [...]
> static void rng_random_init(Object *obj)
> {
> RngRandom *s = RNG_RANDOM(obj);
> 
> object_property_add_str(obj, "filename",
> rng_random_get_filename,
> rng_random_set_filename,
> NULL);
> 
> s->filename = g_strdup("/dev/random");
> s->fd = -1;
> }
> [...]
> 
> And I've looked at hw/virtio/virtio-rng.c:
> 
> [...]
> static void virtio_rng_device_realize(DeviceState *dev, Error **errp)
> {
> [...]
> 
> if (vrng->conf.rng == NULL) {
> vrng->conf.default_backend = 
> RNG_RANDOM(object_new(TYPE_RNG_RANDOM));
> [...]
> 
> From the above, I'm assuming QEMU uses `/dev/random` as the _default_
> entropy source for a 'virtio-rng-pci' device.  If my assumption is
> correct, any reason why not to change the default entropy source for
> 'virtio-rng-pci' devices to `/dev/urandom` (which is the preferred[2]
> source of entropy)?
> 
> And I understand (thanks: Eric Blake for correcting my confusion) that
> there are two cases to distinguish:
> 
> (a) When QEMU needs a random number, the entropy source it chooses.
> IIUC, the answer is: QEMU defers to GnuTLS by default, which uses
> getrandom(2), which in turn uses '/dev/urandom' as its entropy
> source; if getrandom(2) isn't available, GnuTLS uses `/dev/urandom`
> anyway.  (Thanks: Nikos for clarifying this.)
> 
> If QEMU is built with GnuTLS _disabled_, which I'm not sure if any
> Linux distribution does, then it uses libgcrypt, which in turn uses
> the undesired and legacy `/dev/random` as the default entropy
> source.
> 
> (b) When QEMU exposes a Virtio RNG device to the guest, that device
> needs a source of entropy, and IIUC, that source needs to be
> "non-blocking" (i.e. `/dev/urandom`).  However, currently QEMU
> defaults to the problematic `/dev/random`.
> 
> I'd like to get some more clarity on case (b).  
> 
> 
> [1] https://lists.nongnu.org/archive/html/qemu-devel/2018-06/msg08335.html
> -- RNG: Any reason QEMU doesn't default to `/dev/urandom`
> 
> [2] http://man7.org/linux/man-pages/man4/urandom.4.html
> 
> 
> -- 
> /kashyap
> 

-- 
/kashyap



Re: [Qemu-devel] [PATCH v2 2/5] hw/usb/hcd-xhci: Fix GCC 9 build warning

2019-05-02 Thread Alistair Francis
On Wed, May 1, 2019 at 7:12 AM Richard Henderson
 wrote:
>
> On 4/30/19 4:28 PM, Alistair Francis wrote:
> >  for (i = 0; i < usbports; i++) {
> > +g_assert(i < MAX(MAXPORTS_2, MAXPORTS_3));
>
> I would hope that it works to move this out of the loop:
>
>   g_assert(usbports <= MAX(MAXPORTS_2, MAXPORTS_3));

Yes, that also works. I have updated the patch.

Alistair

>
>
> r~



Re: [Qemu-devel] [PATCH v2 3/5] hw/usb/dev-mtp: Fix GCC 9 build warning

2019-05-02 Thread Alistair Francis
On Wed, May 1, 2019 at 2:40 AM Daniel P. Berrangé  wrote:
>
> On Tue, Apr 30, 2019 at 11:28:41PM +, Alistair Francis wrote:
> > Fix this warning with GCC 9 on Fedora 30:
> > hw/usb/dev-mtp.c:1715:36: error: taking address of packed member of ‘struct 
> > ’ may result in an unaligned pointer value 
> > [-Werror=address-of-packed-member]
> >  1715 | dataset->filename);
> >   | ~~~^~
> >
> > Signed-off-by: Alistair Francis 
> > ---
> >  hw/usb/dev-mtp.c | 13 +
> >  1 file changed, 13 insertions(+)
> >
> > diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
> > index 99548b012d..8233beacab 100644
> > --- a/hw/usb/dev-mtp.c
> > +++ b/hw/usb/dev-mtp.c
> > @@ -1711,9 +1711,22 @@ static void usb_mtp_write_metadata(MTPState *s, 
> > uint64_t dlen)
> >  assert(!s->write_pending);
> >  assert(p != NULL);
> >
> > +/*
> > + * We are about to access a packed struct. We are confident that the 
> > pointer
> > + * address won't be unaligned, so we ignore GCC warnings.
> > + */
>
> The data is mis-aligned as we're accessing an int16 array that
> is immediately following an int8 field in a packed struct
>
> This problem is fixed by the following series which Gerd has in the
> USB queue:
>
>   https://lists.gnu.org/archive/html/qemu-devel/2019-04/msg02524.html

Great, that fixes the build issues. Dropping this patch.

Alistair

>
> > +#if defined(CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE) && QEMU_GNUC_PREREQ(9, 0)
> > +#pragma GCC diagnostic push
> > +#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
> > +#endif
> > +
> >  filename = utf16_to_str(MIN(dataset->length, filename_chars),
> >  dataset->filename);
> >
> > +#if defined(CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE) && QEMU_GNUC_PREREQ(9, 0)
> > +#pragma GCC diagnostic pop
> > +#endif
> > +
> >  if (strchr(filename, '/')) {
> >  usb_mtp_queue_result(s, RES_PARAMETER_NOT_SUPPORTED, d->trans,
> >   0, 0, 0, 0);
>
> Regards,
> Daniel
> --
> |: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org -o-https://fstop138.berrange.com :|
> |: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|



Re: [Qemu-devel] [PATCH] s390/ipl: cast to SCSIDevice directly

2019-05-02 Thread Christian Borntraeger



On 02.05.19 17:55, Cornelia Huck wrote:
> Coverity notes that the result of object_dynamic_cast() to
> SCSIDevice is not checked in s390_gen_initial_iplp(); as
> we know that we always have a SCSIDevice in that branch,
> we can instead cast via SCSI_DEVICE directly.
> 

And it even does look nicer. 

Reviewed-by: Christian Borntraeger 

> Coverity: CID 1401098
> Fixes: 5d8668f4 ("s390 vfio-ccw: Add bootindex property and IPLB data")
> Signed-off-by: Cornelia Huck 
> ---
>  hw/s390x/ipl.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c
> index d0cc06a05fd0..b93750c14eac 100644
> --- a/hw/s390x/ipl.c
> +++ b/hw/s390x/ipl.c
> @@ -374,8 +374,7 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl)
>  if (ccw_dev) {
>  switch (devtype) {
>  case CCW_DEVTYPE_SCSI:
> -sd = (SCSIDevice *) object_dynamic_cast(OBJECT(dev_st),
> -   TYPE_SCSI_DEVICE);
> +sd = SCSI_DEVICE(dev_st);
>  ipl->iplb.len = cpu_to_be32(S390_IPLB_MIN_QEMU_SCSI_LEN);
>  ipl->iplb.blk0_len =
>  cpu_to_be32(S390_IPLB_MIN_QEMU_SCSI_LEN - 
> S390_IPLB_HEADER_LEN);
> 




Re: [Qemu-devel] [PATCH v3 1/7] tests/qemu-iotests/005: Add a sanity check for large sparse file support

2019-05-02 Thread Alex Bennée


Thomas Huth  writes:

> "check -raw 005" fails when running on certain filesystems - these do not
> support such large sparse files. Use the same check as in test 220 to
> skip the test in this case.
>
> Suggested-by: Eric Blake 
> Reviewed-by: Eric Blake 
> Signed-off-by: Thomas Huth 

Reviewed-by: Alex Bennée 

> ---
>  tests/qemu-iotests/005 | 9 +
>  1 file changed, 9 insertions(+)
>
> diff --git a/tests/qemu-iotests/005 b/tests/qemu-iotests/005
> index 2fef63af88..9c7681c19b 100755
> --- a/tests/qemu-iotests/005
> +++ b/tests/qemu-iotests/005
> @@ -55,6 +55,15 @@ if [ "$IMGPROTO" = "sheepdog" ]; then
>  _notrun "image protocol $IMGPROTO does not support large image sizes"
>  fi
>
> +# Sanity check: For raw, we require a file system that permits the creation
> +# of a HUGE (but very sparse) file. Check we can create it before continuing.
> +if [ "$IMGFMT" = "raw" ]; then
> +if ! truncate --size=5T "$TEST_IMG"; then
> +_notrun "file system on $TEST_DIR does not support large enough 
> files"
> +fi
> +rm "$TEST_IMG"
> +fi
> +
>  echo
>  echo "creating large image"
>  _make_test_img 5000G


--
Alex Bennée



Re: [Qemu-devel] [PATCH v2 4/5] linux-user/uname: Fix GCC 9 build warnings

2019-05-02 Thread Alistair Francis
On Wed, May 1, 2019 at 5:00 AM Eric Blake  wrote:
>
> On 5/1/19 4:40 AM, Laurent Vivier wrote:
> > On 01/05/2019 01:28, Alistair Francis wrote:
> >> Fix this warning when building with GCC9 on Fedora 30:
> >> In function ‘strncpy’,
> >> inlined from ‘sys_uname’ at 
> >> /home/alistair/qemu/linux-user/uname.c:94:3:
> >> /usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ 
> >> output may be truncated copying 64 bytes from a string of length 64 
> >> [-Werror=stringop-truncation]
> >>   106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos 
> >> (__dest));
> >>   |  
> >> ^~
> >>
> >> Signed-off-by: Alistair Francis 

I'm dropping this patch in favour of the other one.

Alistair

> >> ---
> >>  linux-user/uname.c | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/linux-user/uname.c b/linux-user/uname.c
> >> index 313b79dbad..2fc6096a5b 100644
> >> --- a/linux-user/uname.c
> >> +++ b/linux-user/uname.c
> >> @@ -73,7 +73,7 @@ const char *cpu_to_uname_machine(void *cpu_env)
> >>  #define COPY_UTSNAME_FIELD(dest, src) \
> >>do { \
> >>/* __NEW_UTS_LEN doesn't include terminating null */ \
> >> -  (void) strncpy((dest), (src), __NEW_UTS_LEN); \
> >> +  (void) memcpy((dest), (src), MIN(strlen(src), __NEW_UTS_LEN)); \
> >
> > You should use MIN(strlen(src) + 1, __NEW_UTS_LEN) to copy the NUL
> > character if it is present and fit in __NEW_UTS_LEN.
>
> No, the NUL character is already present, due to the memset() prior to
> any use of COPY_UTSNAME_FIELD().  However, the commit message should
> call that out, as it is not part of the default 3-line diff.
>
> --
> Eric Blake, Principal Software Engineer
> Red Hat, Inc.   +1-919-301-3226
> Virtualization:  qemu.org | libvirt.org
>



  1   2   3   4   >