From: Tarun Sahu <tarunsahu@google.com>
To: Pasha Tatashin <pasha.tatashin@soleen.com>,
Mike Rapoport <rppt@kernel.org>,
Pratyush Yadav <pratyush@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
kexec@lists.infradead.org, Tarun Sahu <tarunsahu@google.com>
Subject: [PATCH 1/1] mm/memfd_luo: use KHOSER_PTR for serialized_data checks
Date: Mon, 15 Jun 2026 13:05:05 +0000 [thread overview]
Message-ID: <9fe93604bac096dd3edfa48a0d2e2ce6e2683f56.1781528022.git.tarunsahu@google.com> (raw)
In-Reply-To: <cover.1781528022.git.tarunsahu@google.com>
In all callbacks (freeze, unpreserve, finish, retrieve), use the
standard KHOSER_LOAD_PTR() and KHOSER_STORE_PTR() macros to safely load
and store the serialized structure pointer.
This resolves the issue where phys_to_virt() was previously called
before checking if the physical address is valid, since KHOSER_LOAD_PTR()
automatically handles translation and returns NULL if the physical
address is 0.
Fixes: b3749f174d68 ("mm: memfd_luo: allow preserving memfd")
Signed-off-by: Tarun Sahu <tarunsahu@google.com>
---
mm/memfd_luo.c | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c
index 59de210bee5f..ec37693841a6 100644
--- a/mm/memfd_luo.c
+++ b/mm/memfd_luo.c
@@ -257,6 +257,7 @@ static void memfd_luo_unpreserve_folios(struct kho_vmalloc *kho_vmalloc,
static int memfd_luo_preserve(struct liveupdate_file_op_args *args)
{
+ DECLARE_KHOSER_PTR(sd, struct memfd_luo_ser *);
struct inode *inode = file_inode(args->file);
struct memfd_luo_folio_ser *folios_ser;
struct memfd_luo_ser *ser;
@@ -309,7 +310,8 @@ static int memfd_luo_preserve(struct liveupdate_file_op_args *args)
inode_unlock(inode);
args->private_data = folios_ser;
- args->serialized_data = virt_to_phys(ser);
+ KHOSER_STORE_PTR(sd, ser);
+ args->serialized_data = sd.phys;
return 0;
@@ -323,13 +325,15 @@ static int memfd_luo_preserve(struct liveupdate_file_op_args *args)
static int memfd_luo_freeze(struct liveupdate_file_op_args *args)
{
+ DECLARE_KHOSER_PTR(sd, struct memfd_luo_ser *) = {
+ .phys = args->serialized_data
+ };
struct memfd_luo_ser *ser;
- if (WARN_ON_ONCE(!args->serialized_data))
+ ser = KHOSER_LOAD_PTR(sd);
+ if (WARN_ON_ONCE(!ser))
return -EINVAL;
- ser = phys_to_virt(args->serialized_data);
-
/*
* The pos might have changed since prepare. Everything else stays the
* same.
@@ -341,17 +345,19 @@ static int memfd_luo_freeze(struct liveupdate_file_op_args *args)
static void memfd_luo_unpreserve(struct liveupdate_file_op_args *args)
{
+ DECLARE_KHOSER_PTR(sd, struct memfd_luo_ser *) = {
+ .phys = args->serialized_data
+ };
struct inode *inode = file_inode(args->file);
struct memfd_luo_ser *ser;
- if (WARN_ON_ONCE(!args->serialized_data))
+ ser = KHOSER_LOAD_PTR(sd);
+ if (WARN_ON_ONCE(!ser))
return;
inode_lock(inode);
shmem_freeze(inode, false);
- ser = phys_to_virt(args->serialized_data);
-
memfd_luo_unpreserve_folios(&ser->folios, args->private_data,
ser->nr_folios);
@@ -386,6 +392,9 @@ static void memfd_luo_discard_folios(const struct memfd_luo_folio_ser *folios_se
static void memfd_luo_finish(struct liveupdate_file_op_args *args)
{
+ DECLARE_KHOSER_PTR(sd, struct memfd_luo_ser *) = {
+ .phys = args->serialized_data
+ };
struct memfd_luo_folio_ser *folios_ser;
struct memfd_luo_ser *ser;
@@ -397,7 +406,7 @@ static void memfd_luo_finish(struct liveupdate_file_op_args *args)
if (args->retrieve_status)
return;
- ser = phys_to_virt(args->serialized_data);
+ ser = KHOSER_LOAD_PTR(sd);
if (!ser)
return;
@@ -517,12 +526,15 @@ static int memfd_luo_retrieve_folios(struct file *file,
static int memfd_luo_retrieve(struct liveupdate_file_op_args *args)
{
+ DECLARE_KHOSER_PTR(sd, struct memfd_luo_ser *) = {
+ .phys = args->serialized_data
+ };
struct memfd_luo_folio_ser *folios_ser;
struct memfd_luo_ser *ser;
struct file *file;
int err;
- ser = phys_to_virt(args->serialized_data);
+ ser = KHOSER_LOAD_PTR(sd);
if (!ser)
return -EINVAL;
--
2.54.0.1136.gdb2ca164c4-goog
next prev parent reply other threads:[~2026-06-15 13:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-15 13:05 [PATCH 0/1] " Tarun Sahu
2026-06-15 13:05 ` Tarun Sahu [this message]
2026-06-16 6:44 ` Mike Rapoport
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9fe93604bac096dd3edfa48a0d2e2ce6e2683f56.1781528022.git.tarunsahu@google.com \
--to=tarunsahu@google.com \
--cc=akpm@linux-foundation.org \
--cc=kexec@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pasha.tatashin@soleen.com \
--cc=pratyush@kernel.org \
--cc=rppt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®