From patchwork Thu Jun 23 23:51:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12893259 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 83999C43334 for ; Thu, 23 Jun 2022 23:52:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24F2A8E01AA; Thu, 23 Jun 2022 19:52:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1FEEF8E01A1; Thu, 23 Jun 2022 19:52:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C6E88E01AA; Thu, 23 Jun 2022 19:52:45 -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 F2A8D8E01A1 for ; Thu, 23 Jun 2022 19:52:44 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D1C2820762 for ; Thu, 23 Jun 2022 23:52:44 +0000 (UTC) X-FDA: 79611153048.10.8369598 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by imf19.hostedemail.com (Postfix) with ESMTP id 866941A001F for ; Thu, 23 Jun 2022 23:52:44 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id i8-20020a17090aee8800b001ecc929d14dso4585561pjz.0 for ; Thu, 23 Jun 2022 16:52:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9qDM1SEwhJHNMkiAW+9hnn1MZNaGCub7B2p3sdAevGo=; b=a7P7HnrlqqsSBAv8Rh9l5P0qKEPodg3DsKsYr1Ea4M2Kn+QsYmKyxzF6uMI7LIyD90 D7dQ6KAxhdboYEDc65+ew8MRy8m7dAcgAw/XN9mFluukHhigzZK9AlkGJoXVhUYCDYxB iLNdAr+Lt1+Hhj13KaJVx531dr/ndkA5+wn+Xx0ZMBms/VzRGeN93f23HV3Fivmq0x4S wekPTJ7XFlXQdG1L1/GEkg4Y9ZXaUdt5cHqskGHTeZ1REkKnnlA7yUZkP2sRj28BTcsr 1SpvYWYgizD/bL6oe+cCC39Of/ccsD5GQvut0an6oon8bsbqSxFnCig0gv8wbdTZOacr re2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9qDM1SEwhJHNMkiAW+9hnn1MZNaGCub7B2p3sdAevGo=; b=cZhur1u5LCirxWu2e0EDCGpEbxFHVXpdkiZAm36XQ//JlNTb5M+5bCQZ5liE5nmjLU k9Xs6gWx73qWQl1ginxV/lwwyi2CQuMCmhj+CyUjo2/UsA8JzTsUgJuQ/pqQouTAhEdH cXZ0ZJBxZJno8/9Gpi6WKej4OLKR2MldZl0craAd90ulgjaPasZ/f3A1ejDGd2Jj3gYe r48B4jJO8P2zgcBlZxYwrsFM+pHdEvmNvaK4/C5ns00EtcEI5QTf2VT1j1NgrXqttWlm jz59hbLGvTt9BrRgoeWEN/UZAV/YyAeObTBiC1/h+XP9XOmWjLXaAb8PtJBY+69xGzRo kc8Q== X-Gm-Message-State: AJIora+JsKqhgQpLWEjz2zQMnS/dmeQtz3QS2FG/jMsNUkR4cItE75WY BOI2Vy8h4kq+t5dw2dMl5KbbQFSVxA== X-Google-Smtp-Source: AGRyM1to5MI42NBV7wBN2fu1N3JmUZLbmtHx8xzIu63b/rMAvK85lhxS+WOmvPyJdXJd+RprgZCMnw== X-Received: by 2002:a17:90a:1588:b0:1e0:a45c:5c1 with SMTP id m8-20020a17090a158800b001e0a45c05c1mr550853pja.65.1656028363425; Thu, 23 Jun 2022 16:52:43 -0700 (PDT) Received: from ik1-406-35019.vs.sakura.ne.jp (ik1-406-35019.vs.sakura.ne.jp. [153.127.16.23]) by smtp.gmail.com with ESMTPSA id r10-20020a170903020a00b00168eab11f67sm362571plh.94.2022.06.23.16.52.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jun 2022 16:52:43 -0700 (PDT) From: Naoya Horiguchi X-Google-Original-From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Andrew Morton , David Hildenbrand , Mike Kravetz , Miaohe Lin , Liu Shixin , Yang Shi , Oscar Salvador , Muchun Song , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [PATCH v2 5/9] mm, hwpoison: make unpoison aware of raw error info in hwpoisoned hugepage Date: Fri, 24 Jun 2022 08:51:49 +0900 Message-Id: <20220623235153.2623702-6-naoya.horiguchi@linux.dev> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220623235153.2623702-1-naoya.horiguchi@linux.dev> References: <20220623235153.2623702-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=a7P7Hnrl; spf=pass (imf19.hostedemail.com: domain of nao.horiguchi@gmail.com designates 209.85.216.42 as permitted sender) smtp.mailfrom=nao.horiguchi@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656028364; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9qDM1SEwhJHNMkiAW+9hnn1MZNaGCub7B2p3sdAevGo=; b=vacpEnJViJ8TYVdwew0HTHVgXSSNwd5D2RcDwkadr2fF2XRpiYwlGXb939n936kKN/2ryn tfN9QTjkaUIayb2CtnmmHOnAme3J+RF03HFTCJh+UOs4gFUP9rCimVO7p9Hi8yelohyULb GtlPDGzpbI0ULIgIdQ11NPdA0HCJOEo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656028364; a=rsa-sha256; cv=none; b=h6zqHZ1jGPa/mQWe/LdDWVh3YMUV1aUlgzjPVTpfmQ26kWoHc5WYyuX0k5djxoCebpFdYd aB2jFr/ZIn7Vo8wyTzETVTT/wMdbpM65DhLVutxEh6il5zN7Jbx15tHw9GyT+C0PUJbyV9 IFFxpdnteRs+5zT8gCol6RvQhYWtJu0= X-Stat-Signature: tywmq88pxiz49ut3nyd51w8cbge59j5n X-Rspamd-Queue-Id: 866941A001F X-Rspam-User: Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=a7P7Hnrl; spf=pass (imf19.hostedemail.com: domain of nao.horiguchi@gmail.com designates 209.85.216.42 as permitted sender) smtp.mailfrom=nao.horiguchi@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam02 X-HE-Tag: 1656028364-260869 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: From: Naoya Horiguchi Raw error info list needs to be removed when hwpoisoned hugetlb is unpoisioned. And unpoison handler needs to know how many errors there are in the target hugepage. So add them. Signed-off-by: Naoya Horiguchi --- include/linux/swapops.h | 9 +++++++++ mm/memory-failure.c | 34 +++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/include/linux/swapops.h b/include/linux/swapops.h index 9584c2e1c54a..ad62776ee99c 100644 --- a/include/linux/swapops.h +++ b/include/linux/swapops.h @@ -494,6 +494,11 @@ static inline void num_poisoned_pages_dec(void) atomic_long_dec(&num_poisoned_pages); } +static inline void num_poisoned_pages_sub(long i) +{ + atomic_long_sub(i, &num_poisoned_pages); +} + #else static inline swp_entry_t make_hwpoison_entry(struct page *page) @@ -514,6 +519,10 @@ static inline struct page *hwpoison_entry_to_page(swp_entry_t entry) static inline void num_poisoned_pages_inc(void) { } + +static inline void num_poisoned_pages_sub(long i) +{ +} #endif static inline int non_swap_entry(swp_entry_t entry) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index af571fa6f2af..6005e953d011 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1571,23 +1571,34 @@ static inline int hugetlb_set_page_hwpoison(struct page *hpage, return ret; } -inline int hugetlb_clear_page_hwpoison(struct page *hpage) +static inline long free_raw_hwp_pages(struct page *hpage, bool move_flag) { struct llist_head *head; struct llist_node *t, *tnode; + long count = 0; - if (raw_hwp_unreliable(hpage)) - return -EBUSY; - ClearPageHWPoison(hpage); head = raw_hwp_list_head(hpage); llist_for_each_safe(tnode, t, head->first) { struct raw_hwp_page *p = container_of(tnode, struct raw_hwp_page, node); - SetPageHWPoison(p->page); + if (move_flag) + SetPageHWPoison(p->page); kfree(p); + count++; } llist_del_all(head); - return 0; + return count; +} + +inline int hugetlb_clear_page_hwpoison(struct page *hpage) +{ + int ret = -EBUSY; + + if (raw_hwp_unreliable(hpage)) + return ret; + ret = !TestClearPageHWPoison(hpage); + free_raw_hwp_pages(hpage, true); + return ret; } /* @@ -1729,6 +1740,10 @@ static inline int try_memory_failure_hugetlb(unsigned long pfn, int flags, int * { return 0; } + +static inline void free_raw_hwp_pages(struct page *hpage, bool move_flag) +{ +} #endif static int memory_failure_dev_pagemap(unsigned long pfn, int flags, @@ -2188,6 +2203,7 @@ int unpoison_memory(unsigned long pfn) struct page *p; int ret = -EBUSY; int freeit = 0; + long count = 1; static DEFINE_RATELIMIT_STATE(unpoison_rs, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST); @@ -2235,6 +2251,8 @@ int unpoison_memory(unsigned long pfn) ret = get_hwpoison_page(p, MF_UNPOISON); if (!ret) { + if (PageHuge(p)) + count = free_raw_hwp_pages(page, false); ret = TestClearPageHWPoison(page) ? 0 : -EBUSY; } else if (ret < 0) { if (ret == -EHWPOISON) { @@ -2243,6 +2261,8 @@ int unpoison_memory(unsigned long pfn) unpoison_pr_info("Unpoison: failed to grab page %#lx\n", pfn, &unpoison_rs); } else { + if (PageHuge(p)) + count = free_raw_hwp_pages(page, false); freeit = !!TestClearPageHWPoison(p); put_page(page); @@ -2255,7 +2275,7 @@ int unpoison_memory(unsigned long pfn) unlock_mutex: mutex_unlock(&mf_mutex); if (!ret || freeit) { - num_poisoned_pages_dec(); + num_poisoned_pages_sub(count); unpoison_pr_info("Unpoison: Software-unpoisoned page %#lx\n", page_to_pfn(p), &unpoison_rs); }