diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index 9db62972467c..cbd5d0b4de08 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -356,18 +356,12 @@ calc_topology(void) guest_ncpus = ncpus; } -int -bhyve_pincpu_parse(const char *opt) +static int +bhyve_pincpu(int vcpu, int pcpu) { const char *value; char *newval; char key[16]; - int vcpu, pcpu; - - if (sscanf(opt, "%d:%d", &vcpu, &pcpu) != 2) { - fprintf(stderr, "invalid format: %s\n", opt); - return (-1); - } if (vcpu < 0) { fprintf(stderr, "invalid vcpu '%d'\n", vcpu); @@ -394,6 +388,42 @@ bhyve_pincpu_parse(const char *opt) return (0); } +int +bhyve_pincpu_parse(const char *opt) +{ + int vcpu_first, vcpu_last, pcpu_first, pcpu_last; + int vcpu, pcpu; + int count; + int i; + + if (sscanf(opt, "%d-%d:%d-%d", &vcpu_first, &vcpu_last, &pcpu_first, &pcpu_last) == 4) { + if (vcpu_first > vcpu_last || pcpu_first > pcpu_last) { + fprintf(stderr, "invalid range (must be ascending): %s\n", opt); + return (-1); + } + count = vcpu_last - vcpu_first + 1; + if (count != (pcpu_last - pcpu_first + 1)) { + fprintf(stderr, "range sizes do not match: %s\n", opt); + return (-1); + } + for (i = 0; i < count; i++) { + vcpu = vcpu_first + i; + pcpu = pcpu_first + i; + if (bhyve_pincpu(vcpu, pcpu) != 0) { + return (-1); + } + } + return (0); + } + + if (sscanf(opt, "%d:%d", &vcpu, &pcpu) == 2) { + return bhyve_pincpu(vcpu, pcpu); + } + + fprintf(stderr, "invalid format: %s\n", opt); + return (-1); +} + static void parse_cpuset(int vcpu, const char *list, cpuset_t *set) {