I am writing a Linux device module that need to occasionally pin userspace memory pages. Some of these pages may be backed by a file placed on a filesystem. That happens if a userspace program which calls my driver has used mmap() to create non-anonymous mappings.
As described in a long series of LWN posts [1] about the issues around get_user_pages() and mmap'ed regions, if a driver does DMA into such pages, it may cause problems.
I want to detect such file-backed pages and treat them differently from "normal" anonymous pages (e.g. by rejecting them, issuing a warning or generally changing the control flow in my module)
Given that I have a pointer to struct page [2] in my possession, is there a way to detect whether it is backed by a file (inode) or not?