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 563BAEB64D9 for ; Sat, 8 Jul 2023 02:40:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B72ED8D0001; Fri, 7 Jul 2023 22:40:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B22C36B0072; Fri, 7 Jul 2023 22:40:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A11658D0001; Fri, 7 Jul 2023 22:40:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 821A26B0071 for ; Fri, 7 Jul 2023 22:40:29 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3230A4018C for ; Sat, 8 Jul 2023 02:40:29 +0000 (UTC) X-FDA: 80986890978.25.711D18A Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf24.hostedemail.com (Postfix) with ESMTP id 9E14D180009 for ; Sat, 8 Jul 2023 02:40:26 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688784027; 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; bh=18zVwXXaVbVPRCO97nhwXAllBmvtlBHy1pfkpAvxLow=; b=ygP9EBp+DXkPzAHjAlqA6KRMHnrbBvz9TULiZ2lmm/WQR6qOvNsT1rLxO/CdNM7KN9Q26B Y1Ehi+2ZwdfcAGwV8nT2ual7TPGCa0hkhxlcjJj6qS+usoKzFTiAWgV41t62JOY3lky5CN CCCAQXp6kBoEyvwVcnNz1NBJr+aeuZY= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688784027; a=rsa-sha256; cv=none; b=OoPjOKlKhP/4evHrqH0rZudcU5wYvGZiJPz/4kcAmQpV5TUIocLPJG2kOeHldUwFWTAQCC G3VyEexefRd5GZu1OBaFPvZwO/vloZ1cvbdr5gp3tdfm29me1GyzHWBd6AdAqaEps/7sxr FoTXTW4iMxbh0pgEAtA34W+bUKZd8UY= 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 X-Rspamd-Queue-Id: 9E14D180009 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 4xxag58gjdsrmzsnq7n55g1jm9cqs97k X-HE-Tag: 1688784026-758317 X-HE-Meta: U2FsdGVkX1/JaFExZqUF2wufEw30gc1NHFSS0hRw+VUVkhNdU2+Cl6uo/kv2AYdHXyBKetoEw2SiY47h7mOASggrw3LhXczyw6eRKh20aRVceIeqF6W9iwnHoWFywYNhoKuKssHjrsuEDixVhOAZgG/satG4M0uT5no8ZD5XOCeB1+ZuIC5HIMZCsbDw2OhdEGfL9xE0A4L6OKhtO7wb8zbHIpbNkUz0rNmykKfX4JWevaF2y8dwaYzTCeyLdOlZKvN+Sds4osEw/s2OEkBKXTfdLn6svVZBWS5UnDzlOnCFS+oYMAjQglMFFbBfQi514uK0ddHGk7R3kIzeQhMjr3dRmtXBw8WLrxJGkJsPNGHgmKjHcoEmz8UlmSrhvzf+OfAj99i6Y2AQla3Mk/+gtAo/T47rjyU28IVKJ6ADI7zRES6dcBnCnZ0FxgT+sRFU3ZY2k103KHYco2IOofYn5Fkhjb2q1TrUTGcekRP5/gljpS2h87fOrKG/E8vS8hfjOoif38vYCT+bb00NY+XtVn8A9sx5FcQWvECO62U0Pa5ca5bTprWV42Z8cP3/Ut0pSE4HQnf+gmvk0OyhOPGCDUOjvMCwr0CydaQPex4OlnfH14EnceGcb7HfiUMb+EWvgwhaKach9ceI0fPfPXojjSND2yl33RoxROs6s6Q9T/DIOsbw/mRtvodjFWn2kZbnCA1He5IHq4ArBciyf80sQFHuGAsfd3RTvAorpy1QTw/DYqbmiHtd7YewB/sj/cKugfblagQaR+L8yfvGau9nALDA73Eju1gK6+ZDt4XnUj79v/FMhaJAous7fi2QQ99W6789fMKAK1h35xgHbIVhBe3eVKj2OAHJR3F9s+qKAL+Jja7xC/+Zt2lCzNuinkjc72Sr8LWu34Z8v5v3vB1/U4lMZoMbcmBvrOSk2gliXYe1z1891RfrprRMcBuv+v/XiJLsXwcUDnVRC0zJ2QP ikQ4mNMh ZIJFq+RkRXLU4FJV33mlZg9p6caC6Yd2NoglAZBGHJqlqYScwxA0FZdebKiGVJS7hbWaCYuIpG++czmK+OG7kAbnqlPlAkGJ9SEcyIq1NmPrplFKLMGJIfMP1ZO+uw2ssY+WCP7qkbHyaqZODlkmiKFrR25DGaffYRwUSOFejztPVYVGB4dxg2Es6mXYyC0YsUA3geVokvXxWotgQG3amLUyY/MYFfIMc+2GF0pEfb93yPzqHK+gJS9ME3kEB3HlqcbIHx/S5iEik0mH7HeOo2zwREA== 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 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.