sst-linux/arch/mips/math-emu
Mateusz Jończyk b0dd4a661c mips/math-emu: fix emulation of the prefx instruction
commit 42a39e4aa59a10aa4afdc14194f3ee63d2db94e1 upstream.

Currently, installation of Debian 12.8 for mipsel fails on machines
without an FPU [1]. This is caused by the fact that zstd (which is used
for initramfs compression) executes the prefx instruction, which is not
emulated properly by the kernel.

The prefx (Prefetch Indexed) instruction fetches data from memory into
the cache without any side effects. Though functionally unrelated, it
requires an FPU [2].

Bytecode format of this instruction ends on "001111" binary:

	(prefx instruction format) & 0x0000003f = 0x0000000f

The code in fpux_emu() runs like so:

	#define MIPSInst(x) x
	#define MIPSInst_FMA_FFMT(x) (MIPSInst(x) & 0x00000007)
	#define MIPSInst_FUNC(x) (MIPSInst(x) & 0x0000003f)
	enum cop1x_func { ..., pfetch_op = 0x0f, ... };

	...

	switch (MIPSInst_FMA_FFMT(ir)) {
	...

	case 0x3:
		if (MIPSInst_FUNC(ir) != pfetch_op)
			return SIGILL;

		/* ignore prefx operation */
		break;

	default:
		return SIGILL;
	}

That snippet above contains a logic error and the
	if (MIPSInst_FUNC(ir) != pfetch_op)
comparison always fires.

When MIPSInst_FUNC(ir) is equal to pfetch_op, ir must end on 001111
binary. In this case, MIPSInst_FMA_FFMT(ir) must be equal to 0x7, which
does not match that case label.

This causes emulation failure for the prefx instruction. Fix it.

This has been broken by
commit 919af8b96c ("MIPS: Make definitions of MIPSInst_FMA_{FUNC,FMTM} consistent with MIPS64 manual")
which modified the MIPSInst_FMA_FFMT macro without updating the users.

Signed-off-by: Mateusz Jończyk <mat.jonczyk@o2.pl>
Cc: stable@vger.kernel.org # after 3 weeks
Cc: Dengcheng Zhu <dzhu@wavecomp.com>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Ming Wang <wangming01@loongson.cn>
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
Fixes: 919af8b96c ("MIPS: Make definitions of MIPSInst_FMA_{FUNC,FMTM} consistent with MIPS64 manual")
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1091858
[2] MIPS Architecture For Programmers Volume II-A: The MIPS32 Instruction Set

Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
2025-02-21 13:49:44 +01:00
..
cp1emu.c mips/math-emu: fix emulation of the prefx instruction 2025-02-21 13:49:44 +01:00
dp_2008class.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 454 2019-06-19 17:09:09 +02:00
dp_add.c
dp_cmp.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 397 2019-06-05 17:37:12 +02:00
dp_div.c MIPS: Use fallthrough for arch/mips 2020-05-07 11:55:47 +02:00
dp_fint.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 397 2019-06-05 17:37:12 +02:00
dp_flong.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 397 2019-06-05 17:37:12 +02:00
dp_fmax.c MIPS: Use fallthrough for arch/mips 2020-05-07 11:55:47 +02:00
dp_fmin.c MIPS: Use fallthrough for arch/mips 2020-05-07 11:55:47 +02:00
dp_fsp.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 397 2019-06-05 17:37:12 +02:00
dp_maddf.c MIPS: Use fallthrough for arch/mips 2020-05-07 11:55:47 +02:00
dp_mul.c MIPS: Use fallthrough for arch/mips 2020-05-07 11:55:47 +02:00
dp_rint.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 309 2019-06-05 17:37:04 +02:00
dp_simple.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 397 2019-06-05 17:37:12 +02:00
dp_sqrt.c MIPS: Use fallthrough for arch/mips 2020-05-07 11:55:47 +02:00
dp_sub.c MIPS: Use fallthrough for arch/mips 2020-05-07 11:55:47 +02:00
dp_tint.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 397 2019-06-05 17:37:12 +02:00
dp_tlong.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 397 2019-06-05 17:37:12 +02:00
dsemul.c MIPS: math-emu: Use the bitmap API to allocate bitmaps 2022-07-11 10:27:50 +02:00
ieee754.c
ieee754.h
ieee754d.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 397 2019-06-05 17:37:12 +02:00
ieee754dp.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 397 2019-06-05 17:37:12 +02:00
ieee754dp.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 397 2019-06-05 17:37:12 +02:00
ieee754int.h MIPS: Add MAC2008 Support 2020-01-22 15:56:08 -08:00
ieee754sp.c
ieee754sp.h
Makefile
me-debugfs.c
sp_2008class.c
sp_add.c
sp_cmp.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 397 2019-06-05 17:37:12 +02:00
sp_div.c
sp_fdp.c
sp_fint.c
sp_flong.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 397 2019-06-05 17:37:12 +02:00
sp_fmax.c
sp_fmin.c
sp_maddf.c
sp_mul.c
sp_rint.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 309 2019-06-05 17:37:04 +02:00
sp_simple.c
sp_sqrt.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 397 2019-06-05 17:37:12 +02:00
sp_sub.c MIPS: Use fallthrough for arch/mips 2020-05-07 11:55:47 +02:00
sp_tint.c
sp_tlong.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 397 2019-06-05 17:37:12 +02:00