Skip to content

Commit ad3150f

Browse files
davidhildenbrandakpm00
authored andcommitted
loongarch/mm: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
Let's support __HAVE_ARCH_PTE_SWP_EXCLUSIVE by stealing one bit from the type. Generic MM currently only uses 5 bits for the type (MAX_SWAPFILES_SHIFT), so the stolen bit is effectively unused. While at it, also mask the type in mk_swap_pte(). Note that this bit does not conflict with swap PMDs and could also be used in swap PMD context later. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: David Hildenbrand <[email protected]> Cc: Huacai Chen <[email protected]> Cc: WANG Xuerui <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 3151cc2 commit ad3150f

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

arch/loongarch/include/asm/pgtable-bits.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define _PAGE_SPECIAL_SHIFT 11
2121
#define _PAGE_HGLOBAL_SHIFT 12 /* HGlobal is a PMD bit */
2222
#define _PAGE_PFN_SHIFT 12
23+
#define _PAGE_SWP_EXCLUSIVE_SHIFT 23
2324
#define _PAGE_PFN_END_SHIFT 48
2425
#define _PAGE_NO_READ_SHIFT 61
2526
#define _PAGE_NO_EXEC_SHIFT 62
@@ -33,6 +34,9 @@
3334
#define _PAGE_PROTNONE (_ULCAST_(1) << _PAGE_PROTNONE_SHIFT)
3435
#define _PAGE_SPECIAL (_ULCAST_(1) << _PAGE_SPECIAL_SHIFT)
3536

37+
/* We borrow bit 23 to store the exclusive marker in swap PTEs. */
38+
#define _PAGE_SWP_EXCLUSIVE (_ULCAST_(1) << _PAGE_SWP_EXCLUSIVE_SHIFT)
39+
3640
/* Used by TLB hardware (placed in EntryLo*) */
3741
#define _PAGE_VALID (_ULCAST_(1) << _PAGE_VALID_SHIFT)
3842
#define _PAGE_DIRTY (_ULCAST_(1) << _PAGE_DIRTY_SHIFT)

arch/loongarch/include/asm/pgtable.h

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,20 +249,51 @@ extern void pud_init(void *addr);
249249
extern void pmd_init(void *addr);
250250

251251
/*
252-
* Non-present pages: high 40 bits are offset, next 8 bits type,
253-
* low 16 bits zero.
252+
* Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that
253+
* are !pte_none() && !pte_present().
254+
*
255+
* Format of swap PTEs:
256+
*
257+
* 6 6 6 6 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3
258+
* 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2
259+
* <--------------------------- offset ---------------------------
260+
*
261+
* 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
262+
* 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
263+
* --------------> E <--- type ---> <---------- zeroes ---------->
264+
*
265+
* E is the exclusive marker that is not stored in swap entries.
266+
* The zero'ed bits include _PAGE_PRESENT and _PAGE_PROTNONE.
254267
*/
255268
static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
256-
{ pte_t pte; pte_val(pte) = (type << 16) | (offset << 24); return pte; }
269+
{ pte_t pte; pte_val(pte) = ((type & 0x7f) << 16) | (offset << 24); return pte; }
257270

258-
#define __swp_type(x) (((x).val >> 16) & 0xff)
271+
#define __swp_type(x) (((x).val >> 16) & 0x7f)
259272
#define __swp_offset(x) ((x).val >> 24)
260273
#define __swp_entry(type, offset) ((swp_entry_t) { pte_val(mk_swap_pte((type), (offset))) })
261274
#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
262275
#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
263276
#define __pmd_to_swp_entry(pmd) ((swp_entry_t) { pmd_val(pmd) })
264277
#define __swp_entry_to_pmd(x) ((pmd_t) { (x).val | _PAGE_HUGE })
265278

279+
#define __HAVE_ARCH_PTE_SWP_EXCLUSIVE
280+
static inline int pte_swp_exclusive(pte_t pte)
281+
{
282+
return pte_val(pte) & _PAGE_SWP_EXCLUSIVE;
283+
}
284+
285+
static inline pte_t pte_swp_mkexclusive(pte_t pte)
286+
{
287+
pte_val(pte) |= _PAGE_SWP_EXCLUSIVE;
288+
return pte;
289+
}
290+
291+
static inline pte_t pte_swp_clear_exclusive(pte_t pte)
292+
{
293+
pte_val(pte) &= ~_PAGE_SWP_EXCLUSIVE;
294+
return pte;
295+
}
296+
266297
extern void paging_init(void);
267298

268299
#define pte_none(pte) (!(pte_val(pte) & ~_PAGE_GLOBAL))

0 commit comments

Comments
 (0)