From patchwork Thu Jun 30 02:27:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12900988 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 D5608C43334 for ; Thu, 30 Jun 2022 02:28:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 593FC6B0074; Wed, 29 Jun 2022 22:28:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 543B86B0075; Wed, 29 Jun 2022 22:28:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 40AE98E0001; Wed, 29 Jun 2022 22:28:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 31B8B6B0074 for ; Wed, 29 Jun 2022 22:28:14 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 052D63468B for ; Thu, 30 Jun 2022 02:28:13 +0000 (UTC) X-FDA: 79633317708.22.A938640 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf23.hostedemail.com (Postfix) with ESMTP id 7BA8514002E for ; Thu, 30 Jun 2022 02:28:13 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1656556092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/lD2AZO8ox5TTpHPepM0dCwWaQ9BZ891lb7mETr4gnI=; b=ghGF/odGZnpA1wVO6LTYB67lU0fj83SJj0Hcgvg9hCzjqf1jt5b4QzvW50nhEzNNnX8x0N w6PWytI7Zrs8obu0Js7WqF2Cpt7WQ5Y6boEsDpFbYgSLPUGa5gb58DUTtpLLZ2o2bv9wQw PBpXkK2HvoYlLCWUCnYuX+F4aP8Yv+Q= From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Andrew Morton , David Hildenbrand , Mike Kravetz , Miaohe Lin , Liu Shixin , Yang Shi , Oscar Salvador , Muchun Song , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [PATCH v3 1/9] mm/hugetlb: check gigantic_page_runtime_supported() in return_unused_surplus_pages() Date: Thu, 30 Jun 2022 11:27:47 +0900 Message-Id: <20220630022755.3362349-2-naoya.horiguchi@linux.dev> In-Reply-To: <20220630022755.3362349-1-naoya.horiguchi@linux.dev> References: <20220630022755.3362349-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656556093; a=rsa-sha256; cv=none; b=a/mKXHXCQojgP4OS34Bh9CMMe4yXa7JyWzkSNyBsH5ZO97egPZddAxTkUyFG5HOdNgWFO0 RA47L+7sX2vl+dkgcX+DWiZciokNvE8aqPM0E8xW8bmJ6Wa7OdCJWSXnsa3hovM7Us+AIh FDfkz+6bBuKxATtAY35+neUr5q8Gp+o= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="ghGF/odG"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf23.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656556093; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/lD2AZO8ox5TTpHPepM0dCwWaQ9BZ891lb7mETr4gnI=; b=DBiMh5gRW3YPmbNqB3Mdp0WNWIbRjEec1vOm7e8Nwx0g8MB7yWjtgLaPb1XehIJiwquUh0 wm3/muasDS0/sYkD8HlFy5jLXnVcCf9NLNAzMyBkDF2RLiZh2uWya/btX9Eib/CkNyyReH +XJ+Ztu59UcNJ9Z5i+eEBr8sY6/Mguo= Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="ghGF/odG"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf23.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 7BA8514002E X-Stat-Signature: 6xgbttn1p57g3nt17ei8ozcgm1hz3fam X-Rspam-User: X-HE-Tag: 1656556093-433594 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: From: Naoya Horiguchi I found a weird state of 1GB hugepage pool, caused by the following procedure: - run a process reserving all free 1GB hugepages, - shrink free 1GB hugepage pool to zero (i.e. writing 0 to /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages), then - kill the reserving process. , then all the hugepages are free *and* surplus at the same time. $ cat /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages 3 $ cat /sys/kernel/mm/hugepages/hugepages-1048576kB/free_hugepages 3 $ cat /sys/kernel/mm/hugepages/hugepages-1048576kB/resv_hugepages 0 $ cat /sys/kernel/mm/hugepages/hugepages-1048576kB/surplus_hugepages 3 This state is resolved by reserving and allocating the pages then freeing them again, so this seems not to result in serious problem. But it's a little surprising (shrinking pool suddenly fails). This behavior is caused by hstate_is_gigantic() check in return_unused_surplus_pages(). This was introduced so long ago in 2008 by commit aa888a74977a ("hugetlb: support larger than MAX_ORDER"), and at that time the gigantic pages were not supposed to be allocated/freed at run-time. Now kernel can support runtime allocation/free, so let's check gigantic_page_runtime_supported() together. Signed-off-by: Naoya Horiguchi --- v2 -> v3: - Fixed typo in patch description, - add !gigantic_page_runtime_supported() check instead of removing hstate_is_gigantic() check (suggested by Miaohe and Muchun) - add a few more !gigantic_page_runtime_supported() check in set_max_huge_pages() (by Mike). --- mm/hugetlb.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a57e1be41401..e67540dbbf88 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2432,8 +2432,7 @@ static void return_unused_surplus_pages(struct hstate *h, /* Uncommit the reservation */ h->resv_huge_pages -= unused_resv_pages; - /* Cannot return gigantic pages currently */ - if (hstate_is_gigantic(h)) + if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported()) goto out; /* @@ -3318,7 +3317,8 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, * the user tries to allocate gigantic pages but let the user free the * boottime allocated gigantic pages. */ - if (hstate_is_gigantic(h) && !IS_ENABLED(CONFIG_CONTIG_ALLOC)) { + if (hstate_is_gigantic(h) && (!IS_ENABLED(CONFIG_CONTIG_ALLOC) || + !gigantic_page_runtime_supported())) { if (count > persistent_huge_pages(h)) { spin_unlock_irq(&hugetlb_lock); mutex_unlock(&h->resize_lock); @@ -3366,6 +3366,19 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid, goto out; } + /* + * We can not decrease gigantic pool size if runtime modification + * is not supported. + */ + if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported()) { + if (count < persistent_huge_pages(h)) { + spin_unlock_irq(&hugetlb_lock); + mutex_unlock(&h->resize_lock); + NODEMASK_FREE(node_alloc_noretry); + return -EINVAL; + } + } + /* * Decrease the pool size * First return free pages to the buddy allocator (being careful From patchwork Thu Jun 30 02:27:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12900989 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 CB197C43334 for ; Thu, 30 Jun 2022 02:28:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 656256B0075; Wed, 29 Jun 2022 22:28:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6060B6B0078; Wed, 29 Jun 2022 22:28:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4CDD28E0001; Wed, 29 Jun 2022 22:28:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3D9106B0075 for ; Wed, 29 Jun 2022 22:28:18 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0DE73207DF for ; Thu, 30 Jun 2022 02:28:18 +0000 (UTC) X-FDA: 79633317876.27.0BD865F Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf03.hostedemail.com (Postfix) with ESMTP id 9CB622001C for ; Thu, 30 Jun 2022 02:28:17 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1656556096; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tggX3TEF1rQUjZFH/3Jh58MKfRiuXYgRwsp7E05HHro=; b=Uj9iRN+AxAftE2JXvhdToqbFJvb87xrZrFfetQMQ+tQjvsigOQVg5JhF8mqK1Wwu5Qcn4S ya5h1uXQGgvYL24mV8Z+7UFf4zVrGSvA1ZrMBAXkRX2KVEk3JP+7Xy0Ibd2/xfPljP1Fx7 pobbEI9CUz+K1pXIAPM90oDRmJM+g7Q= From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Andrew Morton , David Hildenbrand , Mike Kravetz , Miaohe Lin , Liu Shixin , Yang Shi , Oscar Salvador , Muchun Song , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [PATCH v3 2/9] mm/hugetlb: separate path for hwpoison entry in copy_hugetlb_page_range() Date: Thu, 30 Jun 2022 11:27:48 +0900 Message-Id: <20220630022755.3362349-3-naoya.horiguchi@linux.dev> In-Reply-To: <20220630022755.3362349-1-naoya.horiguchi@linux.dev> References: <20220630022755.3362349-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656556097; a=rsa-sha256; cv=none; b=VF7phUp6vP7e9c2C8N7gga4wgfbeXIVbSb40La9JuX44VFEmjSNNBYAWjJTPZSXF5Wjpa9 N9DJWCd+NwX1t0GCN6PxAknPt7op0eH2uMnWdzqMiGF73L+NTHlOm3RzgzueeSMhehecQu Rg3iFt2RLItRIGvpRbmt9wwWTD+2Evs= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Uj9iRN+A; spf=pass (imf03.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656556097; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tggX3TEF1rQUjZFH/3Jh58MKfRiuXYgRwsp7E05HHro=; b=qe9wR2f6M7ZMn6tj5yjv5XD7+Ja9Hx7tNNKbXriglPOxdbuYKoj1BfnfTkF/X6ngAxFmRD yuDA4utNm8G8JprxWWDyhf9XygHMISGAtdZhVGY+i3Z/as0YALjFr5hX9ucUoCn43iLqvG /wD3GaettfStzk41OcG6ilof7Ir8cuQ= X-Rspam-User: X-Rspamd-Server: rspam04 Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Uj9iRN+A; spf=pass (imf03.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Stat-Signature: pxjhwepp7wiyzg9ts1fizrc8e9eomewd X-Rspamd-Queue-Id: 9CB622001C X-HE-Tag: 1656556097-759763 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: From: Naoya Horiguchi Originally copy_hugetlb_page_range() handles migration entries and hwpoisoned entries in similar manner. But recently the related code path has more code for migration entries, and when is_writable_migration_entry() was converted to !is_readable_migration_entry(), hwpoison entries on source processes got to be unexpectedly updated (which is legitimate for migration entries, but not for hwpoison entries). This results in unexpected serious issues like kernel panic when forking processes with hwpoison entries in pmd. Separate the if branch into one for hwpoison entries and one for migration entries. Fixes: 6c287605fd56 ("mm: remember exclusively mapped anonymous pages with PG_anon_exclusive") Signed-off-by: Naoya Horiguchi Reviewed-by: Miaohe Lin Reviewed-by: Mike Kravetz Reviewed-by: Muchun Song Cc: # 5.18 --- mm/hugetlb.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index e67540dbbf88..03fdf342f5f2 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4801,8 +4801,13 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, * sharing with another vma. */ ; - } else if (unlikely(is_hugetlb_entry_migration(entry) || - is_hugetlb_entry_hwpoisoned(entry))) { + } else if (unlikely(is_hugetlb_entry_hwpoisoned(entry))) { + bool uffd_wp = huge_pte_uffd_wp(entry); + + if (!userfaultfd_wp(dst_vma) && uffd_wp) + entry = huge_pte_clear_uffd_wp(entry); + set_huge_swap_pte_at(dst, addr, dst_pte, entry, sz); + } else if (unlikely(is_hugetlb_entry_migration(entry))) { swp_entry_t swp_entry = pte_to_swp_entry(entry); bool uffd_wp = huge_pte_uffd_wp(entry); From patchwork Thu Jun 30 02:27:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12900990 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 21B30C43334 for ; Thu, 30 Jun 2022 02:28:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B38806B0078; Wed, 29 Jun 2022 22:28:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE9968E0001; Wed, 29 Jun 2022 22:28:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D8C46B007D; Wed, 29 Jun 2022 22:28:22 -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 8ED9F6B0078 for ; Wed, 29 Jun 2022 22:28:22 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 51E372097F for ; Thu, 30 Jun 2022 02:28:22 +0000 (UTC) X-FDA: 79633318044.02.CFA5C0B Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf24.hostedemail.com (Postfix) with ESMTP id A018A180032 for ; Thu, 30 Jun 2022 02:28:21 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1656556100; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4+gT1L5I0bxMRIt5l1rKNXOQvY2SKY/BWBll5/2iF1A=; b=P1tfmW+CznR0mXbiljriMcKGZvoad5ycF13FdI9QghcGq+ot+yeIZcr1E12OTtC9IM7dRq 7bu3X/MDOXeQi6rx6YRAVZFAxNpJfctjGuM7t8+0kWhpFP9GfZ4ExO2fk1QgSMJSQgLx6t 9/qpFbPWgF6JvACZD4RItgOkIjp3IXw= From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Andrew Morton , David Hildenbrand , Mike Kravetz , Miaohe Lin , Liu Shixin , Yang Shi , Oscar Salvador , Muchun Song , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [PATCH v3 3/9] mm/hugetlb: make pud_huge() and follow_huge_pud() aware of non-present pud entry Date: Thu, 30 Jun 2022 11:27:49 +0900 Message-Id: <20220630022755.3362349-4-naoya.horiguchi@linux.dev> In-Reply-To: <20220630022755.3362349-1-naoya.horiguchi@linux.dev> References: <20220630022755.3362349-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656556102; a=rsa-sha256; cv=none; b=UyDgfWjSraHgpV3wNv785Csy4uY2WKukpfU2uW5fnbJVsvMF4RGNiizikF3gXit8XtxNix c+IsKMncQazL8H9s0+Y5bcYKikQ6iiP9ZtMbp9JgntVuG9cM0s7I7vgKrBtDJ1jRjvPxmK eGRthI6djiBjvoKLd8+o+Z39EXF8/Wg= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=P1tfmW+C; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf24.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656556102; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4+gT1L5I0bxMRIt5l1rKNXOQvY2SKY/BWBll5/2iF1A=; b=nKNdcvf1a4am6N31ALPR4IPUBPei0HdTcrru/ViIvEYeEnUnEQRRHHfcCb3SxgilBi+NQP 9kg40ZrLCV5+1JstAeVSIofnrIttCGKbJiNYHqSE+y9zS67D9zb5+9XrmOeqE4O9+X51dl 84LI1AO++LWEmxnwChdjIP5TBZPd2Y0= X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: A018A180032 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=P1tfmW+C; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf24.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev X-Rspam-User: X-Stat-Signature: tycktd53bbsr46uhzkobnf1kewh7mino X-HE-Tag: 1656556101-323891 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: From: Naoya Horiguchi follow_pud_mask() does not support non-present pud entry now. As long as I tested on x86_64 server, follow_pud_mask() still simply returns no_page_table() for non-present_pud_entry() due to pud_bad(), so no severe user-visible effect should happen. But generally we should call follow_huge_pud() for non-present pud entry for 1GB hugetlb page. Update pud_huge() and follow_huge_pud() to handle non-present pud entries. The changes are similar to previous works for pud entries commit e66f17ff7177 ("mm/hugetlb: take page table lock in follow_huge_pmd()") and commit cbef8478bee5 ("mm/hugetlb: pmd_huge() returns true for non-present hugepage"). Signed-off-by: Naoya Horiguchi --- v2 -> v3: - fixed typos in subject and description, - added comment on pud_huge(), - added comment about fallback for hwpoisoned entry, - updated initial check about FOLL_{PIN,GET} flags. --- arch/x86/mm/hugetlbpage.c | 8 +++++++- mm/hugetlb.c | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c index a0d023cb4292..9c8193df0187 100644 --- a/arch/x86/mm/hugetlbpage.c +++ b/arch/x86/mm/hugetlbpage.c @@ -68,9 +68,15 @@ int pmd_huge(pmd_t pmd) (pmd_val(pmd) & (_PAGE_PRESENT|_PAGE_PSE)) != _PAGE_PRESENT; } +/* + * pud_huge() returns 1 if @pud is hugetlb related entry, that is normal + * hugetlb entry or non-present (migration or hwpoisoned) hugetlb entry. + * Otherwise, returns 0. + */ int pud_huge(pud_t pud) { - return !!(pud_val(pud) & _PAGE_PSE); + return !pud_none(pud) && + (pud_val(pud) & (_PAGE_PRESENT|_PAGE_PSE)) != _PAGE_PRESENT; } #endif diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 03fdf342f5f2..4c30f3fcfe50 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6963,10 +6963,38 @@ struct page * __weak follow_huge_pud(struct mm_struct *mm, unsigned long address, pud_t *pud, int flags) { - if (flags & (FOLL_GET | FOLL_PIN)) + struct page *page = NULL; + spinlock_t *ptl; + pte_t pte; + + if (WARN_ON_ONCE(flags & FOLL_PIN)) return NULL; - return pte_page(*(pte_t *)pud) + ((address & ~PUD_MASK) >> PAGE_SHIFT); +retry: + ptl = huge_pte_lock(hstate_sizelog(PUD_SHIFT), mm, (pte_t *)pud); + if (!pud_huge(*pud)) + goto out; + pte = huge_ptep_get((pte_t *)pud); + if (pte_present(pte)) { + page = pud_page(*pud) + ((address & ~PUD_MASK) >> PAGE_SHIFT); + if (WARN_ON_ONCE(!try_grab_page(page, flags))) { + page = NULL; + goto out; + } + } else { + if (is_hugetlb_entry_migration(pte)) { + spin_unlock(ptl); + __migration_entry_wait(mm, (pte_t *)pud, ptl); + goto retry; + } + /* + * hwpoisoned entry is treated as no_page_table in + * follow_page_mask(). + */ + } +out: + spin_unlock(ptl); + return page; } struct page * __weak From patchwork Thu Jun 30 02:27:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12900991 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 56BE8CCA47C for ; Thu, 30 Jun 2022 02:28:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E1ED56B007B; Wed, 29 Jun 2022 22:28:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DCEAE6B007D; Wed, 29 Jun 2022 22:28:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C96DC6B007E; Wed, 29 Jun 2022 22:28:26 -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 BA8066B007B for ; Wed, 29 Jun 2022 22:28:26 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8AFC5355B0 for ; Thu, 30 Jun 2022 02:28:26 +0000 (UTC) X-FDA: 79633318212.08.598DEA5 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf15.hostedemail.com (Postfix) with ESMTP id A28BBA0033 for ; Thu, 30 Jun 2022 02:28:25 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1656556104; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wOMgnwsmQWT0PlMYH+FuGsur4UNydG+XcrxtKVbnrBs=; b=EikZrr/igoYVd4UDlTbpVEFA6l/Mv89057tUmr2NRCqf8qX6pBQS7z1kkUfyklkSLy/Xmk Gy0oUY+c/UJYIckBwTl/90qL2gwfuembtzzh9iuXFUcQojLzAIv3gf4nlU9/e8qrLJPUcK D4gW2f0M1O2td7MBg8L9BvjULkAfK5E= From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Andrew Morton , David Hildenbrand , Mike Kravetz , Miaohe Lin , Liu Shixin , Yang Shi , Oscar Salvador , Muchun Song , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [PATCH v3 4/9] mm, hwpoison, hugetlb: support saving mechanism of raw error pages Date: Thu, 30 Jun 2022 11:27:50 +0900 Message-Id: <20220630022755.3362349-5-naoya.horiguchi@linux.dev> In-Reply-To: <20220630022755.3362349-1-naoya.horiguchi@linux.dev> References: <20220630022755.3362349-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656556106; a=rsa-sha256; cv=none; b=haDm/y1WLlZqQ3EBUkMcX50U45ketzJSE0gIEstjHJpuNq2mshxxMMOLTzOUKUdIz07Q2z B2ZtP/rVAjLJK386OAMzHEI7Kyc8tpWdBU9ReoG3ZqN0W0NTnYC4vjFTF+ldSFUGLr/5el xxaDNITd87/xGmLPuO+LQFXIQBZDuF8= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="EikZrr/i"; spf=pass (imf15.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656556106; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wOMgnwsmQWT0PlMYH+FuGsur4UNydG+XcrxtKVbnrBs=; b=UVv70Ve8Ggyhg67QpT82AhuvwRhxpSfcUNChY+XhmhV12WZqqI0AoiuzoZtMJR17HRTqCz RTy0zu4p8EfOg1P/jhlffsWtVY3jO29wMd/tn6GhWrjs0REUEPP7UTimQFPYa9BrotgEgr rw/3qDEH0byzBxB/ZC/yq5JmWyeNifg= X-Rspam-User: X-Rspamd-Server: rspam04 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="EikZrr/i"; spf=pass (imf15.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Stat-Signature: 1mta3kqwjigf9ni9uh9rduefrnxtzxg6 X-Rspamd-Queue-Id: A28BBA0033 X-HE-Tag: 1656556105-557600 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: From: Naoya Horiguchi When handling memory error on a hugetlb page, the error handler tries to dissolve and turn it into 4kB pages. If it's successfully dissolved, PageHWPoison flag is moved to the raw error page, so that's all right. However, dissolve sometimes fails, then the error page is left as hwpoisoned hugepage. It's useful if we can retry to dissolve it to save healthy pages, but that's not possible now because the information about where the raw error pages is lost. Use the private field of a few tail pages to keep that information. The code path of shrinking hugepage pool uses this info to try delayed dissolve. In order to remember multiple errors in a hugepage, a singly-linked list originated from SUBPAGE_INDEX_HWPOISON-th tail page is constructed. Only simple operations (adding an entry or clearing all) are required and the list is assumed not to be very long, so this simple data structure should be enough. If we failed to save raw error info, the hwpoison hugepage has errors on unknown subpage, then this new saving mechanism does not work any more, so disable saving new raw error info and freeing hwpoison hugepages. Signed-off-by: Naoya Horiguchi --- v2 -> v3: - remove duplicate "return ret" lines, - use GFP_ATOMIC instead of GFP_KERNEL, - introduce HPageRawHwpUnreliable pseudo flag (suggested by Muchun), - hugetlb_clear_page_hwpoison removes raw_hwp_page list even if HPageRawHwpUnreliable is true, (by Miaohe) v1 -> v2: - support hwpoison hugepage with multiple errors, - moved the new interface functions to mm/memory-failure.c, - define additional subpage index SUBPAGE_INDEX_HWPOISON_UNRELIABLE, - stop freeing/dissolving hwpoison hugepages with unreliable raw error info, - drop hugetlb_clear_page_hwpoison() in dissolve_free_huge_page() because that's done in update_and_free_page(), - move setting/clearing PG_hwpoison flag to the new interfaces, - checking already hwpoisoned or not on a subpage basis. ChangeLog since previous post on 4/27: - fixed typo in patch description (by Miaohe) - fixed config value in #ifdef statement (by Miaohe) - added sentences about "multiple hwpoison pages" scenario in patch description Signed-off-by: Naoya Horiguchi --- include/linux/hugetlb.h | 18 +++++++++- mm/hugetlb.c | 39 ++++++++++---------- mm/memory-failure.c | 80 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 114 insertions(+), 23 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index e4cff27d1198..bd92a1e9a97b 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -42,6 +42,9 @@ enum { SUBPAGE_INDEX_CGROUP, /* reuse page->private */ SUBPAGE_INDEX_CGROUP_RSVD, /* reuse page->private */ __MAX_CGROUP_SUBPAGE_INDEX = SUBPAGE_INDEX_CGROUP_RSVD, +#endif +#ifdef CONFIG_MEMORY_FAILURE + SUBPAGE_INDEX_HWPOISON, #endif __NR_USED_SUBPAGE, }; @@ -550,7 +553,7 @@ generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr, * Synchronization: Initially set after new page allocation with no * locking. When examined and modified during migration processing * (isolate, migrate, putback) the hugetlb_lock is held. - * HPG_temporary - - Set on a page that is temporarily allocated from the buddy + * HPG_temporary -- Set on a page that is temporarily allocated from the buddy * allocator. Typically used for migration target pages when no pages * are available in the pool. The hugetlb free page path will * immediately free pages with this flag set to the buddy allocator. @@ -560,6 +563,8 @@ generic_hugetlb_get_unmapped_area(struct file *file, unsigned long addr, * HPG_freed - Set when page is on the free lists. * Synchronization: hugetlb_lock held for examination and modification. * HPG_vmemmap_optimized - Set when the vmemmap pages of the page are freed. + * HPG_raw_hwp_unreliable - Set when the hugetlb page has a hwpoison sub-page + * that is not tracked by raw_hwp_page list. */ enum hugetlb_page_flags { HPG_restore_reserve = 0, @@ -567,6 +572,7 @@ enum hugetlb_page_flags { HPG_temporary, HPG_freed, HPG_vmemmap_optimized, + HPG_raw_hwp_unreliable, __NR_HPAGEFLAGS, }; @@ -613,6 +619,7 @@ HPAGEFLAG(Migratable, migratable) HPAGEFLAG(Temporary, temporary) HPAGEFLAG(Freed, freed) HPAGEFLAG(VmemmapOptimized, vmemmap_optimized) +HPAGEFLAG(RawHwpUnreliable, raw_hwp_unreliable) #ifdef CONFIG_HUGETLB_PAGE @@ -798,6 +805,15 @@ extern int dissolve_free_huge_page(struct page *page); extern int dissolve_free_huge_pages(unsigned long start_pfn, unsigned long end_pfn); +#ifdef CONFIG_MEMORY_FAILURE +extern int hugetlb_clear_page_hwpoison(struct page *hpage); +#else +static inline int hugetlb_clear_page_hwpoison(struct page *hpage) +{ + return 0; +} +#endif + #ifdef CONFIG_ARCH_ENABLE_HUGEPAGE_MIGRATION #ifndef arch_hugetlb_migration_supported static inline bool arch_hugetlb_migration_supported(struct hstate *h) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 4c30f3fcfe50..0937638fcb36 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1541,17 +1541,15 @@ static void __update_and_free_page(struct hstate *h, struct page *page) if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported()) return; - if (hugetlb_vmemmap_alloc(h, page)) { - spin_lock_irq(&hugetlb_lock); - /* - * If we cannot allocate vmemmap pages, just refuse to free the - * page and put the page back on the hugetlb free list and treat - * as a surplus page. - */ - add_hugetlb_page(h, page, true); - spin_unlock_irq(&hugetlb_lock); - return; - } + if (hugetlb_vmemmap_alloc(h, page)) + goto fail; + + /* + * Move PageHWPoison flag from head page to the raw error pages, + * which makes any healthy subpages reusable. + */ + if (unlikely(PageHWPoison(page) && hugetlb_clear_page_hwpoison(page))) + goto fail; for (i = 0; i < pages_per_huge_page(h); i++, subpage = mem_map_next(subpage, page, i)) { @@ -1572,6 +1570,16 @@ static void __update_and_free_page(struct hstate *h, struct page *page) } else { __free_pages(page, huge_page_order(h)); } + return; +fail: + spin_lock_irq(&hugetlb_lock); + /* + * If we cannot allocate vmemmap pages or cannot identify raw hwpoison + * subpages reliably, just refuse to free the page and put the page + * back on the hugetlb free list and treat as a surplus page. + */ + add_hugetlb_page(h, page, true); + spin_unlock_irq(&hugetlb_lock); } /* @@ -2115,15 +2123,6 @@ int dissolve_free_huge_page(struct page *page) */ rc = hugetlb_vmemmap_alloc(h, head); if (!rc) { - /* - * Move PageHWPoison flag from head page to the raw - * error page, which makes any subpages rather than - * the error page reusable. - */ - if (PageHWPoison(head) && page != head) { - SetPageHWPoison(page); - ClearPageHWPoison(head); - } update_and_free_page(h, head, false); } else { spin_lock_irq(&hugetlb_lock); diff --git a/mm/memory-failure.c b/mm/memory-failure.c index fb3feb1f363e..71414eb90a7a 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1499,6 +1499,82 @@ static int try_to_split_thp_page(struct page *page, const char *msg) } #ifdef CONFIG_HUGETLB_PAGE +/* + * Struct raw_hwp_page represents information about "raw error page", + * constructing singly linked list originated from ->private field of + * SUBPAGE_INDEX_HWPOISON-th tail page. + */ +struct raw_hwp_page { + struct llist_node node; + struct page *page; +}; + +static inline struct llist_head *raw_hwp_list_head(struct page *hpage) +{ + return (struct llist_head *)&page_private(hpage + SUBPAGE_INDEX_HWPOISON); +} + +static inline int hugetlb_set_page_hwpoison(struct page *hpage, + struct page *page) +{ + struct llist_head *head; + struct raw_hwp_page *raw_hwp; + struct llist_node *t, *tnode; + int ret; + + /* + * Once the hwpoison hugepage has lost reliable raw error info, + * there is little meaning to keep additional error info precisely, + * so skip to add additional raw error info. + */ + if (HPageRawHwpUnreliable(hpage)) + return -EHWPOISON; + head = raw_hwp_list_head(hpage); + llist_for_each_safe(tnode, t, head->first) { + struct raw_hwp_page *p = container_of(tnode, struct raw_hwp_page, node); + + if (p->page == page) + return -EHWPOISON; + } + + ret = TestSetPageHWPoison(hpage) ? -EHWPOISON : 0; + /* the first error event will be counted in action_result(). */ + if (ret) + num_poisoned_pages_inc(); + + raw_hwp = kmalloc(sizeof(struct raw_hwp_page), GFP_ATOMIC); + if (raw_hwp) { + raw_hwp->page = page; + llist_add(&raw_hwp->node, head); + } else { + /* + * Failed to save raw error info. We no longer trace all + * hwpoisoned subpages, and we need refuse to free/dissolve + * this hwpoisoned hugepage. + */ + SetHPageRawHwpUnreliable(hpage); + } + return ret; +} + +inline int hugetlb_clear_page_hwpoison(struct page *hpage) +{ + struct llist_head *head; + struct llist_node *t, *tnode; + + if (!HPageRawHwpUnreliable(hpage)) + ClearPageHWPoison(hpage); + head = raw_hwp_list_head(hpage); + llist_for_each_safe(tnode, t, head->first) { + struct raw_hwp_page *p = container_of(tnode, struct raw_hwp_page, node); + + SetPageHWPoison(p->page); + kfree(p); + } + llist_del_all(head); + return 0; +} + /* * Called from hugetlb code with hugetlb_lock held. * @@ -1533,7 +1609,7 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags) goto out; } - if (TestSetPageHWPoison(head)) { + if (hugetlb_set_page_hwpoison(head, page)) { ret = -EHWPOISON; goto out; } @@ -1585,7 +1661,7 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb lock_page(head); if (hwpoison_filter(p)) { - ClearPageHWPoison(head); + hugetlb_clear_page_hwpoison(head); res = -EOPNOTSUPP; goto out; } From patchwork Thu Jun 30 02:27:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12900992 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 3E8DCC43334 for ; Thu, 30 Jun 2022 02:28:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFCA46B007D; Wed, 29 Jun 2022 22:28:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BABD36B007E; Wed, 29 Jun 2022 22:28:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A737F8E0001; Wed, 29 Jun 2022 22:28:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9934D6B007D for ; Wed, 29 Jun 2022 22:28:30 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 36E4D210A6 for ; Thu, 30 Jun 2022 02:28:30 +0000 (UTC) X-FDA: 79633318380.10.A9E2404 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf31.hostedemail.com (Postfix) with ESMTP id A2AC020018 for ; Thu, 30 Jun 2022 02:28:29 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1656556108; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MDpDnstypIQpWsXVYFpb/N783eDSCsH7VG6URBxsz4o=; b=BZpb25Ii9LP1L3cmjCwGtoV4QvPq15QV8ccB3yPqjFwfSWGPDSgLmptrtTHGFI3OHNfSjx qkpXpGU76VRMnAvxjq3hATR+NxjGRNhZaLjBk8tt5c+cfIDCFuSpqc7CI4oaJtfJrc7YhC NSS6wUCAA7Tw2sXxbm4L84jgQk6P90E= From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Andrew Morton , David Hildenbrand , Mike Kravetz , Miaohe Lin , Liu Shixin , Yang Shi , Oscar Salvador , Muchun Song , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [PATCH v3 5/9] mm, hwpoison: make unpoison aware of raw error info in hwpoisoned hugepage Date: Thu, 30 Jun 2022 11:27:51 +0900 Message-Id: <20220630022755.3362349-6-naoya.horiguchi@linux.dev> In-Reply-To: <20220630022755.3362349-1-naoya.horiguchi@linux.dev> References: <20220630022755.3362349-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=BZpb25Ii; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf31.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656556109; a=rsa-sha256; cv=none; b=VRLo2sLtR4O8eTYESYcqrqhgUTNLGOX4MVQCdc4WSgA3O6IYj5CYHTstozZtgi5GlUVa3j 8akuyJ78PrySh+ojCwzPV6dZqCr04oQInnm2ZpR/yfSYvO6hGV85lUtOEy2tp+f4xJuLj9 CvIN2OCW4+SNHX0bMplW5lxSLkg5V0g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656556109; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MDpDnstypIQpWsXVYFpb/N783eDSCsH7VG6URBxsz4o=; b=nEcPZzunHiIY5y2XOCLIPS5nhYrKSeUYOe59O9oWS5yR5fb/3I7vRkuMCyga9X6XXi4OFW kzNOCgIvIram7aCAOb74EoJghmlP+jNRpMnBTPhdctrD/cHa+QG3MoKb9oDVe5+zcJCo6P ubIRLBkgGnYKr4ImDUn6SEMvcvvX+2U= X-Rspam-User: Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=BZpb25Ii; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf31.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: A2AC020018 X-Stat-Signature: fk15syiq8nhiedz57875ig737cqg6yx9 X-HE-Tag: 1656556109-588619 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: From: Naoya Horiguchi Raw error info list needs to be removed when hwpoisoned hugetlb is unpoisoned. And unpoison handler needs to know how many errors there are in the target hugepage. So add them. Signed-off-by: Naoya Horiguchi --- include/linux/swapops.h | 9 +++++++++ mm/memory-failure.c | 32 ++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/include/linux/swapops.h b/include/linux/swapops.h index 9584c2e1c54a..ad62776ee99c 100644 --- a/include/linux/swapops.h +++ b/include/linux/swapops.h @@ -494,6 +494,11 @@ static inline void num_poisoned_pages_dec(void) atomic_long_dec(&num_poisoned_pages); } +static inline void num_poisoned_pages_sub(long i) +{ + atomic_long_sub(i, &num_poisoned_pages); +} + #else static inline swp_entry_t make_hwpoison_entry(struct page *page) @@ -514,6 +519,10 @@ static inline struct page *hwpoison_entry_to_page(swp_entry_t entry) static inline void num_poisoned_pages_inc(void) { } + +static inline void num_poisoned_pages_sub(long i) +{ +} #endif static inline int non_swap_entry(swp_entry_t entry) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 71414eb90a7a..dc90bfadb1dd 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1557,22 +1557,33 @@ static inline int hugetlb_set_page_hwpoison(struct page *hpage, return ret; } -inline int hugetlb_clear_page_hwpoison(struct page *hpage) +static inline long free_raw_hwp_pages(struct page *hpage, bool move_flag) { struct llist_head *head; struct llist_node *t, *tnode; + long count = 0; - if (!HPageRawHwpUnreliable(hpage)) - ClearPageHWPoison(hpage); head = raw_hwp_list_head(hpage); llist_for_each_safe(tnode, t, head->first) { struct raw_hwp_page *p = container_of(tnode, struct raw_hwp_page, node); - SetPageHWPoison(p->page); + if (move_flag) + SetPageHWPoison(p->page); kfree(p); + count++; } llist_del_all(head); - return 0; + return count; +} + +inline int hugetlb_clear_page_hwpoison(struct page *hpage) +{ + int ret = -EBUSY; + + if (!HPageRawHwpUnreliable(hpage)) + ret = !TestClearPageHWPoison(hpage); + free_raw_hwp_pages(hpage, true); + return ret; } /* @@ -1714,6 +1725,10 @@ static inline int try_memory_failure_hugetlb(unsigned long pfn, int flags, int * { return 0; } + +static inline void free_raw_hwp_pages(struct page *hpage, bool move_flag) +{ +} #endif static int memory_failure_dev_pagemap(unsigned long pfn, int flags, @@ -2173,6 +2188,7 @@ int unpoison_memory(unsigned long pfn) struct page *p; int ret = -EBUSY; int freeit = 0; + long count = 1; static DEFINE_RATELIMIT_STATE(unpoison_rs, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST); @@ -2220,6 +2236,8 @@ int unpoison_memory(unsigned long pfn) ret = get_hwpoison_page(p, MF_UNPOISON); if (!ret) { + if (PageHuge(p)) + count = free_raw_hwp_pages(page, false); ret = TestClearPageHWPoison(page) ? 0 : -EBUSY; } else if (ret < 0) { if (ret == -EHWPOISON) { @@ -2228,6 +2246,8 @@ int unpoison_memory(unsigned long pfn) unpoison_pr_info("Unpoison: failed to grab page %#lx\n", pfn, &unpoison_rs); } else { + if (PageHuge(p)) + count = free_raw_hwp_pages(page, false); freeit = !!TestClearPageHWPoison(p); put_page(page); @@ -2240,7 +2260,7 @@ int unpoison_memory(unsigned long pfn) unlock_mutex: mutex_unlock(&mf_mutex); if (!ret || freeit) { - num_poisoned_pages_dec(); + num_poisoned_pages_sub(count); unpoison_pr_info("Unpoison: Software-unpoisoned page %#lx\n", page_to_pfn(p), &unpoison_rs); } From patchwork Thu Jun 30 02:27:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12900993 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 D1D0CC43334 for ; Thu, 30 Jun 2022 02:28:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 719308E0002; Wed, 29 Jun 2022 22:28:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CA218E0001; Wed, 29 Jun 2022 22:28:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 592A88E0002; Wed, 29 Jun 2022 22:28:34 -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 4A2A78E0001 for ; Wed, 29 Jun 2022 22:28:34 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 21F251204BB for ; Thu, 30 Jun 2022 02:28:34 +0000 (UTC) X-FDA: 79633318548.04.AA45BB4 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf30.hostedemail.com (Postfix) with ESMTP id A3A6C80037 for ; Thu, 30 Jun 2022 02:28:33 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1656556112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SI3BXzvQ1paTor1nht5oQndWpNg1sLLCA8PWdy7uGZs=; b=Wg7Kx1F6zatg0dpsAhIlsBbPFC5GUv6pxbEgRdbnnSrtjXCG9nO/CH7GNsy4i3F/BPBX4u b5qw2lr4r8OE13qoFbKwAUOtYxFC8UEoxSSkEM2KUVhglk6nJKKWZ/TThRaGmjIrgNka38 KWoOu0M1FgLTr9Ac3EaYVxx79iGXU3s= From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Andrew Morton , David Hildenbrand , Mike Kravetz , Miaohe Lin , Liu Shixin , Yang Shi , Oscar Salvador , Muchun Song , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [PATCH v3 6/9] mm, hwpoison: set PG_hwpoison for busy hugetlb pages Date: Thu, 30 Jun 2022 11:27:52 +0900 Message-Id: <20220630022755.3362349-7-naoya.horiguchi@linux.dev> In-Reply-To: <20220630022755.3362349-1-naoya.horiguchi@linux.dev> References: <20220630022755.3362349-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656556113; a=rsa-sha256; cv=none; b=dcblu0vYtl2r+hOaFseWZ0Pd4vOs4CriWbvBZ8TKF5Ms339Y/b5KFfBY4HYc8xyrzr3b1K ULJJI2c6ILUxOb1lxtSB5Pb3c3VtONz1VnneF/OtUrNUJQERy6zNpbOdkhD1B4C/CJulv3 cR2yZJZqpi8Dkj1KwZ9FHMt7wmwAGQI= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Wg7Kx1F6; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf30.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656556113; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SI3BXzvQ1paTor1nht5oQndWpNg1sLLCA8PWdy7uGZs=; b=nt/bMRYZXu6MPifFg5Q4mur2fHdclIn4WnlkDKkf8xSIohUz+Hv0Xoy+3RQ+nIu1OuPlWM /UqtS1uGIdjPxg/wQOFaTwTGSFkSig2zCWRorajYGzRXPQIHXE6TbFoAegLoogd/t9QgIe lnaad0brQAokJCGWuI9Kj2BVGR9o97E= X-Rspamd-Queue-Id: A3A6C80037 X-Rspam-User: Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Wg7Kx1F6; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf30.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev X-Rspamd-Server: rspam02 X-Stat-Signature: 4coo9krp99gbbfkbejqc9k56c59zben1 X-HE-Tag: 1656556113-565028 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: From: Naoya Horiguchi If memory_failure() fails to grab page refcount on a hugetlb page because it's busy, it returns without setting PG_hwpoison on it. This not only loses a chance of error containment, but breaks the rule that action_result() should be called only when memory_failure() do any of handling work (even if that's just setting PG_hwpoison). This inconsistency could harm code maintainability. So set PG_hwpoison and call hugetlb_set_page_hwpoison() for such a case. Fixes: 405ce051236c ("mm/hwpoison: fix race between hugetlb free/demotion and memory_failure_hugetlb()") Signed-off-by: Naoya Horiguchi Reviewed-by: Miaohe Lin --- include/linux/mm.h | 1 + mm/memory-failure.c | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 4346e51484ba..044dc5a2e361 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3233,6 +3233,7 @@ enum mf_flags { MF_SOFT_OFFLINE = 1 << 3, MF_UNPOISON = 1 << 4, MF_SW_SIMULATED = 1 << 5, + MF_NO_RETRY = 1 << 6, }; extern int memory_failure(unsigned long pfn, int flags); extern void memory_failure_queue(unsigned long pfn, int flags); diff --git a/mm/memory-failure.c b/mm/memory-failure.c index dc90bfadb1dd..81e591cf8b4a 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1617,7 +1617,8 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags) count_increased = true; } else { ret = -EBUSY; - goto out; + if (!(flags & MF_NO_RETRY)) + goto out; } if (hugetlb_set_page_hwpoison(head, page)) { @@ -1644,7 +1645,6 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb struct page *p = pfn_to_page(pfn); struct page *head; unsigned long page_flags; - bool retry = true; *hugetlb = 1; retry: @@ -1660,8 +1660,8 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb } return res; } else if (res == -EBUSY) { - if (retry) { - retry = false; + if (!(flags & MF_NO_RETRY)) { + flags |= MF_NO_RETRY; goto retry; } action_result(pfn, MF_MSG_UNKNOWN, MF_IGNORED); From patchwork Thu Jun 30 02:27:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12900994 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 D47EBC43334 for ; Thu, 30 Jun 2022 02:28:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6F3C78E0003; Wed, 29 Jun 2022 22:28:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A2238E0001; Wed, 29 Jun 2022 22:28:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 591488E0003; Wed, 29 Jun 2022 22:28:38 -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 4A4198E0001 for ; Wed, 29 Jun 2022 22:28:38 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 246B760388 for ; Thu, 30 Jun 2022 02:28:38 +0000 (UTC) X-FDA: 79633318716.17.80F5B9F Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf22.hostedemail.com (Postfix) with ESMTP id 9FC28C0031 for ; Thu, 30 Jun 2022 02:28:37 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1656556116; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F1HjpbdSg3INkY0e3nuMILPlQpmtYTlbMJAcRh/swko=; b=TXlbsl+jLSMbzIlvE6VKU8WOFAO2e2aBhqXGEKD5kEcPLHiYms/CrrRiHMSAYCjDMBvNJ9 fxD63qOHRTm8VvAIoskAbJ5oxA2hLWzGGuVasdhTBrfzJQxja3e6/29L5MbxK1sYkL4pYu tsZ2cT1bPVOgDXSDTKr8LCzdf7SflHg= From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Andrew Morton , David Hildenbrand , Mike Kravetz , Miaohe Lin , Liu Shixin , Yang Shi , Oscar Salvador , Muchun Song , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [PATCH v3 7/9] mm, hwpoison: make __page_handle_poison returns int Date: Thu, 30 Jun 2022 11:27:53 +0900 Message-Id: <20220630022755.3362349-8-naoya.horiguchi@linux.dev> In-Reply-To: <20220630022755.3362349-1-naoya.horiguchi@linux.dev> References: <20220630022755.3362349-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656556117; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=F1HjpbdSg3INkY0e3nuMILPlQpmtYTlbMJAcRh/swko=; b=UVMR05OKHfYJU6WpItVU2ul0tJjTp2CY/fSSTQzb02ofUUxB1g9eH4Uw4g+MMNAbzY7Rh7 SAsgyfIYUQ63M+fDRhZr9fQXvVeQXON5NP1sLcSDBZScvUfqD0C0NxRpo8vhdgwsCCnm/n Z0jftWXHAcQIZcRtcc9elCmQVolWx9c= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656556117; a=rsa-sha256; cv=none; b=xe3zSwnFcBo6/7QsNHVgE4hvCxZGepppQt/twzlZTlUFya2hc6lE6slcEr9fLx8kkRO31T OmBZ+zXkQD26GOETTBeR31h1jWHvzro4arjHCA/PI/GafM4314fhvh9JgdCjE6iqN8j8GB UUOR3a3TDok0KQQnoyZtm3aKPxdDm/w= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=TXlbsl+j; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf22.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=TXlbsl+j; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf22.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev X-Rspamd-Server: rspam03 X-Rspam-User: X-Stat-Signature: ptp7w9r7wg3q6umyui89xhz4ofmc768p X-Rspamd-Queue-Id: 9FC28C0031 X-HE-Tag: 1656556117-807008 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: From: Naoya Horiguchi __page_handle_poison() returns bool that shows whether take_page_off_buddy() has passed or not now. But we will want to distinguish another case of "dissolve has passed but taking off failed" by its return value. So change the type of the return value. No functional change. Signed-off-by: Naoya Horiguchi Reviewed-by: Miaohe Lin --- v2 -> v3: - move deleting "res = MF_FAILED" to the later patch. (by Miaohe) --- mm/memory-failure.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 81e591cf8b4a..6c7b9129eade 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -71,7 +71,13 @@ atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0); static bool hw_memory_failure __read_mostly = false; -static bool __page_handle_poison(struct page *page) +/* + * Return values: + * 1: the page is dissolved (if needed) and taken off from buddy, + * 0: the page is dissolved (if needed) and not taken off from buddy, + * < 0: failed to dissolve. + */ +static int __page_handle_poison(struct page *page) { int ret; @@ -81,7 +87,7 @@ static bool __page_handle_poison(struct page *page) ret = take_page_off_buddy(page); zone_pcp_enable(page_zone(page)); - return ret > 0; + return ret; } static bool page_handle_poison(struct page *page, bool hugepage_or_freepage, bool release) @@ -91,7 +97,7 @@ static bool page_handle_poison(struct page *page, bool hugepage_or_freepage, boo * Doing this check for free pages is also fine since dissolve_free_huge_page * returns 0 for non-hugetlb pages as well. */ - if (!__page_handle_poison(page)) + if (__page_handle_poison(page) <= 0) /* * We could fail to take off the target page from buddy * for example due to racy page allocation, but that's @@ -1048,7 +1054,7 @@ static int me_huge_page(struct page_state *ps, struct page *p) * subpages. */ put_page(hpage); - if (__page_handle_poison(p)) { + if (__page_handle_poison(p) > 0) { page_ref_inc(p); res = MF_RECOVERED; } @@ -1684,7 +1690,7 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb if (res == 0) { unlock_page(head); res = MF_FAILED; - if (__page_handle_poison(p)) { + if (__page_handle_poison(p) > 0) { page_ref_inc(p); res = MF_RECOVERED; } From patchwork Thu Jun 30 02:27:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12900995 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 06D01C43334 for ; Thu, 30 Jun 2022 02:28:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 93C978E0005; Wed, 29 Jun 2022 22:28:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8EC8A8E0001; Wed, 29 Jun 2022 22:28:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 78D1E8E0005; Wed, 29 Jun 2022 22:28:42 -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 68AEF8E0001 for ; Wed, 29 Jun 2022 22:28:42 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 33544207DF for ; Thu, 30 Jun 2022 02:28:42 +0000 (UTC) X-FDA: 79633318884.03.7ABFF87 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf10.hostedemail.com (Postfix) with ESMTP id 9CF79C0037 for ; Thu, 30 Jun 2022 02:28:41 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1656556120; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4mMm895HUGvB33w+4B1AJ2mtagQIDtCZZ7dWMv/EeV8=; b=pxOQzK9c3614wZpIA9bTTIlOONEBtlmPH5jhzWmnJd1T0tQkE3B3zB0yTclKMyK9dLA+v/ bwLME081ejMd5Xc+Kys/lGZvLXfzPMxebjdTvUXtI+e0XK6dls/CrW3YkoOdG1HtAUEqC5 yOfSTu9FiikLkQrq1tWumgXTkTDSdP4= From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Andrew Morton , David Hildenbrand , Mike Kravetz , Miaohe Lin , Liu Shixin , Yang Shi , Oscar Salvador , Muchun Song , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [PATCH v3 8/9] mm, hwpoison: skip raw hwpoison page in freeing 1GB hugepage Date: Thu, 30 Jun 2022 11:27:54 +0900 Message-Id: <20220630022755.3362349-9-naoya.horiguchi@linux.dev> In-Reply-To: <20220630022755.3362349-1-naoya.horiguchi@linux.dev> References: <20220630022755.3362349-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656556122; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4mMm895HUGvB33w+4B1AJ2mtagQIDtCZZ7dWMv/EeV8=; b=dDi5c6WWp34h2tRrz0gcxNY5XTFDKIKzaG4hzzGwpFstjbV5GCz/ODHYDS+2EG10yHHi7D abAiQqFOBdMWc/dlDq43J7JsemcXkrgqSQSAFWTZVex0g/8Ny8ubqAwdeDhXLZxjfmveNK 0lxHLeveAx7ri+rq1crIp9XnECDwJiM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656556122; a=rsa-sha256; cv=none; b=VI/2LbEG+fGDGqfVhGJ4+nQVvTfP3Io1EpgjFfH8s1xx8tg7t3qkh6muZkuKFi19qdxcRP 57DIiYtGqbHJ7MgiEC5LObEiaEIEA+kLenddsPNxhseus147DOC+I+E85fyOhvXuERHXlG ivQOSTXxT0Sokoj+QxRO8HUiaCJcLl0= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=pxOQzK9c; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=pxOQzK9c; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev X-Rspamd-Server: rspam03 X-Rspam-User: X-Stat-Signature: hkm3obhkt649jqbjxyk4az81be5odycy X-Rspamd-Queue-Id: 9CF79C0037 X-HE-Tag: 1656556121-62529 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: From: Naoya Horiguchi Currently if memory_failure() (modified to remove blocking code with subsequent patch) is called on a page in some 1GB hugepage, memory error handling fails and the raw error page gets into leaked state. The impact is small in production systems (just leaked single 4kB page), but this limits the testability because unpoison doesn't work for it. We can no longer create 1GB hugepage on the 1GB physical address range with such leaked pages, that's not useful when testing on small systems. When a hwpoison page in a 1GB hugepage is handled, it's caught by the PageHWPoison check in free_pages_prepare() because the 1GB hugepage is broken down into raw error pages before coming to this point: if (unlikely(PageHWPoison(page)) && !order) { ... return false; } Then, the page is not sent to buddy and the page refcount is left 0. Originally this check is supposed to work when the error page is freed from page_handle_poison() (that is called from soft-offline), but now we are opening another path to call it, so the callers of __page_handle_poison() need to handle the case by considering the return value 0 as success. Then page refcount for hwpoison is properly incremented so unpoison works. Signed-off-by: Naoya Horiguchi Reviewed-by: Miaohe Lin --- v2 -> v3: - remove "res = MF_FAILED" in try_memory_failure_hugetlb (by Miaohe) --- mm/memory-failure.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 6c7b9129eade..6a9b11807ee6 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1046,7 +1046,6 @@ static int me_huge_page(struct page_state *ps, struct page *p) res = truncate_error_page(hpage, page_to_pfn(p), mapping); unlock_page(hpage); } else { - res = MF_FAILED; unlock_page(hpage); /* * migration entry prevents later access on error hugepage, @@ -1054,9 +1053,11 @@ static int me_huge_page(struct page_state *ps, struct page *p) * subpages. */ put_page(hpage); - if (__page_handle_poison(p) > 0) { + if (__page_handle_poison(p) >= 0) { page_ref_inc(p); res = MF_RECOVERED; + } else { + res = MF_FAILED; } } @@ -1689,10 +1690,11 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb */ if (res == 0) { unlock_page(head); - res = MF_FAILED; - if (__page_handle_poison(p) > 0) { + if (__page_handle_poison(p) >= 0) { page_ref_inc(p); res = MF_RECOVERED; + } else { + res = MF_FAILED; } action_result(pfn, MF_MSG_FREE_HUGE, res); return res == MF_RECOVERED ? 0 : -EBUSY; From patchwork Thu Jun 30 02:27:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12900996 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 E42F3C433EF for ; Thu, 30 Jun 2022 02:28:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E0D68E0006; Wed, 29 Jun 2022 22:28:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 765B28E0001; Wed, 29 Jun 2022 22:28:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62FAD8E0006; Wed, 29 Jun 2022 22:28:46 -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 5399F8E0001 for ; Wed, 29 Jun 2022 22:28:46 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3370C350DD for ; Thu, 30 Jun 2022 02:28:46 +0000 (UTC) X-FDA: 79633319052.13.FE3B91B Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf14.hostedemail.com (Postfix) with ESMTP id A860010001D for ; Thu, 30 Jun 2022 02:28:45 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1656556124; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sQp82hDOk82vRv92dNThK5SQ8yKvxwYYoFoVJwwIfdQ=; b=SQSSYIl1u2E0NKLfQjCeFwPw4LflsTKAjwE0RiatjPRLkLJA7dqf2Y+NjoBilHeFrUf7cS hGJYAqx3bYUs3bCHvOgg+hIuz5SNUljq5isddMb+JEvFITT+WC7pv7O+udHCCfjGP/mRV0 +D9G7Jg2/69W1MTxSlscl+537HgFeU0= From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Andrew Morton , David Hildenbrand , Mike Kravetz , Miaohe Lin , Liu Shixin , Yang Shi , Oscar Salvador , Muchun Song , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [PATCH v3 9/9] mm, hwpoison: enable memory error handling on 1GB hugepage Date: Thu, 30 Jun 2022 11:27:55 +0900 Message-Id: <20220630022755.3362349-10-naoya.horiguchi@linux.dev> In-Reply-To: <20220630022755.3362349-1-naoya.horiguchi@linux.dev> References: <20220630022755.3362349-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656556125; a=rsa-sha256; cv=none; b=VBXqB9eRT4j8r5ZgfzUVvJAeOTJrEkcs12xIZ6sp9hySAFPNwXcXr/on5xBF31etKktznD a/lw6EYLgbglxHkWHEhaa4GdS4uVdcEH4FfHxcLoiDmAmbC5FxLrWUv5MtFdDhZpe1pPam aSAZ9uCcqkweSirVyxOAYpL7CZv0DrE= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=SQSSYIl1; spf=pass (imf14.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656556125; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sQp82hDOk82vRv92dNThK5SQ8yKvxwYYoFoVJwwIfdQ=; b=G/mFZDSs8cRzsOO3vL8hYhxjoJ8+OYFr2wKt6h/uo7Yy2SYZwnPNKbWIJ+2tU9jqoWFSX3 Jz3KtrWQmLezryNYkHtKogHRDQKo6ySo+m2oPFD71SaEEdH4iEK69V2qUVMUXYJdFNnIwQ Ifyp8saPO0I3lpJjvSjxHkTo5RXnqGE= X-Rspam-User: X-Rspamd-Server: rspam04 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=SQSSYIl1; spf=pass (imf14.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Stat-Signature: bcpdgnqagw35tue9abg658ac3189y6my X-Rspamd-Queue-Id: A860010001D X-HE-Tag: 1656556125-973931 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: From: Naoya Horiguchi Now error handling code is prepared, so remove the blocking code and enable memory error handling on 1GB hugepage. Signed-off-by: Naoya Horiguchi Reviewed-by: Miaohe Lin --- include/linux/mm.h | 1 - include/ras/ras_event.h | 1 - mm/memory-failure.c | 16 ---------------- 3 files changed, 18 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 044dc5a2e361..9d7e9b5a4d1d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3284,7 +3284,6 @@ enum mf_action_page_type { MF_MSG_DIFFERENT_COMPOUND, MF_MSG_HUGE, MF_MSG_FREE_HUGE, - MF_MSG_NON_PMD_HUGE, MF_MSG_UNMAP_FAILED, MF_MSG_DIRTY_SWAPCACHE, MF_MSG_CLEAN_SWAPCACHE, diff --git a/include/ras/ras_event.h b/include/ras/ras_event.h index d0337a41141c..cbd3ddd7c33d 100644 --- a/include/ras/ras_event.h +++ b/include/ras/ras_event.h @@ -360,7 +360,6 @@ TRACE_EVENT(aer_event, EM ( MF_MSG_DIFFERENT_COMPOUND, "different compound page after locking" ) \ EM ( MF_MSG_HUGE, "huge page" ) \ EM ( MF_MSG_FREE_HUGE, "free huge page" ) \ - EM ( MF_MSG_NON_PMD_HUGE, "non-pmd-sized huge page" ) \ EM ( MF_MSG_UNMAP_FAILED, "unmapping failed page" ) \ EM ( MF_MSG_DIRTY_SWAPCACHE, "dirty swapcache page" ) \ EM ( MF_MSG_CLEAN_SWAPCACHE, "clean swapcache page" ) \ diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 6a9b11807ee6..6ee5cbe0cbab 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -728,7 +728,6 @@ static const char * const action_page_types[] = { [MF_MSG_DIFFERENT_COMPOUND] = "different compound page after locking", [MF_MSG_HUGE] = "huge page", [MF_MSG_FREE_HUGE] = "free huge page", - [MF_MSG_NON_PMD_HUGE] = "non-pmd-sized huge page", [MF_MSG_UNMAP_FAILED] = "unmapping failed page", [MF_MSG_DIRTY_SWAPCACHE] = "dirty swapcache page", [MF_MSG_CLEAN_SWAPCACHE] = "clean swapcache page", @@ -1702,21 +1701,6 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb page_flags = head->flags; - /* - * TODO: hwpoison for pud-sized hugetlb doesn't work right now, so - * simply disable it. In order to make it work properly, we need - * make sure that: - * - conversion of a pud that maps an error hugetlb into hwpoison - * entry properly works, and - * - other mm code walking over page table is aware of pud-aligned - * hwpoison entries. - */ - if (huge_page_size(page_hstate(head)) > PMD_SIZE) { - action_result(pfn, MF_MSG_NON_PMD_HUGE, MF_IGNORED); - res = -EBUSY; - goto out; - } - if (!hwpoison_user_mappings(p, pfn, flags, head)) { action_result(pfn, MF_MSG_UNMAP_FAILED, MF_IGNORED); res = -EBUSY;