From patchwork Mon Nov 25 20:17:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 13885243 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 D9098D59D6A for ; Mon, 25 Nov 2024 20:17:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FDA66B0088; Mon, 25 Nov 2024 15:17:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5AD6E6B0089; Mon, 25 Nov 2024 15:17:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 49C5E6B008C; Mon, 25 Nov 2024 15:17:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2C4216B0088 for ; Mon, 25 Nov 2024 15:17:29 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A5D8F40196 for ; Mon, 25 Nov 2024 20:17:28 +0000 (UTC) X-FDA: 82825727334.04.CB2A858 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf28.hostedemail.com (Postfix) with ESMTP id 38B1EC0002 for ; Mon, 25 Nov 2024 20:17:18 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=OB20eP9T; spf=none (imf28.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732565842; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=CHHt0O7rL6AlsO2cAZIVKebUXT6Q6A4nPNqwf9n4YgQ=; b=7nCd4CbTTaEZg3JC9KvcB+sDAVH1AJoFh7bd2LEXpvTSwILRIhuhqfTobo/h4HJeARuwue X3c0tEoGfdKHPed9TDqbXjXLTA4MvKYtjkAhpGiuC2moYSPMGmmNwf5vg3rcI6fS/kdzko 083qNHfNDs322kx2+eTFV+gijygTq58= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=OB20eP9T; spf=none (imf28.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732565842; a=rsa-sha256; cv=none; b=tX+mcFOJR9+LVxxskV0aKjPb77E2Dv2e6I4ZeQf7eqoqIdGheuQ3ZrvTT7xsm8XnzdAvph 2TsmfD6xcjdo1qLlJQyZW/NDFavXmqEigACpHRUUW4IDQNoLp39jkrnlEdc3UfdifTkSQI hpVsCRIv+4Tw0rB+dwARvoZJaykE9To= 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: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=CHHt0O7rL6AlsO2cAZIVKebUXT6Q6A4nPNqwf9n4YgQ=; b=OB20eP9TLDKrc23czqVlgHa227 E7oMY9q7avJj/oSwF5aNqmMlncl5r6ftyptNoLcekbsDMahmjnz2woVFGTlUcMNYjdCIu5yVP5D6j a4NxaKnN/0MOXgw2CD8X2KViPEUrzd7t++994qcWfjQhC66zTSMMHwkaqLWfAH8pNhnKIbUFVC2MM C4KaD5gbA7XqCV8wPJEPH4sXiOZcfQRZADbaETfiIFesToFdonety/tQRMKksIEQBPfQc4t3V3kcD D9S8miBA4DrGsNblPNU3nThhCQ2pb6vfsFhsAN9kR84i7yVlWESw0a9o11HJ082gjsBYm99rTq2gA rSCKDLgw==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tFfWM-0000000CQsy-3kcc; Mon, 25 Nov 2024 20:17:22 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , Kees Cook , linux-mm@kvack.org, stable@vger.kernel.org Subject: [PATCH 1/2] mm: Open-code PageTail in folio_flags() and const_folio_flags() Date: Mon, 25 Nov 2024 20:17:18 +0000 Message-ID: <20241125201721.2963278-1-willy@infradead.org> X-Mailer: git-send-email 2.47.0 MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 38B1EC0002 X-Stat-Signature: h1g1oimh5gjdsy9zko8i9wbsx8naqayx X-Rspam-User: X-HE-Tag: 1732565838-283421 X-HE-Meta: U2FsdGVkX19tNaijtoZDUy0MzbuxYfnKQNmjc7GquE1Zv+wxFjHJDBxdvs1vI+9YuvfeT5NZIJ1xor4IHvrMzdRRCQ1CryjmM02QcbVwzDvXl9WYvoumPYNEJzNxmr+GhLMIAG99quNDbgjGGUIVQto6XmZx9RXjOWBKpBDCwcy6MHe97KIH95rc+mKAfkcBDHzSqLM3S0AZW9jg4sF+EFqP7hoP3rLxh6ssB4f8XeYUTelziP8sAi9WUmXKNu5YFX+kAUHbAGaFy4vyA8OPwn37LnM16b8VJJIE+xv70aYiTv2pLi6TicBkhwAGC6p9CM9i1X3UqUuhl8qeiaKaNMw5MNrjTyZ41MTVfkRm3xTlLnpwdCemrSEe1iK+A37JOSJygJHJRX6AZVhNGJwW2LXPHUupMFP3M8UzKIBiVfLwk85tZS8TmmIhykccH/1dy6KkteALmHeAfCOpIkkkBrmnflFmxCat9iHvrH/bKsodl/UkL3a0OSdziWfNwmm4+yfPr5SbYDMDeEro+C7ITlVqb4RRjSESISTTsOgWxjPmG9vQ5YpqX7kFklob0rzPtmAzHOPoBKH0jKGx71uLK9uSeH2Bd2KPAmjNUZdrRD5TZxRBCNLbKdgq9Gp6dmbUuDTnEC/vDKYdjDzvmxee+iNh1nnJiuKpmK2ljOiN2xPHjUIpzZkT13sRSALZVFz3/OMV88abTgjUSUwJkFEO1xBcuDFY8IMfhl9Gyo2bXhksj+Uoa0ccGo41OdMFbU9Bcn8OBdQrDkumTaTeARRqWngPZ1iUx6yplElfC2COp9sOYSPoHhTJwvlft0eHXRmHyVpXRjdjMI3JdhDLRRBaL/BXy9Jh/8r1SPulcBqgJI6GaY0cGi9+6W1W1qZZXysq35UrTRcpX/PYlAqh5zRVmi2LGBQS2klOZPi2p7niLOF4o9+yID7T8JqfEA4EGB74MTexszlaF3g95ACx43O fByFiwrW o66iDUCBVBpUmIDWU7SQuro08dYYm8amFa+Bj0TsXzjsAIvXh18q/ANTzJYph9/oS761vDwKj1WM/tCdlPQP1Ic0o2NS59dl5cpCZMIizhtEBHj6sRmcsAzxylUma9Kxs1dXE6D4qVGE29RuKjFtM0C3X6dlMPEVAbWZ936e90paa6Kh+i3+GqeVuDQWzR8aOvLANAjjoocYrbweoxcol3f9GyulP8oXfazacZYmRvYWRQyaJ64W50ym/jk5RFuDrwFrQViRzdpTuxcRW3vuJz3g+DYNQ3QbE8GBVZfUq0bVq/5lHtzbJPuocsQ== 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: List-Subscribe: List-Unsubscribe: It is unsafe to call PageTail() in dump_page() as page_is_fake_head() will almost certainly return true when called on a head page that is copied to the stack. That will cause the VM_BUG_ON_PGFLAGS() in const_folio_flags() to trigger when it shouldn't. Fortunately, we don't need to call PageTail() here; it's fine to have a pointer to a virtual alias of the page's flag word rather than the real page's flag word. Fixes: fae7d834c43c (mm: add __dump_folio()) Signed-off-by: Matthew Wilcox (Oracle) Cc: stable@vger.kernel.org --- include/linux/page-flags.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 2220bfec278e..cf46ac720802 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -306,7 +306,7 @@ static const unsigned long *const_folio_flags(const struct folio *folio, { const struct page *page = &folio->page; - VM_BUG_ON_PGFLAGS(PageTail(page), page); + VM_BUG_ON_PGFLAGS(page->compound_head & 1, page); VM_BUG_ON_PGFLAGS(n > 0 && !test_bit(PG_head, &page->flags), page); return &page[n].flags; } @@ -315,7 +315,7 @@ static unsigned long *folio_flags(struct folio *folio, unsigned n) { struct page *page = &folio->page; - VM_BUG_ON_PGFLAGS(PageTail(page), page); + VM_BUG_ON_PGFLAGS(page->compound_head & 1, page); VM_BUG_ON_PGFLAGS(n > 0 && !test_bit(PG_head, &page->flags), page); return &page[n].flags; }