From: Jiaqi Yan <jiaqiyan@google.com>
To: akpm@linux-foundation.org, mike.kravetz@oracle.com,
naoya.horiguchi@nec.com
Cc: songmuchun@bytedance.com, shy828301@gmail.com,
linmiaohe@huawei.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, duenwen@google.com,
axelrasmussen@google.com, jthoughton@google.com,
Jiaqi Yan <jiaqiyan@google.com>
Subject: [PATCH v3 1/4] mm/hwpoison: delete all entries before traversal in __folio_free_raw_hwp
Date: Fri, 7 Jul 2023 20:19:01 +0000 [thread overview]
Message-ID: <20230707201904.953262-2-jiaqiyan@google.com> (raw)
In-Reply-To: <20230707201904.953262-1-jiaqiyan@google.com>
Traversal on llist (e.g. llist_for_each_safe) is only safe AFTER entries
are deleted from the llist. Correct the way __folio_free_raw_hwp deletes
and frees raw_hwp_page entries in raw_hwp_list: first llist_del_all, then
kfree within llist_for_each_safe.
As of today, concurrent adding, deleting, and traversal on raw_hwp_list
from hugetlb.c and/or memory-failure.c are fine with each other. Note
this is guaranteed partly by the lock-free nature of llist, and partly
by holding hugetlb_lock and/or mf_mutex. For example, as llist_del_all
is lock-free with itself, folio_clear_hugetlb_hwpoison()s from
__update_and_free_hugetlb_folio and memory_failure won't need explicit
locking when freeing the raw_hwp_list. New code that manipulates
raw_hwp_list must be careful to ensure the concurrency correctness.
Acked-by: Mike Kravetz <mike.kravetz@oracle.com>
Acked-by: Naoya Horiguchi <naoya.horiguchi@nec.com>
Signed-off-by: Jiaqi Yan <jiaqiyan@google.com>
---
mm/memory-failure.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index e245191e6b04..a08677dcf953 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1829,12 +1829,11 @@ static inline struct llist_head *raw_hwp_list_head(struct folio *folio)
static unsigned long __folio_free_raw_hwp(struct folio *folio, bool move_flag)
{
- struct llist_head *head;
- struct llist_node *t, *tnode;
+ struct llist_node *t, *tnode, *head;
unsigned long count = 0;
- head = raw_hwp_list_head(folio);
- llist_for_each_safe(tnode, t, head->first) {
+ head = llist_del_all(raw_hwp_list_head(folio));
+ llist_for_each_safe(tnode, t, head) {
struct raw_hwp_page *p = container_of(tnode, struct raw_hwp_page, node);
if (move_flag)
@@ -1844,7 +1843,6 @@ static unsigned long __folio_free_raw_hwp(struct folio *folio, bool move_flag)
kfree(p);
count++;
}
- llist_del_all(head);
return count;
}
--
2.41.0.255.g8b1d071c50-goog
next prev parent reply other threads:[~2023-07-07 20:19 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-07 20:19 [PATCH v3 0/4] Improve hugetlbfs read on HWPOISON hugepages Jiaqi Yan
2023-07-07 20:19 ` Jiaqi Yan [this message]
2023-07-08 2:40 ` [PATCH v3 1/4] mm/hwpoison: delete all entries before traversal in __folio_free_raw_hwp Miaohe Lin
2023-07-07 20:19 ` [PATCH v3 2/4] mm/hwpoison: check if a subpage of a hugetlb folio is raw HWPOISON Jiaqi Yan
2023-07-07 20:31 ` Matthew Wilcox
2023-07-07 21:05 ` Andrew Morton
2023-07-10 0:21 ` Naoya Horiguchi
2023-07-10 15:11 ` Jiaqi Yan
2023-07-11 8:59 ` Naoya Horiguchi
2023-07-08 2:57 ` Miaohe Lin
2023-07-10 15:16 ` Jiaqi Yan
2023-07-11 17:05 ` Jiaqi Yan
2023-07-11 18:01 ` Mike Kravetz
2023-07-11 22:22 ` Jiaqi Yan
2023-07-12 2:25 ` Miaohe Lin
2023-07-07 20:19 ` [PATCH v3 3/4] hugetlbfs: improve read HWPOISON hugepage Jiaqi Yan
2023-07-07 20:19 ` [PATCH v3 4/4] selftests/mm: add tests for HWPOISON hugetlbfs read Jiaqi Yan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230707201904.953262-2-jiaqiyan@google.com \
--to=jiaqiyan@google.com \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=duenwen@google.com \
--cc=jthoughton@google.com \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=naoya.horiguchi@nec.com \
--cc=shy828301@gmail.com \
--cc=songmuchun@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox