Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

uio: replace deprecated mmap hook with mmap_prepare in uio_info

The f_op->mmap interface is deprecated, so update uio_info to use its
successor, mmap_prepare.

Therefore, replace the uio_info->mmap hook with a new
uio_info->mmap_prepare hook, and update its one user, target_core_user,
to both specify this new mmap_prepare hook and also to use the new
vm_ops->mapped() hook to continue to maintain a correct udev->kref
refcount.

Then update uio_mmap() to utilise the mmap_prepare compatibility layer to
invoke this callback from the uio mmap invocation.

Link: https://lkml.kernel.org/r/157583e4477705b496896c7acd4ac88a937b8fa6.1774045440.git.ljs@kernel.org
Signed-off-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Bodo Stroesser <bostroesser@gmail.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Clemens Ladisch <clemens@ladisch.de>
Cc: David Hildenbrand <david@kernel.org>
Cc: David Howells <dhowells@redhat.com>
Cc: Dexuan Cui <decui@microsoft.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jann Horn <jannh@google.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: K. Y. Srinivasan <kys@microsoft.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Long Li <longli@microsoft.com>
Cc: Marc Dionne <marc.dionne@auristor.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Pedro Falcato <pfalcato@suse.de>
Cc: Richard Weinberger <richard@nod.at>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vignesh Raghavendra <vigneshr@ti.com>
Cc: Wei Liu <wei.liu@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Lorenzo Stoakes (Oracle) and committed by
Andrew Morton
933f05f5 f98cb7ca

+28 -12
+18 -8
drivers/target/target_core_user.c
··· 1860 1860 return NULL; 1861 1861 } 1862 1862 1863 + static int tcmu_vma_mapped(unsigned long start, unsigned long end, pgoff_t pgoff, 1864 + const struct file *file, void **vm_private_data) 1865 + { 1866 + struct tcmu_dev *udev = *vm_private_data; 1867 + 1868 + pr_debug("vma_mapped\n"); 1869 + 1870 + kref_get(&udev->kref); 1871 + return 0; 1872 + } 1873 + 1863 1874 static void tcmu_vma_open(struct vm_area_struct *vma) 1864 1875 { 1865 1876 struct tcmu_dev *udev = vma->vm_private_data; ··· 1930 1919 } 1931 1920 1932 1921 static const struct vm_operations_struct tcmu_vm_ops = { 1922 + .mapped = tcmu_vma_mapped, 1933 1923 .open = tcmu_vma_open, 1934 1924 .close = tcmu_vma_close, 1935 1925 .fault = tcmu_vma_fault, 1936 1926 }; 1937 1927 1938 - static int tcmu_mmap(struct uio_info *info, struct vm_area_struct *vma) 1928 + static int tcmu_mmap_prepare(struct uio_info *info, struct vm_area_desc *desc) 1939 1929 { 1940 1930 struct tcmu_dev *udev = container_of(info, struct tcmu_dev, uio_info); 1941 1931 1942 - vm_flags_set(vma, VM_DONTEXPAND | VM_DONTDUMP); 1943 - vma->vm_ops = &tcmu_vm_ops; 1932 + vma_desc_set_flags(desc, VMA_DONTEXPAND_BIT, VMA_DONTDUMP_BIT); 1933 + desc->vm_ops = &tcmu_vm_ops; 1944 1934 1945 - vma->vm_private_data = udev; 1935 + desc->private_data = udev; 1946 1936 1947 1937 /* Ensure the mmap is exactly the right size */ 1948 - if (vma_pages(vma) != udev->mmap_pages) 1938 + if (vma_desc_pages(desc) != udev->mmap_pages) 1949 1939 return -EINVAL; 1950 - 1951 - tcmu_vma_open(vma); 1952 1940 1953 1941 return 0; 1954 1942 } ··· 2263 2253 info->irqcontrol = tcmu_irqcontrol; 2264 2254 info->irq = UIO_IRQ_CUSTOM; 2265 2255 2266 - info->mmap = tcmu_mmap; 2256 + info->mmap_prepare = tcmu_mmap_prepare; 2267 2257 info->open = tcmu_open; 2268 2258 info->release = tcmu_release; 2269 2259
+8 -2
drivers/uio/uio.c
··· 850 850 goto out; 851 851 } 852 852 853 - if (idev->info->mmap) { 854 - ret = idev->info->mmap(idev->info, vma); 853 + if (idev->info->mmap_prepare) { 854 + struct vm_area_desc desc; 855 + 856 + compat_set_desc_from_vma(&desc, filep, vma); 857 + ret = idev->info->mmap_prepare(idev->info, &desc); 858 + if (ret) 859 + goto out; 860 + ret = __compat_vma_mmap(&desc, vma); 855 861 goto out; 856 862 } 857 863
+2 -2
include/linux/uio_driver.h
··· 97 97 * @irq_flags: flags for request_irq() 98 98 * @priv: optional private data 99 99 * @handler: the device's irq handler 100 - * @mmap: mmap operation for this uio device 100 + * @mmap_prepare: mmap_prepare operation for this uio device 101 101 * @open: open operation for this uio device 102 102 * @release: release operation for this uio device 103 103 * @irqcontrol: disable/enable irqs when 0/1 is written to /dev/uioX ··· 112 112 unsigned long irq_flags; 113 113 void *priv; 114 114 irqreturn_t (*handler)(int irq, struct uio_info *dev_info); 115 - int (*mmap)(struct uio_info *info, struct vm_area_struct *vma); 115 + int (*mmap_prepare)(struct uio_info *info, struct vm_area_desc *desc); 116 116 int (*open)(struct uio_info *info, struct inode *inode); 117 117 int (*release)(struct uio_info *info, struct inode *inode); 118 118 int (*irqcontrol)(struct uio_info *info, s32 irq_on);