From patchwork Fri Oct 21 08:46:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 6561 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp565600wrr; Fri, 21 Oct 2022 01:32:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4TA/F6oiMxOlxvgWoEZDdpKX+s3C75XIjaYVCu+6HmLGszE9b5LtHHiY1nQxcG3z2skXtM X-Received: by 2002:a05:6402:2b8b:b0:43a:5475:f1ae with SMTP id fj11-20020a0564022b8b00b0043a5475f1aemr16178847edb.363.1666341166375; Fri, 21 Oct 2022 01:32:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666341166; cv=none; d=google.com; s=arc-20160816; b=rk9Bd36nb0Yoy2zo3glZzGcr3nKlDqoQpAWrBjDKnBRimASPMnbLnTU2vlr9OXCOHb JrO8adzmc5/1wHFzoKw/btLT72AluAUvlWzxKDLdYiUTr6JDDB2ajZ2LT1XW4iIvL09n 6vlQ5kFKMeeEWFdY9XxVYB2MwYiwHP3ikPxDrZQotL4BYFUySeLJ76NFQoABrEg1BNn9 SR8E17HgPRZe2zgVUi23XGvw1MdbzF1803x/dAnRJ6bYZt5tROnt0Uq1ypWws90WaTck cPZ7Fome4Jed+R1AEx3qv9I11gRqkxbQ06irRMW33++mnULZoQ0ay0843riS6EYWyu7X xrkA== 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 :message-id:date:subject:cc:to:from; bh=SvtD7TEzG/7RYfxd+tmpCjijSpKb3RLAE436DHlzYsE=; b=nss6F45Gwda6+X1dJA/LiCgUjAiX/fAivM3rkiYOAxxnXmWY0fNtCq/fEzW1OTEwdl 1O0QO/ZViurRBsHNYX3fHwb0MPNsuZduAsFrd2SbXgLsbmBWpVGggJ2blMQelMXZqm/J Rkgh0NJ80eDcg6KEGg7StrqHbYkYvOQa4BPQwvGLMbV30FZNlMFsCyKwOEEeLwdS6qhl ScY8ebVgCkChIP4OBg+YkECEJcvCFA+iELb4xMEwzOGaQLsIR7ZJthS+lll5b6BPXbdY q6woSoWCoRCv/hPupcmIeOISA90Hmef5up1e8JDtxIA2GPWRCTsSVeMosUgyv4ZzLulw 4/aA== 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 dn10-20020a17090794ca00b00791a84056d9si6840984ejc.751.2022.10.21.01.32.21; Fri, 21 Oct 2022 01:32:46 -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 S229931AbiJUI1Z (ORCPT + 99 others); Fri, 21 Oct 2022 04:27:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229746AbiJUI1G (ORCPT ); Fri, 21 Oct 2022 04:27:06 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8766D202711 for ; Fri, 21 Oct 2022 01:27:05 -0700 (PDT) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MtyCy4cKBzpVWk; Fri, 21 Oct 2022 16:23:42 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 16:27:01 +0800 Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 16:27:01 +0800 From: Kefeng Wang To: Naoya Horiguchi , Andrew Morton CC: Miaohe Lin , , , Kefeng Wang Subject: [PATCH 1/3] mm: memory-failure: make put_ref_page() more useful Date: Fri, 21 Oct 2022 16:46:09 +0800 Message-ID: <20221021084611.53765-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747285354880454042?= X-GMAIL-MSGID: =?utf-8?q?1747285354880454042?= Pass pfn/flags to put_ref_page(), then check MF_COUNT_INCREASED and drop refcount to make the code look cleaner. Signed-off-by: Kefeng Wang Acked-by: Naoya Horiguchi Reviewed-by: Miaohe Lin --- mm/memory-failure.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index bead6bccc7f2..b94152abb1c9 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1913,17 +1913,25 @@ static inline unsigned long free_raw_hwp_pages(struct page *hpage, bool flag) } #endif /* CONFIG_HUGETLB_PAGE */ +/* Drop the extra refcount in case we come from madvise() */ +static void put_ref_page(unsigned long pfn, int flags) +{ + struct page *page; + + if (!(flags & MF_COUNT_INCREASED)) + return; + + page = pfn_to_page(pfn); + if (page) + put_page(page); +} + static int memory_failure_dev_pagemap(unsigned long pfn, int flags, struct dev_pagemap *pgmap) { - struct page *page = pfn_to_page(pfn); int rc = -ENXIO; - if (flags & MF_COUNT_INCREASED) - /* - * Drop the extra refcount in case we come from madvise(). - */ - put_page(page); + put_ref_page(pfn, flags); /* device metadata space is not recoverable */ if (!pgmap_pfn_valid(pgmap, pfn)) @@ -2516,12 +2524,6 @@ static int soft_offline_in_use_page(struct page *page) return ret; } -static void put_ref_page(struct page *page) -{ - if (page) - put_page(page); -} - /** * soft_offline_page - Soft offline a page. * @pfn: pfn to soft-offline @@ -2550,19 +2552,17 @@ int soft_offline_page(unsigned long pfn, int flags) { int ret; bool try_again = true; - struct page *page, *ref_page = NULL; + struct page *page; WARN_ON_ONCE(!pfn_valid(pfn) && (flags & MF_COUNT_INCREASED)); if (!pfn_valid(pfn)) return -ENXIO; - if (flags & MF_COUNT_INCREASED) - ref_page = pfn_to_page(pfn); /* Only online pages can be soft-offlined (esp., not ZONE_DEVICE). */ page = pfn_to_online_page(pfn); if (!page) { - put_ref_page(ref_page); + put_ref_page(pfn, flags); return -EIO; } @@ -2570,7 +2570,7 @@ int soft_offline_page(unsigned long pfn, int flags) if (PageHWPoison(page)) { pr_info("%s: %#lx page already poisoned\n", __func__, pfn); - put_ref_page(ref_page); + put_ref_page(pfn, flags); mutex_unlock(&mf_mutex); return 0; } From patchwork Fri Oct 21 08:46:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 6554 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp565241wrr; Fri, 21 Oct 2022 01:31:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4zzLGooJF9BzSBTgFhZlaOXtqrBetbW+iCrEk8wQ66ediNCYmiEiUeSiOppQW9To+d2Eip X-Received: by 2002:a65:6bcb:0:b0:44c:3e11:a7ac with SMTP id e11-20020a656bcb000000b0044c3e11a7acmr15712087pgw.274.1666341107885; Fri, 21 Oct 2022 01:31:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666341107; cv=none; d=google.com; s=arc-20160816; b=dazozBc4YLbVYGg3a9XXCEWZNJLH7wWUaAbc5OVk5j+HUfK2o8TBQhL2mCZH3H2h4D QPXM8TIknFtfQ24ndxzYycxQrWBXgl9jCtzyLmaGb+aQ7HDYqa22PehwdhkDMpyA0Yq2 wp/8vz5jxSa2N0OQtRXAQj8HLyJvKsJX6lZiWrylSO0kAXIu1Sr7uK1VOoQ0JfdZKhJa 96AjUWCfxba4/gUdXF/wGqFi6ho8/TaSfwu+KmCBs0PQGDoQND202Dp1786v+ZPtVwGA J9jLdFOehKaqFdlfIvCZdfhlgDehxxzV3j8bdk4exIl5CDgHFqku0IUfiRYdXx9EtSmA 1xBw== 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=UU5kiPJznsCXvUnAokOkugtvK9CpUBlArCg9rxWhxEc=; b=PLv4eeLEXxXdJZo4FTGGQIgdHvxJEx45fPs/hXtaj0H3v5H2/N3JeM6p3mzkuJVdF7 tRopMGXwRLkDCzcET3PlZeuK3SOyxp1kqjDv+9e7of0UbT4Uu5ct+MDcGwnTDn0pcEby lpLdpvzz+BqAV0G8kMDtVgwqMhs5jkL0FllCBI2HWSlREZeS6/n4/dyXKA5sauu34dqu JguSWXXls5Y+nqe4h8JlAsK9n1IiQ4V/THIOn11kP597t/HFUZn1PM7oSYVxv71gV6cJ TJUAkAmiV/j59UmFjpbnpoq9u4IExo6K8pC3JguaSn8wFjq1P/x5r5g2ZD2KOMY49K8C Nmew== 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 j3-20020a170903028300b0017a034f7246si29846055plr.560.2022.10.21.01.31.34; Fri, 21 Oct 2022 01:31:47 -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 S229958AbiJUI1e (ORCPT + 99 others); Fri, 21 Oct 2022 04:27:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229952AbiJUI1P (ORCPT ); Fri, 21 Oct 2022 04:27:15 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0AB51FB7AB for ; Fri, 21 Oct 2022 01:27:14 -0700 (PDT) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MtyBd3zLvzVj4w; Fri, 21 Oct 2022 16:22:33 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 16:27:02 +0800 Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 16:27:01 +0800 From: Kefeng Wang To: Naoya Horiguchi , Andrew Morton CC: Miaohe Lin , , , Kefeng Wang Subject: [PATCH 2/3] mm: memory-failure: avoid pfn_valid() twice in soft_offline_page() Date: Fri, 21 Oct 2022 16:46:10 +0800 Message-ID: <20221021084611.53765-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221021084611.53765-1-wangkefeng.wang@huawei.com> References: <20221021084611.53765-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747285293629528626?= X-GMAIL-MSGID: =?utf-8?q?1747285293629528626?= Simplify WARN_ON_ONCE(flags & MF_COUNT_INCREASED) under !pfn_valid(). Signed-off-by: Kefeng Wang Acked-by: Naoya Horiguchi Reviewed-by: Miaohe Lin --- mm/memory-failure.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index b94152abb1c9..ca0199d0f79d 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2554,10 +2554,10 @@ int soft_offline_page(unsigned long pfn, int flags) bool try_again = true; struct page *page; - WARN_ON_ONCE(!pfn_valid(pfn) && (flags & MF_COUNT_INCREASED)); - - if (!pfn_valid(pfn)) + if (!pfn_valid(pfn)) { + WARN_ON_ONCE(flags & MF_COUNT_INCREASED); return -ENXIO; + } /* Only online pages can be soft-offlined (esp., not ZONE_DEVICE). */ page = pfn_to_online_page(pfn); From patchwork Fri Oct 21 08:46:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 6555 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp565249wrr; Fri, 21 Oct 2022 01:31:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6jCXracY9KFwcfpGSquWpa4Lw+SiLSlu+ezlKFMLjZVHqdWVEL+QUmSM7Fq5pzvAWWGKU7 X-Received: by 2002:a17:902:7589:b0:178:4ded:a90a with SMTP id j9-20020a170902758900b001784deda90amr18263499pll.74.1666341108777; Fri, 21 Oct 2022 01:31:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666341108; cv=none; d=google.com; s=arc-20160816; b=XjJqh4sJBJyIw7S1V1MlnN4uwGDy4MQwdcOf4muwKGEfUrDGK54z/ooieOVJ4HosBc 7H/SJMPWpmGpMLDbsHEt9QA0dvjrkgdtZwwVy2cpgiDHAJcl6MW2Jo4ti4yj0Q70RAU0 gez1blYIdq1XWkQvlLxUKEcRhmK+RQgtaCG712mvxSVL11x/espDXkU2ZX61sVrXEWl6 0dpLhePVBHvr0S/KPK3DrSQmDRPJFaoHffod4oYScoEW8WBtihzklIOMe+CFufl/Ya8o VvN79SFV0uPt5xQkFyoZPuBAR4RnoBIHtTvVXme6weITOQxxYjQNFRajD0cOejJUR5+w mZjQ== 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=skbbdds17ZacrWxOgkXX0qdH5w3rkeZiTghVmvfF610=; b=QHzQqkwEIbu0SzrSe5PE6+nQatg2Y1LrAhxvDYVC+dus5epNz/87skkEiKiE5kz28y p9NZ2axXjLM7OAzJ9isGpmvj1IYI1ccIpofnAQMCgxZw8KMIaKISSSqDJz7XfYDkUcHH CLZ5BpZeyNmzsNV/oGJHtXpRraK3utNPB/bmt6mcAhQX+s7p7+urbofviknHXTQJMoSH P0tLZXC1aj4H2ihlGVW3YeFo+L1Rmo2jbSBSuG7y2CBKUpG3fuq2MVCtzPRqDxlDCukF f3V0oKidzZV1UT62P1QbfcnvbO/tgXDOFwoKAvHz0wGI79+z/J3JNqkVHOFAHwOQ84eg inCg== 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 ng1-20020a17090b1a8100b0020a97a92a2fsi7130987pjb.135.2022.10.21.01.31.36; Fri, 21 Oct 2022 01:31:48 -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 S230056AbiJUI1i (ORCPT + 99 others); Fri, 21 Oct 2022 04:27:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229728AbiJUI1Z (ORCPT ); Fri, 21 Oct 2022 04:27:25 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84E2B1A4001 for ; Fri, 21 Oct 2022 01:27:24 -0700 (PDT) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MtyBp6z82zVj56; Fri, 21 Oct 2022 16:22:42 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 16:27:02 +0800 Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 16:27:02 +0800 From: Kefeng Wang To: Naoya Horiguchi , Andrew Morton CC: Miaohe Lin , , , Kefeng Wang Subject: [PATCH 3/3] mm: memory-failure: make action_result() return int Date: Fri, 21 Oct 2022 16:46:11 +0800 Message-ID: <20221021084611.53765-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221021084611.53765-1-wangkefeng.wang@huawei.com> References: <20221021084611.53765-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747285294697696637?= X-GMAIL-MSGID: =?utf-8?q?1747285294697696637?= Check mf_result in action_result(), only return 0 when MF_RECOVERED, or return -EBUSY, which will simplify code a bit. Signed-off-by: Kefeng Wang --- mm/memory-failure.c | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index ca0199d0f79d..3f469e2da047 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1182,14 +1182,16 @@ static struct page_state error_states[] = { * "Dirty/Clean" indication is not 100% accurate due to the possibility of * setting PG_dirty outside page lock. See also comment above set_page_dirty(). */ -static void action_result(unsigned long pfn, enum mf_action_page_type type, - enum mf_result result) +static int action_result(unsigned long pfn, enum mf_action_page_type type, + enum mf_result result) { trace_memory_failure_event(pfn, type, result); num_poisoned_pages_inc(); pr_err("%#lx: recovery action for %s: %s\n", pfn, action_page_types[type], action_name[result]); + + return result == MF_RECOVERED ? 0 : -EBUSY; } static int page_action(struct page_state *ps, struct page *p, @@ -1856,8 +1858,7 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb flags |= MF_NO_RETRY; goto retry; } - action_result(pfn, MF_MSG_UNKNOWN, MF_IGNORED); - return res; + return action_result(pfn, MF_MSG_UNKNOWN, MF_IGNORED); } head = compound_head(p); @@ -1883,22 +1884,18 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb } else { res = MF_FAILED; } - action_result(pfn, MF_MSG_FREE_HUGE, res); - return res == MF_RECOVERED ? 0 : -EBUSY; + return action_result(pfn, MF_MSG_FREE_HUGE, res); } page_flags = head->flags; if (!hwpoison_user_mappings(p, pfn, flags, head)) { - action_result(pfn, MF_MSG_UNMAP_FAILED, MF_IGNORED); - res = -EBUSY; - goto out; + res = action_result(pfn, MF_MSG_UNMAP_FAILED, MF_IGNORED); + unlock_page(head); + return res; } return identify_page_state(pfn, p, page_flags); -out: - unlock_page(head); - return res; } #else @@ -2063,16 +2060,13 @@ int memory_failure(unsigned long pfn, int flags) } res = MF_FAILED; } - action_result(pfn, MF_MSG_BUDDY, res); - res = res == MF_RECOVERED ? 0 : -EBUSY; + res = action_result(pfn, MF_MSG_BUDDY, res); } else { - action_result(pfn, MF_MSG_KERNEL_HIGH_ORDER, MF_IGNORED); - res = -EBUSY; + res = action_result(pfn, MF_MSG_KERNEL_HIGH_ORDER, MF_IGNORED); } goto unlock_mutex; } else if (res < 0) { - action_result(pfn, MF_MSG_UNKNOWN, MF_IGNORED); - res = -EBUSY; + res = action_result(pfn, MF_MSG_UNKNOWN, MF_IGNORED); goto unlock_mutex; } } @@ -2093,8 +2087,7 @@ int memory_failure(unsigned long pfn, int flags) */ SetPageHasHWPoisoned(hpage); if (try_to_split_thp_page(p) < 0) { - action_result(pfn, MF_MSG_UNSPLIT_THP, MF_IGNORED); - res = -EBUSY; + res = action_result(pfn, MF_MSG_UNSPLIT_THP, MF_IGNORED); goto unlock_mutex; } VM_BUG_ON_PAGE(!page_count(p), p); @@ -2127,8 +2120,7 @@ int memory_failure(unsigned long pfn, int flags) retry = false; goto try_again; } - action_result(pfn, MF_MSG_DIFFERENT_COMPOUND, MF_IGNORED); - res = -EBUSY; + res = action_result(pfn, MF_MSG_DIFFERENT_COMPOUND, MF_IGNORED); goto unlock_page; } @@ -2168,8 +2160,7 @@ int memory_failure(unsigned long pfn, int flags) * Abort on fail: __filemap_remove_folio() assumes unmapped page. */ if (!hwpoison_user_mappings(p, pfn, flags, p)) { - action_result(pfn, MF_MSG_UNMAP_FAILED, MF_IGNORED); - res = -EBUSY; + res = action_result(pfn, MF_MSG_UNMAP_FAILED, MF_IGNORED); goto unlock_page; } @@ -2177,8 +2168,7 @@ int memory_failure(unsigned long pfn, int flags) * Torn down by someone else? */ if (PageLRU(p) && !PageSwapCache(p) && p->mapping == NULL) { - action_result(pfn, MF_MSG_TRUNCATED_LRU, MF_IGNORED); - res = -EBUSY; + res = action_result(pfn, MF_MSG_TRUNCATED_LRU, MF_IGNORED); goto unlock_page; }