Skip to contentSkip to conversation

hw/riscv/virt-acpi-build: Fix RINTC PLIC context ID for KVM

PATCH Applied Qingwei Hu 4 participants 4 messages Jun 4 – Jun 22 RISC-V

lore
Share & tools
lore

Qingwei Hu

author
#0 lore raw

PATCH 1/1 hw/riscv/virt-acpi-build: Fix RINTC PLIC context ID for KVM

Each RISC-V MADT RINTC entry contains an External Interrupt Controller ID field. On the virt machine without AIA, this field identifies the S-mode PLIC context associated with the hart.

TCG virt has both M-mode and S-mode PLIC contexts, so the S-mode context ID is odd and 2 * local_cpu_id + 1 is correct. KVM virt exposes only S-mode PLIC contexts, and those contexts are numbered contiguously from
0. Reporting the TCG context ID for KVM makes the guest enable a different PLIC context from the one used by QEMU.

With ACPI enabled, this can leave PCI INTx interrupts pending in QEMU while the guest-programmed PLIC context remains disabled. A virtio-blk root disk can then stall during boot because its first interrupt is never delivered.

Use local_cpu_id for KVM and keep the existing odd S-mode context ID for TCG.

Fixes d641da6ed43 ("hw/riscv/virt-acpi-build.c: Add PLIC in MADT")
---
 hw/riscv/virt-acpi-build.c | 2 ++
 1 file changed, 2 insertions(+)
hw/riscv/virt-acpi-build.c +2 -0
index 413d47d70e..6b06d9aa87 100644
@@ -100,6 +100,8 @@ static void riscv_acpi_madt_add_rintc(uint32_t uid,
         build_append_int_noprefix(entry,
                                   ACPI_BUILD_INTC_ID(
                                       arch_ids->cpus[uid].props.node_id,
+                                      kvm_enabled() ?
+                                      local_cpu_id :
                                       2 * local_cpu_id + 1),
                                   4);
     } else {
Signature · 1 line
2.39.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 31 lines · Qingwei Hu

Each RISC-V MADT RINTC entry contains an External Interrupt Controller ID field. On the virt machine without AIA, this field identifies the S-mode PLIC context associated with the hart.

TCG virt has both M-mode and S-mode PLIC contexts, so the S-mode context ID is odd and 2 * local_cpu_id + 1 is correct. KVM virt exposes only S-mode PLIC contexts, and those contexts are numbered contiguously from
0. Reporting the TCG context ID for KVM makes the guest enable a different PLIC context from the one used by QEMU.

With ACPI enabled, this can leave PCI INTx interrupts pending in QEMU while the guest-programmed PLIC context remains disabled. A virtio-blk root disk can then stall during boot because its first interrupt is never delivered.

Use local_cpu_id for KVM and keep the existing odd S-mode context ID for TCG.

Fixes d641da6ed43 ("hw/riscv/virt-acpi-build.c: Add PLIC in MADT")
---
 hw/riscv/virt-acpi-build.c | 2 ++
 1 file changed, 2 insertions(+)
hw/riscv/virt-acpi-build.c +0 -0
index 413d47d70e..6b06d9aa87 100644

hw/riscv/virt-acpi-build.c static void riscv_acpi_madt_add_rintc(uint32_t uid,

Quoted 9 lines
hw/riscv/virt-acpi-build.c +2 -1
@@ -100,6 +100,8 @@ static void riscv_acpi_madt_add_rintc(uint32_t uid,
         build_append_int_noprefix(entry,
                                   ACPI_BUILD_INTC_ID(
                                       arch_ids->cpus[uid].props.node_id,
+                                      kvm_enabled() ?
+                                      local_cpu_id :
                                       2 * local_cpu_id + 1),
                                   4);
     } else {
--

LGTM.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Qingwei Hu
Quoted 15 lines · Qingwei Hu

Each RISC-V MADT RINTC entry contains an External Interrupt Controller ID field. On the virt machine without AIA, this field identifies the S-mode PLIC context associated with the hart.

TCG virt has both M-mode and S-mode PLIC contexts, so the S-mode context ID is odd and 2 * local_cpu_id + 1 is correct. KVM virt exposes only S-mode PLIC contexts, and those contexts are numbered contiguously from
0. Reporting the TCG context ID for KVM makes the guest enable a different PLIC context from the one used by QEMU.

With ACPI enabled, this can leave PCI INTx interrupts pending in QEMU while the guest-programmed PLIC context remains disabled. A virtio-blk root disk can then stall during boot because its first interrupt is never delivered.

Quoted 5 lines

Use local_cpu_id for KVM and keep the existing odd S-mode context ID for TCG.

Fixes d641da6ed43 ("hw/riscv/virt-acpi-build.c: Add PLIC in MADT")

Thanks,
Nutty

Quoted 17 lines
---
  hw/riscv/virt-acpi-build.c | 2 ++
  1 file changed, 2 insertions(+)
hw/riscv/virt-acpi-build.c +2 -0
index 413d47d70e..6b06d9aa87 100644
@@ -100,6 +100,8 @@ static void riscv_acpi_madt_add_rintc(uint32_t uid,
          build_append_int_noprefix(entry,
                                    ACPI_BUILD_INTC_ID(
                                        arch_ids->cpus[uid].props.node_id,
+                                      kvm_enabled() ?
+                                      local_cpu_id :
                                        2 * local_cpu_id + 1),
                                    4);
      } else {
#3 lore raw
In reply to Qingwei Hu
Quoted 16 lines · Qingwei Hu

Each RISC-V MADT RINTC entry contains an External Interrupt Controller ID field. On the virt machine without AIA, this field identifies the S-mode PLIC context associated with the hart.

TCG virt has both M-mode and S-mode PLIC contexts, so the S-mode context ID is odd and 2 * local_cpu_id + 1 is correct. KVM virt exposes only S-mode PLIC contexts, and those contexts are numbered contiguously from
0. Reporting the TCG context ID for KVM makes the guest enable a different PLIC context from the one used by QEMU.

With ACPI enabled, this can leave PCI INTx interrupts pending in QEMU while the guest-programmed PLIC context remains disabled. A virtio-blk root disk can then stall during boot because its first interrupt is never delivered.

Quoted 5 lines

Use local_cpu_id for KVM and keep the existing odd S-mode context ID for TCG.

Fixes d641da6ed43 ("hw/riscv/virt-acpi-build.c: Add PLIC in MADT")

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 21 lines
---
 hw/riscv/virt-acpi-build.c | 2 ++
 1 file changed, 2 insertions(+)
hw/riscv/virt-acpi-build.c +2 -1
index 413d47d70e..6b06d9aa87 100644
@@ -100,6 +100,8 @@ static void riscv_acpi_madt_add_rintc(uint32_t uid,
         build_append_int_noprefix(entry,
                                   ACPI_BUILD_INTC_ID(
                                       arch_ids->cpus[uid].props.node_id,
+                                      kvm_enabled() ?
+                                      local_cpu_id :
                                       2 * local_cpu_id + 1),
                                   4);
     } else {
--

2.39.5