powernv: boot OpenBSD on POWER9
PATCH v3 1/1 powernv: boot OpenBSD on POWER9
OpenBSD/powernv programs PTCR for LPID 0 with a partition table size exponent one smaller than QEMU's existing ISA v3.0 interpretation. Try QEMU's existing PATS interpretation first, then fall back to the OpenBSD LPID 0 form; nonzero LPIDs keep the old behaviour.
The PSI model now exposes POWER9 IRQ level and pending status registers, and keeps both updated while delivering through the existing XIVE LSI source. This lets guests that select the POWER9 PSI LSI IRQ method continue to receive LPC interrupts.
The blast radius is probably minimal: the partition table fallback is limited to bare metal LPID 0 after the original lookup fails, while the PSI change only touches POWER9 PSI state and reuses the existing delivery path.
--- hw/ppc/pnv_psi.c | 11 ++++-- target/ppc/mmu-book3s-v3.c | 38 ++++++++++++++++--- tests/functional/ppc64/meson.build | 2 + tests/functional/ppc64/test_openbsd.py | 52 ++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 9 deletions(-) create mode 100755 tests/functional/ppc64/test_openbsd.py
hw/ppc/pnv_psi.c +8 -3
@@ -688,6 +688,8 @@ static uint64_t pnv_psi_p9_mmio_read(void *opaque, hwaddr addr, unsigned size)case PSIHB9_ESB_CI_BASE :case PSIHB9_ESB_NOTIF_ADDR :case PSIHB9_IVT_OFFSET : +case PSIHB9_IRQ_LEVEL : +case PSIHB9_IRQ_STAT : val = psi->regs[reg];break ;default :
@@ -818,17 +820,20 @@ static void pnv_psi_power9_set_irq(void *opaque, int irq, int state) {PnvPsi *psi = opaque;uint64_t irq_method = psi->regs[PSIHB_REG (PSIHB9_INTERRUPT_CONTROL )]; +uint64_t irq_bit =PPC_BIT (irq);if (irq_method &PSIHB9_IRQ_METHOD ) {qemu_log_mask (LOG_GUEST_ERROR ,"PSI: LSI IRQ method no supported\n" );return ; } -/* Update LSI levels */ +/* Update LSI levels and pending status */ if (state) { - psi->regs[PSIHB_REG (PSIHB9_IRQ_LEVEL )] |=PPC_BIT (irq); + psi->regs[PSIHB_REG (PSIHB9_IRQ_LEVEL )] |= irq_bit; + psi->regs[PSIHB_REG (PSIHB9_IRQ_STAT )] |= irq_bit; }else { - psi->regs[PSIHB_REG (PSIHB9_IRQ_LEVEL )] &= ~PPC_BIT (irq); + psi->regs[PSIHB_REG (PSIHB9_IRQ_LEVEL )] &= ~irq_bit; + psi->regs[PSIHB_REG (PSIHB9_IRQ_STAT )] &= ~irq_bit; }qemu_set_irq (psi->qirqs[irq], state);
target/ppc/mmu-book3s-v3.c +32 -6
@@ -23,25 +23,51 @@#include "mmu-hash64.h" #include "mmu-book3s-v3.h" -bool ppc64_v3_get_pate (PowerPCCPU *cpu,target_ulong lpid,ppc_v3_pate_t *entry) +#define PPC64_V3_PATE_SIZE 16/* two 64-bit words */ + +static bool ppc64_v3_get_pate_from_size (PowerPCCPU *cpu,target_ulong lpid, +ppc_v3_pate_t *entry, +uint64_t table_size) {uint64_t patb = cpu->env.spr[SPR_PTCR ] &PTCR_PATB ; -uint64_t pats = cpu->env.spr[SPR_PTCR ] &PTCR_PATS ; +uint64_t entries;/* Check if partition table is properly aligned */ -if (patb &MAKE_64BIT_MASK (0 , pats +12 )) { +if (patb & (table_size -1 )) {return false; }/* Calculate number of entries */ - pats =1ull << (pats +12 -4 ); -if (pats <= lpid) { + entries = table_size /PPC64_V3_PATE_SIZE ; +if (entries <= lpid) {return false; }/* Grab entry */ - patb +=16 * lpid; + patb +=PPC64_V3_PATE_SIZE * lpid; entry->dw0 =ldq_phys (CPU (cpu)->as, patb); entry->dw1 =ldq_phys (CPU (cpu)->as, patb +8 );return true; } + +bool ppc64_v3_get_pate (PowerPCCPU *cpu,target_ulong lpid,ppc_v3_pate_t *entry) +{ +uint64_t pats = cpu->env.spr[SPR_PTCR ] &PTCR_PATS ; + +/* +* Keep the existing ISA v3.0 PATS interpretation first. OpenBSD/powernv +* computes the value written to PTCR as ffs(PATMEMSZ) - 12, which writes 5 +* for its 64KiB LPID 0 partition table. If the existing interpretation +* fails, accept that form only for the bare metal LPID 0 table. +*/ +if (ppc64_v3_get_pate_from_size (cpu, lpid, entry,1ull << (pats +12 ))) { +return true; + } + +if (lpid ==0 ) { +return ppc64_v3_get_pate_from_size (cpu, lpid, entry, +1ull << (pats +11 )); + } + +return false; +}
tests/functional/ppc64/meson.build +2 -0
@@ -4,6 +4,7 @@ test_ppc64_timeouts = { 'fadump' : 480, 'hv' : 1000, 'mac99' : 120, + 'openbsd' : 240, 'powernv' : 480, 'pseries' : 480, 'replay' : 210,
@@ -20,6 +21,7 @@ tests_ppc64_system_thorough = [ 'fadump', 'hv', 'mac99', + 'openbsd', 'powernv', 'pseries', 'replay',
tests/functional/ppc64/test_openbsd.py new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
2.54.0
Quoted 6 lines · Kirill A. Korinsky
<...snip...>
target/ppc/mmu-book3s-v3.c +4
-0+ +bool ppc64_v3_get_pate (PowerPCCPU *cpu,target_ulong lpid,ppc_v3_pate_t *entry) +{ +uint64_t pats = cpu->env.spr[SPR_PTCR ] &PTCR_PATS ;
target/ppc/mmu-book3s-v3.c line 65
Quoted 10 lines
target/ppc/mmu-book3s-v3.c +10
-0+ +/* +* Keep the existing ISA v3.0 PATS interpretation first. OpenBSD/powernv +* computes the value written to PTCR as ffs(PATMEMSZ) - 12, which writes 5 +* for its 64KiB LPID 0 partition table. If the existing interpretation +* fails, accept that form only for the bare metal LPID 0 table. +*/ +if (ppc64_v3_get_pate_from_size (cpu, lpid, entry,1ull << (pats +12 ))) { +return true; + }
Thanks for the patch, though I still have a doubt here about PATS. PowerISA says Partition Table Size=2^(12+PATS). But seems OpenBSD on PowerNV populates PATS in such way that Partition Table Size=2^11 + PATS. Why does OpenBSD populate PATS this way, or am I missing some document where Partition Table Size was 2^(11+PATS) ?
Rest of the code looks good to me.
Thanks,
- Aditya G
Quoted 17 lines · Aditya Gupta
Quoted 14 lines · Kirill A. Korinsky
<...snip...>
target/ppc/mmu-book3s-v3.c +12
-0+ +bool ppc64_v3_get_pate (PowerPCCPU *cpu,target_ulong lpid,ppc_v3_pate_t *entry) +{ +uint64_t pats = cpu->env.spr[SPR_PTCR ] &PTCR_PATS ; + +/* +* Keep the existing ISA v3.0 PATS interpretation first. OpenBSD/powernv +* computes the value written to PTCR as ffs(PATMEMSZ) - 12, which writes 5 +* for its 64KiB LPID 0 partition table. If the existing interpretation +* fails, accept that form only for the bare metal LPID 0 table. +*/ +if (ppc64_v3_get_pate_from_size (cpu, lpid, entry,1ull << (pats +12 ))) {
Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ return true; + }Thanks for the patch, though I still have a doubt here about PATS. PowerISA says Partition Table Size=2^(12+PATS). But seems OpenBSD on PowerNV populates PATS in such way that Partition Table Size=2^11 + PATS. Why does OpenBSD populate PATS this way, or am I missing some document where Partition
Table Size was 2^(11+PATS) ?
I have no idea why OpenBSD does it but I see in powerpc64's pmap.c:
#define PATMEMSZ (64 * 1024)
#define PATSIZE (ffs(PATMEMSZ) - 12)
which was introduced by this commit:
https://github.com/openbsd/src/commit/dfe2a24332fd6769a7f9bb5806753189dae4d9c9
Signature · 1 line
wbr, Kirill
Quoted 4 lines · Kirill A.Korinsky
I have no idea why OpenBSD does it but I see in powerpc64's
pmap.c:#define PATMEMSZ (64 * 1024)
#define PATSIZE (ffs(PATMEMSZ) - 12)
Hi,
This seems like a bug in openbsd to me.
PowerISAv3.1 under PTCR says,
4:51 PATB | Partition Table Base 59:63 PATS | Partition Table Size=2^12+PATS , PATS≤24
I think the developer was perhaps wanted a LOG2 functions instead of ffs (which is just LOG2, but 1-indexed). IMO, this should better handled on OS side.
Thanks.
Quoted 5 lines
which was introduced by this commit:
https://github.com/openbsd/src/commit/dfe2a24332fd6769a7f9bb5806753189dae4d9c9--
Quoted 12 lines · Shivang Upadhyay
Quoted 4 lines · Kirill A.Korinsky
I have no idea why OpenBSD does it but I see in powerpc64's
pmap.c:#define PATMEMSZ (64 * 1024)
#define PATSIZE (ffs(PATMEMSZ) - 12)Hi,
This seems like a bug in openbsd to me.
PowerISAv3.1 under PTCR says,
Quoted 9 lines
4:51 PATB | Partition Table Base 59:63 PATS | Partition Table Size=2^12+PATS , PATS≤24I think the developer was perhaps wanted a LOG2 functions instead of ffs (which is just LOG2, but 1-indexed). IMO, this should better handled on OS side.
Thanks.
I'd like to add Mark to the loop who is the author of that code.
Quoted 6 lines
Quoted 5 lines
which was introduced by this commit:
https://github.com/openbsd/src/commit/dfe2a24332fd6769a7f9bb5806753189dae4d9c9--
Signature · 1 line
wbr, Kirill
Quoted 12 lines · Shivang Upadhyay
Quoted 4 lines · Kirill A.Korinsky
I have no idea why OpenBSD does it but I see in powerpc64's
pmap.c:#define PATMEMSZ (64 * 1024)
#define PATSIZE (ffs(PATMEMSZ) - 12)Hi,
This seems like a bug in openbsd to me.
PowerISAv3.1 under PTCR says,
Quoted 7 lines
4:51 PATB | Partition Table Base 59:63 PATS | Partition Table Size=2^12+PATS , PATS≤24I think the developer was perhaps wanted a LOG2 functions instead of ffs (which is just LOG2, but 1-indexed). IMO, this should better handled on OS side.
Thanks, OpenBSD was fixed:
https://marc.info/?l=openbsd-cvs&m=178436960888757&w=2
I'll send new version of original diff shortly.
Signature · 1 line
wbr, Kirill