From patchwork Thu Jul 27 11:56:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 13330021 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 A4FE0C41513 for ; Thu, 27 Jul 2023 11:57:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D7266B007E; Thu, 27 Jul 2023 07:57:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2EBAF6B0078; Thu, 27 Jul 2023 07:57:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13D726B007D; Thu, 27 Jul 2023 07:57:02 -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 E46A86B0078 for ; Thu, 27 Jul 2023 07:57:01 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C4233B2B05 for ; Thu, 27 Jul 2023 11:57:01 +0000 (UTC) X-FDA: 81057240642.14.450FF90 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf18.hostedemail.com (Postfix) with ESMTP id 6BEA21C000A for ; Thu, 27 Jul 2023 11:56:56 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf18.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690459018; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=azj0KAbXklqebPEZBU9V1Om7Khs08O1+vwe8Evny4eU=; b=LSj6qSeo/p6I91fxn8PLpvcfWY6T4/KN49wmPoZ2iBWbA8WA95Bldnm4Eiztvx0Puqc4W2 Z2qBBc+Kk2hAZ73KQGZG5hY70I91bf49jxKLKjBsiCJ1F4LH4ThxjAG7a8M/+QDP5Tcg76 Rjcj9SADYAOkVe9G6kFAxN0z8u0jPAQ= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf18.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690459018; a=rsa-sha256; cv=none; b=AjVdMXOR4yDUWRPzaObsqafQFnsvz8fflyqMu65LuddJfcLZ//Z7xPKtxuZWXbYhG5VJBe v6DI1F20XsNBcNDQEzA1uvyp8mTWGAHAFAh45uTjkWWl+hH9Os2Gz7UUl7nNE0c/3Z7Gf5 QR6YQ/+P5hh+ayGXE7jN+nae8OIu4DM= Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RBTk351PczrS0M; Thu, 27 Jul 2023 19:55:55 +0800 (CST) Received: from huawei.com (10.174.151.185) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 27 Jul 2023 19:56:50 +0800 From: Miaohe Lin To: , CC: , , , Subject: [PATCH v2 1/4] mm/swapfile: fix wrong swap entry type for hwpoisoned swapcache page Date: Thu, 27 Jul 2023 19:56:40 +0800 Message-ID: <20230727115643.639741-2-linmiaohe@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230727115643.639741-1-linmiaohe@huawei.com> References: <20230727115643.639741-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 6BEA21C000A X-Stat-Signature: bjzhix641usw4s1naysjt7uhq3ukjnq4 X-Rspam-User: X-HE-Tag: 1690459016-198131 X-HE-Meta: U2FsdGVkX18VGvXH6Ve9pjqVqFy0zbtQG2X/1LNyOC1YlonqMftaG/+ByW7D2YPtPFKIaylnn7aTo8ZDMIZlzmb0IEbHbhS7WLE42q3+Yqr8W0qvwRtcs6fUkyiMXRicwlZH/U+o7bnrKu9gsHLYNUhyh8tytkyiCtQuqyB8lzIZhTxrKXvS8E5tjunV+anq+uy83kl3Md82/F7i3iHPGs7YSU3jybvFuiKpEUasZOBBeKb9EkpPQbs8e4P6Yng5Vux/97XjpNmWhmpecpYL0f/aHX5nTh31THuS4k/MLHeVjUz75cyo45yXOSu2FcR7SVQW9nMF+dDthe+ShX0rNnnm0Cw9qQQhJXrboclItKC7TeHxNatpLSwsqGdUQouJd8c6GWd5CejPvc+G85P1EBUJ1w9qSAOWIVmA41y9tArWd+rBLSxM5RhbSsXHy2a9mtOEYzHy/A3jVTi7HowrNWktPNDa8rIfpNg9DkGEvD1YTTsaf472zveYKYHdDbJR1M/HdcCE8ENgyawEUi8k2mxOcMR1xj+m7zpO/J992rGpsXwGSOxg0H1/wxef3nLQ3ptZ/D5ok1j5p3zZJUh82wOjiCWrqfLR1lQ/UFpWKl1dyPz5bQbFJEE7Yfvz80qdsVTNr0llhKD3FySDnHcpleIdNNps8BzgXv6Eyy50sDV2mPY/ZCfVzdO8naDL2NuMuiQ4okJb0U1+PXFbR1yxa2guk6mxI0YHsAqI9piAKlIpRXktnb5ihbd6iIAUjk6IJcFAE/iUD2ye+F6Wv5er6mVsF4i6KghIrExmHpMz96jUKLZ9qJtg+6l4+H3c+hqg3eaamj1Iv5upmNbhslA21n4B4GglpKvyb2ziIwWW50/oklttpI9as6pNfh3N19BECQpqn0jZdowE8dTWw/SS25FiLx/Fztn3Z/GqB/66A121s62YJM98DGV3uluoWsVmCBm43f12jLwmOobLe4v gP7pxfz6 r7Y7WzJNIzPz5my7owAv8tB4XYNPE8gy11nvwHj+zw1Jdk4xNzuC8gl8ybvfRBWMiiCABV0BIyo2ZbvYrPWpb17ughcTrUBL3pV2qbmcVtHLTKZdCT5PEAJ8rqPFJz4eWwmlKzYIILZMwasQ= 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: Hwpoisoned dirty swap cache page is kept in the swap cache and there's simple interception code in do_swap_page() to catch it. But when trying to swapoff, unuse_pte() will wrongly install a general sense of "future accesses are invalid" swap entry for hwpoisoned swap cache page due to unaware of such type of page. The user will receive SIGBUS signal without expected BUS_MCEERR_AR payload. BTW, typo 'hwposioned' is fixed. Fixes: 6b970599e807 ("mm: hwpoison: support recovery from ksm_might_need_to_copy()") Signed-off-by: Miaohe Lin --- mm/ksm.c | 2 ++ mm/swapfile.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 97a9627116fa..74804158ee02 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2794,6 +2794,8 @@ struct page *ksm_might_need_to_copy(struct page *page, anon_vma->root == vma->anon_vma->root) { return page; /* still no need to copy it */ } + if (PageHWPoison(page)) + return ERR_PTR(-EHWPOISON); if (!PageUptodate(page)) return page; /* let do_swap_page report the error */ diff --git a/mm/swapfile.c b/mm/swapfile.c index e04eb9c0482d..0df94c4000ea 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1744,7 +1744,7 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, struct page *swapcache; spinlock_t *ptl; pte_t *pte, new_pte, old_pte; - bool hwposioned = false; + bool hwpoisoned = PageHWPoison(page); int ret = 1; swapcache = page; @@ -1752,7 +1752,7 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, if (unlikely(!page)) return -ENOMEM; else if (unlikely(PTR_ERR(page) == -EHWPOISON)) - hwposioned = true; + hwpoisoned = true; pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); if (unlikely(!pte || !pte_same_as_swp(ptep_get(pte), @@ -1763,11 +1763,11 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, old_pte = ptep_get(pte); - if (unlikely(hwposioned || !PageUptodate(page))) { + if (unlikely(hwpoisoned || !PageUptodate(page))) { swp_entry_t swp_entry; dec_mm_counter(vma->vm_mm, MM_SWAPENTS); - if (hwposioned) { + if (hwpoisoned) { swp_entry = make_hwpoison_entry(swapcache); page = swapcache; } else { From patchwork Thu Jul 27 11:56:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 13330022 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 EE5CEC0015E for ; Thu, 27 Jul 2023 11:57:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C60F36B0074; Thu, 27 Jul 2023 07:57:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BE99F6B0075; Thu, 27 Jul 2023 07:57:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB1B06B0078; Thu, 27 Jul 2023 07:57:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 81D266B0075 for ; Thu, 27 Jul 2023 07:57:01 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 41F16C04A9 for ; Thu, 27 Jul 2023 11:57:01 +0000 (UTC) X-FDA: 81057240642.16.89C54C8 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf20.hostedemail.com (Postfix) with ESMTP id 9379E1C0009 for ; Thu, 27 Jul 2023 11:56:58 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690459019; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MvyH4AFrYOxo0odqqElQhuARJ/c2riZFZSUjGAvlpN0=; b=y0ZGShTbD0OasdZcqavOYiwhyhjaYwSOpHefNTUAKl17rYYDMa6D+WdCQxZDulbf5pCWzw ddqd6q/etFFXQwhYyM9yMGcyYVuipDuoxejPAkLqSDK5tvkcay5wh4wUVnabDybdV3Y9m7 PgBlNcD40ZHcRL5rMyObF62rrhi0gYY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690459019; a=rsa-sha256; cv=none; b=LQ4VWgTSc8xhbsMrlEva6u/vbKoAyMsYtik4AzC+faiPJyON7xvE6c6N6ASFhtwfCO60Og iDWLXwIhdl0lNC+1/VGcl4AlYALowVrMRoMlyB6KjOXNxlX4zrvOtQso2C7Kiz8kJtMBEr 0ZBmOmrK2aHJjMeaivdZ+EnrBW9dV70= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4RBTh66H48zLntw; Thu, 27 Jul 2023 19:54:14 +0800 (CST) Received: from huawei.com (10.174.151.185) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 27 Jul 2023 19:56:50 +0800 From: Miaohe Lin To: , CC: , , , Subject: [PATCH v2 2/4] mm: memory-failure: fix potential unexpected return value from unpoison_memory() Date: Thu, 27 Jul 2023 19:56:41 +0800 Message-ID: <20230727115643.639741-3-linmiaohe@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230727115643.639741-1-linmiaohe@huawei.com> References: <20230727115643.639741-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 9379E1C0009 X-Rspam-User: X-Stat-Signature: 9pr1ngxk6pyk4tgkk8epb1dqrr4wd91t X-Rspamd-Server: rspam03 X-HE-Tag: 1690459018-403242 X-HE-Meta: U2FsdGVkX1+dFsvoLH4b+gWG4aPtAkOJU9FBsvv9BMROdHFS7wq1auB/Vg6IXLBxz1ruCShzEQ37Sh35xtdaTo03znFq4AWl2UxYrL12bu0zJAR2lWhO9Z/UpoN0WQJjSxxqDauDWWjDqxi/zg1ieyTOMpswXTpGxLIvkAmZLaC8NhRl5BE+iuF13pjd1iu8r3G3appKW/c1BE6XuNU1JgglCLv3x4J8lZh1JPGcfhNm9rZbBfcDdjAaf8+nsXMrrfTKz/YUqvv0y06JvHVtiGNwg+4kDoDZevI1FJddtHnguU+xkw10H5kOezCyJ4meQU8fDO3yU/1hWfg1a73h8Ryr9tjNbm09K/Xkm8LW3x+KFb2PB6oB+16W6aU4WyqcJH1IeutkclXTeFqfGUhEIY+btYEjRlN9ffQfbhELuQCHi/Jl8YVwn7QxBMwFYGl62ZkptQAFrXGJnuVnnBz/I930YXXSrg1fQIY8g5YUBn9PDjezKb728RHR2TtvEHsBGRBhVza4vAJTUwNVtL+XSZmnYKCRC0CrZrDLpDO5K+b694Co/caBi6DCiv3VwF/aGroqlPWbdXXUYrHsgr0ON0Gumm568RRYzGgxeQ70lRqeypnAdxVKJpn9gqyH+VCqdEUIU0uMardrUJzl1ADQ9MKWztc+6PsgztF50lJ1J/sdey5LA4LJ19M8hEhsF1p8+R2/q+NR7ODjcwSBstIhdftiRsU0aJAnWeUqGH+EX72oiZcAtB9gni7Bh3270EaIjUc5ovO7R+0FwkSeMdyAjUmmI8PeUysJgIOhZcxPlnvKvSSCo4hfOZVidf3hn16WBtkkMGZFQ7O75MK9AVgL43CSInjyq5RvothRp/wYiqDwMbHFV7zxcGdHPZ06aqs69JNWQa0KbzwLk8RSBLZwdQAv8jX818NupFw1QjYj9xTy4GUhxdrIDiKscIG6bEbBFUTUicnTOaaAkWImmH7 HYyKHhuT T1O6/ym55vbWPKSxu6m8jvcDh5kL5Htp7xO4ebNE59GEFANP6Y5LEGOp8lBUr1UdRSPIUudruZo+T+5G/tphBYih8N35+sEPAreEPm6LpHoVluNdF7lKMFRL4S43OJGWMnecnAHbYIm/1J6OwJzlWwkY2QRVUPwxvBxQBtut3dBkL67ECAFBhIDbvvdMvMFFPQ2N5 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: If unpoison_memory() fails to clear page hwpoisoned flag, return value ret is expected to be -EBUSY. But when get_hwpoison_page() returns 1 and fails to clear page hwpoisoned flag due to races, return value will be unexpected 1 leading to users being confused. And there's a code smell that the variable "ret" is used not only to save the return value of unpoison_memory(), but also the return value from get_hwpoison_page(). Make a further cleanup by using another auto-variable solely to save the return value of get_hwpoison_page() as suggested by Naoya. Fixes: bf181c582588 ("mm/hwpoison: fix unpoison_memory()") Signed-off-by: Miaohe Lin --- mm/memory-failure.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index a114c8c3039c..4a3e88c15631 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2502,7 +2502,7 @@ int unpoison_memory(unsigned long pfn) { struct folio *folio; struct page *p; - int ret = -EBUSY; + int ret = -EBUSY, ghp; unsigned long count = 1; bool huge = false; static DEFINE_RATELIMIT_STATE(unpoison_rs, DEFAULT_RATELIMIT_INTERVAL, @@ -2550,29 +2550,28 @@ int unpoison_memory(unsigned long pfn) if (folio_test_slab(folio) || PageTable(&folio->page) || folio_test_reserved(folio)) goto unlock_mutex; - ret = get_hwpoison_page(p, MF_UNPOISON); - if (!ret) { + ghp = get_hwpoison_page(p, MF_UNPOISON); + if (!ghp) { if (PageHuge(p)) { huge = true; count = folio_free_raw_hwp(folio, false); - if (count == 0) { - ret = -EBUSY; + if (count == 0) goto unlock_mutex; - } } ret = folio_test_clear_hwpoison(folio) ? 0 : -EBUSY; - } else if (ret < 0) { - if (ret == -EHWPOISON) { + } else if (ghp < 0) { + if (ghp == -EHWPOISON) { ret = put_page_back_buddy(p) ? 0 : -EBUSY; - } else + } else { + ret = ghp; unpoison_pr_info("Unpoison: failed to grab page %#lx\n", pfn, &unpoison_rs); + } } else { if (PageHuge(p)) { huge = true; count = folio_free_raw_hwp(folio, false); if (count == 0) { - ret = -EBUSY; folio_put(folio); goto unlock_mutex; } From patchwork Thu Jul 27 11:56:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 13330024 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 A770AC04A94 for ; Thu, 27 Jul 2023 11:57:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A32D6B0075; Thu, 27 Jul 2023 07:57:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 92C436B007B; Thu, 27 Jul 2023 07:57:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D42D6B0080; Thu, 27 Jul 2023 07:57:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 49D956B0075 for ; Thu, 27 Jul 2023 07:57:02 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 164F81A108E for ; Thu, 27 Jul 2023 11:57:02 +0000 (UTC) X-FDA: 81057240684.11.D722B5D Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf15.hostedemail.com (Postfix) with ESMTP id B5A45A0005 for ; Thu, 27 Jul 2023 11:56:57 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690459019; a=rsa-sha256; cv=none; b=1KUYAbcL0MD6HW1QkbGxPVBwOPS9ZeK9R7sKgdYXZ/m/Nskbn9oy+6cguNbsXmEX+jQuHb ZegjV9zYNmx9HM18fVy++084uAbujAxE9KIKgtPVB/O803+nVzfCAovJiBvIZgJg3YIHxL JFtlfYXO1ExOG9o5ixfmzaD4wW7Pqdo= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690459019; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4nI5Th4Lolt/vdprRi+7d6+NL9neMGjB5HZ5+RCajoc=; b=Cv4hBziprMJQS7tVWy4k1sJ4AbtAbl+pGpEjvEN0F9CViIgClC0Hq/jK/W88jzbCSryDJs gHhjp6xJgH7ihnmGtNvbuPa+7CWs+wi/yVvIOYPVWRkkjXzcmSB3sjKAfHdy8Rgi0f9ciu nMgyqhUnlRigIu/wo5/OeRpxOVEzxGU= Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RBTgN0WB2ztRc7; Thu, 27 Jul 2023 19:53:36 +0800 (CST) Received: from huawei.com (10.174.151.185) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 27 Jul 2023 19:56:51 +0800 From: Miaohe Lin To: , CC: , , , Subject: [PATCH v2 3/4] mm: memory-failure: avoid false hwpoison page mapped error info Date: Thu, 27 Jul 2023 19:56:42 +0800 Message-ID: <20230727115643.639741-4-linmiaohe@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230727115643.639741-1-linmiaohe@huawei.com> References: <20230727115643.639741-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B5A45A0005 X-Stat-Signature: zpge9nkyaa4bosjquksmpfbs97p1ymgw X-HE-Tag: 1690459017-700258 X-HE-Meta: U2FsdGVkX1+ci03Hv98E7t1ECorJ0SE5ikj73tv/hSSsJtTEOAN0SOivNd87MH6G4uySKcUyAvFcORNPh5ZBvR6+r08lH9iyZ/Y5qExIcSvVpddtDAGLa3+a581ScgeoXlSJpBqFLz7c0ADY+qPvJ4EJZfO2mMeROpUA8J5lnmybzN9Sj4sE1ZKqtjlGnfnkgaE69zh8MWjvdLXTMY3NQZ8/gghoDnMF9I11IVhypnx2Lf3mPj0vq0nxuteqFEC+Wi/NYSMFpbM2jVoW/jIn2HApOG3kjmrCQvFsktK7KPeNTvRK9I1SNkokeccij1jWUFhiZfFnc632q9W85O25yegcOlxoyWgMQECHBiB6hOA3x0d7mrJJsJDn2qeD1KgFphdhmLn6rOSl58GVGOh5cJRLqpFaekIFh+p23tal0/9o1tN4JLhBy6v41tB4PO4h4UjZs9j8F8qvcCsc9w8SzJNxu+AISGvIRbQWEqsuVrO1AHFyotpkfDccGUSCKzhCHHvzwvK1aXPlbbdYVVJJEUMtdPUTjKt6sPAOTfDL94JuqxkD6CrXAtaCczQ/pYxV7LdisDx80lhCnqckhk2dYgjSXKDZzsLDgflVcfuUQfgCLstXnoHm9TG0rID91llKU1BPd4eTK6AsYK1pYNnpKy28/+RBY2DiMWJTfrXMsf59o00/w2d3GpNVH7oq66MuQsO8n0QUJDvythOBFB26mgRle906myLBXVgrMbQ80SZty4JxsLpTPmIiZVhMnbhjpzBKcSXOPWQEN8gX/od5tIJN6eHloSd9kDB3MHO+yS8d/7ro3skpTvKOAJJcMSQmtb5w+D7xrMU4Z6JLtQxE8I9sNl3Co7NCAvfmfSjxcCIF0cb8vSuf7t4F8CmYdKeCSqaXuzLWOZR1xXJzdJYkFyVHvMAgy9lJDgPPGjR2skkwk6FpCn52mhRKLdx0TkxL4dAifpCgsNyfsrV6Gre rYALbHAZ O5J+Npp761EQUfTI2nq9Kw1QDIRomWqhXumiQlBr25CktKM0Z0lh4pBhgkkCm5jaOoPCH7fbIfjt9tFpJUO/AFsbrBUb47+r+bLlbpYIr04qnaEFZyeNh1T3DbQJkOz3Xg9lp01aZf17wOEbkqPpAL0oGEVxqrZcE6gop0Bb5hOlL/GO+OzGC9FQwsDuIzo621tXKic1leAgdGw5FL+57rkqE6VUFTvFSpTqK 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: folio->_mapcount is overloaded in SLAB, so folio_mapped() has to be done after folio_test_slab() is checked. Otherwise slab folio might be treated as a mapped folio leading to false 'Someone maps the hwpoison page' error info. Fixes: 230ac719c500 ("mm/hwpoison: don't try to unpoison containment-failed pages") Signed-off-by: Miaohe Lin Reviewed-by: Matthew Wilcox (Oracle) Acked-by: Naoya Horiguchi --- mm/memory-failure.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 4a3e88c15631..d975a6b224f7 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2535,6 +2535,13 @@ int unpoison_memory(unsigned long pfn) goto unlock_mutex; } + if (folio_test_slab(folio) || PageTable(&folio->page) || folio_test_reserved(folio)) + goto unlock_mutex; + + /* + * Note that folio->_mapcount is overloaded in SLAB, so the simple test + * in folio_mapped() has to be done after folio_test_slab() is checked. + */ if (folio_mapped(folio)) { unpoison_pr_info("Unpoison: Someone maps the hwpoison page %#lx\n", pfn, &unpoison_rs); @@ -2547,9 +2554,6 @@ int unpoison_memory(unsigned long pfn) goto unlock_mutex; } - if (folio_test_slab(folio) || PageTable(&folio->page) || folio_test_reserved(folio)) - goto unlock_mutex; - ghp = get_hwpoison_page(p, MF_UNPOISON); if (!ghp) { if (PageHuge(p)) { From patchwork Thu Jul 27 11:56:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 13330023 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 B351AC001E0 for ; Thu, 27 Jul 2023 11:57:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 600976B0078; Thu, 27 Jul 2023 07:57:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D4236B007B; Thu, 27 Jul 2023 07:57:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D8846B0075; Thu, 27 Jul 2023 07:57:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id F012D6B007B for ; Thu, 27 Jul 2023 07:57:01 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9FED91CA0E4 for ; Thu, 27 Jul 2023 11:57:01 +0000 (UTC) X-FDA: 81057240642.17.2E2B41F Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf06.hostedemail.com (Postfix) with ESMTP id 6FEDF18000E for ; Thu, 27 Jul 2023 11:56:56 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf06.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690459018; a=rsa-sha256; cv=none; b=BfYfdREIxF4HyvlQbIbtH6ta+HGpfRC1PLe/VJEAszC3m8FSf9/13rOJNrNeBt36v6TIgf viOm/VWSd4DVHbt+31inuiCq//CtmWuXEYOJYERafzoQZYpL1EwAfpPuoAm9tAA+ouzc3y zcgyr4sRh+sJR7qBC+bSQmddc58Qykk= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf06.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690459018; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eZUV+TNE8UsbdqdXNv32iwr8mS0ZkYc+Ycyp7xM8xCw=; b=P4yhfbbpE7yQbN9aFlP9VutU7af9ucavIAAWfNIjUwwf3xI3LzWP/IBCHRDnB6U18duLlE eP98wku0yD7jwZKe3DjWtfpZaZdee6sf2ANh+DL7k/wWHNs/bRo3HM19MnyfmMtxKwsbJp 2izx3UryhUjrYoCz9BFffrhUv0umDjY= Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RBTgD4yQxzNmV5; Thu, 27 Jul 2023 19:53:28 +0800 (CST) Received: from huawei.com (10.174.151.185) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 27 Jul 2023 19:56:51 +0800 From: Miaohe Lin To: , CC: , , , Subject: [PATCH v2 4/4] mm: memory-failure: add PageOffline() check Date: Thu, 27 Jul 2023 19:56:43 +0800 Message-ID: <20230727115643.639741-5-linmiaohe@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230727115643.639741-1-linmiaohe@huawei.com> References: <20230727115643.639741-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 6FEDF18000E X-Stat-Signature: 55bhjzkzzggf79dmhqy4ffichn8rk17s X-Rspam-User: X-HE-Tag: 1690459016-863703 X-HE-Meta: U2FsdGVkX1/RygHWbMP4NcrDzx9fWehCNQ4HFvrulqYetuInWzoqN+zD8auTRUiBSALdIct+4Lb/puzVudQ/Zak1EfTJS31rLqQvZb4V0AB+KItFn0jYtFPSkNcc1th5xxJujt7DGgqyRviaaVf4yk1Pe1XK+OvdiIhmj2p6GA7mSCDswaSHCcFDA6z54ODvTyTT2BjXdfTOJIrnE9Iv7a9e1eWlZ9ApOQT0jE21E/xBFPUe5KiUY0+ip5U2cZWHljoorpyH7hZ0x1V9pYnGOQzVBxkjI+rQx6z4nIMr8XM8oR1H3IJJnDbyaBZuY4p5RSoPPHLGt+h0+jlKnUS2zHiAlkBleCdZNDJX6AHwjhmguoKuPl1VB7P86U/qEM3pLhjuSYQJtrET9eoc/rIaImYgee+Y9l/j1BJi3qzIQN5DWwI99i6VTo5FCyL4GVaATjCmNzh98JGO6W9zeuqRiFvm4M7StUtYzF+aqOUo5t9qjztIrVgPUcfjRPsuUR8XwpUvegDlbbEklE0yyLaQDEiIUbSYXJeS7lSZOPDWLXxhjgu8anP9trzfdeGiGtEoSMFZx7ZX2PDqwU3g3uo7zfIohl24+FBc9yZQQcvSPjAJxY9YS0zsKguSmqqomDuzy2+LB+TcsPpQbAyBeC+0UwsB/MqnxNMEqwpk8X14ZXu9bV5OveKc7L7igCRKmNpEaieR3yMks7fQinU6ap1w3EsZbzg2I6TKcx/SxD4JGxjvt/TU4h9Sm1h3rr1YTKt9fGVfBYmVuSZYhbOml/15PxLKsOjtQbym/iwlePQL1zfxMckjoRh9dhlMNfHXYDk2IZVPLMafR07GlOZpDBChLPdMNj89F7/O7/2I2O6k7lMU+cjytsjho1OFEVqkGVuGXzylzxeT4KhZQtrCsbFoqcPqvrvFF5oJUkwSYMiMsPGiAwJ6g/LZSKJ/QNhfjnI5ODPcZgwe68SRPy9D36n PPqv62ym 8qIer3kn+gL62yIuHSt6+5AtUXSR/+wSyuY2A6WWUCu9B3lI22goG51uXq6R9ZEaIPJKV3iOaNcrhJnrVKY2pkSug2YAgRk6I/T753Tjrje/QaOd7ld+znbzZ8Bl2GSBEyvV8P098T0i3GOHkoVQ5bou1aVSP5qSpwNWNIVDpuSyt2KY= 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: Memory failure is not interested in logically offlined page. Skip this type of pages. Signed-off-by: Miaohe Lin Acked-by: Naoya Horiguchi --- mm/memory-failure.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index d975a6b224f7..e4c4b9dc852f 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1561,7 +1561,7 @@ static bool hwpoison_user_mappings(struct page *p, unsigned long pfn, * Here we are interested only in user-mapped pages, so skip any * other types of pages. */ - if (PageReserved(p) || PageSlab(p) || PageTable(p)) + if (PageReserved(p) || PageSlab(p) || PageTable(p) || PageOffline(p)) return true; if (!(PageLRU(hpage) || PageHuge(p))) return true; @@ -2535,7 +2535,8 @@ int unpoison_memory(unsigned long pfn) goto unlock_mutex; } - if (folio_test_slab(folio) || PageTable(&folio->page) || folio_test_reserved(folio)) + if (folio_test_slab(folio) || PageTable(&folio->page) || + folio_test_reserved(folio) || PageOffline(&folio->page)) goto unlock_mutex; /*