KVM: arm64: Align pKVM hypervisor sections to 64k when using 4k pages

When the kernel is configured for a 4KiB page size, align the pKVM
hypervisor sections to 64KiB so that the contiguous bit can be used in
the host stage-2 page-table for mapping the rest of the kernel image.

Signed-off-by: Will Deacon <willdeacon@google.com>
Change-Id: Ied1b2a62a41df3467ddaaab725687e7ac085e0c4
diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index 6cadf40..2cc1b8c 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -7,6 +7,13 @@
 
 #include <asm/hyp_image.h>
 #ifdef CONFIG_KVM
+
+#if PAGE_SIZE == SZ_4K
+#define HYP_ALIGN	SZ_64K
+#else
+#define HYP_ALIGN	PAGE_SIZE
+#endif
+
 #define HYPERVISOR_EXTABLE					\
 	. = ALIGN(SZ_8);					\
 	__start___kvm_ex_table = .;				\
@@ -25,21 +32,21 @@
 
 #define HYPERVISOR_RODATA_SECTIONS				\
 	HYP_SECTION_NAME(.rodata) : {				\
-		. = ALIGN(PAGE_SIZE);				\
+		. = ALIGN(HYP_ALIGN);				\
 		__hyp_rodata_start = .;				\
 		*(HYP_SECTION_NAME(.data..ro_after_init))	\
 		*(HYP_SECTION_NAME(.rodata))			\
 		HYPERVISOR_EVENT_IDS				\
-		. = ALIGN(PAGE_SIZE);				\
+		. = ALIGN(HYP_ALIGN);				\
 		__hyp_rodata_end = .;				\
 	}
 
 #define HYPERVISOR_DATA_SECTION					\
 	HYP_SECTION_NAME(.data) : {				\
-		. = ALIGN(PAGE_SIZE);				\
+		. = ALIGN(HYP_ALIGN);				\
 		__hyp_data_start = .;				\
 		*(HYP_SECTION_NAME(.data))			\
-		. = ALIGN(PAGE_SIZE);				\
+		. = ALIGN(HYP_ALIGN);				\
 		__hyp_data_end = .;				\
 	}
 
@@ -59,16 +66,16 @@
 #define BSS_FIRST_SECTIONS					\
 	__hyp_bss_start = .;					\
 	*(HYP_SECTION_NAME(.bss))				\
-	. = ALIGN(PAGE_SIZE);					\
+	. = ALIGN(HYP_ALIGN);					\
 	__hyp_bss_end = .;
 
 /*
  * We require that __hyp_bss_start and __bss_start are aligned, and enforce it
  * with an assertion. But the BSS_SECTION macro places an empty .sbss section
  * between them, which can in some cases cause the linker to misalign them. To
- * work around the issue, force a page alignment for __bss_start.
+ * work around the issue, force at least page alignment for __bss_start.
  */
-#define SBSS_ALIGN			PAGE_SIZE
+#define SBSS_ALIGN			HYP_ALIGN
 #else /* CONFIG_KVM */
 #define HYPERVISOR_EXTABLE
 #define HYPERVISOR_RODATA_SECTIONS
@@ -96,14 +103,14 @@
 jiffies = jiffies_64;
 
 #define HYPERVISOR_TEXT					\
-	. = ALIGN(PAGE_SIZE);				\
+	. = ALIGN(HYP_ALIGN);				\
 	__hyp_idmap_text_start = .;			\
 	*(.hyp.idmap.text)				\
 	__hyp_idmap_text_end = .;			\
 	__hyp_text_start = .;				\
 	*(.hyp.text)					\
 	HYPERVISOR_EXTABLE				\
-	. = ALIGN(PAGE_SIZE);				\
+	. = ALIGN(HYP_ALIGN);				\
 	__hyp_text_end = .;
 
 #define IDMAP_TEXT					\