Re: [PATCH] MIPS: Make cpu_has_mips64r6 constant on 64-bit r6 kernels
From: Maciej W. Rozycki
Date: Mon Nov 23 2026 - 06:32:17 EST
On Mon, 23 Nov 2026, Tzu-Ching Yang wrote:
> > Umm, the wrong fix. You want __isa_ge_or_flag() instead, plus obviously
> > `cpu_has_64bits' is also needed (and __isa_ge_and_flag() can be discarded;
> > I guess it was meant to take care of what `cpu_has_64bits' does and broke
> > the whole idea by mistake).
>
> Your form and v1 differ only on pre-r6 kernels. I built both on
Then you're doing something wrong; with __isa_ge_or_flag() I get:
$ file vmlinux-*
vmlinux-base: ELF 64-bit LSB executable, MIPS, MIPS64 rel6 version 1 (SYSV), statically linked, BuildID[sha1]=10726d48319f6e095188c715586014d94687e241, with debug_info, not stripped
vmlinux-has-mips64r6: ELF 64-bit LSB executable, MIPS, MIPS64 rel6 version 1 (SYSV), statically linked, BuildID[sha1]=01be340ec78999c55ac60d8f51c0a4a5fdfcbb2e, with debug_info, not stripped
$ size --format=gnu vmlinux-*
text data bss total filename
11145180 3682690 301824 15129694 vmlinux-base
11072380 3686698 301824 15060902 vmlinux-has-mips64r6
$ objdump -d vmlinux-base | grep -c dclz
18
$ objdump -d vmlinux-has-mips64r6 | grep -c dclz
1430
$
(the former figure being nonzero is owing to the compiler being able to
produce DCLZ from RTL; the rest is our inline assembly stuff).
> > Your proposal precludes the use of R6 stuff
> > with pre-R6 compilations -- not sure if that makes sense, but let's stay
> > consistent with these macro definitions.
>
> In mainline cpu_has_mips64r6 is already 0 on pre-r6 kernels, and I do
> not think a pre-r6 kernel gets as far as cpu_probe() on an r6 CPU.
That's what we do for MIPS32r6 though, so doing the same for MIPS64r6
will be consistent.
> The comment above __isa_ge_and_ase() in cpu-features.h says that
> "a kernel built for an older ISA cannot run on a MIPSr6 CPU", and
> under QEMU -cpu I6400 (an r6 CPU) a 64-bit malta kernel built for r2
> takes a Reserved Instruction exception at the first jr in head.S.
Regrettable, but even more so __isa_ge_and_flag() doesn't make sense,
since ISA will always match FLAG at run time.
FWIW an early check for the ISA mismatch might be worth having if at all
feasible, reporting the issue via a firmware printf()-like callback where
available. Said JR instruction could be recoded as JALR $0, ... if this
turns out feasible. Not a requirement for your change of course.
> That leaves three ways, and I will send whichever you prefer as v2:
>
> 1. v1 with the unused __isa_ge_and_flag() removed, and in the same
> series a patch that defines cpu_has_mips32r6 as (MIPS_ISA_REV >= 6)
> to match, like cpu_has_mips_1 (MIPS_ISA_REV < 6) in that header.
> cpu_has_mips_r6 is then 0 on pre-r6 kernels and the code that it
> guards is dropped: in bloat-o-meter -t, -11524 bytes for
> 64r2el_defconfig and -11156 for 32r2el_defconfig with GCC 16.2,
> -18704 and -14140 with Clang 23, with no new W=1 warnings in these
> vmlinux builds. r6 kernels stay byte-identical to v1.
> 2. v1 with __isa_ge_and_flag() removed: pre-r6 kernels do not change.
> 3. Your form, with the sizes above.
I maintain that __isa_ge_or_flag() is the correct approach.
Maciej