Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: R2-on-R6 MULTU/MADDU/MSUBU emulation bugfix

MIPS instructions MULTU, MADDU and MSUBU emulation requires registers HI/LO
to be converted to signed 32bits before 64bit sign extension on MIPS64.

Bug was found on running MIPS32 R2 test application on MIPS64 R6 kernel.

Fixes: b0a668fb2038 ("MIPS: kernel: mips-r2-to-r6-emul: Add R2 emulator for MIPS R6")
Signed-off-by: Leonid Yegoshin <Leonid.Yegoshin@imgtec.com>
Reported-by: Nikola.Veljkovic@imgtec.com
Cc: paul.burton@imgtec.com
Cc: yamada.masahiro@socionext.com
Cc: akpm@linux-foundation.org
Cc: andrea.gelmini@gelma.net
Cc: macro@imgtec.com
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/14043/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

Leonid Yegoshin and committed by
Ralf Baechle
d65e5677 1d79bf0e

+6 -6
+6 -6
arch/mips/kernel/mips-r2-to-r6-emul.c
··· 433 433 rs = regs->regs[MIPSInst_RS(ir)]; 434 434 res = (u64)rt * (u64)rs; 435 435 rt = res; 436 - regs->lo = (s64)rt; 437 - regs->hi = (s64)(res >> 32); 436 + regs->lo = (s64)(s32)rt; 437 + regs->hi = (s64)(s32)(res >> 32); 438 438 439 439 MIPS_R2_STATS(muls); 440 440 ··· 670 670 res += ((((s64)rt) << 32) | (u32)rs); 671 671 672 672 rt = res; 673 - regs->lo = (s64)rt; 673 + regs->lo = (s64)(s32)rt; 674 674 rs = res >> 32; 675 - regs->hi = (s64)rs; 675 + regs->hi = (s64)(s32)rs; 676 676 677 677 MIPS_R2_STATS(dsps); 678 678 ··· 728 728 res = ((((s64)rt) << 32) | (u32)rs) - res; 729 729 730 730 rt = res; 731 - regs->lo = (s64)rt; 731 + regs->lo = (s64)(s32)rt; 732 732 rs = res >> 32; 733 - regs->hi = (s64)rs; 733 + regs->hi = (s64)(s32)rs; 734 734 735 735 MIPS_R2_STATS(dsps); 736 736