From patchwork Wed Apr 26 16:49:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 13224765 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 A9FC8C77B7C for ; Wed, 26 Apr 2023 16:50:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D5916B00FF; Wed, 26 Apr 2023 12:50:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3110F6B0100; Wed, 26 Apr 2023 12:50:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0EFC56B0101; Wed, 26 Apr 2023 12:50:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id F1FCE6B00FF for ; Wed, 26 Apr 2023 12:50:28 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AAF9314030F for ; Wed, 26 Apr 2023 16:50:28 +0000 (UTC) X-FDA: 80724130536.12.73F7E13 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf20.hostedemail.com (Postfix) with ESMTP id 4A5751C0015 for ; Wed, 26 Apr 2023 16:50:25 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=NGCXgb+M; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=N2ly96no; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf20.hostedemail.com: domain of khalid.aziz@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=khalid.aziz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682527825; 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=2a9Cp+TU2cZIEMZOzlR4LYSra+7XU34K7asDIdEpMes=; b=S7vRuaZ+LnDqsQ8IFtB39yywBFty0OXlaG6/5DFr8/pTZG2iO4oCyttpXQ5zvab8SpMBOT 95tWP8Jl+wKMRO20GMODvfjYkY0SOznmTj8ltcaKa81XisP9ysBWveIukPGjxQgtX5obfw er7T3IXSexVbyN650l5BELyddV73R/w= ARC-Authentication-Results: i=2; imf20.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=NGCXgb+M; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=N2ly96no; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf20.hostedemail.com: domain of khalid.aziz@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=khalid.aziz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1682527825; a=rsa-sha256; cv=pass; b=G3YsCsQyBb9aSJr0onGangErY7JrV9zuanEjsZjeH/5U4lTE9VQsfv95MTrClBnvmBzg9s de9vsOOy2PITUlrDnzpZqHyDDWLkgbDhU4Kr+EGNhqY35oU+1RTNu4O4QkeD03qEXK2ZPe tssNMavckB+SoIAoDGAuCj9ss6ienOA= Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33QEiVTx003882; Wed, 26 Apr 2023 16:50:00 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-2023-03-30; bh=2a9Cp+TU2cZIEMZOzlR4LYSra+7XU34K7asDIdEpMes=; b=NGCXgb+MRUoVK5+aXnudwcAuFgBoxK2Vv92ciEsSjMDeGzGEf6c6iZ3XBANZTV4Mb8rh 0SxCi3B4fhk4Fcthvk75XxkOkYvfImNYxwET3RPXP3S+0uNCg+pwIhb7KP3uV2PM0CRk F5oFn6w4S5KFQpZKSxflci29pBLOI1aVCRhBuB9LHfQMZpK//aEAWMPHHFux/T6ZqjZu 2xITvJNVpMDBU45N8vWmmDuBsKgQ19IhHm2TpW27+5etBbe/eHtuP1YjKrkXdRQd2KKx jLr47mca6qk7wI3tLo1UbFtVXV6yTFLpWleGwFqJ6yfuW7dlpWRHZw2/DECgOLqzcu4Z NA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q484usxpc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Apr 2023 16:50:00 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33QFROBF032610; Wed, 26 Apr 2023 16:49:59 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2041.outbound.protection.outlook.com [104.47.57.41]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q4618dqs0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Apr 2023 16:49:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xne7v8a8Nw2TLLoKImiN80dLoIzHNgHf/S3n7Mf17YwvUNpADqAriV0gRWk4uiznEQDlI+q65l3fyPGBWptdSGrLif3kMVNT2M33SEv4Fkdiju/QmQwh7e6taWvgglhxH1Oc8wf2oy+j5ZzkzZZH6gJzr8jCdSm/Z6DjRakHY4BJb/PrruUe+CQCc6KmRP/z5BBLt38+om6yq4InzPqF5voOubT76zad/Fie+2fddWs2fPIJ9Th6ueBnL+NW17lcnd6dFv/XJuoUYNWDhJapaOps44NjYHy6ZCyl9YtQ0gz99o71MNbYk2dvuMkWw8jhOS82wpg3z2MY81gaIFMJtw== 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=2a9Cp+TU2cZIEMZOzlR4LYSra+7XU34K7asDIdEpMes=; b=GNK9voBDVVzPwUReSIy1gRgzvpPPAYxjcKA8jd6vweDlOO+gUbMR51wSV47INUlBgoaVRrAOqFPj1GaKEsWuDTNg6vT2UEKA2iSlGplNdqe76VBoFl61QgocpMDW8xT+Hvf+ILHG6c+w+HZ5hurVMqKH4IIhTNbtj2j2JXZkXNt1eFjmKgSQ8hj6ukiYFCN9fUlgFQvIUXG3RNrNhCDmY/a5n/ywrodT0CYPzyz2yomS+WQLt8sjGOY9Rgwukvz6TqJpjNZq2iud+PqAr1jujSdZad8gltXAPXNyVlpGBM1BZkWUY1zNUq15LtkFhIZnEPTuBfq8sHMA/Z6qf6/2nw== 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=2a9Cp+TU2cZIEMZOzlR4LYSra+7XU34K7asDIdEpMes=; b=N2ly96noNEXkGS/R69/NOo58pdqUbIQ1kiyAOnR+ohYeTeyUtX4NqKeAhegG5CHfh3XmzPjsWmUYmOxKY+SQny7YbOVme0H2jtjp506EtuMtVH6grkJSTIavYeMAF1CQWcIoW9h/GgjHMzGZirvv7COwjTXP/vxpI2T62jYOlb8= Received: from CH3PR10MB6810.namprd10.prod.outlook.com (2603:10b6:610:140::15) by IA0PR10MB6913.namprd10.prod.outlook.com (2603:10b6:208:433::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.21; Wed, 26 Apr 2023 16:49:56 +0000 Received: from CH3PR10MB6810.namprd10.prod.outlook.com ([fe80::ba49:e5dd:6a80:37ae]) by CH3PR10MB6810.namprd10.prod.outlook.com ([fe80::ba49:e5dd:6a80:37ae%5]) with mapi id 15.20.6340.021; Wed, 26 Apr 2023 16:49:56 +0000 From: Khalid Aziz To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, mike.kravetz@oracle.com Cc: Khalid Aziz , andreyknvl@gmail.com, dave.hansen@intel.com, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH RFC v2 1/4] mm/ptshare: Add vm flag for shared PTE Date: Wed, 26 Apr 2023 10:49:48 -0600 Message-Id: X-Mailer: git-send-email 2.37.2 In-Reply-To: References: X-ClientProxiedBy: DS7PR03CA0098.namprd03.prod.outlook.com (2603:10b6:5:3b7::13) To CH3PR10MB6810.namprd10.prod.outlook.com (2603:10b6:610:140::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR10MB6810:EE_|IA0PR10MB6913:EE_ X-MS-Office365-Filtering-Correlation-Id: 108f3ebd-3d4a-49e1-be5e-08db467643f5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Db7h8TxMJNjWJfalmBZWrBafvgTmOc7gXlVIC/+kpu4zOv3gmNGnwzsKAc7fjcFv0AV4bcvYOF2r2IdfQ6GSpMccq4AUfVNAAT9UtceSPpUDz6N/J5+97rrDpcNzNBHfc+UuKVvQPzEzP5PVVIvESQ2QJY7hYYDCiL07mmb2a49JOfJSqOlcf8Qe5c9nbK5TLMVrj6mvKrQOr+yGK3xeX8Dd/JeRmmSXf/IjtKeyJ1J9We94qdXuD67FJ8awkRrQl34Qs4+TCADq7trKwiyvKjfPDg+ltsou969J5lLe7rJiipbghKJ2HTa9nFLP4ksbawU0YsiZ7YGwtO+HDe50RD7raKMf9pw/aJ+8Z6LTGZ1UolTFTpbkB/Dggy8SSrNXY4cL7bJ7F20Ef7aMekmnBvNMH9Txz+7ofkYotTJEPE1vXFx7SLJdh6Om4nWV/2vDaxhCKO4RdipcHxysPePLFRPDwttGrZqaJFRXrI9qgHZ1sfJzS1trrVOw4eLPvyrYeNnceT95onnAUT0Tqu+kYgGRNSO/yZ6MXvxY1UAOeNwyz9/B/lU6i9ebIyBX+u5H X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR10MB6810.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(366004)(39860400002)(376002)(136003)(396003)(346002)(451199021)(6666004)(478600001)(83380400001)(2616005)(6506007)(186003)(36756003)(26005)(6512007)(38100700002)(86362001)(6486002)(41300700001)(316002)(66556008)(66946007)(66476007)(7416002)(4326008)(6636002)(2906002)(44832011)(8676002)(8936002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NwUyEbmQ3OSVXRgkFn67u/YIvNI4qI4/Eb8LqLaCzjp9k82NV33Bi86ZJMxCtKl/HTFe6H2t/+zj8m9aL2HgZ+ibUYa5gLj+JvfTZgx4fg56fxnjIau9YaUKd3beic2Kr9Czujfn9Gedet5N6NjCF0PfAk4DKsVnjOKuTZXSMJ7zfGneelID0+fRJpv6sbcgsLuk84wLLOgREWVTL+RQV5KcJBa8lXA1UYi321lSqLLArIvzSqUdLDCdLqdDqHXiFI5rnss5pJ7oIk94gaQ8HVaZGdVVd6yBWH/rmcNGkCGxtGTABEKXbqyIcPAKao7kGPgjBr6ozomWTjSgBFT/U/onWcpenYQuuT56hqTQJ5S1LKhloncGZNYBX0pOSw3cDcEWWPdtwnEmHWgZ4gwrVZQ6MOrZ9kOt5OCfExUfiQV+Y2rL62dHkzFzu1K5dCjZ8KdePg3bU5I+qcBIGWVQ7Xh0X/195CEmAjQ3JH/JWeXX71NN1s7bTHjywrcBeqMwtD2XeIcJYInLk9G51+c1IQpeFiwHci+2eW8Spqf55V690m2mCeUYUGTGKqML4InisxccRagdeTsBevla/uHtLmCmAzkdkqM7uXz96syaYVxiayCW21r74BiCQIq62lNDeNHLSGRRcc4taNkXdepA6my/NkuWAN6tUBsvg3+eI1fn4/YvEOfcvJBAANxjpPGDyX+sn+BwALItKuCAVtSwxS385HT1RiDfAx0mjj12d8TZCTdAclZ29knbeiCSWUoZjPrKDn0yiLXxiqVPAQpwHiUq+88ebM6nVnIyLNeFIw0QKX+loa2ZFGQAA8SnKT4pDPZE2ftwpEYoeLo4Izgl64gAeGAdl5EHuBmlg1XDrRPgecF/xelabLAzceoGRvTZDycvyBvQIPxHSPYXqBMXevFTkT7aJsiOpcZjIfqL5IQAee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rossTenant-AuthSource: CH3PR10MB6810.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2023 16:49:56.6046 (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: rgoIJBTgt795gDaTidhQEU1K6uP+vNhFJJFVKn2y/41E0PjUS2HB0lG10ucFYzQpBsNq279c+mRxBJcA7MHWiw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB6913 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-26_08,2023-04-26_03,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 phishscore=0 mlxlogscore=641 adultscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304260148 X-Proofpoint-GUID: 9VjU5Vai42hnSpoIwODJyFWAqxNiSaGt X-Proofpoint-ORIG-GUID: 9VjU5Vai42hnSpoIwODJyFWAqxNiSaGt X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 4A5751C0015 X-Rspam-User: X-Stat-Signature: x9ar971jwoj1ztter9mo4mmxnuerxp5j X-HE-Tag: 1682527825-820862 X-HE-Meta: U2FsdGVkX1/FtCgoIH6X1NUrQ/eSsqBxjvCbwjLDV+sOYXxeIMenSd2OGYJJ9MrmaogIxlFd9w6vn5OdQxAgihCyMX6q/wlj6QRD8fsnv7n+SjN3Vm31bBaVX1+Pj4U+dqn7E98qk5R858icK4HLH8PRUjc1J2gaXEHiUQvrlD+unWHVtN5kUc7vsLU0/eM3GGFE230MrAKZoiZFVKsV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SbzipNfTqnBoK5OZXoZi9GYuC1pPs3kCtpflq+oChC8wNvLrfHLxi+9QcLIlNWTTRgfzl2bHpw88HbuiJP4SmEx3jN0lei1ysNT4TqydWHBOzytmzz0lFs0SW8w1kvB41qHK/ezdswEVN1uyD0w== 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: Add a bit to vm_flags to indicate a vma shares PTEs with others. Add a function to determine if a vma shares PTE by checking this flag. This is to be used to find the shared page table entries on page fault for vmas sharing PTE. Signed-off-by: Khalid Aziz Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/mm.h | 8 ++++++++ include/trace/events/mmflags.h | 3 ++- mm/internal.h | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 1f79667824eb..539becab551a 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -326,11 +326,13 @@ extern unsigned int kobjsize(const void *objp); #define VM_HIGH_ARCH_BIT_2 34 /* bit only usable on 64-bit architectures */ #define VM_HIGH_ARCH_BIT_3 35 /* bit only usable on 64-bit architectures */ #define VM_HIGH_ARCH_BIT_4 36 /* bit only usable on 64-bit architectures */ +#define VM_HIGH_ARCH_BIT_5 37 /* bit only usable on 64-bit architectures */ #define VM_HIGH_ARCH_0 BIT(VM_HIGH_ARCH_BIT_0) #define VM_HIGH_ARCH_1 BIT(VM_HIGH_ARCH_BIT_1) #define VM_HIGH_ARCH_2 BIT(VM_HIGH_ARCH_BIT_2) #define VM_HIGH_ARCH_3 BIT(VM_HIGH_ARCH_BIT_3) #define VM_HIGH_ARCH_4 BIT(VM_HIGH_ARCH_BIT_4) +#define VM_HIGH_ARCH_5 BIT(VM_HIGH_ARCH_BIT_5) #endif /* CONFIG_ARCH_USES_HIGH_VMA_FLAGS */ #ifdef CONFIG_ARCH_HAS_PKEYS @@ -372,6 +374,12 @@ extern unsigned int kobjsize(const void *objp); # define VM_MTE_ALLOWED VM_NONE #endif +#ifdef CONFIG_ARCH_USES_HIGH_VMA_FLAGS +#define VM_SHARED_PT VM_HIGH_ARCH_5 +#else +#define VM_SHARED_PT VM_NONE +#endif + #ifndef VM_GROWSUP # define VM_GROWSUP VM_NONE #endif diff --git a/include/trace/events/mmflags.h b/include/trace/events/mmflags.h index 9db52bc4ce19..26f751e76c46 100644 --- a/include/trace/events/mmflags.h +++ b/include/trace/events/mmflags.h @@ -194,7 +194,8 @@ IF_HAVE_VM_SOFTDIRTY(VM_SOFTDIRTY, "softdirty" ) \ {VM_MIXEDMAP, "mixedmap" }, \ {VM_HUGEPAGE, "hugepage" }, \ {VM_NOHUGEPAGE, "nohugepage" }, \ - {VM_MERGEABLE, "mergeable" } \ + {VM_MERGEABLE, "mergeable" }, \ + {VM_SHARED_PT, "sharedpt" } \ #define show_vma_flags(flags) \ (flags) ? __print_flags(flags, "|", \ diff --git a/mm/internal.h b/mm/internal.h index 7920a8b7982e..4d60d2d5fe19 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1042,4 +1042,9 @@ struct vma_prepare { struct vm_area_struct *remove; struct vm_area_struct *remove2; }; + +static inline bool vma_is_shared(const struct vm_area_struct *vma) +{ + return vma->vm_flags & VM_SHARED_PT; +} #endif /* __MM_INTERNAL_H */ From patchwork Wed Apr 26 16:49:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 13224763 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 E3A7CC77B78 for ; Wed, 26 Apr 2023 16:50:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 165396B00FD; Wed, 26 Apr 2023 12:50:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 115616B00FE; Wed, 26 Apr 2023 12:50:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA95E6B00FF; Wed, 26 Apr 2023 12:50:27 -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 D985E6B00FD for ; Wed, 26 Apr 2023 12:50:27 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9E0C11C695A for ; Wed, 26 Apr 2023 16:50:27 +0000 (UTC) X-FDA: 80724130494.23.78BA9CF Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf24.hostedemail.com (Postfix) with ESMTP id 45B4618000A for ; Wed, 26 Apr 2023 16:50:24 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=NOeNjmm3; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=SmCF9REh; spf=pass (imf24.hostedemail.com: domain of khalid.aziz@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=khalid.aziz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682527824; 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=OJ9ZwvA5PtO1fy3J0kwyv9tvqOsMb74PvRDYnKl2qJg=; b=ZJ4Wrtx7MtzqANxEC33VfLm/DkFWZCtSHTRklzMtRh33aAzKkFxOpRTD7e7E3uYysmnJj/ J+JXp6uhE0K2aQ8iKpU+xK393DESr9j+j20IGQo9Jgj2KmoTxV8LvsW6rmq/Z5UcU4OEXV TGSc0TPtmLu7fBls+Zx3hwJDLKGBOhE= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1682527824; a=rsa-sha256; cv=pass; b=p+5nQgAQtoIg9cDLcAOv+NgUgIMKW1TaT8dDkHYJVM23U6XofB7lC35oZlJDhoCZGrvTtY +CjBCXcIyw/hBs/A7LmS9TfO/KZ35fdB+/fEyxOJQ0Am8KnZ6pXE8RAc6q7UnX+43Jtbq3 bFKXfKD8Vfp7JPwp0chRhXjjc9WIOpU= ARC-Authentication-Results: i=2; imf24.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=NOeNjmm3; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=SmCF9REh; spf=pass (imf24.hostedemail.com: domain of khalid.aziz@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=khalid.aziz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") 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 33QEi8xp000962; Wed, 26 Apr 2023 16:50:08 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-2023-03-30; bh=OJ9ZwvA5PtO1fy3J0kwyv9tvqOsMb74PvRDYnKl2qJg=; b=NOeNjmm3noKiHg2mIyNfkqvkdMVBLlnz7prltBOJoZ14OJfSbIrVZwzg3exkXYY+3SV2 ET3nStFlKclNyP6D6xeLfzopzZ/vtiuMyknDFMT+CKxVc0yPARRCMIhxtXHGgBeUaJku k1ZrMg5bP4Ch6KLY3GP9eE+oGYkiSRYpHV/a7wPAPEB1YgNPETsMgftSqn6AXNKcRjBQ fJLC0W8Wi3SbpYoDXDFw6A9U57N+Obzjpilb6Pw59rqra6KF9Cb7g5nl4FfRRixbGV4/ aDZ3wMzJKlmbdTFxYX+iONgwSpnyCP1tbjpRKXf0c+X2MseMmGiSPxkfBxsLHeYynnKJ LQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q476u1w43-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Apr 2023 16:50:07 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33QFfqVK032877; Wed, 26 Apr 2023 16:50:06 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2042.outbound.protection.outlook.com [104.47.57.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q4618dqt0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Apr 2023 16:50:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NxStjJitZtEWZ7vqvnCJwks/1QMQah/zW0iwx50krSECCiq0FLD4i/Jb9Ltk7Wt8gVtDwqcIYRqtOnK7/xk3/kWQbFKckjErdCuM3mEiVF+mNXMFObx7kr9ExXvMgvxkQld5t5grUiK1zP6yLK27IXB0SsMQyLa8boeZYEyGzjPJ5F92DLj/Ah6Gf8yLNPURxRBu0KErOgIp7KHnH086ufEcrtsg0TyI5ROOwH4GxO9kbVIkTmxs9q4ka5Tydf3pJaa33tGlt1KRz2r3sqQCMhEvWCynsId9G71qn/rUxx+t2oed/ABIjRhEbD/0U1RLMx3Dw0ZzNHmB/N7UZdEiuQ== 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=OJ9ZwvA5PtO1fy3J0kwyv9tvqOsMb74PvRDYnKl2qJg=; b=e7TiXZpaz+o5uwR3zQtGO+G5WhFiDKUxLDaxAyUja6ysAmNXbjKJBpampXaeMY611OUf49PtoWteQsW+sYgCHm0yKUqQOZ8bTns6ho90zcAm0zl4Hh0eVWQCfzZJoAmb0Fuk1Gbh98qz8H52n2ib6UgdoboB6a1Hty82t7EN5ZKkXV+ThHRzzDKRq1fZEHTHizKv1UwDdsZn+GG2kAGPjjwPeAotPhtU2nFrU3WfrBsti+ALmQEWgC3TihVqAIRM8IB3FT4O54TFD08zyMvDMI77+TUhPNHMZGDixvg6lNsoQh5RE2alQBl5lTwZvnY1I0FaMsbkObl0lsUmacEyOw== 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=OJ9ZwvA5PtO1fy3J0kwyv9tvqOsMb74PvRDYnKl2qJg=; b=SmCF9REhgv3AxmaWAPQFSpoxdn87sjxRQ0YGyWNqnyce6j8sLTm9hua3wyo/JOml+7y2pvSYaRBUlWA4UElvtTpJQWs5+UJUzYPwdDRgebqXuY2SNH+jfdtPU7eTVNSGn2jLRm1RT9rXaTd6uxpFkjwrLX0xd/M8u/0EaaZEhZU= Received: from CH3PR10MB6810.namprd10.prod.outlook.com (2603:10b6:610:140::15) by IA0PR10MB6913.namprd10.prod.outlook.com (2603:10b6:208:433::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.21; Wed, 26 Apr 2023 16:49:59 +0000 Received: from CH3PR10MB6810.namprd10.prod.outlook.com ([fe80::ba49:e5dd:6a80:37ae]) by CH3PR10MB6810.namprd10.prod.outlook.com ([fe80::ba49:e5dd:6a80:37ae%5]) with mapi id 15.20.6340.021; Wed, 26 Apr 2023 16:49:59 +0000 From: Khalid Aziz To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, mike.kravetz@oracle.com Cc: Khalid Aziz , andreyknvl@gmail.com, dave.hansen@intel.com, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH RFC v2 2/4] mm/ptshare: Add flag MAP_SHARED_PT to mmap() Date: Wed, 26 Apr 2023 10:49:49 -0600 Message-Id: <63bb4b1339bbdf33c3412cdd097af61285162cf5.1682453344.git.khalid.aziz@oracle.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: References: X-ClientProxiedBy: SN6PR05CA0025.namprd05.prod.outlook.com (2603:10b6:805:de::38) To CH3PR10MB6810.namprd10.prod.outlook.com (2603:10b6:610:140::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR10MB6810:EE_|IA0PR10MB6913:EE_ X-MS-Office365-Filtering-Correlation-Id: d344b039-bfd0-4417-32f9-08db46764597 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nJCYNoxMgdeqrl226oIjM/3CfFsifcD0oyIqoEF6CfIEzIOOGtMQ97HGjUWvp6pVG+CLNY36eh0H1oHOp3bPcErdgMCKz86RnK3is1SJSLVwr3ag9/njVidM/1+unSkWNnmKnpj4/gJQUXMxkrl9wGlP14Hs9gEvJ4k86sNpMcBX4CpjcuntK3YgoAGBNVyLwoiKP3Ne8NjL3nafnOUab1y/vKU8aSEPlyaBfOUKfznlRcaEQImDIbL1u5Py9KAprC1vtImOIFcXZ5ImYr17kcOc9l16t95w3PJzx4gVsa8qDfAKJLjb8x3Dh1KlxRX6jfbNF0Ivm24JACzbbIOyJmwLl/AeprM93LQuMj7SNZXhvtllwnu0olESqFk1yKDTBnaVpcxsDrP9T0s41iGzjRHsxWlbMcxS5qOE1FF8tk26rG/00arXuWQSrZkcB1wvsQDC9v2SC8Fk4CZDi0jKE3efs0sFteemA5hfDqBTuhKggOZokbCvm/GXzTL9Zmbxr1AmC2C/tmnZowKUdmyWnNlcA46NZNuaXxou3Tou+l+TwWFLzLJjx84+hUdO8rZz X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR10MB6810.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(366004)(39860400002)(376002)(136003)(396003)(346002)(451199021)(6666004)(478600001)(83380400001)(2616005)(6506007)(186003)(36756003)(26005)(6512007)(38100700002)(86362001)(6486002)(41300700001)(316002)(66556008)(66946007)(66476007)(7416002)(4326008)(6636002)(2906002)(44832011)(8676002)(8936002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: r7fhQWd5L4g/dMwRjKdajA70xo0yZNHkd/fHE8p3SLLdRpXmZJUH+LtOSgBfL+AlKtNxuWWytckH5uQZRzCwNl5+E0VfTsWECJUk4pLpIOwPsOGKAjCy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s9+Om/hdsktfY3f+Pf4FOr52dsJPvsN//rlxxVkzLLpkcqUrvbkdHo0oSULAiu4UD1uDkBvy9TLTGyaUMRjjWCfVrAPRw4wT9rALz7IoRuLzTZKsAqYMbb28MYVf3Jlcaq4VKHAfM93Mb/Q8Rs+SrDI9DkUZUdO61N9r0Zz/vVVJWQD4a0XQhcyrs+aT3O4lleK4jnoXYSO4cvUdLi3vE7Djm4rvpkeW2XQwa+lNKZljF5LqnRxDM4xGL6WGR/w8FxtSz8mkG//6g1+0aL9MLBHSHz6JI4/Qi211OJw7C1HEm0cgWfqYjaNyczHW1AGhxf8x8/3Zl4JFqDQAROIH8B3FSokY1hFzM4j2ktutGoAakfG0RTD3eNkbI8TAiZ0eApfzaorCRuyCPvE1Ds3LzwRviouxqDwZBfMfidx69/wiZ6XzQbuanJ5el3KG85Qg+YkqmQvqpEAiQ3ANzH9XznWHODieOIemewPxsdp+Jwbah7KHqO9YDNA8g4ljMHNl/mTzETIVgyV1Aq/YEXd7Vdtt0wupGP9IbWU+LIxqsEC3GO4sEtzcEfkKs9IfOH7POfxc04Bhqmume1QQoqWNRWy0DZwnp8z1q57gQr0HoRzV65HpvSbknuJ8SWE3Nj9DDZLjzMNV5WQiWbeLhHxpwSOlCbG/1IyzvlNw9KHyDpR1eR/DhFu0hmCg9m2Lj6d2knguy0Jx0l/oVQvU0rB1GrPQGAPsAnF4sry8p1 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d344b039-bfd0-4417-32f9-08db46764597 X-MS-Exchange-CrossTenant-AuthSource: CH3PR10MB6810.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2023 16:49:59.3573 (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: WQ7+BVmdzx0XFmbmReFFK8ubCnkHhTi8lCWO3bNBucqL8ty50gAvS8IooMurDSoq/iVwroBMRcnICPt/+3nNFg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB6913 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-26_08,2023-04-26_03,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 phishscore=0 mlxlogscore=979 adultscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304260148 X-Proofpoint-GUID: hQ_Kqw1tXKwKFNpr5WQq20G9YbuOEO6_ X-Proofpoint-ORIG-GUID: hQ_Kqw1tXKwKFNpr5WQq20G9YbuOEO6_ X-Rspam-User: X-Rspamd-Queue-Id: 45B4618000A X-Rspamd-Server: rspam09 X-Stat-Signature: q5jhxypf9hcenbh6jnm3nqhedus1swdi X-HE-Tag: 1682527824-466216 X-HE-Meta: U2FsdGVkX19P2QZsP4js5s+hwU50QtpTJ1KXprWBHWj35mtiMdis7DM8MPGLFTqOpVxH7qJ6707fLRcb6a+CznFgwsMrtrzuhx3XMm40JRokYtt/JNr4cvLdrNCcmVVNV8htwZUdKnAsAOKxxph3ffdBHvRH+ElVRou44y6goCsUfThLQ2u8XB0vX65FN9LvU8Vjc5S1cFsz8FLsUF8Cc7Xzq3TshimNvsRePXpNG1Ay93dbuFKuC3Mcgw04Tre6tjdNh2VfYY+KZQE3HbeRa3DjwJu5r0IVg+50sC4YxAkUjSM365+UJw/jI50UP9b8zNASK64Gc5ADlTvMXCi9/CmtI8XKOYJ+/QRcE1vj6dBsAGp1hKfT1+1xOB7LRY4TA5cKVAdhl9+oC0iJm7NRjkEzI1c/yOQPynUDg07hNeMQr0YZNJE35m4jWPptrfVj0Ruo1jLxReqNEo3DDYTIsgXQbBSo1iR0wPdXRCt5e+ep6e5AmJ3J74XKe5uNTX2c6OGdMEGQ0qt85FzV1rnTIgzaZdJNHhog5bGSXgEvJcr4sztHLX2rv8nWjzp5Y771gejM6zYwngYiO25nMZ83VvWXRDZljUVQkaenli0pJ8xhfQQuQXdfBBxwSPJCS+u3PFzkwEP7QTC6w17tIXc8hO30IidZ9Iy9btVOhXydUlUB4Q0VITASz5XVMH+qJfTDK0PMqyF7xrkkbW2tCSTqALSazBEeb7i7NSq67vIMvzx3k7WmwH0jPo0mFMPuPCOLwD8+T3jr45YpU4mogANUtQxQYZoagB+RzNyK3dGX0UpfrtHC04gqJnHNz48Bfg+gglMNtvxTP6tF4AwLGoDrmK0S6CKjB7OAfYprWvUo429XVMTG+/rN2jxm6fje4mrxRURtEi6cuXxirkpFgNL6yfStnZNJ9l8vFeGGWtEiOtp/cxjtEXd9syj6GnK5FCGlpgQH8VNK0pEn13x8g3U ah4kZle/ LtQkTfAvvi7nh4A0Bu9dQlhJxx4OO6uVHSOWW2NuVPUylkkAgj/dPIV7BV9e2JDRxzfgObg2fbIGX4Kf6TDyRzeP2IiVOqAX/AIm+z+zh8TcuvFwcgM4ta9NnhqM+R1O3uKzh8bjHSFYKOqquYtym5ORcZg+sZkA0v2ADgi8I1mxVW9dMngWplKtCOso0FhShKuYvtE2Rb9B9lKBCRWDgWOfQfsG4wvyw5xmmQ7vE/60UIToUGeCpsjmSu+1mzI8yuRlPgVJi2NHLr4W2+/oE2tYUIpuXlgOXNLIXGQ4XgnSQe9d7QjQZR5AK4cIOMM6F/ym9manHKImX0S64q7Ii+VwJ/gdBtlqtA5xrVAILPue2BWpbv6zxe5M8TBVuomUTdOFR1eKglySyEiZtoyS8HYbZULwEkCizrbtbXt2eLwsBIQM= 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: When a process mmaps a file with MAP_SHARED flag, it is possible that any other processes mmaping the same file with MAP_SHARED flag with same permissions could share the page table entries as well instead of creating duplicate entries. This patch introduces a new flag MAP_SHARED_PT for mmap() which a process can use to hint that it can share page tables with other processes using the same mapping. Signed-off-by: Khalid Aziz --- include/uapi/asm-generic/mman-common.h | 1 + mm/mmap.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/uapi/asm-generic/mman-common.h b/include/uapi/asm-generic/mman-common.h index 6ce1f1ceb432..4d23456b5915 100644 --- a/include/uapi/asm-generic/mman-common.h +++ b/include/uapi/asm-generic/mman-common.h @@ -29,6 +29,7 @@ #define MAP_HUGETLB 0x040000 /* create a huge page mapping */ #define MAP_SYNC 0x080000 /* perform synchronous page faults for the mapping */ #define MAP_FIXED_NOREPLACE 0x100000 /* MAP_FIXED which doesn't unmap underlying mapping */ +#define MAP_SHARED_PT 0x200000 /* Shared page table mappings */ #define MAP_UNINITIALIZED 0x4000000 /* For anonymous mmap, memory could be * uninitialized */ diff --git a/mm/mmap.c b/mm/mmap.c index d5475fbf5729..8b46d465f8d4 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1197,6 +1197,7 @@ unsigned long do_mmap(struct file *file, unsigned long addr, struct mm_struct *mm = current->mm; vm_flags_t vm_flags; int pkey = 0; + int ptshare = 0; validate_mm(mm); *populate = 0; @@ -1234,6 +1235,21 @@ unsigned long do_mmap(struct file *file, unsigned long addr, if (mm->map_count > sysctl_max_map_count) return -ENOMEM; + /* + * If MAP_SHARED_PT is set, MAP_SHARED or MAP_SHARED_VALIDATE must + * be set as well + */ + if (flags & MAP_SHARED_PT) { +#if VM_SHARED_PT + if (flags & (MAP_SHARED | MAP_SHARED_VALIDATE)) + ptshare = 1; + else + return -EINVAL; +#else + return -EINVAL; +#endif + } + /* Obtain the address to map to. we verify (or select) it and ensure * that it represents a valid section of the address space. */ From patchwork Wed Apr 26 16:49:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 13224766 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 7D013C77B78 for ; Wed, 26 Apr 2023 16:50:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 18CEE6B0100; Wed, 26 Apr 2023 12:50:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C9A56B0101; Wed, 26 Apr 2023 12:50:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E0F6C6B0102; Wed, 26 Apr 2023 12:50:31 -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 CCD976B0100 for ; Wed, 26 Apr 2023 12:50:31 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A76CD160349 for ; Wed, 26 Apr 2023 16:50:31 +0000 (UTC) X-FDA: 80724130662.11.2E8A204 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf11.hostedemail.com (Postfix) with ESMTP id 3033440015 for ; Wed, 26 Apr 2023 16:50:28 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=BtTlHT82; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=gY0ipTXi; spf=pass (imf11.hostedemail.com: domain of khalid.aziz@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=khalid.aziz@oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=none) header.from=oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682527828; 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=k5APzXW/ZudHfSFqhzk49VAejkMZvRzADzPwN1MsmQk=; b=PqP+dq1lattnT2QzZFlULwsPB1eMecjlC6TyVx4n5OzmhYVGWtXrQw0tqUcOIAgEPepkCk zrCG5eO9pKfQXmQS0h37BFhbkWEsSExNM2wwpDN8gl77YrIocYI7ruw7j2TyjUv15BUDRJ fYWOrjG2sQ6CjfKJRXjhM4gr56n47zI= ARC-Authentication-Results: i=2; imf11.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=BtTlHT82; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=gY0ipTXi; spf=pass (imf11.hostedemail.com: domain of khalid.aziz@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=khalid.aziz@oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=none) header.from=oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1682527828; a=rsa-sha256; cv=pass; b=3NfUq77qshrDEl+z8gbcy3ReZOFe9wOtW7AiuSPjkwALyUNv06CdVmlxbMBtETzqrDJX+Q 6CVcGdq+cyPdH2OsPPp0MwoA6ia22wkyaaaErNV8KBlSMwX5SY3v1EOKVJaSycLXnjCETK Qu3TuW+F83tb6wWX5ok9AS7K3orKNx0= Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33QEiQag003816; Wed, 26 Apr 2023 16:50:08 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-2023-03-30; bh=k5APzXW/ZudHfSFqhzk49VAejkMZvRzADzPwN1MsmQk=; b=BtTlHT82OJd+muyZdKptmotc8VtIEt9/5r3DTc1YQRwO7hUcSXoIcl50xwW4I8FxqTif jqr5XweMI1+yxcDmlVN8SaU0iqglTY7J/zpLRaeVejdReYW7oN10lGGPv/7mnz7Gu9L2 jksgcpNwyn2eHjQ79jXglqUs2ejk4tnQwiE40GfbXRdmA2EdQxRVBqtN6m4oQR1+RSv5 MWCo0I6AOody2hjSHP5zuPPW4TtmlZ56BfOQkH4Ba6tNgv2w3fz5CfxUIE4oZJADvaOp gVLWYp7d7gGC5JxA8KE1TZu+UQ4KdqI4ay0cp1/ezQ4oJgShfXZd0xjNmN7QuxkxFTiY 0g== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q484usxpj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Apr 2023 16:50:08 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33QFfqVL032877; Wed, 26 Apr 2023 16:50:07 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2042.outbound.protection.outlook.com [104.47.57.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q4618dqt0-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Apr 2023 16:50:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BZWPlwczlKUjolSGUggemrBBvNFmyg7x0RZpTFEpaPX1OFm8rxpfgq6Ungb1UNLjnywsmxfu2UPJOVd3yiKOal854CoCTipeWd2lq3A1Kpyeuxw3pB76wAkfg0vVeBJanQEaGZHvSB6YjPC6eT8RVzonDRmVY7ZJhekOt88uGA35BpjJoCspX4vyGHyIrpwtOfkoMyb8k1aaRkpYZD6iiuWptaGWha0Ev+w8Z6Xxybceu2EDf/ZVNUd0YMXlDYPTctPOPcP/z+2OakkJxe+mBqMNskCPl4O0pvgmEVRl8YhcfuWKngaI77x4h7K5GrXU2CCxTpjUUCu7svW8Ii/AyA== 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=k5APzXW/ZudHfSFqhzk49VAejkMZvRzADzPwN1MsmQk=; b=J3Gp6krS1peVROKEc4tltzGIhkvO42MIcDJRPC4bu1c52gK4N5tLBb7g7/unyy7B9p+KY06d2xIjalj7+xh0oRQhVYH9jEBV9rFxiGRq1HphugmD3K4tjhohtD+J2d6WIYU8Zf33eGFicxc2K1yWybrkxOWcZiVhs3j5I82WXGXU9DkRSWHHwr6yXQY1ygd+35AWn/B/PDVVAA2pQQrkEjktKklGvxMs5DKwsOx9lWsSnT/md5mHknNcFYpv0YvlEmKeAUwBUGPcVVjQK/5q8/MBbMf26sNxyXwSsX6XYy9ZK9pZN4dQDhd1pP0NM6ngrJmpfV3CemNLqPzEN7fZ+Q== 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=k5APzXW/ZudHfSFqhzk49VAejkMZvRzADzPwN1MsmQk=; b=gY0ipTXiaDjOCOtaC4eLVtmqXNCVfZoFdjZx+p5jXEck0NlevNO5MlPcEKp3tztXAD2kXCh4Oi64AaE88hCdBXsAxJ94PRYfHEJ/8MR7yKaYzGLzxtslrhfrq19jZDH9m2x8Dh+Y69jenmHgCgDT0uZp86zqmK5Nx0rBArJeV10= Received: from CH3PR10MB6810.namprd10.prod.outlook.com (2603:10b6:610:140::15) by IA0PR10MB6913.namprd10.prod.outlook.com (2603:10b6:208:433::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.21; Wed, 26 Apr 2023 16:50:02 +0000 Received: from CH3PR10MB6810.namprd10.prod.outlook.com ([fe80::ba49:e5dd:6a80:37ae]) by CH3PR10MB6810.namprd10.prod.outlook.com ([fe80::ba49:e5dd:6a80:37ae%5]) with mapi id 15.20.6340.021; Wed, 26 Apr 2023 16:50:02 +0000 From: Khalid Aziz To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, mike.kravetz@oracle.com Cc: Khalid Aziz , andreyknvl@gmail.com, dave.hansen@intel.com, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH RFC v2 3/4] mm/ptshare: Create new mm struct for page table sharing Date: Wed, 26 Apr 2023 10:49:50 -0600 Message-Id: <1fd52581f4e4960a4d07cb9784d56659ec139d3c.1682453344.git.khalid.aziz@oracle.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: References: X-ClientProxiedBy: SN6PR05CA0003.namprd05.prod.outlook.com (2603:10b6:805:de::16) To CH3PR10MB6810.namprd10.prod.outlook.com (2603:10b6:610:140::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR10MB6810:EE_|IA0PR10MB6913:EE_ X-MS-Office365-Filtering-Correlation-Id: 031d9564-3c56-4b34-db61-08db46764722 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8Kaqs+Hvx6YnhsT33GzL7LJWvKbkjiJiiyoEMm/tE/Vuiir+rgPiZMKvT7fh4ONq61XS1Uf1YEKowIkj/9SV9p89x/FQb4PsMQGMFe5eNOjEfvk6K9QZ0zGWDme3ao+HOHbUbSA69Rpb2YO+c+DxekHd0VeiH0p2R/VUz7eRQqwZyhxzx9zvhu0PiA6AWNW/z83KMj+3voV2zKKsnXeApR5eCxspwriUK78bS2z/DKuUq7WlQjqf0ZZepgz/fBH97Om8cCyXFgGKWqUq+SbMNTwcBuDnt2hqVvlHe8G2Ln55u/xQ1e3lWdJxSpzoDyKPzvBISQVrNEsjyVOcq2qhxbW0GZf0RPaYKaO9ROcWP4zpbeTsm55xm/vVdShlqWMne//ohYwksDkSXA40hlNY7yiKsGMYwPT0hM7rPtfWQu8PCkiF4FsP8aRTQayLCblw3ka+ZjY1EfXg+FBbliBuxSiiHjmTXS3DswEslsggl8Dx82BSPUwlg7ZrSG0njlfy9+mDWW2UuHmgMvOz8sCu2gqktMa2edA6IM81g5OUGInTyzm0aqm+oM3M/rBDCkZ/ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR10MB6810.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(366004)(39860400002)(376002)(136003)(396003)(346002)(451199021)(6666004)(478600001)(83380400001)(2616005)(6506007)(186003)(36756003)(26005)(6512007)(38100700002)(86362001)(6486002)(41300700001)(316002)(66556008)(66946007)(66476007)(7416002)(4326008)(6636002)(2906002)(44832011)(8676002)(8936002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 82zRG2GBDOnMSvuvHnHMCYQZHvtp5npV9L4sWmU21IRIu9Bp1HAAGKP7yrbwzMuaCYQlvnH7+o1MCHSUBRAA4BvMH63NrDRvxUBJx03blPIkmMCBGjMnVDkbSTIJQav9gbg85FRigckQqlblBGlySKbXyS/z/khIFfPixviz2KBXQ6shIu+/vYuGr3GTngcZpRUnjJC/ITFBEdO5ayEMSvj1jGpnNMQ6tbQuLx0MKBnQbe+x43hhEOCKMlbEX3uKMn9eAmLfOq1YOVkvnnUdLsdsqFYtClXjjNfWe4I1sWpFE1u04VGJ4XNbYNfz78hOKLlTah+YxyT/Qywl/ZvnAbtUArutWjc5zzt+s3RLWi+87XavxqvTtpss5v8JBs1z71YT583XWPxM8RkhHr6KTLOGWQMaNSq/ml13u/qBMyFdUbWvRXk/VOVO1V/s3VnoShiPTrE4VxrAEOltB1QlEalZ6yaWaqHBrydhPXUvOCIjIbNL0FVJyESMhQa5Rbao8R4gWv6n0G+kuvAO8rREx7088LXpwPKEN9e6CkdmBRuIJFUi8v4NWXtMPuMdB7Omph6vZWb8MNIdeYkeA8lkU42Sk6yN1hjHA9x0cNOtSI6yfDS2K8A5SBqaog2gDnfF7IxTaQVzakGjwIiQy+jAGVzeUvX44RV1LjiI+Rnf6vsWGhsexJerOzhAWgaj8TE7E/WnNkbPCHA8TqFQ401G3CzprTHckqtKV9FoUr80ajGVoh8MYGeyp2OOFsj+bZKKgHV2b9uyAgXcjnsXAqApGkIiRSfrPDlYhiPakz1I0wFdJuGgNngwNBncO5AEGrLRuOJ6HzhovsLf/Eb2VrKENhvDpQR/b+puotb5Vl6Uyq3K4gxvdfK6FsXs1fwRm6typBJ1yJhnQV/oUWsmsTK1orJ/3A8H2XO7bC6GcpplH2jp7tp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exchange-CrossTenant-AuthSource: CH3PR10MB6810.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2023 16:50:01.9614 (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: FLFXNEH4JxGr70AT9ZkSmyGYEH4dTtkU3GVC0+U+7dB59Q/WF2ifcONe9+GBDgVaH11e8tvoCUkVRA8YmmIxuQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB6913 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-26_08,2023-04-26_03,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 phishscore=0 mlxlogscore=933 adultscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304260148 X-Proofpoint-GUID: QfGvQnN1CUrTTsoTYA2ChFbpzfNp5H01 X-Proofpoint-ORIG-GUID: QfGvQnN1CUrTTsoTYA2ChFbpzfNp5H01 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3033440015 X-Stat-Signature: 5d6rtcejcnkcm1mgksowi4uaobrtc5nc X-HE-Tag: 1682527828-552433 X-HE-Meta: U2FsdGVkX180UEidSfAnFQnw53dGkVWPyKcbUo+OcgA33dgm150tHXneYyGT3n8ZRz/ZzWcSJNWyb6pmY8JdeIUHUgOSXQ2LGJGwlhMaez2Yfwo8ZNEGundyWJcDlANPjaJ+9C1CJQv2YxJkerYX6Nx+S16ZeSdhw9zOgMb6ze5rci/RWtjCdfho1wcRCBQw+J47eny+aMz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P5DsSNB5FAJ2uHVvkF3qX2vkt3ZtuTdxniHGmxsoHlrWhjtIX6TrO7D//T1wc2LFvD/DdiyyqO2L94mlBSyQXcjxkQxyhrDJKGvABQ7OW6lkg0h4w7unjnspQfkm1BmoBxtMVRDQkg== 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: When a process passes MAP_SHARED_PT flag to mmap(), create a new mm struct to hold the shareable page table entries for the newly mapped region. This new mm is not associated with a task. Its lifetime is until the last shared mapping is deleted. This patch also adds a new pointer "ptshare_data" to struct address_space which points to the data structure that will contain pointer to this newly created mm along with properties of the shared mapping. ptshare_data maintains a refcount for the shared mapping so that it can be cleaned up upon last unmap. Signed-off-by: Khalid Aziz Suggested-by: Matthew Wilcox (Oracle) --- include/linux/fs.h | 2 + mm/Makefile | 2 +- mm/internal.h | 14 +++++ mm/mmap.c | 72 ++++++++++++++++++++++++++ mm/ptshare.c | 126 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 mm/ptshare.c diff --git a/include/linux/fs.h b/include/linux/fs.h index c85916e9f7db..db8d3257c712 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -422,6 +422,7 @@ extern const struct address_space_operations empty_aops; * @private_lock: For use by the owner of the address_space. * @private_list: For use by the owner of the address_space. * @private_data: For use by the owner of the address_space. + * @ptshare_data: For shared page table use */ struct address_space { struct inode *host; @@ -443,6 +444,7 @@ struct address_space { spinlock_t private_lock; struct list_head private_list; void *private_data; + void *ptshare_data; } __attribute__((aligned(sizeof(long)))) __randomize_layout; /* * On most architectures that alignment is already the case; but diff --git a/mm/Makefile b/mm/Makefile index 8e105e5b3e29..d9bb14fdf220 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -40,7 +40,7 @@ mmu-y := nommu.o mmu-$(CONFIG_MMU) := highmem.o memory.o mincore.o \ mlock.o mmap.o mmu_gather.o mprotect.o mremap.o \ msync.o page_vma_mapped.o pagewalk.o \ - pgtable-generic.o rmap.o vmalloc.o + pgtable-generic.o rmap.o vmalloc.o ptshare.o ifdef CONFIG_CROSS_MEMORY_ATTACH diff --git a/mm/internal.h b/mm/internal.h index 4d60d2d5fe19..3efb8738e26f 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1047,4 +1047,18 @@ static inline bool vma_is_shared(const struct vm_area_struct *vma) { return vma->vm_flags & VM_SHARED_PT; } + +/* + * mm/ptshare.c + */ +struct ptshare_data { + struct mm_struct *mm; + refcount_t refcnt; + unsigned long start; + unsigned long size; + unsigned long mode; +}; +int ptshare_new_mm(struct file *file, struct vm_area_struct *vma); +void ptshare_del_mm(struct vm_area_struct *vm); +int ptshare_insert_vma(struct mm_struct *mm, struct vm_area_struct *vma); #endif /* __MM_INTERNAL_H */ diff --git a/mm/mmap.c b/mm/mmap.c index 8b46d465f8d4..c5e9b7f6de90 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1382,6 +1382,60 @@ unsigned long do_mmap(struct file *file, unsigned long addr, ((vm_flags & VM_LOCKED) || (flags & (MAP_POPULATE | MAP_NONBLOCK)) == MAP_POPULATE)) *populate = len; + +#if VM_SHARED_PT + /* + * Check if this mapping is a candidate for page table sharing + * at PMD level. It is if following conditions hold: + * - It is not anonymous mapping + * - It is not hugetlbfs mapping (for now) + * - flags conatins MAP_SHARED or MAP_SHARED_VALIDATE and + * MAP_SHARED_PT + * - Start address is aligned to PMD size + * - Mapping size is a multiple of PMD size + */ + if (ptshare && file && !is_file_hugepages(file)) { + struct vm_area_struct *vma; + + vma = find_vma(mm, addr); + if (!((vma->vm_start | vma->vm_end) & (PMD_SIZE - 1))) { + struct ptshare_data *info = file->f_mapping->ptshare_data; + /* + * If this mapping has not been set up for page table + * sharing yet, do so by creating a new mm to hold the + * shared page tables for this mapping + */ + if (info == NULL) { + int ret; + + ret = ptshare_new_mm(file, vma); + if (ret < 0) + return ret; + + info = file->f_mapping->ptshare_data; + ret = ptshare_insert_vma(info->mm, vma); + if (ret < 0) + addr = ret; + else + vm_flags_set(vma, VM_SHARED_PT); + } else { + /* + * Page tables will be shared only if the + * file is mapped in with the same permissions + * across all mappers with same starting + * address and size + */ + if (((prot & info->mode) == info->mode) && + (addr == info->start) && + (len == info->size)) { + vm_flags_set(vma, VM_SHARED_PT); + refcount_inc(&info->refcnt); + } + } + } + } +#endif + return addr; } @@ -2495,6 +2549,22 @@ int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm, if (end == start) return -EINVAL; + /* + * Check if this vma uses shared page tables + */ + vma = find_vma_intersection(mm, start, end); + if (vma && unlikely(vma_is_shared(vma))) { + struct ptshare_data *info = NULL; + + if (vma->vm_file && vma->vm_file->f_mapping) + info = vma->vm_file->f_mapping->ptshare_data; + /* Don't allow partial munmaps */ + if (info && ((start != info->start) || (len != info->size))) + return -EINVAL; + ptshare_del_mm(vma); + } + + /* arch_unmap() might do unmaps itself. */ arch_unmap(mm, start, end); @@ -2664,6 +2734,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, } } + if (vm_flags & VM_SHARED_PT) + vm_flags_set(vma, VM_SHARED_PT); vm_flags = vma->vm_flags; } else if (vm_flags & VM_SHARED) { error = shmem_zero_setup(vma); diff --git a/mm/ptshare.c b/mm/ptshare.c new file mode 100644 index 000000000000..f6784268958c --- /dev/null +++ b/mm/ptshare.c @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Share page table entries when possible to reduce the amount of extra + * memory consumed by page tables + * + * Copyright (C) 2022 Oracle Corp. All rights reserved. + * Authors: Khalid Aziz + * Matthew Wilcox + */ + +#include +#include +#include +#include "internal.h" + +/* + * Create a new mm struct that will hold the shared PTEs. Pointer to + * this new mm is stored in the data structure ptshare_data which also + * includes a refcount for any current references to PTEs in this new + * mm. This refcount is used to determine when the mm struct for shared + * PTEs can be deleted. + */ +int +ptshare_new_mm(struct file *file, struct vm_area_struct *vma) +{ + struct mm_struct *new_mm; + struct ptshare_data *info = NULL; + int retval = 0; + unsigned long start = vma->vm_start; + unsigned long len = vma->vm_end - vma->vm_start; + + new_mm = mm_alloc(); + if (!new_mm) { + retval = -ENOMEM; + goto err_free; + } + new_mm->mmap_base = start; + new_mm->task_size = len; + if (!new_mm->task_size) + new_mm->task_size--; + + info = kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) { + retval = -ENOMEM; + goto err_free; + } + info->mm = new_mm; + info->start = start; + info->size = len; + refcount_set(&info->refcnt, 1); + file->f_mapping->ptshare_data = info; + + return retval; + +err_free: + if (new_mm) + mmput(new_mm); + kfree(info); + return retval; +} + +/* + * insert vma into mm holding shared page tables + */ +int +ptshare_insert_vma(struct mm_struct *mm, struct vm_area_struct *vma) +{ + struct vm_area_struct *new_vma; + int err = 0; + + new_vma = vm_area_dup(vma); + if (!new_vma) + return -ENOMEM; + + new_vma->vm_file = NULL; + /* + * This new vma belongs to host mm, so clear the VM_SHARED_PT + * flag on this so we know this is the host vma when we clean + * up page tables. Do not use THP for page table shared regions + */ + vm_flags_clear(new_vma, (VM_SHARED | VM_SHARED_PT)); + vm_flags_set(new_vma, VM_NOHUGEPAGE); + new_vma->vm_mm = mm; + + err = insert_vm_struct(mm, new_vma); + if (err) + return -ENOMEM; + + return err; +} + +/* + * Free the mm struct created to hold shared PTEs and associated data + * structures + */ +static inline void +free_ptshare_mm(struct ptshare_data *info) +{ + mmput(info->mm); + kfree(info); +} + +/* + * This function is called when a reference to the shared PTEs in mm + * struct is dropped. It updates refcount and checks to see if last + * reference to the mm struct holding shared PTEs has been dropped. If + * so, it cleans up the mm struct and associated data structures + */ +void +ptshare_del_mm(struct vm_area_struct *vma) +{ + struct ptshare_data *info; + struct file *file = vma->vm_file; + + if (!file || (!file->f_mapping)) + return; + info = file->f_mapping->ptshare_data; + WARN_ON(!info); + if (!info) + return; + + if (refcount_dec_and_test(&info->refcnt)) { + free_ptshare_mm(info); + file->f_mapping->ptshare_data = NULL; + } +} From patchwork Wed Apr 26 16:49:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 13224767 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 BC72CC77B78 for ; Wed, 26 Apr 2023 16:50:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5AB206B0101; Wed, 26 Apr 2023 12:50:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5343F6B0102; Wed, 26 Apr 2023 12:50:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3864B6B0103; Wed, 26 Apr 2023 12:50:37 -0400 (EDT) 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 25C846B0101 for ; Wed, 26 Apr 2023 12:50:37 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E7EFF160324 for ; Wed, 26 Apr 2023 16:50:36 +0000 (UTC) X-FDA: 80724130872.16.2C84257 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf08.hostedemail.com (Postfix) with ESMTP id 50F8916000B for ; Wed, 26 Apr 2023 16:50:33 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=JCV9Qq1P; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=C1RkdcZ1; spf=pass (imf08.hostedemail.com: domain of khalid.aziz@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=khalid.aziz@oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=none) header.from=oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682527833; 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=Edtv/rXrLh+RAvkBVKVzY+P/b5NeCvWwYrh6g8zNRzA=; b=dGO5OKterKFO2TYAeyuJbYHcGiPob/xwoXFp+JdSPwHBaqMeobPGOLXjIu3mihi/0wyuqQ 01YE+WsB1NI/pRdcNiWiVttMfUf4BjyAQAmNzz/QSiJG7+fEL6UAH+fQmxNHKV4c8wp8cr oSYEgJeHNHDUwWKkm/i9m2ZQmAyjFik= ARC-Authentication-Results: i=2; imf08.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b=JCV9Qq1P; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=C1RkdcZ1; spf=pass (imf08.hostedemail.com: domain of khalid.aziz@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=khalid.aziz@oracle.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=none) header.from=oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1682527833; a=rsa-sha256; cv=pass; b=SUdiwTtRwU3ufSZwq1vASIRAFLy5HEZEOOQVN+iAccF0heP3ZtzyKl6ZviPqxTnGAGAGT4 CmCgfQiGL1dKKQ/NpseB85dna3KfcyP8lu2ifOp/meAXtmAp5hgLTTWtdGOGt6guqfC7nQ Znh0Q2XOQSR0KzM5QSiKfbBXx2P6Fp4= Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33QEiVjL023324; Wed, 26 Apr 2023 16:50:09 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-2023-03-30; bh=Edtv/rXrLh+RAvkBVKVzY+P/b5NeCvWwYrh6g8zNRzA=; b=JCV9Qq1P25GXfMMotXyEYJB8t/PKsrYZcBtFYw4ou4ExrS/KW792k7+fuFX7O6L6m0Om TfRUj+ZiGqG/shJOIRom5va//tnsbDZkHWCrto7pMUdpb29f0gBwlPRBkwZPMqUMgb1O a1UaTmeXJdHcpyHVzV7DGP3p53DpPte+nAB8rurx/xn3CzF/ZB/6mGzl2pbzlD7Sfxg3 Ote9nR6KfSjOplddXTLomuQMZVe7TbBXutlUThARguS+tb/cknZezOnDN6MOLZNncOUD McyKa2cOY0IOldPjvMInI2mm41/GFfVqgHKuXepxe4Y8MMdv8+0wg3Nbkk9cpZckDBg3 9w== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3q466222sq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Apr 2023 16:50:09 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33QFfqVM032877; Wed, 26 Apr 2023 16:50:08 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2042.outbound.protection.outlook.com [104.47.57.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3q4618dqt0-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Apr 2023 16:50:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dYSyv1rLsAn1vstsYdXPlvQv9fBdduLsZYebQZTyQtseC9rso0RAPPWoFa7R4NOHok9JMOcAerk29Q7vrFo0xzKeAkUWDXcOHgmIQ/Y1NvZeEgFB0mCscNJq8OHQqBVmVx7dmcZBmzk+nvycFWIDx61IJ47W4urxwmYMSDXXJbnG1xDQFr2HeBb0zNS3NT0AdaBO5QM7s75Orl+aL0CzZCq62u6qhJwo31KS1saM/4KasekTykbds7h/FAl/qQRzhLl+omAnM9ntop/Lka11+6uyOX59kMKGUtqwB6K8rmk3Snpk2yTcXCYXix9Z5gdh1xGLs+vGKXeDOE+XsvK44g== 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=Edtv/rXrLh+RAvkBVKVzY+P/b5NeCvWwYrh6g8zNRzA=; b=lLKN1nrUJZox0qbgV/UX59cVN5LSx6+y5wQXYu2MO/78toIOeRPj6d/VpufymGiPF2zXQ0JTMrS89u4FMb9KXYAWOqHPEaM25QzU/60VmRz3zH7gQPdQXQMbvFNeDLueUB1PGG41NhALBNkfEgkOUwo5ub3zmarlhOMSVB6gVqdG4/fO9C5qdusxJAKO012CTCcOOcFqpWfExlJtU9r1428/qXRC2lX9v4yec9bxbAqIJhxUdt7Gb+3nQN52Wk6MUDkJPk5EJJPLJ2P3Pv2zLXeogkaMfB5JUcOWqD+aEVZA8T+ga4WT2UJ78CQ6HpiJWGnDGYxzEqcuWLR0RXwuMg== 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=Edtv/rXrLh+RAvkBVKVzY+P/b5NeCvWwYrh6g8zNRzA=; b=C1RkdcZ1Yqal+dDCB/o5M9vEIIxDLmIIxlYLNqitPC0rQcNGwEZmHiMV2xM0NTDX6IhApXEQHc0RCaa1NC8HhzbRIQtWMgZowPLORStw9/InvEqsrfRG9uG8yIre3kGVjAu8Q5IS8XkPWU81UzJM8V6t0JnwEPVauSn+9r8ay+w= Received: from CH3PR10MB6810.namprd10.prod.outlook.com (2603:10b6:610:140::15) by IA0PR10MB6913.namprd10.prod.outlook.com (2603:10b6:208:433::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.21; Wed, 26 Apr 2023 16:50:04 +0000 Received: from CH3PR10MB6810.namprd10.prod.outlook.com ([fe80::ba49:e5dd:6a80:37ae]) by CH3PR10MB6810.namprd10.prod.outlook.com ([fe80::ba49:e5dd:6a80:37ae%5]) with mapi id 15.20.6340.021; Wed, 26 Apr 2023 16:50:04 +0000 From: Khalid Aziz To: akpm@linux-foundation.org, willy@infradead.org, markhemm@googlemail.com, viro@zeniv.linux.org.uk, david@redhat.com, mike.kravetz@oracle.com Cc: Khalid Aziz , andreyknvl@gmail.com, dave.hansen@intel.com, luto@kernel.org, brauner@kernel.org, arnd@arndb.de, ebiederm@xmission.com, catalin.marinas@arm.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mhiramat@kernel.org, rostedt@goodmis.org, vasily.averin@linux.dev, xhao@linux.alibaba.com, pcc@google.com, neilb@suse.de, maz@kernel.org Subject: [PATCH RFC v2 4/4] mm/ptshare: Add page fault handling for page table shared regions Date: Wed, 26 Apr 2023 10:49:51 -0600 Message-Id: <9edffd2a12a049a42d9a2c216e3f999aae7e65a4.1682453344.git.khalid.aziz@oracle.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: References: X-ClientProxiedBy: SN6PR05CA0025.namprd05.prod.outlook.com (2603:10b6:805:de::38) To CH3PR10MB6810.namprd10.prod.outlook.com (2603:10b6:610:140::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR10MB6810:EE_|IA0PR10MB6913:EE_ X-MS-Office365-Filtering-Correlation-Id: 25d7728f-6416-4b0e-993c-08db467648ac X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SlXtSbuCvg3oE1KP4T5XlxTpikrTsx5uosMfDbpWDOjrs2PVBEk3LOhAf+df6SMPGQft3qDskPVV8d6Jrw3Xx8Q7Cdx0gSIaWesuVBpuB1c8wkMEu4Xx+CqB1BodI8VG3FH/1bkFz8zDmi8cezBTyzfMm0Bv3+etWK2B2LJpXWLZLpUtvNhVB3K2XYKmbN7jEhV553vtaN3HbaKFjVbdaew+ZSk8VBbtb6iolQgtOT2Sn3hu1wVlwT997e3YJmn29MWLintjcdqWzlZWa3iTdlNdKztK7ZtvusELt5D+8L3zJBFK3FEmvE/5A4peCie6wh5ugN9myR7HvTVzeqrR/LaGMXAZjJds7n+reEYl6Rly5Mp+xTnySsz5nWQ52q3FSDeYDlOhHtoeTjiisxlPzhMssw7JgMk9K4zVxoJPLEPagmX/srqMr54dzucs2jW1zd4XIpPMYrNpp1ZwOAjTLdxeGxxPY3a7fmb2QPnbg/5R+lulFmGBd7SMWF3U8lWbX+zYv4KhSekCrSW1FDmXNonqidGKj6j06z6NARL53fjPZkovaXJAqRQ+nvho/NwV X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH3PR10MB6810.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(366004)(39860400002)(376002)(136003)(396003)(346002)(451199021)(6666004)(478600001)(83380400001)(2616005)(6506007)(186003)(36756003)(26005)(6512007)(38100700002)(86362001)(6486002)(41300700001)(316002)(66556008)(66946007)(66476007)(7416002)(4326008)(6636002)(2906002)(30864003)(44832011)(8676002)(8936002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dN0+s8UPOkkdwjUbnryl58VNinOjU2g29ZxoPPRStJTd/Uh/Ku5+bUOc9pPvjXZaMFjvNdTb6wOjzgUNGjwbw1WtdwNg1FuiIZP6p7o+4R87/DyeYOxW5xy2dEmaOZ45UXibM/rjH0Dby6JSN3/Eqgf2ja7hoJqZS6bbaDLunV49E1B8MOSW61NQFafTwIKgRDGvmd2DHlBlwp+qMwwR01oPEHw0HZaTMndYmrMLAaepuHALVB5B5FgKl6sMGLEFQUM0c90unxi+Wmrf8Okj4m/dIF6kp8UdJFdBmmV4R33T3mmrIqwWeYZerk/gKn3mAevMwHofnNWh92/KwJhV60ajOjr8fhxq/ajcjJW1vq7W/UJcODWBRGw2FsbbXu71HO3A1spdYtMRC8+KO1DLk7rISeug/vk4dMxhT9A/t3xdl/ZEZF3ILG6UjAqLzaLg7MMXajgEbfe0q1bdPMFpKTFkfal+augI3XPpBpOUc1eq9471zdvmDZuYBRMgGLNlYPM/SRekB4HCW+IbCrgoAAqYAoLfEn12jEGs7eeM/+Uj8VnPG3KpgwTx986MFyzxoJFge7VAE5MPQtEaAxTzavIFm3PaB7SwCLj0eCJJiTtVyMtLdUop0uXQ+JJ/geYmxa5Vgttll+yELWNH0Jfx1MfX8vm4CLYRj67fr66vo/QM8VBL+zBH6luVCMdQXXAfdxMd/DbwgMj1+BqGm4yTGfIh1VwN+ZlKSfs/4XNsSP06wt16Cg5IIwbEEws1XsLvevaZuliv8vTaq680Dt/a1lCASvkjwxzxo04c39XDINqOqRAdrZaiQMpFrxajw6oTTto0bfmt6CIDeju7jUE24drcK9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: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 25d7728f-6416-4b0e-993c-08db467648ac X-MS-Exchange-CrossTenant-AuthSource: CH3PR10MB6810.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2023 16:50:04.5724 (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: uDEt9OqIUnFU9nE0b3x5Cn8ENbel0y8E16/M/aGd1xQhIxv8RKbEwQ+Nkh3O74C6UnVsejjcO/f8LxXFdUZuUw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB6913 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-26_08,2023-04-26_03,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304260148 X-Proofpoint-ORIG-GUID: r9sQ-rPi09Y3_H-iTY4u9aOCzyz8DFKw X-Proofpoint-GUID: r9sQ-rPi09Y3_H-iTY4u9aOCzyz8DFKw X-Rspamd-Queue-Id: 50F8916000B X-Stat-Signature: 8518n71r9mydnbuqifxh6sdgywcfspue X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1682527833-836012 X-HE-Meta: U2FsdGVkX1/YzL/Eb5gB+aQhZ8SfMhGXkHkKc67e1KqhukvfsMvxkrFjgftUnv3NVrPsLtJbUDdYXQ+LISmrt1BBDnHp//9RN3mFyY+LelYGjscBs/Z0cth3gwvjrZ560wuAUB7T7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e1Lyg2lZad29X3R4BGhwCN+4JO+3MxKFEpUh+4M2E8c/RoqVSAdgvcUYmTpAjfe47TTgmob6njKDkoAzj4Vr3b70kMcgOU9jfPQLvHfSNQ8YoE16feMESmGadYS49gs9sXKF4r9qZFAY69eN5VzEUOSxc+mpxQHKkYo61AvcV5f+ME0dfW5Ar48+HGNml2nqqCXUy5s5EkL0FzLgA0MdQ== 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: Add support for creating a new set of shared page tables in a new mm_struct upon mmap of an region that can potentially share page tables. Add page fault handling for this now shared region. Modify free_pgtables path to make sure page tables in the shared regions are kept intact when a process using page table region exits and there are other mappers for the shared region. Clean up mm_struct holding shared page tables when the last process sharing the region exits. Signed-off-by: Khalid Aziz Signed-off-by: Matthew Wilcox (Oracle) --- mm/internal.h | 2 + mm/memory.c | 105 ++++++++++++++++++++++++++++++------ mm/ptshare.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 232 insertions(+), 18 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 3efb8738e26f..924065f721fe 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1061,4 +1061,6 @@ struct ptshare_data { int ptshare_new_mm(struct file *file, struct vm_area_struct *vma); void ptshare_del_mm(struct vm_area_struct *vm); int ptshare_insert_vma(struct mm_struct *mm, struct vm_area_struct *vma); +extern vm_fault_t find_shared_vma(struct vm_area_struct **vmap, + unsigned long *addrp, unsigned int flags); #endif /* __MM_INTERNAL_H */ diff --git a/mm/memory.c b/mm/memory.c index 01a23ad48a04..c67318ffd001 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -172,17 +172,28 @@ void mm_trace_rss_stat(struct mm_struct *mm, int member) * has been handled earlier when unmapping all the memory regions. */ static void free_pte_range(struct mmu_gather *tlb, pmd_t *pmd, - unsigned long addr) + unsigned long addr, bool shared_pte) { pgtable_t token = pmd_pgtable(*pmd); pmd_clear(pmd); + /* + * if this address range shares page tables with other processes, + * do not release pte pages. Those pages will be released when + * host mm that hosts these pte pages is released + */ + if (shared_pte) { + tlb_flush_pmd_range(tlb, addr, PAGE_SIZE); + tlb->freed_tables = 1; + return; + } pte_free_tlb(tlb, token, addr); mm_dec_nr_ptes(tlb->mm); } static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud, unsigned long addr, unsigned long end, - unsigned long floor, unsigned long ceiling) + unsigned long floor, unsigned long ceiling, + bool shared_pte) { pmd_t *pmd; unsigned long next; @@ -194,7 +205,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud, next = pmd_addr_end(addr, end); if (pmd_none_or_clear_bad(pmd)) continue; - free_pte_range(tlb, pmd, addr); + free_pte_range(tlb, pmd, addr, shared_pte); } while (pmd++, addr = next, addr != end); start &= PUD_MASK; @@ -210,13 +221,19 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud, pmd = pmd_offset(pud, start); pud_clear(pud); - pmd_free_tlb(tlb, pmd, start); - mm_dec_nr_pmds(tlb->mm); + if (shared_pte) { + tlb_flush_pud_range(tlb, start, PAGE_SIZE); + tlb->freed_tables = 1; + } else { + pmd_free_tlb(tlb, pmd, start); + mm_dec_nr_pmds(tlb->mm); + } } static inline void free_pud_range(struct mmu_gather *tlb, p4d_t *p4d, unsigned long addr, unsigned long end, - unsigned long floor, unsigned long ceiling) + unsigned long floor, unsigned long ceiling, + bool shared_pte) { pud_t *pud; unsigned long next; @@ -228,7 +245,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, p4d_t *p4d, next = pud_addr_end(addr, end); if (pud_none_or_clear_bad(pud)) continue; - free_pmd_range(tlb, pud, addr, next, floor, ceiling); + free_pmd_range(tlb, pud, addr, next, floor, ceiling, + shared_pte); } while (pud++, addr = next, addr != end); start &= P4D_MASK; @@ -250,7 +268,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, p4d_t *p4d, static inline void free_p4d_range(struct mmu_gather *tlb, pgd_t *pgd, unsigned long addr, unsigned long end, - unsigned long floor, unsigned long ceiling) + unsigned long floor, unsigned long ceiling, + bool shared_pte) { p4d_t *p4d; unsigned long next; @@ -262,7 +281,8 @@ static inline void free_p4d_range(struct mmu_gather *tlb, pgd_t *pgd, next = p4d_addr_end(addr, end); if (p4d_none_or_clear_bad(p4d)) continue; - free_pud_range(tlb, p4d, addr, next, floor, ceiling); + free_pud_range(tlb, p4d, addr, next, floor, ceiling, + shared_pte); } while (p4d++, addr = next, addr != end); start &= PGDIR_MASK; @@ -284,9 +304,10 @@ static inline void free_p4d_range(struct mmu_gather *tlb, pgd_t *pgd, /* * This function frees user-level page tables of a process. */ -void free_pgd_range(struct mmu_gather *tlb, +static void _free_pgd_range(struct mmu_gather *tlb, unsigned long addr, unsigned long end, - unsigned long floor, unsigned long ceiling) + unsigned long floor, unsigned long ceiling, + bool shared_pte) { pgd_t *pgd; unsigned long next; @@ -342,10 +363,18 @@ void free_pgd_range(struct mmu_gather *tlb, next = pgd_addr_end(addr, end); if (pgd_none_or_clear_bad(pgd)) continue; - free_p4d_range(tlb, pgd, addr, next, floor, ceiling); + free_p4d_range(tlb, pgd, addr, next, floor, ceiling, + shared_pte); } while (pgd++, addr = next, addr != end); } +void free_pgd_range(struct mmu_gather *tlb, + unsigned long addr, unsigned long end, + unsigned long floor, unsigned long ceiling) +{ + _free_pgd_range(tlb, addr, end, floor, ceiling, false); +} + void free_pgtables(struct mmu_gather *tlb, struct maple_tree *mt, struct vm_area_struct *vma, unsigned long floor, unsigned long ceiling) @@ -375,16 +404,20 @@ void free_pgtables(struct mmu_gather *tlb, struct maple_tree *mt, } else { /* * Optimization: gather nearby vmas into one call down + * but make sure vmas not sharing page tables do + * not get combined with vmas sharing page tables */ while (next && next->vm_start <= vma->vm_end + PMD_SIZE - && !is_vm_hugetlb_page(next)) { + && !is_vm_hugetlb_page(next) + && (vma_is_shared(next) == vma_is_shared(vma))) { vma = next; next = mas_find(&mas, ceiling - 1); unlink_anon_vmas(vma); unlink_file_vma(vma); } - free_pgd_range(tlb, addr, vma->vm_end, - floor, next ? next->vm_start : ceiling); + _free_pgd_range(tlb, addr, vma->vm_end, + floor, next ? next->vm_start : ceiling, + vma_is_shared(vma)); } vma = next; } while (vma); @@ -5181,6 +5214,8 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address, unsigned int flags, struct pt_regs *regs) { vm_fault_t ret; + bool shared = false; + struct mm_struct *orig_mm; __set_current_state(TASK_RUNNING); @@ -5191,6 +5226,16 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address, if (ret) return ret; + orig_mm = vma->vm_mm; + if (unlikely(vma_is_shared(vma))) { + ret = find_shared_vma(&vma, &address, flags); + if (ret) + return ret; + if (!vma) + return VM_FAULT_SIGSEGV; + shared = true; + } + if (!arch_vma_access_permitted(vma, flags & FAULT_FLAG_WRITE, flags & FAULT_FLAG_INSTRUCTION, flags & FAULT_FLAG_REMOTE)) @@ -5212,6 +5257,36 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address, lru_gen_exit_fault(); + /* + * Release the read lock on shared VMA's parent mm unless + * __handle_mm_fault released the lock already. + * __handle_mm_fault sets VM_FAULT_RETRY in return value if + * it released mmap lock. If lock was released, that implies + * the lock would have been released on task's original mm if + * this were not a shared PTE vma. To keep lock state consistent, + * make sure to release the lock on task's original mm + */ + if (shared) { + int release_mmlock = 1; + + if (!(ret & VM_FAULT_RETRY)) { + mmap_read_unlock(vma->vm_mm); + release_mmlock = 0; + } else if ((flags & FAULT_FLAG_ALLOW_RETRY) && + (flags & FAULT_FLAG_RETRY_NOWAIT)) { + mmap_read_unlock(vma->vm_mm); + release_mmlock = 0; + } + + /* + * Reset guest vma pointers that were set up in + * find_shared_vma() to process this fault. + */ + vma->vm_mm = orig_mm; + if (release_mmlock) + mmap_read_unlock(orig_mm); + } + if (flags & FAULT_FLAG_USER) { mem_cgroup_exit_user_fault(); /* diff --git a/mm/ptshare.c b/mm/ptshare.c index f6784268958c..e0991a877355 100644 --- a/mm/ptshare.c +++ b/mm/ptshare.c @@ -13,6 +13,136 @@ #include #include "internal.h" +/* + */ +static pmd_t +*get_pmd(struct mm_struct *mm, unsigned long addr) +{ + pgd_t *pgd; + p4d_t *p4d; + pud_t *pud; + pmd_t *pmd; + + pgd = pgd_offset(mm, addr); + if (pgd_none(*pgd)) + return NULL; + + p4d = p4d_offset(pgd, addr); + if (p4d_none(*p4d)) { + p4d = p4d_alloc(mm, pgd, addr); + if (!p4d) + return NULL; + } + + pud = pud_offset(p4d, addr); + if (pud_none(*pud)) { + pud = pud_alloc(mm, p4d, addr); + if (!pud) + return NULL; + } + + pmd = pmd_offset(pud, addr); + if (pmd_none(*pmd)) { + pmd = pmd_alloc(mm, pud, addr); + if (!pmd) + return NULL; + } + + return pmd; +} + +/* + * Find the shared pmd entries in host mm struct and install them into + * guest page tables. + */ +static int +ptshare_copy_pmd(struct mm_struct *host_mm, struct mm_struct *guest_mm, + struct vm_area_struct *vma, unsigned long addr) +{ + pgd_t *guest_pgd; + p4d_t *guest_p4d; + pud_t *guest_pud; + pmd_t *host_pmd; + spinlock_t *host_ptl, *guest_ptl; + + guest_pgd = pgd_offset(guest_mm, addr); + guest_p4d = p4d_offset(guest_pgd, addr); + if (p4d_none(*guest_p4d)) { + guest_p4d = p4d_alloc(guest_mm, guest_pgd, addr); + if (!guest_p4d) + return 1; + } + + guest_pud = pud_offset(guest_p4d, addr); + if (pud_none(*guest_pud)) { + host_pmd = get_pmd(host_mm, addr); + if (!host_pmd) + return 1; + + get_page(virt_to_page(host_pmd)); + host_ptl = pmd_lockptr(host_mm, host_pmd); + guest_ptl = pud_lockptr(guest_mm, guest_pud); + spin_lock(host_ptl); + spin_lock(guest_ptl); + pud_populate(guest_mm, guest_pud, + (pmd_t *)((unsigned long)host_pmd & PAGE_MASK)); + put_page(virt_to_page(host_pmd)); + spin_unlock(guest_ptl); + spin_unlock(host_ptl); + } + + return 0; +} + +/* + * Find the shared page tables in hosting mm struct and install those in + * the guest mm struct + */ +vm_fault_t +find_shared_vma(struct vm_area_struct **vmap, unsigned long *addrp, + unsigned int flags) +{ + struct ptshare_data *info; + struct mm_struct *host_mm; + struct vm_area_struct *host_vma, *guest_vma = *vmap; + unsigned long host_addr; + pmd_t *guest_pmd, *host_pmd; + + if ((!guest_vma->vm_file) || (!guest_vma->vm_file->f_mapping)) + return 0; + info = guest_vma->vm_file->f_mapping->ptshare_data; + if (!info) { + pr_warn("VM_SHARED_PT vma with NULL ptshare_data"); + dump_stack_print_info(KERN_WARNING); + return 0; + } + host_mm = info->mm; + + mmap_read_lock(host_mm); + host_addr = *addrp - guest_vma->vm_start + host_mm->mmap_base; + host_pmd = get_pmd(host_mm, host_addr); + guest_pmd = get_pmd(guest_vma->vm_mm, *addrp); + if (!pmd_same(*guest_pmd, *host_pmd)) { + set_pmd(guest_pmd, *host_pmd); + mmap_read_unlock(host_mm); + return VM_FAULT_NOPAGE; + } + + *addrp = host_addr; + host_vma = find_vma(host_mm, host_addr); + if (!host_vma) + return VM_FAULT_SIGSEGV; + + /* + * Point vm_mm for the faulting vma to the mm struct holding shared + * page tables so the fault handling will happen in the right + * shared context + */ + guest_vma->vm_mm = host_mm; + + return 0; +} + /* * Create a new mm struct that will hold the shared PTEs. Pointer to * this new mm is stored in the data structure ptshare_data which also @@ -38,6 +168,7 @@ ptshare_new_mm(struct file *file, struct vm_area_struct *vma) new_mm->task_size = len; if (!new_mm->task_size) new_mm->task_size--; + new_mm->owner = NULL; info = kzalloc(sizeof(*info), GFP_KERNEL); if (!info) { @@ -63,7 +194,7 @@ ptshare_new_mm(struct file *file, struct vm_area_struct *vma) * insert vma into mm holding shared page tables */ int -ptshare_insert_vma(struct mm_struct *mm, struct vm_area_struct *vma) +ptshare_insert_vma(struct mm_struct *host_mm, struct vm_area_struct *vma) { struct vm_area_struct *new_vma; int err = 0; @@ -80,12 +211,18 @@ ptshare_insert_vma(struct mm_struct *mm, struct vm_area_struct *vma) */ vm_flags_clear(new_vma, (VM_SHARED | VM_SHARED_PT)); vm_flags_set(new_vma, VM_NOHUGEPAGE); - new_vma->vm_mm = mm; + new_vma->vm_mm = host_mm; - err = insert_vm_struct(mm, new_vma); + err = insert_vm_struct(host_mm, new_vma); if (err) return -ENOMEM; + /* + * Copy the PMD entries from host mm to guest so they use the + * same PTEs + */ + err = ptshare_copy_pmd(host_mm, vma->vm_mm, vma, vma->vm_start); + return err; }