Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4171588pxb; Mon, 1 Feb 2021 14:37:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBTcmwMWQ/NczmCEy0ixMlySIhfPzvFU1MO5AmCWvUFEu1KlptdQqeHLgjBZH4rpfNl8ND X-Received: by 2002:a17:906:6d44:: with SMTP id a4mr20451485ejt.453.1612219049999; Mon, 01 Feb 2021 14:37:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1612219049; cv=pass; d=google.com; s=arc-20160816; b=TgJntFcXaIseLNrGN/7+pU2hlz+B266PN+ObL6sDlPXeBYChaYOZT3o0BKlmBpbC23 aoOoCw7l6FgjgVGB4NyCSzhRROCdZHc6s4G2D8S6X7N3YIOsviYXpY4ABJ44FyH5Xln0 wahvGptL6DBvZpj1tgRUGS/BCtckw7E2q7ePAy/bz8l55Kh3nRvv3m6GnVxXPm4SlUhI b+aT4RzpbxGQIQlh3b2SdVv4RLHK2r4l2EhVNWP8SDPaNYmNWvWqg9rI2fIZjdtLdLas ugcui8gOhUu5FzYdaPoQhpen7QvtxfngAA/h9jDQ6YFnO6dhLdr1gty2g5up+48t/Dsx 5tsQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:in-reply-to:user-agent:date:message-id:from :references:cc:to:subject:dkim-signature:dkim-signature; bh=uDzLM6n6KhA21x4GgnmxMW2F+QWTm0cohXugxkfow5Y=; b=CUxLEizLuVwbAeTJfQSC0mNrrHbNa/Adpmz+gB9LR5B3GDBZbv6VEBl/KkUou65NkF 4gRvH+d+lco/Ef0kgWd9K1mKt0NR5o+FPy69GBj5YrmnrbW6Pt16EkHpGBNT5ixVuAhz /DkbETAAYO6Wh2OFXAfXzap41Sw7CGuQDOyHbHxSWCyxWeskhtEr4gp2tpN0c7+x8vly p9fV3gIOGwS2GA+U+0pobZ08qQJupJQ5MwA3U8NRDWfjDS/FaTFLQcsns2Pan77+5M6E qREZaw+CStud/dPjYE7kGa5532+Uset7A7WqIRyQCDL4z+rgxrL6HPlBPPyHWiIWzYUb po5w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=IP9XniS2; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=UDADXDof; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r21si12537649ejo.123.2021.02.01.14.37.05; Mon, 01 Feb 2021 14:37:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=IP9XniS2; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=UDADXDof; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229543AbhBAWfU (ORCPT + 99 others); Mon, 1 Feb 2021 17:35:20 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:57328 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229514AbhBAWfK (ORCPT ); Mon, 1 Feb 2021 17:35:10 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 111MUYWq087359; Mon, 1 Feb 2021 22:33:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : in-reply-to : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=uDzLM6n6KhA21x4GgnmxMW2F+QWTm0cohXugxkfow5Y=; b=IP9XniS2E10IaqcLq9gJR+IU1Si0wPupfI5U03A2WenmVxy3TX8TyL5zGKFWfF4nnkLP sdowLVHf7Gge80+pmbz5MnfnhhX5xxRRykzz39Zh78itXTntP5hLmEi763VSxhF5dEmY HH5jWv+9VcxGGFLR9AL1sL3CUp6KMi6/cahP8XTqbpPrPJ2ExMPvVt1KdZcoz/XkuBp9 jhZlI5GI+2ejlGGrB7o2Mm0taLMSMOl9Wb00elkdyDT7G+rYP4hYkUAKnQEScg7BeQMd y54tRbW4pEK1yjrQX4snGfbuAacTnDyNbt9J/87zZn0HXCC+0MuqKeQ/jJz3z04Klp+B gQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 36cxvqyy12-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 01 Feb 2021 22:33:26 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 111MUWrl038932; Mon, 1 Feb 2021 22:33:26 GMT Received: from nam04-bn3-obe.outbound.protection.outlook.com (mail-bn3nam04lp2057.outbound.protection.outlook.com [104.47.46.57]) by userp3030.oracle.com with ESMTP id 36dhcvp1p7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 01 Feb 2021 22:33:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lqIJ3MUAQ3wiaG+XYC2oQOQkHihyqW78q1Xh1XS5hyOw3It8weG4KeOlQUtlLOWLQOxkdoRugeO9qsauDJCEPz4jleE9ckUpd5UaZoS2SJe6T5MW+7p505Fn34/dZmgLTqv1wbUumiW6xu5yLQiySsyAuXXoSKomvkPUfkrKNey7wUrysVpgtxkf9vpJb+pTo3SkvRfEVfLjUHfDJQbJ58iNntFSHt4iREmuIK0+6TF+nWkjkK+MdvOUV4pBK21Khin8gvhl0zqrpXO72Ex031AJlL7qXwc1t5fceRMwiZLQFTwEr+uoEc8xUWEtr5T+hgBPxu5kF2Nk3BPhDxFR3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uDzLM6n6KhA21x4GgnmxMW2F+QWTm0cohXugxkfow5Y=; b=ieyiWrp1UD30yHRiuP43lPTqEL9a7nRR/Cpul1V3HVOCuhMWQK60GKGRdHSVEsmuf/AzhUlrAFN4UZ5ivew9IkO1EvHppnQcvqSP19Ph+zIiv1HQ8KXHUhmEiGZPxXN54j9f67iWoco36vNAveS+THTFUjHcspfXzZoR9JQgjfQ3VwCwoOE6NVrMd2wkPKPYriI9r7l+YyEEIpqfX+b4b6ERAuhyspgr/6YVN38xXcMON552y0c96CgEZu8rE5duRXUB8UpVESzFB3kVPkqy66JrP95TDqkao0H5FyJF+tugVM5UdSmPRa2ThJfOKERYRCDkjmL+b8KWt7ThW0w81A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uDzLM6n6KhA21x4GgnmxMW2F+QWTm0cohXugxkfow5Y=; b=UDADXDof0F33KpcW0osAvRpFFBeb1rfytLtQA0G115v4ZpAg2CvcLKMqFuLEyGs3z+FVdn2TdD0Clfh5Aqj6ikJhQnHkCUsTCfyR6B0h45DgT59hetr8REPQJTxQe7T3TIQr7ru5RgFaj3VvCokDBu0VripYd62J28Xx2KgxTAg= Received: from MWHPR10MB1389.namprd10.prod.outlook.com (2603:10b6:300:21::22) by MWHPR10MB1853.namprd10.prod.outlook.com (2603:10b6:300:10a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.19; Mon, 1 Feb 2021 22:33:23 +0000 Received: from MWHPR10MB1389.namprd10.prod.outlook.com ([fe80::897d:a360:92db:3074]) by MWHPR10MB1389.namprd10.prod.outlook.com ([fe80::897d:a360:92db:3074%5]) with mapi id 15.20.3805.026; Mon, 1 Feb 2021 22:33:22 +0000 Subject: Re: [PATCH v3 4/9] hugetlb/userfaultfd: Unshare all pmds for hugetlbfs when register wp To: Axel Rasmussen , Alexander Viro , Alexey Dobriyan , Andrea Arcangeli , Andrew Morton , Anshuman Khandual , Catalin Marinas , Chinwen Chang , Huang Ying , Ingo Molnar , Jann Horn , Jerome Glisse , Lokesh Gidra , "Matthew Wilcox (Oracle)" , Michael Ellerman , =?UTF-8?Q?Michal_Koutn=c3=bd?= , Michel Lespinasse , Mike Rapoport , Nicholas Piggin , Peter Xu , Shaohua Li , Shawn Anastasio , Steven Rostedt , Steven Price , Vlastimil Babka Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Adam Ruprecht , Cannon Matthews , "Dr . David Alan Gilbert" , David Rientjes , Oliver Upton References: <20210128224819.2651899-1-axelrasmussen@google.com> <20210128224819.2651899-5-axelrasmussen@google.com> From: Mike Kravetz Message-ID: Date: Mon, 1 Feb 2021 14:33:20 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 In-Reply-To: <20210128224819.2651899-5-axelrasmussen@google.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [50.38.35.18] X-ClientProxiedBy: MWHPR11CA0014.namprd11.prod.outlook.com (2603:10b6:301:1::24) To MWHPR10MB1389.namprd10.prod.outlook.com (2603:10b6:300:21::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.2.112] (50.38.35.18) by MWHPR11CA0014.namprd11.prod.outlook.com (2603:10b6:301:1::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.16 via Frontend Transport; Mon, 1 Feb 2021 22:33:22 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 40ee446a-c6af-4c4d-8310-08d8c70161f0 X-MS-TrafficTypeDiagnostic: MWHPR10MB1853: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PTyDsRCl79d4oQRUsr0g4UZs4ujc+BEI7fDOVxUyLr+mhHJqhajKWscXIH43+/a1ShgdRlqoQzTtX62qyBtuaO4IiRaxb8PF/emUzjKGI038JJjfEFdfD+51aOXmsRCHr0ULBWPwp7jFp9xfsSkE5DZ4yZSQfPbdfzpItlsl99NnRpGDYBhDToL99awVh6HhBaD6MhfJAU0zHL1EDSpZNw9vlRh6Pe0pSKhJYsSojhmu0+s8yiUJXH00g06J4Aifrpe08AScLiNDPYSdP4v6aVZQ2HnGT1ToYRIoCGsq+diiDX3npvDP3GBuVIMJh/uxfNPkMI1BDu7zylTqUZOTW3gXc3taJyT0mgOdQ/yn4Sn8LUrWORtZkEptu4dqk0ludPVU7J03jOhMaaxkb0oxY6VN57DHW1T1FK+zd7niim7WfxUGWwriO1n4hBgSxMlDKPU2Uj8oeYU4avfc15ryx79OFy9PgZ3vuI26Ph2vQ19O5oZpUFSwjfS+SxhDE/goAI+0eu9udWGHFhIF7RAmMLTU4FxWX7pvda87t/Oyn4s8Bd2X5Bb5qcZX3nouhS5QPR2S+P5f7qHPYMeGLieJo1P7AmpY/VOqqm8SBO52EZS+2BT+AOrzzraxd+VtPCe3 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR10MB1389.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(366004)(376002)(346002)(39860400002)(396003)(86362001)(36756003)(44832011)(7416002)(7406005)(31696002)(478600001)(26005)(4326008)(186003)(16526019)(8676002)(6486002)(53546011)(2616005)(956004)(2906002)(66556008)(66476007)(66946007)(8936002)(16576012)(316002)(110136005)(54906003)(52116002)(5660300002)(31686004)(921005)(83380400001)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?B?dlEvUlp1SVNqRXZMYnNHOElrSzVhdlV1VzNRQ0twcjlmN1lXS1lSQ1d4K2Qw?= =?utf-8?B?Sjl0R0plbGYxZlZpd2RLaEREOGZsYS9FS3crZUNvSTlTQVdtTnNDRitRZzVo?= =?utf-8?B?OVRsQUEyaDFiTk11SXhUZHlHanNiOEhYSlBOcXV3SHZhOEdwdTdKMmJjWVUv?= =?utf-8?B?N2FKdDNFNmtJZjdaWWozZXkza0JDd0pZOU5za3l2a3JaTjBMRVJVeE9xOVBG?= =?utf-8?B?QnVyU3YvNGVzanNwRGhBOWY5M3NUb3YvRU16aEFYaTh4VlUzMGxsRlpsVjFx?= =?utf-8?B?WkVvQUZIRU5xZndMOGJRSVZRMlFsZ1JLUnRNUkZFaDZObEppK1JCSVRGaUdO?= =?utf-8?B?QWtRVFBNeEtvTmpiQUZFZ2pWdVcrMlkwUGRYMGNKMGNsdVllcGJ4UjQxQlZj?= =?utf-8?B?d25CSlFyTkszMmFlVkVXeG80UnprK0pSNTF3eVRnTHpkVjdmak1rbFZNdVJa?= =?utf-8?B?VUR4OGNxc0FQOHN5dkVFSmNvNDkveC9CZ2JHU01FbmV4MUZsVTRmZU9KeTdU?= =?utf-8?B?d1RNSHExTWNZWjA5RDlsZGtjY3h6Tzk0TmYyOUl1Q2tQMnk2ckN5Lzg3Rzhp?= =?utf-8?B?ZXVCVGtVendQaUJPcmM1OE41OEpxeVFhTGdpWUdXVDI1aUZhNVUzZnZVTkVM?= =?utf-8?B?ZmxTaGt1MFR5Z0ZtSDQ1QjhLUG9jL0ZRVFFEdEltR24vQzJJWno5bFo4akJv?= =?utf-8?B?eGZKcVM3MkNUaUgxZVpRY3dRSytwalJPcG93ckF4MVNVOXVuL2ZBaDZZRzFV?= =?utf-8?B?WWswU2hiOStmTDVmb2NHeE9wSE5jd1Yxc0VIMG0yRGcxeVlUSGpQMzV4eWw1?= =?utf-8?B?OG04MzQxZ2ViSzVsUkQ0V3lmWHBPUmxJbjJUemJNeXdlcmdXUTF2N2d3NEZZ?= =?utf-8?B?aDZVZVJIdy9HcG9KQkNZM2pjL0drTUIyTG8xdSszL1ExOXZEL3hzaSt5c1VE?= =?utf-8?B?TzlRd1BXTnFia2F4WlhWclB5UGdCbnAyV01oUHhpbFhSOUpxUVZCczNZemx3?= =?utf-8?B?SkFvZms4SnYwQzI4YWk4N0ZZSjlkZWU0Qm9OVklnR3M3aTBIN3lKbXRWbVBv?= =?utf-8?B?Y2FwZ25FbnNGMEFnaDlxbm9jTkh6THVzOUY1VTFBeVVDK1dTRU5nTmR3aks1?= =?utf-8?B?T09LK1FuNXY0Ri9KMjFheEwyUkE0bDZwMEF1UWNLT3NiMjdMclBxTkl3OHA0?= =?utf-8?B?R0lYdSt2U2t3KzRBOFhwSk9DR09DU1NzL0t1ZHFqNXdodVZvbzV1RlVzU01F?= =?utf-8?B?SFdIU1hORlJ2Rzd4dmYvcUtEMGRnM2I0aVRMZVcreDV4bEVWOWJIZzhabHgz?= =?utf-8?B?US9pNGh1emxoSHlYRHIwS1Z4dVNFcUI5dUhWMWx2VjVPcVNPeXVGdk5kK2VE?= =?utf-8?B?azY4NzBIS3ZiOGV2dUZuRlZmZ1VrWXp0djZXWHpBUmJ1NzlieDloSStXd0lF?= =?utf-8?Q?jQqiiyLs?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 40ee446a-c6af-4c4d-8310-08d8c70161f0 X-MS-Exchange-CrossTenant-AuthSource: MWHPR10MB1389.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2021 22:33:22.8190 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LZHsu/Jp8dKYw+0YZBU67bq0Mi70SJvBrb6aIC1QoUlB1pkg32k1vJyS2sKTrrCs2O3jutoojfaYSLiatD0qAg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1853 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9882 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 phishscore=0 spamscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102010122 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9882 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxlogscore=999 mlxscore=0 priorityscore=1501 spamscore=0 impostorscore=0 clxscore=1015 suspectscore=0 lowpriorityscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102010122 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/28/21 2:48 PM, Axel Rasmussen wrote: > From: Peter Xu > > Huge pmd sharing for hugetlbfs is racy with userfaultfd-wp because > userfaultfd-wp is always based on pgtable entries, so they cannot be shared. > > Walk the hugetlb range and unshare all such mappings if there is, right before > UFFDIO_REGISTER will succeed and return to userspace. > > This will pair with want_pmd_share() in hugetlb code so that huge pmd sharing > is completely disabled for userfaultfd-wp registered range. > > Signed-off-by: Peter Xu > Signed-off-by: Axel Rasmussen > --- > fs/userfaultfd.c | 45 ++++++++++++++++++++++++++++++++++++ > include/linux/mmu_notifier.h | 1 + > 2 files changed, 46 insertions(+) > > diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c > index 894cc28142e7..2c6706ac2504 100644 > --- a/fs/userfaultfd.c > +++ b/fs/userfaultfd.c > @@ -15,6 +15,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -1190,6 +1191,47 @@ static ssize_t userfaultfd_read(struct file *file, char __user *buf, > } > } > > +/* > + * This function will unconditionally remove all the shared pmd pgtable entries > + * within the specific vma for a hugetlbfs memory range. > + */ > +static void hugetlb_unshare_all_pmds(struct vm_area_struct *vma) > +{ > +#ifdef CONFIG_HUGETLB_PAGE > + struct hstate *h = hstate_vma(vma); > + unsigned long sz = huge_page_size(h); > + struct mm_struct *mm = vma->vm_mm; > + struct mmu_notifier_range range; > + unsigned long address; > + spinlock_t *ptl; > + pte_t *ptep; > + Perhaps we should add a quick to see if vma is sharable. Might be as simple as !(vma->vm_flags & VM_MAYSHARE). I see a comment/question in a later patch about only doing minor fault processing on shared mappings. Code below looks fine, but it would be a wast to do all that for a vma that could not be shared. -- Mike Kravetz > + /* > + * No need to call adjust_range_if_pmd_sharing_possible(), because > + * we're going to operate on the whole vma > + */ > + mmu_notifier_range_init(&range, MMU_NOTIFY_HUGETLB_UNSHARE, > + 0, vma, mm, vma->vm_start, vma->vm_end); > + mmu_notifier_invalidate_range_start(&range); > + i_mmap_lock_write(vma->vm_file->f_mapping); > + for (address = vma->vm_start; address < vma->vm_end; address += sz) { > + ptep = huge_pte_offset(mm, address, sz); > + if (!ptep) > + continue; > + ptl = huge_pte_lock(h, mm, ptep); > + huge_pmd_unshare(mm, vma, &address, ptep); > + spin_unlock(ptl); > + } > + flush_hugetlb_tlb_range(vma, vma->vm_start, vma->vm_end); > + i_mmap_unlock_write(vma->vm_file->f_mapping); > + /* > + * No need to call mmu_notifier_invalidate_range(), see > + * Documentation/vm/mmu_notifier.rst. > + */ > + mmu_notifier_invalidate_range_end(&range); > +#endif > +} > + > static void __wake_userfault(struct userfaultfd_ctx *ctx, > struct userfaultfd_wake_range *range) > { > @@ -1448,6 +1490,9 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx, > vma->vm_flags = new_flags; > vma->vm_userfaultfd_ctx.ctx = ctx; > > + if (is_vm_hugetlb_page(vma) && uffd_disable_huge_pmd_share(vma)) > + hugetlb_unshare_all_pmds(vma); > + > skip: > prev = vma; > start = vma->vm_end; > diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h > index b8200782dede..ff50c8528113 100644 > --- a/include/linux/mmu_notifier.h > +++ b/include/linux/mmu_notifier.h > @@ -51,6 +51,7 @@ enum mmu_notifier_event { > MMU_NOTIFY_SOFT_DIRTY, > MMU_NOTIFY_RELEASE, > MMU_NOTIFY_MIGRATE, > + MMU_NOTIFY_HUGETLB_UNSHARE, > }; > > #define MMU_NOTIFIER_RANGE_BLOCKABLE (1 << 0) >