From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.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 E940D392821 for ; Mon, 18 May 2026 19:08:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779131288; cv=none; b=YxLbaCPA3Uxr39eunYCHIEn3DfIQBTyvzp/me0pbK2a9mIx/QXdJoYLcBe9UPBwmG0mg3hZGY1WYKO74tEMb5yZTOgQt3mEHhgbqUyBqsxNXbDVv1U9JU1C+BNkEFktB5hBpszbYMcGMCT9s/Vxzzi7UaVQMHvvpNFHH1KFrQlI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779131288; c=relaxed/simple; bh=E3Kryer03O2/9Oyd1Uw9KKyE+KASGqSz2vSPV4e+764=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CVBs+B5uPf66bx8g6q9EposQ/Cw660Y1G5k+kfdB9D/n56dXC29W3ydTFD/KWEwBcE7J/pB8cM6yjBi7w3mR/rWbuV4W0XmSpA4NOCgjbyBXcP8/Wq/af7jMkPcOSVC6iLScviplymFRDNDCd2+1sywGlZ6jEsOxwvNZqgZmgV4= 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=p6qI5u9s; arc=none smtp.client-ip=209.85.214.171 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="p6qI5u9s" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2b2e8b95bdbso1105ad.0 for ; Mon, 18 May 2026 12:08:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779131286; x=1779736086; 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=9ZU0H6rmWmp4oi8XbArQtxOYDJ2GP70DX/0QfuCGiOE=; b=p6qI5u9sMGK+mVgPNudq7z300tibNdUYHgyHqBnst0NPLl3/b6Wp8K5FYPp8BzysEg gEBVYDwmFjiBtGU/hUNgo/j936wGicRlR2sxXm48+BdP3bd+i+1nHfJWVzgJwffzmfho Q7s1kaK/xLD288kdnTFVniOGByxEZh9KuUZOEj3bsTurhEmuyumNBF62aiMmSxSik2yG LVJyneu3LrKca915ix0jVRY/QqEFOQARaxB5omFiG5JjvLYbazjClJ5+fkFlowprKq2K wmS98Ibiu9BoQ7gloY9qzulK1fzc6+LE+UVLxt4KEJ4zH07/l4PxL4QQOhMb1xc2PB79 T4wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779131286; x=1779736086; 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=9ZU0H6rmWmp4oi8XbArQtxOYDJ2GP70DX/0QfuCGiOE=; b=sIgeAVJbEsNRNpn9PZ8+WTiPNBUWnLfqc/Uchv8NGBOIuVbzeLyDEb+7M4ZvoxtBzO FMCBUqcDqktyZcc0kBZ7amL6H9hmACfcKsuAsXxqHGO34AxB4yVOuBhicMj8hcVIoq3z i+dt/cBFthDAeM3qVwZ9RWU6+i1IpppAMdpq+OXMjYdoZW8h84NIM2NY/7HpCOP1XGu0 0JGI4A/lRAM/3EBfFjwsQNUVJH0UzRw135fupkTA+FDEgtAnPTuh1AE2xfCeLVCw+dY6 mvjoO55EDJNxZdvQNjbluSJzqyZi9SUVV2YB7VxDkYHKYcaZZ6XDVTsbyynRccw7r7lC 2syg== X-Forwarded-Encrypted: i=1; AFNElJ9hnazsLzz1LwsaWQVLhLW358LvSyXZm4kY3umnHOXFyvkYcoiX0f39qCoFfUnXlT84YbomfjDjkkI2zq0=@vger.kernel.org X-Gm-Message-State: AOJu0YzI/Pa7EfT1Ool/DekbWkq/EWqtcGlSHv3uvpkDbK4NGLK7VgKt itN/Rg/tPCpSkUjUWBs/nG74CCZnz48cOpjpLwdLLa5duU6vTncM7SeaTt7DMvPdbteGvTpSW51 kZsqk6YH6 X-Gm-Gg: Acq92OFgeGj1sHweoNLE/NfVAocaOgMhwIrsca6l1Ws5mUM/CFfFJXwH8/Lue6Yjc01 oJEUlPMsatZRwlTFBxE/+/ycTL5+SJfcU/K3S6fsThCPI5jnWW68GLHEllBdRpf+IVsTEFY9Nca 0K2mUnsaRFgN0xP+Oh9RmjvVAJ4qbGY6uKemcLWNRgSSYUt6kUCzCDV786kaGLDKrhZJ4i9Pqdl /DJPDg4REXguvbMEIsSAcBPeOq9qjGV9PLJJND3U8P1NbJciamxl+p13XT5VchF04HdTku+3nq/ ONgF3B1WFgzw8gD+M1y1wVLDPeRMNUxSrFtwFJdAa+5ZZpcigs4LVgRqB8rAfewPm7+Nje96OIR vTJ6Ibm3QSxRs4CrAgWMh+BXx8KwxdCWhJ4DNR2Xbw0UDRcep7FgYBDkah94jWqvAfXz6Qym5QT UMTvjvSH9hGNRs8kfnV1exuX/fljJEC8DdMhKwVBcvrb8XW62S7M3qO23+83j7lZznowvCNw== X-Received: by 2002:a17:903:46ce:b0:2bd:9e75:9e98 with SMTP id d9443c01a7336-2bdb329b484mr3857735ad.9.1779131285670; Mon, 18 May 2026 12:08:05 -0700 (PDT) Received: from google.com (153.46.83.34.bc.googleusercontent.com. [34.83.46.153]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c82bb07b007sm14148605a12.11.2026.05.18.12.08.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 12:08:05 -0700 (PDT) Date: Mon, 18 May 2026 19:08:01 +0000 From: Samiullah Khawaja To: Pranjal Shrivastava Cc: David Woodhouse , Lu Baolu , Joerg Roedel , Will Deacon , Jason Gunthorpe , Pasha Tatashin , Robin Murphy , Kevin Tian , Alex Williamson , Shuah Khan , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Saeed Mahameed , Adithya Jayachandran , Parav Pandit , Leon Romanovsky , William Tu , Pratyush Yadav , David Matlack , Andrew Morton , Chris Li , Vipin Sharma , YiFei Zhu Subject: Re: [PATCH v2 01/16] liveupdate: luo_file: Add internal APIs for file preservation Message-ID: References: <20260427175633.1978233-1-skhawaja@google.com> <20260427175633.1978233-2-skhawaja@google.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: On Mon, May 18, 2026 at 11:40:58AM +0000, Pranjal Shrivastava wrote: >On Mon, Apr 27, 2026 at 05:56:18PM +0000, Samiullah Khawaja wrote: >> From: Pasha Tatashin >> >> The core liveupdate mechanism allows userspace to preserve file >> descriptors. However, kernel subsystems often manage struct file >> objects directly and need to participate in the preservation process >> programmatically without relying solely on userspace interaction. >> >> Signed-off-by: Pasha Tatashin >> Signed-off-by: Samiullah Khawaja > >[..] > >> @@ -924,3 +931,65 @@ void liveupdate_unregister_file_handler(struct liveupdate_file_handler *fh) >> luo_flb_unregister_all(fh); >> list_del(&ACCESS_PRIVATE(fh, list)); >> } >> +EXPORT_SYMBOL_GPL(liveupdate_unregister_file_handler); >> + [snip] >> + >> +/** >> + * liveupdate_get_file_incoming - Retrieves a preserved file for in-kernel use. >> + * @s: The incoming liveupdate session (restored from the previous kernel). >> + * @token: The unique token identifying the file to retrieve. >> + * @filep: On success, this will be populated with a pointer to the retrieved >> + * 'struct file'. >> + * >> + * Provides a kernel-internal API for other subsystems to retrieve their >> + * preserved files after a live update. This function is a simple wrapper >> + * around luo_retrieve_file(), allowing callers to find a file by its token. >> + * >> + * The caller receives a new reference to the file and must call fput() when it >> + * is no longer needed. The file's lifetime is managed by LUO and any userspace >> + * file descriptors. If the caller needs to hold a reference to the file beyond >> + * the immediate scope, it must call get_file() itself. > >Thanks for re-wording this and I'm sorry for being a stickler here, I'm >a bit concerned that the last part here might lead to reference leaks in >downstream drivers. > >Looking at the underlying luo_retrieve_file() implementation [1], it >explicitly calls get_file() before returning the pointer (both on the >initial retrieve and on cached ones). This means the caller inherently >receives a reference that they own & the caller is responsible for >exactly one fput(). > >However, that last part of the comment can be misunderstood as the caller >doesn't hold a lasting reference unless they call get_file() themselves. >This makes the reader assume that LUO is going to automatically reap >that initial reference from them. > >If a driver author assumes LUO is going to reap it, they will follow that >last sentence and call get_file() to stash the pointer safely. They might >end up holding two references (thinking one of them will be reaped), and >could ultimately leak the struct file when they only call fput() once >during teardown. > >Should we just drop that last sentence to make the lifecycle contract >unambiguous? (i.e., The caller gets a newly bumped reference, and they >are responsible for exactly one fput() per call). I think these are all valid points. I will remove the last sentences for clarity. > >> + * >> + * Context: It must be called with session mutex acquired of a restored session. >> + * Return: 0 on success. Returns -ENOENT if no file with the matching token is >> + * found, or any other negative errno on failure. >> + */ >> +int liveupdate_get_file_incoming(struct liveupdate_session *s, u64 token, >> + struct file **filep) >> +{ >> + return luo_retrieve_file(luo_file_set_from_session_locked(s), >> + token, filep); >> +} > >Nit: Shouldn't we export both of these functions via EXPORT_SYMBOL_GPL? >Since, these new APIs are intended for kernel subsystems to participate >programmatically, there could be IOMMU drivers (or others) that can be >compiled as loadable modules. Thus we should export these APIs via >EXPORT_SYMBOL_GPL(). If they aren't exported, any loadable module >attempting to use them will compile successfully (due to the header), but >will fail to load at runtime with an Unknown symbol error. > >IIUC, if a function isn't exported with EXPORT_SYMBOL, it remains hidden >inside vmlinux, (i.e. it isn't in the kernel's global symbol table used >during modprobe). Agreed. Will Update this. I think there are other LUO APIs that are not exported and can be used by modules. Let me check those also. > >Thanks, >Praan > >[1] https://elixir.bootlin.com/linux/v7.0-rc3/source/kernel/liveupdate/luo_file.c#L560 >