From: Peter Xu <peterx@redhat.com>
To: Andrew Jones <drjones@redhat.com>
Cc: Alexander Gordeev <agordeev@redhat.com>,
kvm@vger.kernel.org, jan.kiszka@web.de, rkrcmar@redhat.com,
pbonzini@redhat.com
Subject: Re: [PATCH kvm-unit-tests v5 13/14] pci: add msi support for 32/64bit address
Date: Wed, 23 Nov 2016 10:40:10 +0800 [thread overview]
Message-ID: <20161123024010.GB22706@pxdev.xzpeter.org> (raw)
In-Reply-To: <20161122123041.ppxrc3dnwdlo4fdp@kamzik.brq.redhat.com>
On Tue, Nov 22, 2016 at 01:30:41PM +0100, Andrew Jones wrote:
> On Tue, Nov 22, 2016 at 03:21:37PM +0800, Peter Xu wrote:
> > On Tue, Nov 22, 2016 at 08:03:06AM +0100, Alexander Gordeev wrote:
> > > On Tue, Nov 22, 2016 at 12:59:20PM +0800, Peter Xu wrote:
> > > > On Mon, Nov 21, 2016 at 08:27:52PM +0100, Alexander Gordeev wrote:
> > > >
> > > > [...]
> > > >
> > > > > > +void pci_cap_walk(struct pci_dev *dev)
> > > > > > +{
> > > > > > + uint8_t cap_offset;
> > > > > > + uint8_t cap_id;
> > > > > > +
> > > > > > + cap_offset = pci_config_readb(dev->bdf, PCI_CAPABILITY_LIST);
> > > > > > + while (cap_offset) {
> > > > > > + cap_id = pci_config_readb(dev->bdf, cap_offset);
> > > > > > + printf("PCI detected cap 0x%x\n", cap_id);
> > > > > > + if (cap_handlers[cap_id])
> > > > > > + cap_handlers[cap_id](dev, cap_offset);
> > > > > > + cap_offset = pci_config_readb(dev->bdf, cap_offset + 1);
> > > > > > + }
> > > > > > +}
> > > > >
> > > > > Are you sure the function above is safe without range (sanity) checks?
> > > >
> > > > No. :) But if something goes wrong, I guess that's possibly a QEMU PCI
> > > > bug. I can add some check if you think is necessary, like, make sure
> > > > the loop goes no more than a specific value?
> > >
> > > Yes - I suppose PCI cap. list has a limit.
> >
> > Will do. 0xff should suffice. Thanks,
>
> Well, cap_offset has to be 0xff or smaller, since it comes from readb,
> which returns uint8_t. So there's no need to check cap_offset. As for
> dereferencing cap_handlers with cap_id, which is what I think Alex
> was asking about, then after its read we should simply add
>
> assert(cap_id <= PCI_CAP_ID_MAX);
>
> Thanks,
> drew
IIUC here we need to count the loop in case we have a loop in the cap
list (which is possibly QEMU bug, but hardly happen, like cap A points
to cap B, while cap B points back to cap A). In that case, I'll do
this in the loop:
assert(++count <= 255);
To make sure the loop ends somewhere.
IMHO we don't need to check cap_id since cap_id is only used in:
if (cap_handlers[cap_id])
cap_handlers[cap_id](dev, cap_offset);
As long as we provide correct handlers, we'll naturally skip all
unknown cap_ids.
Thanks,
-- peterx
next prev parent reply other threads:[~2016-11-23 2:40 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-15 22:24 [PATCH kvm-unit-tests v5 00/14] VT-d unit test Peter Xu
2016-11-15 22:24 ` [PATCH kvm-unit-tests v5 01/14] pci: fix missing extern for pci_testdev() Peter Xu
2016-11-16 9:26 ` Andrew Jones
2016-11-15 22:24 ` [PATCH kvm-unit-tests v5 02/14] x86/asm: add cpu_relax() Peter Xu
2016-11-15 22:24 ` [PATCH kvm-unit-tests v5 03/14] libcflat: introduce is_power_of_2() Peter Xu
2016-11-15 22:24 ` [PATCH kvm-unit-tests v5 04/14] x86: intel-iommu: add vt-d init test Peter Xu
2016-11-15 22:25 ` [PATCH kvm-unit-tests v5 05/14] libcflat: add IS_ALIGNED() macro, and page sizes Peter Xu
2016-11-15 22:25 ` [PATCH kvm-unit-tests v5 06/14] libcflat: moving MIN/MAX here Peter Xu
2016-11-15 22:25 ` [PATCH kvm-unit-tests v5 07/14] vm/page: provide PGDIR_OFFSET() macro Peter Xu
2016-11-15 22:25 ` [PATCH kvm-unit-tests v5 08/14] pci: introduce struct pci_dev Peter Xu
2016-11-15 22:25 ` [PATCH kvm-unit-tests v5 09/14] pci: provide pci_scan_bars() Peter Xu
2016-11-16 9:50 ` Alexander Gordeev
2016-11-21 7:27 ` Peter Xu
2016-11-21 19:24 ` Alexander Gordeev
2016-11-22 2:16 ` Peter Xu
2016-11-15 22:25 ` [PATCH kvm-unit-tests v5 10/14] pci: provide pci_enable_defaults() Peter Xu
2016-11-15 22:25 ` [PATCH kvm-unit-tests v5 11/14] pci: edu: introduce pci-edu helpers Peter Xu
2016-11-15 22:25 ` [PATCH kvm-unit-tests v5 12/14] x86: intel-iommu: add dmar test Peter Xu
2016-11-15 22:25 ` [PATCH kvm-unit-tests v5 13/14] pci: add msi support for 32/64bit address Peter Xu
2016-11-21 19:27 ` Alexander Gordeev
2016-11-22 4:59 ` Peter Xu
2016-11-22 7:03 ` Alexander Gordeev
2016-11-22 7:21 ` Peter Xu
2016-11-22 12:30 ` Andrew Jones
2016-11-23 2:40 ` Peter Xu [this message]
2016-11-23 10:36 ` Andrew Jones
2016-11-23 10:39 ` Peter Xu
2016-11-15 22:25 ` [PATCH kvm-unit-tests v5 14/14] x86: intel-iommu: add IR MSI test Peter Xu
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=20161123024010.GB22706@pxdev.xzpeter.org \
--to=peterx@redhat.com \
--cc=agordeev@redhat.com \
--cc=drjones@redhat.com \
--cc=jan.kiszka@web.de \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.