From patchwork Thu Mar 21 14:24:39 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: 13598780 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 0A484C54E58 for ; Thu, 21 Mar 2024 14:25:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A60C6B009A; Thu, 21 Mar 2024 10:25:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 908516B009B; Thu, 21 Mar 2024 10:25:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7315C6B009C; Thu, 21 Mar 2024 10:25:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6461A6B009A for ; Thu, 21 Mar 2024 10:25:21 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 409BFA15BB for ; Thu, 21 Mar 2024 14:25:21 +0000 (UTC) X-FDA: 81921268842.09.679A7BB Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf05.hostedemail.com (Postfix) with ESMTP id CC5A1100028 for ; Thu, 21 Mar 2024 14:25:18 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=BmyYt3Mb; dmarc=none; spf=none (imf05.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711031118; 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:in-reply-to:references:references:dkim-signature; bh=TFqb/icTqpLESKsoUJZg7vHbrRZsZRhvgU73HCkwJw0=; b=2SVnH5HXDVvgS5FxA4LvXSlbIqhljrbRQsBTM9Lt2MhdfPQubXDYLGZq4KLYgXendqdlZ7 SP7AwmCq/9atpuXuTEkbV1GAFhdR8hJeVdOkGRA+WxFFtRZhbWfMJ6jHWNqGXr34d6oE/b bDaDegF2El0ZvE7t+Y0ClCQAYt2H9js= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=BmyYt3Mb; dmarc=none; spf=none (imf05.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711031118; a=rsa-sha256; cv=none; b=RpxO2fM+Ox3yGuOvjS9PS3juIxrIxwRUecbwRUCNrTE/N5+nH//We8dm+0WPGya4n+90V3 CUC8pjr/HB2tOt0PiO3IEZ+AfaBC2GHVdhpRoZC9HxHn9d1Rpsfh36RV7pQ3nl4FoSrUre pdaoly34HcAsi3BdPJ6MkLQnb4Lu9Rk= 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=TFqb/icTqpLESKsoUJZg7vHbrRZsZRhvgU73HCkwJw0=; b=BmyYt3Mb/S+Cgpx6rWtSMumZKO fleGe/ejJ9rAdj3cWbRXQbXtvm0aDnnv8QEQjlfXMtz0q1klIfO6cidZ4KRHsy8EOx/ukFdervB+v h5o7md1FznAVlf3+MJ6k2cKJJ/yqhYlM8oi8/N1VzIamj6EMo2x+uV4mLWyK9NronAMc20TsRlK0h 9hO2iukEOAYqNBEwZVjk+ZmAA4usbtx0tO5wlc7/aNyHDyqdp6uOIUjpWCV47ikbLWBufk+0BQEz2 J70tQjQ2tqKHb6nOOGpH8B7XLwVcNPcdXGuHUNw/esGTf5d3s4GeXqxlCDqGgljC/AXlJ3XtujC6V hxBY14hw==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnJLf-00000006u3u-1QqD; Thu, 21 Mar 2024 14:24:51 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, David Hildenbrand , Vlastimil Babka , Miaohe Lin , Muchun Song , Oscar Salvador Subject: [PATCH 1/9] mm: Always initialise folio->_deferred_list Date: Thu, 21 Mar 2024 14:24:39 +0000 Message-ID: <20240321142448.1645400-2-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240321142448.1645400-1-willy@infradead.org> References: <20240321142448.1645400-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: CC5A1100028 X-Stat-Signature: 1z4rnptidsqba7uwwtwarkuoc974euhc X-HE-Tag: 1711031118-722627 X-HE-Meta: U2FsdGVkX18gmpHh6Xfw0H7SC5PwBasixz9clrVuCHYq63ucyPJqwFrQaVjRfJ0nMuacSc764YPuZROsrQdkLlPCSEgr2tFNS5z+gaHB40LZtRX/KH6SkXAsVWG/lsN+vYoz6IlX0Ib31pjZP0f+EW9cX9pvD6Y295887jw+CRK++uRfVDD4+vfoUh/1Hnki/b31CAEgM/RgXBmofb3F3Uc0EyM+uAE6eWEq9StXn6ieAdcK2FU+uPzcrYu9SB/ZIQVvl/r1ZnN3PKdPh1NpehotC/Nk2ft07Cu7vxAQ1OVNs3UImfBn9RYKWMFFNoUzIox9s2F123G9dArs1aqvUGJ6Lg3mQxU0yzEDIK/swoGBMWYISc6QDbKrWEJqtwiYCYxAubbWsWOhmClxecGaId9UL45NSHvlFfdHmx6O0vJsF6L+k/3mCBYe+FvxhmBBYdss02P/jzsNwxmHc03DvbpCTFs3vCbf5+iZ+vlFMBqyQVaR3NbYqmYRd3+4YChr8YvQGokk75QnZWelIywezfkXDCiLx+2+jkVc452A8oQrsTMbhjhFu66qCiVAgMrsCyHekb4VVUyclX56h86qegaUjBbney448uyohI77ko9+0KDsTT9ErygelLglQIkmqts/yi/HABycvWVf1659+2WluSQQlSD2hL6csfb3Ddk9hoQcXYyy2ZD6PHfbCR2FXJCKKigBZbIgRR38x2FPQrM8vyQzthpG3BcqLAJ5ezbukJB1FjCBVDnhdqwABQiIJJYCirhXcbE4PXbTJaqVsMgz6Od7lEhyzei75Uiz6Ty0SUEeKNlhTPG9sQ6b/pkdT1Zm02qDCWASD9oqD/j3rgXKvBJxYpPghz2vctvkalJcGXJZ5BmRs6hp8qefExnAbws6BTxh3UVvGPjH9GCrLbtauoZ36b+7 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: For compound pages which are at least order-2 (and hence have a deferred_list), initialise it and then we can check at free that the page is not part of a deferred list. We recently found this useful to rule out a source of corruption. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Vlastimil Babka Reviewed-by: David Hildenbrand --- mm/huge_memory.c | 2 -- mm/hugetlb.c | 3 ++- mm/internal.h | 2 ++ mm/memcontrol.c | 2 ++ mm/page_alloc.c | 9 +++++---- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 9859aa4f7553..04fb994a7b0b 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -792,8 +792,6 @@ void folio_prep_large_rmappable(struct folio *folio) { if (!folio || !folio_test_large(folio)) return; - if (folio_order(folio) > 1) - INIT_LIST_HEAD(&folio->_deferred_list); folio_set_large_rmappable(folio); } diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 23ef240ba48a..7e9a766059aa 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1796,7 +1796,8 @@ static void __update_and_free_hugetlb_folio(struct hstate *h, destroy_compound_gigantic_folio(folio, huge_page_order(h)); free_gigantic_folio(folio, huge_page_order(h)); } else { - __free_pages(&folio->page, huge_page_order(h)); + INIT_LIST_HEAD(&folio->_deferred_list); + folio_put(folio); } } diff --git a/mm/internal.h b/mm/internal.h index 7e486f2c502c..10895ec52546 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -525,6 +525,8 @@ static inline void prep_compound_head(struct page *page, unsigned int order) atomic_set(&folio->_entire_mapcount, -1); atomic_set(&folio->_nr_pages_mapped, 0); atomic_set(&folio->_pincount, 0); + if (order > 1) + INIT_LIST_HEAD(&folio->_deferred_list); } static inline void prep_compound_tail(struct page *head, int tail_idx) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index fabce2b50c69..a2a74d4ca0b1 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -7448,6 +7448,8 @@ static void uncharge_folio(struct folio *folio, struct uncharge_gather *ug) struct obj_cgroup *objcg; VM_BUG_ON_FOLIO(folio_test_lru(folio), folio); + VM_BUG_ON_FOLIO(folio_order(folio) > 1 && + !list_empty(&folio->_deferred_list), folio); /* * Nobody should be changing or seriously looking at diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 14d39f34d336..4301146a5bf4 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1006,10 +1006,11 @@ static int free_tail_page_prepare(struct page *head_page, struct page *page) } break; case 2: - /* - * the second tail page: ->mapping is - * deferred_list.next -- ignore value. - */ + /* the second tail page: deferred_list overlaps ->mapping */ + if (unlikely(!list_empty(&folio->_deferred_list))) { + bad_page(page, "on deferred list"); + goto out; + } break; default: if (page->mapping != TAIL_MAPPING) {