hwasan: Support for outlined checks in the Linux kernel.
authorPeter Collingbourne <peter@pcc.me.uk>
Tue, 27 Oct 2020 23:26:29 +0000 (16:26 -0700)
committerPeter Collingbourne <peter@pcc.me.uk>
Fri, 30 Oct 2020 21:25:40 +0000 (14:25 -0700)
commit3d049bce98ce39becfaa0fc15a54f1e8a7d62643
tree3a3f1891123b28744d9a3c0ae2d2b9738492b5b7
parentee703eb4726ba570b3831400cc1b0bc3ae0f88b9
hwasan: Support for outlined checks in the Linux kernel.

Add support for match-all tags and GOT-free runtime calls, which
are both required for the kernel to be able to support outlined
checks. This requires extending the access info to let the backend
know when to enable these features. To make the code easier to maintain
introduce an enum with the bit field positions for the access info.

Allow outlined checks to be enabled with -mllvm
-hwasan-inline-all-checks=0. Kernels that contain runtime support for
outlined checks may pass this flag. Kernels lacking runtime support
will continue to link because they do not pass the flag. Old versions
of LLVM will ignore the flag and continue to use inline checks.

With a separate kernel patch [1] I measured the code size of defconfig
+ tag-based KASAN, as well as boot time (i.e. time to init launch)
on a DragonBoard 845c with an Android arm64 GKI kernel. The results
are below:

         code size    boot time
before    92824064      6.18s
after     38822400      6.65s

[1] https://linux-review.googlesource.com/id/I1a30036c70ab3c3ee78d75ed9b87ef7cdc3fdb76

Depends on D90425

Differential Revision: https://reviews.llvm.org/D90426
llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
llvm/test/CodeGen/AArch64/hwasan-check-memaccess.ll
llvm/test/Instrumentation/HWAddressSanitizer/kernel.ll