From nobody Sun Feb 8 14:51:15 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D16953F0751 for ; Thu, 22 Jan 2026 15:18:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769095139; cv=none; b=h0DZpEfxv6uRmdq5c92UeKuzMJgeleqZHCNLOduKu/nZQ0BZ/Dgjop8cXeQMk6rw8xvlVhGlPzhHtAky4w/2A0OQ/p3Gd9rql8+yBcgnq5We7zcOnBp2LMnhoFqIqnC1nEgCVTCDSSpk+sD5/KPmgtiucdzSLrf7fMLhj7E+tvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769095139; c=relaxed/simple; bh=272BvbxC7euhCsy4Z4uBhOtqpvh5RkKjXvXKDX/+ojY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F3Dr567qSlek+CEU9gEpmR2hccQPeVOo46neyhCO+3g2we9ZHBV/XjhAibnW4BZeA3TJGtjMPNu/5/cEM9UsfxGA+S4eR39BgiteeX4Z6zCwoKm2rq5uhml8IsgzV7ojuzW6aEHCtNT3fVd7v6/FUcZFLG5p9KS51G0TGMFTLes= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F2B/t0Bt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="F2B/t0Bt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18692C4AF0B; Thu, 22 Jan 2026 15:18:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769095139; bh=272BvbxC7euhCsy4Z4uBhOtqpvh5RkKjXvXKDX/+ojY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F2B/t0BtpaipEuqECr6q2CJUfcQms0HLxJ1OR2GUvVK3VTqXTupSVgtZ393faJZS7 dQHSzB5HL5WVRoPI4ukuPgq0d/qGc7gxjesKU+pdoSlachfAsOmjvl5EJQtZvZ98cf Gp2gxyG+vB+3v1oSUkc9y0Rh8oIjWfDS/aWB/NydQt1SjKfF7jsTWJZCSF9q4wDsww 7qizAlroyUkBBvubpL9dkVQsVt1+hSTdmt0fq6l7LUBAv8jv4z5PTv1UZZCFrnO2KG Rp3XuvFMJSQIO+AGJDB+u0tQRtAgTYNvF4hTXVH0vo5/zcIP1tQMXwmuCIG/0JvOKV Nn8gSvDHKY5+g== From: Pratyush Yadav To: Hugh Dickins , Baolin Wang , Andrew Morton , Pasha Tatashin , Mike Rapoport , Pratyush Yadav Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] memfd: export alloc_file() Date: Thu, 22 Jan 2026 16:18:39 +0100 Message-ID: <20260122151842.4069702-2-pratyush@kernel.org> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog In-Reply-To: <20260122151842.4069702-1-pratyush@kernel.org> References: <20260122151842.4069702-1-pratyush@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Pratyush Yadav (Google)" The Live Update Orchestrator's (LUO) memfd preservation works by preserving all the folios of a memfd, re-creating an empty memfd on the next boot, and then inserting back the preserved folios. Currently it creates the file by directly calling shmem_file_setup(). This leaves out other work done by alloc_file() like setting up the file mode, flags, or calling the security hooks. Export alloc_file() to let memfd_luo use it. Rename it to memfd_alloc_file() since it is no longer private and thus needs a subsystem prefix. Signed-off-by: Pratyush Yadav (Google) Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pasha Tatashin --- include/linux/memfd.h | 6 ++++++ mm/memfd.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/linux/memfd.h b/include/linux/memfd.h index cc74de3dbcfe..c328a7b356d0 100644 --- a/include/linux/memfd.h +++ b/include/linux/memfd.h @@ -17,6 +17,7 @@ struct folio *memfd_alloc_folio(struct file *memfd, pgoff= _t idx); * to by vm_flags_ptr. */ int memfd_check_seals_mmap(struct file *file, vm_flags_t *vm_flags_ptr); +struct file *memfd_alloc_file(const char *name, unsigned int flags); #else static inline long memfd_fcntl(struct file *f, unsigned int c, unsigned in= t a) { @@ -31,6 +32,11 @@ static inline int memfd_check_seals_mmap(struct file *fi= le, { return 0; } + +static inline struct file *memfd_alloc_file(const char *name, unsigned int= flags) +{ + return ERR_PTR(-EINVAL); +} #endif =20 #endif /* __LINUX_MEMFD_H */ diff --git a/mm/memfd.c b/mm/memfd.c index ab5312aff14b..f032c6052926 100644 --- a/mm/memfd.c +++ b/mm/memfd.c @@ -456,7 +456,7 @@ static char *alloc_name(const char __user *uname) return ERR_PTR(error); } =20 -static struct file *alloc_file(const char *name, unsigned int flags) +struct file *memfd_alloc_file(const char *name, unsigned int flags) { unsigned int *file_seals; struct file *file; @@ -520,5 +520,5 @@ SYSCALL_DEFINE2(memfd_create, return PTR_ERR(name); =20 fd_flags =3D (flags & MFD_CLOEXEC) ? O_CLOEXEC : 0; - return FD_ADD(fd_flags, alloc_file(name, flags)); + return FD_ADD(fd_flags, memfd_alloc_file(name, flags)); } --=20 2.52.0.457.g6b5491de43-goog From nobody Sun Feb 8 14:51:15 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D4BD40F8C8 for ; Thu, 22 Jan 2026 15:19:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769095141; cv=none; b=LuhBnGQnyXL+SF4iwWmGn2Q66YAkW2Fy4Ls41ES1x4oa+3YIxNZ/r0cfRgSlNOvaSjmIcstmS+c4XFWpNIt+3gs6hpkaRSFU0CmPClHNPaYPDQ4X43RyoH+zCDjInlTTzAtJEpXTEewGwlDpnL9+7tU95baij/iiK8b4yusPMTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769095141; c=relaxed/simple; bh=YLJlkAxZgahTe6DNHbxTJdYXwUdyk5vxfIME+2fG3k4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gudmu8nOXSll4eKHHKro11LZJaCsl1N+twSadB1Rsx1PlzWsosMuCI6OE5sXgPUVJztkHnIbQJicganD26a0qgLqnEOg3D40ez2d8QDXZoiS1pwZykuRZhQ6vlV2C5t8l68umfotqPbx0jjihp0McPUaR5fCUUzvXwXzel3kyW8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZX7P+4UF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZX7P+4UF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA89BC116C6; Thu, 22 Jan 2026 15:18:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769095141; bh=YLJlkAxZgahTe6DNHbxTJdYXwUdyk5vxfIME+2fG3k4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZX7P+4UF9IYUrVIBMSwkZXOxFg4C4bYpv88wdSwsODGZatPaTAAHNDBjQn/qZX4N8 13Gtn9SyiPwYl0ljdV4idd1buk9vvd1oFf2hYK+tledpfTNbEMF2CpZh9bVBNMRz0F qEHoKrhq7mSwWDSXkyDEgEyPBHOGJMAVEVS3iDtik76/OupwBO6vfgcm1bRoINpkKv TKi5Ty3kvB4cl4zeyEGirEK77KJjMR1oSpVcws0tbAhnoOZu07x/2sCprKQ/Dugdt3 dJRyQg/FLVKexjSgiDRpxH1tWzst5yL7b3nYixzKI+QqCu0RbX05n82FWjbqFHgkMI SoxcYB7hYnDsw== From: Pratyush Yadav To: Hugh Dickins , Baolin Wang , Andrew Morton , Pasha Tatashin , Mike Rapoport , Pratyush Yadav Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] mm: memfd_luo: use memfd_alloc_file() instead of shmem_file_setup() Date: Thu, 22 Jan 2026 16:18:40 +0100 Message-ID: <20260122151842.4069702-3-pratyush@kernel.org> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog In-Reply-To: <20260122151842.4069702-1-pratyush@kernel.org> References: <20260122151842.4069702-1-pratyush@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Pratyush Yadav (Google)" When restoring a memfd, the file is created using shmem_file_setup(). While memfd creation also calls this function to get the file, it also does other things: 1. The O_LARGEFILE flag is set on the file. If this is not done, writes on the memfd exceeding 2 GiB fail. 2. FMODE_LSEEK, FMODE_PREAD, and FMODE_PWRITE are set on the file. This makes sure the file is seekable and can be used with pread() and pwrite(). 3. Initializes the security field for the inode and makes sure that inode creation is permitted by the security module. Currently, none of those things are done. This means writes above 2 GiB fail, pread(), and pwrite() fail, and so on. lseek() happens to work because file_init_path() sets it because shmem defines fop->llseek. Fix this by using memfd_alloc_file() to get the file to make sure the initialization sequence for normal and preserved memfd is the same. Fixes: b3749f174d68 ("mm: memfd_luo: allow preserving memfd") Signed-off-by: Pratyush Yadav (Google) Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pasha Tatashin --- mm/memfd_luo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c index 4f6ba63b4310..01a72e4d3ef6 100644 --- a/mm/memfd_luo.c +++ b/mm/memfd_luo.c @@ -78,6 +78,7 @@ #include #include #include +#include #include "internal.h" =20 static int memfd_luo_preserve_folios(struct file *file, @@ -443,8 +444,7 @@ static int memfd_luo_retrieve(struct liveupdate_file_op= _args *args) if (!ser) return -EINVAL; =20 - file =3D shmem_file_setup("", 0, VM_NORESERVE); - + file =3D memfd_alloc_file("", 0); if (IS_ERR(file)) { pr_err("failed to setup file: %pe\n", file); return PTR_ERR(file); --=20 2.52.0.457.g6b5491de43-goog From nobody Sun Feb 8 14:51:15 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A0BB42189F for ; Thu, 22 Jan 2026 15:19:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769095143; cv=none; b=VoiSY1hPIXsApuW/rcxhMWlNV4W5VMbSB/O0qeJ+78bU9j48I00CPWMSdFQ80vgk5+P9xDI47LgjPJMcu2w16/AvTmPqbWLViQSnW1kgbAIr1sp7k0ewLarW3fEtHdIrNDvQwxpc8XpewXZYvwxpaqrJ470c67XOmAkmLkUuiyA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769095143; c=relaxed/simple; bh=Nt47UFsOfhU+/Sa/WsYZT61v6HKZPeC+3cKH72ng46Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sv2xbk6MrCzxb9OQ5uVg6iED2qs2pBWFNHP+u35aATNhkJx11sLSIRiFuTMGudTBr3DAMzVBW+rvmGT+kS9BZr8BhiozLTAJ8FnveTImyCrWj5m4aYXWMLA4TsQ4MdM8UP1DFqqbKcYIdWjTXaDH3XC7bfAEj+o0gk9ovIW4n/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F27+4tl9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="F27+4tl9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96069C116C6; Thu, 22 Jan 2026 15:19:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769095143; bh=Nt47UFsOfhU+/Sa/WsYZT61v6HKZPeC+3cKH72ng46Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F27+4tl9g5ai8OC/CPoK5ZI5qEZbkL/ZYyabatTcmWCRlJZ+qSU5GhSWXfbluvDRt BtQ+mSG8+NomVY0I+YeTgZzKOwsCH3AGiYmurkdawxOpWRfxqBSEZQJFMQ4yXLWcAA f8ZdIs2pxZB3n6LL5N8Z4sRLXFpYdb0aMJMIDLVAUuyWorLkLC46xxtiOaE+WCK4VG vmFsGllHJ3JKNKcCksAYjlTOPftjQ14TqnI4z7BTYC8B1SW4ffjXFAMEpvezN0OxEs uuDfpz/yOOnqxVWefmXGAyMjoIOKjzFSKmLG31gmByZ+njmcOPWOS2ogmYq0gQGWFP MQmcyahrNeGvA== From: Pratyush Yadav To: Hugh Dickins , Baolin Wang , Andrew Morton , Pasha Tatashin , Mike Rapoport , Pratyush Yadav Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] mm: memfd_luo: restore and free memfd_luo_ser on failure Date: Thu, 22 Jan 2026 16:18:41 +0100 Message-ID: <20260122151842.4069702-4-pratyush@kernel.org> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog In-Reply-To: <20260122151842.4069702-1-pratyush@kernel.org> References: <20260122151842.4069702-1-pratyush@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Pratyush Yadav (Google)" memfd_luo_ser has the serialization metadata. It is of no use once restoration fails. Free it on failure. Fixes: b3749f174d68 ("mm: memfd_luo: allow preserving memfd") Signed-off-by: Pratyush Yadav (Google) Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pasha Tatashin --- mm/memfd_luo.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c index 01a72e4d3ef6..a34fccc23b6a 100644 --- a/mm/memfd_luo.c +++ b/mm/memfd_luo.c @@ -447,7 +447,8 @@ static int memfd_luo_retrieve(struct liveupdate_file_op= _args *args) file =3D memfd_alloc_file("", 0); if (IS_ERR(file)) { pr_err("failed to setup file: %pe\n", file); - return PTR_ERR(file); + err =3D PTR_ERR(file); + goto free_ser; } =20 vfs_setpos(file, ser->pos, MAX_LFS_FILESIZE); @@ -473,7 +474,8 @@ static int memfd_luo_retrieve(struct liveupdate_file_op= _args *args) =20 put_file: fput(file); - +free_ser: + kho_restore_free(ser); return err; } =20 --=20 2.52.0.457.g6b5491de43-goog