From: Alex Williamson <alex.williamson@redhat.com>
To: Alexey Kardashevskiy <aik@ozlabs.ru>
Cc: kvm@vger.kernel.org, Jason Baron <jbaron@redhat.com>,
qemu-devel@nongnu.org, Alex Graf <agraf@suse.de>,
anthony@codemonkey.ws, David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [Qemu-devel] [RFC PATCH] qemu pci: pci_add_capability enhancement to prevent damaging config space
Date: Sun, 13 May 2012 20:37:19 -0600 [thread overview]
Message-ID: <1336963039.6954.4.camel@bling.home> (raw)
In-Reply-To: <4FADAE82.4020603@ozlabs.ru>
On Sat, 2012-05-12 at 10:27 +1000, Alexey Kardashevskiy wrote:
> 12.05.2012 5:20, Jason Baron написал:
> > On Fri, May 11, 2012 at 04:45:21PM +1000, Alexey Kardashevskiy wrote:
> >> Normally the pci_add_capability is called on devices to add new
> >> capability. This is ok for emulated devices which capabilities list
> >> is being built by QEMU.
> >>
> >> In the case of VFIO the capability may already exist and adding new
> >> capability into the beginning of the linked list may create a loop.
> >
> > Hi,
> >
> > I don't quite understand how we get a loop, if 'offset' is supplied to
> > 'pci_add_capability' and there is an overlap we get -EINVAL. Otherwise,
> > we are adding the capability in a new empty space. So, I see how we
> > could get the capability in the list twice, but not how there is a loop.
> > what am I missing?
>
>
> This happens only with VFIO.
>
> The capability already exists in the config space as it is fetched from
> the host kernel _before_ msi_init is called. Furthermore, msi_init() is
> called when VFIO sees this capability in the config space.
>
> We probably want to re-add all capabilities, do not know...
Yep, I've had a msi[1] and msix[2] patches in my vfio tree for a long
time, we really want to support this generically for all capabilities
though. We either need to detect or allow the caller to specify that
the config space is already programmed. Note that even if we don't
create a loop, particularly finicky drivers may balk at just changing
the order of the capabilities list. Thanks,
Alex
[1]https://github.com/awilliam/qemu-vfio/commit/a9f04351610ab69e22d90a76dc85be3269000a9f
[2]https://github.com/awilliam/qemu-vfio/commit/b4de3d0436b0260fbc6fcd40787c1c92ffca2980
> >>
> >> For example, the old code destroys the following config
> >> of PCIe Intel E1000E:
> >>
> >> before adding PCI_CAP_ID_MSI (0x05):
> >> 0x34: 0xC8
> >> 0xC8: 0x01 0xD0
> >> 0xD0: 0x05 0xE0
> >> 0xE0: 0x10 0x00
> >>
> >> after:
> >> 0x34: 0xD0
> >> 0xC8: 0x01 0xD0
> >> 0xD0: 0x05 0xC8
> >> 0xE0: 0x10 0x00
> >>
> >> As result capabilities 0x01 and 0x05 point to each other.
> >>
> >> The proposed patch does not change capability pointers when
> >> the same type capability is about to add.
> >>
> >> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> >> ---
> >> hw/pci.c | 10 ++++++----
> >> 1 files changed, 6 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/hw/pci.c b/hw/pci.c
> >> index aa0c0b8..1f7c924 100644
> >> --- a/hw/pci.c
> >> +++ b/hw/pci.c
> >> @@ -1794,10 +1794,12 @@ int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
> >> }
> >>
> >> config = pdev->config + offset;
> >> - config[PCI_CAP_LIST_ID] = cap_id;
> >> - config[PCI_CAP_LIST_NEXT] = pdev->config[PCI_CAPABILITY_LIST];
> >> - pdev->config[PCI_CAPABILITY_LIST] = offset;
> >> - pdev->config[PCI_STATUS] |= PCI_STATUS_CAP_LIST;
> >> + if (config[PCI_CAP_LIST_ID] != cap_id) {
> >> + config[PCI_CAP_LIST_ID] = cap_id;
> >> + config[PCI_CAP_LIST_NEXT] = pdev->config[PCI_CAPABILITY_LIST];
> >> + pdev->config[PCI_CAPABILITY_LIST] = offset;
> >> + pdev->config[PCI_STATUS] |= PCI_STATUS_CAP_LIST;
> >> + }
> >> memset(pdev->used + offset, 0xFF, size);
> >> /* Make capability read-only by default */
> >> memset(pdev->wmask + offset, 0, size);
>
>
>
next prev parent reply other threads:[~2012-05-14 2:37 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-11 6:45 [Qemu-devel] [RFC PATCH] qemu pci: pci_add_capability enhancement to prevent damaging config space Alexey Kardashevskiy
2012-05-11 10:52 ` Alexander Graf
2012-05-11 12:47 ` Alexey Kardashevskiy
2012-05-11 14:13 ` Alexander Graf
2012-05-14 3:49 ` Alexey Kardashevskiy
2012-05-18 5:12 ` Alexey Kardashevskiy
2012-05-22 2:02 ` Benjamin Herrenschmidt
2012-05-22 3:21 ` Alexander Graf
2012-05-22 3:44 ` Alexey Kardashevskiy
2012-05-22 5:52 ` Alexander Graf
2012-05-22 6:11 ` Alexey Kardashevskiy
2012-05-22 6:31 ` Alexander Graf
2012-05-22 7:01 ` Alexey Kardashevskiy
2012-05-22 7:13 ` Alexander Graf
2012-05-22 7:37 ` Benjamin Herrenschmidt
2012-06-08 8:47 ` Alexey Kardashevskiy
2012-06-08 10:56 ` Jan Kiszka
2012-06-08 11:16 ` Alexey Kardashevskiy
2012-06-08 11:30 ` Jan Kiszka
2012-06-08 14:00 ` Alexey Kardashevskiy
2012-06-08 14:43 ` Jan Kiszka
2012-06-08 14:56 ` Alex Williamson
2012-06-08 15:05 ` Jan Kiszka
2012-06-08 15:22 ` Alex Williamson
2012-05-22 6:38 ` Alexander Graf
2012-05-11 19:20 ` Jason Baron
2012-05-12 0:27 ` Alexey Kardashevskiy
2012-05-14 2:37 ` Alex Williamson [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-05-11 6:59 Alexey Kardashevskiy
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=1336963039.6954.4.camel@bling.home \
--to=alex.williamson@redhat.com \
--cc=agraf@suse.de \
--cc=aik@ozlabs.ru \
--cc=anthony@codemonkey.ws \
--cc=david@gibson.dropbear.id.au \
--cc=jbaron@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
/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).