From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 6992D1E5B88 for ; Mon, 23 Mar 2026 20:43:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774298629; cv=none; b=THdo0MD4ZFWZlB0NgWF69Prr7FHyySHAEGl0p0gx15CJ8FJtTSebQzLn3xTVMWVC3M0MEwwHHqxJEWVUnG2Srf7B4y5atQC1HVU2ipPB2/Zw1kfMvbdTXhPG9lqUqCssT+H0Y+Uy3yKxRNJUtcmVjMCEdqEBJtsxCOO7EHHhAMQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774298629; c=relaxed/simple; bh=yAD2ucoLlY3NeatOfUyKvy6VOnV5067pVR+1CqISHzI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MH++8BiAh2w8mMtsBl2Dnb+Krnh0JaMAnyGrqgG4rOOjzOMRqBq5oIJgMDzQWY8C63m3QNTKP4WswhvKXU/9hL2oDGZAkMV7gft1JTH5abNHzBnI6YwBcmghKhwDVMofsh3vNndSZ9F14/xQbtnNS0MzQOcmOoOTbqzLE2IDa4Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=FcWaCfRA; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FcWaCfRA" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2b052562254so28045ad.0 for ; Mon, 23 Mar 2026 13:43:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774298628; x=1774903428; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=jv+paj/zuCW/4wO6DwQaFbEbko5bvaSd+BgnRg2Mnpk=; b=FcWaCfRABhevnlEeiblIA/nvVZdWwSSULv11Hw8ZNr7Kang8XzjCwMDrMRxOJ5xvQ3 v+URfnLqpRyt0YSuZoMgpLzCQdHl0O8UTW4YkyeKy5C5UIVQgkQq4YlhIQgGBVCiufIW k8qfishvIze3Ct/89grLCxyvBPi2Coc+qN34eXJJ23ZT/uKk7UlwzlJ3v2fZw3UFZkUg 5Drp1i8VuyHfNwwJTHI7ZrQoRtWhePoiHdBOCz1Im1gIZWDAwOX9wjJA0RlJ+iPtH6kp XWnPlYr/TuaVBfhOhOojgK9uU1TGc4q4Nl9WXjQogW2LFvf3JxdaAHSsePYhb3oTUWzv UUzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774298628; x=1774903428; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jv+paj/zuCW/4wO6DwQaFbEbko5bvaSd+BgnRg2Mnpk=; b=cxzSPnpW0VV00La7GYHP3x1p0nj8AlVXH9bRwBN1ICHqImVy6wFLhdnG2/ZdxySbqn gDs4rZ2NQpzppBth+lgx9NyarozBPZsFmZCbmLf25LiwkYvAWA+Z08nRbA9r/hkwsZ4+ y3tcMGJmsyQs0a8kUb1TWlmkm+RsQhr1URfGFN8tB1hihwVCle5bRzVMyxIxWbr7Kg0i loleeodGTrQQiiQReA6+YKHRyvw/AAlHZbdTyKKkM1rmAjucPvKP7rCej6nJECNm51Wz Ofl51yyhwvFqHE3TD03y80ILp0Hm0nNyApNtBgQWiuF/6at+DqAKt+AT08BFBHjod0IS Jr/g== X-Forwarded-Encrypted: i=1; AJvYcCWbFk3irFkwl9p4ec447P1YeCPwAajN6YD1OsglYdsYe5fqjpVQTdzf9A3mRNJNs356gCB5dcL6rjRIPvc=@vger.kernel.org X-Gm-Message-State: AOJu0YxPlk0S1d55LWUQMnDf3oFiKKhLpQgfq1Jp1GSEGUnRFx0hbGAr wF0bWtb5sbuokcPmjvxkj/ilGSyeU2lLwvEnyrB6j6Z+Vgn3x9k0wd938d5kM4D67Q== X-Gm-Gg: ATEYQzyo/0f86v3gk8vTX+RIJaz9OjGduVv1Qfw8XkRVwCAOKvDZ5p4udWD8yDA+xqz a+TJp/qq2HZIIGIZOzOOjj3TmssjraHt1mIfGYFht4PIlCKlOv+HA8d/30pDNH4yGaXF8hiA3lz mRtlRD8EDpGD17Ht0Ncikzy09HPxCYVrKuvobqetxIGVTdb7+1dLK7owe6VPJK5wzqwvUyVWhBy +ESPgTJMxq87jlpuvciTPmKetfKkr5C+KxyWY6SrfLuGeNszBlFH4R+IyV3WAfX7Whi2nNWEU8d U2yNdxJaYzMkQIGwzf/wBm+CPa+uC6JMJ4w9MOuB5K4F1iBGTHGNIsQxxuO21eq17CfR1UI4KPy BOZ9WFd9udDi2Hmrxnq+Ka5cEqAtRTQ5lvtD6RPjKwclI5eueR7Y/l0z8y4kHMybgAHzLLQQvSr fLIol6kq4J3enlHlhMM1ZLV352d9knjBwWgsRMdJaf0o6PbXeuXNybv46LmQpnLg== X-Received: by 2002:a17:903:22d1:b0:2ae:c566:bd99 with SMTP id d9443c01a7336-2b0a54f45e4mr765685ad.22.1774298627093; Mon, 23 Mar 2026 13:43:47 -0700 (PDT) Received: from google.com (168.136.83.34.bc.googleusercontent.com. [34.83.136.168]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82b04108a1dsm10366461b3a.54.2026.03.23.13.43.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 13:43:46 -0700 (PDT) Date: Mon, 23 Mar 2026 20:43:42 +0000 From: Samiullah Khawaja To: Pasha Tatashin Cc: linux-kselftest@vger.kernel.org, rppt@kernel.org, shuah@kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, dmatlack@google.com, pratyush@kernel.org Subject: Re: [PATCH v2 1/2] liveupdate: prevent double management of files Message-ID: References: <20260323203145.148057-1-pasha.tatashin@soleen.com> <20260323203145.148057-2-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-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20260323203145.148057-2-pasha.tatashin@soleen.com> On Mon, Mar 23, 2026 at 08:31:44PM +0000, Pasha Tatashin wrote: >Currently, LUO does not prevent the same file from being managed twice >across different active sessions. > >Use a global xarray `luo_preserved_files_xa` to keep track of file >pointers being preserved by LUO. Update luo_preserve_file() to check and >insert the file pointer into this xarray when it is preserved, and >erase it in luo_file_unpreserve_files() when it is released. > >This ensures that the same file (struct file) cannot be managed by >multiple sessions. If another session attempts to preserve an already >managed file, it will now fail with -EBUSY. > >Signed-off-by: Pasha Tatashin >--- > kernel/liveupdate/luo_file.c | 17 +++++++++++++++-- > 1 file changed, 15 insertions(+), 2 deletions(-) > >diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c >index a38ea4975824..5f48c3c8c561 100644 >--- a/kernel/liveupdate/luo_file.c >+++ b/kernel/liveupdate/luo_file.c >@@ -110,11 +110,15 @@ > #include > #include > #include >+#include > #include "luo_internal.h" > > static DECLARE_RWSEM(luo_file_handler_lock); > static LIST_HEAD(luo_file_handler_list); > >+/* Keep track of files being preserved by LUO */ >+static DEFINE_XARRAY(luo_preserved_files_xa); >+ > /* 2 4K pages, give space for 128 files per file_set */ > #define LUO_FILE_PGCNT 2ul > #define LUO_FILE_MAX \ >@@ -249,6 +253,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 operation. > * 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 session. > * -EBADF if the file descriptor is invalid. > * -ENOSPC if the file_set is full. > * -ENOENT if no compatible handler is found. >@@ -277,6 +282,11 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd) > if (err) > goto err_fput; > >+ err = xa_insert(&luo_preserved_files_xa, (unsigned long)file, >+ file, GFP_KERNEL); >+ if (err) >+ goto err_free_files_mem; >+ > err = -ENOENT; > scoped_guard(rwsem_read, &luo_file_handler_lock) { > list_private_for_each_entry(fh, &luo_file_handler_list, list) { >@@ -289,11 +299,11 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd) > > /* err is still -ENOENT if no handler was found */ > if (err) >- goto err_free_files_mem; >+ goto err_erase_xa; > > err = luo_flb_file_preserve(fh); > if (err) >- goto err_free_files_mem; >+ goto err_erase_xa; > > luo_file = kzalloc_obj(*luo_file); > if (!luo_file) { >@@ -323,6 +333,8 @@ int luo_preserve_file(struct luo_file_set *file_set, u64 token, int fd) > kfree(luo_file); > err_flb_unpreserve: > luo_flb_file_unpreserve(fh); >+err_erase_xa: >+ xa_erase(&luo_preserved_files_xa, (unsigned long)file); > err_free_files_mem: > luo_free_files_mem(file_set); > err_fput: >@@ -366,6 +378,7 @@ void luo_file_unpreserve_files(struct luo_file_set *file_set) > luo_file->fh->ops->unpreserve(&args); > luo_flb_file_unpreserve(luo_file->fh); > >+ xa_erase(&luo_preserved_files_xa, (unsigned long)luo_file->file); > list_del(&luo_file->list); > file_set->count--; > >-- >2.43.0 > Reviewed-by: Samiullah Khawaja