From patchwork Fri Apr 12 19:35:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13628286 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 1D884C4345F for ; Fri, 12 Apr 2024 19:35:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A6B946B0098; Fri, 12 Apr 2024 15:35:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A1AD06B0099; Fri, 12 Apr 2024 15:35:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B9F56B009A; Fri, 12 Apr 2024 15:35:26 -0400 (EDT) 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 65CD86B0098 for ; Fri, 12 Apr 2024 15:35:26 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 364E8C0206 for ; Fri, 12 Apr 2024 19:35:26 +0000 (UTC) X-FDA: 82001883852.17.D3416CE Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP id 82C2C10000A for ; Fri, 12 Apr 2024 19:35:24 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=eEyQtPt+; dmarc=none; spf=none (imf14.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=1712950524; 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=DI0hgg7M0ok1w+kh42kKZu57KLd8qYkUQd3yT6L4EaQ=; b=KOrTPSO9wBEq0TiP1VQmkv0rbM5Sr7EISFjfkS1SDH09pQNTwE1MRq7eznvGA1FtDtN8BC U9SFd6O29WJQADGB9Aqxj9pXVKQNwGnxqWY7y6yHZ449Jtmrcblz93JmbZFLYn6p1z/1W4 XkPjJldqQIpQ4cyNSCIeZddfYFXbmg8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=eEyQtPt+; dmarc=none; spf=none (imf14.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=1712950524; a=rsa-sha256; cv=none; b=KFA8KzIqEwo7+Zaw4QZmqvZ/nGxwMd736sYiKW09szp9tKCMEyU2qDuKbn8rMqYymypDYt Op+mTJGjAc+/hRmj+YMGAnFzyOi/wIl46K8EBnSQRzaeOf/SXPDRfV9ZQDyVwpuZllCEqI 9JU3y20Dcow7OF54sxk35Z9jUtzJMdU= 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=DI0hgg7M0ok1w+kh42kKZu57KLd8qYkUQd3yT6L4EaQ=; b=eEyQtPt+R5x22q7wRru9TRM7oD now8JHnPu+Ph30VG8k8d+TDwV9YW43OvUOjEfXDCUl99JtQXus0yt7HkwhOsWtYZLE2hAGi4BnXzM UurUWwdGem5JJV47mj5fACdBUlAhpXnwN9XgiSHBiANBaOsFA5e7LBzjv8tZ2wZUPlPzzybabo0KU uz6f0YZduxASr5JQ9BtfNm01L3rrvQtCWylqYg8XL02kTcSSoPvH2NU+jQ6QuLV0iq5fakEpn239U eIV2bTX8hVU+d3HqNEpIHb3+k0HHSIuEzjTF2c2bl0sI/jeiq9WkPcF4L6krmhSCdpsMDGRHd67Ei bUR0SYqQ==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvMg4-00000009t9s-0h7i; Fri, 12 Apr 2024 19:35:12 +0000 From: "Matthew Wilcox (Oracle)" To: Miaohe Lin Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, Jane Chu Subject: [PATCH v3 08/11] mm/memory-failure: Convert hwpoison_user_mappings to take a folio Date: Fri, 12 Apr 2024 20:35:05 +0100 Message-ID: <20240412193510.2356957-9-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412193510.2356957-1-willy@infradead.org> References: <20240412193510.2356957-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 82C2C10000A X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 78jx5qkbxd8fyh7g43sgqagzc9j7cpca X-HE-Tag: 1712950524-685736 X-HE-Meta: U2FsdGVkX1/Lhp2q3vbafyZjLUDAQNybNwUv1g90SEg9q2jdjki7e0kzLZFZo4wlqtnjTm1sFyFJFylEd3DCLZMNJjqA3nz+FWGQVt07qVKi0tIh1vrTmNMJwUSLZaFxM0qV2kZ3jmjxmfh5SbXfjrEv3HcYmGlfKASjYSUrmfeUoJuxZZ5co7vpNxAl7J/oYSLQYuJgzGO20Lp3F3rtQYOTigqHY/nJkej+Mf3YYqLA5AaJDhvsEzA4dYF63dabCejHYsdhE30Mq+zj3TTz74SbgMnVw1EcH1vnx8Focp7spcJvjGfXUCKpaPYtMq2UvPcrMj+umVA3s9P47/DOsT6TDEqfO7MjZ+Lh5sOcQm3i1w3+Kp+gTIeykXbRKRMrH4EXDFA4GTBqXeXC67zagJMYuoXNC0V1/eoI60U6dEdaBDJdg13xB5Pr8TJb+PgnvrumkUHg6T2Pn5fIVSZZ0pQqbugG8eBJVpXQkCbbZeX0bmO2di1q2qGbkicMHA2c995XP2Rmrnzm49iI6XASJH0wQb3Urro60y3poHRpu/tSSYbe0LZuLOMThfcXh8DgXFBxYS1FPw9MlNPnMUZiCThRO7NpJ8DY5/HVQukZ5jFbk4IPKDenpk8AoXhT70bHVVVgtDy2UcntuyLpCPTisn/EngNeSOlM+vWsevfc3VhkWIDDFZORmztEoCm5e8OJx5wIFfBUKstjfqhWIN4TQG5WacwVaiGX4aYyG1icNaTCXISyuifvSSf2Biw8ds4L/OYoJzhQZDKwdfTmGeAOo4E3T6woHXlhrHzyvLJSqpQc4XXp9qAlLB8Quym65M2x+PzWKVoROYuvu9/ibUL/SNVeJR5s5fC7yd80E468PLJ0WV5DtGpNy5d30QQLfl4p0vJL4j+ZTotrnIL863T8SBA1wyJdA+OmZ5U20rb/yEobZUgO+Up9U0nVk5PfD9KmcNQ+UyXQeIhhLjiDJqM sl093k+h FbOSlEjjO403LtT8ntbE5U2/64ko4D0dRSW3SDM8IwjKx+tiFq52BGGNfzSTFQSufnxfP+GHumXtAPKZFjQdrvS40aG2WrCq5NRyJ01KnTvTiMIQsbmoiH8C1cijm0IuGIodOz+7Gb+w6ut3LLISV/ZHzXvY7TJ04OrS0soDHtPFaIqbMF/pk84YGQVrLhlPadAAkbSQ+ZITAa2thhCaR9SY8OokP5GJ63IAjiPgWnrszZOYrDzY9wPmUDOSiJWBIa/xIn2qDNuWI/1uKYbrYfHonnQ== 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: Pass the folio from the callers, and use it throughout instead of hpage. Saves dozens of calls to compound_head(). Acked-by: Miaohe Lin Reviewed-by: Jane Chu Signed-off-by: Matthew Wilcox (Oracle) --- mm/memory-failure.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 2c12bcc9c550..0fcf749682ab 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1553,24 +1553,24 @@ static int get_hwpoison_page(struct page *p, unsigned long flags) * Do all that is necessary to remove user space mappings. Unmap * the pages and send SIGBUS to the processes if the data was dirty. */ -static bool hwpoison_user_mappings(struct page *p, unsigned long pfn, - int flags, struct page *hpage) +static bool hwpoison_user_mappings(struct folio *folio, struct page *p, + unsigned long pfn, int flags) { - struct folio *folio = page_folio(hpage); enum ttu_flags ttu = TTU_IGNORE_MLOCK | TTU_SYNC | TTU_HWPOISON; struct address_space *mapping; LIST_HEAD(tokill); bool unmap_success; int forcekill; - bool mlocked = PageMlocked(hpage); + bool mlocked = folio_test_mlocked(folio); /* * Here we are interested only in user-mapped pages, so skip any * other types of pages. */ - if (PageReserved(p) || PageSlab(p) || PageTable(p) || PageOffline(p)) + if (folio_test_reserved(folio) || folio_test_slab(folio) || + folio_test_pgtable(folio) || folio_test_offline(folio)) return true; - if (!(PageLRU(hpage) || PageHuge(p))) + if (!(folio_test_lru(folio) || folio_test_hugetlb(folio))) return true; /* @@ -1580,7 +1580,7 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn, if (!page_mapped(p)) return true; - if (PageSwapCache(p)) { + if (folio_test_swapcache(folio)) { pr_err("%#lx: keeping poisoned page in swap cache\n", pfn); ttu &= ~TTU_HWPOISON; } @@ -1591,11 +1591,11 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn, * XXX: the dirty test could be racy: set_page_dirty() may not always * be called inside page lock (it's recommended but not enforced). */ - mapping = page_mapping(hpage); - if (!(flags & MF_MUST_KILL) && !PageDirty(hpage) && mapping && + mapping = folio_mapping(folio); + if (!(flags & MF_MUST_KILL) && !folio_test_dirty(folio) && mapping && mapping_can_writeback(mapping)) { - if (page_mkclean(hpage)) { - SetPageDirty(hpage); + if (folio_mkclean(folio)) { + folio_set_dirty(folio); } else { ttu &= ~TTU_HWPOISON; pr_info("%#lx: corrupted page was clean: dropped without side effects\n", @@ -1610,7 +1610,7 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn, */ collect_procs(folio, p, &tokill, flags & MF_ACTION_REQUIRED); - if (PageHuge(hpage) && !PageAnon(hpage)) { + if (folio_test_hugetlb(folio) && !folio_test_anon(folio)) { /* * For hugetlb pages in shared mappings, try_to_unmap * could potentially call huge_pmd_unshare. Because of @@ -1650,7 +1650,7 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn, * use a more force-full uncatchable kill to prevent * any accesses to the poisoned memory. */ - forcekill = PageDirty(hpage) || (flags & MF_MUST_KILL) || + forcekill = folio_test_dirty(folio) || (flags & MF_MUST_KILL) || !unmap_success; kill_procs(&tokill, forcekill, !unmap_success, pfn, flags); @@ -2094,7 +2094,7 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb page_flags = folio->flags; - if (!hwpoison_user_mappings(p, pfn, flags, &folio->page)) { + if (!hwpoison_user_mappings(folio, p, pfn, flags)) { folio_unlock(folio); return action_result(pfn, MF_MSG_UNMAP_FAILED, MF_IGNORED); } @@ -2361,7 +2361,7 @@ int memory_failure(unsigned long pfn, int flags) * Now take care of user space mappings. * Abort on fail: __filemap_remove_folio() assumes unmapped page. */ - if (!hwpoison_user_mappings(p, pfn, flags, p)) { + if (!hwpoison_user_mappings(folio, p, pfn, flags)) { res = action_result(pfn, MF_MSG_UNMAP_FAILED, MF_IGNORED); goto unlock_page; }