From patchwork Mon Nov 14 23:55:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 13042972 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 9AF79C433FE for ; Mon, 14 Nov 2022 23:55:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F0BF66B0072; Mon, 14 Nov 2022 18:55:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EBC016B0073; Mon, 14 Nov 2022 18:55:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC0568E0001; Mon, 14 Nov 2022 18:55:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id BCAC36B0072 for ; Mon, 14 Nov 2022 18:55:24 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 87D4EAB564 for ; Mon, 14 Nov 2022 23:55:24 +0000 (UTC) X-FDA: 80133706968.11.50A082A Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf08.hostedemail.com (Postfix) with ESMTP id 1E774160009 for ; Mon, 14 Nov 2022 23:55:23 +0000 (UTC) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AELDnql025708; Mon, 14 Nov 2022 23:55:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=uRKbYWuEt3rFdhI7IzRGeWhbUjlPV3fd2I2QkSG75kg=; b=rTZ4+sgmhOErph0bqldZnYn1QLT547M9CFi1bb7XShQO9PqVxf4HCEXID+RikL1PkZyW zQs9tSw5X2wH3bKTXQ9cSXtrTp2XZocvVEr7QZAEbYakC0MoWnT+yHSL0oDgrmHILIkI H6WeLqSB3oYx8uiLP9Ccf8W/16B98T5GyEM1tFFe8gEH4RMaWgdRBbSL74plnoiIAz/j ok8CWTSk3zu+KikeYbzI+LE2wvrwTH2TgEuGw4g+kwLPH3zo2uhw0ed5mzsFOk7CXC5q ydQTGqHudv5jR0xTqbt+wpPO1K1r0YBAWGGC2AwYlJjX2MlgdqDzkjrW9kihlFV1AUJ3 ig== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kut2eh2r9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 14 Nov 2022 23:55:18 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2AENADra019263; Mon, 14 Nov 2022 23:55:17 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam02lp2043.outbound.protection.outlook.com [104.47.51.43]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3kt1x4vvax-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 14 Nov 2022 23:55:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CyqHKAWdA0FzBtbbmIiHOOP2PO5VBH3RD/hZY2fbF5xJ3meKCtoauRCI0MeNs5YRCLinAGFAadzZS1grUnuhxrJFf5oO3izGV2zAh/2a94lNI7Q1rFdcFPCehW4zV/PQE0WqYfVHxkTiHjwGclFnhq2+ZURGJuBGjOSktU9ALwHftHq4lu+jbKKqeO+FlLS69yopXDdHNill/Z54QUUF9RqqIR7W23UE0puBGj7+WC/HOce3GZ3wNMHfbHNMwatwXUwt4wL7D1SQQfsskTFTVUUIZZymjfKxFqTkwean4jwNk1SI0C+1/qgDj/TT2AfzYY+nc3L+nxQgI1d/u7fq/g== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=uRKbYWuEt3rFdhI7IzRGeWhbUjlPV3fd2I2QkSG75kg=; b=Ey6qKotx0dpcpy48oxqkwVn8GqZnoJxwL/WvuLUpIVlaO836jovLUfjP3dbALippfiaUU/pgPh2SIpiLFro8zTmmn9dx2CNIW/BcaRoIFGxYVYvS54QyYBKxLA9vkr5BCqfLIGXcVVMNyyNnDC0oVI2Ome/JQnRI9pwT/t507Z/HRET3ugSIvlFt/t4JIFnZJ/5tucjFaB1YYLUVL0MUVespcqPup8bSiYvDsED1NVOxYHzFAPsQHqRygL8oF2P21yZaCD1zF+No50FXgl9rAjomHnDmuH3TLsfelb+JrPVJ889LX9PmduHY5PtV3sZxck+doByueFX3GfiGDuU2CQ== 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=uRKbYWuEt3rFdhI7IzRGeWhbUjlPV3fd2I2QkSG75kg=; b=WxKjaz7gglHEuWWl2dgxLUzXKZ+saS5MZ6F468F68uLNCVy2akMsO1mRstn6mXNYf25cZp1oxLPLZHSh4jcm+0LgR62vY0GaiJ5XL5HbfwAPSeviKSlJbGPovJzh7qai1fUhKZCUPNlMOzPPdCwH3hKWR9Wdl+7pvgO+LLJPF5k= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by BY5PR10MB4178.namprd10.prod.outlook.com (2603:10b6:a03:210::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.17; Mon, 14 Nov 2022 23:55:15 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::8d67:8c42:d124:3721]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::8d67:8c42:d124:3721%4]) with mapi id 15.20.5813.017; Mon, 14 Nov 2022 23:55:15 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Naoya Horiguchi , David Hildenbrand , Axel Rasmussen , Mina Almasry , Peter Xu , Nadav Amit , Rik van Riel , Vlastimil Babka , Matthew Wilcox , Andrew Morton , Mike Kravetz , Wei Chen , stable@vger.kernel.org Subject: [PATCH v10 1/3] madvise: use zap_page_range_single for madvise dontneed Date: Mon, 14 Nov 2022 15:55:05 -0800 Message-Id: <20221114235507.294320-2-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114235507.294320-1-mike.kravetz@oracle.com> References: <20221114235507.294320-1-mike.kravetz@oracle.com> X-ClientProxiedBy: MW4P223CA0027.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::32) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR10MB4196:EE_|BY5PR10MB4178:EE_ X-MS-Office365-Filtering-Correlation-Id: 777c31e5-5db5-48e7-90ef-08dac69bad16 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lMj0EqvFR9sHzoFaGnLaazAQ3qkef9C0N9Q/UguxfC9PG3MaQsYIMZZb9EM8ROIhLmZImNCJFr51bpQp0ut8f1RqWIisV7Wobvaa1gDgFdBoB1SFU6TK/lKI05cpBMi2E+5/gcYgdCCZx8/b/+rT4J4UnkQ1lLWnoPkBx9i+ONulfbmY/bkDx/Ld1Me13XbFn3V5cvqcgHusNMh03ad047mPZPpIRMAiR7/Et+SiiHEU+l2Rbtd6k0uEFePSik/Gjl5GWXS2fZq//yHhj4Alv2uPyLVio7XJEbJEFwJXoJGk11tHhRZpjI6ScTWjYaTqoW0gTJayQcF4uOQmwic45Dz1ySCSWt4FmvIvD/RErd+C1KzjnUGA1FaF8qXGhQod7d9yVJYR0xM/8QxyZHHcnaHT3LnDFUrPZswEdK3a/GGHJFU5lTaHcueDOF5jthzwfLBdPem5v458RiYcHCy1yTDumAyzcKpbkknFfNc7V9xnS5ulPA4gcIGeefPGrvcsEpFvvB1W+zdhV+qYkYpczb3QfZ2C3z9lrketiZwUt/gGEUljA7EeQ2R1qunS0wsDQn/7UsjAoDxOxdJlgaIJZL0KdMV+Wt/JvlIXEFggJTSSJjzwEUtVmO3n0GsYEpCGgggqXDmeJjBbQM5jRg/m+ewoymrq3+Uq9/SuY94kf4+zF28CqcqeTlU8VKk6nXNDmsiKb9a+PN2JUuUoCTbCzHt6ai7Vygw70GzskZP0pg07dY5rnQ6CRNRCwJsXaaSJ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(396003)(136003)(366004)(376002)(346002)(39860400002)(451199015)(2906002)(4326008)(66556008)(2616005)(6512007)(66476007)(8676002)(66946007)(41300700001)(86362001)(36756003)(1076003)(38100700002)(316002)(6506007)(54906003)(83380400001)(8936002)(7416002)(186003)(5660300002)(478600001)(44832011)(26005)(6666004)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: B7U4UjyUH7hX6Slz8SGSpf6Q9rYs3pRugONEe9rql+fuy/bXi4GKOCFODLA9J9OHKAs5tk1U/n4b5NBWykjF6Xppk/kbX45ANM6HAC6YdKE4ofNi6SFsTPUyBoZh8BfPimWovVgJxYRiqyzhQ7MWUG8gYa5ciC+L1rPZ4DePpG1SgcVLdhz2ImC9kD8p5oT3C9BT5DuxpH1o1E7LhoE07zCXDX5dvQqFXB3YtEp4U+fiYkvlH3iXZb8n+WcX+rNM3NndDa7TiY+drIYEn7cOEBR887CrLYcWlzoHWH3qe/QtZK3hSAI17eCk2p4MWedEhdSFlFLooBLDYfJFnXFNE2N2fkdleXMsFuhi6aSb8779Kgpd0dAfkIUVJG8pyZgB4SblrCnEKNyq/3Ndcq6n8SNMIbr50Pu8p9hj+LNtVw0XDz7hNclddHjyAMRSaKrIU2VJzDamU/0wRxVPEvUvuOUfxXiQJIN7SXtTDkwXcXFEqN0Wn7hcRLR9qI+bn58Qh0nus2MBkD2U8YAYL/25jp33Tmt5i9Ignizh38ciWWhjY+xvtPynQvDdhDNR6n7aSAJosSxZV32srLbsmDTO6gXhBp/O9f/jBgVn9+QkBopVlKzo/3uL0KAyTDBahwHkjeFBJbtTnK6UxMCdmIiFb4+kWRLIOMWcKHXDmQNA1wS0k9PIlEv5GDC5gMBStQLAYpNFGVB9DSccPpQ/lcUoW2qOdZMVJZHD9e+BZ50XLVrYBcWYnM7RqF6bkx6ceBp1yD163wgJBoVV6FHHp/0XHOKCQYF9x3DjyXhUT4nsOArLVV1Gkp9uzMH+5I30dtrL61uPW9huUNqQWswY1IEFMqKojY2mQXna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4dU28ggClGSHDFlCRKIwub7Sn7FOHfuq15p58rvAnDRo1di3mgPllmwhVGew1e0kE+2pKLwzWtbNwkq61b+MZ1kKgOFWeGTaPTYHzmaZpfsX8f/TjGiGQkFCMtH8JTOaDD3hanuA81XYV0ERF8YO+wGB0eAHS5orA7gZohOhKTva0WAKNN9nIQiIELFRpz1JbK8khL53rxkNciq4RkITYLm2A0UaAuLYCvGIFS7AtbpxOhYm7pmTM2QJtHXCA3wazYgxHBzdTLfs/cKYZWz0QwbBmm8tlxaGHUJwCuPS7nj1vS67KDgkhvdxKhDB9TDWuqg+D1zTIYeU3Q+Jp1Fi5sl+v5Su4PbHcV5Jybb/U2UEYUWYTqFmIviFvwaC6tZpmTsqd9q/fopJ929HfTl7t8bnPh5t1KBROv4enTwP/JukDB1pWGR5GOX02ZIu0apleGONvnktgZHiMHCLb4gj7RoXfQyKLHcByZ9FbPEOqt5UyB8SkkrRgE3O0QNi/Cyq/HPr6D8v53b0FD13nMiwjVUR7LoVavi2Gm7hJK/fdo5gfF1UOJtO+gRHKsrV/Mxwt7VifJjuQ5IK3RibHBJwBSKws/lfHPOMdgsZr9FvYWTWxHLr97lir5orKGe1bKW4Q9SDdatm7cHgG0gczhjydK3MMW6FBH/IdGQtx7klFHfxopk4DVzJXLYUYlFKLA3LRs5JyZK7Jly/RjgigPppxq5dn9Us7dAeqnkbZmWx0cwMRd0oKaTKMLbnkoA70t8YHojCpZNFq9+a9Z/BHJeS5Czs7vsTJn1/92nOGzcpxYa1g7XZrlsRSQH5y6UT+yefGSwEs9pu4ivokSDph6rvvz6F44xU3XuEsXEglwrpu+pBFH5EWCPJKcovTdw8RlJxBmOnx3U51T9LOuWT7GnAAppCFZ8u8wtHI/qQS2BmvxBk9lBFfX8IN6rI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 777c31e5-5db5-48e7-90ef-08dac69bad16 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2022 23:55:15.4076 (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: yWH0ovwAYflEiG6lavARwV5u+j+mQqViH5CKVgvxkJcZO/GmA7NYrqcBGxAqNPN0BFpug3YWQW3STG2cxGpj9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4178 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-14_15,2022-11-11_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 spamscore=0 adultscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211140168 X-Proofpoint-ORIG-GUID: YCQX9bB0aOLOwIUT_Oi0vXUzwMXUiKz9 X-Proofpoint-GUID: YCQX9bB0aOLOwIUT_Oi0vXUzwMXUiKz9 ARC-Authentication-Results: i=2; imf08.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2022-7-12 header.b=rTZ4+sgm; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=WxKjaz7g; spf=pass (imf08.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1668470124; a=rsa-sha256; cv=pass; b=fVZ6jlJetmn5ILcJ6DFgbtRIuJa61iyjkZrZMkAiM7jgC7SP/KnJWsSfkDWtjLygs/jsEM hn4rSQrfxowgJrNK+n6Zb6j4CiVX+ykEbZO3mbpMXFPf7i6FjpV+DlrWaowgXyRB6YUpU5 zh6tEc0H3t/me7NtV+NemmFrkjcyHz4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668470124; 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:in-reply-to:references:references:dkim-signature; bh=uRKbYWuEt3rFdhI7IzRGeWhbUjlPV3fd2I2QkSG75kg=; b=SqmBVPn//qvUHUwb8TD+rbgQerdajpVaPNhQPSPqTPbcDX6PfO/kATPuoEBWnbHqPgIVCV C7fjzoZRus2frHjwYfh4aap5u39zpbc32xQxcL2fdQHPCTYMK2XFHdREYKEmbUFyA5jKKu heT+HNFX49ls5hlI+h4+/QOkewr+Z9g= X-Rspam-User: Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2022-7-12 header.b=rTZ4+sgm; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=WxKjaz7g; spf=pass (imf08.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") X-Stat-Signature: teq4qhh4n1yek97u4w7pa5ho1fkjir6g X-Rspamd-Queue-Id: 1E774160009 X-Rspamd-Server: rspam09 X-HE-Tag: 1668470123-967662 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: Expose the routine zap_page_range_single to zap a range within a single vma. The madvise routine madvise_dontneed_single_vma can use this routine as it explicitly operates on a single vma. Also, update the mmu notification range in zap_page_range_single to take hugetlb pmd sharing into account. This is required as MADV_DONTNEED supports hugetlb vmas. Fixes: 90e7e7f5ef3f ("mm: enable MADV_DONTNEED for hugetlb mappings") Signed-off-by: Mike Kravetz Reported-by: Wei Chen Cc: --- include/linux/mm.h | 27 +++++++++++++++++++-------- mm/madvise.c | 6 +++--- mm/memory.c | 23 +++++++++++------------ 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 9838b535fa21..dd5a38682537 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1870,6 +1870,23 @@ static void __maybe_unused show_free_areas(unsigned int flags, nodemask_t *nodem __show_free_areas(flags, nodemask, MAX_NR_ZONES - 1); } +/* + * Parameter block passed down to zap_pte_range in exceptional cases. + */ +struct zap_details { + struct folio *single_folio; /* Locked folio to be unmapped */ + bool even_cows; /* Zap COWed private pages too? */ + zap_flags_t zap_flags; /* Extra flags for zapping */ +}; + +/* + * Whether to drop the pte markers, for example, the uffd-wp information for + * file-backed memory. This should only be specified when we will completely + * drop the page in the mm, either by truncation or unmapping of the vma. By + * default, the flag is not set. + */ +#define ZAP_FLAG_DROP_MARKER ((__force zap_flags_t) BIT(0)) + #ifdef CONFIG_MMU extern bool can_do_mlock(void); #else @@ -1887,6 +1904,8 @@ void zap_vma_ptes(struct vm_area_struct *vma, unsigned long address, unsigned long size); void zap_page_range(struct vm_area_struct *vma, unsigned long address, unsigned long size); +void zap_page_range_single(struct vm_area_struct *vma, unsigned long address, + unsigned long size, struct zap_details *details); void unmap_vmas(struct mmu_gather *tlb, struct maple_tree *mt, struct vm_area_struct *start_vma, unsigned long start, unsigned long end); @@ -3518,12 +3537,4 @@ madvise_set_anon_name(struct mm_struct *mm, unsigned long start, } #endif -/* - * Whether to drop the pte markers, for example, the uffd-wp information for - * file-backed memory. This should only be specified when we will completely - * drop the page in the mm, either by truncation or unmapping of the vma. By - * default, the flag is not set. - */ -#define ZAP_FLAG_DROP_MARKER ((__force zap_flags_t) BIT(0)) - #endif /* _LINUX_MM_H */ diff --git a/mm/madvise.c b/mm/madvise.c index df62d9e1035a..a21b186eb7a0 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -785,8 +785,8 @@ static int madvise_free_single_vma(struct vm_area_struct *vma, * Application no longer needs these pages. If the pages are dirty, * it's OK to just throw them away. The app will be more careful about * data it wants to keep. Be sure to free swap resources too. The - * zap_page_range call sets things up for shrink_active_list to actually free - * these pages later if no one else has touched them in the meantime, + * zap_page_range_single call sets things up for shrink_active_list to actually + * free these pages later if no one else has touched them in the meantime, * although we could add these pages to a global reuse list for * shrink_active_list to pick up before reclaiming other pages. * @@ -803,7 +803,7 @@ static int madvise_free_single_vma(struct vm_area_struct *vma, static long madvise_dontneed_single_vma(struct vm_area_struct *vma, unsigned long start, unsigned long end) { - zap_page_range(vma, start, end - start); + zap_page_range_single(vma, start, end - start, NULL); return 0; } diff --git a/mm/memory.c b/mm/memory.c index 98ddb91df9a7..a177f6bbfafc 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1294,15 +1294,6 @@ copy_page_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma) return ret; } -/* - * Parameter block passed down to zap_pte_range in exceptional cases. - */ -struct zap_details { - struct folio *single_folio; /* Locked folio to be unmapped */ - bool even_cows; /* Zap COWed private pages too? */ - zap_flags_t zap_flags; /* Extra flags for zapping */ -}; - /* Whether we should zap all COWed (private) pages too */ static inline bool should_zap_cows(struct zap_details *details) { @@ -1736,19 +1727,27 @@ void zap_page_range(struct vm_area_struct *vma, unsigned long start, * * The range must fit into one VMA. */ -static void zap_page_range_single(struct vm_area_struct *vma, unsigned long address, +void zap_page_range_single(struct vm_area_struct *vma, unsigned long address, unsigned long size, struct zap_details *details) { + const unsigned long end = address + size; struct mmu_notifier_range range; struct mmu_gather tlb; lru_add_drain(); mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, vma->vm_mm, - address, address + size); + address, end); + if (is_vm_hugetlb_page(vma)) + adjust_range_if_pmd_sharing_possible(vma, &range.start, + &range.end); tlb_gather_mmu(&tlb, vma->vm_mm); update_hiwater_rss(vma->vm_mm); mmu_notifier_invalidate_range_start(&range); - unmap_single_vma(&tlb, vma, address, range.end, details); + /* + * unmap 'address-end' not 'range.start-range.end' as range + * could have been expanded for hugetlb pmd sharing. + */ + unmap_single_vma(&tlb, vma, address, end, details); mmu_notifier_invalidate_range_end(&range); tlb_finish_mmu(&tlb); } From patchwork Mon Nov 14 23:55:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 13042973 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 92014C4332F for ; Mon, 14 Nov 2022 23:55:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CE896B0073; Mon, 14 Nov 2022 18:55:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 67F728E0001; Mon, 14 Nov 2022 18:55:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D1996B0075; Mon, 14 Nov 2022 18:55:26 -0500 (EST) 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 3B1256B0073 for ; Mon, 14 Nov 2022 18:55:26 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 175B0160F06 for ; Mon, 14 Nov 2022 23:55:26 +0000 (UTC) X-FDA: 80133707052.05.5CC89B1 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf04.hostedemail.com (Postfix) with ESMTP id 9B4704000A for ; Mon, 14 Nov 2022 23:55:25 +0000 (UTC) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AELDlQq011985; Mon, 14 Nov 2022 23:55:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=GjynOfmK1NGfPSqaN7twnNbL6ZbrLMDmUL3fGSYghrQ=; b=T6CtDUcISpoWS+qqgjcI/LgmNiFfHobr6+GY+AUAn9GLmOnfFb4zfSvj+CtnTKiZ/N9b 59abhXt9gdN/RBN5e/PAv9/02ldA3tMXwSIlgL+iddRDF8QpaJZHBEQuwDfvOGuUIoB/ W4/5Mvgf7TEcR79knPyYwJG0w6LjQzSrz4X23D1Iq2IPVO2CNhQMhP2s209BGYhUXKTo jkzYE81/D0ienmI1l5CwNxNSHENsitWoErtGRS86oIXMFE9BjIgevoOcmqZv5sHOTemM jxxsBYxpUN/l+98Sh9ix/9Y7qzgHmYapD6um7mSInTqWbIPvaPIJ6H2ow8qEqzh5+C3/ Gw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kut2dh2sg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 14 Nov 2022 23:55:20 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2AEMTc7O004738; Mon, 14 Nov 2022 23:55:20 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam02lp2047.outbound.protection.outlook.com [104.47.51.47]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3ku3k5prbj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 14 Nov 2022 23:55:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iXgOEKULtG29bQpYvC0QrKLFuv7zGPtQcuRLaEaGda2YfbR7G9jgnjMxz1wT4ESwWjXvQc07q3d3lrcIs4y0EixCXloF5xRADpPl5AVEoOqJjT/cGA6HuxfPLo19ImAoICnMg6fhzND1IlKd3fVgF2O7+XXbeaKVHsgUF4qCz937yuSkIpQazpgAv53Shxe75ZvDf5n37HVp2iFyRWqsT37a02bD3vZRUGBA8nab1X1qEilASCgAzwj7KKLhL2611EIpEO1YHptffux7FrI4megGWs85nELa8L5kNHD1iH/K2FcGumwtom3UuzTWAC8n0FeV1Z8bmEMkR/yIE3lzsw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GjynOfmK1NGfPSqaN7twnNbL6ZbrLMDmUL3fGSYghrQ=; b=cp9wbw0Pg4AaAO74Ob8+Z3mot2q7aJ8GRw8oefDfAX4l36owKl/NoDMwyn1jkC/4sI8Vkpp6CNAqQb/4mxwcAzW3fyTAElQCF3XKg+sLVYiwplH+0iDNdr/gUDkYT95Dnj9kQHcx++9j810B09rczwFXHxmI0kuQkr/GWXz0t26hmIWKuy8M9d0UFPnSGq394OZfhY5zh2LXL9wKoRWwtIUHC+YupFw8ow0w1YjJkZMcoxyZTDKxUGGzQn4MtfrM59sOiXxF1joctakMsEaZG+l1+AHlJJ1RuNMHN3Vnq7W9J+kDcPzLVVL6LLJGrzrFwEY16ffkGHhvaifDFaym9w== 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=GjynOfmK1NGfPSqaN7twnNbL6ZbrLMDmUL3fGSYghrQ=; b=OrN4TMMq2UHenbzoowssQZqxko0W4T+7YRQTg1u1RLRKncKRj1ltnQIlXkBUnpuEc6kIgArsNO+faoCqSdbk89hHxDmxxaCq14QMZcQK7GdYT0Ryc2jLaB7LQ/oTxB24/u9ESRGnH85u6TjAZ23GMY5gl0SHit8p89IsvSa6Y9E= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by BY5PR10MB4178.namprd10.prod.outlook.com (2603:10b6:a03:210::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.17; Mon, 14 Nov 2022 23:55:18 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::8d67:8c42:d124:3721]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::8d67:8c42:d124:3721%4]) with mapi id 15.20.5813.017; Mon, 14 Nov 2022 23:55:18 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Naoya Horiguchi , David Hildenbrand , Axel Rasmussen , Mina Almasry , Peter Xu , Nadav Amit , Rik van Riel , Vlastimil Babka , Matthew Wilcox , Andrew Morton , Mike Kravetz , Wei Chen , stable@vger.kernel.org Subject: [PATCH v10 2/3] hugetlb: don't delete vma_lock in hugetlb MADV_DONTNEED processing Date: Mon, 14 Nov 2022 15:55:06 -0800 Message-Id: <20221114235507.294320-3-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114235507.294320-1-mike.kravetz@oracle.com> References: <20221114235507.294320-1-mike.kravetz@oracle.com> X-ClientProxiedBy: MW4PR04CA0189.namprd04.prod.outlook.com (2603:10b6:303:86::14) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR10MB4196:EE_|BY5PR10MB4178:EE_ X-MS-Office365-Filtering-Correlation-Id: bb202879-9d96-495a-2af1-08dac69baeba X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vtVNloxCvStDZwTgsh4a6QLFy97342I+WHpYvS1h9gXXeYpN/eEg2dxaHesUW8y2VIhYNtT8YN6I3e3NxdqJNEH9bN0zfJCmk76N5Wg6mGFeEPR52+/9EUaqk2S8U15pDCLmMRvlhWlJGPjUsget/KVuXJ3xWUpkk/aUlSWUE0ryg+UZwug4Wo09kVb24OmrlBLpth51KFu9TnNj6s9Hei7J5Nc1GWB3g6J7MZ/zUcJpozWQ2SgYQPfwGJ/pNuf+O7BYduFyzrOymg5GLKGigRiCWiJYcQ7njdPUP/ip0aLI+SAoUIbDXDLX6TAxfzHR7KKOf+gPxLwrpcXNrpHfH4MiIQU8hj/z12p6MYglzCQ+974OdknihMZO999G9FS7XipdKpDhjpotwwSJa85FftiwYjOz87hEo0gszxIsqXUnPTED5xmh7t6RBXmyeltlbQIunN9GjAL/jn8FnGF20+mgQhUPOR8etsZAE+2/U04izAI1SlEoKzvyYGF24EaMGiqt+SeMLcSxlhn4nXJoaknuRq4KTbg1iII4wfQld2ko1IF+Ab1u2IArEJvnzu76jVtP+VnLkEg4OxqXrE5+w5cbW6hd6HarOBOEyhlFH4QuetzhbhrNgpPz5LSNhk0Cw4ZxSmlLqEuLbQW4L0Z2yDBjgTcENV+QZ+Zmo0uMRK0jXGGK/yAkHDM+xT9+2zC2DB601DLBKmn8OeAMJriKMn7hrSt+4cvnHmgEgQ1Re5J8u2jumxHOCh3r+9KzAxG5eSbpx9Vy3dtNITDQezVExQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(396003)(136003)(366004)(376002)(346002)(39860400002)(451199015)(2906002)(4326008)(66556008)(2616005)(6512007)(66476007)(8676002)(66946007)(41300700001)(86362001)(36756003)(1076003)(38100700002)(316002)(6506007)(54906003)(83380400001)(8936002)(7416002)(186003)(5660300002)(478600001)(44832011)(966005)(26005)(6666004)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5Vq05+Ux7P/KISxQeu8sOtbsNuq69GUzYssEADZwWjArh71nl41aBv63vtSNUqND0gQhn26Ky4CLIhDA2dXJ6no7Ec8bmH5Vyuy1SObhJSaQgQihBn1ebZAwvbc/cWqgYV+NkAFePd0jgyHt0BmwKZW47u1oadDvasQpDkwQ8sUux220rQQWdgKMlwJRUw23cZXDMddWxyJdANP2TBd6O3zCyDM1ad7JFadaHoDR5NYsETb9InMtw7xwYfmFzr0RB4dwpfwe94xAoeLJ70gWkwgBrXTTcNfvexaA+XXIVbNnYwpz6Z8t/iWEwK4bsPcC3LGtw9K+9Df58GxA/+6Ow6JVdZLCj2zhI580d4rCtWsBbm0xCxjqFGUYYCl5htpsxgZIQIZxw5HabHTQLm+r/9O/Qszwbwbuia1zUDRxfLM1zeRzBS88qWyOmnvFL0Mx3AbOM3dfqSqDL7khcn+nSHUCisKGy+xtu1T7la6CLr+pKWuusHICpt1SfuOuS5qJr8QHn6JetXrCRfllDECy695JwpSsH4K5PuAvfL9vT+6JykztGU9/O8fwJWjeza5D9UGo1XvDyTj5RcaKyvujMdHDEHmP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CJ/2laegnP6QL7magsUJvGGiZdfbT3RHNO7sP6T6Y80Y4LjawjdATJfabMEmag6PAUDApp0CeeX+O08TZ6hRBLxlqcGYpLhLy6dcvtoMeHMO7rOrjZNA0V4SeqXwhM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: bb202879-9d96-495a-2af1-08dac69baeba X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2022 23:55:18.1887 (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: ZWHH/q7ln/cT7IcCR7jau9ZV9UUwugS03gJ2lWqMMSe3C2hE1QbixX7G+1qYXqA8Q3cPEuzR4HKGkd9OuuIIpA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4178 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-14_15,2022-11-11_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 adultscore=0 phishscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211140168 X-Proofpoint-GUID: p1ot0EePJy7bfoRG8wLWKkrN3ew2vgbc X-Proofpoint-ORIG-GUID: p1ot0EePJy7bfoRG8wLWKkrN3ew2vgbc ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1668470125; a=rsa-sha256; cv=pass; b=zrcRWbgTaW8sq1ZA2kQoqUO0NZ8luEvfx9qrzuv8y4GJT5/5yGpiE/8CgqpZN/nEmwdvkc ZlYjrWLbr+W9UuE6mCIi02lXiNnMagbncVtSwniuLZ2uq/ICQCVaJ/4Q47+Se4cY+7AWYt r2WmKZCtCgo1P8a2SZP/zKqusSC9GOI= ARC-Authentication-Results: i=2; imf04.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2022-7-12 header.b=T6CtDUcI; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=OrN4TMMq; dmarc=pass (policy=none) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf04.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668470125; 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:in-reply-to:references:references:dkim-signature; bh=GjynOfmK1NGfPSqaN7twnNbL6ZbrLMDmUL3fGSYghrQ=; b=Gz/FIouAmAk3lPMsguNusNFUWx9llS9J52qhGrdcRtU8VwHrSr1oxvpD5TnsfPz2q8exXE KZwmcMUBYPNOl/K5EzZH5q5zWfmWQ4tDNFjrFF/pIKLQWErqznhiNjzrT8c+cJWfbb6O9t Gd2xQUGnAmuS77NUOSLb33IyX1X8Ee0= X-Rspamd-Queue-Id: 9B4704000A X-Rspam-User: Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2022-7-12 header.b=T6CtDUcI; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=OrN4TMMq; dmarc=pass (policy=none) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf04.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com X-Rspamd-Server: rspam06 X-Stat-Signature: zh9w5jp18e8ffoo4t565jn7wk83uqxm5 X-HE-Tag: 1668470125-938549 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: madvise(MADV_DONTNEED) ends up calling zap_page_range() to clear page tables associated with the address range. For hugetlb vmas, zap_page_range will call __unmap_hugepage_range_final. However, __unmap_hugepage_range_final assumes the passed vma is about to be removed and deletes the vma_lock to prevent pmd sharing as the vma is on the way out. In the case of madvise(MADV_DONTNEED) the vma remains, but the missing vma_lock prevents pmd sharing and could potentially lead to issues with truncation/fault races. This issue was originally reported here [1] as a BUG triggered in page_try_dup_anon_rmap. Prior to the introduction of the hugetlb vma_lock, __unmap_hugepage_range_final cleared the VM_MAYSHARE flag to prevent pmd sharing. Subsequent faults on this vma were confused as VM_MAYSHARE indicates a sharable vma, but was not set so page_mapping was not set in new pages added to the page table. This resulted in pages that appeared anonymous in a VM_SHARED vma and triggered the BUG. Address issue by adding a new zap flag ZAP_FLAG_UNMAP to indicate an unmap call from unmap_vmas(). This is used to indicate the 'final' unmapping of a hugetlb vma. When called via MADV_DONTNEED, this flag is not set and the vm_lock is not deleted. [1] https://lore.kernel.org/lkml/CAO4mrfdLMXsao9RF4fUE8-Wfde8xmjsKrTNMNC9wjUb6JudD0g@mail.gmail.com/ Fixes: 90e7e7f5ef3f ("mm: enable MADV_DONTNEED for hugetlb mappings") Signed-off-by: Mike Kravetz Reported-by: Wei Chen Cc: --- include/linux/mm.h | 2 ++ mm/hugetlb.c | 27 ++++++++++++++++----------- mm/memory.c | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index dd5a38682537..a4e24dd2d96e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1886,6 +1886,8 @@ struct zap_details { * default, the flag is not set. */ #define ZAP_FLAG_DROP_MARKER ((__force zap_flags_t) BIT(0)) +/* Set in unmap_vmas() to indicate a final unmap call. Only used by hugetlb */ +#define ZAP_FLAG_UNMAP ((__force zap_flags_t) BIT(1)) #ifdef CONFIG_MMU extern bool can_do_mlock(void); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 9d765364231e..7559b9dfe782 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5210,17 +5210,22 @@ void __unmap_hugepage_range_final(struct mmu_gather *tlb, __unmap_hugepage_range(tlb, vma, start, end, ref_page, zap_flags); - /* - * Unlock and free the vma lock before releasing i_mmap_rwsem. When - * the vma_lock is freed, this makes the vma ineligible for pmd - * sharing. And, i_mmap_rwsem is required to set up pmd sharing. - * This is important as page tables for this unmapped range will - * be asynchrously deleted. If the page tables are shared, there - * will be issues when accessed by someone else. - */ - __hugetlb_vma_unlock_write_free(vma); - - i_mmap_unlock_write(vma->vm_file->f_mapping); + if (zap_flags & ZAP_FLAG_UNMAP) { /* final unmap */ + /* + * Unlock and free the vma lock before releasing i_mmap_rwsem. + * When the vma_lock is freed, this makes the vma ineligible + * for pmd sharing. And, i_mmap_rwsem is required to set up + * pmd sharing. This is important as page tables for this + * unmapped range will be asynchrously deleted. If the page + * tables are shared, there will be issues when accessed by + * someone else. + */ + __hugetlb_vma_unlock_write_free(vma); + i_mmap_unlock_write(vma->vm_file->f_mapping); + } else { + i_mmap_unlock_write(vma->vm_file->f_mapping); + hugetlb_vma_unlock_write(vma); + } } void unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start, diff --git a/mm/memory.c b/mm/memory.c index a177f6bbfafc..6d77bc00bca1 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1673,7 +1673,7 @@ void unmap_vmas(struct mmu_gather *tlb, struct maple_tree *mt, { struct mmu_notifier_range range; struct zap_details details = { - .zap_flags = ZAP_FLAG_DROP_MARKER, + .zap_flags = ZAP_FLAG_DROP_MARKER | ZAP_FLAG_UNMAP, /* Careful - we need to zap private pages too! */ .even_cows = true, }; From patchwork Mon Nov 14 23:55:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 13042974 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 4D40BC433FE for ; Mon, 14 Nov 2022 23:55:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E21D26B0074; Mon, 14 Nov 2022 18:55:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DD0F86B0075; Mon, 14 Nov 2022 18:55:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C23E96B007B; Mon, 14 Nov 2022 18:55:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B5FA76B0074 for ; Mon, 14 Nov 2022 18:55:29 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 70216160F10 for ; Mon, 14 Nov 2022 23:55:29 +0000 (UTC) X-FDA: 80133707178.11.5F896BC Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf02.hostedemail.com (Postfix) with ESMTP id 0BA8E8000B for ; Mon, 14 Nov 2022 23:55:28 +0000 (UTC) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AELDo1l025717; Mon, 14 Nov 2022 23:55:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=VPPSt08uUzVOjjlup/WgRlm3neDn1ahbKHMnfHdh9ok=; b=x7jJ1MTJf2TWbSLZ5LP02EEYLKvL3nv5tXWJLsbwIcVfYTj2cxLi8BDnRG89giAN71ox 0XU5bL+bRQaSqH25G5A9EqGtitKI9xaNVt+ULrTpJ/cE6PRQELa7TihoEztaEsJ1rU42 hhDpXYVOA5ClbwBBD6iTRmIOGER+vz3Yl7xKkmemaIkmkXrMfZwBm/6xERrhIG8b34/k Hn/CPSZ9p0D/hWt3dvZQevHp9u2iBFCsGbxVUxMQ46KFjn8a/jZPJmdYWWM/m6BWxs45 5e5FFaIEf6b3vf7BultyVUVOrYejBTg8v2bM/lygmy9fUtHu02lvw2AyWpLZhsqaD0gf bg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3kut2eh2rg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 14 Nov 2022 23:55:24 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2AENTSSv031835; Mon, 14 Nov 2022 23:55:24 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam02lp2041.outbound.protection.outlook.com [104.47.51.41]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3kt1xaxyb5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 14 Nov 2022 23:55:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i5GjcZHp+uYezbxqpHjN5QfGxO48v+TKy4Yl7rvgpmjbVgzN9MU7Q4Z1Z3mUj6YaxmE/MejB5FlGpiODOL4Igt/vB6FOD75Q6DTTvEbnY4ll1VTUYdc2DVCwJAAi7lYBVTd8IFQ4IQO1ICS4Jrp5Yk3L3YQAhGRutmG914vs7hlT3ITMQkcBqGgPguFESk2chhoS7mrpWHl1dQ0u4gqGSgk7/dwuKQJJKliQnOPVmiG9LGsvPXxx+RjCczh5vwJn4YJE6pXvW+y0GBalqEpwNix/pCdaJFlRbldWALGJ5XL/e6ZB8webQeiWo3Vzjkdmm+EbzcbGmM0Ys6ljvVaWQA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VPPSt08uUzVOjjlup/WgRlm3neDn1ahbKHMnfHdh9ok=; b=NPmS63Xpvpq6H1bMdt2mhGcVPV6gQpetbriaE5u1fVZok9RqsmpshPxJF04IwN+MtK9JRccXYFMyz/2M1FMDIuuteNu9r/ZWuTuqcoKgctF20KCnuaWBTtV11uUyQQlLQAq2eOLLhjhq2wKP03wB5IvAUYg+qmMAzCYS1lZJCd5pHM+yz9Oiv229du5VeByn2ZER3GoJNMmkZ9BOSqOo75yzUVs2U5zfRDUaVbpShOAwNQlahglWgHFIe6MwKPK2Iz6n0N1UhwIMyf2FxzJ1wtVYrfSrnAgK+H+ppi1xaB8DWMHGvv3nr7gyhCSSuSffVWXnVg3sJwYScSgRZv7PxA== 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=VPPSt08uUzVOjjlup/WgRlm3neDn1ahbKHMnfHdh9ok=; b=mSyk5067qaSkurjUL2xCDSTKb2tCRyfe8Oo4ltz1o4E81OBZXHKCG3CegnUtp+nbBNon8oWhFom/XZZfwU5nN34Ae36px/YyBHy5XCEYUGr0xe6HgvRU84f6K3GqFM+1ZKEsyfooR68A3nMgo9vThaz8gL82JfR1ZAfNChXjNwI= Received: from BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) by BY5PR10MB4178.namprd10.prod.outlook.com (2603:10b6:a03:210::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.17; Mon, 14 Nov 2022 23:55:22 +0000 Received: from BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::8d67:8c42:d124:3721]) by BY5PR10MB4196.namprd10.prod.outlook.com ([fe80::8d67:8c42:d124:3721%4]) with mapi id 15.20.5813.017; Mon, 14 Nov 2022 23:55:22 +0000 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Naoya Horiguchi , David Hildenbrand , Axel Rasmussen , Mina Almasry , Peter Xu , Nadav Amit , Rik van Riel , Vlastimil Babka , Matthew Wilcox , Andrew Morton , Mike Kravetz Subject: [PATCH v10 3/3] hugetlb: remove duplicate mmu notifications Date: Mon, 14 Nov 2022 15:55:07 -0800 Message-Id: <20221114235507.294320-4-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114235507.294320-1-mike.kravetz@oracle.com> References: <20221114235507.294320-1-mike.kravetz@oracle.com> X-ClientProxiedBy: MW4PR03CA0123.namprd03.prod.outlook.com (2603:10b6:303:8c::8) To BY5PR10MB4196.namprd10.prod.outlook.com (2603:10b6:a03:20d::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR10MB4196:EE_|BY5PR10MB4178:EE_ X-MS-Office365-Filtering-Correlation-Id: 8cc96700-109a-4945-4ea2-08dac69bb169 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: s8wugrLrt62cio3RX1j9476oN906a6Q/20mZCw3Ryj+08XNFD6Lg7bkLCyMuC+Lfq3/kygps3Ii13/rBDhaqrRDyx0rIRyow6elERrcnDAzU65N+S/YFw3bHlxIbS2zG5PTrDUw1dqsPDi3SpOznvI/JY/ivtXaieJa413DFp20dPtVZbLb9WFwKaN7GoUqdcJF2ZUMX+0e0InayaZNjmGvvcTLqbG3J7ssFAoq0DYsSaSL6JJlpIgcTmM2jMkI6kI9+wUg+T3yDMoiiNy5awCjM5/luyxWH0qyLQSMvKKULpTeCChAegMErajK+9LYrfMJ5ntrQWLoEwwdbcx/eqB6YwkS83EDyC8osUGFj5GZNGJb6LAh1VTd7GBIu5PejsbbYVRgJyFtV71bwFwxRNCb5PmrpiYR13UXu2+lKkpz4z+JZH5s6d2CkaXN01hMr0s0tbu+xh+n8o+bZgff0p8yhGHfQ2LEsaSqVJr2e8FNNm7WVysrPbc9CY0WQSyYNUO32oe6LmJqHBWD4mHOsGOSwVs4RgCaoUUxNfAfFhOrrdojXBfm+dP+pD5jPwQojpfCawiiWm9o5fbkbOnQBpIExITlvBU3VFfXVHzRrvn3J7W+EPx6CwPD+L/00kuTMsguKwnVo6PgiIYIzf9Uk6o5T6Vg+eEnqwxOuprfvUodUev5tX22ZNXILHhD+wd7/xH9EhuDJ/q6n8GILTvnJTbassIk5agannPru9f4kcP2ExH7P+nrfgc4hRvPMEbIq X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR10MB4196.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(396003)(136003)(366004)(376002)(346002)(39860400002)(451199015)(2906002)(4326008)(66556008)(2616005)(6512007)(66476007)(8676002)(66946007)(41300700001)(86362001)(36756003)(1076003)(38100700002)(316002)(6506007)(54906003)(83380400001)(8936002)(7416002)(186003)(5660300002)(478600001)(15650500001)(44832011)(107886003)(26005)(6666004)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wJGXeqnq8xJWvPLkpxYGtKIZ5XPP3ESAFBDwGLJGHndBxy9OZsUks5+lkvc9YK3X29FddfGHjBU/ceqAaTZJ/kD7O8bcRnpaCuGFtld1eULhvS5i5JVa61AFnnqKow/xKuC7KrIwwfAOAsnwMow7rD++Bl8P+XTfadMWbYiMn97I9JwIUaCqHz8BKuxsQRmtuKX48aE3QYkD3Vpvb/hUUvyUiLlt83Dx1SZfWh6FM672hnXoNjL1R8x1IP+WRlqj5SeEWuqX6nW6WyCBrsV9zmyUpmqTmK8gX7MC3r3QzI/YTU4QqEzVefMUGTfo06xAwSVWzn4DH4gzSND3z0CI1ROuEtUOMSCZEqkpVZBvq4blvtyywGyL8b8suQOW4Ot3QRd8uU+GEiFH0ujcUH7A5hF/PiLrrn2LEOrCkc3gy9+/uYHCysYulkwVAV6CcqprmLmz/pALEFneNjocnZqnfnwCNTbJwII2um3L02teEdv161oyMwab6Rz175mQ6nHRUkRd1gpZ8UzyVJW/NPAXUf4IYAO3/wf8EJzXEw+cu3/j1da7QIZbHUXIHuOgQQsZIsXUU88GrXzbADkn2pHLSjMtp3D5+bziQi93P4Rh0/tLJ9i4gEmvwAX2raSSEQ4FoHAYTlq0eOc9cOFfq2y3v0XN3jnvDKGEns5DldfP0+oCt+23tok87MXjKebMsrUFD+r/JdRz3FltvlXChUwMbqudoJwICcOGggxhxLSkaQTj+3HgFc0Zw2Ai/Do0SsVeQQRSqXbLRPa4DmpS4m8EWIwNzuT5EuVnwbCN8Q94uHgeIS9iiHZaBO3C5eD+kxfc07Q6Gkt6R3WGlW4rDLlMwonw2PgPcHiAnC9k8nHJFP7a0D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JqpHQou9di/7K8qkHqnZtz3/g03qe0Q2+pP+9qGEyJ64FDDuFe+QDBpY8geTJeLw4cGopxb2IoWy7J0ou4B/b1q89A0LwzZhQJOuFaTrXkNKiQosyXuOpnzQ2lZM5PskmdpPOYWIyYaSS71hI0yiAQpLXm8Rul+wSUA0gn01ZYWiiVjO81BAI+tRPadrW446O4iCJADzuLPOi+GkeSk2KnUJrta3fXIEVVpzeHlZxHwKfPj+MBl5Gvyi3z1EDpbFOgX/b0IMtq0VEL74H+vysc0ljUL5RNvRXuLHg81eweGvDG4+hC5YFMNmkQZhdNUO6zmDjNQPDASExe5y+NtrgJ23xqRy5unCI2y/VKeSXpadnhnWeq/oYjfbOcOKN52fLbPmBGJXzMLOUguY+Ru/e5hX95L4H+Hke+suRCxZQ3oQ+gU9QDldJ8/C3lTiTKxuLd4FhSqXc1P79l1vp0lpJiqQTGhgUvy4Y07nhiQlHA2uf9waWaRHIQs6simlUL+2WSrdnGVlAbVYd6G9qtzzbiNfDPKFZHu1ElPO9dlZQ0t8RDS8zpPcAIrRdIOdTgl/F914v+FGkEytw5m39tSr/TbYb8HQ+QaVP0IwXdtvZsDglUx/DtwJq/8eRnP0cfiFHYIiFlpzBBv73Msr+qi7ECCQ2hgx1h0AxqJtTZEwDwL+h2+omYp2lzzJT3wzzY8TLkQUzMd4hVXyHA61mQQExpshVD3bM51DEnC8egt/QmAmNoDaVUwCBpjUvQcVE0ZeBwWm8LeLEnZVu9c0jOqX5GaRwlo1jjuKErrbkKMYR7QbB3TZGh7QU+R/tVqRdV7+YkZ5oduhN2t9Z02kuMOPFCq9e8HCMAe6A2RaLEkxKg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8cc96700-109a-4945-4ea2-08dac69bb169 X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4196.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Nov 2022 23:55:22.5983 (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: 555MH+6zYauQcw5wLjtFgZTQNbASmyzhNOwzuzMjlQj9AcsNFv3Ig2mFEmUlrfbDw7H2pyw0B5Fak54IjR21sw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4178 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-14_15,2022-11-11_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 suspectscore=0 malwarescore=0 mlxscore=0 adultscore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211140168 X-Proofpoint-ORIG-GUID: 3eslPMFgPWOTHRGhIK3cSlPdlYMG2Luo X-Proofpoint-GUID: 3eslPMFgPWOTHRGhIK3cSlPdlYMG2Luo ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668470129; 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:in-reply-to:references:references:dkim-signature; bh=VPPSt08uUzVOjjlup/WgRlm3neDn1ahbKHMnfHdh9ok=; b=TW7HXonzRrJdUvwFurnjwT9icgBIR1W47Jzu8Z+ga6ehWuI49tdaOQQZdbE7Ly8KuyGYkt QTnEn6VPXxEX7uqUt/Dg0Idqkbs5nqdhdjfUTQdWBFVThu19KwMD/4PSAkPqHsQq0s1Ca/ 3nkfklSsLhVFHb8OV/c05BYa4phgFi0= ARC-Authentication-Results: i=2; imf02.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2022-7-12 header.b=x7jJ1MTJ; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=mSyk5067; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf02.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1668470129; a=rsa-sha256; cv=pass; b=mnDsNZ+8Wl266ueeRGx5e01LmX3AffCcAH/L0+j7gGU0Gd4q6ZJM5KmLP3wTb9BTyj/1PS Uyfm8k4FiHu5L0+OY4/Ojwme/TZweQaCeKhSmE2QlWl3fqWeZkZpN721icP+S4m6Rv/gB2 FluIQeyAl64mi3ZYR4hSPAt6ra7JhLs= X-Stat-Signature: ixfyzie4aomsamcxnkpa9tbq9qc9pcrg X-Rspamd-Queue-Id: 0BA8E8000B Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2022-7-12 header.b=x7jJ1MTJ; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=mSyk5067; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf02.hostedemail.com: domain of mike.kravetz@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com X-Rspamd-Server: rspam07 X-Rspam-User: X-HE-Tag: 1668470128-82938 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: The common hugetlb unmap routine __unmap_hugepage_range performs mmu notification calls. However, in the case where __unmap_hugepage_range is called via __unmap_hugepage_range_final, mmu notification calls are performed earlier in other calling routines. Remove mmu notification calls from __unmap_hugepage_range. Add notification calls to the only other caller: unmap_hugepage_range. unmap_hugepage_range is called for truncation and hole punch, so change notification type from UNMAP to CLEAR as this is more appropriate. Suggested-by: Peter Xu Signed-off-by: Mike Kravetz --- mm/hugetlb.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 7559b9dfe782..0cdefa63f474 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5074,7 +5074,6 @@ static void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct struct page *page; struct hstate *h = hstate_vma(vma); unsigned long sz = huge_page_size(h); - struct mmu_notifier_range range; unsigned long last_addr_mask; bool force_flush = false; @@ -5089,13 +5088,6 @@ static void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct tlb_change_page_size(tlb, sz); tlb_start_vma(tlb, vma); - /* - * If sharing possible, alert mmu notifiers of worst case. - */ - mmu_notifier_range_init(&range, MMU_NOTIFY_UNMAP, 0, vma, mm, start, - end); - adjust_range_if_pmd_sharing_possible(vma, &range.start, &range.end); - mmu_notifier_invalidate_range_start(&range); last_addr_mask = hugetlb_mask_last_page(h); address = start; for (; address < end; address += sz) { @@ -5180,7 +5172,6 @@ static void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct if (ref_page) break; } - mmu_notifier_invalidate_range_end(&range); tlb_end_vma(tlb, vma); /* @@ -5208,6 +5199,7 @@ void __unmap_hugepage_range_final(struct mmu_gather *tlb, hugetlb_vma_lock_write(vma); i_mmap_lock_write(vma->vm_file->f_mapping); + /* mmu notification performed in caller */ __unmap_hugepage_range(tlb, vma, start, end, ref_page, zap_flags); if (zap_flags & ZAP_FLAG_UNMAP) { /* final unmap */ @@ -5232,10 +5224,18 @@ void unmap_hugepage_range(struct vm_area_struct *vma, unsigned long start, unsigned long end, struct page *ref_page, zap_flags_t zap_flags) { + struct mmu_notifier_range range; struct mmu_gather tlb; + mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma, vma->vm_mm, + start, end); + adjust_range_if_pmd_sharing_possible(vma, &range.start, &range.end); + mmu_notifier_invalidate_range_start(&range); tlb_gather_mmu(&tlb, vma->vm_mm); + __unmap_hugepage_range(&tlb, vma, start, end, ref_page, zap_flags); + + mmu_notifier_invalidate_range_end(&range); tlb_finish_mmu(&tlb); }