From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 21BEB310635 for ; Wed, 25 Feb 2026 22:29:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772058593; cv=none; b=G+aV6OzzrzsgjdArlTqkQx+qAkWW7fybwuZYZXTO6VZsHd8DBJh5x65CKhZ3ddAzMU/tsi9j02X70O6SFAB+/SopE3l2yiz/lkVtm0+PHdrMPcwf4yFc/jbM+ZFw72/kekx0xRivHr4gQTpvATEPwgSqH33ejkF5jLVul2aDxDg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772058593; c=relaxed/simple; bh=GQ5r1G3VoaIJD/4mlI2bH7JYCa7TXODdwhiG6pJZSvY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=njAwXd1Nbn0NKK0imzpJHwTjD9AfHVVyPcY71ylKmL/tsNZBKyq21I2slfRlfmXC9Bzl0Hmwo+1WekDYBsP2sp7TM8InT5v2wFFfTMDEg8m9sNg03HQtPpfUpefVUOMXLDJYNyaUyC/niYKOjWcbU8isEATCP3YONa0qOe8yGpo= 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=cPHKs0df; arc=none smtp.client-ip=209.85.214.182 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="cPHKs0df" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2a964077671so29575ad.0 for ; Wed, 25 Feb 2026 14:29:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772058591; x=1772663391; 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=EvlpF/Rbdy5yVGOyUM/AWdTkLEwWYWZDygf5cNk3LN8=; b=cPHKs0dfuLBGgP9RWwQzmk7U66+8Eq/gOPwRH/k1Xb0Y4nkwfPCZ24XFofGoEDIBqs Q0G7eW5zOXDzRBm4wn7YSnutAdpv53y6VrRE2RDcQTJT8FtApKQEN20OZ6nRtFAP8jWX RfysxOfv8MuykU81yo1oEOUIy6paNULcscWeYr9zvdjR8S9dBEiTWZrx8PVHJ/YT6DPD DoaY9s4zuj0QNt2tsnLipkHAQCcDJBhnW6uTt17O2AkaR+v5LiUgK5dV984uZOPeLW6i giWsPH1lm9RSap7rmBg/41ix4hX3tvohbZXhlcElEfSSNnOfSaz+oBqznDl7za2o/FD2 Ag9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772058591; x=1772663391; 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=EvlpF/Rbdy5yVGOyUM/AWdTkLEwWYWZDygf5cNk3LN8=; b=SMkNXsmDQN4my+F8l8fNGRbqoUCLnyX2ZyfyTjTJ5vF4kzsgZpHjgreqOTLXkdN/l6 uwfY3ttbP/O4hqMiN08lmxUook2zXZow3gmygujd9yFBocB2G6sKrsDxvGGDqpywtFpY 3+h7Tp5VtfhPjSS7CEqmS8kozlQICs04WXKDUv9gMrQBNPcOpOa8WfBKTll2Ki8efWyw qLajuvK4vbzKXRc/Fmi57H9sZyNB3nhMtXqmsgtzSJhnIXPRs1XLr+UWuhZTj4/BwtNf BgH5q0MB0Dc2apqikN2NjZ8rZehG/bMYSxZZvKfxSRWqEeoprY2hVqU/gH6CYUr+S4JZ sdCw== X-Forwarded-Encrypted: i=1; AJvYcCVJjrzd2OLLgWR1fV0kKV7kZb0IX2+01yOjpQBerK/QZ0Vu2rOSz28V074Nm99CMp1wues2f+njXyDoads=@vger.kernel.org X-Gm-Message-State: AOJu0YwlVz356hLRl9YsWQN8zeTqTZNoSrKRSRd94z/9DkMvQ/UUQpOz n2erazzRGwNb2mBGCjWamNH8JAN4dCp1jIN+4YhgVVzIjfU6eE0AZoAdIp3lufz5GQ== X-Gm-Gg: ATEYQzx3G3gxbmvw9nYTZtBgHj+HMr43iMyzd3gk+avH2sXEgWAfhEyGQpn3VWAZX3j vfLM+vL8HuznB0bC1t7ivmhiImaQC464QYOU8u/6DxTXqToBlwgK8CMhwUDh+dfAgIbfcfQSjjz EQq/VQ/YsxyVyGyy72fpwEly/TouxDhGQ+QbDtncWUwvrkCk2PFRmpeRSlbKQRuVx4Pmi7w8FVa o1dwcYReOaD5OcmK1X5EbdJIcwln0Uu75jJkmZcmR3YCGXMPcGPrOPrYCJTWwIeAYBgqIWETiP5 mXXtdJDVOvpwyjzNmrEGSHckvHPdyABIvWrBfWtZV8FsFW9RB4tLnd4ajO6uDDyRasOcp+hOXnM 8BraXtj/tHrGkq5doLxqKsvWHK8dTXw4iJvtv4aWYleYd3CehKkDh42Bg+Nidr/MI6Pc4BeaH3a uO/vDWH4E2JEWV4NYquGQ2UEoam3HJ0Ft8AxrExRA8DnrpHn/1bPdGpNb4ldVQGvDWg2CnMJg= X-Received: by 2002:a17:903:15ce:b0:2a3:cd98:f07 with SMTP id d9443c01a7336-2adfefd95b6mr300155ad.3.1772058591084; Wed, 25 Feb 2026 14:29:51 -0800 (PST) Received: from google.com (222.245.187.35.bc.googleusercontent.com. [35.187.245.222]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2adfb5b2309sm2774685ad.19.2026.02.25.14.29.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Feb 2026 14:29:50 -0800 (PST) Date: Wed, 25 Feb 2026 22:29:41 +0000 From: Pranjal Shrivastava To: Alex Williamson Cc: David Matlack , Adithya Jayachandran , Alexander Graf , Alex Mastro , Alistair Popple , Andrew Morton , Ankit Agrawal , Bjorn Helgaas , Chris Li , David Rientjes , Jacob Pan , Jason Gunthorpe , Jason Gunthorpe , Jonathan Corbet , Josh Hilke , Kevin Tian , kexec@lists.infradead.org, kvm@vger.kernel.org, Leon Romanovsky , Leon Romanovsky , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org, Lukas Wunner , =?utf-8?Q?Micha=C5=82?= Winiarski , Mike Rapoport , Parav Pandit , Pasha Tatashin , Pratyush Yadav , Raghavendra Rao Ananta , Rodrigo Vivi , Saeed Mahameed , Samiullah Khawaja , Shuah Khan , Thomas =?iso-8859-1?Q?Hellstr=F6m?= , Tomita Moeko , Vipin Sharma , Vivek Kasireddy , William Tu , Yi Liu , Zhu Yanjun Subject: Re: [PATCH v2 04/22] vfio/pci: Register a file handler with Live Update Orchestrator Message-ID: References: <20260129212510.967611-1-dmatlack@google.com> <20260129212510.967611-5-dmatlack@google.com> <20260225143328.35be89f6@shazbot.org> 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 Content-Disposition: inline In-Reply-To: On Wed, Feb 25, 2026 at 10:06:18PM +0000, Pranjal Shrivastava wrote: > On Wed, Feb 25, 2026 at 02:33:28PM -0700, Alex Williamson wrote: > > On Thu, 29 Jan 2026 21:24:51 +0000 > > David Matlack wrote: > > > diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c > > > index 0c771064c0b8..19e88322af2c 100644 > > > --- a/drivers/vfio/pci/vfio_pci.c > > > +++ b/drivers/vfio/pci/vfio_pci.c > > > @@ -258,6 +258,10 @@ static int __init vfio_pci_init(void) > > > int ret; > > > bool is_disable_vga = true; > > > > > > + ret = vfio_pci_liveupdate_init(); > > > + if (ret) > > > + return ret; > > > + > > > #ifdef CONFIG_VFIO_PCI_VGA > > > is_disable_vga = disable_vga; > > > #endif > > > @@ -266,8 +270,10 @@ static int __init vfio_pci_init(void) > > > > > > /* Register and scan for devices */ > > > ret = pci_register_driver(&vfio_pci_driver); > > > - if (ret) > > > + if (ret) { > > > + vfio_pci_liveupdate_cleanup(); > > > return ret; > > > + } > > > > > > vfio_pci_fill_ids(); > > > > > > @@ -281,6 +287,7 @@ module_init(vfio_pci_init); > > > static void __exit vfio_pci_cleanup(void) > > > { > > > pci_unregister_driver(&vfio_pci_driver); > > > + vfio_pci_liveupdate_cleanup(); > > > } > > > module_exit(vfio_pci_cleanup); > > > > > > diff --git a/drivers/vfio/pci/vfio_pci_liveupdate.c b/drivers/vfio/pci/vfio_pci_liveupdate.c > > > new file mode 100644 > > > index 000000000000..b84e63c0357b > > > --- /dev/null > > > +++ b/drivers/vfio/pci/vfio_pci_liveupdate.c > > > @@ -0,0 +1,69 @@ > > ... > > > +static const struct liveupdate_file_ops vfio_pci_liveupdate_file_ops = { > > > + .can_preserve = vfio_pci_liveupdate_can_preserve, > > > + .preserve = vfio_pci_liveupdate_preserve, > > > + .unpreserve = vfio_pci_liveupdate_unpreserve, > > > + .retrieve = vfio_pci_liveupdate_retrieve, > > > + .finish = vfio_pci_liveupdate_finish, > > > + .owner = THIS_MODULE, > > > +}; > > > + > > > +static struct liveupdate_file_handler vfio_pci_liveupdate_fh = { > > > + .ops = &vfio_pci_liveupdate_file_ops, > > > + .compatible = VFIO_PCI_LUO_FH_COMPATIBLE, > > > +}; > > > + > > > +int __init vfio_pci_liveupdate_init(void) > > > +{ > > > + if (!liveupdate_enabled()) > > > + return 0; > > > + > > > + return liveupdate_register_file_handler(&vfio_pci_liveupdate_fh); > > > +} > > > > liveupdate_register_file_handler() "pins" vfio-pci with a > > try_module_get(). Since this is done in our module_init function and > > unregister occurs in our module_exit function, rather than relative > > to any actual device binding or usage, this means vfio-pci CANNOT be > > unloaded. That seems bad. Thanks, > > Hmm... IIUC the concern here is about liveupdate policy if the user > wants to unload a module which was previously marked for preservation? > > AFAICT, In such a case, the user is expected to close the LUO session FD, > which "unpreserves" the FD. Finally, when rmmod is executed, the __exit > (vfio_pci_cleanup) calls vfio_pci_liveupdate_cleanup() which ends up > calling liveupdate_unregister_file_handler(), thereby dropping the ref > held by the liveupdate orchestrator which allows the module to be > unloaded. > Ohh wait, You're right, Alex. I just realized the __exit won't even be reached because of the internal pin. The current implementation creates a catch-22 where the module pins itself during init and can't reach the unregister call in exit. I believe we should drop the ref when the user closes the session FD? Additionally, should we move try_module_get out of the global liveupdate_register_file_handler() and instead take the ref only when a file is actually marked for preservation? Thanks, Praan > I think we should document this policy somewhere or have a dev_warn to > scream at the users when they try unloading the module without closing > the session FD. > > Thanks, > Praan > > > > > Alex > > > > > + > > > +void vfio_pci_liveupdate_cleanup(void) > > > +{ > > > + if (!liveupdate_enabled()) > > > + return; > > > + > > > + liveupdate_unregister_file_handler(&vfio_pci_liveupdate_fh); > > > +}