* qemu-kvm: require 4K aligned resource size for memory
@ 2009-10-20 17:15 Michael S. Tsirkin
2009-10-22 6:42 ` Chris Wright
2009-10-22 16:37 ` Marcelo Tosatti
0 siblings, 2 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2009-10-20 17:15 UTC (permalink / raw)
To: Chris Wright; +Cc: Avi Kivity, Dor Laor, kvm
KVM does not virtualize low address bits for memory accesses, so we must
require that PCI BAR size is a multiple of 4K for passthrough to work
(this also guarantees that address is 4K aligned).
Users of recent linux kernels can force resource size up to 4K
using:
commit 32a9a682bef2f6fce7026bd94d1ce20028b0e52d
Author: Yuji Shimada <shimada-yxb@necst.nec.co.jp>
Date: Mon Mar 16 17:13:39 2009 +0900
PCI: allow assignment of memory resources with a specified alignment
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index 237060f..c2ef31f 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -381,6 +381,14 @@ static int assigned_dev_register_regions(PCIRegion *io_regions,
int t = cur_region->type & IORESOURCE_PREFETCH
? PCI_ADDRESS_SPACE_MEM_PREFETCH
: PCI_ADDRESS_SPACE_MEM;
+ if (cur_region->size & 0xFFF) {
+ fprintf(stderr, "Unable to assign device: PCI region %d "
+ "at address 0x%llx has size 0x%x, "
+ " which is not a multiple of 4K\n",
+ i, (unsigned long long)cur_region->base_addr,
+ cur_region->size);
+ return -1;
+ }
/* map physical memory */
pci_dev->v_addrs[i].e_physbase = cur_region->base_addr;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: qemu-kvm: require 4K aligned resource size for memory
2009-10-20 17:15 qemu-kvm: require 4K aligned resource size for memory Michael S. Tsirkin
@ 2009-10-22 6:42 ` Chris Wright
2009-10-22 9:18 ` Michael S. Tsirkin
2009-10-22 16:37 ` Marcelo Tosatti
1 sibling, 1 reply; 4+ messages in thread
From: Chris Wright @ 2009-10-22 6:42 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: Chris Wright, Avi Kivity, Dor Laor, kvm
* Michael S. Tsirkin (mst@redhat.com) wrote:
> KVM does not virtualize low address bits for memory accesses, so we must
> require that PCI BAR size is a multiple of 4K for passthrough to work
> (this also guarantees that address is 4K aligned).
>
> Users of recent linux kernels can force resource size up to 4K
> using:
>
> commit 32a9a682bef2f6fce7026bd94d1ce20028b0e52d
> Author: Yuji Shimada <shimada-yxb@necst.nec.co.jp>
> Date: Mon Mar 16 17:13:39 2009 +0900
> PCI: allow assignment of memory resources with a specified alignment
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>
> ---
>
> diff --git a/hw/device-assignment.c b/hw/device-assignment.c
> index 237060f..c2ef31f 100644
> --- a/hw/device-assignment.c
> +++ b/hw/device-assignment.c
> @@ -381,6 +381,14 @@ static int assigned_dev_register_regions(PCIRegion *io_regions,
> int t = cur_region->type & IORESOURCE_PREFETCH
> ? PCI_ADDRESS_SPACE_MEM_PREFETCH
> : PCI_ADDRESS_SPACE_MEM;
> + if (cur_region->size & 0xFFF) {
> + fprintf(stderr, "Unable to assign device: PCI region %d "
> + "at address 0x%llx has size 0x%x, "
> + " which is not a multiple of 4K\n",
> + i, (unsigned long long)cur_region->base_addr,
> + cur_region->size);
> + return -1;
> + }
should render this useless now shouldn't it?
/* add offset */
pci_dev->v_addrs[i].u.r_virtbase +=
(cur_region->base_addr & 0xFFF);
thanks,
-chris
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: qemu-kvm: require 4K aligned resource size for memory
2009-10-22 6:42 ` Chris Wright
@ 2009-10-22 9:18 ` Michael S. Tsirkin
0 siblings, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2009-10-22 9:18 UTC (permalink / raw)
To: Chris Wright; +Cc: Avi Kivity, Dor Laor, kvm
On Wed, Oct 21, 2009 at 11:42:47PM -0700, Chris Wright wrote:
> * Michael S. Tsirkin (mst@redhat.com) wrote:
> > KVM does not virtualize low address bits for memory accesses, so we must
> > require that PCI BAR size is a multiple of 4K for passthrough to work
> > (this also guarantees that address is 4K aligned).
> >
> > Users of recent linux kernels can force resource size up to 4K
> > using:
> >
> > commit 32a9a682bef2f6fce7026bd94d1ce20028b0e52d
> > Author: Yuji Shimada <shimada-yxb@necst.nec.co.jp>
> > Date: Mon Mar 16 17:13:39 2009 +0900
> > PCI: allow assignment of memory resources with a specified alignment
> >
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> >
> > ---
> >
> > diff --git a/hw/device-assignment.c b/hw/device-assignment.c
> > index 237060f..c2ef31f 100644
> > --- a/hw/device-assignment.c
> > +++ b/hw/device-assignment.c
> > @@ -381,6 +381,14 @@ static int assigned_dev_register_regions(PCIRegion *io_regions,
> > int t = cur_region->type & IORESOURCE_PREFETCH
> > ? PCI_ADDRESS_SPACE_MEM_PREFETCH
> > : PCI_ADDRESS_SPACE_MEM;
> > + if (cur_region->size & 0xFFF) {
> > + fprintf(stderr, "Unable to assign device: PCI region %d "
> > + "at address 0x%llx has size 0x%x, "
> > + " which is not a multiple of 4K\n",
> > + i, (unsigned long long)cur_region->base_addr,
> > + cur_region->size);
> > + return -1;
> > + }
>
> should render this useless now shouldn't it?
>
> /* add offset */
> pci_dev->v_addrs[i].u.r_virtbase +=
> (cur_region->base_addr & 0xFFF);
Yes, we could go over the code and remove all alignment.
But I'd rather not in case we decide on another approach
in the future. And for upstream, all this code will have to
be rewritten anyway.
> thanks,
> -chris
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: qemu-kvm: require 4K aligned resource size for memory
2009-10-20 17:15 qemu-kvm: require 4K aligned resource size for memory Michael S. Tsirkin
2009-10-22 6:42 ` Chris Wright
@ 2009-10-22 16:37 ` Marcelo Tosatti
1 sibling, 0 replies; 4+ messages in thread
From: Marcelo Tosatti @ 2009-10-22 16:37 UTC (permalink / raw)
To: Michael S. Tsirkin; +Cc: Chris Wright, Avi Kivity, Dor Laor, kvm
On Tue, Oct 20, 2009 at 07:15:09PM +0200, Michael S. Tsirkin wrote:
> KVM does not virtualize low address bits for memory accesses, so we must
> require that PCI BAR size is a multiple of 4K for passthrough to work
> (this also guarantees that address is 4K aligned).
>
> Users of recent linux kernels can force resource size up to 4K
> using:
>
> commit 32a9a682bef2f6fce7026bd94d1ce20028b0e52d
> Author: Yuji Shimada <shimada-yxb@necst.nec.co.jp>
> Date: Mon Mar 16 17:13:39 2009 +0900
> PCI: allow assignment of memory resources with a specified alignment
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-10-22 16:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-20 17:15 qemu-kvm: require 4K aligned resource size for memory Michael S. Tsirkin
2009-10-22 6:42 ` Chris Wright
2009-10-22 9:18 ` Michael S. Tsirkin
2009-10-22 16:37 ` Marcelo Tosatti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox