From mboxrd@z Thu Jan 1 00:00:00 1970 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 544E0C433F5 for ; Sun, 6 Mar 2022 08:30:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 594396B0071; Sun, 6 Mar 2022 03:30:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 51C276B0072; Sun, 6 Mar 2022 03:30:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C3016B0073; Sun, 6 Mar 2022 03:30:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0209.hostedemail.com [216.40.44.209]) by kanga.kvack.org (Postfix) with ESMTP id 289736B0071 for ; Sun, 6 Mar 2022 03:30:23 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C5FBC8249980 for ; Sun, 6 Mar 2022 08:30:22 +0000 (UTC) X-FDA: 79213289484.23.7252426 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by imf08.hostedemail.com (Postfix) with ESMTP id 02022160004 for ; Sun, 6 Mar 2022 08:30:21 +0000 (UTC) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-108-tUwZomUWMYSiN451TxRaKw-1; Sun, 06 Mar 2022 08:30:17 +0000 X-MC-Unique: tUwZomUWMYSiN451TxRaKw-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.28; Sun, 6 Mar 2022 08:30:15 +0000 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.028; Sun, 6 Mar 2022 08:30:14 +0000 From: David Laight To: 'Jarkko Sakkinen' , "linux-mm@kvack.org" CC: Dave Hansen , Nathaniel McCallum , Reinette Chatre , "Andrew Morton" , "linux-sgx@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Florian Fainelli , Thomas Bogendoerfer , Matthew Auld , =?iso-8859-1?Q?Thomas_Hellstr=F6m?= , Daniel Vetter , Jason Ekstrand , Chris Wilson , Maarten Lankhorst , Greg Kroah-Hartman , Tvrtko Ursulin , Vasily Averin , Shakeel Butt , "Michal Hocko" , zhangyiru , Alexey Gladkov , Alexander Mikhalitsyn , "linux-mips@vger.kernel.org" , "intel-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" , "codalist@coda.cs.cmu.edu" , "linux-unionfs@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" Subject: RE: [PATCH RFC 0/3] MAP_POPULATE for device memory Thread-Topic: [PATCH RFC 0/3] MAP_POPULATE for device memory Thread-Index: AQHYMRun9YUfQRgF3USRgOtqAakL96yyAc1Q Date: Sun, 6 Mar 2022 08:30:14 +0000 Message-ID: <7f46ef3c80734f478501d21cef0182c5@AcuMS.aculab.com> References: <20220306053211.135762-1-jarkko@kernel.org> In-Reply-To: <20220306053211.135762-1-jarkko@kernel.org> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 02022160004 X-Rspam-User: Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf08.hostedemail.com: domain of david.laight@aculab.com designates 185.58.85.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com X-Stat-Signature: 7b5y6pi8173xhsoduk5yz6iptc13rsc1 X-HE-Tag: 1646555421-724140 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000007, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Jarkko Sakkinen > Sent: 06 March 2022 05:32 >=20 > For device memory (aka VM_IO | VM_PFNMAP) MAP_POPULATE does nothing. Allo= w > to use that for initializing the device memory by providing a new callbac= k > f_ops->populate() for the purpose. >=20 > SGX patches are provided to show the callback in context. >=20 > An obvious alternative is a ioctl but it is less elegant and requires > two syscalls (mmap + ioctl) per memory range, instead of just one > (mmap). Is this all about trying to stop the vm_operations_struct.fault() function being called? It is pretty easy to ensure the mappings are setup in the driver's mmap() function. Then the fault() function can just return -VM_FAULT_SIGBUS; If it is actually device memory you just need to call vm_iomap_memory() That quite nicely mmap()s PCIe memory space into a user process. Mapping driver memory is slightly more difficult. For buffers allocated with dma_alloc_coherent() you can probably use dma_mmap_coherent(). But I have a loop calling remap_pfn_range() because the buffer area is made of multiple 16kB kernel buffers that need to be mapped to contiguous user pages. =09David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)