]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm: use single SWP_DEVICE_EXCLUSIVE entry type
authorDavid Hildenbrand <david@redhat.com>
Mon, 10 Feb 2025 19:37:48 +0000 (20:37 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 17 Mar 2025 05:05:58 +0000 (22:05 -0700)
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.

Link: https://lkml.kernel.org/r/20250210193801.781278-7-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Acked-by: Simona Vetter <simona.vetter@ffwll.ch>
Reviewed-by: Alistair Popple <apopple@nvidia.com>
Tested-by: Alistair Popple <apopple@nvidia.com>
Cc: Alex Shi <alexs@kernel.org>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Dave Airlie <airlied@gmail.com>
Cc: Jann Horn <jannh@google.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Karol Herbst <kherbst@redhat.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Lyude <lyude@redhat.com>
Cc: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: SeongJae Park <sj@kernel.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Yanteng Si <si.yanteng@linux.dev>
Cc: Barry Song <v-songbaohua@oppo.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/swap.h
include/linux/swapops.h
mm/mprotect.c
mm/page_table_check.c
mm/rmap.c

index 91b30701274e1d2187dc7444c5e65d0e287f52fe..9a48e79a0a523a584cb209ed46f1ce7dff02527f 100644 (file)
@@ -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
index 96f26e29fefed3f49dcd1a37c3d05f0dddba99d9..64ea151a7ae39a9f32dcaf8bfb3e27c350e07f65 100644 (file)
@@ -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
index 516b1d847e2cd89dd8bfa93f924a611521d41447..9cb6ab7c4048052ab97691025ef1661573a682a3 100644 (file)
@@ -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,
index 509c6ef8de400e78bb247deaf4e7e2b6a79ff357..c2b3600429a0c435daba9ad46e2dd608b7885e8a 100644 (file)
@@ -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)
index 0cd2a2d3de00d7bf6ff48960fce147127f1e8b36..1129ed132af94410b91594ff389aa4df5a8b21f2 100644 (file)
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -2492,7 +2492,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);