From patchwork Mon Apr 11 16:05:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 12809398 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 57CE8C433FE for ; Mon, 11 Apr 2022 16:07:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B0DC68D0002; Mon, 11 Apr 2022 12:07:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE3BA8D0001; Mon, 11 Apr 2022 12:07:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 87AA68D0002; Mon, 11 Apr 2022 12:07:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0008.hostedemail.com [216.40.44.8]) by kanga.kvack.org (Postfix) with ESMTP id 56BBA6B007B for ; Mon, 11 Apr 2022 12:07:46 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 18F9D183C8CC2 for ; Mon, 11 Apr 2022 16:07:46 +0000 (UTC) X-FDA: 79345078932.21.517FE26 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf27.hostedemail.com (Postfix) with ESMTP id 5E8794000A for ; Mon, 11 Apr 2022 16:07:45 +0000 (UTC) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23BFdIAp008887; Mon, 11 Apr 2022 16:06:46 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-2021-07-09; bh=8O7VlgVnShUCDAt1+14pi5sT00uA2P8ia3lG+caIJOg=; b=uIBNtoKG9B9LvNJU4riSCIfTIbZHkmjT1PiTvo+B+41YzUWs0NPEzt3kqJ7MNhsdvezA Ryrc5mfE8T+xCQ0rlYmqAvvs8fn7suNFsWAViOW8nsbyWTPzGSodGLVnUw+RQswu25XJ gHpQhy5WZS6YUUuwvUt2cxXeNg6z+hDJgpCOI295813jo7osAT/qx6mBoqWSZUm7jWM2 JRRjHUo71u9CRZ2JdtxU6cSndJmmyB8MokSnmkFfzeAgNKyqmzL8bq3a/LMx92zJZVLR bjsJFbW2ZNAhcJB923p7tN5UP+nAuqHtumppm2RvhzUbfbeFUjRJnC5zkpwxpRYpOlIg Nw== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com with ESMTP id 3fb0x2c71k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:06:45 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23BG1EpC031293; Mon, 11 Apr 2022 16:06:42 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2044.outbound.protection.outlook.com [104.47.66.44]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3fb0k27ns6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:06:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y0l18LhlITNg4e7XDbvCqldBT9Hy1klv8r/7AqSk+Xj7GEHv0zXUpfxmpxY1KHp60sILH3rFqB6srxPXFv2dnycrYToNIcO5pcRczLbFQkGriGWqvNEBQ3vGj6XrEJSyrHOwTKn34SLO3L1GzLGU+MjtEAPR8ub8+mOVndf2XNCNatyMwHWYSoWgF04dPW84skjBgRMvYDp6t/N0f7dmKFxD15XhamM3nn5XJWSXOO9XBAEzftkWB2lzFq2C3ck9BJfppu8RvKkZjoWpgN8FYPjyi5ESuzdhFdSn6WDRt11Q48J7PRIXh2Qd8+vO9j52lSKKAYA79lrQq8jlrmr/1A== 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=8O7VlgVnShUCDAt1+14pi5sT00uA2P8ia3lG+caIJOg=; b=mvwL0RgUVhWWWudT7SY1gBe7C4V/jC0Yty7DtYzJRz2LmWUfjp70lW/sTLECnu6ZmYV1hifC3XBxJwelzma8Cf1dK+XKd7tGK15r2IcDACJHTxvxwwjPgHbix+BnB5v/0bD/O17xePtghGj3W7jIuXLZObFVj8TdBIHgoRfqaWDh8bYm2HfXkucLu3tau8ZrE1IY6H/R76+y8tG8BZaD4seW7QikA/gY1XFOHwedzSQm+Nxp09Wkm1UAhz7MHBtuexYNoQsYQ5DOosPx1k0vnhe/ivw3FHB2ywEbnudVprylu/U+RA/27sjvHy0MS2laIPJ5Cia2BfkNq7m4DZ6Xaw== 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=8O7VlgVnShUCDAt1+14pi5sT00uA2P8ia3lG+caIJOg=; b=MsJ5U+W4PKsN4VaruBZa9B+mJn1d8VIEjAdlRe01qzGswURAcayqsbVC9JlaJpiHan8QcALW084hq4expF+qsUVSkBjD8eTjOv39auadf7JDKXIKEtUkH9D3QPVTWqiXm/GAWVVXkkWBf0EGdLqyysu/TV1Pe/IbtqLRmryiyVA= Received: from BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) by BN7PR10MB2609.namprd10.prod.outlook.com (2603:10b6:406:cd::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Mon, 11 Apr 2022 16:06:39 +0000 Received: from BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40]) by BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40%6]) with mapi id 15.20.5144.029; Mon, 11 Apr 2022 16:06:39 +0000 From: Khalid Aziz To: akpm@linux-foundation.org, willy@infradead.org Cc: Khalid Aziz , aneesh.kumar@linux.ibm.com, arnd@arndb.de, 21cnbao@gmail.com, corbet@lwn.net, dave.hansen@linux.intel.com, david@redhat.com, ebiederm@xmission.com, hagen@jauu.net, jack@suse.cz, keescook@chromium.org, kirill@shutemov.name, kucharsk@gmail.com, linkinjeon@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, longpeng2@huawei.com, luto@kernel.org, markhemm@googlemail.com, pcc@google.com, rppt@kernel.org, sieberf@amazon.com, sjpark@amazon.de, surenb@google.com, tst@schoebel-theuer.de, yzaikin@google.com Subject: [PATCH v1 01/14] mm: Add new system calls mshare, mshare_unlink Date: Mon, 11 Apr 2022 10:05:45 -0600 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-ClientProxiedBy: SJ0P220CA0013.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:41b::20) To BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3f2da999-38b0-4d03-358d-08da1bd54308 X-MS-TrafficTypeDiagnostic: BN7PR10MB2609:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XSysgN23Sd9ZXoHEu7E9Doe/CTQvNfpVd4jXdMTH7HjqgZtwupI8M23mFM0yeVjKoUgt9i2hcGKRaPBvxwATQn9rrJs7hjzkKjOnxO6cQ0FcR1MkEOO79tzsVfM1L4idGY42LDhkpIm/jVoTmfZc9qKeBfHB9LfX08xHldzS4UFd20oKZhhKOZkZvJnao9JcvP2ZlgpeDXGc390/FPmTtmIacKUoWzQrtiii1WdCGpGXoFvImNU6mHCoANmJw3OWPTVFJLO2aDCBlajMqKPIcs49bihWVVvl2Cx/Tku/6H7SjpfyBXL/PssiLL75nLjFWwMOlFkQkDKred+/S0DH4KRFG/3449BXJMd0mkMh6XJ5o22IiFYNVJVGxQsEMZHrzLqmFI3l3FLyA1FnpGMVrIXMKh2d6PriVvPzGKEUbuRyTIFG2JgZTgzZnEF0i1ufyuJuaeYmsawqZQVlBOjU5cmyE+G+byQQvrDVjGT56lv2SV39UROEIkNlExR5qcBzWpF9ch6L4rXVkpu8O8kWk5PlxWrMYO63/RErywAgor81uj0HT4Dv6hpipOrW2P6xSbHVDg7UE9YWYdw2DL0msSE980GS9EYX7HLf/Ac3Uco9r8/rxHXzFVfYHTU2A5drhWp7LTNZ1G7btA9b17URwfL6IerFynaBd7OqR/T0FunU+7vpYAdneWzbEqbqOL/Tf/+++H97ABjQVHRz2NshwA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR10MB3220.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(66476007)(6506007)(6666004)(186003)(316002)(52116002)(66556008)(6512007)(8676002)(2616005)(4326008)(86362001)(5660300002)(44832011)(83380400001)(26005)(66946007)(38100700002)(36756003)(2906002)(7416002)(38350700002)(8936002)(6486002)(508600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: F4epE0EKwuX0ahHJAphOoOgUyz0UcU7zi57ldJQLdM7BbuwXoso9TAjmGPzM+E6eot2hfrgY29OgQpqUbqAVa8yOJCmIvAF8y2TXIMEKSMaZX/gfyIjSHgWNGA3OZTEk5k6liGR5GgICG44UUnnb2sSNUB22xFBsVcrH2XCVM6wNcNZaTBKZNzpgZ4MWdBr5Ry8OFgZisyWndkmECkpGqxqwZlRHmFx5NXj13f2LZPrBPk2aSII0R39TE+OITL2vLJwcxsdwILLuko0Ao3Wo6ugQv2CJUf+JW3l0HkokpYhMJjReBuF9H6ep6Ocjqhj801GbfqBJaaHdDDdeKEaYp07MXNLbvIw0D4En5vK+jZY16QH/xR/NIuVFU2B44ybbZ4BygN8sa94MCRp3SphzPSdQTL8KvgwCrixxfZeAwqHcVMVILn2pKcJmF20IvAcHdW2tKleWmX7XonTlEvDqS//XN22WhKdJJJvOBqDx6KCPS0B9w/xSTJ3MU6diA6QUKuHw4++T7hwto7X7+9w546oCGb300CYSRbsc14sg/vgmlsAq4+IZBoFAubGYOymddKR2ZMqiJ58AgkZhhuY5wvLPuhBku/AsUGL9JFTL6/Ouq/sRFcBmRnETHk9hbLg0Mu/EoJXVYDwyjyEtQcjcG1d+a5uyFcmiun2Kcb556MphI1yNTMMiU2ECNGiXHwTrzFVc9mjSA758ZaMaZCNajE5E6cD4vkvQ0iyzCxi9BrteorGc8NCOp8BTxj8J/FCaeAV+CaGvEFDcdJRzKtFmxlRup+gizJcJ+5EPGAhUDPiFqMslQruRSw1mK2HmJZhgeC38U7BTG9G7Ly0jVcLl+1ZR1GMVTR8lITIqPGPhrp+3sDvNgLvJ0g4naENxoIp/pEAUWtOu/YY9SEqII+M/zm3pMUImH2PJ96FpTYz9/t41zyFAFt4qZTJdOauUGBdqan7gw3nGzYUXrVS9vOmyu7wn3bPdZdZk0mnp/l5nms2PDABbgeSFD7lv5Bonfi+084B/PvEsZD8QBklaYYcPHucP4PbQZamvBYXQYdkwNRBwbZ4vNzMSCGqLO2xM3iijw7EcB7VXE+vK02LVQJYXU4AQAiT1feO+j+2wc53SU7Jbj+Zy7RkcjMeglhSMLxKuD8o1QV9mc1AVllH8Ye3Z2x7/Qf27HSAz21ZwyrUfhzj52crheTJs98Qo2mKgZemx23qJ+DoIm7CY7WftAkdNPHgnVAxR0ZBjFkA10XRln3hMU+Rr1dxm1+cE9mDOWitVOQ59h7pEN0rpruWZjMIyhjai8hNJ0po/agbtdOkwQgQ+S9jA2oomAO9PjRyF0/5t9CCRDgzpTQhJ583/XcAc8XA2vLtoq4f9kVmlmYd51oU8igktjfjlF7fzd47YNkjBwS8mN5fC28Et1QzKtlQWKpizSFZ0BhsQ0+OlgWZ8XeQMt7BiNiye2EW23XkSZv6VfGjJf7JocuJ7oEjt0vuC2d/q8Lt17f/sIMHU+mk3XHYh/YlbpaCwxop0URJcwjch2pHX1lwwpfIoH7NOCiCdg9yNGCtoNFWTRumL0VletndnmYlDA/kZNLtUbi1OQ4MQCEf8UiBOLww9GbCuULVAYn5yuhgg0TiZlcTDuAprt0VQnyPkUMsrIE8X03+/kivok2ZifUZFTDrcUBdgADDuSdLyVy7sQsnz9tof7H9FxiUIALKf4YFCrXlT9mBEr3F3Brt5NcQVPwZmKevO26SNyg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3f2da999-38b0-4d03-358d-08da1bd54308 X-MS-Exchange-CrossTenant-AuthSource: BN8PR10MB3220.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2022 16:06:39.5910 (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: vWVowhsvCgl6ME2e96iKe6Nq1wv2XtWY3WvjxbwvRhBf3dc75glJ6mTQHZ+qMCpew45/dG9yhnr0/lMdl+pk3g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR10MB2609 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.858 definitions=2022-04-11_06:2022-04-11,2022-04-11 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxlogscore=921 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204110089 X-Proofpoint-ORIG-GUID: qSGgYe_4RKjfqPtNaaJAXs4NY_iTb92f X-Proofpoint-GUID: qSGgYe_4RKjfqPtNaaJAXs4NY_iTb92f X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 5E8794000A X-Rspam-User: Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=uIBNtoKG; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=MsJ5U+W4; dmarc=pass (policy=none) header.from=oracle.com; spf=none (imf27.hostedemail.com: domain of khalid.aziz@oracle.com has no SPF policy when checking 205.220.177.32) smtp.mailfrom=khalid.aziz@oracle.com X-Stat-Signature: sy8o3qtaynyfnq5rimcxykdkx6a1a4yt X-HE-Tag: 1649693265-595592 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 two new system calls to support PTE sharing across processes through explicit declarations of shared address space.There is almost no implementation in this patch and it only wires up the system calls for x86_64 only. mshare() returns a file descriptor which does not support any operations yet. Signed-off-by: Khalid Aziz Signed-off-by: Matthew Wilcox (Oracle) --- arch/x86/entry/syscalls/syscall_64.tbl | 2 + include/uapi/asm-generic/unistd.h | 7 ++- mm/Makefile | 2 +- mm/mshare.c | 60 ++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 mm/mshare.c diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl index c84d12608cd2..e6e53b85fea6 100644 --- a/arch/x86/entry/syscalls/syscall_64.tbl +++ b/arch/x86/entry/syscalls/syscall_64.tbl @@ -372,6 +372,8 @@ 448 common process_mrelease sys_process_mrelease 449 common futex_waitv sys_futex_waitv 450 common set_mempolicy_home_node sys_set_mempolicy_home_node +451 common mshare sys_mshare +452 common mshare_unlink sys_mshare_unlink # # Due to a historical design error, certain syscalls are numbered differently diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h index 1c48b0ae3ba3..d546086d0661 100644 --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -886,8 +886,13 @@ __SYSCALL(__NR_futex_waitv, sys_futex_waitv) #define __NR_set_mempolicy_home_node 450 __SYSCALL(__NR_set_mempolicy_home_node, sys_set_mempolicy_home_node) +#define __NR_mshare 451 +__SYSCALL(__NR_mshare, sys_mshare) +#define __NR_mshare_unlink 452 +__SYSCALL(__NR_mshare_unlink, sys_mshare_unlink) + #undef __NR_syscalls -#define __NR_syscalls 451 +#define __NR_syscalls 453 /* * 32 bit systems traditionally used different diff --git a/mm/Makefile b/mm/Makefile index 70d4309c9ce3..70a470b5ebe3 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -37,7 +37,7 @@ CFLAGS_init-mm.o += $(call cc-disable-warning, override-init) CFLAGS_init-mm.o += $(call cc-disable-warning, initializer-overrides) mmu-y := nommu.o -mmu-$(CONFIG_MMU) := highmem.o memory.o mincore.o \ +mmu-$(CONFIG_MMU) := highmem.o memory.o mincore.o mshare.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 diff --git a/mm/mshare.c b/mm/mshare.c new file mode 100644 index 000000000000..436195c0e74e --- /dev/null +++ b/mm/mshare.c @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * mm/mshare.c + * + * Page table sharing code + * + * + * Copyright (C) 2021 Oracle Corp. All rights reserved. + * Authors: Khalid Aziz + * Matthew Wilcox + */ + +#include +#include +#include + +static const struct file_operations mshare_fops = { +}; + +/* + * mshare syscall. Returns a file descriptor + */ +SYSCALL_DEFINE5(mshare, const char *, name, unsigned long, addr, + unsigned long, len, int, oflag, mode_t, mode) +{ + int fd; + + /* + * Address range being shared must be aligned to pgdir + * boundary and its size must be a multiple of pgdir size + */ + if ((addr | len) & (PGDIR_SIZE - 1)) + return -EINVAL; + + /* + * Allocate a file descriptor to return + * + * TODO: This code ignores the object name completely. Add + * support for that + */ + fd = anon_inode_getfd("mshare", &mshare_fops, NULL, O_RDWR); + + return fd; +} + +/* + * mshare_unlink syscall. Close and remove the named mshare'd object + */ +SYSCALL_DEFINE1(mshare_unlink, const char *, name) +{ + int fd; + + /* + * Delete the named object + * + * TODO: Mark mshare'd range for deletion + * + */ + return 0; +} From patchwork Mon Apr 11 16:05:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 12809416 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 2C964C4332F for ; Mon, 11 Apr 2022 16:07:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 03BAD8D0001; Mon, 11 Apr 2022 12:07:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E3C828D0006; Mon, 11 Apr 2022 12:07:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A6CC78D0001; Mon, 11 Apr 2022 12:07:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 7D93F8D0003 for ; Mon, 11 Apr 2022 12:07:48 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5035A21C41 for ; Mon, 11 Apr 2022 16:07:48 +0000 (UTC) X-FDA: 79345079016.19.97ADD97 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf20.hostedemail.com (Postfix) with ESMTP id 6904F1C0003 for ; Mon, 11 Apr 2022 16:07:47 +0000 (UTC) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23BFxoAt032238; Mon, 11 Apr 2022 16:06:51 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-2021-07-09; bh=GSmrmOIC+RpQpEBnSj5ZiND7iNP3pFdaNh8U31N0v44=; b=tPF+oGteSVpzZN9zthVRDT+olgjzOnV5aO3PW0s3PiVf0YQ+2C/k8y0q7Z7N0+t9k9Z6 GLQ6AMkLc9+vZo8tLhwBYqe6To/Q3ss0lj65zc3epiP6mK+TuEE64kIuwbrbK8Ia2MoG cdsz1aLmPllxB5uIuCxbYibiEiRaNBV/oR3AERzbfeFeKdW4wgHp9sQoLYE8iCWDz0zs E5+zuQJuS33nVmxFHjJRfJOXwfkwGAlZnpU6SJa0ifKKqDnByQlJrINm81TX/qla/iBz aGDVJQoez5yJ1tCzSef7EZAibd2QOHRENweko19PjfMr6l7xWlb4x4PMB1kujR3uvNMG ow== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com with ESMTP id 3fb0jd43y5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:06:49 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23BG0N4T016213; Mon, 11 Apr 2022 16:06:47 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2046.outbound.protection.outlook.com [104.47.66.46]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3fck11rwrr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:06:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UdJZ8iOoihbnHK/Nd5hDmhvqBfJryR1zdvsGyqqbKcltYKU9JifVMao7el51nhwB4oiy5AtdbctjLchrlPfIZweBl1F8gzCQK8ChlnIukLrlOtDAsvCZloeBW06oge+ycQ58rpnnMeqxCVxskN3hDIeMM83yy3E2L3mdctoqhZwR3ufhfD5bDE4b9fGSdrwKoEMf7L466J554I55R8u1GQoVWdjKMdVhEDXqbITx5Du3jXBm323ucX4rHZ6NcFbGJ8c4cuKpRjygdjXmevGomt3wNrf7BtoBa7RFzTmz4hk7Ub39RI+2hwoSbu6QdklzNHMK/OxqvAotoG1lmTQNgQ== 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=GSmrmOIC+RpQpEBnSj5ZiND7iNP3pFdaNh8U31N0v44=; b=AXroUSXhDyouIPvqz37l9iXp7NpDSXDCkbISHtbe52RZ5YX6CRTcRNAAYZqXwI2FMGGIaUbtt2ZCGhxh3iNoLwaC/R1bu5e1g/Z5c/Or7mMCERxrJ5fmYo5tUL/g3MuFbXv99wTUemHm2QyJQOUwpxzg5++AW6bBOugN/TxnHBgVCeLdzNo9hTuvXGZ2RsEk3zsKw+azpu+iCVgiT5XdOM++7IF1poOO+NEG7ab26iRRqv9EyQg92/250jArBaeFSTqywIEQZYQa3Lq9cT0bvi8ZKNSU1nQPx0JWBAyOd6JTV+X1UxIoDGQyxHXubUwG/Sa2AoWJH3m4m9/si/vcRQ== 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=GSmrmOIC+RpQpEBnSj5ZiND7iNP3pFdaNh8U31N0v44=; b=SZWLL0lp3aV+uOufk+0rirC7vVE4sr/O+PNhla26+rxurEy6XMWh3IuB/qDN8Tgoo/qZWlyUYBi3izijtfItOBlsqlBER1k/Lp/I43anm/tLzXjp+3yVxkiBNRH0tyrS5tr6zRj2ZJtrO+Yp+ytZUveNAfnrtqUu/2QKTg8shnQ= Received: from BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) by BN7PR10MB2609.namprd10.prod.outlook.com (2603:10b6:406:cd::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Mon, 11 Apr 2022 16:06:44 +0000 Received: from BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40]) by BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40%6]) with mapi id 15.20.5144.029; Mon, 11 Apr 2022 16:06:44 +0000 From: Khalid Aziz To: akpm@linux-foundation.org, willy@infradead.org Cc: Khalid Aziz , aneesh.kumar@linux.ibm.com, arnd@arndb.de, 21cnbao@gmail.com, corbet@lwn.net, dave.hansen@linux.intel.com, david@redhat.com, ebiederm@xmission.com, hagen@jauu.net, jack@suse.cz, keescook@chromium.org, kirill@shutemov.name, kucharsk@gmail.com, linkinjeon@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, longpeng2@huawei.com, luto@kernel.org, markhemm@googlemail.com, pcc@google.com, rppt@kernel.org, sieberf@amazon.com, sjpark@amazon.de, surenb@google.com, tst@schoebel-theuer.de, yzaikin@google.com Subject: [PATCH v1 02/14] mm/mshare: Add msharefs filesystem Date: Mon, 11 Apr 2022 10:05:46 -0600 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-ClientProxiedBy: SJ0P220CA0013.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:41b::20) To BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c0c8ef1d-5011-4a5f-f2b3-08da1bd545fb X-MS-TrafficTypeDiagnostic: BN7PR10MB2609:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cAm4x1Tv54TN+9wwWQ+uYH7x8nV68QhoX4eI8CY+/9+1s7CvEDmnnbgVVSy//vpyQcLPh+Qm+BZASoIOQCwdzJiClTkXfSgTsEyvLj56vc9qzdYNDyUS5UW8SSiKYNsyuu8fWBusz9pHW+1V67RjW0V3NJk6Na48DuaFOpuXSAU1r74svktqrIZ9E/XxAuGPpQE2cGODyQv3AQmFdo+P36fyIH9Kfvqjaq5VzbKXCF/DVkBbAuasRFbvSXLocX3iRC83CFfL+fE7ki5I1PaO2UN/xXnm/ZIpfSjPTIuS9EMxN2TvNeq70Kou67fXv8lOSZBEoDIl3nOdB0WTEe2Z5GTxc+G+MAjFAGM/2J3weM6+3D+heHSgmpYyxRGLiTnysN3B9CDePZu705vGrKBBFz207lLIrjUgmX7ZBD6qgzLJmINQpMdj17zTayUh+DcO121a3Q6WzAzPCEKcJjTy0WFdCLn3pMih05c6vzYaI+TofuTo+06txCXN49BWZ09yWOc85Evi2hzrdMPacve8TmCU0p9fTo2aqpo2W0w2asKbyxQk9JJjwQeO8QlMDnftuM3q/wrh8/4DIJy0+TvI5PO6i2WjsjpNA2Z6khAiOUvI/bFRxAha7mvXtN2Cq1vShq6CX+SZLwB6wT82vc8Ly3nQjHf5i14naqwoCYFX1zd8L9VUeR808/vXdT1ummLLgYEkz3xxttnMuObRMT/XuA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR10MB3220.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(66476007)(6506007)(186003)(316002)(52116002)(66556008)(6512007)(8676002)(2616005)(4326008)(86362001)(5660300002)(44832011)(83380400001)(26005)(66946007)(38100700002)(36756003)(2906002)(7416002)(38350700002)(8936002)(6486002)(508600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: E5+GQ+9CD5KechZQWole/xgmLmk3R+xFgkEZ3u13U1GCY7PddoGVDGwUx0GH67ZovVTcL94OIB2cEVVq4QPmCrHXblD9OmtgySYnbYA9wfG9eRN7rB/3HFEzazw/OU3I/XwLpNCZRJ5aJ1xpuXjqRhlbaarZxXkg+OxAbsaWRZ6fl2UfkaR9v6DvgAWyV6dYI5VB9gWPE/Vc3MHtT0MMdC7KBqG9MDPH889i8+lD96iJgMIKf2lB5/j+z5HSRg8TpFan2gR2A2IUkGn5UHvgh/cq8MqZUFPa/KuuIi/eEMWZVbyEbVMGv6u6QJbApGxxviAcn3TTZ4or4pr1WC6+Ckzgiyf5iFE80hElI3CfucY5LKkx8zEhyG0f0L8PxzPlhac9iqIZJ4oHVTJcUUVMyPHwvFzBx6YaqlcayeBujcoizmJb5DSr7YttAhaK4FFWfrAkG07h52NUf1Ddt5V0K44JJTtjaqLC/trW5ErIewig4QxHu3Oyc3LtKicI+3hiLZnET+0TnVZWgHA27XgINQOgTUM9vPrDzbEoYIs/bDqPVaYyON4j0+SofGiBWCNXxyDrABFTzXEhVpsnoHp0pzVgpNBe8oF/sfIHr3hLeWg8RwuUBU683kGs67JPaWCDrRjWJUtxAUKo07XTKiCagfiVbHyDBAwsgS6OFtloK+R8r/aoYeuqalHW2GuKKSNP/axD638GGAefSwDBnWeV+4JtHhv+2wlKwiD+GkQHtPjadpARNGfrXYNhw8VP7rNCu/ZzkUJuJn0ZtXgcxoSAyL5C5BY2RJb/pEEHT+tzyXbKoaP51aeAPMnYgWhGfarckn3+GptOat/R7w5sEoA5zeuvMQDdqRh90wPxGFo+uP4MZMLn+T0ZldPN1h6P43LN2O7l13xF/le0KRSAbaaTJAA3oXUVQ+VNIYMm9cRkxsRwgWkCBmdiOrCcVKlQp4S6BISoFAfnoNrv0DX1ENk2UokeqGudIaN7fMLeDSdczjA5udZUIM1JHxbawNIfX7WMgrdKFInPORKVijirO+DVA00u972o0p10ILDky+5DCj3b0QmXNwmTJ5R3OjRDHYTRI6z3b6Sq1QjgIZG3Ewow/oD9HC4SvbNfbGR0aS39DBgz+X92cvRkkiZL8V5vJPZ1hNCUqtiXELMPZPrnUj7u/n+ARpUOrzKIeJpu1Ls/oymH+mlQgmB1Dmvk4r9ctGLF+xMae9UdlvqoQrrwgJkyU7ITXpjyjLh64gfIK7NNSNDmVAnu5+9vdtaM0HX+7SgLQknGqGSYsNP3N3K6/NtPZ06G5DWhTJ4UCKhS2V0F+GlxwE52yadJkpnYdWXaOCJJyCRb+PTc1ohk/G37zMS9houH68JvqFic8a9sK3ZSPecvrItSf1W8GrQWVwszJfMp01dN35gNw2DFh4z1eWKuc2MleTpMil5czgzgXzsqx7ZFANpliGQTF3Rin60KVKjWlqseftdU/UYMPIy8aMetcsR98U2WR8qN2C7jVKc4BfbREaWLvGOMiIrtnJePzUV9KFy9iq0CSIeQlrmBxuIo8t4GdaL6x8JpttS+DHgwOHTxhQUS8/lwQPiSf5CBUD8jcIpDhzG9vW46B+WhY8DHGzBmgHrKodVfR7c29IEkVucNj4yuodGM9Uf61wW22/vHgClxTk48Lm28KMtV8z6bIM0by2/ftuUOYpLhKATT9Yf4Wp5f9gjdBWYEYDariE8M0VXYpdz2UfffkJKauWgSqg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c0c8ef1d-5011-4a5f-f2b3-08da1bd545fb X-MS-Exchange-CrossTenant-AuthSource: BN8PR10MB3220.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2022 16:06:44.5594 (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: wKe2PlwlwwWrbbHM1DaHdQVPVPcsKDY/uri6aebSYBvFJB36iJgBgfElycH3HiWVYbc8yBp4lZlmp0kBAhCI9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR10MB2609 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.858 definitions=2022-04-11_06:2022-04-11,2022-04-11 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 suspectscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204110089 X-Proofpoint-ORIG-GUID: e7JMvP2STZQ37YlwwHJbHU-VCZAzGJpZ X-Proofpoint-GUID: e7JMvP2STZQ37YlwwHJbHU-VCZAzGJpZ X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6904F1C0003 X-Rspam-User: Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=tPF+oGte; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=SZWLL0lp; dmarc=pass (policy=none) header.from=oracle.com; spf=none (imf20.hostedemail.com: domain of khalid.aziz@oracle.com has no SPF policy when checking 205.220.177.32) smtp.mailfrom=khalid.aziz@oracle.com X-Stat-Signature: gkqgmfbi1p38duyaeb4jf5z7iyz6xh39 X-HE-Tag: 1649693267-809653 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 ram-based filesystem that contains the files created for each shared address range. This adds just the filesystem and creation of files. Page table entries for these shared ranges created by mshare syscall are still not shared. Signed-off-by: Khalid Aziz --- Documentation/filesystems/msharefs.rst | 19 +++ include/uapi/linux/magic.h | 1 + mm/mshare.c | 191 +++++++++++++++++++++++-- 3 files changed, 197 insertions(+), 14 deletions(-) create mode 100644 Documentation/filesystems/msharefs.rst diff --git a/Documentation/filesystems/msharefs.rst b/Documentation/filesystems/msharefs.rst new file mode 100644 index 000000000000..fd161f67045d --- /dev/null +++ b/Documentation/filesystems/msharefs.rst @@ -0,0 +1,19 @@ +.. SPDX-License-Identifier: GPL-2.0 + +===================================================== +msharefs - a filesystem to support shared page tables +===================================================== + +msharefs is a ram-based filesystem that allows multiple processes to +share page table entries for shared pages. + +msharefs is typically mounted like this:: + + mount -t msharefs none /sys/fs/mshare + +When a process calls mshare syscall with a name for the shared address +range, a file with the same name is created under msharefs with that +name. This file can be opened by another process, if permissions +allow, to query the addresses shared under this range. These files are +removed by mshare_unlink syscall and can not be deleted directly. +Hence these files are created as immutable files. diff --git a/include/uapi/linux/magic.h b/include/uapi/linux/magic.h index f724129c0425..2a57a6ec6f3e 100644 --- a/include/uapi/linux/magic.h +++ b/include/uapi/linux/magic.h @@ -105,5 +105,6 @@ #define Z3FOLD_MAGIC 0x33 #define PPC_CMM_MAGIC 0xc7571590 #define SECRETMEM_MAGIC 0x5345434d /* "SECM" */ +#define MSHARE_MAGIC 0x4d534852 /* "MSHR" */ #endif /* __LINUX_MAGIC_H__ */ diff --git a/mm/mshare.c b/mm/mshare.c index 436195c0e74e..ad695288d4bb 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -10,20 +10,117 @@ * Matthew Wilcox */ -#include #include +#include #include +#include +#include +#include +#include +#include -static const struct file_operations mshare_fops = { +static struct super_block *msharefs_sb; + +static const struct file_operations msharefs_file_operations = { + .open = simple_open, + .llseek = no_llseek, }; +static int +msharefs_d_hash(const struct dentry *dentry, struct qstr *qstr) +{ + unsigned long hash = init_name_hash(dentry); + const unsigned char *s = qstr->name; + unsigned int len = qstr->len; + + while (len--) + hash = partial_name_hash(*s++, hash); + qstr->hash = end_name_hash(hash); + return 0; +} + +static struct dentry +*msharefs_alloc_dentry(struct dentry *parent, const char *name) +{ + struct dentry *d; + struct qstr q; + int err; + + q.name = name; + q.len = strlen(name); + + err = msharefs_d_hash(parent, &q); + if (err) + return ERR_PTR(err); + + d = d_alloc(parent, &q); + if (d) + return d; + + return ERR_PTR(-ENOMEM); +} + +static struct inode +*msharefs_get_inode(struct super_block *sb, int mode) +{ + struct inode *inode = new_inode(sb); + + if (inode) { + inode->i_ino = get_next_ino(); + inode->i_mode = mode; + + /* + * msharefs are not meant to be manipulated from userspace. + * Reading from the file is the only allowed operation + */ + inode->i_flags = S_IMMUTABLE; + + inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode); + inode->i_fop = &msharefs_file_operations; + inode->i_size = 0; + inode->i_uid = current_fsuid(); + inode->i_gid = current_fsgid(); + } + + return inode; +} + +static int +mshare_file_create(const char *name, unsigned long flags) +{ + struct inode *inode; + struct dentry *root, *dentry; + int err = 0; + + root = msharefs_sb->s_root; + + inode = msharefs_get_inode(msharefs_sb, S_IFREG | 0400); + if (IS_ERR(inode)) + return PTR_ERR(inode); + + dentry = msharefs_alloc_dentry(root, name); + if (IS_ERR(dentry)) { + err = PTR_ERR(dentry); + goto fail_inode; + } + + d_add(dentry, inode); + + return err; + +fail_inode: + iput(inode); + return err; +} + /* - * mshare syscall. Returns a file descriptor + * mshare syscall */ -SYSCALL_DEFINE5(mshare, const char *, name, unsigned long, addr, +SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, unsigned long, len, int, oflag, mode_t, mode) { - int fd; + char mshare_name[NAME_MAX]; + int err; /* * Address range being shared must be aligned to pgdir @@ -32,15 +129,14 @@ SYSCALL_DEFINE5(mshare, const char *, name, unsigned long, addr, if ((addr | len) & (PGDIR_SIZE - 1)) return -EINVAL; - /* - * Allocate a file descriptor to return - * - * TODO: This code ignores the object name completely. Add - * support for that - */ - fd = anon_inode_getfd("mshare", &mshare_fops, NULL, O_RDWR); + err = copy_from_user(mshare_name, name, NAME_MAX); + if (err) + goto err_out; - return fd; + err = mshare_file_create(mshare_name, oflag); + +err_out: + return err; } /* @@ -48,7 +144,8 @@ SYSCALL_DEFINE5(mshare, const char *, name, unsigned long, addr, */ SYSCALL_DEFINE1(mshare_unlink, const char *, name) { - int fd; + char mshare_name[NAME_MAX]; + int err; /* * Delete the named object @@ -56,5 +153,71 @@ SYSCALL_DEFINE1(mshare_unlink, const char *, name) * TODO: Mark mshare'd range for deletion * */ + err = copy_from_user(mshare_name, name, NAME_MAX); + if (err) + goto err_out; + return 0; + +err_out: + return err; +} + +static const struct dentry_operations msharefs_d_ops = { + .d_hash = msharefs_d_hash, +}; + +static int +msharefs_fill_super(struct super_block *sb, struct fs_context *fc) +{ + static const struct tree_descr empty_descr = {""}; + int err; + + sb->s_d_op = &msharefs_d_ops; + err = simple_fill_super(sb, MSHARE_MAGIC, &empty_descr); + if (err) + return err; + + msharefs_sb = sb; + return 0; +} + +static int +msharefs_get_tree(struct fs_context *fc) +{ + return get_tree_single(fc, msharefs_fill_super); +} + +static const struct fs_context_operations msharefs_context_ops = { + .get_tree = msharefs_get_tree, +}; + +static int +mshare_init_fs_context(struct fs_context *fc) +{ + fc->ops = &msharefs_context_ops; return 0; } + +static struct file_system_type mshare_fs = { + .name = "msharefs", + .init_fs_context = mshare_init_fs_context, + .kill_sb = kill_litter_super, +}; + +static int +mshare_init(void) +{ + int ret = 0; + + ret = sysfs_create_mount_point(fs_kobj, "mshare"); + if (ret) + return ret; + + ret = register_filesystem(&mshare_fs); + if (ret) + sysfs_remove_mount_point(fs_kobj, "mshare"); + + return ret; +} + +fs_initcall(mshare_init); From patchwork Mon Apr 11 16:05:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 12809400 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 C5F80C433EF for ; Mon, 11 Apr 2022 16:07:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B84AE8D0005; Mon, 11 Apr 2022 12:07:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE65A8D0003; Mon, 11 Apr 2022 12:07:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 89B8E8D0005; Mon, 11 Apr 2022 12:07:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0055.hostedemail.com [216.40.44.55]) by kanga.kvack.org (Postfix) with ESMTP id 72FD88D0001 for ; Mon, 11 Apr 2022 12:07:48 -0400 (EDT) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 292B7A7278 for ; Mon, 11 Apr 2022 16:07:48 +0000 (UTC) X-FDA: 79345079016.31.728B944 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf16.hostedemail.com (Postfix) with ESMTP id 290B2180011 for ; Mon, 11 Apr 2022 16:07:46 +0000 (UTC) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23BFxoBF032238; Mon, 11 Apr 2022 16:07:13 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-2021-07-09; bh=cZ1qr4X6tFMeVv1Mz56twvprFe2XP1f++flf8dat6MU=; b=HwRpVn3ZovskAFx9CC9M0WvWwEEmELU1blqHuc8xAJQxeMp1xyVdGgSR9sxix06ADUQf He5oaF0CMJYgZWLwZqKBuD0fRtXdjMPUO7EE+dr1BEPiUkv07zLXWhDtuMfb7aLpfClC vALmYvnIFgniF+pzR3cz4NMkdeQLd2/P894/oThPNLHmkkJNT8u5NBU+6B6NfXPuus+f VZs4/iQ+ahFAaSm9kxfyCgbW3gzBi3hXJib60RULAd21oSaZ2vZ7ItUeDkSVhs7d3Lu+ DsIzX0rhRAMVFPbfbqK6ksppQUyosUt4/UEFmXhhX7cvn0Dtd5NCuEnrgBSkZ8mlZZkA Ng== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com with ESMTP id 3fb0jd43yg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:13 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23BG1fwk009897; Mon, 11 Apr 2022 16:06:52 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2168.outbound.protection.outlook.com [104.47.56.168]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3fb0k2057y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:06:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aJgo6xsagR/wznqt48/QrGJB5fC0U3Au1HiSzLWuxa2x6qBEVL/33p1Ulf7JCrjvL3NGzrok/2KdwKvxpPluZwX5Z/1zN16Q9wJEY+oVkya9uHd4y+AY4ASmXgWB2urmiAjGjf9J7WKXRvEQILGAJwf+iWNu0mqq6IlLWGw0tD/vWTtYxOZUpOKW+7yNpDgPMgM9wezUP0BQcC7xgOejBdUj0Wc2X8loKHGYBU02dcwJ0U2c/kTxiF2yfw9sO5QxR8nxN0XfgO9CiduK4tjcdy+iinnB5Bywvv9XHN7uBjYlqExnLW9+MZtp0Emvpm/XglQN2DNNQb1zao2XSFijUA== 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=cZ1qr4X6tFMeVv1Mz56twvprFe2XP1f++flf8dat6MU=; b=gS6qtyVldv7lrt9X14lNxZrBuLDCneaFOrbDvCQZP1CNP93e5yTa+bmLche1CHRl5OdqBZ5FK0aZphDLECjDqALIiCTX/nBOm0U/9lZbfWWUD9j4vEUYHgJJQV6AhEssg1Qd/JXdR82vbhkoEV1fGuyu0pW8JxemIXY3n+7ildGVPyAZQyAaijXICs0XQrzzo0n9WvQOuCWoeoMjv+8uJ1BOgED55SLdaQ0dC32HbMiYV8X2qJbZ2ReNn99hvDnrJofNZRB5yoR5BaHxaOrBsSmHX8swMzwgPzHFC5wpvutBPER5y/b84QALd5OGL97eDG+MxYlWPtp6h8hbAMMehA== 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=cZ1qr4X6tFMeVv1Mz56twvprFe2XP1f++flf8dat6MU=; b=G1ZWd1HNadf/3kJrMheRkhC50zxxazXB52gRa231eMh0S5tPzs/MMYF8DXZiGNAsHTYZHQ2mclillcRNHDEn5A1GBtZhzcSwFWNUHj1kr2uSXF68CKkqvqIJYNL5yyZwAcAM26H2oFvmfxUzdzwcQuVqjylDwExSl6Ckb1mTSos= Received: from BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) by CO1PR10MB4564.namprd10.prod.outlook.com (2603:10b6:303:6f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Mon, 11 Apr 2022 16:06:50 +0000 Received: from BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40]) by BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40%6]) with mapi id 15.20.5144.029; Mon, 11 Apr 2022 16:06:49 +0000 From: Khalid Aziz To: akpm@linux-foundation.org, willy@infradead.org Cc: Khalid Aziz , aneesh.kumar@linux.ibm.com, arnd@arndb.de, 21cnbao@gmail.com, corbet@lwn.net, dave.hansen@linux.intel.com, david@redhat.com, ebiederm@xmission.com, hagen@jauu.net, jack@suse.cz, keescook@chromium.org, kirill@shutemov.name, kucharsk@gmail.com, linkinjeon@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, longpeng2@huawei.com, luto@kernel.org, markhemm@googlemail.com, pcc@google.com, rppt@kernel.org, sieberf@amazon.com, sjpark@amazon.de, surenb@google.com, tst@schoebel-theuer.de, yzaikin@google.com Subject: [PATCH v1 03/14] mm/mshare: Add read for msharefs Date: Mon, 11 Apr 2022 10:05:47 -0600 Message-Id: <4978f8cd6e566e531af457d46d00e5a7f3b2d8df.1649370874.git.khalid.aziz@oracle.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-ClientProxiedBy: SJ0P220CA0013.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:41b::20) To BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9d1590be-639b-4853-c05e-08da1bd54921 X-MS-TrafficTypeDiagnostic: CO1PR10MB4564:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yozN/gTqZW5mvg46Gfo+OZNnFYlaz0t/ok7I3ltW+qM1iJhTLvX9bBi9+s0+JfmXYJ3E7CoIYtmWy/YcGu0/RlD7BHEAMwUIDT1PkFTvQR5hiQ0IS4ownnfJbxQHpbeGK4sS3UF/9fO5we6K9hi2uehkwFCJJ6TfzewPgU/maziKyFY7hbqXu3Nzf/X8whqB9VeTZWr+43NH5Ad26oyuRaO/JnoYCxDvAfvIzZFP//QiVnANHLElv+Oj1UdojNNmRtSb75oJTRkSfhD2tSlFI6fXcwRCrBr0o0YPo282iovPF40XW2uxk78aqctOUbNGFZkDRPLpkun0lWv/ODjoypBUcB9udj3NIrnDhbpfXuAZxA9wbzuPn+cimaGyU7siFGpNYTx27Rfii2eQN620bCBOPCNjo1oPvNourkFYrDFz7bzhqcKQL7mNzS1FCzHPpNjJqfEHFdvC/NB3N96KFCNHDnLYZnZgNNRSH0qkTEYWi2uFqL9mzAmDT6U8t6AwTuT3ZgTT/42uoGz054YNZJal6JLXXxnWBdtRTx4vrg9KJB0ES8LOaJSnpbGOwJjuLtwwyYzUw48EzZP4Ooq8+uPIKeeKPViVLrpk1yJ+3wzNOy04zbyAy1saxmCIApbPPYiVxY8yOFl7V71ozbZDPEvVEXqX+kCrbmPIlGBjvzGr4EQ7HbKYw14LnonhMZTv2ISpy9TMC8iKNUpsmA9ssg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR10MB3220.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(36756003)(5660300002)(38350700002)(38100700002)(508600001)(8936002)(6506007)(44832011)(7416002)(4326008)(8676002)(66946007)(66476007)(6486002)(66556008)(26005)(186003)(2616005)(86362001)(83380400001)(2906002)(6512007)(52116002)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cdjSvSytdjAt3NRdXhoer+e8kgVyDaNB1o/hDcSUyNX6e/NU2vEn85klIWPZt2OxVUay1bIHNxo10VvkWxWZ0UOytXOUSr1Lp5rPwSndaLX8X4M2f/Sv+C1o8Y6/rDXafQ8CsohxhD3iD8SNKBbUcGzp18wb1i6uuWHVJX6dyYYzzLYIoxOiY83Jg64NgTfi6j/RIrmA5GHUCHBeSLzB6mvXzcOsLB5tIdqU8Yrj+MQyGkonPKkeQHrw68s8v7J0IR2PgJoVAe3Y+DIJ2+tBGLkFZ5n1GMysdx8PhH/WFR51Y16Fdjo0U2ap+aQu4+BpV4uB1ZTOCzlu6Y+conNWaKAlkX7Wi4TDhqEyN0Bn1iT3RMcKCZgVSUURvqI+7k0tXPaOei8VNYCcP1ZEbwRCDS5/RnjztINW/s+giSOY6bNaB48ThkKRPJdAddsdHOwp3oIJBhsx6bn+Is3QuCXW2/5n73EVtVIj36TCDIxByr9At3wj+SnylLfSrR4edpX0dHN9eYm68jdUjLf/mqyNET32HqdDft0xY+0ONCqkPcb4X9qK5BoRQfXMSgAijC3KY0UIAF9HHd+Z2/XD5G3jVyl3bKWfH6QFA89BPuxOQVCXDUJc3AbhCtbuqPmSlqX33khxoRdwM0m2ehERz0d4EWJNJMsUV9EgPntqxT5gPomajLYtQrcPb0/fF5HcQGGBFgKroYHt/9dFPuoMQA9+5oJU4mpIofOLKpB8Uao95bnf/HqRUj2iMAtzDRYYMxA9vgjDd76q0nDvde7GpF7f6p0nHyXMa7WI5kPkI+bkGK9OECIxjWv+D0R4MXiUeF08jnwW9PkZ7ZoF0+7/DTgXRrg1KsEtJhPQdWmbvIzoOfYAHuRDLplKsCkl7LaYjmOn6bAEZAKgNn2L9AW4KLhj9am73v07dVzIxTsn4HPItYYbufMDMEs1aEv5yvWbxWysXN4zoY9R4FO0NIkihzT09ujhS0+72QPewLnVxU2HCyIfHuP72DA0LUqzv3gY+0HCi7EAX/EUad9bwyTEWS/Xlk0cH2eBFVUlld4GQUOy6/7uSZ+ie2uDzzX32Q0QGqGLcl6ScuJFRlcHz7vu4Ej1Xk78NH3EfDrewV1GCw/WTkWKJZ2YHo9Q179K4QGHvJnEQMMu3OowPCiTGGlFV2IrTxoD2I2+/ZvUN0fwrrj3MSwBYh+ZAei5/DMpdz8UmMW4elnqQkvjFWMbj4RjLhSIxtWKRV7e7vv2zxxMDjFpVf2bsl9kj+++89InQ0gKr48RagnYEmXSdQJukipM0kcrF2CZzYlYWpMA+klGzfUpZjMpGNEXXUYUhscXACE+/UHgvr570Lv0RyzLZPGhvErjePu/XfKTDqgEepfOxBIhSQgUCOk2WQ8vSzsDro1mcdG7tihU6jDD23jUZRnho3c53fzOyiLhlFWhr600wjCdZjP5PUOvxnGAWioUz0G3V6nD+QrgJuOrqTbzKTlIOZciLcavpYui0nucuPK/1jrlEn2F4sDIiQ3Wy88LvgxC7V5rxGCOAS7w6Zt0EDGEccoCFhe1XSL0JLRot9bVU8JbA36SXeWgd4L6Al2FGrd8M3nJNDqrC87OFgCkrH76R1ENeAL8rAiuS1IqLMNuOOe9PwKXbKdaCnNo58DG5Jd093MeQmDH8pzrNxnuwbchszsIN6V+sPcC50ytqIXwqnK9SflLYPRL0VUX3nuHmVRoMc52E5q974/AU3IZhPAmLb+F9Q== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9d1590be-639b-4853-c05e-08da1bd54921 X-MS-Exchange-CrossTenant-AuthSource: BN8PR10MB3220.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2022 16:06:49.8091 (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: t8dWzItDQepCVpipYYsIMI2Z6TbjLOPc1/RAjp7X9uTSAIh0KKYvugbR/ZF+PQCXjKpeKV/YhY+y63B5P5AxqQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4564 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.858 definitions=2022-04-11_06:2022-04-11,2022-04-11 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=871 malwarescore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204110089 X-Proofpoint-ORIG-GUID: TaSlDG3ONARtjeJdh-WKfUkOAf4FsFMU X-Proofpoint-GUID: TaSlDG3ONARtjeJdh-WKfUkOAf4FsFMU X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 290B2180011 X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=HwRpVn3Z; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=G1ZWd1HN; dmarc=pass (policy=none) header.from=oracle.com; spf=none (imf16.hostedemail.com: domain of khalid.aziz@oracle.com has no SPF policy when checking 205.220.177.32) smtp.mailfrom=khalid.aziz@oracle.com X-Stat-Signature: acmb5ucr75dwfton11crqqof53eatyps X-HE-Tag: 1649693266-809323 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: Allocate a new mm to store shared page table. Add a read operation to file created by mshare syscall to return the starting address and size of region shared by the corresponding range. This information is returned as struct mshare_info defined in include/uapi/linux/mman.h Signed-off-by: Khalid Aziz --- v1: - Read returns struct instead of two unsigned long (suggested by Mike Rapoport) include/uapi/linux/mman.h | 5 +++ mm/mshare.c | 68 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 68 insertions(+), 5 deletions(-) diff --git a/include/uapi/linux/mman.h b/include/uapi/linux/mman.h index f55bc680b5b0..56fe446e24b1 100644 --- a/include/uapi/linux/mman.h +++ b/include/uapi/linux/mman.h @@ -41,4 +41,9 @@ #define MAP_HUGE_2GB HUGETLB_FLAG_ENCODE_2GB #define MAP_HUGE_16GB HUGETLB_FLAG_ENCODE_16GB +struct mshare_info { + unsigned long start; + unsigned long size; +}; + #endif /* _UAPI_LINUX_MMAN_H */ diff --git a/mm/mshare.c b/mm/mshare.c index ad695288d4bb..59e5d294e562 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -16,14 +16,39 @@ #include #include #include +#include +#include #include #include +#include + +struct mshare_data { + struct mm_struct *mm; + refcount_t refcnt; +}; static struct super_block *msharefs_sb; +static ssize_t +mshare_read(struct kiocb *iocb, struct iov_iter *iov) +{ + struct mshare_data *info = iocb->ki_filp->private_data; + struct mm_struct *mm = info->mm; + size_t ret; + struct mshare_info m_info; + + m_info.start = mm->mmap_base; + m_info.size = mm->task_size - mm->mmap_base; + ret = copy_to_iter(&m_info, sizeof(m_info), iov); + if (!ret) + return -EFAULT; + return ret; +} + static const struct file_operations msharefs_file_operations = { - .open = simple_open, - .llseek = no_llseek, + .open = simple_open, + .read_iter = mshare_read, + .llseek = no_llseek, }; static int @@ -77,7 +102,12 @@ static struct inode inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode); inode->i_fop = &msharefs_file_operations; - inode->i_size = 0; + + /* + * A read from this file will return two unsigned long + */ + inode->i_size = 2 * sizeof(unsigned long); + inode->i_uid = current_fsuid(); inode->i_gid = current_fsgid(); } @@ -86,7 +116,8 @@ static struct inode } static int -mshare_file_create(const char *name, unsigned long flags) +mshare_file_create(const char *name, unsigned long flags, + struct mshare_data *info) { struct inode *inode; struct dentry *root, *dentry; @@ -98,6 +129,8 @@ mshare_file_create(const char *name, unsigned long flags) if (IS_ERR(inode)) return PTR_ERR(inode); + inode->i_private = info; + dentry = msharefs_alloc_dentry(root, name); if (IS_ERR(dentry)) { err = PTR_ERR(dentry); @@ -120,6 +153,8 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, unsigned long, len, int, oflag, mode_t, mode) { char mshare_name[NAME_MAX]; + struct mshare_data *info; + struct mm_struct *mm; int err; /* @@ -133,8 +168,31 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, if (err) goto err_out; - err = mshare_file_create(mshare_name, oflag); + mm = mm_alloc(); + if (!mm) + return -ENOMEM; + info = kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) { + err = -ENOMEM; + goto err_relmm; + } + mm->mmap_base = addr; + mm->task_size = addr + len; + if (!mm->task_size) + mm->task_size--; + info->mm = mm; + refcount_set(&info->refcnt, 1); + + err = mshare_file_create(mshare_name, oflag, info); + if (err) + goto err_relinfo; + + return 0; +err_relinfo: + kfree(info); +err_relmm: + mmput(mm); err_out: return err; } From patchwork Mon Apr 11 16:05:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 12809396 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 75EA7C433F5 for ; Mon, 11 Apr 2022 16:07:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCC956B0074; Mon, 11 Apr 2022 12:07:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D7CA06B0075; Mon, 11 Apr 2022 12:07:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE4276B0078; Mon, 11 Apr 2022 12:07:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 82B476B0075 for ; Mon, 11 Apr 2022 12:07:45 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 54A931219FF for ; Mon, 11 Apr 2022 16:07:45 +0000 (UTC) X-FDA: 79345078890.20.2D0E28B Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf27.hostedemail.com (Postfix) with ESMTP id 7834F40016 for ; Mon, 11 Apr 2022 16:07:44 +0000 (UTC) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23BF9VOV014133; Mon, 11 Apr 2022 16:06:59 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-2021-07-09; bh=jnwvLFTj1SfpHchAOm9ayKGf+zx6iaTYkuHrwHxh2sg=; b=j+OiDoezlXYf/Q49EH3gldajV8bMb00glji1Kpv9Kk/yvC7yVMG29sf3A0+ExCOo1ilg HG8gX66NzwQxRcY7ZUdIVXaaVdX288mRJ2hW4kxLnhQp1umI0nCBwVeEV6TwTgQI0CS2 xkwvAJiSYppTqKuNcmkDezWAJ0x6uDauGZkVY+sY/t3NQPQIFXMII45M1C+O8hlt7r8w 7GY/6GPOTRrIC2fsaqBTcicpbYMoVHfzCveILY8bl2dp+pnrQp29xnvH7szxUk2+hvoy vN5UcnA7Qqm1wkht1epzeU8O/fAmnhChCc61lUR+c9EQiKwtirfi5aj1yU8brrqDbgqv ag== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3fb2ptv6q4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:06:58 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23BG1ABp033069; Mon, 11 Apr 2022 16:06:57 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1anam02lp2041.outbound.protection.outlook.com [104.47.57.41]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3fb0k1kee0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:06:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mRbIvk5iNvPNcaMk/Sw8WhBQtmI/hsdj5DjvO5RPSpO/C92mgg2j73zhJ1Ga+eNKvTECdaDb0n15M4Av15gjqWVsJqRynTWnkbTNlEsHXXIMKJTWcf1Nik0DqFb6781M2kJhKxRJxOZMumG7JXTfs0XQrtrK7CcBWEEyMOIjGf2hxQFvjjA1NYU0WV2v4NySDRO9H/+ODyJcsBpR9f/X08RzO2D+rMEZe8ULGRioLwuPJ3Yu2VuCB/mACFt6w9PEhNOhoyN0H2izYj6oHQQ8kxMD/habfZCB78u/AVosbW+EK9cFmII947cu1Pjrjjm1OXW84oDf9ggrH/ESwgca/w== 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=jnwvLFTj1SfpHchAOm9ayKGf+zx6iaTYkuHrwHxh2sg=; b=X+5CyOaoT0oSo6j3tB/9IjxJFOqUmelKZYZu9jxyEi66R63HI2TiMNwHwUtFtvTrZUQRMEamgNsb/bHF8z76y3yJ2FoTjBVcUAic9e/3aXMq1CKIN7G3VUdKkFFRU8/0p3npP5q1qAH3SmBUEAFBokKhnFjJyHDakyPEQRBzzu3bMQSXVjVd6BjM4eeTkQPKSJVmOEAuuHIjpPY3dVeVazDy5x/4zo/WmPk3wPWOxTh9Tcj1D1SRwGv/r7/z2T8muggVUT1SegtGJX23VfKtVS6a8zztZYabyj+nNN6G8tPfdlqU7xZjACNJIQIu8lod0ljimLevSNZ6xOgxkjmHoA== 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=jnwvLFTj1SfpHchAOm9ayKGf+zx6iaTYkuHrwHxh2sg=; b=AJtEg7MfpfzppTsoGrCgy2+n+ZLPpZyUGKsbcBUbQKF1yip1qLIO5G4sZJAn9aCE2JVkcY45ygQSYxVKR+HX9Ke7TmfSOm1O7mlP4PUnRJCACULDMg/e5fnC97I8W2N9i5wMcXagBX75NfCmjsmyVsYrfMf8Po+oo6KUzfUT2cs= Received: from BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) by MN2PR10MB3616.namprd10.prod.outlook.com (2603:10b6:208:11e::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Mon, 11 Apr 2022 16:06:54 +0000 Received: from BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40]) by BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40%6]) with mapi id 15.20.5144.029; Mon, 11 Apr 2022 16:06:54 +0000 From: Khalid Aziz To: akpm@linux-foundation.org, willy@infradead.org Cc: Khalid Aziz , aneesh.kumar@linux.ibm.com, arnd@arndb.de, 21cnbao@gmail.com, corbet@lwn.net, dave.hansen@linux.intel.com, david@redhat.com, ebiederm@xmission.com, hagen@jauu.net, jack@suse.cz, keescook@chromium.org, kirill@shutemov.name, kucharsk@gmail.com, linkinjeon@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, longpeng2@huawei.com, luto@kernel.org, markhemm@googlemail.com, pcc@google.com, rppt@kernel.org, sieberf@amazon.com, sjpark@amazon.de, surenb@google.com, tst@schoebel-theuer.de, yzaikin@google.com Subject: [PATCH v1 04/14] mm/mshare: implement mshare_unlink syscall Date: Mon, 11 Apr 2022 10:05:48 -0600 Message-Id: <378f51749fd4d0bbe303f1a1b942cf1c7f5ea480.1649370874.git.khalid.aziz@oracle.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-ClientProxiedBy: SJ0P220CA0013.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:41b::20) To BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: eeb6ce93-b483-4703-4242-08da1bd54c1a X-MS-TrafficTypeDiagnostic: MN2PR10MB3616:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EZCbHT7C8jPiDk01uKff9W694nwTbre27zhsXYB7FC3EyFhV0vRz1yeRSItdtV4eB3TiPQIeunF9UROiTnMDXE1X676u4nUkkBb0hHh4dOfOwn9+WzwJXtlf7GpMLYG2jJjTl0/Vnq+4jj5OwhmFJYF11wNGcPRBgztVCc1yO7FkxoVI6ldGXH6IglzuXCVbHBAfk08giPF195nDVWFUhNbH4QNuGP++poc/Rl6WlIwJLrR85XFAxmRaupmG8YVkEpkYJGP0/P24RV6wobksByhkVjRPliN7DJUMKuXxhze26B4dB6i8TtSSntFYt6N38DgNbliA7CBHK+NVi7YGR56iV0iyRlple4psWi8XKqcT78b7vUoQpq9V+lQBvSdJcPIgAgjeN36X33xymCmyy13wBA8Tp1OWeHXliIOyDrdakT7OyJr/re0o0lViduYmlOl4O0alxwLpFPKbK8xJq1A1egku2GsTb0IxYOgyxoWtMsquXfAP7gLSGw77V6aUsSLjf8kctEGpAJtEVyRAkF1gYyT1oLhzIAA3dOoZjWnmIsz+YWFY2xUJhFJMkggkLhOJsljyXk3d3MgBQ0SGonA/lLHgmVZN9YIarG+M08qoK/O7LtZ/aOmVzlrrcvqib4Frtqqb0j+EGuqmWlTnj2AZigk+Z2nUUTAOXpalvQQKzJZ73N41S/j8Uffx0pJi+bI6YRTUYsRE7xCX6tfqKA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR10MB3220.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(186003)(44832011)(7416002)(5660300002)(86362001)(6666004)(36756003)(2616005)(8936002)(52116002)(6506007)(316002)(4326008)(38100700002)(6512007)(2906002)(66556008)(38350700002)(66946007)(66476007)(26005)(508600001)(83380400001)(6486002)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4ED3hNPVSTW85u9XOp1AhgJIkYxrfPhGnn2cfnpCeKAbQQ/Hu2tq2p5B5BSpWrsBexKGfpoy+O9MN9ys1yF0zTx6OQCbCoFhMphYwSo9xpC+7laL233aku6CPM+6rhRtdzy0drVZdAvj4palAbfDOaqfPC/hT3a3Z+m/Z3rlSSRXZKQoVlk186KhbA9wQNV6XKpEXItzf9D1gHSasyi8Tp0LqvQE1HBoxFi/dY6kZPqtko12ed5sKgtAOiUrQAFnR3jpEj3naOKbJ1lcXm8cPlRUj4rK5m53nNLubBe6DWBqtVbhwSPnNlvs4vsJg8ZIzOfqFXJP7cjQzc3D/GT01VLXUe2MxMYBQa8+t+2h4Wk3cK21/eGeKO0+CADC+dkzVCB1R/CtJwrntkcPBSs0MtsevJxdURwTw0botXj18YRRrDtFYbv/2c+GOmMqtLPmj1WI4cKzohPkjUXHw3wchHwvv3zuzg/2OBEqkSFbH/X3HSk2zObRbTlIKG0Mx3qNFqVTlxF1t6WMUU2/kRpa3rwyzktODw7LjTnl5kvMf48JHYBlF4XvlDfsxO07ovvGWmR+HIbin4GGVMNyhJYRv5b6rY/OCxgXkbGqpqGHi7QkcQU0deM4W3D4+pNis1Yw7vlyn85lSUPPhi1Zl6XeCpgReyON1bNAftMZY/yZknMbleSE0DDNGnkDAxYiFrBToYNZhyQMO+a0McNpLixcIgr0wXSemh21eDqGirRAYc5wD5r3mRym0ZZ4dgQsPArDh5s+0aDBZYOc6B4wzZJs4+bCb2YTue/MbdXxy+FJll4qv1nk/m9pjnYk/i4c32EKWeJ0tFFDn3AOt4cyKRIVKVuuriWkHgvkTdvNLxPVYGlAachqAfLTYqTEFS37IFfH3jv66KHStI3cT8jlUd0BbXdey5e5X9qtuVT3eyKxL7Gw7YN6szIX+nryRooewyKEEnSa/jF+ag+/s5K/e3UJTfH1IVpN7weDKuGltG1pCPln+mmFflqGbAcPrZcW7mY+5Gur68kHJ4YHTBWX0m8rqb9ArKxkAXWGxCzkjyN3BNGbavW8Z5yb0xco0KcrNM9iYGIQi6Rzq5QRScMuhSfSJpEWYCxtzCfnt2EkTwQWwZW6diomMNzV/3SL5PZtGX92QbvNAEGnvY77AlbX7opniAuzON3U4SK7a5L72qqgBbwl+rh3cpTYgXzd+YcatvikH1FUl3+SWrFADUyvaUm+SNpcn1kE2lBRJrkAHy+zlCTKVoCgi0LdY2RfGnMyRtCzye+3JWWnuphLG5cOwaa9OF4OHO/OmklynagjUy2Vyg6LZK9fQpRlHwwh/tD71EFCOjyeqhlZcB8MagcmA79LzFgU/G2OwVJeza+V6xg8DWMtkBRgY/LB378B5Ag4vULVefWqmCIiGBhWcdNYUl55MjAWL/tm1YCBq14ARWB15uAMq3ZVANJE+yJLeBVWT8Bx58lKSDtHNxRvpbUN7FfUGJx5/lyxK6R7k1ge1ciIPwjizQcfpOQWxez6M0z8BBb2aZIlOTPksPCLVJ0NNQWS/w+fe6BarY9VUbZV4KarTSaoeCHcPMJw56RdGM2xHB7Fsr0qKaopA4+BBDT1s7i9XO6wsCC+rWMEdK7LyilBUwbhLF+H4hEoejObfYvTbI20TtmrcYm26TCZ9ktHiZk+O/8MgXDa5rUWYV31Iq6ysnmr2ZZkLE+ikWQ/0uMjaFoBOB5uiUmEEYHxUrMz07NCHQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: eeb6ce93-b483-4703-4242-08da1bd54c1a X-MS-Exchange-CrossTenant-AuthSource: BN8PR10MB3220.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2022 16:06:54.8244 (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: JRTuSL1sxDHIzmfsrYZCDRh88KVwxinpJD93PhiXFBJdWyO/kUj3KsR6Aa217JoFyil5zooBXj8pM+ZGPn2geg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB3616 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.858 definitions=2022-04-11_06:2022-04-11,2022-04-11 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 adultscore=0 mlxscore=0 bulkscore=0 phishscore=0 spamscore=0 mlxlogscore=657 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204110089 X-Proofpoint-ORIG-GUID: 5ZtnxGJ7CSYHnHMbj_DkWqGjkafGSnCC X-Proofpoint-GUID: 5ZtnxGJ7CSYHnHMbj_DkWqGjkafGSnCC X-Rspam-User: Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=j+OiDoez; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=AJtEg7Mf; spf=none (imf27.hostedemail.com: domain of khalid.aziz@oracle.com has no SPF policy when checking 205.220.165.32) smtp.mailfrom=khalid.aziz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 7834F40016 X-Stat-Signature: juucrzsueix4food7sqduuzrjwyc7qdo X-HE-Tag: 1649693264-450591 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 code to allow mshare syscall to be made for an exisitng mshare'd region. Complete the implementation for mshare_unlink syscall. Make reading mshare resource name from userspace safer. Fix code to allow msharefs to be unmounted cleanly. Signed-off-by: Khalid Aziz --- mm/mshare.c | 144 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 113 insertions(+), 31 deletions(-) diff --git a/mm/mshare.c b/mm/mshare.c index 0247275aac50..b9d7836f9bd1 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -23,11 +23,24 @@ struct mshare_data { struct mm_struct *mm; + mode_t mode; refcount_t refcnt; }; static struct super_block *msharefs_sb; +static void +msharefs_evict_inode(struct inode *inode) +{ + clear_inode(inode); +} + +static const struct super_operations msharefs_ops = { + .statfs = simple_statfs, + .drop_inode = generic_delete_inode, + .evict_inode = msharefs_evict_inode, +}; + static ssize_t mshare_read(struct kiocb *iocb, struct iov_iter *iov) { @@ -115,7 +128,7 @@ static struct inode } static int -mshare_file_create(const char *name, unsigned long flags, +mshare_file_create(struct filename *fname, int flags, struct mshare_data *info) { struct inode *inode; @@ -124,13 +137,16 @@ mshare_file_create(const char *name, unsigned long flags, root = msharefs_sb->s_root; + /* + * This is a read only file. + */ inode = msharefs_get_inode(msharefs_sb, S_IFREG | 0400); if (IS_ERR(inode)) return PTR_ERR(inode); inode->i_private = info; - dentry = msharefs_alloc_dentry(root, name); + dentry = msharefs_alloc_dentry(root, fname->name); if (IS_ERR(dentry)) { err = PTR_ERR(dentry); goto fail_inode; @@ -138,6 +154,7 @@ mshare_file_create(const char *name, unsigned long flags, d_add(dentry, inode); + dput(dentry); return err; fail_inode: @@ -151,10 +168,13 @@ mshare_file_create(const char *name, unsigned long flags, SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, unsigned long, len, int, oflag, mode_t, mode) { - char mshare_name[NAME_MAX]; struct mshare_data *info; struct mm_struct *mm; - int err; + struct filename *fname = getname(name); + struct dentry *dentry; + struct inode *inode; + struct qstr namestr; + int err = PTR_ERR(fname); /* * Address range being shared must be aligned to pgdir @@ -163,29 +183,56 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, if ((addr | len) & (PGDIR_SIZE - 1)) return -EINVAL; - err = copy_from_user(mshare_name, name, NAME_MAX); + if (IS_ERR(fname)) + goto err_out; + + /* + * Does this mshare entry exist already? If it does, calling + * mshare with O_EXCL|O_CREAT is an error + */ + namestr.name = fname->name; + namestr.len = strlen(fname->name); + err = msharefs_d_hash(msharefs_sb->s_root, &namestr); if (err) goto err_out; + dentry = d_lookup(msharefs_sb->s_root, &namestr); + if (dentry && (oflag & (O_EXCL|O_CREAT))) { + err = -EEXIST; + dput(dentry); + goto err_out; + } - mm = mm_alloc(); - if (!mm) - return -ENOMEM; - info = kzalloc(sizeof(*info), GFP_KERNEL); - if (!info) { - err = -ENOMEM; - goto err_relmm; + if (dentry) { + inode = d_inode(dentry); + if (inode == NULL) { + err = -EINVAL; + goto err_out; + } + info = inode->i_private; + refcount_inc(&info->refcnt); + dput(dentry); + } else { + mm = mm_alloc(); + if (!mm) + return -ENOMEM; + info = kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) { + err = -ENOMEM; + goto err_relmm; + } + mm->mmap_base = addr; + mm->task_size = addr + len; + if (!mm->task_size) + mm->task_size--; + info->mm = mm; + info->mode = mode; + refcount_set(&info->refcnt, 1); + err = mshare_file_create(fname, oflag, info); + if (err) + goto err_relinfo; } - mm->mmap_base = addr; - mm->task_size = addr + len; - if (!mm->task_size) - mm->task_size--; - info->mm = mm; - refcount_set(&info->refcnt, 1); - - err = mshare_file_create(mshare_name, oflag, info); - if (err) - goto err_relinfo; + putname(fname); return 0; err_relinfo: @@ -193,6 +240,7 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, err_relmm: mmput(mm); err_out: + putname(fname); return err; } @@ -201,21 +249,54 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, */ SYSCALL_DEFINE1(mshare_unlink, const char *, name) { - char mshare_name[NAME_MAX]; - int err; + struct filename *fname = getname(name); + int err = PTR_ERR(fname); + struct dentry *dentry; + struct inode *inode; + struct mshare_data *info; + struct qstr namestr; - /* - * Delete the named object - * - * TODO: Mark mshare'd range for deletion - * - */ - err = copy_from_user(mshare_name, name, NAME_MAX); + if (IS_ERR(fname)) + goto err_out; + + namestr.name = fname->name; + namestr.len = strlen(fname->name); + err = msharefs_d_hash(msharefs_sb->s_root, &namestr); if (err) goto err_out; + dentry = d_lookup(msharefs_sb->s_root, &namestr); + if (dentry == NULL) { + err = -EINVAL; + goto err_out; + } + + inode = d_inode(dentry); + if (inode == NULL) { + err = -EINVAL; + goto err_dput; + } + info = inode->i_private; + + /* + * Is this the last reference? + */ + if (refcount_dec_and_test(&info->refcnt)) { + simple_unlink(d_inode(msharefs_sb->s_root), dentry); + d_drop(dentry); + d_delete(dentry); + mmput(info->mm); + kfree(info); + } else { + dput(dentry); + } + + putname(fname); return 0; +err_dput: + dput(dentry); err_out: + putname(fname); return err; } @@ -229,6 +310,7 @@ msharefs_fill_super(struct super_block *sb, struct fs_context *fc) static const struct tree_descr empty_descr = {""}; int err; + sb->s_op = &msharefs_ops; sb->s_d_op = &msharefs_d_ops; err = simple_fill_super(sb, MSHARE_MAGIC, &empty_descr); if (err) From patchwork Mon Apr 11 16:05:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 12809394 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 5F10CC433EF for ; Mon, 11 Apr 2022 16:07:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6B116B0072; Mon, 11 Apr 2022 12:07:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C1B196B0073; Mon, 11 Apr 2022 12:07:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A46156B0074; Mon, 11 Apr 2022 12:07:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0185.hostedemail.com [216.40.44.185]) by kanga.kvack.org (Postfix) with ESMTP id 928B46B0072 for ; Mon, 11 Apr 2022 12:07:44 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 4ED22183C8CC2 for ; Mon, 11 Apr 2022 16:07:44 +0000 (UTC) X-FDA: 79345078848.28.F5148E9 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf30.hostedemail.com (Postfix) with ESMTP id 44B8580004 for ; Mon, 11 Apr 2022 16:07:43 +0000 (UTC) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23BFweRK028178; Mon, 11 Apr 2022 16:07:06 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-2021-07-09; bh=ns/tAb54zwtHaXDOwJwVLMPuANUuMaTEmmT1t7WcQ0s=; b=NsEXOxeKiyr86sL6ScHYSeahKtyHLwPBzgmg9Y3SFiG/MkyRvH+Z6YkfAsCk44YrbgLU WAnU668xEMF4NXndiGdh/wgxsNayKsS4Xsk8KlSEqz7mik7cxAsnQyGS/Of20a5iNVNZ w0x2LSIQJQO8g30MSP0SJJeYL3t6Sc8LIdqbDVGGIJZbdwN/Rzpb1JDFSRUioR3+Nm2Q HSwKqdmbvAgOIRaUJ3/2z1FlWRWn3gsZ+gU7lvcdiUGq7Sfl/nR02+c/XJ1y12Z/bQ2i vpuHG5NxmihlqoOklRSN/VJizm7Sz38PIVwY2Ic1gua2CfT+9tgzPyDpwERWw1bKqlO4 vw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com with ESMTP id 3fb219v1g4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:03 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23BG29o0022489; Mon, 11 Apr 2022 16:07:03 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2101.outbound.protection.outlook.com [104.47.70.101]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3fcg9gdx0p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e5YpHM/T27WNmBLiWhBRA15XlGwF+OfzX1CPS1anZIz2n7sTtHOKNnb0//7bKOAWlcmtKFFIpYbhY1tQsKMjRP0gVBh1nflb9zjLUcSWQVyEixfb4DRG1fQ4JwUcsYniT2bKTIZ1BRAGnQSbXVRPLna5r0aCNqvFXmbtDSVd2RM6ZXIjhp4rx7xIKymcztfEvn1MO3fymJUILXMhbiERwEYaNPCRL2H/VuwdS2Z6SxW6HnN/rq4t8XiNN1arAd3AGPEjoM3pASinVpfgWa3dw10Z04axDfpYmW7g9VJkvg62+izfx3UQhieMf1lsbEe4qubhBnju5Rz+xgGpge1RUw== 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=ns/tAb54zwtHaXDOwJwVLMPuANUuMaTEmmT1t7WcQ0s=; b=abD8w/wbP3AiZlQp2ATZWSFCnvLdK42DgOwpMGScAM4dFbdNvtxKd2znjmJanumnN8ULvGd+LlvwqOXcP+jVodR9jpnI6NBumEwoDbomHQLchR3SEdxZGG/80OgJGw3RjLnb7ZEmvujq7EeiHTAB5gPggeFievnhfuWeTUsBNa5y1GWwZDPFBE0J06FVP1tA5l7+Xq0EBjbGgpWzSx5/K7CaZJSC7QlP1WaCQZJWP8xoIv6h4E/5yJ4kN8sXcj9gPDbVBjFJqZZRO0vtfEEagOl0iMj9xIP9ZeeDMjJQSaoEB5hy6FaZ5PqrxnGB60/Qb2tWTiClAdGuckhqsA4uuQ== 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=ns/tAb54zwtHaXDOwJwVLMPuANUuMaTEmmT1t7WcQ0s=; b=MbWMF2YRD61XTRfaFgXPgY8/A8ST1gNSFDNPTSm3hZg3nHZNewCpp0vKR/MaePqYUjF10JCRCJEGX/Z8AaJqSzO9mkX7/DgWH1gwMY21JuyGUQPu48b5HEqsmsANihx0WdizrrVS6/0LR1Qf4sF7uJhETgL5VGToseYlVByfCcQ= Received: from BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) by CO1PR10MB4564.namprd10.prod.outlook.com (2603:10b6:303:6f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Mon, 11 Apr 2022 16:07:00 +0000 Received: from BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40]) by BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40%6]) with mapi id 15.20.5144.029; Mon, 11 Apr 2022 16:07:00 +0000 From: Khalid Aziz To: akpm@linux-foundation.org, willy@infradead.org Cc: Khalid Aziz , aneesh.kumar@linux.ibm.com, arnd@arndb.de, 21cnbao@gmail.com, corbet@lwn.net, dave.hansen@linux.intel.com, david@redhat.com, ebiederm@xmission.com, hagen@jauu.net, jack@suse.cz, keescook@chromium.org, kirill@shutemov.name, kucharsk@gmail.com, linkinjeon@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, longpeng2@huawei.com, luto@kernel.org, markhemm@googlemail.com, pcc@google.com, rppt@kernel.org, sieberf@amazon.com, sjpark@amazon.de, surenb@google.com, tst@schoebel-theuer.de, yzaikin@google.com Subject: [PATCH v1 05/14] mm/mshare: Add locking to msharefs syscalls Date: Mon, 11 Apr 2022 10:05:49 -0600 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-ClientProxiedBy: SJ0P220CA0013.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:41b::20) To BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 19bb8fc6-a534-4f73-e717-08da1bd54f57 X-MS-TrafficTypeDiagnostic: CO1PR10MB4564:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KctlEP6MfettZWBVS7FORNSke6GKDGO7nO1g5rcDpK09MlYC+7kqoP8KNhbbMch9baotAI6bYkn/zbTHuu1c5usNz4nGybDIVXuIhhiUc7blWGaMgl7bblM+sI0UpU0x4P20TApf1iQNJb7p8dfefxd/Sw10Lf1hOdYgneDGY5uUzZhhg8ROO1Jh5kVjjOlSYWzF4RPmGdW9zvVfN3lkX9OcvcdPmCTQ9xcfU9uTSFifuAus/uIEfBuwPVglGvQZPRe1r3ERnu6gmfEUBSP0SaMncrQQd45ZUwcVAbcUgUExUNsGyWeyLqKGAA3vm4onbhffYTnugLR1bgwV6rcmBFkINJy4hpHraw/396phKEmegtvjRA9bxmSgXrH0mr1NdqCkbh+ZccY3IOpeLm88GnrhOiim0+Y3dYQIA1+SxEPmn6lzcYjGyKnmo9hzdFx1/FH4jj3ixZ2jQGbIg8xudGHfdz9Ae9E6Uno6BuOpV/gPBXDitdiXqmuT8gKJcfn/xN2hYe04njjW99ZLajApdShT4wAGF7JwpmIKzT60TYdIWKhE7AQdeN7/5UddaYvvC7sVxE2BgOCdRrHphwWmEUczR6j8IIu8Gb1P1cthO17hTN7+82VoSFgo0rv23X7NsRDjypXgwFyEQ/N85SiPRLvJDUDAL3EV4RHcFBoo1WVocyp09WGxEOmDLrnEJW+KFmadjytj9vuv3le1XSLdMA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR10MB3220.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(36756003)(5660300002)(38350700002)(38100700002)(508600001)(8936002)(6506007)(44832011)(7416002)(4326008)(8676002)(6666004)(66946007)(66476007)(6486002)(66556008)(26005)(186003)(2616005)(86362001)(83380400001)(2906002)(6512007)(52116002)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BpEDGFtrCXmv4T5emsjofaFse7T0t0B/JkYtPsRJO8iWCdorxrAQGmdFnNH0J+U+SQ9/2nP/8l9TJW4Oyay/u3mcRmsLBTJDZtX+m6euOpgIPj1uWUOZAtZzIKzrgBthJ1u4FwcPRVAQEkBpR72iuqC1RISN7ylXNc2/xMv9oF//TLd0SV3czsvR9wrx1WcLQQ7FLxW+Eix0iTJm6K3Hh69vs1tFEF7RznMu7HQuhG9m8jWbJGSms8aKpprIWx6M2wQlO5Rxiu5GmtMsE3FgTtYqgtxlgch0qHwws7/jPWq4ha1+nR/xhWR6UwmfDO+8dHh9x43Gb6lCQT+Km2Rp2k4ogEL6IU+flapwx6y19QNRdsVO9OVgQKcMyVjC9ZDmX3bMYGaoIDFxBpWmm4jBAe6u5v/sDWJvhsOhf7EyciqlA3YEfEUhcDUfsBhZ8+gSZBBr+ZsPLfvkRGwNf3luOgWYmVwwjTo60bY3ja/WIm3S2OfsL6WBqUwkhE25VBxGI6YRK53R0xNIQPKvaJCY8HRVSBWgswivBYqiWX4nA2bhdk0v22vj9REXut6lNo0cblhoj5J/P9CXhryqL/RVMMtm2NzIVdtClbm7vXRLBaFxozjSxQI5sf0he11asIr0NL7mFeFuSaGGaGfPXH013GvEvH71Z4q1X3yJk3gzslho+lYYSYtlCLuFsRmnGxmDT+esTygt54Jfj+tDnR93Yvle9MLdG0SDNPAiF65lcnwTbyiI+bJ3O/a5GlLFgIUEz6dFAZ17JlCDRygomfLEd48Hf870qjeXl+cnIAH5c3AR70CxOCpg5xGlE1ULZT0Sl6FY6cD7MrhEYNyFj3j38kxFl3hLiU52muzurRWSwOFX9gJD3aA7dqpowphZY6BjnqJzZU6H9b9CZGvRC46vUaU+FJufTMRbWO8KHD42A5EB1kETB42GCYEEa4wu+atv3ckje9hP8VlSNk4R3Sq73Nrx/2PWhiZYmo99LsgGfBIPFXsaYobwH2PJPI2dcK/CJM7kjRfVsFDfm32K9OKmBO9RHGlh34eiWFGxAZZSEqk5G986kf7iUhZJAvtqdhL0cu8Ygc7fqJO+H1Ank6465hjh8hnVbirCd93iM8wKTf5CzGKh8lOa27VDEmB+e3K3cYLrUU+HEt4US2NTTx6HNbT8ViI6+2dgR8RXmB9CXlJTe2N/TLWovpozPfJRMTG2ZCi8zp+H8FN+3ySRgMUUDyNXAi0EK7PHc3Mopw+3QwnVqdxf/03f9LXyVMo0WgtuNNGGWTLCCraZWuOqMnPaJFzHaL6gweaKcj6cW2Y2eYaAIRNWjcFQmS13P3G2ERFdM3wrARTNw+TFZgXZS3e4gj3SDgQRNPulVj/NkMlAL65xqoJzgGmS6PgLzW+d+I51nFRr6/efAcoOAAThvyxgHTZuqBPWWLUGzLOuw/UH8+6um9DZVy+ur9mjfM2WMI7aI2b7+9mK/QXEemIi41WNTMWC35QgkVOp3PPOniSKNLd2TQEE0NJVGCUM7jzRMuvX9oTQJb1J3CfPHZqLjN3l6WHTBkIJ1xa32VaZ3fGDMl4PE2NV0aDtTKcWCtTmYpWgfmYJyhuwvW5WIzUoOfwfvRUrEc/GZ3EQoDcEYpf/L+xFXif2lNIzGLfqPYLBg4SsqLk4kOmANy+Cieq2e7xfwRFGjlXBKT0CZdurl/yj4BPZAHbmTP5zsXE9G5e7Ya8TAZ99/IWUdc3GysKQvXanMg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 19bb8fc6-a534-4f73-e717-08da1bd54f57 X-MS-Exchange-CrossTenant-AuthSource: BN8PR10MB3220.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2022 16:07:00.3084 (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: 3DDcCK4YF193afqhl+aeTxwEt5qYnsQvMssqqfH/vY6uPaCsQ8tWa4Ta9w9zjYD5OK+DVyk969neK1qkLGFtqg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4564 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.858 definitions=2022-04-11_06:2022-04-11,2022-04-11 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=821 spamscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204110089 X-Proofpoint-GUID: fxrT3nSFlHwtEcbmHonYjqmv2ZCA7UUZ X-Proofpoint-ORIG-GUID: fxrT3nSFlHwtEcbmHonYjqmv2ZCA7UUZ X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 6iebgnxss84iartzju76zbqn91ibntet Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=NsEXOxeK; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=MbWMF2YR; dmarc=pass (policy=none) header.from=oracle.com; spf=none (imf30.hostedemail.com: domain of khalid.aziz@oracle.com has no SPF policy when checking 205.220.165.32) smtp.mailfrom=khalid.aziz@oracle.com X-Rspamd-Queue-Id: 44B8580004 X-HE-Tag: 1649693263-67711 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: Lock the root inode for msharefs when creating a new file or deleting an existing one to avoid races. mshare syscalls are low frequency operations, so locking the root inode is reasonable. Signed-off-by: Khalid Aziz --- mm/mshare.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mm/mshare.c b/mm/mshare.c index b9d7836f9bd1..85ccb7f02f33 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -195,11 +195,12 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, err = msharefs_d_hash(msharefs_sb->s_root, &namestr); if (err) goto err_out; + inode_lock(d_inode(msharefs_sb->s_root)); dentry = d_lookup(msharefs_sb->s_root, &namestr); if (dentry && (oflag & (O_EXCL|O_CREAT))) { err = -EEXIST; dput(dentry); - goto err_out; + goto err_unlock_inode; } if (dentry) { @@ -232,6 +233,7 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, goto err_relinfo; } + inode_unlock(d_inode(msharefs_sb->s_root)); putname(fname); return 0; @@ -239,6 +241,8 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, kfree(info); err_relmm: mmput(mm); +err_unlock_inode: + inode_unlock(d_inode(msharefs_sb->s_root)); err_out: putname(fname); return err; @@ -264,10 +268,11 @@ SYSCALL_DEFINE1(mshare_unlink, const char *, name) err = msharefs_d_hash(msharefs_sb->s_root, &namestr); if (err) goto err_out; + inode_lock(d_inode(msharefs_sb->s_root)); dentry = d_lookup(msharefs_sb->s_root, &namestr); if (dentry == NULL) { err = -EINVAL; - goto err_out; + goto err_unlock_inode; } inode = d_inode(dentry); @@ -290,11 +295,14 @@ SYSCALL_DEFINE1(mshare_unlink, const char *, name) dput(dentry); } + inode_unlock(d_inode(msharefs_sb->s_root)); putname(fname); return 0; err_dput: dput(dentry); +err_unlock_inode: + inode_unlock(d_inode(msharefs_sb->s_root)); err_out: putname(fname); return err; From patchwork Mon Apr 11 16:05:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 12809397 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 A1D5AC433EF for ; Mon, 11 Apr 2022 16:07:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 606406B0075; Mon, 11 Apr 2022 12:07:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4C8B16B0078; Mon, 11 Apr 2022 12:07:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2570B6B007B; Mon, 11 Apr 2022 12:07:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0026.hostedemail.com [216.40.44.26]) by kanga.kvack.org (Postfix) with ESMTP id 0BACB6B0078 for ; Mon, 11 Apr 2022 12:07:46 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C5BA28249980 for ; Mon, 11 Apr 2022 16:07:45 +0000 (UTC) X-FDA: 79345078890.22.8CDA6A7 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf31.hostedemail.com (Postfix) with ESMTP id 3E1B920006 for ; Mon, 11 Apr 2022 16:07:44 +0000 (UTC) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23BFDfCB018418; Mon, 11 Apr 2022 16:07:18 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-2021-07-09; bh=8P178QoyGPQDMPSg8arws/itBJ406wm7iSMh17Tern8=; b=l+HL3Qg1M5NZs6chg9BN8TWSIryllhRAFBXgRz6B1Ivy8Ny/2sCSbVhNex67Y9MVVTQu Jli9cYf8wzPRxUGKJsvvtKEtUawT1KTmc7/XBnXH4lC7uvoh6VrrniJf1KN6gtGhe7g5 +S/IEl/dpC/pPJWPaNZDWo6lmWcEMaNUHBZ+FlLUV/jvo1pL3Bfit2LaIHIylmjT+OE0 MqJjFYjgspM67tSxElsNRh+B38b1AeYZOkjC3vMT35XdPoMvkJ8W5yrEwVDElaWBSetH wuo7ClXkcNLlZfj4jZ7/kFK5BQT7NrAXHW1nHFBfMwFOrakzOpUnjiCLMWwE7zVeBa1j EQ== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com with ESMTP id 3fb0r1c6r1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:17 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23BG1Lew006155; Mon, 11 Apr 2022 16:07:07 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2104.outbound.protection.outlook.com [104.47.70.104]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3fb0k1uvhv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WORFC8O+xgDsjx/XBgAtO11S5rj0aHdyoFwqMRQmrrOunY87CIFo7LC8zq0zIEYs/SYESNCECpAj7uvxi7BGOZlGFQZdQhfogBrepjK9hBEKO2k0PG5UR5e4sAycz09tAcVqFz/aGLfovqUkatt5RFIcxwzhJ73CVfknS4DMmAUyH5B1ar/SmoA1xpgEi4+XRi9tU2cmSfOmjlFcMsYh2ttL9Huv37E1LXiFmy1s5osuO4G1rxkqzPd92Pu6TUzLgZpF4e2GT/ui+E1tY/gE3MKR09ZIjyxNo9Bza2hyk9t9y35oh2/Xmj4leAEfuH5rBhegLuhgpaD9ltTAqrfLrg== 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=8P178QoyGPQDMPSg8arws/itBJ406wm7iSMh17Tern8=; b=WBOEkgymXx+7Wy3ncP5CBy1r21P2tP+FQrLc1lk3cimQZiCjmx0jLQBa0KVa59eOsq/Wrdc1SfCO8T/kami5/kABDGVmysUejvXXIXClByAsOAH0vrVKwhiLr9N3LBmGx2yYq6ghNgGXGoqUH0VG47tAn8Z1bPHelnXc6Ac6JI3bLhxoQY1m/5EpjQ9Yteu4D08D8jVmindw9ZyIj87aL24ybXbz4VOwbbPQBqJ1O7uiItj4Jcv7IJLj0T+9mQRyB/gi/OGYkJQ0Ax3edP8Z26fR5ginVzK2S1h0H2HVrIhCjEz/RctYv2CJE2CY2nqUifIBTJRommTKR613SWH0LA== 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=8P178QoyGPQDMPSg8arws/itBJ406wm7iSMh17Tern8=; b=dgcsg5oayF4lwY6mLcMJu0psgpavFnkC4ELa6pB2h2YAobps62slyFsVMtQZfyyx2xXIi1fG12sPmOIOy/gfkn0m0fN3NjtwZ41BXfQKdFJWfZigM/buwpg/f/dPIgL5WBsZ20cUeY/4duVBB2BFtEptM3/M5ujam8O6jy+L5Ec= Received: from BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) by CO1PR10MB4564.namprd10.prod.outlook.com (2603:10b6:303:6f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Mon, 11 Apr 2022 16:07:05 +0000 Received: from BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40]) by BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40%6]) with mapi id 15.20.5144.029; Mon, 11 Apr 2022 16:07:05 +0000 From: Khalid Aziz To: akpm@linux-foundation.org, willy@infradead.org Cc: Khalid Aziz , aneesh.kumar@linux.ibm.com, arnd@arndb.de, 21cnbao@gmail.com, corbet@lwn.net, dave.hansen@linux.intel.com, david@redhat.com, ebiederm@xmission.com, hagen@jauu.net, jack@suse.cz, keescook@chromium.org, kirill@shutemov.name, kucharsk@gmail.com, linkinjeon@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, longpeng2@huawei.com, luto@kernel.org, markhemm@googlemail.com, pcc@google.com, rppt@kernel.org, sieberf@amazon.com, sjpark@amazon.de, surenb@google.com, tst@schoebel-theuer.de, yzaikin@google.com Subject: [PATCH v1 06/14] mm/mshare: Check for mounted filesystem Date: Mon, 11 Apr 2022 10:05:50 -0600 Message-Id: <652c19b08f7cc510f70b48bfc9d522ca6fe74fad.1649370874.git.khalid.aziz@oracle.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-ClientProxiedBy: SJ0P220CA0013.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:41b::20) To BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8a94e878-f19c-4d3e-df90-08da1bd55246 X-MS-TrafficTypeDiagnostic: CO1PR10MB4564:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wYCizQyNVBoPC3G4IK16YPYIy9iGswkh70usTjQSMEdNB816Q06FVEDD9CxGMXsfJJoVN6gRm32ZzBvTykXMG947LokNPJv3qR4beadWjI8+2dhuBFy9VLvq2kbX/qc65MTZbMl8sHxHZx3h+opq9ImfaCCW9HywQtRgDkUnjOKv547HJ7uiU8AeUXIMrhbW/rLLv7QDYHWxqr15yp7k8Lxqr2PONpRU8xDoIKFynxjDcSFeM/aEoffiVjVpWXQBfLF7Hh1xSmJzG4pfuwgsQwElugV2+aNLn87WhpXbVo7gKtvcI9ejbAbAaeXqLMwa7JuqvFGE/R90sjVVq1DaJh/VzHOrK3KuPr11UJ30HiffmGfZXxKG3Ek2GrQUFktdDmMWbL/OVpcccdUffFPVbpzKpukFvp463S0OE9BglHI1DtXnHbXxXewvXSHvTnjhh5GnLCtLCZxPn67I0kWjxN9OF+OxFy5iphCesdauIf7KAC0QDf65d+s6X+gXRdf7dBc09vXdZgad/SVh6gQpLDgmYUc50vl+JAzU9Xebye3QHVeu8zyOXG/JmzrumHOxzAjZnv7+17E1PlZaVTul/8JZTteNEsacxuaq/qu9s0P/neWK9n/CTorxA50pJlDKMtMKjeCahYF9a6YCUTSIzSRbuW6YaqfQfiuM4JTo9fB1XZIjSl1MB76uYcgXoUEfFstIjBEjr1Q6XigNPDIy9w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR10MB3220.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(36756003)(5660300002)(38350700002)(38100700002)(508600001)(8936002)(4744005)(6506007)(44832011)(7416002)(4326008)(8676002)(6666004)(66946007)(66476007)(6486002)(66556008)(26005)(186003)(2616005)(86362001)(2906002)(6512007)(52116002)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GsgJFkIrnFGULmI4JYJGCdqCIbyCD7KF8oBV9r2YNHGzNL1TJF2LsF2T7GVXdnOKHAe2ubQo48RLh4k+dJoKRCmK7XRg4uGwfxZENWDVyaTk6EoiPeqQZ96xygUO9b02hJ8Wo3SgZENH78ag9UZQgFWPFbQWhLiW+r+aLvUy3Zq2s13TJxhzzAwS8Q/LJnoz3n72Z6Vk+YyzPlQA3GodW7R9nUutFIZRvuSogJ9hAPUEkuQ+b3eSRFziKNwDeR2y6jSjfcFcdktrDCCiGCN4p6v3nwuGoCsX6hnB2yEFNyB5U+O8AoFfAZBVIvcy/d5TJpIQN2CYu0OlEQD/qjy7ktZ/BAt69qJw0/WPJm7/zZf+6dgjXG03RwHvCcAT/ZltpNsPJ3CufJQrLa3qn66midE9YV4xXD/1D2WkyLDqMQslXOfD/1/Kkwcv3NmFGZIpZItfKnkH/LifM/xouAgOG0bfKgaAHqd5LyY8x0/j790a/pAkr0cE5oW9QXiz2809HBYyZAp3D9jPjZI5tMfFgADaAgGTdM6Yml/7G6vo/oKQq4Cltxk0g0VSQL+thfGsgzFecPjX8miEosJBalnGE3tR8uOaeTq0+H8OAMRTARlWxwfLAxZ7DydfX0oWizlagVfCPDZ7IG+ccztAMPWGmWGIdaGa4AjTo3PMkZbmIg53Pd0h9mFw4Z7ZVtnaxyB+8+DGtRkYD21w78SgIpHLnyIC+g/hGHQ0cTJUhKUXAkLQFuVESeNcsIpkLrGtEIkTOJLuiOBDK7LuEw1KAaahbjFpu6UIVo2GK1He3qD61Nke32/ZH79C02vbiWEz8ETo2cTowYPNtYurrVy6n7yctgfpn+P9wvdEb+N5QmOFS95NDaoZjbtQBDAah5YJlihzzrDMo5RR+xHl39LBCl/peuFpBR9a2u8+twEqg0dvktbnDbyXqwxqeZOXU/BDnIh40AiFsveAxaPaLVenUq+F/IXw94cc9oejFNSdmMtay/ZFNMoLs33w2fMXFrrjuUkpiDNFUBWgvufBrStoLfTtLJg8wCAvWBC6EBSzRpwGHDl8kt9T8LD/8N8X2pjYUvX7O3LMKJU6yErHfAhf5dykGkaWaZ2fBMBryXyB+fCw/K6mstSykjms+v4wUNXF0Ey7F6WpO6LboeyPo6ssnO/T1dx3DIswf+aCKcs+mRNhUN/YeneslcumFiiFtCevwWaMcU9PKJG75MqRsau5EtHMxAck2dVo5RzQhBftr/+5VjrEyclPe3UiBoWOJ9GCe3o3onKh4wEKhIekXYGZ33t6aRKnCVPKTTP554/OoPr8PAsy4k8IdaRvV+YloV4L9C+pBnTYbi7Pyq0skPK5zwci6gdQSjOoIiF49s0mp9SL/MPw+NrmpDmcS0ePHx+xAxZVI8Ah7knlkgQgDsREYKRcK3fLrm/v0Ai8H36bBucIG380vqPr4FzarIzM74/l5JnKA/7uoq64o2Ji+7ydjBPvq+ilbYJEdR5XE+ZBwziRx2bvRav3ZJr58Djng0yrJiIavanY0/5d+cJZcWl4hP5I4jZdOioABi2oGfAUWbcncYKm0EuUW8/0RTL/KEkagujp37co6o2lqacWwBkune5g3tN4Go2nhGwGPbddMA/SBg2PRcIeK6ANslORywArR1KrvUn+A2D7gfexVcWqoFILWnNSS59Ni3CuQLsHiEHgphVXbFxSSV7yDx/8+SEc8e3ZyCHkUZk3lOIGdmoSBsrDeg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8a94e878-f19c-4d3e-df90-08da1bd55246 X-MS-Exchange-CrossTenant-AuthSource: BN8PR10MB3220.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2022 16:07:05.2612 (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: WvtDlOx3bSPgTVJC32OR2UEQDDpeH5iKJHcYPz2V87oQlUVGW81SlZfWAd0mrtgRh7VBYAuIHmyucDXcp+BhAw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4564 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.858 definitions=2022-04-11_06:2022-04-11,2022-04-11 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 bulkscore=0 suspectscore=0 mlxlogscore=895 mlxscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204110089 X-Proofpoint-GUID: tFRCoNMVrDviBIWRJoprmPPzkO7X8M3F X-Proofpoint-ORIG-GUID: tFRCoNMVrDviBIWRJoprmPPzkO7X8M3F X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3E1B920006 X-Stat-Signature: thzzaofucc58unxoxqjcf9967kxfepnk Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=l+HL3Qg1; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=dgcsg5oa; dmarc=pass (policy=none) header.from=oracle.com; spf=none (imf31.hostedemail.com: domain of khalid.aziz@oracle.com has no SPF policy when checking 205.220.165.32) smtp.mailfrom=khalid.aziz@oracle.com X-Rspam-User: X-HE-Tag: 1649693264-283732 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: Check if msharefs is mounted before performing any msharefs operations to avoid inadvertent NULL pointer dereferences. Signed-off-by: Khalid Aziz --- mm/mshare.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mm/mshare.c b/mm/mshare.c index 85ccb7f02f33..cd2f7ad24d9d 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -176,6 +176,13 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, struct qstr namestr; int err = PTR_ERR(fname); + /* + * Is msharefs mounted? TODO: If not mounted, return error + * or automount? + */ + if (msharefs_sb == NULL) + return -ENOENT; + /* * Address range being shared must be aligned to pgdir * boundary and its size must be a multiple of pgdir size @@ -260,6 +267,9 @@ SYSCALL_DEFINE1(mshare_unlink, const char *, name) struct mshare_data *info; struct qstr namestr; + if (msharefs_sb == NULL) + return -ENOENT; + if (IS_ERR(fname)) goto err_out; From patchwork Mon Apr 11 16:05:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 12809395 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 5663DC433FE for ; Mon, 11 Apr 2022 16:07:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 788996B0073; Mon, 11 Apr 2022 12:07:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 75ED16B0074; Mon, 11 Apr 2022 12:07:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D91B6B0075; Mon, 11 Apr 2022 12:07:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 4F6CD6B0073 for ; Mon, 11 Apr 2022 12:07:45 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 226F31219FC for ; Mon, 11 Apr 2022 16:07:45 +0000 (UTC) X-FDA: 79345078890.12.3BB9E12 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf09.hostedemail.com (Postfix) with ESMTP id 636AE140007 for ; Mon, 11 Apr 2022 16:07:44 +0000 (UTC) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23BFXg43018439; Mon, 11 Apr 2022 16:07:16 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-2021-07-09; bh=+WB/0fdIoEOb4SdCFczYVLlh8JUuV6zKRrLsaUXB4S8=; b=wGo2KM5EJGvpAa8jE5EhEBf9I0joDI1x+gZeHwclDJPFwOWo/4q8NgG0Y47tu/IA6KM5 Z73u54MIwYXd336B7lcSb7lS8B9LKoSOqXZ+WipTj+K+0rBHYiSU05YK+iAMdpVi5F4R /EkOTOoOWgaEtf7RAK43/h7HiqspNHMOXRn4s8exd71H6znX05aOzkI0AkD6pBeyM/w6 jbx7hTVbf7OL7P3VUT2/92YehuSR0tILQHGlkV910V15eiNXRymVLfonFdfrvDJzeDiX EwswGIdV2ag1/u5QK0qgH+qAiDPCz9DxaTrCJHB33aPHywUuUB7fRlc9Eo5RAvqO/1WP zg== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com with ESMTP id 3fb0r1c6ry-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:14 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23BG1Ebt031259; Mon, 11 Apr 2022 16:07:12 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2170.outbound.protection.outlook.com [104.47.56.170]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3fb0k27p9w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B870uCVh/Cqazdu0qfS2CiM4Go19odVsrixgNTqz9Y0HOimkyeKgbEw45J8FBkDN5KYdbLFgpwuugY6ic8RqNsRpJ68o3yXXCpsceKdXQZmA7g6rjecAgvE3GqPibhMC2VfbwO11hqUpZDncIqN5mTNZ1qFtwIr3gvw6PADd+ArK7HCTxdT4MzgcR49JfIcg4q4A3E04LL3R2xMdvSyq5gRonCYNJKU7yn/Wr8yyl8xejo/WsjE6haxHRyIseiU94ZutAiGYQ3cffRYm2TA5m8saceIQXBn5KfODJEpdBp93eopU75hDTZa3H/DYLBZcVMz9JudPWAhP41xotqMl5Q== 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=+WB/0fdIoEOb4SdCFczYVLlh8JUuV6zKRrLsaUXB4S8=; b=h4wEyy2oKJoOBOxmKaNYIcxaohW4QMPrWsEDvW6avdPfrPbJvIhBghncORyu1bB8eLpZN/0yGAhZs6lR1UjEioT2t87CS1nxON/opwLTFQxm8Iiq/0f+ShJXAy0euWDht3jhjQeDoVi55ykPDp5ymwqcZeuK4tb+V58Q0CYsUWVXhfoofUXneuqM4t1aS3pZ1upDvoJ7uHya2N8rZ0n6wn014OS88PirPC2CRhJRGna4caTkS2woYLK+wwK0rivI8wxenbNd+inSMTsEG+w6lS8VmSd7O2YMoYsfdimhX314kweHJ2Wpdlq3lhK/bPXq/bvI9rVrKfKSeIfQMTGvVg== 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=+WB/0fdIoEOb4SdCFczYVLlh8JUuV6zKRrLsaUXB4S8=; b=xamMzkvlmvNOoMC1vWWgL6TOUs4jQMod8hlu12rSQvoXur8Sh3MXVlxiLYiN9ByH3hYluda6E1FGlh/qtnTx6gJvWAHIv15mCcZlIDEy5hfTZfBabFWjfAYp5jPVfseCOxW2V0y1b0NKaKaNJonoQvfj2qV3zaCRx1bRC1+9sLA= Received: from BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) by CO1PR10MB4564.namprd10.prod.outlook.com (2603:10b6:303:6f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Mon, 11 Apr 2022 16:07:10 +0000 Received: from BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40]) by BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40%6]) with mapi id 15.20.5144.029; Mon, 11 Apr 2022 16:07:10 +0000 From: Khalid Aziz To: akpm@linux-foundation.org, willy@infradead.org Cc: Khalid Aziz , aneesh.kumar@linux.ibm.com, arnd@arndb.de, 21cnbao@gmail.com, corbet@lwn.net, dave.hansen@linux.intel.com, david@redhat.com, ebiederm@xmission.com, hagen@jauu.net, jack@suse.cz, keescook@chromium.org, kirill@shutemov.name, kucharsk@gmail.com, linkinjeon@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, longpeng2@huawei.com, luto@kernel.org, markhemm@googlemail.com, pcc@google.com, rppt@kernel.org, sieberf@amazon.com, sjpark@amazon.de, surenb@google.com, tst@schoebel-theuer.de, yzaikin@google.com Subject: [PATCH v1 07/14] mm/mshare: Add vm flag for shared PTE Date: Mon, 11 Apr 2022 10:05:51 -0600 Message-Id: <4ee9ab4d46669c40ab3c42e97774ffab85db5662.1649370874.git.khalid.aziz@oracle.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-ClientProxiedBy: SJ0P220CA0013.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:41b::20) To BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2fb8e20a-a793-4334-ab6b-08da1bd5558b X-MS-TrafficTypeDiagnostic: CO1PR10MB4564:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ivtkJ+GDEgxorCrMzT2/Eci4iYL2UJXgW9nutIUiaumttEb6uF6FhGJO9IN7AA9leWutV34ermvKxJ/QewqgtIk5dLjRoW7P4LxwmWbfb5/CnZX86FpMxjAr74pD15vtQyJyGOfEtYrvIqBMeNEX3zZbAipQrqs1Q4AMaa/0d1prXg6UdRFhoqWGFW7DTXRZt6HOHOSfoOZLfcAkVnlpPVCZt6MmEB5pIURWf4G1L7KnM3pbH1PhRBqa6+DhtCA+WWXTUwp3qCIqrCAm6Iz/+RcgSGKyMjgwkuSi11GQlsvlofh6R8GbLLUrgWoKvOJY6P+61qwuSZKdBugtIDr0Kln51DOGL15QLX10b+R/vUmD9JfQc7RmCObGzbNSL1GJWuOyNpFgM8Z2f66a+RlNyudyrp9xZrCxS5Mn1HAFkPt4j5+bJgef1fJYjdtbAFIbsMeZQYEArrdgfld0zgZKQdZEs2uI5NRmSIhZiMc2qETt2mTczlzRkHXUgiODQy2Mz6owfQkunxxc0DW9S4TuOSYCf0rLy30YNxFqM0a0Crf+NiX8wFvk3B7GPr+fF6gPvV4RpXizrBiMx3VVnptr4S79TbS60fG9e3EdPVkL9v8GzV4sgHxlfJuNE/4jnwg2kGKuza9troI6BaaCzrwPOi7sE6VbPxgG71BhFlucbKJ3zis8ekqoTf3JzIAK+fkohrglyZ8Va0brJdTNSQVQ5w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR10MB3220.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(36756003)(5660300002)(38350700002)(38100700002)(508600001)(8936002)(6506007)(44832011)(7416002)(4326008)(8676002)(6666004)(66946007)(66476007)(6486002)(66556008)(26005)(186003)(2616005)(86362001)(83380400001)(2906002)(6512007)(52116002)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 433V5aFAuqc3XUQ8SBovOU8AcOvhShSjXpmHugebIgXXSz2O74UPZAGk4t9b499ov3Lu+rINYdN7oWFgwBYvHgoVkU1BzBlrYe1MmxMitfl80A5Vx1sRlQV6S4w57VvwI0T41zlRnLY2mKIOIOucmKD7e2xh7b+2kg+E9I1AYFewMIdNE/gkplS3Dk6mGMi+DcMw5Dj3WEukHaGf9NNxRBOLPw+QjMUlCngDtEqyRoMz+oTKN+2oeR3bx9jozq2+7ug3eEth5yhKSYyeA4TiU9I5ACyY4SMubVGKEMHs37yTRQtvKRq84tEPn0/qgo61w9Pw31V1Ni7RbqFyhk3p0zTpMpSq4opEXwQiNUqCGhiwbLAVwjwCJlPdOF9Zf/m5HPlyP3i7wlo+0uh6Vn8aRpMIRs4497SrBVeFQGJD66dOTM9yiEXEwcmw455MtMGF4WJnxR93hFbflHdC4/aD9jID937u3up6i5zVm/KeeEY5NblcCCqoInHxwOoy2XqiNADbkfB+QwP465pTFeBNVhVgxVR4V05/jYljMGl0IUGCJAGf76pr72inNkIyc0SvAVo1r91iXKkQhhgDonhSJrAiZWKp5T1uO2kozeF00Uv+hQ6d6g13bw8C6x7rlHerhzVHMyuUOjlv1DrIA8txl6MqOWPVHo6V8I40yN4Pa8kgHHXS6bIcMQhbjxhd6u6bZfU2cOdx/1l6TyYh+jnGIUBTkdQQjnzeYLmWBm+BywTuXhkDWz/B/1vn1ouA85XKSWOLztkn632k7Zq8aoIiT/FCQFwPnn8bJCEdCOcBvWyjxxJxgXAWsNSRM0NXMO1xoEIXTECQJBw/0L9SN6rziscU6nvJc2WL/o4eUVf6MQkA7p++cbISkeCuC6KZyjAJuhtkrymTEBcs/W0/RLLGljhW7a5Z52SRS7mLI3AOb8BZAFT64le69MMWQZINe3nZ/ydSA+Tfx6pCUDVg5CVT1UMkIE8Cojb0dwVblEyPupn1l3GjlzNWCDh+9Ukzf2SPjdsPiWoOGiDmd7+hZi21EJYUI+xmyQwp0+GxkE0dLf2RLwgqXo0oFp+qSmDAcfP4CWzbvuccCkjrDOmRJ2Xs9ImMGGBATeszx/T0tKlRi4GeggI+5btXboHffiRoRI8GkqMch0m953ubRhged/aJoxp5X904zSDblWKInBNQDRELNzK/qmG3h+JVnEJD8Al2mqdvk23C4ALPSy65+7wk5gLRRL8S9YnCzrmjuUJsw6MqGn9BlgEl7tU7Snwpqiu9EfAy5r1OfqBZVK+PZGE3t/AXrJjlN/gyowVGv3wQXkDXw84BQbbfUR78oBREaxWrTlemThvw1bO7wtgBN2TUj+FLXtA2I6ZjIG2P+u8yfv5nP8ent0HJPP3JW3FBKqSnG2p2v0dzufHBeZOQ7cGSjtvyYIeVETFdF7RjWg/vKyt30e6ZiFjrAZ88rvJZP+9gqeaYwlMZn1GT7++OfGqYAZjBdCyMu1u0PIjC1gnTOnNlzmVR2FbR4G70S+45bodsFAC2ZDNm0s7GO84ZfRpZRTni9s1hkH/CsOKpvW991L+antATT1Rl6moh8eu3l2FSAwnXvdToI0g7OHbeRPRfN4YlzuBzRF/VnaxEoVJnEeimCacMNDeBrwavZPwXY+Srp9/HjrIBgStSszmhk/v0Y5mOsCg3Jsl1VxbbZt3/6C0dVQ+kVBuJIT6gA+AFTJwSUfzbLpBPLp3/FGYVwvfAXA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2fb8e20a-a793-4334-ab6b-08da1bd5558b X-MS-Exchange-CrossTenant-AuthSource: BN8PR10MB3220.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2022 16:07:10.6203 (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: TKcLqdVMk2rNrYKz2+xEa3Gw90FGMkLcgg6Hpp5T+13uuPBz3JxYaKPyAnF5C2BqPKoEkwJyNt+ZbYdjv8+zRA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4564 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.858 definitions=2022-04-11_06:2022-04-11,2022-04-11 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxlogscore=643 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204110089 X-Proofpoint-GUID: Ubl1L46z2mGQYdE3yRAazbaC8cgZTqvB X-Proofpoint-ORIG-GUID: Ubl1L46z2mGQYdE3yRAazbaC8cgZTqvB X-Rspam-User: X-Stat-Signature: ut7rhi4ezg47xrppmn5h97zqnxsdkusx Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=wGo2KM5E; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=xamMzkvl; spf=none (imf09.hostedemail.com: domain of khalid.aziz@oracle.com has no SPF policy when checking 205.220.165.32) smtp.mailfrom=khalid.aziz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 636AE140007 X-HE-Tag: 1649693264-124698 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 5744a3fc4716..821ed7ee7b41 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -308,11 +308,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 @@ -354,6 +356,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 0 +#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 116ed4d5d0f8..002dbf2711c5 100644 --- a/include/trace/events/mmflags.h +++ b/include/trace/events/mmflags.h @@ -184,7 +184,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 d80300392a19..cf50a471384e 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -718,4 +718,9 @@ void vunmap_range_noflush(unsigned long start, unsigned long end); int numa_migrate_prep(struct page *page, struct vm_area_struct *vma, unsigned long addr, int page_nid, int *flags); +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 Mon Apr 11 16:05:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 12809417 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 7127AC433FE for ; Mon, 11 Apr 2022 16:08:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B0DAE8D0006; Mon, 11 Apr 2022 12:07:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A718F8D0003; Mon, 11 Apr 2022 12:07:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C0B18D0006; Mon, 11 Apr 2022 12:07:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 784508D0003 for ; Mon, 11 Apr 2022 12:07:51 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 5B74061AF6 for ; Mon, 11 Apr 2022 16:07:51 +0000 (UTC) X-FDA: 79345079142.01.EDDA74F Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf22.hostedemail.com (Postfix) with ESMTP id 83696C0004 for ; Mon, 11 Apr 2022 16:07:50 +0000 (UTC) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23BEbCeu006846; Mon, 11 Apr 2022 16:07:20 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-2021-07-09; bh=RMrjpdZVMuKH6iGTSdQT19btiD9AINjP7U0Hso/baEY=; b=m7dYV4zO4K+OQiMbAEBS61aGqqGfqVKxgTP2YVSxh13cEOiy0mvpZlsvAECGCabGnbuI LDalC2tQTtDjLcSytRM15XiC39C/jd3WMnTr/JTXptBVvumlH9Bg7iG2mmbn2Hi0DzpJ J5kI6BbbzPjDlsKThq++WIhJjxl7E7O9v1cW/NRGJy5YNzAi6+pOPzuHyZFvgjLTga3u D6jlBZeOYgFgQDyLtS8kl93hp1ge280OxX4PEAuYE8InEtmBR8ztWeaZZBWxAPjFG8YB YWBb4VfcHrmVlqo8k8lhYCZeMGip3BeRzcLJpJdHvRxkA8KOH3lFkDHYbmuXCUAh7nzm xg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com with ESMTP id 3fb1rs47dc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:19 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23BG0NYF016212; Mon, 11 Apr 2022 16:07:18 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2109.outbound.protection.outlook.com [104.47.70.109]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3fck11rxdu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eqFSzDtxLX96PAOZKyX1CVLoSozBjsJgCgdIJEOSvrcmbj0YO+Z0h/Xwo7aaC7O2R+iK9AbNt0kSz2w0k0lJDuKpuxjxU9d0xI7r1IPDfVbHP3Z3YiD21wkXdwh9/L+moNSVi1V7Uob/R0BFg3+5+RhQF8jg7+ugHmpnyBlPVhunTc8bM1WZ299f8gzYMyrADL6qP7AKpBe2BWAfL8o14PZjHTjrG665BF1x2MSWmzssCBDLvo3464EwabLxzM9Dk0X9abMPCdLshOWf4i1YcHZcyK3IMemWzGuJOW7T+JoJdAJsX/OFKekAwg/pQiqT4eYOpOUeznN1oYdOI8Jpnw== 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=RMrjpdZVMuKH6iGTSdQT19btiD9AINjP7U0Hso/baEY=; b=JCfudasCBFN3ThyvyFp5h0bHHY+siTDSUXYoNFETbHjxn+vXbNj6A+GQE65lv/RpMCzoXLGOze2JhCD+4h+MF+4BMCHc3f6DdDFMGG8zR9d9yj1xs3yP3cdrQUsU676xyHmxyQRGp1TvHPVwaN42c2dL/aJpNjGwSnBrLiXTfHUGOqu9RSqZH5zXPvILwb0g1zFpzaU85mt96XSK56Z6MDfuJwN14RWMSRM2eZj155pe/k8k6fTssQ2x00Li6EtEHELt0YI5jhJrJrliE9XZYON6Z433b7SE7AxeHGe1UdvOddfC2SK5i/7t+1XTdZxdVJPESot51FmTKY3cl+Z5jQ== 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=RMrjpdZVMuKH6iGTSdQT19btiD9AINjP7U0Hso/baEY=; b=GlKeUfPzEmW/1yUJQOfSMtc0qYGMQVKilHrKH9IU9p+Jn0E/w1gf0QxgLeAB4NCno1uxuacr0vPqs5kGz8BZxMzkWl89sArPh7rZkwApCUIN28bU6dWk/iCNdzm6HEVNdtzcsL0PVeeM6McgXxKHYf4h3Qy3ttgwABp0nYj//rI= Received: from BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) by CO1PR10MB4564.namprd10.prod.outlook.com (2603:10b6:303:6f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Mon, 11 Apr 2022 16:07:16 +0000 Received: from BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40]) by BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40%6]) with mapi id 15.20.5144.029; Mon, 11 Apr 2022 16:07:16 +0000 From: Khalid Aziz To: akpm@linux-foundation.org, willy@infradead.org Cc: Khalid Aziz , aneesh.kumar@linux.ibm.com, arnd@arndb.de, 21cnbao@gmail.com, corbet@lwn.net, dave.hansen@linux.intel.com, david@redhat.com, ebiederm@xmission.com, hagen@jauu.net, jack@suse.cz, keescook@chromium.org, kirill@shutemov.name, kucharsk@gmail.com, linkinjeon@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, longpeng2@huawei.com, luto@kernel.org, markhemm@googlemail.com, pcc@google.com, rppt@kernel.org, sieberf@amazon.com, sjpark@amazon.de, surenb@google.com, tst@schoebel-theuer.de, yzaikin@google.com Subject: [PATCH v1 08/14] mm/mshare: Add basic page table sharing using mshare Date: Mon, 11 Apr 2022 10:05:52 -0600 Message-Id: <5c96dd165d7ec3da14306b8fd857c7eb95a8c3e6.1649370874.git.khalid.aziz@oracle.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-ClientProxiedBy: SJ0P220CA0013.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:41b::20) To BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f3fbeaf0-bec7-4287-d798-08da1bd558f1 X-MS-TrafficTypeDiagnostic: CO1PR10MB4564:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: olSYWcOwGp0jZ3WzFb6wxcHTXYxZL3Mg1dWzHUWEyTE6mjirFLTk/H7J6XdtitF8nPBSQv6oRgLgsaZM5z669rNT3A5ce6UO3XDPwzXroLzomIPo+fIIJcFxUzLmGDUKPEg9fQbU/cb4VLCJc8Q3JG6Ixmk07S1+WADh6iRz/EvRtZp5Jgs+Oms9dJw2pvBdPgY3H4eCUuQMBeRaHfzmsib3lDYMglA/0s1PQbokOmvFchiQVfGiO+8MvOlrZOZMfQcMAp7g7jh4sD6DltSLBrAq73CkGOLCSgPjX5njlEpBWDHPKlgVjS4HV0FRmTjzHYfQMdK9SJoeRO96w7XSYjy6V9e6HRELRYlTcJV7VSghI0lMZCNng8NSI+CJJs+wqsz1dfL/WFEz9E4o2wUADpQyMhtW4Pv7H5TG65R5lrB2g5P/7Pq6kd1syMDiR7SHDTZ8r5aJftz2EwKCz5Ntw9LB9Hd2jY+U5cehsEGbr4s22TDXCMH66QPxPQXJOkX6RzznNdSYHzZq9qyTY16ny23L/G+4V6wdOPLtx8N/52gvauGgvi4H9gJJaubFYmMNrdmV2kxD9eJu/vigdwCbWZcexP6BCm6x+/RLK/7kQJY1qKwEnY+6cPCFoKX1ZUMGkWT9nO5Zh9IU3lwfzjkeGDPb57yALIbKxPoQALz6PnTztUX570c7oWVBtYubedSVwTpVqXTowa1sjlCfV0SF8/waOruN1p4lUIDKKXQI65Q= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR10MB3220.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(36756003)(5660300002)(38350700002)(38100700002)(508600001)(8936002)(6506007)(44832011)(7416002)(4326008)(8676002)(6666004)(66946007)(66476007)(6486002)(66556008)(26005)(186003)(2616005)(86362001)(83380400001)(2906002)(6512007)(52116002)(316002)(21314003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qnQ2HkgRtSHw96YvDitoO7BB/i+uVq1GDWw8Wl71KtKVzUCgBnYQYLkFKdtBlZBQJ2ElxrrdtEuvJpHjNnbspGvPzN2z2GYpq/sTcq00ODmcy2SzphVQmIGOuh/HorC4FlCRv0jM9pqfEVllHn5T2ATm0kQgTtPh16Bj1u4YOVYScr6/AWtyJm9HUzYqRPN7f//HSkq8YTApUcnhCIm6sck0rMYXMNpqvMzh7DKfsIpV6uVoddcKFaF2ZX57V+gff3MKuqE8j5qxjJQKdlCogf2vIDIzGoH6ycEtXB1YsftdsCJfJtaAhimUGBpKq7obG9fNIUghL6YtQ/6epdto1sPBnutt5tLXRceMh+CrrMm7E4mYnXN92k7tX7h7oQBbkoD9K8CxdVYHe7FmlNUgYLXFxEO9gmIXpoVZzrwvnw6sChtRpByt/YJdPzdtGLX0Oh1WGbbGknm2XgJIiXSZpDoqRvG8xfvX2eeYI6V9ABbnz4hqjgpEgFzIE21E0pyxTUb6x4uMztaT5fSOUJdvUHMgnbsGn1M/ig7hFs8z3upDDq+LkutvWN/XhreK3IuinNmESUGA3WHalUPNpD1waw8AtnGynQ1ccK6z1FGjZKq8yW1eRcoyxfuA9bFFq2yXxsVV0/lvHKvf1PSuQU/KyHo2nXyBR+ThNdKXz5KAjXKrLPewF9xSHfj2od08uQy6qXFfEe0wVCYSu2aU/hbt28yThansHsBi9W7KygCKRHc54/Mk4cfdiyZjNEIL4bwXf9dNjoaPk8Ggp5con+LWZc29meq60Kz9wf0z/5Qm+9Qj00mxKuE6G6ZCmgmUhpjBXS7cT+8A7dOwniRqNXRGhfYj1/XooJiJw5j41RwRPIQcMi2dUgSEz+SKJUQpPsR52kMlV3N1nujQ0Alf3/C+aLrCXblsb6IwjC2kwLiahCr5UzcQjr9/9Qg9QxMghPINBRykM460ETnux5vNoi6scxuHnVS7C0kdWQiodRrO8Oh05Gjw5epq1s9PnNd0S+J11kZh5E24mEAKfygLotJmC0GbDewtVyccPYsZWbA9C5k+3JAnH0B93Y/GaS2yXU5yylV4OTsvFfViuyA8gHmHXNCmpfrRSCNT0ErPy6Dlp6KREyeFhtn7QWSIpLb5HI7wGXjMZ8WW2e/hSt4OuvXun9pk9NQJ5/El+vXllOi4MC5gN2vpw2j0jche1lT1mT2vFGJ6azMJyTj6aNzST57wreJDyA15aSRPMcP3ia2LjgUHBwV0/4V9d2KaG/ztWQiwaVvHgx9K0eJNZR9PLyqwmIsmIe7s6veqalwesjfyG+i/CtkSlfIrLEtaFira4pAOzwRSl820+OFpcbspMwNDBEessaqNXdKLbgAyXwBpI9BXTA6FRAysvVUxaAjPj2AU8oAkNvtVEGXHXy7jdvN0eUtuLPJIbhpZAQNCtm8qMew/uPM6f1ubMX8PNzpRNSPDQIWjOB6U45X4LKYuIdNshhEuYQNfPWZf9GXACibxdN+ngJfHgP8oVLTE+mGcDZrqgfeN8N08grrzCmGx65VSO0MSQcAxmT/lUKTZS0rHteLBBzZyvpIGKqNw8D+3I22MAop7jBG4EfbHRSqaGR+58Uq9/8E5+AZO36KCL0B1AXXRgmTGQIVCEm+Momwvv+Wh1w5ZqNsX9fTJ8fYA6d63/lMqkXOmK/WD53Ni/fXoqOQDNlJifew2Sx2Le2MqsjlEAfrWutJZTI57q4i7jdc/ig== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f3fbeaf0-bec7-4287-d798-08da1bd558f1 X-MS-Exchange-CrossTenant-AuthSource: BN8PR10MB3220.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2022 16:07:16.4324 (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: k7856OagrOlvoUl4fdqcNydL+FpPx7kRhIF2nCetOdtcWC2KwQJ/IHp9C1mNEL75s9jxhr5qOYEaWL64CsC+TQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4564 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.858 definitions=2022-04-11_06:2022-04-11,2022-04-11 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 suspectscore=0 malwarescore=0 mlxlogscore=803 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204110089 X-Proofpoint-ORIG-GUID: mAenxAXbAm2vzM-cAcETcPD9evHGiO0m X-Proofpoint-GUID: mAenxAXbAm2vzM-cAcETcPD9evHGiO0m X-Stat-Signature: bdqcjuksgmf1tohb6dht5ygk4cioqpds Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=m7dYV4zO; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=GlKeUfPz; spf=none (imf22.hostedemail.com: domain of khalid.aziz@oracle.com has no SPF policy when checking 205.220.177.32) smtp.mailfrom=khalid.aziz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 83696C0004 X-HE-Tag: 1649693270-710155 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: This patch adds basic page table sharing across tasks by making mshare syscall. It does this by creating a new mm_struct which hosts the shared vmas and page tables. This mm_struct is maintained as long as there is at least one task using the mshare'd range. It is cleaned up by the last mshare_unlink syscall. Signed-off-by: Khalid Aziz Signed-off-by: Matthew Wilcox (Oracle) --- mm/internal.h | 2 + mm/memory.c | 35 ++++++++++ mm/mshare.c | 190 ++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 214 insertions(+), 13 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index cf50a471384e..68f82f0f8b66 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -718,6 +718,8 @@ void vunmap_range_noflush(unsigned long start, unsigned long end); int numa_migrate_prep(struct page *page, struct vm_area_struct *vma, unsigned long addr, int page_nid, int *flags); +extern vm_fault_t find_shared_vma(struct vm_area_struct **vma, + unsigned long *addrp); static inline bool vma_is_shared(const struct vm_area_struct *vma) { return vma->vm_flags & VM_SHARED_PT; diff --git a/mm/memory.c b/mm/memory.c index c125c4969913..c77c0d643ea8 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4776,6 +4776,7 @@ 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; __set_current_state(TASK_RUNNING); @@ -4785,6 +4786,15 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address, /* do counter updates before entering really critical section. */ check_sync_rss_stat(current); + if (unlikely(vma_is_shared(vma))) { + ret = find_shared_vma(&vma, &address); + 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)) @@ -4802,6 +4812,31 @@ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address, else ret = __handle_mm_fault(vma, address, flags); + /* + * 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; + } + + if (release_mmlock) + mmap_read_unlock(current->mm); + } + if (flags & FAULT_FLAG_USER) { mem_cgroup_exit_user_fault(); /* diff --git a/mm/mshare.c b/mm/mshare.c index cd2f7ad24d9d..d1896adcb00f 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -17,18 +17,49 @@ #include #include #include +#include #include #include #include struct mshare_data { - struct mm_struct *mm; + struct mm_struct *mm, *host_mm; mode_t mode; refcount_t refcnt; }; static struct super_block *msharefs_sb; +/* Returns holding the host mm's lock for read. Caller must release. */ +vm_fault_t +find_shared_vma(struct vm_area_struct **vmap, unsigned long *addrp) +{ + struct vm_area_struct *vma, *guest = *vmap; + struct mshare_data *info = guest->vm_private_data; + struct mm_struct *host_mm = info->mm; + unsigned long host_addr; + pgd_t *pgd, *guest_pgd; + + host_addr = *addrp - guest->vm_start + host_mm->mmap_base; + pgd = pgd_offset(host_mm, host_addr); + guest_pgd = pgd_offset(current->mm, *addrp); + if (!pgd_same(*guest_pgd, *pgd)) { + set_pgd(guest_pgd, *pgd); + return VM_FAULT_NOPAGE; + } + + *addrp = host_addr; + mmap_read_lock(host_mm); + vma = find_vma(host_mm, host_addr); + + /* XXX: expand stack? */ + if (vma && vma->vm_start > host_addr) + vma = NULL; + + *vmap = vma; + return 0; +} + static void msharefs_evict_inode(struct inode *inode) { @@ -169,11 +200,13 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, unsigned long, len, int, oflag, mode_t, mode) { struct mshare_data *info; - struct mm_struct *mm; struct filename *fname = getname(name); struct dentry *dentry; struct inode *inode; struct qstr namestr; + struct vm_area_struct *vma, *next, *new_vma; + struct mm_struct *new_mm; + unsigned long end; int err = PTR_ERR(fname); /* @@ -193,6 +226,8 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, if (IS_ERR(fname)) goto err_out; + end = addr + len; + /* * Does this mshare entry exist already? If it does, calling * mshare with O_EXCL|O_CREAT is an error @@ -205,49 +240,165 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, inode_lock(d_inode(msharefs_sb->s_root)); dentry = d_lookup(msharefs_sb->s_root, &namestr); if (dentry && (oflag & (O_EXCL|O_CREAT))) { + inode = d_inode(dentry); err = -EEXIST; dput(dentry); goto err_unlock_inode; } if (dentry) { + unsigned long mapaddr, prot = PROT_NONE; + inode = d_inode(dentry); if (inode == NULL) { + mmap_write_unlock(current->mm); err = -EINVAL; goto err_out; } info = inode->i_private; - refcount_inc(&info->refcnt); dput(dentry); + + /* + * Map in the address range as anonymous mappings + */ + oflag &= (O_RDONLY | O_WRONLY | O_RDWR); + if (oflag & O_RDONLY) + prot |= PROT_READ; + else if (oflag & O_WRONLY) + prot |= PROT_WRITE; + else if (oflag & O_RDWR) + prot |= (PROT_READ | PROT_WRITE); + mapaddr = vm_mmap(NULL, addr, len, prot, + MAP_FIXED | MAP_SHARED | MAP_ANONYMOUS, 0); + if (IS_ERR((void *)mapaddr)) { + err = -EINVAL; + goto err_out; + } + + refcount_inc(&info->refcnt); + + /* + * Now that we have mmap'd the mshare'd range, update vma + * flags and vm_mm pointer for this mshare'd range. + */ + mmap_write_lock(current->mm); + vma = find_vma(current->mm, addr); + if (vma && vma->vm_start < addr) { + mmap_write_unlock(current->mm); + err = -EINVAL; + goto err_out; + } + + while (vma && vma->vm_start < (addr + len)) { + vma->vm_private_data = info; + vma->vm_mm = info->mm; + vma->vm_flags |= VM_SHARED_PT; + next = vma->vm_next; + vma = next; + } } else { - mm = mm_alloc(); - if (!mm) + unsigned long myaddr; + struct mm_struct *old_mm; + + old_mm = current->mm; + new_mm = mm_alloc(); + if (!new_mm) return -ENOMEM; info = kzalloc(sizeof(*info), GFP_KERNEL); if (!info) { err = -ENOMEM; goto err_relmm; } - mm->mmap_base = addr; - mm->task_size = addr + len; - if (!mm->task_size) - mm->task_size--; - info->mm = mm; + new_mm->mmap_base = addr; + new_mm->task_size = addr + len; + if (!new_mm->task_size) + new_mm->task_size--; + info->mm = new_mm; + info->host_mm = old_mm; info->mode = mode; refcount_set(&info->refcnt, 1); + + /* + * VMAs for this address range may or may not exist. + * If VMAs exist, they should be marked as shared at + * this point and page table info should be copied + * over to newly created mm_struct. TODO: If VMAs do not + * exist, create them and mark them as shared. + */ + mmap_write_lock(old_mm); + vma = find_vma_intersection(old_mm, addr, end); + if (!vma) { + err = -EINVAL; + goto unlock; + } + /* + * TODO: If the currently allocated VMA goes beyond the + * mshare'd range, this VMA needs to be split. + * + * Double check that source VMAs do not extend outside + * the range + */ + vma = find_vma(old_mm, addr + len); + if (vma && vma->vm_start < (addr + len)) { + err = -EINVAL; + goto unlock; + } + + vma = find_vma(old_mm, addr); + if (vma && vma->vm_start < addr) { + err = -EINVAL; + goto unlock; + } + + mmap_write_lock(new_mm); + while (vma && vma->vm_start < (addr + len)) { + /* + * Copy this vma over to host mm + */ + vma->vm_private_data = info; + vma->vm_mm = new_mm; + vma->vm_flags |= VM_SHARED_PT; + new_vma = vm_area_dup(vma); + if (!new_vma) { + err = -ENOMEM; + goto unlock; + } + err = insert_vm_struct(new_mm, new_vma); + if (err) + goto unlock; + + vma = vma->vm_next; + } + mmap_write_unlock(new_mm); + err = mshare_file_create(fname, oflag, info); if (err) - goto err_relinfo; + goto unlock; + + /* + * Copy over current PTEs + */ + myaddr = addr; + while (myaddr < new_mm->task_size) { + *pgd_offset(new_mm, myaddr) = *pgd_offset(old_mm, myaddr); + myaddr += PGDIR_SIZE; + } + /* + * TODO: Free the corresponding page table in calling + * process + */ } + mmap_write_unlock(current->mm); inode_unlock(d_inode(msharefs_sb->s_root)); putname(fname); return 0; -err_relinfo: +unlock: + mmap_write_unlock(current->mm); kfree(info); err_relmm: - mmput(mm); + mmput(new_mm); err_unlock_inode: inode_unlock(d_inode(msharefs_sb->s_root)); err_out: @@ -294,11 +445,24 @@ SYSCALL_DEFINE1(mshare_unlink, const char *, name) /* * Is this the last reference? + * TODO: permission checks are needed before proceeding */ if (refcount_dec_and_test(&info->refcnt)) { simple_unlink(d_inode(msharefs_sb->s_root), dentry); d_drop(dentry); d_delete(dentry); + /* + * TODO: Release all physical pages allocated for this + * mshare range and release associated page table. If + * the final unlink happens from the process that created + * mshare'd range, do we return page tables and pages to + * that process so the creating process can continue using + * the address range it had chosen to mshare at some + * point? + * + * TODO: unmap shared vmas from every task that is using + * this mshare'd range. + */ mmput(info->mm); kfree(info); } else { From patchwork Mon Apr 11 16:05:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 12809418 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 18A39C433EF for ; Mon, 11 Apr 2022 16:08:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 98A9F8D0007; Mon, 11 Apr 2022 12:07:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 90E268D0003; Mon, 11 Apr 2022 12:07:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6EAC78D0007; Mon, 11 Apr 2022 12:07:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0245.hostedemail.com [216.40.44.245]) by kanga.kvack.org (Postfix) with ESMTP id 5E2088D0003 for ; Mon, 11 Apr 2022 12:07:52 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2296A8249980 for ; Mon, 11 Apr 2022 16:07:52 +0000 (UTC) X-FDA: 79345079184.28.6CA98D5 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf21.hostedemail.com (Postfix) with ESMTP id 3A8021C000B for ; Mon, 11 Apr 2022 16:07:51 +0000 (UTC) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23BFdIBI008887; Mon, 11 Apr 2022 16:07: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-2021-07-09; bh=qgqm9y1TOCO2CnDqhxzRfjgnFASSEF5K68HB+lhriDg=; b=pxnwAjcZ1UIjSDJ0gKp80tn4Afci5+9KOgh+HUAI0JmFT3y0ZKfBOEadqvdfPtOqubLh I7earrUJXCpJtLiWgSeVD2SOyHdIHddDLHkJzbLgf7Cm6c1lDKVmH8BNIzE4HYP2Q8k4 NZ0JpIvA48KGVJB/J8SU/xLq3kNWG2nakmjcS78gyxXbjBoGTGSyi1chE/jJ2uBr6+fk 6GFE8bMLKgAOBmPAHXMldWhOpo3Tg9NuB9nNfQGcloTmmSa00OssyMExsBHOeJ9xswAp WaputyOHpe/jbWeRggzUiodvtItX7dbdNNv83Ru9G04tyVU9DVoZlxotFqkqcDjjabc7 Ig== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com with ESMTP id 3fb0x2c74a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:24 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23BG1K7Q006050; Mon, 11 Apr 2022 16:07:24 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2174.outbound.protection.outlook.com [104.47.56.174]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3fb0k1uvqg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XU2YH3KqabHeYIQ3A0YEwIJJYSWUiDHkvdB8gVIvCTkCm3RJUmPXNxBrMqmfD1dLV8iXF3YK4PI3dpudYmm5H2Z0808xyYXy330IxZne3V2+CWP34v+8M0TVEv8jlenChRZfyiExjjb/2xXNDYb27GdWh8zMAxZj7tHUZwDKPHN7LzuImJmspSCmW4/KKHo9AB4Og0fypdeNIgVy0Z5IL25bHKw5uUeL6pO487YWt+1Sqj5+AQkGi2pGj/wGd3bC0MdXPFprXKLj1v1ue1/0JlNOlL+dObCz2fpbqq6JlFooLLKUelV95cQ/jv/uu11SFpFrocssCi2VunSkKLJI4w== 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=qgqm9y1TOCO2CnDqhxzRfjgnFASSEF5K68HB+lhriDg=; b=lqjfBxrWgLjNKrLLQirvha9coIXwPcEm4Zg7b+eNf5evma2rChO8FWO0jPegCiR3SIdurUjkLfP4Q1/ZmRvrg1Qoq0KNV3dsOM6FqWjlZ4x1dY6a4eKuD1tAmfsT4jPlPlO6yfNZVOdkfFQVx5iCIHUgmJXCEHmjz4LF+ELNMQxDj5N/hIiamD+qxHL4xFjaNFw7fM8Cfcl1nnsDRxpsZDYAavXqTHKU7aWRZ8IMpkbTNLY3t0/XTWqncm0d2BulKboWTQ+fML/6RMKg0TTiCy0rH1o5mNhHebhEstZUP3Nrurx4nfQRwc38+fk+w5Ewjf4Q3jVZpkhC4N3shExMuA== 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=qgqm9y1TOCO2CnDqhxzRfjgnFASSEF5K68HB+lhriDg=; b=NZU2n2uAQ8FhalHUBXQlorvcl2+8PmHt3S3+eWfCAPZzUDf/dVTUmk2vWcFAewXbzO+EdcyYB5+DWf4mTpVuEqUGfTpQNfwEKWGqwFPOHBZ/s92o4NTN2aKeqyOTEUZfwhpYcui1jOjsOYOxFZx6ZduxD94UVIjhfxx/p0rOx18= Received: from BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) by CO1PR10MB4564.namprd10.prod.outlook.com (2603:10b6:303:6f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Mon, 11 Apr 2022 16:07:21 +0000 Received: from BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40]) by BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40%6]) with mapi id 15.20.5144.029; Mon, 11 Apr 2022 16:07:21 +0000 From: Khalid Aziz To: akpm@linux-foundation.org, willy@infradead.org Cc: Khalid Aziz , aneesh.kumar@linux.ibm.com, arnd@arndb.de, 21cnbao@gmail.com, corbet@lwn.net, dave.hansen@linux.intel.com, david@redhat.com, ebiederm@xmission.com, hagen@jauu.net, jack@suse.cz, keescook@chromium.org, kirill@shutemov.name, kucharsk@gmail.com, linkinjeon@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, longpeng2@huawei.com, luto@kernel.org, markhemm@googlemail.com, pcc@google.com, rppt@kernel.org, sieberf@amazon.com, sjpark@amazon.de, surenb@google.com, tst@schoebel-theuer.de, yzaikin@google.com Subject: [PATCH v1 09/14] mm/mshare: Do not free PTEs for mshare'd PTEs Date: Mon, 11 Apr 2022 10:05:53 -0600 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-ClientProxiedBy: SJ0P220CA0013.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:41b::20) To BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 70f0bed3-43d6-4b5d-308c-08da1bd55c02 X-MS-TrafficTypeDiagnostic: CO1PR10MB4564:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YHeec3W6l7UtRFrAJRZNHhDR5tWp4FM9jP0BQyqSEixLThUKpIALnouHhT73wXl4nQ+tSJ3wTkEVZZDuMF3yPdgJBR1cFHw1XN7lSpFfTwkB9kjDHEBEuTfKF/F2145b5MxSj4xsBHc95vGgmPxTv5XMCfJy+biCnRMzTl3cF7GNIYpw6CdoAwq9CbaP+1i1Vh7PYN9ijd0iBLaQvz8BGz4NHUBgmIqWLfhRcuAq2VcMaE+ymgtXu02IbvWBpQS6zD+MQbrQXF+V11cQ5ZY32+JtsMb9cRUWK/FFwGg2gZxAPgAAQetGC2+2E73m27ej9DvyIzm/jL4d9HBou0ApgBxSyBD5Vk+uEc+/6VEG0j8FiaSzN38iOmh39D8UtndWJmlrGXzNFWca8uskHxL49toKsaBiNPpQ9x+ZIKVnsM9tsulxp1EVDC1/JpEV5aX/cBTiOxagzq8OSK0sEBmtbuPqjDenGoWgzygTG8dm76Ec4UXVKM0KgL01qH8NedVLhcC3Z4tuxjJYry8/jam+y2pcfm3f+c99QGxVEw+kStCxoWQ9Iuu/9VhyN6X4UIiq6rFXlBGtfVlvyujvAKbXUtMkLTxVz+La1cVr5QBP+Ej2OoVPPe64lZo3fHEPMKEJN7JW47fruJ4r8WczRWrfbFqnk44HEfqXvo6fc8xVAyFuvcS/eTnULP8pEHfdyV3N X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR10MB3220.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(36756003)(5660300002)(38350700002)(38100700002)(508600001)(8936002)(6506007)(44832011)(7416002)(4326008)(8676002)(6666004)(66946007)(66476007)(6486002)(66556008)(26005)(186003)(2616005)(86362001)(83380400001)(2906002)(6512007)(52116002)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EH8zDaVjPrD3YUUC8pJykt92ngq5zgo/WjTkyTa1CRxgUSI7RqscSKxo09Q2ErQN9GlGa1CEmk9vwddQoFCIy7uDncqKkROGtkOj30eW+et9kCgztmmLZkaAaIzz+gZFCFcrmDcg7rtqJokoM0KAC/S6VdTFv6E9sYoWLnAMuAFLm5gB7GwQn9wMgdVZ3hzfD7JDyob7rTFUYrb47cFUkiUDhs8tAyNMINAk1wbN9kjURbPcVZhXMhVmr5Z6TN/9O1eLsBLzg1X4glOODwp0STjCS0sJ52MgvwNp+Kl3E3YbPLHUxQzKBgfqCGVsDQAZhzx7KmB9kimYnVxRdFn7K+phYRFqOxZfsQt5FJ7W8W1CV0vJP1BtgiJ22qq5wkJnyEL5Mb0NH3zvEmlTodoZDAyN5j7MKhNts+D0aP/kHDHI7tlEM6He8zDY23/2ErUFuKHAVg8HDMUndY/oPFQAh1dtiSy4dkGlUyGaZBYjwsz6jx4jCF5tUpJWgDpQLMtW7An12xBWNkH5MdMI/G+y9b/H7cK14/WTShM3YEjxgQU8ZG7lnuEwBLqbPsuEcIY40p9+obSiGsc1gXMV0N4Kk/wt7WgBNtH7qWGVec9y9q6MOAit5pwx8r0cJhGKv8kPusnodarsEh/kkT4jSI2Sm5F5tvvibpdibX8u7hAhzisNsUc2/eIEwptbAy9rvPNU+Do/pZSNxbkJBf7qAdgfKqdQDzPWOX7IOlU556VPyu+bANRqH5IJ1cuNVRwbGWR9b9XGu54ppuUtGNWOBFID96RcxbS4c9v0yl7hz2GGsiIi8ijpi8cobjp9V1mU1LLY+uHSHK3djvJ+MiMpV+Eb3LWuutEaPSPukhGFZGIBJdLc/y1T9HCmdkpdmVZye9JOfC2TxYW0WqAh2Pnwuw/RcjQ3zADiaaHRcd+fgVeT/kF+0i7bhOIJUDRZaj7UTSFmYg3DLA+uVUBz3pqMS5AEa8Bw4ahLVMjaYy86u7x134Si6fBe/0T5Z93u/PhOsg7GOY96k5HweNVhVqxQKTUNvaaF7yS82mzgkf6U14I0/uWN0NOiY6DqhaBOrXLcfn6n8+eR3obQ6Dd+Ruma2lfnQilNb0hpWI2UoVB9foRM8g0Vl9oLwSMPK51K3IAH+3duZViZjMuue11oN8wP4GDTYuRB6/7lPT9vbejnStfOz54j3nTBHiiU6IM62byI/vhAV/Yu8FIQyq0NUIxsYZ6gLITWF2RjXur0duYKrUuqZ4u1FM71/dG6hh9ZqxNtFryWZXLVAwVBqVysbXVgiX8oCLe1qdl3Gc1+X2UKB85bKRzAxHVhFZV9mHfzpkPY00w+soq8E6nfPU/50Kj3MK5dE/iFIi+RX+/lTF1z1AnTbCWJdVE1xtHUDAo+UDRk8HFzFPpFIjA8j8ZK4XttaE0RtKRi1Akhew7pNyM7TQ7XSkjmVwDYQqReLpWfLrSEgCQJBn3qKvf9PECod5ZxddVz5PanKu9TzQh4hWZ6dCa8K0DjFCgdBtXwoMITYBkxsXwZi888xKLFZ9+KndJjIGEapA+OBXCl2H+Bz8Rk757qvK/B/sC0N9Zg2eN9ACdQmJ+qOXXkDBfHUhumzOsP+a4UiCvWLxIzQemR+hibCRQYtEw2Avj5l2qn85RYBTxqY+xHfkjszrFHC31MeHu/vEOpdSljCdDBs7dQfQRFsVM27Dj5nqFvzjJiZh2lyE9DfPvyZ5MecB4wqKtTA1WUKDFeSQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 70f0bed3-43d6-4b5d-308c-08da1bd55c02 X-MS-Exchange-CrossTenant-AuthSource: BN8PR10MB3220.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2022 16:07:21.4946 (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: wgDvpTxdISB7yChkh7FpzPoMdNKYNyOn5iRUBxld3njY422QIf+25O37sRcnxTEFqZoN7Ehec9mMyM0VVjvVjQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4564 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.858 definitions=2022-04-11_06:2022-04-11,2022-04-11 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 bulkscore=0 suspectscore=0 mlxlogscore=985 mlxscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204110089 X-Proofpoint-ORIG-GUID: VRTRdpnCIcMu99bEmce5XNYtkeNCO7oL X-Proofpoint-GUID: VRTRdpnCIcMu99bEmce5XNYtkeNCO7oL X-Rspam-User: X-Stat-Signature: wjqmdgudw4ifesf3sxcrt3or7jwnu6xa Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=pxnwAjcZ; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=NZU2n2uA; spf=none (imf21.hostedemail.com: domain of khalid.aziz@oracle.com has no SPF policy when checking 205.220.177.32) smtp.mailfrom=khalid.aziz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 3A8021C000B X-HE-Tag: 1649693271-576599 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: mshare'd PTEs should not be removed when a task exits. These PTEs are removed when the last task sharing the PTEs exits. Add a check for shared PTEs and skip them. Signed-off-by: Khalid Aziz --- mm/memory.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index c77c0d643ea8..e7c5bc6f8836 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -419,16 +419,25 @@ void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *vma, } else { /* * Optimization: gather nearby vmas into one call down + * as long as they all belong to the same mm (that + * may not be the case if a vma is part of mshare'd + * range */ while (next && next->vm_start <= vma->vm_end + PMD_SIZE - && !is_vm_hugetlb_page(next)) { + && !is_vm_hugetlb_page(next) + && vma->vm_mm == tlb->mm) { vma = next; next = vma->vm_next; unlink_anon_vmas(vma); unlink_file_vma(vma); } - free_pgd_range(tlb, addr, vma->vm_end, - floor, next ? next->vm_start : ceiling); + /* + * Free pgd only if pgd is not allocated for an + * mshare'd range + */ + if (vma->vm_mm == tlb->mm) + free_pgd_range(tlb, addr, vma->vm_end, + floor, next ? next->vm_start : ceiling); } vma = next; } @@ -1551,6 +1560,13 @@ void unmap_page_range(struct mmu_gather *tlb, pgd_t *pgd; unsigned long next; + /* + * If this is an mshare'd page, do not unmap it since it might + * still be in use. + */ + if (vma->vm_mm != tlb->mm) + return; + BUG_ON(addr >= end); tlb_start_vma(tlb, vma); pgd = pgd_offset(vma->vm_mm, addr); From patchwork Mon Apr 11 16:05:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 12809419 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 A6FE8C433F5 for ; Mon, 11 Apr 2022 16:08:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B59FD8D0008; Mon, 11 Apr 2022 12:08:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE36D8D0003; Mon, 11 Apr 2022 12:08:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 873BF8D0008; Mon, 11 Apr 2022 12:08:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 6F4378D0003 for ; Mon, 11 Apr 2022 12:08:01 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 4A0A91219EF for ; Mon, 11 Apr 2022 16:08:01 +0000 (UTC) X-FDA: 79345079562.20.40BCA22 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf19.hostedemail.com (Postfix) with ESMTP id 7C7F21A000A for ; Mon, 11 Apr 2022 16:08:00 +0000 (UTC) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23BFOHmb012645; Mon, 11 Apr 2022 16:07:30 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-2021-07-09; bh=nBCu2FInS4WSs/ZQOC/7AruAxxNj1FoZwFPC3KqxaF8=; b=aqy947/x+vaFNRfBWE7S3GLatOqNk3a593vQNo1m+u/lOubkfC0Uwpfl+/qcW0zKCtxY SLImPLREtHqYLFQnL6/TO538M1foIycXDQ9pYEvuV3mfW1C7QkaXKvdZlh15c9yckNRU fKX8RU164YvfYveT9AVU5jkKXxL1k3+bSPvuseQ8VrzHDAWBTz04C+aggq7vhLgIrmBE TBCWd8wJcQ8OcLueCN10OkUlnH6BGqK+I56qgXchaRpy80c6/x/ymBJmuK6QZvEX15Ko BaTsOZSVHZnFcMj3Q8sGyUX3EmJQjESfjRvny/EX/FNIWza4L1hdyuAHNGECMSAUI0Q4 IQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com with ESMTP id 3fb2ptv6ut-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:30 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23BG1euk009845; Mon, 11 Apr 2022 16:07:29 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2177.outbound.protection.outlook.com [104.47.56.177]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3fb0k205re-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AZh0xN540CcphPrfLDayWF+4NZN3M2cwo1//LcG9cBKkuhuMZ8iBJiiB66cZFstiu8GV/rJMjtggDMgTiDaFRNP3fqlg9R9C5gzcadxeL+KmYg6D8yyHSqwxgPo+s7jDVrLNDyHqvuYTgU8oIfkJ7khnQTUfqwX8dXOqhRM1qq3rqi4EMZhOk764PROoLNJ461LgT0Dd3QF9uJQ8FNEfYFM3FW3XHwNGnGx8Nid3oiffpXpfNc/CKH5YJFz/GwCY/otfSKkw/8cI0f1j1n+N5BO4tRMf2kD0FJz8AXFsWJM0zC9sogEJAZfJyJXBrI0S05oRLY4W4ysgT+qYxtcS+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=nBCu2FInS4WSs/ZQOC/7AruAxxNj1FoZwFPC3KqxaF8=; b=awZLKAy9DQ+efSRPYLDFbQLfEo0PhiCMX7mTLZHjoUT4jblcC3soLnNjusDoWU6n2MdtWEbhZTKZjjAN9OWa6W1KgzVciiHLTiqgpJqZimRKWaX3ZBq0gcU4kBc9HRqMYvhWUw7mP1URbRCMnAb1aUCQ3ABkqhBaOPkO2aqTAAjD/KK+3zLaiDi0/W7RLPhrA4Y2CW28Cup3R3w1Haqo5Zn9T4kEmOcU8kSAkn9RqMnM/kQ54oQ57w0d6xoUvejyFx64/VUI8Pg3eCJOhf/iMUN6sCs51sFyZiCFN9zthTd1AFv955uUaFWLGxNMh1UKWs2JJiKOKoOsy2nOSb2YgQ== 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=nBCu2FInS4WSs/ZQOC/7AruAxxNj1FoZwFPC3KqxaF8=; b=PfnQnRHd31kWbYMronu1hzTYmHS1TJhuSA3CfNDBfto4yaDNMuvxkGEcGspJYdSgN+Fvd5nvuJvo77tNtEBbApvHgl+KCDcrs+8YglcmBOciHGjQmWytkFCsS/vlGXAQBeSsLlsbJ10q2vQlpwfCDZyGXhkjtZxU00gF4YT/Rfc= Received: from BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) by CO1PR10MB4564.namprd10.prod.outlook.com (2603:10b6:303:6f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Mon, 11 Apr 2022 16:07:27 +0000 Received: from BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40]) by BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40%6]) with mapi id 15.20.5144.029; Mon, 11 Apr 2022 16:07:27 +0000 From: Khalid Aziz To: akpm@linux-foundation.org, willy@infradead.org Cc: Khalid Aziz , aneesh.kumar@linux.ibm.com, arnd@arndb.de, 21cnbao@gmail.com, corbet@lwn.net, dave.hansen@linux.intel.com, david@redhat.com, ebiederm@xmission.com, hagen@jauu.net, jack@suse.cz, keescook@chromium.org, kirill@shutemov.name, kucharsk@gmail.com, linkinjeon@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, longpeng2@huawei.com, luto@kernel.org, markhemm@googlemail.com, pcc@google.com, rppt@kernel.org, sieberf@amazon.com, sjpark@amazon.de, surenb@google.com, tst@schoebel-theuer.de, yzaikin@google.com Subject: [PATCH v1 10/14] mm/mshare: Check for mapped vma when mshare'ing existing mshare'd range Date: Mon, 11 Apr 2022 10:05:54 -0600 Message-Id: <96066024c5bc0aff1d3818ec508be5901aaf15b1.1649370874.git.khalid.aziz@oracle.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-ClientProxiedBy: SJ0P220CA0013.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:41b::20) To BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2c5439e5-c76b-4f12-f87e-08da1bd55f84 X-MS-TrafficTypeDiagnostic: CO1PR10MB4564:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ru/sCGITrAh13ifiV9R7FfWe5nmp1TmgvCueL/uU1ieemY9E6frzEG5B4bkU6bP9JoD6n+bcNagQX7O+bP2DY9799QAVhEoEcJm5clkWTUk4Db5nLPCQgAtCrxaXyLxggQK4DpyGH1JZbISQqhEyI+KWp1IQ1KU76ImlPOvdYhM9FkznK+qbQaSzb3yGFsNfTuLM86+HrkyLoKLlDS6of7ZGKle8jMNs+G5DW/V0ARzE/MkvyP4NHVej9NoHfHlaWrYeQwqajrR/0SNaC6OMu34vy+yYPSk0madx+Iab7bPGfIEAH72olwSGRE7TsU6knpqsh7Dqo9av8UvYPUpRBSVtrEiGTnICklYmqe8HKdzuAzdjbP1DcSmn731LvYKjoTfQZsC+QoxnVDnFUVaTgFiiZvhZrbMJOo5LtSi28mnlKHjLpnyo9R70U5NaTxdaIyOBolIyfJ9ipMpeciIJoyWH6zpwXYRlG4Ox902P/JRdYOU2I1PZ0kflbLqQGNMG/iBDGaPibRuMNw3xmcxopRPeGg4wnO3hA1fgW5Q1miSEiBqQw0baOPgVnyDuin0OOI9WSn+RF+0cfpRB1XyNFKi+rD16f7lchIaihhpFJ6Qq7N4NoSljyWOqRNeiNCR2fQv2PUUdeY4fVH9axtW3/3hMTzJtuaKonSe0eF1D6e6HW8eoJGOf0+zNv9rfkrkSbc5GRHU9ovZtu1FTNU8Kdw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR10MB3220.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(36756003)(5660300002)(38350700002)(38100700002)(508600001)(8936002)(6506007)(44832011)(7416002)(4326008)(8676002)(6666004)(66946007)(66476007)(6486002)(66556008)(26005)(186003)(2616005)(86362001)(83380400001)(2906002)(6512007)(52116002)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UJtVQXuAK6K3bxuVsHAvXrN54CtIDnVceu0w7Nm83oTZrByfnTK7wShUpx3Ynm2tSdmB4lEaLMSekuvHPgS3axeCc4egiLp8wfc8dEXonNpCRII8rnhOM5viyu7PFwvyA8uFR1Q4Y9QDBhj+ajpe5kHxBFEKoX2S/IQfwmFYabBr3tD67hmJDa/eazotNUeRtENh9AxxFSLYqqZ6XEBtOVUk8ZVwNbgDRxGWVgGNX7dXnnGjxinyaRkdTc1d6MF5aOi98xyWJF0UKoxsyfLOMfZcRpBb8Q8oknkHwfhod7c70AA1zGnbTyOU7RtpiRTDfJOvsti81RkZtzFi321HsdNdvERTV/0FBVWoV5itrZMj+quE93sN1LYxthrefHUiqmwisNyvatSdgIbWHv9I7MaR5gssAJKWnPetEIfTUK9gTFfqLOjU1h+UakNFVBFcPNlirrRnmqpgOiaFqiaaOg19hwNUn+cF5IGHCI6lKNcurAcgoa+V+1LngNowapIDDa0u/OIr809Nq8uz1k6PMxQrnmMw2vaMi4j76O3d89DMx7JNFupHtEiTR2c4wyQvJyPV+J6d2EPnFVXq9nEmCyAbar5CeLNXcReR0JL7RNUMVI44oEgvu0UgZ1Us7Y8eo8NIC4jXXWqKptwjM8dpOc7cAMczjNLfEia0O/deKNQLTckp4Ht9oYiIDBKthZi2PAnVKX4xV1ZWof4mLbg4iwywWg50O4ws25Z9NglVyUACpsP6XIKE6f6L2GdImnATLhTV6v9dCV/J9ax3yAU9krk/J48Qh1xUfxEakNHmsLz9fpS0T5TsZ+42tHIFGFM2OuCnapMN6dHyrSul2WLFZHFZrZ7MfPB62blvKGMaoRpk9ZsZWJC0MhD18icZgyVLEXnYeRyJWMDdrFwiRvSRWso5wSvr+BHRrscxpdei/gUcU2P8ycH3MHgMo33MLo20iH3ebog7HLC3U0vKaZU77AtRu/td6Zv7Kb1WtgFVElUi97e5m7E/XKWwTPTIRWJqvLUJ1TFLnN+zpHobrLbLIGsZLFGwXGZ57JF0p4Gtf6co2TAh2bF9oL4SLk9+5nyQmAfM/I0lbz4QukMux+r/bpzO0hRbfroevVIL8YE/7LbnQK/R92CHRNeK7AbIaaTkTmFe916tAbNqEHH7aAnHER15IFDTFowptuFEvt2jUfGIm1jWGAvSEtl9BZSmIhN77/dPAoFeA2E7UhZNe697vtC+UuoYhPQOkgp3kcsga/a3c4ApzAoRmw/ICFgrCveCwjSG7VlaHoozvjUlko7U71hTDpTcYC7NNEf/WL7vO88zbluXfaapdSz6vTli/KBqFqtwvwd0ROhUVVNEzVQPx9mvXXHawlDkPuTR8iTWAvoxJOo43vj1hW6K0g9ps/4ZWvIW0PV7ZuN3h4wdp8EI9HxjdtdiZoDTvaQ6XjYhvxegDJntAqpfppPI2sXjQByWiWdWWHYgtd3nkuCz2glJnGhsNnvWu82k+pSkoZZPOQ13aCqlxp/bZec2Cfx2patYrGn6JNeXq3KjWdCShJ97xbaaSXgqsg6qFh0C3QkuJj8r9FFqVpOP65odbyjvpByoV9bwDpXd6X+Oh0lClowHpKFFtSNbycrydtyvxUx7y66PwCotirUh31G1xOMjxKAKW2PawkqWbzrKnW3gHspls5pllMRWe9q9hBRvTNbNHH1aN6IwmDxLHhHzIYLxxKKw72trweUWy64L3wQkLFFeoMF9wJpnJgOsla7iBDRtmSo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2c5439e5-c76b-4f12-f87e-08da1bd55f84 X-MS-Exchange-CrossTenant-AuthSource: BN8PR10MB3220.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2022 16:07:27.4630 (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: H3ItAGj0hgr32xc7DUAhejqfvdEgFIMP5KGUlT0sf9OMpjJGY+fDBLIT5jEOT/VNG4PJStqnjm3iLD4XLt676Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4564 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.858 definitions=2022-04-11_06:2022-04-11,2022-04-11 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=885 malwarescore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204110089 X-Proofpoint-ORIG-GUID: hbrUVbkOVquPKQ22CTZk7nMfxwqTcT6j X-Proofpoint-GUID: hbrUVbkOVquPKQ22CTZk7nMfxwqTcT6j X-Rspam-User: Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b="aqy947/x"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=PfnQnRHd; spf=none (imf19.hostedemail.com: domain of khalid.aziz@oracle.com has no SPF policy when checking 205.220.165.32) smtp.mailfrom=khalid.aziz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 7C7F21A000A X-Stat-Signature: ex9mrdw8w4apfat4gzec3r43hu8d8bhq X-HE-Tag: 1649693280-588394 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 task calls mshare() to map in an existing mshare'd region, make sure this mapping does not overlap any existing mappings in calling task. Ensure mmap locks are taken and released in correct order and in correct read/write mode. Signed-off-by: Khalid Aziz --- mm/mshare.c | 62 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/mm/mshare.c b/mm/mshare.c index d1896adcb00f..40c495ffc0ca 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -249,11 +249,24 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, if (dentry) { unsigned long mapaddr, prot = PROT_NONE; + /* + * If a task is trying to map in an existing mshare'd + * range, make sure there are no overlapping mappings + * in calling process already + */ + mmap_read_lock(current->mm); + vma = find_vma_intersection(current->mm, addr, end); + if (vma) { + mmap_read_unlock(current->mm); + err = -EINVAL; + goto err_unlock_inode; + } + mmap_read_unlock(current->mm); + inode = d_inode(dentry); if (inode == NULL) { - mmap_write_unlock(current->mm); err = -EINVAL; - goto err_out; + goto err_unlock_inode; } info = inode->i_private; dput(dentry); @@ -272,7 +285,7 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, MAP_FIXED | MAP_SHARED | MAP_ANONYMOUS, 0); if (IS_ERR((void *)mapaddr)) { err = -EINVAL; - goto err_out; + goto err_unlock_inode; } refcount_inc(&info->refcnt); @@ -286,7 +299,7 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, if (vma && vma->vm_start < addr) { mmap_write_unlock(current->mm); err = -EINVAL; - goto err_out; + goto err_unlock_inode; } while (vma && vma->vm_start < (addr + len)) { @@ -296,6 +309,7 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, next = vma->vm_next; vma = next; } + mmap_write_unlock(current->mm); } else { unsigned long myaddr; struct mm_struct *old_mm; @@ -325,11 +339,12 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, * over to newly created mm_struct. TODO: If VMAs do not * exist, create them and mark them as shared. */ - mmap_write_lock(old_mm); + mmap_read_lock(old_mm); vma = find_vma_intersection(old_mm, addr, end); if (!vma) { + mmap_read_unlock(old_mm); err = -EINVAL; - goto unlock; + goto free_info; } /* * TODO: If the currently allocated VMA goes beyond the @@ -340,17 +355,21 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, */ vma = find_vma(old_mm, addr + len); if (vma && vma->vm_start < (addr + len)) { + mmap_read_unlock(old_mm); err = -EINVAL; - goto unlock; + goto free_info; } vma = find_vma(old_mm, addr); if (vma && vma->vm_start < addr) { + mmap_read_unlock(old_mm); err = -EINVAL; - goto unlock; + goto free_info; } + mmap_read_unlock(old_mm); mmap_write_lock(new_mm); + mmap_write_lock(old_mm); while (vma && vma->vm_start < (addr + len)) { /* * Copy this vma over to host mm @@ -360,20 +379,21 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, vma->vm_flags |= VM_SHARED_PT; new_vma = vm_area_dup(vma); if (!new_vma) { + mmap_write_unlock(new_mm); + mmap_write_unlock(old_mm); err = -ENOMEM; - goto unlock; + goto free_info; } err = insert_vm_struct(new_mm, new_vma); - if (err) - goto unlock; + if (err) { + mmap_write_unlock(new_mm); + mmap_write_unlock(old_mm); + err = -ENOMEM; + goto free_info; + } vma = vma->vm_next; } - mmap_write_unlock(new_mm); - - err = mshare_file_create(fname, oflag, info); - if (err) - goto unlock; /* * Copy over current PTEs @@ -387,15 +407,19 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, * TODO: Free the corresponding page table in calling * process */ + mmap_write_unlock(old_mm); + mmap_write_unlock(new_mm); + + err = mshare_file_create(fname, oflag, info); + if (err) + goto free_info; } - mmap_write_unlock(current->mm); inode_unlock(d_inode(msharefs_sb->s_root)); putname(fname); return 0; -unlock: - mmap_write_unlock(current->mm); +free_info: kfree(info); err_relmm: mmput(new_mm); From patchwork Mon Apr 11 16:05:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 12809420 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 40F3BC433F5 for ; Mon, 11 Apr 2022 16:08:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 650948D0009; Mon, 11 Apr 2022 12:08:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 601228D0003; Mon, 11 Apr 2022 12:08:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B8EB8D0009; Mon, 11 Apr 2022 12:08:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 27DD88D0003 for ; Mon, 11 Apr 2022 12:08:05 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 01CD421228 for ; Mon, 11 Apr 2022 16:08:04 +0000 (UTC) X-FDA: 79345079730.20.3B84CE2 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf15.hostedemail.com (Postfix) with ESMTP id 2229BA000A for ; Mon, 11 Apr 2022 16:08:03 +0000 (UTC) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23BF2KeH022836; Mon, 11 Apr 2022 16:07:36 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-2021-07-09; bh=n/bDvD0sv1Kt69nE346NeZGzyJMbyg2LSEytf8HnGJA=; b=f+oD3U2lDYxDEhi13Jl5YZYvLvE5Dh41+fM50mLh5pwl+Z7ECL5F3LLazo4cj/ibeKsM 5HsOkE+ZAhK6ARVb4RRCg/Ds+QulWLvmCqt5ctnMW38Ub8MenhmUc/vrJLPgdUwCstTx CXOjQBe9Bh3LvIl5KrLPnsdCMPtvy+GnA1vmkUaWD7jCxQZEoxd415y/3wVbsqXheRbN fT7OKy2qxNdztCS8f2NZZ9QsIe7UZ1nP871sX1dgxn+Gy3DncWw1fa1yrQ5ZgH37pC+j I2el44aNAd6UWcsXE1GxXuGLcLTXU44wJyRvXffmd8F2/ehXKXSo3DGBDvLdVy9dnA0O lA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com with ESMTP id 3fb0jd442c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:35 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23BG28gP022300; Mon, 11 Apr 2022 16:07:34 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2175.outbound.protection.outlook.com [104.47.56.175]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3fcg9gdxds-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lSNMKpzVwdF6IyqeoCEn77JEoDcxH6xU+T6t8wHucpaT6aOPE4Z0dj8Z7UwUSw+dvPV0A099Nxp/+2W8vzhCqmrklMNECY3msaW7jw55YfUJuHBc1GcUStyYpg43z0myvlAuUJiENNgj30pliu5WdbEDMH7q88230iAlcpgKadt6Q0nX+ILdtX3QzpgXcArmk4zTGrEMOInStf2t+agUnV5JVILjw1p6JI2JFcMJREGwPxsIpBlkMymHUEzYV7srCA+6C5LyJ42yU/YbTv9qZOK/lfwu5WrUhWUcZ/lQ9q7Y49i3Xfx7zCeM4iEmQ+PXFSW2FkJuGvgojnj4TxN4Kg== 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=n/bDvD0sv1Kt69nE346NeZGzyJMbyg2LSEytf8HnGJA=; b=XqcHYJDoDxHnrU4+SQx8BfvVTqQYiCqWTIaGn3/g/JosCNeDyfKS67k4/j+VbUvjxpx6DekCbKgLFZI7S1FAlVLW7NN/rzDAgwgv7q0S7aBr/0iDiiBPdyXUlKkaNegSibg+rX44qQk0o39JXFCLD1MegfidUZ/h5c3mqOy+fPgZoakgPqpq2dcPw+waqJh99XdOVepdPn7+jN/LWIoqVjSRYhHwemsKSkQb+ftd8fVCLRTUxJJjzgeLGRnDIrOjFdkXNWkZaVQJJhVMFa6/EmFPlcSXqH2LuD1qn1HXuc00Kuyd8gT0Rm81J/xA5lvQYsT19fo6NOv87mZ4Y8tKpw== 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=n/bDvD0sv1Kt69nE346NeZGzyJMbyg2LSEytf8HnGJA=; b=gEQuO01JkCxZlH3B72JXVQVb7n3o6gQjAMnMHyTrXiDKU1jLp0obsglZKatRC2n72O55D8LQ3zhVn2H5TRi5ZOlVlOFwp85Y7ZltGIdzXLucvf+k2r2L7IKCuNEiJxhgKO0PtLrfEPNVcannH1K4815hsJ+kxdS0QeTvNvEpNCk= Received: from BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) by CO1PR10MB4564.namprd10.prod.outlook.com (2603:10b6:303:6f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Mon, 11 Apr 2022 16:07:32 +0000 Received: from BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40]) by BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40%6]) with mapi id 15.20.5144.029; Mon, 11 Apr 2022 16:07:32 +0000 From: Khalid Aziz To: akpm@linux-foundation.org, willy@infradead.org Cc: Khalid Aziz , aneesh.kumar@linux.ibm.com, arnd@arndb.de, 21cnbao@gmail.com, corbet@lwn.net, dave.hansen@linux.intel.com, david@redhat.com, ebiederm@xmission.com, hagen@jauu.net, jack@suse.cz, keescook@chromium.org, kirill@shutemov.name, kucharsk@gmail.com, linkinjeon@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, longpeng2@huawei.com, luto@kernel.org, markhemm@googlemail.com, pcc@google.com, rppt@kernel.org, sieberf@amazon.com, sjpark@amazon.de, surenb@google.com, tst@schoebel-theuer.de, yzaikin@google.com Subject: [PATCH v1 11/14] mm/mshare: unmap vmas in mshare_unlink Date: Mon, 11 Apr 2022 10:05:55 -0600 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-ClientProxiedBy: SJ0P220CA0013.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:41b::20) To BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 884ea063-ea31-4e39-161d-08da1bd5629a X-MS-TrafficTypeDiagnostic: CO1PR10MB4564:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kZNVjujnqM7bek/baaMbwaBKyeH9qrHZURn+cAstw1bCFx4gqZ6cNNvRZPG42rhj8gELU6L0HaXf7ur8hqwede5BmGvoJbDgNDW+xg5pJBjtqLsx0SoPwp+wr44lzk09HWkEJF8iNTvMLpKffgDQCmJ+zJPAL3LXX8W1qe0PMGJy/NYoMg9JGykyBe2QZ0xAkAMMm0rtPyYsiyplO82auRABNTp0RkjhRjip7y2OY4miZHyM7f3w068V/xI5DT7j+cxc6sboPbEHa2IIVn5KagqlPqa+kqIJIk18HWSrgKOfHGC5v1Xm7oM5JYQ0yLjoADOIU1H6tCoLmoiq4N8xPaJLeJgaocB+upFk0Z6co8j24HJHAD7izYOOrMadNV9uKG1QVgl92FEJcHqoJXA1wouejc6t1dIhnFeH5aU0DLEh6JkvwImOJsHF0WrwpS4uXVC1ICctBGNdP0wdMTRzK0bF5Er/2S/yXurF9Ok2KyPnhmz+qJlvzcu92/im2x737ndRjzfc91Iets3KgAZAIltOQsv1yVAsTtt74G+Ad7gArsnxbboXGuW7LARmGc5OQzVsRkIVE4AMJ7vAqUyCCVIGurYWTviBgPzXj0jRHxRh2/McyvmbLnF9e2IcmDZep0GDNv17JBv9kPx07hqxfg/PPoP5DHz7fUWafHYHmX/EcueTscqHdPloVLrQGctVEG7eD801GFGwcbfw3mDHsg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR10MB3220.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(36756003)(5660300002)(38350700002)(38100700002)(508600001)(8936002)(4744005)(6506007)(44832011)(7416002)(4326008)(8676002)(6666004)(66946007)(66476007)(6486002)(66556008)(26005)(186003)(2616005)(86362001)(2906002)(6512007)(52116002)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: F45v9g1aCCvyPODFWzgygRE4oYZNxZ1OEhJ+MBmv6Uf2dWtJPW1WAu1+8lzR0cN16aNthl2UAypk6GcURaAg64H/GCoVoW9BFxp9IZo6OTVxcgHETLGV49Lc3KQxjlu0SE3YvSTl/Ek5JvOE8/S2+ZmOJiglr78v2c5S21VuD6ONESOuZdPGq5PSZx/oTaGtiITApJiGVEK6yLAQhVCdGmVxXEAs+4N7zC7Gq+4X8uuOobMnjVHN2Lbo2+PhXAVX82n81Yqs3tF4QDKQ9Lz7yaVkBMaHdJoRK0fl8gPk0BF0m30IoMUFa6qMqbQ68hj25M0YnFIIgyHbjENhPSWH8CnIk3jWMnM7b4gUp98FMzlCyZtLQNOm1gUYeYLj57bTLdJKVR6wSeDeB8wS7m5l/AVtfSF2+/rUxf83RwnrCAwTvY4heL1ijvBDzLMgWhinRSHVRKb34whR32eNt3G9Wk+5EtwaJprMxz3nXKC5q0nj6eoGrxWYHcRCxbzRi2ldjeJ72sHL9TT7q95TelAuq+W8V7hWIk0zlC5c17wGW2ZH8x6oY58wKAPmG8mTuFEHX0pkXzsqfwrKjo+8Ja4UCK3h/OUQ1DYG/U4ELSBKh811i8xBgdSq5vWPXTGuaTj0eTnevqzVp70rYwFGSgGd68WYyz6cMnBiAaqktztprDF6bmPQyK95uMF3DNqyPzmrbVcqhM+Lk2j02sIgNQQHKkW9qsAeSc0l1K4Oq65sucSYRkJHej7/TWMrK3Ju4TtyJDMkyfdj5Gg9yCmeZwiJGStVaY3OnpY2QXHxng5LEDdeMRjm+eOEaPquQ4shGqFE59tOwV3Ob9EzpOQhSaO/JpeTk1aqe8UDm/YvTPbh7jToQyINvWlMjCHS4yvduzEliUZW2oWkGf4i4Cfv22Hs7Mgz9jYpY2hvuEQFmCY4VtaMD0iyOrPCZuPwuVAiCN3I7TghIZPSdaYgQ49vuTqjKk65Z6X22b0+qLv32Crggypr6zyElfyxQ3Rfi+8sVWrvDvNe5ATOpUAHMUlsKoo9hYR3EYEiGxfwqai6g/Dw8V6QsosyVRupi5fis14qhB1XE2yVKpY5lKl0krkhdPnzc3pmL8n35XGlLk4DjNp/qmRSdDHOqRamkptW/y2nrwmcAM7M+XTaWKu+Mc5PeH+lLzoUK/W0zjfBf+YOEEdt1Sdhsp7vNH5HNOEB1AVrg+yR0rZ07bpCZozvETrdJ2ro2lHFZe0wawB9ubcTYP1pOrUTGHy8sweYs9YR7jpbWUGc2p1VcGH3DLtCld79MyXdYrWE3aeefcu7/EPBYxwCJlxN2ROklzIV38zKrjKamXYF6opdQtztHbtxR95wcKCE2jszRIMR+7YvLekA8gC93BpeaUeHl4CEbEHEdhR8j4mFx61lxVd9ruG6VXP0Bu3ds+1/x1cJeUofEVBpJQ9BBG4+ojPMnbYowZe1LSkfNwUQMlnxQr3+lYzlD6y5RnNis0MAlkIrzvJ2zocE1duJgk29/uS0F2/chXZOUCB4Gmf73qSEGSG7aUcr0Idmz/3nCcSRAhEVpeqdhDMWJQuRQJsc3BqxBy+GMIIpSWtSqppL2xqPhRSWVoK6K4h43U52awfZlkRpIOV8ur+E5cAdqiqq7E5HsuyL79asoFDQMERZrAqzji7OtzW93EkGW2ON3SD3wOtsPySPNdSzYcgpOsTw5F+ht7nR7D1kc9/JLpUdBi71mGHJxOBGxY2QvgZVC17LYTyPqEm+GYawIem1bsY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 884ea063-ea31-4e39-161d-08da1bd5629a X-MS-Exchange-CrossTenant-AuthSource: BN8PR10MB3220.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2022 16:07:32.5564 (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: WOl9sN1Bsq8Wv5HgAvxh+Y2erXM20rHgCaFmBEo/tpKu4Q72x8xldDt42JoGW5/EFK28Ks4EmoJZbpDqTLMpFw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4564 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.858 definitions=2022-04-11_06:2022-04-11,2022-04-11 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=929 spamscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204110089 X-Proofpoint-ORIG-GUID: goWhaugfxPE19_fKgHV3pPSZr0CitvQX X-Proofpoint-GUID: goWhaugfxPE19_fKgHV3pPSZr0CitvQX X-Stat-Signature: ffp8c8myoecu7fkks3psukeqdgjcjxdc Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=f+oD3U2l; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=gEQuO01J; spf=none (imf15.hostedemail.com: domain of khalid.aziz@oracle.com has no SPF policy when checking 205.220.177.32) smtp.mailfrom=khalid.aziz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 2229BA000A X-HE-Tag: 1649693283-158868 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: mshare() maps in vma for the calling task. These vmas should be unmapped when the task calls mshare_unlink(). Add minimal code to unmap vmas. Signed-off-by: Khalid Aziz --- mm/mshare.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mm/mshare.c b/mm/mshare.c index 40c495ffc0ca..ec23d1db79b2 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -490,6 +490,17 @@ SYSCALL_DEFINE1(mshare_unlink, const char *, name) mmput(info->mm); kfree(info); } else { + /* + * TODO: If mshare'd range is still mapped in the process, + * it should be unmapped. Following is minimal code and + * might need fix up + */ + unsigned long tmp; + + tmp = info->mm->task_size - info->mm->mmap_base; + if (info->host_mm != current->mm) + vm_munmap(info->mm->mmap_base, tmp); + dput(dentry); } From patchwork Mon Apr 11 16:05:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 12809423 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 878C7C433EF for ; Mon, 11 Apr 2022 16:08:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6EDCE8D0003; Mon, 11 Apr 2022 12:08:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 64F616B007D; Mon, 11 Apr 2022 12:08:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A36A8D0003; Mon, 11 Apr 2022 12:08:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 3535B6B007B for ; Mon, 11 Apr 2022 12:08:20 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 1338281BA8 for ; Mon, 11 Apr 2022 16:08:19 +0000 (UTC) X-FDA: 79345080318.11.59478FB Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf07.hostedemail.com (Postfix) with ESMTP id 2A68940007 for ; Mon, 11 Apr 2022 16:08:18 +0000 (UTC) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23BFHY0X031505; Mon, 11 Apr 2022 16:07:41 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-2021-07-09; bh=YhE3xCRhDl83CgVHZp6Hx3ndO5DT70PDuQLRUUmNerM=; b=lU4//b9Y5dFRjiQVuU2JpgVrsjzDs3FZRS83Sd7dWsXAxeE/vz4W6FH8drjQ7BDM/vBz sk/sFZtKnbZ7anoa7Vx5115NkuqUmDrPIcqdTO7FwvfHN7sWb2tuN+SXukUQ4PhrofCP g87mv/qYm99fL/cHHnGFzEncbhGO6OYx7Uj4OXkMi5+6xnZDi4ip61ADNe3k/2d2DPfw 66AgvjeQvPq7c/b2MeVo84ESs2vugm2mvo3HOFHU7uTlUqleK2JdmUEydPMJBmMPm4kZ it+WQCreAM9anrA30qSlV941bQvlU+y9npM3OhGyqbdfu/XGZsl5nTnbN8/zKH6HVha5 iw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com with ESMTP id 3fb1rs47eu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:41 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23BG19vj032959; Mon, 11 Apr 2022 16:07:40 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2175.outbound.protection.outlook.com [104.47.56.175]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3fb0k1kf0c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eFyHxS4Qa83gV5nyMUm0EKa20BOFGLK/QtQVN2QKIrDqaNMyBrr9z5M8u3qP9/3bQdwrvs5hIa87NI7wNDfg7IehJAZCw8na7ucLI978dsBtn0hYNNF7sJW4lOhBJHBE6hG5oV1ZMHkf0mo5IofDFX5yNiXA99zOd63Bdo1XUDWid0PmNAd/7W1a5HeO72bC8jzTESdMprkfCzdHSrC3+/wmacM5TcvvGiCxLo/VptjZs7JkAvXSzVOhwlR9BZIE/kIi8AcsTYiQS8EJLehe62a0AKu8cItgVMqJLb/dkdaEOH2B86bqtkTMov1CN739hp5FVf0DkUBp57R1bWArlg== 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=YhE3xCRhDl83CgVHZp6Hx3ndO5DT70PDuQLRUUmNerM=; b=ezRjpT5k7J/+JQE+1u+a6tne5wTRZGxK4ZnKNXNvo+rsw9zB7oR2vcRLInuK8txUgt405vs6Jg8hLBLJ3VhGWDCH2jIRY9IfUKkhZNrCDLxYBiQxuqoTtEjCbxjDaK2q9ZAORJWyVbVe991WHbhwV5GXpliN6RcYo4Va4nLJHKnBQsu/P385CjSM/2p6HJjXh826+8uqvEt8avotjMqcHDxN83ao1aEyk/0dNS+sI8V5JATnUEZ+51Y/zOGcGys6/n3fvEnHqpb5iZrYcOtdT4jCngkL3AHo8cWIZawzsaoARxaiDtmOMEAuEOs9cRLkWqa35AtcpzgXeCtFRopqWw== 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=YhE3xCRhDl83CgVHZp6Hx3ndO5DT70PDuQLRUUmNerM=; b=bAYxneiOLjftNDE+q9A21shHrqVjLDtafago3n6I5ZB0bgHzgo7B3CzU+p8LQtUVaNnm9o74pNHqEgGxEan7G4EO2E4Nn8YR32mWYpJQRNnAUVV6gHqiOLc+Nq1XLLdal8pUA6cz4PAKGZeYtKhXsZJUbY/+oGqdSxiAhR/el7Y= Received: from BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) by CO1PR10MB4564.namprd10.prod.outlook.com (2603:10b6:303:6f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Mon, 11 Apr 2022 16:07:37 +0000 Received: from BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40]) by BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40%6]) with mapi id 15.20.5144.029; Mon, 11 Apr 2022 16:07:37 +0000 From: Khalid Aziz To: akpm@linux-foundation.org, willy@infradead.org Cc: Khalid Aziz , aneesh.kumar@linux.ibm.com, arnd@arndb.de, 21cnbao@gmail.com, corbet@lwn.net, dave.hansen@linux.intel.com, david@redhat.com, ebiederm@xmission.com, hagen@jauu.net, jack@suse.cz, keescook@chromium.org, kirill@shutemov.name, kucharsk@gmail.com, linkinjeon@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, longpeng2@huawei.com, luto@kernel.org, markhemm@googlemail.com, pcc@google.com, rppt@kernel.org, sieberf@amazon.com, sjpark@amazon.de, surenb@google.com, tst@schoebel-theuer.de, yzaikin@google.com Subject: [PATCH v1 12/14] mm/mshare: Add a proc file with mshare alignment/size information Date: Mon, 11 Apr 2022 10:05:56 -0600 Message-Id: <65c4e9a0d4e47e11e1ee4b9a11aec9b3ecc77067.1649370874.git.khalid.aziz@oracle.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-ClientProxiedBy: SJ0P220CA0013.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:41b::20) To BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e00e369c-451d-4dfd-4a07-08da1bd56584 X-MS-TrafficTypeDiagnostic: CO1PR10MB4564:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TChp19bMds3Iu5f6Nlx8e4gwjALzWvyaGirXvAV3Et03UFHlDnkrqA54P9jAILQgxI3yBR4iU9gKEtMnJqpe4GA38PKizQQgB+fyfZC+g8FKPyTq8uqAq+ndgdST86OGCxRSncAzejVt0ugGbcvAqLayN2RRLP+VbC7q4x86x+rDAaPnN31aT2LVFsCkAGFZIYbrjT5rd1Bnqfc/p/kOafB+zVcvvksXVRE/+mmhkxj4TtyK8sEfybHGIQEnZ+3DL5ha3YMf5IfJJGyIKKHcGE/WJm+3NHtbD5pvevjAChkbfIJw3lSBYF+Fnsjy3rL5rRs8lunWz+yAzn1WNtmWg8G1egRnbI/7JRJwobl6jyMPbUINGlI3OA0h8dAzep9+q9Bd+33ytRyXUJMS7Wk/Id5X2PKWBA6ciBraL8RKFA4KQUqm2ksTLaiP6mXOrtIfJVoD+lDag76sQ6/WxenqaSZIhc1naWViM1zTxXkdgHg63yUv7GkBg/cdPatXSfOnNpp8WIbTpeD0fx0PTgFlDddjdpmz5Dp8c1bS20frNp50V9v3hDRgCoUSHm4L1SP5PzzU+7oMwIkw3Mr6D5kNeTu9eIw88ykAfh06D9RsuUuq3QAykJq44QONKWlL7Ckevij+LmNKCZSEm8O/ZK4CrzxDAKnQHu71e0BkIHlIdgtJxjjUC9LoYmgjctDJCW7+vOeD3lDmo6loXZzHJ6cYFw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR10MB3220.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(36756003)(5660300002)(38350700002)(38100700002)(508600001)(8936002)(6506007)(44832011)(7416002)(4326008)(8676002)(6666004)(66946007)(66476007)(6486002)(66556008)(26005)(186003)(2616005)(86362001)(83380400001)(2906002)(6512007)(52116002)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VZZWkTx3VKG6fwpYRqf/I+owTPQkDMAXlKb70Z44eQb0O96YrQCAnn/aKJKsJ9qrEiJig3bEJPApVrKL4owXFxOWpeAhVREPmW9vvsTmHHNtyPVNcd2oMX+qFGYC8596LKc91E/82Mv0EaVds1g7lB35Lx33Ptq7Fm1g8BJg4ric63v6dBtYvOL2eOKxO9doGFj93JUandqd521/Eib9r3+omBYbkd8CpDWs+Ilfp4hh6CBloF69CvYWbaxFebzMzHvZvcJhxtHUlloirSk2H2pV2XRsBfyuwreQ99Yk4B3EjbObY2XtCZsyo5YF9NoWcMYFLYmWlFKn/QExgYZRYr/+z8V79zlpRTrEPNLX3/+BeOxJlAIXe9We1AQPLkP+c+Sd0+wU9I++QFnezjd4Zuktpsor9y4nNnrM7R4Z6IWxXTlDhHj9KLcb11BEDnq1Kn7A0hPFDHhVtFWxb9nNxiRCTtCPJj7hWOaAaJt5Snt19gBHd1d76wch4Os4Hu0W2GeuvVEhQ+6gPaLPBbwbGlf6ElDNzPnPZVMjgbvuTwOrpaLM1WH5h3Aj6H8mTSqPwYx79fjXqpaSGrYKNu4w5afVtESRxteze/sxa2+jPtlKrHOi+7/yk6piCeeLLjQbkh/dDV9ZS1KIZk9NyYWA7tHt5I70MGf2IHyqszfjm5jrr7kr+HQaMU4j6oyXEvSC4ztCn44Ye1nulm1IPQupvaKGVh7nPT7s2le316ziu9WeKCs7aD9/b7HvssKoPM+mWk5ZEGGyHsdMa5TlzByHjMwbl6vgyegprsNlfQP5p06rALcJtq8y1vZ8wgLbS3+5r+JrcVJl/i/rX7TTbHGUo9G8jCAEIRY8Lt/gDJiAQU7FruVFeTJvjvXF6OaswtxgTUZTz/8maknvWy4qOGYP4Ov/mlB7I3jGp6JYoNFugl+e0sr9XxbZsP4951tz7n3lIbOiC3R5Bp2R/Nsuf/AK8R375MSR2HCjOf3EmUX1XdY7PRB5k5FTg6tfkjfCpmx48KtY6GFgPZs6zKvqs4Zon+fRi/NTgmSzmeo2t1GM/nHYZkCljuXAFU05EryxXl1Cv8FMnJ5ATaW/2IxSkP8PKQGMHxHrLowZ7i6+AymPBm0TBrm0lskk3oOW0JuUPPuj7Yj3lcYNAbHxbHRBdEN9ESJ7dJWpVsXk07T1gpI+RFg2t3qUVPQW1qwfLSDHdcaEFqionc5rEP3dOrqx8JHv5OPsywe+8yO3ymLLiVN8YooSa0pOPZuf3eIXyZ2mCaI2Tmh1SNSAcX/DRmW12NGycqp5icZX4fpkSaG5iHJlfpr2/XO8n7kbynaer5ERlEg2EhrdF4pSXLujm6CtVB6mThstTea1NbYoRniJrEYyDyz8jXBUaH8EflNgT9Iw6hU5UX4lLK67+wHd1cnTuMBdXVOtLW8hE8shfCf7/dci2lLzZXFoEI9iuRPQzT9JBW73CNALXdG+YUwLhB8sXhPxabfUkvZ5EjgCoqOue4f+EAabarxPKE28JhQYks8F7o6kO/vdyiBM+nFyCvphneMo9HD2ArM+FnHMD0oylN8X7/PhiVQzNq9hT/FkyleHxum66k5TYep3Zdd7gXMeDvsTBHBNUDDXj2UQO8xDY9RuKLZGl/5F+FJhPxJMJ/F/bIT/MSQE0C+//s+KrvSpOi57SIfhY0OepuB8mTpQgmnkgj8UbZEwqzfwdsRXZbiPkimS316Qh8oFzYRTOiit/PJhoBIfMfo1SPVAjUTsQpXe5fU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e00e369c-451d-4dfd-4a07-08da1bd56584 X-MS-Exchange-CrossTenant-AuthSource: BN8PR10MB3220.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2022 16:07:37.4155 (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: tFU741it2gVPfcqJ8IhQwxqaMZlAxC8mmLworuO4L2YR/CzAMalzWunxfb8LMb+PyabyKAE+mnguEud3efhYAA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4564 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.858 definitions=2022-04-11_06:2022-04-11,2022-04-11 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 adultscore=0 mlxscore=0 bulkscore=0 phishscore=0 spamscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204110089 X-Proofpoint-ORIG-GUID: GJQXmsXjeuDAPM8lp_RkaEDhC3gnOKUz X-Proofpoint-GUID: GJQXmsXjeuDAPM8lp_RkaEDhC3gnOKUz Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b="lU4//b9Y"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=bAYxneiO; spf=none (imf07.hostedemail.com: domain of khalid.aziz@oracle.com has no SPF policy when checking 205.220.177.32) smtp.mailfrom=khalid.aziz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com X-Stat-Signature: 4qud51fi5dp5jb7khze36tkncwajkm6y X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 2A68940007 X-HE-Tag: 1649693298-123770 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: mshare regions are subject to size and alignment requirement. This alignment boundary can be different on different architectures and userspace needs a way to know what the requirement is. Add a file /proc/sys/vm//mshare_size that can be read by userspace to get the alignment and size requirement. Signed-off-by: Khalid Aziz --- v1: - Provide a way for userspace to determine alignment and size retriction (based upon feedback from Dave Hansen) include/linux/mm.h | 1 + kernel/sysctl.c | 7 +++++++ mm/mshare.c | 3 +++ 3 files changed, 11 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 821ed7ee7b41..d9456d424202 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3339,6 +3339,7 @@ unsigned long wp_shared_mapping_range(struct address_space *mapping, #endif extern int sysctl_nr_trim_pages; +extern ulong sysctl_mshare_size; #ifdef CONFIG_PRINTK void mem_dump_obj(void *object); diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 730ab56d9e92..66697ba5da88 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2810,6 +2810,13 @@ static struct ctl_table vm_table[] = { .extra2 = SYSCTL_ONE, }, #endif + { + .procname = "mshare_size", + .data = &sysctl_mshare_size, + .maxlen = sizeof(sysctl_mshare_size), + .mode = 0444, + .proc_handler = proc_doulongvec_minmax, + }, { } }; diff --git a/mm/mshare.c b/mm/mshare.c index ec23d1db79b2..88c7cefc933d 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -28,6 +28,8 @@ struct mshare_data { refcount_t refcnt; }; +ulong sysctl_mshare_size; + static struct super_block *msharefs_sb; /* Returns holding the host mm's lock for read. Caller must release. */ @@ -573,6 +575,7 @@ mshare_init(void) if (ret) sysfs_remove_mount_point(fs_kobj, "mshare"); + sysctl_mshare_size = PGDIR_SIZE; return ret; } From patchwork Mon Apr 11 16:05:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 12809421 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 A8E67C433EF for ; Mon, 11 Apr 2022 16:08:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 405A28D000A; Mon, 11 Apr 2022 12:08:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3B62B8D0003; Mon, 11 Apr 2022 12:08:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BA9E8D000A; Mon, 11 Apr 2022 12:08:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0159.hostedemail.com [216.40.44.159]) by kanga.kvack.org (Postfix) with ESMTP id 095008D0003 for ; Mon, 11 Apr 2022 12:08:15 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B5848183CEECB for ; Mon, 11 Apr 2022 16:08:14 +0000 (UTC) X-FDA: 79345080108.29.5838678 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf09.hostedemail.com (Postfix) with ESMTP id 09441140003 for ; Mon, 11 Apr 2022 16:08:13 +0000 (UTC) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23BE9Uu9003034; Mon, 11 Apr 2022 16:07:46 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-2021-07-09; bh=bstN5vNsxMv1kOoMK4ovp90qAGzL8wDP/+3UgSW6nPo=; b=ygWhrqKohQQtUiRPhOp8YBlAfx5C05dibCdhohdajEcbDmOJ6nOJsP/+AmxeMWyelePX YI+Z8f0OdZ1YgdeOgotf5CCy7VgtM3n6eXXvXNM6DYETG/YF3z/H4vamlWXc+CUDYMMI tWZe7FCmoDxFZ7r+FhJt1/o7hSpHII6Hk59zHgqKYIRLDZC+dyi4nZfNGmnOc6VrJr7i IK6B/IpifdduAABlKZ4ORj39JRWMcQg7C0IxCStjHY7BdeXgVh1wYCuBrN+JSsvvuBuc wSDGAvCP17ElP/ghpy4ag4CN7EgRdQGqNDwglxm6zkz69fDiI7dIynx6KVHsbp/koOgr 5g== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com with ESMTP id 3fb0x2c75k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:45 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23BG1Eg1031269; Mon, 11 Apr 2022 16:07:44 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2173.outbound.protection.outlook.com [104.47.56.173]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3fb0k27pmw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lDBnXENP7t+YbUrTi12rS+lSUH8DIi07uTVL5bgdM4h2XKmQi3rlPobFc4VpgWOlMt4Tf0EG4wh0QmRvEGe+zoDG/+r+L9gAgy8YoZA90/eEOcX+L0qKMdWoGYWDnqf9Rb8Pt2bIAJCvXdfOWMq1bmmjSR1u+SkftKq+u2IOvCOXAI/s/VjApGmozuxgZxKt7Z1LeKhA7usIoYq5UFZli/5QY+jMRtPZRCDT9CJ+TmHTm5QbryppjpW+tOdg+LjT6kCCS3opDJZ5AXmn1Q3q9EpMfG4LsQHE/fQ5+j2lO+23Ebvh/W5kfrwyHAhjSXEy2FnxZgQ0cApUWaOpGUD3wA== 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=bstN5vNsxMv1kOoMK4ovp90qAGzL8wDP/+3UgSW6nPo=; b=ZBZjgSpJ5afaZMIdgKZbLn6k0PyMvBzXyOhmtjt1Yqjj/qhW72V9j/cVmKEVXzW4ZHsULJdsQajTEpk6kynCx82rWz9E4FfzH0lpGv8qySBwAeCkZKk/nUSSrW1n8s0QSieoblDxXkFzgPyQnOqwlErKre1lw57KFJGk2aj4PV0k7hPxgJmkVo0ce0fI2runeiC8z1szThB2BZxmpCGCXEblvo3IR3N9NL3uF1YBEGWsGzCA5N4iiev7BGUsCMSr7foe8JYoKYdbm/Sv9A3eDdkSmwGafzi09K5CjnJhCQxOiSzyNkk9wTSCXFOJEutQB4qfavyhmQhDSUPVd5Ql+w== 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=bstN5vNsxMv1kOoMK4ovp90qAGzL8wDP/+3UgSW6nPo=; b=Y5h6TMS0diiHIzVWBGO+PV8KcuQV7gQ0xbhOXUBqHt40jFw3ERjzY3lX4LlVh/dK61/xsr9oshnWGs3Y90ZEQLwv0djd+uPk7+HyhI6N/7yOMe5oXx1U9UUMS+UpJPgUIEYcj27YwEI+NtxfzSdTXVyrpEix06lsVIXGX/3Ik1Y= Received: from BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) by CO1PR10MB4564.namprd10.prod.outlook.com (2603:10b6:303:6f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Mon, 11 Apr 2022 16:07:42 +0000 Received: from BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40]) by BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40%6]) with mapi id 15.20.5144.029; Mon, 11 Apr 2022 16:07:42 +0000 From: Khalid Aziz To: akpm@linux-foundation.org, willy@infradead.org Cc: Khalid Aziz , aneesh.kumar@linux.ibm.com, arnd@arndb.de, 21cnbao@gmail.com, corbet@lwn.net, dave.hansen@linux.intel.com, david@redhat.com, ebiederm@xmission.com, hagen@jauu.net, jack@suse.cz, keescook@chromium.org, kirill@shutemov.name, kucharsk@gmail.com, linkinjeon@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, longpeng2@huawei.com, luto@kernel.org, markhemm@googlemail.com, pcc@google.com, rppt@kernel.org, sieberf@amazon.com, sjpark@amazon.de, surenb@google.com, tst@schoebel-theuer.de, yzaikin@google.com Subject: [PATCH v1 13/14] mm/mshare: Enforce mshare'd region permissions Date: Mon, 11 Apr 2022 10:05:57 -0600 Message-Id: <40cfc1e065f27d1d119371c54b6e80421078c791.1649370874.git.khalid.aziz@oracle.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-ClientProxiedBy: SJ0P220CA0013.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:41b::20) To BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f4dd10dd-7438-44cf-ca03-08da1bd5689b X-MS-TrafficTypeDiagnostic: CO1PR10MB4564:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dan3t0Ziid/VAEvmsN/rrwY+xxoG4NpXBq+B+pJ/wGvbdA4KknDdYVGp+KrdlBVvc0iB5wlp6YcheOAw8mihbc+WTO4kpASH9EzqBrAKMbZ6Wr0IVszKct1jkhR5Sq70Sd+ExoSe6gZVfTUfx5C8R3O8+AgVO9CHTngL4gfnt8WRBKNuONYFpDaRsu+wxy3rCmNGI+ip4UAL8uVaHOtnMNCL8IQJ61WG1/1HLb1Nq7BWxTEExbYJ5KTILN3BfGdtTXvNiyxBzly5oAPamDNKEHWwFzGVG1bt83Dizwq7PCv2EP1IE9/sSTSm28At5G7Cf3x8+FGqPu2v3hYZkPV2tzCkrSQX9BXlK8JQk1QeAarMy2MQHrmJq/Wk1XOCpksUpe+Omy9li7IqsaJ1bdr17/Q0yEgZ3Oa+vuKGJ3jtkXTxMS8fdl943hlI3zAVZs5pgjVhYXEt3bIEMRqWlcaCEqtjjFPzpinRYt/5kboPDW8b9bNttKW4d23jTCDrCNS/IZWHZfds8p5yjKF5OIqiy038DadNCojn2BNxmnv9buhhKVdpNgmuVQjxtX8CgfkQbJtB7BWSE0P5W/ulYvaoXKo+peXXQanCww4oZHa7AZEEFLR/YGHGkcdh79qNwEVRaQP7nyoIZx52OhTu86UqG7BPsDZJhGbfYYvmgtLdTAqtbL5R+OBclkXNWfQKKuOa1Ly6qv1E8yxcDyfI4MPeZQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR10MB3220.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(36756003)(5660300002)(38350700002)(38100700002)(508600001)(8936002)(6506007)(44832011)(7416002)(4326008)(8676002)(6666004)(66946007)(66476007)(6486002)(66556008)(26005)(186003)(2616005)(86362001)(83380400001)(2906002)(6512007)(52116002)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HkMh9fUKcK/0xrGyAJYTyw6NBdrK+b4cKngXQYU3FfiomdBEln28En0TDtjU60sMjADfHRFe0VOysTh/rfUvwaOdXxziIQthHN1wO64i2lmBGEMYyaHy1OD3DKhz7M54V9FQiVHvrJZ/GrjG5WDGZoycvQKAgE1LFwv4cvF+x37KCngum9Q6z0Dzelhk56UZgEMlDFEiF7oyBL0lII1OJFPt2nA4FSezaIUOkZnXFUvsLfD0R2wzNySBvZhm0u1/oUZmzYyeMNiyAailSuoZYRdwYjFddfQa+sOsk5at5gnyjJzJHQqZlzzNcHmgyutM/hZaM6ggY1+kwL8mHUhtiERp0wcwG+ch0/o7VnQ6QDtoj3HkCxsqCqTcGcisAyNXDM8mgUlXE/xuJsmhiP9Dm+/1Q2vGaWPfJii6kHYuXy/lTNRCbV6EbNgbFvz2BCkQpqUGTfKz7mJq7AikqzBKZRk6Efk44QriGKZXyv9zax8GZn3PZuTPE9tiO7/B/haoBnnT+dZMY6Anro4QH5Qzw26nakaOwuikaD3nLJaPJr4D3XFOGPTslDr9c4VLA5ZWc143tMZoq6sgND2R1f2TX57HU+HpFjTaXBtyv8MtxqDkyqI6TNIThbdhH3+EBvhfOSMNqOt5/uFXP7P4ZrbTGWZLPjgjPvSATX8W9ooIZujvYswCJBV0YcFXPBsQH1NvrSEjpqrZT/QwSSyvIkxO6t8GIpYyfs+b6H6Ug7jRmb4eDJo1sxlwMd1UEn0+vaDl4pLd+fJVdcvAUDCHBrrJPinl/TQP/NGFwdNuNKHqNb3IOmWpOBmGGMW/GMR+PQsyQbFGdhkGlY0YYAhBMtkJoePUdNoQrKSFJZyYhfkM8Rb4KFg6S/ia+pN3Xty9T+MixVXSoeEbvA/t1mTacEzvRyKQ/L1OSK8JWYKJ1Uq4d1OfLF2Bo9RUa5ZB5mKzBuMfESJDIoayYGwRwqwOrpD2yWxGGLLJVU/DdamhL6TKQtMiCBfQo5v1THHb24rHO28pcZ5eXvabaZtqlghcuF0baw+xactuO0BjGx5F7HrtxbGhRGMV9Rknxfvvn3MZ/hYdBPPHCls+Ulf1aKVKCfphLBPUVTA1JJS68hdxSOzWN6ealbB3oWizvzfTqU+rdH+DrPy5hw0VcdNW2rebOputBfla3akaWplE0lwqsLuoT5dlRXQ6Et8QglHLmkMYlEbMrDUTZmAB+lndr58NAzsBQxkv2PmqtLJiO4L7QDbvjqeauhq8KZxTNxm59eaQrokup6y3vUd+xkzrro48skp1slwL4n7kiRdpImXY+RsSdaYjaDMt00zE/QKxk8hPor5DbDpeSMZtB/Ozvo4Xi8GM9X+Jd6yZ0JkOi4V0PURNAu9oYkUTfTfTqXy+G7ycvELXqWV2aZW9WC38jaldLJzC5vd2YORbNdyAXKDceJXgXMDxNPSowILLcdWak2gI4d3fo4wWRR2tSRK+sR+JyxnB5/lSSurkZBW2zqTLzHPAxSla4/Zw90odlrBHSWAkJi+H01+vbdR8aGWtnNTYr+maCqNC95lD44MTXvLPRADttepZslYaX2AXeCyU3UgTPo7pzF/iw1cT5LTgu/6H0hiMxYukJRfAv4TO4FQtu0dwh4OwtvpJ7EWb0ltxTyW70gVh76vI3BA7+d8UhfEBqrMwZiJccqUjbK3wCYAuKZnusSCLxaH8c+8iYvdTPBtQhl/dzVS5Zfnnma4cYFYEibjYVYp8nBPfothaUAZ7UWjbKWg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f4dd10dd-7438-44cf-ca03-08da1bd5689b X-MS-Exchange-CrossTenant-AuthSource: BN8PR10MB3220.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2022 16:07:42.7432 (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: PL/2WKgOkyo7scLQmIbyr18UdgVQUKfUiCZ+oTHo0kO3wKvwQKfYRnHBWBkqEIJdr7OJWUTegH7nsO6dRBIVHw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4564 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.858 definitions=2022-04-11_06:2022-04-11,2022-04-11 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxlogscore=917 spamscore=0 adultscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204110089 X-Proofpoint-ORIG-GUID: hhFVpB-tQ-N169IxUB2SQW617P72RFql X-Proofpoint-GUID: hhFVpB-tQ-N169IxUB2SQW617P72RFql Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=ygWhrqKo; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Y5h6TMS0; spf=none (imf09.hostedemail.com: domain of khalid.aziz@oracle.com has no SPF policy when checking 205.220.177.32) smtp.mailfrom=khalid.aziz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com X-Stat-Signature: ewqwz7hrjisizj5e1tq4jtjmei7upxnc X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 09441140003 X-HE-Tag: 1649693293-443240 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 creates an mshare region, it specifies permissions allowed for others to access this region as well as permissions for the file to be created in msharefs that allows other processes to get information on mshare'd region. Ensure those permissions are enforced for other tasks accessing this region. Signed-off-by: Khalid Aziz --- mm/mshare.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/mm/mshare.c b/mm/mshare.c index 88c7cefc933d..fba31f3c190f 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -24,7 +24,7 @@ struct mshare_data { struct mm_struct *mm, *host_mm; - mode_t mode; + int flags; refcount_t refcnt; }; @@ -131,7 +131,7 @@ static struct dentry } static struct inode -*msharefs_get_inode(struct super_block *sb, int mode) +*msharefs_get_inode(struct super_block *sb, mode_t mode) { struct inode *inode = new_inode(sb); @@ -161,19 +161,22 @@ static struct inode } static int -mshare_file_create(struct filename *fname, int flags, +mshare_file_create(struct filename *fname, mode_t mode, struct mshare_data *info) { struct inode *inode; struct dentry *root, *dentry; int err = 0; + mode_t fmode; root = msharefs_sb->s_root; /* - * This is a read only file. + * This is a read only file so mask out all other bits. Make sure + * it is readable by owner at least. */ - inode = msharefs_get_inode(msharefs_sb, S_IFREG | 0400); + fmode = (mode & 0444) | S_IFREG | 0400; + inode = msharefs_get_inode(msharefs_sb, fmode); if (IS_ERR(inode)) return PTR_ERR(inode); @@ -247,6 +250,7 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, dput(dentry); goto err_unlock_inode; } + oflag &= (O_RDONLY | O_WRONLY | O_RDWR); if (dentry) { unsigned long mapaddr, prot = PROT_NONE; @@ -276,7 +280,11 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, /* * Map in the address range as anonymous mappings */ - oflag &= (O_RDONLY | O_WRONLY | O_RDWR); + if (oflag != (oflag & info->flags)) { + err = -EPERM; + goto err_unlock_inode; + } + if (oflag & O_RDONLY) prot |= PROT_READ; else if (oflag & O_WRONLY) @@ -331,7 +339,7 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, new_mm->task_size--; info->mm = new_mm; info->host_mm = old_mm; - info->mode = mode; + info->flags = oflag; refcount_set(&info->refcnt, 1); /* @@ -412,7 +420,7 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, mmap_write_unlock(old_mm); mmap_write_unlock(new_mm); - err = mshare_file_create(fname, oflag, info); + err = mshare_file_create(fname, mode, info); if (err) goto free_info; } From patchwork Mon Apr 11 16:05:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 12809422 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 0CD60C433F5 for ; Mon, 11 Apr 2022 16:08:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 984B96B0072; Mon, 11 Apr 2022 12:08:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 934208D0003; Mon, 11 Apr 2022 12:08:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 75F856B007D; Mon, 11 Apr 2022 12:08:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 644106B0072 for ; Mon, 11 Apr 2022 12:08:19 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1F6E021C70 for ; Mon, 11 Apr 2022 16:08:19 +0000 (UTC) X-FDA: 79345080318.09.BA98FCA Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf19.hostedemail.com (Postfix) with ESMTP id 4C2771A0009 for ; Mon, 11 Apr 2022 16:08:18 +0000 (UTC) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23BFdIBW008887; Mon, 11 Apr 2022 16:07:51 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-2021-07-09; bh=EBwYbFR7kFlqsY1mcLiNY9ZzjsnJMqqxbeoLcYz5X30=; b=Of7Ztr0qsUDInaMRqkcBXp8jobpqJtjVv0jlrPeyrBa3CFeHkNTQxoWiw+78n2teIZsa IDPPYPKSygYNJGunuLoj8+oyoFrACBd+Ek8DdtDSCQRRgReyK2oqTMuVBThqyuyxkLba GohPGIcvOsQ8KIbPp/u1TDT5gM+Pf0r5EP3MrGqsw7m+tFmeqOtrp2qlN3IdcLBy50Nz JcsCFYMmSF4AQCPX2U9tMIjs+CfhvRASUJYiBVi59UyY4w+oKq1XNFFDTVvlm/XvANeW cdEgu3KFRO7VqkA3utX97ai3lLrDIjwhU6rXJS7LiwHdLUJNMpmBkM4QWejNYLsV5vIK wQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com with ESMTP id 3fb0x2c761-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:51 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 23BG1fmb009876; Mon, 11 Apr 2022 16:07:50 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2046.outbound.protection.outlook.com [104.47.51.46]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com with ESMTP id 3fb0k205yf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Apr 2022 16:07:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f5iNEZgCNWZv3lnnGZogl3mFs3ROK359ri+a4zVaW7yGYi9w7GTv1YnupQcudEpP+6OTcFCDWVG+4YpvFMePbfQNxAUimJ9jbWvYCbjk/EQEndK+9ffusVd/5yFzO9AnbEbC+2lKhtwlGtf9oId18c2oDTHCm78aZIgMU2atzdPrWWsLtggSSVRpfpwLc6yGoICHhvVduvK/ZrDs4UZHLuxx0xiwUxVNhtO/ILfZRfAm2UAMSgEBjTs1GngA1FrG5wK0jhkguO5iN5yeWXn/y+6NYlDTG6TlheIklHflxBXige1v1Zx8aN9XlfzTgojSM41Td70bM/Hgz16pB25tag== 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=EBwYbFR7kFlqsY1mcLiNY9ZzjsnJMqqxbeoLcYz5X30=; b=N/mGuMv2sx7WAych35KQ/JpScU7XzPLM7BrTXoAVPPA4DuIQ0Xr3W3B661YYDsADid/jQaCrrAPE6qcW2JrLvKp9Zv0MS0+H4VbfjUUoTD0AQOAVB188KZSESwYm5spZIwfkPn54LyKTEbafFQkmjjaZ87AkmeAA19cIn5Hdl1lesOou/mm0uLKIERAg1MNSm0wWxo+7Ojn55ylbn1cvFKXrabgMG7gQD6nvoD+7K5rozqz3qhPH8rdaJrt96eMNqv5wQ5PepL08sqBOTWI0QYH9u+zkMFWCBb9qvEjltfv74nuAFKe5BQaywxBatczHqN8xlBq4m+eYVlSY/9vcOg== 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=EBwYbFR7kFlqsY1mcLiNY9ZzjsnJMqqxbeoLcYz5X30=; b=tZQg3Dn2acuPEOlDsYADKVzo3ztral9YPFpOehrqzzDHOE2k86WADPS4G/Xi7gE68S1lGWJ710qor+Z8lu5mjN2XsG0EBoXlM7uPV1zAIcL/27FgI1lJFNRHhZ0kJV51odKvzW82R4CcxO0B5PQ4zVNFbolYeZz/ZgrF2ecQlzI= Received: from BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) by CO1PR10MB4564.namprd10.prod.outlook.com (2603:10b6:303:6f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Mon, 11 Apr 2022 16:07:48 +0000 Received: from BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40]) by BN8PR10MB3220.namprd10.prod.outlook.com ([fe80::41da:48ff:402:1a40%6]) with mapi id 15.20.5144.029; Mon, 11 Apr 2022 16:07:47 +0000 From: Khalid Aziz To: akpm@linux-foundation.org, willy@infradead.org Cc: Khalid Aziz , aneesh.kumar@linux.ibm.com, arnd@arndb.de, 21cnbao@gmail.com, corbet@lwn.net, dave.hansen@linux.intel.com, david@redhat.com, ebiederm@xmission.com, hagen@jauu.net, jack@suse.cz, keescook@chromium.org, kirill@shutemov.name, kucharsk@gmail.com, linkinjeon@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, longpeng2@huawei.com, luto@kernel.org, markhemm@googlemail.com, pcc@google.com, rppt@kernel.org, sieberf@amazon.com, sjpark@amazon.de, surenb@google.com, tst@schoebel-theuer.de, yzaikin@google.com Subject: [PATCH v1 14/14] mm/mshare: Copy PTEs to host mm Date: Mon, 11 Apr 2022 10:05:58 -0600 Message-Id: <4834724ec012da591863371cf4423d1971771d99.1649370874.git.khalid.aziz@oracle.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-ClientProxiedBy: SJ0P220CA0013.NAMP220.PROD.OUTLOOK.COM (2603:10b6:a03:41b::20) To BN8PR10MB3220.namprd10.prod.outlook.com (2603:10b6:408:c8::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4293f8ed-62a3-447b-d33b-08da1bd56bbc X-MS-TrafficTypeDiagnostic: CO1PR10MB4564:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wAkDE0/kKo10FuRLJ8g8c6m64dnkIHJ8zSzfDkPDcHvkj4x8AlyhvjUqL9AJthC3NwAiFrsA9Y1dJp3Da+pf/Y8deaoHzoC/76H9HEsduagD/7pPNyifC0yVrlihz8Vp5rhX7WoNcxZ0eK+7ZUGelJlX1nkcSNwG8DBVk3QXJ0Tez7hER7zExWManjg+pmM1WGqXkUhbazdaBzySXk8+XJCsAgdx84oxi5Lo2p68YIcge+9aBGGehRaagv9NaKYHs0XbkinGJ3jzghSpNtZI2d2H9NeiiXiy3/dh/cqcZT6AIX9CDcr/EytFwya1B1mHKQbXh+1sLLFEWXEm8wnmEhRlW15fAk8J64yp6T5VbeiXEyyLtoreY67qMFpSi0UQb6gWg1ef4stEosuLJ+Qw1SF+nJvCcyMoOLVjHK0Ws7n+VEk/b7YQX6WpRUxu0iMkoLI2oS8y81DhmFb/Jj2mkNcJirDJOWz8JGMxAMErzbKCGXSrfdbbvs5usOJdM/Oynr2FtyG5KfU65eqxNOfr3wbjU2EL1ZosdJahB0KXBamT75waoqewS+73mmQ3cu8Q8cXOdED02BajLZ3rh06cc/CvcCX/6+VP7CTpL0xiD4XRHKd3vlfYFXgNTUcwA0uPvGFf5H85/knSu/d5R0O3U0zLUpfumYF6wj1FghQ7Ub8dso5mMqLVioxkTtpapHMD X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR10MB3220.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(36756003)(5660300002)(38350700002)(38100700002)(508600001)(8936002)(6506007)(44832011)(7416002)(4326008)(8676002)(6666004)(66946007)(66476007)(6486002)(66556008)(26005)(186003)(2616005)(86362001)(83380400001)(2906002)(6512007)(52116002)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jMc1Q8OPg79azsV4friK7ed/i+vRLNaKy5InFrS88t2HT+5k+e6/EtAzbRDF8fwffQWmPWXzKVB7XNx+4nRrBuflhVSsbf3/t8svq5U5jqAAyeZEjUJgWoOXkfLBemuKaD/hTxS7B6fBQ6H97UIbNgrvOGFs56+7Jk4Ly6snuIsj79ocCfkzu+YnCjnK5o/0iWwe8efkHlr58PKIoHJ0cy/YqRuZqQzk+zcnTsiRk4Xe4ToL7DK1swhq+gDIdBSRdD3SA+yl5SVDaM3SxTpQBp9TWUo6m4RcUEWeaVuL3Ym/zPfLv19UTnWCLEAZ2/Yc+zTHSul2hZyY2YSxN55xiVbwBLfdl0QUjxPxl0CbWoIqWzDiMeOfVG05hPswVGPLxVD+Nxy6z/ffhcRpOgmPtCkxtuX1ijIPJtYX4nqGWZwTLKggcg/f/lfAG4TmPfh8F3YDg4v++2xPhqAcWLkiHFc1PrZPX+ZN1jH0wLvIr1etF5Et67sFTqq1MMLCyLAQIMRCkyYan/tJtsKQ61a72bfwySsm5eKHI8qlAn4v9pX1iJL1MNJt2EIdnAXiTl5MpBRxKZp6eGsFWM7JJM6JXQBSoTEoLt2aNym9c6h/TRL7y9xuq8g4V2VrdhI3RfgPMD8IReT54iTgOkxt0ZsRexO8kiuUowry8nCHxduZ3uvv7hFDeSA5Cga+UkKmgjCWYgq/14He9PONWe7L7sAMnFTGLi2xhI7cZyeAjaNO8Rai6nfphNbHtpOt77EjRUBPtwwulizNHARr1xyWHtpH9X8/VxDdQ33vPXyS/xSss6VR56N5XO6DBEOlwIpAk/UBnqtPzLxCBFJrj4D94Pb6OrWblj5UNFUXE8hfgQ01uUk9uCF9pyq5zySSYq3NRKH0btzNsaqACpWDAvpJNRkKNqHMUhZoWsrahj1xNzSWl2HB9VCVH2n3B7q7pm08exp6rl9JsKRlfewPryPTdKn3Dwig2GxU/5SdApsQdzOY3JECbDZUNHAd5X1nvdY6D3WVc3QmV7RyeqaKiyEdrXLaYygdI5U/RqwyhXGsps9t2wap2U8uwPzEp3pfmzP//fPi5SoqEul5yDsiTgK6dtm9YjRXlTB5vHZmbu+BvjBns6D2YI2C9pM6Rj6ITnQ9wQccczAL5t4uXyAE/0yTTdCCjWrfQ31zC/CYR+Q3DjpopT5MPe7B8W8eCibaXVaHwzXDWdyT06GgmrSxqoPipA7+f6IFbAYZpyf3203u+stGQfPM2dI45n3Ya6tAymdgqEgJFe1miZf5Jyr/REnsFZ4mkq0toVQPpeUDVJgsKWcph/boJvNLR4OT4fBOwtrF7WRQo+oZl1e0Jg7XeB8YZ5breHmjRodo55f7kJeRKNJTYP816j0WtVh04MpZmyLe/SiawLUrrpOaF2G96oBvqjXOJ5+kkLeVsHXthaHFJVYBIHJb1WS1ch/EZsLt/FdrSIpc71tqE5Jb3JW/nux4nnMBhNL8wgCfKGa7oQTLmuqpZXcAgPnmECoZX7vKjW2/ebhQEg3n/vDJhmZedb6iorn6PwdGUUfxKHOT0T+YLMthkDi7+6lfV8qH9VkmeVG1oU6urv3VKs+8MVqLBlznZeeyEn37GS1U2vmxs6rYHf4SoF64jH0ZzmGt9uPSS0+rc8GUDzLFOoDm46u6l3EdwXteU10LvVkl/BQV48/I9x8o0C8n8JlGWc3F04coYiNxA6arKEZOUEzVX21QOQdxSnvaNabVHtViJ3ip3NRgrb5KS5Q= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4293f8ed-62a3-447b-d33b-08da1bd56bbc X-MS-Exchange-CrossTenant-AuthSource: BN8PR10MB3220.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2022 16:07:47.8835 (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: HhIqXH9kA2S7sz2YJN4k9E2UMzZUQX0IRvrOIiVHBxxWqvq2ruhF377w6DY574BxWhTc6aVklAip5amF1rI1eA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4564 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.425,18.0.858 definitions=2022-04-11_06:2022-04-11,2022-04-11 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204110089 X-Proofpoint-ORIG-GUID: YmET7za0myCBpngmRYmgaMFd_OlmKwVS X-Proofpoint-GUID: YmET7za0myCBpngmRYmgaMFd_OlmKwVS X-Rspam-User: X-Stat-Signature: 81xe37tafycb3ghdtapy143o68tyeeyi Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2021-07-09 header.b=Of7Ztr0q; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=tZQg3Dn2; spf=none (imf19.hostedemail.com: domain of khalid.aziz@oracle.com has no SPF policy when checking 205.220.177.32) smtp.mailfrom=khalid.aziz@oracle.com; dmarc=pass (policy=none) header.from=oracle.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 4C2771A0009 X-HE-Tag: 1649693298-469512 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: VMAs for shared addresses are hosted by a separate host mm. Copy over original PTEs from the donor process to host mm so the PTEs are maintained independent of donor process. Signed-off-by: Khalid Aziz --- include/linux/mm.h | 2 ++ mm/memory.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ mm/mshare.c | 14 +++++--------- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index d9456d424202..78c22891a792 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1845,6 +1845,8 @@ void free_pgd_range(struct mmu_gather *tlb, unsigned long addr, unsigned long end, unsigned long floor, unsigned long ceiling); int copy_page_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma); +int +mshare_copy_ptes(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma); int follow_invalidate_pte(struct mm_struct *mm, unsigned long address, struct mmu_notifier_range *range, pte_t **ptepp, pmd_t **pmdpp, spinlock_t **ptlp); diff --git a/mm/memory.c b/mm/memory.c index e7c5bc6f8836..9010d68f053a 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1234,6 +1234,54 @@ copy_p4d_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma, return 0; } +/* + * Copy PTEs for mshare'd pages. + * This code is based upon copy_page_range() + */ +int +mshare_copy_ptes(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma) +{ + pgd_t *src_pgd, *dst_pgd; + unsigned long next; + unsigned long addr = src_vma->vm_start; + unsigned long end = src_vma->vm_end; + struct mm_struct *dst_mm = dst_vma->vm_mm; + struct mm_struct *src_mm = src_vma->vm_mm; + struct mmu_notifier_range range; + int ret = 0; + + mmu_notifier_range_init(&range, MMU_NOTIFY_PROTECTION_PAGE, + 0, src_vma, src_mm, addr, end); + mmu_notifier_invalidate_range_start(&range); + /* + * Disabling preemption is not needed for the write side, as + * the read side doesn't spin, but goes to the mmap_lock. + * + * Use the raw variant of the seqcount_t write API to avoid + * lockdep complaining about preemptibility. + */ + mmap_assert_write_locked(src_mm); + raw_write_seqcount_begin(&src_mm->write_protect_seq); + + dst_pgd = pgd_offset(dst_mm, addr); + src_pgd = pgd_offset(src_mm, addr); + do { + next = pgd_addr_end(addr, end); + if (pgd_none_or_clear_bad(src_pgd)) + continue; + if (unlikely(copy_p4d_range(dst_vma, src_vma, dst_pgd, src_pgd, + addr, next))) { + ret = -ENOMEM; + break; + } + } while (dst_pgd++, src_pgd++, addr = next, addr != end); + + raw_write_seqcount_end(&src_mm->write_protect_seq); + mmu_notifier_invalidate_range_end(&range); + + return ret; +} + int copy_page_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma) { diff --git a/mm/mshare.c b/mm/mshare.c index fba31f3c190f..a399234bf106 100644 --- a/mm/mshare.c +++ b/mm/mshare.c @@ -385,7 +385,6 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, * Copy this vma over to host mm */ vma->vm_private_data = info; - vma->vm_mm = new_mm; vma->vm_flags |= VM_SHARED_PT; new_vma = vm_area_dup(vma); if (!new_vma) { @@ -394,6 +393,7 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, err = -ENOMEM; goto free_info; } + new_vma->vm_mm = new_mm; err = insert_vm_struct(new_mm, new_vma); if (err) { mmap_write_unlock(new_mm); @@ -402,17 +402,13 @@ SYSCALL_DEFINE5(mshare, const char __user *, name, unsigned long, addr, goto free_info; } + /* Copy over current PTEs */ + err = mshare_copy_ptes(new_vma, vma); + if (err != 0) + goto free_info; vma = vma->vm_next; } - /* - * Copy over current PTEs - */ - myaddr = addr; - while (myaddr < new_mm->task_size) { - *pgd_offset(new_mm, myaddr) = *pgd_offset(old_mm, myaddr); - myaddr += PGDIR_SIZE; - } /* * TODO: Free the corresponding page table in calling * process