mm/slub: free KFENCE objects in slab_free_hook()
authorVlastimil Babka <vbabka@suse.cz>
Tue, 14 Nov 2023 21:12:47 +0000 (22:12 +0100)
committerVlastimil Babka <vbabka@suse.cz>
Thu, 28 Dec 2023 18:18:18 +0000 (19:18 +0100)
commit782f8906f8057efc7151b4b98b0a0280a71d005f
tree2ecddbe03bf673832d2e8f7f80124a5fca09ba07
parent284f17ac13fe34ae9eecbe57bb91553374d9b855
mm/slub: free KFENCE objects in slab_free_hook()

When freeing an object that was allocated from KFENCE, we do that in the
slowpath __slab_free(), relying on the fact that KFENCE "slab" cannot be
the cpu slab, so the fastpath has to fallback to the slowpath.

This optimization doesn't help much though, because is_kfence_address()
is checked earlier anyway during the free hook processing or detached
freelist building. Thus we can simplify the code by making the
slab_free_hook() free the KFENCE object immediately, similarly to KASAN
quarantine.

In slab_free_hook() we can place kfence_free() above init processing, as
callers have been making sure to set init to false for KFENCE objects.
This simplifies slab_free(). This places it also above kasan_slab_free()
which is ok as that skips KFENCE objects anyway.

While at it also determine the init value in slab_free_freelist_hook()
outside of the loop.

This change will also make introducing per cpu array caches easier.

Tested-by: Marco Elver <elver@google.com>
Reviewed-by: Chengming Zhou <zhouchengming@bytedance.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
mm/slub.c