From nobody Fri Sep 01 21:19:14 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RcrWR5S16z4rgHl; Fri, 1 Sep 2023 21:19:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RcrWR0s6yz4jX6; Fri, 1 Sep 2023 21:19:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1693603155; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BXKna/EJrsUsR1cuZPzyUP/qcTNSRjwwQxFoPVZc2nA=; b=hYPu21JPKKFX45yHbEdYlK5W4AMjsNVPy/pW6uoVqEFVoBxkoJISxkndGSHz4TKdG8PHK5 RJNbV1Twk16OZ/eRtc/lsAEVBvQqBXzrmHrxpmDVLONnX6KM30UTKhCh70bUcdjPNL0anr VoOWOYGUYJfIBLOCzKtKoGs16M8h+/KV981KPXH6vj0YOI3JNDWNxnPs5zArmUW00MA0zO CwmtXzNSrxNu9gJqZkZrBXE91+hzPwQsYCwElQNxCFRv6n8/xpkMo6FgROtSNYXRWlu4hZ uGWeS1bxGgZZUEg1Gm+b0wNybMI9BxtxR4kVEsRDkgExPeYKCGqg7ViRqe98dA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1693603155; a=rsa-sha256; cv=none; b=YTq1y2OPIebMfhclGrBcaPCC6QEDdJOKDqptN8KkrBZ9k5wCImBspgYsC2269MJz4kZQkz oEaGcL2W20xywTqGbPRVEjMABf9nUfM0BILcEZVKV8u6eosnx6TmNHLuGZ0BkLzmMAZ4yd 2hXBPqm10oa9Js5p2+b6xXC3vfGGHJuHgTE8sx6UBC9bIb+IJJVgxWF0hX5Y49YJHxlQ7P iaFe2y2DdClOQKcBfbr+fpVn4PxWT4cTvKvNiWFAai1fq92vzV0xGKGc2UjFGtLkDD5PNS 3ctZXF3bGDXccDVmaheEM9h/VEgiQVYNPi/6jmBPnF8nlIiENddZAlxWN+oNnw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1693603155; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BXKna/EJrsUsR1cuZPzyUP/qcTNSRjwwQxFoPVZc2nA=; b=Vzw82aIuJfgYsE+HJL/+9KuiyNVPV8U5p6lKMmPTkoDVxKHsRBurvoIswcuBNov+IyzcFu Lm6SPHoGRia/XM0BJq1/K5/xFdhTBi/LOjoIiKBcYQaGlLUrIwACGnirshAYtxUhcqN2fy NC4wl0xf6uyJk1TYZ1gPN3rPobODXylF8OqhNo4PS8TY3e/TqpmRmCDoLVi2L9WWALrUSn wjnpwGh+9E1KgDtpdkVZoyVl362FMmsnDVhBZXUDCkyds21VXtYei1zAHnBcFN0+rgjOkq e8sUWnQYg6+1drLFYTgT51PVvFy1baVQsEAyRoog6aKgQ9Jkb+A5zt9ZMqv9UA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RcrWQ6jbdz239; Fri, 1 Sep 2023 21:19:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 381LJE3H004092; Fri, 1 Sep 2023 21:19:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 381LJE9i004089; Fri, 1 Sep 2023 21:19:14 GMT (envelope-from git) Date: Fri, 1 Sep 2023 21:19:14 GMT Message-Id: <202309012119.381LJE9i004089@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 7063f94283af - main - pci_iov: Refuse to create VFs which require ARI if ARI is not available List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7063f94283af60818429a0c2d70e80ae4ad5c146 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=7063f94283af60818429a0c2d70e80ae4ad5c146 commit 7063f94283af60818429a0c2d70e80ae4ad5c146 Author: John Baldwin AuthorDate: 2023-09-01 21:18:30 +0000 Commit: John Baldwin CommitDate: 2023-09-01 21:18:38 +0000 pci_iov: Refuse to create VFs which require ARI if ARI is not available If a parent downstream port doesn't support ARI, the code would try to create VFs anyway but then all PCI config space access to those VFs would fail. Tested by: np Sponsored by: Chelsio Communications --- sys/dev/pci/pci_iov.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sys/dev/pci/pci_iov.c b/sys/dev/pci/pci_iov.c index db7210cb729a..ff3ac0e64271 100644 --- a/sys/dev/pci/pci_iov.c +++ b/sys/dev/pci/pci_iov.c @@ -435,7 +435,7 @@ out: * affects all PFs on the device. */ static int -pci_iov_set_ari(device_t bus) +pci_iov_set_ari(device_t bus, bool *ari_enabled) { device_t lowest; device_t *devlist; @@ -443,8 +443,10 @@ pci_iov_set_ari(device_t bus) uint16_t iov_ctl; /* If ARI is disabled on the downstream port there is nothing to do. */ - if (!PCIB_ARI_ENABLED(device_get_parent(bus))) + if (!PCIB_ARI_ENABLED(device_get_parent(bus))) { + *ari_enabled = false; return (0); + } error = device_get_children(bus, &devlist, &devcount); @@ -480,6 +482,7 @@ pci_iov_set_ari(device_t bus) device_printf(lowest, "failed to enable ARI\n"); return (ENXIO); } + *ari_enabled = true; return (0); } @@ -683,6 +686,7 @@ pci_iov_config(struct cdev *cdev, struct pci_iov_arg *arg) uint16_t iov_ctl; uint16_t num_vfs, total_vfs; int iov_inited; + bool ari_enabled; mtx_lock(&Giant); dinfo = cdev->si_drv1; @@ -713,7 +717,7 @@ pci_iov_config(struct cdev *cdev, struct pci_iov_arg *arg) if (error != 0) goto out; - error = pci_iov_set_ari(bus); + error = pci_iov_set_ari(bus, &ari_enabled); if (error != 0) goto out; @@ -736,6 +740,11 @@ pci_iov_config(struct cdev *cdev, struct pci_iov_arg *arg) goto out; } + if (!ari_enabled && PCI_RID2SLOT(last_rid) != 0) { + error = ENOSPC; + goto out; + } + iov_ctl = IOV_READ(dinfo, PCIR_SRIOV_CTL, 2); iov_ctl &= ~(PCIM_SRIOV_VF_EN | PCIM_SRIOV_VF_MSE); IOV_WRITE(dinfo, PCIR_SRIOV_CTL, iov_ctl, 2);