From patchwork Tue Nov 16 00:16: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: 12620687 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 6C83EC433EF for ; Tue, 16 Nov 2021 00:16:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 208EF63245 for ; Tue, 16 Nov 2021 00:16:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 208EF63245 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 24FCF6B0085; Mon, 15 Nov 2021 19:16:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AA8A26B0082; Mon, 15 Nov 2021 19:16:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82E916B007E; Mon, 15 Nov 2021 19:16:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0094.hostedemail.com [216.40.44.94]) by kanga.kvack.org (Postfix) with ESMTP id 009006B008A for ; Mon, 15 Nov 2021 19:16:39 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A76301815B7C7 for ; Tue, 16 Nov 2021 00:16:39 +0000 (UTC) X-FDA: 78812877318.22.18D1259 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf21.hostedemail.com (Postfix) with ESMTP id 9583CD036A4F for ; Tue, 16 Nov 2021 00:16:32 +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 1DA5D21940; Tue, 16 Nov 2021 00:16:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1637021798; 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=BlaEG0ElUGAgdmbyfAGjOTEntK3Vr0HOEifG+/ri/r4=; b=mPN4sWSAvF5picN4FqGrp3VT4LJ928v/y3KdE22+aqpYj/mdh4xCOCNCxdZ1lzf2NR9IzV nB222QEnJ+wGbJFGwaIVDKezdWfFP/6HhqbyDgCKxjSNqf+Zme5qgERSiOLA6LjH7Grdbi rahckxTbTbrG5RVnNIXrIg49jpXz8A4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1637021798; 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=BlaEG0ElUGAgdmbyfAGjOTEntK3Vr0HOEifG+/ri/r4=; b=tuOzMKu/bd97/Q3h66evKqEPGyHOiOcYfmjFlEK0mD/PU/JjqgvleEKNHOOz2zrJNcG/p7 a051kACAHt+kSqAw== 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 EDA9D13F72; Tue, 16 Nov 2021 00:16:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8NZKOWX4kmFjXAAAMHmgww (envelope-from ); Tue, 16 Nov 2021 00:16:37 +0000 From: Vlastimil Babka To: Matthew Wilcox , linux-mm@kvack.org, Christoph Lameter , David Rientjes , Joonsoo Kim , Pekka Enberg Cc: Vlastimil Babka Subject: [RFC PATCH 07/32] mm: Use struct slab in kmem_obj_info() Date: Tue, 16 Nov 2021 01:16:03 +0100 Message-Id: <20211116001628.24216-8-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=5088; i=vbabka@suse.cz; h=from:subject; bh=oLcaojp2iDljV7RSPLdEF0k5CMhJvZmt1EnPgMGazVE=; b=owEBbQGS/pANAwAIAeAhynPxiakQAcsmYgBhkvgtDsM08Y5E38E4MHb3uuufkhKxpOllDdppCj7L Fu1Ht+OJATMEAAEIAB0WIQSNS5MBqTXjGL5IXszgIcpz8YmpEAUCYZL4LQAKCRDgIcpz8YmpEH0fB/ 0S2pOvVZDFWPRtQWwOOqBLH//bSxNUYchX5JvpwiH6IMNWd/A/L47kKTCiKgKxodgdDxdmrO+FwPKF TGa8WS0tVCC7rOR0Q0fRYnkyqS/RKEv5N3bb6KknyD6TQTVj3/gezA3zCtZwRqcHB/O6ZNEyS39OkI jo0wRDY0UA/Dcum9iz0ik2qPKNujlchj7v1ClorD1ur2o42hW9Okb9uh/2h5VQbvDCzkQKjiQpVH5O 00H0WqA1UR/TvZndXshpnAgIPJb/p7eYzdH8OeuP4XQXFkrpF4uwDsHE3MsHrZf0O+VsscyuUoRcgu JHLdbzfn5fqybHAkxQzvBBnCphWZN2 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=mPN4sWSA; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="tuOzMKu/"; 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: 9583CD036A4F X-Stat-Signature: x4iq7g33teypsg419yeg941n5oph9o7d X-HE-Tag: 1637021792-147413 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: From: "Matthew Wilcox (Oracle)" All three implementations of slab support kmem_obj_info() which reports details of an object allocated from the slab allocator. By using the slab type instead of the page type, we make it obvious that this can only be called for slabs. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Vlastimil Babka --- mm/slab.c | 12 ++++++------ mm/slab.h | 4 ++-- mm/slab_common.c | 8 ++++---- mm/slob.c | 4 ++-- mm/slub.c | 12 ++++++------ 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/mm/slab.c b/mm/slab.c index a8e35265c1c5..acdede1e6528 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -3646,21 +3646,21 @@ EXPORT_SYMBOL(__kmalloc_node_track_caller); #endif /* CONFIG_NUMA */ #ifdef CONFIG_PRINTK -void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page) +void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab) { struct kmem_cache *cachep; unsigned int objnr; void *objp; kpp->kp_ptr = object; - kpp->kp_page = page; - cachep = page->slab_cache; + kpp->kp_slab = slab; + cachep = slab->slab_cache; kpp->kp_slab_cache = cachep; objp = object - obj_offset(cachep); kpp->kp_data_offset = obj_offset(cachep); - page = virt_to_head_page(objp); - objnr = obj_to_index(cachep, page, objp); - objp = index_to_obj(cachep, page, objnr); + slab = virt_to_slab(objp); + objnr = obj_to_index(cachep, slab_page(slab), objp); + objp = index_to_obj(cachep, slab_page(slab), objnr); kpp->kp_objp = objp; if (DEBUG && cachep->flags & SLAB_STORE_USER) kpp->kp_ret = *dbg_userword(cachep, objp); diff --git a/mm/slab.h b/mm/slab.h index 5203d19922b9..c7ab033a1c2f 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -801,7 +801,7 @@ static inline void debugfs_slab_release(struct kmem_cache *s) { } #define KS_ADDRS_COUNT 16 struct kmem_obj_info { void *kp_ptr; - struct page *kp_page; + struct slab *kp_slab; void *kp_objp; unsigned long kp_data_offset; struct kmem_cache *kp_slab_cache; @@ -809,7 +809,7 @@ struct kmem_obj_info { void *kp_stack[KS_ADDRS_COUNT]; void *kp_free_stack[KS_ADDRS_COUNT]; }; -void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page); +void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab); #endif #endif /* MM_SLAB_H */ diff --git a/mm/slab_common.c b/mm/slab_common.c index e5d080a93009..bddefca7d584 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -579,18 +579,18 @@ void kmem_dump_obj(void *object) { char *cp = IS_ENABLED(CONFIG_MMU) ? "" : "/vmalloc"; int i; - struct page *page; + struct slab *slab; unsigned long ptroffset; struct kmem_obj_info kp = { }; if (WARN_ON_ONCE(!virt_addr_valid(object))) return; - page = virt_to_head_page(object); - if (WARN_ON_ONCE(!PageSlab(page))) { + slab = virt_to_slab(object); + if (WARN_ON_ONCE(!slab)) { pr_cont(" non-slab memory.\n"); return; } - kmem_obj_info(&kp, object, page); + kmem_obj_info(&kp, object, slab); if (kp.kp_slab_cache) pr_cont(" slab%s %s", cp, kp.kp_slab_cache->name); else diff --git a/mm/slob.c b/mm/slob.c index 9bf75376a41a..b65fd468b8cd 100644 --- a/mm/slob.c +++ b/mm/slob.c @@ -462,10 +462,10 @@ static void slob_free(void *block, int size) } #ifdef CONFIG_PRINTK -void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page) +void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab) { kpp->kp_ptr = object; - kpp->kp_page = page; + kpp->kp_slab = slab; } #endif diff --git a/mm/slub.c b/mm/slub.c index 6a7e5146217e..ffcc75020225 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4322,31 +4322,31 @@ int __kmem_cache_shutdown(struct kmem_cache *s) } #ifdef CONFIG_PRINTK -void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page) +void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab) { void *base; int __maybe_unused i; unsigned int objnr; void *objp; void *objp0; - struct kmem_cache *s = page->slab_cache; + struct kmem_cache *s = slab->slab_cache; struct track __maybe_unused *trackp; kpp->kp_ptr = object; - kpp->kp_page = page; + kpp->kp_slab = slab; kpp->kp_slab_cache = s; - base = page_address(page); + base = slab_address(slab); objp0 = kasan_reset_tag(object); #ifdef CONFIG_SLUB_DEBUG objp = restore_red_left(s, objp0); #else objp = objp0; #endif - objnr = obj_to_index(s, page, objp); + objnr = obj_to_index(s, slab_page(slab), objp); kpp->kp_data_offset = (unsigned long)((char *)objp0 - (char *)objp); objp = base + s->size * objnr; kpp->kp_objp = objp; - if (WARN_ON_ONCE(objp < base || objp >= base + page->objects * s->size || (objp - base) % s->size) || + if (WARN_ON_ONCE(objp < base || objp >= base + slab->objects * s->size || (objp - base) % s->size) || !(s->flags & SLAB_STORE_USER)) return; #ifdef CONFIG_SLUB_DEBUG