From nobody Thu Apr 2 20:22:18 2026 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A64B40B6C8 for ; Thu, 26 Mar 2026 16:39:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774543189; cv=none; b=kFWj1IObPlZ4YFLZIixOK5MIVY3qDX8sR8ClyCvZuWKLLCJsfCsOE/bmE8Bp50GLehfBcLqXVllQ5NnbGdJXsuSKMLn0ytfC7ITQgznly2ldcu8ioY9mMPbpel1VNlK16na4BBTt5cEj+e06W2Ju0h3cXYAvEl3q4K4SSi0EIRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774543189; c=relaxed/simple; bh=nMoVBvse899NPg8tpB9OKbPFwPjKBuBCeTp4KA60WEU=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fAhgaCyhLj4ZitkJsHGSPCIU2qVOviqcW4kcfDntedQdg/hpATz+rK1zPlMKr0P9x6Sl33DD3wFCwpNqEj44YYAvItMv6cbVQZcvQX6gHAOCYh7cjhZY3+539m8uMJfjSoRIdOGNvoz1fMGIqdtN4kb5A/K4za8oZQaWfUWlmLQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=aGnEnuH0; arc=none smtp.client-ip=209.85.160.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="aGnEnuH0" Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-50b35f3e489so21252141cf.0 for ; Thu, 26 Mar 2026 09:39:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1774543186; x=1775147986; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=hIdUnvgvoju2sn6Qx2mGLJNfJ9th4UndCcaJvlrJfI0=; b=aGnEnuH00aeslZWeM13KSRQjMeP+myxEwJInFTFq4KuPe/zYUJNi7j0nHe5zPF8BF6 ZyfNZjtaIWghtUTCOhAqwGz/SHoeemz/TK3KUpxov/Pcx6+PtBKT3R066hY7xCgl6lR1 1ZtY+fMcHFOVrC9hFx7d1dnujwi0Q3tPAx6dFT48pUn1LcrU2OzPzeZ2EOBoLXpqP25C 5BnL3mERx1XUJ+qFYv0XN3a0OQTvXIV4Ug4AQGCWqtfMboWSKd0Fdzy3z4HYLo3RO7Sf gSv22mB1LbJg/IG83RUQEXiayW9q055IIA428ov3XwldYfaHHmJDE1k49TPBcDklT8ZN XnUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774543186; x=1775147986; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=hIdUnvgvoju2sn6Qx2mGLJNfJ9th4UndCcaJvlrJfI0=; b=NXttVD33CRHtqOMFORM05doeoB6Ew30VmI8Zug8F4wnJrwY6TWWiRX08AFNBFfbVQO 0zRxgxhwrxBgf70jNbWyhKcPKSBAPs87PYt2z4lD82TDlpNKIZ1/4yfcd4OXrB/HLPWu BCslU6GTjS72ytTmKxpc79mYdp2uuqmvXX8vfcCkCcbtJ2AI4F0zpYQ4wh7HstzUIIfm 25IL996J5HIaXhx7DUB+MZlTnU7de0VRe4vUe6btgq3WZRiHUEqOA92CxHoaYdgILcNo vSkDRL9ilB/IJs+aki877yJNuxdA0SMw4Wfn22H/ll7OFkZjMBaK2H3s6jI6LGQIYpP9 Qp3Q== X-Forwarded-Encrypted: i=1; AJvYcCU0R26tY6Os+KYyE52ZcnUfRkBtbyXrJ/CZx+3OkTTiIWJosyt+/FBj/l9+OjNop1mC2fZSqFrQwRko3aY=@vger.kernel.org X-Gm-Message-State: AOJu0Yzd8BH835Z05ulyxCTlPt8qsCjz2Wpb0tlXPhRTsO++6un4Q9Dd lLFePIgJVUQL1w99FfqQlaLFwWbYuA14YlA0bTad10TnpE6KBtznwmvGGQwxcxHPa5I= X-Gm-Gg: ATEYQzwPyWcx/qeFb8tdumgIP+GehjjWT4aeZS2k6AQtbjyw3Rn8J9nPmj4xWe9CwiJ XUX+Ply1hkIgs30zhmS6R7nMRZvneOcGGW7Xgn1YQl56VIRL7lzdnKgChEQbu224HjkIaQhbeU0 fwpoRPSb4DzYW59lTFKWESBLdorODqlD9DAVUwkoWsuO5Bv+mv/HG+8lRBbahARm8MDL0LN0HXe ky6J2GNPT8Wi7dPn+5glrc/gcMW1wj1qVC8ErrA+IlUo936zPrIQqbTFUyiEeDqVlnqvzs0jWKI LgneTrL35F+cTk8+nvoacAxlMLzeDCiZssmxZ+I12d7fEvzHRreU5mW9yhb03vrfPoedZWYb8R1 jU8lpQfiexsXuDF1Z3kfujBviK8yFdQmBxQlnm6GmVp7CDQxpXO0ZYeNfhKma39P9UEluDCF142 K3qoDNXqf455VDzzLoZbTOOCPKSSJrm0sWlwSRLzytqPbofJHxF4fpY+rJSsTMd0VacBWcA/fJC uAx X-Received: by 2002:a05:622a:8d17:b0:50b:4a3c:8917 with SMTP id d75a77b69052e-50b994a6c29mr24101061cf.24.1774543186042; Thu, 26 Mar 2026 09:39:46 -0700 (PDT) Received: from plex.localdomain ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-50b920f77cfsm28238251cf.6.2026.03.26.09.39.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 09:39:45 -0700 (PDT) From: Pasha Tatashin To: linux-kselftest@vger.kernel.org, rppt@kernel.org, shuah@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, pasha.tatashin@soleen.com, dmatlack@google.com, pratyush@kernel.org, skhawaja@google.com Subject: [PATCH v4 1/3] liveupdate: prevent double management of files Date: Thu, 26 Mar 2026 16:39:41 +0000 Message-ID: <20260326163943.574070-2-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260326163943.574070-1-pasha.tatashin@soleen.com> References: <20260326163943.574070-1-pasha.tatashin@soleen.com> 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" Currently, LUO does not prevent the same file from being managed twice across different active sessions. Use a global xarray luo_preserved_files to keep track of file identifiers being preserved by LUO. Update luo_preserve_file() to check and insert the file identifier into this xarray when it is preserved, and erase it in luo_file_unpreserve_files() when it is released. To allow handlers to define what constitutes a "unique" file (e.g., different struct file objects pointing to the same hardware resource), add a get_id() callback to struct liveupdate_file_ops. If not provided, the default identifier is the struct file pointer itself. This ensures that the same file (or resource) cannot be managed by multiple sessions. If another session attempts to preserve an already managed file, it will now fail with -EBUSY. Reviewed-by: Samiullah Khawaja Reviewed-by: Mike Rapoport (Microsoft) Signed-off-by: Pasha Tatashin --- include/linux/liveupdate.h | 2 ++ kernel/liveupdate/luo_file.c | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/include/linux/liveupdate.h b/include/linux/liveupdate.h index dd11fdc76a5f..61325ad26526 100644 --- a/include/linux/liveupdate.h +++ b/include/linux/liveupdate.h @@ -63,6 +63,7 @@ struct liveupdate_file_op_args { * finish, in order to do successful finish calls for all * resources in the session. * @finish: Required. Final cleanup in the new kernel. + * @get_id: Optional. Returns a unique identifier for the file. * @owner: Module reference * * All operations (except can_preserve) receive a pointer to a @@ -78,6 +79,7 @@ struct liveupdate_file_ops { int (*retrieve)(struct liveupdate_file_op_args *args); bool (*can_finish)(struct liveupdate_file_op_args *args); void (*finish)(struct liveupdate_file_op_args *args); + unsigned long (*get_id)(struct file *file); struct module *owner; }; =20 diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c index 5acee4174bf0..b02e2891cdb8 100644 --- a/kernel/liveupdate/luo_file.c +++ b/kernel/liveupdate/luo_file.c @@ -110,10 +110,14 @@ #include #include #include +#include #include "luo_internal.h" =20 static LIST_HEAD(luo_file_handler_list); =20 +/* Keep track of files being preserved by LUO */ +static DEFINE_XARRAY(luo_preserved_files); + /* 2 4K pages, give space for 128 files per file_set */ #define LUO_FILE_PGCNT 2ul #define LUO_FILE_MAX \ @@ -203,6 +207,12 @@ static void luo_free_files_mem(struct luo_file_set *fi= le_set) file_set->files =3D NULL; } =20 +static unsigned long luo_get_id(struct liveupdate_file_handler *fh, + struct file *file) +{ + return fh->ops->get_id ? fh->ops->get_id(file) : (unsigned long)file; +} + static bool luo_token_is_used(struct luo_file_set *file_set, u64 token) { struct luo_file *iter; @@ -248,6 +258,7 @@ static bool luo_token_is_used(struct luo_file_set *file= _set, u64 token) * Context: Can be called from an ioctl handler during normal system opera= tion. * Return: 0 on success. Returns a negative errno on failure: * -EEXIST if the token is already used. + * -EBUSY if the file descriptor is already preserved by another s= ession. * -EBADF if the file descriptor is invalid. * -ENOSPC if the file_set is full. * -ENOENT if no compatible handler is found. @@ -288,10 +299,15 @@ int luo_preserve_file(struct luo_file_set *file_set, = u64 token, int fd) if (err) goto err_free_files_mem; =20 - err =3D luo_flb_file_preserve(fh); + err =3D xa_insert(&luo_preserved_files, luo_get_id(fh, file), + file, GFP_KERNEL); if (err) goto err_free_files_mem; =20 + err =3D luo_flb_file_preserve(fh); + if (err) + goto err_erase_xa; + luo_file =3D kzalloc_obj(*luo_file); if (!luo_file) { err =3D -ENOMEM; @@ -320,6 +336,8 @@ int luo_preserve_file(struct luo_file_set *file_set, u6= 4 token, int fd) kfree(luo_file); err_flb_unpreserve: luo_flb_file_unpreserve(fh); +err_erase_xa: + xa_erase(&luo_preserved_files, luo_get_id(fh, file)); err_free_files_mem: luo_free_files_mem(file_set); err_fput: @@ -363,6 +381,8 @@ void luo_file_unpreserve_files(struct luo_file_set *fil= e_set) luo_file->fh->ops->unpreserve(&args); luo_flb_file_unpreserve(luo_file->fh); =20 + xa_erase(&luo_preserved_files, + luo_get_id(luo_file->fh, luo_file->file)); list_del(&luo_file->list); file_set->count--; =20 @@ -606,6 +626,11 @@ int luo_retrieve_file(struct luo_file_set *file_set, u= 64 token, luo_file->file =3D args.file; /* Get reference so we can keep this file in LUO until finish */ get_file(luo_file->file); + + WARN_ON(xa_insert(&luo_preserved_files, + luo_get_id(luo_file->fh, luo_file->file), + luo_file->file, GFP_KERNEL)); + *filep =3D luo_file->file; luo_file->retrieve_status =3D 1; =20 @@ -701,8 +726,11 @@ int luo_file_finish(struct luo_file_set *file_set) =20 luo_file_finish_one(file_set, luo_file); =20 - if (luo_file->file) + if (luo_file->file) { + xa_erase(&luo_preserved_files, + luo_get_id(luo_file->fh, luo_file->file)); fput(luo_file->file); + } list_del(&luo_file->list); file_set->count--; mutex_destroy(&luo_file->mutex); --=20 2.43.0 From nobody Thu Apr 2 20:22:18 2026 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14F6B40B6D7 for ; Thu, 26 Mar 2026 16:39:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774543190; cv=none; b=uUSxi/bE3K42zlqedXPNAoWdKLrVf+1rTZHT6He2zWPeQWJvIODLHOUl7tOapARFIT4SmgXlccjROE4DK78B9ypVOgekr13r3at4Mg6A1QiBr74hz4mnIqMiL5mcv54NxBz3dNBO+YGyZzmyYGmu2bPtAFWCsdbe3wTeermW7MQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774543190; c=relaxed/simple; bh=sqnbr9cNssI9b+W5NEejwmZoDUUzKMDtWMQnZN/3ZrY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mWFrAK/734Zd4zpJF+we1Uqxy1AixVcCIm/K7wkSNV8Oj4FqxZuRNWkmHRXYagKbtWuFZIVXDePfkJUTKByVH43jZyLyiyCURdh+69knm62Rke6/n5AGGO4i87AssIe53ewE6x7DXxsehlofrU/bs4EC9WvW+ebBbfPHWlSA6qY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=clvy2G5d; arc=none smtp.client-ip=209.85.160.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="clvy2G5d" Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-50b35f3e489so21252471cf.0 for ; Thu, 26 Mar 2026 09:39:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1774543188; x=1775147988; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=8NveMeYJyXR51CooSgOWz6j3nuc+FLl/9rhH+hQCzaw=; b=clvy2G5d/ToR5ee+iTa9XyhBHaPNfY0RGfThv6qbJG1OgUc7HJ/86RShYwW32CTl41 3K+iE8hYN/Q9uJgs3pan6rH8LTNzjGna0+2XOM90cDTaJZtlBYZprySonqJ2zPdk1OqT YoeZVuFcKyufcar5fTYMkkkkB/hVZkvxib9yLeYxWTb9jie1agn8o9PnS2s9NqoDR4bN VLdus6tPxRo3A5nSm+i1gnRSvip2JamV32XUZ2BqdX/JVppEYUq5RQfJQMqtVEh44BE4 Sk5R3Vrn+6vW2WXRZgK5IRYSqqcKXPKV8nZ8Ei5AA8jWta1Jn9pPvcHZXViSL73OmjCd JQMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774543188; x=1775147988; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=8NveMeYJyXR51CooSgOWz6j3nuc+FLl/9rhH+hQCzaw=; b=FZZ8uVl1eFoPvKE9rw+7gNivaZ7DSUnVy4qPTWCnB6b7EnfnDXijt6T1uvyLN/6ZyL Vpl1/TqsR58zEO7E+/c+/Dj0OQdm5b2goPpc9+sAcJENtaWWvZnIim0HEQZbb9Puv0Ju Pc2NmxU1h7GDCY+t6M57esk8MJ5nA4iWYkkSoh245a4hutBDDnvq3A3zPYO5IFVdY2yh HZrZSn45LcK8LIxZfW0W7FBFujjKpWilFaNEfvNk9QYnbquaaec5M3WqO6TbZkJn/Ev8 n2/gzEtdKJyJmwpUoHkXIWmzRWfgFNSuoT+U2qp169WOZ8lvU/ONl3PmUUdY1vzhbeiE UO6w== X-Forwarded-Encrypted: i=1; AJvYcCX7JzmP/mCs2bbRoFSSQ9TmmJH3uzshS+YkCpnXgGKdXGjEBrWqG72pYH+VsE3NXbDhi/sI1tSpRsWJgac=@vger.kernel.org X-Gm-Message-State: AOJu0Yxz3sZcmPfPsDi6oBi0fKK5nPnBRHt17ob4hBmwvDu/Xa0VFr1e idbgQ5YI/UAtYf006JMuKPEBuNCnagHe1Af+N/5cog1RT8u1K3T4WVGLYC8mPePQnlA= X-Gm-Gg: ATEYQzyy1dOP6oaHtPXliuhf9CdyAJkFHShoLeTCQgboy+u1IjxeYOtk0T2Zn92saiD RrS9feIfBAgEAaBAGiAJusDwRHHiL4SbDVFzM/s4AwHVIQxUCpaZfje7nZMhXPu7tfKqnZCMBjj JHfxJ6tv6cf/mcj4F2CcViPqj0fDfczcX1aVCqmY3BNGcJ6XMxolBlJbi+eE9WEu3C3VMmKenFL Ug+qzE7cWJeqm3fROxdXZV73bJFIl+yv5khvNy7CH1Dk8AX8w3YjWgheYYAlhb9gmykx7ZaP23H d8d/ylV5q+B5P+IArR58Wwxv/9Gx4eoHA1Y6ZSumLxsP4qu9/nYPOvVn9H4CcGC2eksy5+xaz1j X7uR4lPq39PMSen0nHytML80RxBfe72AdJJp9bV4LEQcKF15ysLZLzjbiEMG2nn5sADfwwEyQiS /1VBuRREr4C0Tw//LJu4ajuNvLHbCF//ANN8sFLf2veieuEqvLYsVUIBRim9X4vEOa6g== X-Received: by 2002:ac8:58d4:0:b0:509:1ad4:6309 with SMTP id d75a77b69052e-50b9951400emr25921331cf.32.1774543187273; Thu, 26 Mar 2026 09:39:47 -0700 (PDT) Received: from plex.localdomain ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-50b920f77cfsm28238251cf.6.2026.03.26.09.39.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 09:39:46 -0700 (PDT) From: Pasha Tatashin To: linux-kselftest@vger.kernel.org, rppt@kernel.org, shuah@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, pasha.tatashin@soleen.com, dmatlack@google.com, pratyush@kernel.org, skhawaja@google.com Subject: [PATCH v4 2/3] memfd: implement get_id for memfd_luo Date: Thu, 26 Mar 2026 16:39:42 +0000 Message-ID: <20260326163943.574070-3-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260326163943.574070-1-pasha.tatashin@soleen.com> References: <20260326163943.574070-1-pasha.tatashin@soleen.com> 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" Memfds are identified by their underlying inode. Implement get_id for memfd_luo to return the inode pointer. This prevents the same memfd from being managed twice by LUO if the same inode is pointed by multiple file objects. Signed-off-by: Pasha Tatashin --- mm/memfd_luo.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c index b8edb9f981d7..6629ab4d8e30 100644 --- a/mm/memfd_luo.c +++ b/mm/memfd_luo.c @@ -529,6 +529,11 @@ static bool memfd_luo_can_preserve(struct liveupdate_f= ile_handler *handler, return shmem_file(file) && !inode->i_nlink; } =20 +static unsigned long memfd_luo_get_id(struct file *file) +{ + return (unsigned long)file_inode(file); +} + static const struct liveupdate_file_ops memfd_luo_file_ops =3D { .freeze =3D memfd_luo_freeze, .finish =3D memfd_luo_finish, @@ -536,6 +541,7 @@ static const struct liveupdate_file_ops memfd_luo_file_= ops =3D { .preserve =3D memfd_luo_preserve, .unpreserve =3D memfd_luo_unpreserve, .can_preserve =3D memfd_luo_can_preserve, + .get_id =3D memfd_luo_get_id, .owner =3D THIS_MODULE, }; =20 --=20 2.43.0 From nobody Thu Apr 2 20:22:18 2026 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 658AC406281 for ; Thu, 26 Mar 2026 16:39:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774543191; cv=none; b=FBzF6W9HadE4rd9NK3gJDS5Amqs3CiJfS+70NkzjZNyoCyTluxG0NjaBOL7GZBMtKqyCztrLx/wUmfKNMA1q6qLBvUs9rPlIR4xP8HsJONzswhddpLMvzkJzTcJmFKZ2pgllkTPIg/EVnwwEcZlMsV3GZrhRh7XJGnv6dKOgNew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774543191; c=relaxed/simple; bh=GBazXh/uUV+veTugAXj7FLLeItvlURuuxUNZwTmoUrY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dPNfNTmQmXPcjmAHPx5tZWslOo6a8y5czhyXbJ81VoqmOZo8/hLR8p8OZW694X8sHUTim6+fdiazip288Gx0/HLehcNbWo93OcEcVXX+6/crH4+mzNK5H7m+/ghn2RYupfSlHM0qu/9zD/KFAgdeIF+mfoovjYJeOMYEhK9CqLo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b=Ds8KrWBO; arc=none smtp.client-ip=209.85.160.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen.com header.i=@soleen.com header.b="Ds8KrWBO" Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-50b29c4e554so14988881cf.0 for ; Thu, 26 Mar 2026 09:39:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; t=1774543188; x=1775147988; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=PHul+QGmCaYYH+cSj7r6hzl0Za0NZYfxsHk+JlDRO+k=; b=Ds8KrWBOU9GXh5edQu2VDbmKEgosBYsKe79AxCi2LjUaRSKXQi4gn0D/Q3u8AcmN76 tcYB5FOpvfCHdyOXaDzLihUFY0WtyVf3inqKMmbXL694fuOdtDi0XnpSzbBqwJBxs7z4 v1RNieDVLtk5rXOH3MqrAHT/Dtxb/OCrCEOXQEaZK95MF/qolTN/yeRsPv6GX2HG3xtj lv7Ti895wvUkXixdYs+kFpmH+UNHq/cNbTT5i0tTL42LslpsWJ00TCxw1pqbyex9bdp8 Y9e2yDHkEhLM6b/D0Ehi3II5YOU/HBAtACdQiLICheNtKYYb3QeatqibVn3L6FpNmp3X /zUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774543188; x=1775147988; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=PHul+QGmCaYYH+cSj7r6hzl0Za0NZYfxsHk+JlDRO+k=; b=X4ZGd4T1kRgbBojv5z7tN/J9bwTRceASxAjI0UHHw0UuPi4y0HzUWrdhuTF18X4OFQ OuA3qN+0ur5tQQa/lbSEHc+d8kIJI6gocu8iOjCowJjS8KEXADRoswstGSr92ACI8Y77 jT/YY5pdCrF+myNLKeyOHo2V9731XcnOo4r8GZONGlsaHWRjiyc6BUEngzr/tGwILWfF 8PfFFlBbblWmXR8y1bEmRjrzFjnDj1xb2Vs92IvhbgZZJugeKHFFxa94RDpbHMW4ligk Z5jts02QUTZa5p+Nwtnm3bgmX2lUCcne9/QZhACcg6tb4vG+D0ZpxuIMMAVIyxli2Tjz ITJg== X-Forwarded-Encrypted: i=1; AJvYcCU2eJKOTdCNdGb7TzD5p++Sshq828gDyg820NingFykrhY3yq4dZu8/HvD475Up1U+HL1INkJjv0KNEyTY=@vger.kernel.org X-Gm-Message-State: AOJu0YxmmfhEtRCUfxJv7HH4Y30Cqb+GSCYx7b4tywwg4nKBTyvA4Bha bnbjbBOGJbJJcHRKDcuOSDRtgeb9/LHHU/CGCV0Em8Sr52kI7H4SbnBhg7k345tpn3I= X-Gm-Gg: ATEYQzy+ale53sLaszCslDkIrro9nftFjcKBc4kJikD0pmXEeh6az5PXXxkxTkDLHJr WlGYA2y8TaZorlIO9ole4dj7m8tYl14cZAuP5XW7fUEEPFJgIVfSmsjjyrZBEDAkhx1zDgT5HlX lerzcJzOrpeZHYPdA/8Fa+P9sQ5y2FISykDAsp7PVHNrit2q6wp06B1HDjnieA8+iRCSF9IA4vE 0eZ5NkIWZT3a2g8M514n1MmWkyRRLGghiYXkXaWRJu8G//pQQUHBVeZesxKiYH2SJCFqGvb5aHz BEozUYseazbC5bRuVi+57QriWIvwcfv8gNWLlDrFtJ+Wovm37I5CUEWYUYoYbOLllKjxl3TCHue JwsrFONnNx1jL5LkqV9e4X7UpmUGXzzZxuvana+Hm4O1Fu3NlpLRgk5LZoEtyNge6NPfKRl6CTP HjCAuwV7XBOVrtGk6pTrLUp899ELPvwnzKwBF7TVxpF4suS7ziV5aDeqFIRdAu/abZQA== X-Received: by 2002:a05:622a:251a:b0:508:faa5:4512 with SMTP id d75a77b69052e-50b80e5418dmr113877081cf.50.1774543188330; Thu, 26 Mar 2026 09:39:48 -0700 (PDT) Received: from plex.localdomain ([71.181.43.54]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-50b920f77cfsm28238251cf.6.2026.03.26.09.39.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 09:39:47 -0700 (PDT) From: Pasha Tatashin To: linux-kselftest@vger.kernel.org, rppt@kernel.org, shuah@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, pasha.tatashin@soleen.com, dmatlack@google.com, pratyush@kernel.org, skhawaja@google.com Subject: [PATCH v4 3/3] selftests: liveupdate: add test for double preservation Date: Thu, 26 Mar 2026 16:39:43 +0000 Message-ID: <20260326163943.574070-4-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260326163943.574070-1-pasha.tatashin@soleen.com> References: <20260326163943.574070-1-pasha.tatashin@soleen.com> 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" Verify that a file can only be preserved once across all active sessions. Attempting to preserve it a second time, whether in the same or a different session, should fail with EBUSY. Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Samiullah Khawaja Signed-off-by: Pasha Tatashin --- .../testing/selftests/liveupdate/liveupdate.c | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tools/testing/selftests/liveupdate/liveupdate.c b/tools/testin= g/selftests/liveupdate/liveupdate.c index c2878e3d5ef9..37c808fbe1e9 100644 --- a/tools/testing/selftests/liveupdate/liveupdate.c +++ b/tools/testing/selftests/liveupdate/liveupdate.c @@ -345,4 +345,45 @@ TEST_F(liveupdate_device, preserve_unsupported_fd) ASSERT_EQ(close(session_fd), 0); } =20 +/* + * Test Case: Prevent Double Preservation + * + * Verifies that a file (memfd) can only be preserved once across all acti= ve + * sessions. Attempting to preserve it a second time, whether in the same = or + * a different session, should fail with EBUSY. + */ +TEST_F(liveupdate_device, prevent_double_preservation) +{ + int session_fd1, session_fd2, mem_fd; + int ret; + + self->fd1 =3D open(LIVEUPDATE_DEV, O_RDWR); + if (self->fd1 < 0 && errno =3D=3D ENOENT) + SKIP(return, "%s does not exist", LIVEUPDATE_DEV); + ASSERT_GE(self->fd1, 0); + + session_fd1 =3D create_session(self->fd1, "double-preserve-session-1"); + ASSERT_GE(session_fd1, 0); + session_fd2 =3D create_session(self->fd1, "double-preserve-session-2"); + ASSERT_GE(session_fd2, 0); + + mem_fd =3D memfd_create("test-memfd", 0); + ASSERT_GE(mem_fd, 0); + + /* First preservation should succeed */ + ASSERT_EQ(preserve_fd(session_fd1, mem_fd, 0x1111), 0); + + /* Second preservation in a different session should fail with EBUSY */ + ret =3D preserve_fd(session_fd2, mem_fd, 0x2222); + EXPECT_EQ(ret, -EBUSY); + + /* Second preservation in the same session (different token) should fail = with EBUSY */ + ret =3D preserve_fd(session_fd1, mem_fd, 0x3333); + EXPECT_EQ(ret, -EBUSY); + + ASSERT_EQ(close(mem_fd), 0); + ASSERT_EQ(close(session_fd1), 0); + ASSERT_EQ(close(session_fd2), 0); +} + TEST_HARNESS_MAIN --=20 2.43.0