From patchwork Mon Oct 4 13:46:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 12534183 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 9B1EAC4332F for ; Mon, 4 Oct 2021 14:42:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 30A1A613A2 for ; Mon, 4 Oct 2021 14:42:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 30A1A613A2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id B4C3B940046; Mon, 4 Oct 2021 10:42:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AFBC394000B; Mon, 4 Oct 2021 10:42:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A1230940046; Mon, 4 Oct 2021 10:42:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0226.hostedemail.com [216.40.44.226]) by kanga.kvack.org (Postfix) with ESMTP id 9217894000B for ; Mon, 4 Oct 2021 10:42:43 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4B75F2DEBA for ; Mon, 4 Oct 2021 14:42:43 +0000 (UTC) X-FDA: 78659021406.37.8169D57 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf01.hostedemail.com (Postfix) with ESMTP id 0608250714E0 for ; Mon, 4 Oct 2021 14:42:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=qc/45yb1X633dZ86WEJwm+UIp3+I+JOTpOrA5rVUcsQ=; b=HhaPDBEv5xqIaT8qh/NUBl/ssJ RGhOOioizqTnd3wBumySL5A1wXpgCx4j+nNYRYjQ/ApvcNbLY61QfpMG1EYrkqAHouuwLqva2I1di EfHJD7bhTK+zzN1Nk5ENja9K8NL8+TUFADDO8bnH41ZNuiSoAHYmlOgtw/lI+dzpal8RBcERmk53X horYAVr/r9OYSmvYB26r74OvLnmQYV2aUz+w0AKlQNTDo2ba6GyXSwYrRjXZIgjwi9eYLPw5SYgTI N3ElDkV3FAoS7LP9GnSG/XSWdQoYJGxod5xn/bHwDL7X6fGSdXTmdehJLiUZ+w2CfRQlQjsl27rY5 e5As9CDw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mXP96-00H0vE-6W; Mon, 04 Oct 2021 14:41:14 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH 42/62] mm/slub: Convert check_valid_pointer() to struct slab Date: Mon, 4 Oct 2021 14:46:30 +0100 Message-Id: <20211004134650.4031813-43-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211004134650.4031813-1-willy@infradead.org> References: <20211004134650.4031813-1-willy@infradead.org> MIME-Version: 1.0 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=HhaPDBEv; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0608250714E0 X-Stat-Signature: frsk3stxgtoiun94fk1aucsoiipegwtn X-HE-Tag: 1633358562-38710 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: Improves type safety and removes a lot of calls to slab_page(). Signed-off-by: Matthew Wilcox (Oracle) --- mm/slub.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index b1122b8cb36f..524e3c7eac30 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -638,19 +638,19 @@ static inline void metadata_access_disable(void) * Object debugging */ -/* Verify that a pointer has an address that is valid within a slab page */ +/* Verify that a pointer has an address that is valid within a slab */ static inline int check_valid_pointer(struct kmem_cache *s, - struct page *page, void *object) + struct slab *slab, void *object) { void *base; if (!object) return 1; - base = page_address(page); + base = slab_address(slab); object = kasan_reset_tag(object); object = restore_red_left(s, object); - if (object < base || object >= base + page->objects * s->size || + if (object < base || object >= base + slab->objects * s->size || (object - base) % s->size) { return 0; } @@ -803,7 +803,7 @@ static bool freelist_corrupted(struct kmem_cache *s, struct slab *slab, void **freelist, void *nextfree) { if ((s->flags & SLAB_CONSISTENCY_CHECKS) && - !check_valid_pointer(s, slab_page(slab), nextfree) && freelist) { + !check_valid_pointer(s, slab, nextfree) && freelist) { object_err(s, slab_page(slab), *freelist, "Freechain corrupt"); *freelist = NULL; slab_fix(s, "Isolate corrupted freechain"); @@ -1072,7 +1072,7 @@ static int check_object(struct kmem_cache *s, struct slab *slab, return 1; /* Check free pointer validity */ - if (!check_valid_pointer(s, slab_page(slab), get_freepointer(s, p))) { + if (!check_valid_pointer(s, slab, get_freepointer(s, p))) { object_err(s, slab_page(slab), p, "Freepointer corrupt"); /* * No choice but to zap it and thus lose the remainder @@ -1125,7 +1125,7 @@ static int on_freelist(struct kmem_cache *s, struct slab *slab, void *search) while (fp && nr <= slab->objects) { if (fp == search) return 1; - if (!check_valid_pointer(s, slab_page(slab), fp)) { + if (!check_valid_pointer(s, slab, fp)) { if (object) { object_err(s, slab_page(slab), object, "Freechain corrupt"); @@ -1266,7 +1266,7 @@ static inline int alloc_consistency_checks(struct kmem_cache *s, if (!check_slab(s, slab)) return 0; - if (!check_valid_pointer(s, slab_page(slab), object)) { + if (!check_valid_pointer(s, slab, object)) { object_err(s, slab_page(slab), object, "Freelist Pointer check fails"); return 0; } @@ -1310,7 +1310,7 @@ static noinline int alloc_debug_processing(struct kmem_cache *s, static inline int free_consistency_checks(struct kmem_cache *s, struct slab *slab, void *object, unsigned long addr) { - if (!check_valid_pointer(s, slab_page(slab), object)) { + if (!check_valid_pointer(s, slab, object)) { slab_err(s, slab_page(slab), "Invalid object pointer 0x%p", object); return 0; }