From mboxrd@z Thu Jan 1 00:00:00 1970 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 D3060EB64D9 for ; Sun, 2 Jul 2023 23:50:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B6F368E0085; Sun, 2 Jul 2023 19:50:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B1F7F8E007C; Sun, 2 Jul 2023 19:50:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E6AB8E0085; Sun, 2 Jul 2023 19:50:47 -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 8E0AE8E007C for ; Sun, 2 Jul 2023 19:50:47 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 392D8140202 for ; Sun, 2 Jul 2023 23:50:47 +0000 (UTC) X-FDA: 80968319334.12.F0792E1 Received: from out-60.mta0.migadu.com (out-60.mta0.migadu.com [91.218.175.60]) by imf02.hostedemail.com (Postfix) with ESMTP id 3B40680006 for ; Sun, 2 Jul 2023 23:50:44 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=OYSUxmAq; spf=pass (imf02.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 91.218.175.60 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688341845; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DhWA0YLBWsVFxrFnH3VgBgG6UALQpN/vPaWrnHpD31Q=; b=EI7glezc28XWM6Wlv4S09Shgs/hIdS4+00lS1nUS1nAfO3svukjNR/b0sF4GYEKs9uYPbi 3gQcXHTGYHkel7TcuY0bD7/rSzlAAHHlBmrqDs0L+eL765DX2oWXb9IQX42dMLma/+xRmh U+PYLcHaecTvq8kooCNmbLVZin4mgrg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688341845; a=rsa-sha256; cv=none; b=kDUsA3qN08sLedZ/Gua174zdMZeWN5H0ep/QRr5iBLaPwLOoqx2lAdUPurYhymkS9r9fNH nJLzjy9wKHyW/BoMRs+1A7mxaMOEqEVRoBJmRvYKHKwNzUMcwdvmqMEYTmD+j769D97Pfe u1Vrf2PrGEHgq7GBMIa3LEtZ0Buw2FI= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=OYSUxmAq; spf=pass (imf02.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 91.218.175.60 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev; dmarc=pass (policy=none) header.from=linux.dev Date: Mon, 3 Jul 2023 08:50:34 +0900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1688341843; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DhWA0YLBWsVFxrFnH3VgBgG6UALQpN/vPaWrnHpD31Q=; b=OYSUxmAqM30vAxweav6qFvAT6mTMaKY67p8PccP42j9OKdkrOF2V8VwmTvVtcfA3IFTDcW R1Jx38yrz1VnB8QlArvAa35jurRBn9N46FkED/KD7+zeSgJOmGiMgyoOLUZR28hONrjj2d XkyWU3zbXB8wbKD6myJ6k51mJjS1264= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Naoya Horiguchi To: Jiaqi Yan Cc: mike.kravetz@oracle.com, naoya.horiguchi@nec.com, songmuchun@bytedance.com, shy828301@gmail.com, linmiaohe@huawei.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, duenwen@google.com, axelrasmussen@google.com, jthoughton@google.com Subject: Re: [PATCH v2 1/4] mm/hwpoison: delete all entries before traversal in __folio_free_raw_hwp Message-ID: <20230702235034.GA2906304@ik1-406-35019.vs.sakura.ne.jp> References: <20230623164015.3431990-1-jiaqiyan@google.com> <20230623164015.3431990-2-jiaqiyan@google.com> <20230630145217.GA2213127@ik1-406-35019.vs.sakura.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 3B40680006 X-Rspam-User: X-Stat-Signature: jbf7gjkozjuffzze6yhmfidyb5dj58wy X-Rspamd-Server: rspam03 X-HE-Tag: 1688341844-606589 X-HE-Meta: U2FsdGVkX191g9xc6Zys7J2KA4A2EpY4LX/c+or4jHNgeiFehN6sNzzTt1w9JgoWwO6r2ApFlbov/QBXzXA9RJt/FFqucn9JJWCsqNhSAg6yHj4uA3ma1XG3ybeHWtCcRgnKNbW5vhBj52l7z/xLj1lIZo6piA8pPCAv8u1Tl5ndDCUbxjXuSftna1oHZcaKMgQv2RLGQ1GQDZ1rx1l8YP1JLd8Keqg1heEzmQZ0kfNrhMgtlydQ8MIE34lNdRqmRT9dsJNwrLjl8OvcX3hlrnxOB/pg+96efqG7Ydjf39CqW+JEFWHkODxBQRwrcEoWBHk1h0XdN2OPgrDiaR+t8oFnuEmrTCgv9i3i9Gwb4ivDjUHOazORR3ZhF5/ovqbJXY0TwbaaYvoOgv2O/tpKn/eLwMlzBefBZlTY+7A3X94bKNQvoHazmgylioJBlbnVeu+owhBrimsv+JwAd2zj2nZLjFZ2n+WCrFB3pdhuW5RHjVbRkxI7yKiN3a70G8jGIeXqMl1Ym7rk62K5NP7cNnvioadyzA6C0ykl8oxlR2Zxdvra36WNPfFKjPa1G1MqMUJNU8ccfeaLf4lK7UBzZzoFSOejtuE3Rg3UO8WgY1E58N2x6uAu7b3t8UbgietoMkTVTqwIOVSZGsjAi1OiiaBU+SfrpNW60TTDFIOARZn/bASEU0YcT7hjM99MA1gzzbdV6wTjVrqajaZt7wCH6sn69nCyPuExjhohEzfMDzoIo//wE2YhPe1QfKahBSvoXdXPjZBK9YWks6wOy6Qh2h7s1bXZDn9L4jRpGPGvIYMoYYzgTYDg/fpAnL5+Y4bG8Te/jtGyPFuu/PwnBHxMNe2OGh3wG2uMFwGWyZPYg3PTm10BBa7gCCZ8sfdPICk/C6j3pnR1r/mMP4STk32v5aqtBm8tixjrzEm2Jj8WH6iBogX2Q6lxATmdwbCF6C3sMn5z4edSoJUUMll/b1u 9Wi9qsnY NARra6aH9+pZzJxI0j/JBNGnIEirUDe4+0N/cmYn/QSmPOzU7yLGGecncAO5k3U8BK/5Gqa7eqQ51qakI1xXEIp+qtHuUXc6sGmh4AUXCRBJEcMI4LRZSUZAjy6LnCmfbcDgu2CUuZbTrNCQvoUCyJK3gY9SdJlbW82URVxfZ3luLcd3F2Owy1OMIg6Y8QJgKt3roaDugRajjUFxbK72ai3+sydpMR6zUlVd5gyNbGRgHAEM= 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: On Fri, Jun 30, 2023 at 01:59:23PM -0700, Jiaqi Yan wrote: > On Fri, Jun 30, 2023 at 7:52 AM Naoya Horiguchi > wrote: > > > > On Fri, Jun 23, 2023 at 04:40:12PM +0000, Jiaqi Yan wrote: > > > Traversal on llist (e.g. llist_for_each_safe) is only safe AFTER entries > > > are deleted from the llist. > > > > > > llist_del_all are 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. > > > > > > Signed-off-by: Jiaqi Yan > > > > (Sorry if stupid question...) folio_set_hugetlb_hwpoison() also calls > > llist_for_each_safe() but it still traverses the list without calling > > llist_del_all(). This convention applies only when removing item(s)? > > I think in our previous discussion, Mike and I agree as of today's > code in hugetlb.c and memory-failure.c, concurrent adding, deleting, > traversing are fine with each other and with themselves [1], but new > code need to be careful wrt ops on raw_hwp_list. > > This patch is a low-hanging fruit to ensure any caller of > __folio_free_raw_hwp won't introduce any problem by correcting one > thing in __folio_free_raw_hwp: since it wants to delete raw_hwp_page > entries in the list, it should do it by first llist_del_all, and then > kfree with a llist_for_each_safe. Thanks for the explanation, this is worth adding to the patch description for future developers to understand the background. > > As for folio_set_hugetlb_hwpoison, I am not very comfortable fixing > it. I imagine a way to fix it is llist_del_all() => > llist_for_each_safe{...} => llist_add_batch(), or llist_add() within > llist_for_each_safe{...}. I haven't really thought through if this is > a correct fix. I see. Changing folio_set_hugetlb_hwpoison() like this is a little too complex considering that this fix is for precaution. So no change on this for now is fine to me. Anyway this patch looks fine to me. Acked-by: Naoya Horiguchi > > [1] https://lore.kernel.org/lkml/CACw3F51o1ZFSYZa+XLnk4Wwjy2w_q=Kn+aOQs0=qpfG-ZYDFKg@mail.gmail.com/#t > > > > > > Thanks, > > Naoya Horiguchi > > > > > --- > > > 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 004a02f44271..c415c3c462a3 100644 > > > --- a/mm/memory-failure.c > > > +++ b/mm/memory-failure.c > > > @@ -1825,12 +1825,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) > > > @@ -1840,7 +1839,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.162.gfafddb0af9-goog > > > > > > > > >