All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Eric Blake" <eblake@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>
Subject: [Qemu-devel] [PULL 13/36] log: Clean up misuse of Range for -dfilter
Date: Mon, 4 Jul 2016 19:46:53 +0300	[thread overview]
Message-ID: <20160704194653-mutt-send-email-mst@redhat.com> (raw)
In-Reply-To: <1467650742-17580-1-git-send-email-mst@redhat.com>

From: Markus Armbruster <armbru@redhat.com>

Range encodes an integer interval [a,b] as { begin = a, end = b + 1 },
where a \in [0,2^64-1] and b \in [1,2^64].  Thus, zero end is to be
interpreted as 2^64.

The implementation of -dfilter (commit 3514552) uses Range
differently: it encodes [a,b] as { begin = a, end = b }.  The code
works, but it contradicts the specification of Range in range.h.

Switch to the specified representation.  Since it can't represent
[0,UINT64_MAX], we have to reject that now.  Add a test for it.

While we're rejecting anyway: observe that we reject -dfilter LOB..UPB
where LOB > UPB when UPB is zero, but happily create an empty Range
when it isn't.  Reject it then, too, and add a test for it.

While there, add a positive test for the problematic upper bound
UINT64_MAX.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 tests/test-logging.c | 10 ++++++++++
 util/log.c           | 28 +++++++++++++++-------------
 2 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/tests/test-logging.c b/tests/test-logging.c
index 440e75f..b6fa94e 100644
--- a/tests/test-logging.c
+++ b/tests/test-logging.c
@@ -68,6 +68,16 @@ static void test_parse_range(void)
     g_assert(qemu_log_in_addr_range(0x2050));
     g_assert(qemu_log_in_addr_range(0x3050));
 
+    qemu_set_dfilter_ranges("0xffffffffffffffff-1", &error_abort);
+    g_assert(qemu_log_in_addr_range(UINT64_MAX));
+    g_assert_false(qemu_log_in_addr_range(UINT64_MAX - 1));
+
+    qemu_set_dfilter_ranges("0..0xffffffffffffffff", &err);
+    error_free_or_abort(&err);
+
+    qemu_set_dfilter_ranges("2..1", &err);
+    error_free_or_abort(&err);
+
     qemu_set_dfilter_ranges("0x1000+onehundred", &err);
     error_free_or_abort(&err);
 
diff --git a/util/log.c b/util/log.c
index 32e4160..f811d61 100644
--- a/util/log.c
+++ b/util/log.c
@@ -131,8 +131,8 @@ bool qemu_log_in_addr_range(uint64_t addr)
     if (debug_regions) {
         int i = 0;
         for (i = 0; i < debug_regions->len; i++) {
-            struct Range *range = &g_array_index(debug_regions, Range, i);
-            if (addr >= range->begin && addr <= range->end) {
+            Range *range = &g_array_index(debug_regions, Range, i);
+            if (addr >= range->begin && addr <= range->end - 1) {
                 return true;
             }
         }
@@ -158,7 +158,7 @@ void qemu_set_dfilter_ranges(const char *filter_spec, Error **errp)
     for (i = 0; ranges[i]; i++) {
         const char *r = ranges[i];
         const char *range_op, *r2, *e;
-        uint64_t r1val, r2val;
+        uint64_t r1val, r2val, lob, upb;
         struct Range range;
 
         range_op = strstr(r, "-");
@@ -187,27 +187,29 @@ void qemu_set_dfilter_ranges(const char *filter_spec, Error **errp)
                        (int)(r2 - range_op), range_op);
             goto out;
         }
-        if (r2val == 0) {
-            error_setg(errp, "Invalid range");
-            goto out;
-        }
 
         switch (*range_op) {
         case '+':
-            range.begin = r1val;
-            range.end = r1val + (r2val - 1);
+            lob = r1val;
+            upb = r1val + r2val - 1;
             break;
         case '-':
-            range.end = r1val;
-            range.begin = r1val - (r2val - 1);
+            upb = r1val;
+            lob = r1val - (r2val - 1);
             break;
         case '.':
-            range.begin = r1val;
-            range.end = r2val;
+            lob = r1val;
+            upb = r2val;
             break;
         default:
             g_assert_not_reached();
         }
+        if (lob > upb || (lob == 0 && upb == UINT64_MAX)) {
+            error_setg(errp, "Invalid range");
+            goto out;
+        }
+        range.begin = lob;
+        range.end = upb + 1;
         g_array_append_val(debug_regions, range);
     }
 out:
-- 
MST

  parent reply	other threads:[~2016-07-04 16:47 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1467650742-17580-1-git-send-email-mst@redhat.com>
2016-07-04 16:46 ` [Qemu-devel] [PULL 01/36] xen: fix ram init regression Michael S. Tsirkin
2016-07-04 16:46   ` Michael S. Tsirkin
2016-07-04 16:46 ` [Qemu-devel] [PULL 02/36] hw/ppc: realize the PCI root bus as part of mac99 init Michael S. Tsirkin
2016-07-04 16:46 ` [Qemu-devel] [PULL 03/36] hw/pci: delay bus_master_enable_region initialization Michael S. Tsirkin
2016-07-09  1:34   ` Mark Cave-Ayland
2016-07-09  7:07     ` Marcel Apfelbaum
2016-07-09  9:09       ` Mark Cave-Ayland
2016-07-11 14:42   ` Leon Alrae
2016-07-11 15:18     ` Marcel Apfelbaum
2016-07-11 18:41       ` Mark Cave-Ayland
2016-07-14 12:40         ` Marcel Apfelbaum
2016-07-04 16:46 ` [Qemu-devel] [PULL 04/36] q35: allow dynamic sysbus Michael S. Tsirkin
2016-07-04 16:46 ` [Qemu-devel] [PULL 05/36] hw/iommu: enable iommu with -device Michael S. Tsirkin
2016-07-04 16:46 ` [Qemu-devel] [PULL 06/36] machine: remove iommu property Michael S. Tsirkin
2016-07-04 16:46 ` [Qemu-devel] [PULL 07/36] piix: Set I440FXState member pci_info.w32 in one place Michael S. Tsirkin
2016-07-04 16:46 ` [Qemu-devel] [PULL 08/36] pc: Eliminate PcPciInfo Michael S. Tsirkin
2016-07-04 16:46 ` [Qemu-devel] [PULL 09/36] virtio: revert host notifiers to old semantics Michael S. Tsirkin
2016-07-04 16:46 ` [Qemu-devel] [PULL 10/36] virtio: set low features early on load Michael S. Tsirkin
2016-07-04 16:46 ` [Qemu-devel] [PULL 11/36] Revert "virtio-net: unbreak self announcement and guest offloads after migration" Michael S. Tsirkin
2016-07-04 16:46 ` [Qemu-devel] [PULL 12/36] pci_register_bar: cleanup Michael S. Tsirkin
2016-07-04 16:46 ` Michael S. Tsirkin [this message]
2016-07-04 16:46 ` [Qemu-devel] [PULL 14/36] range: Eliminate direct Range member access Michael S. Tsirkin
2016-07-04 16:47 ` [Qemu-devel] [PULL 15/36] range: Replace internal representation of Range Michael S. Tsirkin
2016-07-04 16:47 ` [Qemu-devel] [PULL 16/36] log: Permit -dfilter 0..0xffffffffffffffff Michael S. Tsirkin
2016-07-04 16:47 ` [Qemu-devel] [PULL 17/36] tests: acpi: add CPU hotplug testcase Michael S. Tsirkin
2016-07-04 16:47 ` [Qemu-devel] [PULL 18/36] tests: add APIC.cphp and DSDT.cphp blobs Michael S. Tsirkin
2016-07-04 16:47 ` [Qemu-devel] [PULL 19/36] tests/acpi: add pxb/pxb-pcie tests Michael S. Tsirkin
2016-07-04 16:47 ` [Qemu-devel] [PULL 20/36] hw/pxb: declare pxb devices as not hot-pluggable Michael S. Tsirkin
2016-07-04 16:47 ` [Qemu-devel] [PULL 21/36] hw/acpi: fix a DSDT table issue when a pxb is present Michael S. Tsirkin
2016-07-04 16:47 ` [Qemu-devel] [PULL 22/36] acpi: refactor pxb crs computation Michael S. Tsirkin
2016-07-04 16:47 ` [Qemu-devel] [PULL 23/36] hw/apci: handle 64-bit MMIO regions correctly Michael S. Tsirkin
2016-07-04 16:47 ` [Qemu-devel] [PULL 24/36] tests/acpi: Add pxb/pxb-pcie tests blobs Michael S. Tsirkin
2016-07-04 16:47 ` [Qemu-devel] [PULL 25/36] change pvscsi_init_msi() type to void Michael S. Tsirkin
2016-07-04 16:47 ` [Qemu-devel] [PULL 26/36] usb xhci: change msi/msix property type Michael S. Tsirkin
2016-07-04 16:47 ` [Qemu-devel] [PULL 27/36] intel-hda: change msi " Michael S. Tsirkin
2016-07-04 16:47 ` [Qemu-devel] [PULL 28/36] mptsas: " Michael S. Tsirkin
2016-07-04 16:48 ` [Qemu-devel] [PULL 29/36] megasas: change msi/msix " Michael S. Tsirkin
2016-07-04 16:48 ` [Qemu-devel] [PULL 30/36] pci bridge dev: change msi " Michael S. Tsirkin
2016-07-04 16:48 ` [Qemu-devel] [PULL 31/36] pci: Convert msi_init() to Error and fix callers to check it Michael S. Tsirkin
2016-07-04 16:48 ` [Qemu-devel] [PULL 32/36] megasas: remove unnecessary megasas_use_msi() Michael S. Tsirkin
2016-07-04 16:48 ` [Qemu-devel] [PULL 33/36] mptsas: remove unnecessary internal msi state flag Michael S. Tsirkin
2016-07-04 16:48 ` [Qemu-devel] [PULL 34/36] vmxnet3: " Michael S. Tsirkin
2016-07-04 16:48 ` [Qemu-devel] [PULL 35/36] e1000e: " Michael S. Tsirkin
2016-07-04 16:48 ` [Qemu-devel] [PULL 36/36] vmw_pvscsi: " Michael S. Tsirkin

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=20160704194653-mutt-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.