Skip to content

tlbilxlpid -> error: invalid instruction #1891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nickdesaulniers opened this issue Jul 24, 2023 · 14 comments
Closed

tlbilxlpid -> error: invalid instruction #1891

nickdesaulniers opened this issue Jul 24, 2023 · 14 comments
Assignees
Labels
[ARCH] powerpc This bug impacts ARCH=powerpc [BUG] llvm A bug that should be fixed in upstream LLVM [FIXED][LINUX] 6.6 This bug was fixed in Linux 6.6 [FIXED][LLVM] 18 This bug was fixed in LLVM 18 Reported upstream This bug was filed on LLVM’s issue tracker, Phabricator, or the kernel mailing list. [Reported-by] kbuild test robot Reported-by: kbuild test robot <[email protected]>

Comments

@nickdesaulniers
Copy link
Member

via https://lore.kernel.org/llvm/[email protected]/

it looks like:

void foo(void) {
    asm volatile("tlbilxlpid");
}

produces:

<source>:2:18: error: invalid instruction
    asm volatile("tlbilxlpid");
                 ^
<inline asm>:1:2: note: instantiated into assembly here
        tlbilxlpid
        ^~~~~~~~~~

for --target=powerpc-linux-gnu. I wonder if clang is missing support for this instruction (or perhaps it's an alias to something that clang does understand).

Reported upstream: llvm/llvm-project#64080

@nickdesaulniers nickdesaulniers added [BUG] Untriaged Something isn't working [ARCH] powerpc This bug impacts ARCH=powerpc Reported upstream This bug was filed on LLVM’s issue tracker, Phabricator, or the kernel mailing list. [Reported-by] kbuild test robot Reported-by: kbuild test robot <[email protected]> [BUG] llvm A bug that should be fixed in upstream LLVM [PATCH] Submitted A patch has been submitted for review and removed [BUG] Untriaged Something isn't working labels Jul 24, 2023
@nickdesaulniers
Copy link
Member Author

@nathanchance
Copy link
Member

@nathanchance nathanchance added [FIXED][LLVM] 18 This bug was fixed in LLVM 18 and removed [PATCH] Submitted A patch has been submitted for review labels Aug 2, 2023
@nickdesaulniers
Copy link
Member Author

nickdesaulniers commented Aug 2, 2023

We should use .inst in the kernel for clang < 18 (or 17 if we get a backport). There are 2 different values necessary dependent on the endianness.

@nickdesaulniers
Copy link
Member Author

.inst might be aarch64-only :(

@nickdesaulniers
Copy link
Member Author

ah, .long is used, include/asm/dcr-native.h for example

@nickdesaulniers
Copy link
Member Author

nickdesaulniers commented Aug 2, 2023

diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
index d58df71ace58..f3d32e250b08 100644
--- a/arch/powerpc/kvm/e500mc.c
+++ b/arch/powerpc/kvm/e500mc.c
@@ -92,7 +92,12 @@ void kvmppc_e500_tlbil_all(struct kvmppc_vcpu_e500 *vcpu_e500)
 
        local_irq_save(flags);
        mtspr(SPRN_MAS5, MAS5_SGS | get_lpid(&vcpu_e500->vcpu));
+// https://github.com/ClangBuiltLinux/linux/issues/1891
+#if defined(CONFIG_CC_IS_CLANG) && CONFIG_CLANG_VERSION < 180000
+       asm (".long 0x7c000024");
+#else
        asm volatile("tlbilxlpid");
+#endif
        mtspr(SPRN_MAS5, 0);
        local_irq_restore(flags);
 }

is the tentative patch. volatile is not necessary since there are no outputs. We don't need to flip the .long value based on endianness. Will wait to see about backports for clang 17 to get the version right.

@nickdesaulniers nickdesaulniers added the [PATCH] Exists There is a patch that fixes this issue label Aug 2, 2023
@nickdesaulniers
Copy link
Member Author

@mpe Looking at include/asm/dcr-native.h, do you have a preference between the above vs just changing the existing asm statement to use .long and a comment (no preprocessor directives)?

@mpe
Copy link

mpe commented Aug 2, 2023

The usual solution is to define the value in ppc-opcode.h. Actually we already have a PPC_TLBILX macro in there, so maybe you can use that, or add a variant of it. I don't think it's worth an #ifdef CLANG, just always use the .long version, though I guess a comment saying it can be removed when Clang version X is unsupported would be good.

@nickdesaulniers
Copy link
Member Author

@mpe thoughts on:

diff --git a/arch/powerpc/include/asm/ppc-opcode.h b/arch/powerpc/include/asm/ppc-opcode.h
index ef6972aa33b9..d84473db7c02 100644
--- a/arch/powerpc/include/asm/ppc-opcode.h
+++ b/arch/powerpc/include/asm/ppc-opcode.h
@@ -616,6 +616,7 @@
 #define PPC_TLBILX(t, a, b)    stringify_in_c(.long PPC_RAW_TLBILX(t, a, b))
 #define PPC_TLBILX_ALL(a, b)   PPC_TLBILX(0, a, b)
 #define PPC_TLBILX_PID(a, b)   PPC_TLBILX(1, a, b)
+#define PPC_TLBILX_LPID()      PPC_TLBILX(0, 0, 0)
 #define PPC_TLBILX_VA(a, b)    PPC_TLBILX(3, a, b)
 #define PPC_WAIT_v203          stringify_in_c(.long PPC_RAW_WAIT_v203)
 #define PPC_WAIT(w, p)         stringify_in_c(.long PPC_RAW_WAIT(w, p))
diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
index d58df71ace58..96ea8507d8a3 100644
--- a/arch/powerpc/kvm/e500mc.c
+++ b/arch/powerpc/kvm/e500mc.c
@@ -20,6 +20,7 @@
 #include <asm/cputable.h>
 #include <asm/kvm_ppc.h>
 #include <asm/dbell.h>
+#include <asm/opcode.h>
 
 #include "booke.h"
 #include "e500.h"
@@ -92,7 +93,10 @@ void kvmppc_e500_tlbil_all(struct kvmppc_vcpu_e500 *vcpu_e500)
 
        local_irq_save(flags);
        mtspr(SPRN_MAS5, MAS5_SGS | get_lpid(&vcpu_e500->vcpu));
-       asm volatile("tlbilxlpid");
+       /* clang-17 and older could not assemble tlbilxlpid.
+        * https://github.com/ClangBuiltLinux/linux/issues/1891
+        */
+       PPC_TLBILX_LPID();
        mtspr(SPRN_MAS5, 0);
        local_irq_restore(flags);
 }

@nickdesaulniers
Copy link
Member Author

nickdesaulniers commented Aug 2, 2023

or does that need to be asm volatile (PPC_TLBILX_LPID());? (looks like yes)

@mpe
Copy link

mpe commented Aug 3, 2023

The brackets on the macro aren't needed because it takes no params, see eg. PPC_ISA_3_0_INVALIDATE_ERAT. And then yes the call site is asm volatile (PPC_TLBILX_LPID). The volatile is not needed there but that's an orthogonal change I guess.

@nickdesaulniers
Copy link
Member Author

nickdesaulniers commented Aug 3, 2023

@nickdesaulniers nickdesaulniers added [PATCH] Submitted A patch has been submitted for review and removed [PATCH] Exists There is a patch that fixes this issue labels Aug 3, 2023
@nickdesaulniers nickdesaulniers self-assigned this Aug 3, 2023
mpe pushed a commit to linuxppc/linux-ci that referenced this issue Aug 15, 2023
Clang didn't recognize the instruction tlbilxlpid. This was fixed in
clang-18 [0] then backported to clang-17 [1].  To support clang-16 and
older, rather than using that instruction bare in inline asm, add it to
ppc-opcode.h and use that macro as is done elsewhere for other
instructions.

Link: ClangBuiltLinux/linux#1891
Link: llvm/llvm-project#64080
Link: llvm/llvm-project@53648ac [0]
Link: llvm/llvm-project-release-prs@0af7e5e [1]
Reported-by: kernel test robot <[email protected]>
Closes: https://lore.kernel.org/llvm/[email protected]/
Suggested-by: Michael Ellerman <[email protected]>
Signed-off-by: Nick Desaulniers <[email protected]>
Reviewed-by: Christophe Leroy <[email protected]>
Signed-off-by: Michael Ellerman <[email protected]>
Link: https://msgid.link/[email protected]
mpe pushed a commit to linuxppc/linux that referenced this issue Aug 17, 2023
Clang didn't recognize the instruction tlbilxlpid. This was fixed in
clang-18 [0] then backported to clang-17 [1].  To support clang-16 and
older, rather than using that instruction bare in inline asm, add it to
ppc-opcode.h and use that macro as is done elsewhere for other
instructions.

Link: ClangBuiltLinux#1891
Link: llvm/llvm-project#64080
Link: llvm/llvm-project@53648ac [0]
Link: llvm/llvm-project-release-prs@0af7e5e [1]
Reported-by: kernel test robot <[email protected]>
Closes: https://lore.kernel.org/llvm/[email protected]/
Suggested-by: Michael Ellerman <[email protected]>
Signed-off-by: Nick Desaulniers <[email protected]>
Reviewed-by: Christophe Leroy <[email protected]>
Signed-off-by: Michael Ellerman <[email protected]>
Link: https://msgid.link/[email protected]
@nickdesaulniers
Copy link
Member Author

nickdesaulniers commented Aug 17, 2023

@nickdesaulniers nickdesaulniers removed the [PATCH] Submitted A patch has been submitted for review label Aug 17, 2023
@nickdesaulniers nickdesaulniers added the [PATCH] Accepted A submitted patch has been accepted upstream label Aug 17, 2023
@nathanchance
Copy link
Member

@nathanchance nathanchance added [FIXED][LINUX] 6.6 This bug was fixed in Linux 6.6 and removed [PATCH] Accepted A submitted patch has been accepted upstream labels Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[ARCH] powerpc This bug impacts ARCH=powerpc [BUG] llvm A bug that should be fixed in upstream LLVM [FIXED][LINUX] 6.6 This bug was fixed in Linux 6.6 [FIXED][LLVM] 18 This bug was fixed in LLVM 18 Reported upstream This bug was filed on LLVM’s issue tracker, Phabricator, or the kernel mailing list. [Reported-by] kbuild test robot Reported-by: kbuild test robot <[email protected]>
Projects
None yet
Development

No branches or pull requests

3 participants