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 E9DA5C0015E for ; Wed, 12 Jul 2023 02:25:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C0AD6B0071; Tue, 11 Jul 2023 22:25:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 070D66B0072; Tue, 11 Jul 2023 22:25:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA2766B0075; Tue, 11 Jul 2023 22:25:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DB37A6B0071 for ; Tue, 11 Jul 2023 22:25:50 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 96375A0400 for ; Wed, 12 Jul 2023 02:25:50 +0000 (UTC) X-FDA: 81001369260.23.2E363BF Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf20.hostedemail.com (Postfix) with ESMTP id BC2B71C0007 for ; Wed, 12 Jul 2023 02:25:47 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf20.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 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=1689128748; 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=I6yyMxfTzzSpaUloO/fwMBuWoeRoE0g+7qUqHPEf7vU=; b=ixzNyptdWg59AWlddiozBsS30Cf0L7dawasmgrn9j/v3WMWDAdU5JeTSldXwe9MY3tZy2J pRQJE3sliChEenJW0t1VDuOwipjwFMyY/kSPlK/4Xpl3kFTZD89+U28hbC+g3XE7D1u9Jf h2YyJ7rFcRaD3uHzlkd1BDCXd/ivnSY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf20.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689128748; a=rsa-sha256; cv=none; b=F6PQhE3rK8yxstmhgCU/eOnzZ6JFIemHWd2Tw464o/15ddBXcX7JNVaePeL1ImJ+ISoMdH LpxrdJSvUTTZ/I1s7xe2aAY4lvo8qlgNo6LvMVBaztgx3ARFRM7zEQG1CJiW8QhiH2cCco 3qDcNw/SHbYJBljuN/Lny4z8mOufDLs= Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4R11jF5LJGzMn13; Wed, 12 Jul 2023 10:22:25 +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; Wed, 12 Jul 2023 10:25:42 +0800 Subject: Re: [PATCH v3 2/4] mm/hwpoison: check if a subpage of a hugetlb folio is raw HWPOISON To: Mike Kravetz , Jiaqi Yan CC: , , , , , , , , References: <20230707201904.953262-1-jiaqiyan@google.com> <20230707201904.953262-3-jiaqiyan@google.com> <6682284d-7ad3-9b59-687d-899f4d08d911@huawei.com> <20230711180159.GA3887@monkey> From: Miaohe Lin Message-ID: Date: Wed, 12 Jul 2023 10:25:41 +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: <20230711180159.GA3887@monkey> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: BC2B71C0007 X-Stat-Signature: h8ayreomjsnbohdjant7xf6kjr1aeexz X-Rspam-User: X-HE-Tag: 1689128747-742821 X-HE-Meta: U2FsdGVkX1+ZVwZaBI7Ab85ghZKxWALCxmP4094QPmyh6P1fhJT64MY5tpv0lzBmcxy0sUMC5RiPUx0vhs1sVTEyPWpG3FxK+bp7pqrApz7Vq12HXkh3Evn96YYqRbr83XvB1qUcso6VHwa8c87IJFm73np8kUxmPojatZkeF16hPvG34lejPN/0gQhJRdTHixlPysw2Y7pqRKPK+gBgLhTIazbu9ks+J5ZviZaHQbiEzfvuOvh9aJAwVzU4ynoaN6djB4NOHan90VSOJhOb7mH5QrBOD8G1ls7SgTIEgjf8EeyiM9JuxyiIQFC5YYVB061QAEQpV+A6H7o9Irz/Laft23ZlBNxfSiD2Y888v7oEImFmPI8NBLnfkaXVKCpYQ0wWVuM5WGV12f/qru4MMkdlQlyM1wjT50B4pDdQk41SNSGZnnEAI5uyACxieaTrRpPTdR3D6Tmy5HXOu/A9P+pdhs6LGXaESmZHOBfkED5Zt6iXYfnp/CyO5Z4lmVdRUeEp4izifXggTCvBc/yTsWxzB+whdfX5BRaksTNJAOKfCHRC/WQJ3FcV7FR2oQQfGyCFJ51YSgKJ0Ag0K8pH2JTQKTQ6L6THkhTz3HdXUVuJgv+uqeJfDIbnEeWoWXJahuIFTr/wFbhB3X0G2t2kx1+02qxzpUvlCc7S7FcH7hziRO6cMCpyR+L0AKxt3ipsumokTkqnunqlrh5SCKkAb/gBh6+XeUGZXtVwNPBk3yodvUHz52x23C4/HK7AfijssnrISEgBSkbdQLW0sN4LROyub9ZijkBfYQB4pFeGRSICJmGUFsaK95Od9BTwvwaMJMlnm1Hek8mZCEPkb8tV3dIO7gluofbyYufKzKB7iVbmQqf+wWgG2C/cWaPZoMqHfIArmJ7L2E72grZVF2nwFuvJpqHac90+ABDEmZnZzNS4r+kA3Tw/95Nu3VAqN/IxWJzi8zmm6R6khflpO+A DcwxQvg0 jVXB5fv9uVKeBOUBc2JmAEP9AOULSVWxMgdu5G8+M/pzjl0WFZjCxftUFLTnhXYxl1IxJR+teo2uc9wVfqB2xHqFPT9uxgLZW96JiwmXYq4pladNqQ+eQcmv9ztOLEKokETseazJrSoURmKTEPhtwfO/8lBwt47yf9pBMTNep2E9vAJVIz6kEMlL43Q== 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/12 2:01, Mike Kravetz wrote: > On 07/11/23 10:05, Jiaqi Yan wrote: >> On Mon, Jul 10, 2023 at 8:16 AM Jiaqi Yan wrote: >>> On Fri, Jul 7, 2023 at 7:57 PM Miaohe Lin wrote: >>>> On 2023/7/8 4:19, Jiaqi Yan wrote: >>>> >>>>> + if (subpage == p->page) { >>>>> + ret = true; >>>>> + break; >>>>> + } >>>>> + } >>>>> + >>>>> + return ret; >>>>> } >>>> >>>> It seems there's a race between __is_raw_hwp_subpage and unpoison_memory: >>>> unpoison_memory __is_raw_hwp_subpage >>>> if (!folio_test_hwpoison(folio)) -- hwpoison is set >>>> folio_free_raw_hwp llist_for_each_entry_safe raw_hwp_list >>>> llist_del_all .. >>>> folio_test_clear_hwpoison >>>> >>> >>> Thanks Miaohe for raising this concern. >>> >>>> But __is_raw_hwp_subpage is used in hugetlbfs, unpoison_memory couldn't reach here because there's a >>>> folio_mapping == NULL check before folio_free_raw_hwp. >>> >>> I agree. But in near future I do want to make __is_raw_hwp_subpage >>> work for shared-mapping hugetlb, so it would be nice to work with >>> unpoison_memory. It doesn't seem to me that holding mf_mutex in >>> __is_raw_hwp_subpage is nice or even absolutely correct. Let me think >>> if I can come up with something in v4. >> >> At my 2nd thought, if __is_raw_hwp_subpage simply takes mf_mutex >> before llist_for_each_entry, it will introduce a deadlock: >> >> unpoison_memory __is_raw_hwp_subpage >> held mf_mutex held hugetlb_lock >> get_hwpoison_hugetlb_folio attempts mf_mutex >> attempts hugetlb lock >> >> Not for this patch series, but for future, is it a good idea to make >> mf_mutex available to hugetlb code? Then enforce the order of locking >> to be mf_mutex first, hugetlb_lock second? I believe this is the >> current locking pattern / order for try_memory_failure_hugetlb. > > I think only holding mf_mutex in __is_raw_hwp_subpage would be sufficient > to prevent races with unpoison_memory. memory failure code needs to take Since soft_offline_page, memory_failure and unpoison_memory both holds mf_mutex, I think this should be enough to prevent races between them too. Thanks.