[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b55a87cc-239c-4475-88aa-6296e67b4e7d@lucifer.local>
Date: Thu, 13 Nov 2025 14:56:09 +0000
From: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: Christian Borntraeger <borntraeger@...ux.ibm.com>,
Janosch Frank <frankja@...ux.ibm.com>,
Claudio Imbrenda <imbrenda@...ux.ibm.com>,
David Hildenbrand <david@...hat.com>,
Alexander Gordeev <agordeev@...ux.ibm.com>,
Gerald Schaefer <gerald.schaefer@...ux.ibm.com>,
Heiko Carstens <hca@...ux.ibm.com>, Vasily Gorbik <gor@...ux.ibm.com>,
Sven Schnelle <svens@...ux.ibm.com>, Peter Xu <peterx@...hat.com>,
Alexander Viro <viro@...iv.linux.org.uk>,
Christian Brauner <brauner@...nel.org>, Jan Kara <jack@...e.cz>,
Arnd Bergmann <arnd@...db.de>, Zi Yan <ziy@...dia.com>,
Baolin Wang <baolin.wang@...ux.alibaba.com>,
"Liam R . Howlett" <Liam.Howlett@...cle.com>,
Nico Pache <npache@...hat.com>, Ryan Roberts <ryan.roberts@....com>,
Dev Jain <dev.jain@....com>, Barry Song <baohua@...nel.org>,
Lance Yang <lance.yang@...ux.dev>, Muchun Song <muchun.song@...ux.dev>,
Oscar Salvador <osalvador@...e.de>, Vlastimil Babka <vbabka@...e.cz>,
Mike Rapoport <rppt@...nel.org>,
Suren Baghdasaryan <surenb@...gle.com>, Michal Hocko <mhocko@...e.com>,
Matthew Brost <matthew.brost@...el.com>,
Joshua Hahn <joshua.hahnjy@...il.com>, Rakie Kim <rakie.kim@...com>,
Byungchul Park <byungchul@...com>, Gregory Price <gourry@...rry.net>,
Ying Huang <ying.huang@...ux.alibaba.com>,
Alistair Popple <apopple@...dia.com>,
Axel Rasmussen <axelrasmussen@...gle.com>,
Yuanchu Xie <yuanchu@...gle.com>, Wei Xu <weixugc@...gle.com>,
Kemeng Shi <shikemeng@...weicloud.com>,
Kairui Song <kasong@...cent.com>, Nhat Pham <nphamcs@...il.com>,
Baoquan He <bhe@...hat.com>, Chris Li <chrisl@...nel.org>,
SeongJae Park <sj@...nel.org>, Matthew Wilcox <willy@...radead.org>,
Jason Gunthorpe <jgg@...pe.ca>, Leon Romanovsky <leon@...nel.org>,
Xu Xin <xu.xin16@....com.cn>,
Chengming Zhou <chengming.zhou@...ux.dev>,
Jann Horn <jannh@...gle.com>, Miaohe Lin <linmiaohe@...wei.com>,
Naoya Horiguchi <nao.horiguchi@...il.com>,
Pedro Falcato <pfalcato@...e.de>,
Pasha Tatashin <pasha.tatashin@...een.com>,
Rik van Riel <riel@...riel.com>, Harry Yoo <harry.yoo@...cle.com>,
Hugh Dickins <hughd@...gle.com>, linux-kernel@...r.kernel.org,
kvm@...r.kernel.org, linux-s390@...r.kernel.org,
linux-fsdevel@...r.kernel.org, linux-mm@...ck.org,
linux-arch@...r.kernel.org, damon@...ts.linux.dev
Subject: Re: [PATCH v3 02/16] mm: introduce leaf entry type and use to
simplify leaf entry logic
Hi Andrew,
Please apply the attached fix-patch.
This ensures that we do not accidentally conflict with any valid swap
entry. We can do so without occupying any additional swap (softleaf) type.
Cheers, Lorenzo
----8<----
>From 78439310eded5db10692c3e8d0d322bdd6409eff Mon Sep 17 00:00:00 2001
From: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
Date: Thu, 13 Nov 2025 14:20:34 +0000
Subject: [PATCH] mm: avoid any possible collision between swap entries,
SOFTLEAF_NONE
The way swap entries are encoded varies by architecture. For x86-64 for
instance, the encoded swap offset is the one's complement of the specified
swap offset.
As a result, device 0, offset 0 would be encoded as 0..01..10b.
This means it is possible to specify a PTE entry that is both device 0,
offset 0 and something that will be identified as a swap entry rather than
a pte_none() entry.
For other architectures, the encoding may preclude such entries being
valid.
The softleaf implementation currently depends on a 0..0b entry being
uniquely identifiable as a none entry.
This is therefore not a safe assumption, so let's fix that.
PTE markers unconditionally occupy a softleaf type, and currently use only
3 bits of the offset field to encode their type with no further information
recorded.
It is therefore no issue at all to add an additional marker type
designating the field as a none entry.
We also make the none checks more canonical by adjusting softleaf_is_none()
to reference softleaf_mk_none().
By doing so we avoid any possible collision with swap file entries while
taking up no further meaningful resource.
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
---
include/linux/leafops.h | 8 +++++---
include/linux/swap.h | 1 +
include/linux/swapops.h | 6 +++++-
3 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/include/linux/leafops.h b/include/linux/leafops.h
index cff9d94fd5d1..74fd95b55e9c 100644
--- a/include/linux/leafops.h
+++ b/include/linux/leafops.h
@@ -40,7 +40,8 @@ enum softleaf_type {
*/
static inline softleaf_t softleaf_mk_none(void)
{
- return ((softleaf_t) { 0 });
+ /* Uniquely identifies none entry. */
+ return make_pte_marker_entry(PTE_MARKER_SOFTLEAF_NONE);
}
/**
@@ -72,7 +73,7 @@ static inline softleaf_t softleaf_from_pte(pte_t pte)
*/
static inline bool softleaf_is_none(softleaf_t entry)
{
- return entry.val == 0;
+ return entry.val == softleaf_mk_none().val;
}
/**
@@ -199,7 +200,8 @@ static inline bool softleaf_is_hwpoison(softleaf_t entry)
*/
static inline bool softleaf_is_marker(softleaf_t entry)
{
- return softleaf_type(entry) == SOFTLEAF_MARKER;
+ return softleaf_type(entry) == SOFTLEAF_MARKER &&
+ !softleaf_is_none(entry);
}
/**
diff --git a/include/linux/swap.h b/include/linux/swap.h
index 38ca3df68716..e5abea55448b 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -112,6 +112,7 @@ static inline int current_is_kswapd(void)
#define SWP_HWPOISON_NUM 0
#endif
+/* Leave a type reserved for softleaf none. */
#define MAX_SWAPFILES \
((1 << MAX_SWAPFILES_SHIFT) - SWP_DEVICE_NUM - \
SWP_MIGRATION_NUM - SWP_HWPOISON_NUM - \
diff --git a/include/linux/swapops.h b/include/linux/swapops.h
index 0a4b3f51ecf5..04e74716a845 100644
--- a/include/linux/swapops.h
+++ b/include/linux/swapops.h
@@ -419,7 +419,11 @@ typedef unsigned long pte_marker;
* PROT_NONE, rather than if they were a memory hole or equivalent.
*/
#define PTE_MARKER_GUARD BIT(2)
-#define PTE_MARKER_MASK (BIT(3) - 1)
+
+/* Internal use by the softleaf implementation to represent 'none' entries. */
+#define PTE_MARKER_SOFTLEAF_NONE BIT(3)
+
+#define PTE_MARKER_MASK (BIT(4) - 1)
static inline swp_entry_t make_pte_marker_entry(pte_marker marker)
{
--
2.51.0
Powered by blists - more mailing lists