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: 126951 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp1073337vqo; Thu, 27 Jul 2023 05:49:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlHFKH0hr86aOg1Dl9EzKdxQxOO6dH5ncPOj+KHN30OrExtsbA95WKGaS0x9YWSrIZXOWuXq X-Received: by 2002:a17:90a:c385:b0:267:ee56:4c59 with SMTP id h5-20020a17090ac38500b00267ee564c59mr3562127pjt.35.1690462173755; Thu, 27 Jul 2023 05:49:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690462173; cv=none; d=google.com; s=arc-20160816; b=ZISec5MFSulk5YC1NhE9G7n7s3y7o1ANI+ISNCD/qE3u2+DZWMnhE778xos0OQ+SC3 aGo+wOLPfftc2VtUFrmX9N7/1nF7yMz1571SHjxBqADdgvKx6CYU+HuJHLUpHqn+37nD X9nwxYe7o4fIMB5R0k22Ud7wIObCQdEEZLJIJliK2aAWwTPNhMlwOhzsjBeQb/+PnIxt zAGnlLUHyAsMaJpYlv5Z6scw2NNmALTszksJ9ssixZLatVz4DdASARnIb2SFZ3xOe4yq yVbIgC3jpOzNCZMKcM2ftdOV/ECgAiw2Ag8+LnAWEIOSl4FYWvxGR2/usnCzDx1NKnuo uLzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=azj0KAbXklqebPEZBU9V1Om7Khs08O1+vwe8Evny4eU=; fh=eUbl4v09I/Ha4OhmJ6gzDr/GCs46/1skqMRau+2m7SY=; b=l1am01V9dswTEpSf4BH6PJlN22a9unfuQK/c/IuseM+Qq7gOI1mb8enkVvyEPSRIo7 Ls7NnMw9nRuwNfGLM2S2A864i0kLokYe4H/rBqe+PcEuj/N/ZVEh5B04RR9JVXwlfxIK VcA8xo9ilu+rvJlv3WYY/xWkHg4afvhJV8EZPn07qESA4+D31+PkhJbpV9IV67/Z8XBo JmJo45YTrlBCvH4UW4IBPzKb7PHCDmTI+V2OJ7F8lE+bgysGJjvwJ25MasAPLoADgz9t 6vvs62lABaI+B8SahClIN4WnsaDsUH+2P4ztv2cP0bsnc7eDXNNQOa9ZvQEYmnR3xGI2 vqCg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o7-20020a17090ad24700b00262ee948d18si2817004pjw.132.2023.07.27.05.49.20; Thu, 27 Jul 2023 05:49:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232716AbjG0L47 (ORCPT + 99 others); Thu, 27 Jul 2023 07:56:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233573AbjG0L44 (ORCPT ); Thu, 27 Jul 2023 07:56:56 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84B0A2738 for ; Thu, 27 Jul 2023 04:56:52 -0700 (PDT) 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772578064455558674 X-GMAIL-MSGID: 1772578064455558674 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: 126941 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp1057689vqo; Thu, 27 Jul 2023 05:21:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlHJqonzYp/gutZzC67hytuoemg7wVwjvnYqvmFrRYKC6wva6XUfS0Xgdr/FrjiEqtXsNec8 X-Received: by 2002:a17:906:209a:b0:99b:5abb:8caf with SMTP id 26-20020a170906209a00b0099b5abb8cafmr1656772ejq.44.1690460517181; Thu, 27 Jul 2023 05:21:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690460517; cv=none; d=google.com; s=arc-20160816; b=WJxUeTUKc23HhV1WbOH4BoJM0CclkffM1tjaKAnpDfsyIRk+DV0apuCjZ9QqBBXwjU rE+yORTkqzGw58xgLEz6DDbnasbfwS+sxFk/FNQ2FzJYqmf87PcGlwhYHZdR5Rsx8LGm /XZJulhFyYANfXU31UmfJCJ+B7UTtfNeAjhm4LYVuXPWgoQpDEw6wTufiA8iVLhgwtdK KkohiniTa5xxeKcjMsiPG3aLzdD7ndG/CGDNJAq1eR1+2vCiLRdOGKIGYTXhB3s0RBz0 UykY8vSiMo+KdKpW238bM7lzASzxoThm+vyUXTYw0B2Xwp3TEcyaqNdnDVp6GID1W6ss gqVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=MvyH4AFrYOxo0odqqElQhuARJ/c2riZFZSUjGAvlpN0=; fh=eUbl4v09I/Ha4OhmJ6gzDr/GCs46/1skqMRau+2m7SY=; b=eK4BaAasV/VR4HNv07sUxTipsojp5cmbqjUj2jIzXYRJSsqv2Pprm8UWPHZ4h4eQP0 4ltPNBjlZJ4mOTUvCHQkOsYhne+sQ96+qWe0/ARkd8PtzQDTQ75ccJtDYh46qTZeZTYk VurtE4iRBTb+QysV++Bztwv0AHvWPO8nOQM+fa0SrtT9JocDv92eOxSq8ltEgyBDQNfI M505/I+pNNbEWxLS2CR4U9h5feP1rip6oJ+MxWpnvz9jk2/rNWs0Dx3vH5MoGzmiXo54 KGpjv57L6A+iPJSmh5Nur8Avtt1fbdgeJKDxlFnC2N46h8ht00uQaYc6ahhUILY3OzzZ A+Tg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lu22-20020a170906fad600b009938cb10548si933954ejb.549.2023.07.27.05.21.32; Thu, 27 Jul 2023 05:21:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233606AbjG0L5C (ORCPT + 99 others); Thu, 27 Jul 2023 07:57:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233574AbjG0L44 (ORCPT ); Thu, 27 Jul 2023 07:56:56 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B1A52D4B for ; Thu, 27 Jul 2023 04:56:53 -0700 (PDT) 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772576327271747850 X-GMAIL-MSGID: 1772576327271747850 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: 126942 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp1057702vqo; Thu, 27 Jul 2023 05:21:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlEWsof+sqkckFymbQDW6NHDoVeNYyrly9xq4qcS8foOUhHRWY8XJk9KnqNXXSj6kHkwNeJy X-Received: by 2002:a05:651c:106:b0:2b6:c790:150a with SMTP id a6-20020a05651c010600b002b6c790150amr1725615ljb.22.1690460518931; Thu, 27 Jul 2023 05:21:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690460518; cv=none; d=google.com; s=arc-20160816; b=Kodd0aBwYKnqu4JFjAVuUmtnTSj4ENGDUMfZwh5blC+8toXYWNfnVGX4IBJQI3fOzj pX1M8JE+h9Yh6LZD8X/CFFP2qmpKqVcJi2qwWBz2a39wa5xPagx9b6S5QMFTuAJLSlUk 42CM6xWj3tn3u/BDD0DBf44+XSf77esFo8G6M25BILK+SQb7jW8/92lvQ6bMMJqj125y p6tqoyVZ8JwlAn5isdLpqi6NJpGnzmweNWohSl5U789iPfoFsFArLZKLvs5iIRJ3ieQL C1DB8KuAorRqN2BxKySaDo1tDj0msltL4p3UjuPi+qMf/+N6bFtVxBeI5ZwTjSO3Soid 3nzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=4nI5Th4Lolt/vdprRi+7d6+NL9neMGjB5HZ5+RCajoc=; fh=eUbl4v09I/Ha4OhmJ6gzDr/GCs46/1skqMRau+2m7SY=; b=fjsCDfx0VajQ/LHls3cgp6OgFDUBPvkXnrCFSphy0GthxbzKh7qTp5EQ/BrTwAbOqP C23NSY7o5s97ppawZgK9pQ0Q9NVsmHWAH/1mxrD1H8N+U8W6syyw4zs47Q2crmFBk8/O mIsO5i+o3Xe/pqDH0pCE8nQc/kN6aum6kW0sYoHV22eUNre5ukURfFE48yxMN4AvijHi A4s2aFPorRar0u3gMJ/JmAVDCv2c30IUd56z+shqjyWz/cU/FM+KZr7YhFofm3fpk5Dq PXEHfp55qi1VaNtWSaG101CydZoJycwT7RURu3cURjq5D4p0PJpt6HlzH6lHmabqJusx y9XQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cf24-20020a170906b2d800b009877bb42154si929823ejb.465.2023.07.27.05.21.34; Thu, 27 Jul 2023 05:21:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233580AbjG0L5I (ORCPT + 99 others); Thu, 27 Jul 2023 07:57:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233589AbjG0L46 (ORCPT ); Thu, 27 Jul 2023 07:56:58 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0F122D54 for ; Thu, 27 Jul 2023 04:56:54 -0700 (PDT) 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772576328600275638 X-GMAIL-MSGID: 1772576328600275638 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: 126940 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp1057683vqo; Thu, 27 Jul 2023 05:21:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlEhZLRzwczGGdsID8+o9sZrTNL5Z62E7OFqm9tvoJxBcwVzL2e6bRsLXpQSlywRWetZlgu+ X-Received: by 2002:aa7:d5c2:0:b0:521:ad49:8493 with SMTP id d2-20020aa7d5c2000000b00521ad498493mr2228077eds.6.1690460516618; Thu, 27 Jul 2023 05:21:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690460516; cv=none; d=google.com; s=arc-20160816; b=vWyn+iXxdIWRJHRDitZoR5lZr5pCPGxLMXk2Hxbl/wNI7ZhsVV8YbLNjMGtiqkRK5+ iyg5NqUj9ZleH7hhDyJz4gksSrYt+OWI780Y17CEu6tm8qR1AwsZ+pwFwbbFjAcKxq2Q J7MQrTw31hQi/qlvQAZ67b2s3XwsXy2lFIBVY/jnhJgcpL8O9lsBQcJMkBNPZs2LZimb lk/xtnaAGueXT9y8xzJns8h4Xs+o5do3bvPAqQ41x+tTVb+JwbkAH1kH99525unonGoe F19xdrlB9M32o/WAV+bPxce070fKuFIZhbvlAB2tMbM4v0hQSNKvT2mRUVOn6CK4cwvS Fblw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=eZUV+TNE8UsbdqdXNv32iwr8mS0ZkYc+Ycyp7xM8xCw=; fh=eUbl4v09I/Ha4OhmJ6gzDr/GCs46/1skqMRau+2m7SY=; b=Velw454V1sXunAeGwovnqcyCZ3LflShwuS1IbfO27pjeUEzJE8+PfhqqNF6r10rMd+ 8Llw4SUUGWQkl1roTUmwEHTQ7XPLaFNEH+YzTkDKzGSY8xCI91T3VmezrII2tAjPiTqd xcXRYwbtRI7KjpAfLc9Nrl9yicFU5d/HpluXOlluE5bRNghPj+is0mIyTucVmZPCmE/Z pDeraHbKf31VUTO4GrIvW6JPjposPUOBOyZ9d5jlrq10YuFnsmLMeKaBCIQoiYDcxmuN BGMyuzAAy7HBdT/L1f1gkAJ22yxdjTh+kyzmJTnm4vlsM5sDrFZDqyfN4WbRShieOuCC oSNQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s13-20020aa7c54d000000b0052258f550ffsi852083edr.500.2023.07.27.05.21.32; Thu, 27 Jul 2023 05:21:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233642AbjG0L5G (ORCPT + 99 others); Thu, 27 Jul 2023 07:57:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233580AbjG0L46 (ORCPT ); Thu, 27 Jul 2023 07:56:58 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DD122D4E for ; Thu, 27 Jul 2023 04:56:54 -0700 (PDT) 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772576326772905115 X-GMAIL-MSGID: 1772576326772905115 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; /*