forked from Minki/linux
mm/kfence: Convert kfence_guarded_alloc() to struct slab
The function sets some fields that are being moved from struct page to struct slab so it needs to be converted. Signed-off-by: Vlastimil Babka <vbabka@suse.cz> Tested-by: Marco Elver <elver@google.com> Cc: Alexander Potapenko <glider@google.com> Cc: Marco Elver <elver@google.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: <kasan-dev@googlegroups.com>
This commit is contained in:
parent
6e48a966df
commit
8dae0cfed5
@ -360,7 +360,7 @@ static void *kfence_guarded_alloc(struct kmem_cache *cache, size_t size, gfp_t g
|
||||
{
|
||||
struct kfence_metadata *meta = NULL;
|
||||
unsigned long flags;
|
||||
struct page *page;
|
||||
struct slab *slab;
|
||||
void *addr;
|
||||
|
||||
/* Try to obtain a free object. */
|
||||
@ -424,13 +424,13 @@ static void *kfence_guarded_alloc(struct kmem_cache *cache, size_t size, gfp_t g
|
||||
|
||||
alloc_covered_add(alloc_stack_hash, 1);
|
||||
|
||||
/* Set required struct page fields. */
|
||||
page = virt_to_page(meta->addr);
|
||||
page->slab_cache = cache;
|
||||
/* Set required slab fields. */
|
||||
slab = virt_to_slab((void *)meta->addr);
|
||||
slab->slab_cache = cache;
|
||||
if (IS_ENABLED(CONFIG_SLUB))
|
||||
page->objects = 1;
|
||||
slab->objects = 1;
|
||||
if (IS_ENABLED(CONFIG_SLAB))
|
||||
page->s_mem = addr;
|
||||
slab->s_mem = addr;
|
||||
|
||||
/* Memory initialization. */
|
||||
for_each_canary(meta, set_canary_byte);
|
||||
|
@ -282,7 +282,7 @@ static void *test_alloc(struct kunit *test, size_t size, gfp_t gfp, enum allocat
|
||||
alloc = kmalloc(size, gfp);
|
||||
|
||||
if (is_kfence_address(alloc)) {
|
||||
struct page *page = virt_to_head_page(alloc);
|
||||
struct slab *slab = virt_to_slab(alloc);
|
||||
struct kmem_cache *s = test_cache ?:
|
||||
kmalloc_caches[kmalloc_type(GFP_KERNEL)][__kmalloc_index(size, false)];
|
||||
|
||||
@ -291,8 +291,8 @@ static void *test_alloc(struct kunit *test, size_t size, gfp_t gfp, enum allocat
|
||||
* even for KFENCE objects; these are required so that
|
||||
* memcg accounting works correctly.
|
||||
*/
|
||||
KUNIT_EXPECT_EQ(test, obj_to_index(s, page_slab(page), alloc), 0U);
|
||||
KUNIT_EXPECT_EQ(test, objs_per_slab(s, page_slab(page)), 1);
|
||||
KUNIT_EXPECT_EQ(test, obj_to_index(s, slab, alloc), 0U);
|
||||
KUNIT_EXPECT_EQ(test, objs_per_slab(s, slab), 1);
|
||||
|
||||
if (policy == ALLOCATE_ANY)
|
||||
return alloc;
|
||||
|
Loading…
Reference in New Issue
Block a user