Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm: pgtable: fix pte_swp_exclusive

Make pte_swp_exclusive return bool instead of int. This will better
reflect how pte_swp_exclusive is actually used in the code.

This fixes swap/swapoff problems on Alpha due pte_swp_exclusive not
returning correct values when _PAGE_SWP_EXCLUSIVE bit resides in upper
32-bits of PTE (like on alpha).

Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
Cc: Sam James <sam@gentoo.org>
Link: https://lore.kernel.org/lkml/20250218175735.19882-2-linmag7@gmail.com/
Link: https://lore.kernel.org/lkml/20250602041118.GA2675383@ZenIV/
[ Applied as the 'sed' script Al suggested - Linus ]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Magnus Lindholm and committed by
Linus Torvalds
403d1338 488ef356

+27 -27
+1 -1
arch/alpha/include/asm/pgtable.h
··· 327 327 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 328 328 #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) 329 329 330 - static inline int pte_swp_exclusive(pte_t pte) 330 + static inline bool pte_swp_exclusive(pte_t pte) 331 331 { 332 332 return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 333 333 }
+1 -1
arch/arc/include/asm/pgtable-bits-arcv2.h
··· 130 130 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 131 131 #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) 132 132 133 - static inline int pte_swp_exclusive(pte_t pte) 133 + static inline bool pte_swp_exclusive(pte_t pte) 134 134 { 135 135 return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 136 136 }
+1 -1
arch/arm/include/asm/pgtable.h
··· 301 301 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 302 302 #define __swp_entry_to_pte(swp) __pte((swp).val) 303 303 304 - static inline int pte_swp_exclusive(pte_t pte) 304 + static inline bool pte_swp_exclusive(pte_t pte) 305 305 { 306 306 return pte_isset(pte, L_PTE_SWP_EXCLUSIVE); 307 307 }
+1 -1
arch/arm64/include/asm/pgtable.h
··· 563 563 return set_pte_bit(pte, __pgprot(PTE_SWP_EXCLUSIVE)); 564 564 } 565 565 566 - static inline int pte_swp_exclusive(pte_t pte) 566 + static inline bool pte_swp_exclusive(pte_t pte) 567 567 { 568 568 return pte_val(pte) & PTE_SWP_EXCLUSIVE; 569 569 }
+1 -1
arch/csky/include/asm/pgtable.h
··· 200 200 return pte; 201 201 } 202 202 203 - static inline int pte_swp_exclusive(pte_t pte) 203 + static inline bool pte_swp_exclusive(pte_t pte) 204 204 { 205 205 return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 206 206 }
+1 -1
arch/hexagon/include/asm/pgtable.h
··· 387 387 (((type & 0x1f) << 1) | \ 388 388 ((offset & 0x3ffff8) << 10) | ((offset & 0x7) << 7)) }) 389 389 390 - static inline int pte_swp_exclusive(pte_t pte) 390 + static inline bool pte_swp_exclusive(pte_t pte) 391 391 { 392 392 return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 393 393 }
+1 -1
arch/loongarch/include/asm/pgtable.h
··· 301 301 #define __pmd_to_swp_entry(pmd) ((swp_entry_t) { pmd_val(pmd) }) 302 302 #define __swp_entry_to_pmd(x) ((pmd_t) { (x).val | _PAGE_HUGE }) 303 303 304 - static inline int pte_swp_exclusive(pte_t pte) 304 + static inline bool pte_swp_exclusive(pte_t pte) 305 305 { 306 306 return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 307 307 }
+1 -1
arch/m68k/include/asm/mcf_pgtable.h
··· 268 268 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 269 269 #define __swp_entry_to_pte(x) (__pte((x).val)) 270 270 271 - static inline int pte_swp_exclusive(pte_t pte) 271 + static inline bool pte_swp_exclusive(pte_t pte) 272 272 { 273 273 return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 274 274 }
+1 -1
arch/m68k/include/asm/motorola_pgtable.h
··· 185 185 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 186 186 #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) 187 187 188 - static inline int pte_swp_exclusive(pte_t pte) 188 + static inline bool pte_swp_exclusive(pte_t pte) 189 189 { 190 190 return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 191 191 }
+1 -1
arch/m68k/include/asm/sun3_pgtable.h
··· 169 169 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 170 170 #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) 171 171 172 - static inline int pte_swp_exclusive(pte_t pte) 172 + static inline bool pte_swp_exclusive(pte_t pte) 173 173 { 174 174 return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 175 175 }
+1 -1
arch/microblaze/include/asm/pgtable.h
··· 398 398 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> 2 }) 399 399 #define __swp_entry_to_pte(x) ((pte_t) { (x).val << 2 }) 400 400 401 - static inline int pte_swp_exclusive(pte_t pte) 401 + static inline bool pte_swp_exclusive(pte_t pte) 402 402 { 403 403 return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 404 404 }
+2 -2
arch/mips/include/asm/pgtable.h
··· 534 534 #endif 535 535 536 536 #if defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32) 537 - static inline int pte_swp_exclusive(pte_t pte) 537 + static inline bool pte_swp_exclusive(pte_t pte) 538 538 { 539 539 return pte.pte_low & _PAGE_SWP_EXCLUSIVE; 540 540 } ··· 551 551 return pte; 552 552 } 553 553 #else 554 - static inline int pte_swp_exclusive(pte_t pte) 554 + static inline bool pte_swp_exclusive(pte_t pte) 555 555 { 556 556 return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 557 557 }
+1 -1
arch/nios2/include/asm/pgtable.h
··· 259 259 #define __swp_entry_to_pte(swp) ((pte_t) { (swp).val }) 260 260 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 261 261 262 - static inline int pte_swp_exclusive(pte_t pte) 262 + static inline bool pte_swp_exclusive(pte_t pte) 263 263 { 264 264 return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 265 265 }
+1 -1
arch/openrisc/include/asm/pgtable.h
··· 411 411 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 412 412 #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) 413 413 414 - static inline int pte_swp_exclusive(pte_t pte) 414 + static inline bool pte_swp_exclusive(pte_t pte) 415 415 { 416 416 return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 417 417 }
+1 -1
arch/parisc/include/asm/pgtable.h
··· 425 425 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 426 426 #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) 427 427 428 - static inline int pte_swp_exclusive(pte_t pte) 428 + static inline bool pte_swp_exclusive(pte_t pte) 429 429 { 430 430 return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 431 431 }
+1 -1
arch/powerpc/include/asm/book3s/32/pgtable.h
··· 365 365 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> 3 }) 366 366 #define __swp_entry_to_pte(x) ((pte_t) { (x).val << 3 }) 367 367 368 - static inline int pte_swp_exclusive(pte_t pte) 368 + static inline bool pte_swp_exclusive(pte_t pte) 369 369 { 370 370 return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 371 371 }
+1 -1
arch/powerpc/include/asm/book3s/64/pgtable.h
··· 693 693 return __pte_raw(pte_raw(pte) | cpu_to_be64(_PAGE_SWP_EXCLUSIVE)); 694 694 } 695 695 696 - static inline int pte_swp_exclusive(pte_t pte) 696 + static inline bool pte_swp_exclusive(pte_t pte) 697 697 { 698 698 return !!(pte_raw(pte) & cpu_to_be64(_PAGE_SWP_EXCLUSIVE)); 699 699 }
+1 -1
arch/powerpc/include/asm/nohash/pgtable.h
··· 286 286 return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot)); 287 287 } 288 288 289 - static inline int pte_swp_exclusive(pte_t pte) 289 + static inline bool pte_swp_exclusive(pte_t pte) 290 290 { 291 291 return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 292 292 }
+1 -1
arch/riscv/include/asm/pgtable.h
··· 1028 1028 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 1029 1029 #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) 1030 1030 1031 - static inline int pte_swp_exclusive(pte_t pte) 1031 + static inline bool pte_swp_exclusive(pte_t pte) 1032 1032 { 1033 1033 return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 1034 1034 }
+1 -1
arch/s390/include/asm/pgtable.h
··· 915 915 } 916 916 #endif 917 917 918 - static inline int pte_swp_exclusive(pte_t pte) 918 + static inline bool pte_swp_exclusive(pte_t pte) 919 919 { 920 920 return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 921 921 }
+1 -1
arch/sh/include/asm/pgtable_32.h
··· 470 470 /* In both cases, we borrow bit 6 to store the exclusive marker in swap PTEs. */ 471 471 #define _PAGE_SWP_EXCLUSIVE _PAGE_USER 472 472 473 - static inline int pte_swp_exclusive(pte_t pte) 473 + static inline bool pte_swp_exclusive(pte_t pte) 474 474 { 475 475 return pte.pte_low & _PAGE_SWP_EXCLUSIVE; 476 476 }
+1 -1
arch/sparc/include/asm/pgtable_32.h
··· 348 348 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 349 349 #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) 350 350 351 - static inline int pte_swp_exclusive(pte_t pte) 351 + static inline bool pte_swp_exclusive(pte_t pte) 352 352 { 353 353 return pte_val(pte) & SRMMU_SWP_EXCLUSIVE; 354 354 }
+1 -1
arch/sparc/include/asm/pgtable_64.h
··· 1023 1023 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 1024 1024 #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) 1025 1025 1026 - static inline int pte_swp_exclusive(pte_t pte) 1026 + static inline bool pte_swp_exclusive(pte_t pte) 1027 1027 { 1028 1028 return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 1029 1029 }
+1 -1
arch/um/include/asm/pgtable.h
··· 314 314 ((swp_entry_t) { pte_val(pte_mkuptodate(pte)) }) 315 315 #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) 316 316 317 - static inline int pte_swp_exclusive(pte_t pte) 317 + static inline bool pte_swp_exclusive(pte_t pte) 318 318 { 319 319 return pte_get_bits(pte, _PAGE_SWP_EXCLUSIVE); 320 320 }
+1 -1
arch/x86/include/asm/pgtable.h
··· 1561 1561 return pte_set_flags(pte, _PAGE_SWP_EXCLUSIVE); 1562 1562 } 1563 1563 1564 - static inline int pte_swp_exclusive(pte_t pte) 1564 + static inline bool pte_swp_exclusive(pte_t pte) 1565 1565 { 1566 1566 return pte_flags(pte) & _PAGE_SWP_EXCLUSIVE; 1567 1567 }
+1 -1
arch/xtensa/include/asm/pgtable.h
··· 349 349 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 350 350 #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) 351 351 352 - static inline int pte_swp_exclusive(pte_t pte) 352 + static inline bool pte_swp_exclusive(pte_t pte) 353 353 { 354 354 return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 355 355 }