From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 BCF5D43E068 for ; Tue, 21 Jul 2026 23:02:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784674979; cv=none; b=OAMWyA7HFISf+2lBGNd9uGx3aCKLrCceX1DUjqMyM5yfnXQgpweROtQZxy5n7mNF1qiYrlE4RH1nPkTPppc0u6SbBZ+J1X6HZr3nuH7SjljHMShQ0JUMXmWdCULyEyNUf4GCcDW203z8TLolSUSe6EUKyxXNR68Y575YScYkA48= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784674979; c=relaxed/simple; bh=RcvIeY5uIWgnuFkqgc6CgFGm4Q9bbYpIoUkmhII+nNo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=siBvlugBd4JpEeGaazt5FyYX0EnH0DkjtRY3FRCmkXcwgFsuq65Ii0r0/JwyH9Cj7gskp9Gp6cKkHJTURAxJwPmYMZdLdMjhBkkyEG7lLsbTRX2yQQPCdG0SXu1lTni72lSy8uzOvIq/Xm6oVReRVhRPEyZm7Fe1+0NbGt66cxw= 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=iG8yIN+j; arc=none smtp.client-ip=209.85.214.172 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="iG8yIN+j" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2ccdf36f63dso604525ad.0 for ; Tue, 21 Jul 2026 16:02:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784674977; x=1785279777; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=kK8bQTGCWBVYNgO28KRycMBgomSj7cEEqhXHP2aOvCg=; b=iG8yIN+jsG+yh9SKcvizikh7K8VKc/SRmkvzqHHe4mSfHNwlC/DiY/znrvcnPUA8sg hj8zs9mufmgWJYxwvSjC/dyzHL9OWI6vXeN0COD445/JhIeqiIalpBWqOEGy/06qviT1 sorGTqnt3wCCfsLWOl9PBvxHeMXxuNTE/AeebdtJn/WMYBcMmw2Tc8ViU0lgSqnJqVVf 7d6QZdd5R0GAyatjDflgl4lfDhqXeqbN8+raPS7Hp99RwD9IdSeE3odeInVCyN2uMUWH 5RhVDQwJzt8ts2+gcClFoo5KFsQhVa0VjhyGOkti83IhNCQ3XkoU8cseg2x0QfWDFXWG c0uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784674977; x=1785279777; h=in-reply-to:content-transfer-encoding:content-disposition :content-type: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:content-type; bh=kK8bQTGCWBVYNgO28KRycMBgomSj7cEEqhXHP2aOvCg=; b=sy2v/x0mu8OnGOGubgRF4F1qKN9SZEPZiPfAImkdo1FNZE6+p+wWhsXdRyjkX7qhCZ oVeSsP+qWR4bDEeRLQvKvGpvsiRIpPx3Yh94VZYxarz/PbWLZUKMFBVXbLMpLNDhAOjh 6mEHJeA56CwVBMKojJKPIYskcgYqCxHP+fMNXn0OiHUJr/2Niv1I3+w+3ugGApPNXm9q v2QiZhOKZcMFxXa9K3yhTqnE2M/Cdqf00UMkGrHP8HXZwExcFLfBorLH80ofe2Qa6mTe NDi4FP0D2+J1NZwHHYzWuxXyquthofYAI4uQx5u08GaZ6Q6OeWY9f8iyy1hCMocgo2DA zjJg== X-Forwarded-Encrypted: i=1; AHgh+Rpc7qb3njmZLU7viPYwZRnVKxEiB4X0Aoc7wVqlzCmI7OTUmkhGuP8PVPFjwBpZcXKk22na1OuGU5RIB8k=@vger.kernel.org X-Gm-Message-State: AOJu0YxG8Taazf0Lz9KhA14XFWwOjiKN0RzHQEQJQlujMqOt70BaYJTd zUNZ6T1kjIBeomesaca6OD9902fH6kOLgqTy839UQdPb94IJbPyUobhr7Tjt10/ipg== X-Gm-Gg: AR+sD109GB/FMbRC6zc7Vrlw0osVXRchAMtfWAepefUFo6oOVbnE/d87BX0rzUOTqga 3OCwTCi0h765fnAyPyCbIpDH4dnO9p3d7epZ6dWv9Nt6y3doQdX73FxguYD9rjkKU9dEm6o8gZG 5p4igybnqakLn+8oD7NLRAAtxOzfEfVZefGtPDLlNCcTfcmSnNQuFkV2sQxx3IOESmNRbjUuhxR 49RnRiMrIsa8/CpJ5nsUnb26khEBA5OrYeLoBEub7+FVyfUYMK8qpCPlnoBED7K3IB4B9vIq4kB pp+z6oU8+gvz3IUkYjfUt37Wojni1Qj7BbQq8BktRJY1/lO+mpFWjoRpypLggYmDved5CX+65hy zB6gh8wCv67K58uZE+6lr80egNItx1LYiLupAFF/GHQa4CGPDovlmQwy7ls3ORvYtPgpfbj9MnJ yDH/AjRAUv27PMOC7K9zAg3LGK1U/zloWvvVJOA1ShFavamN7w/lCOTH6HfF+Xzo5fnqZKPbDI X-Received: by 2002:a17:903:2409:b0:2c7:9e6a:1a8d with SMTP id d9443c01a7336-2cf8f3c3e69mr1002465ad.12.1784674976345; Tue, 21 Jul 2026 16:02:56 -0700 (PDT) Received: from google.com (168.136.83.34.bc.googleusercontent.com. [34.83.136.168]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cbb8f18bb8dsm207669a12.19.2026.07.21.16.02.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2026 16:02:55 -0700 (PDT) Date: Tue, 21 Jul 2026 23:02:52 +0000 From: Samiullah Khawaja To: David Matlack Cc: Pasha Tatashin , kexec@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-pci@vger.kernel.org, Adithya Jayachandran , Alexander Graf , Alex Williamson , Bjorn Helgaas , Chris Li , David Rientjes , Jacob Pan , Jason Gunthorpe , Jonathan Corbet , Josh Hilke , Leon Romanovsky , Lukas Wunner , Mike Rapoport , Parav Pandit , Pranjal Shrivastava , Pratyush Yadav , Saeed Mahameed , Shuah Khan , Vipin Sharma , William Tu , Yi Liu Subject: Re: [PATCH v7 03/12] PCI: liveupdate: Track incoming preserved PCI devices Message-ID: References: <20260710212616.1351130-1-dmatlack@google.com> <20260710212616.1351130-4-dmatlack@google.com> <178432481253.189683.3297727348836286619.b4-review@b4> 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=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Mon, Jul 20, 2026 at 02:54:51PM -0700, David Matlack wrote: >On Fri, Jul 17, 2026 at 2:47 PM Pasha Tatashin > wrote: >> >> On Fri, 10 Jul 2026 21:26:06 +0000, David Matlack wrote: >> > diff --git a/drivers/pci/liveupdate.c b/drivers/pci/liveupdate.c >> > index 03075ce06ac9..df6a02240aa4 100644 >> > --- a/drivers/pci/liveupdate.c >> > +++ b/drivers/pci/liveupdate.c >> > @@ -298,6 +377,87 @@ void pci_liveupdate_unpreserve(struct pci_dev *dev) >> > [ ... skip 76 lines ... ] >> > + /* >> > + * Hold the ref on the incoming FLB until pci_liveupdate_finish() so >> > + * that dev->liveupdate.incoming cannot get freed while the PCI core >> > + * has a pointer to it. It's better to leak the incoming FLB than do a >> > + * use-after-free if driver does not call pci_liveupdate_finish(). >> > + */ >> >> I am confused by this. Each preserved PCI device must have an associated >> FD preserved with it via LUO. I.e., vfiofd would need to be preserved. If >> the vfiofd was not reclaimed, and finish is not possible, that vfiofd >> would still be owned by LUO, and therefore PCI FLB refcount would stay >> positive. >> >> However, if finish is possible, and this is the last vfiofd that is >> finished, FLB will be freed as soon as the reference count reaches zero, >> which I would think is the expected behavior. >> >> What is the point of holding a reference here, instead of only for the >> duration of FLB access, i.e. to make sure we are accessing a valid data? > >The duration of the access is from here until pci_liveupdate_finish() >because that it when the pointer (dev->liveupdate.incoming) is >cleared. So that is why the PCI core holds the reference from here >until pci_liveupdate_finish(). I think LUO gives you guarantee that this pointer remains valid until the FLB finish(), because all the vfiofd that were preserved have not finished. And when all vfiofd have finished, LUO lets you know that the pointer is becoming invalid so you can unset these in the finish() callback from LUO? If I understand this correctly, I think by keeping long references until finish you are replicating the vfiofd bound lifecycle that LUO already gives you. > >We could avoid this by deleteing dev->liveupdate.incoming and, >instead, fetching the incoming FLB and doing the xarray lookup every >atime the PCI core needs to access the device's incoming ser struct, >but that would be inefficient. Sami