From patchwork Tue Nov 16 00:16:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 12620725 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4607EC433F5 for ; Tue, 16 Nov 2021 00:17:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F3097614C8 for ; Tue, 16 Nov 2021 00:17:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org F3097614C8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id E49A16B00A1; Mon, 15 Nov 2021 19:16:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 286276B00A0; Mon, 15 Nov 2021 19:16:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C97E26B00A9; Mon, 15 Nov 2021 19:16:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0056.hostedemail.com [216.40.44.56]) by kanga.kvack.org (Postfix) with ESMTP id 8CD5A6B00A4 for ; Mon, 15 Nov 2021 19:16:43 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 46EF71815B7C7 for ; Tue, 16 Nov 2021 00:16:43 +0000 (UTC) X-FDA: 78812877486.16.D480BDF Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf21.hostedemail.com (Postfix) with ESMTP id 0A38BD036A48 for ; Tue, 16 Nov 2021 00:16:35 +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 2440E21985; Tue, 16 Nov 2021 00:16:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1637021801; 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=jlcyhF2LLUE3bvmbDw8O0jIb6Enb6GP8zJd72Sp+Bx4=; b=ljDnu3I5pA7LxM52HzWPV0LSBbeoD/Z7zAddYdK++n1la0tvokux5J64ShLQCUhiUvS9Ex 7gM31IPPLS3Xv2E0D07gls+7RlE8vtxMuVzXgsXhA6bnk0+GIjxgAq/AoNiPmxkfLTPb5P SKIgR1OVCuupQ+Z2qgAHyfbsBYIZ/Sc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1637021801; 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=jlcyhF2LLUE3bvmbDw8O0jIb6Enb6GP8zJd72Sp+Bx4=; b=IirEgiGddeLbACivjqf31ztq2SS5nNXxd8TTV1sAqLmQnvwrq/KBVISbwT8jViwWjA63Aw 6cT76vst85AQBZDQ== 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 ED9DF139DB; Tue, 16 Nov 2021 00:16:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id CMxgOWj4kmFjXAAAMHmgww (envelope-from ); Tue, 16 Nov 2021 00:16:40 +0000 From: Vlastimil Babka To: Matthew Wilcox , linux-mm@kvack.org, Christoph Lameter , David Rientjes , Joonsoo Kim , Pekka Enberg Cc: Vlastimil Babka , Alexander Potapenko , Marco Elver , Dmitry Vyukov , kasan-dev@googlegroups.com Subject: [RFC PATCH 25/32] mm/kfence: Convert kfence_guarded_alloc() to struct slab Date: Tue, 16 Nov 2021 01:16:21 +0100 Message-Id: <20211116001628.24216-26-vbabka@suse.cz> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211116001628.24216-1-vbabka@suse.cz> References: <20211116001628.24216-1-vbabka@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2573; h=from:subject; bh=cWCuHox2hs9ihwBAo3Akoy8nEbvO0ofNE6iZX9Rgt+o=; b=owEBbQGS/pANAwAIAeAhynPxiakQAcsmYgBhkvhOwJgpWqypMqjNDyHsLI3sXHr7P80qS6s2ts/L 3rJka4uJATMEAAEIAB0WIQSNS5MBqTXjGL5IXszgIcpz8YmpEAUCYZL4TgAKCRDgIcpz8YmpEAdMCA Ctmcd0hMpy5IvRPb/Zr2eu47QEcHeQOG9jh6KIq86yXC2L5XLTwL71NEz25yxP2Vl6EfzszsDxcTJ0 UOIfIy+r+d+hTADzHqDGs2501lh8/vM07kTBJc5CUF/PVWAPfarkXC31YdAYCGCR2cL+Oc4vtItczY QL9BJZLcGq4vdiGbaLvUZJtxir+AY4jOGi/xRknxupkmzBA7HzvVkwfZ4ze5bIXCR09O1C8l1LJ1hu 4AphWha3BoWLtAOVZL1wayRYAX/0QMQS+kXOEsdUu1bGEU/eXu7lr2vLrs0uQQmMOY/lFaqx10y8ow QqErRy755K3r21yXsQGQYXKe+J+a42 X-Developer-Key: i=vbabka@suse.cz; a=openpgp; fpr=A940D434992C2E8E99103D50224FA7E7CC82A664 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=ljDnu3I5; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=IirEgiGd; dmarc=none; spf=pass (imf21.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 0A38BD036A48 X-Stat-Signature: bbgibmicg6dhdg43xmqc84nkro8qwjjg X-HE-Tag: 1637021795-490983 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 Cc: Alexander Potapenko Cc: Marco Elver Cc: Dmitry Vyukov Cc: Tested-by: Marco Elver --- 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;