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 6F75DC4707B for ; Fri, 12 Jan 2024 03:02:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D53EE6B0095; Thu, 11 Jan 2024 22:02:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D02C76B0096; Thu, 11 Jan 2024 22:02:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF0AB6B0099; Thu, 11 Jan 2024 22:02:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B48246B0095 for ; Thu, 11 Jan 2024 22:02:19 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 89A74A01DD for ; Fri, 12 Jan 2024 03:02:19 +0000 (UTC) X-FDA: 81669160398.11.7F999AF Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf25.hostedemail.com (Postfix) with ESMTP id DA028A000B for ; Fri, 12 Jan 2024 03:02:14 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 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=1705028537; 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=j/bZvusA7mW1aqhZu9nX1rDLTOAfX/80ggZBIsBWu78=; b=Q7G01tjc+VZX9n1oWeHoSafNtZjAo8u8mZQVloMqgS1yZWmI8DrNONsQ9ekRRAsZJF3J3y 7zGKfgxPYmwqhkkAWj7CuUqF4cgsQwhWZqx/9tYCf+65COekkZQIxoFfVLmrs8spBNhFON dZoHX8W1tWaHLBXhIF061VYn/dj1LBg= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705028537; a=rsa-sha256; cv=none; b=MjGPYJK5Z4gF67JirDniUOo1FNONGByNaOJzAx1HmqxLr1ZWaw55wpxg/JoqorlS2FWef4 IRi46E4lJ2HyRkLZpkQ1klyFBJdml0D4Axz72F2b0zXRIAQSvZD2aZySIZ7W08eMzmMxR3 /O9TahkPHoRnoybfHGFsJy/InU9Pjm0= Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4TB5sF3MFmz1Q7m0; Fri, 12 Jan 2024 11:01:21 +0800 (CST) Received: from canpemm500002.china.huawei.com (unknown [7.192.104.244]) by mail.maildlp.com (Postfix) with ESMTPS id 0BB5114093A; Fri, 12 Jan 2024 11:01:53 +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.35; Fri, 12 Jan 2024 11:01:52 +0800 Subject: Re: [PATCH] fix hugetlbfs hwpoison handling To: Sidhartha Kumar CC: , , , , , , , , , , , , References: <20240111191655.295530-1-sidhartha.kumar@oracle.com> From: Miaohe Lin Message-ID: <3b1206e2-85e5-7c66-b5eb-288cc7117420@huawei.com> Date: Fri, 12 Jan 2024 11:01:35 +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: <20240111191655.295530-1-sidhartha.kumar@oracle.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-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: DA028A000B X-Stat-Signature: y69axgjzr5rwgyi58hb49zumbizry1sx X-Rspam-User: X-HE-Tag: 1705028534-396847 X-HE-Meta: U2FsdGVkX18MF24Gu0wrgE4kcqQQslq5H02Q5EIwgxXUfU3dR9WOoLs6Lm5Rs1lx8wGzNHBI0HFtXmU+JllEphEfseyb4EgcThaWuQuADk6VrgmsoCkPfrG+qyKhp2cNPvWVj60FJb1lL2CrwG0ShLKiEWw/nECFrSHB6vuFbOgJ/SiisTb2LXbixQ7R0xj2Vzq9YwX2ihhsl4SVXwPBcCRMwhuPSYbs1H3KCaw4kr9nooL1QGqS1Og5F430menUOjTf4b7Qn5LV5lsF8CqqQIPbmHOprEV3A0V69UIza47AGm3H6VUKfBLig0B3dUfx16sHSUGHXK/fO3BbD8LhPJeDILWz9j3606BSf0MWcglaXsTi+2/bTaw1lp3wwqprf0meVXHS0M2aolSRct/dhuZ+fAXyWq77Ve5y2ERKcUrBEt+EFNHIxJRVPjmxiZCX7NUgsYfJ/YUDgCWjAlLZnE3tT4CkpbHrJHfhG+i9HR/3+5yaOjsPQxatJ6WShF+A3I9aMRvMpM9pqF36s0YP+yRCwJUgsOiRRijoItSFipvHM8E3KW4eqA2jU/AQhuzABDVdk2EIwXdf85GRqp7SlJNkaab6WHtRYhskkDBmdYqrb38Y0TrMzHsqjRMy8jiBI1fbYHKVRBPRGXBdmuuAc7otZulx/9b6+f7mPSFl4UFM2zLszapSy/4l8t7rFljOvTYFLwjpM+uTHZCXN8WT+MzNVpc2zcPzRubYfhpDSdXwOlxHN5bGPno/ACPCSkR03cFeUT3bda0hdsRtyWdkaKPkHhFMqBO3SRufhW/43QfmNOWnExTSLCsdPA4LMxmKAlwyPYgW8m5EjFX6TIBFfa7fr/T6IrCeR5jiBLAit7rg1DukFFEdJEDHTh9flJkx6BjE3t1PIe2BOML2/TNpjlNaPVUBJJ/ePndKVZ83/NOkZcsouseEbexJ9S1mGuHryObq8gxIfZWkaCKmk+L laTiBsIC HPETtouHyXil80+s3sKP9FB/WIinU6+20pBPxF3osh29+gZ6DfEwsLGHSBZrhSJjfRq+MjgeaaPUr1GH1UouIamEEVWccNz2eKncRtfabUkuf0vY4kfC3tBza7OFnKV2hzw7c6Il3udf55pUfFiqX6rfMg7HkhuDW7BKXaRF87FIxL4jNGFLSWsA/MEAu8wIyou8YX7w9WWAjftaI2KIalPdpXJN671H0gmaa0KA9d/74Kw+QWrZKv54nyTTFzq2QCKiAM+vB7NJQK0nYPm8H387GzBQPjzHjqomU63wf3/Bn68Q= 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: List-Subscribe: List-Unsubscribe: On 2024/1/12 3:16, Sidhartha Kumar wrote: > has_extra_refcount() makes the assumption that a ref count of 1 means > the page is not referenced by other users. Commit a08c7193e4f1 > (mm/filemap: remove hugetlb special casing in filemap.c) modifies > __filemap_add_folio() by calling folio_ref_add(folio, nr); for all cases > (including hugtetlb) where nr is the number of pages in the folio. We > should check if the page is not referenced by other users by checking > the page count against the number of pages rather than 1. Thanks for your patch. > > In hugetlbfs_read_iter(), folio_test_has_hwpoisoned() is testing the wrong > flag as, in the hugetlb case, memory-failure code calls > folio_test_set_hwpoison() to indicate poison. folio_test_hwpoison() is the > correct function to test for that flag. > > After these fixes, the hugetlb hwpoison read selftest passes all cases. > > Fixes: a08c7193e4f1 ("mm/filemap: remove hugetlb special casing in filemap.c") > Closes: https://lore.kernel.org/linux-mm/20230713001833.3778937-1-jiaqiyan@google.com/T/#m8e1469119e5b831bbd05d495f96b842e4a1c5519 > Cc: # 6.7+ > Signed-off-by: Sidhartha Kumar > Reported-by: Muhammad Usama Anjum > Tested-by: Muhammad Usama Anjum > --- > fs/hugetlbfs/inode.c | 2 +- > mm/memory-failure.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c > index 36132c9125f9..3a248e4f7e93 100644 > --- a/fs/hugetlbfs/inode.c > +++ b/fs/hugetlbfs/inode.c > @@ -340,7 +340,7 @@ static ssize_t hugetlbfs_read_iter(struct kiocb *iocb, struct iov_iter *to) > } else { > folio_unlock(folio); > > - if (!folio_test_has_hwpoisoned(folio)) > + if (!folio_test_hwpoison(folio)) > want = nr; > else { > /* > diff --git a/mm/memory-failure.c b/mm/memory-failure.c > index d8c853b35dbb..87f6bf7d8bc1 100644 > --- a/mm/memory-failure.c > +++ b/mm/memory-failure.c > @@ -973,7 +973,7 @@ struct page_state { > static bool has_extra_refcount(struct page_state *ps, struct page *p, > bool extra_pins) > { > - int count = page_count(p) - 1; > + int count = page_count(p) - folio_nr_pages(page_folio(p)); IIRC, the refcnt of 1 here means the page is held by memory-failure. So I think it shouldn't be changed to folio_nr_pages(page_folio(p)). > > if (extra_pins) > count -= 1; Indeed @extra_pins indicates whether hugetlb page is kept in page cache. So the page refcnt of 'folio_nr_pages(page_folio(p))' might be used here. Thanks.