Commit 152125b7 authored by Martin Schwidefsky's avatar Martin Schwidefsky

s390/mm: implement dirty bits for large segment table entries

The large segment table entry format has block of bits for the
ACC/F values for the large page. These bits are valid only if
another bit (AV bit 0x10000) of the segment table entry is set.
The ACC/F bits do not have a meaning if the AV bit is off.
This allows to put the THP splitting bit, the segment young bit
and the new segment dirty bit into the ACC/F bits as long as
the AV bit stays off. The dirty and young information is only
available if the pmd is large.
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
parent 55e4283c
This diff is collapsed.
...@@ -10,42 +10,33 @@ ...@@ -10,42 +10,33 @@
static inline pmd_t __pte_to_pmd(pte_t pte) static inline pmd_t __pte_to_pmd(pte_t pte)
{ {
int none, young, prot;
pmd_t pmd; pmd_t pmd;
/* /*
* Convert encoding pte bits pmd bits * Convert encoding pte bits pmd bits
* .IR...wrdytp ..R...I...y. * .IR...wrdytp dy..R...I...wr
* empty .10...000000 -> ..0...1...0. * empty .10...000000 -> 00..0...1...00
* prot-none, clean, old .11...000001 -> ..0...1...1. * prot-none, clean, old .11...000001 -> 00..1...1...00
* prot-none, clean, young .11...000101 -> ..1...1...1. * prot-none, clean, young .11...000101 -> 01..1...1...00
* prot-none, dirty, old .10...001001 -> ..0...1...1. * prot-none, dirty, old .10...001001 -> 10..1...1...00
* prot-none, dirty, young .10...001101 -> ..1...1...1. * prot-none, dirty, young .10...001101 -> 11..1...1...00
* read-only, clean, old .11...010001 -> ..1...1...0. * read-only, clean, old .11...010001 -> 00..1...1...01
* read-only, clean, young .01...010101 -> ..1...0...1. * read-only, clean, young .01...010101 -> 01..1...0...01
* read-only, dirty, old .11...011001 -> ..1...1...0. * read-only, dirty, old .11...011001 -> 10..1...1...01
* read-only, dirty, young .01...011101 -> ..1...0...1. * read-only, dirty, young .01...011101 -> 11..1...0...01
* read-write, clean, old .11...110001 -> ..0...1...0. * read-write, clean, old .11...110001 -> 00..0...1...11
* read-write, clean, young .01...110101 -> ..0...0...1. * read-write, clean, young .01...110101 -> 01..0...0...11
* read-write, dirty, old .10...111001 -> ..0...1...0. * read-write, dirty, old .10...111001 -> 10..0...1...11
* read-write, dirty, young .00...111101 -> ..0...0...1. * read-write, dirty, young .00...111101 -> 11..0...0...11
* Huge ptes are dirty by definition, a clean pte is made dirty
* by the conversion.
*/ */
if (pte_present(pte)) { if (pte_present(pte)) {
pmd_val(pmd) = pte_val(pte) & PAGE_MASK; pmd_val(pmd) = pte_val(pte) & PAGE_MASK;
if (pte_val(pte) & _PAGE_INVALID) pmd_val(pmd) |= (pte_val(pte) & _PAGE_READ) >> 4;
pmd_val(pmd) |= _SEGMENT_ENTRY_INVALID; pmd_val(pmd) |= (pte_val(pte) & _PAGE_WRITE) >> 4;
none = (pte_val(pte) & _PAGE_PRESENT) && pmd_val(pmd) |= (pte_val(pte) & _PAGE_INVALID) >> 5;
!(pte_val(pte) & _PAGE_READ) && pmd_val(pmd) |= (pte_val(pte) & _PAGE_PROTECT);
!(pte_val(pte) & _PAGE_WRITE); pmd_val(pmd) |= (pte_val(pte) & _PAGE_DIRTY) << 10;
prot = (pte_val(pte) & _PAGE_PROTECT) && pmd_val(pmd) |= (pte_val(pte) & _PAGE_YOUNG) << 10;
!(pte_val(pte) & _PAGE_WRITE);
young = pte_val(pte) & _PAGE_YOUNG;
if (none || young)
pmd_val(pmd) |= _SEGMENT_ENTRY_YOUNG;
if (prot || (none && young))
pmd_val(pmd) |= _SEGMENT_ENTRY_PROTECT;
} else } else
pmd_val(pmd) = _SEGMENT_ENTRY_INVALID; pmd_val(pmd) = _SEGMENT_ENTRY_INVALID;
return pmd; return pmd;
...@@ -57,33 +48,30 @@ static inline pte_t __pmd_to_pte(pmd_t pmd) ...@@ -57,33 +48,30 @@ static inline pte_t __pmd_to_pte(pmd_t pmd)
/* /*
* Convert encoding pmd bits pte bits * Convert encoding pmd bits pte bits
* ..R...I...y. .IR...wrdytp * dy..R...I...wr .IR...wrdytp
* empty ..0...1...0. -> .10...000000 * empty 00..0...1...00 -> .10...001100
* prot-none, old ..0...1...1. -> .10...001001 * prot-none, clean, old 00..0...1...00 -> .10...000001
* prot-none, young ..1...1...1. -> .10...001101 * prot-none, clean, young 01..0...1...00 -> .10...000101
* read-only, old ..1...1...0. -> .11...011001 * prot-none, dirty, old 10..0...1...00 -> .10...001001
* read-only, young ..1...0...1. -> .01...011101 * prot-none, dirty, young 11..0...1...00 -> .10...001101
* read-write, old ..0...1...0. -> .10...111001 * read-only, clean, old 00..1...1...01 -> .11...010001
* read-write, young ..0...0...1. -> .00...111101 * read-only, clean, young 01..1...1...01 -> .11...010101
* Huge ptes are dirty by definition * read-only, dirty, old 10..1...1...01 -> .11...011001
* read-only, dirty, young 11..1...1...01 -> .11...011101
* read-write, clean, old 00..0...1...11 -> .10...110001
* read-write, clean, young 01..0...1...11 -> .10...110101
* read-write, dirty, old 10..0...1...11 -> .10...111001
* read-write, dirty, young 11..0...1...11 -> .10...111101
*/ */
if (pmd_present(pmd)) { if (pmd_present(pmd)) {
pte_val(pte) = _PAGE_PRESENT | _PAGE_LARGE | _PAGE_DIRTY | pte_val(pte) = pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN_LARGE;
(pmd_val(pmd) & PAGE_MASK); pte_val(pte) |= _PAGE_LARGE | _PAGE_PRESENT;
if (pmd_val(pmd) & _SEGMENT_ENTRY_INVALID) pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_READ) << 4;
pte_val(pte) |= _PAGE_INVALID; pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_WRITE) << 4;
if (pmd_prot_none(pmd)) { pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_INVALID) << 5;
if (pmd_val(pmd) & _SEGMENT_ENTRY_PROTECT) pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_PROTECT);
pte_val(pte) |= _PAGE_YOUNG; pmd_val(pmd) |= (pte_val(pte) & _PAGE_DIRTY) << 10;
} else { pmd_val(pmd) |= (pte_val(pte) & _PAGE_YOUNG) << 10;
pte_val(pte) |= _PAGE_READ;
if (pmd_val(pmd) & _SEGMENT_ENTRY_PROTECT)
pte_val(pte) |= _PAGE_PROTECT;
else
pte_val(pte) |= _PAGE_WRITE;
if (pmd_val(pmd) & _SEGMENT_ENTRY_YOUNG)
pte_val(pte) |= _PAGE_YOUNG;
}
} else } else
pte_val(pte) = _PAGE_INVALID; pte_val(pte) = _PAGE_INVALID;
return pte; return pte;
...@@ -96,6 +84,7 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, ...@@ -96,6 +84,7 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
pmd = __pte_to_pmd(pte); pmd = __pte_to_pmd(pte);
if (!MACHINE_HAS_HPAGE) { if (!MACHINE_HAS_HPAGE) {
/* Emulated huge ptes loose the dirty and young bit */
pmd_val(pmd) &= ~_SEGMENT_ENTRY_ORIGIN; pmd_val(pmd) &= ~_SEGMENT_ENTRY_ORIGIN;
pmd_val(pmd) |= pte_page(pte)[1].index; pmd_val(pmd) |= pte_page(pte)[1].index;
} else } else
...@@ -113,6 +102,8 @@ pte_t huge_ptep_get(pte_t *ptep) ...@@ -113,6 +102,8 @@ pte_t huge_ptep_get(pte_t *ptep)
origin = pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN; origin = pmd_val(pmd) & _SEGMENT_ENTRY_ORIGIN;
pmd_val(pmd) &= ~_SEGMENT_ENTRY_ORIGIN; pmd_val(pmd) &= ~_SEGMENT_ENTRY_ORIGIN;
pmd_val(pmd) |= *(unsigned long *) origin; pmd_val(pmd) |= *(unsigned long *) origin;
/* Emulated huge ptes are young and dirty by definition */
pmd_val(pmd) |= _SEGMENT_ENTRY_YOUNG | _SEGMENT_ENTRY_DIRTY;
} }
return __pmd_to_pte(pmd); return __pmd_to_pte(pmd);
} }
......
...@@ -1433,6 +1433,9 @@ int pmdp_set_access_flags(struct vm_area_struct *vma, ...@@ -1433,6 +1433,9 @@ int pmdp_set_access_flags(struct vm_area_struct *vma,
{ {
VM_BUG_ON(address & ~HPAGE_PMD_MASK); VM_BUG_ON(address & ~HPAGE_PMD_MASK);
entry = pmd_mkyoung(entry);
if (dirty)
entry = pmd_mkdirty(entry);
if (pmd_same(*pmdp, entry)) if (pmd_same(*pmdp, entry))
return 0; return 0;
pmdp_invalidate(vma, address, pmdp); pmdp_invalidate(vma, address, pmdp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment