From nobody Thu Sep 07 21:06:56 2023 X-Original-To: dev-commits-src-branches@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 4RhWyS5gmhz4s3Wl; Thu, 7 Sep 2023 21:06:56 +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 4RhWyS5FwVz3K7q; Thu, 7 Sep 2023 21:06:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1694120816; 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=R/+jsklkHxSur3dCG+D/jcW/GiQ/+tjKjSurQGTW/Ic=; b=EcEvqh3pxJUZPFwpaWg4KFMMgI8pXf5mS3tA8fQqPhJgcyFLgqipfXpGVFqXvf/qHYr4wR lovJD7ruiZWHzFun7O8wdcFF3w8z5Br7OPj0pY4BS02JjTSI6t8kmqI6sZQgOVVJXpxbkL m+UgB4HK9ddbdwG4X1suinBrUvaQ1TFGi4aMnt4s/DtrUbAin9coGCAfUuVYvnwMGl6/r6 nzMgodoUFZ5wGJ/EQqYWU+yjoBrLY9yZ7dMWLgbdU4Tkqh6o1/EJQ2WPYEWQ+fYrr7jSoq RDhFwFxzgZImu/PwxLHjrVm09OP31hXulia/g4p6RjVREGqgiGH2FF5roYvhbw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1694120816; a=rsa-sha256; cv=none; b=uUbqO6vMJ0aaQkbklEEoIsIqSE3fKgrTBy5TAM68aP0dHsuU0Fgp7FFirss85rUn69zlH2 6mv3K8QsTRv40s1KQCRuAHEMvcEPMmn308VBxcopa0eQGxrXctwn8LwMDPyeuUQbm/sne6 zUS7W8Nne0hY3VCsyQuml6+a62Pj49bKAdmnKjBP8wjldXZe0xTh7bAipWyLxm3d8To6C4 d4S1oanpoOvau5G4cTcL4XKhJglu8VhD4c15pNSDVaVgAgVgjsl5sE+TBopE1/qitb7GUu +TXZI92WxxVrnXvBvY/1G3PBWIMk1n6G4XkGHdixW+PKjvud5a3wNv8CSky3+Q== 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=1694120816; 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=R/+jsklkHxSur3dCG+D/jcW/GiQ/+tjKjSurQGTW/Ic=; b=cs70nwkGGMrSsKcgtqJVHbe3y7954jBF2udUusTH42H5P8mtdaaNIUdm0rFuboiQBKJ49S aLiqkiZkRAIq0Tj8aOjs4LCVZRFfkPD8pcVcDfkMyjKSq+jxrWpVRqDYH5H5NTYuyqQgtp Aj0c8/HxlWHN+BoH3tmi68EdJGw/7VnNDQLPUPoq/H9yxmxvwZBAcitSS+6H2wMW2SQ+Xz mi15qW28/7tSuxIaULz4tj0tE6zVH++dpjNE9H3QyrFfgceKjzg07+qpnDcvWqfRB2qOFQ Hqo2+MaYf3tDbIc+Ckz84pLD+Pybp6xQDazLEOU+O0CBlL3luoGJ8IwKBLiehA== 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 4RhWyS4CRhzqb; Thu, 7 Sep 2023 21:06:56 +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 387L6umn031282; Thu, 7 Sep 2023 21:06:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 387L6um6031279; Thu, 7 Sep 2023 21:06:56 GMT (envelope-from git) Date: Thu, 7 Sep 2023 21:06:56 GMT Message-Id: <202309072106.387L6um6031279@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: dde83fc4d2e6 - stable/14 - pci_iov: Refuse to create VFs which require ARI if ARI is not available List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/14 X-Git-Reftype: branch X-Git-Commit: dde83fc4d2e6e8a3009bdfb7d14dcc8ef802b22f Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=dde83fc4d2e6e8a3009bdfb7d14dcc8ef802b22f commit dde83fc4d2e6e8a3009bdfb7d14dcc8ef802b22f Author: John Baldwin AuthorDate: 2023-09-01 21:18:30 +0000 Commit: John Baldwin CommitDate: 2023-09-07 21:06:33 +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 Approved by: re (kib) Sponsored by: Chelsio Communications (cherry picked from commit 7063f94283af60818429a0c2d70e80ae4ad5c146) --- 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);