From patchwork Tue Jul 12 13:05:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12914962 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 A6318C433EF for ; Tue, 12 Jul 2022 13:06:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2606594006D; Tue, 12 Jul 2022 09:06:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 20F1C940063; Tue, 12 Jul 2022 09:06:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0FE6094006D; Tue, 12 Jul 2022 09:06:00 -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 01DB8940063 for ; Tue, 12 Jul 2022 09:05:59 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id BFB1D20F29 for ; Tue, 12 Jul 2022 13:05:59 +0000 (UTC) X-FDA: 79678470438.01.F539A4C Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf15.hostedemail.com (Postfix) with ESMTP id DC76EA00A8 for ; Tue, 12 Jul 2022 13:05:57 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Lj1Cd4xJ9zkWhq; Tue, 12 Jul 2022 21:03:41 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 12 Jul 2022 21:05:51 +0800 From: Miaohe Lin To: , , CC: , , Subject: [PATCH] mm/hugetlb: avoid corrupting page->mapping in hugetlb_mcopy_atomic_pte Date: Tue, 12 Jul 2022 21:05:42 +0800 Message-ID: <20220712130542.18836-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657631158; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=VitQx3q+iCYw3d/36WRi3cPi58P+LCv5KaKeQBua0UU=; b=tRX0eKRtXk6+EFiwIb4AIwkPSAxFuvEXw+/msHzmrttPfzd9RH0cORhpV+fDohJxeSYz9k xMaYx2/bDVo8esR+aunO/dtF880KBlnb0nakLAJ1RXU3Gbj6hCw1Fds7jcxpVJdwrC9gYH lAX+SJm+2q4fD6bMo1kZMg4hYr5nvfg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657631158; a=rsa-sha256; cv=none; b=5nXQRsSvu2Dc2ZRLQQpUIiCqIABoVEqcfwDuCD3wYiR3JVhPCS6TVr0QPq0thSrwBAUwRg ck7gsx+qQver0AjTZi1BiHEgZ3bR78w5uTuYbuf+gUbsMBg0W1DdvdOPp1WoTQmsE4fpka TeMoV7DPuCcjOfjcN8JR+BbKyfE5tsU= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Stat-Signature: ngmt6rz48jguswr44561g8zepuhngbf6 X-Rspamd-Queue-Id: DC76EA00A8 X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspamd-Server: rspam05 X-HE-Tag: 1657631157-663278 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: In MCOPY_ATOMIC_CONTINUE case with a non-shared VMA, pages in the page cache are installed in the ptes. But hugepage_add_new_anon_rmap is called for them mistakenly because they're not vm_shared. This will corrupt the page->mapping used by page cache code. Fixes: f619147104c8 ("userfaultfd: add UFFDIO_CONTINUE ioctl") Signed-off-by: Miaohe Lin Reviewed-by: Mike Kravetz --- mm/hugetlb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 8d379e03f672..b232e1508e49 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6038,7 +6038,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, if (!huge_pte_none_mostly(huge_ptep_get(dst_pte))) goto out_release_unlock; - if (vm_shared) { + if (page_in_pagecache) { page_dup_file_rmap(page, true); } else { ClearHPageRestoreReserve(page);