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