From: Alex Williamson <alex.williamson@redhat.com>
To: mjr@cs.wisc.edu
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2] Align PCI capabilities in pci_find_space
Date: Tue, 25 Sep 2012 21:08:22 -0600 [thread overview]
Message-ID: <1348628902.28860.156.camel@bling.home> (raw)
In-Reply-To: <1348621313-47404-1-git-send-email-mjr@cs.wisc.edu>
On Tue, 2012-09-25 at 20:01 -0500, mjr@cs.wisc.edu wrote:
> From: Matt Renzelmann <mjr@cs.wisc.edu>
>
> The current implementation of pci_find_space does not correctly align
> PCI capabilities in the PCI configuration space. This patch fixes
> this issue.
>
> Signed-off-by: Matt Renzelmann <mjr@cs.wisc.edu>
> ---
>
> Alex Williamson <alex.williamson@redhat.com> wrote:
> > I think you could just search every 4th byte. In fact, this whole used
> > byte-map could be turned into a single uint64_t bitmap for standard
> > config space. Thanks,
>
> I've not tested this version of the patch, in contrast to the last, so
> I'm a bit less confident of its correctness. I did not reimplement it
> as suggested as I'm not that familiar with this code, and instead just
> applied the every 4th byte strategy.
>
> hw/pci.c | 12 ++++++++----
> 1 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/hw/pci.c b/hw/pci.c
> index f855cf3..e99866a 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -1631,11 +1631,15 @@ static int pci_find_space(PCIDevice *pdev, uint8_t size)
> int config_size = pci_config_size(pdev);
> int offset = PCI_CONFIG_HEADER_SIZE;
> int i;
> - for (i = PCI_CONFIG_HEADER_SIZE; i < config_size; ++i)
> - if (pdev->used[i])
> - offset = i + 1;
> - else if (i - offset + 1 == size)
> +
> + for (i = PCI_CONFIG_HEADER_SIZE; i < config_size; i += 4) {
> + if (pdev->used[i]) {
> + offset = i + 4;
> + } else if (i - offset + 1 == size) {
This test needs to change as well. Looks like it should now be:
(i - offset + 4 >= size)
Whereas we were previously calculating the difference from the offset to
the current pointer plus the current unused byte, we're now assuming the
current dword is empty because we're only handing out dword aligned
offsets and it would be broken for something to not mark the first entry
used. Probably worthwhile to also add a comment noting the PCI spec
requires dword alignment for capabilities. Thanks,
Alex
> return offset;
> + }
> + }
> +
> return 0;
> }
>
next prev parent reply other threads:[~2012-09-26 3:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-26 1:01 [Qemu-devel] [PATCH v2] Align PCI capabilities in pci_find_space mjr
2012-09-26 3:08 ` Alex Williamson [this message]
2012-09-26 14:01 ` Alex Williamson
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=1348628902.28860.156.camel@bling.home \
--to=alex.williamson@redhat.com \
--cc=mjr@cs.wisc.edu \
--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).