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

[Xen-devel] [PATCH 06/12] xen: add domain specific parameter support



Add the framework for being able to define domain specific parameters.
This includes the needed macros for defining a parameter and the
minimal set of functions for doing parameter parsing.

Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
 xen/arch/arm/domain.c    |  5 +++++
 xen/arch/x86/domain.c    |  4 ++++
 xen/common/domain.c      | 10 ++++++++++
 xen/common/domctl.c      | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 xen/common/kernel.c      | 12 ++++++++++++
 xen/include/xen/domain.h |  3 +++
 xen/include/xen/init.h   | 34 +++++++++++++++++++++++++++++-----
 xen/include/xen/lib.h    |  1 +
 8 files changed, 110 insertions(+), 5 deletions(-)

diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
index feebbf5a92..3f8bd6bdcc 100644
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -1011,6 +1011,11 @@ void vcpu_kick(struct vcpu *vcpu)
     }
 }
 
+int arch_domain_check_parflags(struct domain *d, unsigned int flags)
+{
+    return 0;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index d67a0478f6..8e57e7a181 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -2106,6 +2106,10 @@ static int __init init_vcpu_kick_softirq(void)
 }
 __initcall(init_vcpu_kick_softirq);
 
+int arch_domain_check_parflags(struct domain *d, unsigned int flags)
+{
+    return 0;
+}
 
 /*
  * Local variables:
diff --git a/xen/common/domain.c b/xen/common/domain.c
index 65151e2ac4..ac0ad97638 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -1647,6 +1647,16 @@ int continue_hypercall_on_cpu(
     return 0;
 }
 
+int domain_check_parflags(void *instance, unsigned int flags)
+{
+    struct domain *d = instance;
+
+    if ( !(flags & PARAM_FLAG_RUNTIME) && d->creation_finished )
+         return -EBUSY;
+
+    return arch_domain_check_parflags(d, flags);
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index b2948814aa..149f0ed9d8 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -1075,6 +1075,52 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) 
u_domctl)
             copyback = 1;
         break;
 
+    case XEN_DOMCTL_set_parameter:
+    {
+#define XEN_SET_PARAMETER_MAX_SIZE 1023
+        char *params;
+
+        if ( op->u.set_parameter.pad[0] || op->u.set_parameter.pad[1] ||
+             op->u.set_parameter.pad[2] )
+        {
+            ret = -EINVAL;
+            break;
+        }
+        if ( d == current->domain )
+        {
+            printk("domain %u can't set parameter for itself!\n",
+                   d->domain_id);
+            ret = -EBUSY;
+            break;
+        }
+        if ( op->u.set_parameter.size > XEN_SET_PARAMETER_MAX_SIZE )
+        {
+            printk("parameter size too big!\n");
+            ret = -E2BIG;
+            break;
+        }
+        params = xmalloc_bytes(op->u.set_parameter.size + 1);
+        if ( !params )
+        {
+            ret = -ENOMEM;
+            break;
+        }
+        if ( copy_from_guest(params, op->u.set_parameter.params,
+                             op->u.set_parameter.size) )
+            ret = -EFAULT;
+        else
+        {
+            domain_pause(d);
+            params[op->u.set_parameter.size] = 0;
+            ret = domain_param_parse(d, params);
+            domain_unpause(d);
+        }
+
+        xfree(params);
+
+        break;
+    }
+
     default:
         ret = arch_do_domctl(op, d, u_domctl);
         break;
diff --git a/xen/common/kernel.c b/xen/common/kernel.c
index 0d3d7f6135..d0b3af1453 100644
--- a/xen/common/kernel.c
+++ b/xen/common/kernel.c
@@ -222,6 +222,13 @@ static const struct parse_data runtime_parse_data = {
     .end    = __param_end,
 };
 
+static const struct parse_data domain_parse_data = {
+    .scope = SCOPE_DOMAIN,
+    .start = __param_start,
+    .end   = __param_end,
+    .check = domain_check_parflags,
+};
+
 static void __init _cmdline_parse(const char *cmdline)
 {
     parse_params(cmdline, &boot_parse_data, NULL);
@@ -232,6 +239,11 @@ int runtime_parse(const char *line)
     return parse_params(line, &runtime_parse_data, NULL);
 }
 
+int domain_param_parse(struct domain *d, const char *line)
+{
+    return parse_params(line, &domain_parse_data, d);
+}
+
 /**
  *    cmdline_parse -- parses the xen command line.
  * If CONFIG_CMDLINE is set, it would be parsed prior to @cmdline.
diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h
index 5e393fd7f2..944ed5beeb 100644
--- a/xen/include/xen/domain.h
+++ b/xen/include/xen/domain.h
@@ -72,6 +72,9 @@ int arch_domain_soft_reset(struct domain *d);
 
 void arch_p2m_set_access_required(struct domain *d, bool access_required);
 
+int domain_check_parflags(void *instance, unsigned int flags);
+int arch_domain_check_parflags(struct domain *d, unsigned int flags);
+
 int arch_set_info_guest(struct vcpu *, vcpu_guest_context_u);
 void arch_get_info_guest(struct vcpu *, vcpu_guest_context_u);
 
diff --git a/xen/include/xen/init.h b/xen/include/xen/init.h
index 3975964ee8..13cf5214b3 100644
--- a/xen/include/xen/init.h
+++ b/xen/include/xen/init.h
@@ -54,6 +54,8 @@
 
 #ifndef __ASSEMBLY__
 
+struct domain;
+
 /*
  * Used for initialization calls..
  */
@@ -74,7 +76,8 @@ void do_initcalls(void);
  * Used for kernel command line parameter setup
  */
 enum param_scope {
-    SCOPE_GLOBAL
+    SCOPE_GLOBAL,
+    SCOPE_DOMAIN
 };
 
 struct kernel_param {
@@ -93,6 +96,7 @@ struct kernel_param {
     union {
         void *var;
         int (*func)(const char *);
+        int (*func_domain)(const char *, struct domain *);
         int (*call)(const char *, void *);
     } par;
 };
@@ -109,12 +113,12 @@ extern const struct kernel_param __param_start[], 
__param_end[];
     __attribute__((__aligned__(1))) char
 #define __kparam          __param(__initsetup)
 
-#define def_custom_param(_name, _scope, _flags, _func) \
+#define def_custom_param(_name, _scope, _flags, _ptr, _func) \
     { .name = _name, \
       .type = OPT_CUSTOM, \
       .scope = _scope, \
       .flags = _flags, \
-      .par.func = _func }
+      .par._ptr = _func }
 #define def_var_param(_name, _type, _scope, _flags, _var) \
     { .name = _name, \
       .type = _type, \
@@ -126,7 +130,7 @@ extern const struct kernel_param __param_start[], 
__param_end[];
 #define custom_param(_name, _var) \
     __setup_str __setup_str_##_var[] = _name; \
     __kparam __setup_##_var = \
-        def_custom_param(__setup_str_##_var, SCOPE_GLOBAL, 0, _var)
+        def_custom_param(__setup_str_##_var, SCOPE_GLOBAL, 0, func, _var)
 #define boolean_param(_name, _var) \
     __setup_str __setup_str_##_var[] = _name; \
     __kparam __setup_##_var = \
@@ -148,7 +152,7 @@ extern const struct kernel_param __param_start[], 
__param_end[];
 
 #define custom_runtime_only_param(_name, _var) \
     __rtparam __rtpar_##_var = \
-        def_custom_param(_name, SCOPE_GLOBAL, 0, _var)
+        def_custom_param(_name, SCOPE_GLOBAL, 0, func, _var)
 #define boolean_runtime_only_param(_name, _var) \
     __rtparam __rtpar_##_var = \
         def_var_param(_name, OPT_BOOL, SCOPE_GLOBAL, 0, _var)
@@ -178,6 +182,26 @@ extern const struct kernel_param __param_start[], 
__param_end[];
     string_param(_name, _var); \
     string_runtime_only_param(_name, _var)
 
+#define custom_domain_param(_name, _flags, _var) \
+    __rtparam __domain_par_##_var = \
+        def_custom_param(_name, SCOPE_DOMAIN, _flags, func_domain, _var)
+#define boolean_domain_param(_name, _flags, _var) \
+    __rtparam __domain_par_##_var = \
+        def_var_param(_name, OPT_BOOL, SCOPE_DOMAIN, _flags, \
+                      (struct domain *)NULL->_var)
+#define integer_domain_param(_name, _flags, _var) \
+    __rtparam __domain_par_##_var = \
+        def_var_param(_name, OPT_UINT, SCOPE_DOMAIN, _flags, \
+                      (struct domain *)NULL->_var)
+#define size_domain_param(_name, _flags, _var) \
+    __rtparam __domain_par_##_var = \
+        def_var_param(_name, OPT_SIZE, SCOPE_DOMAIN, _flags, \
+                      (struct domain *)NULL->_var)
+#define string_domain_param(_name, _flags, _var) \
+    __rtparam __domain_par_##_var = \
+        def_var_param(_name, OPT_STR, SCOPE_DOMAIN, _flags, \
+                      (struct domain *)NULL->_var)
+
 #endif /* __ASSEMBLY__ */
 
 #ifdef CONFIG_LATE_HWDOM
diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h
index 972fc843fa..7ba5929ed5 100644
--- a/xen/include/xen/lib.h
+++ b/xen/include/xen/lib.h
@@ -70,6 +70,7 @@ struct domain;
 
 void cmdline_parse(const char *cmdline);
 int runtime_parse(const char *line);
+int domain_param_parse(struct domain *d, const char *line);
 int parse_bool(const char *s, const char *e);
 
 /**
-- 
2.16.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.