qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Bandan Das <bsd@redhat.com>
To: qemu-devel@nongnu.org, alex.williamson@redhat.com
Subject: [Qemu-devel] [PATCH] vfio: convert to 128 bit arithmetic calculations when adding mem regions
Date: Wed, 23 Mar 2016 16:57:35 -0400	[thread overview]
Message-ID: <jpgr3f0rjy8.fsf@linux.bootlegged.copy> (raw)


vfio_listener_region_add for a iommu mr results in
an overflow assert since vt-d memory region is initialized
with UINT64_MAX. Convert calculations to 128 bit arithmetic
for such regions and let int128_get64 assert for non iommu
regions only.

Suggested-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Bandan Das <bsd@redhat.com>
---
This is v2 of http://patchwork.ozlabs.org/patch/600364/
 hw/vfio/common.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index fb588d8..9489ff3 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -323,7 +323,7 @@ static void vfio_listener_region_add(MemoryListener *listener,
 {
     VFIOContainer *container = container_of(listener, VFIOContainer, listener);
     hwaddr iova, end;
-    Int128 llend;
+    Int128 llend, endaddr;
     void *vaddr;
     int ret;
 
@@ -349,14 +349,15 @@ static void vfio_listener_region_add(MemoryListener *listener,
     if (int128_ge(int128_make64(iova), llend)) {
         return;
     }
-    end = int128_get64(llend);
+    endaddr = int128_sub(llend, int128_one());
 
-    if ((iova < container->min_iova) || ((end - 1) > container->max_iova)) {
-        error_report("vfio: IOMMU container %p can't map guest IOVA region"
-                     " 0x%"HWADDR_PRIx"..0x%"HWADDR_PRIx,
-                     container, iova, end - 1);
-        ret = -EFAULT;
-        goto fail;
+    if ((iova < container->min_iova) || (int128_get64(endaddr) >
+                                         container->max_iova)) {
+            error_report("vfio: IOMMU container %p can't map guest IOVA region"
+                         " 0x%"HWADDR_PRIx"..0x%"HWADDR_PRIx,
+                         container, iova, int128_get64(endaddr));
+            ret = -EFAULT;
+            goto fail;
     }
 
     memory_region_ref(section->mr);
@@ -364,7 +365,7 @@ static void vfio_listener_region_add(MemoryListener *listener,
     if (memory_region_is_iommu(section->mr)) {
         VFIOGuestIOMMU *giommu;
 
-        trace_vfio_listener_region_add_iommu(iova, end - 1);
+        trace_vfio_listener_region_add_iommu(iova, int128_get64(endaddr));
         /*
          * FIXME: We should do some checking to see if the
          * capabilities of the host VFIO IOMMU are adequate to model
@@ -389,6 +390,8 @@ static void vfio_listener_region_add(MemoryListener *listener,
         return;
     }
 
+    end = int128_get64(llend);
+
     /* Here we assume that memory_region_is_ram(section->mr)==true */
 
     vaddr = memory_region_get_ram_ptr(section->mr) +
-- 
2.5.0

             reply	other threads:[~2016-03-23 20:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-23 20:57 Bandan Das [this message]
2016-03-23 23:00 ` [Qemu-devel] [PATCH] vfio: convert to 128 bit arithmetic calculations when adding mem regions Alex Williamson
2016-03-24  0:20   ` Bandan Das

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=jpgr3f0rjy8.fsf@linux.bootlegged.copy \
    --to=bsd@redhat.com \
    --cc=alex.williamson@redhat.com \
    --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).