From: Akihiko Odaki <akihiko.odaki@daynix.com>
To: "Michael S. Tsirkin" <mst@redhat.com>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Alex Williamson" <alex.williamson@redhat.com>,
"Cédric Le Goater" <clg@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Jason Wang" <jasowang@redhat.com>,
"Sriram Yagnaraman" <sriram.yagnaraman@ericsson.com>,
"Keith Busch" <kbusch@kernel.org>,
"Klaus Jensen" <its@irrelevant.dk>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
Yui Washizu <yui.washidu@gmail.com>,
Akihiko Odaki <akihiko.odaki@daynix.com>
Subject: [PATCH for-9.2 v6 9/9] pcie_sriov: Make a PCI device with user-created VF ARI-capable
Date: Fri, 02 Aug 2024 15:49:53 +0900 [thread overview]
Message-ID: <20240802-sriov-v6-9-0c8ff49c4276@daynix.com> (raw)
In-Reply-To: <20240802-sriov-v6-0-0c8ff49c4276@daynix.com>
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
docs/system/sriov.rst | 3 ++-
include/hw/pci/pcie_sriov.h | 7 +++++--
hw/pci/pcie_sriov.c | 12 ++++++++----
hw/virtio/virtio-pci.c | 16 ++++++++++------
4 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/docs/system/sriov.rst b/docs/system/sriov.rst
index a851a66a4b8b..d12178f3c319 100644
--- a/docs/system/sriov.rst
+++ b/docs/system/sriov.rst
@@ -28,7 +28,8 @@ virtio-net-pci functions to a bus. Below is a command line example:
The VFs specify the paired PF with ``sriov-pf`` property. The PF must be
added after all VFs. It is the user's responsibility to ensure that VFs have
function numbers larger than one of the PF, and that the function numbers
-have a consistent stride.
+have a consistent stride. Both the PF and VFs are ARI-capable so you can have
+255 VFs at maximum.
You may also need to perform additional steps to activate the SR-IOV feature on
your guest. For Linux, refer to [1]_.
diff --git a/include/hw/pci/pcie_sriov.h b/include/hw/pci/pcie_sriov.h
index f75b8f22ee92..aeaa38cf3456 100644
--- a/include/hw/pci/pcie_sriov.h
+++ b/include/hw/pci/pcie_sriov.h
@@ -43,12 +43,15 @@ void pcie_sriov_vf_register_bar(PCIDevice *dev, int region_num,
/**
* pcie_sriov_pf_init_from_user_created_vfs() - Initialize PF with user-created
- * VFs.
+ * VFs, adding ARI to PF
* @dev: A PCIe device being realized.
* @offset: The offset of the SR-IOV capability.
* @errp: pointer to Error*, to store an error if it happens.
*
- * Return: The size of added capability. 0 if the user did not create VFs.
+ * Initializes a PF with user-created VFs, adding the ARI extended capability to
+ * the PF. The VFs should call pcie_ari_init() to form an ARI device.
+ *
+ * Return: The size of added capabilities. 0 if the user did not create VFs.
* -1 if failed.
*/
int16_t pcie_sriov_pf_init_from_user_created_vfs(PCIDevice *dev,
diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c
index 0c875e61fe96..64c655db29c4 100644
--- a/hw/pci/pcie_sriov.c
+++ b/hw/pci/pcie_sriov.c
@@ -90,12 +90,10 @@ static bool pcie_sriov_pf_init_common(PCIDevice *dev, uint16_t offset,
}
if (total_vfs) {
- uint16_t ari_cap = pcie_find_capability(dev, PCI_EXT_CAP_ID_ARI);
uint16_t first_vf_devfn = dev->devfn + vf_offset;
uint16_t last_vf_devfn = first_vf_devfn + vf_stride * (total_vfs - 1);
- if ((!ari_cap && PCI_SLOT(dev->devfn) != PCI_SLOT(last_vf_devfn)) ||
- last_vf_devfn >= PCI_DEVFN_MAX) {
+ if (last_vf_devfn >= PCI_DEVFN_MAX) {
error_setg(errp, "VF function number overflows");
return false;
}
@@ -257,6 +255,7 @@ int16_t pcie_sriov_pf_init_from_user_created_vfs(PCIDevice *dev,
PCIDevice **vfs;
BusState *bus = qdev_get_parent_bus(DEVICE(dev));
uint16_t ven_id = pci_get_word(dev->config + PCI_VENDOR_ID);
+ uint16_t size = PCI_EXT_CAP_SRIOV_SIZEOF;
uint16_t vf_dev_id;
uint16_t vf_offset;
uint16_t vf_stride;
@@ -323,6 +322,11 @@ int16_t pcie_sriov_pf_init_from_user_created_vfs(PCIDevice *dev,
return -1;
}
+ if (!pcie_find_capability(dev, PCI_EXT_CAP_ID_ARI)) {
+ pcie_ari_init(dev, offset + size);
+ size += PCI_ARI_SIZEOF;
+ }
+
for (i = 0; i < pf->len; i++) {
vfs[i]->exp.sriov_vf.pf = dev;
vfs[i]->exp.sriov_vf.vf_number = i;
@@ -343,7 +347,7 @@ int16_t pcie_sriov_pf_init_from_user_created_vfs(PCIDevice *dev,
}
}
- return PCI_EXT_CAP_SRIOV_SIZEOF;
+ return size;
}
bool pcie_sriov_register_device(PCIDevice *dev, Error **errp)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 0c8fcc5627d5..b19e2983ee22 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -2102,12 +2102,16 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)
PCI_BASE_ADDRESS_SPACE_IO, &proxy->bar);
}
- res = pcie_sriov_pf_init_from_user_created_vfs(&proxy->pci_dev,
- proxy->last_pcie_cap_offset,
- errp);
- if (res > 0) {
- proxy->last_pcie_cap_offset += res;
- virtio_add_feature(&vdev->host_features, VIRTIO_F_SR_IOV);
+ if (pci_is_vf(&proxy->pci_dev)) {
+ pcie_ari_init(&proxy->pci_dev, proxy->last_pcie_cap_offset);
+ proxy->last_pcie_cap_offset += PCI_ARI_SIZEOF;
+ } else {
+ res = pcie_sriov_pf_init_from_user_created_vfs(
+ &proxy->pci_dev, proxy->last_pcie_cap_offset, errp);
+ if (res > 0) {
+ proxy->last_pcie_cap_offset += res;
+ virtio_add_feature(&vdev->host_features, VIRTIO_F_SR_IOV);
+ }
}
}
--
2.45.2
prev parent reply other threads:[~2024-08-02 6:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-02 6:49 [PATCH for-9.2 v6 0/9] virtio-net: add support for SR-IOV emulation Akihiko Odaki
2024-08-02 6:49 ` [PATCH for-9.2 v6 1/9] hw/pci: Do not add ROM BAR for SR-IOV VF Akihiko Odaki
2024-08-02 6:49 ` [PATCH for-9.2 v6 2/9] hw/pci: Fix SR-IOV VF number calculation Akihiko Odaki
2024-08-02 6:49 ` [PATCH for-9.2 v6 3/9] pcie_sriov: Ensure PF and VF are mutually exclusive Akihiko Odaki
2024-08-02 6:49 ` [PATCH for-9.2 v6 4/9] pcie_sriov: Check PCI Express for SR-IOV PF Akihiko Odaki
2024-08-02 6:49 ` [PATCH for-9.2 v6 5/9] pcie_sriov: Allow user to create SR-IOV device Akihiko Odaki
2024-08-02 6:49 ` [PATCH for-9.2 v6 6/9] virtio-pci: Implement SR-IOV PF Akihiko Odaki
2024-08-02 6:49 ` [PATCH for-9.2 v6 7/9] virtio-net: Implement SR-IOV VF Akihiko Odaki
2024-08-02 6:49 ` [PATCH for-9.2 v6 8/9] docs: Document composable SR-IOV device Akihiko Odaki
2024-08-02 6:49 ` Akihiko Odaki [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240802-sriov-v6-9-0c8ff49c4276@daynix.com \
--to=akihiko.odaki@daynix.com \
--cc=alex.williamson@redhat.com \
--cc=berrange@redhat.com \
--cc=clg@redhat.com \
--cc=eduardo@habkost.net \
--cc=its@irrelevant.dk \
--cc=jasowang@redhat.com \
--cc=kbusch@kernel.org \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=sriram.yagnaraman@ericsson.com \
--cc=yui.washidu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).