loongarch queue
The following changes since commit ae4f3443209ab154b48b706a146e5f557ab147cb:
Merge tag 'qtest-20260819-pull-request' of https://gitlab.com/farosas/qemu into staging (2026-08-19 08:21:57 -0700)
are available in the Git repository at:
https://github.com/gaosong715/qemu.git tags/pull-loongarch-20260820
for you to fetch changes up to 215a4fc08f2aafce54c168cf41c64c79187430c1:
target/loongarch: check FPE before reading fcc in bceqz/bcnez (2026-08-20 07:24:34 -0400)
----------------------------------------------------------------
pull-loongarch-20260820
----------------------------------------------------------------
Jan Mercl (1):
target/loongarch: check FPE before reading fcc in bceqz/bcnez
Song Gao (3):
target/loongarch: Add kvm support dintc
Add dintc kvm_irqchip_in_kernel support
target/loongarch: KVM disable msgint
hw/intc/loongarch_dintc.c | 13 ++++ hw/intc/loongarch_dintc_kvm.c | 48 ++++++++++++++ hw/intc/meson.build | 2 + include/hw/intc/loongarch_dintc.h | 10 +++ target/loongarch/cpu.c | 8 ++- target/loongarch/cpu.h | 1 + target/loongarch/kvm/kvm.c | 74 ++++++++++++++++++++++ target/loongarch/tcg/insn_trans/trans_branch.c.inc | 2 + 8 files changed, 155 insertions(+), 3 deletions(-) create mode 100644 hw/intc/loongarch_dintc_kvm.c
[PULL 2/4] Add dintc kvm_irqchip_in_kernel support
Function kvm_dintc_realize() is added if kvm_irqchip_in_kernel is set. It is to create and initialize DINTC device in kernel mode. and use kvm_irqchip_send_msi() to send msi to kernel.
Message-ID: <[email protected]>
--- hw/intc/loongarch_dintc.c | 13 +++++++++ hw/intc/loongarch_dintc_kvm.c | 48 +++++++++++++++++++++++++++++++ hw/intc/meson.build | 2 ++ include/hw/intc/loongarch_dintc.h | 10 +++++++ 4 files changed, 73 insertions(+) create mode 100644 hw/intc/loongarch_dintc_kvm.c
hw/intc/loongarch_dintc.c +13 -0
@@ -68,6 +68,15 @@ static void loongarch_dintc_mem_write(void *opaque, hwaddr addr, } irq_num =FIELD_EX64 (msg_addr,MSG_ADDR ,IRQ_NUM ); +if (kvm_irqchip_in_kernel ()) { +MSIMessage msg; + + msg.address = msg_addr; + msg.data = val; +kvm_irqchip_send_msi (kvm_state, msg); +return ; + } +async_run_on_cpu (cs, do_set_vcpu_dintc_irq,RUN_ON_CPU_HOST_INT (irq_num));qemu_set_irq (s->cpu[cpu_num].parent_irq,1 );
@@ -110,6 +119,10 @@ static void loongarch_dintc_realize(DeviceState *dev, Error **errp)qdev_init_gpio_out (dev, &s->cpu[i].parent_irq,1 ); } +if (kvm_irqchip_in_kernel ()) { +kvm_dintc_realize (dev, errp); + } +return ; }
hw/intc/loongarch_dintc_kvm.c new file +48 -0
48 lines not on this page · raw message
hw/intc/meson.build +2 -0
@@ -90,3 +90,5 @@ specific_ss.add(when: 'CONFIG_LOONGARCH_EXTIOI', if_true: files('loongarch_extio specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_LOONGARCH_EXTIOI'], if_true: files('loongarch_extioi_kvm.c')) specific_ss.add(when: 'CONFIG_LOONGARCH_DINTC', if_true: files('loongarch_dintc.c')) +specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_LOONGARCH_DINTC'], + if_true: files('loongarch_dintc_kvm.c'))
include/hw/intc/loongarch_dintc.h +10 -0
@@ -9,8 +9,13 @@#include "hw/core/sysbus.h" #include "hw/loongarch/virt.h" #include "system/memory.h" +#include "hw/pci-host/ls7a.h" #define NR_VECTORS 256 +#define IRQ_BIT_BASE 5 +#define IRQ_BIT_LEN 8 +#define CPU_BIT_BASE 13 +#define CPU_BIT_LEN 8#define TYPE_LOONGARCH_DINTC "loongarch_dintc"OBJECT_DECLARE_TYPE (LoongArchDINTCState, LoongArchDINTCClass,LOONGARCH_DINTC )
@@ -25,7 +30,10 @@ struct LoongArchDINTCState {SysBusDevice parent_obj;MemoryRegion dintc_mmio;DINTCCore *cpu; +int dev_fd;uint32_t num_cpu; +uint64_t msg_addr_base; +uint64_t msg_addr_size; };struct LoongArchDINTCClass {
@@ -34,3 +42,5 @@ struct LoongArchDINTCClass {DeviceRealize parent_realize;DeviceUnrealize parent_unrealize; }; + +void kvm_dintc_realize (DeviceState *dev,Error **errp);
Signature · 1 line
2.55.0
[PULL 3/4] target/loongarch: KVM disable msgint
In reply to Song GaoFrom: gaosong <[email protected]>
In KVM mode, msgint is disabled by default; please enable it manually.
e.g
... -cpu max,msgint=on ...
Message-ID: <[email protected]>
--- target/loongarch/cpu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
target/loongarch/cpu.c +5 -2
@@ -450,6 +450,9 @@ static void loongarch_max_initfn(Object *obj)loongarch_la464_initfn (obj); cpu->ptw =ON_OFF_AUTO_AUTO ; +if (kvm_enabled ()){ + cpu->msgint=ON_OFF_AUTO_OFF ; + }if (tcg_enabled ()) {uint32_t data = cpu->env.cpucfg[2 ]; data =FIELD_DP32 (data,CPUCFG2 ,HPTW ,1 );
@@ -464,9 +467,9 @@ static void loongarch_max_initfn(Object *obj) data = cpu->env.cpucfg[3 ]; data =FIELD_DP32 (data,CPUCFG3 ,DBAR_HINTS ,1 ); cpu->env.cpucfg[3 ] = data; + cpu->env.cpucfg[1 ] =FIELD_DP32 (cpu->env.cpucfg[1 ],CPUCFG1 ,MSG_INT ,1 ); + cpu->msgint =ON_OFF_AUTO_AUTO ; } - cpu->env.cpucfg[1 ] =FIELD_DP32 (cpu->env.cpucfg[1 ],CPUCFG1 ,MSG_INT ,1 ); - cpu->msgint =ON_OFF_AUTO_AUTO ; }#if defined(CONFIG_KVM )
Signature · 1 line
2.55.0
[PULL 4/4] target/loongarch: check FPE before reading fcc in bceqz/bcnez
In reply to Song GaoFrom: Jan Mercl <[email protected]>
gen_cz_bc() loads env->cf[cj] without CHECK_FPE, unlike every other translator that touches an fcc register (trans_fcmp.c.inc and trans_fmov.c.inc, for movcf2gr/movgr2cf/movcf2fr/movfr2cf/fsel).
A guest that manages the FPU lazily -- Linux clears CSR.EUEN.FPE in lose_fpu() on every context switch -- relies on the next fcc access raising a Floating-Point-Disabled exception so the kernel can restore that task's fcc. Because bceqz and bcnez never raise it, they branch on the condition flag left behind by whichever task last owned the FPU.
Real Loongson hardware does raise the exception, so this is TCG-only. It surfaces as Go binaries dying at startup in runtime.check() with "fatal error: float64nan1" -- roughly one process start in a thousand once the guest has more runnable tasks than vCPUs -- and in general as a conditional branch silently taking the wrong path.
With four tasks each executing 5M bcnez on a 2-vCPU guest, master mispredicts 89 of 20000000. With this patch, 0 of 100000000 over five runs; a Loongson-3C5000 is likewise 0 of 600000000.
CHECK_FPE is defined in trans_farith.c.inc, which translate.c includes before trans_branch.c.inc, so it is already in scope.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4209
Message-ID: <[email protected]>
--- target/loongarch/tcg/insn_trans/trans_branch.c.inc | 2 ++ 1 file changed, 2 insertions(+)
target/loongarch/tcg/insn_trans/trans_branch.c.inc +2 -0
@@ -66,6 +66,8 @@ static bool gen_cz_bc(DisasContext *ctx, arg_c_offs *a, TCGCond cond) TCGv src1 = tcg_temp_new(); TCGv src2 = tcg_constant_tl(0); + CHECK_FPE; + tcg_gen_ld8u_tl(src1, tcg_env, offsetof(CPULoongArchState, cf[a->cj])); gen_bc(ctx, src1, src2, a->offs, cond);
Signature · 1 line
2.55.0
[PULL 1/4] target/loongarch: Add kvm support dintc
In reply to Song GaoThis patch adds Kvm put/get msgint CSRs and check msgint feature.
Message-ID: <[email protected]>
--- target/loongarch/cpu.c | 5 ++- target/loongarch/cpu.h | 1 + target/loongarch/kvm/kvm.c | 74 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 3 deletions(-)
target/loongarch/cpu.c +2 -3
@@ -451,9 +451,6 @@ static void loongarch_max_initfn(Object *obj) cpu->ptw =ON_OFF_AUTO_AUTO ;if (tcg_enabled ()) { - cpu->env.cpucfg[1 ] =FIELD_DP32 (cpu->env.cpucfg[1 ],CPUCFG1 ,MSG_INT ,1 ); - cpu->msgint =ON_OFF_AUTO_AUTO ; -uint32_t data = cpu->env.cpucfg[2 ]; data =FIELD_DP32 (data,CPUCFG2 ,HPTW ,1 );/* Enable LA v1.1 instructions */
@@ -468,6 +465,8 @@ static void loongarch_max_initfn(Object *obj) data =FIELD_DP32 (data,CPUCFG3 ,DBAR_HINTS ,1 ); cpu->env.cpucfg[3 ] = data; } + cpu->env.cpucfg[1 ] =FIELD_DP32 (cpu->env.cpucfg[1 ],CPUCFG1 ,MSG_INT ,1 ); + cpu->msgint =ON_OFF_AUTO_AUTO ; }#if defined(CONFIG_KVM )
target/loongarch/cpu.h +1 -0
@@ -301,6 +301,7 @@ enum loongarch_features {LOONGARCH_FEATURE_PV_IPI ,LOONGARCH_FEATURE_STEALTIME ,LOONGARCH_FEATURE_PTW , + LOONGARCH_FEATURE_MSGINT, }; typedef struct LoongArchBT {
target/loongarch/kvm/kvm.c +74 -0
110 lines not on this page · raw message
Signature · 1 line
2.55.0
Richard Henderson
AppliedQuoted 6 lines · Song Gao
The following changes since commit
ae4f3443209ab154b48b706a146e5f557ab147cb:Merge tag 'qtest-20260819-pull-request' ofhttps://gitlab.com/farosas/qemu into staging (2026-08-19 08:21:57 -0700)are available in the Git repository at:
Quoted 8 lines
https://github.com/gaosong715/qemu.git tags/pull-loongarch-20260820for you to fetch changes up to
215a4fc08f2aafce54c168cf41c64c79187430c1:target/loongarch: check FPE before reading fcc in bceqz/bcnez (2026-08-20 07:24:34 -0400)----------------------------------------------------------------
pull-loongarch-20260820
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/11.2 as appropriate.
r~