PCI/P2PDMA: Allow userspace VMA allocations through sysfs
authorLogan Gunthorpe <logang@deltatee.com>
Fri, 21 Oct 2022 17:41:15 +0000 (11:41 -0600)
committerJens Axboe <axboe@kernel.dk>
Wed, 9 Nov 2022 18:29:21 +0000 (11:29 -0700)
commit7e9c7ef83d785236f5a8c3761dd053fae9b92fb8
treee5eec3cc49d298ae4fd4718fe6c516287ddc889d
parent7ee4ccf57484d260c37b29f9a48b65c4101403e8
PCI/P2PDMA: Allow userspace VMA allocations through sysfs

Create a sysfs bin attribute called "allocate" under the existing
"p2pmem" group. The only allowable operation on this file is the mmap()
call.

When mmap() is called on this attribute, the kernel allocates a chunk of
memory from the genalloc and inserts the pages into the VMA. The
dev_pagemap .page_free callback will indicate when these pages are no
longer used and they will be put back into the genalloc.

On device unbind, remove the sysfs file before the memremap_pages are
cleaned up. This ensures unmap_mapping_range() is called on the files
inode and no new mappings can be created.

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Link: https://lore.kernel.org/r/20221021174116.7200-9-logang@deltatee.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/pci/p2pdma.c