From patchwork Thu Jul 14 04:24:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12917274 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 11C15C43334 for ; Thu, 14 Jul 2022 04:24:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 78B27940170; Thu, 14 Jul 2022 00:24:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 712D4940134; Thu, 14 Jul 2022 00:24:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B3D7940170; Thu, 14 Jul 2022 00:24:37 -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 47569940134 for ; Thu, 14 Jul 2022 00:24:37 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 1EB04602D3 for ; Thu, 14 Jul 2022 04:24:37 +0000 (UTC) X-FDA: 79684414194.23.D1EF731 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf14.hostedemail.com (Postfix) with ESMTP id AD72810006A for ; Thu, 14 Jul 2022 04:24:36 +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=1657772675; 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=CM1fnHF5+SZu84iYIKJ8/xtAtt5Of29zh4flgmzpzHg=; b=BwviJmTV1NrutOKVW7t2ZR6/VQYai6/hAH0p6/moeb7eViAcHkhWJ74cRMf/BH6aWMBfOt JTXER4Pykc+d0ZrjjBIFmZ9MbvYJR0obkimJH7iVtGyJTVv3Re+3nv86VDVzq29/4mFDg3 m+chYuz91PWa0PJiptIsKIaUEdj78/w= 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: [mm-unstable PATCH v7 1/8] mm/hugetlb: check gigantic_page_runtime_supported() in return_unused_surplus_pages() Date: Thu, 14 Jul 2022 13:24:13 +0900 Message-Id: <20220714042420.1847125-2-naoya.horiguchi@linux.dev> In-Reply-To: <20220714042420.1847125-1-naoya.horiguchi@linux.dev> References: <20220714042420.1847125-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=1657772676; a=rsa-sha256; cv=none; b=Q00T8LcCnHt9KJgg920OZ0G3Gx4OvxnSvr8J0vI0WRuMQ0oEi7Zlzo0o+EApJoL/8C5FVc L4gK48jQL/nNEp8cOhp7iD9QioPyl8rHt9i3zwEK8imKq/VuL1xcJ8GixPniWkP+BuC9fy PpAI8r64EuUDoQazmukC7qhtYp9Tkts= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=BwviJmTV; 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=1657772676; 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=CM1fnHF5+SZu84iYIKJ8/xtAtt5Of29zh4flgmzpzHg=; b=fPhCxuwm7tsD7krjfx8Ai6PIvoDbloSH/NEobUpJ/XkXgSdSSSI1PiOs9CiVGhm9CQ5nt0 FQx7jtELKEqyWuNWfH5KG6gJXek4qeGtBKc0PPrcNkGl3yqQfquJzT3Cnm6zy1+jD39Vk+ kd76V1v9OwGe5LHIGjYIpX5FQLtrBBI= X-Rspamd-Queue-Id: AD72810006A Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=BwviJmTV; 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-Rspamd-Server: rspam02 X-Rspam-User: X-Stat-Signature: zyb7hf7mjkr8ib4wumx7u94fo4c5re36 X-HE-Tag: 1657772676-991871 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 Reviewed-by: Miaohe Lin --- v4 -> v5: - drop additional gigantic_page_runtime_supported() checks. 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 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a4506ed1f1db..cf8ccee7654c 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; /* From patchwork Thu Jul 14 04:24:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12917275 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 339FCC43334 for ; Thu, 14 Jul 2022 04:24:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BCEC5940171; Thu, 14 Jul 2022 00:24:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B5820940134; Thu, 14 Jul 2022 00:24:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F990940171; Thu, 14 Jul 2022 00:24:41 -0400 (EDT) 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 8C102940134 for ; Thu, 14 Jul 2022 00:24:41 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5C2163381A for ; Thu, 14 Jul 2022 04:24:41 +0000 (UTC) X-FDA: 79684414362.15.26555B5 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf03.hostedemail.com (Postfix) with ESMTP id D744520039 for ; Thu, 14 Jul 2022 04:24:40 +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=1657772679; 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=uxYP30zRX3+087a7ADNvtSYGr7OYdBOK6+qjv5apzug=; b=sGAgNWl+QsPuHrDIKzPoBBx6HVHedRs64JXAKDuyH1mhvAaIvkUIwJIwreEZXvxkTNVElP 3c0Z6BUl/ANe58vB+qbj24Xi8DpYV0IC5ddQGxxDvHrQM+RKyM/pJ3oGzdVa9KdApisg37 sWcmVrsOAyW2EBgafjcV6q6BrUuw+SU= 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: [mm-unstable PATCH v7 2/8] mm/hugetlb: make pud_huge() and follow_huge_pud() aware of non-present pud entry Date: Thu, 14 Jul 2022 13:24:14 +0900 Message-Id: <20220714042420.1847125-3-naoya.horiguchi@linux.dev> In-Reply-To: <20220714042420.1847125-1-naoya.horiguchi@linux.dev> References: <20220714042420.1847125-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; imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=sGAgNWl+; dmarc=pass (policy=none) header.from=linux.dev; 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657772681; 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=uxYP30zRX3+087a7ADNvtSYGr7OYdBOK6+qjv5apzug=; b=Pi7IC90znB1Smj0OrlcEzsL93ihUOnqlTlMM3XzeO8l8l0Uki9JJ9LIgaCjovx93n1QzwN moeUF33vgaE40D1aR9Gsd6D4+GdM4uCUTmuybiRhcXOqQulgkzKD1axmpMdlXlYRHCEjJM eAzaTtG9ToasEyGA5YhuVS41zXX+d+Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657772681; a=rsa-sha256; cv=none; b=WEvGPQhCkLKvC5j0JSC8FbvbKPTy09XrJMP19LtD1RIgIPxHQTRY6jKqP/qVMhm6BlKSua DPqTY2PmuIyb86DTkqPy/Q/z3r02uNY/rJU5U0ilkMbOJ3G+sqB6hu3YGPyTAaVIrSO4DO IWxtClvBF3VmjxpOWc0c17JB84/K9yM= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D744520039 X-Stat-Signature: rrk5uhkd6ffyf6y5rm4mzub1qkcz34ba Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=sGAgNWl+; dmarc=pass (policy=none) header.from=linux.dev; 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 X-Rspam-User: X-HE-Tag: 1657772680-702551 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 Reviewed-by: Miaohe Lin Reviewed-by: Mike Kravetz --- 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 509408da0da1..6b3033845c6d 100644 --- a/arch/x86/mm/hugetlbpage.c +++ b/arch/x86/mm/hugetlbpage.c @@ -30,9 +30,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; } #ifdef CONFIG_HUGETLB_PAGE diff --git a/mm/hugetlb.c b/mm/hugetlb.c index cf8ccee7654c..77119d93a0f9 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6978,10 +6978,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 Jul 14 04:24:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12917276 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 DCB74C43334 for ; Thu, 14 Jul 2022 04:24:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6EDF3940172; Thu, 14 Jul 2022 00:24:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6766E940134; Thu, 14 Jul 2022 00:24:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4EF44940172; Thu, 14 Jul 2022 00:24:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 36E04940134 for ; Thu, 14 Jul 2022 00:24:46 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0860B2033B for ; Thu, 14 Jul 2022 04:24:46 +0000 (UTC) X-FDA: 79684414572.16.C53E41A Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf06.hostedemail.com (Postfix) with ESMTP id 5F07A18002E for ; Thu, 14 Jul 2022 04:24: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=1657772684; 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=2HEiXvveIRaM1Imnm50qU12/KAXnRIn+n/f2e60/B68=; b=PhsMb1z9Nk+MJY+yVYXjYwIobwbZKtnK8UHLyqznKyNsnU/WSUVDdbfMtEW1j8Rvdr+K2P hH6iuHdyCjDRDe+68OIGg74huSkFd8DKCbJDmGosC9fFjwuxx/vmpbaKVliweoifVDssBK /B6/oz3lNU4oujbJHWXZNDpy4mLqGZ4= 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: [mm-unstable PATCH v7 3/8] mm, hwpoison, hugetlb: support saving mechanism of raw error pages Date: Thu, 14 Jul 2022 13:24:15 +0900 Message-Id: <20220714042420.1847125-4-naoya.horiguchi@linux.dev> In-Reply-To: <20220714042420.1847125-1-naoya.horiguchi@linux.dev> References: <20220714042420.1847125-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; imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=PhsMb1z9; spf=pass (imf06.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657772685; a=rsa-sha256; cv=none; b=Rf3shD8uzxiMVM+Hxbt1O8dS6AAi+TDhhOswku5x91zz6oug1PxAH36/V6KLoXtAqz3lBw gdU0jUt2difpDtOATPt5jbYxyv6dx6K+tEFvlqpeO6ED6XWJWG4sjAu+V22gKSb21FH2n2 zGxtkIixewe/UevneZf3gqdGUKWw5+g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657772685; 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=2HEiXvveIRaM1Imnm50qU12/KAXnRIn+n/f2e60/B68=; b=VW9bB6F7BSS+ySl6sv6LbISmtZAeKI2bHoEETpMKUe1K6No2FThRv7WkPJ5G8tHonwMaeh 3AtcHt729EPcSAVXT9BScTaGn6owxi1rFKg2fgpD4S6HV7Wlhhd4uvPd6RVgE1mNUp8zuv 7ZO3kP4ndYxs10m9Ds2aLGSW4zmdCz0= X-Rspamd-Queue-Id: 5F07A18002E Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=PhsMb1z9; spf=pass (imf06.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-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: cqc5qqrq6pupjdax7ppntnch6ouc3btx X-HE-Tag: 1657772685-899409 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 Reported-by: kernel test robot Reviewed-by: Miaohe Lin --- v6 -> v7: - free raw_hwp_page list when HPageRawHwpUnreliable is set, - hugetlb_clear_page_hwpoison returns immediately when HPageRawHwpUnreliable is set. v5 -> v6: - remove additional buggy HPageRawHwpUnreliable check v4 -> v5: - fixed build error (reported by kernel test robot). - do not try to undo remove_hugetlb_page() when HPageRawHwpUnreliable is true, - check HPageRawHwpUnreliable() before hugetlb_vmemmap_restore(), - call num_poisoned_pages_inc() in hugetlb_set_page_hwpoison() when kalloc succeeds, - remove "inline" in the definition of hugetlb_clear_page_hwpoison(). v3 -> v4: - resolve conflict with "mm: hugetlb_vmemmap: improve hugetlb_vmemmap code readability", use hugetlb_vmemmap_restore() instead of hugetlb_vmemmap_alloc(). 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 --- include/linux/hugetlb.h | 17 +++++++- mm/hugetlb.c | 23 ++++++----- mm/memory-failure.c | 89 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 116 insertions(+), 13 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 6d0620edf0a6..3ec981a0d8b3 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, }; @@ -551,7 +554,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. @@ -561,6 +564,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, @@ -568,6 +573,7 @@ enum hugetlb_page_flags { HPG_temporary, HPG_freed, HPG_vmemmap_optimized, + HPG_raw_hwp_unreliable, __NR_HPAGEFLAGS, }; @@ -614,6 +620,7 @@ HPAGEFLAG(Migratable, migratable) HPAGEFLAG(Temporary, temporary) HPAGEFLAG(Freed, freed) HPAGEFLAG(VmemmapOptimized, vmemmap_optimized) +HPAGEFLAG(RawHwpUnreliable, raw_hwp_unreliable) #ifdef CONFIG_HUGETLB_PAGE @@ -796,6 +803,14 @@ 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 void hugetlb_clear_page_hwpoison(struct page *hpage); +#else +static inline void hugetlb_clear_page_hwpoison(struct page *hpage) +{ +} +#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 77119d93a0f9..e590632bc70f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1535,6 +1535,13 @@ static void __update_and_free_page(struct hstate *h, struct page *page) if (hstate_is_gigantic(h) && !gigantic_page_runtime_supported()) return; + /* + * If we don't know which subpages are hwpoisoned, we can't free + * the hugepage, so it's leaked intentionally. + */ + if (HPageRawHwpUnreliable(page)) + return; + if (hugetlb_vmemmap_restore(h, page)) { spin_lock_irq(&hugetlb_lock); /* @@ -1547,6 +1554,13 @@ static void __update_and_free_page(struct hstate *h, struct page *page) return; } + /* + * 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); + for (i = 0; i < pages_per_huge_page(h); i++, subpage = mem_map_next(subpage, page, i)) { subpage->flags &= ~(1 << PG_locked | 1 << PG_error | @@ -2109,15 +2123,6 @@ int dissolve_free_huge_page(struct page *page) */ rc = hugetlb_vmemmap_restore(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 c9931c676335..fa29849769ed 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1664,6 +1664,90 @@ int mf_dax_kill_procs(struct address_space *mapping, pgoff_t index, EXPORT_SYMBOL_GPL(mf_dax_kill_procs); #endif /* CONFIG_FS_DAX */ +#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 void __free_raw_hwp_pages(struct page *hpage) +{ + struct llist_head *head; + struct llist_node *t, *tnode; + + 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); +} + +static 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 = TestSetPageHWPoison(hpage) ? -EHWPOISON : 0; + + /* + * 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; + } + + raw_hwp = kmalloc(sizeof(struct raw_hwp_page), GFP_ATOMIC); + if (raw_hwp) { + raw_hwp->page = page; + llist_add(&raw_hwp->node, head); + /* the first error event will be counted in action_result(). */ + if (ret) + num_poisoned_pages_inc(); + } 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); + /* + * Once HPageRawHwpUnreliable is set, raw_hwp_page is not + * used any more, so free it. + */ + __free_raw_hwp_pages(hpage); + } + return ret; +} + +void hugetlb_clear_page_hwpoison(struct page *hpage) +{ + if (HPageRawHwpUnreliable(hpage)) + return; + ClearPageHWPoison(hpage); + __free_raw_hwp_pages(hpage); +} + /* * Called from hugetlb code with hugetlb_lock held. * @@ -1698,7 +1782,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; } @@ -1710,7 +1794,6 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags) return ret; } -#ifdef CONFIG_HUGETLB_PAGE /* * Taking refcount of hugetlb pages needs extra care about race conditions * with basic operations like hugepage allocation/free/demotion. @@ -1751,7 +1834,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 Jul 14 04:24:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12917277 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 F0FACCCA487 for ; Thu, 14 Jul 2022 04:24:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84BFC940173; Thu, 14 Jul 2022 00:24:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D708940134; Thu, 14 Jul 2022 00:24:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69D36940173; Thu, 14 Jul 2022 00:24: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 55532940134 for ; Thu, 14 Jul 2022 00:24:50 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 34F038083C for ; Thu, 14 Jul 2022 04:24:50 +0000 (UTC) X-FDA: 79684414740.28.75A0AE2 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf07.hostedemail.com (Postfix) with ESMTP id 8D75B40038 for ; Thu, 14 Jul 2022 04:24:49 +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=1657772688; 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=Vci+a2j3p4dRTO4MvgjEzQFBNpUGagACvgxCOkke+7Y=; b=WJNZQLeeJiGf/RGk2CRNPv9wRnsekMjkGr8ZWSoOA6S/JQh1Q/oeu2H0YZMNJiIy53mOY/ xcdUwC5oL30e0z9tHk+tr6hRIVpIW8J/eQUU0s/mcFZkQCySp+qGSEmeJyV2eRQIIlCSag jZqk3kJflYbLc496e8mA2+EEAK9P0N8= 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: [mm-unstable PATCH v7 4/8] mm, hwpoison: make unpoison aware of raw error info in hwpoisoned hugepage Date: Thu, 14 Jul 2022 13:24:16 +0900 Message-Id: <20220714042420.1847125-5-naoya.horiguchi@linux.dev> In-Reply-To: <20220714042420.1847125-1-naoya.horiguchi@linux.dev> References: <20220714042420.1847125-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; imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=WJNZQLee; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf07.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=1657772689; 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=Vci+a2j3p4dRTO4MvgjEzQFBNpUGagACvgxCOkke+7Y=; b=UGn/YYkR0fiL/xSPmscZ2q6JQzuWgqGs7a5WvldOgNiUjmARqIOd39toE/HVuDGcmfzTIG c+B/rlVB8owmStiFtWNetxzm1OIHL3Bcn9pNPJAANJ32rrG7+czaCVnqfrBrRyGtuH+s4k QFN9n5PGtuvTEy6fWJnc+kMbUyV460o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657772689; a=rsa-sha256; cv=none; b=7LnZC3PoO7j56kCwn4Dn/7WR1IStoaiuUH7JOiWim9avYj4gMH+nPRDWnZtu8OO7Pu3HyJ HYTrkZfJaa0SgP6pOEL+hMTej4n2sDGeF/n22VmdIcqMdtNQ1r5fz/VVcM8qLrW/88ku0w j2jMwjLMh7KOXb+GrvUrcJo/vMxKbYI= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8D75B40038 X-Stat-Signature: s3f7acntq3cx6u58ngkii1k84yg8qbas Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=WJNZQLee; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf07.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-HE-Tag: 1657772689-169029 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. HPageVmemmapOptimized(hpage) and HPageRawHwpUnreliable(hpage)) sometimes can't be unpoisoned, so skip them. Signed-off-by: Naoya Horiguchi Reported-by: kernel test robot Reviewed-by: Miaohe Lin --- v6 -> v7: - free_raw_hwp_pages() checks HPageVmemmapOptimized(hpage) only when move_flag is true so that unpoison works for HPageVmemmapOptimized pages. v5 -> v6: - set type of return value of hugetlb_clear_page_hwpoison() to void - change type of return value of hugetlb_clear_page_hwpoison() to unsigned long v4 -> v5: - fix type of return value of free_raw_hwp_pages() (found by kernel test robot), - prevent unpoison for HPageVmemmapOptimized and HPageRawHwpUnreliable. --- include/linux/swapops.h | 9 +++++++ mm/memory-failure.c | 52 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/include/linux/swapops.h b/include/linux/swapops.h index a01aeb3fcc0b..ddc98f96ad2c 100644 --- a/include/linux/swapops.h +++ b/include/linux/swapops.h @@ -498,6 +498,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) @@ -518,6 +523,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 fa29849769ed..8b9c0d228549 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1680,19 +1680,23 @@ static inline struct llist_head *raw_hwp_list_head(struct page *hpage) return (struct llist_head *)&page_private(hpage + SUBPAGE_INDEX_HWPOISON); } -static void __free_raw_hwp_pages(struct page *hpage) +static unsigned long __free_raw_hwp_pages(struct page *hpage, bool move_flag) { struct llist_head *head; struct llist_node *t, *tnode; + unsigned long count = 0; 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 count; } static int hugetlb_set_page_hwpoison(struct page *hpage, struct page *page) @@ -1735,17 +1739,36 @@ static int hugetlb_set_page_hwpoison(struct page *hpage, struct page *page) * Once HPageRawHwpUnreliable is set, raw_hwp_page is not * used any more, so free it. */ - __free_raw_hwp_pages(hpage); + __free_raw_hwp_pages(hpage, false); } return ret; } +static unsigned long free_raw_hwp_pages(struct page *hpage, bool move_flag) +{ + /* + * HPageVmemmapOptimized hugepages can't be freed because struct + * pages for tail pages are required but they don't exist. + */ + if (move_flag && HPageVmemmapOptimized(hpage)) + return 0; + + /* + * HPageRawHwpUnreliable hugepages shouldn't be unpoisoned by + * definition. + */ + if (HPageRawHwpUnreliable(hpage)) + return 0; + + return __free_raw_hwp_pages(hpage, move_flag); +} + void hugetlb_clear_page_hwpoison(struct page *hpage) { if (HPageRawHwpUnreliable(hpage)) return; ClearPageHWPoison(hpage); - __free_raw_hwp_pages(hpage); + free_raw_hwp_pages(hpage, true); } /* @@ -1889,6 +1912,10 @@ static inline int try_memory_failure_hugetlb(unsigned long pfn, int flags, int * return 0; } +static inline unsigned long free_raw_hwp_pages(struct page *hpage, bool flag) +{ + return 0; +} #endif /* CONFIG_HUGETLB_PAGE */ static int memory_failure_dev_pagemap(unsigned long pfn, int flags, @@ -2294,6 +2321,7 @@ int unpoison_memory(unsigned long pfn) struct page *p; int ret = -EBUSY; int freeit = 0; + unsigned long count = 1; static DEFINE_RATELIMIT_STATE(unpoison_rs, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST); @@ -2341,6 +2369,13 @@ 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); + if (count == 0) { + ret = -EBUSY; + goto unlock_mutex; + } + } ret = TestClearPageHWPoison(page) ? 0 : -EBUSY; } else if (ret < 0) { if (ret == -EHWPOISON) { @@ -2349,6 +2384,13 @@ 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); + if (count == 0) { + ret = -EBUSY; + goto unlock_mutex; + } + } freeit = !!TestClearPageHWPoison(p); put_page(page); @@ -2361,7 +2403,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 Jul 14 04:24:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12917278 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 58ABEC43334 for ; Thu, 14 Jul 2022 04:24:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA37F940174; Thu, 14 Jul 2022 00:24:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D2CB9940134; Thu, 14 Jul 2022 00:24:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BCE23940174; Thu, 14 Jul 2022 00:24:54 -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 AB618940134 for ; Thu, 14 Jul 2022 00:24:54 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 8933F1206D0 for ; Thu, 14 Jul 2022 04:24:54 +0000 (UTC) X-FDA: 79684414908.06.3959253 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf06.hostedemail.com (Postfix) with ESMTP id 1573D18002D for ; Thu, 14 Jul 2022 04:24:53 +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=1657772692; 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=ngKLKDdl8tKKfu2TGB+i86Efy0xem0/rhnoFe8dfEL8=; b=i+JllwS2lmZjxpmph0m/xZ/95qQFQ9W39AEul2qTClWf+jTSUEePa4iApnYrfC/HeX40oQ XCG/rCkeP3uZ9W6iZ2OkXG7QRLomr+H56pCZUBD7y+6ztKea7tfQRbzgubVccZ4tRPH7BV hd+wZo1QT5MjFHR8uEtDGxMqCrANJbc= 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: [mm-unstable PATCH v7 5/8] mm, hwpoison: set PG_hwpoison for busy hugetlb pages Date: Thu, 14 Jul 2022 13:24:17 +0900 Message-Id: <20220714042420.1847125-6-naoya.horiguchi@linux.dev> In-Reply-To: <20220714042420.1847125-1-naoya.horiguchi@linux.dev> References: <20220714042420.1847125-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=1657772694; a=rsa-sha256; cv=none; b=sL+sNTqJFn877o64OcU9FI6zKaRClZc0tMXaySuCn0N2DFEfc4UN0jPkNJ6nuEbgwUEjox m9RhAlQLDOo0Kh4CiLbcPm0T0CdA1ysMtm/6bkFNTDX5Q1y5RSFmN+2FnTaoJnPezlusB/ b888IhJZZW8W7xcBroGyVdsBY2j7I+c= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=i+JllwS2; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf06.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=1657772694; 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=ngKLKDdl8tKKfu2TGB+i86Efy0xem0/rhnoFe8dfEL8=; b=0W/txbDPeWzWtrIVp6yzPgQ47NXL1kQ/qGjhbNUxorvjEGeKbJX7Y7SU/Gul7SA1vtzoWj DQ15PJiY7CBZxqzThaSS55rBkU7K/BRLvLxjstojODAfoFVvkGJ08YbUYmaBJ7TFOH6ja/ VgmYubygnyGAvkLCmG3P6/NzM0Itz2E= X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1573D18002D Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=i+JllwS2; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf06.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev X-Stat-Signature: uaysbo9a1duq3j1793589qpu8tju1x8x X-Rspam-User: X-HE-Tag: 1657772693-266087 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 4287bec50c28..7668831c919f 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3188,6 +3188,7 @@ enum mf_flags { MF_SOFT_OFFLINE = 1 << 3, MF_UNPOISON = 1 << 4, MF_SW_SIMULATED = 1 << 5, + MF_NO_RETRY = 1 << 6, }; int mf_dax_kill_procs(struct address_space *mapping, pgoff_t index, unsigned long count, int mf_flags); diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 8b9c0d228549..f15d521c3f1f 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1802,7 +1802,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)) { @@ -1829,7 +1830,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: @@ -1845,8 +1845,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 Jul 14 04:24:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12917279 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 0BB81CCA487 for ; Thu, 14 Jul 2022 04:25:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9843D940175; Thu, 14 Jul 2022 00:24:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 934C0940134; Thu, 14 Jul 2022 00:24:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7FC92940175; Thu, 14 Jul 2022 00:24:59 -0400 (EDT) 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 6A213940134 for ; Thu, 14 Jul 2022 00:24:59 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 439FA60D65 for ; Thu, 14 Jul 2022 04:24:59 +0000 (UTC) X-FDA: 79684415118.26.A2CE62C Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf17.hostedemail.com (Postfix) with ESMTP id A896A4007F for ; Thu, 14 Jul 2022 04:24:58 +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=1657772697; 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=t1cH48TsYgnMbCs85Xjd/gEDfmg15eYdysyMKeEyQaw=; b=MK+VYGzFHPOhVzFkcB+WBdKd2SKCz3HDhj7lJOuCvwCqOvR1ka6CIA8COfVSSJa8TYsznd yld9V/YJipttANKJ/y1yiaPg2E3pEBrXWBBOMqaLi3iv5MxZJdR/ZtafuhZkOXk0frOxOY uhUGxs30vHI6QanO2s9rQUQ4wcPT2mc= 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: [mm-unstable PATCH v7 6/8] mm, hwpoison: make __page_handle_poison returns int Date: Thu, 14 Jul 2022 13:24:18 +0900 Message-Id: <20220714042420.1847125-7-naoya.horiguchi@linux.dev> In-Reply-To: <20220714042420.1847125-1-naoya.horiguchi@linux.dev> References: <20220714042420.1847125-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=1657772698; a=rsa-sha256; cv=none; b=KtgptrAMqIFNwaL7cvAehS90XAI2kgHsOgCUKhNP1iyy5EIok6AXTRKfPCnJje/NXCTRBs xLzZcxv8i1GFAK5ObN0mYx2A4ptsviRHSC1kchSOzTgvwLq13qSeFB+MxKzucWKlIunf7x BvUXYPkT9TzK7t5TsZlr6KVKIKalyIs= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=MK+VYGzF; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf17.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=1657772698; 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=t1cH48TsYgnMbCs85Xjd/gEDfmg15eYdysyMKeEyQaw=; b=fmvTx1XO2g0W5u8BKeJ+d1t7PYIzcyC6t20ShSE29kW0qYI/pV2+VRGn1ZXmRTaGxZZ0U0 hfM3RTGJsdXkOuiZcguthKnrmqCd0+kz4QJEWcUMz6gKjDpOH5xT+Om+O/q9qbnqoCaPtX i1VaqZ1C+u/7si3lOYkP2M5nrS9x7cA= Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=MK+VYGzF; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf17.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: c3ij63tiub5trwbsipojeq38sscet4y1 X-Rspamd-Queue-Id: A896A4007F X-Rspamd-Server: rspam08 X-HE-Tag: 1657772698-489192 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 f15d521c3f1f..c8fa3643791c 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 @@ -1086,7 +1092,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; } @@ -1869,7 +1875,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 Jul 14 04:24:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12917280 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 549A1CCA487 for ; Thu, 14 Jul 2022 04:25:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF2AE940176; Thu, 14 Jul 2022 00:25:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA163940134; Thu, 14 Jul 2022 00:25:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6958940176; Thu, 14 Jul 2022 00:25:03 -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 B339B940134 for ; Thu, 14 Jul 2022 00:25:03 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8D1DC33887 for ; Thu, 14 Jul 2022 04:25:03 +0000 (UTC) X-FDA: 79684415286.04.3FB4E2F Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf12.hostedemail.com (Postfix) with ESMTP id F2D9A40075 for ; Thu, 14 Jul 2022 04:25:02 +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=1657772701; 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=QFGu2TWdKctYd3jzQb7mcIpilK5qcQQipmt2wnr4Teg=; b=X5Y7ADJtRLRlG8Hoy8Xid5t/PtUaUJdq5UHQ5PPCu3LL68/j93w3CesxPKtcqAnywdK5Kq k1xfExT3M7VNgAXkK/Grlf2AO78LpJJKq2lw6VIFfaRoP0wz3y1/s0rJJXXbV6usFO8rAu zK7P5ELEEt7xmWa6st/unT9NT5CpW8I= 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: [mm-unstable PATCH v7 7/8] mm, hwpoison: skip raw hwpoison page in freeing 1GB hugepage Date: Thu, 14 Jul 2022 13:24:19 +0900 Message-Id: <20220714042420.1847125-8-naoya.horiguchi@linux.dev> In-Reply-To: <20220714042420.1847125-1-naoya.horiguchi@linux.dev> References: <20220714042420.1847125-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; imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=X5Y7ADJt; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf12.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=1657772703; 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=QFGu2TWdKctYd3jzQb7mcIpilK5qcQQipmt2wnr4Teg=; b=il44Q8RUhk0HmnTmPrXePOMoSig9vpco9MS8nkIjSpqHHzXzf7wY1bwd7cc27JEQcfy6AS 0q3behbvfhRuATralJ60dSdZ1huccaau2OppyRwcTtu6E490zSHinygO0Il5UYZ72Ua/cH xMadM+FiybDi28OcTD5WiH4O6gWaY/s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657772703; a=rsa-sha256; cv=none; b=h1BNAst/f4TKmT+zUqBkEmjSzrsRZkd0MnRnH0RN0dOxEd8fRSFTFrM6WOxA68mH4YAPUi 29OJqrxh6f58SZeKO3+wY4xfun5T+NzpXq3Kxu1ejsMZpPazhEA1zHH/+hfFIKxnE0+cXi NF2Qp9q4q+sirD3leAVtg5m+qX5Xq9s= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: F2D9A40075 X-Stat-Signature: eh8shsbf9tninpjthsjnh9654ygnu1ex Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=X5Y7ADJt; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf12.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-HE-Tag: 1657772702-197589 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 c8fa3643791c..3721de624b98 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1084,7 +1084,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, @@ -1092,9 +1091,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; } } @@ -1874,10 +1875,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 Jul 14 04:24:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12917281 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 B0F48C43334 for ; Thu, 14 Jul 2022 04:25:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 45662940177; Thu, 14 Jul 2022 00:25:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 40499940134; Thu, 14 Jul 2022 00:25:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A68E940177; Thu, 14 Jul 2022 00:25:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 185E6940134 for ; Thu, 14 Jul 2022 00:25:08 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id DEECF440 for ; Thu, 14 Jul 2022 04:25:07 +0000 (UTC) X-FDA: 79684415454.22.9201F84 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf22.hostedemail.com (Postfix) with ESMTP id 50BE8C0072 for ; Thu, 14 Jul 2022 04:25:07 +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=1657772706; 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=XRf9R0o+fSMZ5LBdaxhYZP7PNoN9BepwjSvwbf2mACk=; b=wzJaSUq+cq2c/g7wOTMheofahuoQLC/lJySne8NngV8YOHuAPY31JeADHfGWPWMqTm3wQA Ixki1i7UdSNcr2KkhLOOeoxTZb5F6aIR/JB0CyUkd7X0prMPH9JnaSQZ5eDKI2qJoIjNJ5 FqdNfTOfdndIk0HbG8CCQgtT31c9cuI= 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: [mm-unstable PATCH v7 8/8] mm, hwpoison: enable memory error handling on 1GB hugepage Date: Thu, 14 Jul 2022 13:24:20 +0900 Message-Id: <20220714042420.1847125-9-naoya.horiguchi@linux.dev> In-Reply-To: <20220714042420.1847125-1-naoya.horiguchi@linux.dev> References: <20220714042420.1847125-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=1657772707; a=rsa-sha256; cv=none; b=u5eLoV1lnDQZ5t3v+yJwyYZ/H36TXTGnzy/Mrm/fn0ZXuRTTJMT0sz0LLVEdeZJLLUofIq SMxZW/1favoyUFfW/V2NhzHI3MTmlA0WBAAmHTGvVAEp5i/4h8rhWds+TqFucVUi8YD3Ig 8jFJqIMv34UYYIE/tu2hCtw+w1NsFkc= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=wzJaSUq+; 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657772707; 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=XRf9R0o+fSMZ5LBdaxhYZP7PNoN9BepwjSvwbf2mACk=; b=2RXEilUywcx/dEO4bcwVHkD0lcSqGLihCfzgXoib3gEt0eEbTvBFIr+9VzdhGYPVb/YGHj +L77UYk+No4NhJJkQlvGNfdg/NJYjFEvlJnqS3iufoHJsNTG+8lqXHDHPD2QfffGeVjVPD KA5eSDAlunuXLj8NCfcfW09Me7GrIB4= X-Rspam-User: X-Stat-Signature: f3ribf77xkaqt7oddhisg5y387ajcfg9 X-Rspamd-Queue-Id: 50BE8C0072 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=wzJaSUq+; 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-HE-Tag: 1657772707-303914 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 7668831c919f..b0e83835184e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3241,7 +3241,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 3721de624b98..d86b5acd5754 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -765,7 +765,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", @@ -1887,21 +1886,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;