From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A408F4ADDBF for ; Wed, 2 Sep 2026 17:09:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788368961; cv=none; b=Nn5dl0yRJzybNRyeBT60lNnQPbgTFHUpFUfyiYO+DTzplXSoD+au9Dc9czH5H/iEumlpRtdWXuTlnhH0k7KkCwHUkWjIqnoMFbOtimt92+71UZncXE5UlQKAgq6tQKPByBU7Zy41o/jIRTd849wdRZ7SfZQR5hd4cyLOZBopd3I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788368961; c=relaxed/simple; bh=+TFumKg4vUw97Pul2ExjPcC44bsRVHJ+Tf9Dy7/Z9m8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dQcJ/DBOJYBViXI5ZujpqsSPpkrqzXgIoTxYITpGq6nT8US2TPsCZ9gaYXq+7PlZUJjo3JdsAJH5/2MiYYdjxLgz9R3E91kRD9xiFsUjInFRlbtIWnU0yZIl5CA2B9o3KGmWcp8zzFApvrBqrYvxismXh2N/bc9DORK4BDsKx2k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=D0nvOKeH; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="D0nvOKeH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788368958; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6VcPgyv1gE40oA19P7nVU/CSABYm1sXHl0KxbrSx48A=; b=D0nvOKeH4Lrv5R/Swjgzs8bYHQFy79IP9X/8D6IpVp5mfinBzhI11nIN3VndtrQ4sKOEZX tmFU/nfGDpEC82o2/NKB+UijCCsyWyiWpnl8piLoOWaC4wFe8dEJ6MsP7FuYp6PtjLqnFd 7gOoYycCGQUUumutHsH8ut2QlcXD53g= 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> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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