* [PATCH v2 0/3] KVM/MIPS32: Fixes for Linux 3.10
@ 2013-05-17 21:25 Sanjay Lal
2013-05-17 21:25 ` [PATCH 1/3] KVM/MIPS32: Move include/asm/kvm.h => include/uapi/asm/kvm.h since it is a user visible API Sanjay Lal
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Sanjay Lal @ 2013-05-17 21:25 UTC (permalink / raw)
To: kvm; +Cc: linux-mips, ralf, gleb, mtosatti, 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [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 21:25 [PATCH v2 0/3] KVM/MIPS32: Fixes for Linux 3.10 Sanjay Lal
@ 2013-05-17 21:25 ` Sanjay Lal
2013-05-17 21:25 ` [PATCH 2/3] KVM/MIPS32: Wrap calls to gfn_to_pfn() with srcu_read_lock/unlock() Sanjay Lal
2013-05-17 21:25 ` [PATCH 3/3] KVM/MIPS32: Fix up KVM breakage caused by d532f3d26716a39dfd4b88d687bd344fbe77e390 which allows ASID mask and increment to be determined @ runtime Sanjay Lal
2 siblings, 0 replies; 7+ messages in thread
From: Sanjay Lal @ 2013-05-17 21:25 UTC (permalink / raw)
To: kvm; +Cc: linux-mips, ralf, gleb, mtosatti, Sanjay Lal
Signed-off-by: Sanjay Lal <sanjayl@kymasys.com>
---
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..0000000
--- 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 <sanjayl@kymasys.com>
-*/
-
-#ifndef __LINUX_KVM_MIPS_H
-#define __LINUX_KVM_MIPS_H
-
-#include <linux/types.h>
-
-#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 0000000..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 <sanjayl@kymasys.com>
+*/
+
+#ifndef __LINUX_KVM_MIPS_H
+#define __LINUX_KVM_MIPS_H
+
+#include <linux/types.h>
+
+#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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] KVM/MIPS32: Wrap calls to gfn_to_pfn() with srcu_read_lock/unlock()
2013-05-17 21:25 [PATCH v2 0/3] KVM/MIPS32: Fixes for Linux 3.10 Sanjay Lal
2013-05-17 21:25 ` [PATCH 1/3] KVM/MIPS32: Move include/asm/kvm.h => include/uapi/asm/kvm.h since it is a user visible API Sanjay Lal
@ 2013-05-17 21:25 ` Sanjay Lal
2013-05-18 6:21 ` Gleb Natapov
2013-05-17 21:25 ` [PATCH 3/3] KVM/MIPS32: Fix up KVM breakage caused by d532f3d26716a39dfd4b88d687bd344fbe77e390 which allows ASID mask and increment to be determined @ runtime Sanjay Lal
2 siblings, 1 reply; 7+ messages in thread
From: Sanjay Lal @ 2013-05-17 21:25 UTC (permalink / raw)
To: kvm; +Cc: linux-mips, ralf, gleb, mtosatti, 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 <sanjayl@kymasys.com>
---
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 <linux/mm.h>
#include <linux/delay.h>
#include <linux/module.h>
+#include <linux/bootmem.h>
#include <linux/kvm_host.h>
+#include <linux/srcu.h>
+
#include <asm/cpu.h>
#include <asm/bootinfo.h>
@@ -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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [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 21:25 [PATCH v2 0/3] KVM/MIPS32: Fixes for Linux 3.10 Sanjay Lal
2013-05-17 21:25 ` [PATCH 1/3] KVM/MIPS32: Move include/asm/kvm.h => include/uapi/asm/kvm.h since it is a user visible API Sanjay Lal
2013-05-17 21:25 ` [PATCH 2/3] KVM/MIPS32: Wrap calls to gfn_to_pfn() with srcu_read_lock/unlock() Sanjay Lal
@ 2013-05-17 21:25 ` Sanjay Lal
2013-05-18 0:06 ` Ralf Baechle
2 siblings, 1 reply; 7+ messages in thread
From: Sanjay Lal @ 2013-05-17 21:25 UTC (permalink / raw)
To: kvm; +Cc: linux-mips, ralf, gleb, mtosatti, 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 <sanjayl@kymasys.com>
---
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->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 */
@@ -1356,7 +1356,7 @@ kvm_mips_emulate_tlbmod(unsigned long cause, uint32_t *opc,
{
struct mips_coproc *cop0 = vcpu->arch.cop0;
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));
struct kvm_vcpu_arch *arch = &vcpu->arch;
enum emulation_result er = EMULATE_DONE;
@@ -1783,7 +1783,7 @@ kvm_mips_handle_tlbmiss(unsigned long cause, uint32_t *opc,
*/
index = kvm_mips_guest_tlb_lookup(vcpu,
(va & VPN2_MASK) |
- ASID_MASK(kvm_read_c0_guest_entryhi
+ KVM_ASID_MASK(kvm_read_c0_guest_entryhi
(vcpu->arch.cop0)));
if (index < 0) {
if (exccode == T_TLB_LD_MISS) {
diff --git a/arch/mips/kvm/kvm_tlb.c b/arch/mips/kvm/kvm_tlb.c
index ab2e9b0..2a02051 100644
--- a/arch/mips/kvm/kvm_tlb.c
+++ b/arch/mips/kvm/kvm_tlb.c
@@ -54,13 +54,13 @@ EXPORT_SYMBOL(kvm_mips_is_error_pfn);
uint32_t kvm_mips_get_kernel_asid(struct kvm_vcpu *vcpu)
{
- return ASID_MASK(vcpu->arch.guest_kernel_asid[smp_processor_id()]);
+ return KVM_ASID_MASK(vcpu->arch.guest_kernel_asid[smp_processor_id()]);
}
uint32_t kvm_mips_get_user_asid(struct kvm_vcpu *vcpu)
{
- return ASID_MASK(vcpu->arch.guest_user_asid[smp_processor_id()]);
+ return KVM_ASID_MASK(vcpu->arch.guest_user_asid[smp_processor_id()]);
}
inline uint32_t kvm_mips_get_commpage_asid (struct kvm_vcpu *vcpu)
@@ -87,7 +87,7 @@ void kvm_mips_dump_host_tlbs(void)
old_pagemask = read_c0_pagemask();
printk("HOST TLBs:\n");
- printk("ASID: %#lx\n", ASID_MASK(read_c0_entryhi()));
+ printk("ASID: %#lx\n", KVM_ASID_MASK(read_c0_entryhi()));
for (i = 0; i < current_cpu_data.tlbsize; i++) {
write_c0_index(i);
@@ -446,7 +446,7 @@ int kvm_mips_guest_tlb_lookup(struct kvm_vcpu *vcpu, unsigned long entryhi)
for (i = 0; i < KVM_MIPS_GUEST_TLB_SIZE; i++) {
if (((TLB_VPN2(tlb[i]) & ~tlb[i].tlb_mask) == ((entryhi & VPN2_MASK) & ~tlb[i].tlb_mask)) &&
- (TLB_IS_GLOBAL(tlb[i]) || (TLB_ASID(tlb[i]) == ASID_MASK(entryhi)))) {
+ (TLB_IS_GLOBAL(tlb[i]) || (TLB_ASID(tlb[i]) == KVM_ASID_MASK(entryhi)))) {
index = i;
break;
}
@@ -539,7 +539,7 @@ int kvm_mips_host_tlb_inv(struct kvm_vcpu *vcpu, unsigned long va)
#ifdef DEBUG
if (idx > 0) {
kvm_debug("%s: Invalidated entryhi %#lx @ idx %d\n", __func__,
- (va & VPN2_MASK) | (vcpu->arch.asid_map[va & ASID_MASK] & ASID_MASK), idx);
+ (va & VPN2_MASK) | (vcpu->arch.asid_map[va & KVM_ASID_MASK] & KVM_ASID_MASK), idx);
}
#endif
@@ -644,7 +644,7 @@ kvm_get_new_mmu_context(struct mm_struct *mm, unsigned long cpu,
{
unsigned long asid = asid_cache(cpu);
- if (!(ASID_MASK(ASID_INC(asid)))) {
+ if (!KVM_ASID_MASK((asid = ASID_INC(asid)))) {
if (cpu_has_vtag_icache) {
flush_icache_all();
}
@@ -822,7 +822,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
if (!newasid) {
/* If we preempted while the guest was executing, then reload the pre-empted ASID */
if (current->flags & PF_VCPU) {
- write_c0_entryhi(ASID_MASK(vcpu->arch.preempt_entryhi));
+ write_c0_entryhi(KVM_ASID_MASK(vcpu->arch.preempt_entryhi));
ehb();
}
} else {
@@ -834,10 +834,10 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
*/
if (current->flags & PF_VCPU) {
if (KVM_GUEST_KERNEL_MODE(vcpu))
- write_c0_entryhi(ASID_MASK(vcpu->arch.
+ write_c0_entryhi(KVM_ASID_MASK(vcpu->arch.
guest_kernel_asid[cpu]));
else
- write_c0_entryhi(ASID_MASK(vcpu->arch.
+ write_c0_entryhi(KVM_ASID_MASK(vcpu->arch.
guest_user_asid[cpu]));
ehb();
}
@@ -897,7 +897,7 @@ uint32_t kvm_get_inst(uint32_t *opc, struct kvm_vcpu *vcpu)
kvm_mips_guest_tlb_lookup(vcpu,
((unsigned long) opc & VPN2_MASK)
|
- ASID_MASK(kvm_read_c0_guest_entryhi(cop0)));
+ KVM_ASID_MASK(kvm_read_c0_guest_entryhi(cop0)));
if (index < 0) {
kvm_err
("%s: get_user_failed for %p, vcpu: %p, ASID: %#lx\n",
--
1.7.11.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* 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 21:25 ` [PATCH 3/3] KVM/MIPS32: Fix up KVM breakage caused by d532f3d26716a39dfd4b88d687bd344fbe77e390 which allows ASID mask and increment to be determined @ runtime Sanjay Lal
@ 2013-05-18 0:06 ` Ralf Baechle
2013-05-18 6:23 ` Gleb Natapov
0 siblings, 1 reply; 7+ messages in thread
From: Ralf Baechle @ 2013-05-18 0:06 UTC (permalink / raw)
To: Sanjay Lal; +Cc: kvm, linux-mips, gleb, mtosatti
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 <sanjayl@kymasys.com>
> To: kvm@vger.kernel.org
> Cc: linux-mips@linux-mips.org, ralf@linux-mips.org, gleb@redhat.com,
> mtosatti@redhat.com, Sanjay Lal <sanjayl@kymasys.com>
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3] KVM/MIPS32: Wrap calls to gfn_to_pfn() with srcu_read_lock/unlock()
2013-05-17 21:25 ` [PATCH 2/3] KVM/MIPS32: Wrap calls to gfn_to_pfn() with srcu_read_lock/unlock() Sanjay Lal
@ 2013-05-18 6:21 ` Gleb Natapov
0 siblings, 0 replies; 7+ messages in thread
From: Gleb Natapov @ 2013-05-18 6:21 UTC (permalink / raw)
To: Sanjay Lal; +Cc: kvm, linux-mips, ralf, mtosatti
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 <sanjayl@kymasys.com>
> ---
> 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 <linux/mm.h>
> #include <linux/delay.h>
> #include <linux/module.h>
> +#include <linux/bootmem.h>
Is this include still needed now when you export min_low_pfn in
mips_ksyms.c?
> #include <linux/kvm_host.h>
> +#include <linux/srcu.h>
> +
>
> #include <asm/cpu.h>
> #include <asm/bootinfo.h>
> @@ -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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* 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-18 0:06 ` Ralf Baechle
@ 2013-05-18 6:23 ` Gleb Natapov
0 siblings, 0 replies; 7+ messages in thread
From: Gleb Natapov @ 2013-05-18 6:23 UTC (permalink / raw)
To: Ralf Baechle; +Cc: Sanjay Lal, kvm, linux-mips, mtosatti
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 <sanjayl@kymasys.com>
> > To: kvm@vger.kernel.org
> > Cc: linux-mips@linux-mips.org, ralf@linux-mips.org, gleb@redhat.com,
> > mtosatti@redhat.com, Sanjay Lal <sanjayl@kymasys.com>
> > 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.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-05-18 6:23 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-17 21:25 [PATCH v2 0/3] KVM/MIPS32: Fixes for Linux 3.10 Sanjay Lal
2013-05-17 21:25 ` [PATCH 1/3] KVM/MIPS32: Move include/asm/kvm.h => include/uapi/asm/kvm.h since it is a user visible API Sanjay Lal
2013-05-17 21:25 ` [PATCH 2/3] KVM/MIPS32: Wrap calls to gfn_to_pfn() with srcu_read_lock/unlock() Sanjay Lal
2013-05-18 6:21 ` Gleb Natapov
2013-05-17 21:25 ` [PATCH 3/3] KVM/MIPS32: Fix up KVM breakage caused by d532f3d26716a39dfd4b88d687bd344fbe77e390 which allows ASID mask and increment to be determined @ runtime Sanjay Lal
2013-05-18 0:06 ` Ralf Baechle
2013-05-18 6:23 ` Gleb Natapov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox