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);