From patchwork Thu Jun 23 23:51:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12893256 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 4FD35C43334 for ; Thu, 23 Jun 2022 23:52:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D25678E01A7; Thu, 23 Jun 2022 19:52:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CD4128E01A1; Thu, 23 Jun 2022 19:52:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9C898E01A7; Thu, 23 Jun 2022 19:52:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id AC2FB8E01A1 for ; Thu, 23 Jun 2022 19:52:35 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 87AA132B for ; Thu, 23 Jun 2022 23:52:35 +0000 (UTC) X-FDA: 79611152670.30.5C33FBF Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf24.hostedemail.com (Postfix) with ESMTP id 30DD5180034 for ; Thu, 23 Jun 2022 23:52:35 +0000 (UTC) Received: by mail-pf1-f178.google.com with SMTP id bo5so1057591pfb.4 for ; Thu, 23 Jun 2022 16:52:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l+d0OGtRtkY09M0VLBofFywNSItSfbSemC3EkYMtQyY=; b=ou1qFSPl8LCvTmp9oUsKtEu26AbVApYmilkjIi5Rqdhn7tRx0awXZilRcMS07UUquu QsIs67X8QqsYXNyNzHjQNz4bMesy8pxAo3Bce4yXtWS4IsYr//Q6obb1scOMH/WtDmL/ SsxBh2QpvXr8qN7vUjWsuvyZg8bCvfUzCU06EOdhNks5pav3NCoN2wDpgXepSFDFWoJh 8gCeRcS9v75oR4dEJJeo6B0GAHI6EUGSyxBzaS1PBsydIbR84FKq3cCjokSPygKkHr3b DoJiHIvWanhxYmJRFwaglGt55RhnE69wEJocNsqgwWlBFy7k6z/n2lV6xFjGI2JJQole GCsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l+d0OGtRtkY09M0VLBofFywNSItSfbSemC3EkYMtQyY=; b=IMoKxtO90/KVbUn1ZyTluL3vyqtVynJO4/LHseuS3fISxVA2v56OCzIiYqnhu6w7gR 62Q68aSBCyBj8GIHA3CNbVnjqF2zAgxdqLTuEYfrdd/qOkGS1mPD0yguYSsl+uc3TbZr y80ozxJ20o125Q2t3S3INuQS8UXQdtHepHyjXqEs8lGqvlOQV9Z0BixnxIr1BNwz0Q7R Q4d92pXoUNKL3X1SVViANbycPbDfcGy3Z+f140g3wENGCzqe/qq2/LRavk3AZXjdVQeV 8x2iWTp8NaP/5zM29UwAUsYX84ppBGfjim07AAxbih2JJdgF9i7eDN13tCy61SjA8wVD HL8Q== X-Gm-Message-State: AJIora+KgDYZ2yhk2DVsHYzW3EvYyZmGMCTP2tfiRezouCVqt+Z2+JcP hL1NXfn1NHUSCpXWUJte6egfe08TYA== X-Google-Smtp-Source: AGRyM1sCQntLUzCfsXoFtqsZy7Xh7dUH0cStwNLtXgYEfOK9ftLkc8zvJEC5P2/PdCc5Fs8haLDBMg== X-Received: by 2002:a05:6a00:134f:b0:51c:4c92:1dae with SMTP id k15-20020a056a00134f00b0051c4c921daemr43342643pfu.32.1656028354057; Thu, 23 Jun 2022 16:52:34 -0700 (PDT) Received: from ik1-406-35019.vs.sakura.ne.jp (ik1-406-35019.vs.sakura.ne.jp. [153.127.16.23]) by smtp.gmail.com with ESMTPSA id r10-20020a170903020a00b00168eab11f67sm362571plh.94.2022.06.23.16.52.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jun 2022 16:52:33 -0700 (PDT) From: Naoya Horiguchi X-Google-Original-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 v2 2/9] mm/hugetlb: separate path for hwpoison entry in copy_hugetlb_page_range() Date: Fri, 24 Jun 2022 08:51:46 +0900 Message-Id: <20220623235153.2623702-3-naoya.horiguchi@linux.dev> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220623235153.2623702-1-naoya.horiguchi@linux.dev> References: <20220623235153.2623702-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656028355; a=rsa-sha256; cv=none; b=0y8kNcXXmlh325NWPUswjxqujzqwrJwEJh3DH2p08fVqiU3uy2bZLp3hVDK5wJy9J0bqdV 4C1SJHAp1TFRIK5L0/AIghkqTpHPYMHNPvkUlmztEyikKioy70gjYPYxTum9p+6j3GX1i2 TeiJ8xxe8O4yG+CTvq4gDxlHxFMMFNk= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ou1qFSPl; spf=pass (imf24.hostedemail.com: domain of nao.horiguchi@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=nao.horiguchi@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656028355; 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=l+d0OGtRtkY09M0VLBofFywNSItSfbSemC3EkYMtQyY=; b=8kEd8hVmidUOIs+MLHlEVShy/nq4u5fOPVip99yVO82TghMHGnYZ64hF78rnjkq6OXR+vf mXqOsIZipYOfVSENiP+0kaKXw46IEd6F0EOFb4eTKfvoAPmTd918yEwdoKw4QRs77r/HzU OjD6U03/3IAcQKre20jR25ccGR2zocU= X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 30DD5180034 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ou1qFSPl; spf=pass (imf24.hostedemail.com: domain of nao.horiguchi@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=nao.horiguchi@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Stat-Signature: ui5pahokj7wgi5gwxdu4a9ejeegzou98 X-HE-Tag: 1656028355-948104 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 hwpoisone 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 foking 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 Cc: # 5.18 Reviewed-by: Miaohe Lin Reviewed-by: Mike Kravetz Reviewed-by: Muchun Song --- mm/hugetlb.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index c538278170a2..f59f43c06601 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4784,8 +4784,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);