ClangBuiltLinux / linux

Linux kernel source tree
Other
241 stars 14 forks source link

error: instruction requires a CPU feature not currently enabled in arch/mips/include/asm/mipsregs.h #1532

Open nathanchance opened 2 years ago

nathanchance commented 2 years ago

Initially reported by @emojifreak in #1526.

# Disable CONFIG_MIPS32_O32 with menuconfig (https://github.com/ClangBuiltLinux/linux/issues/884)
$ make -skj"$(nproc)" ARCH=mips LLVM=1 distclean loongson3_defconfig menuconfig arch/mips/kvm/tlb.o
...
In file included from arch/mips/kvm/tlb.c:13:
In file included from ./include/linux/sched.h:12:
In file included from ./arch/mips/include/generated/asm/current.h:1:
In file included from ./include/asm-generic/current.h:5:
In file included from ./include/linux/thread_info.h:27:
In file included from ./include/linux/bitops.h:33:
In file included from ./arch/mips/include/asm/bitops.h:19:
In file included from ./arch/mips/include/asm/barrier.h:11:
In file included from ./arch/mips/include/asm/addrspace.h:13:
In file included from ./arch/mips/include/asm/mach-loongson64/spaces.h:16:
In file included from ./arch/mips/include/asm/mach-generic/spaces.h:15:
./arch/mips/include/asm/mipsregs.h:2832:3: error: instruction requires a CPU feature not currently enabled
                __tlbgp()
                ^
./arch/mips/include/asm/mipsregs.h:2106:19: note: expanded from macro '__tlbgp'
#define __tlbgp()       _ASM_SET_VIRT "tlbgp\n\t"
                        ^
./arch/mips/include/asm/mipsregs.h:2096:36: note: expanded from macro '_ASM_SET_VIRT'
#define _ASM_SET_VIRT ".set\tvirt\n\t"
                                   ^
<inline asm>:4:2: note: instantiated into assembly here
        tlbgp
        ^
...

cvise spits out:

$ cat tlb.i
void kvm_vz_save_guesttlb() {
  __asm__(".set\tvirt\n\t"
          "tlbgr\n\t");
}

$ mips-suse-linux-gcc -march=mips64r2 -c -o /dev/null tlb.i

$ clang --target=mips-linux-gnu -mabi=64 -march=mips64r2 -c -o /dev/null tlb.i
tlb.i:2:24: error: instruction requires a CPU feature not currently enabled
  __asm__(".set\tvirt\n\t"
                       ^
<inline asm>:2:2: note: instantiated into assembly here
        tlbgr
        ^
1 error generated.

Reduced IR:

$ cat reduced.ll
target triple = "mips64el-unknown-linux-gnuabi64"

define void @kvm_vz_save_guesttlb() {
entry:
  tail call void asm sideeffect ".set\09virt\0A\09tlbgr\0A\09", "~{$1}"()
  ret void
}

$ llc reduced.ll
<inline asm>:2:2: error: instruction requires a CPU feature not currently enabled
        tlbgr
        ^

According to https://github.com/llvm/llvm-project/commit/d4349f3bf676c0fcb4242b5abe8f5f6043ed4b34, .set virt should be supported...

ihalip commented 2 years ago
$ llc-14 -mcpu=mips64r2 reduced.ll
<inline asm>:1:13: error: instruction requires a CPU feature not currently enabled
        .set virt; tlbgr;
                   ^
$ llc-14 -mcpu=mips64r5 reduced.ll # OK

But Loongson is mips64r2 with extensions (including virtualization). GNU as accepts these instructions with mips64r2, llvm doesn't.

nickdesaulniers commented 11 months ago

https://lore.kernel.org/lkml/202312120116.CP1IYKWT-lkp@intel.com/ is also reporting this though it's using malta_kvm_defconfig. It thought we test that config in CI?

nathanchance commented 11 months ago

We have never tested malta_kvm_defconfig, we used to test malta_kvm_guest_defconfig: https://github.com/ClangBuiltLinux/continuous-integration2/commit/ab0f69c9f75453766445d4cf39d75250f91eda88