qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Evgeny Yakovlev <wrfsh@yandex-team.ru>
To: qemu-devel@nongnu.org, mst@redhat.com
Cc: yc-core@yandex-team.ru
Subject: [Qemu-devel] [PATCH] i386/acpi: fix gint overflow in crs_range_compare
Date: Thu, 18 Jul 2019 18:48:52 +0300	[thread overview]
Message-ID: <1563464932-24284-1-git-send-email-wrfsh@yandex-team.ru> (raw)

When very large regions (32GB sized in our case, PCI pass-through of GPUs)
are compared substraction result does not fit into gint.

As a result crs_replace_with_free_ranges does not get sorted ranges and
incorrectly computes PCI64 free space regions. Which then makes linux
guest complain about device and PCI64 hole intersection and device
becomes unusable.

Fix that by returning exactly fitting ranges.

Signed-off-by: Evgeny Yakovlev <wrfsh@yandex-team.ru>
---
 hw/i386/acpi-build.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index d281ffa..5cf88a6 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -758,7 +758,13 @@ static gint crs_range_compare(gconstpointer a, gconstpointer b)
      CrsRangeEntry *entry_a = *(CrsRangeEntry **)a;
      CrsRangeEntry *entry_b = *(CrsRangeEntry **)b;
 
-     return (int64_t)entry_a->base - (int64_t)entry_b->base;
+     if (entry_a->base < entry_b->base) {
+         return -1;
+     } else if (entry_a->base > entry_b->base) {
+         return 1;
+     } else {
+         return 0;
+     }
 }
 
 /*
-- 
2.7.4



             reply	other threads:[~2019-07-18 15:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-18 15:48 Evgeny Yakovlev [this message]
2019-07-18 16:02 ` [Qemu-devel] [PATCH] i386/acpi: fix gint overflow in crs_range_compare no-reply

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=1563464932-24284-1-git-send-email-wrfsh@yandex-team.ru \
    --to=wrfsh@yandex-team.ru \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=yc-core@yandex-team.ru \
    /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).