kfence: move the size check to the beginning of __kfence_alloc()
authorAlexander Potapenko <glider@google.com>
Fri, 23 Jul 2021 22:50:11 +0000 (15:50 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 24 Jul 2021 00:43:28 +0000 (17:43 -0700)
commit235a85cb32bb123854ad31de46fdbf04c1d57cda
tree20de2e4c1293425ab5f2566e1525ef70e2981e20
parent32ae8a0669392248a92d7545a7363004543f3932
kfence: move the size check to the beginning of __kfence_alloc()

Check the allocation size before toggling kfence_allocation_gate.

This way allocations that can't be served by KFENCE will not result in
waiting for another CONFIG_KFENCE_SAMPLE_INTERVAL without allocating
anything.

Link: https://lkml.kernel.org/r/20210714092222.1890268-1-glider@google.com
Signed-off-by: Alexander Potapenko <glider@google.com>
Suggested-by: Marco Elver <elver@google.com>
Reviewed-by: Marco Elver <elver@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Marco Elver <elver@google.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: <stable@vger.kernel.org> [5.12+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/kfence/core.c