From patchwork Wed Dec 1 18:15:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 12650795 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7FCDC433F5 for ; Wed, 1 Dec 2021 18:34:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7293F6B0075; Wed, 1 Dec 2021 13:22:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 694716B007B; Wed, 1 Dec 2021 13:22:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1AAFD6B007E; Wed, 1 Dec 2021 13:22:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0205.hostedemail.com [216.40.44.205]) by kanga.kvack.org (Postfix) with ESMTP id EF2856B007B for ; Wed, 1 Dec 2021 13:22:09 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B3C0A181327C9 for ; Wed, 1 Dec 2021 18:21:59 +0000 (UTC) X-FDA: 78870044358.05.2DD5B95 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf08.hostedemail.com (Postfix) with ESMTP id EF66530000AE for ; Wed, 1 Dec 2021 18:21:59 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0A010218E0; Wed, 1 Dec 2021 18:15:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1638382520; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pRNn3FUWmIkB+AIBt8k4Hc3p8VqTdjyb4KkYPCXkybg=; b=ELzro/zIxjVcRcN04EgCAo22xNe9OBJSJDb3yhxSZGuQ9259suTkCJSXQVIbMMJsY8Ow+W Mr5zTKf5qsTwbjwbDYGphhlaSIxjrs8g1Vn+DKuhueggUyaL9PfXfbE/PrIMOpo2wAc4dD s1vO6dRNQ0U4iqKykj8uElhVMmrYY20= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1638382520; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pRNn3FUWmIkB+AIBt8k4Hc3p8VqTdjyb4KkYPCXkybg=; b=kmr6F2+S1arvtzhRZO9wnXSmRb0Fqlw/CTQvGuUnDXUW/CBZ3QhyJk6fs+tQ0K2s+5NtDN YDF27BS9XOA/cbBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D33C213D9D; Wed, 1 Dec 2021 18:15:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id yAUOM7e7p2HPSAAAMHmgww (envelope-from ); Wed, 01 Dec 2021 18:15:19 +0000 From: Vlastimil Babka To: Matthew Wilcox , Christoph Lameter , David Rientjes , Joonsoo Kim , Pekka Enberg Cc: linux-mm@kvack.org, Andrew Morton , patches@lists.linux.dev, Vlastimil Babka , Marco Elver , Alexander Potapenko , Dmitry Vyukov , kasan-dev@googlegroups.com Subject: [PATCH v2 26/33] mm/kfence: Convert kfence_guarded_alloc() to struct slab Date: Wed, 1 Dec 2021 19:15:03 +0100 Message-Id: <20211201181510.18784-27-vbabka@suse.cz> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211201181510.18784-1-vbabka@suse.cz> References: <20211201181510.18784-1-vbabka@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2616; h=from:subject; bh=+CNHtzGum/tOmd/kW8GAUx888uquumIQ2d0wfPG8TF4=; b=owEBbQGS/pANAwAIAeAhynPxiakQAcsmYgBhp7ubr9qa0wQH93+qc0CSNF9NLizxF8+su0OTZzLH lGacLvSJATMEAAEIAB0WIQSNS5MBqTXjGL5IXszgIcpz8YmpEAUCYae7mwAKCRDgIcpz8YmpEJDXCA CpJyrm/iqqE/v6T1tHy7bIGV5jHGrybBMM/EmUqQSj86aWhtP8Oi8CPAIFBtOu+CTFldmPk4Nh/0nq uw93aFHn4LHexWfSTIp53E0vyNSuHBYqtokdvrdbJN848c4mu37p5Ip8eLzmFavLDfrBdCoQYkGvpL IEcYpRa+yB8sVCIywEoZSrPi6OQwzslxQspXoZb7yM7Pm6AHdV/uPNfOui/2aRHVfFh0nYWuvz6ER2 WK77d7PonT7Mpg5p4Hwd82vtUvdGkz/R4PMOTbU3gIYV5zFvZ+2VOTvua7gTWrKL/iQG+0yxHKrhZf QchjOVxsNvaOcxzNOGhcIz4RzdVBRz X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: EF66530000AE X-Stat-Signature: wejmw679qqthzseocds39pbg7ogqix31 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="ELzro/zI"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=kmr6F2+S; dmarc=none; spf=pass (imf08.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-HE-Tag: 1638382919-622387 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Tested-by: Marco Elver Cc: Alexander Potapenko Cc: Marco Elver Cc: Dmitry Vyukov Cc: --- mm/kfence/core.c | 12 ++++++------ mm/kfence/kfence_test.c | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mm/kfence/core.c b/mm/kfence/core.c index 09945784df9e..4eb60cf5ff8b 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -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); diff --git a/mm/kfence/kfence_test.c b/mm/kfence/kfence_test.c index f7276711d7b9..a22b1af85577 100644 --- a/mm/kfence/kfence_test.c +++ b/mm/kfence/kfence_test.c @@ -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;