From patchwork Tue Mar 12 03:50:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13589504 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 D3B4AC54E49 for ; Tue, 12 Mar 2024 03:50:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4BADD6B00C7; Mon, 11 Mar 2024 23:50:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 426546B00DE; Mon, 11 Mar 2024 23:50:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2BDC46B00DF; Mon, 11 Mar 2024 23:50:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 18FA56B00C7 for ; Mon, 11 Mar 2024 23:50:24 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B96F18046B for ; Tue, 12 Mar 2024 03:50:23 +0000 (UTC) X-FDA: 81887009526.05.09A0BB5 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf07.hostedemail.com (Postfix) with ESMTP id 3A45040008 for ; Tue, 12 Mar 2024 03:50:21 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=l0qzWhc2; dmarc=none; spf=none (imf07.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=1710215422; 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=5f7oX51Aibooo3IXpgcLBXZIyCqaT3ILWc9LUGUXvBw=; b=XuXJnyeevul2pOHoLzp52LrCaikb37H8BkSPkQJwKc4nESS2laUiZYRXIgRK16JwFXbUlZ BQOLRqHfXyrs1EFebAfhMLHb7EIC1jxfonBY1VmTQgiY0Zetc/Gdpt/DtYcCVdn+JWIdlZ TQ56kNs2Cyg0SQxM1JDg7nWZlCMn070= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=l0qzWhc2; dmarc=none; spf=none (imf07.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=1710215422; a=rsa-sha256; cv=none; b=QcDA28Ek7Fv/llfQRA1ZeYiaTRVpGaOJ3iPyiVmvVYMaKWfdVDZI3mnk8RgPUmr7ABbTdi 5rr0NsE0dG3Dvqw5zp/em0lJyY3z25HpS9hhGWxpf6o3bMzjD07GWdaEemFFx/aP3+eBpM a/I231qygMp8YftDHmaiHvkjLuY+Veg= 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=5f7oX51Aibooo3IXpgcLBXZIyCqaT3ILWc9LUGUXvBw=; b=l0qzWhc2iU3ppMAWcs8Nq28qet ZVg0hb5Lx6E6ojynE61LNjA4EhXqGVlr+L9oMSoPBGWopRCqgcT4Rut9Gl5H5YJJnpoyYztw/C8t5 FVHfQnU6Hjtx5qwb4jbCHxTw7CSo0/bA4VsXHtJ8RNk+yxBZoUW1VifXbkNC2rDAYi1RzsGWl5m1T CuIEnrK3cIJwyr3YiNBA+mTZU9rkHfNTVkfN+4SvJY3JJI0zJTZ2ChTn7vW0HqRkM+q4wnMWJpw5p NimKKXMy6tgZC79PdgkT+MmdGCz5bYcAdSwDTIXhQ0eAP32QtPVYpJCZDm/DUysd0IZxFk8S0jgf9 XIhuAbKQ==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rjt9g-00000002ATz-3k5x; Tue, 12 Mar 2024 03:50:21 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH] mm: Always initialise folio->_deferred_list Date: Tue, 12 Mar 2024 03:50:12 +0000 Message-ID: <20240312035017.516865-1-willy@infradead.org> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 3A45040008 X-Stat-Signature: 36iy9g4syfm97zm8bn998fcbmdzb41ck X-Rspam-User: X-HE-Tag: 1710215421-219250 X-HE-Meta: U2FsdGVkX18xxnOGuH1ux6Ta8a1gY/hbi2nFCh6Q4Nl2l0jlFulhexnTx94u0+jCFWWXkwbFmSA9OXJTRVTTGib182qX4XqEFdT9KlAGjWhNorUrsUfdAtI+irRyViDWcFb/KUvs8dNsxARpe0MOJFJKrgYzLty7tKoupHSiOmEoUP94uv/yTbVeQzo1dSg4ksMRpH0cc881LS0Nv9VI6+GnM4hqTWG5o5rqToBF/kHzIbzJAsrO5Sw3Wfyq88NFLBCnDBy5u0d5U87YUbUxmAGSnmLIvmmw9NmOcYljju71Zr8I7IT+Kdb4nBLto2lhJSJeX9fe42Yp2Nqy3FQNPONKLVdKhAne1U6mosHpQxeta8I52aiOcVR2qX10H0p1fh0YR/589U4SWySBC/yqG0oXbI9ARDVLUxLuL9rmvHGZaVqxwaJW6GAVHfI4jCi5SWllnwl9XczETR8aCtH7eep31pVeu1JE2l9w8BYSDs2uiTZOsPc6XuuZWTwmGZmvLitNcpTrF0KaxBOg6oVhFU3K1worgpJgiGFGC6hr5uvi8eOrHkysmagcctII6KyvdLC6/4IMjH12LSyrU0pPzEAYsKkOH9dmgrSV+wLUOgd0tu//lyT2U79acDWTcehDmHKjUdlYy7qUFmItU/m3yyBf2V2+qMpaDiKMUsMbPduaiFiFKU4A3jtsI4kZQUJTIO58QAQwoUIIBQjzeMkdrBXWdwvkSMhoqTVEoOqUUqlGgPaHY6EQF9xKkWnlBbpGTGTDwAcotMFSklE7v5m93DCcZcP2F9CkgkTHi8C5tsYtewNSaLru8/5WuO5N18ftNQgBcQxRZJCz7GxGho7xn4V1+vMNiXP3IyxJh8pEP6N3IQDYLp7qPs3Mrgy9uecMr511dQxXLus/WmuXAx4uoTDStbNG/Bg3tw+vuw4T3LSBTtZzjwGUWqhariWp3OqP8b4YPVb6qfXBrCT7636 p1nDpvT5 nPy31MnBdkMUMJCgpWZXsbEf/dLsAd+IkacQB4q68K/P+AWsYHU8tES2rcr4RmGBEwlzKBLgORhDGTGvycP9ABOgrdgYjlvbyEyxvxuehSGfTkavTeIWRDpp/GvXwioBWNodWcukC3sF9LSFbPkEWUGq2LEvVF/vbc73s6xm5OA6IbClMnnsiCxbasXRK7+H0cmwJCJEYzYdbNTbTE6MRk2KLHR7X1yeCgfzv 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) --- mm/huge_memory.c | 2 -- mm/internal.h | 2 ++ mm/memcontrol.c | 2 ++ mm/page_alloc.c | 9 +++++---- 4 files changed, 9 insertions(+), 6 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/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 138bcfa18234..e2334c4ee550 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -7483,6 +7483,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 62240014a498..8374ba9b6249 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) {