From: Alex Williamson <alex.williamson@redhat.com>
To: Akihiko Odaki <akihiko.odaki@daynix.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
qemu-arm@nongnu.org, "Michael S . Tsirkin" <mst@redhat.com>,
Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
Gerd Hoffmann <kraxel@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Richard Henderson <richard.henderson@linaro.org>,
Eduardo Habkost <eduardo@habkost.net>,
John Snow <jsnow@redhat.com>,
Dmitry Fleytman <dmitry.fleytman@gmail.com>,
Jason Wang <jasowang@redhat.com>, Stefan Weil <sw@weilnetz.de>,
Keith Busch <kbusch@kernel.org>, Klaus Jensen <its@irrelevant.dk>,
Peter Maydell <peter.maydell@linaro.org>,
Andrey Smirnov <andrew.smirnov@gmail.com>,
Paul Burton <paulburton@kernel.org>,
Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>,
Yan Vugenfirer <yan@daynix.com>,
Yuri Benditovich <yuri.benditovich@daynix.com>
Subject: Re: [PATCH v3 14/16] hw/vfio/pci: Omit errp for pci_add_capability
Date: Wed, 26 Oct 2022 16:10:15 -0600 [thread overview]
Message-ID: <20221026161015.211b3f36.alex.williamson@redhat.com> (raw)
In-Reply-To: <20221026201527.24063-15-akihiko.odaki@daynix.com>
On Thu, 27 Oct 2022 05:15:25 +0900
Akihiko Odaki <akihiko.odaki@daynix.com> wrote:
> The code generating errors in pci_add_capability has a comment which
> says:
> > Verify that capabilities don't overlap. Note: device assignment
> > depends on this check to verify that the device is not broken.
> > Should never trigger for emulated devices, but it's helpful for
> > debugging these.
>
> Indeed vfio has some code that passes capability offsets and sizes from
> a physical device, but it explicitly pays attention so that the
> capabilities never overlap. Therefore, in pci_add_capability(), we can
> always assert that capabilities never overlap, and that is what happens
> when omitting errp.
>
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
> ---
> hw/vfio/pci-quirks.c | 15 +++------------
> hw/vfio/pci.c | 14 +++++---------
> 2 files changed, 8 insertions(+), 21 deletions(-)
>
> diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
> index f0147a050a..e94fd273ea 100644
> --- a/hw/vfio/pci-quirks.c
> +++ b/hw/vfio/pci-quirks.c
> @@ -1530,7 +1530,7 @@ const PropertyInfo qdev_prop_nv_gpudirect_clique = {
> static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice *vdev, Error **errp)
> {
> PCIDevice *pdev = &vdev->pdev;
> - int ret, pos = 0xC8;
> + int pos = 0xC8;
>
> if (vdev->nv_gpudirect_clique == 0xFF) {
> return 0;
> @@ -1547,11 +1547,7 @@ static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice *vdev, Error **errp)
> return -EINVAL;
> }
>
> - ret = pci_add_capability(pdev, PCI_CAP_ID_VNDR, pos, 8, errp);
> - if (ret < 0) {
> - error_prepend(errp, "Failed to add NVIDIA GPUDirect cap: ");
> - return ret;
> - }
> + pci_add_capability(pdev, PCI_CAP_ID_VNDR, pos, 8);
>
> memset(vdev->emulated_config_bits + pos, 0xFF, 8);
> pos += PCI_CAP_FLAGS;
> @@ -1718,12 +1714,7 @@ static int vfio_add_vmd_shadow_cap(VFIOPCIDevice *vdev, Error **errp)
> return -EFAULT;
> }
>
> - ret = pci_add_capability(&vdev->pdev, PCI_CAP_ID_VNDR, pos,
> - VMD_SHADOW_CAP_LEN, errp);
> - if (ret < 0) {
> - error_prepend(errp, "Failed to add VMD MEMBAR Shadow cap: ");
> - return ret;
> - }
> + pci_add_capability(&vdev->pdev, PCI_CAP_ID_VNDR, pos, VMD_SHADOW_CAP_LEN);
For these, I guess we're assuming that since they're added first via
vfio_add_virt_caps() that we cannot create an overlap?
>
> memset(vdev->emulated_config_bits + pos, 0xFF, VMD_SHADOW_CAP_LEN);
> pos += PCI_CAP_FLAGS;
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index 939dcc3d4a..2b653d01e3 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -1826,7 +1826,7 @@ static void vfio_add_emulated_long(VFIOPCIDevice *vdev, int pos,
> vfio_set_long_bits(vdev->emulated_config_bits + pos, mask, mask);
> }
>
> -static int vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,
> +static int vfio_setup_pcie_cap(VFIOPCIDevice *vdev, uint8_t pos, uint8_t size,
> Error **errp)
> {
> uint16_t flags;
> @@ -1943,11 +1943,7 @@ static int vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,
> 1, PCI_EXP_FLAGS_VERS);
> }
>
> - pos = pci_add_capability(&vdev->pdev, PCI_CAP_ID_EXP, pos, size,
> - errp);
> - if (pos < 0) {
> - return pos;
> - }
> + pos = pci_add_capability(&vdev->pdev, PCI_CAP_ID_EXP, pos, size);
>
> vdev->pdev.exp.exp_cap = pos;
>
> @@ -2045,14 +2041,14 @@ static int vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos, Error **errp)
> case PCI_CAP_ID_PM:
> vfio_check_pm_reset(vdev, pos);
> vdev->pm_cap = pos;
> - ret = pci_add_capability(pdev, cap_id, pos, size, errp);
> + pci_add_capability(pdev, cap_id, pos, size);
> break;
> case PCI_CAP_ID_AF:
> vfio_check_af_flr(vdev, pos);
> - ret = pci_add_capability(pdev, cap_id, pos, size, errp);
> + pci_add_capability(pdev, cap_id, pos, size);
> break;
> default:
> - ret = pci_add_capability(pdev, cap_id, pos, size, errp);
> + pci_add_capability(pdev, cap_id, pos, size);
> break;
> }
And for these we've calculated a size to make sure that we don't bump
into the next capability, but how do you account for the MSI and MSI-X
cases above this chunk where vfio's overlap prevention can't be used?
Thanks,
Alex
next prev parent reply other threads:[~2022-10-26 22:12 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-26 20:15 [PATCH v3 00/16] pci: Abort if pci_add_capability fails Akihiko Odaki
2022-10-26 20:15 ` [PATCH v3 01/16] pci: Allow to omit errp for pci_add_capability Akihiko Odaki
2022-10-26 20:15 ` [PATCH v3 02/16] hw/i386/amd_iommu: Omit " Akihiko Odaki
2022-10-27 5:43 ` Markus Armbruster
2022-10-26 20:15 ` [PATCH v3 03/16] ahci: " Akihiko Odaki
2022-10-26 20:15 ` [PATCH v3 04/16] e1000e: " Akihiko Odaki
2022-10-26 20:15 ` [PATCH v3 05/16] eepro100: " Akihiko Odaki
2022-10-26 20:15 ` [PATCH v3 06/16] hw/nvme: " Akihiko Odaki
2022-10-26 20:15 ` [PATCH v3 07/16] msi: " Akihiko Odaki
2022-10-26 20:15 ` [PATCH v3 08/16] hw/pci/pci_bridge: " Akihiko Odaki
2022-10-26 20:15 ` [PATCH v3 09/16] pcie: " Akihiko Odaki
2022-10-26 20:15 ` [PATCH v3 10/16] pci/shpc: " Akihiko Odaki
2022-10-26 20:15 ` [PATCH v3 11/16] msix: " Akihiko Odaki
2022-10-26 20:15 ` [PATCH v3 12/16] pci/slotid: " Akihiko Odaki
2022-10-26 20:15 ` [PATCH v3 13/16] hw/pci-bridge/pcie_pci_bridge: " Akihiko Odaki
2022-10-26 20:15 ` [PATCH v3 14/16] hw/vfio/pci: " Akihiko Odaki
2022-10-26 22:10 ` Alex Williamson [this message]
2022-10-26 20:15 ` [PATCH v3 15/16] virtio-pci: " Akihiko Odaki
2022-10-26 20:15 ` [PATCH v3 16/16] pci: Remove legacy errp from pci_add_capability Akihiko Odaki
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=20221026161015.211b3f36.alex.williamson@redhat.com \
--to=alex.williamson@redhat.com \
--cc=akihiko.odaki@daynix.com \
--cc=aleksandar.rikalo@syrmia.com \
--cc=andrew.smirnov@gmail.com \
--cc=dmitry.fleytman@gmail.com \
--cc=eduardo@habkost.net \
--cc=its@irrelevant.dk \
--cc=jasowang@redhat.com \
--cc=jsnow@redhat.com \
--cc=kbusch@kernel.org \
--cc=kraxel@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=paulburton@kernel.org \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=sw@weilnetz.de \
--cc=yan@daynix.com \
--cc=yuri.benditovich@daynix.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).