[PATCHv2 2/3] qemu: Add range checking for scheduler tunables when changed by API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The quota and period tunables for cpu scheduler accept only a certain
range of values. When changing the live configuration invalid values get
rejected. This check is not performed when changing persistent config.

This patch adds a separate range check, that improves error messages
when changing live config and adds the check for persistent config.
This check is done only when using the API. It is still possible to
specify invalid values in the XML.
---
Diff to v1:
- changed typecast to native long long specification
---
 src/qemu/qemu_driver.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4b8b751..8e8e00c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -106,6 +106,11 @@
 #define QEMU_NB_TOTAL_CPU_STAT_PARAM 3
 #define QEMU_NB_PER_CPU_STAT_PARAM 2

+#define QEMU_SCHED_MIN_PERIOD              1000LL
+#define QEMU_SCHED_MAX_PERIOD           1000000LL
+#define QEMU_SCHED_MIN_QUOTA               1000LL
+#define QEMU_SCHED_MAX_QUOTA  18446744073709551LL
+
 #if HAVE_LINUX_KVM_H
 # include <linux/kvm.h>
 #endif
@@ -7790,6 +7795,15 @@ cleanup:
     return -1;
 }

+#define SCHED_RANGE_CHECK(VAR, NAME, MIN, MAX)                              \
+    if (((VAR) > 0 && (VAR) < (MIN)) || (VAR) > (MAX)) {                    \
+        virReportError(VIR_ERR_INVALID_ARG,                                 \
+                       _("value of '%s' is out of range [%lld, %lld]"),     \
+                       NAME, MIN, MAX);                                     \
+        rc = -1;                                                            \
+        goto cleanup;                                                       \
+    }
+
 static int
 qemuSetSchedulerParametersFlags(virDomainPtr dom,
                                 virTypedParameterPtr params,
@@ -7876,6 +7890,9 @@ qemuSetSchedulerParametersFlags(virDomainPtr dom,
                 vmdef->cputune.shares = value_ul;

         } else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_VCPU_PERIOD)) {
+            SCHED_RANGE_CHECK(value_ul, VIR_DOMAIN_SCHEDULER_VCPU_PERIOD,
+                              QEMU_SCHED_MIN_PERIOD, QEMU_SCHED_MAX_PERIOD);
+
             if (flags & VIR_DOMAIN_AFFECT_LIVE && value_ul) {
                 if ((rc = qemuSetVcpusBWLive(vm, group, value_ul, 0)))
                     goto cleanup;
@@ -7887,6 +7904,9 @@ qemuSetSchedulerParametersFlags(virDomainPtr dom,
                 vmdef->cputune.period = params[i].value.ul;

         } else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA)) {
+            SCHED_RANGE_CHECK(value_l, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA,
+                              QEMU_SCHED_MIN_QUOTA, QEMU_SCHED_MAX_QUOTA);
+
             if (flags & VIR_DOMAIN_AFFECT_LIVE && value_l) {
                 if ((rc = qemuSetVcpusBWLive(vm, group, 0, value_l)))
                     goto cleanup;
@@ -7898,6 +7918,9 @@ qemuSetSchedulerParametersFlags(virDomainPtr dom,
                 vmdef->cputune.quota = value_l;

         } else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_EMULATOR_PERIOD)) {
+            SCHED_RANGE_CHECK(value_ul, VIR_DOMAIN_SCHEDULER_EMULATOR_PERIOD,
+                              QEMU_SCHED_MIN_PERIOD, QEMU_SCHED_MAX_PERIOD);
+
             if (flags & VIR_DOMAIN_AFFECT_LIVE && value_ul) {
                 if ((rc = qemuSetEmulatorBandwidthLive(vm, group, value_ul, 0)))
                     goto cleanup;
@@ -7909,6 +7932,9 @@ qemuSetSchedulerParametersFlags(virDomainPtr dom,
                 vmdef->cputune.emulator_period = value_ul;

         } else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_EMULATOR_QUOTA)) {
+            SCHED_RANGE_CHECK(value_l, VIR_DOMAIN_SCHEDULER_EMULATOR_QUOTA,
+                              QEMU_SCHED_MIN_QUOTA, QEMU_SCHED_MAX_QUOTA);
+
             if (flags & VIR_DOMAIN_AFFECT_LIVE && value_l) {
                 if ((rc = qemuSetEmulatorBandwidthLive(vm, group, 0, value_l)))
                     goto cleanup;
@@ -7944,6 +7970,7 @@ cleanup:
     qemuDriverUnlock(driver);
     return ret;
 }
+#undef SCHED_RANGE_CHECK

 static int
 qemuSetSchedulerParameters(virDomainPtr dom,
-- 
1.7.12

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]