Skip to contentSkip to conversation

loongarch queue

GIT PULL Applied Bibo Mao 3 participants 10 messages Jan 15 – Jan 16

lore
Share & tools
lore

Bibo Mao

author
#0 lore raw

The following changes since commit d03c3e522eb0696dcfc9c2cf643431eaaf51ca0f:

Merge tag 'pull-vfio-20260113' of https://github.com/legoater/qemu into staging (2026-01-14 02:37:13 +1100)

are available in the Git repository at:

https://github.com/bibo-mao/qemu.git tags/pull-loongarch-20260115

for you to fetch changes up to 49ee001a5b8378e9a9b3db8cbf61e7eda970ecd2:

hw/loongarch/virt: Don't abort on access to unimplemented IOCSR (2026-01-15 14:36:11 +0800)

----------------------------------------------------------------
pull-loongarch-20260115 queue

----------------------------------------------------------------
Song Gao (3):
target/loongach: Fix some exceptions failure in updating CSR_BADV target/loongarch: Fix exception BCE missing to update CSR_BADV target/loongarch: Fix exception ADEF/ADEM missing to update CSR_BADV

Xianglai Li (2):
hw/loongarch/virt: Modify the interrupt trigger type in fdt table hw/loongarch/virt: Fix irq allocation failure with pci device from fdt

Yao Zi (1):
hw/loongarch/virt: Don't abort on access to unimplemented IOCSR

 hw/loongarch/virt-fdt-build.c  | 55 ++++++++++++++++++++++++++++--------------
 hw/loongarch/virt.c            | 14 +++++++++--
 target/loongarch/tcg/tcg_cpu.c |  7 +++---
 3 files changed, 53 insertions(+), 23 deletions(-)
author
#1 lore raw

[PULL 4/6] target/loongarch: Fix exception BCE missing to update CSR_BADV

From: Song Gao <[email protected]>

Exception BCE need update CSR_BADV, and the value is env->pc.

---
 target/loongarch/tcg/tcg_cpu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
target/loongarch/tcg/tcg_cpu.c +3 -1
index d91cb9904f..4b4bf39d09 100644
@@ -113,6 +113,9 @@ static void loongarch_cpu_do_interrupt(CPUState *cs)
         cause = cs->exception_index;
         update_badinstr = 0;
         break;
+    case EXCCODE_BCE:
+        env->CSR_BADV = env->pc;
+        QEMU_FALLTHROUGH;
     case EXCCODE_SYS:
     case EXCCODE_BRK:
     case EXCCODE_INE:
@@ -121,7 +124,6 @@ static void loongarch_cpu_do_interrupt(CPUState *cs)
     case EXCCODE_FPE:
     case EXCCODE_SXD:
     case EXCCODE_ASXD:
-    case EXCCODE_BCE:
     case EXCCODE_ADEM:
     case EXCCODE_PIL:
     case EXCCODE_PIS:
Signature · 1 line
2.52.0
author
#2 lore raw

[PULL 6/6] hw/loongarch/virt: Don't abort on access to unimplemented IOCSR

In reply to Bibo Mao

From: Yao Zi <[email protected]>

Since commit f2e61edb2946 ("hw/loongarch/virt: Use MemTxAttrs interface for misc ops") which adds a call to g_assert_not_reached() in the path of handling unimplemented IOCSRs, QEMU would abort when the guest accesses unimplemented IOCSRs.

This is too serious since there's nothing fatal happening in QEMU itself, and the guest could probably continue running if we give zero as result for these reads, which also matches the behavior observed on 3A5000M real machine.

Replace the assertion with qemu_log_mask(LOG_UNIMP, ...), it's still possible to examine unimplemented IOCSR access through "-d unimp" command line arguments.

Fixes f2e61edb2946 ("hw/loongarch/virt: Use MemTxAttrs interface for misc ops")
---
 hw/loongarch/virt.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
hw/loongarch/virt.c +12 -2
index 7c13881885..a75968e4c9 100644
@@ -47,6 +47,7 @@
 #include "hw/block/flash.h"
 #include "hw/virtio/virtio-iommu.h"
 #include "qemu/error-report.h"
+#include "qemu/log.h"
 #include "kvm/kvm_loongarch.h"
 
 static void virt_get_dmsi(Object *obj, Visitor *v, const char *name,
@@ -754,8 +755,15 @@ static MemTxResult virt_iocsr_misc_write(void *opaque, hwaddr addr,
                              EXTIOI_VIRT_BASE + EXTIOI_VIRT_CONFIG,
                              features, attrs, NULL);
         break;
+    case VERSION_REG:
+    case FEATURE_REG:
+    case VENDOR_REG:
+    case CPUNAME_REG:
+        break;
     default:
-        g_assert_not_reached();
+        qemu_log_mask(LOG_UNIMP, "%s: Unimplemented IOCSR 0x%" HWADDR_PRIx "\n",
+                      __func__, addr);
+        break;
     }
 
     return MEMTX_OK;
@@ -813,7 +821,9 @@ static MemTxResult virt_iocsr_misc_read(void *opaque, hwaddr addr,
         }
         break;
     default:
-        g_assert_not_reached();
+        qemu_log_mask(LOG_UNIMP, "%s: Unimplemented IOCSR 0x%" HWADDR_PRIx "\n",
+                      __func__, addr);
+        break;
     }
 
     *data = ret;
Signature · 1 line
2.52.0
author
#3 lore raw

[PULL 1/6] hw/loongarch/virt: Modify the interrupt trigger type in fdt table

In reply to Bibo Mao

From: Xianglai Li <[email protected]>

In the loongarch virt fdt file, the interrupt trigger type directly uses magic numbers. Now, refer to the definitions in the linux kernel and use macro definitions.

---
 hw/loongarch/virt-fdt-build.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
hw/loongarch/virt-fdt-build.c +9 -2
index 4afefc8266..e2718f61b3 100644
@@ -16,6 +16,11 @@
 #include "system/reset.h"
 #include "target/loongarch/cpu.h"
 
+#define FDT_IRQ_TYPE_EDGE_RISING  1
+#define FDT_IRQ_TYPE_EDGE_FALLING 2
+#define FDT_IRQ_TYPE_LEVEL_HIGH   4
+#define FDT_IRQ_TYPE_LEVEL_LOW    8
+
 static void create_fdt(LoongArchVirtMachineState *lvms)
 {
     MachineState *ms = MACHINE(lvms);
@@ -434,7 +439,8 @@ static void fdt_add_uart_node(LoongArchVirtMachineState *lvms,
     if (chosen) {
         qemu_fdt_setprop_string(ms->fdt, "/chosen", "stdout-path", nodename);
     }
-    qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts", irq, 0x4);
+    qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts", irq,
+                           FDT_IRQ_TYPE_LEVEL_HIGH);
     qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
                           *pch_pic_phandle);
     g_free(nodename);
@@ -454,7 +460,8 @@ static void fdt_add_rtc_node(LoongArchVirtMachineState *lvms,
                             "loongson,ls7a-rtc");
     qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg", 2, base, 2, size);
     qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupts",
-                           VIRT_RTC_IRQ - VIRT_GSI_BASE , 0x4);
+                           VIRT_RTC_IRQ - VIRT_GSI_BASE ,
+                           FDT_IRQ_TYPE_LEVEL_HIGH);
     qemu_fdt_setprop_cell(ms->fdt, nodename, "interrupt-parent",
                           *pch_pic_phandle);
     g_free(nodename);
Signature · 1 line
2.52.0
author
#4 lore raw

[PULL 5/6] target/loongarch: Fix exception ADEF/ADEM missing to update CSR_BADV

In reply to Bibo Mao

From: Song Gao <[email protected]>

Exception ADEM/ADEF need update CSR_BADV, the value from the virtual address.

---
 target/loongarch/tcg/tcg_cpu.c | 1 +
 1 file changed, 1 insertion(+)
target/loongarch/tcg/tcg_cpu.c +1 -0
index 4b4bf39d09..af92277669 100644
@@ -227,6 +227,7 @@ static void loongarch_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
 {
     CPULoongArchState *env = cpu_env(cs);
 
+    env->CSR_BADV = addr;
     if (access_type == MMU_INST_FETCH) {
         do_raise_exception(env, EXCCODE_ADEF, retaddr);
     } else {
Signature · 1 line
2.52.0
author
#5 lore raw

[PULL 3/6] target/loongach: Fix some exceptions failure in updating CSR_BADV

In reply to Bibo Mao

From: Song Gao <[email protected]>

According to Volume 1 Manual 7.4.8 ,exception,SYS,BRK,INE,IPE,PPD FPE,SXD,ASXD are need't update CSR_BADV, this patch correct it.

---
 target/loongarch/tcg/tcg_cpu.c | 2 --
 1 file changed, 2 deletions(-)
target/loongarch/tcg/tcg_cpu.c +0 -2
index cb70692ace..d91cb9904f 100644
@@ -121,8 +121,6 @@ static void loongarch_cpu_do_interrupt(CPUState *cs)
     case EXCCODE_FPE:
     case EXCCODE_SXD:
     case EXCCODE_ASXD:
-        env->CSR_BADV = env->pc;
-        QEMU_FALLTHROUGH;
     case EXCCODE_BCE:
     case EXCCODE_ADEM:
     case EXCCODE_PIL:
Signature · 1 line
2.52.0
author
#6 lore raw

[PULL 2/6] hw/loongarch/virt: Fix irq allocation failure with pci device from fdt

In reply to Bibo Mao

From: Xianglai Li <[email protected]>

When we use the -kernel parameter to start an elf format kernel relying on fdt, we get the following error:

pcieport 0000:00:01.0: of_irq_parse_pci: failed with rc=-22 pcieport 0000:00:01.0: enabling device (0000 -> 0003) pcieport 0000:00:01.0: PME: Signaling with IRQ 19 pcieport 0000:00:01.0: AER: enabled with IRQ 19 pcieport 0000:00:01.1: of_irq_parse_pci: failed with rc=-22 pcieport 0000:00:01.1: enabling device (0000 -> 0003) pcieport 0000:00:01.1: PME: Signaling with IRQ 20 pcieport 0000:00:01.1: AER: enabled with IRQ 20 pcieport 0000:00:01.2: of_irq_parse_pci: failed with rc=-22 pcieport 0000:00:01.2: enabling device (0000 -> 0003) pcieport 0000:00:01.2: PME: Signaling with IRQ 21 pcieport 0000:00:01.2: AER: enabled with IRQ 21 pcieport 0000:00:01.3: of_irq_parse_pci: failed with rc=-22 pcieport 0000:00:01.3: enabling device (0000 -> 0003) pcieport 0000:00:01.3: PME: Signaling with IRQ 22 pcieport 0000:00:01.3: AER: enabled with IRQ 22 pcieport 0000:00:01.4: of_irq_parse_pci: failed with rc=-22

This is because the description of interrupt-cell is missing in the pcie irq map. And there is a lack of a description of the interrupt trigger type. Now it is corrected and the correct interrupt-cell is added in the pcie irq map.

Refer to the implementation in arm and add some comments.

---
 hw/loongarch/virt-fdt-build.c | 44 ++++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 16 deletions(-)
hw/loongarch/virt-fdt-build.c +28 -16
index e2718f61b3..6c06b36fca 100644
@@ -321,6 +321,8 @@ static void fdt_add_pcie_irq_map_node(const LoongArchVirtMachineState *lvms,
     uint32_t full_irq_map[PCI_NUM_PINS * PCI_NUM_PINS * 10] = {};
     uint32_t *irq_map = full_irq_map;
     const MachineState *ms = MACHINE(lvms);
+    uint32_t pin_mask;
+    uint32_t devfn_mask;
 
     /*
      * This code creates a standard swizzle of interrupts such that
@@ -333,37 +335,45 @@ static void fdt_add_pcie_irq_map_node(const LoongArchVirtMachineState *lvms,
      */
 
     for (dev = 0; dev < PCI_NUM_PINS; dev++) {
-        int devfn = dev * 0x8;
+        int devfn = PCI_DEVFN(dev, 0);
 
         for (pin = 0; pin < PCI_NUM_PINS; pin++) {
-            int irq_nr = 16 + ((pin + PCI_SLOT(devfn)) % PCI_NUM_PINS);
+            int irq_nr = VIRT_DEVICE_IRQS + \
+                         ((pin + PCI_SLOT(devfn)) % PCI_NUM_PINS);
             int i = 0;
 
-            /* Fill PCI address cells */
-            irq_map[i] = cpu_to_be32(devfn << 8);
-            i += 3;
-
-            /* Fill PCI Interrupt cells */
-            irq_map[i] = cpu_to_be32(pin + 1);
-            i += 1;
-
-            /* Fill interrupt controller phandle and cells */
-            irq_map[i++] = cpu_to_be32(*pch_pic_phandle);
-            irq_map[i++] = cpu_to_be32(irq_nr);
+            uint32_t map[] = {
+                devfn << 8, 0, 0,             /* devfn */
+                pin + 1,                      /* PCI pin */
+                *pch_pic_phandle,             /* interrupt controller handle */
+                irq_nr,                       /* irq number */
+                FDT_IRQ_TYPE_LEVEL_HIGH };    /* irq trigger level */
 
             if (!irq_map_stride) {
-                irq_map_stride = i;
+                irq_map_stride = sizeof(map) / sizeof(uint32_t);
             }
+
+            /* Convert map to big endian */
+            for (i = 0; i < irq_map_stride; i++) {
+                irq_map[i] = cpu_to_be32(map[i]);
+            }
+
             irq_map += irq_map_stride;
         }
     }
 
-
     qemu_fdt_setprop(ms->fdt, nodename, "interrupt-map", full_irq_map,
                      PCI_NUM_PINS * PCI_NUM_PINS *
                      irq_map_stride * sizeof(uint32_t));
+
+    /* Only need to match the pci slot bit */
+    devfn_mask = PCI_DEVFN((PCI_NUM_PINS - 1), 0) << 8;
+    /* The pci interrupt only needs to match the specified low bit */
+    pin_mask = (1 << ((PCI_NUM_PINS - 1))) - 1;
+
     qemu_fdt_setprop_cells(ms->fdt, nodename, "interrupt-map-mask",
-                     0x1800, 0, 0, 0x7);
+                           devfn_mask, 0, 0,  /* address cells */
+                           pin_mask);
 }
 
 static void fdt_add_pcie_node(const LoongArchVirtMachineState *lvms,
@@ -419,6 +429,8 @@ static void fdt_add_pcie_node(const LoongArchVirtMachineState *lvms,
     }
     qemu_fdt_setprop_cells(ms->fdt, nodename, "msi-map",
                            0, *pch_msi_phandle, 0, 0x10000);
+
+    qemu_fdt_setprop_cell(ms->fdt, nodename, "#interrupt-cells", 1);
     fdt_add_pcie_irq_map_node(lvms, nodename, pch_pic_phandle);
     g_free(nodename);
 }
Signature · 1 line
2.52.0
#7 lore raw

Re: [PULL 2/6] hw/loongarch/virt: Fix irq allocation failure with pci device from fdt

Quoted 4 lines · Bibo Mao

From: Xianglai Li <[email protected]>

When we use the -kernel parameter to start an elf format kernel relying on fdt, we get the following error:

..

Hi!

I can't find this patch in qemu-devel mailing list archives, besides this pull request. Has it not been there?

Quoted 18 lines

pcieport 0000:00:01.0: of_irq_parse_pci: failed with rc=-22 pcieport 0000:00:01.0: enabling device (0000 -> 0003) pcieport 0000:00:01.0: PME: Signaling with IRQ 19 pcieport 0000:00:01.0: AER: enabled with IRQ 19 pcieport 0000:00:01.1: of_irq_parse_pci: failed with rc=-22 pcieport 0000:00:01.1: enabling device (0000 -> 0003) pcieport 0000:00:01.1: PME: Signaling with IRQ 20 pcieport 0000:00:01.1: AER: enabled with IRQ 20 pcieport 0000:00:01.2: of_irq_parse_pci: failed with rc=-22 pcieport 0000:00:01.2: enabling device (0000 -> 0003) pcieport 0000:00:01.2: PME: Signaling with IRQ 21 pcieport 0000:00:01.2: AER: enabled with IRQ 21 pcieport 0000:00:01.3: of_irq_parse_pci: failed with rc=-22 pcieport 0000:00:01.3: enabling device (0000 -> 0003) pcieport 0000:00:01.3: PME: Signaling with IRQ 22 pcieport 0000:00:01.3: AER: enabled with IRQ 22 pcieport 0000:00:01.4: of_irq_parse_pci: failed with rc=-22

Quoted 6 lines

This is because the description of interrupt-cell is missing in the pcie irq map. And there is a lack of a description of the interrupt trigger type. Now it is corrected and the correct interrupt-cell is added in the pcie irq map.

Refer to the implementation in arm and add some comments.

This looks like a qemu-stable material to me. Please let me know if it is not and I shouldn't pick it up for qemu stable series.

Thanks,

/mjt

#8 lore raw
In reply to Bibo Mao
Quoted 6 lines · Bibo Mao

The following changes since commit d03c3e522eb0696dcfc9c2cf643431eaaf51ca0f:

   Merge tag 'pull-vfio-20260113' ofhttps://github.com/legoater/qemu into staging (2026-01-14 02:37:13 +1100)

are available in the Git repository at:

Quoted 8 lines
   https://github.com/bibo-mao/qemu.git tags/pull-loongarch-20260115

for you to fetch changes up to 49ee001a5b8378e9a9b3db8cbf61e7eda970ecd2:

   hw/loongarch/virt: Don't abort on access to unimplemented IOCSR (2026-01-15 14:36:11 +0800)

----------------------------------------------------------------
pull-loongarch-20260115 queue

Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/11.0 as appropriate.

r~

#9 lore raw
In reply to Bibo Mao

On 1/15/26 09:48, Bibo Mao wrote:
...

Quoted 5 lines

pull-loongarch-20260115 queue

----------------------------------------------------------------
Song Gao (3):
target/loongach: Fix some exceptions failure in updating CSR_BADV

There's a typo here, "loongach". FWIW, - this patch has been applied to the master branch already.

Quoted 6 lines

target/loongarch: Fix exception BCE missing to update CSR_BADV target/loongarch: Fix exception ADEF/ADEM missing to update CSR_BADV

Xianglai Li (2):
hw/loongarch/virt: Modify the interrupt trigger type in fdt table hw/loongarch/virt: Fix irq allocation failure with pci device from fdt

Actually, none of the above changes has been on qemu-devel list for some reason. This is rather unusual.

Quoted 2 lines

Yao Zi (1):
hw/loongarch/virt: Don't abort on access to unimplemented IOCSR

And it looks like most of it - maybe except of "Modify the interrupt trigger type" which is just cosmetic - are candidates for qemu-stable.

Please let me know if this is the case or not. And please add
Cc: qemu-stable@.. for patches which should be picked up for the stable series in the future.

Thanks,

/mjt