linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Avoid live-lock in fault-in+uaccess loops with sub-page faults
@ 2021-11-24 19:20 Catalin Marinas
  2021-11-24 19:20 ` [PATCH 1/3] mm: Introduce fault_in_exact_writeable() to probe for " Catalin Marinas
                   ` (3 more replies)
  0 siblings, 4 replies; 34+ messages in thread
From: Catalin Marinas @ 2021-11-24 19:20 UTC (permalink / raw)
  To: Linus Torvalds, Josef Bacik, David Sterba
  Cc: Andreas Gruenbacher, Al Viro, Andrew Morton, Will Deacon,
	linux-fsdevel, linux-kernel, linux-arm-kernel, linux-btrfs

Hi,

There are a few places in the filesystem layer where a uaccess is
performed in a loop with page faults disabled, together with a
fault_in_*() call to pre-fault the pages. On architectures like arm64
with MTE (memory tagging extensions) or SPARC ADI, even if the
fault_in_*() succeeded, the uaccess can still fault indefinitely.

In general this is not an issue since such code restarts the
fault_in_*() from where the uaccess failed, therefore guaranteeing
forward progress. The btrfs search_ioctl(), however, rewinds the
fault_in_*() position and it can live-lock. This was reported by Al
here:

https://lore.kernel.org/r/YSqOUb7yZ7kBoKRY@zeniv-ca.linux.org.uk

There's also an analysis by Al of other fault-in places:

https://lore.kernel.org/r/YSldx9uhMYhT/G8X@zeniv-ca.linux.org.uk

and another sub-thread on the same topic:

https://lore.kernel.org/r/YXBFqD9WVuU8awIv@arm.com

So far only btrfs search_ioctl() seems to be affected and that's what
this series addresses. The existing loops like generic_perform_write()
already guarantee forward progress.

Andreas raised a concern about O_DIRECT accesses since on fault the user
address is rewound to a block size boundary. I tried ext4, btrfs and
gfs2 and I could not get any of them to live-lock. Depending on the
alignment of the user buffer (page or not), I found two behaviours:

- the copy to or from the user buffer succeeds entirely if it goes
  through the kernel mapping (GUP, kmap'ed page; user MTE tags are not
  checked) or

- the copy partially succeeds after a few attempts at uaccess on the
  faulting same address (the highest number of attempts in my tests was
  11 with btrfs).

Given the high cost of such sub-page probing (which is done prior to the
uaccess) my proposal is to only change the btrfs search_ioctl() (as per
the last patch). We can extend the API and call places in the future if
needed but I hope filesystems already deal with this in other ways.

Thanks.

Catalin Marinas (3):
  mm: Introduce fault_in_exact_writeable() to probe for sub-page faults
  arm64: Add support for sub-page faults user probing
  btrfs: Avoid live-lock in search_ioctl() on hardware with sub-page
    faults

 arch/Kconfig                     |  7 +++++++
 arch/arm64/Kconfig               |  1 +
 arch/arm64/include/asm/uaccess.h | 33 ++++++++++++++++++++++++++++++++
 fs/btrfs/ioctl.c                 |  3 ++-
 include/linux/pagemap.h          |  1 +
 include/linux/uaccess.h          | 21 ++++++++++++++++++++
 mm/gup.c                         | 19 ++++++++++++++++++
 7 files changed, 84 insertions(+), 1 deletion(-)


^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2021-11-29 23:16 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-24 19:20 [PATCH 0/3] Avoid live-lock in fault-in+uaccess loops with sub-page faults Catalin Marinas
2021-11-24 19:20 ` [PATCH 1/3] mm: Introduce fault_in_exact_writeable() to probe for " Catalin Marinas
2021-11-24 19:20 ` [PATCH 2/3] arm64: Add support for sub-page faults user probing Catalin Marinas
2021-11-24 19:20 ` [PATCH 3/3] btrfs: Avoid live-lock in search_ioctl() on hardware with sub-page faults Catalin Marinas
2021-11-24 20:03   ` Matthew Wilcox
2021-11-24 20:37     ` Catalin Marinas
2021-11-25 22:25       ` Andreas Gruenbacher
2021-11-25 22:42         ` Catalin Marinas
2021-11-26 22:29         ` Andreas Gruenbacher
2021-11-26 22:57           ` Catalin Marinas
2021-11-27  3:52             ` Andreas Gruenbacher
2021-11-27 14:33               ` Catalin Marinas
2021-11-27 12:39         ` Andreas Gruenbacher
2021-11-27 15:21           ` Catalin Marinas
2021-11-27 18:05             ` Andreas Gruenbacher
2021-11-29 12:16               ` Catalin Marinas
2021-11-29 13:33                 ` Andreas Gruenbacher
2021-11-29 15:36                   ` Catalin Marinas
2021-11-29 18:40                     ` Linus Torvalds
2021-11-29 19:31                       ` Andreas Gruenbacher
2021-11-29 20:56                       ` Catalin Marinas
2021-11-29 21:53                         ` Linus Torvalds
2021-11-29 23:12                           ` Catalin Marinas
2021-11-29 13:52               ` Catalin Marinas
2021-11-24 23:00     ` Linus Torvalds
2021-11-25 11:10       ` Catalin Marinas
2021-11-25 18:13         ` Linus Torvalds
2021-11-25 20:43           ` Catalin Marinas
2021-11-25 21:02             ` Matthew Wilcox
2021-11-25 21:29               ` Catalin Marinas
2021-11-25 21:40               ` Andreas Gruenbacher
2021-11-26 16:42   ` David Sterba
2021-11-24 21:36 ` [PATCH 0/3] Avoid live-lock in fault-in+uaccess loops " Andrew Morton
2021-11-24 22:31   ` Catalin Marinas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).