Re: [PATCH] KVM/MIPS32: Export min_low_pfn.

2013-05-17 Thread Gleb Natapov
On Fri, May 17, 2013 at 02:42:48PM -0700, David Daney wrote:
> On 05/17/2013 02:06 PM, Sanjay Lal wrote:
> >The KVM module uses the standard MIPS cache management routines, which use 
> >min_low_pfn.
> >This creates and indirect dependency, requiring min_low_pfn to be exported.
> >
> >Signed-off-by: Sanjay Lal 
> >---
> >  arch/mips/kernel/mips_ksyms.c | 6 ++
> >  1 file changed, 6 insertions(+)
> >
> >diff --git a/arch/mips/kernel/mips_ksyms.c b/arch/mips/kernel/mips_ksyms.c
> >index 6e58e97..0299472 100644
> >--- a/arch/mips/kernel/mips_ksyms.c
> >+++ b/arch/mips/kernel/mips_ksyms.c
> >@@ -14,6 +14,7 @@
> >  #include 
> >  #include 
> >  #include 
> >+#include 
> >
> >  extern void *__bzero(void *__s, size_t __count);
> >  extern long __strncpy_from_user_nocheck_asm(char *__to,
> >@@ -60,3 +61,8 @@ EXPORT_SYMBOL(invalid_pte_table);
> >  /* _mcount is defined in arch/mips/kernel/mcount.S */
> >  EXPORT_SYMBOL(_mcount);
> >  #endif
> >+
> >+/* The KVM module uses the standard MIPS cache functions which use
> >+ * min_low_pfn, requiring it to be exported.
> >+ */
> >+EXPORT_SYMBOL(min_low_pfn);
> 
> I think I asked this before, but I don't remember the answer:
> 
> Why not put EXPORT_SYMBOL(min_low_pfn) in mm/bootmem.c adjacent to
> where the symbol is defined?
> 
He did answered here:
http://permalink.gmane.org/gmane.comp.emulators.kvm.devel/109895.

I suggested mips_ksyms.c solution as an option.

> Cluttering up the kernel with multiple architectures all doing
> architecture specific exports of the same symbol is not a clean way
> of doing things.
> 
> The second time something needs to be done, it should be factored
> out into common code.
> 
Exports are different. You define interface between the kernel and modules
here, exporting the symbol may not be desirable for some arch. And 
min_low_pfn is not the only example. Anything in arch _ksyms files is like that:
exported by some archs but not the others. 

--
Gleb.
--
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 3/3] KVM/MIPS32: Fix up KVM breakage caused by d532f3d26716a39dfd4b88d687bd344fbe77e390 which allows ASID mask and increment to be determined @ runtime.

2013-05-17 Thread Gleb Natapov
On Sat, May 18, 2013 at 02:06:36AM +0200, Ralf Baechle wrote:
> On Fri, May 17, 2013 at 02:25:12PM -0700, Sanjay Lal wrote:
> > Date:   Fri, 17 May 2013 14:25:12 -0700
> > From: Sanjay Lal 
> > To: kvm@vger.kernel.org
> > Cc: linux-m...@linux-mips.org, r...@linux-mips.org, g...@redhat.com,
> >  mtosa...@redhat.com, Sanjay Lal 
> > Subject: [PATCH 3/3] KVM/MIPS32: Fix up KVM breakage caused by
> >  d532f3d26716a39dfd4b88d687bd344fbe77e390 which allows ASID mask and
> >  increment to be determined @ runtime.
> 
> Good grief, yet another bug report against that patch ...  I've reverted
> d532f3d26 just before your posting.  So I'm going to drop this patch.
> 
Ralf, I am going to take patch 1 and 2 through kvm.git. Can you take
"Export min_low_pfn" through mips tree?

--
Gleb.
--
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 2/3] KVM/MIPS32: Wrap calls to gfn_to_pfn() with srcu_read_lock/unlock()

2013-05-17 Thread Gleb Natapov
On Fri, May 17, 2013 at 02:25:11PM -0700, Sanjay Lal wrote:
> - As suggested by Gleb, wrap calls to gfn_to_pfn() with 
> srcu_read_lock/unlock().
>   Memory slots should be acccessed from a SRCU read section.
> - kvm_mips_map_page() now returns an error code to it's callers, instead of 
> calling panic()
>  if it cannot find a mapping for a particular gfn.
> 
> Signed-off-by: Sanjay Lal 
> ---
>  arch/mips/kvm/kvm_tlb.c | 36 +++-
>  1 file changed, 27 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/mips/kvm/kvm_tlb.c b/arch/mips/kvm/kvm_tlb.c
> index 89511a9..ab2e9b0 100644
> --- a/arch/mips/kvm/kvm_tlb.c
> +++ b/arch/mips/kvm/kvm_tlb.c
> @@ -16,7 +16,10 @@
>  #include 
>  #include 
>  #include 
> +#include 
Is this include still needed now when you export min_low_pfn in
mips_ksyms.c?

>  #include 
> +#include 
> +
>  
>  #include 
>  #include 
> @@ -169,21 +172,27 @@ void kvm_mips_dump_shadow_tlbs(struct kvm_vcpu *vcpu)
>   }
>  }
>  
> -static void kvm_mips_map_page(struct kvm *kvm, gfn_t gfn)
> +static int kvm_mips_map_page(struct kvm *kvm, gfn_t gfn)
>  {
> + int srcu_idx, err = 0;
>   pfn_t pfn;
>  
>   if (kvm->arch.guest_pmap[gfn] != KVM_INVALID_PAGE)
> - return;
> + return 0;
>  
> +srcu_idx = srcu_read_lock(&kvm->srcu);
>   pfn = kvm_mips_gfn_to_pfn(kvm, gfn);
>  
>   if (kvm_mips_is_error_pfn(pfn)) {
> - panic("Couldn't get pfn for gfn %#" PRIx64 "!\n", gfn);
> + kvm_err("Couldn't get pfn for gfn %#" PRIx64 "!\n", gfn);
> + err = -EFAULT;
> + goto out;
>   }
>  
>   kvm->arch.guest_pmap[gfn] = pfn;
> - return;
> +out:
> + srcu_read_unlock(&kvm->srcu, srcu_idx);
> + return err;
>  }
>  
>  /* Translate guest KSEG0 addresses to Host PA */
> @@ -207,7 +216,10 @@ unsigned long 
> kvm_mips_translate_guest_kseg0_to_hpa(struct kvm_vcpu *vcpu,
>   gva);
>   return KVM_INVALID_PAGE;
>   }
> - kvm_mips_map_page(vcpu->kvm, gfn);
> +
> + if (kvm_mips_map_page(vcpu->kvm, gfn) < 0)
> + return KVM_INVALID_ADDR;
> +
>   return (kvm->arch.guest_pmap[gfn] << PAGE_SHIFT) + offset;
>  }
>  
> @@ -310,8 +322,11 @@ int kvm_mips_handle_kseg0_tlb_fault(unsigned long 
> badvaddr,
>   even = !(gfn & 0x1);
>   vaddr = badvaddr & (PAGE_MASK << 1);
>  
> - kvm_mips_map_page(vcpu->kvm, gfn);
> - kvm_mips_map_page(vcpu->kvm, gfn ^ 0x1);
> + if (kvm_mips_map_page(vcpu->kvm, gfn) < 0)
> + return -1;
> +
> + if (kvm_mips_map_page(vcpu->kvm, gfn ^ 0x1) < 0)
> + return -1;
>  
>   if (even) {
>   pfn0 = kvm->arch.guest_pmap[gfn];
> @@ -389,8 +404,11 @@ kvm_mips_handle_mapped_seg_tlb_fault(struct kvm_vcpu 
> *vcpu,
>   pfn0 = 0;
>   pfn1 = 0;
>   } else {
> - kvm_mips_map_page(kvm, mips3_tlbpfn_to_paddr(tlb->tlb_lo0) >> 
> PAGE_SHIFT);
> - kvm_mips_map_page(kvm, mips3_tlbpfn_to_paddr(tlb->tlb_lo1) >> 
> PAGE_SHIFT);
> + if (kvm_mips_map_page(kvm, mips3_tlbpfn_to_paddr(tlb->tlb_lo0) 
> >> PAGE_SHIFT) < 0)
> + return -1;
> +
> + if (kvm_mips_map_page(kvm, mips3_tlbpfn_to_paddr(tlb->tlb_lo1) 
> >> PAGE_SHIFT) < 0)
> + return -1;
>  
>   pfn0 = kvm->arch.guest_pmap[mips3_tlbpfn_to_paddr(tlb->tlb_lo0) 
> >> PAGE_SHIFT];
>   pfn1 = kvm->arch.guest_pmap[mips3_tlbpfn_to_paddr(tlb->tlb_lo1) 
> >> PAGE_SHIFT];
> -- 
> 1.7.11.3

--
Gleb.
--
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 3/3] KVM/MIPS32: Fix up KVM breakage caused by d532f3d26716a39dfd4b88d687bd344fbe77e390 which allows ASID mask and increment to be determined @ runtime.

2013-05-17 Thread Ralf Baechle
On Fri, May 17, 2013 at 02:25:12PM -0700, Sanjay Lal wrote:
> Date:   Fri, 17 May 2013 14:25:12 -0700
> From: Sanjay Lal 
> To: kvm@vger.kernel.org
> Cc: linux-m...@linux-mips.org, r...@linux-mips.org, g...@redhat.com,
>  mtosa...@redhat.com, Sanjay Lal 
> Subject: [PATCH 3/3] KVM/MIPS32: Fix up KVM breakage caused by
>  d532f3d26716a39dfd4b88d687bd344fbe77e390 which allows ASID mask and
>  increment to be determined @ runtime.

Good grief, yet another bug report against that patch ...  I've reverted
d532f3d26 just before your posting.  So I'm going to drop this patch.

Thanks,

  Ralf
--
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] KVM/MIPS32: Export min_low_pfn.

2013-05-17 Thread David Daney

On 05/17/2013 02:06 PM, Sanjay Lal wrote:

The KVM module uses the standard MIPS cache management routines, which use 
min_low_pfn.
This creates and indirect dependency, requiring min_low_pfn to be exported.

Signed-off-by: Sanjay Lal 
---
  arch/mips/kernel/mips_ksyms.c | 6 ++
  1 file changed, 6 insertions(+)

diff --git a/arch/mips/kernel/mips_ksyms.c b/arch/mips/kernel/mips_ksyms.c
index 6e58e97..0299472 100644
--- a/arch/mips/kernel/mips_ksyms.c
+++ b/arch/mips/kernel/mips_ksyms.c
@@ -14,6 +14,7 @@
  #include 
  #include 
  #include 
+#include 

  extern void *__bzero(void *__s, size_t __count);
  extern long __strncpy_from_user_nocheck_asm(char *__to,
@@ -60,3 +61,8 @@ EXPORT_SYMBOL(invalid_pte_table);
  /* _mcount is defined in arch/mips/kernel/mcount.S */
  EXPORT_SYMBOL(_mcount);
  #endif
+
+/* The KVM module uses the standard MIPS cache functions which use
+ * min_low_pfn, requiring it to be exported.
+ */
+EXPORT_SYMBOL(min_low_pfn);


I think I asked this before, but I don't remember the answer:

Why not put EXPORT_SYMBOL(min_low_pfn) in mm/bootmem.c adjacent to where 
the symbol is defined?


Cluttering up the kernel with multiple architectures all doing 
architecture specific exports of the same symbol is not a clean way of 
doing things.


The second time something needs to be done, it should be factored out 
into common code.


David Daney





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


[RESEND][PATCH v2] kvm/ppc/booke: Hold srcu lock when calling gfn functions

2013-05-17 Thread Scott Wood
KVM core expects arch code to acquire the srcu lock when calling
gfn_to_memslot and similar functions.

Signed-off-by: Scott Wood 
---
Resending as it doesn't seem to have made it to the mailing list
archives or patchwork.

v2: Eliminate need_srcu and move the locking into the switch cases
that need it.

 arch/powerpc/kvm/44x_tlb.c  |5 +
 arch/powerpc/kvm/booke.c|7 +++
 arch/powerpc/kvm/e500_mmu.c |5 +
 3 files changed, 17 insertions(+)

diff --git a/arch/powerpc/kvm/44x_tlb.c b/arch/powerpc/kvm/44x_tlb.c
index 5dd3ab4..ed03854 100644
--- a/arch/powerpc/kvm/44x_tlb.c
+++ b/arch/powerpc/kvm/44x_tlb.c
@@ -441,6 +441,7 @@ int kvmppc_44x_emul_tlbwe(struct kvm_vcpu *vcpu, u8 ra, u8 
rs, u8 ws)
struct kvmppc_vcpu_44x *vcpu_44x = to_44x(vcpu);
struct kvmppc_44x_tlbe *tlbe;
unsigned int gtlb_index;
+   int idx;
 
gtlb_index = kvmppc_get_gpr(vcpu, ra);
if (gtlb_index >= KVM44x_GUEST_TLB_SIZE) {
@@ -473,6 +474,8 @@ int kvmppc_44x_emul_tlbwe(struct kvm_vcpu *vcpu, u8 ra, u8 
rs, u8 ws)
return EMULATE_FAIL;
}
 
+   idx = srcu_read_lock(&vcpu->kvm->srcu);
+
if (tlbe_is_host_safe(vcpu, tlbe)) {
gva_t eaddr;
gpa_t gpaddr;
@@ -489,6 +492,8 @@ int kvmppc_44x_emul_tlbwe(struct kvm_vcpu *vcpu, u8 ra, u8 
rs, u8 ws)
kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index);
}
 
+   srcu_read_unlock(&vcpu->kvm->srcu, idx);
+
trace_kvm_gtlb_write(gtlb_index, tlbe->tid, tlbe->word0, tlbe->word1,
 tlbe->word2);
 
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 1020119..ecbe908 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -832,6 +832,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu 
*vcpu,
 {
int r = RESUME_HOST;
int s;
+   int idx;
 
/* update before a new last_exit_type is rewritten */
kvmppc_update_timing_stats(vcpu);
@@ -1053,6 +1054,8 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
break;
}
 
+   idx = srcu_read_lock(&vcpu->kvm->srcu);
+
gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr);
gfn = gpaddr >> PAGE_SHIFT;
 
@@ -1075,6 +1078,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
kvmppc_account_exit(vcpu, MMIO_EXITS);
}
 
+   srcu_read_unlock(&vcpu->kvm->srcu, idx);
break;
}
 
@@ -1098,6 +1102,8 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
 
kvmppc_account_exit(vcpu, ITLB_VIRT_MISS_EXITS);
 
+   idx = srcu_read_lock(&vcpu->kvm->srcu);
+
gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr);
gfn = gpaddr >> PAGE_SHIFT;
 
@@ -1114,6 +1120,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct 
kvm_vcpu *vcpu,
kvmppc_booke_queue_irqprio(vcpu, 
BOOKE_IRQPRIO_MACHINE_CHECK);
}
 
+   srcu_read_unlock(&vcpu->kvm->srcu, idx);
break;
}
 
diff --git a/arch/powerpc/kvm/e500_mmu.c b/arch/powerpc/kvm/e500_mmu.c
index c41a5a9..6d6f153 100644
--- a/arch/powerpc/kvm/e500_mmu.c
+++ b/arch/powerpc/kvm/e500_mmu.c
@@ -396,6 +396,7 @@ int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu)
struct kvm_book3e_206_tlb_entry *gtlbe;
int tlbsel, esel;
int recal = 0;
+   int idx;
 
tlbsel = get_tlb_tlbsel(vcpu);
esel = get_tlb_esel(vcpu, tlbsel);
@@ -430,6 +431,8 @@ int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu)
kvmppc_set_tlb1map_range(vcpu, gtlbe);
}
 
+   idx = srcu_read_lock(&vcpu->kvm->srcu);
+
/* Invalidate shadow mappings for the about-to-be-clobbered TLBE. */
if (tlbe_is_host_safe(vcpu, gtlbe)) {
u64 eaddr = get_tlb_eaddr(gtlbe);
@@ -444,6 +447,8 @@ int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu)
kvmppc_mmu_map(vcpu, eaddr, raddr, index_of(tlbsel, esel));
}
 
+   srcu_read_unlock(&vcpu->kvm->srcu, idx);
+
kvmppc_set_exit_type(vcpu, EMULATED_TLBWE_EXITS);
return EMULATE_DONE;
 }
-- 
1.7.10.4



--
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 3/3] KVM/MIPS32: Fix up KVM breakage caused by d532f3d26716a39dfd4b88d687bd344fbe77e390 which allows ASID mask and increment to be determined @ runtime.

2013-05-17 Thread Sanjay Lal
The ASID paramters have default values which are then patched @ runtime
as part of the TLB initialization.  The fixup does not work since KVM
is a kernel module and we end up with the default mask of 0xfc0 instead of
the standard ASID mask of 0xff for MIPS32R2 processors.

I've posted the issue on the MIPS mailing list and until a solution is found,
For now define KVM_ASID_MASK as 0xFF to fix this issue up for Linux 3.10.

Signed-off-by: Sanjay Lal 
---
 arch/mips/include/asm/kvm_host.h |  5 +
 arch/mips/kvm/kvm_mips_emul.c| 22 +++---
 arch/mips/kvm/kvm_tlb.c  | 20 ++--
 3 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h
index e68781e..747c193 100644
--- a/arch/mips/include/asm/kvm_host.h
+++ b/arch/mips/include/asm/kvm_host.h
@@ -71,6 +71,11 @@
 #define CAUSEB_DC   27
 #define CAUSEF_DC   (_ULCAST_(1)   << 27)
 
+/* KVM supports MIPS32R2 and beyond, so ASID_MASK is always 0xFF.
+ * This is to work around the bug introduced by commit 
d532f3d26716a39dfd4b88d687bd344fbe77e390
+ */
+#define KVM_ASID_MASK(x) ((x) & 0xFF)
+
 struct kvm;
 struct kvm_run;
 struct kvm_vcpu;
diff --git a/arch/mips/kvm/kvm_mips_emul.c b/arch/mips/kvm/kvm_mips_emul.c
index 2b2bac9..b8eee34 100644
--- a/arch/mips/kvm/kvm_mips_emul.c
+++ b/arch/mips/kvm/kvm_mips_emul.c
@@ -525,16 +525,16 @@ kvm_mips_emulate_CP0(uint32_t inst, uint32_t *opc, 
uint32_t cause,
printk("MTCz, cop0->reg[EBASE]: %#lx\n",
   kvm_read_c0_guest_ebase(cop0));
} else if (rd == MIPS_CP0_TLB_HI && sel == 0) {
-   uint32_t nasid = ASID_MASK(vcpu->arch.gprs[rt]);
+   uint32_t nasid = 
KVM_ASID_MASK(vcpu->arch.gprs[rt]);
if ((KSEGX(vcpu->arch.gprs[rt]) != CKSEG0)
&&
-   (ASID_MASK(kvm_read_c0_guest_entryhi(cop0))
+   
(KVM_ASID_MASK(kvm_read_c0_guest_entryhi(cop0))
  != nasid)) {
 
kvm_debug
("MTCz, change ASID from %#lx to 
%#lx\n",
-
ASID_MASK(kvm_read_c0_guest_entryhi(cop0)),
-ASID_MASK(vcpu->arch.gprs[rt]));
+
KVM_ASID_MASK(kvm_read_c0_guest_entryhi(cop0)),
+
KVM_ASID_MASK(vcpu->arch.gprs[rt]));
 
/* Blow away the shadow host TLBs */
kvm_mips_flush_host_tlb(1);
@@ -986,7 +986,7 @@ kvm_mips_emulate_cache(uint32_t inst, uint32_t *opc, 
uint32_t cause,
 * resulting handler will do the right thing
 */
index = kvm_mips_guest_tlb_lookup(vcpu, (va & VPN2_MASK) |
- 
ASID_MASK(kvm_read_c0_guest_entryhi(cop0)));
+ 
KVM_ASID_MASK(kvm_read_c0_guest_entryhi(cop0)));
 
if (index < 0) {
vcpu->arch.host_cp0_entryhi = (va & VPN2_MASK);
@@ -1151,7 +1151,7 @@ kvm_mips_emulate_tlbmiss_ld(unsigned long cause, uint32_t 
*opc,
struct kvm_vcpu_arch *arch = &vcpu->arch;
enum emulation_result er = EMULATE_DONE;
unsigned long entryhi = (vcpu->arch.  host_cp0_badvaddr & VPN2_MASK) |
-   ASID_MASK(kvm_read_c0_guest_entryhi(cop0));
+   KVM_ASID_MASK(kvm_read_c0_guest_entryhi(cop0));
 
if ((kvm_read_c0_guest_status(cop0) & ST0_EXL) == 0) {
/* save old pc */
@@ -1198,7 +1198,7 @@ kvm_mips_emulate_tlbinv_ld(unsigned long cause, uint32_t 
*opc,
enum emulation_result er = EMULATE_DONE;
unsigned long entryhi =
(vcpu->arch.host_cp0_badvaddr & VPN2_MASK) |
-   ASID_MASK(kvm_read_c0_guest_entryhi(cop0));
+   KVM_ASID_MASK(kvm_read_c0_guest_entryhi(cop0));
 
if ((kvm_read_c0_guest_status(cop0) & ST0_EXL) == 0) {
/* save old pc */
@@ -1243,7 +1243,7 @@ kvm_mips_emulate_tlbmiss_st(unsigned long cause, uint32_t 
*opc,
struct kvm_vcpu_arch *arch = &vcpu->arch;
enum emulation_result er = EMULATE_DONE;
unsigned long entryhi = (vcpu->arch.host_cp0_badvaddr & VPN2_MASK) |
-   ASID_MASK(kvm_read_c0_guest_entryhi(cop0));
+   KVM_ASID_MASK(kvm_read_c0_guest_entryhi(cop0));
 
if ((kvm_read_c0_guest_status(cop0) & ST0_EXL) == 0) {
/* save old pc */
@@ -1287,7 +1287,7 @@ kvm_mips_emulate_tlbinv_st(unsigned long cause, uint32_t 
*opc,
struct kvm_vcpu_arch *arch = &vcpu

[PATCH 2/3] KVM/MIPS32: Wrap calls to gfn_to_pfn() with srcu_read_lock/unlock()

2013-05-17 Thread Sanjay Lal
- As suggested by Gleb, wrap calls to gfn_to_pfn() with srcu_read_lock/unlock().
  Memory slots should be acccessed from a SRCU read section.
- kvm_mips_map_page() now returns an error code to it's callers, instead of 
calling panic()
 if it cannot find a mapping for a particular gfn.

Signed-off-by: Sanjay Lal 
---
 arch/mips/kvm/kvm_tlb.c | 36 +++-
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/arch/mips/kvm/kvm_tlb.c b/arch/mips/kvm/kvm_tlb.c
index 89511a9..ab2e9b0 100644
--- a/arch/mips/kvm/kvm_tlb.c
+++ b/arch/mips/kvm/kvm_tlb.c
@@ -16,7 +16,10 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
+
 
 #include 
 #include 
@@ -169,21 +172,27 @@ void kvm_mips_dump_shadow_tlbs(struct kvm_vcpu *vcpu)
}
 }
 
-static void kvm_mips_map_page(struct kvm *kvm, gfn_t gfn)
+static int kvm_mips_map_page(struct kvm *kvm, gfn_t gfn)
 {
+   int srcu_idx, err = 0;
pfn_t pfn;
 
if (kvm->arch.guest_pmap[gfn] != KVM_INVALID_PAGE)
-   return;
+   return 0;
 
+srcu_idx = srcu_read_lock(&kvm->srcu);
pfn = kvm_mips_gfn_to_pfn(kvm, gfn);
 
if (kvm_mips_is_error_pfn(pfn)) {
-   panic("Couldn't get pfn for gfn %#" PRIx64 "!\n", gfn);
+   kvm_err("Couldn't get pfn for gfn %#" PRIx64 "!\n", gfn);
+   err = -EFAULT;
+   goto out;
}
 
kvm->arch.guest_pmap[gfn] = pfn;
-   return;
+out:
+   srcu_read_unlock(&kvm->srcu, srcu_idx);
+   return err;
 }
 
 /* Translate guest KSEG0 addresses to Host PA */
@@ -207,7 +216,10 @@ unsigned long kvm_mips_translate_guest_kseg0_to_hpa(struct 
kvm_vcpu *vcpu,
gva);
return KVM_INVALID_PAGE;
}
-   kvm_mips_map_page(vcpu->kvm, gfn);
+
+   if (kvm_mips_map_page(vcpu->kvm, gfn) < 0)
+   return KVM_INVALID_ADDR;
+
return (kvm->arch.guest_pmap[gfn] << PAGE_SHIFT) + offset;
 }
 
@@ -310,8 +322,11 @@ int kvm_mips_handle_kseg0_tlb_fault(unsigned long badvaddr,
even = !(gfn & 0x1);
vaddr = badvaddr & (PAGE_MASK << 1);
 
-   kvm_mips_map_page(vcpu->kvm, gfn);
-   kvm_mips_map_page(vcpu->kvm, gfn ^ 0x1);
+   if (kvm_mips_map_page(vcpu->kvm, gfn) < 0)
+   return -1;
+
+   if (kvm_mips_map_page(vcpu->kvm, gfn ^ 0x1) < 0)
+   return -1;
 
if (even) {
pfn0 = kvm->arch.guest_pmap[gfn];
@@ -389,8 +404,11 @@ kvm_mips_handle_mapped_seg_tlb_fault(struct kvm_vcpu *vcpu,
pfn0 = 0;
pfn1 = 0;
} else {
-   kvm_mips_map_page(kvm, mips3_tlbpfn_to_paddr(tlb->tlb_lo0) >> 
PAGE_SHIFT);
-   kvm_mips_map_page(kvm, mips3_tlbpfn_to_paddr(tlb->tlb_lo1) >> 
PAGE_SHIFT);
+   if (kvm_mips_map_page(kvm, mips3_tlbpfn_to_paddr(tlb->tlb_lo0) 
>> PAGE_SHIFT) < 0)
+   return -1;
+
+   if (kvm_mips_map_page(kvm, mips3_tlbpfn_to_paddr(tlb->tlb_lo1) 
>> PAGE_SHIFT) < 0)
+   return -1;
 
pfn0 = kvm->arch.guest_pmap[mips3_tlbpfn_to_paddr(tlb->tlb_lo0) 
>> PAGE_SHIFT];
pfn1 = kvm->arch.guest_pmap[mips3_tlbpfn_to_paddr(tlb->tlb_lo1) 
>> PAGE_SHIFT];
-- 
1.7.11.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


[PATCH v2 0/3] KVM/MIPS32: Fixes for Linux 3.10

2013-05-17 Thread Sanjay Lal
The following patch set fixes a few issues with KVM/MIPS32 in Linux 3.10.

--

Sanjay Lal (3):
  KVM/MIPS32: Move include/asm/kvm.h => include/uapi/asm/kvm.h since it
is a user visible API.
  KVM/MIPS32: Wrap calls to gfn_to_pfn() with srcu_read_lock/unlock()
  KVM/MIPS32: Fix up KVM breakage caused by
d532f3d26716a39dfd4b88d687bd344fbe77e390 which allows ASID mask
and increment to be determined @ runtime.

 arch/mips/include/asm/kvm.h  | 55 ---
 arch/mips/include/asm/kvm_host.h |  5 
 arch/mips/include/uapi/asm/kvm.h | 55 +++
 arch/mips/kvm/kvm_mips_emul.c| 22 
 arch/mips/kvm/kvm_tlb.c  | 56 ++--
 5 files changed, 108 insertions(+), 85 deletions(-)
 delete mode 100644 arch/mips/include/asm/kvm.h
 create mode 100644 arch/mips/include/uapi/asm/kvm.h

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


[PATCH 1/3] KVM/MIPS32: Move include/asm/kvm.h => include/uapi/asm/kvm.h since it is a user visible API.

2013-05-17 Thread Sanjay Lal

Signed-off-by: Sanjay Lal 
---
 arch/mips/include/asm/kvm.h  | 55 
 arch/mips/include/uapi/asm/kvm.h | 55 
 2 files changed, 55 insertions(+), 55 deletions(-)
 delete mode 100644 arch/mips/include/asm/kvm.h
 create mode 100644 arch/mips/include/uapi/asm/kvm.h

diff --git a/arch/mips/include/asm/kvm.h b/arch/mips/include/asm/kvm.h
deleted file mode 100644
index 85789ea..000
--- a/arch/mips/include/asm/kvm.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
-* This file is subject to the terms and conditions of the GNU General Public
-* License.  See the file "COPYING" in the main directory of this archive
-* for more details.
-*
-* Copyright (C) 2012  MIPS Technologies, Inc.  All rights reserved.
-* Authors: Sanjay Lal 
-*/
-
-#ifndef __LINUX_KVM_MIPS_H
-#define __LINUX_KVM_MIPS_H
-
-#include 
-
-#define __KVM_MIPS
-
-#define N_MIPS_COPROC_REGS  32
-#define N_MIPS_COPROC_SEL  8
-
-/* for KVM_GET_REGS and KVM_SET_REGS */
-struct kvm_regs {
-   __u32 gprs[32];
-   __u32 hi;
-   __u32 lo;
-   __u32 pc;
-
-   __u32 cp0reg[N_MIPS_COPROC_REGS][N_MIPS_COPROC_SEL];
-};
-
-/* for KVM_GET_SREGS and KVM_SET_SREGS */
-struct kvm_sregs {
-};
-
-/* for KVM_GET_FPU and KVM_SET_FPU */
-struct kvm_fpu {
-};
-
-struct kvm_debug_exit_arch {
-};
-
-/* for KVM_SET_GUEST_DEBUG */
-struct kvm_guest_debug_arch {
-};
-
-struct kvm_mips_interrupt {
-   /* in */
-   __u32 cpu;
-   __u32 irq;
-};
-
-/* definition of registers in kvm_run */
-struct kvm_sync_regs {
-};
-
-#endif /* __LINUX_KVM_MIPS_H */
diff --git a/arch/mips/include/uapi/asm/kvm.h b/arch/mips/include/uapi/asm/kvm.h
new file mode 100644
index 000..85789ea
--- /dev/null
+++ b/arch/mips/include/uapi/asm/kvm.h
@@ -0,0 +1,55 @@
+/*
+* This file is subject to the terms and conditions of the GNU General Public
+* License.  See the file "COPYING" in the main directory of this archive
+* for more details.
+*
+* Copyright (C) 2012  MIPS Technologies, Inc.  All rights reserved.
+* Authors: Sanjay Lal 
+*/
+
+#ifndef __LINUX_KVM_MIPS_H
+#define __LINUX_KVM_MIPS_H
+
+#include 
+
+#define __KVM_MIPS
+
+#define N_MIPS_COPROC_REGS  32
+#define N_MIPS_COPROC_SEL  8
+
+/* for KVM_GET_REGS and KVM_SET_REGS */
+struct kvm_regs {
+   __u32 gprs[32];
+   __u32 hi;
+   __u32 lo;
+   __u32 pc;
+
+   __u32 cp0reg[N_MIPS_COPROC_REGS][N_MIPS_COPROC_SEL];
+};
+
+/* for KVM_GET_SREGS and KVM_SET_SREGS */
+struct kvm_sregs {
+};
+
+/* for KVM_GET_FPU and KVM_SET_FPU */
+struct kvm_fpu {
+};
+
+struct kvm_debug_exit_arch {
+};
+
+/* for KVM_SET_GUEST_DEBUG */
+struct kvm_guest_debug_arch {
+};
+
+struct kvm_mips_interrupt {
+   /* in */
+   __u32 cpu;
+   __u32 irq;
+};
+
+/* definition of registers in kvm_run */
+struct kvm_sync_regs {
+};
+
+#endif /* __LINUX_KVM_MIPS_H */
-- 
1.7.11.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


[PATCH] KVM/MIPS32: Export min_low_pfn.

2013-05-17 Thread Sanjay Lal
The KVM module uses the standard MIPS cache management routines, which use 
min_low_pfn.
This creates and indirect dependency, requiring min_low_pfn to be exported.

Signed-off-by: Sanjay Lal 
---
 arch/mips/kernel/mips_ksyms.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/mips/kernel/mips_ksyms.c b/arch/mips/kernel/mips_ksyms.c
index 6e58e97..0299472 100644
--- a/arch/mips/kernel/mips_ksyms.c
+++ b/arch/mips/kernel/mips_ksyms.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 extern void *__bzero(void *__s, size_t __count);
 extern long __strncpy_from_user_nocheck_asm(char *__to,
@@ -60,3 +61,8 @@ EXPORT_SYMBOL(invalid_pte_table);
 /* _mcount is defined in arch/mips/kernel/mcount.S */
 EXPORT_SYMBOL(_mcount);
 #endif
+
+/* The KVM module uses the standard MIPS cache functions which use
+ * min_low_pfn, requiring it to be exported.
+ */
+EXPORT_SYMBOL(min_low_pfn);
-- 
1.7.11.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: [PATCH] KVM: allow host header to be included even for !CONFIG_KVM

2013-05-17 Thread Kevin Hilman
Frederic Weisbecker  writes:

> On Fri, May 17, 2013 at 07:09:42AM -0700, Kevin Hilman wrote:
>> Frederic Weisbecker  writes:
>> 
>> > On Thu, May 16, 2013 at 12:52:03AM +0200, Frederic Weisbecker wrote:
>> >> On Mon, Mar 25, 2013 at 02:14:20PM -0700, Kevin Hilman wrote:
>> >> > Gleb Natapov  writes:
>> >> > 
>> >> > > On Sun, Mar 24, 2013 at 02:44:26PM +0100, Frederic Weisbecker wrote:
>> >> > >> 2013/3/21 Gleb Natapov :
>> >> > >> > Isn't is simpler for kernel/context_tracking.c to define empty
>> >> > >> > __guest_enter()/__guest_exit() if !CONFIG_KVM.
>> >> > >> 
>> >> > >> That doesn't look right. Off-cases are usually handled from the
>> >> > >> headers, right? So that we avoid iffdeffery ugliness in core code.
>> >> > > Lets put it in linux/context_tracking.h header then.
>> >> > 
>> >> > Here's a version to do that.
>> >> > 
>> >> > Kevin
>> >> > 
>> >> > From d9d909394479dd7ff90b7bddb95a564945406719 Mon Sep 17 00:00:00 2001
>> >> > From: Kevin Hilman 
>> >> > Date: Mon, 25 Mar 2013 14:12:41 -0700
>> >> > Subject: [PATCH v2] ontext_tracking: fix !CONFIG_KVM compile: add stub 
>> >> > guest
>> >> >  enter/exit
>> >> 
>> >> Sorry for my very delayed response...
>> >> 
>> >> > 
>> >> > When KVM is not enabled, or not available on a platform, the KVM
>> >> > headers should not be included.  Instead, just define stub
>> >> > __guest_[enter|exit] functions.
>> >> 
>> >> May be it would be cleaner to move guest_enter/exit definitions altogether
>> >> in linux/context_tracking.h
>> >> 
>> >> After all that's where the implementation mostly belong to.
>> >> 
>> >> Let me see if I can get that in shape.
>> >
>> > Does the following work for you?
>> 
>> Nope. 
>> 
>> Since it still includs kvm_host.h on non-KVM builds, there is potential
>> for problems.  For example, on ARM (v3.10-rc1 + this patch) has this
>> build error:
>> 
>>   CC  kernel/context_tracking.o
>> In file included from 
>> /work/kernel/linaro/nohz/arch/arm/include/asm/kvm_host.h:41:0,
>>  from /work/kernel/linaro/nohz/include/linux/kvm_host.h:34,
>>  from /work/kernel/linaro/nohz/kernel/context_tracking.c:18:
>> /work/kernel/linaro/nohz/arch/arm/include/asm/kvm_vgic.h:38:6: warning: 
>> "CONFIG_KVM_ARM_MAX_VCPUS" is not defined [-Wundef]
>> In file included from 
>> /work/kernel/linaro/nohz/arch/arm/include/asm/kvm_host.h:41:0,
>>  from /work/kernel/linaro/nohz/include/linux/kvm_host.h:34,
>>  from /work/kernel/linaro/nohz/kernel/context_tracking.c:18:
>> /work/kernel/linaro/nohz/arch/arm/include/asm/kvm_vgic.h:59:11: error: 
>> 'CONFIG_KVM_ARM_MAX_VCPUS' undeclared here (not in a function)
>
> Sorry I forgot to remove the include to kvm_host.h in context_tracking.c,
> here's the fixed patch:

Yup, that one builds just fine.

Reviewed-and-Tested-by: Kevin Hilman 

Kevin
--
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] KVM: allow host header to be included even for !CONFIG_KVM

2013-05-17 Thread Frederic Weisbecker
On Fri, May 17, 2013 at 07:09:42AM -0700, Kevin Hilman wrote:
> Frederic Weisbecker  writes:
> 
> > On Thu, May 16, 2013 at 12:52:03AM +0200, Frederic Weisbecker wrote:
> >> On Mon, Mar 25, 2013 at 02:14:20PM -0700, Kevin Hilman wrote:
> >> > Gleb Natapov  writes:
> >> > 
> >> > > On Sun, Mar 24, 2013 at 02:44:26PM +0100, Frederic Weisbecker wrote:
> >> > >> 2013/3/21 Gleb Natapov :
> >> > >> > Isn't is simpler for kernel/context_tracking.c to define empty
> >> > >> > __guest_enter()/__guest_exit() if !CONFIG_KVM.
> >> > >> 
> >> > >> That doesn't look right. Off-cases are usually handled from the
> >> > >> headers, right? So that we avoid iffdeffery ugliness in core code.
> >> > > Lets put it in linux/context_tracking.h header then.
> >> > 
> >> > Here's a version to do that.
> >> > 
> >> > Kevin
> >> > 
> >> > From d9d909394479dd7ff90b7bddb95a564945406719 Mon Sep 17 00:00:00 2001
> >> > From: Kevin Hilman 
> >> > Date: Mon, 25 Mar 2013 14:12:41 -0700
> >> > Subject: [PATCH v2] ontext_tracking: fix !CONFIG_KVM compile: add stub 
> >> > guest
> >> >  enter/exit
> >> 
> >> Sorry for my very delayed response...
> >> 
> >> > 
> >> > When KVM is not enabled, or not available on a platform, the KVM
> >> > headers should not be included.  Instead, just define stub
> >> > __guest_[enter|exit] functions.
> >> 
> >> May be it would be cleaner to move guest_enter/exit definitions altogether
> >> in linux/context_tracking.h
> >> 
> >> After all that's where the implementation mostly belong to.
> >> 
> >> Let me see if I can get that in shape.
> >
> > Does the following work for you?
> 
> Nope. 
> 
> Since it still includs kvm_host.h on non-KVM builds, there is potential
> for problems.  For example, on ARM (v3.10-rc1 + this patch) has this
> build error:
> 
>   CC  kernel/context_tracking.o
> In file included from 
> /work/kernel/linaro/nohz/arch/arm/include/asm/kvm_host.h:41:0,
>  from /work/kernel/linaro/nohz/include/linux/kvm_host.h:34,
>  from /work/kernel/linaro/nohz/kernel/context_tracking.c:18:
> /work/kernel/linaro/nohz/arch/arm/include/asm/kvm_vgic.h:38:6: warning: 
> "CONFIG_KVM_ARM_MAX_VCPUS" is not defined [-Wundef]
> In file included from 
> /work/kernel/linaro/nohz/arch/arm/include/asm/kvm_host.h:41:0,
>  from /work/kernel/linaro/nohz/include/linux/kvm_host.h:34,
>  from /work/kernel/linaro/nohz/kernel/context_tracking.c:18:
> /work/kernel/linaro/nohz/arch/arm/include/asm/kvm_vgic.h:59:11: error: 
> 'CONFIG_KVM_ARM_MAX_VCPUS' undeclared here (not in a function)

Sorry I forgot to remove the include to kvm_host.h in context_tracking.c,
here's the fixed patch:

diff --git a/include/linux/context_tracking.h b/include/linux/context_tracking.h
index 365f4a6..fc09d7b 100644
--- a/include/linux/context_tracking.h
+++ b/include/linux/context_tracking.h
@@ -3,6 +3,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 struct context_tracking {
@@ -19,6 +20,26 @@ struct context_tracking {
} state;
 };
 
+static inline void __guest_enter(void)
+{
+   /*
+* This is running in ioctl context so we can avoid
+* the call to vtime_account() with its unnecessary idle check.
+*/
+   vtime_account_system(current);
+   current->flags |= PF_VCPU;
+}
+
+static inline void __guest_exit(void)
+{
+   /*
+* This is running in ioctl context so we can avoid
+* the call to vtime_account() with its unnecessary idle check.
+*/
+   vtime_account_system(current);
+   current->flags &= ~PF_VCPU;
+}
+
 #ifdef CONFIG_CONTEXT_TRACKING
 DECLARE_PER_CPU(struct context_tracking, context_tracking);
 
@@ -35,6 +56,9 @@ static inline bool context_tracking_active(void)
 extern void user_enter(void);
 extern void user_exit(void);
 
+extern void guest_enter(void);
+extern void guest_exit(void);
+
 static inline enum ctx_state exception_enter(void)
 {
enum ctx_state prev_ctx;
@@ -57,6 +81,17 @@ extern void context_tracking_task_switch(struct task_struct 
*prev,
 static inline bool context_tracking_in_user(void) { return false; }
 static inline void user_enter(void) { }
 static inline void user_exit(void) { }
+
+static inline void guest_enter(void)
+{
+   __guest_enter();
+}
+
+static inline void guest_exit(void)
+{
+   __guest_exit();
+}
+
 static inline enum ctx_state exception_enter(void) { return 0; }
 static inline void exception_exit(enum ctx_state prev_ctx) { }
 static inline void context_tracking_task_switch(struct task_struct *prev,
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index f0eea07..8db53cf 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -760,42 +761,6 @@ static inline int kvm_iommu_unmap_guest(struct kvm *kvm)
 }
 #endif
 
-static inline void __guest_enter(void)
-{
-   /*
-* This is running in ioctl context so we can avoid
-*

Re: [PATCH] KVM: allow host header to be included even for !CONFIG_KVM

2013-05-17 Thread Kevin Hilman
Frederic Weisbecker  writes:

> On Thu, May 16, 2013 at 12:52:03AM +0200, Frederic Weisbecker wrote:
>> On Mon, Mar 25, 2013 at 02:14:20PM -0700, Kevin Hilman wrote:
>> > Gleb Natapov  writes:
>> > 
>> > > On Sun, Mar 24, 2013 at 02:44:26PM +0100, Frederic Weisbecker wrote:
>> > >> 2013/3/21 Gleb Natapov :
>> > >> > Isn't is simpler for kernel/context_tracking.c to define empty
>> > >> > __guest_enter()/__guest_exit() if !CONFIG_KVM.
>> > >> 
>> > >> That doesn't look right. Off-cases are usually handled from the
>> > >> headers, right? So that we avoid iffdeffery ugliness in core code.
>> > > Lets put it in linux/context_tracking.h header then.
>> > 
>> > Here's a version to do that.
>> > 
>> > Kevin
>> > 
>> > From d9d909394479dd7ff90b7bddb95a564945406719 Mon Sep 17 00:00:00 2001
>> > From: Kevin Hilman 
>> > Date: Mon, 25 Mar 2013 14:12:41 -0700
>> > Subject: [PATCH v2] ontext_tracking: fix !CONFIG_KVM compile: add stub 
>> > guest
>> >  enter/exit
>> 
>> Sorry for my very delayed response...
>> 
>> > 
>> > When KVM is not enabled, or not available on a platform, the KVM
>> > headers should not be included.  Instead, just define stub
>> > __guest_[enter|exit] functions.
>> 
>> May be it would be cleaner to move guest_enter/exit definitions altogether
>> in linux/context_tracking.h
>> 
>> After all that's where the implementation mostly belong to.
>> 
>> Let me see if I can get that in shape.
>
> Does the following work for you?

Nope. 

Since it still includs kvm_host.h on non-KVM builds, there is potential
for problems.  For example, on ARM (v3.10-rc1 + this patch) has this
build error:

  CC  kernel/context_tracking.o
In file included from 
/work/kernel/linaro/nohz/arch/arm/include/asm/kvm_host.h:41:0,
 from /work/kernel/linaro/nohz/include/linux/kvm_host.h:34,
 from /work/kernel/linaro/nohz/kernel/context_tracking.c:18:
/work/kernel/linaro/nohz/arch/arm/include/asm/kvm_vgic.h:38:6: warning: 
"CONFIG_KVM_ARM_MAX_VCPUS" is not defined [-Wundef]
In file included from 
/work/kernel/linaro/nohz/arch/arm/include/asm/kvm_host.h:41:0,
 from /work/kernel/linaro/nohz/include/linux/kvm_host.h:34,
 from /work/kernel/linaro/nohz/kernel/context_tracking.c:18:
/work/kernel/linaro/nohz/arch/arm/include/asm/kvm_vgic.h:59:11: error: 
'CONFIG_KVM_ARM_MAX_VCPUS' undeclared here (not in a function)

Kevin
--
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 7/8] s390/kvm: avoid automatic sie reentry

2013-05-17 Thread Christian Borntraeger
From: Martin Schwidefsky 

Do not automatically restart the sie instruction in entry64.S after an
interrupt, return to the caller with a reason code instead. That allows
to deal with RCU and other conditions in C code.

Signed-off-by: Martin Schwidefsky 
Signed-off-by: Christian Borntraeger 
---
 arch/s390/kernel/entry64.S | 76 --
 arch/s390/kvm/kvm-s390.c   |  4 ++-
 2 files changed, 36 insertions(+), 44 deletions(-)

diff --git a/arch/s390/kernel/entry64.S b/arch/s390/kernel/entry64.S
index c7daeef..51d99ac 100644
--- a/arch/s390/kernel/entry64.S
+++ b/arch/s390/kernel/entry64.S
@@ -47,7 +47,6 @@ _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | 
_TIF_NEED_RESCHED | \
 _TIF_MCCK_PENDING)
 _TIF_TRACE= (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
 _TIF_SYSCALL_TRACEPOINT)
-_TIF_EXIT_SIE = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_MCCK_PENDING)
 
 #define BASED(name) name-system_call(%r13)
 
@@ -81,25 +80,27 @@ _TIF_EXIT_SIE = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | 
_TIF_MCCK_PENDING)
 #endif
.endm
 
-   .macro  HANDLE_SIE_INTERCEPT scratch,pgmcheck
+   .macro  HANDLE_SIE_INTERCEPT scratch,reason
 #if defined(CONFIG_KVM) || defined(CONFIG_KVM_MODULE)
tmhh%r8,0x0001  # interrupting from user ?
-   jnz .+52
+   jnz .+62
lgr \scratch,%r9
-   slg \scratch,BASED(.Lsie_loop)
-   clg \scratch,BASED(.Lsie_length)
-   .if \pgmcheck
+   slg \scratch,BASED(.Lsie_critical)
+   clg \scratch,BASED(.Lsie_critical_length)
+   .if \reason==1
# Some program interrupts are suppressing (e.g. protection).
# We must also check the instruction after SIE in that case.
# do_protection_exception will rewind to rewind_pad
-   jh  .+32
+   jh  .+42
.else
-   jhe .+32
+   jhe .+42
.endif
-   lg  %r9,BASED(.Lsie_loop)
-   LPP BASED(.Lhost_id)# set host id
-   lg  %r14,__SF_EMPTY(%r15)   # get control block pointer
+   lg  %r14,__SF_EMPTY(%r15)   # get control block pointer
+   LPP __SF_EMPTY+16(%r15) # set host id
ni  __SIE_PROG0C+3(%r14),0xfe   # no longer in SIE
+   lctlg   %c1,%c1,__LC_USER_ASCE  # load primary asce
+   larl%r9,sie_exit# skip forward to sie_exit
+   mvi __SF_EMPTY+31(%r15),\reason # set exit reason
 #endif
.endm
 
@@ -452,7 +453,7 @@ ENTRY(io_int_handler)
lg  %r12,__LC_THREAD_INFO
larl%r13,system_call
lmg %r8,%r9,__LC_IO_OLD_PSW
-   HANDLE_SIE_INTERCEPT %r14,0
+   HANDLE_SIE_INTERCEPT %r14,2
SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_STACK,STACK_SHIFT
tmhh%r8,0x0001  # interrupting from user?
jz  io_skip
@@ -597,7 +598,7 @@ ENTRY(ext_int_handler)
lg  %r12,__LC_THREAD_INFO
larl%r13,system_call
lmg %r8,%r9,__LC_EXT_OLD_PSW
-   HANDLE_SIE_INTERCEPT %r14,0
+   HANDLE_SIE_INTERCEPT %r14,3
SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_STACK,STACK_SHIFT
tmhh%r8,0x0001  # interrupting from user ?
jz  ext_skip
@@ -645,7 +646,7 @@ ENTRY(mcck_int_handler)
lg  %r12,__LC_THREAD_INFO
larl%r13,system_call
lmg %r8,%r9,__LC_MCK_OLD_PSW
-   HANDLE_SIE_INTERCEPT %r14,0
+   HANDLE_SIE_INTERCEPT %r14,4
tm  __LC_MCCK_CODE,0x80 # system damage?
jo  mcck_panic  # yes -> rest of mcck code invalid
lghi%r14,__LC_CPU_TIMER_SAVE_AREA
@@ -939,19 +940,8 @@ ENTRY(sie64a)
stmg%r6,%r14,__SF_GPRS(%r15)# save kernel registers
stg %r2,__SF_EMPTY(%r15)# save control block pointer
stg %r3,__SF_EMPTY+8(%r15)  # save guest register save area
-   xc  __SF_EMPTY+16(8,%r15),__SF_EMPTY+16(%r15) # host id == 0
+   xc  __SF_EMPTY+16(16,%r15),__SF_EMPTY+16(%r15) # host id & reason
lmg %r0,%r13,0(%r3) # load guest gprs 0-13
-# some program checks are suppressing. C code (e.g. do_protection_exception)
-# will rewind the PSW by the ILC, which is 4 bytes in case of SIE. Other
-# instructions in the sie_loop should not cause program interrupts. So
-# lets use a nop (47 00 00 00) as a landing pad.
-# See also HANDLE_SIE_INTERCEPT
-rewind_pad:
-   nop 0
-sie_loop:
-   lg  %r14,__LC_THREAD_INFO   # pointer thread_info struct
-   tm  __TI_flags+7(%r14),_TIF_EXIT_SIE
-   jnz sie_exit
lg  %r14,__LC_GMAP  # get gmap pointer
ltgr%r14,%r14
jz  sie_gmap
@@ -966,33 +956,33 @@ sie_gmap:
 sie_done:
LPP __SF_EMPTY+16(%r15) # set host id
ni  __SIE_PROG0C+3(%

[PATCH 0/8] s390/kvm fixes

2013-05-17 Thread Christian Borntraeger
Gleb, Paolo, Marcelo,

here are some low level changes to kvm on s390 that we have been
cooking for a while now.

Patch "s390/pgtable: fix ipte notify bit" will go via Martins
tree into 3.10, but is included to reduce the amount of merge
conflicts. 

Patch "s390: fix gmap_ipte_notifier vs. software dirty pages"
will also go via Martins tree into 3.10 and it fixes a hang with
heavy host paging and KVM. This is optional for merging, but
makes testing on kvm/next easier.

This series addresses 2 problems:
- paging of guest prefix page
- RCU timeouts

The first problem is basically that we must not have the host pte
invalid or r/o for the guest prefix pages. (everything else has fully
nested paging but the prefix page must not cause host faults).
It is not enough to pin the page, also the pte has to be r/w all the
time. Mlocking is not enough due to memory compaction, malicious
unmapping etc.
We use the existing callback mechanism of the s390 page table functions
to kick guests out of SIE and hold them until this is done. We cant 
use the existing kick functions since we must hold a pgste lock while
we wait for SIE to exit and IPIs might dead lock.

The second problem is that with KVM on s390 we have seen very long
RCU stalls due to SIE not exiting on interrupts. Instead of returning
to SIE, we now force an exit into the kvm module, which then does the
guest exit/enter magic, fixing rcu.

The whole bunch is probably too complex for 3.10, so please queue for
3.11

Christian Borntraeger (5):
  s390/pgtable: fix ipte notify bit
  s390/kvm: Mark if a cpu is in SIE
  s390/kvm: Provide a way to prevent reentering SIE
  s390/kvm: Kick guests out of sie if prefix page host pte is touched
  s390: fix gmap_ipte_notifier vs. software dirty pages

Martin Schwidefsky (3):
  s390/kvm: fix psw rewinding in handle_skey
  s390/kvm: rename RCP_xxx defines to PGSTE_xxx
  s390/kvm: avoid automatic sie reentry

 arch/s390/include/asm/kvm_host.h |  8 +++-
 arch/s390/include/asm/pgtable.h  | 83 +++-
 arch/s390/kernel/asm-offsets.c   |  3 ++
 arch/s390/kernel/entry64.S   | 80 ++
 arch/s390/kvm/intercept.c| 39 +--
 arch/s390/kvm/kvm-s390.c | 81 ++-
 arch/s390/kvm/kvm-s390.h |  5 +++
 arch/s390/kvm/priv.c |  3 +-
 arch/s390/mm/pgtable.c   |  5 +--
 9 files changed, 179 insertions(+), 128 deletions(-)

-- 
1.8.1.4

--
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 4/8] s390/kvm: Mark if a cpu is in SIE

2013-05-17 Thread Christian Borntraeger
Lets track in a private bit if the sie control block is active.
We want to track this as closely as possible, so we also have to
instrument the interrupt and program check handler. Lets use the
existing HANDLE_SIE_INTERCEPT macro.

Signed-off-by: Christian Borntraeger 
Acked-by: Martin Schwidefsky 
---
 arch/s390/include/asm/kvm_host.h |  5 -
 arch/s390/kernel/asm-offsets.c   |  2 ++
 arch/s390/kernel/entry64.S   | 10 +++---
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index 16bd5d1..962b92e 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -68,7 +68,10 @@ struct sca_block {
 struct kvm_s390_sie_block {
atomic_t cpuflags;  /* 0x */
__u32   prefix; /* 0x0004 */
-   __u8reserved8[32];  /* 0x0008 */
+   __u8reserved08[4];  /* 0x0008 */
+#define PROG_IN_SIE (1<<0)
+   __u32   prog0c; /* 0x000c */
+   __u8reserved10[24]; /* 0x0010 */
__u64   cputm;  /* 0x0028 */
__u64   ckc;/* 0x0030 */
__u64   epoch;  /* 0x0038 */
diff --git a/arch/s390/kernel/asm-offsets.c b/arch/s390/kernel/asm-offsets.c
index 7a82f9f..6456bbe 100644
--- a/arch/s390/kernel/asm-offsets.c
+++ b/arch/s390/kernel/asm-offsets.c
@@ -7,6 +7,7 @@
 #define ASM_OFFSETS_C
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -161,6 +162,7 @@ int main(void)
DEFINE(__LC_PGM_TDB, offsetof(struct _lowcore, pgm_tdb));
DEFINE(__THREAD_trap_tdb, offsetof(struct task_struct, 
thread.trap_tdb));
DEFINE(__GMAP_ASCE, offsetof(struct gmap, asce));
+   DEFINE(__SIE_PROG0C, offsetof(struct kvm_s390_sie_block, prog0c));
 #endif /* CONFIG_32BIT */
return 0;
 }
diff --git a/arch/s390/kernel/entry64.S b/arch/s390/kernel/entry64.S
index 4c17eec..c2e81b4 100644
--- a/arch/s390/kernel/entry64.S
+++ b/arch/s390/kernel/entry64.S
@@ -84,7 +84,7 @@ _TIF_EXIT_SIE = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | 
_TIF_MCCK_PENDING)
.macro  HANDLE_SIE_INTERCEPT scratch,pgmcheck
 #if defined(CONFIG_KVM) || defined(CONFIG_KVM_MODULE)
tmhh%r8,0x0001  # interrupting from user ?
-   jnz .+42
+   jnz .+52
lgr \scratch,%r9
slg \scratch,BASED(.Lsie_loop)
clg \scratch,BASED(.Lsie_length)
@@ -92,12 +92,14 @@ _TIF_EXIT_SIE = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | 
_TIF_MCCK_PENDING)
# Some program interrupts are suppressing (e.g. protection).
# We must also check the instruction after SIE in that case.
# do_protection_exception will rewind to rewind_pad
-   jh  .+22
+   jh  .+32
.else
-   jhe .+22
+   jhe .+32
.endif
lg  %r9,BASED(.Lsie_loop)
LPP BASED(.Lhost_id)# set host id
+   lg  %r14,__SF_EMPTY(%r15)   # get control block pointer
+   ni  __SIE_PROG0C+3(%r14),0xfe   # no longer in SIE
 #endif
.endm
 
@@ -956,10 +958,12 @@ sie_loop:
lctlg   %c1,%c1,__GMAP_ASCE(%r14)   # load primary asce
 sie_gmap:
lg  %r14,__SF_EMPTY(%r15)   # get control block pointer
+   oi  __SIE_PROG0C+3(%r14),1  # we are in SIE now
LPP __SF_EMPTY(%r15)# set guest id
sie 0(%r14)
 sie_done:
LPP __SF_EMPTY+16(%r15) # set host id
+   ni  __SIE_PROG0C+3(%r14),0xfe   # no longer in SIE
lg  %r14,__LC_THREAD_INFO   # pointer thread_info struct
 sie_exit:
lctlg   %c1,%c1,__LC_USER_ASCE  # load primary asce
-- 
1.8.1.4

--
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 2/8] s390/kvm: fix psw rewinding in handle_skey

2013-05-17 Thread Christian Borntraeger
From: Martin Schwidefsky 

The PSW can wrap if the guest has been running in the 24 bit or 31 bit
addressing mode. Use __rewind_psw to find the correct address.

Signed-off-by: Martin Schwidefsky 
Signed-off-by: Christian Borntraeger 
---
 arch/s390/kvm/priv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index 6bbd7b5..ecc58a6 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -105,7 +105,8 @@ static int handle_store_cpu_address(struct kvm_vcpu *vcpu)
 static int handle_skey(struct kvm_vcpu *vcpu)
 {
vcpu->stat.instruction_storage_key++;
-   vcpu->arch.sie_block->gpsw.addr -= 4;
+   vcpu->arch.sie_block->gpsw.addr =
+   __rewind_psw(vcpu->arch.sie_block->gpsw, 4);
VCPU_EVENT(vcpu, 4, "%s", "retrying storage key operation");
return 0;
 }
-- 
1.8.1.4

--
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 8/8] s390: fix gmap_ipte_notifier vs. software dirty pages

2013-05-17 Thread Christian Borntraeger
On heavy paging load some guest cpus started to loop in gmap_ipte_notify.
This was visible as stalled cpus inside the guest. The gmap_ipte_notifier
tries to map a user page and then made sure that the pte is valid and
writable. Turns out that with the software change bit tracking the pte
can become read-only (and only software writable) if the page is clean.
Since we loop in this code, the page would stay clean and, therefore,
be never writable again.
Let us just use fixup_user_fault, that guarantees to call handle_mm_fault.

Signed-off-by: Christian Borntraeger 
---
 arch/s390/mm/pgtable.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c
index 5ca7568..1e0c438 100644
--- a/arch/s390/mm/pgtable.c
+++ b/arch/s390/mm/pgtable.c
@@ -677,8 +677,7 @@ int gmap_ipte_notify(struct gmap *gmap, unsigned long 
start, unsigned long len)
break;
}
/* Get the page mapped */
-   if (get_user_pages(current, gmap->mm, addr, 1, 1, 0,
-  NULL, NULL) != 1) {
+   if (fixup_user_fault(current, gmap->mm, addr, 
FAULT_FLAG_WRITE)) {
rc = -EFAULT;
break;
}
-- 
1.8.1.4

--
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 6/8] s390/kvm: Kick guests out of sie if prefix page host pte is touched

2013-05-17 Thread Christian Borntraeger
The guest prefix pages must be mapped writeable all the time
while SIE is running, otherwise the guest might see random
behaviour. (pinned at the pte level) Turns out that mlocking is
not enough, the page table entry (not the page) might change or
become r/o. This patch uses the gmap notifiers to kick guest
cpus out of SIE.

Signed-off-by: Christian Borntraeger 
Acked-by: Martin Schwidefsky 
---
 arch/s390/include/asm/pgtable.h |  1 +
 arch/s390/kvm/intercept.c   | 39 ++--
 arch/s390/kvm/kvm-s390.c| 49 +
 arch/s390/kvm/kvm-s390.h|  1 +
 4 files changed, 53 insertions(+), 37 deletions(-)

diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index 1fc68d9..1d0ad7d 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -739,6 +739,7 @@ struct gmap {
struct mm_struct *mm;
unsigned long *table;
unsigned long asce;
+   void *private;
struct list_head crst_list;
 };
 
diff --git a/arch/s390/kvm/intercept.c b/arch/s390/kvm/intercept.c
index b7d1b2e..f0b8be0 100644
--- a/arch/s390/kvm/intercept.c
+++ b/arch/s390/kvm/intercept.c
@@ -174,47 +174,12 @@ static int handle_stop(struct kvm_vcpu *vcpu)
 
 static int handle_validity(struct kvm_vcpu *vcpu)
 {
-   unsigned long vmaddr;
int viwhy = vcpu->arch.sie_block->ipb >> 16;
-   int rc;
 
vcpu->stat.exit_validity++;
trace_kvm_s390_intercept_validity(vcpu, viwhy);
-   if (viwhy == 0x37) {
-   vmaddr = gmap_fault(vcpu->arch.sie_block->prefix,
-   vcpu->arch.gmap);
-   if (IS_ERR_VALUE(vmaddr)) {
-   rc = -EOPNOTSUPP;
-   goto out;
-   }
-   rc = fault_in_pages_writeable((char __user *) vmaddr,
-PAGE_SIZE);
-   if (rc) {
-   /* user will receive sigsegv, exit to user */
-   rc = -EOPNOTSUPP;
-   goto out;
-   }
-   vmaddr = gmap_fault(vcpu->arch.sie_block->prefix + PAGE_SIZE,
-   vcpu->arch.gmap);
-   if (IS_ERR_VALUE(vmaddr)) {
-   rc = -EOPNOTSUPP;
-   goto out;
-   }
-   rc = fault_in_pages_writeable((char __user *) vmaddr,
-PAGE_SIZE);
-   if (rc) {
-   /* user will receive sigsegv, exit to user */
-   rc = -EOPNOTSUPP;
-   goto out;
-   }
-   } else
-   rc = -EOPNOTSUPP;
-
-out:
-   if (rc)
-   VCPU_EVENT(vcpu, 2, "unhandled validity intercept code %d",
-  viwhy);
-   return rc;
+   WARN_ONCE(true, "kvm: unhandled validity intercept 0x%x\n", viwhy);
+   return -EOPNOTSUPP;
 }
 
 static int handle_instruction(struct kvm_vcpu *vcpu)
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index ef4ef21..08227c1 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -84,6 +84,7 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
 };
 
 static unsigned long long *facilities;
+static struct gmap_notifier gmap_notifier;
 
 /* Section: not file related */
 int kvm_arch_hardware_enable(void *garbage)
@@ -96,13 +97,18 @@ void kvm_arch_hardware_disable(void *garbage)
 {
 }
 
+static void kvm_gmap_notifier(struct gmap *gmap, unsigned long address);
+
 int kvm_arch_hardware_setup(void)
 {
+   gmap_notifier.notifier_call = kvm_gmap_notifier;
+   gmap_register_ipte_notifier(&gmap_notifier);
return 0;
 }
 
 void kvm_arch_hardware_unsetup(void)
 {
+   gmap_unregister_ipte_notifier(&gmap_notifier);
 }
 
 void kvm_arch_check_processor_compat(void *rtn)
@@ -239,6 +245,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
kvm->arch.gmap = gmap_alloc(current->mm);
if (!kvm->arch.gmap)
goto out_nogmap;
+   kvm->arch.gmap->private = kvm;
}
 
kvm->arch.css_support = 0;
@@ -309,6 +316,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
vcpu->arch.gmap = gmap_alloc(current->mm);
if (!vcpu->arch.gmap)
return -ENOMEM;
+   vcpu->arch.gmap->private = vcpu->kvm;
return 0;
}
 
@@ -482,6 +490,22 @@ void exit_sie_sync(struct kvm_vcpu *vcpu)
exit_sie(vcpu);
 }
 
+static void kvm_gmap_notifier(struct gmap *gmap, unsigned long address)
+{
+   int i;
+   struct kvm *kvm = gmap->private;
+   struct kvm_vcpu *vcpu;
+
+   kvm_for_each_vcpu(i, vcpu, kvm) {
+   /* match against both prefix pages */
+   if (vcpu->arch.sie_block->prefix == (address & ~0x1000UL)) {
+   VCPU_EVENT(vcpu, 2, "gma

[PATCH 1/8] s390/pgtable: fix ipte notify bit

2013-05-17 Thread Christian Borntraeger
Dont use the same bit as user referenced.

Signed-off-by: Christian Borntraeger 
---
 arch/s390/include/asm/pgtable.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index 4105b82..0f0de30 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -306,7 +306,7 @@ extern unsigned long MODULES_END;
 #define RCP_HC_BIT 0x0020UL
 #define RCP_GR_BIT 0x0004UL
 #define RCP_GC_BIT 0x0002UL
-#define RCP_IN_BIT 0x8000UL/* IPTE notify bit */
+#define RCP_IN_BIT 0x2000UL/* IPTE notify bit */
 
 /* User dirty / referenced bit for KVM's migration feature */
 #define KVM_UR_BIT 0x8000UL
@@ -374,7 +374,7 @@ extern unsigned long MODULES_END;
 #define RCP_HC_BIT 0x0020UL
 #define RCP_GR_BIT 0x0004UL
 #define RCP_GC_BIT 0x0002UL
-#define RCP_IN_BIT 0x8000UL/* IPTE notify bit */
+#define RCP_IN_BIT 0x2000UL/* IPTE notify bit */
 
 /* User dirty / referenced bit for KVM's migration feature */
 #define KVM_UR_BIT 0x8000UL
-- 
1.8.1.4

--
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 3/8] s390/kvm: rename RCP_xxx defines to PGSTE_xxx

2013-05-17 Thread Christian Borntraeger
From: Martin Schwidefsky 

The RCP byte is a part of the PGSTE value, the existing RCP_xxx names
are inaccurate. As the defines describe bits and pieces of the PGSTE,
the names should start with PGSTE_. The KVM_UR_BIT and KVM_UC_BIT are
part of the PGSTE as well, give them better names as well.

Signed-off-by: Martin Schwidefsky 
Signed-off-by: Christian Borntraeger 
---
 arch/s390/include/asm/pgtable.h | 82 -
 arch/s390/mm/pgtable.c  |  2 +-
 2 files changed, 40 insertions(+), 44 deletions(-)

diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index 0f0de30..1fc68d9 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -299,18 +299,16 @@ extern unsigned long MODULES_END;
 #define _SEGMENT_ENTRY_EMPTY   (_SEGMENT_ENTRY_INV)
 
 /* Page status table bits for virtualization */
-#define RCP_ACC_BITS   0xf000UL
-#define RCP_FP_BIT 0x0800UL
-#define RCP_PCL_BIT0x0080UL
-#define RCP_HR_BIT 0x0040UL
-#define RCP_HC_BIT 0x0020UL
-#define RCP_GR_BIT 0x0004UL
-#define RCP_GC_BIT 0x0002UL
-#define RCP_IN_BIT 0x2000UL/* IPTE notify bit */
-
-/* User dirty / referenced bit for KVM's migration feature */
-#define KVM_UR_BIT 0x8000UL
-#define KVM_UC_BIT 0x4000UL
+#define PGSTE_ACC_BITS 0xf000UL
+#define PGSTE_FP_BIT   0x0800UL
+#define PGSTE_PCL_BIT  0x0080UL
+#define PGSTE_HR_BIT   0x0040UL
+#define PGSTE_HC_BIT   0x0020UL
+#define PGSTE_GR_BIT   0x0004UL
+#define PGSTE_GC_BIT   0x0002UL
+#define PGSTE_UR_BIT   0x8000UL
+#define PGSTE_UC_BIT   0x4000UL/* user dirty (migration) */
+#define PGSTE_IN_BIT   0x2000UL/* IPTE notify bit */
 
 #else /* CONFIG_64BIT */
 
@@ -367,18 +365,16 @@ extern unsigned long MODULES_END;
 | _SEGMENT_ENTRY_SPLIT | _SEGMENT_ENTRY_CO)
 
 /* Page status table bits for virtualization */
-#define RCP_ACC_BITS   0xf000UL
-#define RCP_FP_BIT 0x0800UL
-#define RCP_PCL_BIT0x0080UL
-#define RCP_HR_BIT 0x0040UL
-#define RCP_HC_BIT 0x0020UL
-#define RCP_GR_BIT 0x0004UL
-#define RCP_GC_BIT 0x0002UL
-#define RCP_IN_BIT 0x2000UL/* IPTE notify bit */
-
-/* User dirty / referenced bit for KVM's migration feature */
-#define KVM_UR_BIT 0x8000UL
-#define KVM_UC_BIT 0x4000UL
+#define PGSTE_ACC_BITS 0xf000UL
+#define PGSTE_FP_BIT   0x0800UL
+#define PGSTE_PCL_BIT  0x0080UL
+#define PGSTE_HR_BIT   0x0040UL
+#define PGSTE_HC_BIT   0x0020UL
+#define PGSTE_GR_BIT   0x0004UL
+#define PGSTE_GC_BIT   0x0002UL
+#define PGSTE_UR_BIT   0x8000UL
+#define PGSTE_UC_BIT   0x4000UL/* user dirty (migration) */
+#define PGSTE_IN_BIT   0x2000UL/* IPTE notify bit */
 
 #endif /* CONFIG_64BIT */
 
@@ -618,8 +614,8 @@ static inline pgste_t pgste_get_lock(pte_t *ptep)
asm(
"   lg  %0,%2\n"
"0: lgr %1,%0\n"
-   "   nihh%0,0xff7f\n"/* clear RCP_PCL_BIT in old */
-   "   oihh%1,0x0080\n"/* set RCP_PCL_BIT in new */
+   "   nihh%0,0xff7f\n"/* clear PCL bit in old */
+   "   oihh%1,0x0080\n"/* set PCL bit in new */
"   csg %0,%1,%2\n"
"   jl  0b\n"
: "=&d" (old), "=&d" (new), "=Q" (ptep[PTRS_PER_PTE])
@@ -632,7 +628,7 @@ static inline void pgste_set_unlock(pte_t *ptep, pgste_t 
pgste)
 {
 #ifdef CONFIG_PGSTE
asm(
-   "   nihh%1,0xff7f\n"/* clear RCP_PCL_BIT */
+   "   nihh%1,0xff7f\n"/* clear PCL bit */
"   stg %1,%0\n"
: "=Q" (ptep[PTRS_PER_PTE])
: "d" (pgste_val(pgste)), "Q" (ptep[PTRS_PER_PTE]) : "cc");
@@ -657,14 +653,14 @@ static inline pgste_t pgste_update_all(pte_t *ptep, 
pgste_t pgste)
else if (bits)
page_reset_referenced(address);
/* Transfer page changed & referenced bit to guest bits in pgste */
-   pgste_val(pgste) |= bits << 48; /* RCP_GR_BIT & RCP_GC_BIT */
+   pgste_val(pgste) |= bits << 48; /* GR bit & GC bit */
/* Get host changed & referenced bits from pgste */
-   bits |= (pgste_val(pgste) & (RCP_HR_BIT | RCP_HC_BIT)) >> 52;
+   bits |= (pgste_val(pgste) & (PGSTE_HR_BIT | PGSTE_HC_BIT)) >> 52;
/* Transfer page changed & referenced bit to kvm user bits */
-   pgste_val(pgste) |= bits << 45; /* KVM_UR_BIT & KVM_UC_BIT */
+   pgste_val(pgste) |= bits << 45; /* PGSTE_UR_BIT & PGSTE_UC_BIT 
*/
/* Clear relevant host bits in pgste. */
-   pgste_

[PATCH 5/8] s390/kvm: Provide a way to prevent reentering SIE

2013-05-17 Thread Christian Borntraeger
Lets provide functions to prevent KVM from reentering SIE and
to kick cpus out of SIE. We cannot use the common kvm_vcpu_kick code,
since we need to kick out guests in places that hold architecture
specific locks (e.g. pgste lock) which might be necessary on the
other cpus - so no waiting possible.

So lets provide a bit in a private field of the sie control block
that acts as a gate keeper, after we claimed we are in SIE.
Please note that we do not reuse prog0c, since we want to access
that bit without atomic ops.

Signed-off-by: Christian Borntraeger 
Acked-by: Martin Schwidefsky 
---
 arch/s390/include/asm/kvm_host.h |  5 -
 arch/s390/kernel/asm-offsets.c   |  1 +
 arch/s390/kernel/entry64.S   |  4 +++-
 arch/s390/kvm/kvm-s390.c | 28 
 arch/s390/kvm/kvm-s390.h |  4 
 5 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index 962b92e..9a809f9 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -71,7 +71,10 @@ struct kvm_s390_sie_block {
__u8reserved08[4];  /* 0x0008 */
 #define PROG_IN_SIE (1<<0)
__u32   prog0c; /* 0x000c */
-   __u8reserved10[24]; /* 0x0010 */
+   __u8reserved10[16]; /* 0x0010 */
+#define PROG_BLOCK_SIE 0x0001
+   atomic_t prog20;/* 0x0020 */
+   __u8reserved24[4];  /* 0x0024 */
__u64   cputm;  /* 0x0028 */
__u64   ckc;/* 0x0030 */
__u64   epoch;  /* 0x0038 */
diff --git a/arch/s390/kernel/asm-offsets.c b/arch/s390/kernel/asm-offsets.c
index 6456bbe..78db633 100644
--- a/arch/s390/kernel/asm-offsets.c
+++ b/arch/s390/kernel/asm-offsets.c
@@ -163,6 +163,7 @@ int main(void)
DEFINE(__THREAD_trap_tdb, offsetof(struct task_struct, 
thread.trap_tdb));
DEFINE(__GMAP_ASCE, offsetof(struct gmap, asce));
DEFINE(__SIE_PROG0C, offsetof(struct kvm_s390_sie_block, prog0c));
+   DEFINE(__SIE_PROG20, offsetof(struct kvm_s390_sie_block, prog20));
 #endif /* CONFIG_32BIT */
return 0;
 }
diff --git a/arch/s390/kernel/entry64.S b/arch/s390/kernel/entry64.S
index c2e81b4..c7daeef 100644
--- a/arch/s390/kernel/entry64.S
+++ b/arch/s390/kernel/entry64.S
@@ -958,7 +958,9 @@ sie_loop:
lctlg   %c1,%c1,__GMAP_ASCE(%r14)   # load primary asce
 sie_gmap:
lg  %r14,__SF_EMPTY(%r15)   # get control block pointer
-   oi  __SIE_PROG0C+3(%r14),1  # we are in SIE now
+   oi  __SIE_PROG0C+3(%r14),1  # we are going into SIE now
+   tm  __SIE_PROG20+3(%r14),1  # last exit...
+   jnz sie_done
LPP __SF_EMPTY(%r15)# set guest id
sie 0(%r14)
 sie_done:
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index c1c7c68..ef4ef21 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -454,6 +454,34 @@ int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu)
return 0;
 }
 
+void s390_vcpu_block(struct kvm_vcpu *vcpu)
+{
+   atomic_set_mask(PROG_BLOCK_SIE, &vcpu->arch.sie_block->prog20);
+}
+
+void s390_vcpu_unblock(struct kvm_vcpu *vcpu)
+{
+   atomic_clear_mask(PROG_BLOCK_SIE, &vcpu->arch.sie_block->prog20);
+}
+
+/*
+ * Kick a guest cpu out of SIE and wait until SIE is not running.
+ * If the CPU is not running (e.g. waiting as idle) the function will
+ * return immediately. */
+void exit_sie(struct kvm_vcpu *vcpu)
+{
+   atomic_set_mask(CPUSTAT_STOP_INT, &vcpu->arch.sie_block->cpuflags);
+   while (vcpu->arch.sie_block->prog0c & PROG_IN_SIE)
+   cpu_relax();
+}
+
+/* Kick a guest cpu out of SIE and prevent SIE-reentry */
+void exit_sie_sync(struct kvm_vcpu *vcpu)
+{
+   s390_vcpu_block(vcpu);
+   exit_sie(vcpu);
+}
+
 int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu)
 {
/* kvm common code refers to this, but never calls it */
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index efc14f6..7a8abfd 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -133,6 +133,10 @@ int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu);
 /* implemented in kvm-s390.c */
 int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu,
 unsigned long addr);
+void s390_vcpu_block(struct kvm_vcpu *vcpu);
+void s390_vcpu_unblock(struct kvm_vcpu *vcpu);
+void exit_sie(struct kvm_vcpu *vcpu);
+void exit_sie_sync(struct kvm_vcpu *vcpu);
 /* implemented in diag.c */
 int kvm_s390_handle_diag(struct kvm_vcpu *vcpu);
 
-- 
1.8.1.4

--
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] virtio_pci: fix macro exported in uapi

2013-05-17 Thread David Howells
Rusty Russell  wrote:

> Macro still isn't usable, because userspace can't know whether it's the
> new or old.
> 
> We need to either remove it from UAPI, or rename it to
> VIRTIO_PCI_CONFIG_OFF.

Surely, if userspace is using it as is, you can't remove it, rename it or
alter it?

David
--
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: 2013 Linux Plumbers Virtualization Microconference proposal call for participation

2013-05-17 Thread Stefan Hajnoczi
On Thu, May 16, 2013 at 02:32:30PM -0600, Alex Williamson wrote:
> We'd like to hold another virtualization microconference as part of this
> year's Linux Plumbers Conference.  To do so, we need to show that
> there's enough interest, materials, and people willing to attend. 

Convenience info:

September 18-20, 2013
New Orleans, Louisiana
--
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