* [Stable-10.0.5 01/38] target/loongarch: Add CRC feature flag and use it to gate CRC instructions
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 02/38] target/loongarch: Guard 64-bit-only insn translation with TRANS64 macro Michael Tokarev
` (36 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, WANG Rui, Bibo Mao, Philippe Mathieu-Daudé,
Song Gao, Michael Tokarev
From: WANG Rui <wangrui@loongson.cn>
This patch replaces the obsolete IOCSR_BRD bit with CRC in cpucfg1[25],
in both LA464 and LA132 CPU initialization functions. The corresponding
field macro in `cpu.h` is updated to reflect this change.
Additionally, the availability macro `avail_CRC()` is introduced in
`translate.h` to check the CRC feature flag.
All CRC-related instruction translations are updated to be gated by
the new CRC feature flag instead of hardcoded CPU features.
This ensures correctness and configurability when enabling CRC
instructions based on hardware capabilities.
Signed-off-by: WANG Rui <wangrui@loongson.cn>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-Id: <20250418082103.447780-2-wangrui@loongson.cn>
Signed-off-by: Song Gao <gaosong@loongson.cn>
(cherry picked from commit 256df51e727235b3d5e937ca2784c45663c00f59)
(Mjt: pick this one up for 10.0.x so subsequent changes applies cleanly)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index ea1665e270..fc439d0090 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -431,7 +431,7 @@ static void loongarch_la464_initfn(Object *obj)
data = FIELD_DP32(data, CPUCFG1, EP, 1);
data = FIELD_DP32(data, CPUCFG1, RPLV, 1);
data = FIELD_DP32(data, CPUCFG1, HP, 1);
- data = FIELD_DP32(data, CPUCFG1, IOCSR_BRD, 1);
+ data = FIELD_DP32(data, CPUCFG1, CRC, 1);
env->cpucfg[1] = data;
data = 0;
@@ -530,7 +530,7 @@ static void loongarch_la132_initfn(Object *obj)
data = FIELD_DP32(data, CPUCFG1, EP, 0);
data = FIELD_DP32(data, CPUCFG1, RPLV, 0);
data = FIELD_DP32(data, CPUCFG1, HP, 1);
- data = FIELD_DP32(data, CPUCFG1, IOCSR_BRD, 1);
+ data = FIELD_DP32(data, CPUCFG1, CRC, 1);
env->cpucfg[1] = data;
}
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
index 254e4fbdcd..ab76a0b451 100644
--- a/target/loongarch/cpu.h
+++ b/target/loongarch/cpu.h
@@ -129,7 +129,7 @@ FIELD(CPUCFG1, RI, 21, 1)
FIELD(CPUCFG1, EP, 22, 1)
FIELD(CPUCFG1, RPLV, 23, 1)
FIELD(CPUCFG1, HP, 24, 1)
-FIELD(CPUCFG1, IOCSR_BRD, 25, 1)
+FIELD(CPUCFG1, CRC, 25, 1)
FIELD(CPUCFG1, MSG_INT, 26, 1)
/* cpucfg[1].arch */
diff --git a/target/loongarch/tcg/insn_trans/trans_extra.c.inc b/target/loongarch/tcg/insn_trans/trans_extra.c.inc
index cfa361fecf..eda3d6e561 100644
--- a/target/loongarch/tcg/insn_trans/trans_extra.c.inc
+++ b/target/loongarch/tcg/insn_trans/trans_extra.c.inc
@@ -97,11 +97,11 @@ static bool gen_crc(DisasContext *ctx, arg_rrr *a,
return true;
}
-TRANS(crc_w_b_w, 64, gen_crc, gen_helper_crc32, tcg_constant_tl(1))
-TRANS(crc_w_h_w, 64, gen_crc, gen_helper_crc32, tcg_constant_tl(2))
-TRANS(crc_w_w_w, 64, gen_crc, gen_helper_crc32, tcg_constant_tl(4))
-TRANS(crc_w_d_w, 64, gen_crc, gen_helper_crc32, tcg_constant_tl(8))
-TRANS(crcc_w_b_w, 64, gen_crc, gen_helper_crc32c, tcg_constant_tl(1))
-TRANS(crcc_w_h_w, 64, gen_crc, gen_helper_crc32c, tcg_constant_tl(2))
-TRANS(crcc_w_w_w, 64, gen_crc, gen_helper_crc32c, tcg_constant_tl(4))
-TRANS(crcc_w_d_w, 64, gen_crc, gen_helper_crc32c, tcg_constant_tl(8))
+TRANS(crc_w_b_w, CRC, gen_crc, gen_helper_crc32, tcg_constant_tl(1))
+TRANS(crc_w_h_w, CRC, gen_crc, gen_helper_crc32, tcg_constant_tl(2))
+TRANS(crc_w_w_w, CRC, gen_crc, gen_helper_crc32, tcg_constant_tl(4))
+TRANS(crc_w_d_w, CRC, gen_crc, gen_helper_crc32, tcg_constant_tl(8))
+TRANS(crcc_w_b_w, CRC, gen_crc, gen_helper_crc32c, tcg_constant_tl(1))
+TRANS(crcc_w_h_w, CRC, gen_crc, gen_helper_crc32c, tcg_constant_tl(2))
+TRANS(crcc_w_w_w, CRC, gen_crc, gen_helper_crc32c, tcg_constant_tl(4))
+TRANS(crcc_w_d_w, CRC, gen_crc, gen_helper_crc32c, tcg_constant_tl(8))
diff --git a/target/loongarch/translate.h b/target/loongarch/translate.h
index 195f53573a..018dc5eb17 100644
--- a/target/loongarch/translate.h
+++ b/target/loongarch/translate.h
@@ -25,6 +25,7 @@
#define avail_LSX(C) (FIELD_EX32((C)->cpucfg2, CPUCFG2, LSX))
#define avail_LASX(C) (FIELD_EX32((C)->cpucfg2, CPUCFG2, LASX))
#define avail_IOCSR(C) (FIELD_EX32((C)->cpucfg1, CPUCFG1, IOCSR))
+#define avail_CRC(C) (FIELD_EX32((C)->cpucfg1, CPUCFG1, CRC))
/*
* If an operation is being performed on less than TARGET_LONG_BITS,
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 02/38] target/loongarch: Guard 64-bit-only insn translation with TRANS64 macro
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 01/38] target/loongarch: Add CRC feature flag and use it to gate CRC instructions Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 03/38] ui/vnc: Fix crash when specifying [vnc] without id in the config file Michael Tokarev
` (35 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-stable, WANG Rui, Bibo Mao, Song Gao, Michael Tokarev
From: WANG Rui <wangrui@loongson.cn>
This patch replaces uses of the generic TRANS macro with TRANS64 for
instructions that are only valid when 64-bit support is available.
This improves correctness and avoids potential assertion failures or
undefined behavior during translation on 32-bit-only configurations.
Signed-off-by: WANG Rui <wangrui@loongson.cn>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
Reviewed-by: Song Gao <gaosong@loongson.cn>
Signed-off-by: Song Gao <gaosong@loongson.cn>
(cherry picked from commit 96e7448c1f820c56caea8447c01f5227b0c95c79)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/target/loongarch/tcg/insn_trans/trans_atomic.c.inc b/target/loongarch/tcg/insn_trans/trans_atomic.c.inc
index 3d70d75941..77eeedbc42 100644
--- a/target/loongarch/tcg/insn_trans/trans_atomic.c.inc
+++ b/target/loongarch/tcg/insn_trans/trans_atomic.c.inc
@@ -74,38 +74,38 @@ TRANS(sc_w, ALL, gen_sc, MO_TESL)
TRANS(ll_d, 64, gen_ll, MO_TEUQ)
TRANS(sc_d, 64, gen_sc, MO_TEUQ)
TRANS(amswap_w, LAM, gen_am, tcg_gen_atomic_xchg_tl, MO_TESL)
-TRANS(amswap_d, LAM, gen_am, tcg_gen_atomic_xchg_tl, MO_TEUQ)
+TRANS64(amswap_d, LAM, gen_am, tcg_gen_atomic_xchg_tl, MO_TEUQ)
TRANS(amadd_w, LAM, gen_am, tcg_gen_atomic_fetch_add_tl, MO_TESL)
-TRANS(amadd_d, LAM, gen_am, tcg_gen_atomic_fetch_add_tl, MO_TEUQ)
+TRANS64(amadd_d, LAM, gen_am, tcg_gen_atomic_fetch_add_tl, MO_TEUQ)
TRANS(amand_w, LAM, gen_am, tcg_gen_atomic_fetch_and_tl, MO_TESL)
-TRANS(amand_d, LAM, gen_am, tcg_gen_atomic_fetch_and_tl, MO_TEUQ)
+TRANS64(amand_d, LAM, gen_am, tcg_gen_atomic_fetch_and_tl, MO_TEUQ)
TRANS(amor_w, LAM, gen_am, tcg_gen_atomic_fetch_or_tl, MO_TESL)
-TRANS(amor_d, LAM, gen_am, tcg_gen_atomic_fetch_or_tl, MO_TEUQ)
+TRANS64(amor_d, LAM, gen_am, tcg_gen_atomic_fetch_or_tl, MO_TEUQ)
TRANS(amxor_w, LAM, gen_am, tcg_gen_atomic_fetch_xor_tl, MO_TESL)
-TRANS(amxor_d, LAM, gen_am, tcg_gen_atomic_fetch_xor_tl, MO_TEUQ)
+TRANS64(amxor_d, LAM, gen_am, tcg_gen_atomic_fetch_xor_tl, MO_TEUQ)
TRANS(ammax_w, LAM, gen_am, tcg_gen_atomic_fetch_smax_tl, MO_TESL)
-TRANS(ammax_d, LAM, gen_am, tcg_gen_atomic_fetch_smax_tl, MO_TEUQ)
+TRANS64(ammax_d, LAM, gen_am, tcg_gen_atomic_fetch_smax_tl, MO_TEUQ)
TRANS(ammin_w, LAM, gen_am, tcg_gen_atomic_fetch_smin_tl, MO_TESL)
-TRANS(ammin_d, LAM, gen_am, tcg_gen_atomic_fetch_smin_tl, MO_TEUQ)
+TRANS64(ammin_d, LAM, gen_am, tcg_gen_atomic_fetch_smin_tl, MO_TEUQ)
TRANS(ammax_wu, LAM, gen_am, tcg_gen_atomic_fetch_umax_tl, MO_TESL)
-TRANS(ammax_du, LAM, gen_am, tcg_gen_atomic_fetch_umax_tl, MO_TEUQ)
+TRANS64(ammax_du, LAM, gen_am, tcg_gen_atomic_fetch_umax_tl, MO_TEUQ)
TRANS(ammin_wu, LAM, gen_am, tcg_gen_atomic_fetch_umin_tl, MO_TESL)
-TRANS(ammin_du, LAM, gen_am, tcg_gen_atomic_fetch_umin_tl, MO_TEUQ)
+TRANS64(ammin_du, LAM, gen_am, tcg_gen_atomic_fetch_umin_tl, MO_TEUQ)
TRANS(amswap_db_w, LAM, gen_am, tcg_gen_atomic_xchg_tl, MO_TESL)
-TRANS(amswap_db_d, LAM, gen_am, tcg_gen_atomic_xchg_tl, MO_TEUQ)
+TRANS64(amswap_db_d, LAM, gen_am, tcg_gen_atomic_xchg_tl, MO_TEUQ)
TRANS(amadd_db_w, LAM, gen_am, tcg_gen_atomic_fetch_add_tl, MO_TESL)
-TRANS(amadd_db_d, LAM, gen_am, tcg_gen_atomic_fetch_add_tl, MO_TEUQ)
+TRANS64(amadd_db_d, LAM, gen_am, tcg_gen_atomic_fetch_add_tl, MO_TEUQ)
TRANS(amand_db_w, LAM, gen_am, tcg_gen_atomic_fetch_and_tl, MO_TESL)
-TRANS(amand_db_d, LAM, gen_am, tcg_gen_atomic_fetch_and_tl, MO_TEUQ)
+TRANS64(amand_db_d, LAM, gen_am, tcg_gen_atomic_fetch_and_tl, MO_TEUQ)
TRANS(amor_db_w, LAM, gen_am, tcg_gen_atomic_fetch_or_tl, MO_TESL)
-TRANS(amor_db_d, LAM, gen_am, tcg_gen_atomic_fetch_or_tl, MO_TEUQ)
+TRANS64(amor_db_d, LAM, gen_am, tcg_gen_atomic_fetch_or_tl, MO_TEUQ)
TRANS(amxor_db_w, LAM, gen_am, tcg_gen_atomic_fetch_xor_tl, MO_TESL)
-TRANS(amxor_db_d, LAM, gen_am, tcg_gen_atomic_fetch_xor_tl, MO_TEUQ)
+TRANS64(amxor_db_d, LAM, gen_am, tcg_gen_atomic_fetch_xor_tl, MO_TEUQ)
TRANS(ammax_db_w, LAM, gen_am, tcg_gen_atomic_fetch_smax_tl, MO_TESL)
-TRANS(ammax_db_d, LAM, gen_am, tcg_gen_atomic_fetch_smax_tl, MO_TEUQ)
+TRANS64(ammax_db_d, LAM, gen_am, tcg_gen_atomic_fetch_smax_tl, MO_TEUQ)
TRANS(ammin_db_w, LAM, gen_am, tcg_gen_atomic_fetch_smin_tl, MO_TESL)
-TRANS(ammin_db_d, LAM, gen_am, tcg_gen_atomic_fetch_smin_tl, MO_TEUQ)
+TRANS64(ammin_db_d, LAM, gen_am, tcg_gen_atomic_fetch_smin_tl, MO_TEUQ)
TRANS(ammax_db_wu, LAM, gen_am, tcg_gen_atomic_fetch_umax_tl, MO_TESL)
-TRANS(ammax_db_du, LAM, gen_am, tcg_gen_atomic_fetch_umax_tl, MO_TEUQ)
+TRANS64(ammax_db_du, LAM, gen_am, tcg_gen_atomic_fetch_umax_tl, MO_TEUQ)
TRANS(ammin_db_wu, LAM, gen_am, tcg_gen_atomic_fetch_umin_tl, MO_TESL)
-TRANS(ammin_db_du, LAM, gen_am, tcg_gen_atomic_fetch_umin_tl, MO_TEUQ)
+TRANS64(ammin_db_du, LAM, gen_am, tcg_gen_atomic_fetch_umin_tl, MO_TEUQ)
diff --git a/target/loongarch/tcg/insn_trans/trans_extra.c.inc b/target/loongarch/tcg/insn_trans/trans_extra.c.inc
index eda3d6e561..298a80cff5 100644
--- a/target/loongarch/tcg/insn_trans/trans_extra.c.inc
+++ b/target/loongarch/tcg/insn_trans/trans_extra.c.inc
@@ -69,6 +69,10 @@ static bool trans_rdtimeh_w(DisasContext *ctx, arg_rdtimeh_w *a)
static bool trans_rdtime_d(DisasContext *ctx, arg_rdtime_d *a)
{
+ if (!avail_64(ctx)) {
+ return false;
+ }
+
return gen_rdtime(ctx, a, 0, 0);
}
@@ -100,8 +104,8 @@ static bool gen_crc(DisasContext *ctx, arg_rrr *a,
TRANS(crc_w_b_w, CRC, gen_crc, gen_helper_crc32, tcg_constant_tl(1))
TRANS(crc_w_h_w, CRC, gen_crc, gen_helper_crc32, tcg_constant_tl(2))
TRANS(crc_w_w_w, CRC, gen_crc, gen_helper_crc32, tcg_constant_tl(4))
-TRANS(crc_w_d_w, CRC, gen_crc, gen_helper_crc32, tcg_constant_tl(8))
+TRANS64(crc_w_d_w, CRC, gen_crc, gen_helper_crc32, tcg_constant_tl(8))
TRANS(crcc_w_b_w, CRC, gen_crc, gen_helper_crc32c, tcg_constant_tl(1))
TRANS(crcc_w_h_w, CRC, gen_crc, gen_helper_crc32c, tcg_constant_tl(2))
TRANS(crcc_w_w_w, CRC, gen_crc, gen_helper_crc32c, tcg_constant_tl(4))
-TRANS(crcc_w_d_w, CRC, gen_crc, gen_helper_crc32c, tcg_constant_tl(8))
+TRANS64(crcc_w_d_w, CRC, gen_crc, gen_helper_crc32c, tcg_constant_tl(8))
diff --git a/target/loongarch/tcg/insn_trans/trans_farith.c.inc b/target/loongarch/tcg/insn_trans/trans_farith.c.inc
index f4a0dea727..ff6cf3448e 100644
--- a/target/loongarch/tcg/insn_trans/trans_farith.c.inc
+++ b/target/loongarch/tcg/insn_trans/trans_farith.c.inc
@@ -183,16 +183,16 @@ TRANS(fmaxa_s, FP_SP, gen_fff, gen_helper_fmaxa_s)
TRANS(fmaxa_d, FP_DP, gen_fff, gen_helper_fmaxa_d)
TRANS(fmina_s, FP_SP, gen_fff, gen_helper_fmina_s)
TRANS(fmina_d, FP_DP, gen_fff, gen_helper_fmina_d)
-TRANS(fscaleb_s, FP_SP, gen_fff, gen_helper_fscaleb_s)
-TRANS(fscaleb_d, FP_DP, gen_fff, gen_helper_fscaleb_d)
+TRANS64(fscaleb_s, FP_SP, gen_fff, gen_helper_fscaleb_s)
+TRANS64(fscaleb_d, FP_DP, gen_fff, gen_helper_fscaleb_d)
TRANS(fsqrt_s, FP_SP, gen_ff, gen_helper_fsqrt_s)
TRANS(fsqrt_d, FP_DP, gen_ff, gen_helper_fsqrt_d)
TRANS(frecip_s, FP_SP, gen_ff, gen_helper_frecip_s)
TRANS(frecip_d, FP_DP, gen_ff, gen_helper_frecip_d)
TRANS(frsqrt_s, FP_SP, gen_ff, gen_helper_frsqrt_s)
TRANS(frsqrt_d, FP_DP, gen_ff, gen_helper_frsqrt_d)
-TRANS(flogb_s, FP_SP, gen_ff, gen_helper_flogb_s)
-TRANS(flogb_d, FP_DP, gen_ff, gen_helper_flogb_d)
+TRANS64(flogb_s, FP_SP, gen_ff, gen_helper_flogb_s)
+TRANS64(flogb_d, FP_DP, gen_ff, gen_helper_flogb_d)
TRANS(fclass_s, FP_SP, gen_ff, gen_helper_fclass_s)
TRANS(fclass_d, FP_DP, gen_ff, gen_helper_fclass_d)
TRANS(fmadd_s, FP_SP, gen_muladd, gen_helper_fmuladd_s, 0)
diff --git a/target/loongarch/tcg/insn_trans/trans_fcnv.c.inc b/target/loongarch/tcg/insn_trans/trans_fcnv.c.inc
index 833c059d6d..ca1d76a366 100644
--- a/target/loongarch/tcg/insn_trans/trans_fcnv.c.inc
+++ b/target/loongarch/tcg/insn_trans/trans_fcnv.c.inc
@@ -29,5 +29,5 @@ TRANS(ffint_s_w, FP_SP, gen_ff, gen_helper_ffint_s_w)
TRANS(ffint_s_l, FP_SP, gen_ff, gen_helper_ffint_s_l)
TRANS(ffint_d_w, FP_DP, gen_ff, gen_helper_ffint_d_w)
TRANS(ffint_d_l, FP_DP, gen_ff, gen_helper_ffint_d_l)
-TRANS(frint_s, FP_SP, gen_ff, gen_helper_frint_s)
-TRANS(frint_d, FP_DP, gen_ff, gen_helper_frint_d)
+TRANS64(frint_s, FP_SP, gen_ff, gen_helper_frint_s)
+TRANS64(frint_d, FP_DP, gen_ff, gen_helper_frint_d)
diff --git a/target/loongarch/tcg/insn_trans/trans_fmemory.c.inc b/target/loongarch/tcg/insn_trans/trans_fmemory.c.inc
index 13452bc7e5..79da4718a5 100644
--- a/target/loongarch/tcg/insn_trans/trans_fmemory.c.inc
+++ b/target/loongarch/tcg/insn_trans/trans_fmemory.c.inc
@@ -148,11 +148,11 @@ TRANS(fldx_s, FP_SP, gen_floadx, MO_TEUL)
TRANS(fldx_d, FP_DP, gen_floadx, MO_TEUQ)
TRANS(fstx_s, FP_SP, gen_fstorex, MO_TEUL)
TRANS(fstx_d, FP_DP, gen_fstorex, MO_TEUQ)
-TRANS(fldgt_s, FP_SP, gen_fload_gt, MO_TEUL)
-TRANS(fldgt_d, FP_DP, gen_fload_gt, MO_TEUQ)
-TRANS(fldle_s, FP_SP, gen_fload_le, MO_TEUL)
-TRANS(fldle_d, FP_DP, gen_fload_le, MO_TEUQ)
-TRANS(fstgt_s, FP_SP, gen_fstore_gt, MO_TEUL)
-TRANS(fstgt_d, FP_DP, gen_fstore_gt, MO_TEUQ)
-TRANS(fstle_s, FP_SP, gen_fstore_le, MO_TEUL)
-TRANS(fstle_d, FP_DP, gen_fstore_le, MO_TEUQ)
+TRANS64(fldgt_s, FP_SP, gen_fload_gt, MO_TEUL)
+TRANS64(fldgt_d, FP_DP, gen_fload_gt, MO_TEUQ)
+TRANS64(fldle_s, FP_SP, gen_fload_le, MO_TEUL)
+TRANS64(fldle_d, FP_DP, gen_fload_le, MO_TEUQ)
+TRANS64(fstgt_s, FP_SP, gen_fstore_gt, MO_TEUL)
+TRANS64(fstgt_d, FP_DP, gen_fstore_gt, MO_TEUQ)
+TRANS64(fstle_s, FP_SP, gen_fstore_le, MO_TEUL)
+TRANS64(fstle_d, FP_DP, gen_fstore_le, MO_TEUQ)
diff --git a/target/loongarch/tcg/insn_trans/trans_privileged.c.inc b/target/loongarch/tcg/insn_trans/trans_privileged.c.inc
index ecbfe23b63..34cfab8879 100644
--- a/target/loongarch/tcg/insn_trans/trans_privileged.c.inc
+++ b/target/loongarch/tcg/insn_trans/trans_privileged.c.inc
@@ -233,11 +233,11 @@ static bool gen_iocsrwr(DisasContext *ctx, arg_rr *a,
TRANS(iocsrrd_b, IOCSR, gen_iocsrrd, gen_helper_iocsrrd_b)
TRANS(iocsrrd_h, IOCSR, gen_iocsrrd, gen_helper_iocsrrd_h)
TRANS(iocsrrd_w, IOCSR, gen_iocsrrd, gen_helper_iocsrrd_w)
-TRANS(iocsrrd_d, IOCSR, gen_iocsrrd, gen_helper_iocsrrd_d)
+TRANS64(iocsrrd_d, IOCSR, gen_iocsrrd, gen_helper_iocsrrd_d)
TRANS(iocsrwr_b, IOCSR, gen_iocsrwr, gen_helper_iocsrwr_b)
TRANS(iocsrwr_h, IOCSR, gen_iocsrwr, gen_helper_iocsrwr_h)
TRANS(iocsrwr_w, IOCSR, gen_iocsrwr, gen_helper_iocsrwr_w)
-TRANS(iocsrwr_d, IOCSR, gen_iocsrwr, gen_helper_iocsrwr_d)
+TRANS64(iocsrwr_d, IOCSR, gen_iocsrwr, gen_helper_iocsrwr_d)
static void check_mmu_idx(DisasContext *ctx)
{
diff --git a/target/loongarch/tcg/insn_trans/trans_shift.c.inc b/target/loongarch/tcg/insn_trans/trans_shift.c.inc
index 377307785a..136c4c8455 100644
--- a/target/loongarch/tcg/insn_trans/trans_shift.c.inc
+++ b/target/loongarch/tcg/insn_trans/trans_shift.c.inc
@@ -78,7 +78,7 @@ TRANS(sra_w, ALL, gen_rrr, EXT_SIGN, EXT_NONE, EXT_SIGN, gen_sra_w)
TRANS(sll_d, 64, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, gen_sll_d)
TRANS(srl_d, 64, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, gen_srl_d)
TRANS(sra_d, 64, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, gen_sra_d)
-TRANS(rotr_w, 64, gen_rrr, EXT_ZERO, EXT_NONE, EXT_SIGN, gen_rotr_w)
+TRANS(rotr_w, ALL, gen_rrr, EXT_ZERO, EXT_NONE, EXT_SIGN, gen_rotr_w)
TRANS(rotr_d, 64, gen_rrr, EXT_NONE, EXT_NONE, EXT_NONE, gen_rotr_d)
TRANS(slli_w, ALL, gen_rri_c, EXT_NONE, EXT_SIGN, tcg_gen_shli_tl)
TRANS(slli_d, 64, gen_rri_c, EXT_NONE, EXT_NONE, tcg_gen_shli_tl)
@@ -86,5 +86,5 @@ TRANS(srli_w, ALL, gen_rri_c, EXT_ZERO, EXT_SIGN, tcg_gen_shri_tl)
TRANS(srli_d, 64, gen_rri_c, EXT_NONE, EXT_NONE, tcg_gen_shri_tl)
TRANS(srai_w, ALL, gen_rri_c, EXT_NONE, EXT_NONE, gen_sari_w)
TRANS(srai_d, 64, gen_rri_c, EXT_NONE, EXT_NONE, tcg_gen_sari_tl)
-TRANS(rotri_w, 64, gen_rri_v, EXT_NONE, EXT_NONE, gen_rotr_w)
+TRANS(rotri_w, ALL, gen_rri_v, EXT_NONE, EXT_NONE, gen_rotr_w)
TRANS(rotri_d, 64, gen_rri_c, EXT_NONE, EXT_NONE, tcg_gen_rotri_tl)
diff --git a/target/loongarch/translate.h b/target/loongarch/translate.h
index 018dc5eb17..bbe015ba57 100644
--- a/target/loongarch/translate.h
+++ b/target/loongarch/translate.h
@@ -14,6 +14,10 @@
static bool trans_##NAME(DisasContext *ctx, arg_##NAME * a) \
{ return avail_##AVAIL(ctx) && FUNC(ctx, a, __VA_ARGS__); }
+#define TRANS64(NAME, AVAIL, FUNC, ...) \
+ static bool trans_##NAME(DisasContext *ctx, arg_##NAME * a) \
+ { return avail_64(ctx) && avail_##AVAIL(ctx) && FUNC(ctx, a, __VA_ARGS__); }
+
#define avail_ALL(C) true
#define avail_64(C) (FIELD_EX32((C)->cpucfg1, CPUCFG1, ARCH) == \
CPUCFG1_ARCH_LA64)
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 03/38] ui/vnc: Fix crash when specifying [vnc] without id in the config file
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 01/38] target/loongarch: Add CRC feature flag and use it to gate CRC instructions Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 02/38] target/loongarch: Guard 64-bit-only insn translation with TRANS64 macro Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 04/38] python: backport 'kick event queue on legacy event_pull()' Michael Tokarev
` (34 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Thomas Huth, Marc-André Lureau, Michael Tokarev
From: Thomas Huth <thuth@redhat.com>
QEMU currently crashes when there is a [vnc] section in the config
file that does not have an "id = ..." line:
$ echo "[vnc]" > /tmp/qemu.conf
$ ./qemu-system-x86_64 -readconfig /tmp/qemu.conf
qemu-system-x86_64: ../../devel/qemu/ui/vnc.c:4347: vnc_init_func:
Assertion `id' failed.
Aborted (core dumped)
The required "id" is only set up automatically while parsing the command
line, but not when reading the options from the config file.
Thus let's move code that automatically adds the id (if it does not
exist yet) to the init function that needs the id for the first time,
replacing the assert() statement there.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2836
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-ID: <20250821145130.845104-1-thuth@redhat.com>
(cherry picked from commit 38dd513263d814dc3cf554b899c118a46ca77577)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/ui/vnc.c b/ui/vnc.c
index a6bf8442d5..6a26f05daa 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -4265,8 +4265,9 @@ void vnc_display_add_client(const char *id, int csock, bool skipauth)
}
}
-static void vnc_auto_assign_id(QemuOptsList *olist, QemuOpts *opts)
+static char *vnc_auto_assign_id(QemuOpts *opts)
{
+ QemuOptsList *olist = qemu_find_opts("vnc");
int i = 2;
char *id;
@@ -4276,23 +4277,18 @@ static void vnc_auto_assign_id(QemuOptsList *olist, QemuOpts *opts)
id = g_strdup_printf("vnc%d", i++);
}
qemu_opts_set_id(opts, id);
+
+ return id;
}
void vnc_parse(const char *str)
{
QemuOptsList *olist = qemu_find_opts("vnc");
QemuOpts *opts = qemu_opts_parse_noisily(olist, str, !is_help_option(str));
- const char *id;
if (!opts) {
exit(1);
}
-
- id = qemu_opts_id(opts);
- if (!id) {
- /* auto-assign id if not present */
- vnc_auto_assign_id(olist, opts);
- }
}
int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp)
@@ -4300,7 +4296,11 @@ int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp)
Error *local_err = NULL;
char *id = (char *)qemu_opts_id(opts);
- assert(id);
+ if (!id) {
+ /* auto-assign id if not present */
+ id = vnc_auto_assign_id(opts);
+ }
+
vnc_display_init(id, &local_err);
if (local_err) {
error_propagate(errp, local_err);
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 04/38] python: backport 'kick event queue on legacy event_pull()'
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (2 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 03/38] ui/vnc: Fix crash when specifying [vnc] without id in the config file Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 05/38] python: backport 'drop Python3.6 workarounds' Michael Tokarev
` (33 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, John Snow, Jag Raman, Daniel P. Berrangé,
Michael Tokarev
From: John Snow <jsnow@redhat.com>
This corrects an oversight in qmp-shell operation where new events will
not accumulate in the event queue when pressing "enter" with an empty
command buffer, so no new events show up.
Reported-by: Jag Raman <jag.raman@oracle.com>
Signed-off-by: John Snow <jsnow@redhat.com>
cherry picked from commit python-qemu-qmp@0443582d16cf9efd52b2c41a7b5be7af42c856cd
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit 1e343714bfc06cc982e68a290f3809117d6dfcd0)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/python/qemu/qmp/legacy.py b/python/qemu/qmp/legacy.py
index 22a2b5616e..c8d0a29b56 100644
--- a/python/qemu/qmp/legacy.py
+++ b/python/qemu/qmp/legacy.py
@@ -231,6 +231,9 @@ def pull_event(self,
:return: The first available QMP event, or None.
"""
+ # Kick the event loop to allow events to accumulate
+ self._sync(asyncio.sleep(0))
+
if not wait:
# wait is False/0: "do not wait, do not except."
if self._qmp.events.empty():
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 05/38] python: backport 'drop Python3.6 workarounds'
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (3 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 04/38] python: backport 'kick event queue on legacy event_pull()' Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 06/38] python: backport 'Use @asynciocontextmanager' Michael Tokarev
` (32 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, John Snow, Daniel P. Berrangé, Michael Tokarev
From: John Snow <jsnow@redhat.com>
Now that the minimum version is 3.7, drop some of the 3.6-specific hacks
we've been carrying. A single remaining compatibility hack concerning
3.6's lack of @asynccontextmanager is addressed in the following commit.
Signed-off-by: John Snow <jsnow@redhat.com>
cherry picked from commit python-qemu-qmp@3e8e34e594cfc6b707e6f67959166acde4b421b8
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit f9d2e0a3bd7ba2a693a892881f91cf53fa90cc71)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/python/qemu/qmp/protocol.py b/python/qemu/qmp/protocol.py
index a4ffdfad51..4aff0ea423 100644
--- a/python/qemu/qmp/protocol.py
+++ b/python/qemu/qmp/protocol.py
@@ -36,13 +36,10 @@
from .error import QMPError
from .util import (
bottom_half,
- create_task,
exception_summary,
flush,
- is_closing,
pretty_traceback,
upper_half,
- wait_closed,
)
@@ -663,8 +660,8 @@ async def _establish_session(self) -> None:
reader_coro = self._bh_loop_forever(self._bh_recv_message, 'Reader')
writer_coro = self._bh_loop_forever(self._bh_send_message, 'Writer')
- self._reader_task = create_task(reader_coro)
- self._writer_task = create_task(writer_coro)
+ self._reader_task = asyncio.create_task(reader_coro)
+ self._writer_task = asyncio.create_task(writer_coro)
self._bh_tasks = asyncio.gather(
self._reader_task,
@@ -689,7 +686,7 @@ def _schedule_disconnect(self) -> None:
if not self._dc_task:
self._set_state(Runstate.DISCONNECTING)
self.logger.debug("Scheduling disconnect.")
- self._dc_task = create_task(self._bh_disconnect())
+ self._dc_task = asyncio.create_task(self._bh_disconnect())
@upper_half
async def _wait_disconnect(self) -> None:
@@ -825,13 +822,13 @@ async def _bh_close_stream(self, error_pathway: bool = False) -> None:
if not self._writer:
return
- if not is_closing(self._writer):
+ if not self._writer.is_closing():
self.logger.debug("Closing StreamWriter.")
self._writer.close()
self.logger.debug("Waiting for StreamWriter to close ...")
try:
- await wait_closed(self._writer)
+ await self._writer.wait_closed()
except Exception: # pylint: disable=broad-except
# It's hard to tell if the Stream is already closed or
# not. Even if one of the tasks has failed, it may have
diff --git a/python/qemu/qmp/qmp_tui.py b/python/qemu/qmp/qmp_tui.py
index 2d9ebbd20b..562be008d5 100644
--- a/python/qemu/qmp/qmp_tui.py
+++ b/python/qemu/qmp/qmp_tui.py
@@ -40,7 +40,7 @@
from .message import DeserializationError, Message, UnexpectedTypeError
from .protocol import ConnectError, Runstate
from .qmp_client import ExecInterruptedError, QMPClient
-from .util import create_task, pretty_traceback
+from .util import pretty_traceback
# The name of the signal that is used to update the history list
@@ -225,7 +225,7 @@ def cb_send_to_server(self, raw_msg: str) -> None:
"""
try:
msg = Message(bytes(raw_msg, encoding='utf-8'))
- create_task(self._send_to_server(msg))
+ asyncio.create_task(self._send_to_server(msg))
except (DeserializationError, UnexpectedTypeError) as err:
raw_msg = format_json(raw_msg)
logging.info('Invalid message: %s', err.error_message)
@@ -246,7 +246,7 @@ def kill_app(self) -> None:
Initiates killing of app. A bridge between asynchronous and synchronous
code.
"""
- create_task(self._kill_app())
+ asyncio.create_task(self._kill_app())
async def _kill_app(self) -> None:
"""
@@ -393,7 +393,7 @@ def run(self, debug: bool = False) -> None:
handle_mouse=True,
event_loop=event_loop)
- create_task(self.manage_connection(), self.aloop)
+ self.aloop.create_task(self.manage_connection())
try:
main_loop.run()
except Exception as err:
diff --git a/python/qemu/qmp/util.py b/python/qemu/qmp/util.py
index ca6225e9cd..0b3e781373 100644
--- a/python/qemu/qmp/util.py
+++ b/python/qemu/qmp/util.py
@@ -1,25 +1,15 @@
"""
Miscellaneous Utilities
-This module provides asyncio utilities and compatibility wrappers for
-Python 3.6 to provide some features that otherwise become available in
-Python 3.7+.
-
-Various logging and debugging utilities are also provided, such as
-`exception_summary()` and `pretty_traceback()`, used primarily for
-adding information into the logging stream.
+This module provides asyncio and various logging and debugging
+utilities, such as `exception_summary()` and `pretty_traceback()`, used
+primarily for adding information into the logging stream.
"""
import asyncio
import sys
import traceback
-from typing import (
- Any,
- Coroutine,
- Optional,
- TypeVar,
- cast,
-)
+from typing import TypeVar, cast
T = TypeVar('T')
@@ -79,95 +69,6 @@ def bottom_half(func: T) -> T:
return func
-# -------------------------------
-# Section: Compatibility Wrappers
-# -------------------------------
-
-
-def create_task(coro: Coroutine[Any, Any, T],
- loop: Optional[asyncio.AbstractEventLoop] = None
- ) -> 'asyncio.Future[T]':
- """
- Python 3.6-compatible `asyncio.create_task` wrapper.
-
- :param coro: The coroutine to execute in a task.
- :param loop: Optionally, the loop to create the task in.
-
- :return: An `asyncio.Future` object.
- """
- if sys.version_info >= (3, 7):
- if loop is not None:
- return loop.create_task(coro)
- return asyncio.create_task(coro) # pylint: disable=no-member
-
- # Python 3.6:
- return asyncio.ensure_future(coro, loop=loop)
-
-
-def is_closing(writer: asyncio.StreamWriter) -> bool:
- """
- Python 3.6-compatible `asyncio.StreamWriter.is_closing` wrapper.
-
- :param writer: The `asyncio.StreamWriter` object.
- :return: `True` if the writer is closing, or closed.
- """
- if sys.version_info >= (3, 7):
- return writer.is_closing()
-
- # Python 3.6:
- transport = writer.transport
- assert isinstance(transport, asyncio.WriteTransport)
- return transport.is_closing()
-
-
-async def wait_closed(writer: asyncio.StreamWriter) -> None:
- """
- Python 3.6-compatible `asyncio.StreamWriter.wait_closed` wrapper.
-
- :param writer: The `asyncio.StreamWriter` to wait on.
- """
- if sys.version_info >= (3, 7):
- await writer.wait_closed()
- return
-
- # Python 3.6
- transport = writer.transport
- assert isinstance(transport, asyncio.WriteTransport)
-
- while not transport.is_closing():
- await asyncio.sleep(0)
-
- # This is an ugly workaround, but it's the best I can come up with.
- sock = transport.get_extra_info('socket')
-
- if sock is None:
- # Our transport doesn't have a socket? ...
- # Nothing we can reasonably do.
- return
-
- while sock.fileno() != -1:
- await asyncio.sleep(0)
-
-
-def asyncio_run(coro: Coroutine[Any, Any, T], *, debug: bool = False) -> T:
- """
- Python 3.6-compatible `asyncio.run` wrapper.
-
- :param coro: A coroutine to execute now.
- :return: The return value from the coroutine.
- """
- if sys.version_info >= (3, 7):
- return asyncio.run(coro, debug=debug)
-
- # Python 3.6
- loop = asyncio.get_event_loop()
- loop.set_debug(debug)
- ret = loop.run_until_complete(coro)
- loop.close()
-
- return ret
-
-
# ----------------------------
# Section: Logging & Debugging
# ----------------------------
diff --git a/python/tests/protocol.py b/python/tests/protocol.py
index 56c4d441f9..c254c77b17 100644
--- a/python/tests/protocol.py
+++ b/python/tests/protocol.py
@@ -8,7 +8,6 @@
from qemu.qmp import ConnectError, Runstate
from qemu.qmp.protocol import AsyncProtocol, StateError
-from qemu.qmp.util import asyncio_run, create_task
class NullProtocol(AsyncProtocol[None]):
@@ -124,7 +123,7 @@ async def _runner():
if allow_cancellation:
return
raise
- return create_task(_runner())
+ return asyncio.create_task(_runner())
@contextmanager
@@ -271,7 +270,7 @@ async def _watcher():
msg=f"Expected state '{state.name}'",
)
- self.runstate_watcher = create_task(_watcher())
+ self.runstate_watcher = asyncio.create_task(_watcher())
# Kick the loop and force the task to block on the event.
await asyncio.sleep(0)
@@ -589,7 +588,8 @@ async def _asyncTearDown(self):
async def testSmoke(self):
with TemporaryDirectory(suffix='.qmp') as tmpdir:
sock = os.path.join(tmpdir, type(self.proto).__name__ + ".sock")
- server_task = create_task(self.server.start_server_and_accept(sock))
+ server_task = asyncio.create_task(
+ self.server.start_server_and_accept(sock))
# give the server a chance to start listening [...]
await asyncio.sleep(0)
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 06/38] python: backport 'Use @asynciocontextmanager'
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (4 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 05/38] python: backport 'drop Python3.6 workarounds' Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 07/38] python: backport 'qmp-shell-wrap: handle missing binary gracefully' Michael Tokarev
` (31 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, John Snow, Daniel P. Berrangé, Michael Tokarev
From: John Snow <jsnow@redhat.com>
This removes a non-idiomatic use of a "coroutine callback" in favor of
something a bit more standardized.
Signed-off-by: John Snow <jsnow@redhat.com>
cherry picked from commit python-qemu-qmp@commit 97f7ffa3be17a50544b52767d14b6fd478c07b9e
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit 0408b8d7a086486f5c1887798be744b2d73bcda9)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/python/qemu/qmp/protocol.py b/python/qemu/qmp/protocol.py
index 4aff0ea423..56e6dfa5a7 100644
--- a/python/qemu/qmp/protocol.py
+++ b/python/qemu/qmp/protocol.py
@@ -15,6 +15,7 @@
import asyncio
from asyncio import StreamReader, StreamWriter
+from contextlib import asynccontextmanager
from enum import Enum
from functools import wraps
import logging
@@ -22,6 +23,7 @@
from ssl import SSLContext
from typing import (
Any,
+ AsyncGenerator,
Awaitable,
Callable,
Generic,
@@ -318,9 +320,8 @@ async def start_server(self, address: SocketAddrT,
This exception will wrap a more concrete one. In most cases,
the wrapped exception will be `OSError`.
"""
- await self._session_guard(
- self._do_start_server(address, ssl),
- 'Failed to establish connection')
+ async with self._session_guard('Failed to establish connection'):
+ await self._do_start_server(address, ssl)
assert self.runstate == Runstate.CONNECTING
@upper_half
@@ -343,12 +344,10 @@ async def accept(self) -> None:
"""
if self._accepted is None:
raise QMPError("Cannot call accept() before start_server().")
- await self._session_guard(
- self._do_accept(),
- 'Failed to establish connection')
- await self._session_guard(
- self._establish_session(),
- 'Failed to establish session')
+ async with self._session_guard('Failed to establish connection'):
+ await self._do_accept()
+ async with self._session_guard('Failed to establish session'):
+ await self._establish_session()
assert self.runstate == Runstate.RUNNING
@upper_half
@@ -373,12 +372,10 @@ async def connect(self, address: Union[SocketAddrT, socket.socket],
protocol-level failure occurs while establishing a new
session, the wrapped error may also be an `QMPError`.
"""
- await self._session_guard(
- self._do_connect(address, ssl),
- 'Failed to establish connection')
- await self._session_guard(
- self._establish_session(),
- 'Failed to establish session')
+ async with self._session_guard('Failed to establish connection'):
+ await self._do_connect(address, ssl)
+ async with self._session_guard('Failed to establish session'):
+ await self._establish_session()
assert self.runstate == Runstate.RUNNING
@upper_half
@@ -399,7 +396,8 @@ async def disconnect(self) -> None:
# Section: Session machinery
# --------------------------
- async def _session_guard(self, coro: Awaitable[None], emsg: str) -> None:
+ @asynccontextmanager
+ async def _session_guard(self, emsg: str) -> AsyncGenerator[None, None]:
"""
Async guard function used to roll back to `IDLE` on any error.
@@ -416,10 +414,9 @@ async def _session_guard(self, coro: Awaitable[None], emsg: str) -> None:
:raise ConnectError:
When any other error is encountered in the guarded block.
"""
- # Note: After Python 3.6 support is removed, this should be an
- # @asynccontextmanager instead of accepting a callback.
try:
- await coro
+ # Caller's code runs here.
+ yield
except BaseException as err:
self.logger.error("%s: %s", emsg, exception_summary(err))
self.logger.debug("%s:\n%s\n", emsg, pretty_traceback())
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 07/38] python: backport 'qmp-shell-wrap: handle missing binary gracefully'
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (5 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 06/38] python: backport 'Use @asynciocontextmanager' Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 08/38] python: backport 'qmp-tui: Do not crash if optional dependencies are not met' Michael Tokarev
` (30 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, John Snow, Daniel P. Berrangé, Michael Tokarev
From: John Snow <jsnow@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
cherry picked from commit python-qemu-qmp@9c889dcbd58817b0c917a9d2dd16161f48ac8203
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit fcaeeb7653d2c6f38183170e1cae5729adb7875c)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/python/qemu/qmp/qmp_shell.py b/python/qemu/qmp/qmp_shell.py
index 98e684e9e8..1ba0e72407 100644
--- a/python/qemu/qmp/qmp_shell.py
+++ b/python/qemu/qmp/qmp_shell.py
@@ -610,6 +610,8 @@ def main_wrap() -> None:
for _ in qemu.repl():
pass
+ except FileNotFoundError:
+ sys.stderr.write(f"ERROR: QEMU executable '{cmd[0]}' not found.\n")
finally:
os.unlink(sockpath)
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 08/38] python: backport 'qmp-tui: Do not crash if optional dependencies are not met'
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (6 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 07/38] python: backport 'qmp-shell-wrap: handle missing binary gracefully' Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 09/38] python: backport 'Remove deprecated get_event_loop calls' Michael Tokarev
` (29 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, John Snow, Daniel P. Berrangé, Michael Tokarev
From: John Snow <jsnow@redhat.com>
Based on the discussion at https://github.com/pypa/pip/issues/9726 -
even though the setuptools documentation implies that it is possible to
guard script execution with optional dependency groups, this is not true
in practice with the scripts generated by pip.
Just do the simple thing and guard the import statements.
Signed-off-by: John Snow <jsnow@redhat.com>
cherry picked from commit python-qemu-qmp@df520dcacf9a75dd4c82ab1129768de4128b554c
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit fd0ed46d4effbf2700804657bad9c6db086527c4)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/python/qemu/qmp/qmp_tui.py b/python/qemu/qmp/qmp_tui.py
index 562be008d5..53ea6c59a7 100644
--- a/python/qemu/qmp/qmp_tui.py
+++ b/python/qemu/qmp/qmp_tui.py
@@ -21,6 +21,7 @@
import logging
from logging import Handler, LogRecord
import signal
+import sys
from typing import (
List,
Optional,
@@ -30,10 +31,20 @@
cast,
)
-from pygments import lexers
-from pygments import token as Token
-import urwid
-import urwid_readline
+
+try:
+ from pygments import lexers
+ from pygments import token as Token
+ import urwid
+ import urwid_readline
+except ModuleNotFoundError as exc:
+ print(
+ f"Module '{exc.name}' not found.",
+ "You need the optional 'tui' group: pip install qemu.qmp[tui]",
+ sep='\n',
+ file=sys.stderr,
+ )
+ sys.exit(1)
from .error import ProtocolError
from .legacy import QEMUMonitorProtocol, QMPBadPortError
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 09/38] python: backport 'Remove deprecated get_event_loop calls'
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (7 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 08/38] python: backport 'qmp-tui: Do not crash if optional dependencies are not met' Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 10/38] python: backport 'avoid creating additional event loops per thread' Michael Tokarev
` (28 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, John Snow, Daniel P. Berrangé, Michael Tokarev
From: John Snow <jsnow@redhat.com>
This method was deprecated in 3.12 because it ordinarily should not be
used from coroutines; if there is not a currently running event loop,
this automatically creates a new event loop - which is usually not what
you want from code that would ever run in the bottom half.
In our case, we do want this behavior in two places:
(1) The synchronous shim, for convenience: this allows fully sync
programs to use QEMUMonitorProtocol() without needing to set up an event
loop beforehand. This is intentional to fully box in the async
complexities into the legacy sync shim.
(2) The qmp_tui shell; instead of relying on asyncio.run to create and
run an asyncio program, we need to be able to pass the current asyncio
loop to urwid setup functions. For convenience, again, we create one if
one is not present to simplify the creation of the TUI appliance.
The remaining user of get_event_loop() was in fact one of the erroneous
users that should not have been using this function: if there's no
running event loop inside of a coroutine, you're in big trouble :)
Signed-off-by: John Snow <jsnow@redhat.com>
cherry picked from commit python-qemu-qmp@aa1ff9907603a3033296027e1bd021133df86ef1
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit 5d99044d09db0fa8c2b3294e301927118f9effc9)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/python/qemu/qmp/legacy.py b/python/qemu/qmp/legacy.py
index c8d0a29b56..735d42971e 100644
--- a/python/qemu/qmp/legacy.py
+++ b/python/qemu/qmp/legacy.py
@@ -86,7 +86,14 @@ def __init__(self,
"server argument should be False when passing a socket")
self._qmp = QMPClient(nickname)
- self._aloop = asyncio.get_event_loop()
+
+ try:
+ self._aloop = asyncio.get_running_loop()
+ except RuntimeError:
+ # No running loop; since this is a sync shim likely to be
+ # used in fully sync programs, create one if neccessary.
+ self._aloop = asyncio.get_event_loop_policy().get_event_loop()
+
self._address = address
self._timeout: Optional[float] = None
diff --git a/python/qemu/qmp/qmp_tui.py b/python/qemu/qmp/qmp_tui.py
index 53ea6c59a7..12bdc17c99 100644
--- a/python/qemu/qmp/qmp_tui.py
+++ b/python/qemu/qmp/qmp_tui.py
@@ -388,7 +388,12 @@ def run(self, debug: bool = False) -> None:
screen = urwid.raw_display.Screen()
screen.set_terminal_properties(256)
- self.aloop = asyncio.get_event_loop()
+ try:
+ self.aloop = asyncio.get_running_loop()
+ except RuntimeError:
+ # No running asyncio event loop. Create one if necessary.
+ self.aloop = asyncio.get_event_loop_policy().get_event_loop()
+
self.aloop.set_debug(debug)
# Gracefully handle SIGTERM and SIGINT signals
diff --git a/python/tests/protocol.py b/python/tests/protocol.py
index c254c77b17..e565802516 100644
--- a/python/tests/protocol.py
+++ b/python/tests/protocol.py
@@ -227,7 +227,7 @@ def async_test(async_test_method):
Decorator; adds SetUp and TearDown to async tests.
"""
async def _wrapper(self, *args, **kwargs):
- loop = asyncio.get_event_loop()
+ loop = asyncio.get_running_loop()
loop.set_debug(True)
await self._asyncSetUp()
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 10/38] python: backport 'avoid creating additional event loops per thread'
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (8 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 09/38] python: backport 'Remove deprecated get_event_loop calls' Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 11/38] iotests: drop compat for old version context manager Michael Tokarev
` (27 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, John Snow, Richard W.M. Jones,
Daniel P. Berrangé, Michael Tokarev
From: John Snow <jsnow@redhat.com>
This commit is two backports squashed into one to avoid regressions.
python: *really* remove get_event_loop
A prior commit, aa1ff990, switched away from using get_event_loop *by
default*, but this is not good enough to avoid deprecation warnings as
`asyncio.get_event_loop_policy().get_event_loop()` is *also*
deprecated. Replace this mechanism with explicit calls to
asyncio.get_new_loop() and revise the cleanup mechanisms in __del__ to
match.
python: avoid creating additional event loops per thread
"Too hasty by far!", commit 21ce2ee4 attempted to avoid deprecated
behavior altogether by calling new_event_loop() directly if there was no
loop currently running, but this has the unfortunate side effect of
potentially creating multiple event loops per thread if tests
instantiate multiple QMP connections in a single thread. This behavior
is apparently not well-defined and causes problems in some, but not all,
combinations of Python interpreter version and platform environment.
Partially revert to Daniel Berrange's original patch, which calls
get_event_loop and simply suppresses the deprecation warning in
Python<=3.13. This time, however, additionally register new loops
created with new_event_loop() so that future calls to get_event_loop()
will return the loop already created.
Reported-by: Richard W.M. Jones <rjones@redhat.com>
Reported-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
cherry picked from commit python-qemu-qmp@21ce2ee4f2df87efe84a27b9c5112487f4670622
cherry picked from commit python-qemu-qmp@c08fb82b38212956ccffc03fc6d015c3979f42fe
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit 85f223e5b031eb8ab63fbca314a4fb296a3a2632)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/python/qemu/qmp/legacy.py b/python/qemu/qmp/legacy.py
index 735d42971e..e46695ae2c 100644
--- a/python/qemu/qmp/legacy.py
+++ b/python/qemu/qmp/legacy.py
@@ -38,6 +38,7 @@
from .error import QMPError
from .protocol import Runstate, SocketAddrT
from .qmp_client import QMPClient
+from .util import get_or_create_event_loop
#: QMPMessage is an entire QMP message of any kind.
@@ -86,17 +87,13 @@ def __init__(self,
"server argument should be False when passing a socket")
self._qmp = QMPClient(nickname)
-
- try:
- self._aloop = asyncio.get_running_loop()
- except RuntimeError:
- # No running loop; since this is a sync shim likely to be
- # used in fully sync programs, create one if neccessary.
- self._aloop = asyncio.get_event_loop_policy().get_event_loop()
-
self._address = address
self._timeout: Optional[float] = None
+ # This is a sync shim intended for use in fully synchronous
+ # programs. Create and set an event loop if necessary.
+ self._aloop = get_or_create_event_loop()
+
if server:
assert not isinstance(self._address, socket.socket)
self._sync(self._qmp.start_server(self._address))
@@ -313,17 +310,30 @@ def send_fd_scm(self, fd: int) -> None:
self._qmp.send_fd_scm(fd)
def __del__(self) -> None:
- if self._qmp.runstate == Runstate.IDLE:
- return
+ if self._qmp.runstate != Runstate.IDLE:
+ self._qmp.logger.warning(
+ "QEMUMonitorProtocol object garbage collected without a prior "
+ "call to close()"
+ )
if not self._aloop.is_running():
- self.close()
- else:
- # Garbage collection ran while the event loop was running.
- # Nothing we can do about it now, but if we don't raise our
- # own error, the user will be treated to a lot of traceback
- # they might not understand.
+ if self._qmp.runstate != Runstate.IDLE:
+ # If the user neglected to close the QMP session and we
+ # are not currently running in an asyncio context, we
+ # have the opportunity to close the QMP session. If we
+ # do not do this, the error messages presented over
+ # dangling async resources may not make any sense to the
+ # user.
+ self.close()
+
+ if self._qmp.runstate != Runstate.IDLE:
+ # If QMP is still not quiesced, it means that the garbage
+ # collector ran from a context within the event loop and we
+ # are simply too late to take any corrective action. Raise
+ # our own error to give meaningful feedback to the user in
+ # order to prevent pages of asyncio stacktrace jargon.
raise QMPError(
- "QEMUMonitorProtocol.close()"
- " was not called before object was garbage collected"
+ "QEMUMonitorProtocol.close() was not called before object was "
+ "garbage collected, and could not be closed due to GC running "
+ "in the event loop"
)
diff --git a/python/qemu/qmp/qmp_tui.py b/python/qemu/qmp/qmp_tui.py
index 12bdc17c99..d946c20513 100644
--- a/python/qemu/qmp/qmp_tui.py
+++ b/python/qemu/qmp/qmp_tui.py
@@ -51,7 +51,7 @@
from .message import DeserializationError, Message, UnexpectedTypeError
from .protocol import ConnectError, Runstate
from .qmp_client import ExecInterruptedError, QMPClient
-from .util import pretty_traceback
+from .util import get_or_create_event_loop, pretty_traceback
# The name of the signal that is used to update the history list
@@ -387,13 +387,7 @@ def run(self, debug: bool = False) -> None:
"""
screen = urwid.raw_display.Screen()
screen.set_terminal_properties(256)
-
- try:
- self.aloop = asyncio.get_running_loop()
- except RuntimeError:
- # No running asyncio event loop. Create one if necessary.
- self.aloop = asyncio.get_event_loop_policy().get_event_loop()
-
+ self.aloop = get_or_create_event_loop()
self.aloop.set_debug(debug)
# Gracefully handle SIGTERM and SIGINT signals
diff --git a/python/qemu/qmp/util.py b/python/qemu/qmp/util.py
index 0b3e781373..47ec39a8b5 100644
--- a/python/qemu/qmp/util.py
+++ b/python/qemu/qmp/util.py
@@ -10,6 +10,7 @@
import sys
import traceback
from typing import TypeVar, cast
+import warnings
T = TypeVar('T')
@@ -20,6 +21,32 @@
# --------------------------
+def get_or_create_event_loop() -> asyncio.AbstractEventLoop:
+ """
+ Return this thread's current event loop, or create a new one.
+
+ This function behaves similarly to asyncio.get_event_loop() in
+ Python<=3.13, where if there is no event loop currently associated
+ with the current context, it will create and register one. It should
+ generally not be used in any asyncio-native applications.
+ """
+ try:
+ with warnings.catch_warnings():
+ # Python <= 3.13 will trigger deprecation warnings if no
+ # event loop is set, but will create and set a new loop.
+ warnings.simplefilter("ignore")
+ loop = asyncio.get_event_loop()
+ except RuntimeError:
+ # Python 3.14+: No event loop set for this thread,
+ # create and set one.
+ loop = asyncio.new_event_loop()
+ # Set this loop as the current thread's loop, to be returned
+ # by calls to get_event_loop() in the future.
+ asyncio.set_event_loop(loop)
+
+ return loop
+
+
async def flush(writer: asyncio.StreamWriter) -> None:
"""
Utility function to ensure a StreamWriter is *fully* drained.
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 11/38] iotests: drop compat for old version context manager
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (9 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 10/38] python: backport 'avoid creating additional event loops per thread' Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 12/38] python: ensure QEMUQtestProtocol closes its socket Michael Tokarev
` (26 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-stable, Daniel P. Berrangé, Michael Tokarev
From: Daniel P. Berrangé <berrange@redhat.com>
Our minimum python is now 3.9, so back compat with prior
python versions is no longer required.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit 82c7cb93c750196f513a1b11cb85e0328bad444f)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py
index 6326e46b7b..29caaa8a34 100644
--- a/tests/qemu-iotests/testenv.py
+++ b/tests/qemu-iotests/testenv.py
@@ -22,15 +22,12 @@
from pathlib import Path
import shutil
import collections
+import contextlib
import random
import subprocess
import glob
from typing import List, Dict, Any, Optional
-if sys.version_info >= (3, 9):
- from contextlib import AbstractContextManager as ContextManager
-else:
- from typing import ContextManager
DEF_GDB_OPTIONS = 'localhost:12345'
@@ -58,7 +55,7 @@ def get_default_machine(qemu_prog: str) -> str:
return default_machine
-class TestEnv(ContextManager['TestEnv']):
+class TestEnv(contextlib.AbstractContextManager['TestEnv']):
"""
Manage system environment for running tests
diff --git a/tests/qemu-iotests/testrunner.py b/tests/qemu-iotests/testrunner.py
index 2e236c8fa3..14cc8492f9 100644
--- a/tests/qemu-iotests/testrunner.py
+++ b/tests/qemu-iotests/testrunner.py
@@ -30,11 +30,6 @@
from typing import List, Optional, Any, Sequence, Dict
from testenv import TestEnv
-if sys.version_info >= (3, 9):
- from contextlib import AbstractContextManager as ContextManager
-else:
- from typing import ContextManager
-
def silent_unlink(path: Path) -> None:
try:
@@ -57,7 +52,7 @@ def file_diff(file1: str, file2: str) -> List[str]:
return res
-class LastElapsedTime(ContextManager['LastElapsedTime']):
+class LastElapsedTime(contextlib.AbstractContextManager['LastElapsedTime']):
""" Cache for elapsed time for tests, to show it during new test run
It is safe to use get() at any time. To use update(), you must either
@@ -112,7 +107,7 @@ def __init__(self, status: str, description: str = '',
self.interrupted = interrupted
-class TestRunner(ContextManager['TestRunner']):
+class TestRunner(contextlib.AbstractContextManager['TestRunner']):
shared_self = None
@staticmethod
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 12/38] python: ensure QEMUQtestProtocol closes its socket
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (10 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 11/38] iotests: drop compat for old version context manager Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 13/38] iotests/147: ensure temporary sockets are closed before exiting Michael Tokarev
` (25 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-stable, Daniel P. Berrangé, Michael Tokarev
From: Daniel P. Berrangé <berrange@redhat.com>
While QEMUQtestMachine closes the socket that was passed to
QEMUQtestProtocol, the python resource leak manager still
believes that the copy QEMUQtestProtocol holds is open. We
must explicitly call close to avoid this leak warnnig.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit 6ccb48ffc19fe25511313a246d4a8bad51114ea9)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/python/qemu/machine/qtest.py b/python/qemu/machine/qtest.py
index 4f5ede85b2..781f674ffa 100644
--- a/python/qemu/machine/qtest.py
+++ b/python/qemu/machine/qtest.py
@@ -177,6 +177,8 @@ def _post_shutdown(self) -> None:
self._qtest_sock_pair[0].close()
self._qtest_sock_pair[1].close()
self._qtest_sock_pair = None
+ if self._qtest is not None:
+ self._qtest.close()
super()._post_shutdown()
def qtest(self, cmd: str) -> str:
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 13/38] iotests/147: ensure temporary sockets are closed before exiting
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (11 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 12/38] python: ensure QEMUQtestProtocol closes its socket Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 14/38] iotests/151: ensure subprocesses are cleaned up Michael Tokarev
` (24 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-stable, Daniel P. Berrangé, Michael Tokarev
From: Daniel P. Berrangé <berrange@redhat.com>
This avoids the python resource leak detector from issuing warnings
in the iotests.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit d4d0ebfcc926c11d16320d0d5accf22e3441c115)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/tests/qemu-iotests/147 b/tests/qemu-iotests/147
index 6d6f077a14..3e14bd389a 100755
--- a/tests/qemu-iotests/147
+++ b/tests/qemu-iotests/147
@@ -277,6 +277,7 @@ class BuiltinNBD(NBDBlockdevAddBase):
} }
self.client_test(filename, flatten_sock_addr(address), 'nbd-export')
+ sockfd.close()
self._server_down()
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 14/38] iotests/151: ensure subprocesses are cleaned up
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (12 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 13/38] iotests/147: ensure temporary sockets are closed before exiting Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 15/38] iotests/check: always enable all python warnings Michael Tokarev
` (23 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-stable, Daniel P. Berrangé, Michael Tokarev
From: Daniel P. Berrangé <berrange@redhat.com>
The iotest 151 creates a bunch of subprocesses, with their stdout
connected to a pipe but never reads any data from them and does
not gurantee the processes are killed on cleanup.
This triggers resource leak warnings from python when the
subprocess.Popen object is garbage collected.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit 2b2fb25c2aaf5b2e8172d845db39cc50a951a12e)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/tests/qemu-iotests/151 b/tests/qemu-iotests/151
index f2ff9c5dac..06ee3585db 100755
--- a/tests/qemu-iotests/151
+++ b/tests/qemu-iotests/151
@@ -263,6 +263,11 @@ class TestThrottledWithNbdExportBase(iotests.QMPTestCase):
break
except subprocess.TimeoutExpired:
self.vm.qtest(f'clock_step {1 * 1000 * 1000 * 1000}')
+ try:
+ p.kill()
+ p.stdout.close()
+ except:
+ pass
except IndexError:
pass
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 15/38] iotests/check: always enable all python warnings
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (13 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 14/38] iotests/151: ensure subprocesses are cleaned up Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 16/38] .gitmodules: move u-boot mirrors to qemu-project-mirrors Michael Tokarev
` (22 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-stable, Daniel P. Berrangé, Michael Tokarev
From: Daniel P. Berrangé <berrange@redhat.com>
Of most importance is that this gives us a heads-up if anything
we rely on has been deprecated. The default python behaviour
only emits a warning if triggered from __main__ which is very
limited.
Setting the env variable further ensures that any python child
processes will also display warnings.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit 9a494d83538680651197651031375c2b6fa2490b)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/tests/qemu-iotests/check b/tests/qemu-iotests/check
index 545f9ec7bd..d9b7c1d598 100755
--- a/tests/qemu-iotests/check
+++ b/tests/qemu-iotests/check
@@ -21,6 +21,7 @@ import sys
import argparse
import shutil
from pathlib import Path
+import warnings
from findtests import TestFinder
from testenv import TestEnv
@@ -137,6 +138,9 @@ def make_argparser() -> argparse.ArgumentParser:
if __name__ == '__main__':
+ warnings.simplefilter("default")
+ os.environ["PYTHONWARNINGS"] = "default"
+
args = make_argparser().parse_args()
env = TestEnv(source_dir=args.source_dir,
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 16/38] .gitmodules: move u-boot mirrors to qemu-project-mirrors
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (14 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 15/38] iotests/check: always enable all python warnings Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 17/38] tests/docker/dockerfiles/python.docker: pull fedora:40 image instead of fedora:latest Michael Tokarev
` (21 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Alex Bennée, Daniel P. Berrangé,
Richard Henderson, Michael Tokarev
From: Alex Bennée <alex.bennee@linaro.org>
To continue our GitLab Open Source Program license we need to pass an
automated license check for all repos under qemu-project. While U-Boot
is clearly GPLv2 rather than fight with the automated validation
script just move the mirror across to a separate project.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
Cc: qemu-stable@nongnu.org
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20250908141911.2546063-1-alex.bennee@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
(cherry picked from commit a11d1847d5ef8a7db58e6d4e44f36fec708f0981)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/.gitmodules b/.gitmodules
index 73cae4cd4d..e27dfe8c2c 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -15,7 +15,7 @@
url = https://gitlab.com/qemu-project/qemu-palcode.git
[submodule "roms/u-boot"]
path = roms/u-boot
- url = https://gitlab.com/qemu-project/u-boot.git
+ url = https://gitlab.com/qemu-project-mirrors/u-boot.git
[submodule "roms/skiboot"]
path = roms/skiboot
url = https://gitlab.com/qemu-project/skiboot.git
@@ -27,7 +27,7 @@
url = https://gitlab.com/qemu-project/seabios-hppa.git
[submodule "roms/u-boot-sam460ex"]
path = roms/u-boot-sam460ex
- url = https://gitlab.com/qemu-project/u-boot-sam460ex.git
+ url = https://gitlab.com/qemu-project-mirrors/u-boot-sam460ex.git
[submodule "roms/edk2"]
path = roms/edk2
url = https://gitlab.com/qemu-project/edk2.git
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 17/38] tests/docker/dockerfiles/python.docker: pull fedora:40 image instead of fedora:latest
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (15 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 16/38] .gitmodules: move u-boot mirrors to qemu-project-mirrors Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 18/38] ci: run RISC-V cross jobs by default Michael Tokarev
` (20 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-stable, Michael Tokarev, Daniel P. Berrangé
All other fedora dockerfiles use fedora:40.
fedora:latest does not have python3.8 anymore,
so python minreq/etc tests are failing in 10.0.x.
This patch is specific to 10.0.x stable branch.
In master, support for python3.8 has been dropped.
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/tests/docker/dockerfiles/python.docker b/tests/docker/dockerfiles/python.docker
index 8f0af9ef25..e1ddd46f50 100644
--- a/tests/docker/dockerfiles/python.docker
+++ b/tests/docker/dockerfiles/python.docker
@@ -1,6 +1,6 @@
# Python library testing environment
-FROM fedora:latest
+FROM fedora:40
MAINTAINER John Snow <jsnow@redhat.com>
# Please keep this list sorted alphabetically
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 18/38] ci: run RISC-V cross jobs by default
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (16 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 17/38] tests/docker/dockerfiles/python.docker: pull fedora:40 image instead of fedora:latest Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 19/38] rust: hpet: fix new warning Michael Tokarev
` (19 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-stable, Paolo Bonzini, Michael Tokarev
From: Paolo Bonzini <pbonzini@redhat.com>
The riscv64-debian-cross container is based on Trixie rather than sid
these days, so it is pretty much as stable as the others. Enable it
by default.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit eb8f7292e1315be0e36000a847b77153dcf460ef)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/.gitlab-ci.d/container-cross.yml b/.gitlab-ci.d/container-cross.yml
index 34c0e729ad..e45ea17cf1 100644
--- a/.gitlab-ci.d/container-cross.yml
+++ b/.gitlab-ci.d/container-cross.yml
@@ -67,11 +67,8 @@ ppc64el-debian-cross-container:
riscv64-debian-cross-container:
extends: .container_job_template
stage: containers
- # as we are currently based on 'sid/unstable' we may break so...
- allow_failure: true
variables:
NAME: debian-riscv64-cross
- QEMU_JOB_OPTIONAL: 1
s390x-debian-cross-container:
extends: .container_job_template
diff --git a/.gitlab-ci.d/crossbuilds.yml b/.gitlab-ci.d/crossbuilds.yml
index 7ae0f966f1..3f76c901ba 100644
--- a/.gitlab-ci.d/crossbuilds.yml
+++ b/.gitlab-ci.d/crossbuilds.yml
@@ -118,12 +118,8 @@ cross-ppc64el-kvm-only:
IMAGE: debian-ppc64el-cross
EXTRA_CONFIGURE_OPTS: --disable-tcg --without-default-devices
-# The riscv64 cross-builds currently use a 'sid' container to get
-# compilers and libraries. Until something more stable is found we
-# allow_failure so as not to block CI.
cross-riscv64-system:
extends: .cross_system_build_job
- allow_failure: true
needs:
job: riscv64-debian-cross-container
variables:
@@ -131,7 +127,6 @@ cross-riscv64-system:
cross-riscv64-user:
extends: .cross_user_build_job
- allow_failure: true
needs:
job: riscv64-debian-cross-container
variables:
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 19/38] rust: hpet: fix new warning
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (17 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 18/38] ci: run RISC-V cross jobs by default Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 20/38] hw/usb/network: Remove hardcoded 0x40 prefix in STRING_ETHADDR response Michael Tokarev
` (18 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Paolo Bonzini, Zhao Liu, Stefan Hajnoczi,
Michael Tokarev
From: Paolo Bonzini <pbonzini@redhat.com>
Nightly rustc complains that HPETAddrDecode has a lifetime but it is not
clearly noted that it comes from &self. Apply the compiler's suggestion
to shut it up.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 6b3fad084fc4e13901e252fe6c2a2c46ecea999b)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/rust/hw/timer/hpet/src/hpet.rs b/rust/hw/timer/hpet/src/hpet.rs
index 3ae3ec25f1..0bb31283ad 100644
--- a/rust/hw/timer/hpet/src/hpet.rs
+++ b/rust/hw/timer/hpet/src/hpet.rs
@@ -765,7 +765,7 @@ fn reset_hold(&self, _type: ResetType) {
self.rtc_irq_level.set(0);
}
- fn decode(&self, mut addr: hwaddr, size: u32) -> HPETAddrDecode {
+ fn decode(&self, mut addr: hwaddr, size: u32) -> HPETAddrDecode<'_> {
let shift = ((addr & 4) * 8) as u32;
let len = std::cmp::min(size * 8, 64 - shift);
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 20/38] hw/usb/network: Remove hardcoded 0x40 prefix in STRING_ETHADDR response
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (18 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 19/38] rust: hpet: fix new warning Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 21/38] i386/cpu: Enable SMM cpu address space under KVM Michael Tokarev
` (17 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Stéphane Graber, Daniel P. Berrangé,
Peter Maydell, Michael Tokarev
From: Stéphane Graber <stgraber@stgraber.org>
USB NICs have a "40:" prefix hardcoded for all MAC addresses when we
return the guest the MAC address if it queries the STRING_ETHADDR USB
string property. This doesn't match what we use for the
OID_802_3_PERMANENT_ADDRESS or OID_802_3_CURRENT_ADDRESS OIDs for
NDIS, or the MAC address we actually use in the QEMU networking code
to send/receive packets for this device, or the NIC info string we
print for users. In all those other places we directly use
s->conf.macaddr.a, which is the full thing the user asks for.
This overrides user-provided configuration and leads to an inconsistent
experience.
I couldn't find any documented reason (comment or git commits) for
this behavior. It seems like everyone is just expecting the MAC
address to be fully passed through to the guest, but it isn't.
This may have been a debugging hack that accidentally made it through
to the accepted patch: it has been in the code since it was originally
added back in 2008.
This is also particularly problematic as the "40:" prefix isn't a
reserved prefix for MAC addresses (IEEE OUI). There are a number of
valid allocations out there which use this prefix, meaning that QEMU
may be causing MAC address conflicts.
Cc: qemu-stable@nongnu.org
Fixes: 6c9f886ceae5b ("Add CDC-Ethernet usb NIC (original patch from Thomas Sailer)"
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2951
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
[PMM: beef up commit message based on mailing list discussion]
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
(cherry picked from commit aaf042299acf83919862c7d7dd5fc36acf4e0671)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c
index a87a0ffb95..e01a0389d4 100644
--- a/hw/usb/dev-network.c
+++ b/hw/usb/dev-network.c
@@ -1383,7 +1383,7 @@ static void usb_net_realize(USBDevice *dev, Error **errp)
qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
snprintf(s->usbstring_mac, sizeof(s->usbstring_mac),
"%02x%02x%02x%02x%02x%02x",
- 0x40,
+ s->conf.macaddr.a[0],
s->conf.macaddr.a[1],
s->conf.macaddr.a[2],
s->conf.macaddr.a[3],
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 21/38] i386/cpu: Enable SMM cpu address space under KVM
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (19 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 20/38] hw/usb/network: Remove hardcoded 0x40 prefix in STRING_ETHADDR response Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 22/38] target/i386: Define enum X86ASIdx for x86's address spaces Michael Tokarev
` (16 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Xiaoyao Li, Kirill Martynov, Zhao Liu, Paolo Bonzini,
Michael Tokarev
From: Xiaoyao Li <xiaoyao.li@intel.com>
Kirill Martynov reported assertation in cpu_asidx_from_attrs() being hit
when x86_cpu_dump_state() is called to dump the CPU state[*]. It happens
when the CPU is in SMM and KVM emulation failure due to misbehaving
guest.
The root cause is that QEMU i386 never enables the SMM address space for
cpu since KVM SMM support has been added.
Enable the SMM cpu address space under KVM when the SMM is enabled for
the x86machine.
[*] https://lore.kernel.org/qemu-devel/20250523154431.506993-1-stdcalllevi@yandex-team.ru/
Reported-by: Kirill Martynov <stdcalllevi@yandex-team.ru>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Tested-by: Kirill Martynov <stdcalllevi@yandex-team.ru>
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Link: https://lore.kernel.org/r/20250730095253.1833411-2-xiaoyao.li@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 0516f4b70264b9710a25718d21bd35ef463c875e)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/system/physmem.c b/system/physmem.c
index 32f5895b80..82d453ddde 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -763,9 +763,6 @@ void cpu_address_space_init(CPUState *cpu, int asidx,
cpu->as = as;
}
- /* KVM cannot currently support multiple address spaces. */
- assert(asidx == 0 || !kvm_enabled());
-
if (!cpu->cpu_ases) {
cpu->cpu_ases = g_new0(CPUAddressSpace, cpu->num_ases);
cpu->cpu_ases_count = cpu->num_ases;
@@ -788,8 +785,6 @@ void cpu_address_space_destroy(CPUState *cpu, int asidx)
assert(cpu->cpu_ases);
assert(asidx >= 0 && asidx < cpu->num_ases);
- /* KVM cannot currently support multiple address spaces. */
- assert(asidx == 0 || !kvm_enabled());
cpuas = &cpu->cpu_ases[asidx];
if (tcg_enabled()) {
diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c
index 6269fa8045..80ae347508 100644
--- a/target/i386/kvm/kvm-cpu.c
+++ b/target/i386/kvm/kvm-cpu.c
@@ -13,6 +13,7 @@
#include "qapi/error.h"
#include "system/system.h"
#include "hw/boards.h"
+#include "hw/i386/x86.h"
#include "kvm_i386.h"
#include "accel/accel-cpu-target.h"
@@ -90,6 +91,15 @@ static bool kvm_cpu_realizefn(CPUState *cs, Error **errp)
kvm_set_guest_phys_bits(cs);
}
+ /*
+ * When SMM is enabled, there is 2 address spaces. Otherwise only 1.
+ *
+ * Only initialize address space 0 here, the second one for SMM is
+ * initialized at register_smram_listener() after machine init done.
+ */
+ cs->num_ases = x86_machine_is_smm_enabled(X86_MACHINE(current_machine)) ? 2 : 1;
+ cpu_address_space_init(cs, 0, "cpu-memory", cs->memory);
+
return true;
}
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 141694f803..589f879beb 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -2678,6 +2678,7 @@ static MemoryRegion smram_as_mem;
static void register_smram_listener(Notifier *n, void *unused)
{
+ CPUState *cpu;
MemoryRegion *smram =
(MemoryRegion *) object_resolve_path("/machine/smram", NULL);
@@ -2702,6 +2703,10 @@ static void register_smram_listener(Notifier *n, void *unused)
address_space_init(&smram_address_space, &smram_as_root, "KVM-SMRAM");
kvm_memory_listener_register(kvm_state, &smram_listener,
&smram_address_space, 1, "kvm-smram");
+
+ CPU_FOREACH(cpu) {
+ cpu_address_space_init(cpu, 1, "cpu-smm", &smram_as_root);
+ }
}
static void *kvm_msr_energy_thread(void *data)
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 22/38] target/i386: Define enum X86ASIdx for x86's address spaces
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (20 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 21/38] i386/cpu: Enable SMM cpu address space under KVM Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 23/38] multiboot: Fix the split lock Michael Tokarev
` (15 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Xiaoyao Li, Philippe Mathieu-Daudé, Zhao Liu,
Kirill Martynov, Paolo Bonzini, Michael Tokarev
From: Xiaoyao Li <xiaoyao.li@intel.com>
Define X86ASIdx as enum, like ARM's ARMASIdx, so that it's clear index 0
is for memory and index 1 is for SMM.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Tested-By: Kirill Martynov <stdcalllevi@yandex-team.ru>
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Link: https://lore.kernel.org/r/20250730095253.1833411-3-xiaoyao.li@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 591f817d819f5511fd9001dc863a326d23088811)
(Mjt: pick this change for completness with the previous one)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 76f24446a5..d5484f04d0 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -2517,6 +2517,11 @@ bool cpu_has_x2apic_feature(CPUX86State *env);
void x86_cpu_set_a20(X86CPU *cpu, int a20_state);
void cpu_sync_avx_hflag(CPUX86State *env);
+typedef enum X86ASIdx {
+ X86ASIdx_MEM = 0,
+ X86ASIdx_SMM = 1,
+} X86ASIdx;
+
#ifndef CONFIG_USER_ONLY
static inline int x86_asidx_from_attrs(CPUState *cs, MemTxAttrs attrs)
{
diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c
index 80ae347508..e462cbe62c 100644
--- a/target/i386/kvm/kvm-cpu.c
+++ b/target/i386/kvm/kvm-cpu.c
@@ -98,7 +98,7 @@ static bool kvm_cpu_realizefn(CPUState *cs, Error **errp)
* initialized at register_smram_listener() after machine init done.
*/
cs->num_ases = x86_machine_is_smm_enabled(X86_MACHINE(current_machine)) ? 2 : 1;
- cpu_address_space_init(cs, 0, "cpu-memory", cs->memory);
+ cpu_address_space_init(cs, X86ASIdx_MEM, "cpu-memory", cs->memory);
return true;
}
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 589f879beb..70d6095be9 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -2702,10 +2702,10 @@ static void register_smram_listener(Notifier *n, void *unused)
address_space_init(&smram_address_space, &smram_as_root, "KVM-SMRAM");
kvm_memory_listener_register(kvm_state, &smram_listener,
- &smram_address_space, 1, "kvm-smram");
+ &smram_address_space, X86ASIdx_SMM, "kvm-smram");
CPU_FOREACH(cpu) {
- cpu_address_space_init(cpu, 1, "cpu-smm", &smram_as_root);
+ cpu_address_space_init(cpu, X86ASIdx_SMM, "cpu-smm", &smram_as_root);
}
}
diff --git a/target/i386/tcg/system/tcg-cpu.c b/target/i386/tcg/system/tcg-cpu.c
index 13a3507863..8276c32c7b 100644
--- a/target/i386/tcg/system/tcg-cpu.c
+++ b/target/i386/tcg/system/tcg-cpu.c
@@ -73,8 +73,8 @@ bool tcg_cpu_realizefn(CPUState *cs, Error **errp)
memory_region_set_enabled(cpu->cpu_as_mem, true);
cs->num_ases = 2;
- cpu_address_space_init(cs, 0, "cpu-memory", cs->memory);
- cpu_address_space_init(cs, 1, "cpu-smm", cpu->cpu_as_root);
+ cpu_address_space_init(cs, X86ASIdx_MEM, "cpu-memory", cs->memory);
+ cpu_address_space_init(cs, X86ASIdx_SMM, "cpu-smm", cpu->cpu_as_root);
/* ... SMRAM with higher priority, linked from /machine/smram. */
cpu->machine_done.notify = tcg_cpu_machine_done;
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 23/38] multiboot: Fix the split lock
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (21 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 22/38] target/i386: Define enum X86ASIdx for x86's address spaces Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 24/38] linux-user: avoid -Werror=int-in-bool-context Michael Tokarev
` (14 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Xiaoyao Li, Philippe Mathieu-Daudé,
Paolo Bonzini, Michael Tokarev
From: Xiaoyao Li <xiaoyao.li@intel.com>
While running the kvm-unit-tests on Intel platforms with "split lock
disable" feature, every test triggers a kernel warning of
x86/split lock detection: #AC: qemu-system-x86_64/373232 took a split_lock trap at address: 0x1e3
Hack KVM by exiting to QEMU on split lock #AC, we get
KVM: exception 17 exit (error code 0x0)
EAX=00000001 EBX=00000000 ECX=00000014 EDX=0001fb80
ESI=00000000 EDI=000000a8 EBP=00000000 ESP=00006f10
EIP=000001e3 EFL=00010002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0900 00009000 0000ffff 00009300 DPL=0 DS16 [-WA]
CS =c000 000c0000 0000ffff 00009b00 DPL=0 CS16 [-RA]
SS =0000 00000000 0000ffff 00009300 DPL=0 DS16 [-WA]
DS =c000 000c0000 0000ffff 00009300 DPL=0 DS16 [-WA]
FS =0950 00009500 0000ffff 00009300 DPL=0 DS16 [-WA]
GS =06f2 00006f20 0000ffff 00009300 DPL=0 DS16 [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT= 000c02b4 00000027
IDT= 00000000 000003ff
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
EFER=0000000000000000
Code=89 16 08 00 65 66 0f 01 16 06 00 66 b8 01 00 00 00 0f 22 c0 <65> 66 ff 2e 00 00 b8 10 00 00 00 8e d0 8e d8 8e c0 8e e0 8e e8 66 b8 08 00 66 ba 10 05 66
And it matches with what disassembled from multiboo_dma.bin:
#objdump -b binary -m i386 -D pc-bios/multiboot_dma.bin
1d1: 08 00 or %al,(%eax)
1d3: 65 66 0f 01 16 lgdtw %gs:(%esi)
1d8: 06 push %es
1d9: 00 66 b8 add %ah,-0x48(%esi)
1dc: 01 00 add %eax,(%eax)
1de: 00 00 add %al,(%eax)
1e0: 0f 22 c0 mov %eax,%cr0
> 1e3: 65 66 ff 2e ljmpw *%gs:(%esi)
1e7: 00 00 add %al,(%eax)
1e9: b8 10 00 00 00 mov $0x10,%eax
1ee: 8e d0 mov %eax,%ss
1f0: 8e d8 mov %eax,%ds
1f2: 8e c0 mov %eax,%es
1f4: 8e e0 mov %eax,%fs
1f6: 8e e8 mov %eax,%gs
1f8: 66 b8 08 00 mov $0x8,%ax
1fc: 66 ba 10 05 mov $0x510,%dx
We can see that the instruction at 0x1e3 is a far jmp through the GDT.
However, the GDT is not 8 byte aligned, the base is 0xc02b4.
Intel processors follow the LOCK semantics to set the accessed flag of the
segment descriptor when loading a segment descriptor. If the the segment
descriptor crosses two cache line, it causes split lock.
Fix it by aligning the GDT on 8 bytes, so that segment descriptor cannot
span two cache lines.
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Link: https://lore.kernel.org/r/20250808035027.2194673-1-xiaoyao.li@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 4c8f69b94839f72314c69902312068d0b9b05a34)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/pc-bios/multiboot_dma.bin b/pc-bios/multiboot_dma.bin
index c0e2c3102a..e6d0c97093 100644
Binary files a/pc-bios/multiboot_dma.bin and b/pc-bios/multiboot_dma.bin differ
diff --git a/pc-bios/optionrom/multiboot.S b/pc-bios/optionrom/multiboot.S
index 181a4b03a3..c95e35c9cb 100644
--- a/pc-bios/optionrom/multiboot.S
+++ b/pc-bios/optionrom/multiboot.S
@@ -208,7 +208,7 @@ ljmp2:
prot_jump: .long prot_mode
.short 8
-.align 4, 0
+.align 8, 0
gdt:
/* 0x00 */
.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 24/38] linux-user: avoid -Werror=int-in-bool-context
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (22 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 23/38] multiboot: Fix the split lock Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 25/38] target/sparc: Allow TRANS macro with no extra arguments Michael Tokarev
` (13 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Paolo Bonzini, Richard Henderson,
Daniel P. Berrangé, Michael Tokarev
From: Paolo Bonzini <pbonzini@redhat.com>
linux-user is failing to compile on Fedora 43:
../linux-user/strace.c:57:66: error: enum constant in boolean context [-Werror=int-in-bool-context]
57 | #define FLAG_BASIC(V, M, N) { V, M | QEMU_BUILD_BUG_ON_ZERO(!(M)), N }
The warning does not seem to be too useful and we could even disable it,
but the workaround is simple in this case.
Cc: qemu-stable@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit db05b0d21ec1e0532cf5f5103ae6520a838d96f9)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/linux-user/strace.c b/linux-user/strace.c
index 3b744ccd4a..85b956fdfb 100644
--- a/linux-user/strace.c
+++ b/linux-user/strace.c
@@ -54,7 +54,7 @@ struct flags {
};
/* No 'struct flags' element should have a zero mask. */
-#define FLAG_BASIC(V, M, N) { V, M | QEMU_BUILD_BUG_ON_ZERO(!(M)), N }
+#define FLAG_BASIC(V, M, N) { V, M | QEMU_BUILD_BUG_ON_ZERO((M) == 0), N }
/* common flags for all architectures */
#define FLAG_GENERIC_MASK(V, M) FLAG_BASIC(V, M, #V)
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 25/38] target/sparc: Allow TRANS macro with no extra arguments
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (23 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 24/38] linux-user: avoid -Werror=int-in-bool-context Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 26/38] target/sparc: Loosen decode of STBAR for v8 Michael Tokarev
` (12 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Richard Henderson, Mark Cave-Ayland, Michael Tokarev
From: Richard Henderson <richard.henderson@linaro.org>
Use ## to drop the preceding comma if __VA_ARGS__ is empty.
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
(cherry picked from commit b7cd0a1821adf9906c5edb248394bb2a95482656)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/target/sparc/translate.c b/target/sparc/translate.c
index bfe63649db..ddc4154ee3 100644
--- a/target/sparc/translate.c
+++ b/target/sparc/translate.c
@@ -2488,7 +2488,7 @@ static int extract_qfpreg(DisasContext *dc, int x)
#define TRANS(NAME, AVAIL, FUNC, ...) \
static bool trans_##NAME(DisasContext *dc, arg_##NAME *a) \
- { return avail_##AVAIL(dc) && FUNC(dc, __VA_ARGS__); }
+ { return avail_##AVAIL(dc) && FUNC(dc, ## __VA_ARGS__); }
#define avail_ALL(C) true
#ifdef TARGET_SPARC64
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 26/38] target/sparc: Loosen decode of STBAR for v8
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (24 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 25/38] target/sparc: Allow TRANS macro with no extra arguments Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 27/38] target/sparc: Loosen decode of RDY for v7 Michael Tokarev
` (11 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Richard Henderson, Mark Cave-Ayland, Michael Tokarev
From: Richard Henderson <richard.henderson@linaro.org>
Solaris 8 appears to have a bug whereby it executes v9 MEMBAR
instructions when booting a freshly installed image. According
to the SPARC v8 architecture manual, whilst bits 13 and bits 12-0
of the "Read State Register Instructions" are notionally zero,
they are marked as unused (i.e. ignored).
Fixes: af25071c1d ("target/sparc: Move RDASR, STBAR, MEMBAR to decodetree")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3097
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Tested-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
(cherry picked from commit b6cdd6c6050567c02a3b3cd428f85bb79d7455aa)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/target/sparc/insns.decode b/target/sparc/insns.decode
index 9e39d23273..1b1b85e9c2 100644
--- a/target/sparc/insns.decode
+++ b/target/sparc/insns.decode
@@ -88,7 +88,7 @@ CALL 01 i:s30
{
[
- STBAR 10 00000 101000 01111 0 0000000000000
+ STBAR_v9 10 00000 101000 01111 0 0000000000000
MEMBAR 10 00000 101000 01111 1 000000 cmask:3 mmask:4
RDCCR 10 rd:5 101000 00010 0 0000000000000
@@ -107,6 +107,17 @@ CALL 01 i:s30
RDSTICK_CMPR 10 rd:5 101000 11001 0 0000000000000
RDSTRAND_STATUS 10 rd:5 101000 11010 0 0000000000000
]
+
+ # The v8 manual, section B.30 STBAR instruction, says
+ # bits [12:0] are ignored, but bit 13 must be 0.
+ # However, section B.28 Read State Register Instruction has a
+ # comment that RDASR with rs1 = 15, rd = 0 is STBAR. Here,
+ # bit 13 is also ignored and rd != 0 is merely reserved.
+ #
+ # Solaris 8 executes v9 MEMBAR instruction 0x8143e008 during boot.
+ # This confirms that bit 13 is ignored, as 0x8143c000 is STBAR.
+ STBAR_v8 10 ----- 101000 01111 - -------------
+
# Before v8, all rs1 accepted; otherwise rs1==0.
RDY 10 rd:5 101000 rs1:5 0 0000000000000
}
diff --git a/target/sparc/translate.c b/target/sparc/translate.c
index ddc4154ee3..53183dc609 100644
--- a/target/sparc/translate.c
+++ b/target/sparc/translate.c
@@ -2824,12 +2824,15 @@ static bool trans_Tcc_i_v9(DisasContext *dc, arg_Tcc_i_v9 *a)
return do_tcc(dc, a->cond, a->cc, a->rs1, true, a->i);
}
-static bool trans_STBAR(DisasContext *dc, arg_STBAR *a)
+static bool do_stbar(DisasContext *dc)
{
tcg_gen_mb(TCG_MO_ST_ST | TCG_BAR_SC);
return advance_pc(dc);
}
+TRANS(STBAR_v8, 32, do_stbar)
+TRANS(STBAR_v9, 64, do_stbar)
+
static bool trans_MEMBAR(DisasContext *dc, arg_MEMBAR *a)
{
if (avail_32(dc)) {
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 27/38] target/sparc: Loosen decode of RDY for v7
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (25 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 26/38] target/sparc: Loosen decode of STBAR for v8 Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 28/38] target/sparc: Loosen decode of RDPSR " Michael Tokarev
` (10 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Richard Henderson, Mark Cave-Ayland, Michael Tokarev
From: Richard Henderson <richard.henderson@linaro.org>
Bits [18:0] are not decoded with v7, and for v8 unused values
of rs1 simply produce undefined results.
Fixes: af25071c1d ("target/sparc: Move RDASR, STBAR, MEMBAR to decodetree")
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Tested-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
(cherry picked from commit 49d669ccf33a772e3baf3fe4ebb996dc015f46c1)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/target/sparc/insns.decode b/target/sparc/insns.decode
index 1b1b85e9c2..74848996ae 100644
--- a/target/sparc/insns.decode
+++ b/target/sparc/insns.decode
@@ -91,6 +91,7 @@ CALL 01 i:s30
STBAR_v9 10 00000 101000 01111 0 0000000000000
MEMBAR 10 00000 101000 01111 1 000000 cmask:3 mmask:4
+ RDY_v9 10 rd:5 101000 00000 0 0000000000000
RDCCR 10 rd:5 101000 00010 0 0000000000000
RDASI 10 rd:5 101000 00011 0 0000000000000
RDTICK 10 rd:5 101000 00100 0 0000000000000
@@ -118,8 +119,15 @@ CALL 01 i:s30
# This confirms that bit 13 is ignored, as 0x8143c000 is STBAR.
STBAR_v8 10 ----- 101000 01111 - -------------
- # Before v8, all rs1 accepted; otherwise rs1==0.
- RDY 10 rd:5 101000 rs1:5 0 0000000000000
+ # For v7, bits [18:0] are ignored.
+ # For v8, bits [18:14], aka rs1, are repurposed and rs1 = 0 is RDY,
+ # and other values are RDASR. However, the v8 manual explicitly
+ # says that rs1 in 1..14 yield undefined results and do not cause
+ # an illegal instruction trap, and rs1 in 16..31 are available for
+ # implementation specific usage.
+ # Implement not causing an illegal instruction trap for v8 by
+ # continuing to interpret unused values per v7, i.e. as RDY.
+ RDY_v7 10 rd:5 101000 ----- - -------------
}
{
diff --git a/target/sparc/translate.c b/target/sparc/translate.c
index 53183dc609..b54285e491 100644
--- a/target/sparc/translate.c
+++ b/target/sparc/translate.c
@@ -2864,18 +2864,8 @@ static TCGv do_rdy(DisasContext *dc, TCGv dst)
return cpu_y;
}
-static bool trans_RDY(DisasContext *dc, arg_RDY *a)
-{
- /*
- * TODO: Need a feature bit for sparcv8. In the meantime, treat all
- * 32-bit cpus like sparcv7, which ignores the rs1 field.
- * This matches after all other ASR, so Leon3 Asr17 is handled first.
- */
- if (avail_64(dc) && a->rs1 != 0) {
- return false;
- }
- return do_rd_special(dc, true, a->rd, do_rdy);
-}
+TRANS(RDY_v7, 32, do_rd_special, true, a->rd, do_rdy)
+TRANS(RDY_v9, 64, do_rd_special, true, a->rd, do_rdy)
static TCGv do_rd_leon3_config(DisasContext *dc, TCGv dst)
{
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 28/38] target/sparc: Loosen decode of RDPSR for v7
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (26 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 27/38] target/sparc: Loosen decode of RDY for v7 Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 29/38] target/sparc: Loosen decode of RDWIM " Michael Tokarev
` (9 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Richard Henderson, Mark Cave-Ayland, Michael Tokarev
From: Richard Henderson <richard.henderson@linaro.org>
For v7, bits [18:0] are ignored.
For v8, bits [18:14] are reserved and bits [13:0] are ignored.
Fixes: 668bb9b755e ("target/sparc: Move RDPSR, RDHPR to decodetree")
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
(cherry picked from commit a0345f628394fbd001276c80fd02c8ad0d1b7ee2)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/target/sparc/insns.decode b/target/sparc/insns.decode
index 74848996ae..1c6403ad8a 100644
--- a/target/sparc/insns.decode
+++ b/target/sparc/insns.decode
@@ -158,14 +158,16 @@ CALL 01 i:s30
}
{
- RDPSR 10 rd:5 101001 00000 0 0000000000000
- RDHPR_hpstate 10 rd:5 101001 00000 0 0000000000000
+ [
+ RDHPR_hpstate 10 rd:5 101001 00000 0 0000000000000
+ RDHPR_htstate 10 rd:5 101001 00001 0 0000000000000
+ RDHPR_hintp 10 rd:5 101001 00011 0 0000000000000
+ RDHPR_htba 10 rd:5 101001 00101 0 0000000000000
+ RDHPR_hver 10 rd:5 101001 00110 0 0000000000000
+ RDHPR_hstick_cmpr 10 rd:5 101001 11111 0 0000000000000
+ ]
+ RDPSR 10 rd:5 101001 ----- - -------------
}
-RDHPR_htstate 10 rd:5 101001 00001 0 0000000000000
-RDHPR_hintp 10 rd:5 101001 00011 0 0000000000000
-RDHPR_htba 10 rd:5 101001 00101 0 0000000000000
-RDHPR_hver 10 rd:5 101001 00110 0 0000000000000
-RDHPR_hstick_cmpr 10 rd:5 101001 11111 0 0000000000000
{
WRPSR 10 00000 110001 ..... . ............. @n_r_ri
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 29/38] target/sparc: Loosen decode of RDWIM for v7
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (27 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 28/38] target/sparc: Loosen decode of RDPSR " Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 30/38] target/sparc: Loosen decode of RDTBR " Michael Tokarev
` (8 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Richard Henderson, Mark Cave-Ayland, Michael Tokarev
From: Richard Henderson <richard.henderson@linaro.org>
For v7, bits [18:0] are ignored.
For v8, bits [18:14] are reserved and bits [13:0] are ignored.
Fixes: 5d617bfba07 ("target/sparc: Move RDWIM, RDPR to decodetree")
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
(cherry picked from commit dc9678cc9725d6c3053c6f110f162d956eb9d48f)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/target/sparc/insns.decode b/target/sparc/insns.decode
index 1c6403ad8a..77b2f54fdf 100644
--- a/target/sparc/insns.decode
+++ b/target/sparc/insns.decode
@@ -180,26 +180,28 @@ RESTORED 10 00001 110001 00000 0 0000000000000
# UA2005 INVALW
{
- RDWIM 10 rd:5 101010 00000 0 0000000000000
- RDPR_tpc 10 rd:5 101010 00000 0 0000000000000
+ [
+ RDPR_tpc 10 rd:5 101010 00000 0 0000000000000
+ RDPR_tnpc 10 rd:5 101010 00001 0 0000000000000
+ RDPR_tstate 10 rd:5 101010 00010 0 0000000000000
+ RDPR_tt 10 rd:5 101010 00011 0 0000000000000
+ RDPR_tick 10 rd:5 101010 00100 0 0000000000000
+ RDPR_tba 10 rd:5 101010 00101 0 0000000000000
+ RDPR_pstate 10 rd:5 101010 00110 0 0000000000000
+ RDPR_tl 10 rd:5 101010 00111 0 0000000000000
+ RDPR_pil 10 rd:5 101010 01000 0 0000000000000
+ RDPR_cwp 10 rd:5 101010 01001 0 0000000000000
+ RDPR_cansave 10 rd:5 101010 01010 0 0000000000000
+ RDPR_canrestore 10 rd:5 101010 01011 0 0000000000000
+ RDPR_cleanwin 10 rd:5 101010 01100 0 0000000000000
+ RDPR_otherwin 10 rd:5 101010 01101 0 0000000000000
+ RDPR_wstate 10 rd:5 101010 01110 0 0000000000000
+ RDPR_gl 10 rd:5 101010 10000 0 0000000000000
+ RDPR_strand_status 10 rd:5 101010 11010 0 0000000000000
+ RDPR_ver 10 rd:5 101010 11111 0 0000000000000
+ ]
+ RDWIM 10 rd:5 101010 ----- - -------------
}
-RDPR_tnpc 10 rd:5 101010 00001 0 0000000000000
-RDPR_tstate 10 rd:5 101010 00010 0 0000000000000
-RDPR_tt 10 rd:5 101010 00011 0 0000000000000
-RDPR_tick 10 rd:5 101010 00100 0 0000000000000
-RDPR_tba 10 rd:5 101010 00101 0 0000000000000
-RDPR_pstate 10 rd:5 101010 00110 0 0000000000000
-RDPR_tl 10 rd:5 101010 00111 0 0000000000000
-RDPR_pil 10 rd:5 101010 01000 0 0000000000000
-RDPR_cwp 10 rd:5 101010 01001 0 0000000000000
-RDPR_cansave 10 rd:5 101010 01010 0 0000000000000
-RDPR_canrestore 10 rd:5 101010 01011 0 0000000000000
-RDPR_cleanwin 10 rd:5 101010 01100 0 0000000000000
-RDPR_otherwin 10 rd:5 101010 01101 0 0000000000000
-RDPR_wstate 10 rd:5 101010 01110 0 0000000000000
-RDPR_gl 10 rd:5 101010 10000 0 0000000000000
-RDPR_strand_status 10 rd:5 101010 11010 0 0000000000000
-RDPR_ver 10 rd:5 101010 11111 0 0000000000000
{
WRWIM 10 00000 110010 ..... . ............. @n_r_ri
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 30/38] target/sparc: Loosen decode of RDTBR for v7
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (28 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 29/38] target/sparc: Loosen decode of RDWIM " Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 31/38] target/sparc: Relax decode of rs2_or_imm " Michael Tokarev
` (7 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Richard Henderson, Mark Cave-Ayland, Michael Tokarev
From: Richard Henderson <richard.henderson@linaro.org>
For v7, bits [18:0] are ignored.
For v8, bits [18:14] are reserved and bits [13:0] are ignored.
Fixes: e8325dc02d0 ("target/sparc: Move RDTBR, FLUSHW to decodetree")
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
(cherry picked from commit 6ff52f9dee064d3c2138426834320f5877863d9b)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/target/sparc/insns.decode b/target/sparc/insns.decode
index 77b2f54fdf..242ec42016 100644
--- a/target/sparc/insns.decode
+++ b/target/sparc/insns.decode
@@ -226,7 +226,7 @@ WRPR_strand_status 10 11010 110010 ..... . ............. @n_r_ri
{
FLUSHW 10 00000 101011 00000 0 0000000000000
- RDTBR 10 rd:5 101011 00000 0 0000000000000
+ RDTBR 10 rd:5 101011 ----- - -------------
}
{
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 31/38] target/sparc: Relax decode of rs2_or_imm for v7
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (29 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 30/38] target/sparc: Loosen decode of RDTBR " Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 32/38] hw/pci-host/dino: Don't call pci_register_root_bus() in init Michael Tokarev
` (6 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Richard Henderson, Mark Cave-Ayland, Michael Tokarev
From: Richard Henderson <richard.henderson@linaro.org>
For v7, bits [12:5] are ignored for !imm.
For v8, those same bits are reserved, but are not trapped.
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
(cherry picked from commit df663ac0a4e5d916b6b3e77552a925fec02bced4)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/target/sparc/translate.c b/target/sparc/translate.c
index b54285e491..45956673f7 100644
--- a/target/sparc/translate.c
+++ b/target/sparc/translate.c
@@ -2527,6 +2527,32 @@ static int extract_qfpreg(DisasContext *dc, int x)
# define avail_VIS4(C) false
#endif
+/*
+ * We decoded bit 13 as imm, and bits [12:0] as rs2_or_imm.
+ * For v9, if !imm, then the unused bits [12:5] must be zero.
+ * For v7 and v8, the unused bits are ignored; clear them here.
+ */
+static bool check_rs2(DisasContext *dc, int *rs2)
+{
+ if (unlikely(*rs2 & ~0x1f)) {
+ if (avail_64(dc)) {
+ return false;
+ }
+ *rs2 &= 0x1f;
+ }
+ return true;
+}
+
+static bool check_r_r_ri(DisasContext *dc, arg_r_r_ri *a)
+{
+ return a->imm || check_rs2(dc, &a->rs2_or_imm);
+}
+
+static bool check_r_r_ri_cc(DisasContext *dc, arg_r_r_ri_cc *a)
+{
+ return a->imm || check_rs2(dc, &a->rs2_or_imm);
+}
+
/* Default case for non jump instructions. */
static bool advance_pc(DisasContext *dc)
{
@@ -3250,8 +3276,7 @@ static bool do_wr_special(DisasContext *dc, arg_r_r_ri *a, bool priv,
{
TCGv src;
- /* For simplicity, we under-decoded the rs2 form. */
- if (!a->imm && (a->rs2_or_imm & ~0x1f)) {
+ if (!check_r_r_ri(dc, a)) {
return false;
}
if (!priv) {
@@ -3694,8 +3719,7 @@ static bool do_arith_int(DisasContext *dc, arg_r_r_ri_cc *a,
{
TCGv dst, src1;
- /* For simplicity, we under-decoded the rs2 form. */
- if (!a->imm && a->rs2_or_imm & ~0x1f) {
+ if (!check_r_r_ri_cc(dc, a)) {
return false;
}
@@ -3779,11 +3803,11 @@ static bool trans_OR(DisasContext *dc, arg_r_r_ri_cc *a)
{
/* OR with %g0 is the canonical alias for MOV. */
if (!a->cc && a->rs1 == 0) {
+ if (!check_r_r_ri_cc(dc, a)) {
+ return false;
+ }
if (a->imm || a->rs2_or_imm == 0) {
gen_store_gpr(dc, a->rd, tcg_constant_tl(a->rs2_or_imm));
- } else if (a->rs2_or_imm & ~0x1f) {
- /* For simplicity, we under-decoded the rs2 form. */
- return false;
} else {
gen_store_gpr(dc, a->rd, cpu_regs[a->rs2_or_imm]);
}
@@ -3800,8 +3824,7 @@ static bool trans_UDIV(DisasContext *dc, arg_r_r_ri *a)
if (!avail_DIV(dc)) {
return false;
}
- /* For simplicity, we under-decoded the rs2 form. */
- if (!a->imm && a->rs2_or_imm & ~0x1f) {
+ if (!check_r_r_ri(dc, a)) {
return false;
}
@@ -3852,8 +3875,7 @@ static bool trans_UDIVX(DisasContext *dc, arg_r_r_ri *a)
if (!avail_64(dc)) {
return false;
}
- /* For simplicity, we under-decoded the rs2 form. */
- if (!a->imm && a->rs2_or_imm & ~0x1f) {
+ if (!check_r_r_ri(dc, a)) {
return false;
}
@@ -3890,8 +3912,7 @@ static bool trans_SDIVX(DisasContext *dc, arg_r_r_ri *a)
if (!avail_64(dc)) {
return false;
}
- /* For simplicity, we under-decoded the rs2 form. */
- if (!a->imm && a->rs2_or_imm & ~0x1f) {
+ if (!check_r_r_ri(dc, a)) {
return false;
}
@@ -4187,8 +4208,7 @@ TRANS(SRA_i, ALL, do_shift_i, a, false, false)
static TCGv gen_rs2_or_imm(DisasContext *dc, bool imm, int rs2_or_imm)
{
- /* For simplicity, we under-decoded the rs2 form. */
- if (!imm && rs2_or_imm & ~0x1f) {
+ if (!imm && !check_rs2(dc, &rs2_or_imm)) {
return NULL;
}
if (imm || rs2_or_imm == 0) {
@@ -4251,8 +4271,7 @@ static bool do_add_special(DisasContext *dc, arg_r_r_ri *a,
{
TCGv src1, sum;
- /* For simplicity, we under-decoded the rs2 form. */
- if (!a->imm && a->rs2_or_imm & ~0x1f) {
+ if (!check_r_r_ri(dc, a)) {
return false;
}
@@ -4370,8 +4389,7 @@ static TCGv gen_ldst_addr(DisasContext *dc, int rs1, bool imm, int rs2_or_imm)
{
TCGv addr, tmp = NULL;
- /* For simplicity, we under-decoded the rs2 form. */
- if (!imm && rs2_or_imm & ~0x1f) {
+ if (!imm && !check_rs2(dc, &rs2_or_imm)) {
return NULL;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 32/38] hw/pci-host/dino: Don't call pci_register_root_bus() in init
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (30 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 31/38] target/sparc: Relax decode of rs2_or_imm " Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 33/38] hw/pci-host/astro: Don't call pci_regsiter_root_bus() " Michael Tokarev
` (5 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Peter Maydell, Alex Bennée, Richard Henderson,
Michael Tokarev
From: Peter Maydell <peter.maydell@linaro.org>
In the dino PCI host bridge device, we call pci_register_root_bus()
in the device's instance_init. This is a problem for two reasons
* the PCI bridge is then available to the rest of the simulation
(e.g. via pci_qdev_find_device()), even though it hasn't
yet been realized
* we do not attempt to unregister in an instance_deinit,
which means that if you go through an instance_init -> deinit
lifecycle the freed memory for the host-bridge device is
left on the pci_host_bridges list
ASAN reports the resulting use-after-free:
==1771223==ERROR: AddressSanitizer: heap-use-after-free on address 0x527000018f80 at pc 0x5b4b9d3369b5 bp 0x7ffd01929980 sp 0x7ffd01929978
WRITE of size 8 at 0x527000018f80 thread T0
#0 0x5b4b9d3369b4 in pci_host_bus_register /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../hw/pci/pci.c:608:5
#1 0x5b4b9d321566 in pci_root_bus_internal_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../hw/pci/pci.c:677:5
#2 0x5b4b9d3215e0 in pci_root_bus_new /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../hw/pci/pci.c:706:5
#3 0x5b4b9d321fe5 in pci_register_root_bus /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../hw/pci/pci.c:751:11
#4 0x5b4b9d390521 in dino_pcihost_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../hw/pci-host/dino.c:473:16
0x527000018f80 is located 1664 bytes inside of 12384-byte region [0x527000018900,0x52700001b960)
freed by thread T0 here:
#0 0x5b4b9cab185a in free (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/qemu-system-hppa+0x17ad85a) (BuildId: ca496bb2e4fc750ebd289b448bad8d99c0ecd140)
#1 0x5b4b9e3ee723 in object_finalize /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../qom/object.c:734:9
#2 0x5b4b9e3e69db in object_unref /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../qom/object.c:1232:9
#3 0x5b4b9ea6173c in qmp_device_list_properties /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../qom/qom-qmp-cmds.c:237:5
#4 0x5b4b9ec4e0f3 in qmp_marshal_device_list_properties /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/qapi/qapi-commands-qdev.c:65:14
previously allocated by thread T0 here:
#0 0x5b4b9cab1af3 in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/qemu-system-hppa+0x17adaf3) (BuildId: ca496bb2e4fc750ebd289b448bad8d99c0ecd140)
#1 0x799d8270eb09 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x62b09) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75)
#2 0x5b4b9e3e75fc in object_new_with_type /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../qom/object.c:767:15
#3 0x5b4b9e3e7409 in object_new_with_class /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../qom/object.c:782:12
#4 0x5b4b9ea609a5 in qmp_device_list_properties /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../qom/qom-qmp-cmds.c:206:11
where we allocated one instance of the dino device, put it on the
list, freed it, and then trying to allocate a second instance touches
the freed memory on the pci_host_bridges list.
Fix this by deferring all the setup of memory regions and registering
the PCI bridge to the device's realize method. This brings it into
line with almost all other PCI host bridges, which call
pci_register_root_bus() in realize.
Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3118
Fixes: 63901b6cc4d8b4 ("dino: move PCI bus initialisation to dino_pcihost_init()")
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Tested-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20250918114259.1802337-2-peter.maydell@linaro.org>
(cherry picked from commit e4a1b308b27cd77338b8f05d3a31e6b38eb717c7)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/hw/pci-host/dino.c b/hw/pci-host/dino.c
index 58fdbf7bc9..36e3791424 100644
--- a/hw/pci-host/dino.c
+++ b/hw/pci-host/dino.c
@@ -413,43 +413,7 @@ static void dino_pcihost_reset(DeviceState *dev)
static void dino_pcihost_realize(DeviceState *dev, Error **errp)
{
DinoState *s = DINO_PCI_HOST_BRIDGE(dev);
-
- /* Set up PCI view of memory: Bus master address space. */
- memory_region_init(&s->bm, OBJECT(s), "bm-dino", 4 * GiB);
- memory_region_init_alias(&s->bm_ram_alias, OBJECT(s),
- "bm-system", s->memory_as, 0,
- 0xf0000000 + DINO_MEM_CHUNK_SIZE);
- memory_region_init_alias(&s->bm_pci_alias, OBJECT(s),
- "bm-pci", &s->pci_mem,
- 0xf0000000 + DINO_MEM_CHUNK_SIZE,
- 30 * DINO_MEM_CHUNK_SIZE);
- memory_region_init_alias(&s->bm_cpu_alias, OBJECT(s),
- "bm-cpu", s->memory_as, 0xfff00000,
- 0xfffff);
- memory_region_add_subregion(&s->bm, 0,
- &s->bm_ram_alias);
- memory_region_add_subregion(&s->bm,
- 0xf0000000 + DINO_MEM_CHUNK_SIZE,
- &s->bm_pci_alias);
- memory_region_add_subregion(&s->bm, 0xfff00000,
- &s->bm_cpu_alias);
-
- address_space_init(&s->bm_as, &s->bm, "pci-bm");
-}
-
-static void dino_pcihost_unrealize(DeviceState *dev)
-{
- DinoState *s = DINO_PCI_HOST_BRIDGE(dev);
-
- address_space_destroy(&s->bm_as);
-}
-
-static void dino_pcihost_init(Object *obj)
-{
- DinoState *s = DINO_PCI_HOST_BRIDGE(obj);
- PCIHostState *phb = PCI_HOST_BRIDGE(obj);
- SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
- int i;
+ PCIHostState *phb = PCI_HOST_BRIDGE(dev);
/* Dino PCI access from main memory. */
memory_region_init_io(&s->this_mem, OBJECT(s), &dino_chip_ops,
@@ -476,7 +440,7 @@ static void dino_pcihost_init(Object *obj)
PCI_DEVFN(0, 0), 32, TYPE_PCI_BUS);
/* Set up windows into PCI bus memory. */
- for (i = 1; i < 31; i++) {
+ for (int i = 1; i < 31; i++) {
uint32_t addr = 0xf0000000 + i * DINO_MEM_CHUNK_SIZE;
char *name = g_strdup_printf("PCI Outbound Window %d", i);
memory_region_init_alias(&s->pci_mem_alias[i], OBJECT(s),
@@ -487,9 +451,38 @@ static void dino_pcihost_init(Object *obj)
pci_setup_iommu(phb->bus, &dino_iommu_ops, s);
- sysbus_init_mmio(sbd, &s->this_mem);
+ sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->this_mem);
- qdev_init_gpio_in(DEVICE(obj), dino_set_irq, DINO_IRQS);
+ qdev_init_gpio_in(dev, dino_set_irq, DINO_IRQS);
+
+ /* Set up PCI view of memory: Bus master address space. */
+ memory_region_init(&s->bm, OBJECT(s), "bm-dino", 4 * GiB);
+ memory_region_init_alias(&s->bm_ram_alias, OBJECT(s),
+ "bm-system", s->memory_as, 0,
+ 0xf0000000 + DINO_MEM_CHUNK_SIZE);
+ memory_region_init_alias(&s->bm_pci_alias, OBJECT(s),
+ "bm-pci", &s->pci_mem,
+ 0xf0000000 + DINO_MEM_CHUNK_SIZE,
+ 30 * DINO_MEM_CHUNK_SIZE);
+ memory_region_init_alias(&s->bm_cpu_alias, OBJECT(s),
+ "bm-cpu", s->memory_as, 0xfff00000,
+ 0xfffff);
+ memory_region_add_subregion(&s->bm, 0,
+ &s->bm_ram_alias);
+ memory_region_add_subregion(&s->bm,
+ 0xf0000000 + DINO_MEM_CHUNK_SIZE,
+ &s->bm_pci_alias);
+ memory_region_add_subregion(&s->bm, 0xfff00000,
+ &s->bm_cpu_alias);
+
+ address_space_init(&s->bm_as, &s->bm, "pci-bm");
+}
+
+static void dino_pcihost_unrealize(DeviceState *dev)
+{
+ DinoState *s = DINO_PCI_HOST_BRIDGE(dev);
+
+ address_space_destroy(&s->bm_as);
}
static const Property dino_pcihost_properties[] = {
@@ -511,7 +504,6 @@ static void dino_pcihost_class_init(ObjectClass *klass, void *data)
static const TypeInfo dino_pcihost_info = {
.name = TYPE_DINO_PCI_HOST_BRIDGE,
.parent = TYPE_PCI_HOST_BRIDGE,
- .instance_init = dino_pcihost_init,
.instance_size = sizeof(DinoState),
.class_init = dino_pcihost_class_init,
};
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 33/38] hw/pci-host/astro: Don't call pci_regsiter_root_bus() in init
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (31 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 32/38] hw/pci-host/dino: Don't call pci_register_root_bus() in init Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 34/38] tcg/optimize: Fix folding of vector bitsel Michael Tokarev
` (4 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Peter Maydell, Alex Bennée, Richard Henderson,
Michael Tokarev
From: Peter Maydell <peter.maydell@linaro.org>
In the astro PCI host bridge device, we call pci_register_root_bus()
in the device's instance_init. This is a problem for two reasons
* the PCI bridge is then available to the rest of the simulation
(e.g. via pci_qdev_find_device()), even though it hasn't
yet been realized
* we do not attempt to unregister in an instance_deinit,
which means that if you go through an instance_init -> deinit
lifecycle the freed memory for the host-bridge device is
left on the pci_host_bridges list
ASAN reports the resulting use-after-free:
==1776584==ERROR: AddressSanitizer: heap-use-after-free on address 0x51f00000cb00 at pc 0x5b2d460a89b5 bp 0x7ffef7617f50 sp 0x7ffef7617f48
WRITE of size 8 at 0x51f00000cb00 thread T0
#0 0x5b2d460a89b4 in pci_host_bus_register /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../hw/pci/pci.c:608:5
#1 0x5b2d46093566 in pci_root_bus_internal_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../hw/pci/pci.c:677:5
#2 0x5b2d460935e0 in pci_root_bus_new /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../hw/pci/pci.c:706:5
#3 0x5b2d46093fe5 in pci_register_root_bus /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../hw/pci/pci.c:751:11
#4 0x5b2d46fe2335 in elroy_pcihost_init /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../hw/pci-host/astro.c:455:16
0x51f00000cb00 is located 1664 bytes inside of 3456-byte region [0x51f00000c480,0x51f00000d200)
freed by thread T0 here:
#0 0x5b2d4582385a in free (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/qemu-system-hppa+0x17ad85a) (BuildId: 692b49eedc6fb0ef618bbb6784a09311b3b7f1e8)
#1 0x5b2d47160723 in object_finalize /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../qom/object.c:734:9
#2 0x5b2d471589db in object_unref /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../qom/object.c:1232:9
#3 0x5b2d477d373c in qmp_device_list_properties /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../qom/qom-qmp-cmds.c:237:5
previously allocated by thread T0 here:
#0 0x5b2d45823af3 in malloc (/mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/qemu-system-hppa+0x17adaf3) (BuildId: 692b49eedc6fb0ef618bbb6784a09311b3b7f1e8)
#1 0x79728fa08b09 in g_malloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x62b09) (BuildId: 1eb6131419edb83b2178b682829a6913cf682d75)
#2 0x5b2d471595fc in object_new_with_type /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../qom/object.c:767:15
#3 0x5b2d47159409 in object_new_with_class /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../qom/object.c:782:12
#4 0x5b2d477d29a5 in qmp_device_list_properties /mnt/nvmedisk/linaro/qemu-from-laptop/qemu/build/hppa-asan/../../qom/qom-qmp-cmds.c:206:11
Cc: qemu-stable@nongnu.org
Fixes: e029bb00a79be ("hw/pci-host: Add Astro system bus adapter found on PA-RISC machines")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3118
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Tested-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20250918114259.1802337-3-peter.maydell@linaro.org>
(cherry picked from commit 76d2b8d42adb0db2d1ccd08a626f25ddd30208a8)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/hw/pci-host/astro.c b/hw/pci-host/astro.c
index 039cc3ad01..a2565c3ec4 100644
--- a/hw/pci-host/astro.c
+++ b/hw/pci-host/astro.c
@@ -423,22 +423,23 @@ static void elroy_reset(DeviceState *dev)
}
}
-static void elroy_pcihost_init(Object *obj)
+static void elroy_pcihost_realize(DeviceState *dev, Error **errp)
{
- ElroyState *s = ELROY_PCI_HOST_BRIDGE(obj);
- PCIHostState *phb = PCI_HOST_BRIDGE(obj);
- SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
+ ElroyState *s = ELROY_PCI_HOST_BRIDGE(dev);
+ PCIHostState *phb = PCI_HOST_BRIDGE(dev);
+ SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+ Object *obj = OBJECT(s);
/* Elroy config access from CPU. */
- memory_region_init_io(&s->this_mem, OBJECT(s), &elroy_chip_ops,
+ memory_region_init_io(&s->this_mem, obj, &elroy_chip_ops,
s, "elroy", 0x2000);
/* Elroy PCI config. */
- memory_region_init_io(&phb->conf_mem, OBJECT(phb),
- &elroy_config_addr_ops, DEVICE(s),
+ memory_region_init_io(&phb->conf_mem, obj,
+ &elroy_config_addr_ops, dev,
"pci-conf-idx", 8);
- memory_region_init_io(&phb->data_mem, OBJECT(phb),
- &elroy_config_data_ops, DEVICE(s),
+ memory_region_init_io(&phb->data_mem, obj,
+ &elroy_config_data_ops, dev,
"pci-conf-data", 8);
memory_region_add_subregion(&s->this_mem, 0x40,
&phb->conf_mem);
@@ -446,8 +447,8 @@ static void elroy_pcihost_init(Object *obj)
&phb->data_mem);
/* Elroy PCI bus memory. */
- memory_region_init(&s->pci_mmio, OBJECT(s), "pci-mmio", UINT64_MAX);
- memory_region_init_io(&s->pci_io, OBJECT(s), &unassigned_io_ops, obj,
+ memory_region_init(&s->pci_mmio, obj, "pci-mmio", UINT64_MAX);
+ memory_region_init_io(&s->pci_io, obj, &unassigned_io_ops, obj,
"pci-isa-mmio",
((uint32_t) IOS_DIST_BASE_SIZE) / ROPES_PER_IOC);
@@ -458,7 +459,7 @@ static void elroy_pcihost_init(Object *obj)
sysbus_init_mmio(sbd, &s->this_mem);
- qdev_init_gpio_in(DEVICE(obj), elroy_set_irq, ELROY_IRQS);
+ qdev_init_gpio_in(dev, elroy_set_irq, ELROY_IRQS);
}
static const VMStateDescription vmstate_elroy = {
@@ -486,6 +487,7 @@ static void elroy_pcihost_class_init(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
device_class_set_legacy_reset(dc, elroy_reset);
+ dc->realize = elroy_pcihost_realize;
dc->vmsd = &vmstate_elroy;
dc->user_creatable = false;
}
@@ -493,7 +495,6 @@ static void elroy_pcihost_class_init(ObjectClass *klass, void *data)
static const TypeInfo elroy_pcihost_info = {
.name = TYPE_ELROY_PCI_HOST_BRIDGE,
.parent = TYPE_PCI_HOST_BRIDGE,
- .instance_init = elroy_pcihost_init,
.instance_size = sizeof(ElroyState),
.class_init = elroy_pcihost_class_init,
};
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 34/38] tcg/optimize: Fix folding of vector bitsel
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (32 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 33/38] hw/pci-host/astro: Don't call pci_regsiter_root_bus() " Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 35/38] .gitlab-ci.d/buildtest.yml: Unset CI_COMMIT_DESCRIPTION for htags Michael Tokarev
` (3 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-stable, WANG Rui, Richard Henderson, Michael Tokarev
From: WANG Rui <wangrui@loongson.cn>
It looks like a typo. When the false value (C) is the constant -1, the
correct fold should be: R = B | ~A
Reproducer (LoongArch64 assembly):
.text
.globl _start
_start:
vldi $vr1, 3073
vldi $vr2, 1023
vbitsel.v $vr0, $vr2, $vr1, $vr2
vpickve2gr.d $a1, $vr0, 1
xori $a0, $a1, 1
li.w $a7, 93
syscall 0
Fixes: e58b977238e3 ("tcg/optimize: Optimize bitsel_vec")
Link: https://github.com/llvm/llvm-project/issues/159610
Signed-off-by: WANG Rui <wangrui@loongson.cn>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20250919124901.2756538-1-wangrui@loongson.cn>
(cherry picked from commit a50347a4145faf6d409afd4b9b682c8b3e60854a)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/tcg/optimize.c b/tcg/optimize.c
index f922f86a1d..3ecc3fb5e3 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -1410,9 +1410,10 @@ static bool fold_bitsel_vec(OptContext *ctx, TCGOp *op)
return fold_and(ctx, op);
}
if (fv == -1 && TCG_TARGET_HAS_orc_vec) {
+ TCGArg ta = op->args[2];
op->opc = INDEX_op_orc_vec;
op->args[2] = op->args[1];
- op->args[1] = op->args[3];
+ op->args[1] = ta;
return fold_orc(ctx, op);
}
}
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 35/38] .gitlab-ci.d/buildtest.yml: Unset CI_COMMIT_DESCRIPTION for htags
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (33 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 34/38] tcg/optimize: Fix folding of vector bitsel Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 36/38] tests: Fix "make check-functional" for targets without thorough tests Michael Tokarev
` (2 subsequent siblings)
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Peter Maydell, Alex Bennée,
Daniel P. Berrangé, Thomas Huth, Michael Tokarev
From: Peter Maydell <peter.maydell@linaro.org>
In commit 52a21689cd829 we added a workaround for a bug in older
versions of htags where they fail with a weird error message if the
environment is too large. However, we missed one variable which
gitlab CI can set to the body of the commit message:
CI_COMMIT_DESCRIPTION.
Add this to the variables we unset when running htags, so that
the 'pages' job doesn't fail if the most recent commit happens
to have a very large commit message.
Cc: qemu-stable@nongnu.org
Fixes: 52a21689cd8 (".gitlab-ci.d/buildtest.yml: Work around htags bug when environment is large")
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-ID: <20250916163030.1467893-1-peter.maydell@linaro.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
(cherry picked from commit fd34f56fe886250bdd64f9c222c1cb4c07a594ad)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/.gitlab-ci.d/buildtest.yml b/.gitlab-ci.d/buildtest.yml
index 00f4bfcd9f..e22d407dbf 100644
--- a/.gitlab-ci.d/buildtest.yml
+++ b/.gitlab-ci.d/buildtest.yml
@@ -751,7 +751,7 @@ pages:
- make gtags
# We unset variables to work around a bug in some htags versions
# which causes it to fail when the environment is large
- - CI_COMMIT_MESSAGE= CI_COMMIT_TAG_MESSAGE= htags
+ - CI_COMMIT_MESSAGE= CI_COMMIT_TAG_MESSAGE= CI_COMMIT_DESCRIPTION= htags
-anT --tree-view=filetree -m qemu_init
-t "Welcome to the QEMU sourcecode"
- mv HTML public/src
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 36/38] tests: Fix "make check-functional" for targets without thorough tests
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (34 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 35/38] .gitlab-ci.d/buildtest.yml: Unset CI_COMMIT_DESCRIPTION for htags Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 37/38] accel/tcg: Properly unlink a TB linked to itself Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 38/38] tests/tcg/multiarch: Add tb-link test Michael Tokarev
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-stable, Thomas Huth, Peter Maydell, Michael Tokarev
From: Thomas Huth <thuth@redhat.com>
If QEMU gets configured for a single target that does not have
any thorough functional tests, "make check-functional" currently
fails with the error message "No rule to make target 'check-func'".
This happens because "check-func" only gets defined for thorough
tests (quick ones get added to "check-func-quick" instead).
The same problem can happen with the quick tests for targets that
do not have any functional test at all. To fix it, simply make sure
that the targets are always available in the Makefile.
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Closes: https://gitlab.com/qemu-project/qemu/-/issues/3119
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-ID: <20250918125154.126072-1-thuth@redhat.com>
(cherry picked from commit 4f1ebc7712a7db61155080164f2169320d033559)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/tests/Makefile.include b/tests/Makefile.include
index 010369bd3a..9b7c410ff2 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -164,6 +164,9 @@ check-functional:
@$(NINJA) precache-functional
@QEMU_TEST_NO_DOWNLOAD=1 $(MAKE) SPEED=thorough check-func check-func-quick
+.PHONY: check-func check-func-quick
+check-func check-func-quick:
+
# Consolidated targets
.PHONY: check check-clean get-vm-images
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 37/38] accel/tcg: Properly unlink a TB linked to itself
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (35 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 36/38] tests: Fix "make check-functional" for targets without thorough tests Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
2025-09-26 12:45 ` [Stable-10.0.5 38/38] tests/tcg/multiarch: Add tb-link test Michael Tokarev
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Richard Henderson, 李威威,
Anton Johansson, Michael Tokarev
From: Richard Henderson <richard.henderson@linaro.org>
When we remove dest from orig's links, we lose the link
that we rely on later to reset links. This can lead to
failure to release from spinlock with self-modifying code.
Cc: qemu-stable@nongnu.org
Reported-by: 李威威 <liweiwei@kubuds.cn>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Anton Johansson <anjo@rev.ng>
Tested-by: Anton Johansson <anjo@rev.ng>
(cherry picked from commit 03fe6659803f83690b8587d01f8ee56bb4be4b90)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c
index 3f1bebf6ab..ab51a555a9 100644
--- a/accel/tcg/tb-maint.c
+++ b/accel/tcg/tb-maint.c
@@ -839,6 +839,14 @@ static inline void tb_remove_from_jmp_list(TranslationBlock *orig, int n_orig)
* We first acquired the lock, and since the destination pointer matches,
* we know for sure that @orig is in the jmp list.
*/
+ if (dest == orig) {
+ /*
+ * In the case of a TB that links to itself, removing the entry
+ * from the list means that it won't be present later during
+ * tb_jmp_unlink -- unlink now.
+ */
+ tb_reset_jump(orig, n_orig);
+ }
pprev = &dest->jmp_list_head;
TB_FOR_EACH_JMP(dest, tb, n) {
if (tb == orig && n == n_orig) {
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread* [Stable-10.0.5 38/38] tests/tcg/multiarch: Add tb-link test
2025-09-26 12:45 [Stable-10.0.5 00/38] Patch Round-up for stable 10.0.5, freeze on 2025-10-06 Michael Tokarev
` (36 preceding siblings ...)
2025-09-26 12:45 ` [Stable-10.0.5 37/38] accel/tcg: Properly unlink a TB linked to itself Michael Tokarev
@ 2025-09-26 12:45 ` Michael Tokarev
37 siblings, 0 replies; 39+ messages in thread
From: Michael Tokarev @ 2025-09-26 12:45 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-stable, Richard Henderson, Michael Tokarev
From: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
(cherry picked from commit e13e1195db8af18e149065a59351ea85215645bb)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Makefile.target
index 45c9cfe18c..cfecf65c2d 100644
--- a/tests/tcg/multiarch/Makefile.target
+++ b/tests/tcg/multiarch/Makefile.target
@@ -45,6 +45,8 @@ vma-pthread: LDFLAGS+=-pthread
sigreturn-sigmask: CFLAGS+=-pthread
sigreturn-sigmask: LDFLAGS+=-pthread
+tb-link: LDFLAGS+=-lpthread
+
# GCC versions 12/13/14/15 at least incorrectly complain about
# "'SHA1Transform' reading 64 bytes from a region of size 0"; see the gcc bug
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106709
diff --git a/tests/tcg/multiarch/tb-link.c b/tests/tcg/multiarch/tb-link.c
new file mode 100644
index 0000000000..4e40306fa1
--- /dev/null
+++ b/tests/tcg/multiarch/tb-link.c
@@ -0,0 +1,67 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Verify that a single TB spin-loop is properly invalidated,
+ * releasing the thread from the spin-loop.
+ */
+
+#include <assert.h>
+#include <sys/mman.h>
+#include <pthread.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <sched.h>
+
+
+#ifdef __x86_64__
+#define READY 0x000047c6 /* movb $0,0(%rdi) */
+#define LOOP 0xfceb9090 /* 1: nop*2; jmp 1b */
+#define RETURN 0x909090c3 /* ret; nop*3 */
+#define NOP 0x90909090 /* nop*4 */
+#elif defined(__aarch64__)
+#define READY 0x3900001f /* strb wzr,[x0] */
+#define LOOP 0x14000000 /* b . */
+#define RETURN 0xd65f03c0 /* ret */
+#define NOP 0xd503201f /* nop */
+#elif defined(__riscv)
+#define READY 0x00050023 /* sb zero, (a0) */
+#define LOOP 0x0000006f /* jal zero, #0 */
+#define RETURN 0x00008067 /* jalr zero, ra, 0 */
+#define NOP 0x00000013 /* nop */
+#endif
+
+
+int main()
+{
+#ifdef READY
+ int tmp;
+ pthread_t thread_id;
+ bool hold = true;
+ uint32_t *buf;
+
+ buf = mmap(NULL, 3 * sizeof(uint32_t),
+ PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ assert(buf != MAP_FAILED);
+
+ buf[0] = READY;
+ buf[1] = LOOP;
+ buf[2] = RETURN;
+
+ alarm(2);
+
+ tmp = pthread_create(&thread_id, NULL, (void *(*)(void *))buf, &hold);
+ assert(tmp == 0);
+
+ while (hold) {
+ sched_yield();
+ }
+
+ buf[1] = NOP;
+ __builtin___clear_cache(&buf[1], &buf[2]);
+
+ tmp = pthread_join(thread_id, NULL);
+ assert(tmp == 0);
+#endif
+ return 0;
+}
--
2.47.3
^ permalink raw reply related [flat|nested] 39+ messages in thread