[PATCH v3 04/10] powerpc: kvm: allow flexible PAGE_OFFSET
Christophe Leroy (CS GROUP)
chleroy at kernel.org
Mon Nov 16 05:38:58 PST 2026
Hi Arnd,
Le 16/11/2026 à 13:48, Arnd Bergmann a écrit :
> From: Arnd Bergmann <arnd at arndb.de>
>
> As described by the Sashiko bot, the KVM code on powerpc has multiple
> hardcoded PAGE_OFFSET values. In order to change the default, make these
> compute the correct register values from configuration symbols.
>
> Signed-off-by: Arnd Bergmann <arnd at arndb.de>
> ---
> arch/powerpc/kvm/book3s_32_sr.S | 4 ++--
> arch/powerpc/kvm/booke_interrupts.S | 4 ++--
> arch/powerpc/kvm/e500_mmu_host.c | 3 ++-
> 3 files changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/arch/powerpc/kvm/book3s_32_sr.S b/arch/powerpc/kvm/book3s_32_sr.S
> index 6cfcd20d4668..0d8a7857f2bd 100644
> --- a/arch/powerpc/kvm/book3s_32_sr.S
> +++ b/arch/powerpc/kvm/book3s_32_sr.S
> @@ -113,8 +113,8 @@
>
> li r0, 4
> mtctr r0
> - LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * 0xc))
> - lis r4, 0xc000
> + LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * (PAGE_OFFSET >> 28)))
> + lis r4, (PAGE_OFFSET >> 16)
This is not enough I think. You need to load ctr with the number of
segments you want to populate. Here above it is hardcoded to 4.
> 3: mtsrin r3, r4
> addi r3, r3, 0x111 /* increment VSID */
> addis r4, r4, 0x1000 /* address of next segment */
> diff --git a/arch/powerpc/kvm/booke_interrupts.S b/arch/powerpc/kvm/booke_interrupts.S
> index 205545d820a1..ede394f3f63f 100644
> --- a/arch/powerpc/kvm/booke_interrupts.S
> +++ b/arch/powerpc/kvm/booke_interrupts.S
> @@ -230,8 +230,8 @@ _GLOBAL(kvmppc_resume_host)
> #endif
>
> /* Restore host IVPR before re-enabling interrupts. We cheat and know
> - * that Linux IVPR is always 0xc0000000. */
> - lis r3, 0xc000
> + * that Linux IVPR is always PAGE_OFFSET. */
> + lis r3, PAGE_OFFSET >> 16
Maybe use PAGE_OFFSET at h instead of PAGE_OFFSET >> 16.
> mtspr SPRN_IVPR, r3
That's probably valid but wouldn't it be more correct to use
interrupt_base at h as in head_44x.S and head_85xx.S :
lis r4,interrupt_base at h /* IVPR only uses the high 16-bits */
mtspr SPRN_IVPR,r4
>
> /* Switch to kernel stack and jump to handler. */
> diff --git a/arch/powerpc/kvm/e500_mmu_host.c b/arch/powerpc/kvm/e500_mmu_host.c
> index fa6128119874..9edad9bed589 100644
> --- a/arch/powerpc/kvm/e500_mmu_host.c
> +++ b/arch/powerpc/kvm/e500_mmu_host.c
> @@ -115,7 +115,8 @@ static u32 get_host_mas0(unsigned long eaddr)
> mtspr(SPRN_MAS6, 0);
> mas4 = mfspr(SPRN_MAS4);
> mtspr(SPRN_MAS4, mas4 & ~MAS4_TLBSEL_MASK);
> - asm volatile("tlbsx 0, %0" : : "b" (eaddr & ~CONFIG_PAGE_OFFSET));
> + asm volatile("tlbsx 0, %0" :
> + : "b" (eaddr & (rounddown_pow_of_two(PAGE_OFFSET)-1)));
I think this is not valid.
With PAGE_OFFSET equal to 0xc0000000,
Before:
eaddr & 0x3fffffff
Now:
eaddr & (0x80000000 - 1) = eaddr & 0x7fffffff
> mas0 = mfspr(SPRN_MAS0);
> mtspr(SPRN_MAS4, mas4);
> local_irq_restore(flags);
Christophe
More information about the linux-arm-kernel
mailing list