Re: [RFC PATCH] UML: add support for KASAN under x86_64

From: Dmitry Vyukov
Date: Thu Jan 16 2020 - 03:44:22 EST


On Wed, Jan 15, 2020 at 7:28 PM Patricia Alfonso
<trishalfonso@xxxxxxxxxx> wrote:
> +config KASAN_SHADOW_OFFSET
> + hex
> + depends on KASAN
> + default 0x100000000000
> + help
> + This is the offset at which the ~2.25TB of shadow memory is
> + initialized and used by KASAN for memory debugging. The default
> + is 0x100000000000.

What are restrictions on this value?
In user-space we use 0x7fff8000 as a base (just below 2GB) and it's
extremely profitable wrt codegen since it fits into immediate of most
instructions.
We can load and add the base with a short instruction:
2d8c: 48 81 c2 00 80 ff 7f add $0x7fff8000,%rdx
Or even add base, load shadow and check it with a single 7-byte instruction:
1e4: 80 b8 00 80 ff 7f 00 cmpb $0x0,0x7fff8000(%rax)

While with the large base, it takes 10 bytes just to load the const
into a register (current x86 KASAN codegen):
ffffffff81001571: 48 b8 00 00 00 00 00 fc ff df movabs
$0xdffffc0000000000,%rax
Most instructions don't have 8-byte immediates, so then we separately
need to add/load/check.