Skip to content

Commit af94002

Browse files
committed
csky: Fixup swapon
Current csky's swappon is broken by wrong swap PTE entry format. Now redesign the new format for abiv1 & abiv2 and make swappon + zram work properly on csky machines. C-SKY PTE has VALID, DIRTY to emulate PRESENT, READ, WRITE, EXEC attributes. GLOBAL bit is shared by two pages in the same tlb entry. So we need to keep GLOBAL, VALID, PRESENT zero in swp_pte. To distinguish PAGE_NONE and swp_pte, we need to use an additional bit (abiv1 is _PAGE_READ, abiv2 is _PAGE_WRITE). Signed-off-by: Guo Ren <guoren@linux.alibaba.com> Cc: Arnd Bergmann <arnd@arndb.de>
1 parent a8fac05 commit af94002

3 files changed

Lines changed: 52 additions & 9 deletions

File tree

arch/csky/abiv1/inc/abi/pgtable-bits.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,28 @@
2424
#define _CACHE_CACHED _PAGE_CACHE
2525
#define _CACHE_UNCACHED _PAGE_UNCACHE
2626

27+
#define _PAGE_PROT_NONE _PAGE_READ
28+
29+
/*
30+
* Encode and decode a swap entry
31+
*
32+
* Format of swap PTE:
33+
* bit 0: _PAGE_PRESENT (zero)
34+
* bit 1: _PAGE_READ (zero)
35+
* bit 2 - 5: swap type[0 - 3]
36+
* bit 6: _PAGE_GLOBAL (zero)
37+
* bit 7: _PAGE_VALID (zero)
38+
* bit 8: swap type[4]
39+
* bit 9 - 31: swap offset
40+
*/
41+
#define __swp_type(x) ((((x).val >> 2) & 0xf) | \
42+
(((x).val >> 4) & 0x10))
43+
#define __swp_offset(x) ((x).val >> 9)
44+
#define __swp_entry(type, offset) ((swp_entry_t) { \
45+
((type & 0xf) << 2) | \
46+
((type & 0x10) << 4) | \
47+
((offset) << 9)})
48+
2749
#define HAVE_ARCH_UNMAPPED_AREA
2850

2951
#endif /* __ASM_CSKY_PGTABLE_BITS_H */

arch/csky/abiv2/inc/abi/pgtable-bits.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,26 @@
2424
#define _CACHE_CACHED (_PAGE_CACHE | _PAGE_BUF)
2525
#define _CACHE_UNCACHED (0)
2626

27+
#define _PAGE_PROT_NONE _PAGE_WRITE
28+
29+
/*
30+
* Encode and decode a swap entry
31+
*
32+
* Format of swap PTE:
33+
* bit 0: _PAGE_GLOBAL (zero)
34+
* bit 1: _PAGE_VALID (zero)
35+
* bit 2 - 6: swap type
36+
* bit 7 - 8: swap offset[0 - 1]
37+
* bit 9: _PAGE_WRITE (zero)
38+
* bit 10: _PAGE_PRESENT (zero)
39+
* bit 11 - 31: swap offset[2 - 22]
40+
*/
41+
#define __swp_type(x) (((x).val >> 2) & 0x1f)
42+
#define __swp_offset(x) ((((x).val >> 7) & 0x3) | \
43+
(((x).val >> 9) & 0x7ffffc))
44+
#define __swp_entry(type, offset) ((swp_entry_t) { \
45+
((type & 0x1f) << 2) | \
46+
((offset & 0x3) << 7) | \
47+
((offset & 0x7ffffc) << 9)})
48+
2749
#endif /* __ASM_CSKY_PGTABLE_BITS_H */

arch/csky/include/asm/pgtable.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@
4141
#define pfn_pte(pfn, prot) __pte(((unsigned long long)(pfn) << PAGE_SHIFT) \
4242
| pgprot_val(prot))
4343

44-
#define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_MODIFIED | \
45-
_CACHE_MASK)
46-
47-
#define __swp_type(x) (((x).val >> 4) & 0xff)
48-
#define __swp_offset(x) ((x).val >> 12)
49-
#define __swp_entry(type, offset) ((swp_entry_t) {((type) << 4) | \
50-
((offset) << 12) })
5144
#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
5245
#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
5346

@@ -61,8 +54,7 @@
6154
*/
6255
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
6356

64-
#define PAGE_NONE __pgprot(_PAGE_BASE | \
65-
_CACHE_CACHED)
57+
#define PAGE_NONE __pgprot(_PAGE_PROT_NONE)
6658
#define PAGE_READ __pgprot(_PAGE_BASE | _PAGE_READ | \
6759
_CACHE_CACHED)
6860
#define PAGE_WRITE __pgprot(_PAGE_BASE | _PAGE_READ | _PAGE_WRITE | \
@@ -79,6 +71,13 @@
7971
_PAGE_GLOBAL | \
8072
_CACHE_UNCACHED | _PAGE_SO)
8173

74+
#define _PAGE_CHG_MASK (~(unsigned long) \
75+
(_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \
76+
_CACHE_MASK | _PAGE_GLOBAL))
77+
78+
#define MAX_SWAPFILES_CHECK() \
79+
BUILD_BUG_ON(MAX_SWAPFILES_SHIFT != 5)
80+
8281
#define __P000 PAGE_NONE
8382
#define __P001 PAGE_READ
8483
#define __P010 PAGE_READ

0 commit comments

Comments
 (0)