* [PULL 0/3] loongarch-next queue
@ 2026-05-08 2:27 Song Gao
2026-05-08 2:27 ` [PULL 1/3] hw/loongarch/virt: Define virt machine type with type_init() Song Gao
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Song Gao @ 2026-05-08 2:27 UTC (permalink / raw)
To: qemu-devel
The following changes since commit ee7eb612be8f8886d48c1d0c1f1c65e495138f83:
Merge tag 'single-binary-20260506' of https://github.com/philmd/qemu into staging (2026-05-06 10:45:02 -0400)
are available in the Git repository at:
https://github.com/gaosong715/qemu.git tags/pull-loongarch-20260508-2
for you to fetch changes up to d735016e9111e7bf0c2457556cedafd387c044a9:
target/loongarch: Add support for dbar hint variants (2026-05-08 02:48:04 -0400)
----------------------------------------------------------------
pull-loongarch-20260508
----------------------------------------------------------------
Bibo Mao (2):
hw/loongarch/virt: Define virt machine type with type_init()
hw/loongarch/virt: Define versioned virt machine
Song Gao (1):
target/loongarch: Add support for dbar hint variants
hw/loongarch/virt.c | 66 +++++++++++++++++-----
target/loongarch/cpu.c | 4 ++
target/loongarch/tcg/insn_trans/trans_memory.c.inc | 63 ++++++++++++++++++++-
target/loongarch/tcg/translate.c | 1 +
target/loongarch/translate.h | 3 +
5 files changed, 122 insertions(+), 15 deletions(-)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PULL 1/3] hw/loongarch/virt: Define virt machine type with type_init()
2026-05-08 2:27 [PULL 0/3] loongarch-next queue Song Gao
@ 2026-05-08 2:27 ` Song Gao
2026-05-08 2:28 ` [PULL 2/3] hw/loongarch/virt: Define versioned virt machine Song Gao
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Song Gao @ 2026-05-08 2:27 UTC (permalink / raw)
To: qemu-devel; +Cc: Bibo Mao
From: Bibo Mao <maobibo@loongson.cn>
Define virt machine with function type_init(), so that qemu versioned
virt machine can be added in later with similar method.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Reviewed-by: Song Gao <gaosong@loongson.cn>
Signed-off-by: Song Gao <gaosong@loongson.cn>
---
hw/loongarch/virt.c | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index 2fc1526130..c134b102c2 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -1535,18 +1535,21 @@ static void virt_class_init(ObjectClass *oc, const void *data)
"for PCI MMIO");
}
-static const TypeInfo virt_machine_types[] = {
- {
- .name = TYPE_LOONGARCH_VIRT_MACHINE,
- .parent = TYPE_MACHINE,
- .instance_size = sizeof(LoongArchVirtMachineState),
- .class_init = virt_class_init,
- .instance_init = virt_initfn,
- .interfaces = (const InterfaceInfo[]) {
- { TYPE_HOTPLUG_HANDLER },
- { }
- },
- }
+static const TypeInfo virt_machine_info = {
+ .name = TYPE_LOONGARCH_VIRT_MACHINE,
+ .parent = TYPE_MACHINE,
+ .instance_size = sizeof(LoongArchVirtMachineState),
+ .class_init = virt_class_init,
+ .instance_init = virt_initfn,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_HOTPLUG_HANDLER },
+ { }
+ },
};
-DEFINE_TYPES(virt_machine_types)
+static void machvirt_machine_init(void)
+{
+ type_register_static(&virt_machine_info);
+}
+
+type_init(machvirt_machine_init);
--
2.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PULL 2/3] hw/loongarch/virt: Define versioned virt machine
2026-05-08 2:27 [PULL 0/3] loongarch-next queue Song Gao
2026-05-08 2:27 ` [PULL 1/3] hw/loongarch/virt: Define virt machine type with type_init() Song Gao
@ 2026-05-08 2:28 ` Song Gao
2026-05-08 2:28 ` [PULL 3/3] target/loongarch: Add support for dbar hint variants Song Gao
2026-05-11 14:21 ` [PULL 0/3] loongarch-next queue Stefan Hajnoczi
3 siblings, 0 replies; 5+ messages in thread
From: Song Gao @ 2026-05-08 2:28 UTC (permalink / raw)
To: qemu-devel; +Cc: Bibo Mao
From: Bibo Mao <maobibo@loongson.cn>
Add versioned virt machine started from QEMU 11.1
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Reviewed-by: Song Gao <gaosong@loongson.cn>
Signed-off-by: Song Gao <gaosong@loongson.cn>
---
hw/loongarch/virt.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index c134b102c2..f68ccdb12b 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -1535,9 +1535,41 @@ static void virt_class_init(ObjectClass *oc, const void *data)
"for PCI MMIO");
}
+#define DEFINE_VIRT_MACHINE_VERSION(latest, ...) \
+ static void MACHINE_VER_SYM(class_init, virt, __VA_ARGS__)( \
+ ObjectClass *oc, \
+ const void *data) \
+ { \
+ MachineClass *mc = MACHINE_CLASS(oc); \
+ MACHINE_VER_SYM(options, virt, __VA_ARGS__)(mc); \
+ mc->desc = "QEMU " MACHINE_VER_STR(__VA_ARGS__) " LoongArch Virtual Machine"; \
+ MACHINE_VER_DEPRECATION(__VA_ARGS__); \
+ if (latest) { \
+ mc->alias = "virt"; \
+ } \
+ } \
+ static const TypeInfo MACHINE_VER_SYM(info, virt, __VA_ARGS__) = \
+ { \
+ .name = MACHINE_VER_TYPE_NAME("virt", __VA_ARGS__), \
+ .parent = TYPE_LOONGARCH_VIRT_MACHINE, \
+ .class_init = MACHINE_VER_SYM(class_init, virt, __VA_ARGS__), \
+ }; \
+ static void MACHINE_VER_SYM(register, virt, __VA_ARGS__)(void) \
+ { \
+ MACHINE_VER_DELETION(__VA_ARGS__); \
+ type_register_static(&MACHINE_VER_SYM(info, virt, __VA_ARGS__)); \
+ } \
+ type_init(MACHINE_VER_SYM(register, virt, __VA_ARGS__));
+
+#define DEFINE_VIRT_MACHINE_AS_LATEST(major, minor) \
+ DEFINE_VIRT_MACHINE_VERSION(true, major, minor)
+#define DEFINE_VIRT_MACHINE(major, minor) \
+ DEFINE_VIRT_MACHINE_VERSION(false, major, minor)
+
static const TypeInfo virt_machine_info = {
.name = TYPE_LOONGARCH_VIRT_MACHINE,
.parent = TYPE_MACHINE,
+ .abstract = true,
.instance_size = sizeof(LoongArchVirtMachineState),
.class_init = virt_class_init,
.instance_init = virt_initfn,
@@ -1553,3 +1585,8 @@ static void machvirt_machine_init(void)
}
type_init(machvirt_machine_init);
+
+static void virt_machine_11_1_options(MachineClass *mc)
+{
+}
+DEFINE_VIRT_MACHINE_AS_LATEST(11, 1)
--
2.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PULL 3/3] target/loongarch: Add support for dbar hint variants
2026-05-08 2:27 [PULL 0/3] loongarch-next queue Song Gao
2026-05-08 2:27 ` [PULL 1/3] hw/loongarch/virt: Define virt machine type with type_init() Song Gao
2026-05-08 2:28 ` [PULL 2/3] hw/loongarch/virt: Define versioned virt machine Song Gao
@ 2026-05-08 2:28 ` Song Gao
2026-05-11 14:21 ` [PULL 0/3] loongarch-next queue Stefan Hajnoczi
3 siblings, 0 replies; 5+ messages in thread
From: Song Gao @ 2026-05-08 2:28 UTC (permalink / raw)
To: qemu-devel; +Cc: Bibo Mao
LoongArch architecture (since LA664) introduces fine-grained dbar
hints that allow controlling which memory accesses are ordered by
the barrier. Previously, all dbar instructions were treated as a
full barrier (TCG_MO_ALL | TCG_BAR_SC).
This patch adds support for decoding dbar hints and emitting the
appropriate TCG memory barrier flags. For CPUs that do not advertise
the DBAR_HINTS feature (cpucfg3.DBAR_HINTS = 0), all dbar hints
fall back to a full barrier, preserving compatibility.
The hint encoding follows the LoongArch v1.10 specification:
The hint is a 5-bit field (bits 4-0). Bit4 is reserved and currently
ignored/discarded. Only bits 3-0 are used for ordering control.
* Bit3: barrier for previous read (0: true, 1: false)
* Bit2: barrier for previous write (0: true, 1: false)
* Bit1: barrier for succeeding read (0: true, 1: false)
* Bit0: barrier for succeeding write (0: true, 1: false)
The mapping to TCG memory order flags is as follows:
TCG_BAR_SC |TCG_MO_LD_LD | TCG_MO_LD_ST;
TCG_BAR_SC |TCG_MO_ST_LD | TCG_MO_ST_ST;
TCG_BAR_SC |TCG_MO_LD_LD | TCG_MO_ST_LD;
TCG_BAR_SC |TCG_MO_ST_ST | TCG_MO_LD_ST;
Special hint handling:
- hint 0x700: LL/SC loop barrier, treated as a full barrier as recommended.
- hint 0xf and 0x1f: reserved/no-op, treated as no operation
Signed-off-by: Song Gao <gaosong@loongson.cn>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
---
target/loongarch/cpu.c | 4 ++
.../tcg/insn_trans/trans_memory.c.inc | 63 ++++++++++++++++++-
target/loongarch/tcg/translate.c | 1 +
target/loongarch/translate.h | 3 +
4 files changed, 69 insertions(+), 2 deletions(-)
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index e22568c84a..d8d106b07e 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -455,6 +455,10 @@ static void loongarch_max_initfn(Object *obj)
data = FIELD_DP32(data, CPUCFG2, LLACQ_SCREL, 1);
data = FIELD_DP32(data, CPUCFG2, SCQ, 1);
cpu->env.cpucfg[2] = data;
+
+ data = cpu->env.cpucfg[3];
+ data = FIELD_DP32(data, CPUCFG3, DBAR_HINTS, 1);
+ cpu->env.cpucfg[3] = data;
}
}
diff --git a/target/loongarch/tcg/insn_trans/trans_memory.c.inc b/target/loongarch/tcg/insn_trans/trans_memory.c.inc
index e287d46363..dcecf02e54 100644
--- a/target/loongarch/tcg/insn_trans/trans_memory.c.inc
+++ b/target/loongarch/tcg/insn_trans/trans_memory.c.inc
@@ -137,11 +137,70 @@ static bool trans_preldx(DisasContext *ctx, arg_preldx * a)
return true;
}
+/*
+ * Decode dbar hint and emit appropriate TCG memory barrier.
+ *
+ * The hint is a 5-bit field (0-31) encoded in the instruction.
+ * For hint 0x700 (special LL/SC loop barrier), treat as full barrier.
+ *
+ * See LoongArch Reference Manual v1.10, Section 4.2.2 for details.
+ */
static bool trans_dbar(DisasContext *ctx, arg_dbar * a)
{
- tcg_gen_mb(TCG_BAR_SC | TCG_MO_ALL);
+ int hint = a->imm;
+ TCGBar bar_flags = 0;
+
+ /* Reserved/no-op hints: 0xf and 0x1f */
+ if (hint == 0xf || hint == 0x1f) {
+ return true;
+ }
+
+ /* If the CPU does not support fine-grained hints,or for the special LL/SC
+ * loop barrier (0x700), emit a full barrier.
+ */
+ if (!avail_DBAR_HINT(ctx) || hint == 0x700) {
+ tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
+ return true;
+ }
+
+ /*
+ * Fine-grained hint decoding:
+ * The hint is a 5-bit field (bits 4-0). Bit4 is reserved and currently
+ * ignored/discarded. Only bits 3-0 are used for ordering control.
+ * Bit3: barrier for previous read (0: true, 1: false)
+ * Bit2: barrier for previous write (0: true, 1: false)
+ * Bit1: barrier for succeeding read (0: true, 1: false)
+ * Bit0: barrier for succeeding write (0: true, 1: false)
+ *
+ * For each combination, we set the corresponding TCG_MO_* flag if both
+ * sides of the barrier require ordering.
+ */
+
+ bool prev_rd = !(hint & 0x08); /* bit3 */
+ bool prev_wr = !(hint & 0x04); /* bit2 */
+ bool succ_rd = !(hint & 0x02); /* bit1 */
+ bool succ_wr = !(hint & 0x01); /* bit0 */
+
+ if (prev_rd) {
+ bar_flags |= TCG_MO_LD_LD | TCG_MO_LD_ST;
+ }
+ if (prev_wr) {
+ bar_flags |= TCG_MO_ST_LD | TCG_MO_ST_ST;
+ }
+ if (succ_rd) {
+ bar_flags |= TCG_MO_LD_LD | TCG_MO_ST_LD;
+ }
+ if (succ_wr) {
+ bar_flags |= TCG_MO_ST_ST | TCG_MO_LD_ST;
+ }
+
+ if (bar_flags == 0) {
+ bar_flags = TCG_MO_ALL;
+ }
+
+ tcg_gen_mb(bar_flags | TCG_BAR_SC);
return true;
-}
+ }
static bool trans_ibar(DisasContext *ctx, arg_ibar *a)
{
diff --git a/target/loongarch/tcg/translate.c b/target/loongarch/tcg/translate.c
index 202b80e047..124dce6269 100644
--- a/target/loongarch/tcg/translate.c
+++ b/target/loongarch/tcg/translate.c
@@ -149,6 +149,7 @@ static void loongarch_tr_init_disas_context(DisasContextBase *dcbase,
ctx->cpucfg1 = env->cpucfg[1];
ctx->cpucfg2 = env->cpucfg[2];
+ ctx->cpucfg3 = env->cpucfg[3];
}
static void loongarch_tr_tb_start(DisasContextBase *dcbase, CPUState *cs)
diff --git a/target/loongarch/translate.h b/target/loongarch/translate.h
index ba1c89e57b..8aa8325dc6 100644
--- a/target/loongarch/translate.h
+++ b/target/loongarch/translate.h
@@ -43,6 +43,8 @@
#define avail_LLACQ_SCREL(C) (FIELD_EX32((C)->cpucfg2, CPUCFG2, LLACQ_SCREL))
#define avail_LLACQ_SCREL_64(C) (avail_64(C) && avail_LLACQ_SCREL(C))
+#define avail_DBAR_HINT(C) (FIELD_EX32((C)->cpucfg3, CPUCFG3, DBAR_HINTS))
+
/*
* If an operation is being performed on less than TARGET_LONG_BITS,
* it may require the inputs to be sign- or zero-extended; which will
@@ -66,6 +68,7 @@ typedef struct DisasContext {
bool va32; /* 32-bit virtual address */
uint32_t cpucfg1;
uint32_t cpucfg2;
+ uint32_t cpucfg3;
} DisasContext;
void generate_exception(DisasContext *ctx, int excp);
--
2.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PULL 0/3] loongarch-next queue
2026-05-08 2:27 [PULL 0/3] loongarch-next queue Song Gao
` (2 preceding siblings ...)
2026-05-08 2:28 ` [PULL 3/3] target/loongarch: Add support for dbar hint variants Song Gao
@ 2026-05-11 14:21 ` Stefan Hajnoczi
3 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2026-05-11 14:21 UTC (permalink / raw)
To: Song Gao; +Cc: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 116 bytes --]
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/11.1 for any user-visible changes.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-05-11 14:22 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-08 2:27 [PULL 0/3] loongarch-next queue Song Gao
2026-05-08 2:27 ` [PULL 1/3] hw/loongarch/virt: Define virt machine type with type_init() Song Gao
2026-05-08 2:28 ` [PULL 2/3] hw/loongarch/virt: Define versioned virt machine Song Gao
2026-05-08 2:28 ` [PULL 3/3] target/loongarch: Add support for dbar hint variants Song Gao
2026-05-11 14:21 ` [PULL 0/3] loongarch-next queue Stefan Hajnoczi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox