]> git.ipfire.org Git - thirdparty/linux.git/commit - mm/memory.c
mm: refactor do_fault_around()
authorLorenzo Stoakes <lstoakes@gmail.com>
Fri, 17 Mar 2023 21:58:25 +0000 (21:58 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 6 Apr 2023 02:42:51 +0000 (19:42 -0700)
commit9042599e81c295f0b12d940248d6608e87e7b6b6
tree4a0ea1f330bf97fede0dbb73ca8638d3528fde31
parent1c06b6a599b5b7be74a6baffafa00b0f70cbe523
mm: refactor do_fault_around()

Patch series "Refactor do_fault_around()"

Refactor do_fault_around() to avoid bitwise tricks and rather difficult to
follow logic.  Additionally, prefer fault_around_pages to
fault_around_bytes as the operations are performed at a base page
granularity.

This patch (of 2):

The existing logic is confusing and fails to abstract a number of bitwise
tricks.

Use ALIGN_DOWN() to perform alignment, pte_index() to obtain a PTE index
and represent the address range using PTE offsets, which naturally make it
clear that the operation is intended to occur within only a single PTE and
prevent spanning of more than one page table.

We rely on the fact that fault_around_bytes will always be page-aligned,
at least one page in size, a power of two and that it will not exceed
PAGE_SIZE * PTRS_PER_PTE in size (i.e.  the address space mapped by a
PTE).  These are all guaranteed by fault_around_bytes_set().

Link: https://lkml.kernel.org/r/cover.1679089214.git.lstoakes@gmail.com
Link: https://lkml.kernel.org/r/d125db1c3665a63b80cea29d56407825482e2262.1679089214.git.lstoakes@gmail.com
Signed-off-by: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/memory.c