android_kernel_xiaomi_sm8450/mm/kasan
Mark Rutland f746714fe4 UPSTREAM: arm64: kasan: mte: use a constant kernel GCR_EL1 value
When KASAN_HW_TAGS is selected, KASAN is enabled at boot time, and the
hardware supports MTE, we'll initialize `kernel_gcr_excl` with a value
dependent on KASAN_TAG_MAX. While the resulting value is a constant
which depends on KASAN_TAG_MAX, we have to perform some runtime work to
generate the value, and have to read the value from memory during the
exception entry path. It would be better if we could generate this as a
constant at compile-time, and use it as such directly.

Early in boot within __cpu_setup(), we initialize GCR_EL1 to a safe
value, and later override this with the value required by KASAN. If
CONFIG_KASAN_HW_TAGS is not selected, or if KASAN is disabeld at boot
time, the kernel will not use IRG instructions, and so the initial value
of GCR_EL1 is does not matter to the kernel. Thus, we can instead have
__cpu_setup() initialize GCR_EL1 to a value consistent with
KASAN_TAG_MAX, and avoid the need to re-initialize it during hotplug and
resume form suspend.

This patch makes arem64 use a compile-time constant KERNEL_GCR_EL1
value, which is compatible with KASAN_HW_TAGS when this is selected.
This removes the need to re-initialize GCR_EL1 dynamically, and acts as
an optimization to the entry assembly, which no longer needs to load
this value from memory. The redundant initialization hooks are removed.

In order to do this, KASAN_TAG_MAX needs to be visible outside of the
core KASAN code. To do this, I've moved the KASAN_TAG_* values into
<linux/kasan-tags.h>.

There should be no functional change as a result of this patch.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Peter Collingbourne <pcc@google.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: Will Deacon <will@kernel.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>
Tested-by: Andrey Konovalov <andreyknvl@gmail.com>
Link: https://lore.kernel.org/r/20210714143843.56537-3-mark.rutland@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
(cherry picked from commit 82868247897bea2d69a83dca9a6a557e2c96dac4)
Change-Id: I397025af7051bedcdd35987af5deec46c228f8e2
Signed-off-by: Peter Collingbourne <pcc@google.com>
Bug: 192536783
2021-10-01 09:39:35 -07:00
..
common.c FROMGIT: kasan: use separate (un)poison implementation for integrated init 2021-06-17 14:39:37 -07:00
generic.c FROMGIT: kasan: init memory in kasan_(un)poison for HW_TAGS 2021-03-24 15:09:16 -07:00
hw_tags.c UPSTREAM: arm64: kasan: mte: use a constant kernel GCR_EL1 value 2021-10-01 09:39:35 -07:00
init.c UPSTREAM: arm/kasan: fix the array size of kasan_early_shadow_pte[] 2021-03-05 19:32:48 +00:00
kasan.h UPSTREAM: arm64: kasan: mte: use a constant kernel GCR_EL1 value 2021-10-01 09:39:35 -07:00
Makefile UPSTREAM: kasan, arm64: implement HW_TAGS runtime 2021-01-19 21:47:30 -08:00
quarantine.c FROMGIT: kasan: prefix global functions with kasan_ 2021-02-07 13:41:41 -08:00
report_generic.c FROMGIT: mm/kasan: switch from strlcpy to strscpy 2021-03-24 15:09:15 -07:00
report_hw_tags.c FROMGIT: kasan: prefix global functions with kasan_ 2021-02-07 13:41:41 -08:00
report_sw_tags.c FROMGIT: kasan: prefix global functions with kasan_ 2021-02-07 13:41:41 -08:00
report.c FROMGIT: kasan: use dump_stack_lvl(KERN_ERR) to print stacks 2021-05-21 13:17:09 -07:00
shadow.c FROMGIT: kasan: init memory in kasan_(un)poison for HW_TAGS 2021-03-24 15:09:16 -07:00
sw_tags.c UPSTREAM: kasan: fix kasan_byte_accessible() to be consistent with actual checks 2021-05-14 19:52:50 +00:00