llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

X86 ChromeOS devices with kernel 4.4 fails to boot after 4b0aa5724feaa89a9538dcab97e018110b0e4bc3

Open jcai19 opened this issue 6 years ago • 27 comments

Bugzilla Link 47468
Resolution FIXED
Resolved on Sep 22, 2020 02:45
Version trunk
OS All
Blocks llvm/llvm-project#4440 llvm/llvm-project#46070
CC @jcai19,@cmtice,@topperc,@dwblaikie,@zmodem,@jyknight,@lalozano,@m-gupta,@nathanchance,@nickdesaulniers,@stephenhines

Extended Description

While building with recent LLVM versions, we found X86 ChromeOS images with kernel 4.4 all failed to boot. We bisected it to the following commit.

commit 4b0aa5724feaa89a9538dcab97e018110b0e4bc3 Author: James Y Knight [email protected] Date: Fri May 15 23:43:30 2020 -0400

Change the INLINEASM_BR MachineInstr to be a non-terminating instruction.

Link: https://crbug.com/1123683

jcai19 avatar Sep 09 '20 00:09 jcai19

Cherry-picked to 11.x as 410b0dc84bbdafabe3a2c3eedd96e50340a6e0d0 and 6250d4944539f67d6a605928e97c087fe306a79e. Thanks everyone!

zmodem avatar Sep 22 '20 09:09 zmodem

Manoj notes that the fix will depend on

commit a0385bd7acd6 ("[llvm] Add contains(KeyType) -> bool methods to SmallPtrSet")

which doesn't look like it's in release/11.x to me.

So we'll likely want to cherry pick the following 2 patches to close this out:

1: commit a0385bd7acd6 ("[llvm] Add contains(KeyType) -> bool methods to SmallPtrSet")

2: commit f7a53d82c090 ("#47468 : Fix findPHICopyInsertPoint, so that copies aren't incorrectly inserted after an INLINEASM_BR.")

nickdesaulniers avatar Sep 21 '20 16:09 nickdesaulniers

Manoj reports the CrOS tests look good:

https://chromium-review.googlesource.com/c/chromiumos/overlays/chromiumos-overlay/+/2417398/3#message-18cdbb29241e515a94ffc182889a7c9c2b335ec7

Nathan reports clang-11+patch and ToT+patch look good:

tot: https://paste.myself5.de/raw/aciqosofos clang-11: https://del.dog/raw/xapegagywo (tot showed one failure, but that's due to a missed cherry pick for an unrelated breakage upstream in kernel sources)

The fixed was merged on master in: https://reviews.llvm.org/rGf7a53d82c0902147909f28a9295a9d00b4b27d38

Let's get this cherry-picked over to release/11.x and close this out. Hans?

nickdesaulniers avatar Sep 18 '20 18:09 nickdesaulniers

Fix committed to master as f7a53d82c0902147909f28a9295a9d00b4b27d38, which cherry-picks cleanly to 11.x.

@​Hans: shall I push to 11.x?

jyknight avatar Sep 18 '20 18:09 jyknight

All of my kernel build+boot tests with release/11.x + https://reviews.llvm.org/D87865 passed.

nickdesaulniers avatar Sep 18 '20 05:09 nickdesaulniers

All of my tests with this on ToT LLVM look good. Going to rerun them again with this on top of release/11.x.

nickdesaulniers avatar Sep 18 '20 02:09 nickdesaulniers

The verification I've done so far is limited to one test device. Will start a more complete test with the patch.

jcai19 avatar Sep 17 '20 23:09 jcai19

I verified https://reviews.llvm.org/D87865 fixed the issue locally.

jcai19 avatar Sep 17 '20 23:09 jcai19

Thanks!

Jian and Manoj are testing this on CrOS kernels. Nathan is testing this on various linux kernel distro's configs. I'm testing this with kernel patches that use asm goto w/ outputs, and our 65 various kernel tree and configs: https://travis-ci.com/github/ClangBuiltLinux/continuous-integration.

It will take me at least an hour and a half to two hours to get through all of those.

Hans, I suspect we can have the patch ready and well qualified by tonight (US time, maybe next 6-8 hours).

nickdesaulniers avatar Sep 17 '20 23:09 nickdesaulniers

I've got the "Slightly better fix" posted for review now: https://reviews.llvm.org/D87865

Please verify this works for you as well, thanks!

jyknight avatar Sep 17 '20 22:09 jyknight

Thanks for the fix. I've verified locally it fixed the issue in a test device.

jcai19 avatar Sep 17 '20 21:09 jcai19

The bug is in llvm::findPHICopyInsertPoint.

We're correctly hitting the special case for placement in a block with asm-goto or invoke. Then, the code places the copy after the last use or def of the register. Unfortunately, placing after the last use is wrong -- inlineasm_br uses the register, in this example. Yet, the whole point of the special-case is to find a place to insert the copy before that instruction.

I believe just placing the copy after last DEF, not after the last use or def, will be a correct fix. E.g.:

--- a/llvm/lib/CodeGen/PHIEliminationUtils.cpp +++ b/llvm/lib/CodeGen/PHIEliminationUtils.cpp @@ -34,7 +34,7 @@ llvm::findPHICopyInsertPoint(MachineBasicBlock* MBB, MachineBasicBlock* SuccMBB, // Discover any defs/uses in this basic block. SmallPtrSet<MachineInstr*, 8> DefUsesInMBB; MachineRegisterInfo& MRI = MBB->getParent()->getRegInfo();

  • for (MachineInstr &RI : MRI.reg_instructions(SrcReg)) {
  • for (MachineInstr &RI : MRI.def_instructions(SrcReg)) { if (RI.getParent() == MBB) DefUsesInMBB.insert(&RI); }

However, that will have the effect of placing the copy earlier than necessary in the block, which might increase register pressure. I'm going to try to make a slightly better fix.

jyknight avatar Sep 17 '20 20:09 jyknight

fwiw, dumping the output of llc -O2 -print-before-all repro.ll -o - to a file and comparing that before vs after the changes in question, things start to go visibly wrong after

Eliminate PHI nodes for register allocation

pass. We have:

  • $rbx = MOV64rr $r14 ...
  • INLINEASM_BR ...
  • INLINEASM_BR ...
  • $rbx = MOV64rr killed $r14

(so we were doing mov then inline asm blob; after we have those reversed, which is bad)

nickdesaulniers avatar Sep 17 '20 20:09 nickdesaulniers

repro.ll smaller reproducer

$ llc -O2 repro.ll

Specifically: .Ltmp1: lock decl 192(%r14) je .Ltmp0 #NO_APP movq %r14, %rbx

It seems like the movq %r14, %rbx would occur before the lock'd decl unconditionally prior to the patches in question in clang-11.

nickdesaulniers avatar Sep 17 '20 19:09 nickdesaulniers

free_user_ns__user_namespace.ll Attaching reproducer extracted via:

$ llvm-extract --func=free_user_ns user_namespace.ll -o free_user_ns__user_namespace.ll

It looks like a BB terminated with callbr has an indirect target back to itself.

Will work on reducing this further via bugpoint or such.

nickdesaulniers avatar Sep 17 '20 19:09 nickdesaulniers

Comparing the disassemblies between:

  1. commit 78c69a00a4cff786e0
  2. commit 78c69a00a4cff786e0 + cherry pick 4b0aa5724feaa + cherry pick 78c69a00a4cff

I can see a few differences, which look pretty obviously wrong to me, for example the relatively small fn free_user_ns:

example:

-     2ab: 4c 89 f3                             movq    %r14, %rbx
-     2ae: f0                                   lock
-     2af: 41 ff 8e c0 00 00 00                 decl    192(%r14)
-     2b6: 74 d2                                je      0x28a <free_user_ns+0xa>
+     2ab: f0                                   lock
+     2ac: 41 ff 8e c0 00 00 00                 decl    192(%r14)
+     2b3: 74 d5                                je      0x28a <free_user_ns+0xa>
+     2b5: 4c 89 f3                             movq    %r14, %rbx

so the mov was occurring unconditionally before the dec, now it's conditional (oops) and after the dec (double oops)

Since free_user_ns is relatively small, should make the reproducer concise and getting it easy.

nickdesaulniers avatar Sep 17 '20 19:09 nickdesaulniers

Specifically, the linux-4.4.y branch of the stable tree of the Linux kernel with CONFIG_USER_NS enabled; kernel/user_namespace.o seems to the the culprit of an object file bisection performed by Jian. Still digging in what's broken about it.

nickdesaulniers avatar Sep 17 '20 18:09 nickdesaulniers

We were able to get physical access to the device.

We have bisected down to the object file affected.

I'm working through pinpointing where things are going wrong now.

nickdesaulniers avatar Sep 17 '20 18:09 nickdesaulniers

As it's currently looking, I don't think we can hold the release for this.

zmodem avatar Sep 17 '20 12:09 zmodem

We are still actively debugging this. We have found that the devices actually boot the first time but reboot when system UI is restarted for any reason e.g. tests. And the problem indeed starts from the mentioned LLVM patch.

Lack of access to a physical device has unfortunately made debugging really slow.

m-gupta avatar Sep 15 '20 15:09 m-gupta