Skip to contentSkip to conversation

arm/arm64: kvm: Use virt_to_idmap instead of virt_to_phys for idmap mappings

PATCH RESEND Superseded Santosh Shilimkar 3 participants 5 messages Nov 19, 2013 – Dec 11, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND v2 1/1 arm/arm64: kvm: Use virt_to_idmap instead of virt_to_phys for idmap mappings

KVM initialisation fails on architectures implementing virt_to_idmap() because virt_to_phys() on such architectures won't fetch you the correct idmap page.

So update the KVM ARM code to use the virt_to_idmap() to fix the issue. Since the KVM code is shared between arm and arm64, we create kvm_virt_to_phys() and handle the redirection in respective headers.

Cc Christoffer Dall <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Catalin Marinas <[email protected]>

---
Update the earlier version as per Marc's suggestion

 arch/arm/include/asm/kvm_mmu.h   |    1 +
 arch/arm/kvm/mmu.c               |    8 ++++----
 arch/arm64/include/asm/kvm_mmu.h |    1 +
 3 files changed, 6 insertions(+), 4 deletions(-)
arch/arm/include/asm/kvm_mmu.h +1 -0
index 77de4a4..2d122ad 100644
@@ -140,6 +140,7 @@ static inline void coherent_icache_guest_page(struct kvm *kvm, hva_t hva,
 }
 
 #define kvm_flush_dcache_to_poc(a,l)	__cpuc_flush_dcache_area((a), (l))
+#define kvm_virt_to_phys(x)		virt_to_idmap((unsigned long)(x))
 
 #endif	/* !__ASSEMBLY__ */
 
arch/arm/kvm/mmu.c +4 -4
index 5809069..659db0e 100644
@@ -916,9 +916,9 @@ int kvm_mmu_init(void)
 {
 	int err;
 
-	hyp_idmap_start = virt_to_phys(__hyp_idmap_text_start);
-	hyp_idmap_end = virt_to_phys(__hyp_idmap_text_end);
-	hyp_idmap_vector = virt_to_phys(__kvm_hyp_init);
+	hyp_idmap_start = kvm_virt_to_phys(__hyp_idmap_text_start);
+	hyp_idmap_end = kvm_virt_to_phys(__hyp_idmap_text_end);
+	hyp_idmap_vector = kvm_virt_to_phys(__kvm_hyp_init);
 
 	if ((hyp_idmap_start ^ hyp_idmap_end) & PAGE_MASK) {
 		/*
@@ -945,7 +945,7 @@ int kvm_mmu_init(void)
 		 */
 		kvm_flush_dcache_to_poc(init_bounce_page, len);
 
-		phys_base = virt_to_phys(init_bounce_page);
+		phys_base = kvm_virt_to_phys(init_bounce_page);
 		hyp_idmap_vector += phys_base - hyp_idmap_start;
 		hyp_idmap_start = phys_base;
 		hyp_idmap_end = phys_base + len;
arch/arm64/include/asm/kvm_mmu.h +1 -0
index 680f74e..7f1f940 100644
@@ -136,6 +136,7 @@ static inline void coherent_icache_guest_page(struct kvm *kvm, hva_t hva,
 }
 
 #define kvm_flush_dcache_to_poc(a,l)	__flush_dcache_area((a), (l))
+#define kvm_virt_to_phys(x)		__virt_to_phys((unsigned long)(x))
 
 #endif /* __ASSEMBLY__ */
 #endif /* __ARM64_KVM_MMU_H__ */
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH RESEND v2 1/1 arm/arm64: kvm: Use virt_to_idmap instead of virt_to_phys for idmap mappings

Christoffer,

Quoted 8 lines · Santosh Shilimkar

KVM initialisation fails on architectures implementing virt_to_idmap() because virt_to_phys() on such architectures won't fetch you the correct idmap page.

So update the KVM ARM code to use the virt_to_idmap() to fix the issue. Since the KVM code is shared between arm and arm64, we create kvm_virt_to_phys() and handle the redirection in respective headers.

Quoted 7 lines
Cc Christoffer Dall <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Catalin Marinas <[email protected]>

---
Update the earlier version as per Marc's suggestion

Have you picked this up for 3.14 ?

Quoted 56 lines
 arch/arm/include/asm/kvm_mmu.h   |    1 +
 arch/arm/kvm/mmu.c               |    8 ++++----
 arch/arm64/include/asm/kvm_mmu.h |    1 +
 3 files changed, 6 insertions(+), 4 deletions(-)
arch/arm/include/asm/kvm_mmu.h +1 -0
index 77de4a4..2d122ad 100644
@@ -140,6 +140,7 @@ static inline void coherent_icache_guest_page(struct kvm *kvm, hva_t hva,
 }
 
 #define kvm_flush_dcache_to_poc(a,l)	__cpuc_flush_dcache_area((a), (l))
+#define kvm_virt_to_phys(x)		virt_to_idmap((unsigned long)(x))
 
 #endif	/* !__ASSEMBLY__ */
 
arch/arm/kvm/mmu.c +4 -4
index 5809069..659db0e 100644
@@ -916,9 +916,9 @@ int kvm_mmu_init(void)
 {
 	int err;
 
-	hyp_idmap_start = virt_to_phys(__hyp_idmap_text_start);
-	hyp_idmap_end = virt_to_phys(__hyp_idmap_text_end);
-	hyp_idmap_vector = virt_to_phys(__kvm_hyp_init);
+	hyp_idmap_start = kvm_virt_to_phys(__hyp_idmap_text_start);
+	hyp_idmap_end = kvm_virt_to_phys(__hyp_idmap_text_end);
+	hyp_idmap_vector = kvm_virt_to_phys(__kvm_hyp_init);
 
 	if ((hyp_idmap_start ^ hyp_idmap_end) & PAGE_MASK) {
 		/*
@@ -945,7 +945,7 @@ int kvm_mmu_init(void)
 		 */
 		kvm_flush_dcache_to_poc(init_bounce_page, len);
 
-		phys_base = virt_to_phys(init_bounce_page);
+		phys_base = kvm_virt_to_phys(init_bounce_page);
 		hyp_idmap_vector += phys_base - hyp_idmap_start;
 		hyp_idmap_start = phys_base;
 		hyp_idmap_end = phys_base + len;
arch/arm64/include/asm/kvm_mmu.h +1 -0
index 680f74e..7f1f940 100644
@@ -136,6 +136,7 @@ static inline void coherent_icache_guest_page(struct kvm *kvm, hva_t hva,
 }
 
 #define kvm_flush_dcache_to_poc(a,l)	__flush_dcache_area((a), (l))
+#define kvm_virt_to_phys(x)		__virt_to_phys((unsigned long)(x))
 
 #endif /* __ASSEMBLY__ */
 #endif /* __ARM64_KVM_MMU_H__ */
#2 lore raw

PATCH RESEND v2 1/1 arm/arm64: kvm: Use virt_to_idmap instead of virt_to_phys for idmap mappings

Quoted 11 lines · Santosh Shilimkar

Christoffer,

Quoted 8 lines · Santosh Shilimkar

KVM initialisation fails on architectures implementing virt_to_idmap() because virt_to_phys() on such architectures won't fetch you the correct idmap page.

So update the KVM ARM code to use the virt_to_idmap() to fix the issue. Since the KVM code is shared between arm and arm64, we create kvm_virt_to_phys() and handle the redirection in respective headers.

Quoted 9 lines
Quoted 7 lines
Cc Christoffer Dall <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Catalin Marinas <[email protected]>

---
Update the earlier version as per Marc's suggestion

Have you picked this up for 3.14 ?

Actually, I was waiting for Marc to ack this one. Marc?

-Christoffer

Quoted 57 lines
Quoted 56 lines
 arch/arm/include/asm/kvm_mmu.h   |    1 +
 arch/arm/kvm/mmu.c               |    8 ++++----
 arch/arm64/include/asm/kvm_mmu.h |    1 +
 3 files changed, 6 insertions(+), 4 deletions(-)
arch/arm/include/asm/kvm_mmu.h +1 -0
index 77de4a4..2d122ad 100644
@@ -140,6 +140,7 @@ static inline void coherent_icache_guest_page(struct kvm *kvm, hva_t hva,
 }
 
 #define kvm_flush_dcache_to_poc(a,l)	__cpuc_flush_dcache_area((a), (l))
+#define kvm_virt_to_phys(x)		virt_to_idmap((unsigned long)(x))
 
 #endif	/* !__ASSEMBLY__ */
 
arch/arm/kvm/mmu.c +4 -4
index 5809069..659db0e 100644
@@ -916,9 +916,9 @@ int kvm_mmu_init(void)
 {
 	int err;
 
-	hyp_idmap_start = virt_to_phys(__hyp_idmap_text_start);
-	hyp_idmap_end = virt_to_phys(__hyp_idmap_text_end);
-	hyp_idmap_vector = virt_to_phys(__kvm_hyp_init);
+	hyp_idmap_start = kvm_virt_to_phys(__hyp_idmap_text_start);
+	hyp_idmap_end = kvm_virt_to_phys(__hyp_idmap_text_end);
+	hyp_idmap_vector = kvm_virt_to_phys(__kvm_hyp_init);
 
 	if ((hyp_idmap_start ^ hyp_idmap_end) & PAGE_MASK) {
 		/*
@@ -945,7 +945,7 @@ int kvm_mmu_init(void)
 		 */
 		kvm_flush_dcache_to_poc(init_bounce_page, len);
 
-		phys_base = virt_to_phys(init_bounce_page);
+		phys_base = kvm_virt_to_phys(init_bounce_page);
 		hyp_idmap_vector += phys_base - hyp_idmap_start;
 		hyp_idmap_start = phys_base;
 		hyp_idmap_end = phys_base + len;
arch/arm64/include/asm/kvm_mmu.h +1 -0
index 680f74e..7f1f940 100644
@@ -136,6 +136,7 @@ static inline void coherent_icache_guest_page(struct kvm *kvm, hva_t hva,
 }
 
 #define kvm_flush_dcache_to_poc(a,l)	__flush_dcache_area((a), (l))
+#define kvm_virt_to_phys(x)		__virt_to_phys((unsigned long)(x))
 
 #endif /* __ASSEMBLY__ */
 #endif /* __ARM64_KVM_MMU_H__ */
Signature · 1 line
Christoffer
#3 lore raw

PATCH RESEND v2 1/1 arm/arm64: kvm: Use virt_to_idmap instead of virt_to_phys for idmap mappings

Quoted 19 lines · Christoffer Dall
Quoted 18 lines · Santosh Shilimkar

Christoffer,

Quoted 15 lines · Santosh Shilimkar

KVM initialisation fails on architectures implementing virt_to_idmap() because virt_to_phys() on such architectures won't fetch you the correct idmap page.

So update the KVM ARM code to use the virt_to_idmap() to fix the issue. Since the KVM code is shared between arm and arm64, we create kvm_virt_to_phys() and handle the redirection in respective headers.

Cc Christoffer Dall <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Catalin Marinas <[email protected]>

---
Update the earlier version as per Marc's suggestion

Quoted 4 lines
Quoted 2 lines

Have you picked this up for 3.14 ?

Actually, I was waiting for Marc to ack this one. Marc?

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#4 lore raw

PATCH RESEND v2 1/1 arm/arm64: kvm: Use virt_to_idmap instead of virt_to_phys for idmap mappings

Quoted 20 lines · Marc Zyngier
Quoted 19 lines · Christoffer Dall
Quoted 18 lines · Santosh Shilimkar

Christoffer,

Quoted 15 lines · Santosh Shilimkar

KVM initialisation fails on architectures implementing virt_to_idmap() because virt_to_phys() on such architectures won't fetch you the correct idmap page.

So update the KVM ARM code to use the virt_to_idmap() to fix the issue. Since the KVM code is shared between arm and arm64, we create kvm_virt_to_phys() and handle the redirection in respective headers.

Cc Christoffer Dall <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Catalin Marinas <[email protected]>

---
Update the earlier version as per Marc's suggestion

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Have you picked this up for 3.14 ?

Actually, I was waiting for Marc to ack this one. Marc?

	M.

Thanks, applied.

-Christoffer