Re: [PATCH v3 12/16] PCI: Obey iomem restrictions for procfs mmap

2020-10-23 Thread Jason Gunthorpe
On Thu, Oct 22, 2020 at 09:00:44AM +0200, Daniel Vetter wrote: > On Thu, Oct 22, 2020 at 1:20 AM Jason Gunthorpe wrote: > > > > On Wed, Oct 21, 2020 at 09:24:08PM +0200, Daniel Vetter wrote: > > > On Wed, Oct 21, 2020 at 6:37 PM Jason Gunthorpe wrote: > > > > > > > > On Wed, Oct 21, 2020 at 05:54

Re: [PATCH v3 12/16] PCI: Obey iomem restrictions for procfs mmap

2020-10-22 Thread Daniel Vetter
On Thu, Oct 22, 2020 at 1:43 PM Jason Gunthorpe wrote: > > On Thu, Oct 22, 2020 at 09:00:44AM +0200, Daniel Vetter wrote: > > On Thu, Oct 22, 2020 at 1:20 AM Jason Gunthorpe wrote: > > > > > > On Wed, Oct 21, 2020 at 09:24:08PM +0200, Daniel Vetter wrote: > > > > On Wed, Oct 21, 2020 at 6:37 PM J

Re: [PATCH v3 12/16] PCI: Obey iomem restrictions for procfs mmap

2020-10-22 Thread Jason Gunthorpe
On Wed, Oct 21, 2020 at 09:24:08PM +0200, Daniel Vetter wrote: > On Wed, Oct 21, 2020 at 6:37 PM Jason Gunthorpe wrote: > > > > On Wed, Oct 21, 2020 at 05:54:54PM +0200, Daniel Vetter wrote: > > > > > The trouble is that io_remap_pfn adjust vma->pgoff, so we'd need to > > > split that. So ideally

Re: [PATCH v3 12/16] PCI: Obey iomem restrictions for procfs mmap

2020-10-22 Thread Jason Gunthorpe
On Wed, Oct 21, 2020 at 10:56:51AM +0200, Daniel Vetter wrote: > There's three ways to access PCI BARs from userspace: /dev/mem, sysfs > files, and the old proc interface. Two check against > iomem_is_exclusive, proc never did. And with CONFIG_IO_STRICT_DEVMEM, > this starts to matter, since we don

Re: [PATCH v3 12/16] PCI: Obey iomem restrictions for procfs mmap

2020-10-22 Thread Jason Gunthorpe
On Wed, Oct 21, 2020 at 04:42:11PM +0200, Daniel Vetter wrote: > Uh yes. In drivers/gpu this isn't a problem because we only install > ptes from the vm_ops->fault handler. So no races. And I don't think > you can fix this otherwise through holding locks: mmap_sem we can't > hold because before vma

Re: [PATCH v3 12/16] PCI: Obey iomem restrictions for procfs mmap

2020-10-22 Thread Jason Gunthorpe
On Wed, Oct 21, 2020 at 05:54:54PM +0200, Daniel Vetter wrote: > The trouble is that io_remap_pfn adjust vma->pgoff, so we'd need to > split that. So ideally ->mmap would never set up any ptes. /dev/mem makes pgoff == pfn so it doesn't get changed by remap. pgoff doesn't get touched for MAP_SHAR

Re: [PATCH v3 12/16] PCI: Obey iomem restrictions for procfs mmap

2020-10-22 Thread Daniel Vetter
On Thu, Oct 22, 2020 at 1:20 AM Jason Gunthorpe wrote: > > On Wed, Oct 21, 2020 at 09:24:08PM +0200, Daniel Vetter wrote: > > On Wed, Oct 21, 2020 at 6:37 PM Jason Gunthorpe wrote: > > > > > > On Wed, Oct 21, 2020 at 05:54:54PM +0200, Daniel Vetter wrote: > > > > > > > The trouble is that io_rema

Re: [PATCH v3 12/16] PCI: Obey iomem restrictions for procfs mmap

2020-10-21 Thread Daniel Vetter
On Wed, Oct 21, 2020 at 6:37 PM Jason Gunthorpe wrote: > > On Wed, Oct 21, 2020 at 05:54:54PM +0200, Daniel Vetter wrote: > > > The trouble is that io_remap_pfn adjust vma->pgoff, so we'd need to > > split that. So ideally ->mmap would never set up any ptes. > > /dev/mem makes pgoff == pfn so it d

Re: [PATCH v3 12/16] PCI: Obey iomem restrictions for procfs mmap

2020-10-21 Thread Daniel Vetter
On Wed, Oct 21, 2020 at 5:13 PM Jason Gunthorpe wrote: > > On Wed, Oct 21, 2020 at 04:42:11PM +0200, Daniel Vetter wrote: > > > Uh yes. In drivers/gpu this isn't a problem because we only install > > ptes from the vm_ops->fault handler. So no races. And I don't think > > you can fix this otherwise

Re: [PATCH v3 12/16] PCI: Obey iomem restrictions for procfs mmap

2020-10-21 Thread Daniel Vetter
On Wed, Oct 21, 2020 at 2:50 PM Jason Gunthorpe wrote: > > On Wed, Oct 21, 2020 at 10:56:51AM +0200, Daniel Vetter wrote: > > There's three ways to access PCI BARs from userspace: /dev/mem, sysfs > > files, and the old proc interface. Two check against > > iomem_is_exclusive, proc never did. And w

[PATCH v3 12/16] PCI: Obey iomem restrictions for procfs mmap

2020-10-21 Thread Daniel Vetter
There's three ways to access PCI BARs from userspace: /dev/mem, sysfs files, and the old proc interface. Two check against iomem_is_exclusive, proc never did. And with CONFIG_IO_STRICT_DEVMEM, this starts to matter, since we don't want random userspace having access to PCI BARs while a driver is lo