Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3423210ybi; Sun, 26 May 2019 23:08:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzvGEc0R9dybgE0X4gz2vzM8X9YNngy+OWjjkAXA0bpSW3l0iZLC1//pf0owpTLnAOioI8T X-Received: by 2002:a17:902:e683:: with SMTP id cn3mr102998027plb.86.1558937316310; Sun, 26 May 2019 23:08:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558937316; cv=none; d=google.com; s=arc-20160816; b=QaPjmRA+AX/0S8bzPlaQIMqIL+ZnmuPNr5o8Syuh6gzOmI2WqnSsBaKu/g/V4mhzGn i9kUT6bZNLb7dbe+ErRE5DMhFRNwd4iOnOTFRYo+C7hX7gDUVFDAvyYeE7o7Iorg5FDB V+CXGORJ/gW90yPHTs9duxjK6gm8QHIRabX4vqe5jUe6DQI2WV4s1dZYsZSN8y1A1/wI UZUMEF6jK2NeclwR8dskrGvP0FknPcAQSR2ylSWo4Rlk/CKBKWaZgbphC76ImnzZNSkr C9cAWEznNndffRaFtoeZuNLj8PaF9MkORXun9DRbddegnjP97ww2twabunE50W7nclGI +Wog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=J+flJg4D+B292+R0mjnCGOvi2ClGFqVNzhwfO4APIzk=; b=eBaNU6+V8XfIei6y5dRbFWdvyv/aPp1fVeLuqs3yL45lGD1+YzbpxwBlVgJsc+fyM7 RYr5EFI4sm9FIlDGPLOawij6oZRJSe+zjbAQrgtwgjl4cZi+yh37qDL70QqxdJQnNPf2 aUHh7Vy3/TEbU+BEV+yLJbL34EwSdWeqoIZhGMUrta56rFDyp0fZRE4ueCq12s0epsvH RtmSbTx4km76pQ1BMsac/izWLhDx6nR1+JqqnTqz/Ax9lkahwnV0ir6I04/F/6OdtNWU mGIxhi7fbq4A9sE0SKcV8ZlK5GHqJVorOHEufFI8T9Dm21IO4EFQmGyTSCeoyd7R+7lT /lUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=OlkrPsci; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w21si4178357pgh.251.2019.05.26.23.08.09; Sun, 26 May 2019 23:08:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=OlkrPsci; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726112AbfE0GGq (ORCPT + 99 others); Mon, 27 May 2019 02:06:46 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:41978 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725996AbfE0GGq (ORCPT ); Mon, 27 May 2019 02:06:46 -0400 Received: by mail-pl1-f194.google.com with SMTP id d14so1082358pls.8 for ; Sun, 26 May 2019 23:06:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=J+flJg4D+B292+R0mjnCGOvi2ClGFqVNzhwfO4APIzk=; b=OlkrPsciOkbhWZp3PP44UreYr8KL5SZwPqqMfrHRqMPhAIRFfzi8ZkB26S4HuYnWXf eL/2+2N+Ct1wjX1UiIPfIe29z48HiAE2LS0lX+Tv362vNKl/wkXZYhh4Ym5kTUK0YmiP Ht1PEIMm9bkr6Wd7JTRmdqTfGesPel0ffT/ILlMLbUBvKOVXFoWlXe+lRTMbJNwBmoZ0 5HlvHblnBsRhv/7CxEKdnLRDjcNugmUknRqpexNkhwq8Q5H0+EFwbGhf7wVl2yzEnDds RTcGgj3AQRwXjhWuCqq9yGeQW7qlongtT5ABvk5WRKh8cMmv4++nywV0CY13wjDO20ki 5bgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=J+flJg4D+B292+R0mjnCGOvi2ClGFqVNzhwfO4APIzk=; b=EpWaNuHMeCBVN5CGcAHtu57BiP19zEDoPI2CkilaN78B6nWVe7oIY3mKZBXiRGI/L8 QTvYph7lUluKGVM6qm1kZFLdnJ1a1+Xv8FuqTG0KD9HNv6uwWHgSLl4PLW/1plngJgYq 3DK+oQm1fGTYW0HLesYDcN0KorB3Gke6+J42RND6Dgl558x+zv+zGxy1jNyeOzaqHxs7 +wpGMmI12+xXzMBdgoTtyV8CDhIfmJgUBqUzZ1qsOX8OhcGSY/f/XDiDEnd2xzFNLLnz P5dnFlA+hCSDYw82TQo/UIfISEFLafelwxzlpcSk4OA20bKs3FF+3CDrnGXiXlcngCIF zgQA== X-Gm-Message-State: APjAAAXsm5m8F53mEibQytBA5CoaC/7NzfdplqgL6eN9DQcwbfE3owe9 pKGkc505oAHYLpVQ4SXzug== X-Received: by 2002:a17:902:2ba7:: with SMTP id l36mr29760193plb.334.1558937205300; Sun, 26 May 2019 23:06:45 -0700 (PDT) Received: from www9186uo.sakura.ne.jp (www9186uo.sakura.ne.jp. [153.121.56.200]) by smtp.gmail.com with ESMTPSA id b4sm9939550pfd.120.2019.05.26.23.06.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 May 2019 23:06:44 -0700 (PDT) From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Andrew Morton , Michal Hocko , Mike Kravetz , xishi.qiuxishi@alibaba-inc.com, "Chen, Jerry T" , "Zhuo, Qiuxu" , linux-kernel@vger.kernel.org Subject: [PATCH v1] mm: hugetlb: soft-offline: fix wrong return value of soft offline Date: Mon, 27 May 2019 15:06:40 +0900 Message-Id: <1558937200-18544-1-git-send-email-n-horiguchi@ah.jp.nec.com> X-Mailer: git-send-email 2.7.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Soft offline events for hugetlb pages return -EBUSY when page migration succeeded and dissolve_free_huge_page() failed, which can happen when there're surplus hugepages. We should judge pass/fail of soft offline by checking whether the raw error page was finally contained or not (i.e. the result of set_hwpoison_free_buddy_page()), so this behavior is wrong. This problem was introduced by the following change of commit 6bc9b56433b76 ("mm: fix race on soft-offlining"): if (ret > 0) ret = -EIO; } else { - if (PageHuge(page)) - dissolve_free_huge_page(page); + /* + * We set PG_hwpoison only when the migration source hugepage + * was successfully dissolved, because otherwise hwpoisoned + * hugepage remains on free hugepage list, then userspace will + * find it as SIGBUS by allocation failure. That's not expected + * in soft-offlining. + */ + ret = dissolve_free_huge_page(page); + if (!ret) { + if (set_hwpoison_free_buddy_page(page)) + num_poisoned_pages_inc(); + } } return ret; } , so a simple fix is to restore the PageHuge precheck, but my code reading shows that we already have PageHuge check in dissolve_free_huge_page() with hugetlb_lock, which is better place to check it. And currently dissolve_free_huge_page() returns -EBUSY for !PageHuge but that's simply wrong because that that case should be considered as success (meaning that "the given hugetlb was already dissolved.") This change affects other callers of dissolve_free_huge_page(), which are also cleaned up by this patch. Reported-by: Chen, Jerry T Signed-off-by: Naoya Horiguchi Fixes: 6bc9b56433b76 ("mm: fix race on soft-offlining") Cc: # v4.19+ --- mm/hugetlb.c | 15 +++++++++------ mm/memory-failure.c | 7 +++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git v5.1-rc6-mmotm-2019-04-25-16-30/mm/hugetlb.c v5.1-rc6-mmotm-2019-04-25-16-30_patched/mm/hugetlb.c index bf58cee..385899f 100644 --- v5.1-rc6-mmotm-2019-04-25-16-30/mm/hugetlb.c +++ v5.1-rc6-mmotm-2019-04-25-16-30_patched/mm/hugetlb.c @@ -1518,7 +1518,12 @@ int dissolve_free_huge_page(struct page *page) int rc = -EBUSY; spin_lock(&hugetlb_lock); - if (PageHuge(page) && !page_count(page)) { + if (!PageHuge(page)) { + rc = 0; + goto out; + } + + if (!page_count(page)) { struct page *head = compound_head(page); struct hstate *h = page_hstate(head); int nid = page_to_nid(head); @@ -1563,11 +1568,9 @@ int dissolve_free_huge_pages(unsigned long start_pfn, unsigned long end_pfn) for (pfn = start_pfn; pfn < end_pfn; pfn += 1 << minimum_order) { page = pfn_to_page(pfn); - if (PageHuge(page) && !page_count(page)) { - rc = dissolve_free_huge_page(page); - if (rc) - break; - } + rc = dissolve_free_huge_page(page); + if (rc) + break; } return rc; diff --git v5.1-rc6-mmotm-2019-04-25-16-30/mm/memory-failure.c v5.1-rc6-mmotm-2019-04-25-16-30_patched/mm/memory-failure.c index fc8b517..3a83e27 100644 --- v5.1-rc6-mmotm-2019-04-25-16-30/mm/memory-failure.c +++ v5.1-rc6-mmotm-2019-04-25-16-30_patched/mm/memory-failure.c @@ -1733,6 +1733,8 @@ static int soft_offline_huge_page(struct page *page, int flags) if (!ret) { if (set_hwpoison_free_buddy_page(page)) num_poisoned_pages_inc(); + else + ret = -EBUSY; } } return ret; @@ -1857,11 +1859,8 @@ static int soft_offline_in_use_page(struct page *page, int flags) static int soft_offline_free_page(struct page *page) { - int rc = 0; - struct page *head = compound_head(page); + int rc = dissolve_free_huge_page(page); - if (PageHuge(head)) - rc = dissolve_free_huge_page(page); if (!rc) { if (set_hwpoison_free_buddy_page(page)) num_poisoned_pages_inc(); -- 2.7.0