Skip to contentSkip to conversation

KVM: PPC: Align pt_regs in kvm_vcpu_arch structure

PATCH Superseded Fabiano Rosas 2 participants 2 messages May 25, 2022 – Jun 17, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: PPC: Align pt_regs in kvm_vcpu_arch structure

The H_ENTER_NESTED hypercall receives as second parameter the address of a region of memory containing the values for the nested guest privileged registers. We currently use the pt_regs structure contained within kvm_vcpu_arch for that end.

Most hypercalls that receive a memory address expect that region to not cross a 4k page boundary. We would want H_ENTER_NESTED to follow the same pattern so this patch ensures the pt_regs structure sits within a page.

---
 arch/powerpc/include/asm/kvm_host.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/kvm_host.h +5 -1
index faf301d0dec0..87eba60f2920 100644
@@ -519,7 +519,11 @@ struct kvm_vcpu_arch {
 	struct kvmppc_book3s_shadow_vcpu *shadow_vcpu;
 #endif
 
-	struct pt_regs regs;
+	/*
+	 * This is passed along to the HV via H_ENTER_NESTED. Align to
+	 * prevent it crossing a real 4K page.
+	 */
+	struct pt_regs regs __aligned(512);
 
 	struct thread_fp_state fp;
 
Signature · 1 line
2.35.1
#1 lore raw

Hi, Fabiano.

Quoted 11 lines · Fabiano Rosas

The H_ENTER_NESTED hypercall receives as second parameter the address of a region of memory containing the values for the nested guest privileged registers. We currently use the pt_regs structure contained within kvm_vcpu_arch for that end.

Most hypercalls that receive a memory address expect that region to not cross a 4k page boundary. We would want H_ENTER_NESTED to follow the same pattern so this patch ensures the pt_regs structure sits within a page.

Is it necessary to explain in the commit message that even though the second parameter needs to be 4k-aligned, we're aligning pt_regs to 512 bytes so it can be placed within a 4k boundary because its size is below 512 bytes?

The natural thinking would be aligning it to 4k bytes, which would punch a huge hole in kvm_vcpu_arch. I think having the explanation of why 512 vs. 4k is worthwhile mentioning.

Quoted 21 lines
---
  arch/powerpc/include/asm/kvm_host.h | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/kvm_host.h +5 -1
index faf301d0dec0..87eba60f2920 100644
@@ -519,7 +519,11 @@ struct kvm_vcpu_arch {
  	struct kvmppc_book3s_shadow_vcpu *shadow_vcpu;
  #endif
 
-	struct pt_regs regs;
+	/*
+	 * This is passed along to the HV via H_ENTER_NESTED. Align to
+	 * prevent it crossing a real 4K page.
+	 */
+	struct pt_regs regs __aligned(512);
 
  	struct thread_fp_state fp;
 
Signature · 1 line
Murilo