From nobody Tue Feb 10 04:12:33 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C37EC04A94 for ; Thu, 27 Jul 2023 11:57:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233626AbjG0L5D (ORCPT ); Thu, 27 Jul 2023 07:57:03 -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 Content-Transfer-Encoding: quoted-printable 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 =3D -EBUSY; + int ret =3D -EBUSY, ghp; unsigned long count =3D 1; bool huge =3D 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_reser= ved(folio)) goto unlock_mutex; =20 - ret =3D get_hwpoison_page(p, MF_UNPOISON); - if (!ret) { + ghp =3D get_hwpoison_page(p, MF_UNPOISON); + if (!ghp) { if (PageHuge(p)) { huge =3D true; count =3D folio_free_raw_hwp(folio, false); - if (count =3D=3D 0) { - ret =3D -EBUSY; + if (count =3D=3D 0) goto unlock_mutex; - } } ret =3D folio_test_clear_hwpoison(folio) ? 0 : -EBUSY; - } else if (ret < 0) { - if (ret =3D=3D -EHWPOISON) { + } else if (ghp < 0) { + if (ghp =3D=3D -EHWPOISON) { ret =3D put_page_back_buddy(p) ? 0 : -EBUSY; - } else + } else { + ret =3D ghp; unpoison_pr_info("Unpoison: failed to grab page %#lx\n", pfn, &unpoison_rs); + } } else { if (PageHuge(p)) { huge =3D true; count =3D folio_free_raw_hwp(folio, false); if (count =3D=3D 0) { - ret =3D -EBUSY; folio_put(folio); goto unlock_mutex; } --=20 2.33.0