From: Kevin O'Connor <kevin@koconnor.net>
To: Alexey Korolev <alexey.korolev@endace.com>
Cc: sfd@endace.com, yamahata@valinux.co.jp, seabios@seabios.org,
qemu-devel@nongnu.org, mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH 2/3] Add a new PCI region type to supports 64 bit ranges
Date: Wed, 28 Dec 2011 21:56:47 -0500 [thread overview]
Message-ID: <20111229025647.GB29199@morn.localdomain> (raw)
In-Reply-To: <4EFAA86D.3090103@endace.com>
On Wed, Dec 28, 2011 at 06:26:05PM +1300, Alexey Korolev wrote:
> This patch adds PCI_REGION_TYPE_PREFMEM_64 region type and modifies types of
> variables to make it possible to work with 64 bit addresses.
>
> Why I've added just one region type PCI_REGION_TYPE_PREFMEM_64 and haven't
> added PCI_REGION_TYPE_MEM_64? According to PCI architecture
> specification, the
> bridges can describe 64bit ranges for prefetchable type of memory
> only. So it's very
> unlikely that devices exporting 64bit non-prefetchable BARs. Anyway
> this code will work
> with 64bit non-prefetchable BARs unless the PCI device is not behind
> the secondary bus.
[...]
> --- a/src/pciinit.c
> +++ b/src/pciinit.c
> @@ -22,6 +22,7 @@ enum pci_region_type {
> PCI_REGION_TYPE_IO,
> PCI_REGION_TYPE_MEM,
> PCI_REGION_TYPE_PREFMEM,
> + PCI_REGION_TYPE_PREFMEM_64,
> PCI_REGION_TYPE_COUNT,
> };
This doesn't seem right. A 64bit bar is not a new category - it's
just a way of representing larger values within the existing
categories. Tracking of 64bit prefmem sections separately from
regular prefmem sections doesn't make sense, because both need to be
allocated from the same pool when behind a bridge.
> struct pci_bus {
> struct {
> - /* pci region stats */
> - u32 count[32 - PCI_MEM_INDEX_SHIFT];
> - u32 sum, max;
> /* seconday bus region sizes */
> u32 size;
> - /* pci region assignments */
> - u32 bases[32 - PCI_MEM_INDEX_SHIFT];
> - u32 base;
> + /* pci region stats */
> + u32 max;
> + u32 count[32 - PCI_MEM_INDEX_SHIFT];
> + s64 sum;
> + /* pci region assignments */
> + s64 base;
> + s64 bases[32 - PCI_MEM_INDEX_SHIFT];
Why the choice of s64 over u64? Given the amount of bit manipulation
on these values, I think using u64 would be safer.
> @@ -69,6 +72,8 @@ static enum pci_region_type pci_addr_to_type(u32 addr)
> {
> if (addr & PCI_BASE_ADDRESS_SPACE_IO)
> return PCI_REGION_TYPE_IO;
> + if (addr & PCI_BASE_ADDRESS_MEM_TYPE_64)
> + return PCI_REGION_TYPE_PREFMEM_64;
This seems dangerous - a 64bit bar can be non-prefetchable - getting
this wrong could cause random (hard to debug) crashes.
> @@ -378,19 +383,16 @@ static void pci_bios_check_devices(struct
> pci_bus *busses)
> struct pci_bus *bus = &busses[pci_bdf_to_bus(pci->bdf)];
> int i;
> for (i = 0; i < PCI_NUM_REGIONS; i++) {
> - u32 val, size;
> + u32 val, size, type;
> pci_bios_get_bar(pci, i, &val, &size);
> if (val == 0)
> continue;
>
> - pci_bios_bus_reserve(bus, pci_addr_to_type(val), size);
> + type = pci_addr_to_type(val);
> + pci_bios_bus_reserve(bus, type, size);
> pci->bars[i].addr = val;
> pci->bars[i].size = size;
> - pci->bars[i].is64 = (!(val & PCI_BASE_ADDRESS_SPACE_IO) &&
> - (val & PCI_BASE_ADDRESS_MEM_TYPE_MASK)
> - == PCI_BASE_ADDRESS_MEM_TYPE_64);
> -
> - if (pci->bars[i].is64)
> + if (type == PCI_REGION_TYPE_PREFMEM_64)
> i++;
If there is a 64bit bar, then the size could be over 32bits - the code
really needs to handle this (or it could cause overlapping regions
which result in random crashes).
-Kevin
next prev parent reply other threads:[~2011-12-29 2:56 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-28 4:41 [Qemu-devel] [Seabios] [PATCH 0/3] 64bit PCI BARs allocations Alexey Korolev
2011-12-28 5:00 ` [Qemu-devel] [PATCH 1/3] Add new range above 4GB in _CRS table Alexey Korolev
2011-12-28 5:26 ` [Qemu-devel] [PATCH 2/3] Add a new PCI region type to supports 64 bit ranges Alexey Korolev
2011-12-28 11:30 ` Michael S. Tsirkin
2011-12-29 3:57 ` Alexey Korolev
2011-12-29 2:56 ` Kevin O'Connor [this message]
2011-12-29 5:00 ` Alexey Korolev
2011-12-30 5:57 ` Kevin O'Connor
2011-12-29 5:32 ` Alexey Korolev
2011-12-29 16:16 ` Michael S. Tsirkin
2012-01-03 15:14 ` Gerd Hoffmann
2012-01-04 3:10 ` Kevin O'Connor
2011-12-28 5:35 ` [Qemu-devel] [PATCH 3/3] Changes related to secondary buses and 64bit regions Alexey Korolev
2011-12-28 6:30 ` [Qemu-devel] [SeaBIOS] " Alexey Korolev
2011-12-28 11:43 ` [Qemu-devel] " Michael S. Tsirkin
2011-12-29 5:40 ` Alexey Korolev
2011-12-29 16:18 ` Michael S. Tsirkin
2011-12-30 4:56 ` Alexey Korolev
2011-12-29 5:41 ` Alexey Korolev
2011-12-29 16:19 ` Michael S. Tsirkin
2011-12-29 16:21 ` Michael S. Tsirkin
2011-12-30 5:10 ` Alexey Korolev
2011-12-30 6:02 ` Kevin O'Connor
2011-12-30 5:10 ` Alexey Korolev
2011-12-30 6:22 ` Kevin O'Connor
2011-12-30 7:05 ` Alexey Korolev
2011-12-30 5:03 ` Kevin O'Connor
2011-12-28 11:43 ` [Qemu-devel] [Seabios] [PATCH 0/3] 64bit PCI BARs allocations Michael S. Tsirkin
2011-12-29 9:20 ` Alexey Korolev
2011-12-29 16:21 ` Michael S. Tsirkin
2011-12-29 22:17 ` Alexey Korolev
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=20111229025647.GB29199@morn.localdomain \
--to=kevin@koconnor.net \
--cc=alexey.korolev@endace.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=seabios@seabios.org \
--cc=sfd@endace.com \
--cc=yamahata@valinux.co.jp \
/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).