mm: COW fixes part 3: reliable GUP R/W FOLL_GET of anonymous pages
Subsystems (9)
cover mm: COW fixes part 3: reliable GUP R/W FOLL_GET of anonymous pages
More information on the general COW issues can be found at [2]. This series is based on v5.17-rc8, [1]:
[PATCH v3 0/9] mm: COW fixes part 1: fix the COW security issue for THP and swap
and [4]:
[PATCH v2 00/15] mm: COW fixes part 2: reliable GUP pins of anonymous pages
v1 is located at:
https://github.com/davidhildenbrand/linux/tree/cow_fixes_part_3_v1
This series fixes memory corruptions when a GUP R/W reference (FOLL_WRITE | FOLL_GET) was taken on an anonymous page and COW logic fails to detect exclusivity of the page to then replacing the anonymous page by a copy in the page table: The GUP reference lost synchronicity with the pages mapped into the page tables. This series focuses on x86, arm64, s390x and ppc64/book3s -- other architectures are fairly easy to support by implementing __HAVE_ARCH_PTE_SWP_EXCLUSIVE.
This primarily fixes the O_DIRECT memory corruptions that can happen on concurrent swapout, whereby we lose DMA reads to a page (modifying the user page by writing to it).
O_DIRECT currently uses FOLL_GET for short-term (!FOLL_LONGTERM) DMA from/to a user page. In the long run, we want to convert it to properly use FOLL_PIN, and John is working on it, but that might take a while and might not be easy to backport. In the meantime, let's restore what used to work before we started modifying our COW logic: make R/W FOLL_GET references reliable as long as there is no fork() after GUP involved.
This is just the natural follow-up of part 2, that will also further reduce "wrong COW" on the swapin path, for example, when we cannot remove a page from the swapcache due to concurrent writeback, or if we have two threads faulting on the same swapped-out page. Fixing O_DIRECT is just a nice side-product :)
This issue, including other related COW issues, has been summarized in [3] under 2):
"
2. Intra Process Memory Corruptions due to Wrong COW (FOLL_GET)
It was discovered that we can create a memory corruption by reading a file via O_DIRECT to a part (e.g., first 512 bytes) of a page, concurrently writing to an unrelated part (e.g., last byte) of the same page, and concurrently write-protecting the page via clear_refs SOFTDIRTY tracking [6].
For the reproducer, the issue is that O_DIRECT grabs a reference of the target page (via FOLL_GET) and clear_refs write-protects the relevant page table entry. On successive write access to the page from the process itself, we wrongly COW the page when resolving the write fault, resulting in a loss of synchronicity and consequently a memory corruption.
While some people might think that using clear_refs in this combination is a corner cases, it turns out to be a more generic problem unfortunately.
For example, it was just recently discovered that we can similarly create a memory corruption without clear_refs, simply by concurrently swapping out the buffer pages [7]. Note that we nowadays even use the swap infrastructure in Linux without an actual swap disk/partition: the prime example is zram which is enabled as default under Fedora [10].
The root issue is that a write-fault on a page that has additional references results in a COW and thereby a loss of synchronicity and consequently a memory corruption if two parties believe they are referencing the same page.
"
We don't particularly care about R/O FOLL_GET references: they were never reliable and O_DIRECT doesn't expect to observe modifications from a page after DMA was started.
Note that:
* this only fixes the issue on x86, arm64, s390x and ppc64/book3s ("enterprise architectures"). Other architectures have to implement __HAVE_ARCH_PTE_SWP_EXCLUSIVE to achieve the same.
* this does *not * consider any kind of fork() after taking the reference:
fork() after GUP never worked reliably with FOLL_GET.
* Not losing PG_anon_exclusive during swapout was the last remaining piece. KSM already makes sure that there are no other references on a page before considering it for sharing. Page migration maintains PG_anon_exclusive and simply fails when there are additional references (freezing the refcount fails). Only swapout code dropped the PG_anon_exclusive flag because it requires more work to remember + restore it.
With this series in place, most COW issues of [3] are fixed on said architectures. Other architectures can implement __HAVE_ARCH_PTE_SWP_EXCLUSIVE fairly easily.
What remains is the COW security issue on hugetlb with FOLL_GET, and SOFTDIRTY tracking. I'll tackle both (guess what?) in part 4 once part 2 and part 3 are on its way upstream.
[1] https://lkml.kernel.org/r/[email protected]
[2] https://lkml.kernel.org/r/[email protected]
[3] https://lore.kernel.org/r/[email protected]
[4] https://lkml.kernel.org/r/[email protected]
David Hildenbrand (7):
mm/swap: remember PG_anon_exclusive via a swp pte bit mm/debug_vm_pgtable: add tests for __HAVE_ARCH_PTE_SWP_EXCLUSIVE x86/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE arm64/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE s390/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE powerpc/pgtable: remove _PAGE_BIT_SWAP_TYPE for book3s powerpc/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE for book3s
arch/arm64/include/asm/pgtable-prot.h | 1 + arch/arm64/include/asm/pgtable.h | 23 ++++++-- arch/powerpc/include/asm/book3s/64/pgtable.h | 31 ++++++++--- arch/s390/include/asm/pgtable.h | 37 ++++++++++--- arch/x86/include/asm/pgtable.h | 16 ++++++ arch/x86/include/asm/pgtable_64.h | 4 +- arch/x86/include/asm/pgtable_types.h | 5 ++ include/linux/pgtable.h | 29 +++++++++++ include/linux/swapops.h | 2 + mm/debug_vm_pgtable.c | 15 ++++++ mm/memory.c | 55 ++++++++++++++++++-- mm/rmap.c | 19 ++++--- mm/swapfile.c | 13 ++++- 13 files changed, 219 insertions(+), 31 deletions(-)
Signature · 1 line
2.35.1
PATCH 1/7 mm/swap: remember PG_anon_exclusive via a swp pte bit
Currently, we clear PG_anon_exclusive in try_to_unmap() and forget about it. We do this, to keep fork() logic on swap entries easy and efficient:
for example, if we wouldn't clear it when unmapping, we'd have to lookup the page in the swapcache for each and every swap entry during fork() and clear PG_anon_exclusive if set.
Instead, we want to store that information directly in the swap pte, protected by the page table lock, similarly to how we handle SWP_MIGRATION_READ_EXCLUSIVE for migration entries. However, for actual swap entries, we don't want to mess with the swap type (e.g., still one bit) because it overcomplicates swap code.
In try_to_unmap(), we already reject to unmap in case the page might be pinned, because we must not lose PG_anon_exclusive on pinned pages ever. Checking if there are other unexpected references reliably *before* completely unmapping a page is unfortunately not really possible: THP heavily overcomplicate the situation. Once fully unmapped it's easier -- we, for example, make sure that there are no unexpected references *after* unmapping a page before starting writeback on that page.
So, we currently might end up unmapping a page and clearing PG_anon_exclusive if that page has additional references, for example, due to a FOLL_GET.
do_swap_page() has to re-determine if a page is exclusive, which will easily fail if there are other references on a page, most prominently GUP references via FOLL_GET. This can currently result in memory corruptions when taking a FOLL_GET | FOLL_WRITE reference on a page even when fork() is never involved: try_to_unmap() will succeed, and when refaulting the page, it cannot be marked exclusive and will get replaced by a copy in the page tables on the next write access, resulting in writes via the GUP reference to the page being lost.
In an ideal world, everybody that uses GUP and wants to modify page content, such as O_DIRECT, would properly use FOLL_PIN. However, that conversion will take a while. It's easier to fix what used to work in the past (FOLL_GET | FOLL_WRITE) remembering PG_anon_exclusive. In addition, by remembering PG_anon_exclusive we can further reduce unnecessary COW in some cases, so it's the natural thing to do.
So let's transfer the PG_anon_exclusive information to the swap pte and store it via an architecture-dependant pte bit; use that information when restoring the swap pte in do_swap_page() and unuse_pte(). During fork(), we simply have to clear the pte bit and are done.
Of course, there is one corner case to handle: swap backends that don't support concurrent page modifications while the page is under writeback. Special case these, and drop the exclusive marker. Add a comment why that is just fine (also, reuse_swap_page() would have done the same in the past).
In the future, we'll hopefully have all architectures support __HAVE_ARCH_PTE_SWP_EXCLUSIVE, such that we can get rid of the empty stubs and the define completely. Then, we can also convert SWP_MIGRATION_READ_EXCLUSIVE. For architectures it's fairly easy to
support: either simply use a yet unused pte bit that can be used for swap entries, steal one from the arch type bits if they exceed 5, or steal one from the offset bits.
Note: R/O FOLL_GET references were never really reliable, especially when taking one on a shared page and then writing to the page (e.g., GUP after fork()). FOLL_GET, including R/W references, were never really reliable once fork was involved (e.g., GUP before fork(), GUP during fork()). KSM steps back in case it stumbles over unexpected references and is, therefore, fine.
--- include/linux/pgtable.h | 29 ++++++++++++++++++++++ include/linux/swapops.h | 2 ++ mm/memory.c | 55 ++++++++++++++++++++++++++++++++++++++--- mm/rmap.c | 19 ++++++++------ mm/swapfile.c | 13 +++++++++- 5 files changed, 105 insertions(+), 13 deletions(-)
include/linux/pgtable.h +29 -0
@@ -1003,6 +1003,35 @@ static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)#define arch_start_context_switch (prev) do {} while (0)#endif +/* +* When replacing an anonymous page by a real (!non) swap entry, we clear +* PG_anon_exclusive from the page and instead remember whether the flag was +* set in the swp pte. During fork(), we have to mark the entry as !exclusive +* (possibly shared). On swapin, we use that information to restore +* PG_anon_exclusive, which is very helpful in cases where we might have +* additional (e.g., FOLL_GET) references on a page and wouldn't be able to +* detect exclusivity. +* +* These functions don't apply to non-swap entries (e.g., migration, hwpoison, +* ...). +*/ +#ifndef __HAVE_ARCH_PTE_SWP_EXCLUSIVE +static inline pte_t pte_swp_mkexclusive (pte_t pte) +{ +return pte; +} + +static inline int pte_swp_exclusive (pte_t pte) +{ +return false; +} + +static inline pte_t pte_swp_clear_exclusive (pte_t pte) +{ +return pte; +} +#endif +#ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY #ifndef CONFIG_ARCH_ENABLE_THP_MIGRATION static inline pmd_t pmd_swp_mksoft_dirty (pmd_t pmd)
include/linux/swapops.h +2 -0
@@ -26,6 +26,8 @@/* Clear all flags but only keep swp_entry_t related information */ static inline pte_t pte_swp_clear_flags (pte_t pte) { +if (pte_swp_exclusive (pte)) + pte =pte_swp_clear_exclusive (pte);if (pte_swp_soft_dirty (pte)) pte =pte_swp_clear_soft_dirty (pte);if (pte_swp_uffd_wp (pte))
mm/memory.c +51 -4
80 lines not on this page · raw message
mm/rmap.c +11 -8
@@ -1643,14 +1643,15 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,break ; }/* -* Note: We *don't* remember yet if the page was mapped -* exclusively in the swap entry, so swapin code has -* to re-determine that manually and might detect the -* page as possibly shared, for example, if there are -* other references on the page or if the page is under -* writeback. We made sure that there are no GUP pins -* on the page that would rely on it, so for GUP pins -* this is fine. +* Note: We *don't* remember if the page was mapped +* exclusively in the swap pte if the architecture +* doesn't support __HAVE_ARCH_PTE_SWP_EXCLUSIVE. In +* that case, swapin code has to re-determine that +* manually and might detect the page as possibly +* shared, for example, if there are other references on +* the page or if the page is under writeback. We made +* sure that there are no GUP pins on the page that +* would rely on it, so for GUP pins this is fine. */ if (list_empty (&mm->mmlist)) {spin_lock (&mmlist_lock);
@@ -1661,6 +1662,8 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma,dec_mm_counter (mm,MM_ANONPAGES );inc_mm_counter (mm,MM_SWAPENTS ); swp_pte =swp_entry_to_pte (entry); +if (anon_exclusive) + swp_pte =pte_swp_mkexclusive (swp_pte);if (pte_soft_dirty (pteval)) swp_pte =pte_swp_mksoft_dirty (swp_pte);if (pte_uffd_wp (pteval))
mm/swapfile.c +12 -1
@@ -1804,7 +1804,18 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd,inc_mm_counter (vma->vm_mm,MM_ANONPAGES );get_page (page);if (page == swapcache) { -page_add_anon_rmap (page, vma, addr,RMAP_NONE ); +rmap_t rmap_flags =RMAP_NONE ; + +/* +* See do_swap_page(): PageWriteback() would be problematic. +* However, we do a wait_on_page_writeback() just before this +* call and have the page locked. +*/ +VM_BUG_ON_PAGE (PageWriteback (page), page); +if (pte_swp_exclusive (*pte)) + rmap_flags |=RMAP_EXCLUSIVE ; + +page_add_anon_rmap (page, vma, addr, rmap_flags); }else {/* ksm created a completely new copy */ page_add_new_anon_rmap (page, vma, addr);lru_cache_add_inactive_or_unevictable (page, vma);
Signature · 1 line
2.35.1
PATCH 2/7 mm/debug_vm_pgtable: add tests for __HAVE_ARCH_PTE_SWP_EXCLUSIVE
In reply to David HildenbrandLet's test that __HAVE_ARCH_PTE_SWP_EXCLUSIVE works as expected.
--- mm/debug_vm_pgtable.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
mm/debug_vm_pgtable.c +15 -0
@@ -837,6 +837,19 @@ static void __init pmd_soft_dirty_tests(struct pgtable_debug_args *args) { }static void __init pmd_swap_soft_dirty_tests (struct pgtable_debug_args *args) { }#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ +static void __init pte_swap_exclusive_tests (struct pgtable_debug_args *args) +{ +#ifdef __HAVE_ARCH_PTE_SWP_EXCLUSIVE +pte_t pte =pfn_pte (args->fixed_pte_pfn, args->page_prot); + +pr_debug ("Validating PTE swap exclusive\n" ); + pte =pte_swp_mkexclusive (pte); +WARN_ON (!pte_swp_exclusive (pte)); + pte =pte_swp_clear_exclusive (pte); +WARN_ON (pte_swp_exclusive (pte)); +#endif /* __HAVE_ARCH_PTE_SWP_EXCLUSIVE */ +} +static void __init pte_swap_tests (struct pgtable_debug_args *args) {swp_entry_t swp;
@@ -1288,6 +1301,8 @@ static int __init debug_vm_pgtable(void)pte_swap_soft_dirty_tests (&args);pmd_swap_soft_dirty_tests (&args); +pte_swap_exclusive_tests (&args); +pte_swap_tests (&args);pmd_swap_tests (&args);
Signature · 1 line
2.35.1
PATCH 3/7 x86/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
In reply to David HildenbrandLet's use bit 3 to remember PG_anon_exclusive in swap ptes.
--- arch/x86/include/asm/pgtable.h | 16 ++++++++++++++++ arch/x86/include/asm/pgtable_64.h | 4 +++- arch/x86/include/asm/pgtable_types.h | 5 +++++ 3 files changed, 24 insertions(+), 1 deletion(-)
arch/x86/include/asm/pgtable.h +16 -0
@@ -1291,6 +1291,22 @@ static inline void update_mmu_cache_pud(struct vm_area_struct *vma, { } +#define __HAVE_ARCH_PTE_SWP_EXCLUSIVE +static inline pte_t pte_swp_mkexclusive (pte_t pte) +{ +return pte_set_flags (pte, _PAGE_SWP_EXCLUSIVE); +} + +static inline int pte_swp_exclusive (pte_t pte) +{ +return pte_flags (pte) & _PAGE_SWP_EXCLUSIVE; +} + +static inline pte_t pte_swp_clear_exclusive (pte_t pte) +{ +return pte_clear_flags (pte, _PAGE_SWP_EXCLUSIVE); +} +#ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY static inline pte_t pte_swp_mksoft_dirty (pte_t pte) {
arch/x86/include/asm/pgtable_64.h +3 -1
@@ -186,7 +186,7 @@ static inline void native_pgd_clear(pgd_t *pgd)* * | ... | 11| 10| 9|8|7|6|5| 4| 3|2| 1|0| <- bit number * | ... |SW3|SW2|SW1|G|L|D|A|CD|WT|U| W|P| <- bit names -* | TYPE (59-63) | ~OFFSET (9-58) |0|0|X|X| X| X|F|SD|0| <- swp entry +* | TYPE (59-63) | ~OFFSET (9-58) |0|0|X|X| X| E|F|SD|0| <- swp entry * * G (8) is aliased and used as a PROT_NONE indicator for * !present ptes. We need to start storing swap entries above
@@ -203,6 +203,8 @@ static inline void native_pgd_clear(pgd_t *pgd)* F (2) in swp entry is used to record when a pagetable is * writeprotected by userfaultfd WP support. * +* E (3) in swp entry is used to rememeber PG_anon_exclusive. +* * Bit 7 in swp entry should be 0 because pmd_present checks not only P, * but also L and G. *
arch/x86/include/asm/pgtable_types.h +5 -0
@@ -83,6 +83,11 @@#define _PAGE_SOFT_DIRTY (_AT(pteval_t, 0))#endif +/* +* We borrow bit 3 to remember PG_anon_exclusive. +*/ +#define _PAGE_SWP_EXCLUSIVE _PAGE_PWT +/* * Tracking soft dirty bit when a page goes to a swap is tricky. * We need a bit which can be stored in pte _and_ not conflict
Signature · 1 line
2.35.1
PATCH 4/7 arm64/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
In reply to David HildenbrandLet's use one of the type bits: core-mm only supports 5, so there is no need to consume 6.
--- arch/arm64/include/asm/pgtable-prot.h | 1 + arch/arm64/include/asm/pgtable.h | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-)
arch/arm64/include/asm/pgtable-prot.h +1 -0
@@ -14,6 +14,7 @@* Software defined PTE bits definition. */ #define PTE_WRITE (PTE_DBM)/* same as DBM (51) */ +#define PTE_SWP_EXCLUSIVE (_AT(pteval_t, 1) << 2)/* only for swp ptes */ #define PTE_DIRTY (_AT(pteval_t, 1) << 55)#define PTE_SPECIAL (_AT(pteval_t, 1) << 56)#define PTE_DEVMAP (_AT(pteval_t, 1) << 57)
arch/arm64/include/asm/pgtable.h +20 -3
@@ -402,6 +402,22 @@ static inline pgprot_t mk_pmd_sect_prot(pgprot_t prot)return __pgprot ((pgprot_val (prot) & ~PMD_TABLE_BIT ) |PMD_TYPE_SECT ); } +#define __HAVE_ARCH_PTE_SWP_EXCLUSIVE +static inline pte_t pte_swp_mkexclusive (pte_t pte) +{ +return set_pte_bit (pte,__pgprot (PTE_SWP_EXCLUSIVE )); +} + +static inline int pte_swp_exclusive (pte_t pte) +{ +return pte_val (pte) &PTE_SWP_EXCLUSIVE ; +} + +static inline pte_t pte_swp_clear_exclusive (pte_t pte) +{ +return clear_pte_bit (pte,__pgprot (PTE_SWP_EXCLUSIVE )); +} +#ifdef CONFIG_NUMA_BALANCING /* * See the comment in include/linux/pgtable.h
@@ -909,12 +925,13 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma,/* * Encode and decode a swap entry: * bits 0-1: present (must be zero) -* bits 2-7: swap type +* bits 2: remember PG_anon_exclusive +* bits 3-7: swap type * bits 8-57: swap offset * bit 58: PTE_PROT_NONE (must be zero) */ -#define __SWP_TYPE_SHIFT 2 -#define __SWP_TYPE_BITS 6 +#define __SWP_TYPE_SHIFT 3 +#define __SWP_TYPE_BITS 5#define __SWP_OFFSET_BITS 50#define __SWP_TYPE_MASK ((1 << __SWP_TYPE_BITS) - 1)#define __SWP_OFFSET_SHIFT (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT)
Signature · 1 line
2.35.1
PATCH 5/7 s390/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
In reply to David HildenbrandLet's steal one bit from the offset. While at it, document the meaning of bit 62 for swap ptes.
--- arch/s390/include/asm/pgtable.h | 37 ++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-)
arch/s390/include/asm/pgtable.h +30 -7
@@ -181,6 +181,8 @@ static inline int is_module_addr(void *addr)#define _PAGE_SOFT_DIRTY 0x000#endif +#define _PAGE_SWP_EXCLUSIVE _PAGE_LARGE/* SW pte exclusive swap bit */ +/* Set of bits not changed in pte_modify */ #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_SPECIAL | _PAGE_DIRTY | \ _PAGE_YOUNG | _PAGE_SOFT_DIRTY)
@@ -796,6 +798,24 @@ static inline int pmd_protnone(pmd_t pmd) }#endif +#define __HAVE_ARCH_PTE_SWP_EXCLUSIVE +static inline pte_t pte_swp_mkexclusive (pte_t pte) +{ +pte_val (pte) |= _PAGE_SWP_EXCLUSIVE; +return pte; +} + +static inline int pte_swp_exclusive (pte_t pte) +{ +return pte_val (pte) & _PAGE_SWP_EXCLUSIVE; +} + +static inline pte_t pte_swp_clear_exclusive (pte_t pte) +{ +pte_val (pte) &= ~_PAGE_SWP_EXCLUSIVE; +return pte; +} +static inline int pte_soft_dirty (pte_t pte) {return pte_val (pte) & _PAGE_SOFT_DIRTY;
@@ -1675,16 +1695,19 @@ static inline int has_transparent_hugepage(void)* information in the lowcore. * Bits 54 and 63 are used to indicate the page type. * A swap pte is indicated by bit pattern (pte & 0x201) == 0x200 -* This leaves the bits 0-51 and bits 56-62 to store type and offset. -* We use the 5 bits from 57-61 for the type and the 52 bits from 0-51 +* This leaves the bits 0-50 and bits 56-61 to store type and offset. +* We use the 5 bits from 57-61 for the type and the 51 bits from 0-50 * for the offset. -* | offset |01100|type |00| -* |0000000000111111111122222222223333333333444444444455|55555|55566|66| -* |0123456789012345678901234567890123456789012345678901|23456|78901|23| +* | offset |E|01100|type |S0| +* |000000000011111111112222222222333333333344444444445|5|55555|55566|66| +* |012345678901234567890123456789012345678901234567890|1|23456|78901|23| +* +* S (bit 62) is used for softdirty tracking. +* E (bit 51) is used to remember PG_anon_exclusive. */ -#define __SWP_OFFSET_MASK ((1UL << 52) - 1) -#define __SWP_OFFSET_SHIFT 12 +#define __SWP_OFFSET_MASK ((1UL << 51) - 1) +#define __SWP_OFFSET_SHIFT 13#define __SWP_TYPE_MASK ((1UL << 5) - 1)#define __SWP_TYPE_SHIFT 2
Signature · 1 line
2.35.1
PATCH 6/7 powerpc/pgtable: remove _PAGE_BIT_SWAP_TYPE for book3s
In reply to David HildenbrandThe swap type is simply stored in bits 0x1f of the swap pte. Let's simplify by just getting rid of _PAGE_BIT_SWAP_TYPE. It's not like that we can simply change it: _PAGE_SWP_SOFT_DIRTY would suddenly fall into _RPAGE_RSV1, which isn't possible and would make the BUILD_BUG_ON(_PAGE_HPTEFLAGS & _PAGE_SWP_SOFT_DIRTY) angry.
While at it, make it clearer which bit we're actually using for _PAGE_SWP_SOFT_DIRTY by just using the proper define and introduce and use SWP_TYPE_MASK.
--- arch/powerpc/include/asm/book3s/64/pgtable.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/book3s/64/pgtable.h +5 -7
@@ -13,7 +13,6 @@/* * Common bits between hash and Radix page table */ -#define _PAGE_BIT_SWAP_TYPE 0#define _PAGE_EXEC 0x00001/* execute permission */ #define _PAGE_WRITE 0x00002/* write access allowed */
@@ -751,17 +750,16 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)* Don't have overlapping bits with _PAGE_HPTEFLAGS \ * We filter HPTEFLAGS on set_pte. \ */ \ -BUILD_BUG_ON (_PAGE_HPTEFLAGS & (0x1f << _PAGE_BIT_SWAP_TYPE)); \ +BUILD_BUG_ON (_PAGE_HPTEFLAGS &SWP_TYPE_MASK ); \BUILD_BUG_ON (_PAGE_HPTEFLAGS & _PAGE_SWP_SOFT_DIRTY); \ } while (0)#define SWP_TYPE_BITS 5 -#define __swp_type (x) (((x).val >> _PAGE_BIT_SWAP_TYPE) \ - & ((1UL << SWP_TYPE_BITS) - 1)) +#define SWP_TYPE_MASK ((1UL << SWP_TYPE_BITS) - 1) +#define __swp_type (x) ((x).val & SWP_TYPE_MASK)#define __swp_offset (x) (((x).val & PTE_RPN_MASK) >> PAGE_SHIFT)#define __swp_entry (type, offset) ((swp_entry_t) { \ - ((type) << _PAGE_BIT_SWAP_TYPE) \ - | (((offset) << PAGE_SHIFT) & PTE_RPN_MASK)}) + (type) | (((offset) << PAGE_SHIFT) & PTE_RPN_MASK)})/* * swp_entry_t must be independent of pte bits. We build a swp_entry_t from * swap type and offset we get from swap and convert that to pte to find a
@@ -774,7 +772,7 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)#define __swp_entry_to_pmd (x) (pte_pmd(__swp_entry_to_pte(x)))#ifdef CONFIG_MEM_SOFT_DIRTY -#define _PAGE_SWP_SOFT_DIRTY (1UL << (SWP_TYPE_BITS + _PAGE_BIT_SWAP_TYPE)) +#define _PAGE_SWP_SOFT_DIRTY _PAGE_NON_IDEMPOTENT#else #define _PAGE_SWP_SOFT_DIRTY 0UL#endif /* CONFIG_MEM_SOFT_DIRTY */
Signature · 1 line
2.35.1
PATCH 7/7 powerpc/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE for book3s
In reply to David HildenbrandRight now, the last 5 bits (0x1f) of the swap entry are used for the type and the bit before that (0x20) is used for _PAGE_SWP_SOFT_DIRTY. We cannot use 0x40, as that collides with _RPAGE_RSV1 -- contained in _PAGE_HPTEFLAGS. The next candidate would be _RPAGE_SW3 (0x200) -- which is used for _PAGE_SOFT_DIRTY for !swp ptes.
So let's just use _PAGE_SOFT_DIRTY for _PAGE_SWP_SOFT_DIRTY (to make it easier to grasp) and use 0x20 now for _PAGE_SWP_EXCLUSIVE.
--- arch/powerpc/include/asm/book3s/64/pgtable.h | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/book3s/64/pgtable.h +20 -1
@@ -752,6 +752,7 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)*/ \BUILD_BUG_ON (_PAGE_HPTEFLAGS &SWP_TYPE_MASK ); \BUILD_BUG_ON (_PAGE_HPTEFLAGS & _PAGE_SWP_SOFT_DIRTY); \ +BUILD_BUG_ON (_PAGE_HPTEFLAGS & _PAGE_SWP_EXCLUSIVE); \ } while (0)#define SWP_TYPE_BITS 5
@@ -772,11 +773,13 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)#define __swp_entry_to_pmd (x) (pte_pmd(__swp_entry_to_pte(x)))#ifdef CONFIG_MEM_SOFT_DIRTY -#define _PAGE_SWP_SOFT_DIRTY _PAGE_NON_IDEMPOTENT +#define _PAGE_SWP_SOFT_DIRTY _PAGE_SOFT_DIRTY#else #define _PAGE_SWP_SOFT_DIRTY 0UL#endif /* CONFIG_MEM_SOFT_DIRTY */ +#define _PAGE_SWP_EXCLUSIVE _PAGE_NON_IDEMPOTENT +#ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY static inline pte_t pte_swp_mksoft_dirty (pte_t pte) {
@@ -794,6 +797,22 @@ static inline pte_t pte_swp_clear_soft_dirty(pte_t pte) }#endif /* CONFIG_HAVE_ARCH_SOFT_DIRTY */ +#define __HAVE_ARCH_PTE_SWP_EXCLUSIVE +static inline pte_t pte_swp_mkexclusive (pte_t pte) +{ +return __pte_raw (pte_raw (pte) |cpu_to_be64 (_PAGE_SWP_EXCLUSIVE)); +} + +static inline int pte_swp_exclusive (pte_t pte) +{ +return !!(pte_raw (pte) &cpu_to_be64 (_PAGE_SWP_EXCLUSIVE)); +} + +static inline pte_t pte_swp_clear_exclusive (pte_t pte) +{ +return __pte_raw (pte_raw (pte) &cpu_to_be64 (~_PAGE_SWP_EXCLUSIVE)); +} +static inline bool check_pte_access (unsigned long access,unsigned long ptev) {/*
Signature · 1 line
2.35.1
Gerald Schaefer
maintainerRe: [PATCH v1 5/7] s390/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
In reply to David HildenbrandQuoted 2 lines · On Tue, 15 Mar 2022 15:18:35 +0100 David Hildenbrand <[email protected]> wrote:
Let's steal one bit from the offset. While at it, document the meaning of bit 62 for swap ptes.
You define _PAGE_SWP_EXCLUSIVE as _PAGE_LARGE, which is bit 52, and this is not part of the swap pte offset IIUC. So stealing any bit might actually not be necessary, see below.
Also, bit 62 should be the soft dirty bit for normal PTEs, and this doesn't seem to be used for swap PTEs at all. But I might be missing some use case where softdirty also needs to be preserved in swap PTEs.
Quoted 51 lines
Signed-off-by David Hildenbrand <[email protected]>--- arch/s390/include/asm/pgtable.h | 37 ++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-)arch/s390/include/asm/pgtable.h +21
-2@@ -181,6 +181,8 @@ static inline int is_module_addr(void *addr)#define _PAGE_SOFT_DIRTY 0x000#endif +#define _PAGE_SWP_EXCLUSIVE _PAGE_LARGE/* SW pte exclusive swap bit */ +/* Set of bits not changed in pte_modify */ #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_SPECIAL | _PAGE_DIRTY | \ _PAGE_YOUNG | _PAGE_SOFT_DIRTY)@@ -796,6 +798,24 @@ static inline int pmd_protnone(pmd_t pmd) }#endif +#define __HAVE_ARCH_PTE_SWP_EXCLUSIVE +static inline pte_t pte_swp_mkexclusive (pte_t pte) +{ +pte_val (pte) |= _PAGE_SWP_EXCLUSIVE; +return pte; +} + +static inline int pte_swp_exclusive (pte_t pte) +{ +return pte_val (pte) & _PAGE_SWP_EXCLUSIVE; +} + +static inline pte_t pte_swp_clear_exclusive (pte_t pte) +{ +pte_val (pte) &= ~_PAGE_SWP_EXCLUSIVE; +return pte; +} +static inline int pte_soft_dirty (pte_t pte) {return pte_val (pte) & _PAGE_SOFT_DIRTY;@@ -1675,16 +1695,19 @@ static inline int has_transparent_hugepage(void)* information in the lowcore. * Bits 54 and 63 are used to indicate the page type. * A swap pte is indicated by bit pattern (pte & 0x201) == 0x200 -* This leaves the bits 0-51 and bits 56-62 to store type and offset. -* We use the 5 bits from 57-61 for the type and the 52 bits from 0-51 +* This leaves the bits 0-50 and bits 56-61 to store type and offset.
arch/s390/include/asm/pgtable.h static inline int has_transparent_hugepage(void) · line 1705
Quoted 10 lines
arch/s390/include/asm/pgtable.h +6
-3+* We use the 5 bits from 57-61 for the type and the 51 bits from 0-50 * for the offset. -* | offset |01100|type |00| -* |0000000000111111111122222222223333333333444444444455|55555|55566|66| -* |0123456789012345678901234567890123456789012345678901|23456|78901|23| +* | offset |E|01100|type |S0| +* |000000000011111111112222222222333333333344444444445|5|55555|55566|66| +* |012345678901234567890123456789012345678901234567890|1|23456|78901|23| +* +* S (bit 62) is used for softdirty tracking.
Unless there is some use for softdirty tracking in swap PTEs, I think this description does not belong here, to the swap PTE layout.
arch/s390/include/asm/pgtable.h static inline int has_transparent_hugepage(void) · line 1706
Quoted 1 line
arch/s390/include/asm/pgtable.h +1
-0+* E (bit 51) is used to remember PG_anon_exclusive.
It is bit 52, at least with this patch, so I guess this could all be done w/o stealing anything. That is, of course, only if it is allowed to use bit 52 in this case. The POP says bit 52 has to be 0, or else a "translation-specification exception" is recognized. However, I think it could be OK for PTEs marked as invalid, like it is the case for swap PTEs.
The comment here says at the beginning:
/*
* 64 bit swap entry format:
* A page-table entry has some bits we have to treat in a special way.
* Bits 52 and bit 55 have to be zero, otherwise a specification
* exception will occur instead of a page translation exception. The
* specification exception has the bad habit not to store necessary
* information in the lowcore.
This would mean that it is not OK to have bit 52 not zero for swap PTEs. But if I read the POP correctly, all bits except for the DAT-protection would be ignored for invalid PTEs, so maybe this comment needs some update (for both bits 52 and also 55).
Heiko might also have some more insight.
Anyway, stealing bit 51 might still be an option, but then _PAGE_SWP_EXCLUSIVE would need to be defined appropriately.
Re: [PATCH v1 5/7] s390/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
Quoted 9 lines · Gerald Schaefer
Quoted 2 lines · On Tue, 15 Mar 2022 15:18:35 +0100 David Hildenbrand <[email protected]> wrote:
Let's steal one bit from the offset. While at it, document the meaning of bit 62 for swap ptes.
You define
_PAGE_SWP_EXCLUSIVEas_PAGE_LARGE, which is bit 52, and this is not part of the swap pte offset IIUC. So stealing any bit might actually not be necessary, see below.
Indeed, thanks for catching that. I actually intended to use bit 51 ...
Quoted 5 lines
Also, bit 62 should be the soft dirty bit for normal PTEs, and this doesn't seem to be used for swap PTEs at all. But I might be missing some use case where softdirty also needs to be preserved in swap PTEs.
It is, see below.
Quoted 56 lines
Quoted 56 lines
Signed-off-by David Hildenbrand <[email protected]>--- arch/s390/include/asm/pgtable.h | 37 ++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-)arch/s390/include/asm/pgtable.h +22
-5@@ -181,6 +181,8 @@ static inline int is_module_addr(void *addr)#define _PAGE_SOFT_DIRTY 0x000#endif +#define _PAGE_SWP_EXCLUSIVE _PAGE_LARGE/* SW pte exclusive swap bit */ +/* Set of bits not changed in pte_modify */ #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_SPECIAL | _PAGE_DIRTY | \ _PAGE_YOUNG | _PAGE_SOFT_DIRTY)@@ -796,6 +798,24 @@ static inline int pmd_protnone(pmd_t pmd) }#endif +#define __HAVE_ARCH_PTE_SWP_EXCLUSIVE +static inline pte_t pte_swp_mkexclusive (pte_t pte) +{ +pte_val (pte) |= _PAGE_SWP_EXCLUSIVE; +return pte; +} + +static inline int pte_swp_exclusive (pte_t pte) +{ +return pte_val (pte) & _PAGE_SWP_EXCLUSIVE; +} + +static inline pte_t pte_swp_clear_exclusive (pte_t pte) +{ +pte_val (pte) &= ~_PAGE_SWP_EXCLUSIVE; +return pte; +} +static inline int pte_soft_dirty (pte_t pte) {return pte_val (pte) & _PAGE_SOFT_DIRTY;@@ -1675,16 +1695,19 @@ static inline int has_transparent_hugepage(void)* information in the lowcore. * Bits 54 and 63 are used to indicate the page type. * A swap pte is indicated by bit pattern (pte & 0x201) == 0x200 -* This leaves the bits 0-51 and bits 56-62 to store type and offset. -* We use the 5 bits from 57-61 for the type and the 52 bits from 0-51 +* This leaves the bits 0-50 and bits 56-61 to store type and offset. +* We use the 5 bits from 57-61 for the type and the 51 bits from 0-50 * for the offset. -* | offset |01100|type |00| -* |0000000000111111111122222222223333333333444444444455|55555|55566|66| -* |0123456789012345678901234567890123456789012345678901|23456|78901|23|
Quoted 8 lines
arch/s390/include/asm/pgtable.h static inline int has_transparent_hugepage(void) · line 1705
Quoted 5 lines
arch/s390/include/asm/pgtable.h +5
-0+* | offset |E|01100|type |S0| +* |000000000011111111112222222222333333333344444444445|5|55555|55566|66| +* |012345678901234567890123456789012345678901234567890|1|23456|78901|23| +* +* S (bit 62) is used for softdirty tracking. Unless there is some use for softdirty tracking in swap PTEs, I think this description does not belong here, to the swap PTE layout.
See pte_swp_soft_dirty and friends. E.g., do_swap_page() has to restore it for the ordinary PTE from the swp pte.
if (pte_swp_soft_dirty(vmf->orig_pte))
pte = pte_mksoft_dirty(pte);
Quoted 9 lines
arch/s390/include/asm/pgtable.h static inline int has_transparent_hugepage(void) · line 1706
Quoted 2 lines
arch/s390/include/asm/pgtable.h +1
-0+* E (bit 51) is used to remember PG_anon_exclusive. It is bit 52, at least with this patch, so I guess this could all be done w/o stealing anything. That is, of course, only if it is allowed to use bit 52 in this case. The POP says bit 52 has to be 0, or else a "translation-specification exception" is recognized. However, I think it could be OK for PTEs marked as invalid, like it is the case for swap PTEs.
My tests with this patch worked, BUT it was under z/VM on a fairly old z machine. At least 2MiB huge pages are supported there. I did not run into specification exception in that setup, but that doesn't mean that that's the case under LPAR/KVM/newer systems.
Quoted 10 lines
The comment here says at the beginning:
/*
* 64 bit swap entry format:
* A page-table entry has some bits we have to treat in a special way.
* Bits 52 and bit 55 have to be zero, otherwise a specification
* exception will occur instead of a page translation exception. The
* specification exception has the bad habit not to store necessary
* information in the lowcore.
Quoted 6 lines
This would mean that it is not OK to have bit 52 not zero for swap PTEs. But if I read the POP correctly, all bits except for the DAT-protection would be ignored for invalid PTEs, so maybe this comment needs some update (for both bits 52 and also 55).
Heiko might also have some more insight.
Indeed, I wonder why we should get a specification exception when the PTE is invalid. I'll dig a bit into the PoP.
Quoted 4 lines
Anyway, stealing bit 51 might still be an option, but then
_PAGE_SWP_EXCLUSIVEwould need to be defined appropriately.
Indeed.
Thanks for the very-fast review!
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v1 5/7] s390/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
Quoted 10 lines
Quoted 7 lines
This would mean that it is not OK to have bit 52 not zero for swap PTEs. But if I read the POP correctly, all bits except for the DAT-protection would be ignored for invalid PTEs, so maybe this comment needs some update (for both bits 52 and also 55).
Heiko might also have some more insight.
Indeed, I wonder why we should get a specification exception when the PTE is invalid. I'll dig a bit into the PoP.
SA22-7832-12 6-46 ("Translation-Specification Exception") is clearer
"The page-table entry used for the translation is valid, and bit position 52 does not contain zero."
"The page-table entry used for the translation is valid, EDAT-1 does not apply, the instruction-exe- cution-protection facility is not installed, and bit position 55 does not contain zero. It is model dependent whether this condition is recognized."
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v1 5/7] s390/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
Quoted 13 lines · David Hildenbrand
Quoted 10 lines
Quoted 7 lines
This would mean that it is not OK to have bit 52 not zero for swap PTEs. But if I read the POP correctly, all bits except for the DAT-protection would be ignored for invalid PTEs, so maybe this comment needs some update (for both bits 52 and also 55).
Heiko might also have some more insight.
Indeed, I wonder why we should get a specification exception when the PTE is invalid. I'll dig a bit into the PoP.
SA22-7832-12 6-46 ("Translation-Specification Exception") is clearer
Quoted 9 lines
"The page-table entry used for the translation is valid, and bit position 52 does not contain zero."
"The page-table entry used for the translation is valid, EDAT-1 does not apply, the instruction-exe- cution-protection facility is not installed, and bit position 55 does not contain zero. It is model dependent whether this condition is recognized."
I wonder if the following matches reality:
arch/s390/include/asm/pgtable.h +6 -8
@@ -1669,18 +1669,16 @@ static inline int has_transparent_hugepage(void)/* * 64 bit swap entry format: * A page-table entry has some bits we have to treat in a special way. -* Bits 52 and bit 55 have to be zero, otherwise a specification -* exception will occur instead of a page translation exception. The -* specification exception has the bad habit not to store necessary -* information in the lowcore. * Bits 54 and 63 are used to indicate the page type. * A swap pte is indicated by bit pattern (pte & 0x201) == 0x200 -* This leaves the bits 0-51 and bits 56-62 to store type and offset. -* We use the 5 bits from 57-61 for the type and the 52 bits from 0-51 -* for the offset. -* | offset |01100|type |00| +* | offset |XX1XX|type |S0| * |0000000000111111111122222222223333333333444444444455|55555|55566|66| * |0123456789012345678901234567890123456789012345678901|23456|78901|23| +* +* Bits 0-51 store the offset. +* Bits 57-62 store the type. +* Bit 62 (S) is used for softdirty tracking. +* Bits 52, 53, 55 and 56 (X) are unused. */ #define __SWP_OFFSET_MASK ((1UL << 52) - 1)
I'm not sure why bit 53 was indicated as "1" and bit 55 was indicated as "0". At least for 52 and 55 there was a clear description.
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v1 5/7] s390/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
Quoted 40 lines · David Hildenbrand
Quoted 13 lines · David Hildenbrand
Quoted 10 lines
Quoted 7 lines
This would mean that it is not OK to have bit 52 not zero for swap PTEs. But if I read the POP correctly, all bits except for the DAT-protection would be ignored for invalid PTEs, so maybe this comment needs some update (for both bits 52 and also 55).
Heiko might also have some more insight.
Indeed, I wonder why we should get a specification exception when the PTE is invalid. I'll dig a bit into the PoP.
SA22-7832-12 6-46 ("Translation-Specification Exception") is clearer
Quoted 9 lines
"The page-table entry used for the translation is valid, and bit position 52 does not contain zero."
"The page-table entry used for the translation is valid, EDAT-1 does not apply, the instruction-exe- cution-protection facility is not installed, and bit position 55 does not contain zero. It is model dependent whether this condition is recognized."
I wonder if the following matches reality:
arch/s390/include/asm/pgtable.h +0
-4@@ -1669,18 +1669,16 @@ static inline int has_transparent_hugepage(void)/* * 64 bit swap entry format: * A page-table entry has some bits we have to treat in a special way. -* Bits 52 and bit 55 have to be zero, otherwise a specification -* exception will occur instead of a page translation exception. The -* specification exception has the bad habit not to store necessary -* information in the lowcore. * Bits 54 and 63 are used to indicate the page type. * A swap pte is indicated by bit pattern (pte & 0x201) == 0x200
arch/s390/include/asm/pgtable.h static inline int has_transparent_hugepage(void) · line 1679
Quoted 10 lines
arch/s390/include/asm/pgtable.h +4
-4-* This leaves the bits 0-51 and bits 56-62 to store type and offset. -* We use the 5 bits from 57-61 for the type and the 52 bits from 0-51 -* for the offset. -* | offset |01100|type |00| +* | offset |XX1XX|type |S0| * |0000000000111111111122222222223333333333444444444455|55555|55566|66| * |0123456789012345678901234567890123456789012345678901|23456|78901|23| +* +* Bits 0-51 store the offset. +* Bits 57-62 store the type.
^ 57-61, I should stop working for today :)
Signature · 3 lines
Thanks, David / dhildenb
Gerald Schaefer
maintainerRe: [PATCH v1 5/7] s390/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
In reply to David HildenbrandQuoted 57 lines · On Tue, 15 Mar 2022 18:12:16 +0100 David Hildenbrand <[email protected]> wrote:
Quoted 13 lines · David Hildenbrand
Quoted 10 lines
Quoted 7 lines
This would mean that it is not OK to have bit 52 not zero for swap PTEs. But if I read the POP correctly, all bits except for the DAT-protection would be ignored for invalid PTEs, so maybe this comment needs some update (for both bits 52 and also 55).
Heiko might also have some more insight.
Indeed, I wonder why we should get a specification exception when the PTE is invalid. I'll dig a bit into the PoP.
SA22-7832-12 6-46 ("Translation-Specification Exception") is clearer
Quoted 9 lines
"The page-table entry used for the translation is valid, and bit position 52 does not contain zero."
"The page-table entry used for the translation is valid, EDAT-1 does not apply, the instruction-exe- cution-protection facility is not installed, and bit position 55 does not contain zero. It is model dependent whether this condition is recognized."
I wonder if the following matches reality:
arch/s390/include/asm/pgtable.h +6
-8@@ -1669,18 +1669,16 @@ static inline int has_transparent_hugepage(void)/* * 64 bit swap entry format: * A page-table entry has some bits we have to treat in a special way. -* Bits 52 and bit 55 have to be zero, otherwise a specification -* exception will occur instead of a page translation exception. The -* specification exception has the bad habit not to store necessary -* information in the lowcore. * Bits 54 and 63 are used to indicate the page type. * A swap pte is indicated by bit pattern (pte & 0x201) == 0x200 -* This leaves the bits 0-51 and bits 56-62 to store type and offset. -* We use the 5 bits from 57-61 for the type and the 52 bits from 0-51 -* for the offset. -* | offset |01100|type |00| +* | offset |XX1XX|type |S0| * |0000000000111111111122222222223333333333444444444455|55555|55566|66| * |0123456789012345678901234567890123456789012345678901|23456|78901|23| +* +* Bits 0-51 store the offset. +* Bits 57-62 store the type. +* Bit 62 (S) is used for softdirty tracking. +* Bits 52, 53, 55 and 56 (X) are unused. */ #define __SWP_OFFSET_MASK ((1UL << 52) - 1)
Quoted 2 lines
I'm not sure why bit 53 was indicated as "1" and bit 55 was indicated as "0". At least for 52 and 55 there was a clear description.
Bit 53 is the invalid bit, and that is always 1 for swap ptes, in addition to protection bit 54. Bit 55, along with bit 52, has to be zero according to the (potentially deprecated) comment.
It is interesting that bit 56 seems to be unused, at least according to the comment, but that would also mention bit 62 as unused, so that clearly needs some update.
If bit 56 could be used for _PAGE_SWP_EXCLUSIVE, that would be better than stealing a bit from the offset, or using potentially dangerous bit 52. It is defined as _PAGE_UNUSED and only used for kvm, not sure if this is also relevant for swap ptes, similar to bit 62.
Adding Christian on cc, maybe he has some insight on _PAGE_UNUSED bit 56 and swap ptes.
Re: [PATCH v1 5/7] s390/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
Quoted 57 lines · Gerald Schaefer
Quoted 54 lines · On Tue, 15 Mar 2022 18:12:16 +0100 David Hildenbrand <[email protected]> wrote:
Quoted 13 lines · David Hildenbrand
Quoted 10 lines
Quoted 7 lines
This would mean that it is not OK to have bit 52 not zero for swap PTEs. But if I read the POP correctly, all bits except for the DAT-protection would be ignored for invalid PTEs, so maybe this comment needs some update (for both bits 52 and also 55).
Heiko might also have some more insight.
Indeed, I wonder why we should get a specification exception when the PTE is invalid. I'll dig a bit into the PoP.
SA22-7832-12 6-46 ("Translation-Specification Exception") is clearer
Quoted 9 lines
"The page-table entry used for the translation is valid, and bit position 52 does not contain zero."
"The page-table entry used for the translation is valid, EDAT-1 does not apply, the instruction-exe- cution-protection facility is not installed, and bit position 55 does not contain zero. It is model dependent whether this condition is recognized."
I wonder if the following matches reality:
arch/s390/include/asm/pgtable.h +6
-8@@ -1669,18 +1669,16 @@ static inline int has_transparent_hugepage(void)/* * 64 bit swap entry format: * A page-table entry has some bits we have to treat in a special way. -* Bits 52 and bit 55 have to be zero, otherwise a specification -* exception will occur instead of a page translation exception. The -* specification exception has the bad habit not to store necessary -* information in the lowcore. * Bits 54 and 63 are used to indicate the page type. * A swap pte is indicated by bit pattern (pte & 0x201) == 0x200 -* This leaves the bits 0-51 and bits 56-62 to store type and offset. -* We use the 5 bits from 57-61 for the type and the 52 bits from 0-51 -* for the offset. -* | offset |01100|type |00| +* | offset |XX1XX|type |S0| * |0000000000111111111122222222223333333333444444444455|55555|55566|66| * |0123456789012345678901234567890123456789012345678901|23456|78901|23| +* +* Bits 0-51 store the offset. +* Bits 57-62 store the type. +* Bit 62 (S) is used for softdirty tracking. +* Bits 52, 53, 55 and 56 (X) are unused. */
Quoted 7 lines
Quoted 5 lines
arch/s390/include/asm/pgtable.h +0
-0#define __SWP_OFFSET_MASK ((1UL << 52) - 1)I'm not sure why bit 53 was indicated as "1" and bit 55 was indicated as "0". At least for 52 and 55 there was a clear description.
Bit 53 is the invalid bit, and that is always 1 for swap ptes, in addition
Ah, right, I missed the meaning of bot 53 because this documentation is just sub-optimal.
Quoted 2 lines
to protection bit 54. Bit 55, along with bit 52, has to be zero according to the (potentially deprecated) comment.
Yeah, that 52/55 comment is just wrong when dealing with invalid PTEs.
Quoted 4 lines
It is interesting that bit 56 seems to be unused, at least according to the comment, but that would also mention bit 62 as unused, so that clearly needs some update.
I currently have the following cleanup patch:
From a4a8db2920e035e90a410b9170829326bb1fab92 Mon Sep 17 00:00:00 2001
From: David Hildenbrand <[email protected]>
Date: Tue, 15 Mar 2022 18:14:09 +0100
Subject: [PATCH] s390/pgtable: cleanup description of swp pte layout
Bit 52 and bit 55 don't have to be zero: they only trigger a translation-specifiation exception if the PTE is marked as valid, which is not the case for swap ptes.
Document which bits are used for what, and which ones are unused.
--- arch/s390/include/asm/pgtable.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
arch/s390/include/asm/pgtable.h +8 -9
@@ -1669,18 +1669,17 @@ static inline int has_transparent_hugepage(void)/* * 64 bit swap entry format: * A page-table entry has some bits we have to treat in a special way. -* Bits 52 and bit 55 have to be zero, otherwise a specification -* exception will occur instead of a page translation exception. The -* specification exception has the bad habit not to store necessary -* information in the lowcore. -* Bits 54 and 63 are used to indicate the page type. +* Bits 54 and 63 are used to indicate the page type. Bit 53 marks the pte +* as invalid. * A swap pte is indicated by bit pattern (pte & 0x201) == 0x200 -* This leaves the bits 0-51 and bits 56-62 to store type and offset. -* We use the 5 bits from 57-61 for the type and the 52 bits from 0-51 -* for the offset. -* | offset |01100|type |00| +* | offset |X11XX|type |S0| * |0000000000111111111122222222223333333333444444444455|55555|55566|66| * |0123456789012345678901234567890123456789012345678901|23456|78901|23| +* +* Bits 0-51 store the offset. +* Bits 57-61 store the type. +* Bit 62 (S) is used for softdirty tracking. +* Bits 52, 55 and 56 (X) are unused. */ #define __SWP_OFFSET_MASK ((1UL << 52) - 1)
Signature · 1 line
2.35.1
Quoted 5 lines
If bit 56 could be used for
_PAGE_SWP_EXCLUSIVE, that would be better than stealing a bit from the offset, or using potentially dangerous bit 52. It is defined as_PAGE_UNUSEDand only used for kvm, not sure if this is also relevant for swap ptes, similar to bit 62.
I don't think it is, and I also don't think there is anything wrong with reusing bit 52.
Quoted 3 lines
Adding Christian on cc, maybe he has some insight on
_PAGE_UNUSEDbit 56 and swap ptes.
Signature · 3 lines
Thanks, David / dhildenb
Christian Borntraeger
reviewerRe: [PATCH v1 5/7] s390/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
In reply to Gerald SchaeferAm 16.03.22 um 11:56 schrieb Gerald Schaefer:
Quoted 71 lines
Quoted 57 lines · On Tue, 15 Mar 2022 18:12:16 +0100 David Hildenbrand <[email protected]> wrote:
Quoted 13 lines · David Hildenbrand
Quoted 10 lines
Quoted 7 lines
This would mean that it is not OK to have bit 52 not zero for swap PTEs. But if I read the POP correctly, all bits except for the DAT-protection would be ignored for invalid PTEs, so maybe this comment needs some update (for both bits 52 and also 55).
Heiko might also have some more insight.
Indeed, I wonder why we should get a specification exception when the PTE is invalid. I'll dig a bit into the PoP.
SA22-7832-12 6-46 ("Translation-Specification Exception") is clearer
Quoted 9 lines
"The page-table entry used for the translation is valid, and bit position 52 does not contain zero."
"The page-table entry used for the translation is valid, EDAT-1 does not apply, the instruction-exe- cution-protection facility is not installed, and bit position 55 does not contain zero. It is model dependent whether this condition is recognized."
I wonder if the following matches reality:
arch/s390/include/asm/pgtable.h +6
-8@@ -1669,18 +1669,16 @@ static inline int has_transparent_hugepage(void)/* * 64 bit swap entry format: * A page-table entry has some bits we have to treat in a special way. -* Bits 52 and bit 55 have to be zero, otherwise a specification -* exception will occur instead of a page translation exception. The -* specification exception has the bad habit not to store necessary -* information in the lowcore. * Bits 54 and 63 are used to indicate the page type. * A swap pte is indicated by bit pattern (pte & 0x201) == 0x200 -* This leaves the bits 0-51 and bits 56-62 to store type and offset. -* We use the 5 bits from 57-61 for the type and the 52 bits from 0-51 -* for the offset. -* | offset |01100|type |00| +* | offset |XX1XX|type |S0| * |0000000000111111111122222222223333333333444444444455|55555|55566|66| * |0123456789012345678901234567890123456789012345678901|23456|78901|23| +* +* Bits 0-51 store the offset. +* Bits 57-62 store the type. +* Bit 62 (S) is used for softdirty tracking. +* Bits 52, 53, 55 and 56 (X) are unused. */ #define __SWP_OFFSET_MASK ((1UL << 52) - 1)Quoted 2 lines
I'm not sure why bit 53 was indicated as "1" and bit 55 was indicated as "0". At least for 52 and 55 there was a clear description.
Bit 53 is the invalid bit, and that is always 1 for swap ptes, in addition to protection bit 54. Bit 55, along with bit 52, has to be zero according to the (potentially deprecated) comment.
It is interesting that bit 56 seems to be unused, at least according to the comment, but that would also mention bit 62 as unused, so that clearly needs some update.
Quoted 7 lines
If bit 56 could be used for
_PAGE_SWP_EXCLUSIVE, that would be better than stealing a bit from the offset, or using potentially dangerous bit 52. It is defined as_PAGE_UNUSEDand only used for kvm, not sure if this is also relevant for swap ptes, similar to bit 62.Adding Christian on cc, maybe he has some insight on
_PAGE_UNUSEDbit 56 and swap ptes.
I think _PAGE_UNUSED is not used for swap ptes. It is used _before_ swapping to decide whether we swap or discard the page.
Regarding bit 52, the POP says in chapter 3 for the page table entry
[..]
Page-Invalid Bit (I): Bit 53 controls whether the page associated with the page-table entry is avail- able. When the bit is zero, address translation pro- ceeds by using the page-table entry. When the bit is one, the page-table entry cannot be used for transla- tion.
-->When the page-invalid bit is one, all other bits in the -->page-table entry are available for use by program- -->ming.
this was added with the z14 POP, but I guess it was just a clarification and should be valid for older machines as well.
So 52 and 56 should be ok, with 52 probably the better choice.
PS: the page protect bit is special and should not be used (bit54) for KVM related reasons
Gerald Schaefer
maintainerRe: [PATCH v1 5/7] s390/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
Quoted 96 lines · On Wed, 16 Mar 2022 14:01:07 +0100 Christian Borntraeger…
Am 16.03.22 um 11:56 schrieb Gerald Schaefer:
Quoted 71 lines
Quoted 57 lines · On Tue, 15 Mar 2022 18:12:16 +0100 David Hildenbrand <[email protected]> wrote:
Quoted 13 lines · David Hildenbrand
Quoted 10 lines
Quoted 7 lines
This would mean that it is not OK to have bit 52 not zero for swap PTEs. But if I read the POP correctly, all bits except for the DAT-protection would be ignored for invalid PTEs, so maybe this comment needs some update (for both bits 52 and also 55).
Heiko might also have some more insight.
Indeed, I wonder why we should get a specification exception when the PTE is invalid. I'll dig a bit into the PoP.
SA22-7832-12 6-46 ("Translation-Specification Exception") is clearer
Quoted 9 lines
"The page-table entry used for the translation is valid, and bit position 52 does not contain zero."
"The page-table entry used for the translation is valid, EDAT-1 does not apply, the instruction-exe- cution-protection facility is not installed, and bit position 55 does not contain zero. It is model dependent whether this condition is recognized."
I wonder if the following matches reality:
arch/s390/include/asm/pgtable.h +6
-8@@ -1669,18 +1669,16 @@ static inline int has_transparent_hugepage(void)/* * 64 bit swap entry format: * A page-table entry has some bits we have to treat in a special way. -* Bits 52 and bit 55 have to be zero, otherwise a specification -* exception will occur instead of a page translation exception. The -* specification exception has the bad habit not to store necessary -* information in the lowcore. * Bits 54 and 63 are used to indicate the page type. * A swap pte is indicated by bit pattern (pte & 0x201) == 0x200 -* This leaves the bits 0-51 and bits 56-62 to store type and offset. -* We use the 5 bits from 57-61 for the type and the 52 bits from 0-51 -* for the offset. -* | offset |01100|type |00| +* | offset |XX1XX|type |S0| * |0000000000111111111122222222223333333333444444444455|55555|55566|66| * |0123456789012345678901234567890123456789012345678901|23456|78901|23| +* +* Bits 0-51 store the offset. +* Bits 57-62 store the type. +* Bit 62 (S) is used for softdirty tracking. +* Bits 52, 53, 55 and 56 (X) are unused. */ #define __SWP_OFFSET_MASK ((1UL << 52) - 1)Quoted 2 lines
I'm not sure why bit 53 was indicated as "1" and bit 55 was indicated as "0". At least for 52 and 55 there was a clear description.
Bit 53 is the invalid bit, and that is always 1 for swap ptes, in addition to protection bit 54. Bit 55, along with bit 52, has to be zero according to the (potentially deprecated) comment.
It is interesting that bit 56 seems to be unused, at least according to the comment, but that would also mention bit 62 as unused, so that clearly needs some update.
Quoted 7 lines
If bit 56 could be used for
_PAGE_SWP_EXCLUSIVE, that would be better than stealing a bit from the offset, or using potentially dangerous bit 52. It is defined as_PAGE_UNUSEDand only used for kvm, not sure if this is also relevant for swap ptes, similar to bit 62.Adding Christian on cc, maybe he has some insight on
_PAGE_UNUSEDbit 56 and swap ptes.I think
_PAGE_UNUSEDis not used for swap ptes. It is used _before_ swapping to decide whether we swap or discard the page.Regarding bit 52, the POP says in chapter 3 for the page table entry
[..]
Page-Invalid Bit (I): Bit 53 controls whether the page associated with the page-table entry is avail- able. When the bit is zero, address translation pro- ceeds by using the page-table entry. When the bit is one, the page-table entry cannot be used for transla- tion.
Quoted 7 lines
-->When the page-invalid bit is one, all other bits in the -->page-table entry are available for use by program- -->ming.
this was added with the z14 POP, but I guess it was just a clarification and should be valid for older machines as well.
So 52 and 56 should be ok, with 52 probably the better choice.
Ok, bit 55 would then also be an option IIUC, since execution protection should not be relevant for swap ptes. And Davids clean-up removing the restriction for bit 52 and 55 in the comment would make sense.
I would also favor bit 52 though (PAGE_LARGE), as in Davids initial patch version, since this is never used for any real ptes. The PAGE_LARGE flag is only set in the "virtual" large ptes that the hugetlb code is seeing from huge_ptep_get(). But it will (and must) never be written as a valid pte, or else it will generate an exception. IIRC, we only set it to detect such possible bugs, e.g. hugetlb code writing a pte (which really is a pmd/pud) directly, instead of using set_huge_pte_at().
Re: [PATCH v1 5/7] s390/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
Quoted 111 lines · Gerald Schaefer
Quoted 96 lines · On Wed, 16 Mar 2022 14:01:07 +0100 Christian Borntraeger…
Am 16.03.22 um 11:56 schrieb Gerald Schaefer:
Quoted 71 lines
Quoted 57 lines · On Tue, 15 Mar 2022 18:12:16 +0100 David Hildenbrand <[email protected]> wrote:
Quoted 13 lines · David Hildenbrand
Quoted 10 lines
Quoted 7 lines
This would mean that it is not OK to have bit 52 not zero for swap PTEs. But if I read the POP correctly, all bits except for the DAT-protection would be ignored for invalid PTEs, so maybe this comment needs some update (for both bits 52 and also 55).
Heiko might also have some more insight.
Indeed, I wonder why we should get a specification exception when the PTE is invalid. I'll dig a bit into the PoP.
SA22-7832-12 6-46 ("Translation-Specification Exception") is clearer
Quoted 9 lines
"The page-table entry used for the translation is valid, and bit position 52 does not contain zero."
"The page-table entry used for the translation is valid, EDAT-1 does not apply, the instruction-exe- cution-protection facility is not installed, and bit position 55 does not contain zero. It is model dependent whether this condition is recognized."
I wonder if the following matches reality:
arch/s390/include/asm/pgtable.h +6
-8@@ -1669,18 +1669,16 @@ static inline int has_transparent_hugepage(void)/* * 64 bit swap entry format: * A page-table entry has some bits we have to treat in a special way. -* Bits 52 and bit 55 have to be zero, otherwise a specification -* exception will occur instead of a page translation exception. The -* specification exception has the bad habit not to store necessary -* information in the lowcore. * Bits 54 and 63 are used to indicate the page type. * A swap pte is indicated by bit pattern (pte & 0x201) == 0x200 -* This leaves the bits 0-51 and bits 56-62 to store type and offset. -* We use the 5 bits from 57-61 for the type and the 52 bits from 0-51 -* for the offset. -* | offset |01100|type |00| +* | offset |XX1XX|type |S0| * |0000000000111111111122222222223333333333444444444455|55555|55566|66| * |0123456789012345678901234567890123456789012345678901|23456|78901|23| +* +* Bits 0-51 store the offset. +* Bits 57-62 store the type. +* Bit 62 (S) is used for softdirty tracking. +* Bits 52, 53, 55 and 56 (X) are unused. */ #define __SWP_OFFSET_MASK ((1UL << 52) - 1)Quoted 2 lines
I'm not sure why bit 53 was indicated as "1" and bit 55 was indicated as "0". At least for 52 and 55 there was a clear description.
Bit 53 is the invalid bit, and that is always 1 for swap ptes, in addition to protection bit 54. Bit 55, along with bit 52, has to be zero according to the (potentially deprecated) comment.
It is interesting that bit 56 seems to be unused, at least according to the comment, but that would also mention bit 62 as unused, so that clearly needs some update.
Quoted 7 lines
If bit 56 could be used for
_PAGE_SWP_EXCLUSIVE, that would be better than stealing a bit from the offset, or using potentially dangerous bit 52. It is defined as_PAGE_UNUSEDand only used for kvm, not sure if this is also relevant for swap ptes, similar to bit 62.Adding Christian on cc, maybe he has some insight on
_PAGE_UNUSEDbit 56 and swap ptes.I think
_PAGE_UNUSEDis not used for swap ptes. It is used _before_ swapping to decide whether we swap or discard the page.Regarding bit 52, the POP says in chapter 3 for the page table entry
[..]
Page-Invalid Bit (I): Bit 53 controls whether the page associated with the page-table entry is avail- able. When the bit is zero, address translation pro- ceeds by using the page-table entry. When the bit is one, the page-table entry cannot be used for transla- tion.Quoted 7 lines
-->When the page-invalid bit is one, all other bits in the -->page-table entry are available for use by program- -->ming.
this was added with the z14 POP, but I guess it was just a clarification and should be valid for older machines as well.
So 52 and 56 should be ok, with 52 probably the better choice.Ok, bit 55 would then also be an option IIUC, since execution protection should not be relevant for swap ptes. And Davids clean-up removing the restriction for bit 52 and 55 in the comment would make sense.
Quoted 8 lines
I would also favor bit 52 though (
PAGE_LARGE), as in Davids initial patch version, since this is never used for any real ptes. ThePAGE_LARGEflag is only set in the "virtual" large ptes that the hugetlb code is seeing fromhuge_ptep_get(). But it will (and must) never be written as a valid pte, or else it will generate an exception. IIRC, we only set it to detect such possible bugs, e.g. hugetlb code writing a pte (which really is a pmd/pud) directly, instead of usingset_huge_pte_at().
Agreed. I'll include the doc cleanup patch and a fixed-up version of this patch (still using bit 52, not messing with the offset bits) in the next version.
Thanks all!
Signature · 3 lines
Thanks, David / dhildenb
Catalin Marinas
maintainerRe: [PATCH v1 4/7] arm64/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
In reply to David Hildenbrandarch/arm64/include/asm/pgtable-prot.h line 17
Quoted 9 lines · David Hildenbrand
arch/arm64/include/asm/pgtable-prot.h +1
-0@@ -14,6 +14,7 @@* Software defined PTE bits definition. */ #define PTE_WRITE (PTE_DBM)/* same as DBM (51) */ +#define PTE_SWP_EXCLUSIVE (_AT(pteval_t, 1) << 2)/* only for swp ptes */
I think we can use bit 1 here.
arch/arm64/include/asm/pgtable-prot.h static inline pmd_t pmdp_establish(struct vm_area_struct *vma, · line 931
Quoted 9 lines
arch/arm64/include/asm/pgtable-prot.h +2
-1@@ -909,12 +925,13 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma,/* * Encode and decode a swap entry: * bits 0-1: present (must be zero) -* bits 2-7: swap type +* bits 2: remember PG_anon_exclusive +* bits 3-7: swap type * bits 8-57: swap offset * bit 58: PTE_PROT_NONE (must be zero)
I don't remember exactly why we reserved bits 0 and 1 when, from the hardware perspective, it's sufficient for bit 0 to be 0 and the whole pte becomes invalid. We use bit 1 as the 'table' bit (when 0 at pmd level, it's a huge page) but we shouldn't check for this on a swap entry.
Signature · 1 line
Catalin
Re: [PATCH v1 4/7] arm64/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
Quoted 13 lines · Catalin Marinas
arch/arm64/include/asm/pgtable-prot.h line 17
Quoted 9 lines · David Hildenbrand
arch/arm64/include/asm/pgtable-prot.h +1
-0@@ -14,6 +14,7 @@* Software defined PTE bits definition. */ #define PTE_WRITE (PTE_DBM)/* same as DBM (51) */ +#define PTE_SWP_EXCLUSIVE (_AT(pteval_t, 1) << 2)/* only for swp ptes */ I think we can use bit 1 here.
Quoted 15 lines
arch/arm64/include/asm/pgtable-prot.h static inline pmd_t pmdp_establish(struct vm_area_struct *vma, · line 931
Quoted 9 lines
arch/arm64/include/asm/pgtable-prot.h +2
-1@@ -909,12 +925,13 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma,/* * Encode and decode a swap entry: * bits 0-1: present (must be zero) -* bits 2-7: swap type +* bits 2: remember PG_anon_exclusive +* bits 3-7: swap type * bits 8-57: swap offset * bit 58: PTE_PROT_NONE (must be zero) I don't remember exactly why we reserved bits 0 and 1 when, from the hardware perspective, it's sufficient for bit 0 to be 0 and the whole pte becomes invalid. We use bit 1 as the 'table' bit (when 0 at pmd level, it's a huge page) but we shouldn't check for this on a swap entry.
You mean
arch/arm64/include/asm/pgtable-hwdef.h:#define PTE_TABLE_BIT (_AT(pteval_t, 1) << 1)
right?
I wonder why it even exists, for arm64 I only spot:
arch/arm64/include/asm/pgtable.h:#define pte_mkhuge(pte) (__pte(pte_val(pte) & ~PTE_TABLE_BIT))
I don't really see code that sets PTE_TABLE_BIT.
Similarly, I don't see code that sets PMD_TABLE_BIT/PUD_TABLE_BIT/P4D_TABLE_BIT. Most probably setting code is not using the defines, that's why I'm not finding it.
Signature · 3 lines
Thanks, David / dhildenb
Catalin Marinas
maintainerRe: [PATCH v1 4/7] arm64/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
Quoted 18 lines · David Hildenbrand
Quoted 16 lines · Catalin Marinas
arch/arm64/include/asm/pgtable.h static inline pmd_t pmdp_establish(struct vm_area_struct *vma, · line 931
Quoted 9 lines · David Hildenbrand
arch/arm64/include/asm/pgtable.h +2
-1@@ -909,12 +925,13 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma,/* * Encode and decode a swap entry: * bits 0-1: present (must be zero) -* bits 2-7: swap type +* bits 2: remember PG_anon_exclusive +* bits 3-7: swap type * bits 8-57: swap offset * bit 58: PTE_PROT_NONE (must be zero) I don't remember exactly why we reserved bits 0 and 1 when, from the hardware perspective, it's sufficient for bit 0 to be 0 and the whole pte becomes invalid. We use bit 1 as the 'table' bit (when 0 at pmd level, it's a huge page) but we shouldn't check for this on a swap entry.
Quoted 5 lines
You mean
arch/arm64/include/asm/pgtable-hwdef.h:#define
PTE_TABLE_BIT(_AT(pteval_t, 1)<< 1)right?
Yes.
Quoted 8 lines
I wonder why it even exists, for arm64 I only spot:
arch/arm64/include/asm/pgtable.h:#define
pte_mkhuge(pte)(__pte(pte_val(pte) & ~PTE_TABLE_BIT))I don't really see code that sets
PTE_TABLE_BIT.Similarly, I don't see code that sets PMD_TABLE_BIT/PUD_TABLE_BIT/P4D_TABLE_BIT. Most probably setting code is not using the defines, that's why I'm not finding it.
It gets set as part of P*D_TYPE_TABLE via p*d_populate(). We use the P*D_TABLE_BIT mostly for checking whether it's a huge page or not (the arm64 hugetlbpage.c code).
Signature · 1 line
Catalin
Re: [PATCH v1 4/7] arm64/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
Quoted 31 lines · Catalin Marinas
Quoted 18 lines · David Hildenbrand
Quoted 16 lines · Catalin Marinas
Review static inline pmd_t pmdp_establish(struct vm_area_struct *vma, · line 931
Quoted 9 lines · David Hildenbrand
(quoted diff) +2
-1@@ -909,12 +925,13 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma, /* * Encode and decode a swap entry: * bits 0-1: present (must be zero) - * bits 2-7: swap type + * bits 2: remember PG_anon_exclusive + * bits 3-7: swap type * bits 8-57: swap offset * bit 58: PTE_PROT_NONE (must be zero)I don't remember exactly why we reserved bits 0 and 1 when, from the hardware perspective, it's sufficient for bit 0 to be 0 and the whole pte becomes invalid. We use bit 1 as the 'table' bit (when 0 at pmd level, it's a huge page) but we shouldn't check for this on a swap entry.
Quoted 5 lines
You mean
arch/arm64/include/asm/pgtable-hwdef.h:#define
PTE_TABLE_BIT(_AT(pteval_t, 1)<< 1)right?
Yes.
Quoted 4 lines
I wonder why it even exists, for arm64 I only spot:
arch/arm64/include/asm/pgtable.h:#define
pte_mkhuge(pte)(__pte(pte_val(pte) & ~PTE_TABLE_BIT))
Quoted 9 lines
Quoted 4 lines
I don't really see code that sets
PTE_TABLE_BIT.Similarly, I don't see code that sets PMD_TABLE_BIT/PUD_TABLE_BIT/P4D_TABLE_BIT. Most probably setting code is not using the defines, that's why I'm not finding it.
It gets set as part of P*D_TYPE_TABLE via p*d_populate(). We use the P*D_TABLE_BIT mostly for checking whether it's a huge page or not (the arm64
hugetlbpage.ccode).
Makes sense, after digging into the arm arm, I agree that it should be safe to reuse bit 1. I'll use this (yet untested) patch in v2:
From a48d08339574b7c42e0b032f0fc334872591744c Mon Sep 17 00:00:00 2001
From: David Hildenbrand <[email protected]>
Date: Thu, 17 Mar 2022 11:46:26 +0100
Subject: [PATCH] arm64/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
Let's use bit 1, which should be irrelevant if the PTE is marked invalid eiher way -- we really only care about bit 0.
Note that one alternative would be using one of the type bits: core-mm only supports 5 bits, so there is no need to reserve space for 6.
--- arch/arm64/include/asm/pgtable-prot.h | 1 + arch/arm64/include/asm/pgtable.h | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-)
arch/arm64/include/asm/pgtable-prot.h +1 -0
@@ -14,6 +14,7 @@* Software defined PTE bits definition. */ #define PTE_WRITE (PTE_DBM)/* same as DBM (51) */ +#define PTE_SWP_EXCLUSIVE (PTE_TABLE_BIT)/* only for swp ptes */ #define PTE_DIRTY (_AT(pteval_t, 1) << 55)#define PTE_SPECIAL (_AT(pteval_t, 1) << 56)#define PTE_DEVMAP (_AT(pteval_t, 1) << 57)
arch/arm64/include/asm/pgtable.h +18 -1
@@ -402,6 +402,22 @@ static inline pgprot_t mk_pmd_sect_prot(pgprot_t prot)return __pgprot ((pgprot_val (prot) & ~PMD_TABLE_BIT ) |PMD_TYPE_SECT ); } +#define __HAVE_ARCH_PTE_SWP_EXCLUSIVE +static inline pte_t pte_swp_mkexclusive (pte_t pte) +{ +return set_pte_bit (pte,__pgprot (PTE_SWP_EXCLUSIVE )); +} + +static inline int pte_swp_exclusive (pte_t pte) +{ +return pte_val (pte) &PTE_SWP_EXCLUSIVE ; +} + +static inline pte_t pte_swp_clear_exclusive (pte_t pte) +{ +return clear_pte_bit (pte,__pgprot (PTE_SWP_EXCLUSIVE )); +} +#ifdef CONFIG_NUMA_BALANCING /* * See the comment in include/linux/pgtable.h
@@ -908,7 +924,8 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma,/* * Encode and decode a swap entry: -* bits 0-1: present (must be zero) +* bits 0: present (must be zero) +* bits 1: remember PG_anon_exclusive * bits 2-7: swap type * bits 8-57: swap offset * bit 58: PTE_PROT_NONE (must be zero)
Signature · 7 lines
2.35.1 -- Thanks, David / dhildenb
Re: [PATCH v1 4/7] arm64/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
Quoted 40 lines · David Hildenbrand
arch/arm64/include/asm/pgtable-prot.h +1
-0@@ -14,6 +14,7 @@* Software defined PTE bits definition. */ #define PTE_WRITE (PTE_DBM)/* same as DBM (51) */ +#define PTE_SWP_EXCLUSIVE (PTE_TABLE_BIT)/* only for swp ptes */ #define PTE_DIRTY (_AT(pteval_t, 1) << 55)#define PTE_SPECIAL (_AT(pteval_t, 1) << 56)#define PTE_DEVMAP (_AT(pteval_t, 1) << 57)arch/arm64/include/asm/pgtable.h +16
-0@@ -402,6 +402,22 @@ static inline pgprot_t mk_pmd_sect_prot(pgprot_t prot)return __pgprot ((pgprot_val (prot) & ~PMD_TABLE_BIT ) |PMD_TYPE_SECT ); } +#define __HAVE_ARCH_PTE_SWP_EXCLUSIVE +static inline pte_t pte_swp_mkexclusive (pte_t pte) +{ +return set_pte_bit (pte,__pgprot (PTE_SWP_EXCLUSIVE )); +} + +static inline int pte_swp_exclusive (pte_t pte) +{ +return pte_val (pte) &PTE_SWP_EXCLUSIVE ; +} + +static inline pte_t pte_swp_clear_exclusive (pte_t pte) +{ +return clear_pte_bit (pte,__pgprot (PTE_SWP_EXCLUSIVE )); +} +#ifdef CONFIG_NUMA_BALANCING /* * See the comment in include/linux/pgtable.h
arch/arm64/include/asm/pgtable.h static inline pmd_t pmdp_establish(struct vm_area_struct *vma, · line 928
Quoted 6 lines
arch/arm64/include/asm/pgtable.h +2
-1@@ -908,7 +924,8 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma,/* * Encode and decode a swap entry: -* bits 0-1: present (must be zero) +* bits 0: present (must be zero) +* bits 1: remember PG_anon_exclusive
It looks fine to me.
Re: [PATCH v1 4/7] arm64/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
Quoted 50 lines · Catalin Marinas
Quoted 40 lines · David Hildenbrand
arch/arm64/include/asm/pgtable-prot.h +1
-0@@ -14,6 +14,7 @@* Software defined PTE bits definition. */ #define PTE_WRITE (PTE_DBM)/* same as DBM (51) */ +#define PTE_SWP_EXCLUSIVE (PTE_TABLE_BIT)/* only for swp ptes */ #define PTE_DIRTY (_AT(pteval_t, 1) << 55)#define PTE_SPECIAL (_AT(pteval_t, 1) << 56)#define PTE_DEVMAP (_AT(pteval_t, 1) << 57)arch/arm64/include/asm/pgtable.h +16
-0@@ -402,6 +402,22 @@ static inline pgprot_t mk_pmd_sect_prot(pgprot_t prot)return __pgprot ((pgprot_val (prot) & ~PMD_TABLE_BIT ) |PMD_TYPE_SECT ); } +#define __HAVE_ARCH_PTE_SWP_EXCLUSIVE +static inline pte_t pte_swp_mkexclusive (pte_t pte) +{ +return set_pte_bit (pte,__pgprot (PTE_SWP_EXCLUSIVE )); +} + +static inline int pte_swp_exclusive (pte_t pte) +{ +return pte_val (pte) &PTE_SWP_EXCLUSIVE ; +} + +static inline pte_t pte_swp_clear_exclusive (pte_t pte) +{ +return clear_pte_bit (pte,__pgprot (PTE_SWP_EXCLUSIVE )); +} +#ifdef CONFIG_NUMA_BALANCING /* * See the comment in include/linux/pgtable.h arch/arm64/include/asm/pgtable.h static inline pmd_t pmdp_establish(struct vm_area_struct *vma, · line 928
Quoted 6 lines
arch/arm64/include/asm/pgtable.h +2
-1@@ -908,7 +924,8 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma,/* * Encode and decode a swap entry: -* bits 0-1: present (must be zero) +* bits 0: present (must be zero) +* bits 1: remember PG_anon_exclusive It looks fine to me.
Quoted 2 lines
Reviewed-by Catalin Marinas <[email protected]>
Great, thanks!
Signature · 3 lines
Thanks, David / dhildenb
Quoted 5 lines · David Hildenbrand
This is just the natural follow-up of part 2, that will also further reduce "wrong COW" on the swapin path, for example, when we cannot remove a page from the swapcache due to concurrent writeback, or if we have two threads faulting on the same swapped-out page. Fixing
O_DIRECTis just a nice side-product :)
I know I would benefit alot from a description of the swap specific issue a bit more. Most of this message talks about clear_refs which I do understand a bit better.
Is this talking about what happens after a page gets swapped back in? eg the exclusive bit is missing when the page is recreated?
Otherwise nothing stood out to me here, but I know almost nothing about swap.
Thanks,
Jason
Quoted 6 lines · Jason Gunthorpe
Quoted 5 lines · David Hildenbrand
This is just the natural follow-up of part 2, that will also further reduce "wrong COW" on the swapin path, for example, when we cannot remove a page from the swapcache due to concurrent writeback, or if we have two threads faulting on the same swapped-out page. Fixing
O_DIRECTis just a nice side-product :)
Hi Jason,
thanks or the review!
Quoted 4 lines
I know I would benefit alot from a description of the swap specific issue a bit more. Most of this message talks about
clear_refswhich I do understand a bit better.
Patch #1 contains some additional information. In general, it's the same issue as with any other mechanism that could get the page mapped R/O while there is a FOLL_GET | FOLL_WRITE reference to it -- for example, DMA to that page as happens with our O_DIRECT reproducer.
Part 2 essentially fixed the other cases (i.e., clear_refs), but the remaining swapout+refault from swapcache case is handled in this series.
Quoted 3 lines
Is this talking about what happens after a page gets swapped back in? eg the exclusive bit is missing when the page is recreated?
Right, try_to_unmap() was the last remaining case where we'd have lost the exclusivity information -- it wasn't required for reliable GUP pins in part 2.
Here is what happens without PG_anon_exclusive:
1. The application uses parts of an anonymous base page for direct I/O, let's assume the first 512 bytes of page.
fd = open(filename, O_DIRECT| ...);pread(fd, page, 512, 0);
O_DIRECT will take a FOLL_GET|FOLL_WRITE reference on the page
2. Reclaim kicks in and wants to swapout the page -- mm/vmscan.c
shrink_page_list() first adds the page to the swapcache and then unmaps it via try_to_unmap().
After the page was successfully unmapped, pageout() will start triggering writeback but will realize that there are additional references on the page (via is_page_cache_freeable()) and fail.
3. The application uses unrelated parts of the page for other purposes while the DMA is not completed, e.g., doing a a simple
page[4095]++;
The read access will fault in the page readable from the swap cache in do_swap_page(). The write access will trigger our COW fault handler. As we have an additional reference on the page, we will create a copy and map it into out page table. At this point, the page table and the GUP reference are out of sync.
4. O_DIRECT completes
The read targets the page that is no longer referenced in the page tables. For the application, it looks like the read() never happened, as we lost our DMA read to our page.
With PG_anon_exclusive from series part 2, we don't remember exclusivity information in try_to_unmap() yet. do_swap_page() cannot restore it as it has to assume the page is possibly shared.
With this series, we remember exclusivity information in try_to_unmap() in the SWP PTE. do_swap_page() can restore it. Consequently, our COW fault handler won't create a wrong copy and we won't go out of sync between GUP and the page mapped into the page table.
Hope that helps!
Signature · 3 lines
Thanks, David / dhildenb
Will Deacon
maintainerRe: [PATCH v1 4/7] arm64/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
In reply to Catalin MarinasQuoted 13 lines · Catalin Marinas
arch/arm64/include/asm/pgtable-prot.h line 17
Quoted 9 lines · David Hildenbrand
arch/arm64/include/asm/pgtable-prot.h +1
-0@@ -14,6 +14,7 @@* Software defined PTE bits definition. */ #define PTE_WRITE (PTE_DBM)/* same as DBM (51) */ +#define PTE_SWP_EXCLUSIVE (_AT(pteval_t, 1) << 2)/* only for swp ptes */ I think we can use bit 1 here.
Quoted 15 lines
arch/arm64/include/asm/pgtable-prot.h static inline pmd_t pmdp_establish(struct vm_area_struct *vma, · line 931
Quoted 9 lines
arch/arm64/include/asm/pgtable-prot.h +2
-1@@ -909,12 +925,13 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma,/* * Encode and decode a swap entry: * bits 0-1: present (must be zero) -* bits 2-7: swap type +* bits 2: remember PG_anon_exclusive +* bits 3-7: swap type * bits 8-57: swap offset * bit 58: PTE_PROT_NONE (must be zero) I don't remember exactly why we reserved bits 0 and 1 when, from the hardware perspective, it's sufficient for bit 0 to be 0 and the whole pte becomes invalid. We use bit 1 as the 'table' bit (when 0 at pmd level, it's a huge page) but we shouldn't check for this on a swap entry.
I'm a little worried that when we're dealing with huge mappings at the PMD level we might lose the ability to distinguish them from a pte-level mapping with this new flag set if we use bit 1. A similar issue to this was fixed a long time ago by 59911ca4325d ("ARM64: mm: Move PTE_PROT_NONE bit") when we used to use bit 1 for PTE_PROT_NONE.
Is something like:
pmd_to_swp_entry(swp_entry_to_pmd(pmd));
supposed to preserve the original pmd? I'm not sure that's guaranteed after this change if bit 1 can be cleared in the process -- we could end up with a pte, which the hardware would interpret as a table entry and end up with really bad things happening.
Will
Will Deacon
maintainerRe: [PATCH v1 4/7] arm64/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
Quoted 36 lines · Will Deacon
Quoted 13 lines · Catalin Marinas
arch/arm64/include/asm/pgtable-prot.h line 17
Quoted 9 lines · David Hildenbrand
arch/arm64/include/asm/pgtable-prot.h +1
-0@@ -14,6 +14,7 @@* Software defined PTE bits definition. */ #define PTE_WRITE (PTE_DBM)/* same as DBM (51) */ +#define PTE_SWP_EXCLUSIVE (_AT(pteval_t, 1) << 2)/* only for swp ptes */ I think we can use bit 1 here.
Quoted 15 lines
arch/arm64/include/asm/pgtable-prot.h static inline pmd_t pmdp_establish(struct vm_area_struct *vma, · line 931
Quoted 9 lines
arch/arm64/include/asm/pgtable-prot.h +2
-1@@ -909,12 +925,13 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma,/* * Encode and decode a swap entry: * bits 0-1: present (must be zero) -* bits 2-7: swap type +* bits 2: remember PG_anon_exclusive +* bits 3-7: swap type * bits 8-57: swap offset * bit 58: PTE_PROT_NONE (must be zero) I don't remember exactly why we reserved bits 0 and 1 when, from the hardware perspective, it's sufficient for bit 0 to be 0 and the whole pte becomes invalid. We use bit 1 as the 'table' bit (when 0 at pmd level, it's a huge page) but we shouldn't check for this on a swap entry.
I'm a little worried that when we're dealing with huge mappings at the PMD level we might lose the ability to distinguish them from a pte-level mapping with this new flag set if we use bit 1. A similar issue to this was fixed a long time ago by
59911ca4325d("ARM64: mm: MovePTE_PROT_NONEbit") when we used to use bit 1 forPTE_PROT_NONE.
Quoted 8 lines
Is something like:
pmd_to_swp_entry(swp_entry_to_pmd(pmd));supposed to preserve the original pmd? I'm not sure that's guaranteed after this change if bit 1 can be cleared in the process -- we could end up with a pte, which the hardware would interpret as a table entry and end up with really bad things happening.
(I got this back to front: having the bit set rather than cleared would be an issue, but the overall point remains).
Will
Re: [PATCH v1 4/7] arm64/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
In reply to Will DeaconQuoted 36 lines · Will Deacon
Quoted 13 lines · Catalin Marinas
arch/arm64/include/asm/pgtable-prot.h line 17
Quoted 9 lines · David Hildenbrand
arch/arm64/include/asm/pgtable-prot.h +1
-0@@ -14,6 +14,7 @@* Software defined PTE bits definition. */ #define PTE_WRITE (PTE_DBM)/* same as DBM (51) */ +#define PTE_SWP_EXCLUSIVE (_AT(pteval_t, 1) << 2)/* only for swp ptes */ I think we can use bit 1 here.
Quoted 15 lines
arch/arm64/include/asm/pgtable-prot.h static inline pmd_t pmdp_establish(struct vm_area_struct *vma, · line 931
Quoted 9 lines
arch/arm64/include/asm/pgtable-prot.h +2
-1@@ -909,12 +925,13 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma,/* * Encode and decode a swap entry: * bits 0-1: present (must be zero) -* bits 2-7: swap type +* bits 2: remember PG_anon_exclusive +* bits 3-7: swap type * bits 8-57: swap offset * bit 58: PTE_PROT_NONE (must be zero) I don't remember exactly why we reserved bits 0 and 1 when, from the hardware perspective, it's sufficient for bit 0 to be 0 and the whole pte becomes invalid. We use bit 1 as the 'table' bit (when 0 at pmd level, it's a huge page) but we shouldn't check for this on a swap entry.
I'm a little worried that when we're dealing with huge mappings at the PMD level we might lose the ability to distinguish them from a pte-level mapping with this new flag set if we use bit 1. A similar issue to this was fixed a long time ago by
59911ca4325d("ARM64: mm: MovePTE_PROT_NONEbit") when we used to use bit 1 forPTE_PROT_NONE.
Quoted 3 lines
Is something like:
pmd_to_swp_entry(swp_entry_to_pmd(pmd));
Note that __HAVE_ARCH_PTE_SWP_EXCLUSIVE currently only applies to actual swap entries, not non-swap entries (migration, hwpoison, ...). So it really only applies to PTEs -- PMDs are not applicable.
So the example you gave cannot possibly have that bit set. From what I understand, it should be fine. But I have no real preference: I can also just stick to the original patch, whatever you prefer.
Thanks!
Signature · 3 lines
Thanks, David / dhildenb
Will Deacon
maintainerRe: [PATCH v1 4/7] arm64/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
Quoted 37 lines · David Hildenbrand
Quoted 36 lines · Will Deacon
Quoted 13 lines · Catalin Marinas
arch/arm64/include/asm/pgtable-prot.h line 17
Quoted 9 lines · David Hildenbrand
arch/arm64/include/asm/pgtable-prot.h +1
-0@@ -14,6 +14,7 @@* Software defined PTE bits definition. */ #define PTE_WRITE (PTE_DBM)/* same as DBM (51) */ +#define PTE_SWP_EXCLUSIVE (_AT(pteval_t, 1) << 2)/* only for swp ptes */ I think we can use bit 1 here.
Quoted 15 lines
arch/arm64/include/asm/pgtable-prot.h static inline pmd_t pmdp_establish(struct vm_area_struct *vma, · line 931
Quoted 9 lines
arch/arm64/include/asm/pgtable-prot.h +2
-1@@ -909,12 +925,13 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma,/* * Encode and decode a swap entry: * bits 0-1: present (must be zero) -* bits 2-7: swap type +* bits 2: remember PG_anon_exclusive +* bits 3-7: swap type * bits 8-57: swap offset * bit 58: PTE_PROT_NONE (must be zero) I don't remember exactly why we reserved bits 0 and 1 when, from the hardware perspective, it's sufficient for bit 0 to be 0 and the whole pte becomes invalid. We use bit 1 as the 'table' bit (when 0 at pmd level, it's a huge page) but we shouldn't check for this on a swap entry.
I'm a little worried that when we're dealing with huge mappings at the PMD level we might lose the ability to distinguish them from a pte-level mapping with this new flag set if we use bit 1. A similar issue to this was fixed a long time ago by
59911ca4325d("ARM64: mm: MovePTE_PROT_NONEbit") when we used to use bit 1 forPTE_PROT_NONE.
Quoted 7 lines
Quoted 3 lines
Is something like:
pmd_to_swp_entry(swp_entry_to_pmd(pmd));Note that
__HAVE_ARCH_PTE_SWP_EXCLUSIVEcurrently only applies to actual swap entries, not non-swap entries (migration, hwpoison, ...). So it really only applies to PTEs -- PMDs are not applicable.
Right, thanks for the clarification.
Quoted 3 lines
So the example you gave cannot possibly have that bit set. From what I understand, it should be fine. But I have no real preference: I can also just stick to the original patch, whatever you prefer.
I think I'd prefer to stay on the safe side and stick with bit 2 as you originally proposed. If we need to support crazy numbers of swapfiles in future then we can revisit the idea of allocating bit 1.
Thanks, and sorry for the trouble.
Will
Catalin Marinas
maintainerRe: [PATCH v1 4/7] arm64/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
Quoted 8 lines · Will Deacon
Quoted 3 lines · David Hildenbrand
So the example you gave cannot possibly have that bit set. From what I understand, it should be fine. But I have no real preference: I can also just stick to the original patch, whatever you prefer.
I think I'd prefer to stay on the safe side and stick with bit 2 as you originally proposed. If we need to support crazy numbers of swapfiles in future then we can revisit the idea of allocating bit 1.
Sounds fine to me. David, feel free to keep my reviewed-by on the original patch.
Signature · 1 line
Catalin
Re: [PATCH v1 4/7] arm64/pgtable: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE
Quoted 6 lines · Catalin Marinas
Quoted 5 lines · Will Deacon
Quoted 3 lines · David Hildenbrand
So the example you gave cannot possibly have that bit set. From what I understand, it should be fine. But I have no real preference: I can also just stick to the original patch, whatever you prefer.
Quoted 7 lines
Quoted 3 lines
I think I'd prefer to stay on the safe side and stick with bit 2 as you originally proposed. If we need to support crazy numbers of swapfiles in future then we can revisit the idea of allocating bit 1.
Sounds fine to me. David, feel free to keep my reviewed-by on the original patch.
Thanks both, I'll add the following comment to the patch:
"Note that we might be able to reuse bit 1, but reusing bit 1 turned out
problematic in the past for PROT_NONE handling; so let's play safe and use another bit."
Signature · 3 lines
Thanks, David / dhildenb