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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADB62C0015E for ; Sat, 8 Jul 2023 02:40:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232079AbjGHCka (ORCPT ); Fri, 7 Jul 2023 22:40:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230115AbjGHCk0 (ORCPT ); Fri, 7 Jul 2023 22:40:26 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42F25170C for ; Fri, 7 Jul 2023 19:40:25 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QyZHD2gyRzqTwZ; Sat, 8 Jul 2023 10:39:52 +0800 (CST) Received: from [10.174.151.185] (10.174.151.185) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Sat, 8 Jul 2023 10:40:21 +0800 Subject: Re: [PATCH v3 1/4] mm/hwpoison: delete all entries before traversal in __folio_free_raw_hwp To: Jiaqi Yan , , , Andrew Morton CC: , , , , , , References: <20230707201904.953262-1-jiaqiyan@google.com> <20230707201904.953262-2-jiaqiyan@google.com> From: Miaohe Lin Message-ID: <0be87971-543d-4d39-850e-3d9160ffa5e2@huawei.com> Date: Sat, 8 Jul 2023 10:40:21 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20230707201904.953262-2-jiaqiyan@google.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023/7/8 4:19, Jiaqi Yan wrote: > 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 I think there's a race on freeing the raw_hwp_list between unpoison_memory and __update_and_free_hugetlb_folio: unpoison_memory __update_and_free_hugetlb_folio if (folio_test_hwpoison) folio_clear_hugetlb_hwpoison folio_free_raw_hwp folio_free_raw_hwp folio_test_clear_hwpoison unpoison_memory and __update_and_free_hugetlb_folio can traverse and free the raw_hwp_list at the same time. And I believe your patch will fix the problem. Thanks. > 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 > Acked-by: Naoya Horiguchi > Signed-off-by: Jiaqi Yan Anyway, this patch looks good to me. Reviewed-by: Miaohe Lin Thanks.