On Tue, Mar 16, 2021 at 04:33:01PM +0100, Daniel Vetter wrote: > Way back it was a reasonable assumptions that iomem mappings never > change the pfn range they point at. But this has changed: > > - gpu drivers dynamically manage their memory nowadays, invalidating > ptes with unmap_mapping_range when buffers get moved > > - contiguous dma allocations have moved from dedicated carvetouts to > cma regions. This means if we miss the unmap the pfn might contain > pagecache or anon memory (well anything allocated with GFP_MOVEABLE) > > - even /dev/mem now invalidates mappings when the kernel requests that > iomem region when CONFIG_IO_STRICT_DEVMEM is set, see 3234ac664a87 > ("/dev/mem: Revoke mappings when a driver claims the region") > > Accessing pfns obtained from ptes without holding all the locks is > therefore no longer a good idea. > > Unfortunately there's some users where this is not fixable (like v4l > userptr of iomem mappings) or involves a pile of work (vfio type1 > iommu). For now annotate these as unsafe and splat appropriately. > > This patch adds an unsafe_follow_pfn, which later patches will then > roll out to all appropriate places. > > Also mark up follow_pfn as EXPORT_SYMBOL_GPL. The only safe way to use > that by drivers/modules is together with an mmu_notifier, and that's > all _GPL stuff. > > Signed-off-by: Daniel Vetter <daniel.vet...@intel.com> > Cc: Christoph Hellwig <h...@infradead.org> > Cc: Jason Gunthorpe <j...@ziepe.ca> > Cc: Kees Cook <keesc...@chromium.org> > Cc: Dan Williams <dan.j.willi...@intel.com> > Cc: Andrew Morton <a...@linux-foundation.org> > Cc: John Hubbard <jhubb...@nvidia.com> > Cc: Jérôme Glisse <jgli...@redhat.com> > Cc: Jan Kara <j...@suse.cz> > Cc: Dan Williams <dan.j.willi...@intel.com> > Cc: linux...@kvack.org > Cc: linux-arm-ker...@lists.infradead.org > Cc: linux-samsung-...@vger.kernel.org > Cc: linux-me...@vger.kernel.org > Cc: k...@vger.kernel.org > Signed-off-by: Daniel Vetter <daniel.vet...@ffwll.ch> > -- > v5: Suggestions from Christoph > - reindent for less weirdness > - use IS_ENABLED instead of #ifdef > - same checks for nommu, for consistency > - EXPORT_SYMBOL_GPL for follow_pfn. > - kerneldoc was already updated in previous versions to explain when > follow_pfn can be used safely > --- > include/linux/mm.h | 2 ++ > mm/memory.c | 34 ++++++++++++++++++++++++++++++++-- > mm/nommu.c | 27 ++++++++++++++++++++++++++- > security/Kconfig | 13 +++++++++++++ > 4 files changed, 73 insertions(+), 3 deletions(-)
Reviewed-by: Jason Gunthorpe <j...@nvidia.com> Jason _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel