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; }