[PATCH v5 0/3] KVM/arm/arm64: enhance armv7/8 fp/simd lazy switch

2015-12-06 Thread Mario Smarduch
This patch series combines the previous armv7 and armv8 versions.
For an FP and lmbench load it reduces fp/simd context switch from 30-50% down
to near 0%. Results will vary with load but is no worse then current
approach.

In summary current lazy vfp/simd implementation switches hardware context only
on guest access and again on exit to host, otherwise hardware context is
skipped. This patch set builds on that functionality and executes a hardware
context switch only when  vCPU is scheduled out or returns to user space.

Running floating point app on nearly idle system:
./tst-float 10uS - (sleep for .1s) fp/simd switch reduced by 99%+
./tst-float 1uS -  (sleep for .01s)   reduced by 98%+
./tst-float 1000uS -   (sleep for 1ms)reduced by ~98%
...
./tst-float 1uS - reduced by  2%+

Tested on FastModels and Foundation Model (need to test on Juno)

Tests Ran:
--
armv7 - with CONFIG_VFP, CONFIG_NEON, CONFIG_KERNEL_MODE_NEON options enabled:

- On host executed 12 fp applications - evenly pinned to cpus
- Two guests - with 12 fp processes - also pinned to vpus.
- Executing with various sleep intervals to measure ration between exits
  and fp/simd switch

armv8:
-  added mix of armv7 and armv8 guests.

These patches are based on earlier arm64 fp/simd optimization work -
https://lists.cs.columbia.edu/pipermail/kvmarm/2015-July/015748.html

And subsequent fixes by Marc and Christoffer at KVM Forum hackathon to handle
32-bit guest on 64 bit host - 
https://lists.cs.columbia.edu/pipermail/kvmarm/2015-August/016128.html

Chances since v4->v5:
- Followed up on Marcs comments
  - Removed dirty flag, and used trap bits to check for dirty fp/simd
  - Seperated host form hyp code
  - As a consequence for arm64 added a commend assember header file
  - Fixed up critical accesses to fpexec, and added isb
  - Converted defines to inline functions

Changes since v3->v4:
- Followup on Christoffers comments 
  - Move fpexc handling to vcpu_load and vcpu_put
  - Enable and restore fpexc in EL2 mode when running a 32 bit guest on
64bit EL2
  - rework hcptr handling

Changes since v2->v3:
- combined arm v7 and v8 into one short patch series
- moved access to fpexec_el2 back to EL2
- Move host restore to EL1 from EL2 and call directly from host
- optimize trap enable code 
- renamed some variables to match usage

Changes since v1->v2:
- Fixed vfp/simd trap configuration to enable trace trapping
- Removed set_hcptr branch label
- Fixed handling of FPEXC to restore guest and host versions on vcpu_put
- Tested arm32/arm64
- rebased to 4.3-rc2
- changed a couple register accesses from 64 to 32 bit


Mario Smarduch (3):
  add hooks for armv7 fp/simd lazy switch support
  enable enhanced armv7 fp/simd lazy switch
  enable enhanced armv8 fp/simd lazy switch

 arch/arm/include/asm/kvm_emulate.h   |  55 ++
 arch/arm/include/asm/kvm_host.h  |   9 +++
 arch/arm/kernel/asm-offsets.c|   2 +
 arch/arm/kvm/Makefile|   2 +-
 arch/arm/kvm/arm.c   |  25 
 arch/arm/kvm/fpsimd_switch.S |  46 +++
 arch/arm/kvm/interrupts.S|  32 +++
 arch/arm/kvm/interrupts_head.S   |  33 +--
 arch/arm64/include/asm/kvm_asm.h |   2 +
 arch/arm64/include/asm/kvm_emulate.h |  16 ++
 arch/arm64/include/asm/kvm_host.h|  15 +
 arch/arm64/kernel/asm-offsets.c  |   1 +
 arch/arm64/kvm/Makefile  |   3 +-
 arch/arm64/kvm/fpsimd_switch.S   |  38 
 arch/arm64/kvm/hyp.S | 108 +--
 arch/arm64/kvm/hyp_head.S|  48 
 16 files changed, 322 insertions(+), 113 deletions(-)
 create mode 100644 arch/arm/kvm/fpsimd_switch.S
 create mode 100644 arch/arm64/kvm/fpsimd_switch.S
 create mode 100644 arch/arm64/kvm/hyp_head.S

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] VSOCK: fix returnvar.cocci warnings

2015-12-06 Thread David Miller
From: Julia Lawall 
Date: Sun, 6 Dec 2015 06:56:23 +0100 (CET)

> Remove unneeded variable used to store return value.
> 
> Generated by: scripts/coccinelle/misc/returnvar.cocci
> 
> CC: Asias He 
> Signed-off-by: Fengguang Wu 
> Signed-off-by: Julia Lawall 

Applied to net-next, thanks.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 2/3] KVM/arm/arm64: enable enhanced armv7 fp/simd lazy switch

2015-12-06 Thread Mario Smarduch
This patch tracks armv7 fp/simd hardware state with hcptr register.
On vcpu_load saves host fpexc, enables FP access, and sets trapping
on fp/simd access. On first fp/simd access trap to handler to save host and 
restore guest context, clear trapping bits to enable vcpu lazy mode. On 
vcpu_put if trap bits are cleared save guest and restore host context and 
always restore host fpexc.

Signed-off-by: Mario Smarduch 
---
 arch/arm/include/asm/kvm_emulate.h   | 50 
 arch/arm/include/asm/kvm_host.h  |  1 +
 arch/arm/kvm/Makefile|  2 +-
 arch/arm/kvm/arm.c   | 13 ++
 arch/arm/kvm/fpsimd_switch.S | 46 +
 arch/arm/kvm/interrupts.S| 32 +--
 arch/arm/kvm/interrupts_head.S   | 33 ++--
 arch/arm64/include/asm/kvm_emulate.h |  9 +++
 arch/arm64/include/asm/kvm_host.h|  1 +
 9 files changed, 142 insertions(+), 45 deletions(-)
 create mode 100644 arch/arm/kvm/fpsimd_switch.S

diff --git a/arch/arm/include/asm/kvm_emulate.h 
b/arch/arm/include/asm/kvm_emulate.h
index a9c80a2..3de11a2 100644
--- a/arch/arm/include/asm/kvm_emulate.h
+++ b/arch/arm/include/asm/kvm_emulate.h
@@ -243,4 +243,54 @@ static inline unsigned long vcpu_data_host_to_guest(struct 
kvm_vcpu *vcpu,
}
 }
 
+#ifdef CONFIG_VFPv3
+/* Called from vcpu_load - save fpexc and enable guest access to fp/simd unit 
*/
+static inline void kvm_enable_vcpu_fpexc(struct kvm_vcpu *vcpu)
+{
+   u32 fpexc;
+
+   asm volatile(
+"mrc p10, 7, %0, cr8, cr0, 0\n"
+"str %0, [%1]\n"
+"mov %0, #(1 << 30)\n"
+"mcr p10, 7, %0, cr8, cr0, 0\n"
+"isb\n"
+: "+r" (fpexc)
+: "r" (>arch.host_fpexc)
+   );
+}
+
+/* Called from vcpu_put - restore host fpexc */
+static inline void kvm_restore_host_fpexc(struct kvm_vcpu *vcpu)
+{
+   asm volatile(
+"mcr p10, 7, %0, cr8, cr0, 0\n"
+:
+: "r" (vcpu->arch.host_fpexc)
+   );
+}
+
+/* If trap bits are reset then fp/simd registers are dirty */
+static inline bool kvm_vcpu_vfp_isdirty(struct kvm_vcpu *vcpu)
+{
+   return !!(~vcpu->arch.hcptr & (HCPTR_TCP(10) | HCPTR_TCP(11)));
+}
+
+static inline void vcpu_reset_cptr(struct kvm_vcpu *vcpu)
+{
+   vcpu->arch.hcptr |= (HCPTR_TTA | HCPTR_TCP(10)  | HCPTR_TCP(11));
+}
+#else
+static inline void kvm_enable_vcpu_fpexc(struct kvm_vcpu *vcpu) {}
+static inline void kvm_restore_host_fpexc(struct kvm_vcpu *vcpu) {}
+static inline bool kvm_vcpu_vfp_isdirty(struct kvm_vcpu *vcpu)
+{
+   return false;
+}
+static inline void vcpu_reset_cptr(struct kvm_vcpu *vcpu)
+{
+   vcpu->arch.hcptr = HCPTR_TTA;
+}
+#endif
+
 #endif /* __ARM_KVM_EMULATE_H__ */
diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h
index 09bb1f2..ecc883a 100644
--- a/arch/arm/include/asm/kvm_host.h
+++ b/arch/arm/include/asm/kvm_host.h
@@ -227,6 +227,7 @@ int kvm_perf_teardown(void);
 void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot);
 
 struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr);
+void kvm_restore_host_vfp_state(struct kvm_vcpu *);
 
 static inline void kvm_arch_hardware_disable(void) {}
 static inline void kvm_arch_hardware_unsetup(void) {}
diff --git a/arch/arm/kvm/Makefile b/arch/arm/kvm/Makefile
index c5eef02c..411b3e4 100644
--- a/arch/arm/kvm/Makefile
+++ b/arch/arm/kvm/Makefile
@@ -19,7 +19,7 @@ kvm-arm-y = $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o 
$(KVM)/eventfd.o $(KVM)/vf
 
 obj-y += kvm-arm.o init.o interrupts.o
 obj-y += arm.o handle_exit.o guest.o mmu.o emulate.o reset.o
-obj-y += coproc.o coproc_a15.o coproc_a7.o mmio.o psci.o perf.o
+obj-y += coproc.o coproc_a15.o coproc_a7.o mmio.o psci.o perf.o fpsimd_switch.o
 obj-y += $(KVM)/arm/vgic.o
 obj-y += $(KVM)/arm/vgic-v2.o
 obj-y += $(KVM)/arm/vgic-v2-emul.o
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index dc017ad..1de07ab 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -291,10 +291,23 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
vcpu->arch.host_cpu_context = this_cpu_ptr(kvm_host_cpu_state);
 
kvm_arm_set_running_vcpu(vcpu);
+
+   /*  Save and enable FPEXC before we load guest context */
+   kvm_enable_vcpu_fpexc(vcpu);
+
+   /* reset hyp cptr register to trap on tracing and vfp/simd access*/
+   vcpu_reset_cptr(vcpu);
 }
 
 void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
 {
+   /* If the fp/simd registers are dirty save guest, restore host. */
+   if (kvm_vcpu_vfp_isdirty(vcpu))
+   kvm_restore_host_vfp_state(vcpu);
+
+   /* Restore host FPEXC trashed in vcpu_load */
+   kvm_restore_host_fpexc(vcpu);
+
/*
 * The arch-generic KVM code expects the cpu field of a vcpu to be -1
 * if the vcpu is no longer assigned to a cpu.  This is used for the
diff --git 

[PATCH v5 1/3] KVM/arm: add hooks for armv7 fp/simd lazy switch support

2015-12-06 Thread Mario Smarduch
This patch adds vcpu fields to configure hcptr trap register which is also used 
to determine if fp/simd registers are dirty. Adds a field to save host FPEXC, 
and offsets associated offsets.

Signed-off-by: Mario Smarduch 
---
 arch/arm/include/asm/kvm_host.h | 6 ++
 arch/arm/kernel/asm-offsets.c   | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h
index 3df1e97..09bb1f2 100644
--- a/arch/arm/include/asm/kvm_host.h
+++ b/arch/arm/include/asm/kvm_host.h
@@ -104,6 +104,12 @@ struct kvm_vcpu_arch {
/* HYP trapping configuration */
u32 hcr;
 
+   /* HYP Co-processor fp/simd and trace trapping configuration */
+   u32 hcptr;
+
+   /* Save host FPEXC register to later restore on vcpu put */
+   u32 host_fpexc;
+
/* Interrupt related fields */
u32 irq_lines;  /* IRQ and FIQ levels */
 
diff --git a/arch/arm/kernel/asm-offsets.c b/arch/arm/kernel/asm-offsets.c
index 871b826..28ebd4c 100644
--- a/arch/arm/kernel/asm-offsets.c
+++ b/arch/arm/kernel/asm-offsets.c
@@ -185,6 +185,8 @@ int main(void)
   DEFINE(VCPU_PC,  offsetof(struct kvm_vcpu, 
arch.regs.usr_regs.ARM_pc));
   DEFINE(VCPU_CPSR,offsetof(struct kvm_vcpu, 
arch.regs.usr_regs.ARM_cpsr));
   DEFINE(VCPU_HCR, offsetof(struct kvm_vcpu, arch.hcr));
+  DEFINE(VCPU_HCPTR,   offsetof(struct kvm_vcpu, arch.hcptr));
+  DEFINE(VCPU_VFP_HOST_FPEXC,  offsetof(struct kvm_vcpu, arch.host_fpexc));
   DEFINE(VCPU_IRQ_LINES,   offsetof(struct kvm_vcpu, arch.irq_lines));
   DEFINE(VCPU_HSR, offsetof(struct kvm_vcpu, arch.fault.hsr));
   DEFINE(VCPU_HxFAR,   offsetof(struct kvm_vcpu, arch.fault.hxfar));
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 3/3] KVM/arm/arm64: enable enhanced armv8 fp/simd lazy switch

2015-12-06 Thread Mario Smarduch
This patch tracks armv7 and armv8 fp/simd hardware state with cptr_el2 register.
On vcpu_load for 32 bit guests enable FP access, and enable fp/simd
trapping for 32 and 64 bit guests. On first fp/simd access trap to handler 
to save host and restore guest context, and clear trapping bits to enable vcpu 
lazy mode. On vcpu_put if trap bits are clear save guest and restore host 
context and also save 32 bit guest fpexc register.

Signed-off-by: Mario Smarduch 
---
 arch/arm/include/asm/kvm_emulate.h   |   5 ++
 arch/arm/include/asm/kvm_host.h  |   2 +
 arch/arm/kvm/arm.c   |  20 +--
 arch/arm64/include/asm/kvm_asm.h |   2 +
 arch/arm64/include/asm/kvm_emulate.h |  15 +++--
 arch/arm64/include/asm/kvm_host.h|  16 +-
 arch/arm64/kernel/asm-offsets.c  |   1 +
 arch/arm64/kvm/Makefile  |   3 +-
 arch/arm64/kvm/fpsimd_switch.S   |  38 
 arch/arm64/kvm/hyp.S | 108 +--
 arch/arm64/kvm/hyp_head.S|  48 
 11 files changed, 181 insertions(+), 77 deletions(-)
 create mode 100644 arch/arm64/kvm/fpsimd_switch.S
 create mode 100644 arch/arm64/kvm/hyp_head.S

diff --git a/arch/arm/include/asm/kvm_emulate.h 
b/arch/arm/include/asm/kvm_emulate.h
index 3de11a2..13feed5 100644
--- a/arch/arm/include/asm/kvm_emulate.h
+++ b/arch/arm/include/asm/kvm_emulate.h
@@ -243,6 +243,11 @@ static inline unsigned long vcpu_data_host_to_guest(struct 
kvm_vcpu *vcpu,
}
 }
 
+static inline bool kvm_guest_vcpu_is_32bit(struct kvm_vcpu *vcpu)
+{
+   return true;
+}
+
 #ifdef CONFIG_VFPv3
 /* Called from vcpu_load - save fpexc and enable guest access to fp/simd unit 
*/
 static inline void kvm_enable_vcpu_fpexc(struct kvm_vcpu *vcpu)
diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h
index ecc883a..720ae51 100644
--- a/arch/arm/include/asm/kvm_host.h
+++ b/arch/arm/include/asm/kvm_host.h
@@ -227,6 +227,8 @@ int kvm_perf_teardown(void);
 void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot);
 
 struct kvm_vcpu *kvm_mpidr_to_vcpu(struct kvm *kvm, unsigned long mpidr);
+
+static inline void kvm_save_guest_vcpu_fpexc(struct kvm_vcpu *vcpu) {}
 void kvm_restore_host_vfp_state(struct kvm_vcpu *);
 
 static inline void kvm_arch_hardware_disable(void) {}
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 1de07ab..dd59f8a 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -292,8 +292,12 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 
kvm_arm_set_running_vcpu(vcpu);
 
-   /*  Save and enable FPEXC before we load guest context */
-   kvm_enable_vcpu_fpexc(vcpu);
+   /*
+* For 32bit guest executing on arm64, enable fp/simd access in
+* EL2. On arm32 save host fpexc and then enable fp/simd access.
+*/
+   if (kvm_guest_vcpu_is_32bit(vcpu))
+   kvm_enable_vcpu_fpexc(vcpu);
 
/* reset hyp cptr register to trap on tracing and vfp/simd access*/
vcpu_reset_cptr(vcpu);
@@ -302,10 +306,18 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
 {
/* If the fp/simd registers are dirty save guest, restore host. */
-   if (kvm_vcpu_vfp_isdirty(vcpu))
+   if (kvm_vcpu_vfp_isdirty(vcpu)) {
kvm_restore_host_vfp_state(vcpu);
 
-   /* Restore host FPEXC trashed in vcpu_load */
+   /*
+* For 32bit guest on arm64 save the guest fpexc register
+* in EL2 mode.
+*/
+   if (kvm_guest_vcpu_is_32bit(vcpu))
+   kvm_save_guest_vcpu_fpexc(vcpu);
+   }
+
+   /* For arm32 restore host FPEXC trashed in vcpu_load. */
kvm_restore_host_fpexc(vcpu);
 
/*
diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h
index 5e37710..d53d069 100644
--- a/arch/arm64/include/asm/kvm_asm.h
+++ b/arch/arm64/include/asm/kvm_asm.h
@@ -117,6 +117,8 @@ extern char __kvm_hyp_vector[];
 extern void __kvm_flush_vm_context(void);
 extern void __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa);
 extern void __kvm_tlb_flush_vmid(struct kvm *kvm);
+extern void __kvm_vcpu_enable_fpexc32(void);
+extern void __kvm_vcpu_save_fpexc32(struct kvm_vcpu *vcpu);
 
 extern int __kvm_vcpu_run(struct kvm_vcpu *vcpu);
 
diff --git a/arch/arm64/include/asm/kvm_emulate.h 
b/arch/arm64/include/asm/kvm_emulate.h
index 8dccbd7..bbbee9d 100644
--- a/arch/arm64/include/asm/kvm_emulate.h
+++ b/arch/arm64/include/asm/kvm_emulate.h
@@ -290,13 +290,20 @@ static inline unsigned long 
vcpu_data_host_to_guest(struct kvm_vcpu *vcpu,
return data;/* Leave LE untouched */
 }
 
-static inline void kvm_enable_vcpu_fpexc(struct kvm_vcpu *vcpu) {}
-static inline void kvm_restore_host_fpexc(struct kvm_vcpu *vcpu) {}
-static inline void vcpu_reset_cptr(struct kvm_vcpu *vcpu) {}
+static 

Re: [PATCH] VSOCK: fix returnvar.cocci warnings

2015-12-06 Thread Stefan Hajnoczi
On Sun, Dec 06, 2015 at 06:56:23AM +0100, Julia Lawall wrote:
> Remove unneeded variable used to store return value.
> 
> Generated by: scripts/coccinelle/misc/returnvar.cocci
> 
> CC: Asias He 
> Signed-off-by: Fengguang Wu 
> Signed-off-by: Julia Lawall 
> 
> ---
> 
>  vsock.c |3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> --- a/drivers/vhost/vsock.c
> +++ b/drivers/vhost/vsock.c
> @@ -56,8 +56,7 @@ struct vhost_vsock {
>  
>  static u32 vhost_transport_get_local_cid(void)
>  {
> - u32 cid = VHOST_VSOCK_DEFAULT_HOST_CID;
> - return cid;
> + return VHOST_VSOCK_DEFAULT_HOST_CID;
>  }
>  
>  static struct vhost_vsock *vhost_vsock_get(u32 guest_cid)

Reviewed-by: Stefan Hajnoczi 


signature.asc
Description: PGP signature


Re: [v2,2/9] powerpc/smp: Add smp_muxed_ipi_set_message

2015-12-06 Thread Michael Ellerman
On Wed, 2015-25-11 at 23:44:49 UTC, "Suresh E. Warrier" wrote:
> smp_muxed_ipi_message_pass() invokes smp_ops->cause_ipi, which
> updates the MFFR through an ioremapped address, to cause the
> IPI. Because of this real mode callers cannot call
> smp_muxed_ipi_message_pass() for IPI messaging.

You're talking about the XICS code here but you don't mention that. Please
expand it to make it clear that you're talking about XICS.

cheers
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] target-i386: kvm: clear unusable segments' flags in migration

2015-12-06 Thread Michael Chapman
This commit fixes migration of a QEMU/KVM guest from kernel >= v3.9 to
kernel <= v3.7 (e.g. from RHEL 7 to RHEL 6). Without this commit a guest
migrated across these kernel versions fails to resume on the target host
as its segment descriptors are invalid.

Two separate kernel commits combined together to result in this bug:

  commit f0495f9b9992f80f82b14306946444b287193390
  Author: Avi Kivity 
  Date:   Thu Jun 7 17:06:10 2012 +0300

  KVM: VMX: Relax check on unusable segment

  Some userspace (e.g. QEMU 1.1) munge the d and g bits of segment
  descriptors, causing us not to recognize them as unusable segments
  with emulate_invalid_guest_state=1.  Relax the check by testing for
  segment not present (a non-present segment cannot be usable).

  Signed-off-by: Avi Kivity 

  commit 25391454e73e3156202264eb3c473825afe4bc94
  Author: Gleb Natapov 
  Date:   Mon Jan 21 15:36:46 2013 +0200

  KVM: VMX: don't clobber segment AR of unusable segments.

  Usability is returned in unusable field, so not need to clobber entire
  AR. Callers have to know how to deal with unusable segments already
  since if emulate_invalid_guest_state=true AR is not zeroed.

  Signed-off-by: Gleb Natapov 
  Signed-off-by: Marcelo Tosatti 

The first commit changed the KVM_SET_SREGS ioctl so that it did no treat
segment flags == 0 as an unusable segment, instead only looking at the
"present" flag.

The second commit changed KVM_GET_SREGS so that it did not clear the
flags of an unusable segment.

Since QEMU does not itself maintain the "unusable" flag across a
migration, the end result is that unusable segments read from a kernel
with these commits and loaded into a kernel without these commits are
not properly recognised as being unusable.

This commit updates both get_seg and set_seg so that the problem is
avoided even when migrating to or migrating from a QEMU without this
commit. In get_seg, we clear the segment flags if the segment is marked
unusable. In set_seg, we mark the segment unusable if the segment's
"present" flag is not set.

Signed-off-by: Michael Chapman 
---
 target-i386/kvm.c | 22 +-
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 6dc9846..7bf5a33 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1107,7 +1107,7 @@ static void set_seg(struct kvm_segment *lhs, const 
SegmentCache *rhs)
 lhs->l = (flags >> DESC_L_SHIFT) & 1;
 lhs->g = (flags & DESC_G_MASK) != 0;
 lhs->avl = (flags & DESC_AVL_MASK) != 0;
-lhs->unusable = 0;
+lhs->unusable = !lhs->present;
 lhs->padding = 0;
 }
 
@@ -1116,14 +1116,18 @@ static void get_seg(SegmentCache *lhs, const struct 
kvm_segment *rhs)
 lhs->selector = rhs->selector;
 lhs->base = rhs->base;
 lhs->limit = rhs->limit;
-lhs->flags = (rhs->type << DESC_TYPE_SHIFT) |
- (rhs->present * DESC_P_MASK) |
- (rhs->dpl << DESC_DPL_SHIFT) |
- (rhs->db << DESC_B_SHIFT) |
- (rhs->s * DESC_S_MASK) |
- (rhs->l << DESC_L_SHIFT) |
- (rhs->g * DESC_G_MASK) |
- (rhs->avl * DESC_AVL_MASK);
+if (rhs->unusable) {
+lhs->flags = 0;
+} else {
+lhs->flags = (rhs->type << DESC_TYPE_SHIFT) |
+ (rhs->present * DESC_P_MASK) |
+ (rhs->dpl << DESC_DPL_SHIFT) |
+ (rhs->db << DESC_B_SHIFT) |
+ (rhs->s * DESC_S_MASK) |
+ (rhs->l << DESC_L_SHIFT) |
+ (rhs->g * DESC_G_MASK) |
+ (rhs->avl * DESC_AVL_MASK);
+}
 }
 
 static void kvm_getput_reg(__u64 *kvm_reg, target_ulong *qemu_reg, int set)
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [v2,3/9] powerpc/powernv: Add icp_native_cause_ipi_rm

2015-12-06 Thread Michael Ellerman
Subject would be better as "powerpc/xics".

On Wed, 2015-25-11 at 23:44:50 UTC, "Suresh E. Warrier" wrote:
> Function to cause an IPI. Requires kvm_hstate.xics_phys
> to be initialized with physical address of XICS.

Please expand the change log a bit, this is a bit terse.

> diff --git a/arch/powerpc/sysdev/xics/icp-native.c 
> b/arch/powerpc/sysdev/xics/icp-native.c
> index eae3265..e39b18a 100644
> --- a/arch/powerpc/sysdev/xics/icp-native.c
> +++ b/arch/powerpc/sysdev/xics/icp-native.c
> @@ -159,6 +159,25 @@ static void icp_native_cause_ipi(int cpu, unsigned long 
> data)
>   icp_native_set_qirr(cpu, IPI_PRIORITY);
>  }
>  
> +void icp_native_cause_ipi_rm(int cpu)
> +{
> + /*
> +  * Currently not used to send IPIs to another CPU
> +  * on the same core. Only caller is KVM real mode.
> +  * Need the physical address of the XICS to be
> +  * previously saved in kvm_hstate in the paca.
> +  */
> + unsigned long xics_phys;
> +
> + /*
> +  * Just like the cause_ipi functions, it is required to
> +  * include a full barrier (out8 includes a sync) before
> +  * causing the IPI.
> +  */
> + xics_phys = paca[cpu].kvm_hstate.xics_phys;
> + out_rm8((u8 *)(xics_phys + XICS_MFRR), IPI_PRIORITY);
> +}

This doesn't build without KVM:

  arch/powerpc/sysdev/xics/icp-native.c:177:23: error: 'struct paca_struct' has 
no member named 'kvm_hstate'


Probably the whole function should be #ifdef CONFIG_KVM_BOOK3S_64_HV or
something.

cheers
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html