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 5C029EB64D9 for ; Sat, 8 Jul 2023 02:57:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D8E988D0001; Fri, 7 Jul 2023 22:57:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D3E696B0072; Fri, 7 Jul 2023 22:57:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C06B88D0001; Fri, 7 Jul 2023 22:57:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id AEA4C6B0071 for ; Fri, 7 Jul 2023 22:57:14 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 55F8E8017E for ; Sat, 8 Jul 2023 02:57:14 +0000 (UTC) X-FDA: 80986933188.08.F2662EA Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf20.hostedemail.com (Postfix) with ESMTP id 6712F1C0015 for ; Sat, 8 Jul 2023 02:57:09 +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.189 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=1688785032; 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=0hNlycoJBxAjN9gEF7k84DkMeM7RiQCP+RcJDoYg/Yk=; b=F02qvIzhIQ//UJDStK5nxGs8SdH44F5OnN03Tdya5iNUdVnWEtFoFBJheNO6nPg6Dtnpem DBi+DH/jBUvr7Kv5crhvmaeSLTPBiKUPmrDW1AUG7oqOWiPcQiL6jDpZOVU+EaHHgMeHom kLxcQKgfnHitmJC0djOeckI+h4Yulyc= 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.189 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688785032; a=rsa-sha256; cv=none; b=EupakgSNni9hVVZYJRm1rt0KKf7yohMh0mxZe72W2OvE83QIPXygX9qOWTLT0/cVxV38e5 aI2tAAIVPgYfHJfxeywMtrXIkmGjBJDBQvnTCAz/LXOPfONoR0MRWGSAP4WHZTsvk7qVsb hUSE53qKHyjZP5ylVYLKkhDJGJMnu4w= Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4QyZcQ2khxzPk16; Sat, 8 Jul 2023 10:54:46 +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:57:01 +0800 Subject: Re: [PATCH v3 2/4] mm/hwpoison: check if a subpage of a hugetlb folio is raw HWPOISON To: Jiaqi Yan , , , CC: , , , , , , References: <20230707201904.953262-1-jiaqiyan@google.com> <20230707201904.953262-3-jiaqiyan@google.com> From: Miaohe Lin Message-ID: <6682284d-7ad3-9b59-687d-899f4d08d911@huawei.com> Date: Sat, 8 Jul 2023 10:57:00 +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-3-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: 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: 6712F1C0015 X-Stat-Signature: pbdn9cbef3nbf8wp86jf6ezif9gyscfx X-Rspam-User: X-HE-Tag: 1688785029-593685 X-HE-Meta: U2FsdGVkX18K8Twv5ks/d6eWVOQ73acgsM4GTQfFHH94MLeXGF06pO8HPukoFx4RMV13tLeGGyzjfqlz+Wn6eDeh9Z1QZf6Ypwh0Og4GbpYa51b88xh0fdvQFWnwT3zZ5dDbr76GKJizV/ypJQ+d7Ri54OWEJXnUy4uQbnZ38t3IIqchErdcLHKR5ACWrRw3+c3e9RUUj0vo5SsT5c+LIz1dHODQMWOw8YaG6rr3JIXSnZEQIz2Bd//CMIAGdt8LqTjbzStPfwRfpqeueclQU7qptLmujWFiljTgNoBfcpP2VLAVepg1Vem60fe68I8smnoYlWTNnbk/8IPz/S2LypScln/1U93jmA3B6kTawHSxEvbeqU2gg1+I/F/MnpQL0FIrzlLzgXdWmnL2NRCq++fGu4q2+sFT3CAQPZRGIMaZp/8eYpdd06klFb6QCkB9BwdQJE3OerVDZey1LcDyVxN8ID55cl1BMABGjAa4jbS3zyFkIMjQbV2kK5g1P2tu6DSyhQvLz3fAElwMUsyyHP3mRp2Ylb5aof8CoJSDDN1Wl9LLPmFqYZajeNK7peuhYXM6gV30BJCifBRX+bhQx0qrfYSk8Gpc3qv7kuHcVVNZ05RuJXQNwV2YUwFmslIma3TUvCNI7J8gfOwIqfnC4FGa+ayE31fhZAFzrDneJu8pNNgHPw1KDSsALtdui44cwg+f8hlyXXE8jMU14BEAlsacVQSor3I3tfwlDEx6OcmsPxZUol/V6xQqUZ/rk602OfhNSrTHqshdu3xaHHzv8yVsMN8wH4A/3Ptr8X0OHxERevfHhRKLJX64FwUs7sLuUTHDNVzyiOA1YT9CAWOjYfmNiI4kjFqAGN3FWJ5YBFrOriOqczamI0a3CxNuDvCntgvt/Ew4dmn46lUQlbmbYZ4aL8tROV+gsyRIH5rd6j5NJz1sD9XCGRWxAMW8oIOpVsjOrH1U9NYSAEm2VKr osAVueH3 bQVtrfl7s4QyQIQQaThzXWsvXDbvBiq/VuCTnRZCjjUqsOVXZKb7ZjTf+n4QOw64s4uVXw+T4BDiKhimmRb2cd0II+V46wFH4zfuntE2WXoTdr+R0H2OKmcqwuL3ojGEon3okubad5vSOCPw3Zyl3hP5zkI4fndyae73RNYjNveia/e+AvKApRu1lnCUI+4VrO8zsddNdo/3bAkigaVLXosmFPnsfB77ZQHTy 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: > Add the functionality, is_raw_hwp_subpage, to tell if a subpage of a > hugetlb folio is a raw HWPOISON page. This functionality relies on > RawHwpUnreliable to be not set; otherwise hugepage's raw HWPOISON list > becomes meaningless. > > is_raw_hwp_subpage needs to hold hugetlb_lock in order to synchronize > with __get_huge_page_for_hwpoison, who iterates and inserts an entry to > raw_hwp_list. llist itself doesn't ensure insertion is synchornized with > the iterating used by __is_raw_hwp_list. Caller can minimize the > overhead of lock cycles by first checking if folio / head page's > HWPOISON flag is set. > > Exports this functionality to be immediately used in the read operation > for hugetlbfs. > > Reviewed-by: Mike Kravetz > Reviewed-by: Naoya Horiguchi > Signed-off-by: Jiaqi Yan > --- > include/linux/hugetlb.h | 19 +++++++++++++++++++ > include/linux/mm.h | 7 +++++++ > mm/hugetlb.c | 10 ++++++++++ > mm/memory-failure.c | 34 ++++++++++++++++++++++++---------- > 4 files changed, 60 insertions(+), 10 deletions(-) > ... > -static inline struct llist_head *raw_hwp_list_head(struct folio *folio) > +bool __is_raw_hwp_subpage(struct folio *folio, struct page *subpage) > { > - return (struct llist_head *)&folio->_hugetlb_hwpoison; > + struct llist_head *raw_hwp_head; > + struct raw_hwp_page *p, *tmp; > + bool ret = false; > + > + if (!folio_test_hwpoison(folio)) > + return false; > + > + /* > + * When RawHwpUnreliable is set, kernel lost track of which subpages > + * are HWPOISON. So return as if ALL subpages are HWPOISONed. > + */ > + if (folio_test_hugetlb_raw_hwp_unreliable(folio)) > + return true; > + > + raw_hwp_head = raw_hwp_list_head(folio); > + llist_for_each_entry_safe(p, tmp, raw_hwp_head->first, node) { Since we don't free the raw_hwp_list, does llist_for_each_entry works same as llist_for_each_entry_safe? > + 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 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. Anyway, this patch looks good to me. Reviewed-by: Miaohe Lin Thanks.