From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org, Anthony Liguori <anthony@codemonkey.ws>
Cc: Chegu Vinod <chegu_vinod@hp.com>
Subject: [Qemu-devel] [PATCH 8/8] vl.c: validate -numa "cpus" parameter properly
Date: Wed, 16 Jan 2013 13:24:11 -0200 [thread overview]
Message-ID: <1358349851-20960-9-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1358349851-20960-1-git-send-email-ehabkost@redhat.com>
- Accept empty strings without aborting
- Use parse_uint*() to parse numbers
- Abort if anything except '-' or end-of-string is found after the first
number.
- Check for endvalue < value
Also change the MAX_CPUMASK_BITS warning message from "A max of %d CPUs
are supported in a guest" to "qemu: NUMA: A max of %d VCPUs are
supported".
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: Eric Blake <eblake@redhat.com>
---
vl.c | 32 +++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/vl.c b/vl.c
index 98cf9f0..2d156e2 100644
--- a/vl.c
+++ b/vl.c
@@ -1246,21 +1246,43 @@ static void numa_node_parse_cpus(int nodenr, const char *cpus)
char *endptr;
unsigned long long value, endvalue;
- value = strtoull(cpus, &endptr, 10);
+ /* Empty CPU range strings will be considered valid, they will simply
+ * not set any bit in the CPU bitmap.
+ */
+ if (!*cpus) {
+ return;
+ }
+
+ if (parse_uint(cpus, &value, &endptr) < 0) {
+ goto error;
+ }
if (*endptr == '-') {
- endvalue = strtoull(endptr+1, &endptr, 10);
- } else {
+ if (parse_uint_full(endptr + 1, &endvalue) < 0) {
+ goto error;
+ }
+ } else if (*endptr == '\0') {
endvalue = value;
+ } else {
+ goto error;
}
- if (!(endvalue < MAX_CPUMASK_BITS)) {
+ if (endvalue >= MAX_CPUMASK_BITS) {
endvalue = MAX_CPUMASK_BITS - 1;
fprintf(stderr,
- "A max of %d CPUs are supported in a guest\n",
+ "qemu: NUMA: A max of %d VCPUs are supported\n",
MAX_CPUMASK_BITS);
}
+ if (endvalue < value) {
+ goto error;
+ }
+
bitmap_set(node_cpumask[nodenr], value, endvalue-value+1);
+ return;
+
+error:
+ fprintf(stderr, "qemu: Invalid NUMA CPU range: %s\n", cpus);
+ exit(1);
}
static void numa_add(const char *optarg)
--
1.7.11.7
next prev parent reply other threads:[~2013-01-16 16:51 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-16 15:24 [Qemu-devel] [PATCH 0/8] -numa option parsing fixes (v2) Eduardo Habkost
2013-01-16 15:24 ` [Qemu-devel] [PATCH 1/8] cutils: unsigned int parsing functions Eduardo Habkost
2013-01-16 17:10 ` Eric Blake
2013-01-16 17:33 ` Eduardo Habkost
2013-01-16 17:50 ` Eric Blake
2013-01-16 17:56 ` Eduardo Habkost
2013-01-16 15:24 ` [Qemu-devel] [PATCH 2/8] vl.c: Fix off-by-one bug when handling "-numa node" argument Eduardo Habkost
2013-01-16 18:00 ` Eric Blake
2013-01-16 15:24 ` [Qemu-devel] [PATCH 3/8] vl.c: Abort on unknown -numa option type Eduardo Habkost
2013-01-16 15:24 ` [Qemu-devel] [PATCH 4/8] vl.c: Check for NUMA node limit inside numa_add() Eduardo Habkost
2013-01-16 17:56 ` Eric Blake
2013-01-16 15:24 ` [Qemu-devel] [PATCH 5/8] vl.c: numa_add(): Validate nodeid before using it Eduardo Habkost
2013-01-16 17:23 ` Eric Blake
2013-01-16 15:24 ` [Qemu-devel] [PATCH 6/8] vl.c: Use parse_uint_full() for NUMA nodeid Eduardo Habkost
2013-01-16 17:25 ` Eric Blake
2013-01-16 17:42 ` Eduardo Habkost
2013-01-16 17:54 ` Eric Blake
2013-01-16 18:18 ` Eduardo Habkost
2013-01-16 15:24 ` [Qemu-devel] [PATCH 7/8] vl.c: Extract -numa "cpus" parsing to separate function Eduardo Habkost
2013-01-16 18:23 ` Eric Blake
2013-01-16 15:24 ` Eduardo Habkost [this message]
2013-01-16 17:30 ` [Qemu-devel] [PATCH 8/8] vl.c: validate -numa "cpus" parameter properly Eric Blake
2013-01-16 17:50 ` Eduardo Habkost
-- strict thread matches above, loose matches on Subject: below --
2013-01-16 18:28 [Qemu-devel] [PATCH 0/8] -numa option parsing fixes (v3) Eduardo Habkost
2013-01-16 18:28 ` [Qemu-devel] [PATCH 8/8] vl.c: validate -numa "cpus" parameter properly Eduardo Habkost
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=1358349851-20960-9-git-send-email-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=chegu_vinod@hp.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).