From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E8E9FC624D9 for ; Wed, 2 Sep 2026 17:09:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:content-type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6VcPgyv1gE40oA19P7nVU/CSABYm1sXHl0KxbrSx48A=; b=Kl6Urr3qilzWeZ/p82RUhzdeBK nGLP1dvYPbdkuKpqrUUb/l/tgd1z9IHG3NHDJC031kKXsSy+rhoScOoMpOBtV6fzPCOMVJnl9qS3A n466FroeTl/HJjBCwCDcy/k4zthBskXE96iBjAEn4o8EGMy56+23FavgF7ZNAaTWCsfaEIza81ThQ nzxE3OQt2JOFnOyb/yTQOWi7Xgit3LfRtrsGCgWHr24NOKl5GUoQV/5wHfHJsfUnfgit4hKXVyvw/ DHR9r+gk3ZS7va6Ba8dRdI9CYduGTw+W/ioNjG/2RrECzaIBkZDJ+kaUflPAsvnmrEb2F4/v5lKGj aFmRo2Ew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x1oSi-0000000FOg7-3nRl; Wed, 02 Sep 2026 17:09:24 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x1oSf-0000000FOdu-3ZTj for kexec@lists.infradead.org; Wed, 02 Sep 2026 17:09:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788368961; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6VcPgyv1gE40oA19P7nVU/CSABYm1sXHl0KxbrSx48A=; b=hlbzAZw4WVkI9XxADwkyM203hXflaLmDTKW6kUiFf1hEoEPVS+O8/T5437fg3UfXeG/rz7 mc78hxuOQYRqaBpNxJ1MWXOw6vP/zUuWYHDr96DPy3Hxtjcl/kqRgwvj+qH+9/VIFIdcbx 3K6150opBS0F6hfrwVnWVYz9DvMcTiY= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-357-9ohpF6yuO9K3q3jbMtnuDg-1; Wed, 02 Sep 2026 13:09:17 -0400 X-MC-Unique: 9ohpF6yuO9K3q3jbMtnuDg-1 X-Mimecast-MFC-AGG-ID: 9ohpF6yuO9K3q3jbMtnuDg_1788368955 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 09AB8180267F; Wed, 2 Sep 2026 17:09:15 +0000 (UTC) Received: from djeffery-thinkpadp1gen3.rmtusga.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AF3D11955D8D; Wed, 2 Sep 2026 17:09:11 +0000 (UTC) From: David Jeffery To: driver-core@lists.linux.dev, Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-scsi@vger.kernel.org, Tarun Sahu , Stuart Hayes , Laurence Oberman , Bjorn Helgaas , kexec@lists.infradead.org, "Ewan Milne" , "John Meneghini" , "Lombardi, Maurizio" , "Bart Van Assche" , "John Garry" , "Jeremy Allison" , "Martin K . Petersen" , "Pasha Tatashin" , David Jeffery Subject: [PATCH 7/9] PCI: Link a virtual function to its physical function Date: Wed, 2 Sep 2026 13:07:32 -0400 Message-ID: <20260902170734.95504-8-djeffery@redhat.com> In-Reply-To: <20260902170734.95504-1-djeffery@redhat.com> References: <20260902170734.95504-1-djeffery@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-MFC-PROC-ID: Ltwl5bkfgAf7WRdENHP5sXNOjAtNlpFRgniaaefULtg_1788368955 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260902_100921_957492_695D5B18 X-CRM114-Status: GOOD ( 13.12 ) X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" Errors-To: kexec-bounces+kexec=archiver.kernel.org@lists.infradead.org With a PCI virtual function having the same bus for its parent as the physical function it is associated with, there is no explicit dependency between the two in the device tree. With async shutdown, this can result in the PF being shutdown before the VF has an opportunity to shutdown. Link the VF as a consumer of the PF to note its dependency and ensure clean shutdown ordering. Signed-off-by: Tarun Sahu Signed-off-by: David Jeffery Tested-by: Laurence Oberman --- drivers/pci/iov.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 9d408fb8ac25..9b74211c6ab4 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -382,14 +382,20 @@ int pci_iov_add_virtfn(struct pci_dev *dev, int id) } pci_device_add(virtfn, virtfn->bus); + if (!device_link_add(&virtfn->dev, &dev->dev, DL_FLAG_STATELESS)) { + rc = -ENOMEM; + goto failed1; + } + rc = pci_iov_sysfs_link(dev, virtfn, id); if (rc) - goto failed1; + goto unlink; pci_bus_add_device(virtfn); return 0; - +unlink: + device_link_remove(&virtfn->dev, &dev->dev); failed1: pci_stop_and_remove_bus_device(virtfn); pci_dev_put(dev); @@ -421,6 +427,7 @@ void pci_iov_remove_virtfn(struct pci_dev *dev, int id) if (virtfn->dev.kobj.sd) sysfs_remove_link(&virtfn->dev.kobj, "physfn"); + device_link_remove(&virtfn->dev, &dev->dev); pci_stop_and_remove_bus_device(virtfn); virtfn_remove_bus(dev->bus, virtfn->bus); -- 2.55.0