Skip to contentSkip to conversation

tcg/mips stable patches

PATCH In review Richard Henderson 2 participants 4 messages Jul 29 – Jul 31

lore
Share & tools
lore
#0 lore raw

cover tcg/mips stable patches

Supercedes: [email protected] ("[RFC PATCH 11.0 0/2] tcg/mips64: Fix shifts and unaligned loads - [DORA-B]")

Hi Quentin, thanks for these. Note that I cannot even compile test mips64 anymore because Debian buster was the last os release, and buster has package versions too old for qemu.

I've fixed up the html damage from your mailer, reviewed the changes, and have changed the second patch to fix the address inside the called function. If one wanted to backport the fix all the way to qemu v8, one would have to apply your patch in two locations for mips32.

Michael, the first patch applies cleanly from stable-10.1, and the second applies from stable-10.0.

r~

Quintin Kong (2):
tcg/mips64: Fix variable shift operand order tcg/mips64: Preserve the base of unaligned loads

 tcg/mips/tcg-target.c.inc | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 tcg/mips64: Fix variable shift operand order

From: Quintin Kong <[email protected]>

TCGOutOpBinary passes (output, value, count), but MIPS variable shift instructions encode (rd, rt, rs), where rt is the value and rs is the count. tcg_out_opc_reg() takes its register fields in (rd, rs, rt) order, so passing (a0, a1, a2) encodes the value as the count and the count as the value.

Swap a1 and a2 at the four variable shift emitters. This covers the I32 and I64 forms of SHL, SHR, SAR, and ROTR.

Fixes 03568c0d5395 ("tcg: Convert rotl, rotr to TCGOutOpBinary")
Fixes b5aafbaa8346 ("tcg: Convert sar to TCGOutOpBinary")
Fixes 27d21ee7c791 ("tcg: Convert shl to TCGOutOpBinary")
Fixes edd6ba8a6bc8 ("tcg: Convert shr to TCGOutOpBinary")

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4103

Message-ID: <[email protected]>

---
 tcg/mips/tcg-target.c.inc | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tcg/mips/tcg-target.c.inc +4 -4
index 400eafbab4..29cf7fa0ab 100644
@@ -2049,7 +2049,7 @@ static void tgen_rotr(TCGContext *s, TCGType type,
                      TCGReg a0, TCGReg a1, TCGReg a2)
 {
     MIPSInsn insn = type == TCG_TYPE_I32 ? OPC_ROTRV : OPC_DROTRV;
-    tcg_out_opc_reg(s, insn, a0, a1, a2);
+    tcg_out_opc_reg(s, insn, a0, a2, a1);
 }
 
 static void tgen_rotri(TCGContext *s, TCGType type,
@@ -2073,7 +2073,7 @@ static void tgen_sar(TCGContext *s, TCGType type,
                      TCGReg a0, TCGReg a1, TCGReg a2)
 {
     MIPSInsn insn = type == TCG_TYPE_I32 ? OPC_SRAV : OPC_DSRAV;
-    tcg_out_opc_reg(s, insn, a0, a1, a2);
+    tcg_out_opc_reg(s, insn, a0, a2, a1);
 }
 
 static void tgen_sari(TCGContext *s, TCGType type,
@@ -2096,7 +2096,7 @@ static void tgen_shl(TCGContext *s, TCGType type,
                      TCGReg a0, TCGReg a1, TCGReg a2)
 {
     MIPSInsn insn = type == TCG_TYPE_I32 ? OPC_SLLV : OPC_DSLLV;
-    tcg_out_opc_reg(s, insn, a0, a1, a2);
+    tcg_out_opc_reg(s, insn, a0, a2, a1);
 }
 
 static void tgen_shli(TCGContext *s, TCGType type,
@@ -2119,7 +2119,7 @@ static void tgen_shr(TCGContext *s, TCGType type,
                      TCGReg a0, TCGReg a1, TCGReg a2)
 {
     MIPSInsn insn = type == TCG_TYPE_I32 ? OPC_SRLV : OPC_DSRLV;
-    tcg_out_opc_reg(s, insn, a0, a1, a2);
+    tcg_out_opc_reg(s, insn, a0, a2, a1);
 }
 
 static void tgen_shri(TCGContext *s, TCGType type,
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/2 tcg/mips64: Preserve the base of unaligned loads

In reply to Richard Henderson

From: Quintin Kong <[email protected]>

The qemu_ld output constraint permits the output register to overlap a dead address input. That is valid for a direct load, but a pre-R6 MIPS host implements an unaligned 32-bit or 64-bit load with an LWR/LWL or LDR/LDL pair. Both instructions require the original base address.

If lo and base overlap, the first instruction replaces the base with part of the loaded value. The second instruction then accesses an unrelated address.

Prior to eb664d0c527, the address register was always a temporary, so this problem never occured. Copy an overlapping base to TCG_TMP0.

Fixes eb664d0c527 ("tcg/mips: Rationalize args to tcg_out_qemu_{ld,st}")

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4102

[rth: Move fixup into tcg_out_qemu_ld_unalign for qemu 10 series]

Message-ID: <[email protected]>

---
 tcg/mips/tcg-target.c.inc | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
tcg/mips/tcg-target.c.inc +11 -3
index 29cf7fa0ab..a683bff625 100644
@@ -1338,9 +1338,9 @@ static void tcg_out_qemu_ld_unalign(TCGContext *s, TCGReg lo, TCGReg hi,
     const MIPSInsn ld1 = HOST_BIG_ENDIAN ? OPC_LDL : OPC_LDR;
     const MIPSInsn ld2 = HOST_BIG_ENDIAN ? OPC_LDR : OPC_LDL;
     bool sgn = opc & MO_SIGN;
+    MemOp size = opc & MO_SIZE;
 
-    switch (opc & MO_SIZE) {
-    case MO_16:
+    if (size == MO_16) {
         if (HOST_BIG_ENDIAN) {
             tcg_out_opc_imm(s, sgn ? OPC_LB : OPC_LBU, TCG_TMP0, base, 0);
             tcg_out_opc_imm(s, OPC_LBU, lo, base, 1);
@@ -1360,8 +1360,16 @@ static void tcg_out_qemu_ld_unalign(TCGContext *s, TCGReg lo, TCGReg hi,
             tcg_out_opc_sa(s, OPC_SLL, TCG_TMP1, TCG_TMP1, 8);
             tcg_out_opc_reg(s, OPC_OR, lo, TCG_TMP0, TCG_TMP1);
         }
-        break;
+        return;
+    }
 
+    /* Both loads in the unaligned pair require the original base. */
+    if (lo == base) {
+        tcg_out_mov(s, TCG_TYPE_PTR, TCG_TMP0, base);
+        base = TCG_TMP0;
+    }
+
+    switch (size) {
     case MO_32:
         tcg_out_opc_imm(s, lw1, lo, base, 0);
         tcg_out_opc_imm(s, lw2, lo, base, 3);
Signature · 1 line
2.43.0
#3 lore raw
In reply to Richard Henderson

Hi Richard,

Thanks very much for clearing up the HTML damage from my mailer and for the review. I agree that fixing&nbsp;the&nbsp;address&nbsp;inside&nbsp;the&nbsp;called function could be better. Thanks again, and thanks Michael for taking these onto stable-10.0/10.1.

Best,
Quintin

原始邮件

发件人:Richard Henderson <[email protected]&gt;
发件时间:2026年7月29日 18:27
收件人:qemu-devel <[email protected]&gt;
抄送:mjt <[email protected]&gt;, 2358543632 <[email protected]&gt;, quintin.kong <[email protected]&gt; 主题:[PATCH 0/2] tcg/mips stable patches

       Supercedes:&nbsp;[email protected]

("[RFC&nbsp;PATCH&nbsp;11.0&nbsp;0/2]&nbsp;tcg/mips64:&nbsp;Fix&nbsp;shifts&nbsp;and&nbsp;unaligned&nbsp;loads&nbsp;-&nbsp;[DORA-B]")

Hi&nbsp;Quentin,&nbsp;thanks&nbsp;for&nbsp;these.&nbsp;&nbsp;Note&nbsp;that&nbsp;I&nbsp;cannot&nbsp;even&nbsp;compile&nbsp;test mips64&nbsp;anymore&nbsp;because&nbsp;Debian&nbsp;buster&nbsp;was&nbsp;the&nbsp;last&nbsp;os&nbsp;release,&nbsp;and buster&nbsp;has&nbsp;package&nbsp;versions&nbsp;too&nbsp;old&nbsp;for&nbsp;qemu.

I've&nbsp;fixed&nbsp;up&nbsp;the&nbsp;html&nbsp;damage&nbsp;from&nbsp;your&nbsp;mailer,&nbsp;reviewed&nbsp;the&nbsp;changes, and&nbsp;have&nbsp;changed&nbsp;the&nbsp;second&nbsp;patch&nbsp;to&nbsp;fix&nbsp;the&nbsp;address&nbsp;inside&nbsp;the&nbsp;called function.&nbsp;&nbsp;If&nbsp;one&nbsp;wanted&nbsp;to&nbsp;backport&nbsp;the&nbsp;fix&nbsp;all&nbsp;the&nbsp;way&nbsp;to&nbsp;qemu&nbsp;v8, one&nbsp;would&nbsp;have&nbsp;to&nbsp;apply&nbsp;your&nbsp;patch&nbsp;in&nbsp;two&nbsp;locations&nbsp;for&nbsp;mips32.

Michael,&nbsp;the&nbsp;first&nbsp;patch&nbsp;applies&nbsp;cleanly&nbsp;from&nbsp;stable-10.1,&nbsp;and&nbsp;the second&nbsp;applies&nbsp;from&nbsp;stable-10.0.

r~

Quintin&nbsp;Kong&nbsp;(2):
&nbsp;&nbsp;tcg/mips64:&nbsp;Fix&nbsp;variable&nbsp;shift&nbsp;operand&nbsp;order &nbsp;&nbsp;tcg/mips64:&nbsp;Preserve&nbsp;the&nbsp;base&nbsp;of&nbsp;unaligned&nbsp;loads

&nbsp;tcg/mips/tcg-target.c.inc&nbsp;|&nbsp;22&nbsp;+++++++++++++++------- &nbsp;1&nbsp;file&nbsp;changed,&nbsp;15&nbsp;insertions(+),&nbsp;7&nbsp;deletions(-)

--&nbsp;
2.43.0