mm/gup/writeback: add callbacks for inaccessible pages

With the introduction of protected KVM guests on s390 there is now a
concept of inaccessible pages.  These pages need to be made accessible
before the host can access them.

While cpu accesses will trigger a fault that can be resolved, I/O accesses
will just fail.  We need to add a callback into architecture code for
places that will do I/O, namely when writeback is started or when a page
reference is taken.

This is not only to enable paging, file backing etc, it is also necessary
to protect the host against a malicious user space.  For example a bad
QEMU could simply start direct I/O on such protected memory.  We do not
want userspace to be able to trigger I/O errors and thus the logic is
"whenever somebody accesses that page (gup) or does I/O, make sure that
this page can be accessed".  When the guest tries to access that page we
will wait in the page fault handler for writeback to have finished and for
the page_ref to be the expected value.

On s390x the function is not supposed to fail, so it is ok to use a
WARN_ON on failure.  If we ever need some more finegrained handling we can
tackle this when we know the details.

Signed-off-by: Claudio Imbrenda <>
Acked-by: Will Deacon <>
Reviewed-by: David Hildenbrand <>
Reviewed-by: Christian Borntraeger <>
Reviewed-by: John Hubbard <>
Cc: Jan Kara <>
Cc: Matthew Wilcox <>
Cc: Ira Weiny <>
Cc: Jérôme Glisse <>
Cc: Al Viro <>
Cc: Christoph Hellwig <>
Cc: Dan Williams <>
Cc: Dave Chinner <>
Cc: Jason Gunthorpe <>
Cc: Jonathan Corbet <>
Cc: Michal Hocko <>
Cc: Mike Kravetz <>
Cc: Shuah Khan <>
Cc: Vlastimil Babka <>
Signed-off-by: Andrew Morton <>
Signed-off-by: Stephen Rothwell <>
[ backport]
Signed-off-by: Christian Borntraeger <>
3 files changed