linux/arch
Peter Xu 0d206b5d2e mm/swap: add swp_offset_pfn() to fetch PFN from swap entry
We've got a bunch of special swap entries that stores PFN inside the swap
offset fields.  To fetch the PFN, normally the user just calls
swp_offset() assuming that'll be the PFN.

Add a helper swp_offset_pfn() to fetch the PFN instead, fetching only the
max possible length of a PFN on the host, meanwhile doing proper check
with MAX_PHYSMEM_BITS to make sure the swap offsets can actually store the
PFNs properly always using the BUILD_BUG_ON() in is_pfn_swap_entry().

One reason to do so is we never tried to sanitize whether swap offset can
really fit for storing PFN.  At the meantime, this patch also prepares us
with the future possibility to store more information inside the swp
offset field, so assuming "swp_offset(entry)" to be the PFN will not stand
any more very soon.

Replace many of the swp_offset() callers to use swp_offset_pfn() where
proper.  Note that many of the existing users are not candidates for the
replacement, e.g.:

  (1) When the swap entry is not a pfn swap entry at all, or,
  (2) when we wanna keep the whole swp_offset but only change the swp type.

For the latter, it can happen when fork() triggered on a write-migration
swap entry pte, we may want to only change the migration type from
write->read but keep the rest, so it's not "fetching PFN" but "changing
swap type only".  They're left aside so that when there're more
information within the swp offset they'll be carried over naturally in
those cases.

Since at it, dropping hwpoison_entry_to_pfn() because that's exactly what
the new swp_offset_pfn() is about.

Link: https://lkml.kernel.org/r/20220811161331.37055-4-peterx@redhat.com
Signed-off-by: Peter Xu <peterx@redhat.com>
Reviewed-by: "Huang, Ying" <ying.huang@intel.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Andi Kleen <andi.kleen@intel.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: "Kirill A . Shutemov" <kirill@shutemov.name>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nadav Amit <nadav.amit@gmail.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Dave Hansen <dave.hansen@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-09-26 19:46:05 -07:00
..
alpha mm/madvise: introduce MADV_COLLAPSE sync hugepage collapse 2022-09-11 20:25:46 -07:00
arc arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
arm arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
arm64 mm/swap: add swp_offset_pfn() to fetch PFN from swap entry 2022-09-26 19:46:05 -07:00
csky arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
hexagon provide arch_test_bit_acquire for architectures that define test_bit 2022-08-27 09:49:54 -07:00
ia64 arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
loongarch arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
m68k arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
microblaze - The usual batches of cleanups from Baoquan He, Muchun Song, Miaohe 2022-08-05 16:32:45 -07:00
mips arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
nios2 arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
openrisc Updates to various subsystems which I help look after. lib, ocfs2, 2022-08-07 10:03:24 -07:00
parisc mm/madvise: introduce MADV_COLLAPSE sync hugepage collapse 2022-09-11 20:25:46 -07:00
powerpc Merge branch 'mm-hotfixes-stable' into mm-stable 2022-09-26 13:13:15 -07:00
riscv RISC-V Fixes for 6.0-rc3 2022-08-26 11:26:27 -07:00
s390 s390/hugetlb: switch to generic version of follow_huge_pud() 2022-09-11 20:26:01 -07:00
sh arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
sparc arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
um asm goto: eradicate CC_HAS_ASM_GOTO 2022-08-21 10:06:28 -07:00
x86 mm/x86: use SWP_TYPE_BITS in 3-level swap macros 2022-09-26 19:46:04 -07:00
xtensa arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
.gitignore
Kconfig asm goto: eradicate CC_HAS_ASM_GOTO 2022-08-21 10:06:28 -07:00