On Mon, Nov 16, 2026, at 14:38, Christophe Leroy (CS GROUP) wrote:
> Le 16/11/2026 à 13:48, Arnd Bergmann a écrit :
>> 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.
Ok, trying this one now
--- a/arch/powerpc/kvm/book3s_32_sr.S
+++ b/arch/powerpc/kvm/book3s_32_sr.S
@@ -107,14 +107,12 @@
KVM_LOAD_BAT(2, r9, r10, r11)
KVM_LOAD_BAT(3, r9, r10, r11)
- /* Restore Segment Registers */
-
- /* 0xc - 0xf */
-
- li r0, 4
+ /* Restore Segment Registers, assumes PAGE_OFFSET is segment aligned */
+ li r0, (0x100000000 - PAGE_OFFSET) >> 28
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@h
3: mtsrin r3, r4
addi r3, r3, 0x111 /* increment VSID */
addis r4, r4, 0x1000 /* address of next segment */
>> /* 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@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@h as in head_44x.S and head_85xx.S :
>
> lis r4,interrupt_base@h /* IVPR only uses the high 16-bits */
> mtspr SPRN_IVPR,r4
Ok, copying that version now:
--- a/arch/powerpc/kvm/booke_interrupts.S
+++ b/arch/powerpc/kvm/booke_interrupts.S
@@ -229,9 +229,8 @@ _GLOBAL(kvmppc_resume_host)
mtspr SPRN_PID1, r3
#endif
- /* Restore host IVPR before re-enabling interrupts. We cheat and know
- * that Linux IVPR is always PAGE_OFFSET. */
- lis r3, PAGE_OFFSET >> 16
+ /* Restore host IVPR before re-enabling interrupts. */
+ lis r3, interrupt_base@h /* IVPR only uses the high 16-bits */
mtspr SPRN_IVPR, r3
/* Switch to kernel stack and jump to handler. */
>> @@ -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
I'm probably still misunderstanding the intention of this code then,
my reading of the comment was that both 0x3fffffff and 0x7fffffff
would be valid choices here as both are below PAGE_OFFSET and
large enough to alias the correct set.
What are the actual requirements for the mask?
Thanks for looking at these bits in detail, I'm quite out of my
comfort zone here, especially with the book-e stuff.
Arnd