[Android-virt] [PATCH 2/4] ARM: KVM: Use build-time checks to prevent HYP code from spanning two pages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Instead of failing at boot time, be kind and fail at compile time when
the HYP code spans multiple pages. We definitely don't want that now.

Signed-off-by: Marc Zyngier <marc.zyngier at arm.com>
---
 arch/arm/include/asm/kvm_asm.h |    1 -
 arch/arm/kvm/arm.c             |   15 ---------------
 arch/arm/kvm/exports.c         |    1 -
 arch/arm/kvm/interrupts.S      |   21 +++++++++++++--------
 4 files changed, 13 insertions(+), 25 deletions(-)

diff --git a/arch/arm/include/asm/kvm_asm.h b/arch/arm/include/asm/kvm_asm.h
index 008702c..69afdf3 100644
--- a/arch/arm/include/asm/kvm_asm.h
+++ b/arch/arm/include/asm/kvm_asm.h
@@ -38,7 +38,6 @@ extern char __kvm_hyp_init[];
 extern char __kvm_hyp_init_end[];
 
 extern char __kvm_hyp_vector[];
-extern char __kvm_hyp_vector_end[];
 
 extern char __kvm_hyp_code_start[];
 extern char __kvm_hyp_code_end[];
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index bb4083b..8dc723d 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -699,23 +699,8 @@ static int init_hyp_mode(void)
 				   (unsigned long)init_end_phys_addr);
 
 	/*
-	 * Map Hyp exception vectors
-	 */
-	err = create_hyp_mappings(kvm_hyp_pgd,
-				  __kvm_hyp_vector, __kvm_hyp_vector_end);
-	if (err) {
-		kvm_err("Cannot map hyp vector\n");
-		goto out_free_mappings;
-	}
-
-	/*
 	 * Map the Hyp-code called directly from the host
 	 */
-	if (__kvm_hyp_code_end - __kvm_hyp_code_start > PAGE_SIZE) {
-		kvm_err("Cannot initialize module, Hyp-code spans two pages\n");
-		return -EFAULT;
-	}
-
 	err = create_hyp_mappings(kvm_hyp_pgd,
 				  __kvm_hyp_code_start, __kvm_hyp_code_end);
 	if (err) {
diff --git a/arch/arm/kvm/exports.c b/arch/arm/kvm/exports.c
index b3868b4..065222a 100644
--- a/arch/arm/kvm/exports.c
+++ b/arch/arm/kvm/exports.c
@@ -20,7 +20,6 @@ EXPORT_SYMBOL_GPL(__kvm_hyp_init);
 EXPORT_SYMBOL_GPL(__kvm_hyp_init_end);
 
 EXPORT_SYMBOL_GPL(__kvm_hyp_vector);
-EXPORT_SYMBOL_GPL(__kvm_hyp_vector_end);
 
 EXPORT_SYMBOL_GPL(__kvm_hyp_code_start);
 EXPORT_SYMBOL_GPL(__kvm_hyp_code_end);
diff --git a/arch/arm/kvm/interrupts.S b/arch/arm/kvm/interrupts.S
index ee567d1..8e427dc 100644
--- a/arch/arm/kvm/interrupts.S
+++ b/arch/arm/kvm/interrupts.S
@@ -15,6 +15,7 @@
  */
 
 #include <linux/linkage.h>
+#include <linux/const.h>
 #include <asm/unified.h>
 #include <asm/page.h>
 #include <asm/asm-offsets.h>
@@ -28,7 +29,7 @@
 
 	.text
 	.arm
-	.align 12
+	.align	PAGE_SHIFT
 
 __kvm_hyp_code_start:
 	.globl __kvm_hyp_code_start
@@ -369,11 +370,6 @@ return_to_ioctl:
 THUMB(	orr	lr, lr, #1)
 	mov	pc, lr
 
-	.ltorg
-
-
-__kvm_hyp_code_end:
-	.globl __kvm_hyp_code_end
 
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 @  Hypervisor exception vector and handlers
@@ -542,5 +538,14 @@ hyp_fiq:
 
 	.ltorg
 
-__kvm_hyp_vector_end:
-	.globl __kvm_hyp_vector_end
+	/*
+	 * The below lines makes sure the HYP mode code fits in a
+	 * single page (the assembler will bark at you if it doesn't).
+	 * Please keep them together. If you plan to restructure
+	 * the code or increase its size over a page, you'll have to
+	 * fix the code in init_hyp_mode().
+	 */
+__kvm_hyp_code_end:
+	.globl	__kvm_hyp_code_end
+
+	.org	__kvm_hyp_code_start + PAGE_SIZE
-- 
1.7.7.1





[Index of Archives]     [Linux KVM]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux