Message ID | 20250129115411.2077152-7-david@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | mm: fixes for device-exclusive entries (hmm) | expand |
On Wed, Jan 29, 2025 at 12:54:04PM +0100, David Hildenbrand wrote: > There is no need for the distinction anymore; let's merge the readable > and writable device-exclusive entries into a single device-exclusive > entry type. > > Signed-off-by: David Hildenbrand <david@redhat.com> Yeah I really don't think there's a need to track that on the cpu ptes. Device should have write/dirty bits (which nouveau really should forward) or defensively assume the page is always dirtied when clearing a pte. Plus the entire point of device exclusive access is to support device atomics, so in practice it's always a write access that dirties anyway. Acked-by: Simona Vetter <simona.vetter@ffwll.ch> > --- > include/linux/swap.h | 7 +++---- > include/linux/swapops.h | 27 ++++----------------------- > mm/mprotect.c | 8 -------- > mm/page_table_check.c | 5 ++--- > mm/rmap.c | 2 +- > 5 files changed, 10 insertions(+), 39 deletions(-) > > diff --git a/include/linux/swap.h b/include/linux/swap.h > index 91b30701274e..9a48e79a0a52 100644 > --- a/include/linux/swap.h > +++ b/include/linux/swap.h > @@ -74,14 +74,13 @@ static inline int current_is_kswapd(void) > * to a special SWP_DEVICE_{READ|WRITE} entry. > * > * When a page is mapped by the device for exclusive access we set the CPU page > - * table entries to special SWP_DEVICE_EXCLUSIVE_* entries. > + * table entries to a special SWP_DEVICE_EXCLUSIVE entry. > */ > #ifdef CONFIG_DEVICE_PRIVATE > -#define SWP_DEVICE_NUM 4 > +#define SWP_DEVICE_NUM 3 > #define SWP_DEVICE_WRITE (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_NUM) > #define SWP_DEVICE_READ (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_NUM+1) > -#define SWP_DEVICE_EXCLUSIVE_WRITE (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_NUM+2) > -#define SWP_DEVICE_EXCLUSIVE_READ (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_NUM+3) > +#define SWP_DEVICE_EXCLUSIVE (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_NUM+2) > #else > #define SWP_DEVICE_NUM 0 > #endif > diff --git a/include/linux/swapops.h b/include/linux/swapops.h > index 96f26e29fefe..64ea151a7ae3 100644 > --- a/include/linux/swapops.h > +++ b/include/linux/swapops.h > @@ -186,26 +186,16 @@ static inline bool is_writable_device_private_entry(swp_entry_t entry) > return unlikely(swp_type(entry) == SWP_DEVICE_WRITE); > } > > -static inline swp_entry_t make_readable_device_exclusive_entry(pgoff_t offset) > +static inline swp_entry_t make_device_exclusive_entry(pgoff_t offset) > { > - return swp_entry(SWP_DEVICE_EXCLUSIVE_READ, offset); > -} > - > -static inline swp_entry_t make_writable_device_exclusive_entry(pgoff_t offset) > -{ > - return swp_entry(SWP_DEVICE_EXCLUSIVE_WRITE, offset); > + return swp_entry(SWP_DEVICE_EXCLUSIVE, offset); > } > > static inline bool is_device_exclusive_entry(swp_entry_t entry) > { > - return swp_type(entry) == SWP_DEVICE_EXCLUSIVE_READ || > - swp_type(entry) == SWP_DEVICE_EXCLUSIVE_WRITE; > + return swp_type(entry) == SWP_DEVICE_EXCLUSIVE; > } > > -static inline bool is_writable_device_exclusive_entry(swp_entry_t entry) > -{ > - return unlikely(swp_type(entry) == SWP_DEVICE_EXCLUSIVE_WRITE); > -} > #else /* CONFIG_DEVICE_PRIVATE */ > static inline swp_entry_t make_readable_device_private_entry(pgoff_t offset) > { > @@ -227,12 +217,7 @@ static inline bool is_writable_device_private_entry(swp_entry_t entry) > return false; > } > > -static inline swp_entry_t make_readable_device_exclusive_entry(pgoff_t offset) > -{ > - return swp_entry(0, 0); > -} > - > -static inline swp_entry_t make_writable_device_exclusive_entry(pgoff_t offset) > +static inline swp_entry_t make_device_exclusive_entry(pgoff_t offset) > { > return swp_entry(0, 0); > } > @@ -242,10 +227,6 @@ static inline bool is_device_exclusive_entry(swp_entry_t entry) > return false; > } > > -static inline bool is_writable_device_exclusive_entry(swp_entry_t entry) > -{ > - return false; > -} > #endif /* CONFIG_DEVICE_PRIVATE */ > > #ifdef CONFIG_MIGRATION > diff --git a/mm/mprotect.c b/mm/mprotect.c > index 516b1d847e2c..9cb6ab7c4048 100644 > --- a/mm/mprotect.c > +++ b/mm/mprotect.c > @@ -225,14 +225,6 @@ static long change_pte_range(struct mmu_gather *tlb, > newpte = swp_entry_to_pte(entry); > if (pte_swp_uffd_wp(oldpte)) > newpte = pte_swp_mkuffd_wp(newpte); > - } else if (is_writable_device_exclusive_entry(entry)) { > - entry = make_readable_device_exclusive_entry( > - swp_offset(entry)); > - newpte = swp_entry_to_pte(entry); > - if (pte_swp_soft_dirty(oldpte)) > - newpte = pte_swp_mksoft_dirty(newpte); > - if (pte_swp_uffd_wp(oldpte)) > - newpte = pte_swp_mkuffd_wp(newpte); > } else if (is_pte_marker_entry(entry)) { > /* > * Ignore error swap entries unconditionally, > diff --git a/mm/page_table_check.c b/mm/page_table_check.c > index 509c6ef8de40..c2b3600429a0 100644 > --- a/mm/page_table_check.c > +++ b/mm/page_table_check.c > @@ -196,9 +196,8 @@ EXPORT_SYMBOL(__page_table_check_pud_clear); > /* Whether the swap entry cached writable information */ > static inline bool swap_cached_writable(swp_entry_t entry) > { > - return is_writable_device_exclusive_entry(entry) || > - is_writable_device_private_entry(entry) || > - is_writable_migration_entry(entry); > + return is_writable_device_private_entry(entry) || > + is_writable_migration_entry(entry); > } > > static inline void page_table_check_pte_flags(pte_t pte) > diff --git a/mm/rmap.c b/mm/rmap.c > index 49ffac6d27f8..65d9bbea16d0 100644 > --- a/mm/rmap.c > +++ b/mm/rmap.c > @@ -2470,7 +2470,7 @@ struct page *make_device_exclusive(struct mm_struct *mm, unsigned long addr, > * do_swap_page() will trigger the conversion back while holding the > * folio lock. > */ > - entry = make_writable_device_exclusive_entry(page_to_pfn(page)); > + entry = make_device_exclusive_entry(page_to_pfn(page)); > swp_pte = swp_entry_to_pte(entry); > if (pte_soft_dirty(fw.pte)) > swp_pte = pte_swp_mksoft_dirty(swp_pte); > -- > 2.48.1 >
diff --git a/include/linux/swap.h b/include/linux/swap.h index 91b30701274e..9a48e79a0a52 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -74,14 +74,13 @@ static inline int current_is_kswapd(void) * to a special SWP_DEVICE_{READ|WRITE} entry. * * When a page is mapped by the device for exclusive access we set the CPU page - * table entries to special SWP_DEVICE_EXCLUSIVE_* entries. + * table entries to a special SWP_DEVICE_EXCLUSIVE entry. */ #ifdef CONFIG_DEVICE_PRIVATE -#define SWP_DEVICE_NUM 4 +#define SWP_DEVICE_NUM 3 #define SWP_DEVICE_WRITE (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_NUM) #define SWP_DEVICE_READ (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_NUM+1) -#define SWP_DEVICE_EXCLUSIVE_WRITE (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_NUM+2) -#define SWP_DEVICE_EXCLUSIVE_READ (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_NUM+3) +#define SWP_DEVICE_EXCLUSIVE (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_NUM+2) #else #define SWP_DEVICE_NUM 0 #endif diff --git a/include/linux/swapops.h b/include/linux/swapops.h index 96f26e29fefe..64ea151a7ae3 100644 --- a/include/linux/swapops.h +++ b/include/linux/swapops.h @@ -186,26 +186,16 @@ static inline bool is_writable_device_private_entry(swp_entry_t entry) return unlikely(swp_type(entry) == SWP_DEVICE_WRITE); } -static inline swp_entry_t make_readable_device_exclusive_entry(pgoff_t offset) +static inline swp_entry_t make_device_exclusive_entry(pgoff_t offset) { - return swp_entry(SWP_DEVICE_EXCLUSIVE_READ, offset); -} - -static inline swp_entry_t make_writable_device_exclusive_entry(pgoff_t offset) -{ - return swp_entry(SWP_DEVICE_EXCLUSIVE_WRITE, offset); + return swp_entry(SWP_DEVICE_EXCLUSIVE, offset); } static inline bool is_device_exclusive_entry(swp_entry_t entry) { - return swp_type(entry) == SWP_DEVICE_EXCLUSIVE_READ || - swp_type(entry) == SWP_DEVICE_EXCLUSIVE_WRITE; + return swp_type(entry) == SWP_DEVICE_EXCLUSIVE; } -static inline bool is_writable_device_exclusive_entry(swp_entry_t entry) -{ - return unlikely(swp_type(entry) == SWP_DEVICE_EXCLUSIVE_WRITE); -} #else /* CONFIG_DEVICE_PRIVATE */ static inline swp_entry_t make_readable_device_private_entry(pgoff_t offset) { @@ -227,12 +217,7 @@ static inline bool is_writable_device_private_entry(swp_entry_t entry) return false; } -static inline swp_entry_t make_readable_device_exclusive_entry(pgoff_t offset) -{ - return swp_entry(0, 0); -} - -static inline swp_entry_t make_writable_device_exclusive_entry(pgoff_t offset) +static inline swp_entry_t make_device_exclusive_entry(pgoff_t offset) { return swp_entry(0, 0); } @@ -242,10 +227,6 @@ static inline bool is_device_exclusive_entry(swp_entry_t entry) return false; } -static inline bool is_writable_device_exclusive_entry(swp_entry_t entry) -{ - return false; -} #endif /* CONFIG_DEVICE_PRIVATE */ #ifdef CONFIG_MIGRATION diff --git a/mm/mprotect.c b/mm/mprotect.c index 516b1d847e2c..9cb6ab7c4048 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -225,14 +225,6 @@ static long change_pte_range(struct mmu_gather *tlb, newpte = swp_entry_to_pte(entry); if (pte_swp_uffd_wp(oldpte)) newpte = pte_swp_mkuffd_wp(newpte); - } else if (is_writable_device_exclusive_entry(entry)) { - entry = make_readable_device_exclusive_entry( - swp_offset(entry)); - newpte = swp_entry_to_pte(entry); - if (pte_swp_soft_dirty(oldpte)) - newpte = pte_swp_mksoft_dirty(newpte); - if (pte_swp_uffd_wp(oldpte)) - newpte = pte_swp_mkuffd_wp(newpte); } else if (is_pte_marker_entry(entry)) { /* * Ignore error swap entries unconditionally, diff --git a/mm/page_table_check.c b/mm/page_table_check.c index 509c6ef8de40..c2b3600429a0 100644 --- a/mm/page_table_check.c +++ b/mm/page_table_check.c @@ -196,9 +196,8 @@ EXPORT_SYMBOL(__page_table_check_pud_clear); /* Whether the swap entry cached writable information */ static inline bool swap_cached_writable(swp_entry_t entry) { - return is_writable_device_exclusive_entry(entry) || - is_writable_device_private_entry(entry) || - is_writable_migration_entry(entry); + return is_writable_device_private_entry(entry) || + is_writable_migration_entry(entry); } static inline void page_table_check_pte_flags(pte_t pte) diff --git a/mm/rmap.c b/mm/rmap.c index 49ffac6d27f8..65d9bbea16d0 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -2470,7 +2470,7 @@ struct page *make_device_exclusive(struct mm_struct *mm, unsigned long addr, * do_swap_page() will trigger the conversion back while holding the * folio lock. */ - entry = make_writable_device_exclusive_entry(page_to_pfn(page)); + entry = make_device_exclusive_entry(page_to_pfn(page)); swp_pte = swp_entry_to_pte(entry); if (pte_soft_dirty(fw.pte)) swp_pte = pte_swp_mksoft_dirty(swp_pte);
There is no need for the distinction anymore; let's merge the readable and writable device-exclusive entries into a single device-exclusive entry type. Signed-off-by: David Hildenbrand <david@redhat.com> --- include/linux/swap.h | 7 +++---- include/linux/swapops.h | 27 ++++----------------------- mm/mprotect.c | 8 -------- mm/page_table_check.c | 5 ++--- mm/rmap.c | 2 +- 5 files changed, 10 insertions(+), 39 deletions(-)