diff mbox

[Xen-devel,PULL,1/7] exec: Limit translation limiting in address_space_translate to xen

Message ID 1399475403-5408-1-git-send-email-stefano.stabellini@eu.citrix.com
State Superseded
Headers show

Commit Message

Stefano Stabellini May 7, 2014, 3:09 p.m. UTC
From: Alexey Kardashevskiy <aik@ozlabs.ru>

The address_space_translate() function cuts the returned plen (page size)
to hardcoded TARGET_PAGE_SIZE. This function can be used on pages bigger
than that so this limiting should not be used on such pages.

Since originally the limiting was introduced for XEN, we can safely
limit this piece of code to XEN. So does the patch.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
 exec.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Peter Maydell May 7, 2014, 3:12 p.m. UTC | #1
On 7 May 2014 16:09, Stefano Stabellini
<stefano.stabellini@eu.citrix.com> wrote:
> From: Alexey Kardashevskiy <aik@ozlabs.ru>
>
> The address_space_translate() function cuts the returned plen (page size)
> to hardcoded TARGET_PAGE_SIZE. This function can be used on pages bigger
> than that so this limiting should not be used on such pages.
>
> Since originally the limiting was introduced for XEN, we can safely
> limit this piece of code to XEN. So does the patch.
>
> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> ---
>  exec.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/exec.c b/exec.c
> index 91513c6..cf12049 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -380,7 +380,7 @@ MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr,
>          as = iotlb.target_as;
>      }
>
> -    if (memory_access_is_direct(mr, is_write)) {
> +    if (xen_enabled() && memory_access_is_direct(mr, is_write)) {
>          hwaddr page = ((addr & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE) - addr;
>          len = MIN(page, len);
>      }

We should put this patch in (both as an efficiency thing and an
expedient fix) but we really need to either track down which
callers of this API are relying on the returned plen not being
truncated, or we need to fix Xen to not truncate either. This
is just a bandaid IMHO.

thanks
-- PMM
Paolo Bonzini May 7, 2014, 3:22 p.m. UTC | #2
Il 07/05/2014 17:12, Peter Maydell ha scritto:
>> > -    if (memory_access_is_direct(mr, is_write)) {
>> > +    if (xen_enabled() && memory_access_is_direct(mr, is_write)) {
>> >          hwaddr page = ((addr & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE) - addr;
>> >          len = MIN(page, len);
>> >      }
> We should put this patch in (both as an efficiency thing and an
> expedient fix) but we really need to either track down which
> callers of this API are relying on the returned plen not being
> truncated, or we need to fix Xen to not truncate either. This
> is just a bandaid IMHO.

Fixing Xen to not truncate is not possible because of the Xen mapcache, 
unless of course QEMU is changed to avoid the mapcache completely on 
64-bit hosts.  I'm not sure if that makes sense from the Xen point of view.

Regarding fixing callers, a known one is virtio-scsi which is a bug and 
on my todo list.  But another is VFIO, which cannot accept truncation if 
the IOMMU page size is greater than TARGET_PAGE_SIZE.

Paolo
Stefano Stabellini May 7, 2014, 3:30 p.m. UTC | #3
On Wed, 7 May 2014, Paolo Bonzini wrote:
> Il 07/05/2014 17:12, Peter Maydell ha scritto:
> > > > -    if (memory_access_is_direct(mr, is_write)) {
> > > > +    if (xen_enabled() && memory_access_is_direct(mr, is_write)) {
> > > >          hwaddr page = ((addr & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE) -
> > > addr;
> > > >          len = MIN(page, len);
> > > >      }
> > We should put this patch in (both as an efficiency thing and an
> > expedient fix) but we really need to either track down which
> > callers of this API are relying on the returned plen not being
> > truncated, or we need to fix Xen to not truncate either. This
> > is just a bandaid IMHO.
> 
> Fixing Xen to not truncate is not possible because of the Xen mapcache, unless
> of course QEMU is changed to avoid the mapcache completely on 64-bit hosts.
> I'm not sure if that makes sense from the Xen point of view.

Right, it makes sense, however we would still need to keep the 32-bit
mapcache code path working.


> Regarding fixing callers, a known one is virtio-scsi which is a bug and on my
> todo list.  But another is VFIO, which cannot accept truncation if the IOMMU
> page size is greater than TARGET_PAGE_SIZE.
Peter Maydell May 7, 2014, 3:32 p.m. UTC | #4
On 7 May 2014 16:22, Paolo Bonzini <pbonzini@redhat.com> wrote:
> Fixing Xen to not truncate is not possible because of the Xen mapcache,
> unless of course QEMU is changed to avoid the mapcache completely on 64-bit
> hosts.  I'm not sure if that makes sense from the Xen point of view.
>
> Regarding fixing callers, a known one is virtio-scsi which is a bug and on
> my todo list.  But another is VFIO, which cannot accept truncation if the
> IOMMU page size is greater than TARGET_PAGE_SIZE.

The API can't simultaneously allow the implementation to truncate
and guarantee to the caller that we don't truncate, so one of these
has to change, surely?

Otherwise we would need to provide some sort of flag for
truncation-unacceptable so that incompatible combinations
fail nicely rather than silently doing weird stuff, I guess.

thanks
-- PMM
Paolo Bonzini May 7, 2014, 3:38 p.m. UTC | #5
Il 07/05/2014 17:32, Peter Maydell ha scritto:
> > Regarding fixing callers, a known one is virtio-scsi which is a bug and on
> > my todo list.  But another is VFIO, which cannot accept truncation if the
> > IOMMU page size is greater than TARGET_PAGE_SIZE.
>
> The API can't simultaneously allow the implementation to truncate
> and guarantee to the caller that we don't truncate, so one of these
> has to change, surely?

We can provide a function to return the truncation granularity, and add 
to VFIO a check that will prevent using VFIO together with Xen.

Paolo
diff mbox

Patch

diff --git a/exec.c b/exec.c
index 91513c6..cf12049 100644
--- a/exec.c
+++ b/exec.c
@@ -380,7 +380,7 @@  MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr,
         as = iotlb.target_as;
     }
 
-    if (memory_access_is_direct(mr, is_write)) {
+    if (xen_enabled() && memory_access_is_direct(mr, is_write)) {
         hwaddr page = ((addr & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE) - addr;
         len = MIN(page, len);
     }